From 57a0cb51026f6a35be0976f26af2e216dd3b6cfc Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 22 Aug 2010 00:55:40 +0000 Subject: [PATCH] Refactor stuff. --- src/debugfps.cpp | 24 +++++++++--------- src/debugfps.h | 2 +- src/debugrecord.cpp | 6 ++--- src/debugrecord.h | 2 +- src/debugsprite.cpp | 10 +++++--- src/debugsprite.h | 2 +- src/entity.cpp | 10 ++++---- src/entity.h | 8 +++--- src/font.cpp | 4 +-- src/font.h | 2 +- src/game.cpp | 4 +-- src/game.h | 2 +- src/gtk/editor.cpp | 2 +- src/profiler.cpp | 14 +++++------ src/profiler.h | 4 +-- src/test-map.cpp | 2 +- src/ticker.cpp | 60 ++++++++++++++++++++++----------------------- src/ticker.h | 2 +- src/tileset.cpp | 4 +-- src/tileset.h | 2 +- 20 files changed, 84 insertions(+), 82 deletions(-) diff --git a/src/debugfps.cpp b/src/debugfps.cpp index fd0c9d46..a09c87fc 100644 --- a/src/debugfps.cpp +++ b/src/debugfps.cpp @@ -42,9 +42,9 @@ Entity::Group DebugFps::GetGroup() return GROUP_AFTER; } -void DebugFps::TickRender(float deltams) +void DebugFps::TickDraw(float deltams) { - Entity::TickRender(deltams); + Entity::TickDraw(deltams); data->frame++; @@ -52,26 +52,26 @@ void DebugFps::TickRender(float deltams) Font *font = Forge::GetFont(data->fontid); sprintf(buf, "%2.2f fps (%i)", - 1e3f / Profiler::GetMean(Profiler::STAT_TICK_FRAME), data->frame); + 1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), data->frame); font->PrintBold(10, 10, buf); - sprintf(buf, "Game % 7.2f % 7.2f", - Profiler::GetMean(Profiler::STAT_TICK_GAME), + sprintf(buf, "Game % 7.2f % 7.2f", + Profiler::GetAvg(Profiler::STAT_TICK_GAME), Profiler::GetMax(Profiler::STAT_TICK_GAME)); font->PrintBold(10, 34, buf); - sprintf(buf, "Render % 7.2f % 7.2f", - Profiler::GetMean(Profiler::STAT_TICK_RENDER), - Profiler::GetMax(Profiler::STAT_TICK_RENDER)); + sprintf(buf, "Draw % 7.2f % 7.2f", + Profiler::GetAvg(Profiler::STAT_TICK_DRAW), + Profiler::GetMax(Profiler::STAT_TICK_DRAW)); font->PrintBold(10, 50, buf); - sprintf(buf, "Blit % 7.2f % 7.2f", - Profiler::GetMean(Profiler::STAT_TICK_BLIT), + sprintf(buf, "Blit % 7.2f % 7.2f", + Profiler::GetAvg(Profiler::STAT_TICK_BLIT), Profiler::GetMax(Profiler::STAT_TICK_BLIT)); font->PrintBold(10, 66, buf); - sprintf(buf, "Frame % 7.2f % 7.2f", - Profiler::GetMean(Profiler::STAT_TICK_FRAME), + sprintf(buf, "Frame % 7.2f % 7.2f", + Profiler::GetAvg(Profiler::STAT_TICK_FRAME), Profiler::GetMax(Profiler::STAT_TICK_FRAME)); font->PrintBold(10, 82, buf); } diff --git a/src/debugfps.h b/src/debugfps.h index 5cd533c6..6bea0105 100644 --- a/src/debugfps.h +++ b/src/debugfps.h @@ -23,7 +23,7 @@ public: protected: virtual Group GetGroup(); - virtual void TickRender(float deltams); + virtual void TickDraw(float deltams); private: DebugFpsData *data; diff --git a/src/debugrecord.cpp b/src/debugrecord.cpp index 22ebc039..32a40299 100644 --- a/src/debugrecord.cpp +++ b/src/debugrecord.cpp @@ -44,7 +44,7 @@ DebugRecord::DebugRecord(char const *path) Entity::Group DebugRecord::GetGroup() { - return GROUP_RENDER_CAPTURE; + return GROUP_DRAW_CAPTURE; } void DebugRecord::TickGame(float deltams) @@ -52,9 +52,9 @@ void DebugRecord::TickGame(float deltams) Entity::TickGame(deltams); } -void DebugRecord::TickRender(float deltams) +void DebugRecord::TickDraw(float deltams) { - Entity::TickRender(deltams); + Entity::TickDraw(deltams); int width = Video::GetWidth(); int height = Video::GetHeight(); diff --git a/src/debugrecord.h b/src/debugrecord.h index 248d21f2..8d22ae94 100644 --- a/src/debugrecord.h +++ b/src/debugrecord.h @@ -24,7 +24,7 @@ public: protected: virtual Group GetGroup(); virtual void TickGame(float deltams); - virtual void TickRender(float deltams); + virtual void TickDraw(float deltams); private: DebugRecordData *data; diff --git a/src/debugsprite.cpp b/src/debugsprite.cpp index fe094853..a687bde2 100644 --- a/src/debugsprite.cpp +++ b/src/debugsprite.cpp @@ -55,16 +55,18 @@ void DebugSprite::TickGame(float deltams) data->y += 0.1f * deltams * axis.y; } -void DebugSprite::TickRender(float deltams) +void DebugSprite::TickDraw(float deltams) { - Entity::TickRender(deltams); + Entity::TickDraw(deltams); int x = data->x; int y = data->y; int z = data->z; - data->game->GetScene()->AddTile((data->tiler << 16) | 15, x, y, z + 32, 1); - data->game->GetScene()->AddTile((data->tiler << 16) | 31, x, y, z, 1); + data->game->GetScene()->AddTile((data->tiler << 16) | 15, + x - 16, y - 32, z + 32, 1); + data->game->GetScene()->AddTile((data->tiler << 16) | 31, + x - 16, y - 32, z, 1); } DebugSprite::~DebugSprite() diff --git a/src/debugsprite.h b/src/debugsprite.h index 73f6bdcb..486ac118 100644 --- a/src/debugsprite.h +++ b/src/debugsprite.h @@ -25,7 +25,7 @@ public: protected: virtual Group GetGroup(); virtual void TickGame(float deltams); - virtual void TickRender(float deltams); + virtual void TickDraw(float deltams); private: DebugSpriteData *data; diff --git a/src/entity.cpp b/src/entity.cpp index 63d9e077..ac1c65e4 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -37,7 +37,7 @@ Entity::~Entity() char const *Entity::GetName() { - return "Generic entity"; + return ""; } Entity::Group Entity::GetGroup() @@ -54,12 +54,12 @@ void Entity::TickGame(float deltams) #endif } -void Entity::TickRender(float deltams) +void Entity::TickDraw(float deltams) { #if !FINAL_RELEASE - if (state != STATE_PRETICK_RENDER) - fprintf(stderr, "ERROR: invalid entity render tick\n"); - state = STATE_POSTTICK_RENDER; + if (state != STATE_PRETICK_DRAW) + fprintf(stderr, "ERROR: invalid entity draw tick\n"); + state = STATE_POSTTICK_DRAW; #endif } diff --git a/src/entity.h b/src/entity.h index 2ac7bea8..989b0cd8 100644 --- a/src/entity.h +++ b/src/entity.h @@ -32,7 +32,7 @@ protected: GROUP_BEFORE = 0, GROUP_DEFAULT, GROUP_AFTER, - GROUP_RENDER_CAPTURE, + GROUP_DRAW_CAPTURE, // Must be the last element GROUP_COUNT } @@ -45,7 +45,7 @@ protected: virtual Group GetGroup(); virtual void TickGame(float deltams); - virtual void TickRender(float deltams); + virtual void TickDraw(float deltams); Entity *next; int ref, destroy; @@ -56,8 +56,8 @@ protected: STATE_IDLE = 0, STATE_PRETICK_GAME, STATE_POSTTICK_GAME, - STATE_PRETICK_RENDER, - STATE_POSTTICK_RENDER, + STATE_PRETICK_DRAW, + STATE_POSTTICK_DRAW, } state; #endif diff --git a/src/font.cpp b/src/font.cpp index 7734683a..731c7760 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -81,9 +81,9 @@ Entity::Group Font::GetGroup() return GROUP_BEFORE; } -void Font::TickRender(float deltams) +void Font::TickDraw(float deltams) { - Entity::TickRender(deltams); + Entity::TickDraw(deltams); } char const *Font::GetName() diff --git a/src/font.h b/src/font.h index b5c3a214..97ef6d73 100644 --- a/src/font.h +++ b/src/font.h @@ -25,7 +25,7 @@ protected: /* Inherited from Entity */ virtual char const *GetName(); virtual Group GetGroup(); - virtual void TickRender(float deltams); + virtual void TickDraw(float deltams); public: /* New methods */ diff --git a/src/game.cpp b/src/game.cpp index 6f53c117..cb20b60e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -57,9 +57,9 @@ void Game::TickGame(float deltams) Entity::TickGame(deltams); } -void Game::TickRender(float deltams) +void Game::TickDraw(float deltams) { - Entity::TickRender(deltams); + Entity::TickDraw(deltams); GetScene(); diff --git a/src/game.h b/src/game.h index f5f6b842..228b8244 100644 --- a/src/game.h +++ b/src/game.h @@ -26,7 +26,7 @@ protected: /* Inherited from Entity */ virtual Group GetGroup(); virtual void TickGame(float deltams); - virtual void TickRender(float deltams); + virtual void TickDraw(float deltams); public: /* New methods */ diff --git a/src/gtk/editor.cpp b/src/gtk/editor.cpp index 5c16d07a..9f4fb1b7 100644 --- a/src/gtk/editor.cpp +++ b/src/gtk/editor.cpp @@ -78,7 +78,7 @@ static gint draw(GtkWidget *widget, GdkEventExpose *event) /* Clear the screen, tick the renderer, show the frame and * clamp to desired framerate. */ Video::Clear(); - Ticker::TickRender(); + Ticker::TickDraw(); gtk_gl_area_swapbuffers(GTK_GL_AREA(widget)); while (g_main_context_iteration(NULL, FALSE)) ; diff --git a/src/profiler.cpp b/src/profiler.cpp index 8f8ebc92..12693fa7 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -29,14 +29,14 @@ public: for (int i = 0; i < HISTORY; i++) history[i] = 0.0f; frame = 0; - mean = max = 0.0f; + avg = max = 0.0f; } private: float history[HISTORY]; Timer timer; int frame; - float mean, max; + float avg, max; } data[Profiler::STAT_COUNT]; @@ -55,21 +55,21 @@ void Profiler::Stop(int id) data[id].history[data->frame % ProfilerData::HISTORY] = deltams; data[id].frame++; - data[id].mean = 0.0f; + data[id].avg = 0.0f; data[id].max = 0.0f; for (int i = 0; i < ProfilerData::HISTORY; i++) { - data[id].mean += data[id].history[i]; + data[id].avg += data[id].history[i]; if (data[id].history[i] > data[id].max) data[id].max = data[id].history[i]; } - data[id].mean /= ProfilerData::HISTORY; + data[id].avg /= ProfilerData::HISTORY; } -float Profiler::GetMean(int id) +float Profiler::GetAvg(int id) { - return data[id].mean; + return data[id].avg; } float Profiler::GetMax(int id) diff --git a/src/profiler.h b/src/profiler.h index 2db62a55..abdc3547 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -21,14 +21,14 @@ public: { STAT_TICK_FRAME = 0, STAT_TICK_GAME, - STAT_TICK_RENDER, + STAT_TICK_DRAW, STAT_TICK_BLIT, STAT_COUNT }; static void Start(int id); static void Stop(int id); - static float GetMean(int id); + static float GetAvg(int id); static float GetMax(int id); }; diff --git a/src/test-map.cpp b/src/test-map.cpp index b0aecd5b..91ba2e98 100644 --- a/src/test-map.cpp +++ b/src/test-map.cpp @@ -61,7 +61,7 @@ int main(int argc, char **argv) /* Clear the screen, tick the renderer, show the frame and * clamp to desired framerate. */ Video::Clear(); - Ticker::TickRender(); + Ticker::TickDraw(); SDL_GL_SwapBuffers(); Ticker::ClampFps(1000.0f / FPS); } diff --git a/src/ticker.cpp b/src/ticker.cpp index 8d976d92..a5c0a15d 100644 --- a/src/ticker.cpp +++ b/src/ticker.cpp @@ -80,74 +80,74 @@ void Ticker::TickGame() * before inserting awaiting objects, because there is no way these * are already marked for destruction. */ for (int i = 0; i < Entity::GROUP_COUNT; i++) - for (Entity *a = data->list[i], *prev = NULL; a; prev = a, a = a->next) - if (a->destroy) + for (Entity *e = data->list[i], *prev = NULL; e; prev = e, e = e->next) + if (e->destroy) { if (prev) - prev->next = a->next; + prev->next = e->next; else - data->list[i] = a->next; + data->list[i] = e->next; data->nentities--; - delete a; + delete e; } /* Insert waiting objects into the appropriate lists */ while (data->todo) { - Entity *a = data->todo; - data->todo = a->next; + Entity *e = data->todo; + data->todo = e->next; - int i = a->GetGroup(); - a->next = data->list[i]; - data->list[i] = a; + int i = e->GetGroup(); + e->next = data->list[i]; + data->list[i] = e; data->nentities++; } /* Tick objects for the game loop */ for (int i = 0; i < Entity::GROUP_COUNT; i++) - for (Entity *a = data->list[i]; a; a = a->next) - if (!a->destroy) + for (Entity *e = data->list[i]; e; e = e->next) + if (!e->destroy) { #if !FINAL_RELEASE - if (a->state != Entity::STATE_IDLE) + if (e->state != Entity::STATE_IDLE) fprintf(stderr, "ERROR: entity not idle for game tick\n"); - a->state = Entity::STATE_PRETICK_GAME; + e->state = Entity::STATE_PRETICK_GAME; #endif - a->TickGame(data->deltams); + e->TickGame(data->deltams); #if !FINAL_RELEASE - if (a->state != Entity::STATE_POSTTICK_GAME) + if (e->state != Entity::STATE_POSTTICK_GAME) fprintf(stderr, "ERROR: entity missed super game tick\n"); - a->state = Entity::STATE_IDLE; + e->state = Entity::STATE_IDLE; #endif } Profiler::Stop(Profiler::STAT_TICK_GAME); } -void Ticker::TickRender() +void Ticker::TickDraw() { - Profiler::Start(Profiler::STAT_TICK_RENDER); + Profiler::Start(Profiler::STAT_TICK_DRAW); - /* Tick objects for the render loop */ + /* Tick objects for the draw loop */ for (int i = 0; i < Entity::GROUP_COUNT; i++) - for (Entity *a = data->list[i]; a; a = a->next) - if (!a->destroy) + for (Entity *e = data->list[i]; e; e = e->next) + if (!e->destroy) { #if !FINAL_RELEASE - if (a->state != Entity::STATE_IDLE) - fprintf(stderr, "ERROR: entity not idle for render tick\n"); - a->state = Entity::STATE_PRETICK_RENDER; + if (e->state != Entity::STATE_IDLE) + fprintf(stderr, "ERROR: entity not idle for draw tick\n"); + e->state = Entity::STATE_PRETICK_DRAW; #endif - a->TickRender(data->deltams); + e->TickDraw(data->deltams); #if !FINAL_RELEASE - if (a->state != Entity::STATE_POSTTICK_RENDER) - fprintf(stderr, "ERROR: entity missed super render tick\n"); - a->state = Entity::STATE_IDLE; + if (e->state != Entity::STATE_POSTTICK_DRAW) + fprintf(stderr, "ERROR: entity missed super draw tick\n"); + e->state = Entity::STATE_IDLE; #endif } - Profiler::Stop(Profiler::STAT_TICK_RENDER); + Profiler::Stop(Profiler::STAT_TICK_DRAW); Profiler::Start(Profiler::STAT_TICK_BLIT); } diff --git a/src/ticker.h b/src/ticker.h index ffb4ba1b..d2a42fc6 100644 --- a/src/ticker.h +++ b/src/ticker.h @@ -22,7 +22,7 @@ public: static void Register(Entity *entity); static void TickGame(); - static void TickRender(); + static void TickDraw(); static void ClampFps(float deltams); }; diff --git a/src/tileset.cpp b/src/tileset.cpp index 290de810..3c80efc3 100644 --- a/src/tileset.cpp +++ b/src/tileset.cpp @@ -79,9 +79,9 @@ Entity::Group TileSet::GetGroup() return GROUP_BEFORE; } -void TileSet::TickRender(float deltams) +void TileSet::TickDraw(float deltams) { - Entity::TickRender(deltams); + Entity::TickDraw(deltams); if (data->img) { diff --git a/src/tileset.h b/src/tileset.h index 791140a3..128700d9 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -30,7 +30,7 @@ protected: /* Inherited from Entity */ virtual char const *GetName(); virtual Group GetGroup(); - virtual void TickRender(float deltams); + virtual void TickDraw(float deltams); public: /* New methods */