fix: minor fixes

This commit is contained in:
Nomango 2018-10-18 23:10:09 +08:00
parent e7cc0773e6
commit 24206e00b6
7 changed files with 90 additions and 15 deletions

View File

@ -55,12 +55,12 @@ void easy2d::Spawn::Update()
{ {
Action::Update(); Action::Update();
size_t doneNum = 0; size_t done_num = 0;
for (const auto& action : actions_) for (const auto& action : actions_)
{ {
if (action->IsDone()) if (action->IsDone())
{ {
++doneNum; ++done_num;
} }
else else
{ {
@ -68,7 +68,7 @@ void easy2d::Spawn::Update()
} }
} }
if (doneNum == actions_.size()) if (done_num == actions_.size())
{ {
this->Stop(); this->Stop();
} }

View File

@ -104,7 +104,7 @@ namespace easy2d
bool running_; bool running_;
bool done_; bool done_;
bool initialized_; bool initialized_;
Node * target_; Node* target_;
Time started_; Time started_;
}; };

View File

@ -234,6 +234,7 @@ namespace easy2d
// 数字类型转字符串 // 数字类型转字符串
static String Parse(int value); static String Parse(int value);
static String Parse(unsigned int value); static String Parse(unsigned int value);
static String Parse(unsigned long long value);
static String Parse(float value); static String Parse(float value);
static String Parse(double value); static String Parse(double value);
@ -523,11 +524,11 @@ namespace easy2d
Duration(); Duration();
explicit Duration( explicit Duration(
int64_t milliseconds int milliseconds
); );
// 获取毫秒数 // 获取毫秒数
int64_t Milliseconds() const; int Milliseconds() const;
// 获取秒数 // 获取秒数
float Seconds() const; float Seconds() const;
@ -549,18 +550,29 @@ namespace easy2d
Duration operator - (Duration const &) const; Duration operator - (Duration const &) const;
Duration operator * (int) const; Duration operator * (int) const;
Duration operator * (float) const; Duration operator * (float) const;
Duration operator * (double) const;
Duration operator / (int) const; Duration operator / (int) const;
Duration operator / (float) const; Duration operator / (float) const;
Duration operator / (double) const;
Duration& operator += (Duration const &); Duration& operator += (Duration const &);
Duration& operator -= (Duration const &); Duration& operator -= (Duration const &);
Duration& operator *= (int); Duration& operator *= (int);
Duration& operator *= (float); Duration& operator *= (float);
Duration& operator *= (double);
Duration& operator /= (int); Duration& operator /= (int);
Duration& operator /= (float); 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: private:
int64_t milliseconds_; int milliseconds_;
}; };

View File

@ -36,7 +36,7 @@ easy2d::Task::Task(const Function & func, float delay, int times, const String &
: running_(true) : running_(true)
, stopped_(false) , stopped_(false)
, run_times_(0) , run_times_(0)
, delay_(std::max(delay, 0.f)) , delay_(Duration::Second * std::max(delay, 0.f))
, total_times_(times) , total_times_(times)
, callback_(func) , callback_(func)
, name_(name) , name_(name)

View File

@ -31,12 +31,12 @@ easy2d::Duration::Duration()
{ {
} }
easy2d::Duration::Duration(int64_t milliseconds) easy2d::Duration::Duration(int milliseconds)
: milliseconds_(milliseconds) : milliseconds_(milliseconds)
{ {
} }
int64_t easy2d::Duration::Milliseconds() const int easy2d::Duration::Milliseconds() const
{ {
return milliseconds_; return milliseconds_;
} }
@ -118,14 +118,28 @@ easy2d::Duration easy2d::Duration::operator/(int value) const
easy2d::Duration easy2d::Duration::operator*(float value) const easy2d::Duration easy2d::Duration::operator*(float value) const
{ {
int64_t ms = static_cast<int64_t>(milliseconds_ * value); int ms = static_cast<int>(milliseconds_ * value);
Duration d(ms); Duration d(ms);
return std::move(d); return std::move(d);
} }
easy2d::Duration easy2d::Duration::operator/(float value) const easy2d::Duration easy2d::Duration::operator/(float value) const
{ {
int64_t ms = static_cast<int64_t>(milliseconds_ / value); int ms = static_cast<int>(milliseconds_ / value);
Duration d(ms);
return std::move(d);
}
easy2d::Duration easy2d::Duration::operator*(double value) const
{
int ms = static_cast<int>(milliseconds_ * value);
Duration d(ms);
return std::move(d);
}
easy2d::Duration easy2d::Duration::operator/(double value) const
{
int ms = static_cast<int>(milliseconds_ / value);
Duration d(ms); Duration d(ms);
return std::move(d); return std::move(d);
} }
@ -156,12 +170,54 @@ easy2d::Duration & easy2d::Duration::operator/=(int value)
easy2d::Duration & easy2d::Duration::operator*=(float value) easy2d::Duration & easy2d::Duration::operator*=(float value)
{ {
milliseconds_ *= value; milliseconds_ = static_cast<int>(milliseconds_ * value);
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator/=(float value) easy2d::Duration & easy2d::Duration::operator/=(float value)
{ {
milliseconds_ /= value; milliseconds_ = static_cast<int>(milliseconds_ / value);
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator*=(double value)
{
milliseconds_ = static_cast<int>(milliseconds_ * value);
return (*this);
}
easy2d::Duration & easy2d::Duration::operator/=(double value)
{
milliseconds_ = static_cast<int>(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);
}

View File

@ -81,6 +81,13 @@ easy2d::String easy2d::String::Parse(unsigned int value)
return std::move(tmp); 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) easy2d::String easy2d::String::Parse(float value)
{ {
String tmp; String tmp;

View File

@ -67,7 +67,7 @@ easy2d::Time & easy2d::Time::operator-=(Duration const &other)
easy2d::Duration easy2d::Time::operator-(Time const & other) const easy2d::Duration easy2d::Time::operator-(Time const & other) const
{ {
auto ms = duration_cast<milliseconds>(time_ - other.time_).count(); auto ms = duration_cast<milliseconds>(time_ - other.time_).count();
Duration d(static_cast<int64_t>(ms)); Duration d(static_cast<int>(ms));
return std::move(d); return std::move(d);
} }