18 #include "precompiled.h"
64 m_Simulation2(new
CSimulation2(&m_World->GetUnitManager(), m_World->GetTerrain())),
65 m_GameView(disableGraphics ? NULL : new
CGameView(this)),
145 if (mapType ==
"random")
148 std::wstring scriptFile;
158 std::wstring mapFile;
161 if (mapType ==
"skirmish")
181 std::stringstream stream(state);
186 CancelLoad(L
"Failed to load saved game state. It might have been\nsaved with an incompatible version of the game.");
230 if (ok && !JSVAL_IS_VOID(fval))
280 const double deltaSimTime = deltaRealTime *
m_SimRate;
294 size_t maxTurns = (size_t)m_SimRate;
307 g_Renderer.GetTimeManager().Update(deltaSimTime);
337 if (!cmpPlayerManager)
343 for (
int i = 0; i < numPlayers; ++i)
The container that holds the rules, resources and attributes of the game.
static CColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f)
CNetClient * g_NetClient
Global network client for the standard game.
CUnitManager & GetUnitManager()
Get a reference to the unit manager object.
void SetInitAttributes(const CScriptValRooted &settings)
Set the attributes identifying the scenario/RMS used to initialise this simulation.
bool HasProperty(jsval obj, const char *name)
Check the named property has been defined on the given object.
void CachePlayerColours()
Retrieving player colours from scripts is slow, so this updates an internal cache of all players' col...
ISoundManager * g_SoundManager
bool DeserializeState(std::istream &stream)
void LoadFinished()
Call when the game has started and all data files have been loaded, to signal to the server that we a...
CWorld * m_World
pointer to the CWorld object representing the game world.
virtual void IdleTask()=0
void SetObjectManager(CObjectManager &objectManager)
A trivial wrapper around a jsval.
void RegisterInitRMS(const CStrW &scriptFile, const CScriptValRooted &settings, int playerID)
Implementation of CNetTurnManager for offline games.
void RegisterInit(const CStrW &mapFile, const CScriptValRooted &settings, int playerID)
Initializes the game world with the attributes provided.
bool LoadDefaultScripts()
Call LoadScripts for each of the game's standard simulation script paths.
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
CGameView * m_GameView
pointer to the CGameView object representing the view into the game world.
Public API for simulation system.
void InitGame(const CScriptVal &data)
Initialise a new game, based on some script data.
bool WillUpdate(float simFrameLength)
Returns whether Update(simFrameLength, ...) will process at least one new turn.
void Interpolate(float simFrameLength, float realFrameLength)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
CWorld is a general data class containing whatever is needed to accurately represent the world...
void SetPlayerID(int playerID)
bool Update(const double deltaRealTime, bool doInterpolate=true)
Periodic heartbeat that controls the process.
void SetTurnManager(CNetTurnManager *turnManager)
Replace the current turn manager.
virtual entity_id_t GetPlayerByID(int32_t id)=0
void StartGame(const CScriptValRooted &attribs, const std::string &savedState)
bool m_Paused
the game is paused and no updates will be performed if true.
JSObject * GetScriptObject()
See CGUI::GetScriptObject; applies to the currently active page.
ScriptInterface & GetScriptInterface() const
std::string m_InitialSavedState
Common network turn system (used by clients and offline games).
void MakeDirty()
Marks the LOS texture as needing recomputation.
CGame * g_Game
Globally accessible pointer to the CGame object.
void SetSimRate(float simRate)
Set the simulation scale multiplier.
static bool IsInitialised()
void RegisterInit(const CScriptValRooted &attribs, const std::string &savedState)
Initializes the game with the set of attributes provided.
A simplified syntax for accessing entity components.
CNetTurnManager * m_TurnManager
void CancelLoad(const CStrW &message)
bool Update(float simFrameLength, size_t maxTurns)
Advance the simulation by a certain time.
std::vector< CColor > m_PlayerColours
bool GetProperty(jsval obj, const char *name, T &out)
Get the named property on the given object.
void SetPlayerID(int playerId)
Set the current user's player ID, which will be added into command messages.
void Interpolate(float simFrameLength, float realFrameLength)
Advance the graphics by a certain time.
CGameView * GetView()
Get the pointer to the game view object.
CGame(bool disableGraphics=false)
Constructor.
virtual CLOSTexture & GetLOSTexture()
Return the LOS texture to be used for rendering this scene.
void LDR_EndRegistering()
CColor GetPlayerColour(int player) const
jsval get() const
Returns the current value (or JSVAL_VOID if uninitialised).
CObjectManager & GetObjectManager() const
virtual void StartGame(const CScriptValRooted &attribs)=0
Started the game with the given game attributes.
void RegMemFun(T *this_, int(T::*func)(void), const wchar_t *description, int estimated_duration_ms)
Implementation of IReplayLogger that saves data to a file in the logs directory.
float m_SimRate
Timescale multiplier for simulation rate.
int ProgressiveLoad()
RegMemFun incremental loader function.
PSRETURN ReallyStartGame()
Game initialization has been completed.
IReplayLogger * m_ReplayLogger
virtual int32_t GetNumPlayers()=0
bool HasPages()
Returns whether there are any current pages.
bool m_GameStarted
the game has been initialized and ready for use if true.
CScriptValRooted GetInitAttributes()
Get the data passed to SetInitAttributes.
void SendEventToAll(const CStr &eventName)
See CGUI::SendEventToAll; applies to the currently active page.
IReplayLogger & GetReplayLogger() const
void LDR_BeginRegistering()
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
CSimulation2 * m_Simulation2
pointer to the CSimulation2 object operating on the game world.