summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--StarsEx/Clock.cpp14
-rw-r--r--StarsEx/Clock.h9
-rw-r--r--StarsEx/Clock.inl28
3 files changed, 33 insertions, 18 deletions
diff --git a/StarsEx/Clock.cpp b/StarsEx/Clock.cpp
index e5db6c3..4a321d8 100644
--- a/StarsEx/Clock.cpp
+++ b/StarsEx/Clock.cpp
@@ -122,20 +122,6 @@ Clock::TimeCompression() const
}
-Clock::count_type
-Clock::GameTime() const
-{
- return std::chrono::duration_cast<elapsed_duration>(m_game_elapsed).count();
-}
-
-
-Clock::count_type
-Clock::RealTime() const
-{
- return std::chrono::duration_cast<elapsed_duration>(m_real_elapsed).count();
-}
-
-
void
Clock::SetTimeCompression(double compression)
{
diff --git a/StarsEx/Clock.h b/StarsEx/Clock.h
index 4f51330..39e08ac 100644
--- a/StarsEx/Clock.h
+++ b/StarsEx/Clock.h
@@ -8,14 +8,13 @@
#define Clock_h
#include <chrono>
+#include <cstdint>
class Clock
{
public:
using inner_clock = std::chrono::high_resolution_clock;
- using elapsed_duration = std::chrono::milliseconds;
- using count_type = elapsed_duration::rep;
static Clock* GetInstance();
static bool Init();
@@ -30,8 +29,8 @@ public:
double GuiDelta() const;
double Rate() const;
double TimeCompression() const;
- count_type GameTime() const;
- count_type RealTime() const;
+ template <typename R = std::uint32_t> R GameTime() const;
+ template <typename R = std::uint32_t> R RealTime() const;
void SetTimeCompression(double compression);
@@ -51,4 +50,6 @@ private:
};
+#include "Clock.inl"
+
#endif // Clock_h
diff --git a/StarsEx/Clock.inl b/StarsEx/Clock.inl
new file mode 100644
index 0000000..42a2693
--- /dev/null
+++ b/StarsEx/Clock.inl
@@ -0,0 +1,28 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+*/
+
+#include "Clock.h"
+
+#include <chrono>
+#include <ratio>
+
+
+template <typename R>
+R
+Clock::GameTime() const
+{
+ using target_duration = std::chrono::duration<R, std::milli>;
+ return std::chrono::duration_cast<target_duration>(m_game_elapsed).count();
+}
+
+
+template <typename R>
+R
+Clock::RealTime() const
+{
+ using target_duration = std::chrono::duration<R, std::milli>;
+ return std::chrono::duration_cast<target_duration>(m_real_elapsed).count();
+}