Browse Source

Add a benchmark mode to the ticker.

legacy
Sam Hocevar sam 14 years ago
parent
commit
016a5ec38b
2 changed files with 36 additions and 10 deletions
  1. +34
    -10
      src/ticker.cpp
  2. +2
    -0
      src/ticker.h

+ 34
- 10
src/ticker.cpp View File

@@ -30,7 +30,7 @@ public:
TickerData() : TickerData() :
todolist(0), autolist(0), todolist(0), autolist(0),
nentities(0), nentities(0),
frame(0), deltams(0), bias(0), fps(0),
frame(0), benchmark(0), deltams(0), bias(0), fps(0),
quit(0), quitframe(0), quitdelay(20), panic(0) quit(0), quitframe(0), quitdelay(20), panic(0)
{ {
for (int i = 0; i < Entity::ALLGROUP_END; i++) for (int i = 0; i < Entity::ALLGROUP_END; i++)
@@ -61,7 +61,7 @@ private:
int nentities; int nentities;


/* Fixed framerate management */ /* Fixed framerate management */
int frame;
int frame, benchmark;
Timer timer; Timer timer;
float deltams, bias, fps; float deltams, bias, fps;


@@ -168,8 +168,15 @@ void Ticker::TickGame()


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


data->deltams = data->timer.GetMs();
data->bias += data->deltams;
if (data->benchmark && data->fps)
{
data->deltams = 1000.0f / data->fps;
}
else
{
data->deltams = data->timer.GetMs();
data->bias += data->deltams;
}


/* If shutdown is stuck, kick the first entity we meet and see /* If shutdown is stuck, kick the first entity we meet and see
* whether it makes things better. Note that it is always a bug to * whether it makes things better. Note that it is always a bug to
@@ -317,13 +324,30 @@ void Ticker::ClampFps()
{ {
Profiler::Stop(Profiler::STAT_TICK_BLIT); Profiler::Stop(Profiler::STAT_TICK_BLIT);


float deltams = data->fps ? 1000.0f / data->fps : 0.0f;
if (data->benchmark)
{
data->bias = 0.0f;
}
else
{
float deltams = data->fps ? 1000.0f / data->fps : 0.0f;

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

void Ticker::StartBenchmark()
{
data->benchmark++;
}


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;
void Ticker::StopBenchmark()
{
data->benchmark--;
} }


int Ticker::GetFrameNum() int Ticker::GetFrameNum()


+ 2
- 0
src/ticker.h View File

@@ -32,6 +32,8 @@ public:
static void TickGame(); static void TickGame();
static void TickDraw(); static void TickDraw();
static void ClampFps(); static void ClampFps();
static void StartBenchmark();
static void StopBenchmark();
static int GetFrameNum(); static int GetFrameNum();


static void Shutdown(); static void Shutdown();


Loading…
Cancel
Save