Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/Simulation2.cpp
Show First 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationCommand>& commands) | ||||
* simulations run independantly while comparing their states each turn. This is way faster than a | * simulations run independantly while comparing their states each turn. This is way faster than a | ||||
* complete serialization test and allows us to reproduce OOSes on rejoin. | * complete serialization test and allows us to reproduce OOSes on rejoin. | ||||
*/ | */ | ||||
const bool serializationTestDebugDump = false; // set true to save human-readable state dumps before an error is detected, for debugging (but slow) | const bool serializationTestDebugDump = false; // set true to save human-readable state dumps before an error is detected, for debugging (but slow) | ||||
const bool serializationTestHash = true; // set true to save and compare hash of state | const bool serializationTestHash = true; // set true to save and compare hash of state | ||||
SerializationTestState primaryStateBefore; | SerializationTestState primaryStateBefore; | ||||
ScriptInterface& scriptInterface = m_ComponentManager.GetScriptInterface(); | const ScriptInterface& scriptInterface = m_ComponentManager.GetScriptInterface(); | ||||
const bool startRejoinTest = (int64_t) m_RejoinTestTurn == m_TurnNumber; | const bool startRejoinTest = (int64_t) m_RejoinTestTurn == m_TurnNumber; | ||||
if (startRejoinTest) | if (startRejoinTest) | ||||
m_TestingRejoin = true; | m_TestingRejoin = true; | ||||
if (m_EnableSerializationTest || m_TestingRejoin) | if (m_EnableSerializationTest || m_TestingRejoin) | ||||
{ | { | ||||
ENSURE(m_ComponentManager.SerializeState(primaryStateBefore.state)); | ENSURE(m_ComponentManager.SerializeState(primaryStateBefore.state)); | ||||
▲ Show 20 Lines • Show All 573 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() | ||||
{ | { | ||||
ScriptInterface& scriptInterface = GetScriptInterface(); | const ScriptInterface& scriptInterface = GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue aiData(cx, ICmpAIManager::GetAIs(scriptInterface)); | JS::RootedValue aiData(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(cx); | JS::RootedValue ais(cx); | ||||
if (!scriptInterface.Eval("({})", &ais) || !scriptInterface.SetProperty(ais, "AIData", aiData)) | if (!scriptInterface.Eval("({})", &ais) || !scriptInterface.SetProperty(ais, "AIData", aiData)) | ||||
return std::string(); | return std::string(); | ||||
return scriptInterface.StringifyJSON(&ais); | return scriptInterface.StringifyJSON(&ais); | ||||
} | } |
Wildfire Games · Phabricator