Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/Simulation2.cpp
Show All 16 Lines | |||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "Simulation2.h" | #include "Simulation2.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | #include "scriptinterface/FunctionWrapper.h" | ||||
#include "scriptinterface/ScriptContext.h" | #include "scriptinterface/ScriptContext.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/StructuredClone.h" | |||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
#include "simulation2/system/ComponentManager.h" | #include "simulation2/system/ComponentManager.h" | ||||
#include "simulation2/system/ParamNode.h" | #include "simulation2/system/ParamNode.h" | ||||
#include "simulation2/system/SimContext.h" | #include "simulation2/system/SimContext.h" | ||||
#include "simulation2/components/ICmpAIManager.h" | #include "simulation2/components/ICmpAIManager.h" | ||||
#include "simulation2/components/ICmpCommandQueue.h" | #include "simulation2/components/ICmpCommandQueue.h" | ||||
#include "simulation2/components/ICmpTemplateManager.h" | #include "simulation2/components/ICmpTemplateManager.h" | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | public: | ||||
void ReportSerializationFailure( | void ReportSerializationFailure( | ||||
SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter, | SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter, | ||||
SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter); | SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter); | ||||
void InitRNGSeedSimulation(); | void InitRNGSeedSimulation(); | ||||
void InitRNGSeedAI(); | void InitRNGSeedAI(); | ||||
static std::vector<SimulationCommand> CloneCommandsFromOtherCompartment(const ScriptInterface& oldScript, const ScriptInterface& newScript, | static std::vector<SimulationCommand> CloneCommandsFromOtherCompartment(const ScriptInterface& newScript, const ScriptInterface& oldScript, | ||||
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()); | ||||
ScriptRequest 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, Script::CloneValueFromOtherCompartment(newScript, 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 227 Lines • ▼ Show 20 Lines | if (m_EnableSerializationTest || startRejoinTest) | ||||
m_SecondaryComponentManager->LoadComponentTypes(); | m_SecondaryComponentManager->LoadComponentTypes(); | ||||
m_SecondaryLoadedScripts = std::make_unique<std::set<VfsPath>>(); | m_SecondaryLoadedScripts = std::make_unique<std::set<VfsPath>>(); | ||||
ENSURE(LoadDefaultScripts(*m_SecondaryComponentManager, m_SecondaryLoadedScripts.get())); | ENSURE(LoadDefaultScripts(*m_SecondaryComponentManager, m_SecondaryLoadedScripts.get())); | ||||
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. | ||||
{ | { | ||||
ScriptRequest rq(scriptInterface); | |||||
ScriptRequest rq2(m_SecondaryComponentManager->GetScriptInterface()); | ScriptRequest rq2(m_SecondaryComponentManager->GetScriptInterface()); | ||||
JS::RootedValue mapSettingsCloned(rq2.cx, | JS::RootedValue mapSettingsCloned(rq2.cx, Script::CloneValueFromOtherCompartment(m_SecondaryComponentManager->GetScriptInterface(), scriptInterface, m_MapSettings)); | ||||
m_SecondaryComponentManager->GetScriptInterface().CloneValueFromOtherCompartment(scriptInterface, m_MapSettings)); | |||||
ENSURE(LoadTriggerScripts(*m_SecondaryComponentManager, mapSettingsCloned, m_SecondaryLoadedScripts.get())); | ENSURE(LoadTriggerScripts(*m_SecondaryComponentManager, mapSettingsCloned, m_SecondaryLoadedScripts.get())); | ||||
} | } | ||||
// Load the map into the secondary simulation | // Load the map into the secondary simulation | ||||
LDR_BeginRegistering(); | LDR_BeginRegistering(); | ||||
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>(); | std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>(); | ||||
Show All 36 Lines | if (m_EnableSerializationTest || m_TestingRejoin) | ||||
} | } | ||||
SerializationTestState primaryStateAfter; | SerializationTestState primaryStateAfter; | ||||
ENSURE(m_ComponentManager.SerializeState(primaryStateAfter.state)); | ENSURE(m_ComponentManager.SerializeState(primaryStateAfter.state)); | ||||
if (serializationTestHash) | if (serializationTestHash) | ||||
ENSURE(m_ComponentManager.ComputeStateHash(primaryStateAfter.hash, false)); | ENSURE(m_ComponentManager.ComputeStateHash(primaryStateAfter.hash, false)); | ||||
UpdateComponents(*m_SecondaryContext, turnLengthFixed, | UpdateComponents(*m_SecondaryContext, turnLengthFixed, | ||||
CloneCommandsFromOtherCompartment(scriptInterface, m_SecondaryComponentManager->GetScriptInterface(), commands)); | CloneCommandsFromOtherCompartment(m_SecondaryComponentManager->GetScriptInterface(), scriptInterface, commands)); | ||||
SerializationTestState secondaryStateAfter; | SerializationTestState secondaryStateAfter; | ||||
ENSURE(m_SecondaryComponentManager->SerializeState(secondaryStateAfter.state)); | ENSURE(m_SecondaryComponentManager->SerializeState(secondaryStateAfter.state)); | ||||
if (serializationTestHash) | if (serializationTestHash) | ||||
ENSURE(m_SecondaryComponentManager->ComputeStateHash(secondaryStateAfter.hash, false)); | ENSURE(m_SecondaryComponentManager->ComputeStateHash(secondaryStateAfter.hash, false)); | ||||
if (primaryStateAfter.state.str() != secondaryStateAfter.state.str() || | if (primaryStateAfter.state.str() != secondaryStateAfter.state.str() || | ||||
primaryStateAfter.hash != secondaryStateAfter.hash) | primaryStateAfter.hash != secondaryStateAfter.hash) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 516 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator