diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 12db89cbc1..ed27d93048 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -1320,9 +1320,7 @@ PS::Loader::Task CMapReader::RunMapGeneration(const CStrW& scriptFile) const VfsPath scriptPath{scriptFile.empty() ? L"" : static_cast(RANDOM_MAP_PREFIX) + scriptFile}; - const std::shared_ptr mapgenContext{ScriptContext::CreateContext( - MAP_GENERATION_CONTEXT_SIZE)}; - + ScriptContext mapgenContext{MAP_GENERATION_CONTEXT_SIZE}; ScriptInterface mapgenInterface{"Engine", "MapGenerator", mapgenContext, [](const VfsPath& path){ // Only allow to load modules inside the maps folder. diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index 98ed8f7631..d562dd0392 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -415,7 +415,7 @@ void CNetServerWorker::Run() g_Profiler2.RegisterCurrentThread("Net server"); // We create a new ScriptContext for this network thread, with a single ScriptInterface. - std::shared_ptr netServerContext = ScriptContext::CreateContext(); + ScriptContext netServerContext; m_ScriptInterface = new ScriptInterface("Engine", "Net server", netServerContext); m_InitAttributes.init(m_ScriptInterface->GetGeneralJSContext(), JS::UndefinedValue()); diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index d2055d1aea..c9668c9288 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -555,7 +555,7 @@ bool Init(const CmdLineArgs& args, int flags) // their own threads and also their own contexts. const int contextSize = 384 * 1024 * 1024; const int heapGrowthBytesGCTrigger = 12 * 1024 * 1024; - g_ScriptContext = ScriptContext::CreateContext(contextSize, heapGrowthBytesGCTrigger); + g_ScriptContext = std::make_shared(contextSize, heapGrowthBytesGCTrigger); // On the first Init (INIT_MODS), check for command-line arguments // or use the default mods from the config and enable those. diff --git a/source/ps/Replay.cpp b/source/ps/Replay.cpp index 0c6bac94c7..9e8815ab74 100644 --- a/source/ps/Replay.cpp +++ b/source/ps/Replay.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -202,7 +202,7 @@ void CReplayPlayer::Replay(const bool serializationtest, const int rejointesttur const int contextSize = 384 * 1024 * 1024; const int heapGrowthBytesGCTrigger = 12 * 1024 * 1024; - g_ScriptContext = ScriptContext::CreateContext(contextSize, heapGrowthBytesGCTrigger); + g_ScriptContext = std::make_shared(contextSize, heapGrowthBytesGCTrigger); std::vector commands; u32 turn = 0; diff --git a/source/scriptinterface/ScriptContext.cpp b/source/scriptinterface/ScriptContext.cpp index 19cce2733d..e36d1edb00 100644 --- a/source/scriptinterface/ScriptContext.cpp +++ b/source/scriptinterface/ScriptContext.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -102,11 +102,6 @@ void GCSliceCallbackHook(JSContext*, JS::GCProgress progress, const JS::GCDescri #endif } -std::shared_ptr ScriptContext::CreateContext(int contextSize, uint32_t heapGrowthBytesGCTrigger) -{ - return std::make_shared(contextSize, heapGrowthBytesGCTrigger); -} - ScriptContext::ScriptContext(int contextSize, uint32_t heapGrowthBytesGCTrigger): m_JobQueue{std::make_unique()}, m_ContextSize{contextSize}, diff --git a/source/scriptinterface/ScriptContext.h b/source/scriptinterface/ScriptContext.h index 16c536ee86..391e19671b 100644 --- a/source/scriptinterface/ScriptContext.h +++ b/source/scriptinterface/ScriptContext.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -47,9 +47,6 @@ class JobQueue; class ScriptContext { public: - ScriptContext(int contextSize, uint32_t heapGrowthBytesGCTrigger); - ~ScriptContext(); - /** * Returns a context, in which any number of ScriptInterfaces compartments can live. * Each context should only ever be used on a single thread. @@ -57,10 +54,9 @@ public: * @param contextSize Maximum size in bytes of the new context * @param heapGrowthBytesGCTrigger Size in bytes of cumulated allocations after which a GC will be triggered */ - static std::shared_ptr CreateContext( - int contextSize = DEFAULT_CONTEXT_SIZE, + ScriptContext(int contextSize = DEFAULT_CONTEXT_SIZE, uint32_t heapGrowthBytesGCTrigger = DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER); - + ~ScriptContext(); /** * MaybeIncrementalGC checks if running a GC is worth the time that will take. diff --git a/source/test_setup.cpp b/source/test_setup.cpp index 2729b1aa91..c12e5f1973 100644 --- a/source/test_setup.cpp +++ b/source/test_setup.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -85,7 +85,7 @@ class MiscSetup : public CxxTest::GlobalFixture g_Profiler2.Initialise(); m_ScriptEngine = new ScriptEngine; - g_ScriptContext = ScriptContext::CreateContext(); + g_ScriptContext = std::make_shared(); taskManager.emplace();