Clean up the EngineProcess loop
This commit is contained in:
parent
b7fe998252
commit
4fa02965bf
@ -573,12 +573,11 @@ void EventProcess(SDL_Event event)
|
|||||||
|
|
||||||
void EngineProcess()
|
void EngineProcess()
|
||||||
{
|
{
|
||||||
int frameStart = SDL_GetTicks();
|
double frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f;
|
||||||
float frameTime;
|
|
||||||
float frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f;
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while(engine->Running())
|
while(engine->Running())
|
||||||
{
|
{
|
||||||
|
int frameStart = SDL_GetTicks();
|
||||||
if(engine->Broken()) { engine->UnBreak(); break; }
|
if(engine->Broken()) { engine->UnBreak(); break; }
|
||||||
event.type = 0;
|
event.type = 0;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
@ -594,7 +593,7 @@ void EngineProcess()
|
|||||||
if(scale != engine->Scale || fullscreen != engine->Fullscreen)
|
if(scale != engine->Scale || fullscreen != engine->Fullscreen)
|
||||||
{
|
{
|
||||||
sdl_scrn = SDLSetScreen(engine->Scale, engine->Fullscreen);
|
sdl_scrn = SDLSetScreen(engine->Scale, engine->Fullscreen);
|
||||||
inputScale = 1.0f/float(scale);
|
inputScale = 1.0f/(float)scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OGLI
|
#ifdef OGLI
|
||||||
@ -606,23 +605,19 @@ void EngineProcess()
|
|||||||
blit(engine->g->vid);
|
blit(engine->g->vid);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
frameTime = SDL_GetTicks() - frameStart;
|
int frameTime = SDL_GetTicks() - frameStart;
|
||||||
frameTimeAvg = (frameTimeAvg*(1.0f-0.2f)) + (0.2f*frameTime);
|
frameTimeAvg = frameTimeAvg * 0.8 + frameTime * 0.2;
|
||||||
if(ui::Engine::Ref().FpsLimit > 2.0f)
|
int fpsLimit = ui::Engine::Ref().FpsLimit;
|
||||||
|
if(fpsLimit > 2)
|
||||||
{
|
{
|
||||||
float targetFrameTime = 1000.0f/((float)ui::Engine::Ref().FpsLimit);
|
double offset = 1000.0 / fpsLimit - frameTimeAvg;
|
||||||
if(targetFrameTime - frameTimeAvg > 0)
|
if(offset > 0)
|
||||||
{
|
SDL_Delay(offset + 0.5);
|
||||||
SDL_Delay((targetFrameTime - frameTimeAvg) + 0.5f);
|
|
||||||
frameTime = SDL_GetTicks() - frameStart;//+= (int)(targetFrameTime - frameTimeAvg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
correctedFrameTimeAvg = (correctedFrameTimeAvg*(1.0f-0.05f)) + (0.05f*frameTime);
|
int correctedFrameTime = SDL_GetTicks() - frameStart;
|
||||||
fps = 1000.0f/correctedFrameTimeAvg;
|
correctedFrameTimeAvg = correctedFrameTimeAvg * 0.95 + correctedFrameTime * 0.05;
|
||||||
engine->SetFps(fps);
|
engine->SetFps(1000.0 / correctedFrameTimeAvg);
|
||||||
frameStart = SDL_GetTicks();
|
if(frameStart - lastTick > 1000)
|
||||||
|
|
||||||
if(frameStart-lastTick>250)
|
|
||||||
{
|
{
|
||||||
//Run client tick every second
|
//Run client tick every second
|
||||||
lastTick = frameStart;
|
lastTick = frameStart;
|
||||||
|
Reference in New Issue
Block a user