瀏覽代碼

Try to detect assets not calling their super tick methods. Already spotted

one bug thanks to that.
legacy
Sam Hocevar sam 15 年之前
父節點
當前提交
14e45d0fd4
共有 4 個檔案被更改,包括 50 行新增3 行删除
  1. +13
    -2
      src/asset.cpp
  2. +12
    -0
      src/asset.h
  3. +1
    -1
      src/debugfps.cpp
  4. +24
    -0
      src/ticker.cpp

+ 13
- 2
src/asset.cpp 查看文件

@@ -22,6 +22,9 @@ Asset::Asset() :
ref(0), ref(0),
destroy(0) destroy(0)
{ {
#if !FINAL_RELEASE
state = STATE_IDLE;
#endif
Ticker::Register(this); Ticker::Register(this);
} }


@@ -40,12 +43,20 @@ Asset::Group Asset::GetGroup()


void Asset::TickGame(float delta_time) void Asset::TickGame(float delta_time)
{ {

#if !FINAL_RELEASE
if (state != STATE_PRETICK_GAME)
fprintf(stderr, "ERROR: invalid asset game tick\n");
state = STATE_POSTTICK_GAME;
#endif
} }


void Asset::TickRender(float delta_time) void Asset::TickRender(float delta_time)
{ {

#if !FINAL_RELEASE
if (state != STATE_PRETICK_RENDER)
fprintf(stderr, "ERROR: invalid asset render tick\n");
state = STATE_POSTTICK_RENDER;
#endif
} }


void Asset::Ref() void Asset::Ref()


+ 12
- 0
src/asset.h 查看文件

@@ -45,6 +45,18 @@ protected:


Asset *next; Asset *next;
int ref, destroy; int ref, destroy;

#if !FINAL_RELEASE
enum
{
STATE_IDLE = 0,
STATE_PRETICK_GAME,
STATE_POSTTICK_GAME,
STATE_PRETICK_RENDER,
STATE_POSTTICK_RENDER,
}
state;
#endif
}; };


#endif // __DH_ASSET_H__ #endif // __DH_ASSET_H__


+ 1
- 1
src/debugfps.cpp 查看文件

@@ -45,7 +45,7 @@ Asset::Group DebugFps::GetGroup()


void DebugFps::TickRender(float delta_time) void DebugFps::TickRender(float delta_time)
{ {
Asset::TickGame(delta_time);
Asset::TickRender(delta_time);


data->frame++; data->frame++;




+ 24
- 0
src/ticker.cpp 查看文件

@@ -111,7 +111,19 @@ void Ticker::TickGame()
for (int i = 0; i < Asset::GROUP_COUNT; i++) for (int i = 0; i < Asset::GROUP_COUNT; i++)
for (Asset *a = data->list[i]; a; a = a->next) for (Asset *a = data->list[i]; a; a = a->next)
if (!a->destroy) if (!a->destroy)
{
#if !FINAL_RELEASE
if (a->state != Asset::STATE_IDLE)
fprintf(stderr, "ERROR: asset not idle for game tick\n");
a->state = Asset::STATE_PRETICK_GAME;
#endif
a->TickGame(data->delta_time); a->TickGame(data->delta_time);
#if !FINAL_RELEASE
if (a->state != Asset::STATE_POSTTICK_GAME)
fprintf(stderr, "ERROR: asset missed super game tick\n");
a->state = Asset::STATE_IDLE;
#endif
}


Profiler::Stop(Profiler::STAT_TICK_GAME); Profiler::Stop(Profiler::STAT_TICK_GAME);
} }
@@ -124,7 +136,19 @@ void Ticker::TickRender()
for (int i = 0; i < Asset::GROUP_COUNT; i++) for (int i = 0; i < Asset::GROUP_COUNT; i++)
for (Asset *a = data->list[i]; a; a = a->next) for (Asset *a = data->list[i]; a; a = a->next)
if (!a->destroy) if (!a->destroy)
{
#if !FINAL_RELEASE
if (a->state != Asset::STATE_IDLE)
fprintf(stderr, "ERROR: asset not idle for render tick\n");
a->state = Asset::STATE_PRETICK_RENDER;
#endif
a->TickRender(data->delta_time); a->TickRender(data->delta_time);
#if !FINAL_RELEASE
if (a->state != Asset::STATE_POSTTICK_RENDER)
fprintf(stderr, "ERROR: asset missed super render tick\n");
a->state = Asset::STATE_IDLE;
#endif
}


Profiler::Stop(Profiler::STAT_TICK_RENDER); Profiler::Stop(Profiler::STAT_TICK_RENDER);
Profiler::Start(Profiler::STAT_TICK_BLIT); Profiler::Start(Profiler::STAT_TICK_BLIT);


Loading…
取消
儲存