MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_system_chrono.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_SYSTEM_CHRONO_H_1614111259
12#define INCGUARD_MGL_SYSTEM_CHRONO_H_1614111259
13
14#include <mgl/mgl_environment.h>
16
17namespace MGL::System
18{
20class Chrono
21{
22public:
23 /* ------------------------------------------------------------------------- */
27 /* ------------------------------------------------------------------------- */
28 Chrono() noexcept
29 : _chrono(ModuleSet::GetInstance().GetChronoModule())
30 {}
31
32 /* ------------------------------------------------------------------------- */
37 /* ------------------------------------------------------------------------- */
38 [[nodiscard]] EpochTime GetCurrentEpochTime() const noexcept
39 {
40 return _chrono.GetCurrentEpochTime();
41 }
42
43 /* ------------------------------------------------------------------------- */
49 /* ------------------------------------------------------------------------- */
50 static constexpr int32_t MinutesToSeconds(int32_t minutes) noexcept
51 {
52 return minutes * 60;
53 }
54
55 /* ------------------------------------------------------------------------- */
61 /* ------------------------------------------------------------------------- */
62 static constexpr int32_t HoursToSeconds(int32_t hours) noexcept
63 {
64 return MinutesToSeconds(hours * 60);
65 }
66
67 /* ------------------------------------------------------------------------- */
73 /* ------------------------------------------------------------------------- */
74 static constexpr int32_t DaysToSeconds(int32_t days) noexcept
75 {
76 return HoursToSeconds(days * 24);
77 }
78
79 /* ------------------------------------------------------------------------- */
85 /* ------------------------------------------------------------------------- */
86 [[nodiscard]] bool IsAvailableTickTimer() const noexcept
87 {
88 return _chrono.IsAvailableTickTimer();
89 }
90
91 /* ------------------------------------------------------------------------- */
96 /* ------------------------------------------------------------------------- */
97 [[nodiscard]] TickTime GetTickTime() const noexcept
98 {
99 return _chrono.GetTickTime();
100 }
101
102 /* ------------------------------------------------------------------------- */
109 /* ------------------------------------------------------------------------- */
110 [[nodiscard]] static constexpr TickTime GetTickPassTime(TickTime start, TickTime end)
111 {
112 if (start < end)
113 {
114 return end - start;
115 }
116 else if (start > end)
117 {
118 return static_cast<TickTime>(~0u) - start + end;
119 }
120 else
121 {
122 return 0;
123 }
124 }
125
126 /* ------------------------------------------------------------------------- */
131 /* ------------------------------------------------------------------------- */
132 [[nodiscard]] float TicksToMilliseconds(TickTime tickTime) const noexcept
133 {
134 return _chrono.TicksToNanoseconds(tickTime) / 1000.0f / 1000.0f;
135 }
136
137 /* ------------------------------------------------------------------------- */
142 /* ------------------------------------------------------------------------- */
143 [[nodiscard]] float TicksToMicroseconds(TickTime tickTime) const noexcept
144 {
145 return _chrono.TicksToNanoseconds(tickTime) / 1000.0f;
146 }
147
148 /* ------------------------------------------------------------------------- */
153 /* ------------------------------------------------------------------------- */
154 [[nodiscard]] float TicksToNanoseconds(TickTime tickTime) const noexcept
155 {
156 return _chrono.TicksToNanoseconds(tickTime);
157 }
158
159private:
160 ChronoModuleInterface &_chrono;
161};
162} // namespace MGL::System
163
164#endif // INCGUARD_MGL_SYSTEM_CHRONO_H_1614111259
165
166// vim: et ts=4 sw=4 sts=4
日付と時間のクラス
Definition mgl_system_chrono.h:21
static constexpr int32_t MinutesToSeconds(int32_t minutes) noexcept
分を秒に変換
Definition mgl_system_chrono.h:50
EpochTime GetCurrentEpochTime() const noexcept
現在時刻をエポック時間で取得
Definition mgl_system_chrono.h:38
static constexpr int32_t HoursToSeconds(int32_t hours) noexcept
時間を秒に変換
Definition mgl_system_chrono.h:62
Chrono() noexcept
コンストラクタ
Definition mgl_system_chrono.h:28
float TicksToMilliseconds(TickTime tickTime) const noexcept
TickTimeをミリ秒に変換
Definition mgl_system_chrono.h:132
static constexpr TickTime GetTickPassTime(TickTime start, TickTime end)
2つのTickTimeから経過時間を取得
Definition mgl_system_chrono.h:110
float TicksToMicroseconds(TickTime tickTime) const noexcept
TickTimeをマイクロ秒に変換
Definition mgl_system_chrono.h:143
bool IsAvailableTickTimer() const noexcept
Tickタイマーに対応しているかを取得
Definition mgl_system_chrono.h:86
float TicksToNanoseconds(TickTime tickTime) const noexcept
TickTimeをナノ秒に変換
Definition mgl_system_chrono.h:154
TickTime GetTickTime() const noexcept
現在のTickTimeを取得
Definition mgl_system_chrono.h:97
static constexpr int32_t DaysToSeconds(int32_t days) noexcept
日数を秒に変換
Definition mgl_system_chrono.h:74
日付と時間のモジュールインターフェース
Definition mgl_chrono_module_interface.h:20
virtual EpochTime GetCurrentEpochTime() const noexcept=0
現在時刻をエポック時間で取得
virtual float TicksToNanoseconds(TickTime tickTime) const noexcept=0
TickTimeをナノ秒に変換
virtual bool IsAvailableTickTimer() const noexcept=0
Tickタイマーに対応しているかを取得
virtual TickTime GetTickTime() const noexcept=0
現在のTickTimeを取得
システム関連モジュールセットクラス
Definition mgl_system_module_set.h:27
time_t EpochTime
UNIXエポック時間を表す型
Definition mgl_chrono_defs.h:22
uint64_t TickTime
Tickタイムを表す型
Definition mgl_chrono_defs.h:78
MGL 環境定義
MGL システム関連モジュールセット