ソースを参照

Get the timer to talk milliseconds instead of seconds.

legacy
Sam Hocevar sam 14年前
コミット
50e4f67254
23個のファイルの変更84行の追加83行の削除
  1. +11
    -11
      src/debugfps.cpp
  2. +1
    -1
      src/debugfps.h
  3. +4
    -4
      src/debugrecord.cpp
  4. +2
    -2
      src/debugrecord.h
  5. +4
    -4
      src/debugsprite.cpp
  6. +2
    -2
      src/debugsprite.h
  7. +2
    -2
      src/entity.cpp
  8. +2
    -2
      src/entity.h
  9. +2
    -2
      src/font.cpp
  10. +1
    -1
      src/font.h
  11. +4
    -4
      src/game.cpp
  12. +2
    -2
      src/game.h
  13. +1
    -1
      src/gtk/editor.cpp
  14. +3
    -3
      src/profiler.cpp
  15. +2
    -2
      src/sdlinput.cpp
  16. +1
    -1
      src/sdlinput.h
  17. +1
    -1
      src/test-map.cpp
  18. +11
    -11
      src/ticker.cpp
  19. +1
    -1
      src/ticker.h
  20. +2
    -2
      src/tileset.cpp
  21. +1
    -1
      src/tileset.h
  22. +21
    -20
      src/timer.cpp
  23. +3
    -3
      src/timer.h

+ 11
- 11
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);
}



+ 1
- 1
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;


+ 4
- 4
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();


+ 2
- 2
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;


+ 4
- 4
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);


+ 2
- 2
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;


+ 2
- 2
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)


+ 2
- 2
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;


+ 2
- 2
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()


+ 1
- 1
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 */


+ 4
- 4
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();



+ 2
- 2
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 */


+ 1
- 1
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;


+ 3
- 3
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;


+ 2
- 2
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;


+ 1
- 1
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;


+ 1
- 1
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();


+ 11
- 11
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;
}


+ 1
- 1
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__


+ 2
- 2
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)
{


+ 1
- 1
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 */


+ 21
- 20
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);
}


+ 3
- 3
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;


読み込み中…
キャンセル
保存