浏览代码

Add a recording mode to Ticker that ensures fixed deltatime even when

lagging behind.
legacy
Sam Hocevar sam 14 年前
父节点
当前提交
eec2eb7a9a
共有 3 个文件被更改,包括 31 次插入14 次删除
  1. +4
    -0
      src/debugrecord.cpp
  2. +25
    -14
      src/ticker.cpp
  3. +2
    -0
      src/ticker.h

+ 4
- 0
src/debugrecord.cpp 查看文件

@@ -45,6 +45,8 @@ private:
DebugRecord::DebugRecord(char const *path, float fps) DebugRecord::DebugRecord(char const *path, float fps)
: data(new DebugRecordData()) : data(new DebugRecordData())
{ {
Ticker::StartRecording();

data->path = strdup(path); data->path = strdup(path);
data->width = 0; data->width = 0;
data->height = 0; data->height = 0;
@@ -96,5 +98,7 @@ void DebugRecord::TickDraw(float deltams)


DebugRecord::~DebugRecord() DebugRecord::~DebugRecord()
{ {
Ticker::StopRecording();

delete data; delete data;
} }

+ 25
- 14
src/ticker.cpp 查看文件

@@ -30,7 +30,7 @@ public:
TickerData() : TickerData() :
todolist(0), autolist(0), todolist(0), autolist(0),
nentities(0), nentities(0),
frame(0), benchmark(0), deltams(0), bias(0), fps(0), frame(0), benchmark(0), recording(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, benchmark; int frame, benchmark, recording;
Timer timer; Timer timer;
float deltams, bias, fps; float deltams, bias, fps;


@@ -168,7 +168,7 @@ void Ticker::TickGame()


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


if (data->benchmark && data->fps) if (data->recording && data->fps)
{ {
data->deltams = 1000.0f / data->fps; data->deltams = 1000.0f / data->fps;
} }
@@ -324,20 +324,21 @@ void Ticker::ClampFps()
{ {
Profiler::Stop(Profiler::STAT_TICK_BLIT); Profiler::Stop(Profiler::STAT_TICK_BLIT);


if (data->benchmark) /* If benchmarking, set wait time to 0. If FPS are fixed, force wait
* time to 1/FPS. Otherwise, set wait time to 0. */
float framems = (!data->benchmark && data->fps) ? 1000.0f / data->fps
: 0.0f;

if (!data->benchmark)
{ {
data->bias = 0.0f; if (framems > data->bias + 200.0f)
framems = data->bias + 200.0f; // Don't go below 5 fps
if (framems > data->bias)
data->timer.WaitMs(framems - data->bias);
} }
else
{
float deltams = data->fps ? 1000.0f / data->fps : 0.0f;


if (deltams > data->bias + 200.0f) if (!data->recording)
deltams = data->bias + 200.0f; // Don't go below 5 fps data->bias -= framems;
if (deltams > data->bias)
data->timer.WaitMs(deltams - data->bias);
data->bias -= deltams;
}
} }


void Ticker::StartBenchmark() void Ticker::StartBenchmark()
@@ -350,6 +351,16 @@ void Ticker::StopBenchmark()
data->benchmark--; data->benchmark--;
} }


void Ticker::StartRecording()
{
data->recording++;
}

void Ticker::StopRecording()
{
data->recording--;
}

int Ticker::GetFrameNum() int Ticker::GetFrameNum()
{ {
return data->frame; return data->frame;


+ 2
- 0
src/ticker.h 查看文件

@@ -34,6 +34,8 @@ public:
static void ClampFps(); static void ClampFps();
static void StartBenchmark(); static void StartBenchmark();
static void StopBenchmark(); static void StopBenchmark();
static void StartRecording();
static void StopRecording();
static int GetFrameNum(); static int GetFrameNum();


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


||||||
x
 
000:0
正在加载...
取消
保存