update Ticker

This commit is contained in:
Nomango 2020-05-20 10:16:54 +08:00
parent 86bb0e4239
commit 01ce68accb
2 changed files with 11 additions and 7 deletions

View File

@ -37,11 +37,15 @@ TickerPtr Ticker::Create(Duration interval, int times)
Ticker::Ticker() Ticker::Ticker()
: ticked_times_(0) : ticked_times_(0)
, total_times_(0) , total_times_(0)
, is_paused_(false)
{ {
} }
bool Ticker::Tick() bool Ticker::Tick()
{ {
if (is_paused_)
return false;
if (!timer_) if (!timer_)
timer_ = Timer::Create(); timer_ = Timer::Create();
@ -55,6 +59,9 @@ bool Ticker::Tick()
bool Ticker::Tick(Duration dt) bool Ticker::Tick(Duration dt)
{ {
if (is_paused_)
return false;
if (ticked_times_ == total_times_) if (ticked_times_ == total_times_)
return false; return false;

View File

@ -100,6 +100,7 @@ public:
void Reset(); void Reset();
private: private:
bool is_paused_;
int ticked_times_; int ticked_times_;
int total_times_; int total_times_;
Duration interval_; Duration interval_;
@ -111,21 +112,17 @@ private:
inline void Ticker::Pause() inline void Ticker::Pause()
{ {
KGE_ASSERT(timer_); is_paused_ = true;
timer_->Pause();
} }
inline void Ticker::Resume() inline void Ticker::Resume()
{ {
KGE_ASSERT(timer_); is_paused_ = false;
timer_->Resume();
} }
inline bool Ticker::IsPausing() const inline bool Ticker::IsPausing() const
{ {
if (timer_) return is_paused_;
return timer_->IsPausing();
return true;
} }
inline int Ticker::GetTickedTimes() const inline int Ticker::GetTickedTimes() const