From 01ce68accb577b3d56c6d87359096e0316f21db3 Mon Sep 17 00:00:00 2001 From: Nomango Date: Wed, 20 May 2020 10:16:54 +0800 Subject: [PATCH] update Ticker --- src/kiwano/core/Ticker.cpp | 7 +++++++ src/kiwano/core/Ticker.h | 11 ++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/kiwano/core/Ticker.cpp b/src/kiwano/core/Ticker.cpp index 4d3ac55b..b3884cd8 100644 --- a/src/kiwano/core/Ticker.cpp +++ b/src/kiwano/core/Ticker.cpp @@ -37,11 +37,15 @@ TickerPtr Ticker::Create(Duration interval, int times) Ticker::Ticker() : ticked_times_(0) , total_times_(0) + , is_paused_(false) { } bool Ticker::Tick() { + if (is_paused_) + return false; + if (!timer_) timer_ = Timer::Create(); @@ -55,6 +59,9 @@ bool Ticker::Tick() bool Ticker::Tick(Duration dt) { + if (is_paused_) + return false; + if (ticked_times_ == total_times_) return false; diff --git a/src/kiwano/core/Ticker.h b/src/kiwano/core/Ticker.h index 1b7986f8..a4663769 100644 --- a/src/kiwano/core/Ticker.h +++ b/src/kiwano/core/Ticker.h @@ -100,6 +100,7 @@ public: void Reset(); private: + bool is_paused_; int ticked_times_; int total_times_; Duration interval_; @@ -111,21 +112,17 @@ private: inline void Ticker::Pause() { - KGE_ASSERT(timer_); - timer_->Pause(); + is_paused_ = true; } inline void Ticker::Resume() { - KGE_ASSERT(timer_); - timer_->Resume(); + is_paused_ = false; } inline bool Ticker::IsPausing() const { - if (timer_) - return timer_->IsPausing(); - return true; + return is_paused_; } inline int Ticker::GetTickedTimes() const