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

typedef std::vector< std::pair< entity_id_t, IComponent * > > InterfaceList
 
typedef boost::unordered_map< entity_id_t, IComponent * > InterfaceListUnordered
 

Public Member Functions

 CSimulation2 (CUnitManager *unitManager, shared_ptr< ScriptRuntime > rt, 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 (JS::HandleValue data)
 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)
 
std::string GenerateSchema ()
 
std::vector< std::string > GetRMSData ()
 Get random map script data. More...
 
std::vector< std::string > GetCivData ()
 Get civilization 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

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

Constructor & Destructor Documentation

CSimulation2::CSimulation2 ( CUnitManager unitManager,
shared_ptr< ScriptRuntime rt,
CTerrain terrain 
)
CSimulation2::~CSimulation2 ( )

Member Function Documentation

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
entity_id_t CSimulation2::AddEntity ( const std::wstring &  templateName,
entity_id_t  preferredId 
)
entity_id_t CSimulation2::AddLocalEntity ( const std::wstring &  templateName)
void CSimulation2::BroadcastMessage ( const CMessage msg) const
bool CSimulation2::ComputeStateHash ( std::string &  outHash,
bool  quick 
)
bool CSimulation2::DeserializeState ( std::istream &  stream)
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.

bool CSimulation2::DumpDebugState ( std::ostream &  stream)
void CSimulation2::EnableOOSLog ( )
void CSimulation2::EnableRejoinTest ( int  rejoinTestTurn)
void CSimulation2::EnableSerializationTest ( )
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)

std::string CSimulation2::GenerateSchema ( )
std::string CSimulation2::GetAIData ( )

Get AI data.

Returns
string containing JSON format data
std::vector< std::string > CSimulation2::GetCivData ( )

Get civilization data.

Returns
vector of strings containing JSON format data
CSimulation2::InterfaceList CSimulation2::GetEntitiesWithInterface ( int  iid)

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

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

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

JS::Value CSimulation2::GetInitAttributes ( )

Get the data passed to SetInitAttributes.

void CSimulation2::GetInitAttributes ( JS::MutableHandleValue  ret)
float CSimulation2::GetLastFrameOffset ( ) const

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

the offset corresponding to the currently-rendered scene.

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

Get the current map settings.

std::string CSimulation2::GetMapSettingsString ( )

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

std::string CSimulation2::GetMapSizes ( )

Get map sizes data.

Returns
string containing JSON format data
std::string CSimulation2::GetPlayerDefaults ( )

Get player default data.

Returns
string containing JSON format data
std::vector< std::string > CSimulation2::GetRMSData ( )

Get random map script data.

Returns
vector of strings containing JSON format data
ScriptInterface & CSimulation2::GetScriptInterface ( ) const
const CSimContext & CSimulation2::GetSimContext ( ) const
const std::string & CSimulation2::GetStartupScript ( )

Get the current startup script.

void CSimulation2::InitGame ( JS::HandleValue  data)

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.

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

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

Returns
false on failure
void CSimulation2::LoadMapSettings ( )

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

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)
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
CSimulation2::NONCOPYABLE ( CSimulation2  )
private
void CSimulation2::PostMessage ( entity_id_t  ent,
const CMessage msg 
) const
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.

int CSimulation2::ProgressiveLoad ( )

RegMemFun incremental loader function.

IComponent * CSimulation2::QueryInterface ( entity_id_t  ent,
int  iid 
) const
Status CSimulation2::ReloadChangedFile ( const VfsPath path)

Reload any scripts that were loaded from the given filename.

(This is used to implement hotloading.)

void CSimulation2::RenderSubmit ( SceneCollector collector,
const CFrustum frustum,
bool  culling 
)
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)
bool CSimulation2::SerializeState ( std::ostream &  stream)
void CSimulation2::SetInitAttributes ( JS::HandleValue  settings)

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

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.

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).

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

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

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

Member Data Documentation

CSimulation2Impl* CSimulation2::m
private

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