diff --git a/src/gameGlobalInfo.cpp b/src/gameGlobalInfo.cpp index cdf517710f..02e53b97a7 100644 --- a/src/gameGlobalInfo.cpp +++ b/src/gameGlobalInfo.cpp @@ -281,6 +281,7 @@ void GameGlobalInfo::reset() script_environment_base = nullptr; elapsed_time = 0.0f; + wall_time.restart(); callsign_counter = 0; global_message = ""; global_message_timeout = 0.0f; diff --git a/src/gameGlobalInfo.h b/src/gameGlobalInfo.h index 62b02343f8..4d278ecf94 100644 --- a/src/gameGlobalInfo.h +++ b/src/gameGlobalInfo.h @@ -6,6 +6,7 @@ #include "components/radar.h" #include "Updatable.h" #include "multiplayer.h" +#include "timer.h" #include #include #include @@ -58,6 +59,7 @@ class GameGlobalInfo : public MultiplayerObject, public Updatable string default_skybox = "default"; string gm_control_code; float elapsed_time; + sp::SystemStopwatch wall_time; string scenario; std::unordered_map scenario_settings; diff --git a/src/script.cpp b/src/script.cpp index 67b8a6fa60..2e77701d16 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -408,6 +408,11 @@ static float luaGetScenarioTime() return gameGlobalInfo->elapsed_time; } +static float luaGetWallTime() +{ + return gameGlobalInfo->wall_time.get(); +} + static int luaGetAllObjects(lua_State* L) { lua_newtable(L); @@ -1350,6 +1355,11 @@ bool setupScriptEnvironment(sp::script::Environment& env) /// This timer stops when the game is paused. /// Example: getScenarioTime() -- after two minutes, returns 120.0 env.setGlobal("getScenarioTime", &luaGetScenarioTime); + /// float getWallTime() + /// Returns the elapsed wall time since scenario start, in seconds. + /// This timer does *not* stop when the game is paused. + /// Example: getWallTime() -- after one minute of the game being paused and two minutes of the game running, returns 180.0 + env.setGlobal("getWallTime", &luaGetWallTime); /// std::vector getAllObjects() /// Returns a list of all objects that have a position in the world.