浏览代码

Getting rid of TimerData class

legacy
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 9 年前
父节点
当前提交
28031dac1e
共有 1 个文件被更改,包括 12 次插入30 次删除
  1. +12
    -30
      src/lol/sys/timer.h

+ 12
- 30
src/lol/sys/timer.h 查看文件

@@ -25,15 +25,9 @@ namespace lol
* Timer implementation class * Timer implementation class
*/ */


class TimerData
class Timer
{ {
friend class Timer;

private: private:
TimerData()
{
(void)GetSeconds(true);
}


float GetSeconds(bool reset) float GetSeconds(bool reset)
{ {
@@ -47,55 +41,43 @@ private:
return std::chrono::duration_cast<std::chrono::duration<float>>(tp - tp0).count(); return std::chrono::duration_cast<std::chrono::duration<float>>(tp - tp0).count();
} }


static void WaitSeconds(float seconds)
{
if (seconds > 0.0f)
std::this_thread::sleep_for(std::chrono::duration<float>(seconds));
}

std::chrono::steady_clock::time_point m_tp;
};

class Timer
{
public: public:
Timer() Timer()
: data(new TimerData())
: m_tp()
{ {
(void)GetSeconds(true);
} }


~Timer() ~Timer()
{ {
delete data;
} }


void Reset() void Reset()
{ {
(void)data->GetSeconds(true);
(void)GetSeconds(true);
} }


float Get() float Get()
{ {
return data->GetSeconds(true);
return GetSeconds(true);
} }


float Poll() float Poll()
{ {
return data->GetSeconds(false);
return GetSeconds(false);
} }


void Wait(float seconds) void Wait(float seconds)
{ {
float secs_elapsed = data->GetSeconds(false);
data->WaitSeconds(seconds - secs_elapsed);
if (seconds > 0.0f)
{
float secs_elapsed = GetSeconds(false);
std::this_thread::sleep_for(std::chrono::duration<float>(seconds - secs_elapsed));
}
} }


private: private:
TimerData *data;

/* Copying timers is forbidden for now. */
Timer(Timer const &t);
Timer operator =(Timer const &t);
std::chrono::steady_clock::time_point m_tp;
}; };


} /* namespace lol */ } /* namespace lol */


正在加载...
取消
保存