1
0
forked from 0ad/0ad

Rename ScriptRuntime to ScriptContext

SM52 essentially replaces JSRuntime with JSContext (though JSContext
itself was replaced with JSCompartment).
To prepare for this migration, rename all Runtime-related things to
Context.

Part of the SM52 migration, stage: SM45 compatible.

Patch by: Itms
Refs #4893

Differential Revision: https://code.wildfiregames.com/D3091
This was SVN commit r24181.
This commit is contained in:
wraitii 2020-11-14 10:57:50 +00:00
parent aae417bd29
commit aa15066c69
49 changed files with 250 additions and 250 deletions

View File

@ -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 <vector>
// 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 @@ void* CMapGeneratorWorker::RunThread(CMapGeneratorWorker* self)
debug_SetThreadName("MapGenerator");
g_Profiler2.RegisterCurrentThread("MapGenerator");
shared_ptr<ScriptRuntime> mapgenRuntime = ScriptRuntime::CreateRuntime(RMS_RUNTIME_SIZE);
shared_ptr<ScriptContext> 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)

View File

@ -81,7 +81,7 @@ private:
* 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
{

View File

@ -28,7 +28,7 @@ class TestLOSTexture : public CxxTest::TestSuite
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 @@ public:
void test_perf_DISABLED()
{
CSimulation2 sim(NULL, g_ScriptRuntime, NULL);
CSimulation2 sim(NULL, g_ScriptContext, NULL);
CLOSTexture tex(sim);
const ssize_t size = 257;

View File

@ -49,7 +49,7 @@ public:
for (const VfsPath& path : paths)
{
ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptRuntime);
ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptContext);
ScriptTestSetup(scriptInterface);
CMapGeneratorWorker worker(&scriptInterface);

View File

@ -61,13 +61,13 @@ const CStr CGUI::EventNameMouseLeftRelease = "MouseLeftRelease";
const CStr CGUI::EventNameMouseRightDoubleClick = "MouseRightDoubleClick";
const CStr CGUI::EventNameMouseRightRelease = "MouseRightRelease";
CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
CGUI::CGUI(const shared_ptr<ScriptContext>& 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);

View File

@ -57,7 +57,7 @@ private:
using ConstructObjectFunction = IGUIObject* (*)(CGUI&);
public:
CGUI(const shared_ptr<ScriptRuntime>& runtime);
CGUI(const shared_ptr<ScriptContext>& context);
~CGUI();
/**

View File

@ -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 @@ static Status ReloadChangedFileCB(void* param, const VfsPath& path)
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 @@ void CGUIManager::PushPage(const CStrW& pageName, shared_ptr<ScriptInterface::St
// 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<ScriptInterface::StructuredClone> args)
@ -126,7 +126,7 @@ CGUIManager::SGUIPage::SGUIPage(const CStrW& pageName, const shared_ptr<ScriptIn
{
}
void CGUIManager::SGUIPage::LoadPage(shared_ptr<ScriptRuntime> scriptRuntime)
void CGUIManager::SGUIPage::LoadPage(shared_ptr<ScriptContext> scriptContext)
{
// If we're hotloading then try to grab some data from the previous page
shared_ptr<ScriptInterface::StructuredClone> hotloadData;
@ -143,7 +143,7 @@ void CGUIManager::SGUIPage::LoadPage(shared_ptr<ScriptRuntime> scriptRuntime)
g_CursorName = g_DefaultCursor;
inputs.clear();
gui.reset(new CGUI(scriptRuntime));
gui.reset(new CGUI(scriptContext));
gui->AddObjectTypes();
@ -268,7 +268,7 @@ Status CGUIManager::ReloadChangedFile(const VfsPath& path)
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 @@ Status CGUIManager::ReloadAllPages()
{
// 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 @@ void CGUIManager::TickObjects()
{
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;

View File

@ -50,7 +50,7 @@ public:
{
return m_ScriptInterface;
}
shared_ptr<ScriptRuntime> GetRuntime() { return m_ScriptRuntime; }
shared_ptr<ScriptContext> GetContext() { return m_ScriptContext; }
shared_ptr<CGUI> GetActiveGUI() { return top(); }
/**
@ -137,7 +137,7 @@ private:
/**
* Create the CGUI with it's own ScriptInterface. Deletes the previous CGUI if it existed.
*/
void LoadPage(shared_ptr<ScriptRuntime> scriptRuntime);
void LoadPage(shared_ptr<ScriptContext> scriptContext);
/**
* Sets the callback handler when a new page is opened that will be performed when the page is closed.
@ -165,7 +165,7 @@ private:
shared_ptr<CGUI> top() const;
shared_ptr<ScriptRuntime> m_ScriptRuntime;
shared_ptr<ScriptContext> m_ScriptContext;
shared_ptr<ScriptInterface> m_ScriptInterface;
using PageStackType = std::vector<SGUIPage>;

View File

@ -501,7 +501,7 @@ static void RunRLServer(const bool isNonVisual, const std::vector<OsPath> modsTo
// 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 @@ static void RunGameOrAtlas(int argc, const char* argv[])
// 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();
}

View File

@ -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::RunThread(CNetServerWorker* data)
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<ScriptRuntime> 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<ScriptContext> 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 @@ bool CNetServerWorker::RunStep()
// (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);

View File

@ -136,7 +136,7 @@ public:
// 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 @@ public:
void test_rejoin_DISABLED()
{
ScriptInterface scriptInterface("Engine", "Test", g_ScriptRuntime);
ScriptInterface scriptInterface("Engine", "Test", g_ScriptContext);
ScriptInterface::Request rq(scriptInterface);
TestStdoutLogger logger;

View File

@ -26,7 +26,7 @@ class TestNetMessage : public CxxTest::TestSuite
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);

View File

@ -67,7 +67,7 @@ const CStr CGame::EventNameSimulationUpdate = "SimulationUpdate";
**/
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),

