summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan.goodliffe@octal.co.uk>2026-03-27 17:40:05 +0000
committerDan Goodliffe <dan.goodliffe@octal.co.uk>2026-03-27 17:40:05 +0000
commit135402168801035c38be600fa64702c1ba63b9fe (patch)
tree36f13d91fc08b0f0cb395fa648bde777c8c76773 /game
parentAdd wrapper for ImGui::TextEx for any contiguous char range (diff)
downloadilt-135402168801035c38be600fa64702c1ba63b9fe.tar.bz2
ilt-135402168801035c38be600fa64702c1ba63b9fe.tar.xz
ilt-135402168801035c38be600fa64702c1ba63b9fe.zip
Use std::chrono for worldTimeHEADmain
Defines a world time type alias, a game time scale factor (the rate at which world time progresses compare to real time) and display the world time on the status bar.
Diffstat (limited to 'game')
-rw-r--r--game/environment.cpp12
-rw-r--r--game/environment.h8
2 files changed, 13 insertions, 7 deletions
diff --git a/game/environment.cpp b/game/environment.cpp
index f8da316..58a5b53 100644
--- a/game/environment.cpp
+++ b/game/environment.cpp
@@ -5,15 +5,17 @@
constexpr Direction2D DONCASTER = {-1.1_degrees, 53.5_degrees};
-Environment::Environment() : worldTime {"2026-06-01T12:00:00"_time_t}, earthPos {DONCASTER} { }
+Environment::Environment() : worldTime {"2026-06-01T12:00:00"_seconds}, gameTimeScaleFactor {1440}, earthPos {DONCASTER}
+{
+}
void
-Environment::tick(TickDuration)
+Environment::tick(TickDuration elapsed)
{
- worldTime += 50;
+ worldTime += std::chrono::duration_cast<WorldTime::duration>(elapsed * gameTimeScaleFactor);
}
-time_t
+Environment::WorldTime
Environment::getWorldTime() const
{
return worldTime;
@@ -22,7 +24,7 @@ Environment::getWorldTime() const
Direction2D
Environment::getSunPos() const
{
- return getSunPos(earthPos, worldTime);
+ return getSunPos(earthPos, worldTime.time_since_epoch().count());
}
void
diff --git a/game/environment.h b/game/environment.h
index 271792f..94211bc 100644
--- a/game/environment.h
+++ b/game/environment.h
@@ -2,20 +2,24 @@
#include "config/types.h"
#include "worldobject.h"
+#include <chrono>
class SceneRenderer;
class SceneProvider;
class Environment : public WorldObject {
public:
+ using WorldTime = std::chrono::utc_time<std::chrono::seconds>;
+
Environment();
void tick(TickDuration elapsed) override;
void render(const SceneRenderer &, const SceneProvider &) const;
[[nodiscard]] Direction2D getSunPos() const;
- [[nodiscard]] time_t getWorldTime() const;
+ [[nodiscard]] WorldTime getWorldTime() const;
[[nodiscard]] static Direction2D getSunPos(Direction2D position, time_t time);
private:
- time_t worldTime;
+ WorldTime worldTime;
+ uint16_t gameTimeScaleFactor;
glm::vec<2, Angle> earthPos;
};