Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/Simulation2.cpp
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | public: | ||||
void InitRNGSeedAI(); | void InitRNGSeedAI(); | ||||
static std::vector<SimulationCommand> CloneCommandsFromOtherContext(const ScriptInterface& oldScript, const ScriptInterface& newScript, | 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); | ScriptRequest rqNew(newScript); | ||||
for (const SimulationCommand& command : commands) | for (const SimulationCommand& command : commands) | ||||
{ | { | ||||
JS::RootedValue tmpCommand(rqNew.cx, newScript.CloneValueFromOtherCompartment(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 234 Lines • ▼ Show 20 Lines | if (m_EnableSerializationTest || startRejoinTest) | ||||
delete m_SecondaryLoadedScripts; | delete m_SecondaryLoadedScripts; | ||||
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()); | ScriptRequest rq2(m_SecondaryComponentManager->GetScriptInterface()); | ||||
JS::RootedValue mapSettingsCloned(rq2.cx, | JS::RootedValue mapSettingsCloned(rq2.cx, | ||||
m_SecondaryComponentManager->GetScriptInterface().CloneValueFromOtherCompartment( | 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 | ||||
▲ Show 20 Lines • Show All 295 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()); | ScriptRequest rq(GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, rq.globalValue()); | 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()); | ScriptRequest rq(GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, rq.globalValue()); | 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()); | ScriptRequest rq(GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, rq.globalValue()); | 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()); | ScriptRequest rq(GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, rq.globalValue()); | 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); | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | |||||
std::string CSimulation2::GetMapSizes() | std::string CSimulation2::GetMapSizes() | ||||
{ | { | ||||
return ReadJSON(L"simulation/data/settings/map_sizes.json"); | return ReadJSON(L"simulation/data/settings/map_sizes.json"); | ||||
} | } | ||||
std::string CSimulation2::GetAIData() | std::string CSimulation2::GetAIData() | ||||
{ | { | ||||
const ScriptInterface& scriptInterface = GetScriptInterface(); | const ScriptInterface& scriptInterface = GetScriptInterface(); | ||||
ScriptInterface::Request rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
JS::RootedValue aiData(rq.cx, ICmpAIManager::GetAIs(scriptInterface)); | JS::RootedValue aiData(rq.cx, ICmpAIManager::GetAIs(scriptInterface)); | ||||
// Build single JSON string with array of AI data | // Build single JSON string with array of AI data | ||||
JS::RootedValue ais(rq.cx); | JS::RootedValue ais(rq.cx); | ||||
if (!ScriptInterface::CreateObject(rq, &ais, "AIData", aiData)) | if (!ScriptInterface::CreateObject(rq, &ais, "AIData", aiData)) | ||||
return std::string(); | return std::string(); | ||||
return scriptInterface.StringifyJSON(&ais); | return scriptInterface.StringifyJSON(&ais); | ||||
} | } |
Wildfire Games · Phabricator