8 #ifndef DXLE_INC_TIME_HPP_ 9 #define DXLE_INC_TIME_HPP_ 12 #if defined(__c2__) && __clang_major__ == 3 && __clang_minor__ == 8 20 #include <type_traits> 39 void reset(std::chrono::milliseconds = std::chrono::milliseconds{ 0 });
45 std::chrono::milliseconds pass_time;
51 namespace timing_maker
56 #ifndef DXLE_NO_CXX11_REF_QUALIFIERS 57 virtual std::vector<std::chrono::milliseconds>
make_timing() &&
59 return this->make_timing();
67 count_per_second(
size_t count, std::chrono::milliseconds millisecond = std::chrono::milliseconds(1000))
68 : timing(millisecond / count)
72 return std::vector<std::chrono::milliseconds>(1, timing);
75 std::chrono::milliseconds timing;
81 raw_timing(std::vector<std::chrono::milliseconds> timing_)
82 : timing(
std::move(timing_))
88 #ifndef DXLE_NO_CXX11_REF_QUALIFIERS 89 std::vector<std::chrono::milliseconds>
make_timing() &&
override 91 return std::move(timing);
95 std::vector<std::chrono::milliseconds> timing;
103 template<typename timing_maker_T, typename std::enable_if<std::is_base_of<timing_maker::timing_maker_bace, typename std::remove_reference<timing_maker_T>::type>::value,
nullptr_t>::type =
nullptr>
104 counter(timing_maker_T&& timing_maker);
114 void reset_pass_time(std::chrono::milliseconds = std::chrono::milliseconds{ 0 });
118 void reset_count(
size_t = 0);
122 std::vector<std::chrono::milliseconds> timing;
123 size_t next_timing_index;
124 std::chrono::milliseconds last_pass_time;
131 using namespace time;
133 #ifdef DXLE_SUPPORT_CXX11_USER_DEFINED_LITERALS 137 namespace time_literals {
145 using namespace time_literals;
147 using namespace literals;
150 using namespace literals::time_literals;
153 #endif //#ifdef DXLE_SUPPORT_CXX11_USER_DEFINED_LITERALS 168 if (is_stop_ ==
true){
170 old_time = DxLib::GetNowCount();
185 pass_time = set_time;
192 inline void timer::update()
194 if (is_stop_ ==
false){
195 int now_time = DxLib::GetNowCount();
196 pass_time += std::chrono::milliseconds((now_time - old_time) & INT_MAX);
203 template<typename timing_maker_T, typename std::enable_if<std::is_base_of<timing_maker::timing_maker_bace, typename std::remove_reference<timing_maker_T>::type>::value,
nullptr_t >::type>
206 , timing(
std::forward<timing_maker_T>(timing_maker).make_timing())
207 , next_timing_index(0)
212 : count((other.count))
213 , timing((other.timing))
214 , next_timing_index((other.next_timing_index))
215 , last_pass_time(other.last_pass_time)
216 , timer_((other.timer_))
220 count = (other.count);
221 timing = (other.timing);
222 next_timing_index = (other.next_timing_index);
223 last_pass_time = (other.last_pass_time);
224 timer_ = (other.timer_);
228 : count(
std::move(other.count))
229 , timing(
std::move(other.timing))
230 , next_timing_index(
std::move(other.next_timing_index))
231 , last_pass_time(
std::move(other.last_pass_time))
232 , timer_(
std::move(other.timer_))
236 count = std::move(other.count);
237 timing = std::move(other.timing);
238 next_timing_index = std::move(other.next_timing_index);
239 last_pass_time = std::move(other.last_pass_time);
240 timer_ = std::move(other.timer_);
258 last_pass_time = std::chrono::milliseconds{ 0 };
261 timer_.
reset(new_pass_time);
279 inline void counter::update()
281 using std::chrono::milliseconds;
282 assert(!timing.empty());
283 assert((std::any_of(timing.begin(), timing.end(), [](
const milliseconds& x) {
return x.count() > 0; })));
288 milliseconds pass_time{ now_time - last_pass_time };
289 if (timing[next_timing_index] <= pass_time) {
291 last_pass_time += pass_time;
293 next_timing_index %= timing.size();
#define DXLE_REF_QUALIFIERS_LVALUE
std::chrono::milliseconds get_pass_time()
counter(timing_maker_T &&timing_maker)
std::vector< std::chrono::milliseconds > make_timing() &&override
count_per_second(size_t count, std::chrono::milliseconds millisecond=std::chrono::milliseconds(1000))
std::vector< std::chrono::milliseconds > make_timing() const DXLE_REF_QUALIFIERS_LVALUE override
std::vector< std::chrono::milliseconds > make_timing() const DXLE_REF_QUALIFIERS_LVALUE override
void reset_pass_time(std::chrono::milliseconds=std::chrono::milliseconds{ 0 })
counter & operator=(const counter &other)
raw_timing(std::vector< std::chrono::milliseconds > timing_)
void reset(std::chrono::milliseconds=std::chrono::milliseconds{ 0 })
void reset_count(size_t=0)
virtual std::vector< std::chrono::milliseconds > make_timing() &&
std::chrono::milliseconds get_pass_time()