Magic_Game/core/Common/Duration.cpp

80 lines
1.6 KiB
C++
Raw Normal View History

2018-09-05 13:33:39 +08:00
#include "..\e2dutil.h"
using namespace std::chrono;
e2d::Duration::Duration()
2018-09-04 22:42:34 +08:00
: duration_ms_()
{
}
2018-08-02 00:27:45 +08:00
e2d::Duration::Duration(float seconds)
2018-09-04 22:42:34 +08:00
: duration_ms_(static_cast<long long>(seconds * 1000.f))
{
2018-07-22 00:41:24 +08:00
}
2018-09-04 22:42:34 +08:00
int e2d::Duration::Milliseconds() const
2018-07-22 00:41:24 +08:00
{
2018-09-04 22:42:34 +08:00
return static_cast<int>(duration_ms_.count());
2018-07-22 00:41:24 +08:00
}
2018-09-04 22:42:34 +08:00
float e2d::Duration::Seconds() const
2018-07-22 00:41:24 +08:00
{
2018-09-04 22:42:34 +08:00
return duration_ms_.count() / 1000.f;
2018-07-22 00:41:24 +08:00
}
bool e2d::Duration::operator==(const Duration & other) const
{
2018-09-04 22:42:34 +08:00
return duration_ms_ == other.duration_ms_;
2018-07-22 00:41:24 +08:00
}
bool e2d::Duration::operator!=(const Duration & other) const
{
2018-09-04 22:42:34 +08:00
return duration_ms_ != other.duration_ms_;
2018-07-22 00:41:24 +08:00
}
bool e2d::Duration::operator>(const Duration & other) const
{
2018-09-04 22:42:34 +08:00
return duration_ms_ > other.duration_ms_;
2018-07-22 00:41:24 +08:00
}
bool e2d::Duration::operator>=(const Duration & other) const
{
2018-09-04 22:42:34 +08:00
return duration_ms_ >= other.duration_ms_;
2018-07-22 00:41:24 +08:00
}
bool e2d::Duration::operator<(const Duration & other) const
{
2018-09-04 22:42:34 +08:00
return duration_ms_ < other.duration_ms_;
2018-07-22 00:41:24 +08:00
}
bool e2d::Duration::operator<=(const Duration & other) const
{
2018-09-04 22:42:34 +08:00
return duration_ms_ <= other.duration_ms_;
2018-07-22 00:41:24 +08:00
}
e2d::Duration e2d::Duration::operator+(Duration const & other) const
{
2018-08-02 00:27:45 +08:00
Duration d;
2018-09-04 22:42:34 +08:00
d.duration_ms_ = duration_ms_ + other.duration_ms_;
2018-08-02 00:27:45 +08:00
return std::move(d);
2018-07-22 00:41:24 +08:00
}
e2d::Duration e2d::Duration::operator-(Duration const & other) const
{
2018-08-02 00:27:45 +08:00
Duration d;
2018-09-04 22:42:34 +08:00
d.duration_ms_ = duration_ms_ - other.duration_ms_;
2018-08-02 00:27:45 +08:00
return std::move(d);
}
2018-07-29 01:43:15 +08:00
e2d::Duration & e2d::Duration::operator+=(Duration const &other)
{
2018-09-04 22:42:34 +08:00
duration_ms_ += other.duration_ms_;
2018-07-29 01:43:15 +08:00
return (*this);
}
e2d::Duration & e2d::Duration::operator-=(Duration const &other)
{
2018-09-04 22:42:34 +08:00
duration_ms_ -= other.duration_ms_;
2018-07-29 01:43:15 +08:00
return (*this);
}