Ticket #4199: Simulation2.cpp.patch

File Simulation2.cpp.patch, 4.7 KB (added by Imarok, 8 years ago)

fixes the thing. Only problem: InitGame in InitGame.js expects InitAttributes.settings being undefined when loading a map in atlas: // No settings when loading a map in Atlas, so do nothing (L29)

  • source/simulation2/Simulation2.cpp

     
    5151public:
    5252    CSimulation2Impl(CUnitManager* unitManager, shared_ptr<ScriptRuntime> rt, CTerrain* terrain) :
    5353        m_SimContext(), m_ComponentManager(m_SimContext, rt),
    54         m_EnableOOSLog(false), m_EnableSerializationTest(false),
    55         m_MapSettings(rt->m_rt), m_InitAttributes(rt->m_rt)
     54        m_EnableOOSLog(false), m_EnableSerializationTest(false), m_InitAttributes(rt->m_rt)
    5655    {
    5756        m_SimContext.m_UnitManager = unitManager;
    5857        m_SimContext.m_Terrain = terrain;
     
    118117
    119118    std::string m_StartupScript;
    120119    JS::PersistentRootedValue m_InitAttributes;
    121     JS::PersistentRootedValue m_MapSettings;
    122120
    123121    std::set<VfsPath> m_LoadedScripts;
    124122
     
    364362        ENSURE(LoadDefaultScripts(secondaryComponentManager, &secondaryLoadedScripts));
    365363        ResetComponentState(secondaryComponentManager, false, false);
    366364
     365        JSContext* cx = scriptInterface.GetContext();
     366        JSAutoRequest rq(cx);
     367        JS::RootedValue mapSettings(cx);
     368        scriptInterface.GetProperty(m_InitAttributes, "settings", &mapSettings);
    367369        // Load the trigger scripts after we have loaded the simulation.
    368370        {
    369371            JSContext* cx2 = secondaryComponentManager.GetScriptInterface().GetContext();
     
    370372            JSAutoRequest rq2(cx2);
    371373            JS::RootedValue mapSettingsCloned(cx2,
    372374                secondaryComponentManager.GetScriptInterface().CloneValueFromOtherContext(
    373                     scriptInterface, m_MapSettings));
     375                scriptInterface, mapSettings));
    374376            ENSURE(LoadTriggerScripts(secondaryComponentManager, mapSettingsCloned, &secondaryLoadedScripts));
    375377        }
    376378
     
    746748
    747749void CSimulation2::SetMapSettings(const std::string& settings)
    748750{
    749     m->m_ComponentManager.GetScriptInterface().ParseJSON(settings, &m->m_MapSettings);
     751    ScriptInterface& scriptInterface = m->m_ComponentManager.GetScriptInterface();
     752    JSContext* cx = scriptInterface.GetContext();
     753    JSAutoRequest rq(cx);
     754    JS::RootedValue mapSettings(cx);
     755
     756    scriptInterface.ParseJSON(settings, &mapSettings);
     757    scriptInterface.SetProperty(m->m_InitAttributes, "settings", mapSettings);
    750758}
    751759
    752760void CSimulation2::SetMapSettings(JS::HandleValue settings)
    753761{
    754     m->m_MapSettings = settings;
     762    ScriptInterface& scriptInterface = m->m_ComponentManager.GetScriptInterface();
     763    scriptInterface.SetProperty(m->m_InitAttributes, "settings", settings);
    755764
    756765    u32 seed = 0;
    757     if (!m->m_ComponentManager.GetScriptInterface().GetProperty(m->m_MapSettings, "Seed", seed))
     766    if (!scriptInterface.GetProperty(settings, "Seed", seed))
    758767        LOGWARNING("CSimulation2::SetInitAttributes: No seed value specified - using %d", seed);
    759768
    760769    m->m_ComponentManager.SetRNGSeed(seed);
     
    762771
    763772std::string CSimulation2::GetMapSettingsString()
    764773{
    765     return m->m_ComponentManager.GetScriptInterface().StringifyJSON(&m->m_MapSettings);
     774    ScriptInterface& scriptInterface = m->m_ComponentManager.GetScriptInterface();
     775    JSContext* cx = scriptInterface.GetContext();
     776    JSAutoRequest rq(cx);
     777    JS::RootedValue mapSettings(cx);
     778    GetMapSettings(&mapSettings);
     779    return scriptInterface.StringifyJSON(&mapSettings);
    766780}
    767781
    768782void CSimulation2::GetMapSettings(JS::MutableHandleValue ret)
    769783{
    770     ret.set(m->m_MapSettings);
     784    m->m_ComponentManager.GetScriptInterface().GetProperty(m->m_InitAttributes, "settings", ret);
    771785}
    772786
    773787void CSimulation2::LoadPlayerSettings(bool newPlayers)
     
    774788{
    775789    JSContext* cx = GetScriptInterface().GetContext();
    776790    JSAutoRequest rq(cx);
     791    JS::RootedValue mapSettings(cx);
     792    GetMapSettings(&mapSettings);
    777793    JS::RootedValue global(cx, GetScriptInterface().GetGlobalObject());
    778     GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", m->m_MapSettings, newPlayers);
     794    GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", mapSettings, newPlayers);
    779795}
    780796
    781797void CSimulation2::LoadMapSettings()
     
    782798{
    783799    JSContext* cx = GetScriptInterface().GetContext();
    784800    JSAutoRequest rq(cx);
     801    JS::RootedValue mapSettings(cx);
     802    GetMapSettings(&mapSettings);
    785803
    786804    JS::RootedValue global(cx, GetScriptInterface().GetGlobalObject());
    787805
    788806    // Initialize here instead of in Update()
    789     GetScriptInterface().CallFunctionVoid(global, "LoadMapSettings", m->m_MapSettings);
     807    GetScriptInterface().CallFunctionVoid(global, "LoadMapSettings", mapSettings);
    790808
    791809    if (!m->m_StartupScript.empty())
    792810        GetScriptInterface().LoadScript(L"map startup script", m->m_StartupScript);
    793811
    794812    // Load the trigger scripts after we have loaded the simulation and the map.
    795     m->LoadTriggerScripts(m->m_ComponentManager, m->m_MapSettings, &m->m_LoadedScripts);
     813    m->LoadTriggerScripts(m->m_ComponentManager, mapSettings, &m->m_LoadedScripts);
    796814}
    797815
    798816int CSimulation2::ProgressiveLoad()