Ticket #4199: Simulation2.cpp.patch
File Simulation2.cpp.patch, 4.7 KB (added by , 8 years ago) |
---|
-
source/simulation2/Simulation2.cpp
51 51 public: 52 52 CSimulation2Impl(CUnitManager* unitManager, shared_ptr<ScriptRuntime> rt, CTerrain* terrain) : 53 53 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) 56 55 { 57 56 m_SimContext.m_UnitManager = unitManager; 58 57 m_SimContext.m_Terrain = terrain; … … 118 117 119 118 std::string m_StartupScript; 120 119 JS::PersistentRootedValue m_InitAttributes; 121 JS::PersistentRootedValue m_MapSettings;122 120 123 121 std::set<VfsPath> m_LoadedScripts; 124 122 … … 364 362 ENSURE(LoadDefaultScripts(secondaryComponentManager, &secondaryLoadedScripts)); 365 363 ResetComponentState(secondaryComponentManager, false, false); 366 364 365 JSContext* cx = scriptInterface.GetContext(); 366 JSAutoRequest rq(cx); 367 JS::RootedValue mapSettings(cx); 368 scriptInterface.GetProperty(m_InitAttributes, "settings", &mapSettings); 367 369 // Load the trigger scripts after we have loaded the simulation. 368 370 { 369 371 JSContext* cx2 = secondaryComponentManager.GetScriptInterface().GetContext(); … … 370 372 JSAutoRequest rq2(cx2); 371 373 JS::RootedValue mapSettingsCloned(cx2, 372 374 secondaryComponentManager.GetScriptInterface().CloneValueFromOtherContext( 373 scriptInterface, m_MapSettings));375 scriptInterface, mapSettings)); 374 376 ENSURE(LoadTriggerScripts(secondaryComponentManager, mapSettingsCloned, &secondaryLoadedScripts)); 375 377 } 376 378 … … 746 748 747 749 void CSimulation2::SetMapSettings(const std::string& settings) 748 750 { 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); 750 758 } 751 759 752 760 void CSimulation2::SetMapSettings(JS::HandleValue settings) 753 761 { 754 m->m_MapSettings = settings; 762 ScriptInterface& scriptInterface = m->m_ComponentManager.GetScriptInterface(); 763 scriptInterface.SetProperty(m->m_InitAttributes, "settings", settings); 755 764 756 765 u32 seed = 0; 757 if (! m->m_ComponentManager.GetScriptInterface().GetProperty(m->m_MapSettings, "Seed", seed))766 if (!scriptInterface.GetProperty(settings, "Seed", seed)) 758 767 LOGWARNING("CSimulation2::SetInitAttributes: No seed value specified - using %d", seed); 759 768 760 769 m->m_ComponentManager.SetRNGSeed(seed); … … 762 771 763 772 std::string CSimulation2::GetMapSettingsString() 764 773 { 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); 766 780 } 767 781 768 782 void CSimulation2::GetMapSettings(JS::MutableHandleValue ret) 769 783 { 770 ret.set(m->m_MapSettings);784 m->m_ComponentManager.GetScriptInterface().GetProperty(m->m_InitAttributes, "settings", ret); 771 785 } 772 786 773 787 void CSimulation2::LoadPlayerSettings(bool newPlayers) … … 774 788 { 775 789 JSContext* cx = GetScriptInterface().GetContext(); 776 790 JSAutoRequest rq(cx); 791 JS::RootedValue mapSettings(cx); 792 GetMapSettings(&mapSettings); 777 793 JS::RootedValue global(cx, GetScriptInterface().GetGlobalObject()); 778 GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", m ->m_MapSettings, newPlayers);794 GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", mapSettings, newPlayers); 779 795 } 780 796 781 797 void CSimulation2::LoadMapSettings() … … 782 798 { 783 799 JSContext* cx = GetScriptInterface().GetContext(); 784 800 JSAutoRequest rq(cx); 801 JS::RootedValue mapSettings(cx); 802 GetMapSettings(&mapSettings); 785 803 786 804 JS::RootedValue global(cx, GetScriptInterface().GetGlobalObject()); 787 805 788 806 // Initialize here instead of in Update() 789 GetScriptInterface().CallFunctionVoid(global, "LoadMapSettings", m ->m_MapSettings);807 GetScriptInterface().CallFunctionVoid(global, "LoadMapSettings", mapSettings); 790 808 791 809 if (!m->m_StartupScript.empty()) 792 810 GetScriptInterface().LoadScript(L"map startup script", m->m_StartupScript); 793 811 794 812 // 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); 796 814 } 797 815 798 816 int CSimulation2::ProgressiveLoad()