@@ -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); | |||
} | |||
@@ -23,7 +23,7 @@ public: | |||
protected: | |||
virtual Group GetGroup(); | |||
virtual void TickRender(float deltams); | |||
virtual void TickDraw(float deltams); | |||
private: | |||
DebugFpsData *data; | |||
@@ -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(); | |||
@@ -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; | |||
@@ -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() | |||
@@ -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; | |||
@@ -37,7 +37,7 @@ Entity::~Entity() | |||
char const *Entity::GetName() | |||
{ | |||
return "Generic entity"; | |||
return "<entity>"; | |||
} | |||
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 | |||
} | |||
@@ -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 | |||
@@ -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() | |||
@@ -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 */ | |||
@@ -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(); | |||
@@ -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 */ | |||
@@ -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)) | |||
; | |||
@@ -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) | |||
@@ -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); | |||
}; | |||
@@ -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); | |||
} | |||
@@ -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); | |||
} | |||
@@ -22,7 +22,7 @@ public: | |||
static void Register(Entity *entity); | |||
static void TickGame(); | |||
static void TickRender(); | |||
static void TickDraw(); | |||
static void ClampFps(float deltams); | |||
}; | |||
@@ -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) | |||
{ | |||
@@ -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 */ | |||