Main Changes:
- Added automatic frameskip support - Improved Timers speed git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@6 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#ifndef CLOGFILE_H_
|
||||
#define CLOGFILE_H_
|
||||
|
||||
#define REVISION "CloneKeenPlus Beta v0.2.9.0 (Commander Genius)"
|
||||
#define REVISION "CloneKeenPlus Beta v0.2.9.1 (Commander Genius)"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "CSingleton.h"
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
#include "include/gamepdo.h"
|
||||
#include "include/misc.h"
|
||||
#include "sdl/CVideoDriver.h"
|
||||
#include "sdl/CTimer.h"
|
||||
#include "sdl/CInput.h"
|
||||
#include "sdl/sound/CSound.h"
|
||||
#include "CGraphics.h"
|
||||
#include "sdl/CInput.h"
|
||||
#include "vorticon/CPlayer.h"
|
||||
#include "keenext.h"
|
||||
|
||||
|
||||
@@ -488,6 +488,7 @@ short saveDriverConfiguration(stCloneKeenPlus *pCKP)
|
||||
Parser.saveIntValue("scale","Video",g_pVideoDriver->getZoomValue());
|
||||
Parser.saveIntValue("OGLfilter","Video",g_pVideoDriver->getOGLFilter());
|
||||
Parser.saveIntValue("filter","Video",g_pVideoDriver->getFiltermode());
|
||||
Parser.saveIntValue("autoframeskip","Video",g_pVideoDriver->getTargetFPS());
|
||||
|
||||
Parser.saveIntValue("channels","Audio",(g_pSound->getAudioSpec()).channels);
|
||||
Parser.saveIntValue("format","Audio",(g_pSound->getAudioSpec()).format);
|
||||
@@ -528,6 +529,7 @@ short loadDriverConfiguration(stCloneKeenPlus *pCKP)
|
||||
|
||||
g_pVideoDriver->setOGLFilter(Parser.getIntValue("OGLfilter","Video"));
|
||||
g_pVideoDriver->setZoom(Parser.getIntValue("scale","Video"));
|
||||
g_pVideoDriver->setTargetFPS(Parser.getIntValue("autoframeskip","Video"));
|
||||
|
||||
g_pVideoDriver->setFilter(Parser.getIntValue("filter","Video"));
|
||||
|
||||
|
||||
47
src/menu.cpp
47
src/menu.cpp
@@ -643,6 +643,7 @@ short GraphicsDlg(stCloneKeenPlus *pCKP)
|
||||
bool fsmode;
|
||||
char buf[256];
|
||||
short retval = 0;
|
||||
unsigned char autoframeskip = 0;
|
||||
|
||||
showmapatpos(90, MAINMENU_X, MENUS_Y, 0, pCKP);
|
||||
|
||||
@@ -718,6 +719,24 @@ short GraphicsDlg(stCloneKeenPlus *pCKP)
|
||||
else
|
||||
DisplayMenu->addOptionText("Software Rendering");
|
||||
|
||||
autoframeskip = g_pVideoDriver->getTargetFPS();
|
||||
switch(autoframeskip)
|
||||
{
|
||||
case 60:
|
||||
DisplayMenu->addOptionText("Auto-Frameskip : 60 fps"); break;
|
||||
case 50:
|
||||
DisplayMenu->addOptionText("Auto-Frameskip : 50 fps"); break;
|
||||
case 40:
|
||||
DisplayMenu->addOptionText("Auto-Frameskip : 40 fps"); break;
|
||||
case 30:
|
||||
DisplayMenu->addOptionText("Auto-Frameskip : 30 fps"); break;
|
||||
case 20:
|
||||
DisplayMenu->addOptionText("Auto-Frameskip : 20 fps"); break;
|
||||
default:
|
||||
DisplayMenu->addOptionText("Auto-Frameskip disabled"); break;
|
||||
};
|
||||
|
||||
|
||||
DisplayMenu->addSeparator();
|
||||
DisplayMenu->addOptionText("Save and return");
|
||||
DisplayMenu->addOptionText("Cancel");
|
||||
@@ -843,7 +862,32 @@ short GraphicsDlg(stCloneKeenPlus *pCKP)
|
||||
else
|
||||
DisplayMenu->setOptionText(5,"Software Rendering");
|
||||
}
|
||||
else if(selection == 7)
|
||||
else if(selection == 6)
|
||||
{
|
||||
if(autoframeskip < 60 && autoframeskip >= 0)
|
||||
autoframeskip += 10;
|
||||
else
|
||||
autoframeskip = 0;
|
||||
|
||||
switch(autoframeskip)
|
||||
{
|
||||
case 60:
|
||||
DisplayMenu->setOptionText(6,"Auto-Frameskip : 60 fps"); break;
|
||||
case 50:
|
||||
DisplayMenu->setOptionText(6,"Auto-Frameskip : 50 fps"); break;
|
||||
case 40:
|
||||
DisplayMenu->setOptionText(6,"Auto-Frameskip : 40 fps"); break;
|
||||
case 30:
|
||||
DisplayMenu->setOptionText(6,"Auto-Frameskip : 30 fps"); break;
|
||||
case 20:
|
||||
DisplayMenu->setOptionText(6,"Auto-Frameskip : 20 fps"); break;
|
||||
case 10:
|
||||
DisplayMenu->setOptionText(6,"Auto-Frameskip : 10 fps"); break;
|
||||
default:
|
||||
DisplayMenu->setOptionText(6,"Auto-Frameskip disabled"); break;
|
||||
};
|
||||
}
|
||||
else if(selection == 8)
|
||||
{
|
||||
g_pVideoDriver->stop();
|
||||
|
||||
@@ -858,6 +902,7 @@ short GraphicsDlg(stCloneKeenPlus *pCKP)
|
||||
g_pVideoDriver->setZoom(zoom);
|
||||
g_pVideoDriver->setFilter(filter);
|
||||
g_pVideoDriver->setFrameskip(frameskip);
|
||||
g_pVideoDriver->setTargetFPS(autoframeskip);
|
||||
saveDriverConfiguration(pCKP);
|
||||
g_pGraphics->allocScrollBufmem();
|
||||
|
||||
|
||||
@@ -8,24 +8,9 @@
|
||||
|
||||
#include "../keen.h"
|
||||
#include "../keenext.h"
|
||||
#include <SDL.h>
|
||||
|
||||
#include "CTimer.h"
|
||||
|
||||
typedef char int8;
|
||||
typedef short int16;
|
||||
typedef long int32;
|
||||
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned long uint32;
|
||||
|
||||
#ifdef __GNUC__
|
||||
typedef unsigned long long uint64;
|
||||
typedef long long int64;
|
||||
#define INLINE inline
|
||||
#define GINLINE inline
|
||||
#endif
|
||||
#include "CVideoDriver.h"
|
||||
|
||||
Uint32 FPSCallback(Uint32 interval, void* param);
|
||||
|
||||
@@ -38,6 +23,34 @@ Uint32 FPSCallback(Uint32 interval, void* param)
|
||||
{
|
||||
fps = (curfps << 1);
|
||||
curfps = 0;
|
||||
|
||||
unsigned char targetfps;
|
||||
targetfps = g_pVideoDriver->getTargetFPS();
|
||||
|
||||
if(targetfps > 0)
|
||||
{
|
||||
if(fps > targetfps + 10)
|
||||
{
|
||||
uint8 fsk;
|
||||
fsk = g_pVideoDriver->getFrameskip();
|
||||
|
||||
if(fsk < 20)
|
||||
fsk++;
|
||||
|
||||
g_pVideoDriver->setFrameskip(fsk);
|
||||
}
|
||||
else if( fps < targetfps - 10)
|
||||
{
|
||||
uint8 fsk;
|
||||
fsk = g_pVideoDriver->getFrameskip();
|
||||
|
||||
if(fsk > 0)
|
||||
fsk--;
|
||||
|
||||
g_pVideoDriver->setFrameskip(fsk);
|
||||
}
|
||||
}
|
||||
|
||||
return interval;
|
||||
}
|
||||
|
||||
@@ -45,6 +58,9 @@ CTimer::CTimer() {
|
||||
RefreshThrottleFPS();
|
||||
if(SDL_Init(SDL_INIT_TIMER) == 0)
|
||||
ckp_timer_id = SDL_AddTimer(1000, FPSCallback, NULL);
|
||||
|
||||
ltime = 0;
|
||||
m_frameskip = 0;
|
||||
}
|
||||
|
||||
CTimer::~CTimer() {
|
||||
@@ -53,22 +69,23 @@ CTimer::~CTimer() {
|
||||
|
||||
void CTimer::SpeedThrottle(void)
|
||||
{
|
||||
static uint64 ttime,ltime=0;
|
||||
//regulateFrameskip();
|
||||
|
||||
waiter:
|
||||
|
||||
ttime=SDL_GetTicks();
|
||||
ttime*=10000;
|
||||
//ttime*=10000;
|
||||
ttime<<=14;
|
||||
|
||||
if( (ttime-ltime) < (tfreq/desiredfps) )
|
||||
{
|
||||
int64 delay;
|
||||
delay=(tfreq/desiredfps)-(ttime-ltime);
|
||||
if(delay>0)
|
||||
SDL_Delay(delay/10000);
|
||||
goto waiter;
|
||||
delay=(tfreq/desiredfps)-(ttime-ltime);
|
||||
if(delay>0)
|
||||
//SDL_Delay(delay/10000);
|
||||
SDL_Delay(delay>>14);
|
||||
goto waiter;
|
||||
}
|
||||
if( (ttime-ltime) >= (tfreq*4/desiredfps))
|
||||
if( (ttime-ltime) >= ((tfreq<<2)/desiredfps) )
|
||||
ltime=ttime;
|
||||
else
|
||||
ltime+=tfreq/desiredfps;
|
||||
@@ -77,8 +94,8 @@ void CTimer::RefreshThrottleFPS(void)
|
||||
{
|
||||
// desiredfps=FCEUI_GetDesiredFPS()>>8;
|
||||
// desiredfps = 23000000;
|
||||
desiredfps = 21800000;
|
||||
//desiredfps = 21800000;
|
||||
desiredfps = 13600000;
|
||||
tfreq=10000000;
|
||||
tfreq<<=16; /* Adjustment for fps returned from FCEUI_GetDesiredFPS(). */
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,25 @@
|
||||
#include "../CSingleton.h"
|
||||
#define g_pTimer CTimer::Get()
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
void initTimer(void);
|
||||
|
||||
typedef char int8;
|
||||
typedef short int16;
|
||||
typedef long int32;
|
||||
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned long uint32;
|
||||
|
||||
#ifdef __GNUC__
|
||||
typedef unsigned long long uint64;
|
||||
typedef long long int64;
|
||||
#define INLINE inline
|
||||
#define GINLINE inline
|
||||
#endif
|
||||
|
||||
class CTimer : public CSingleton<CTimer>
|
||||
{
|
||||
public:
|
||||
@@ -23,7 +40,18 @@ public:
|
||||
void SpeedThrottle(void);
|
||||
void RefreshThrottleFPS(void);
|
||||
|
||||
uint8 getFrameskip(void){ return m_frameskip; }
|
||||
void setFrameskip(uint8 frameskip){ m_frameskip = frameskip; }
|
||||
|
||||
private:
|
||||
|
||||
uint64 ttime;
|
||||
uint64 ltime;
|
||||
int64 delay;
|
||||
|
||||
uint64 m_timepoint;
|
||||
uint64 m_elaptime;
|
||||
uint8 m_frameskip;
|
||||
};
|
||||
|
||||
#endif /* CTIMER_H_ */
|
||||
|
||||
@@ -55,6 +55,7 @@ CVideoDriver::CVideoDriver() {
|
||||
Filtermode=1;
|
||||
Zoom=2;
|
||||
FrameSkip=2;
|
||||
m_targetfps = 0; // Disable automatic frameskipping by default
|
||||
m_opengl = false;
|
||||
m_opengl_filter = GL_NEAREST;
|
||||
mp_OpenGL = NULL;
|
||||
@@ -220,7 +221,7 @@ bool CVideoDriver::createSurfaces(void)
|
||||
//Set surface alpha
|
||||
SDL_SetAlpha( FGLayerSurface, SDL_SRCALPHA, 225 );
|
||||
|
||||
if(Width == 320)
|
||||
if(Width == 320 && !m_opengl)
|
||||
{
|
||||
g_pLogFile->textOut("Blitsurface = Screen<br>");
|
||||
BlitSurface = screen;
|
||||
@@ -244,10 +245,6 @@ bool CVideoDriver::createSurfaces(void)
|
||||
dstrect.w = GAME_STD_WIDTH;
|
||||
dstrect.h = GAME_STD_HEIGHT;
|
||||
|
||||
|
||||
|
||||
// TODO: If OpenGL used, do we still need this?
|
||||
|
||||
if(m_opengl) // If OpenGL could be set, initialize the matrices
|
||||
{
|
||||
mp_OpenGL = new COpenGL();
|
||||
|
||||
@@ -66,6 +66,9 @@ public:
|
||||
void enableOpenGL(bool value) { m_opengl = value; }
|
||||
void setOGLFilter(unsigned char value) { m_opengl_filter = (value==1) ? GL_LINEAR : GL_NEAREST ; }
|
||||
|
||||
void setTargetFPS(unsigned char targetfps){ if( targetfps >= 0 && targetfps <= 60 ) m_targetfps = targetfps; }
|
||||
unsigned char getTargetFPS(void){ return m_targetfps; }
|
||||
|
||||
void showFPS(bool value);
|
||||
|
||||
private:
|
||||
@@ -79,6 +82,7 @@ private:
|
||||
short Filtermode;
|
||||
unsigned short Zoom;
|
||||
unsigned short FrameSkip;
|
||||
unsigned char m_targetfps; // Used for automatic frame skipping
|
||||
bool showfps;
|
||||
bool m_opengl;
|
||||
int m_opengl_filter;
|
||||
|
||||
Reference in New Issue
Block a user