View File

@ -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_DoRenderGui = true;
bool g_DoRenderLogger = true;
bool g_DoRenderCursor = true;
thread_local shared_ptr<ScriptRuntime> g_ScriptRuntime;
thread_local shared_ptr<ScriptContext> g_ScriptContext;
static const int SANE_TEX_QUALITY_DEFAULT = 5; // keep in sync with code
@ -725,7 +725,7 @@ from_config:
// 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 @@ bool Init(const CmdLineArgs& args, int flags)
// 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();

View File

@ -141,7 +141,7 @@ void RunHardwareDetection()
{
TIMER(L"RunHardwareDetection");
ScriptInterface scriptInterface("Engine", "HWDetect", g_ScriptRuntime);
ScriptInterface scriptInterface("Engine", "HWDetect", g_ScriptContext);
ScriptInterface::Request rq(scriptInterface);

View File

@ -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<CStr> g_modsLoaded;
@ -104,9 +104,9 @@ JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface)
return JS::ObjectValue(*obj);
}
void Mod::CacheEnabledModVersions(const shared_ptr<ScriptRuntime>& scriptRuntime)
void Mod::CacheEnabledModVersions(const shared_ptr<ScriptContext>& scriptContext)
{
ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptRuntime);
ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptContext);
ScriptInterface::Request rq(scriptInterface);
JS::RootedValue availableMods(rq.cx, GetAvailableMods(scriptInterface));

View File

