Index: source/gui/GUIManager.cpp =================================================================== --- source/gui/GUIManager.cpp +++ source/gui/GUIManager.cpp @@ -380,7 +380,7 @@ // We share the script context with everything else that runs in the same thread. // This call makes sure we trigger GC regularly even if the simulation is not running. - m_ScriptInterface->GetContext()->MaybeIncrementalGC(1.0f); + m_ScriptInterface->GetContext().MaybeIncrementalGC(1.0f); // Save an immutable copy so iterators aren't invalidated by tick handlers PageStackType pageStack = m_PageStack; Index: source/network/NetServer.cpp =================================================================== --- source/network/NetServer.cpp +++ source/network/NetServer.cpp @@ -445,7 +445,7 @@ // (Do as little work as possible while the mutex is held open, // to avoid performance problems and deadlocks.) - m_ScriptInterface->GetContext()->MaybeIncrementalGC(0.5f); + m_ScriptInterface->GetContext().MaybeIncrementalGC(0.5f); ScriptRequest rq(m_ScriptInterface); Index: source/ps/Game.cpp =================================================================== --- source/ps/Game.cpp +++ source/ps/Game.cpp @@ -254,7 +254,7 @@ Script::GetProperty(rq, attribs, "script", scriptFile); Script::GetProperty(rq, attribs, "settings", &settings); - m_World->RegisterInitRMS(scriptFile, *scriptInterface.GetContext(), settings, m_PlayerID); + m_World->RegisterInitRMS(scriptFile, scriptInterface.GetContext(), settings, m_PlayerID); } else { @@ -263,7 +263,7 @@ Script::GetProperty(rq, attribs, "map", mapFile); Script::GetProperty(rq, attribs, "settings", &settings); - m_World->RegisterInit(mapFile, *scriptInterface.GetContext(), settings, m_PlayerID); + m_World->RegisterInit(mapFile, scriptInterface.GetContext(), settings, m_PlayerID); } if (m_GameView) LDR_Register([&waterManager = g_Renderer.GetSceneRenderer().GetWaterManager()](const double) Index: source/scriptinterface/ScriptInterface.h =================================================================== --- source/scriptinterface/ScriptInterface.h +++ source/scriptinterface/ScriptInterface.h @@ -83,7 +83,15 @@ * @param debugName Name of this interface for CScriptStats purposes. * @param context ScriptContext to use when initializing this interface. */ - ScriptInterface(const char* nativeScopeName, const char* debugName, const std::shared_ptr& context); + ScriptInterface(const char* nativeScopeName, const char* debugName, ScriptContext& context); + + template + ScriptInterface(const char* nativeScopeName, const char* debugName, Context&& context) : + ScriptInterface(nativeScopeName, debugName, *context) + { + static_assert(std::is_lvalue_reference_v, "`ScriptInterface` doesn't take ownership " + "of the context."); + } /** * Alternate constructor. This creates the new Realm in the same Compartment as the neighbor scriptInterface. @@ -137,7 +145,7 @@ * ScriptInterface::Request and use the context from that. */ JSContext* GetGeneralJSContext() const; - std::shared_ptr GetContext() const; + ScriptContext& GetContext() const; /** * Load global scripts that most script interfaces need, Index: source/scriptinterface/ScriptInterface.cpp =================================================================== --- source/scriptinterface/ScriptInterface.cpp +++ source/scriptinterface/ScriptInterface.cpp @@ -52,12 +52,12 @@ struct ScriptInterface_impl { - ScriptInterface_impl(const char* nativeScopeName, const std::shared_ptr& context, JS::Compartment* compartment); + ScriptInterface_impl(const char* nativeScopeName, ScriptContext& context, JS::Compartment* compartment); ~ScriptInterface_impl(); // Take care to keep this declaration before heap rooted members. Destructors of heap rooted // members have to be called before the context destructor. - std::shared_ptr m_context; + ScriptContext& m_context; friend ScriptRequest; private: @@ -300,8 +300,10 @@ return true; } -ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const std::shared_ptr& context, JS::Compartment* compartment) : - m_context(context), m_cx(context->GetGeneralJSContext()), m_glob(context->GetGeneralJSContext()), m_nativeScope(context->GetGeneralJSContext()) +ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, ScriptContext& context, + JS::Compartment* compartment) : + m_context(context), m_cx(context.GetGeneralJSContext()), m_glob(context.GetGeneralJSContext()), + m_nativeScope(context.GetGeneralJSContext()) { JS::RealmCreationOptions creationOpt; // Keep JIT code during non-shrinking GCs. This brings a quite big performance improvement. @@ -339,15 +341,15 @@ ScriptFunction::Register<&ProfileStop>(m_cx, m_nativeScope, "ProfileStop"); ScriptFunction::Register<&ProfileAttribute>(m_cx, m_nativeScope, "ProfileAttribute"); - m_context->RegisterRealm(JS::GetObjectRealmOrNull(m_glob)); + m_context.RegisterRealm(JS::GetObjectRealmOrNull(m_glob)); } ScriptInterface_impl::~ScriptInterface_impl() { - m_context->UnRegisterRealm(JS::GetObjectRealmOrNull(m_glob)); + m_context.UnRegisterRealm(JS::GetObjectRealmOrNull(m_glob)); } -ScriptInterface::ScriptInterface(const char* nativeScopeName, const char* debugName, const std::shared_ptr& context) : +ScriptInterface::ScriptInterface(const char* nativeScopeName, const char* debugName, ScriptContext& context) : m(std::make_unique(nativeScopeName, context, nullptr)) { // Profiler stats table isn't thread-safe, so only enable this on the main thread @@ -456,10 +458,10 @@ JSContext* ScriptInterface::GetGeneralJSContext() const { - return m->m_context->GetGeneralJSContext(); + return m->m_context.GetGeneralJSContext(); } -std::shared_ptr ScriptInterface::GetContext() const +ScriptContext& ScriptInterface::GetContext() const { return m->m_context; } Index: source/simulation2/Simulation2.cpp =================================================================== --- source/simulation2/Simulation2.cpp +++ source/simulation2/Simulation2.cpp @@ -54,7 +54,7 @@ { public: CSimulation2Impl(CUnitManager* unitManager, std::shared_ptr cx, CTerrain* terrain) : - m_SimContext(), m_ComponentManager(m_SimContext, cx), + m_SimContext(), m_ComponentManager(m_SimContext, *cx), m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false), m_MapSettings(cx->GetGeneralJSContext()), m_InitAttributes(cx->GetGeneralJSContext()) { @@ -443,7 +443,7 @@ Script::GetProperty(rq, m_InitAttributes, "map", mapFile); VfsPath mapfilename = VfsPath(mapFile).ChangeExtension(L".pmp"); - mapReader->LoadMap(mapfilename, *scriptInterface.GetContext(), JS::UndefinedHandleValue, + mapReader->LoadMap(mapfilename, scriptInterface.GetContext(), JS::UndefinedHandleValue, m_SecondaryTerrain.get(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, m_SecondaryContext.get(), INVALID_PLAYER, true); // throws exception on failure } @@ -502,9 +502,9 @@ // (TODO: we ought to schedule this for a frame where we're not // running the sim update, to spread the load) if (m_TurnNumber % 500 == 0) - scriptInterface.GetContext()->ShrinkingGC(); + scriptInterface.GetContext().ShrinkingGC(); else - scriptInterface.GetContext()->MaybeIncrementalGC(0.0f); + scriptInterface.GetContext().MaybeIncrementalGC(0.0f); if (m_EnableOOSLog) DumpState(); Index: source/simulation2/components/tests/test_CinemaManager.h =================================================================== --- source/simulation2/components/tests/test_CinemaManager.h +++ source/simulation2/components/tests/test_CinemaManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -34,7 +34,7 @@ void test_basic() { - ComponentTestHelper test(g_ScriptContext); + ComponentTestHelper test(*g_ScriptContext); ICmpCinemaManager* cmp = test.Add(CID_CinemaManager, "", SYSTEM_ENTITY); Index: source/simulation2/components/tests/test_CommandQueue.h =================================================================== --- source/simulation2/components/tests/test_CommandQueue.h +++ source/simulation2/components/tests/test_CommandQueue.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -34,7 +34,7 @@ void test_basic() { - ComponentTestHelper test(g_ScriptContext); + ComponentTestHelper test(*g_ScriptContext); ScriptRequest rq(test.GetScriptInterface()); std::vector empty; Index: source/simulation2/components/tests/test_ObstructionManager.h =================================================================== --- source/simulation2/components/tests/test_ObstructionManager.h +++ source/simulation2/components/tests/test_ObstructionManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -103,7 +103,7 @@ ent3z = ent2z + ent2c + ent3c; // ensure it just touches the border of ent2 ent3g = ent3; - testHelper = new ComponentTestHelper(g_ScriptContext); + testHelper = new ComponentTestHelper(*g_ScriptContext); cmp = testHelper->Add(CID_ObstructionManager, "", SYSTEM_ENTITY); cmp->SetBounds(fixed::FromInt(0), fixed::FromInt(0), fixed::FromInt(1000), fixed::FromInt(1000)); Index: source/simulation2/components/tests/test_Pathfinder.h =================================================================== --- source/simulation2/components/tests/test_Pathfinder.h +++ source/simulation2/components/tests/test_Pathfinder.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -145,7 +145,7 @@ LDR_BeginRegistering(); mapReader->LoadMap(L"maps/skirmishes/Median Oasis (2).pmp", - *sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, + sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &sim2, &sim2.GetSimContext(), -1, false); LDR_EndRegistering(); @@ -259,7 +259,7 @@ LDR_BeginRegistering(); mapReader->LoadMap(L"maps/scenarios/Peloponnese.pmp", - *sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, + sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &sim2, &sim2.GetSimContext(), -1, false); LDR_EndRegistering(); @@ -316,7 +316,7 @@ LDR_BeginRegistering(); mapReader->LoadMap(L"maps/scenarios/Peloponnese.pmp", - *sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, + sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &sim2, &sim2.GetSimContext(), -1, false); LDR_EndRegistering(); Index: source/simulation2/components/tests/test_Position.h =================================================================== --- source/simulation2/components/tests/test_Position.h +++ source/simulation2/components/tests/test_Position.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -65,7 +65,7 @@ void test_basic() { - ComponentTestHelper test(g_ScriptContext); + ComponentTestHelper test(*g_ScriptContext); MockTerrain terrain; test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain); @@ -137,7 +137,7 @@ void test_water() { - ComponentTestHelper test(g_ScriptContext); + ComponentTestHelper test(*g_ScriptContext); MockTerrain terrain; test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain); @@ -210,7 +210,7 @@ void test_serialize() { - ComponentTestHelper test(g_ScriptContext); + ComponentTestHelper test(*g_ScriptContext); MockTerrain terrain; test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain); Index: source/simulation2/components/tests/test_RangeManager.h =================================================================== --- source/simulation2/components/tests/test_RangeManager.h +++ source/simulation2/components/tests/test_RangeManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -130,7 +130,7 @@ void test_basic() { - ComponentTestHelper test(g_ScriptContext); + ComponentTestHelper test(*g_ScriptContext); ICmpRangeManager* cmp = test.Add(CID_RangeManager, "", SYSTEM_ENTITY); @@ -199,7 +199,7 @@ void test_queries() { - ComponentTestHelper test(g_ScriptContext); + ComponentTestHelper test(*g_ScriptContext); ICmpRangeManager* cmp = test.Add(CID_RangeManager, "", SYSTEM_ENTITY); @@ -271,7 +271,7 @@ void test_IsInTargetParabolicRange() { - ComponentTestHelper test(g_ScriptContext); + ComponentTestHelper test(*g_ScriptContext); ICmpRangeManager* cmp = test.Add(CID_RangeManager, "", SYSTEM_ENTITY); const entity_id_t source = 200; const entity_id_t target = 201; Index: source/simulation2/components/tests/test_scripts.h =================================================================== --- source/simulation2/components/tests/test_scripts.h +++ source/simulation2/components/tests/test_scripts.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -90,7 +90,7 @@ for (const VfsPath& path : paths) { CSimContext context; - CComponentManager componentManager(context, g_ScriptContext, true); + CComponentManager componentManager(context, *g_ScriptContext, true); ScriptTestSetup(componentManager.GetScriptInterface()); ScriptRequest rq(componentManager.GetScriptInterface()); @@ -117,7 +117,7 @@ // Clean up previous scripts. g_ScriptContext->ShrinkingGC(); CSimContext context; - CComponentManager componentManager(context, g_ScriptContext, true); + CComponentManager componentManager(context, *g_ScriptContext, true); ScriptTestSetup(componentManager.GetScriptInterface()); Index: source/simulation2/system/ComponentManager.h =================================================================== --- source/simulation2/system/ComponentManager.h +++ source/simulation2/system/ComponentManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -74,7 +74,7 @@ }; public: - CComponentManager(CSimContext&, std::shared_ptr cx, bool skipScriptFunctions = false); + CComponentManager(CSimContext&, ScriptContext& cx, bool skipScriptFunctions = false); ~CComponentManager(); void LoadComponentTypes(); Index: source/simulation2/system/ComponentManager.cpp =================================================================== --- source/simulation2/system/ComponentManager.cpp +++ source/simulation2/system/ComponentManager.cpp @@ -57,7 +57,7 @@ JS::PersistentRootedValue msg; }; -CComponentManager::CComponentManager(CSimContext& context, std::shared_ptr cx, bool skipScriptFunctions) : +CComponentManager::CComponentManager(CSimContext& context, ScriptContext& cx, bool skipScriptFunctions) : m_NextScriptComponentTypeId(CID__LastNative), m_ScriptInterface("Engine", "Simulation", cx), m_SimContext(context), m_CurrentlyHotloading(false) Index: source/simulation2/system/ComponentTest.h =================================================================== --- source/simulation2/system/ComponentTest.h +++ source/simulation2/system/ComponentTest.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -55,7 +55,7 @@ bool m_isSystemEntityInit = false; public: - ComponentTestHelper(std::shared_ptr scriptContext) : + ComponentTestHelper(ScriptContext& scriptContext) : m_Context(), m_ComponentManager(m_Context, scriptContext), m_Cmp(NULL) { m_ComponentManager.LoadComponentTypes(); Index: source/simulation2/tests/test_CmpTemplateManager.h =================================================================== --- source/simulation2/tests/test_CmpTemplateManager.h +++ source/simulation2/tests/test_CmpTemplateManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -54,7 +54,7 @@ void test_LoadTemplate() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -88,7 +88,7 @@ void test_LoadTemplate_scriptcache() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -148,7 +148,7 @@ void test_LoadTemplate_errors() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -180,7 +180,7 @@ void test_LoadTemplate_multiple() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; Index: source/simulation2/tests/test_ComponentManager.h =================================================================== --- source/simulation2/tests/test_ComponentManager.h +++ source/simulation2/tests/test_ComponentManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -59,14 +59,14 @@ void test_Load() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); } void test_LookupCID() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT_EQUALS(man.LookupCID("Test1A"), (int)CID_Test1A); @@ -76,7 +76,7 @@ void test_AllocateNewEntity() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)2); TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)3); @@ -102,7 +102,7 @@ double first; { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.SetRNGSeed(123); if (!man.m_ScriptInterface.MathRandom(first)) @@ -112,7 +112,7 @@ double second; { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.SetRNGSeed(123); if (!man.m_ScriptInterface.MathRandom(second)) @@ -125,7 +125,7 @@ void test_AddComponent_errors() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); CEntityHandle hnd1 = man.AllocateEntityHandle(1); @@ -148,7 +148,7 @@ void test_QueryInterface() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -173,7 +173,7 @@ void test_SendMessage() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4; @@ -247,7 +247,7 @@ void test_ParamNode() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -268,7 +268,7 @@ void test_script_basic() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test.js")); @@ -312,7 +312,7 @@ void test_script_helper_basic() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-helper.js")); TS_ASSERT(man.LoadScript(L"simulation/helpers/test-helper.js")); @@ -329,7 +329,7 @@ void test_script_global_helper() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-global-helper.js")); @@ -345,7 +345,7 @@ void test_script_interface() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/interfaces/test-interface.js")); TS_ASSERT(man.LoadScript(L"simulation/components/test-interface.js")); @@ -363,7 +363,7 @@ void test_script_errors() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); ScriptTestSetup(man.m_ScriptInterface); man.LoadComponentTypes(); @@ -378,7 +378,7 @@ void test_script_entityID() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); ScriptTestSetup(man.m_ScriptInterface); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-entityid.js")); @@ -398,7 +398,7 @@ void test_script_QueryInterface() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-query.js")); @@ -419,7 +419,7 @@ void test_script_AddEntity() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js")); TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js")); @@ -452,7 +452,7 @@ void test_script_AddLocalEntity() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js")); TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js")); @@ -485,7 +485,7 @@ void test_script_DestroyEntity() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-destroyentity.js")); @@ -505,7 +505,7 @@ void test_script_messages() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-msg.js")); @@ -538,7 +538,7 @@ void test_script_template() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js")); @@ -560,7 +560,7 @@ void test_script_template_readonly() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js")); @@ -582,7 +582,7 @@ void test_script_hotload() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-hotload1.js")); @@ -618,7 +618,7 @@ void test_script_modding() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); CParamNode testParam; @@ -643,7 +643,7 @@ void test_serialization() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 10, ent2 = 20, ent3 = FIRST_LOCAL_ENTITY; @@ -714,7 +714,7 @@ ); CSimContext context2; - CComponentManager man2(context2, g_ScriptContext); + CComponentManager man2(context2, *g_ScriptContext); man2.LoadComponentTypes(); TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL); @@ -734,7 +734,7 @@ { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); ScriptTestSetup(man.m_ScriptInterface); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); @@ -810,7 +810,7 @@ TS_ASSERT(man.SerializeState(stateStream)); CSimContext context2; - CComponentManager man2(context2, g_ScriptContext); + CComponentManager man2(context2, *g_ScriptContext); man2.LoadComponentTypes(); TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js")); @@ -827,7 +827,7 @@ void test_script_serialization_errors() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); @@ -847,7 +847,7 @@ { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); man.InitSystemEntity(); @@ -871,7 +871,7 @@ TS_ASSERT(man.SerializeState(stateStream)); CSimContext context2; - CComponentManager man2(context2, g_ScriptContext); + CComponentManager man2(context2, *g_ScriptContext); man2.LoadComponentTypes(); TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js")); @@ -882,7 +882,7 @@ void test_dynamic_subscription() { CSimContext context; - CComponentManager man(context, g_ScriptContext); + CComponentManager man(context, *g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1; Index: source/simulation2/tests/test_Serializer.h =================================================================== --- source/simulation2/tests/test_Serializer.h +++ source/simulation2/tests/test_Serializer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -895,7 +895,7 @@ LDR_BeginRegistering(); mapReader->LoadMap(L"maps/skirmishes/Greek Acropolis (2).pmp", - *sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, + sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &sim2, &sim2.GetSimContext(), -1, false); LDR_EndRegistering();