Pyrogenesis trunk
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CSimulation2 Class Reference

Public API for simulation system. More...

#include <Simulation2.h>

Collaboration diagram for CSimulation2:
Collaboration graph
[legend]

Public Types

using InterfaceList = std::vector< std::pair< entity_id_t, IComponent * > >
 
using InterfaceListUnordered = std::unordered_map< entity_id_t, IComponent * >
 

Public Member Functions

 CSimulation2 (CUnitManager *unitManager, ScriptContext &cx, CTerrain *terrain)
 
 ~CSimulation2 ()
 
void EnableSerializationTest ()
 
void EnableRejoinTest (int rejoinTestTurn)
 
void EnableOOSLog ()
 
bool LoadScripts (const VfsPath &path)
 Load all scripts in the specified directory (non-recursively), so they can register new component types and functions. More...
 
bool LoadDefaultScripts ()
 Call LoadScripts for each of the game's standard simulation script paths. More...
 
void LoadPlayerSettings (bool newPlayers)
 Loads the player settings script (called before map is loaded) More...
 
void LoadMapSettings ()
 Loads the map settings script (called after map is loaded) More...
 
void SetStartupScript (const std::string &script)
 Set a startup script, which will get executed before the first turn. More...
 
const std::string & GetStartupScript ()
 Get the current startup script. More...
 
void SetInitAttributes (JS::HandleValue settings)
 Set the attributes identifying the scenario/RMS used to initialise this simulation. More...
 
JS::Value GetInitAttributes ()
 Get the data passed to SetInitAttributes. More...
 
void GetInitAttributes (JS::MutableHandleValue ret)
 
void SetMapSettings (const std::string &settings)
 Set the initial map settings (as a UTF-8-encoded JSON string), which will be used to set up the simulation state. More...
 
void SetMapSettings (JS::HandleValue settings)
 Set the initial map settings, which will be used to set up the simulation state. More...
 
std::string GetMapSettingsString ()
 Get the current map settings as a UTF-8 JSON string. More...
 
void GetMapSettings (JS::MutableHandleValue ret)
 Get the current map settings. More...
 
int ProgressiveLoad ()
 RegMemFun incremental loader function. More...
 
Status ReloadChangedFile (const VfsPath &path)
 Reload any scripts that were loaded from the given filename. More...
 
void ResetState (bool skipScriptedComponents=false, bool skipAI=false)
 Initialise (or re-initialise) the complete simulation state. More...
 