@ -22,7 +22,7 @@
#include "ps/GameSetup/CmdLineArgs.h"
#include "scriptinterface/ScriptInterface.h"
class ScriptRuntime;
class ScriptContext;
extern std::vector<CStr> g_modsLoaded;
extern CmdLineArgs g_args;
@ -37,7 +37,7 @@ namespace Mod
* 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>& scriptRuntime);
void CacheEnabledModVersions(const shared_ptr<ScriptContext>& scriptContext);
/**
* Get the loaded mods and their version.

View File

@ -40,7 +40,7 @@ CModInstaller::~CModInstaller()
CModInstaller::ModInstallationResult CModInstaller::Install(
const OsPath& mod,
const std::shared_ptr<ScriptRuntime>& scriptRuntime,
const std::shared_ptr<ScriptContext>& scriptContext,
bool keepFile)
{
const OsPath modTemp = m_TempDir / mod.Basename() / mod.Filename().ChangeExtension(L".zip");
@ -63,7 +63,7 @@ CModInstaller::ModInstallationResult CModInstaller::Install(
// 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);

View File

@ -57,7 +57,7 @@ public:
*/
ModInstallationResult Install(
const OsPath& mod,
const std::shared_ptr<ScriptRuntime>& scriptRuntime,
const std::shared_ptr<ScriptContext>& scriptContext,
bool keepFile);
/**

View File

@ -483,7 +483,7 @@ bool ModIo::AdvanceRequest(const ScriptInterface& scriptInterface)
{
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:

View File

@ -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 @@ void CReplayPlayer::Replay(const bool serializationtest, const int rejointesttur
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 @@ void CReplayPlayer::Replay(const bool serializationtest, const int rejointesttur
// 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;

View File

@ -42,7 +42,7 @@ public:
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 @@ public:
void test_mods_parsing()
{
ScriptInterface script("Test", "Test", g_ScriptRuntime);
ScriptInterface script("Test", "Test", g_ScriptContext);
PKStruct pk;

View File

@ -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 @@ void ErrorReporter(JSContext* cx, const char* message, JSErrorReport* report)
} // anonymous namespace
shared_ptr<ScriptRuntime> ScriptRuntime::CreateRuntime(int runtimeSize, int heapGrowthBytesGCTrigger)
shared_ptr<ScriptContext> ScriptContext::CreateContext(int contextSize, int heapGrowthBytesGCTrigger)
{
return shared_ptr<ScriptRuntime>(new ScriptRuntime(runtimeSize, heapGrowthBytesGCTrigger));
return shared_ptr<ScriptContext>(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 @@ ScriptRuntime::ScriptRuntime(int runtimeSize, int heapGrowthBytesGCTrigger):
.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 @@ void ScriptRuntime::MaybeIncrementalGC(double delay)
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::MaybeIncrementalGC(double delay)
}
}
void ScriptRuntime::ShrinkingGC()
void ScriptContext::ShrinkingGC()
{
JS_SetGCParameter(m_rt, JSGC_MODE, JSGC_MODE_COMPARTMENT);
JS::PrepareForFullGC(m_rt);
@ -317,7 +317,7 @@ void ScriptRuntime::ShrinkingGC()
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));

View File

@ -15,8 +15,8 @@
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#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<ScriptRuntime> CreateRuntime(
int runtimeSize = DEFAULT_RUNTIME_SIZE,
static shared_ptr<ScriptContext> 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 @@ private:
void PrepareCompartmentsForIncrementalGC() const;
std::list<JSCompartment*> m_Compartments;
int m_RuntimeSize;
int m_ContextSize;
int m_HeapGrowthBytesGCTrigger;
int m_LastGCBytes;
double m_LastGCCheck;
};
#endif // INCLUDED_SCRIPTRUNTIME
#endif // INCLUDED_SCRIPTCONTEXT

View File

@ -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<ScriptEngine>
@ -36,21 +36,21 @@ class ScriptEngine : public Singleton<ScriptEngine>
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<const JSRuntime*> m_Runtimes;
std::list<const JSContext*> m_Contexts;
};
#endif // INCLUDED_SCRIPTENGINE

View File

@ -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<ScriptRuntime>& runtime);
ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptContext>& 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<ScriptRuntime> m_runtime;
// members have to be called before the context destructor.
shared_ptr<ScriptContext> m_context;
friend ScriptInterface::Request;
private:
@ -318,8 +318,8 @@ bool ScriptInterface::MathRandom(double& nbr)
return true;
}
ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& 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<ScriptContext>& 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 @@ ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const sh
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 @@ void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs)
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<ScriptRuntime>& runtime) :
m(new ScriptInterface_impl(nativeScopeName, runtime))
ScriptInterface::ScriptInterface(const char* nativeScopeName, const char* debugName, const shared_ptr<ScriptContext>& 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 @@ void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs) co
JSRuntime* ScriptInterface::GetJSRuntime() const
{
return m->m_runtime->GetJSRuntime();
return m->m_context->GetJSRuntime();
}
shared_ptr<ScriptRuntime> ScriptInterface::GetRuntime() const
shared_ptr<ScriptContext> ScriptInterface::GetContext() const
{
return m->m_runtime;
return m->m_context;
}
void ScriptInterface::CallConstructor(JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out) const

View File

@ -50,11 +50,11 @@ ERROR_TYPE(Scripting_DefineType, CreationFailed);
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<ScriptRuntime> 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<ScriptContext> g_ScriptContext;
/**
@ -76,9 +76,9 @@ public:
* @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<ScriptRuntime>& runtime);
ScriptInterface(const char* nativeScopeName, const char* debugName, const shared_ptr<ScriptContext>& context);
~ScriptInterface();
@ -92,7 +92,7 @@ public:
static CmptPrivate* GetScriptInterfaceAndCBData(JSContext* cx);
JSRuntime* GetJSRuntime() const;
shared_ptr<ScriptRuntime> GetRuntime() const;
shared_ptr<ScriptContext> GetContext() const;
/**
* RAII structure which encapsulates an access to the context and compartment of a ScriptInterface.

View File

@ -33,7 +33,7 @@ class TestScriptConversions : public CxxTest::TestSuite
template <typename T>
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 @@ class TestScriptConversions : public CxxTest::TestSuite
template <typename T>
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 @@ class TestScriptConversions : public CxxTest::TestSuite
template <typename T>
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 @@ public:
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 @@ public:
roundtrip<float>(-std::numeric_limits<float>::infinity(), "-Infinity");
convert_to<float>(std::numeric_limits<float>::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 @@ public:
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);

View File

@ -28,7 +28,7 @@ class TestScriptInterface : public CxxTest::TestSuite
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
*/
void test_rooted_templates()
{
ScriptInterface script("Test", "Test", g_ScriptRuntime);
ScriptInterface script("Test", "Test", g_ScriptContext);
ScriptInterface::Request rq(script);
@ -215,7 +215,7 @@ public:
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 @@ public:
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 @@ public:
// 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(

View File

@ -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<ScriptRuntime> rt, CTerrain* terrain) :
CSimulation2Impl(CUnitManager* unitManager, shared_ptr<ScriptContext> 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 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
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 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
// (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 @@ void CSimulation2Impl::DumpState()
////////////////////////////////////////////////////////////////
CSimulation2::CSimulation2(CUnitManager* unitManager, shared_ptr<ScriptRuntime> rt, CTerrain* terrain) :
CSimulation2::CSimulation2(CUnitManager* unitManager, shared_ptr<ScriptContext> rt, CTerrain* terrain) :
m(new CSimulation2Impl(unitManager, rt, terrain))
{
}

View File

@ -35,7 +35,7 @@ class CUnitManager;
class IComponent;
class SceneCollector;
class ScriptInterface;
class ScriptRuntime;
class ScriptContext;
/**
* Public API for simulation system.
@ -48,7 +48,7 @@ class CSimulation2
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<ScriptRuntime> rt, CTerrain* terrain);
CSimulation2(CUnitManager* unitManager, shared_ptr<ScriptContext> rt, CTerrain* terrain);
~CSimulation2();
void EnableSerializationTest();

View File

@ -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 @@ private:
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<ScriptInterface> m_ScriptInterface;
JS::PersistentRootedValue m_Obj;
@ -211,15 +211,15 @@ public:
};
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 @@ private:
}
// 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<ScriptRuntime> m_ScriptRuntime;
// members have to be called before the context destructor.
shared_ptr<ScriptContext> m_ScriptContext;
shared_ptr<ScriptInterface> m_ScriptInterface;
boost::rand48 m_RNG;

View File

@ -34,7 +34,7 @@ public:
void test_basic()
{
ComponentTestHelper test(g_ScriptRuntime);
ComponentTestHelper test(g_ScriptContext);
ICmpCinemaManager* cmp = test.Add<ICmpCinemaManager>(CID_CinemaManager, "", SYSTEM_ENTITY);

View File

@ -34,7 +34,7 @@ public:
void test_basic()
{
ComponentTestHelper test(g_ScriptRuntime);
ComponentTestHelper test(g_ScriptContext);
ScriptInterface::Request rq(test.GetScriptInterface());
std::vector<SimulationCommand> empty;

View File

@ -103,7 +103,7 @@ public:
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<ICmpObstructionManager>(CID_ObstructionManager, "", SYSTEM_ENTITY);
cmp->SetBounds(fixed::FromInt(0), fixed::FromInt(0), fixed::FromInt(1000), fixed::FromInt(1000));

View File

@ -139,7 +139,7 @@ public:
{
CTerrain terrain;
CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain);
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
sim2.LoadDefaultScripts();
sim2.ResetState();
@ -196,7 +196,7 @@ public:
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 @@ public:
{
CTerrain terrain;
CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain);
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
sim2.LoadDefaultScripts();
sim2.ResetState();
@ -307,7 +307,7 @@ public:
{
CTerrain terrain;
CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain);
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
sim2.LoadDefaultScripts();
sim2.ResetState();

View File

@ -64,7 +64,7 @@ public:
void test_basic()
{
ComponentTestHelper test(g_ScriptRuntime);
ComponentTestHelper test(g_ScriptContext);
MockTerrain terrain;
test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain);
@ -136,7 +136,7 @@ public:
void test_water()
{
ComponentTestHelper test(g_ScriptRuntime);
ComponentTestHelper test(g_ScriptContext);
MockTerrain terrain;
test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain);
@ -209,7 +209,7 @@ public:
void test_serialize()
{
ComponentTestHelper test(g_ScriptRuntime);
ComponentTestHelper test(g_ScriptContext);
MockTerrain terrain;
test.AddMock(SYSTEM_ENTITY, IID_Terrain, terrain);

View File

@ -87,7 +87,7 @@ public:
void test_basic()
{
ComponentTestHelper test(g_ScriptRuntime);
ComponentTestHelper test(g_ScriptContext);
ICmpRangeManager* cmp = test.Add<ICmpRangeManager>(CID_RangeManager, "", SYSTEM_ENTITY);

View File

@ -69,7 +69,7 @@ public:
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 @@ public:
for (const VfsPath& path : paths)
{
CSimContext context;
CComponentManager componentManager(context, g_ScriptRuntime, true);
CComponentManager componentManager(context, g_ScriptContext, true);
ScriptTestSetup(componentManager.GetScriptInterface());

View File

@ -53,7 +53,7 @@ public:
JS::PersistentRootedValue msg;
};
CComponentManager::CComponentManager(CSimContext& context, shared_ptr<ScriptRuntime> rt, bool skipScriptFunctions) :
CComponentManager::CComponentManager(CSimContext& context, shared_ptr<ScriptContext> rt, bool skipScriptFunctions) :
m_NextScriptComponentTypeId(CID__LastNative),
m_ScriptInterface("Engine", "Simulation", rt),
m_SimContext(context), m_CurrentlyHotloading(false)

View File

@ -74,7 +74,7 @@ private:
};
public:
CComponentManager(CSimContext&, shared_ptr<ScriptRuntime> rt, bool skipScriptFunctions = false);
CComponentManager(CSimContext&, shared_ptr<ScriptContext> rt, bool skipScriptFunctions = false);
~CComponentManager();
void LoadComponentTypes();

View File

@ -56,8 +56,8 @@ class ComponentTestHelper
bool m_isSystemEntityInit = false;
public:
ComponentTestHelper(shared_ptr<ScriptRuntime> runtime) :
m_Context(), m_ComponentManager(m_Context, runtime), m_Cmp(NULL)
ComponentTestHelper(shared_ptr<ScriptContext> scriptContext) :
m_Context(), m_ComponentManager(m_Context, scriptContext), m_Cmp(NULL)
{
m_ComponentManager.LoadComponentTypes();
}
@ -147,7 +147,7 @@ public:
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)

View File

@ -52,7 +52,7 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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();

View File

@ -59,14 +59,14 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
void test_script_modding()
{
CSimContext context;
CComponentManager man(context, g_ScriptRuntime);
CComponentManager man(context, g_ScriptContext);
man.LoadComponentTypes();
CParamNode testParam;
@ -645,7 +645,7 @@ public:
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 @@ public:
);
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 @@ public:
{
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 @@ entities:\n\
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 @@ entities:\n\
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 @@ entities:\n\
{
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 @@ entities:\n\
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 @@ entities:\n\
void test_dynamic_subscription()
{
CSimContext context;
CComponentManager man(context, g_ScriptRuntime);
CComponentManager man(context, g_ScriptContext);
man.LoadComponentTypes();
entity_id_t ent1 = 1;

View File

@ -31,7 +31,7 @@ class TestSerializeTemplates : public CxxTest::TestSuite
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 @@ public:
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 @@ public:
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 @@ public:
void test_Debug_grid()
{
ScriptInterface script("Test", "Test", g_ScriptRuntime);
ScriptInterface script("Test", "Test", g_ScriptContext);
std::stringstream stream;
CDebugSerializer serialize(script, stream);

View File

@ -74,7 +74,7 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
{
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 @@ public:
CTerrain terrain;
CSimulation2 sim2(NULL, g_ScriptRuntime, &terrain);
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
sim2.LoadDefaultScripts();
sim2.ResetState();

View File

@ -57,7 +57,7 @@ public:
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 @@ public:
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 @@ public:
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));

View File

@ -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 @@ class MiscSetup : public CxxTest::GlobalFixture
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();

View File

@ -69,7 +69,7 @@ public:
MeshManager(ColladaManager),
SkeletonAnimManager(ColladaManager),
UnitManager(),
Simulation2(&UnitManager, g_ScriptRuntime, &Terrain),
Simulation2(&UnitManager, g_ScriptContext, &Terrain),
ObjectManager(MeshManager, SkeletonAnimManager, Simulation2),
LOSTexture(Simulation2),
TerritoryTexture(Simulation2)