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,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(). */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user