Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gameGlobalInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/gameGlobalInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "components/radar.h"
#include "Updatable.h"
#include "multiplayer.h"
#include "timer.h"
#include <list>
#include <functional>
#include <optional>
Expand Down Expand Up @@ -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<string, string> scenario_settings;

Expand Down
10 changes: 10 additions & 0 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<sp::ecs::Entity> getAllObjects()
/// Returns a list of all objects that have a position in the world.
Expand Down
Loading