Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Public API for simulation system. More...
#include <Simulation2.h>
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... | |
IComponent * | QueryInterface (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 InterfaceListUnordered & | GetEntitiesWithInterfaceUnordered (int iid) |
Returns a list of components implementing the given interface, and their associated entities, as an unordered map. More... | |
const CSimContext & | GetSimContext () const |
ScriptInterface & | GetScriptInterface () 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 | |
CSimulation2Impl * | m |
Public API for simulation system.
Most code should interact with the simulation only through this API.
using CSimulation2::InterfaceList = std::vector<std::pair<entity_id_t, IComponent*> > |
using CSimulation2::InterfaceListUnordered = std::unordered_map<entity_id_t, IComponent*> |
CSimulation2::CSimulation2 | ( | CUnitManager * | unitManager, |
ScriptContext & | cx, | ||
CTerrain * | terrain | ||
) |
CSimulation2::~CSimulation2 | ( | ) |
void CSimulation2::ActivateRejoinTest | ( | int | turn | ) |
Activate the rejoin-test feature for turn.
turn. |
entity_id_t CSimulation2::AddEntity | ( | const std::wstring & | templateName | ) |
Construct a new entity and add it to the world.
templateName | see ICmpTemplateManager for syntax |
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.
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.
std::string CSimulation2::GetPlayerDefaults | ( | ) |
Get player default data.
std::vector< std::string > CSimulation2::GetRMSData | ( | ) |
Get random map script data.
ScriptInterface & CSimulation2::GetScriptInterface | ( | ) | const |
const CSimContext & CSimulation2::GetSimContext | ( | ) | const |
const std::string & CSimulation2::GetStartupScript | ( | ) |
Get the current startup script.
std::vector< std::string > CSimulation2::GetVictoryConditiondData | ( | ) |
Get victory condition data.
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.
void CSimulation2::Interpolate | ( | float | simFrameLength, |
float | frameOffset, | ||
float | realFrameLength | ||
) |
bool CSimulation2::LoadDefaultScripts | ( | ) |
Call LoadScripts for each of the game's standard simulation script paths.
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)
newPlayers | will 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.
|
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 |
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.
skipScriptedComponents | don't load the scripted system components (this is intended for use by test cases that don't mount all of VFS) |
skipAI | don'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 | ||
) |
|
private |