update Ticker
This commit is contained in:
parent
f24342acbb
commit
471b6983cd
|
|
@ -35,7 +35,7 @@ EventTickerPtr EventTicker::Create(Duration interval, int times)
|
|||
if (ptr)
|
||||
{
|
||||
ptr->SetInterval(interval);
|
||||
ptr->SetTotalTickTimes(times);
|
||||
ptr->SetTotalTickCount(times);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,13 +64,7 @@ Task::Task()
|
|||
|
||||
void Task::Update(Duration dt)
|
||||
{
|
||||
if (!ticker_)
|
||||
{
|
||||
Remove();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ticker_->GetTotalTickTimes() == 0)
|
||||
if (!ticker_ || ticker_->GetTotalTickCount() == 0)
|
||||
{
|
||||
Remove();
|
||||
return;
|
||||
|
|
@ -81,7 +75,7 @@ void Task::Update(Duration dt)
|
|||
if (callback_)
|
||||
callback_(this, ticker_->GetDeltaTime());
|
||||
|
||||
if (ticker_->GetTickedTimes() == ticker_->GetTotalTickTimes())
|
||||
if (ticker_->GetTickedCount() == ticker_->GetTotalTickCount())
|
||||
Remove();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ TickerPtr Ticker::Create(Duration interval, int times)
|
|||
if (ptr)
|
||||
{
|
||||
ptr->SetInterval(interval);
|
||||
ptr->SetTotalTickTimes(times);
|
||||
ptr->SetTotalTickCount(times);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Ticker::Ticker()
|
||||
: ticked_times_(0)
|
||||
, total_times_(0)
|
||||
: ticked_count_(0)
|
||||
, total_tick_count_(0)
|
||||
, is_paused_(false)
|
||||
{
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ bool Ticker::Tick(Duration dt)
|
|||
if (is_paused_)
|
||||
return false;
|
||||
|
||||
if (ticked_times_ == total_times_)
|
||||
if (ticked_count_ == total_tick_count_)
|
||||
return false;
|
||||
|
||||
elapsed_time_ += dt;
|
||||
|
|
@ -72,7 +72,7 @@ bool Ticker::Tick(Duration dt)
|
|||
delta_time_ = elapsed_time_;
|
||||
error_time_ = (elapsed_time_ + error_time_) - interval_;
|
||||
elapsed_time_ = 0;
|
||||
++ticked_times_;
|
||||
++ticked_count_;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -115,7 +115,7 @@ void Ticker::Reset()
|
|||
elapsed_time_ = 0;
|
||||
delta_time_ = 0;
|
||||
error_time_ = 0;
|
||||
ticked_times_ = 0;
|
||||
ticked_count_ = 0;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建报时器
|
||||
/// @param interval 报时间隔
|
||||
/// @param times 报时次数(设 -1 为永久)
|
||||
static TickerPtr Create(Duration interval, int times = -1);
|
||||
/// @param tick_count 报时次数(设 -1 为永久)
|
||||
static TickerPtr Create(Duration interval, int tick_count = -1);
|
||||
|
||||
Ticker();
|
||||
|
||||
|
|
@ -69,15 +69,15 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取报时器报时次数
|
||||
int GetTickedTimes() const;
|
||||
int GetTickedCount() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取报时器总报时次数
|
||||
int GetTotalTickTimes() const;
|
||||
int GetTotalTickCount() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置报时器总报时次数
|
||||
void SetTotalTickTimes(int times);
|
||||
void SetTotalTickCount(int count);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取报时间隔
|
||||
|
|
@ -101,8 +101,8 @@ public:
|
|||
|
||||
private:
|
||||
bool is_paused_;
|
||||
int ticked_times_;
|
||||
int total_times_;
|
||||
int ticked_count_;
|
||||
int total_tick_count_;
|
||||
Duration interval_;
|
||||
Duration elapsed_time_;
|
||||
Duration delta_time_;
|
||||
|
|
@ -115,19 +115,19 @@ inline bool Ticker::IsPausing() const
|
|||
return is_paused_;
|
||||
}
|
||||
|
||||
inline int Ticker::GetTickedTimes() const
|
||||
inline int Ticker::GetTickedCount() const
|
||||
{
|
||||
return ticked_times_;
|
||||
return ticked_count_;
|
||||
}
|
||||
|
||||
inline int Ticker::GetTotalTickTimes() const
|
||||
inline int Ticker::GetTotalTickCount() const
|
||||
{
|
||||
return total_times_;
|
||||
return total_tick_count_;
|
||||
}
|
||||
|
||||
inline void Ticker::SetTotalTickTimes(int times)
|
||||
inline void Ticker::SetTotalTickCount(int count)
|
||||
{
|
||||
total_times_ = times;
|
||||
total_tick_count_ = count;
|
||||
}
|
||||
|
||||
inline Duration Ticker::GetInterval() const
|
||||
|
|
|
|||
Loading…
Reference in New Issue