From 135402168801035c38be600fa64702c1ba63b9fe Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 27 Mar 2026 17:40:05 +0000 Subject: Use std::chrono for worldTime 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. --- game/environment.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'game/environment.cpp') 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(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 -- cgit v1.3