mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-25 07:08:24 +00:00
Encapsulate runtime creation.
- Makes it easier to change down the line (and change is coming) - Allows making g_ScriptRuntime thread-local easily. - Remove ParentRuntime, which is not used at the moment. Part of the SM52 migration, stage: SM45 compatible. Patch by: Itms Tested By: Freagarach Refs #4893 Differential Revision: https://code.wildfiregames.com/D3087 This was SVN commit r24171.
This commit is contained in:
@@ -48,15 +48,13 @@ ERROR_TYPE(Scripting_DefineType, CreationFailed);
|
||||
// but as large as necessary for all wrapped functions)
|
||||
#define SCRIPT_INTERFACE_MAX_ARGS 8
|
||||
|
||||
// TODO: what's a good default?
|
||||
#define DEFAULT_RUNTIME_SIZE 16 * 1024 * 1024
|
||||
#define DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER 2 * 1024 *1024
|
||||
|
||||
struct ScriptInterface_impl;
|
||||
|
||||
class ScriptRuntime;
|
||||
|
||||
extern shared_ptr<ScriptRuntime> g_ScriptRuntime;
|
||||
// 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;
|
||||
|
||||
|
||||
/**
|
||||
@@ -73,17 +71,6 @@ class ScriptInterface
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns a runtime, which can used to initialise any number of
|
||||
* ScriptInterfaces contexts. Values created in one context may be used
|
||||
* in any other context from the same runtime (but not any other runtime).
|
||||
* Each runtime should only ever be used on a single thread.
|
||||
* @param runtimeSize Maximum size in bytes of the new runtime
|
||||
*/
|
||||
static shared_ptr<ScriptRuntime> CreateRuntime(shared_ptr<ScriptRuntime> parentRuntime = shared_ptr<ScriptRuntime>(), int runtimeSize = DEFAULT_RUNTIME_SIZE,
|
||||
int heapGrowthBytesGCTrigger = DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param nativeScopeName Name of global object that functions (via RegisterFunction) will
|
||||
@@ -442,7 +429,7 @@ private:
|
||||
void Register(const char* name, JSNative fptr, size_t 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.
|
||||
// members have to be called before the custom destructor of ScriptInterface_impl.
|
||||
std::unique_ptr<ScriptInterface_impl> m;
|
||||
|
||||
boost::rand48* m_rng;
|
||||
|
||||
Reference in New Issue
Block a user