| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 13:33:39 +08:00
										 |  |  | #include "..\e2dutil.h"
 | 
					
						
							| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const easy2d::Duration easy2d::Duration::Millisecond = easy2d::Duration(1); | 
					
						
							|  |  |  | const easy2d::Duration easy2d::Duration::Second = 1000 * easy2d::Duration::Millisecond; | 
					
						
							|  |  |  | const easy2d::Duration easy2d::Duration::Minute = 60 * easy2d::Duration::Second; | 
					
						
							|  |  |  | const easy2d::Duration easy2d::Duration::Hour = 60 * easy2d::Duration::Minute; | 
					
						
							| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | easy2d::Duration::Duration() | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	: milliseconds_(0) | 
					
						
							| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 23:10:09 +08:00
										 |  |  | easy2d::Duration::Duration(int milliseconds) | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	: milliseconds_(milliseconds) | 
					
						
							| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 23:10:09 +08:00
										 |  |  | int easy2d::Duration::Milliseconds() const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	return milliseconds_; | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | float easy2d::Duration::Seconds() const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	int64_t sec = milliseconds_ / Second.milliseconds_; | 
					
						
							|  |  |  | 	int64_t ms = milliseconds_ % Second.milliseconds_; | 
					
						
							|  |  |  | 	return static_cast<float>(sec) + static_cast<float>(ms) / 1000.f; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | float easy2d::Duration::Minutes() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int64_t min = milliseconds_ / Minute.milliseconds_; | 
					
						
							|  |  |  | 	int64_t ms = milliseconds_ % Minute.milliseconds_; | 
					
						
							|  |  |  | 	return static_cast<float>(min) + static_cast<float>(ms) / (60 * 1000.f); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | float easy2d::Duration::Hours() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int64_t hour = milliseconds_ / Hour.milliseconds_; | 
					
						
							|  |  |  | 	int64_t ms = milliseconds_ % Hour.milliseconds_; | 
					
						
							|  |  |  | 	return static_cast<float>(hour) + static_cast<float>(ms) / (60 * 60 * 1000.f); | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | bool easy2d::Duration::operator==(const Duration & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	return milliseconds_ == other.milliseconds_; | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | bool easy2d::Duration::operator!=(const Duration & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	return milliseconds_ != other.milliseconds_; | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | bool easy2d::Duration::operator>(const Duration & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	return milliseconds_ > other.milliseconds_; | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | bool easy2d::Duration::operator>=(const Duration & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	return milliseconds_ >= other.milliseconds_; | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | bool easy2d::Duration::operator<(const Duration & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	return milliseconds_ < other.milliseconds_; | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | bool easy2d::Duration::operator<=(const Duration & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	return milliseconds_ <= other.milliseconds_; | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | easy2d::Duration easy2d::Duration::operator+(Duration const & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	Duration d(milliseconds_ + other.milliseconds_); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	return std::move(d); | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | easy2d::Duration easy2d::Duration::operator-(Duration const & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	Duration d(milliseconds_ - other.milliseconds_); | 
					
						
							|  |  |  | 	return std::move(d); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | easy2d::Duration easy2d::Duration::operator*(int value) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Duration d(milliseconds_ * value); | 
					
						
							|  |  |  | 	return std::move(d); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | easy2d::Duration easy2d::Duration::operator/(int value) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Duration d(milliseconds_ / value); | 
					
						
							|  |  |  | 	return std::move(d); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | easy2d::Duration easy2d::Duration::operator*(float value) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 23:10:09 +08:00
										 |  |  | 	int ms = static_cast<int>(milliseconds_ * value); | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	Duration d(ms); | 
					
						
							|  |  |  | 	return std::move(d); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | easy2d::Duration easy2d::Duration::operator/(float value) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 23:10:09 +08:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	Duration d(ms); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	return std::move(d); | 
					
						
							| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | easy2d::Duration & easy2d::Duration::operator+=(Duration const &other) | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	milliseconds_ += other.milliseconds_; | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | 	return (*this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 14:13:15 +08:00
										 |  |  | easy2d::Duration & easy2d::Duration::operator-=(Duration const &other) | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	milliseconds_ -= other.milliseconds_; | 
					
						
							|  |  |  | 	return (*this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | easy2d::Duration & easy2d::Duration::operator*=(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	milliseconds_ *= value; | 
					
						
							|  |  |  | 	return (*this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | easy2d::Duration & easy2d::Duration::operator/=(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	milliseconds_ /= value; | 
					
						
							|  |  |  | 	return (*this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | easy2d::Duration & easy2d::Duration::operator*=(float value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 23:10:09 +08:00
										 |  |  | 	milliseconds_ = static_cast<int>(milliseconds_ * value); | 
					
						
							| 
									
										
										
										
											2018-10-18 15:33:14 +08:00
										 |  |  | 	return (*this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | easy2d::Duration & easy2d::Duration::operator/=(float value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 23:10:09 +08:00
										 |  |  | 	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::Duration::operator/=(double value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	milliseconds_ = static_cast<int>(milliseconds_ / value); | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | 	return (*this); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-18 23:10:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							|  |  |  | } |