Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>

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 *, CTerrain *)
 
 ~CSimulation2 ()
 
void EnableOOSLog ()
 
void EnableSerializationTest ()
 
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 (const CScriptValRooted &settings)
 Set the attributes identifying the scenario/RMS used to initialise this simulation. More...
 
CScriptValRooted GetInitAttributes ()
 Get the data passed to SetInitAttributes. More...
 
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 (const CScriptValRooted &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...
 
CScriptVal GetMapSettings ()
 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 InitGame (const CScriptVal &data)
 Initialise a new game, based on some script data. More...
 
void InitSavedGame ()
 
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

std::string ReadJSON (VfsPath path)
 
 NONCOPYABLE (CSimulation2)
 

Private Attributes

CSimulation2Implm
 

Detailed Description

Public API for simulation system.

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

Definition at line 46 of file Simulation2.h.

Member Typedef Documentation

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

Definition at line 196 of file Simulation2.h.

Definition at line 197 of file Simulation2.h.

Constructor & Destructor Documentation

CSimulation2::CSimulation2 ( CUnitManager unitManager,
CTerrain terrain 
)

Definition at line 566 of file Simulation2.cpp.

CSimulation2::~CSimulation2 ( )

Definition at line 571 of file Simulation2.cpp.

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

Definition at line 588 of file Simulation2.cpp.

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

Definition at line 593 of file Simulation2.cpp.

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

Definition at line 598 of file Simulation2.cpp.

void CSimulation2::BroadcastMessage ( const CMessage msg) const

Definition at line 623 of file Simulation2.cpp.

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

Definition at line 766 of file Simulation2.cpp.

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

Definition at line 781 of file Simulation2.cpp.

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.

Definition at line 603 of file Simulation2.cpp.

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

Definition at line 771 of file Simulation2.cpp.

void CSimulation2::EnableOOSLog ( )

Definition at line 578 of file Simulation2.cpp.

void CSimulation2::EnableSerializationTest ( )

Definition at line 583 of file Simulation2.cpp.

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)

Definition at line 608 of file Simulation2.cpp.

std::string CSimulation2::GenerateSchema ( )

Definition at line 787 of file Simulation2.cpp.

std::string CSimulation2::GetAIData ( )

Get AI data.

Returns
string containing JSON format data

Definition at line 900 of file Simulation2.cpp.

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

Get civilization data.

Returns
vector of strings containing JSON format data

Definition at line 828 of file Simulation2.cpp.

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

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

Definition at line 628 of file Simulation2.cpp.

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

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

Definition at line 633 of file Simulation2.cpp.

CScriptValRooted CSimulation2::GetInitAttributes ( )

Get the data passed to SetInitAttributes.

Definition at line 712 of file Simulation2.cpp.

float CSimulation2::GetLastFrameOffset ( ) const

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

the offset corresponding to the currently-rendered scene.

Definition at line 682 of file Simulation2.cpp.

CScriptVal CSimulation2::GetMapSettings ( )

Get the current map settings.

Definition at line 732 of file Simulation2.cpp.

std::string CSimulation2::GetMapSettingsString ( )

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

Definition at line 727 of file Simulation2.cpp.

std::string CSimulation2::GetMapSizes ( )

Get map sizes data.

Returns
string containing JSON format data

Definition at line 869 of file Simulation2.cpp.

std::string CSimulation2::GetPlayerDefaults ( )

Get player default data.

Returns
string containing JSON format data

Definition at line 864 of file Simulation2.cpp.

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

Get random map script data.

Returns
vector of strings containing JSON format data

Definition at line 792 of file Simulation2.cpp.

ScriptInterface & CSimulation2::GetScriptInterface ( ) const

Definition at line 643 of file Simulation2.cpp.

const CSimContext & CSimulation2::GetSimContext ( ) const

Definition at line 638 of file Simulation2.cpp.

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

Get the current startup script.

Definition at line 702 of file Simulation2.cpp.

void CSimulation2::InitGame ( const CScriptVal 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. Saved games are initialized with InitSavedGame.

Definition at line 648 of file Simulation2.cpp.

void CSimulation2::InitSavedGame ( )

Definition at line 653 of file Simulation2.cpp.

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

Definition at line 669 of file Simulation2.cpp.

bool CSimulation2::LoadDefaultScripts ( )

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

Returns
false on failure

Definition at line 692 of file Simulation2.cpp.

void CSimulation2::LoadMapSettings ( )

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

Definition at line 742 of file Simulation2.cpp.

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)

Definition at line 737 of file Simulation2.cpp.

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

Definition at line 687 of file Simulation2.cpp.

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

Definition at line 618 of file Simulation2.cpp.

int CSimulation2::ProgressiveLoad ( )

RegMemFun incremental loader function.

Definition at line 751 of file Simulation2.cpp.

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

Definition at line 613 of file Simulation2.cpp.

std::string CSimulation2::ReadJSON ( VfsPath  path)
private

Definition at line 874 of file Simulation2.cpp.

Status CSimulation2::ReloadChangedFile ( const VfsPath path)

Reload any scripts that were loaded from the given filename.

(This is used to implement hotloading.)

Definition at line 756 of file Simulation2.cpp.

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

Definition at line 674 of file Simulation2.cpp.

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)

Definition at line 761 of file Simulation2.cpp.

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

Definition at line 776 of file Simulation2.cpp.

void CSimulation2::SetInitAttributes ( const CScriptValRooted settings)

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

Definition at line 707 of file Simulation2.cpp.

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.

Definition at line 717 of file Simulation2.cpp.

void CSimulation2::SetMapSettings ( const CScriptValRooted settings)

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

Definition at line 722 of file Simulation2.cpp.

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

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

Definition at line 697 of file Simulation2.cpp.

void CSimulation2::Update ( int  turnLength)

Definition at line 658 of file Simulation2.cpp.

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

Definition at line 664 of file Simulation2.cpp.

Member Data Documentation

CSimulation2Impl* CSimulation2::m
private

Definition at line 260 of file Simulation2.h.


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