Index: source/graphics/MapGenerator.h =================================================================== --- source/graphics/MapGenerator.h +++ source/graphics/MapGenerator.h @@ -81,7 +81,7 @@ * Thread-safety: * - Initialize and constructor/destructor must be called from the main thread. * - ScriptInterface created and destroyed by thread - * - StructuredClone used to return JS map data - JS:Values can't be used across threads/runtimes. + * - StructuredClone used to return JS map data - JS:Values can't be used across threads/contexts. */ class CMapGeneratorWorker { Index: source/graphics/MapGenerator.cpp =================================================================== --- source/graphics/MapGenerator.cpp +++ source/graphics/MapGenerator.cpp @@ -31,7 +31,7 @@ #include "ps/FileIo.h" #include "ps/Profile.h" #include "ps/scripting/JSInterface_VFS.h" -#include "scriptinterface/ScriptRuntime.h" +#include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptConversions.h" #include "scriptinterface/ScriptInterface.h" #include "simulation2/helpers/MapEdgeTiles.h" @@ -40,7 +40,7 @@ #include // TODO: Maybe this should be optimized depending on the map size. -constexpr int RMS_RUNTIME_SIZE = 96 * 1024 * 1024; +constexpr int RMS_CONTEXT_SIZE = 96 * 1024 * 1024; extern bool IsQuitRequested(); @@ -89,12 +89,12 @@ debug_SetThreadName("MapGenerator"); g_Profiler2.RegisterCurrentThread("MapGenerator"); - shared_ptr mapgenRuntime = ScriptRuntime::CreateRuntime(RMS_RUNTIME_SIZE); + shared_ptr mapgenContext = ScriptContext::CreateContext(RMS_CONTEXT_SIZE); // Enable the script to be aborted - JS_SetInterruptCallback(mapgenRuntime->GetJSRuntime(), MapGeneratorInterruptCallback); + JS_SetInterruptCallback(mapgenContext->GetJSRuntime(), MapGeneratorInterruptCallback); - self->m_ScriptInterface = new ScriptInterface("Engine", "MapGenerator", mapgenRuntime); + self->m_ScriptInterface = new ScriptInterface("Engine", "MapGenerator", mapgenContext); // Run map generation scripts if (!self->Run() || self->m_Progress > 0) Index: source/graphics/tests/test_LOSTexture.h =================================================================== --- source/graphics/tests/test_LOSTexture.h +++ source/graphics/tests/test_LOSTexture.h @@ -28,7 +28,7 @@ public: void test_basic() { - CSimulation2 sim(NULL, g_ScriptRuntime, NULL); + CSimulation2 sim(NULL, g_ScriptContext, NULL); CLOSTexture tex(sim); const ssize_t size = 8; @@ -67,7 +67,7 @@ void test_perf_DISABLED() { - CSimulation2 sim(NULL, g_ScriptRuntime, NULL); + CSimulation2 sim(NULL, g_ScriptContext, NULL); CLOSTexture tex(sim); const ssize_t size = 257; Index: source/graphics/tests/test_MapGenerator.h =================================================================== --- source/graphics/tests/test_MapGenerator.h +++ source/graphics/tests/test_MapGenerator.h @@ -49,7 +49,7 @@ for (const VfsPath& path : paths) { - ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptRuntime); + ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptContext); ScriptTestSetup(scriptInterface); CMapGeneratorWorker worker(&scriptInterface); Index: source/gui/CGUI.h =================================================================== --- source/gui/CGUI.h +++ source/gui/CGUI.h @@ -57,7 +57,7 @@ using ConstructObjectFunction = IGUIObject* (*)(CGUI&); public: - CGUI(const shared_ptr& runtime); + CGUI(const shared_ptr& context); ~CGUI(); /** Index: source/gui/CGUI.cpp =================================================================== --- source/gui/CGUI.cpp +++ source/gui/CGUI.cpp @@ -61,13 +61,13 @@ const CStr CGUI::EventNameMouseRightDoubleClick = "MouseRightDoubleClick"; const CStr CGUI::EventNameMouseRightRelease = "MouseRightRelease"; -CGUI::CGUI(const shared_ptr& runtime) +CGUI::CGUI(const shared_ptr& context) : m_BaseObject(*this), m_FocusedObject(nullptr), m_InternalNameNumber(0), m_MouseButtons(0) { - m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime)); + m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", context)); m_ScriptInterface->SetCallbackData(this); GuiScriptingInit(*m_ScriptInterface); Index: source/gui/GUIManager.h =================================================================== --- source/gui/GUIManager.h +++ source/gui/GUIManager.h @@ -50,7 +50,7 @@ { return m_ScriptInterface; } - shared_ptr GetRuntime() { return m_ScriptRuntime; } + shared_ptr GetContext() { return m_ScriptContext; } shared_ptr GetActiveGUI() { return top(); } /** @@ -137,7 +137,7 @@ /** * Create the CGUI with it's own ScriptInterface. Deletes the previous CGUI if it existed. */ - void LoadPage(shared_ptr scriptRuntime); + void LoadPage(shared_ptr scriptContext); /** * Sets the callback handler when a new page is opened that will be performed when the page is closed. @@ -165,7 +165,7 @@ shared_ptr top() const; - shared_ptr m_ScriptRuntime; + shared_ptr m_ScriptContext; shared_ptr m_ScriptInterface; using PageStackType = std::vector; Index: source/gui/GUIManager.cpp =================================================================== --- source/gui/GUIManager.cpp +++ source/gui/GUIManager.cpp @@ -26,8 +26,8 @@ #include "ps/GameSetup/Config.h" #include "ps/Profile.h" #include "ps/XML/Xeromyces.h" +#include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptInterface.h" -#include "scriptinterface/ScriptRuntime.h" CGUIManager* g_GUI = nullptr; @@ -60,8 +60,8 @@ CGUIManager::CGUIManager() { - m_ScriptRuntime = g_ScriptRuntime; - m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIManager", m_ScriptRuntime)); + m_ScriptContext = g_ScriptContext; + m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIManager", m_ScriptContext)); m_ScriptInterface->SetCallbackData(this); m_ScriptInterface->LoadGlobalScripts(); @@ -106,7 +106,7 @@ // Push the page prior to loading its contents, because that may push // another GUI page on init which should be pushed on top of this new page. m_PageStack.emplace_back(pageName, initData); - m_PageStack.back().LoadPage(m_ScriptRuntime); + m_PageStack.back().LoadPage(m_ScriptContext); } void CGUIManager::PopPage(shared_ptr args) @@ -126,7 +126,7 @@ { } -void CGUIManager::SGUIPage::LoadPage(shared_ptr scriptRuntime) +void CGUIManager::SGUIPage::LoadPage(shared_ptr scriptContext) { // If we're hotloading then try to grab some data from the previous page shared_ptr hotloadData; @@ -143,7 +143,7 @@ g_CursorName = g_DefaultCursor; inputs.clear(); - gui.reset(new CGUI(scriptRuntime)); + gui.reset(new CGUI(scriptContext)); gui->AddObjectTypes(); @@ -268,7 +268,7 @@ if (p.inputs.find(path) != p.inputs.end()) { LOGMESSAGE("GUI file '%s' changed - reloading page '%s'", path.string8(), utf8_from_wstring(p.name)); - p.LoadPage(m_ScriptRuntime); + p.LoadPage(m_ScriptContext); // TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators } @@ -279,7 +279,7 @@ { // TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators for (SGUIPage& p : m_PageStack) - p.LoadPage(m_ScriptRuntime); + p.LoadPage(m_ScriptContext); return INFO::OK; } @@ -349,9 +349,9 @@ { PROFILE3("gui tick"); - // We share the script runtime with everything else that runs in the same thread. + // 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->GetRuntime()->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/main.cpp =================================================================== --- source/main.cpp +++ source/main.cpp @@ -501,7 +501,7 @@ // Install the mods without deleting the pyromod files for (const OsPath& modPath : modsToInstall) - installer.Install(modPath, g_ScriptRuntime, true); + installer.Install(modPath, g_ScriptContext, true); installedMods = installer.GetInstalledMods(); } @@ -694,7 +694,7 @@ // Install the mods without deleting the pyromod files for (const OsPath& modPath : modsToInstall) - installer.Install(modPath, g_ScriptRuntime, true); + installer.Install(modPath, g_ScriptContext, true); installedMods = installer.GetInstalledMods(); } Index: source/network/NetServer.cpp =================================================================== --- source/network/NetServer.cpp +++ source/network/NetServer.cpp @@ -32,8 +32,8 @@ #include "ps/ConfigDB.h" #include "ps/GUID.h" #include "ps/Profile.h" +#include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptInterface.h" -#include "scriptinterface/ScriptRuntime.h" #include "simulation2/Simulation2.h" #include "simulation2/system/TurnManager.h" @@ -383,13 +383,12 @@ void CNetServerWorker::Run() { - // The script runtime uses the profiler and therefore the thread must be registered before the runtime is created + // The script context uses the profiler and therefore the thread must be registered before the context is created g_Profiler2.RegisterCurrentThread("Net server"); - // To avoid the need for JS_SetContextThread, we create and use and destroy - // the script interface entirely within this network thread - shared_ptr netServerRuntime = ScriptRuntime::CreateRuntime(); - m_ScriptInterface = new ScriptInterface("Engine", "Net server", netServerRuntime); + // We create a new ScriptContext for this network thread, with a single ScriptInterface. + shared_ptr netServerContext = ScriptContext::CreateContext(); + m_ScriptInterface = new ScriptInterface("Engine", "Net server", netServerContext); m_GameAttributes.init(m_ScriptInterface->GetJSRuntime(), JS::UndefinedValue()); while (true) @@ -417,7 +416,7 @@ // (Do as little work as possible while the mutex is held open, // to avoid performance problems and deadlocks.) - m_ScriptInterface->GetRuntime()->MaybeIncrementalGC(0.5f); + m_ScriptInterface->GetContext()->MaybeIncrementalGC(0.5f); ScriptInterface::Request rq(m_ScriptInterface); Index: source/network/tests/test_Net.h =================================================================== --- source/network/tests/test_Net.h +++ source/network/tests/test_Net.h @@ -136,7 +136,7 @@ // This doesn't actually test much, it just runs a very quick multiplayer game // and prints a load of debug output so you can see if anything funny's going on - ScriptInterface scriptInterface("Engine", "Test", g_ScriptRuntime); + ScriptInterface scriptInterface("Engine", "Test", g_ScriptContext); ScriptInterface::Request rq(scriptInterface); TestStdoutLogger logger; @@ -215,7 +215,7 @@ void test_rejoin_DISABLED() { - ScriptInterface scriptInterface("Engine", "Test", g_ScriptRuntime); + ScriptInterface scriptInterface("Engine", "Test", g_ScriptContext); ScriptInterface::Request rq(scriptInterface); TestStdoutLogger logger; Index: source/network/tests/test_NetMessage.h =================================================================== --- source/network/tests/test_NetMessage.h +++ source/network/tests/test_NetMessage.h @@ -26,7 +26,7 @@ public: void test_sim() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); JS::RootedValue val(rq.cx); Index: source/ps/Game.cpp =================================================================== --- source/ps/Game.cpp +++ source/ps/Game.cpp @@ -67,7 +67,7 @@ **/ CGame::CGame(bool replayLog): m_World(new CWorld(this)), - m_Simulation2(new CSimulation2(&m_World->GetUnitManager(), g_ScriptRuntime, m_World->GetTerrain())), + m_Simulation2(new CSimulation2(&m_World->GetUnitManager(), g_ScriptContext, m_World->GetTerrain())), m_GameView(CRenderer::IsInitialised() ? new CGameView(this) : nullptr), m_GameStarted(false), m_Paused(false), Index: source/ps/GameSetup/GameSetup.cpp =================================================================== --- source/ps/GameSetup/GameSetup.cpp +++ source/ps/GameSetup/GameSetup.cpp @@ -77,8 +77,8 @@ #include "renderer/ModelRenderer.h" #include "scriptinterface/ScriptInterface.h" #include "scriptinterface/ScriptStats.h" +#include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptConversions.h" -#include "scriptinterface/ScriptRuntime.h" #include "simulation2/Simulation2.h" #include "lobby/IXmppClient.h" #include "soundmanager/scripting/JSInterface_Sound.h" @@ -109,7 +109,7 @@ bool g_DoRenderLogger = true; bool g_DoRenderCursor = true; -thread_local shared_ptr g_ScriptRuntime; +thread_local shared_ptr g_ScriptContext; static const int SANE_TEX_QUALITY_DEFAULT = 5; // keep in sync with code @@ -725,7 +725,7 @@ // This is needed to ensure that no callbacks from the JSAPI try to use // the profiler when it's already destructed - g_ScriptRuntime.reset(); + g_ScriptContext.reset(); // resource // first shut down all resource owners, and then the handle manager. @@ -889,20 +889,20 @@ // g_ConfigDB, command line args, globals CONFIG_Init(args); - // Using a global object for the runtime is a workaround until Simulation and AI use - // their own threads and also their own runtimes. - const int runtimeSize = 384 * 1024 * 1024; + // Using a global object for the context is a workaround until Simulation and AI use + // their own threads and also their own contexts. + const int contextSize = 384 * 1024 * 1024; const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024; - g_ScriptRuntime = ScriptRuntime::CreateRuntime(runtimeSize, heapGrowthBytesGCTrigger); + g_ScriptContext = ScriptContext::CreateContext(contextSize, heapGrowthBytesGCTrigger); - Mod::CacheEnabledModVersions(g_ScriptRuntime); + Mod::CacheEnabledModVersions(g_ScriptContext); // Special command-line mode to dump the entity schemas instead of running the game. // (This must be done after loading VFS etc, but should be done before wasting time // on anything else.) if (args.Has("dumpSchema")) { - CSimulation2 sim(NULL, g_ScriptRuntime, NULL); + CSimulation2 sim(NULL, g_ScriptContext, NULL); sim.LoadDefaultScripts(); std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc); f << sim.GenerateSchema(); Index: source/ps/GameSetup/HWDetect.cpp =================================================================== --- source/ps/GameSetup/HWDetect.cpp +++ source/ps/GameSetup/HWDetect.cpp @@ -141,7 +141,7 @@ { TIMER(L"RunHardwareDetection"); - ScriptInterface scriptInterface("Engine", "HWDetect", g_ScriptRuntime); + ScriptInterface scriptInterface("Engine", "HWDetect", g_ScriptContext); ScriptInterface::Request rq(scriptInterface); Index: source/ps/Mod.h =================================================================== --- source/ps/Mod.h +++ source/ps/Mod.h @@ -22,7 +22,7 @@ #include "ps/GameSetup/CmdLineArgs.h" #include "scriptinterface/ScriptInterface.h" -class ScriptRuntime; +class ScriptContext; extern std::vector g_modsLoaded; extern CmdLineArgs g_args; @@ -37,7 +37,7 @@ * JS pages can request the version numbers too often easily. * Make sure this is called after each MountMods call. */ - void CacheEnabledModVersions(const shared_ptr& scriptRuntime); + void CacheEnabledModVersions(const shared_ptr& scriptContext); /** * Get the loaded mods and their version. Index: source/ps/Mod.cpp =================================================================== --- source/ps/Mod.cpp +++ source/ps/Mod.cpp @@ -28,8 +28,8 @@ #include "ps/GameSetup/GameSetup.h" #include "ps/GameSetup/Paths.h" #include "ps/Pyrogenesis.h" +#include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptInterface.h" -#include "scriptinterface/ScriptRuntime.h" std::vector g_modsLoaded; @@ -104,9 +104,9 @@ return JS::ObjectValue(*obj); } -void Mod::CacheEnabledModVersions(const shared_ptr& scriptRuntime) +void Mod::CacheEnabledModVersions(const shared_ptr& scriptContext) { - ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptRuntime); + ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptContext); ScriptInterface::Request rq(scriptInterface); JS::RootedValue availableMods(rq.cx, GetAvailableMods(scriptInterface)); Index: source/ps/ModInstaller.h =================================================================== --- source/ps/ModInstaller.h +++ source/ps/ModInstaller.h @@ -57,7 +57,7 @@ */ ModInstallationResult Install( const OsPath& mod, - const std::shared_ptr& scriptRuntime, + const std::shared_ptr& scriptContext, bool keepFile); /** Index: source/ps/ModInstaller.cpp =================================================================== --- source/ps/ModInstaller.cpp +++ source/ps/ModInstaller.cpp @@ -40,7 +40,7 @@ CModInstaller::ModInstallationResult CModInstaller::Install( const OsPath& mod, - const std::shared_ptr& scriptRuntime, + const std::shared_ptr& scriptContext, bool keepFile) { const OsPath modTemp = m_TempDir / mod.Basename() / mod.Filename().ChangeExtension(L".zip"); @@ -63,7 +63,7 @@ // Extract the name of the mod CStr modName; { - ScriptInterface scriptInterface("Engine", "ModInstaller", scriptRuntime); + ScriptInterface scriptInterface("Engine", "ModInstaller", scriptContext); ScriptInterface::Request rq(scriptInterface); JS::RootedValue json_val(rq.cx); Index: source/ps/ModIo.cpp =================================================================== --- source/ps/ModIo.cpp +++ source/ps/ModIo.cpp @@ -483,7 +483,7 @@ { Paths paths(g_args); CModInstaller installer(paths.UserData() / "mods", paths.Cache()); - installer.Install(m_DownloadFilePath, g_ScriptRuntime, false); + installer.Install(m_DownloadFilePath, g_ScriptContext, false); } break; default: Index: source/ps/Replay.cpp =================================================================== --- source/ps/Replay.cpp +++ source/ps/Replay.cpp @@ -34,8 +34,8 @@ #include "ps/Mod.h" #include "ps/Util.h" #include "ps/VisualReplay.h" +#include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptInterface.h" -#include "scriptinterface/ScriptRuntime.h" #include "scriptinterface/ScriptStats.h" #include "simulation2/components/ICmpGuiInterface.h" #include "simulation2/helpers/Player.h" @@ -202,11 +202,11 @@ g_ScriptStatsTable = new CScriptStatsTable; g_ProfileViewer.AddRootTable(g_ScriptStatsTable); - const int runtimeSize = 384 * 1024 * 1024; + const int contextSize = 384 * 1024 * 1024; const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024; - g_ScriptRuntime = ScriptRuntime::CreateRuntime(runtimeSize, heapGrowthBytesGCTrigger); + g_ScriptContext = ScriptContext::CreateContext(contextSize, heapGrowthBytesGCTrigger); - Mod::CacheEnabledModVersions(g_ScriptRuntime); + Mod::CacheEnabledModVersions(g_ScriptContext); g_Game = new CGame(false); if (serializationtest) @@ -310,7 +310,7 @@ // Must be explicitly destructed here to avoid callbacks from the JSAPI trying to use g_Profiler2 when // it's already destructed. - g_ScriptRuntime.reset(); + g_ScriptContext.reset(); // Clean up delete &g_TexMan; Index: source/ps/tests/test_ModIo.h =================================================================== --- source/ps/tests/test_ModIo.h +++ source/ps/tests/test_ModIo.h @@ -42,7 +42,7 @@ void test_id_parsing() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); #define TS_ASSERT_PARSE(input, expected_error, expected_id) \ { \ @@ -90,7 +90,7 @@ void test_mods_parsing() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); PKStruct pk; Index: source/scriptinterface/ScriptContext.h =================================================================== --- source/scriptinterface/ScriptContext.h +++ source/scriptinterface/ScriptContext.h @@ -15,8 +15,8 @@ * along with 0 A.D. If not, see . */ -#ifndef INCLUDED_SCRIPTRUNTIME -#define INCLUDED_SCRIPTRUNTIME +#ifndef INCLUDED_SCRIPTCONTEXT +#define INCLUDED_SCRIPTCONTEXT #include "ScriptTypes.h" #include "ScriptExtraHeaders.h" @@ -26,37 +26,38 @@ constexpr int STACK_CHUNK_SIZE = 8192; // Those are minimal defaults. The runtime for the main game is larger and GCs upon a larger growth. -constexpr int DEFAULT_RUNTIME_SIZE = 16 * 1024 * 1024; +constexpr int DEFAULT_CONTEXT_SIZE = 16 * 1024 * 1024; constexpr int DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER = 2 * 1024 * 1024; /** * Abstraction around a SpiderMonkey JSRuntime/JSContext. * - * A single ScriptRuntime, with the associated runtime and context, + * A single ScriptContext, with the associated runtime and context, * should only be used on a single thread. * - * (One means to share data between threads and runtimes is to create + * (One means to share data between threads and contexts is to create * a ScriptInterface::StructuredClone.) */ -class ScriptRuntime +class ScriptContext { public: - ScriptRuntime(int runtimeSize, int heapGrowthBytesGCTrigger); - ~ScriptRuntime(); + ScriptContext(int contextSize, int heapGrowthBytesGCTrigger); + ~ScriptContext(); /** - * Returns a runtime/context, in which any number of ScriptInterfaces compartments can live. - * Each runtime should only ever be used on a single thread. - * @param runtimeSize Maximum size in bytes of the new runtime + * Returns a context, in which any number of ScriptInterfaces compartments can live. + * Each context should only ever be used on a single thread. + * @param parentContext Parent context from the parent thread, with which we share some thread-safe data + * @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 shared_ptr CreateRuntime( - int runtimeSize = DEFAULT_RUNTIME_SIZE, + static shared_ptr CreateContext( + int contextSize = DEFAULT_CONTEXT_SIZE, int heapGrowthBytesGCTrigger = DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER); /** - * MaybeIncrementalRuntimeGC tries to determine whether a runtime-wide garbage collection would free up enough memory to + * MaybeIncrementalGC tries to determine whether a context-wide garbage collection would free up enough memory to * be worth the amount of time it would take. It does this with our own logic and NOT some predefined JSAPI logic because * such functionality currently isn't available out of the box. * It does incremental GC which means it will collect one slice each time it's called until the garbage collection is done. @@ -93,10 +94,10 @@ void PrepareCompartmentsForIncrementalGC() const; std::list m_Compartments; - int m_RuntimeSize; + int m_ContextSize; int m_HeapGrowthBytesGCTrigger; int m_LastGCBytes; double m_LastGCCheck; }; -#endif // INCLUDED_SCRIPTRUNTIME +#endif // INCLUDED_SCRIPTCONTEXT Index: source/scriptinterface/ScriptContext.cpp =================================================================== --- source/scriptinterface/ScriptContext.cpp +++ source/scriptinterface/ScriptContext.cpp @@ -17,7 +17,7 @@ #include "precompiled.h" -#include "ScriptRuntime.h" +#include "ScriptContext.h" #include "ps/GameSetup/Config.h" #include "ps/Profile.h" @@ -135,35 +135,32 @@ } // anonymous namespace - -shared_ptr ScriptRuntime::CreateRuntime(int runtimeSize, int heapGrowthBytesGCTrigger) +shared_ptr ScriptContext::CreateContext(int contextSize, int heapGrowthBytesGCTrigger) { - return shared_ptr(new ScriptRuntime(runtimeSize, heapGrowthBytesGCTrigger)); + return shared_ptr(new ScriptContext(contextSize, heapGrowthBytesGCTrigger)); } -ScriptRuntime::ScriptRuntime(int runtimeSize, int heapGrowthBytesGCTrigger): +ScriptContext::ScriptContext(int contextSize, int heapGrowthBytesGCTrigger): m_LastGCBytes(0), m_LastGCCheck(0.0f), m_HeapGrowthBytesGCTrigger(heapGrowthBytesGCTrigger), - m_RuntimeSize(runtimeSize) + m_ContextSize(contextSize) { - ENSURE(ScriptEngine::IsInitialised() && "The ScriptEngine must be initialized before constructing any ScriptRuntimes!"); + ENSURE(ScriptEngine::IsInitialised() && "The ScriptEngine must be initialized before constructing any ScriptContexts!"); - m_rt = JS_NewRuntime(runtimeSize, JS::DefaultNurseryBytes, nullptr); + m_rt = JS_NewRuntime(contextSize, JS::DefaultNurseryBytes, nullptr); ENSURE(m_rt); // TODO: error handling JS::SetGCSliceCallback(m_rt, GCSliceCallbackHook); - JS_SetGCParameter(m_rt, JSGC_MAX_MALLOC_BYTES, m_RuntimeSize); - JS_SetGCParameter(m_rt, JSGC_MAX_BYTES, m_RuntimeSize); + JS_SetGCParameter(m_rt, JSGC_MAX_MALLOC_BYTES, m_ContextSize); + JS_SetGCParameter(m_rt, JSGC_MAX_BYTES, m_ContextSize); JS_SetGCParameter(m_rt, JSGC_MODE, JSGC_MODE_INCREMENTAL); // The whole heap-growth mechanism seems to work only for non-incremental GCs. // We disable it to make it more clear if full GCs happen triggered by this JSAPI internal mechanism. JS_SetGCParameter(m_rt, JSGC_DYNAMIC_HEAP_GROWTH, false); - ScriptEngine::GetSingleton().RegisterRuntime(m_rt); - m_cx = JS_NewContext(m_rt, STACK_CHUNK_SIZE); ENSURE(m_cx); // TODO: error handling @@ -184,30 +181,33 @@ .setExtraWarnings(true) .setWerror(false) .setStrictMode(true); + + ScriptEngine::GetSingleton().RegisterContext(m_cx); } -ScriptRuntime::~ScriptRuntime() +ScriptContext::~ScriptContext() { + ENSURE(ScriptEngine::IsInitialised() && "The ScriptEngine must be active (initialized and not yet shut down) when destroying a ScriptContext!"); + JS_DestroyContext(m_cx); JS_DestroyRuntime(m_rt); - ENSURE(ScriptEngine::IsInitialised() && "The ScriptEngine must be active (initialized and not yet shut down) when destroying a ScriptRuntime!"); - ScriptEngine::GetSingleton().UnRegisterRuntime(m_rt); + ScriptEngine::GetSingleton().UnRegisterContext(m_cx); } -void ScriptRuntime::RegisterCompartment(JSCompartment* cmpt) +void ScriptContext::RegisterCompartment(JSCompartment* cmpt) { ENSURE(cmpt); m_Compartments.push_back(cmpt); } -void ScriptRuntime::UnRegisterCompartment(JSCompartment* cmpt) +void ScriptContext::UnRegisterCompartment(JSCompartment* cmpt) { m_Compartments.remove(cmpt); } #define GC_DEBUG_PRINT 0 -void ScriptRuntime::MaybeIncrementalGC(double delay) +void ScriptContext::MaybeIncrementalGC(double delay) { PROFILE2("MaybeIncrementalGC"); @@ -260,31 +260,31 @@ m_HeapGrowthBytesGCTrigger / 1024); #endif - // A hack to make sure we never exceed the runtime size because we can't collect the memory + // A hack to make sure we never exceed the context size because we can't collect the memory // fast enough. - if (gcBytes > m_RuntimeSize / 2) + if (gcBytes > m_ContextSize / 2) { if (JS::IsIncrementalGCInProgress(m_rt)) { #if GC_DEBUG_PRINT - printf("Finishing incremental GC because gcBytes > m_RuntimeSize / 2. \n"); + printf("Finishing incremental GC because gcBytes > m_ContextSize / 2. \n"); #endif PrepareCompartmentsForIncrementalGC(); JS::FinishIncrementalGC(m_rt, JS::gcreason::REFRESH_FRAME); } else { - if (gcBytes > m_RuntimeSize * 0.75) + if (gcBytes > m_ContextSize * 0.75) { ShrinkingGC(); #if GC_DEBUG_PRINT - printf("Running shrinking GC because gcBytes > m_RuntimeSize * 0.75. \n"); + printf("Running shrinking GC because gcBytes > m_ContextSize * 0.75. \n"); #endif } else { #if GC_DEBUG_PRINT - printf("Running full GC because gcBytes > m_RuntimeSize / 2. \n"); + printf("Running full GC because gcBytes > m_ContextSize / 2. \n"); #endif JS_GC(m_rt); } @@ -309,7 +309,7 @@ } } -void ScriptRuntime::ShrinkingGC() +void ScriptContext::ShrinkingGC() { JS_SetGCParameter(m_rt, JSGC_MODE, JSGC_MODE_COMPARTMENT); JS::PrepareForFullGC(m_rt); @@ -317,7 +317,7 @@ JS_SetGCParameter(m_rt, JSGC_MODE, JSGC_MODE_INCREMENTAL); } -void ScriptRuntime::PrepareCompartmentsForIncrementalGC() const +void ScriptContext::PrepareCompartmentsForIncrementalGC() const { for (JSCompartment* const& cmpt : m_Compartments) JS::PrepareZoneForGC(js::GetCompartmentZone(cmpt)); Index: source/scriptinterface/ScriptEngine.h =================================================================== --- source/scriptinterface/ScriptEngine.h +++ source/scriptinterface/ScriptEngine.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -25,10 +25,10 @@ /** * A class using the RAII (Resource Acquisition Is Initialization) idiom to manage initialization - * and shutdown of the SpiderMonkey script engine. It also keeps a count of active script runtimes + * and shutdown of the SpiderMonkey script engine. It also keeps a count of active script contexts * in order to validate the following constraints: - * 1. JS_Init must be called before any ScriptRuntimes are initialized - * 2. JS_Shutdown must be called after all ScriptRuntimes have been destroyed + * 1. JS_Init must be called before any ScriptContexts are initialized + * 2. JS_Shutdown must be called after all ScriptContexts have been destroyed */ class ScriptEngine : public Singleton @@ -36,21 +36,21 @@ public: ScriptEngine() { - ENSURE(m_Runtimes.empty() && "JS_Init must be called before any runtimes are created!"); + ENSURE(m_Contexts.empty() && "JS_Init must be called before any contexts are created!"); JS_Init(); } ~ScriptEngine() { - ENSURE(m_Runtimes.empty() && "All runtimes must be destroyed before calling JS_ShutDown!"); + ENSURE(m_Contexts.empty() && "All contexts must be destroyed before calling JS_ShutDown!"); JS_ShutDown(); } - void RegisterRuntime(const JSRuntime* rt) { m_Runtimes.push_back(rt); } - void UnRegisterRuntime(const JSRuntime* rt) { m_Runtimes.remove(rt); } + void RegisterContext(const JSContext* cx) { m_Contexts.push_back(cx); } + void UnRegisterContext(const JSContext* cx) { m_Contexts.remove(cx); } private: - std::list m_Runtimes; + std::list m_Contexts; }; #endif // INCLUDED_SCRIPTENGINE Index: source/scriptinterface/ScriptInterface.h =================================================================== --- source/scriptinterface/ScriptInterface.h +++ source/scriptinterface/ScriptInterface.h @@ -50,11 +50,11 @@ struct ScriptInterface_impl; -class ScriptRuntime; +class ScriptContext; -// Using a global object for the runtime is a workaround until Simulation, AI, etc, -// use their own threads and also their own runtimes. -extern thread_local shared_ptr g_ScriptRuntime; +// Using a global object for the context is a workaround until Simulation, AI, etc, +// use their own threads and also their own contexts. +extern thread_local shared_ptr g_ScriptContext; /** @@ -76,9 +76,9 @@ * @param nativeScopeName Name of global object that functions (via RegisterFunction) will * be placed into, as a scoping mechanism; typically "Engine" * @param debugName Name of this interface for CScriptStats purposes. - * @param runtime ScriptRuntime to use when initializing this interface. + * @param context ScriptContext to use when initializing this interface. */ - ScriptInterface(const char* nativeScopeName, const char* debugName, const shared_ptr& runtime); + ScriptInterface(const char* nativeScopeName, const char* debugName, const shared_ptr& context); ~ScriptInterface(); @@ -92,7 +92,7 @@ static CmptPrivate* GetScriptInterfaceAndCBData(JSContext* cx); JSRuntime* GetJSRuntime() const; - shared_ptr GetRuntime() const; + shared_ptr GetContext() const; /** * RAII structure which encapsulates an access to the context and compartment of a ScriptInterface. Index: source/scriptinterface/ScriptInterface.cpp =================================================================== --- source/scriptinterface/ScriptInterface.cpp +++ source/scriptinterface/ScriptInterface.cpp @@ -17,8 +17,8 @@ #include "precompiled.h" +#include "ScriptContext.h" #include "ScriptInterface.h" -#include "ScriptRuntime.h" #include "ScriptStats.h" #include "lib/debug.h" @@ -54,13 +54,13 @@ struct ScriptInterface_impl { - ScriptInterface_impl(const char* nativeScopeName, const shared_ptr& runtime); + ScriptInterface_impl(const char* nativeScopeName, const shared_ptr& context); ~ScriptInterface_impl(); void Register(const char* name, JSNative fptr, uint nargs) const; // Take care to keep this declaration before heap rooted members. Destructors of heap rooted - // members have to be called before the runtime destructor. - shared_ptr m_runtime; + // members have to be called before the context destructor. + shared_ptr m_context; friend ScriptInterface::Request; private: @@ -318,8 +318,8 @@ return true; } -ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr& runtime) : - m_runtime(runtime), m_cx(runtime->GetGeneralJSContext()), m_glob(runtime->GetJSRuntime()), m_nativeScope(runtime->GetJSRuntime()) +ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr& context) : + m_context(context), m_cx(context->GetGeneralJSContext()), m_glob(context->GetJSRuntime()), m_nativeScope(context->GetJSRuntime()) { JS::CompartmentOptions opt; opt.setVersion(JSVERSION_LATEST); @@ -348,12 +348,12 @@ Register("ProfileStop", ::ProfileStop, 0); Register("ProfileAttribute", ::ProfileAttribute, 1); - m_runtime->RegisterCompartment(js::GetObjectCompartment(m_glob)); + m_context->RegisterCompartment(js::GetObjectCompartment(m_glob)); } ScriptInterface_impl::~ScriptInterface_impl() { - m_runtime->UnRegisterCompartment(js::GetObjectCompartment(m_glob)); + m_context->UnRegisterCompartment(js::GetObjectCompartment(m_glob)); } void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs) const @@ -364,8 +364,8 @@ JS::RootedFunction func(m_cx, JS_DefineFunction(m_cx, nativeScope, name, fptr, nargs, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)); } -ScriptInterface::ScriptInterface(const char* nativeScopeName, const char* debugName, const shared_ptr& runtime) : - m(new ScriptInterface_impl(nativeScopeName, runtime)) +ScriptInterface::ScriptInterface(const char* nativeScopeName, const char* debugName, const shared_ptr& context) : + m(new ScriptInterface_impl(nativeScopeName, context)) { // Profiler stats table isn't thread-safe, so only enable this on the main thread if (ThreadUtil::IsMainThread()) @@ -447,12 +447,12 @@ JSRuntime* ScriptInterface::GetJSRuntime() const { - return m->m_runtime->GetJSRuntime(); + return m->m_context->GetJSRuntime(); } -shared_ptr ScriptInterface::GetRuntime() const +shared_ptr ScriptInterface::GetContext() const { - return m->m_runtime; + return m->m_context; } void ScriptInterface::CallConstructor(JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out) const Index: source/scriptinterface/tests/test_ScriptConversions.h =================================================================== --- source/scriptinterface/tests/test_ScriptConversions.h +++ source/scriptinterface/tests/test_ScriptConversions.h @@ -33,7 +33,7 @@ template void convert_to(const T& value, const std::string& expected) { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); TS_ASSERT(script.LoadGlobalScripts()); ScriptInterface::Request rq(script); @@ -52,7 +52,7 @@ template void roundtrip(const T& value, const char* expected) { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); TS_ASSERT(script.LoadGlobalScripts()); ScriptInterface::Request rq(script); @@ -74,7 +74,7 @@ template void call_prototype_function(const T& u, const T& v, const std::string& func, const std::string& expected) { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); TS_ASSERT(script.LoadGlobalScripts()); ScriptInterface::Request rq(script); @@ -168,7 +168,7 @@ void test_integers() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); // using new uninitialized variables each time to be sure the test doesn't succeeed if ToJSVal doesn't touch the value at all. @@ -200,7 +200,7 @@ roundtrip(-std::numeric_limits::infinity(), "-Infinity"); convert_to(std::numeric_limits::quiet_NaN(), "NaN"); // can't use roundtrip since nan != nan - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); float f = 0; @@ -250,7 +250,7 @@ void test_utf8utf16_conversion() { // Fancier conversion: we store UTF8 and get UTF16 and vice-versa - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); TS_ASSERT(script.LoadGlobalScripts()); ScriptInterface::Request rq(script); Index: source/scriptinterface/tests/test_ScriptInterface.h =================================================================== --- source/scriptinterface/tests/test_ScriptInterface.h +++ source/scriptinterface/tests/test_ScriptInterface.h @@ -28,7 +28,7 @@ public: void test_loadscript_basic() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); TestLogger logger; TS_ASSERT(script.LoadScript(L"test.js", "var x = 1+1;")); TS_ASSERT_STR_NOT_CONTAINS(logger.GetOutput(), "JavaScript error"); @@ -37,7 +37,7 @@ void test_loadscript_error() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); TestLogger logger; TS_ASSERT(!script.LoadScript(L"test.js", "1+")); TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "JavaScript error: test.js line 1\nSyntaxError: expected expression, got end of script"); @@ -45,7 +45,7 @@ void test_loadscript_strict_warning() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); TestLogger logger; // in strict mode, this inside a function doesn't point to the global object TS_ASSERT(script.LoadScript(L"test.js", "var isStrict = (function() { return !this; })();warn('isStrict is '+isStrict);")); @@ -54,7 +54,7 @@ void test_loadscript_strict_error() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); TestLogger logger; TS_ASSERT(!script.LoadScript(L"test.js", "with(1){}")); TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "JavaScript error: test.js line 1\nSyntaxError: strict mode code may not contain \'with\' statements"); @@ -62,8 +62,8 @@ void test_clone_basic() { - ScriptInterface script1("Test", "Test", g_ScriptRuntime); - ScriptInterface script2("Test", "Test", g_ScriptRuntime); + ScriptInterface script1("Test", "Test", g_ScriptContext); + ScriptInterface script2("Test", "Test", g_ScriptContext); ScriptInterface::Request rq1(script1); JS::RootedValue obj1(rq1.cx); @@ -83,8 +83,8 @@ void test_clone_getters() { // The tests should be run with JS_SetGCZeal so this can try to find GC bugs - ScriptInterface script1("Test", "Test", g_ScriptRuntime); - ScriptInterface script2("Test", "Test", g_ScriptRuntime); + ScriptInterface script1("Test", "Test", g_ScriptContext); + ScriptInterface script2("Test", "Test", g_ScriptContext); ScriptInterface::Request rq1(script1); @@ -104,8 +104,8 @@ void test_clone_cyclic() { - ScriptInterface script1("Test", "Test", g_ScriptRuntime); - ScriptInterface script2("Test", "Test", g_ScriptRuntime); + ScriptInterface script1("Test", "Test", g_ScriptContext); + ScriptInterface script2("Test", "Test", g_ScriptContext); ScriptInterface::Request rq1(script1); @@ -136,7 +136,7 @@ */ void test_rooted_templates() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); @@ -215,7 +215,7 @@ void test_random() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); double d1, d2; TS_ASSERT(script.Eval("Math.random()", d1)); @@ -235,7 +235,7 @@ void test_json() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); std::string input = "({'x':1,'z':[2,'3\\u263A\\ud800'],\"y\":true})"; @@ -253,7 +253,7 @@ // extends the functionality and is then assigned to the name of the function. void test_function_override() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); TS_ASSERT(script.Eval( Index: source/simulation2/Simulation2.h =================================================================== --- source/simulation2/Simulation2.h +++ source/simulation2/Simulation2.h @@ -35,7 +35,7 @@ class IComponent; class SceneCollector; class ScriptInterface; -class ScriptRuntime; +class ScriptContext; /** * Public API for simulation system. @@ -48,7 +48,7 @@ public: // TODO: CUnitManager should probably be handled automatically by this // module, but for now we'll have it passed in externally instead - CSimulation2(CUnitManager* unitManager, shared_ptr rt, CTerrain* terrain); + CSimulation2(CUnitManager* unitManager, shared_ptr rt, CTerrain* terrain); ~CSimulation2(); void EnableSerializationTest(); Index: source/simulation2/Simulation2.cpp =================================================================== --- source/simulation2/Simulation2.cpp +++ source/simulation2/Simulation2.cpp @@ -19,8 +19,8 @@ #include "Simulation2.h" +#include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptInterface.h" -#include "scriptinterface/ScriptRuntime.h" #include "simulation2/MessageTypes.h" #include "simulation2/system/ComponentManager.h" @@ -49,7 +49,7 @@ class CSimulation2Impl { public: - CSimulation2Impl(CUnitManager* unitManager, shared_ptr rt, CTerrain* terrain) : + CSimulation2Impl(CUnitManager* unitManager, shared_ptr rt, CTerrain* terrain) : m_SimContext(), m_ComponentManager(m_SimContext, rt), m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false), m_SecondaryTerrain(nullptr), m_SecondaryContext(nullptr), m_SecondaryComponentManager(nullptr), m_SecondaryLoadedScripts(nullptr), @@ -411,7 +411,7 @@ m_SecondaryContext->m_Terrain = m_SecondaryTerrain; delete m_SecondaryComponentManager; - m_SecondaryComponentManager = new CComponentManager(*m_SecondaryContext, scriptInterface.GetRuntime()); + m_SecondaryComponentManager = new CComponentManager(*m_SecondaryContext, scriptInterface.GetContext()); m_SecondaryComponentManager->LoadComponentTypes(); delete m_SecondaryLoadedScripts; @@ -505,9 +505,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.GetRuntime()->ShrinkingGC(); + scriptInterface.GetContext()->ShrinkingGC(); else - scriptInterface.GetRuntime()->MaybeIncrementalGC(0.0f); + scriptInterface.GetContext()->MaybeIncrementalGC(0.0f); if (m_EnableOOSLog) DumpState(); @@ -638,7 +638,7 @@ //////////////////////////////////////////////////////////////// -CSimulation2::CSimulation2(CUnitManager* unitManager, shared_ptr rt, CTerrain* terrain) : +CSimulation2::CSimulation2(CUnitManager* unitManager, shared_ptr rt, CTerrain* terrain) : m(new CSimulation2Impl(unitManager, rt, terrain)) { } Index: source/simulation2/components/CCmpAIManager.cpp =================================================================== --- source/simulation2/components/CCmpAIManager.cpp +++ source/simulation2/components/CCmpAIManager.cpp @@ -32,7 +32,7 @@ #include "ps/scripting/JSInterface_VFS.h" #include "ps/TemplateLoader.h" #include "ps/Util.h" -#include "scriptinterface/ScriptRuntime.h" +#include "scriptinterface/ScriptContext.h" #include "simulation2/components/ICmpAIInterface.h" #include "simulation2/components/ICmpCommandQueue.h" #include "simulation2/components/ICmpObstructionManager.h" @@ -196,7 +196,7 @@ bool m_UseSharedComponent; // Take care to keep this declaration before heap rooted members. Destructors of heap rooted - // members have to be called before the runtime destructor. + // members have to be called before the context destructor. shared_ptr m_ScriptInterface; JS::PersistentRootedValue m_Obj; @@ -211,15 +211,15 @@ }; CAIWorker() : - m_ScriptInterface(new ScriptInterface("Engine", "AI", g_ScriptRuntime)), + m_ScriptInterface(new ScriptInterface("Engine", "AI", g_ScriptContext)), m_TurnNum(0), m_CommandsComputed(true), m_HasLoadedEntityTemplates(false), m_HasSharedComponent(false), - m_EntityTemplates(g_ScriptRuntime->GetJSRuntime()), - m_SharedAIObj(g_ScriptRuntime->GetJSRuntime()), - m_PassabilityMapVal(g_ScriptRuntime->GetJSRuntime()), - m_TerritoryMapVal(g_ScriptRuntime->GetJSRuntime()) + m_EntityTemplates(g_ScriptContext->GetJSRuntime()), + m_SharedAIObj(g_ScriptContext->GetJSRuntime()), + m_PassabilityMapVal(g_ScriptContext->GetJSRuntime()), + m_TerritoryMapVal(g_ScriptContext->GetJSRuntime()) { m_ScriptInterface->ReplaceNondeterministicRNG(m_RNG); @@ -869,8 +869,8 @@ } // Take care to keep this declaration before heap rooted members. Destructors of heap rooted - // members have to be called before the runtime destructor. - shared_ptr m_ScriptRuntime; + // members have to be called before the context destructor. + shared_ptr m_ScriptContext; shared_ptr m_ScriptInterface; boost::rand48 m_RNG; Index: source/simulation2/components/tests/test_CinemaManager.h =================================================================== --- source/simulation2/components/tests/test_CinemaManager.h +++ source/simulation2/components/tests/test_CinemaManager.h @@ -34,7 +34,7 @@ void test_basic() { - ComponentTestHelper test(g_ScriptRuntime); + 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 @@ -34,7 +34,7 @@ void test_basic() { - ComponentTestHelper test(g_ScriptRuntime); + ComponentTestHelper test(g_ScriptContext); ScriptInterface::Request 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 @@ -103,7 +103,7 @@ ent3z = ent2z + ent2c + ent3c; // ensure it just touches the border of ent2 ent3g = ent3; - testHelper = new ComponentTestHelper(g_ScriptRuntime); + 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 @@ -139,7 +139,7 @@ { CTerrain terrain; - CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain); + CSimulation2 sim2(NULL, g_ScriptContext, &terrain); sim2.LoadDefaultScripts(); sim2.ResetState(); @@ -196,7 +196,7 @@ CTerrain terrain; terrain.Initialize(5, NULL); - CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain); + CSimulation2 sim2(NULL, g_ScriptContext, &terrain); sim2.LoadDefaultScripts(); sim2.ResetState(); @@ -250,7 +250,7 @@ { CTerrain terrain; - CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain); + CSimulation2 sim2(NULL, g_ScriptContext, &terrain); sim2.LoadDefaultScripts(); sim2.ResetState(); @@ -307,7 +307,7 @@ { CTerrain terrain; - CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain); + CSimulation2 sim2(NULL, g_ScriptContext, &terrain); sim2.LoadDefaultScripts(); sim2.ResetState(); Index: source/simulation2/components/tests/test_Position.h =================================================================== --- source/simulation2/components/tests/test_Position.h +++ source/simulation2/components/tests/test_Position.h @@ -64,7 +64,7 @@ void test_basic() { - ComponentTestHelper test(g_ScriptRuntime); + ComponentTestHelper test(g_ScriptContext); MockTerrain terrain; test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain); @@ -136,7 +136,7 @@ void test_water() { - ComponentTestHelper test(g_ScriptRuntime); + ComponentTestHelper test(g_ScriptContext); MockTerrain terrain; test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain); @@ -209,7 +209,7 @@ void test_serialize() { - ComponentTestHelper test(g_ScriptRuntime); + 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 @@ -87,7 +87,7 @@ void test_basic() { - ComponentTestHelper test(g_ScriptRuntime); + ComponentTestHelper test(g_ScriptContext); ICmpRangeManager* cmp = test.Add(CID_RangeManager, "", SYSTEM_ENTITY); Index: source/simulation2/components/tests/test_scripts.h =================================================================== --- source/simulation2/components/tests/test_scripts.h +++ source/simulation2/components/tests/test_scripts.h @@ -69,7 +69,7 @@ for (const VfsPath& path : paths) { CSimContext context; - CComponentManager componentManager(context, g_ScriptRuntime, true); + CComponentManager componentManager(context, g_ScriptContext, true); ScriptTestSetup(componentManager.GetScriptInterface()); load_script(componentManager.GetScriptInterface(), path); } @@ -90,7 +90,7 @@ for (const VfsPath& path : paths) { CSimContext context; - CComponentManager componentManager(context, g_ScriptRuntime, 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 @@ -74,7 +74,7 @@ }; public: - CComponentManager(CSimContext&, shared_ptr rt, bool skipScriptFunctions = false); + CComponentManager(CSimContext&, shared_ptr rt, bool skipScriptFunctions = false); ~CComponentManager(); void LoadComponentTypes(); Index: source/simulation2/system/ComponentManager.cpp =================================================================== --- source/simulation2/system/ComponentManager.cpp +++ source/simulation2/system/ComponentManager.cpp @@ -53,7 +53,7 @@ JS::PersistentRootedValue msg; }; -CComponentManager::CComponentManager(CSimContext& context, shared_ptr rt, bool skipScriptFunctions) : +CComponentManager::CComponentManager(CSimContext& context, shared_ptr rt, bool skipScriptFunctions) : m_NextScriptComponentTypeId(CID__LastNative), m_ScriptInterface("Engine", "Simulation", rt), m_SimContext(context), m_CurrentlyHotloading(false) Index: source/simulation2/system/ComponentTest.h =================================================================== --- source/simulation2/system/ComponentTest.h +++ source/simulation2/system/ComponentTest.h @@ -56,8 +56,8 @@ bool m_isSystemEntityInit = false; public: - ComponentTestHelper(shared_ptr runtime) : - m_Context(), m_ComponentManager(m_Context, runtime), m_Cmp(NULL) + ComponentTestHelper(shared_ptr scriptContext) : + m_Context(), m_ComponentManager(m_Context, scriptContext), m_Cmp(NULL) { m_ComponentManager.LoadComponentTypes(); } @@ -147,7 +147,7 @@ CStdSerializer std1(GetScriptInterface(), stdstr1); m_Cmp->Serialize(std1); - ComponentTestHelper test2(GetScriptInterface().GetRuntime()); + ComponentTestHelper test2(GetScriptInterface().GetContext()); // (We should never need to add any mock objects etc to test2, since deserialization // mustn't depend on other components already existing) Index: source/simulation2/tests/test_CmpTemplateManager.h =================================================================== --- source/simulation2/tests/test_CmpTemplateManager.h +++ source/simulation2/tests/test_CmpTemplateManager.h @@ -52,7 +52,7 @@ void test_LoadTemplate() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -86,7 +86,7 @@ void test_LoadTemplate_scriptcache() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -146,7 +146,7 @@ void test_LoadTemplate_errors() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -178,7 +178,7 @@ void test_LoadTemplate_multiple() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1, ent2 = 2; @@ -238,7 +238,7 @@ void test_load_all_DISABLED() // disabled since it's a bit slow and noisy { CTerrain dummy; - CSimulation2 sim(NULL, g_ScriptRuntime, &dummy); + CSimulation2 sim(NULL, g_ScriptContext, &dummy); sim.LoadDefaultScripts(); sim.ResetState(); Index: source/simulation2/tests/test_ComponentManager.h =================================================================== --- source/simulation2/tests/test_ComponentManager.h +++ source/simulation2/tests/test_ComponentManager.h @@ -59,14 +59,14 @@ void test_Load() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); } void test_LookupCID() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + 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_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); ScriptTestSetup(man.m_ScriptInterface); man.LoadComponentTypes(); @@ -380,7 +380,7 @@ void test_script_entityID() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); ScriptTestSetup(man.m_ScriptInterface); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-entityid.js")); @@ -400,7 +400,7 @@ void test_script_QueryInterface() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-query.js")); @@ -421,7 +421,7 @@ void test_script_AddEntity() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + 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")); @@ -454,7 +454,7 @@ void test_script_AddLocalEntity() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + 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")); @@ -487,7 +487,7 @@ void test_script_DestroyEntity() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-destroyentity.js")); @@ -507,7 +507,7 @@ void test_script_messages() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-msg.js")); @@ -540,7 +540,7 @@ void test_script_template() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js")); @@ -562,7 +562,7 @@ void test_script_template_readonly() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js")); @@ -584,7 +584,7 @@ void test_script_hotload() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-hotload1.js")); @@ -620,7 +620,7 @@ void test_script_modding() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); CParamNode testParam; @@ -645,7 +645,7 @@ void test_serialization() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 10, ent2 = 20, ent3 = FIRST_LOCAL_ENTITY; @@ -716,7 +716,7 @@ ); CSimContext context2; - CComponentManager man2(context2, g_ScriptRuntime); + CComponentManager man2(context2, g_ScriptContext); man2.LoadComponentTypes(); TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL); @@ -736,7 +736,7 @@ { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); ScriptTestSetup(man.m_ScriptInterface); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); @@ -812,7 +812,7 @@ TS_ASSERT(man.SerializeState(stateStream)); CSimContext context2; - CComponentManager man2(context2, g_ScriptRuntime); + CComponentManager man2(context2, g_ScriptContext); man2.LoadComponentTypes(); TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js")); @@ -829,7 +829,7 @@ void test_script_serialization_errors() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); @@ -848,7 +848,7 @@ { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js")); man.InitSystemEntity(); @@ -872,7 +872,7 @@ TS_ASSERT(man.SerializeState(stateStream)); CSimContext context2; - CComponentManager man2(context2, g_ScriptRuntime); + CComponentManager man2(context2, g_ScriptContext); man2.LoadComponentTypes(); TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js")); @@ -883,7 +883,7 @@ void test_dynamic_subscription() { CSimContext context; - CComponentManager man(context, g_ScriptRuntime); + CComponentManager man(context, g_ScriptContext); man.LoadComponentTypes(); entity_id_t ent1 = 1; Index: source/simulation2/tests/test_SerializeTemplates.h =================================================================== --- source/simulation2/tests/test_SerializeTemplates.h +++ source/simulation2/tests/test_SerializeTemplates.h @@ -31,7 +31,7 @@ public: void test_Debug_array() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CDebugSerializer serialize(script, stream); @@ -44,7 +44,7 @@ void test_Debug_vector() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CDebugSerializer serialize(script, stream); @@ -57,7 +57,7 @@ void test_Debug_set() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CDebugSerializer serialize(script, stream); @@ -70,7 +70,7 @@ void test_Debug_grid() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CDebugSerializer serialize(script, stream); Index: source/simulation2/tests/test_Serializer.h =================================================================== --- source/simulation2/tests/test_Serializer.h +++ source/simulation2/tests/test_Serializer.h @@ -74,7 +74,7 @@ void test_Debug_basic() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CDebugSerializer serialize(script, stream); serialize.NumberI32_Unbounded("x", -123); @@ -85,7 +85,7 @@ void test_Debug_floats() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CDebugSerializer serialize(script, stream); serialize.NumberFloat_Unbounded("x", 1e4f); @@ -116,7 +116,7 @@ void test_Debug_types() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CDebugSerializer serialize(script, stream); @@ -147,7 +147,7 @@ void test_Std_basic() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CStdSerializer serialize(script, stream); @@ -174,7 +174,7 @@ void test_Std_types() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CStdSerializer serialize(script, stream); @@ -241,7 +241,7 @@ void test_Hash_basic() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); CHashSerializer serialize(script); serialize.NumberI32_Unbounded("x", -123); @@ -255,7 +255,7 @@ void test_Hash_stream() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); CHashSerializer hashSerialize(script); hashSerialize.NumberI32_Unbounded("x", -123); @@ -278,7 +278,7 @@ void test_bounds() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); std::stringstream stream; CDebugSerializer serialize(script, stream); serialize.NumberI32("x", 16, -16, 16); @@ -291,7 +291,7 @@ void helper_script_roundtrip(const char* msg, const char* input, const char* expected, size_t expstreamlen = 0, const char* expstream = NULL, const char* debug = NULL) { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); JS::RootedValue obj(rq.cx); @@ -753,7 +753,7 @@ void test_script_exceptions() { - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); JS::RootedValue obj(rq.cx); @@ -787,7 +787,7 @@ { const char* input = "var x = {}; for (var i=0;i<256;++i) x[i]=Math.pow(i, 2); x"; - ScriptInterface script("Test", "Test", g_ScriptRuntime); + ScriptInterface script("Test", "Test", g_ScriptContext); ScriptInterface::Request rq(script); JS::RootedValue obj(rq.cx); @@ -832,7 +832,7 @@ CTerrain terrain; - CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain); + CSimulation2 sim2(NULL, g_ScriptContext, &terrain); sim2.LoadDefaultScripts(); sim2.ResetState(); Index: source/simulation2/tests/test_Simulation2.h =================================================================== --- source/simulation2/tests/test_Simulation2.h +++ source/simulation2/tests/test_Simulation2.h @@ -57,7 +57,7 @@ void test_AddEntity() { - CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain); + CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain); TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/")); sim.ResetState(true, true); @@ -77,7 +77,7 @@ void test_DestroyEntity() { - CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain); + CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain); TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/")); sim.ResetState(true, true); @@ -133,7 +133,7 @@ void test_hotload_scripts() { - CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain); + CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain); TS_ASSERT_OK(CreateDirectories(DataDir()/"mods"/"_test.sim"/"simulation"/"components"/"hotload"/"", 0700)); Index: source/test_setup.cpp =================================================================== --- source/test_setup.cpp +++ source/test_setup.cpp @@ -37,7 +37,7 @@ #include "lib/sysdep/sysdep.h" #include "ps/Profiler2.h" #include "scriptinterface/ScriptEngine.h" -#include "scriptinterface/ScriptRuntime.h" +#include "scriptinterface/ScriptContext.h" class LeakReporter : public CxxTest::GlobalFixture { @@ -80,14 +80,14 @@ g_Profiler2.Initialise(); m_ScriptEngine = new ScriptEngine; - g_ScriptRuntime = ScriptRuntime::CreateRuntime(); + g_ScriptContext = ScriptContext::CreateContext(); return true; } virtual bool tearDownWorld() { - g_ScriptRuntime.reset(); + g_ScriptContext.reset(); SAFE_DELETE(m_ScriptEngine); g_Profiler2.Shutdown(); Index: source/tools/atlas/GameInterface/ActorViewer.cpp =================================================================== --- source/tools/atlas/GameInterface/ActorViewer.cpp +++ source/tools/atlas/GameInterface/ActorViewer.cpp @@ -69,7 +69,7 @@ MeshManager(ColladaManager), SkeletonAnimManager(ColladaManager), UnitManager(), - Simulation2(&UnitManager, g_ScriptRuntime, &Terrain), + Simulation2(&UnitManager, g_ScriptContext, &Terrain), ObjectManager(MeshManager, SkeletonAnimManager, Simulation2), LOSTexture(Simulation2), TerritoryTexture(Simulation2)