diff --git a/src/debugfps.cpp b/src/debugfps.cpp index b963a8bd..1e89a1f8 100644 --- a/src/debugfps.cpp +++ b/src/debugfps.cpp @@ -43,36 +43,36 @@ Entity::Group DebugFps::GetGroup() return GROUP_AFTER; } -void DebugFps::TickRender(float delta_time) +void DebugFps::TickRender(float deltams) { - Entity::TickRender(delta_time); + Entity::TickRender(deltams); data->frame++; char buf[1024]; sprintf(buf, "%2.2f fps (%i)", - 1.0f / Profiler::GetMean(Profiler::STAT_TICK_FRAME), data->frame); + 1e3f / Profiler::GetMean(Profiler::STAT_TICK_FRAME), data->frame); data->font->PrintBold(10, 10, buf); sprintf(buf, "Game % 7.2f % 7.2f", - 1e3f * Profiler::GetMean(Profiler::STAT_TICK_GAME), - 1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME)); + Profiler::GetMean(Profiler::STAT_TICK_GAME), + Profiler::GetMax(Profiler::STAT_TICK_GAME)); data->font->PrintBold(10, 34, buf); sprintf(buf, "Render % 7.2f % 7.2f", - 1e3f * Profiler::GetMean(Profiler::STAT_TICK_RENDER), - 1e3f * Profiler::GetMax(Profiler::STAT_TICK_RENDER)); + Profiler::GetMean(Profiler::STAT_TICK_RENDER), + Profiler::GetMax(Profiler::STAT_TICK_RENDER)); data->font->PrintBold(10, 50, buf); sprintf(buf, "Blit % 7.2f % 7.2f", - 1e3f * Profiler::GetMean(Profiler::STAT_TICK_BLIT), - 1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT)); + Profiler::GetMean(Profiler::STAT_TICK_BLIT), + Profiler::GetMax(Profiler::STAT_TICK_BLIT)); data->font->PrintBold(10, 66, buf); sprintf(buf, "Frame % 7.2f % 7.2f", - 1e3f * Profiler::GetMean(Profiler::STAT_TICK_FRAME), - 1e3f * Profiler::GetMax(Profiler::STAT_TICK_FRAME)); + Profiler::GetMean(Profiler::STAT_TICK_FRAME), + Profiler::GetMax(Profiler::STAT_TICK_FRAME)); data->font->PrintBold(10, 82, buf); } diff --git a/src/debugfps.h b/src/debugfps.h index dfb50555..5cd533c6 100644 --- a/src/debugfps.h +++ b/src/debugfps.h @@ -23,7 +23,7 @@ public: protected: virtual Group GetGroup(); - virtual void TickRender(float delta_time); + virtual void TickRender(float deltams); private: DebugFpsData *data; diff --git a/src/debugrecord.cpp b/src/debugrecord.cpp index fa33ace1..84b4f669 100644 --- a/src/debugrecord.cpp +++ b/src/debugrecord.cpp @@ -47,14 +47,14 @@ Entity::Group DebugRecord::GetGroup() return GROUP_RENDER_CAPTURE; } -void DebugRecord::TickGame(float delta_time) +void DebugRecord::TickGame(float deltams) { - Entity::TickGame(delta_time); + Entity::TickGame(deltams); } -void DebugRecord::TickRender(float delta_time) +void DebugRecord::TickRender(float deltams) { - Entity::TickRender(delta_time); + Entity::TickRender(deltams); int width = Video::GetWidth(); int height = Video::GetHeight(); diff --git a/src/debugrecord.h b/src/debugrecord.h index 7ebd09f5..248d21f2 100644 --- a/src/debugrecord.h +++ b/src/debugrecord.h @@ -23,8 +23,8 @@ public: protected: virtual Group GetGroup(); - virtual void TickGame(float delta_time); - virtual void TickRender(float delta_time); + virtual void TickGame(float deltams); + virtual void TickRender(float deltams); private: DebugRecordData *data; diff --git a/src/debugsprite.cpp b/src/debugsprite.cpp index f60bc96b..9e6fae6c 100644 --- a/src/debugsprite.cpp +++ b/src/debugsprite.cpp @@ -43,14 +43,14 @@ Entity::Group DebugSprite::GetGroup() return GROUP_DEFAULT; } -void DebugSprite::TickGame(float delta_time) +void DebugSprite::TickGame(float deltams) { - Entity::TickGame(delta_time); + Entity::TickGame(deltams); } -void DebugSprite::TickRender(float delta_time) +void DebugSprite::TickRender(float deltams) { - Entity::TickRender(delta_time); + Entity::TickRender(deltams); data->game->GetScene()->AddTile((data->tiler << 16) | 15, 320, 240, 32, 1); data->game->GetScene()->AddTile((data->tiler << 16) | 31, 320, 240, 0, 1); diff --git a/src/debugsprite.h b/src/debugsprite.h index c5787299..73f6bdcb 100644 --- a/src/debugsprite.h +++ b/src/debugsprite.h @@ -24,8 +24,8 @@ public: protected: virtual Group GetGroup(); - virtual void TickGame(float delta_time); - virtual void TickRender(float delta_time); + virtual void TickGame(float deltams); + virtual void TickRender(float deltams); private: DebugSpriteData *data; diff --git a/src/entity.cpp b/src/entity.cpp index f72a5feb..11cd3136 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -41,7 +41,7 @@ Entity::Group Entity::GetGroup() return GROUP_DEFAULT; } -void Entity::TickGame(float delta_time) +void Entity::TickGame(float deltams) { #if !FINAL_RELEASE if (state != STATE_PRETICK_GAME) @@ -50,7 +50,7 @@ void Entity::TickGame(float delta_time) #endif } -void Entity::TickRender(float delta_time) +void Entity::TickRender(float deltams) { #if !FINAL_RELEASE if (state != STATE_PRETICK_RENDER) diff --git a/src/entity.h b/src/entity.h index f85db501..d943e0dd 100644 --- a/src/entity.h +++ b/src/entity.h @@ -42,8 +42,8 @@ protected: virtual Group GetGroup(); - virtual void TickGame(float delta_time); - virtual void TickRender(float delta_time); + virtual void TickGame(float deltams); + virtual void TickRender(float deltams); Entity *next; int ref, destroy; diff --git a/src/font.cpp b/src/font.cpp index f7d342ec..a70f5b56 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -81,9 +81,9 @@ Entity::Group Font::GetGroup() return GROUP_BEFORE; } -void Font::TickRender(float delta_time) +void Font::TickRender(float deltams) { - Entity::TickRender(delta_time); + Entity::TickRender(deltams); } char const *Font::GetName() diff --git a/src/font.h b/src/font.h index 1c54c707..0ab5026a 100644 --- a/src/font.h +++ b/src/font.h @@ -24,7 +24,7 @@ public: protected: /* Inherited from Entity */ virtual Group GetGroup(); - virtual void TickRender(float delta_time); + virtual void TickRender(float deltams); public: /* New methods */ diff --git a/src/game.cpp b/src/game.cpp index 4ec84218..988aca50 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -53,14 +53,14 @@ Entity::Group Game::GetGroup() return Entity::GetGroup(); } -void Game::TickGame(float delta_time) +void Game::TickGame(float deltams) { - Entity::TickGame(delta_time); + Entity::TickGame(deltams); } -void Game::TickRender(float delta_time) +void Game::TickRender(float deltams) { - Entity::TickRender(delta_time); + Entity::TickRender(deltams); GetScene(); diff --git a/src/game.h b/src/game.h index c2ea0d9f..f5f6b842 100644 --- a/src/game.h +++ b/src/game.h @@ -25,8 +25,8 @@ public: protected: /* Inherited from Entity */ virtual Group GetGroup(); - virtual void TickGame(float delta_time); - virtual void TickRender(float delta_time); + virtual void TickGame(float deltams); + virtual void TickRender(float deltams); public: /* New methods */ diff --git a/src/gtk/editor.cpp b/src/gtk/editor.cpp index 6e748f2c..72946ae4 100644 --- a/src/gtk/editor.cpp +++ b/src/gtk/editor.cpp @@ -84,7 +84,7 @@ static gint draw(GtkWidget *widget, GdkEventExpose *event) gtk_gl_area_swapbuffers(GTK_GL_AREA(widget)); while (g_main_context_iteration(NULL, FALSE)) ; - Ticker::ClampFps(1.0f / FPS); + Ticker::ClampFps(1000.0f / FPS); } return TRUE; diff --git a/src/profiler.cpp b/src/profiler.cpp index b6a7402f..bdaddeff 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -47,14 +47,14 @@ data[Profiler::STAT_COUNT]; void Profiler::Start(int id) { - data[id].timer.GetSeconds(); + data[id].timer.GetMs(); } void Profiler::Stop(int id) { - float delta_time = data[id].timer.GetSeconds(); + float deltams = data[id].timer.GetMs(); - data[id].history[data->frame % ProfilerData::HISTORY] = delta_time; + data[id].history[data->frame % ProfilerData::HISTORY] = deltams; data[id].frame++; data[id].mean = 0.0f; data[id].max = 0.0f; diff --git a/src/sdlinput.cpp b/src/sdlinput.cpp index 23396ba7..67bf9478 100644 --- a/src/sdlinput.cpp +++ b/src/sdlinput.cpp @@ -40,9 +40,9 @@ Entity::Group SdlInput::GetGroup() return GROUP_BEFORE; } -void SdlInput::TickGame(float delta_time) +void SdlInput::TickGame(float deltams) { - Entity::TickGame(delta_time); + Entity::TickGame(deltams); if (data->game->Finished()) destroy = 1; diff --git a/src/sdlinput.h b/src/sdlinput.h index e1224fb4..7ed9ff5f 100644 --- a/src/sdlinput.h +++ b/src/sdlinput.h @@ -24,7 +24,7 @@ public: protected: virtual Group GetGroup(); - virtual void TickGame(float delta_time); + virtual void TickGame(float deltams); private: SdlInputData *data; diff --git a/src/test-map.cpp b/src/test-map.cpp index 56d30d78..3e936d01 100644 --- a/src/test-map.cpp +++ b/src/test-map.cpp @@ -66,7 +66,7 @@ int main(int argc, char **argv) Video::Clear(); Ticker::TickRender(); SDL_GL_SwapBuffers(); - Ticker::ClampFps(1.0f / FPS); + Ticker::ClampFps(1000.0f / FPS); } SDL_Quit(); diff --git a/src/ticker.cpp b/src/ticker.cpp index aa453088..71d017e9 100644 --- a/src/ticker.cpp +++ b/src/ticker.cpp @@ -50,7 +50,7 @@ private: /* Fixed framerate management */ Timer timer; - float delta_time, bias; + float deltams, bias; } tickerdata; @@ -76,8 +76,8 @@ void Ticker::TickGame() Profiler::Start(Profiler::STAT_TICK_GAME); - data->delta_time = data->timer.GetSeconds(); - data->bias += data->delta_time; + data->deltams = data->timer.GetMs(); + data->bias += data->deltams; /* Garbage collect objects that can be destroyed. We can do this * before inserting awaiting objects, because there is no way these @@ -117,7 +117,7 @@ void Ticker::TickGame() fprintf(stderr, "ERROR: entity not idle for game tick\n"); a->state = Entity::STATE_PRETICK_GAME; #endif - a->TickGame(data->delta_time); + a->TickGame(data->deltams); #if !FINAL_RELEASE if (a->state != Entity::STATE_POSTTICK_GAME) fprintf(stderr, "ERROR: entity missed super game tick\n"); @@ -142,7 +142,7 @@ void Ticker::TickRender() fprintf(stderr, "ERROR: entity not idle for render tick\n"); a->state = Entity::STATE_PRETICK_RENDER; #endif - a->TickRender(data->delta_time); + a->TickRender(data->deltams); #if !FINAL_RELEASE if (a->state != Entity::STATE_POSTTICK_RENDER) fprintf(stderr, "ERROR: entity missed super render tick\n"); @@ -154,14 +154,14 @@ void Ticker::TickRender() Profiler::Start(Profiler::STAT_TICK_BLIT); } -void Ticker::ClampFps(float delta_time) +void Ticker::ClampFps(float deltams) { Profiler::Stop(Profiler::STAT_TICK_BLIT); - if (delta_time > data->bias + 0.2f) - delta_time = data->bias + 0.2f; // Don't go below 5 fps - if (delta_time > data->bias) - data->timer.WaitSeconds(delta_time - data->bias); - data->bias -= delta_time; + if (deltams > data->bias + 200.0f) + deltams = data->bias + 200.0f; // Don't go below 5 fps + if (deltams > data->bias) + data->timer.WaitMs(deltams - data->bias); + data->bias -= deltams; } diff --git a/src/ticker.h b/src/ticker.h index 84acf597..ffb4ba1b 100644 --- a/src/ticker.h +++ b/src/ticker.h @@ -23,7 +23,7 @@ public: static void TickGame(); static void TickRender(); - static void ClampFps(float delta_time); + static void ClampFps(float deltams); }; #endif // __DH_TICKER_H__ diff --git a/src/tileset.cpp b/src/tileset.cpp index 1efc707b..70acd9d8 100644 --- a/src/tileset.cpp +++ b/src/tileset.cpp @@ -79,9 +79,9 @@ Entity::Group TileSet::GetGroup() return GROUP_BEFORE; } -void TileSet::TickRender(float delta_time) +void TileSet::TickRender(float deltams) { - Entity::TickRender(delta_time); + Entity::TickRender(deltams); if (data->img) { diff --git a/src/tileset.h b/src/tileset.h index b47fecb4..91888eaf 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -29,7 +29,7 @@ public: protected: /* Inherited from Entity */ virtual Group GetGroup(); - virtual void TickRender(float delta_time); + virtual void TickRender(float deltams); public: /* New methods */ diff --git a/src/timer.cpp b/src/timer.cpp index 017e5b48..8ebb51cc 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -40,7 +40,7 @@ private: #elif defined _WIN32 LARGE_INTEGER tmp; QueryPerformanceFrequency(&tmp); - seconds_per_cycle = 1.0f / tmp.QuadPart; + ms_per_cycle = 1e3f / tmp.QuadPart; QueryPerformanceCounter(&cycles0); #else SDL_Init(SDL_INIT_TIMER); @@ -48,36 +48,37 @@ private: #endif } - float GetOrWait(float seconds, bool update) + float GetOrWait(float deltams, bool update) { - float ret, delta_time; + float ret, towait; #if defined __linux__ struct timeval tv; gettimeofday(&tv, NULL); - ret = 1e-6f * (tv.tv_usec - tv0.tv_usec) + (tv.tv_sec - tv0.tv_sec); + ret = 1e-3f * (tv.tv_usec - tv0.tv_usec) + + 1e3f * (tv.tv_sec - tv0.tv_sec); if (update) tv0 = tv; - delta_time = seconds - ret; - if (delta_time > 0.0f) - usleep((int)(delta_time * 1e6f)); + towait = deltams - ret; + if (towait > 0.0f) + usleep((int)(towait * 1e3f)); #elif defined _WIN32 LARGE_INTEGER cycles; QueryPerformanceCounter(&cycles); - ret = seconds_per_cycle * (cycles.QuadPart - cycles0.QuadPart); + ret = ms_per_cycle * (cycles.QuadPart - cycles0.QuadPart); if (update) cycles0 = cycles; - delta_time = seconds - ret; - if (delta_time > 5e-4f) // FIXME: use native Win32 stuff - SDL_Delay((int)(delta_time * 1e3f + 0.5f)); + towait = deltams - ret; + if (towait > 5e-4f) // FIXME: use native Win32 stuff + SDL_Delay((int)(towait * 1e3f + 0.5f)); #else /* The crappy SDL fallback */ Uint32 ticks = SDL_GetTicks(); - ret = 1e-3f * (ticks - ticks0); + ret = 1e-6f * (ticks - ticks0); if (update) ticks0 = ticks; - delta_time = seconds - ret; - if (delta_time > 5e-4f) - SDL_Delay((int)(delta_time * 1e3f + 0.5f)); + towait = deltams - ret; + if (towait > 0.5f) + SDL_Delay((int)(towait + 0.5f)); #endif return ret; } @@ -85,7 +86,7 @@ private: #if defined __linux__ struct timeval tv0; #elif defined _WIN32 - float seconds_per_cycle; + float ms_per_cycle; LARGE_INTEGER cycles0; #else Uint32 ticks0; @@ -106,18 +107,18 @@ Timer::~Timer() delete data; } -float Timer::GetSeconds() +float Timer::GetMs() { return data->GetOrWait(0.0f, true); } -float Timer::PollSeconds() +float Timer::PollMs() { return data->GetOrWait(0.0f, false); } -void Timer::WaitSeconds(float seconds) +void Timer::WaitMs(float deltams) { - (void)data->GetOrWait(seconds, false); + (void)data->GetOrWait(deltams, false); } diff --git a/src/timer.h b/src/timer.h index 1db74ebd..6fa730ef 100644 --- a/src/timer.h +++ b/src/timer.h @@ -19,9 +19,9 @@ public: Timer(); ~Timer(); - float GetSeconds(); - float PollSeconds(); - void WaitSeconds(float milliseconds); + float GetMs(); + float PollMs(); + void WaitMs(float deltams); private: TimerData *data;