Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/Simulation2.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
class CSimulation2Impl | class CSimulation2Impl | ||||
{ | { | ||||
public: | public: | ||||
CSimulation2Impl(CUnitManager* unitManager, shared_ptr<ScriptRuntime> rt, CTerrain* terrain) : | CSimulation2Impl(CUnitManager* unitManager, shared_ptr<ScriptRuntime> rt, CTerrain* terrain) : | ||||
m_SimContext(), m_ComponentManager(m_SimContext, rt), | m_SimContext(), m_ComponentManager(m_SimContext, rt), | ||||
m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false), | m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false), | ||||
m_SecondaryTerrain(nullptr), m_SecondaryContext(nullptr), m_SecondaryComponentManager(nullptr), m_SecondaryLoadedScripts(nullptr), | m_SecondaryTerrain(nullptr), m_SecondaryContext(nullptr), m_SecondaryComponentManager(nullptr), m_SecondaryLoadedScripts(nullptr), | ||||
m_MapSettings(rt->m_rt), m_InitAttributes(rt->m_rt) | m_MapSettings(rt->GetJSRuntime()), m_InitAttributes(rt->GetJSRuntime()) | ||||
{ | { | ||||
m_SimContext.m_UnitManager = unitManager; | m_SimContext.m_UnitManager = unitManager; | ||||
m_SimContext.m_Terrain = terrain; | m_SimContext.m_Terrain = terrain; | ||||
m_ComponentManager.LoadComponentTypes(); | m_ComponentManager.LoadComponentTypes(); | ||||
RegisterFileReloadFunc(ReloadChangedFileCB, this); | RegisterFileReloadFunc(ReloadChangedFileCB, this); | ||||
// Tests won't have config initialised | // Tests won't have config initialised | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | static std::vector<SimulationCommand> CloneCommandsFromOtherContext(const ScriptInterface& oldScript, const ScriptInterface& newScript, | ||||
const std::vector<SimulationCommand>& commands) | const std::vector<SimulationCommand>& commands) | ||||
{ | { | ||||
std::vector<SimulationCommand> newCommands; | std::vector<SimulationCommand> newCommands; | ||||
newCommands.reserve(commands.size()); | newCommands.reserve(commands.size()); | ||||
ScriptInterface::Request rqNew(newScript); | ScriptInterface::Request rqNew(newScript); | ||||
for (const SimulationCommand& command : commands) | for (const SimulationCommand& command : commands) | ||||
{ | { | ||||
JS::RootedValue tmpCommand(rqNew.cx, newScript.CloneValueFromOtherContext(oldScript, command.data)); | JS::RootedValue tmpCommand(rqNew.cx, newScript.CloneValueFromOtherCompartment(oldScript, command.data)); | ||||
newScript.FreezeObject(tmpCommand, true); | newScript.FreezeObject(tmpCommand, true); | ||||
SimulationCommand cmd(command.player, rqNew.cx, tmpCommand); | SimulationCommand cmd(command.player, rqNew.cx, tmpCommand); | ||||
newCommands.emplace_back(std::move(cmd)); | newCommands.emplace_back(std::move(cmd)); | ||||
} | } | ||||
return newCommands; | return newCommands; | ||||
} | } | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | if (m_EnableSerializationTest || startRejoinTest) | ||||
m_SecondaryLoadedScripts = new std::set<VfsPath>(); | m_SecondaryLoadedScripts = new std::set<VfsPath>(); | ||||
ENSURE(LoadDefaultScripts(*m_SecondaryComponentManager, m_SecondaryLoadedScripts)); | ENSURE(LoadDefaultScripts(*m_SecondaryComponentManager, m_SecondaryLoadedScripts)); | ||||
ResetComponentState(*m_SecondaryComponentManager, false, false); | ResetComponentState(*m_SecondaryComponentManager, false, false); | ||||
// Load the trigger scripts after we have loaded the simulation. | // Load the trigger scripts after we have loaded the simulation. | ||||
{ | { | ||||
ScriptInterface::Request rq2(m_SecondaryComponentManager->GetScriptInterface()); | ScriptInterface::Request rq2(m_SecondaryComponentManager->GetScriptInterface()); | ||||
JS::RootedValue mapSettingsCloned(rq2.cx, | JS::RootedValue mapSettingsCloned(rq2.cx, | ||||
m_SecondaryComponentManager->GetScriptInterface().CloneValueFromOtherContext( | m_SecondaryComponentManager->GetScriptInterface().CloneValueFromOtherCompartment( | ||||
scriptInterface, m_MapSettings)); | scriptInterface, m_MapSettings)); | ||||
ENSURE(LoadTriggerScripts(*m_SecondaryComponentManager, mapSettingsCloned, m_SecondaryLoadedScripts)); | ENSURE(LoadTriggerScripts(*m_SecondaryComponentManager, mapSettingsCloned, m_SecondaryLoadedScripts)); | ||||
} | } | ||||
// Load the map into the secondary simulation | // Load the map into the secondary simulation | ||||
LDR_BeginRegistering(); | LDR_BeginRegistering(); | ||||
std::unique_ptr<CMapReader> mapReader(new CMapReader); | std::unique_ptr<CMapReader> mapReader(new CMapReader); | ||||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | |||||
ScriptInterface& CSimulation2::GetScriptInterface() const | ScriptInterface& CSimulation2::GetScriptInterface() const | ||||
{ | { | ||||
return m->m_ComponentManager.GetScriptInterface(); | return m->m_ComponentManager.GetScriptInterface(); | ||||
} | } | ||||
void CSimulation2::PreInitGame() | void CSimulation2::PreInitGame() | ||||
{ | { | ||||
ScriptInterface::Request rq(GetScriptInterface()); | ScriptInterface::Request rq(GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, GetScriptInterface().GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
GetScriptInterface().CallFunctionVoid(global, "PreInitGame"); | GetScriptInterface().CallFunctionVoid(global, "PreInitGame"); | ||||
} | } | ||||
void CSimulation2::InitGame() | void CSimulation2::InitGame() | ||||
{ | { | ||||
ScriptInterface::Request rq(GetScriptInterface()); | ScriptInterface::Request rq(GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, GetScriptInterface().GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
JS::RootedValue settings(rq.cx); | JS::RootedValue settings(rq.cx); | ||||
JS::RootedValue tmpInitAttributes(rq.cx, GetInitAttributes()); | JS::RootedValue tmpInitAttributes(rq.cx, GetInitAttributes()); | ||||
GetScriptInterface().GetProperty(tmpInitAttributes, "settings", &settings); | GetScriptInterface().GetProperty(tmpInitAttributes, "settings", &settings); | ||||
GetScriptInterface().CallFunctionVoid(global, "InitGame", settings); | GetScriptInterface().CallFunctionVoid(global, "InitGame", settings); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | |||||
void CSimulation2::GetMapSettings(JS::MutableHandleValue ret) | void CSimulation2::GetMapSettings(JS::MutableHandleValue ret) | ||||
{ | { | ||||
ret.set(m->m_MapSettings); | ret.set(m->m_MapSettings); | ||||
} | } | ||||
void CSimulation2::LoadPlayerSettings(bool newPlayers) | void CSimulation2::LoadPlayerSettings(bool newPlayers) | ||||
{ | { | ||||
ScriptInterface::Request rq(GetScriptInterface()); | ScriptInterface::Request rq(GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, GetScriptInterface().GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", m->m_MapSettings, newPlayers); | GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", m->m_MapSettings, newPlayers); | ||||
} | } | ||||
void CSimulation2::LoadMapSettings() | void CSimulation2::LoadMapSettings() | ||||
{ | { | ||||
ScriptInterface::Request rq(GetScriptInterface()); | ScriptInterface::Request rq(GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, GetScriptInterface().GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
// Initialize here instead of in Update() | // Initialize here instead of in Update() | ||||
GetScriptInterface().CallFunctionVoid(global, "LoadMapSettings", m->m_MapSettings); | GetScriptInterface().CallFunctionVoid(global, "LoadMapSettings", m->m_MapSettings); | ||||
GetScriptInterface().FreezeObject(m->m_InitAttributes, true); | GetScriptInterface().FreezeObject(m->m_InitAttributes, true); | ||||
GetScriptInterface().SetGlobal("InitAttributes", m->m_InitAttributes, true, true, true); | GetScriptInterface().SetGlobal("InitAttributes", m->m_InitAttributes, true, true, true); | ||||
if (!m->m_StartupScript.empty()) | if (!m->m_StartupScript.empty()) | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator