18#ifndef INCLUDED_SIMULATION2
19#define INCLUDED_SIMULATION2
30#include <js/TypeDecls.h>
35#include <unordered_map>
47namespace Script {
class Context; }
48namespace JS {
class Value; }
49namespace Script {
class Interface; }
63 using std::runtime_error::runtime_error;
66 constexpr static auto DEFAULT_SCRIPTS{std::to_array({L
"simulation/components/interfaces/",
67 L
"simulation/helpers/", L
"simulation/components/"})};
77 const std::span<const wchar_t* const> scriptDirectories,
160 void ResetState(
bool skipScriptedComponents =
false,
bool skipAI =
false);
177 void Update(
int turnLength);
178 void Update(
int turnLength,
const std::vector<SimulationCommand>& commands);
179 void Interpolate(
float simFrameLength,
float frameOffset,
float realFrameLength);
216 std::vector<std::pair<entity_id_t, IComponent*> >;
219 std::unordered_map<entity_id_t, IComponent*>;
287 const std::unique_ptr<CSimulation2Impl>
m;
std::int32_t turn_id_t
At 1000 turns/second, a 32-bit counter would overflow in ~49 days.
Definition: SimulationCommand.h:31
Contains pointers to various 'global' objects that are needed by the simulation code,...
Definition: SimContext.h:34
Definition: Simulation2.cpp:76
Public API for simulation system.
Definition: Simulation2.h:57
static constexpr auto DEFAULT_SCRIPTS
Definition: Simulation2.h:66
void PreInitGame()
Replace/destroy some entities (e.g.
Definition: Simulation2.cpp:739
CSimulation2(CUnitManager *unitManager, Script::Context &cx, CTerrain *terrain, const std::span< const wchar_t *const > scriptDirectories, const SimulationDebugOptions debugOptions={})
Definition: Simulation2.cpp:669
const CSimContext & GetSimContext() const
Definition: Simulation2.cpp:729
void FlushDestroyedEntities()
Does the actual destruction of entities from DestroyEntity.
Definition: Simulation2.cpp:699
entity_id_t AddLocalEntity(const std::wstring &templateName)
Definition: Simulation2.cpp:689
float GetLastFrameOffset() const
Returns the last frame offset passed to Interpolate(), i.e.
Definition: Simulation2.cpp:782
void SetInitAttributes(JS::HandleValue settings)
Set the attributes identifying the scenario/RMS used to initialise this simulation.
Definition: Simulation2.cpp:797
std::unordered_map< entity_id_t, IComponent * > InterfaceListUnordered
Definition: Simulation2.h:219
entity_id_t AddEntity(const std::wstring &templateName)
Construct a new entity and add it to the world.
Definition: Simulation2.cpp:679
const std::string & GetStartupScript()
Get the current startup script.
Definition: Simulation2.cpp:792
std::vector< std::string > GetVictoryConditiondData()
Get victory condition data.
Definition: Simulation2.cpp:948
void RenderSubmit(SceneCollector &collector, const CFrustum &frustum, bool culling)
Definition: Simulation2.cpp:774
JS::Value GetInitAttributes()
Get the data passed to SetInitAttributes.
Definition: Simulation2.cpp:802
std::string GetAIData()
Get AI data.
Definition: Simulation2.cpp:983
void InitGame()
Initialise a new game, based on some script data.
Definition: Simulation2.cpp:746
const std::unique_ptr< CSimulation2Impl > m
Definition: Simulation2.h:287
void LoadPlayerSettings(bool newPlayers)
Loads the player settings script (called before map is loaded)
Definition: Simulation2.cpp:835
bool SerializeState(std::ostream &stream)
Definition: Simulation2.cpp:887
std::vector< std::pair< entity_id_t, IComponent * > > InterfaceList
Definition: Simulation2.h:216
InterfaceList GetEntitiesWithInterface(int iid)
Returns a list of components implementing the given interface, and their associated entities,...
Definition: Simulation2.cpp:719
void BroadcastMessage(const CMessage &msg) const
Definition: Simulation2.cpp:714
std::string GenerateSchema()
Definition: Simulation2.cpp:906
void GetMapSettings(JS::MutableHandleValue ret)
Get the current map settings.
Definition: Simulation2.cpp:830
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 simul...
Definition: Simulation2.cpp:812
Status ReloadChangedFile(const VfsPath &path)
Reload any scripts that were loaded from the given filename.
Definition: Simulation2.cpp:866
void Interpolate(float simFrameLength, float frameOffset, float realFrameLength)
Definition: Simulation2.cpp:769
void PostMessage(entity_id_t ent, const CMessage &msg) const
Definition: Simulation2.cpp:709
void ResetState(bool skipScriptedComponents=false, bool skipAI=false)
Initialise (or re-initialise) the complete simulation state.
Definition: Simulation2.cpp:871
IComponent * QueryInterface(entity_id_t ent, int iid) const
Definition: Simulation2.cpp:704
bool DeserializeState(std::istream &stream)
Definition: Simulation2.cpp:892
std::string GetMapSettingsString()
Get the current map settings as a UTF-8 JSON string.
Definition: Simulation2.cpp:825
std::vector< std::string > GetRMSData()
Get random map script data.
Definition: Simulation2.cpp:943
void ActivateRejoinTest(turn_id_t turn)
Activate the rejoin-test feature for turn.
Definition: Simulation2.cpp:898
void DestroyEntity(entity_id_t ent)
Destroys the specified entity, once FlushDestroyedEntities is called.
Definition: Simulation2.cpp:694
bool ComputeStateHash(std::string &outHash, bool quick)
Definition: Simulation2.cpp:876
NONCOPYABLE(CSimulation2)
bool DumpDebugState(std::ostream &stream)
Definition: Simulation2.cpp:881
PS::Loader::Task ProgressiveLoad()
RegMemFun incremental loader function.
Definition: Simulation2.cpp:861
void SetStartupScript(const std::string &script)
Set a startup script, which will get executed before the first turn.
Definition: Simulation2.cpp:787
void Update(int turnLength)
Definition: Simulation2.cpp:758
Script::Interface & GetScriptInterface() const
Definition: Simulation2.cpp:734
void LoadMapSettings()
Loads the map settings script (called after map is loaded)
Definition: Simulation2.cpp:842
std::string GetMapSizes()
Get map sizes data.
Definition: Simulation2.cpp:978
std::string GetPlayerDefaults()
Get player default data.
Definition: Simulation2.cpp:973
const InterfaceListUnordered & GetEntitiesWithInterfaceUnordered(int iid)
Returns a list of components implementing the given interface, and their associated entities,...
Definition: Simulation2.cpp:724
Definition: UnitManager.h:39
Definition: IComponent.h:33
Coroutine which performs the actual work.
Definition: Loader.h:126
This interface accepts renderable objects.
Definition: Scene.h:90
Definition: Interface.h:93
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32
std::uint32_t entity_id_t
Entity ID type.
Definition: Entity.h:29
std::int64_t Status
Error handling system.
Definition: status.h:174
Definition: Simulation2.h:62
Simulation command, typically received over the network in multiplayer games.
Definition: SimulationCommand.h:39
Definition: DebugOptions.h:24