From 24206e00b669681d790cf0098f3584af28672f90 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Thu, 18 Oct 2018 23:10:09 +0800 Subject: [PATCH] fix: minor fixes --- core/actions/Spawn.cpp | 6 ++-- core/e2daction.h | 2 +- core/e2dutil.h | 18 +++++++++-- core/objects/Task.cpp | 2 +- core/utils/Duration.cpp | 68 +++++++++++++++++++++++++++++++++++++---- core/utils/String.cpp | 7 +++++ core/utils/Time.cpp | 2 +- 7 files changed, 90 insertions(+), 15 deletions(-) diff --git a/core/actions/Spawn.cpp b/core/actions/Spawn.cpp index 3ee4f42f..04703b3a 100644 --- a/core/actions/Spawn.cpp +++ b/core/actions/Spawn.cpp @@ -55,12 +55,12 @@ void easy2d::Spawn::Update() { Action::Update(); - size_t doneNum = 0; + size_t done_num = 0; for (const auto& action : actions_) { if (action->IsDone()) { - ++doneNum; + ++done_num; } else { @@ -68,7 +68,7 @@ void easy2d::Spawn::Update() } } - if (doneNum == actions_.size()) + if (done_num == actions_.size()) { this->Stop(); } diff --git a/core/e2daction.h b/core/e2daction.h index 1dea1480..e82c863c 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -104,7 +104,7 @@ namespace easy2d bool running_; bool done_; bool initialized_; - Node * target_; + Node* target_; Time started_; }; diff --git a/core/e2dutil.h b/core/e2dutil.h index 993967ef..64be5bd8 100644 --- a/core/e2dutil.h +++ b/core/e2dutil.h @@ -234,6 +234,7 @@ namespace easy2d // 数字类型转字符串 static String Parse(int value); static String Parse(unsigned int value); + static String Parse(unsigned long long value); static String Parse(float value); static String Parse(double value); @@ -523,11 +524,11 @@ namespace easy2d Duration(); explicit Duration( - int64_t milliseconds + int milliseconds ); // 获取毫秒数 - int64_t Milliseconds() const; + int Milliseconds() const; // 获取秒数 float Seconds() const; @@ -549,18 +550,29 @@ namespace easy2d Duration operator - (Duration const &) const; Duration operator * (int) const; Duration operator * (float) const; + Duration operator * (double) const; Duration operator / (int) const; Duration operator / (float) const; + Duration operator / (double) const; Duration& operator += (Duration const &); Duration& operator -= (Duration const &); Duration& operator *= (int); Duration& operator *= (float); + Duration& operator *= (double); Duration& operator /= (int); Duration& operator /= (float); + Duration& operator /= (double); + + friend Duration operator* (int, const Duration &); + friend Duration operator* (float, const Duration &); + friend Duration operator* (double, const Duration &); + friend Duration operator/ (int, const Duration &); + friend Duration operator/ (float, const Duration &); + friend Duration operator/ (double, const Duration &); private: - int64_t milliseconds_; + int milliseconds_; }; diff --git a/core/objects/Task.cpp b/core/objects/Task.cpp index 504bc869..3a77e60a 100644 --- a/core/objects/Task.cpp +++ b/core/objects/Task.cpp @@ -36,7 +36,7 @@ easy2d::Task::Task(const Function & func, float delay, int times, const String & : running_(true) , stopped_(false) , run_times_(0) - , delay_(std::max(delay, 0.f)) + , delay_(Duration::Second * std::max(delay, 0.f)) , total_times_(times) , callback_(func) , name_(name) diff --git a/core/utils/Duration.cpp b/core/utils/Duration.cpp index 8bf90418..5e39406d 100644 --- a/core/utils/Duration.cpp +++ b/core/utils/Duration.cpp @@ -31,12 +31,12 @@ easy2d::Duration::Duration() { } -easy2d::Duration::Duration(int64_t milliseconds) +easy2d::Duration::Duration(int milliseconds) : milliseconds_(milliseconds) { } -int64_t easy2d::Duration::Milliseconds() const +int easy2d::Duration::Milliseconds() const { return milliseconds_; } @@ -118,14 +118,28 @@ easy2d::Duration easy2d::Duration::operator/(int value) const easy2d::Duration easy2d::Duration::operator*(float value) const { - int64_t ms = static_cast(milliseconds_ * value); + int ms = static_cast(milliseconds_ * value); Duration d(ms); return std::move(d); } easy2d::Duration easy2d::Duration::operator/(float value) const { - int64_t ms = static_cast(milliseconds_ / value); + int ms = static_cast(milliseconds_ / value); + Duration d(ms); + return std::move(d); +} + +easy2d::Duration easy2d::Duration::operator*(double value) const +{ + int ms = static_cast(milliseconds_ * value); + Duration d(ms); + return std::move(d); +} + +easy2d::Duration easy2d::Duration::operator/(double value) const +{ + int ms = static_cast(milliseconds_ / value); Duration d(ms); return std::move(d); } @@ -156,12 +170,54 @@ easy2d::Duration & easy2d::Duration::operator/=(int value) easy2d::Duration & easy2d::Duration::operator*=(float value) { - milliseconds_ *= value; + milliseconds_ = static_cast(milliseconds_ * value); return (*this); } easy2d::Duration & easy2d::Duration::operator/=(float value) { - milliseconds_ /= value; + milliseconds_ = static_cast(milliseconds_ / value); return (*this); } + +easy2d::Duration & easy2d::Duration::operator*=(double value) +{ + milliseconds_ = static_cast(milliseconds_ * value); + return (*this); +} + +easy2d::Duration & easy2d::Duration::operator/=(double value) +{ + milliseconds_ = static_cast(milliseconds_ / value); + return (*this); +} + +easy2d::Duration easy2d::operator*(int value, const Duration & dur) +{ + return std::move(dur * value); +} + +easy2d::Duration easy2d::operator/(int value, const Duration & dur) +{ + return std::move(dur / value); +} + +easy2d::Duration easy2d::operator*(float value, const Duration & dur) +{ + return std::move(dur * value); +} + +easy2d::Duration easy2d::operator/(float value, const Duration & dur) +{ + return std::move(dur / value); +} + +easy2d::Duration easy2d::operator*(double value, const Duration & dur) +{ + return std::move(dur * value); +} + +easy2d::Duration easy2d::operator/(double value, const Duration & dur) +{ + return std::move(dur / value); +} diff --git a/core/utils/String.cpp b/core/utils/String.cpp index 7e948caf..b0e81b47 100644 --- a/core/utils/String.cpp +++ b/core/utils/String.cpp @@ -81,6 +81,13 @@ easy2d::String easy2d::String::Parse(unsigned int value) return std::move(tmp); } +easy2d::String easy2d::String::Parse(unsigned long long value) +{ + String tmp; + tmp.string_ = std::to_wstring(value); + return std::move(tmp); +} + easy2d::String easy2d::String::Parse(float value) { String tmp; diff --git a/core/utils/Time.cpp b/core/utils/Time.cpp index f242c480..78fd4fba 100644 --- a/core/utils/Time.cpp +++ b/core/utils/Time.cpp @@ -67,7 +67,7 @@ easy2d::Time & easy2d::Time::operator-=(Duration const &other) easy2d::Duration easy2d::Time::operator-(Time const & other) const { auto ms = duration_cast(time_ - other.time_).count(); - Duration d(static_cast(ms)); + Duration d(static_cast(ms)); return std::move(d); }