From f8dd0a8ed10fb6adb7ce9fcc5d9b7976f63a7813 Mon Sep 17 00:00:00 2001 From: Nomango Date: Mon, 20 Jul 2020 16:55:56 +0800 Subject: [PATCH] fixes --- src/kiwano/core/Time.cpp | 16 ++++++++-------- src/kiwano/utils/Task.cpp | 23 +++++++++++++++++++++++ src/kiwano/utils/Task.h | 17 +++++++---------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/kiwano/core/Time.cpp b/src/kiwano/core/Time.cpp index 33b120d8..eafaccf0 100644 --- a/src/kiwano/core/Time.cpp +++ b/src/kiwano/core/Time.cpp @@ -250,11 +250,12 @@ String Duration::ToString() const return String("0s"); } - String result; + StringStream stream; + int64_t total_ms = milliseconds_; if (total_ms < 0) { - result.append("-"); + stream << "-"; total_ms = -total_ms; } @@ -265,23 +266,22 @@ String Duration::ToString() const if (hour) { - result.append(std::to_string(hour)).append("h"); - result.append(std::to_string(min)).append("m"); + stream << hour << 'h' << min << 'm'; } else if (min) { - result.append(std::to_string(min)).append("m"); + stream << min << 'm'; } if (ms != 0) { - result.append(std::to_string(static_cast(sec + ms) / 1000.f)).append("s"); + stream << float(sec) + float(ms) / 1000.f << 's'; } else if (sec != 0) { - result.append(std::to_string(sec)).append("s"); + stream << sec << 's'; } - return result; + return stream.str(); } bool Duration::operator==(const Duration& other) const diff --git a/src/kiwano/utils/Task.cpp b/src/kiwano/utils/Task.cpp index 89f25f24..dd7dc34e 100644 --- a/src/kiwano/utils/Task.cpp +++ b/src/kiwano/utils/Task.cpp @@ -62,8 +62,31 @@ Task::Task() { } +void Task::Start() +{ + if (!running_) + { + running_ = true; + if (ticker_) + ticker_->Resume(); + } +} + +void Task::Stop() +{ + if (running_) + { + running_ = false; + if (ticker_) + ticker_->Pause(); + } +} + void Task::Update(Duration dt) { + if (!running_ || removeable_) + return; + if (!ticker_ || ticker_->GetTotalTickCount() == 0) { Remove(); diff --git a/src/kiwano/utils/Task.h b/src/kiwano/utils/Task.h index 09b27dba..d9c4ca66 100644 --- a/src/kiwano/utils/Task.h +++ b/src/kiwano/utils/Task.h @@ -129,16 +129,6 @@ private: Callback callback_; }; -inline void Task::Start() -{ - running_ = true; -} - -inline void Task::Stop() -{ - running_ = false; -} - inline void Task::Remove() { removeable_ = true; @@ -162,6 +152,13 @@ inline TickerPtr Task::GetTicker() const inline void Task::SetTicker(TickerPtr ticker) { ticker_ = ticker; + if (ticker_) + { + if (running_) + ticker_->Resume(); + else + ticker_->Pause(); + } } inline Task::Callback Task::GetCallback() const