void PreInitGame ()
 Replace/destroy some entities (e.g. More...
 
void InitGame ()
 Initialise a new game, based on some script data. More...
 
void Update (int turnLength)
 
void Update (int turnLength, const std::vector< SimulationCommand > &commands)
 
void Interpolate (float simFrameLength, float frameOffset, float realFrameLength)
 
void RenderSubmit (SceneCollector &collector, const CFrustum &frustum, bool culling)
 
float GetLastFrameOffset () const
 Returns the last frame offset passed to Interpolate(), i.e. More...
 
entity_id_t AddEntity (const std::wstring &templateName)
 Construct a new entity and add it to the world. More...
 
entity_id_t AddEntity (const std::wstring &templateName, entity_id_t preferredId)
 
entity_id_t AddLocalEntity (const std::wstring &templateName)
 
void DestroyEntity (entity_id_t ent)
 Destroys the specified entity, once FlushDestroyedEntities is called. More...
 
void FlushDestroyedEntities ()
 Does the actual destruction of entities from DestroyEntity. More...
 
IComponentQueryInterface (entity_id_t ent, int iid) const
 
void PostMessage (entity_id_t ent, const CMessage &msg) const
 
void BroadcastMessage (const CMessage &msg) const
 
InterfaceList GetEntitiesWithInterface (int iid)
 Returns a list of components implementing the given interface, and their associated entities, sorted by entity ID. More...
 
const InterfaceListUnorderedGetEntitiesWithInterfaceUnordered (int iid)
 Returns a list of components implementing the given interface, and their associated entities, as an unordered map. More...
 
const CSimContextGetSimContext () const
 
ScriptInterfaceGetScriptInterface () const
 
bool ComputeStateHash (std::string &outHash, bool quick)
 
bool DumpDebugState (std::ostream &stream)
 
bool SerializeState (std::ostream &stream)
 
bool DeserializeState (std::istream &stream)
 
void ActivateRejoinTest (int turn)
 Activate the rejoin-test feature for turn. More...
 
std::string GenerateSchema ()
 
std::vector< std::string > GetRMSData ()
 Get random map script data. More...
 
std::vector< std::string > GetVictoryConditiondData ()
 Get victory condition data. More...
 
std::string GetPlayerDefaults ()
 Get player default data. More...
 
std::string GetMapSizes ()
 Get map sizes data. More...
 
std::string GetAIData ()
 Get AI data. More...
 

Private Member Functions

 NONCOPYABLE (CSimulation2)
 

Private Attributes

CSimulation2Implm
 

Detailed Description

Public API for simulation system.

Most code should interact with the simulation only through this API.

Member Typedef Documentation

◆ InterfaceList

using CSimulation2::InterfaceList = std::vector<std::pair<entity_id_t, IComponent*> >

◆ InterfaceListUnordered

Constructor & Destructor Documentation

◆ CSimulation2()

CSimulation2::CSimulation2 ( CUnitManager unitManager,
ScriptContext cx,
CTerrain terrain 
)

◆ ~CSimulation2()

CSimulation2::~CSimulation2 ( )

Member Function Documentation

◆ ActivateRejoinTest()

void CSimulation2::ActivateRejoinTest ( int  turn)

Activate the rejoin-test feature for turn.

Parameters
turn.

◆ AddEntity() [1/2]

entity_id_t CSimulation2::AddEntity ( const std::wstring &  templateName)

Construct a new entity and add it to the world.

Parameters
templateNamesee ICmpTemplateManager for syntax
Returns
the new entity ID, or INVALID_ENTITY on error

◆ AddEntity() [2/2]

entity_id_t CSimulation2::AddEntity ( const std::wstring &  templateName,
entity_id_t  preferredId 
)

◆ AddLocalEntity()

entity_id_t CSimulation2::AddLocalEntity ( const std::wstring &  templateName)

◆ BroadcastMessage()

void CSimulation2::BroadcastMessage ( const CMessage msg) const

◆ ComputeStateHash()

bool CSimulation2::ComputeStateHash ( std::string &  outHash,
bool  quick 
)

◆ DeserializeState()

bool CSimulation2::DeserializeState ( std::istream &  stream)

◆ DestroyEntity()

void CSimulation2::DestroyEntity ( entity_id_t  ent)

Destroys the specified entity, once FlushDestroyedEntities is called.

Has no effect if the entity does not exist, or has already been added to the destruction queue.

◆ DumpDebugState()

bool CSimulation2::DumpDebugState ( std::ostream &  stream)

◆ EnableOOSLog()

void CSimulation2::EnableOOSLog ( )

◆ EnableRejoinTest()

void CSimulation2::EnableRejoinTest ( int  rejoinTestTurn)

◆ EnableSerializationTest()

void CSimulation2::EnableSerializationTest ( )

◆ FlushDestroyedEntities()

void CSimulation2::FlushDestroyedEntities ( )

Does the actual destruction of entities from DestroyEntity.

This is called automatically by Update, but should also be called at other times when an entity might have been deleted and should be removed from any further processing (e.g. after editor UI message processing)

◆ GenerateSchema()

std::string CSimulation2::GenerateSchema ( )

◆ GetAIData()

std::string CSimulation2::GetAIData ( )

Get AI data.

Returns
string containing JSON format data

◆ GetEntitiesWithInterface()

CSimulation2::InterfaceList CSimulation2::GetEntitiesWithInterface ( int  iid)

Returns a list of components implementing the given interface, and their associated entities, sorted by entity ID.

◆ GetEntitiesWithInterfaceUnordered()

const CSimulation2::InterfaceListUnordered & CSimulation2::GetEntitiesWithInterfaceUnordered ( int  iid)

Returns a list of components implementing the given interface, and their associated entities, as an unordered map.

◆ GetInitAttributes() [1/2]

JS::Value CSimulation2::GetInitAttributes ( )

Get the data passed to SetInitAttributes.

◆ GetInitAttributes() [2/2]

void CSimulation2::GetInitAttributes ( JS::MutableHandleValue  ret)

◆ GetLastFrameOffset()

float CSimulation2::GetLastFrameOffset ( ) const

Returns the last frame offset passed to Interpolate(), i.e.

the offset corresponding to the currently-rendered scene.

◆ GetMapSettings()

void CSimulation2::GetMapSettings ( JS::MutableHandleValue  ret)

Get the current map settings.

◆ GetMapSettingsString()

std::string CSimulation2::GetMapSettingsString ( )

Get the current map settings as a UTF-8 JSON string.

◆ GetMapSizes()

std::string CSimulation2::GetMapSizes ( )

Get map sizes data.

Returns
string containing JSON format data

◆ GetPlayerDefaults()

std::string CSimulation2::GetPlayerDefaults ( )

Get player default data.

Returns
string containing JSON format data

◆ GetRMSData()

std::vector< std::string > CSimulation2::GetRMSData ( )

Get random map script data.

Returns
vector of strings containing JSON format data

◆ GetScriptInterface()

ScriptInterface & CSimulation2::GetScriptInterface ( ) const

◆ GetSimContext()

const CSimContext & CSimulation2::GetSimContext ( ) const

◆ GetStartupScript()

const std::string & CSimulation2::GetStartupScript ( )

Get the current startup script.

◆ GetVictoryConditiondData()

std::vector< std::string > CSimulation2::GetVictoryConditiondData ( )

Get victory condition data.

Returns
vector of strings containing JSON format data

◆ InitGame()

void CSimulation2::InitGame ( )

Initialise a new game, based on some script data.

(Called on CGame instantiation) (This mustn't be used when e.g. loading saved games, only when starting new ones.) This calls the InitGame function defined in helpers/InitGame.js.

◆ Interpolate()

void CSimulation2::Interpolate ( float  simFrameLength,
float  frameOffset,
float  realFrameLength 
)

◆ LoadDefaultScripts()

bool CSimulation2::LoadDefaultScripts ( )

Call LoadScripts for each of the game's standard simulation script paths.

Returns
false on failure

◆ LoadMapSettings()

void CSimulation2::LoadMapSettings ( )

Loads the map settings script (called after map is loaded)

◆ LoadPlayerSettings()

void CSimulation2::LoadPlayerSettings ( bool  newPlayers)

Loads the player settings script (called before map is loaded)

Parameters
newPlayerswill delete all the existing player entities (if any) and create new ones (needed for loading maps, but Atlas might want to update existing player data)

◆ LoadScripts()

bool CSimulation2::LoadScripts ( const VfsPath path)

Load all scripts in the specified directory (non-recursively), so they can register new component types and functions.

This should be called immediately after constructing the CSimulation2 object.

Returns
false on failure

◆ NONCOPYABLE()

CSimulation2::NONCOPYABLE ( CSimulation2  )
private

◆ PostMessage()

void CSimulation2::PostMessage ( entity_id_t  ent,
const CMessage msg 
) const

◆ PreInitGame()

void CSimulation2::PreInitGame ( )

Replace/destroy some entities (e.g.

skirmish replacers) Called right before InitGame, on CGame instantiation. (This mustn't be used when e.g. loading saved games, only when starting new ones.) This calls the PreInitGame function defined in helpers/InitGame.js.

◆ ProgressiveLoad()

int CSimulation2::ProgressiveLoad ( )

RegMemFun incremental loader function.

◆ QueryInterface()

IComponent * CSimulation2::QueryInterface ( entity_id_t  ent,
int  iid 
) const

◆ ReloadChangedFile()

Status CSimulation2::ReloadChangedFile ( const VfsPath path)

Reload any scripts that were loaded from the given filename.

(This is used to implement hotloading.)

◆ RenderSubmit()

void CSimulation2::RenderSubmit ( SceneCollector collector,
const CFrustum frustum,
bool  culling 
)

◆ ResetState()

void CSimulation2::ResetState ( bool  skipScriptedComponents = false,
bool  skipAI = false 
)

Initialise (or re-initialise) the complete simulation state.

Must be called after LoadScripts, and must be called before any methods that depend on the simulation state.

Parameters
skipScriptedComponentsdon't load the scripted system components (this is intended for use by test cases that don't mount all of VFS)
skipAIdon't initialise the AI system (this is intended for use by test cases that don't want all entity templates loaded automatically)

◆ SerializeState()

bool CSimulation2::SerializeState ( std::ostream &  stream)

◆ SetInitAttributes()

void CSimulation2::SetInitAttributes ( JS::HandleValue  settings)

Set the attributes identifying the scenario/RMS used to initialise this simulation.

◆ SetMapSettings() [1/2]

void CSimulation2::SetMapSettings ( const std::string &  settings)

Set the initial map settings (as a UTF-8-encoded JSON string), which will be used to set up the simulation state.

Called from atlas.

◆ SetMapSettings() [2/2]

void CSimulation2::SetMapSettings ( JS::HandleValue  settings)

Set the initial map settings, which will be used to set up the simulation state.

Called from MapReader (for all map-types).

◆ SetStartupScript()

void CSimulation2::SetStartupScript ( const std::string &  script)

Set a startup script, which will get executed before the first turn.

◆ Update() [1/2]

void CSimulation2::Update ( int  turnLength)

◆ Update() [2/2]

void CSimulation2::Update ( int  turnLength,
const std::vector< SimulationCommand > &  commands 
)

Member Data Documentation

◆ m

CSimulation2Impl* CSimulation2::m
private

The documentation for this class was generated from the following files: