Changeset View
Changeset View
Standalone View
Standalone View
source/scriptinterface/ScriptInterface.h
Show All 18 Lines | |||||
#define INCLUDED_SCRIPTINTERFACE | #define INCLUDED_SCRIPTINTERFACE | ||||
#include "lib/file/vfs/vfs_path.h" | #include "lib/file/vfs/vfs_path.h" | ||||
#include "maths/Fixed.h" | #include "maths/Fixed.h" | ||||
#include "ps/Errors.h" | #include "ps/Errors.h" | ||||
#include "scriptinterface/ScriptExceptions.h" | #include "scriptinterface/ScriptExceptions.h" | ||||
#include "scriptinterface/ScriptTypes.h" | #include "scriptinterface/ScriptTypes.h" | ||||
#include <boost/random/linear_congruential.hpp> | |||||
#include <map> | #include <map> | ||||
ERROR_GROUP(Scripting); | ERROR_GROUP(Scripting); | ||||
ERROR_TYPE(Scripting, SetupFailed); | ERROR_TYPE(Scripting, SetupFailed); | ||||
ERROR_SUBGROUP(Scripting, LoadFile); | ERROR_SUBGROUP(Scripting, LoadFile); | ||||
ERROR_TYPE(Scripting_LoadFile, OpenFailed); | ERROR_TYPE(Scripting_LoadFile, OpenFailed); | ||||
ERROR_TYPE(Scripting_LoadFile, EvalErrors); | ERROR_TYPE(Scripting_LoadFile, EvalErrors); | ||||
Show All 16 Lines | |||||
class ScriptInterface; | class ScriptInterface; | ||||
struct ScriptInterface_impl; | struct ScriptInterface_impl; | ||||
class ScriptContext; | class ScriptContext; | ||||
// Using a global object for the context is a workaround until Simulation, AI, etc, | // Using a global object for the context is a workaround until Simulation, AI, etc, | ||||
// use their own threads and also their own contexts. | // use their own threads and also their own contexts. | ||||
extern thread_local shared_ptr<ScriptContext> g_ScriptContext; | extern thread_local shared_ptr<ScriptContext> g_ScriptContext; | ||||
namespace boost { namespace random { class rand48; } } | |||||
/** | /** | ||||
* RAII structure which encapsulates an access to the context and compartment of a ScriptInterface. | * RAII structure which encapsulates an access to the context and compartment of a ScriptInterface. | ||||
* This struct provides: | * This struct provides: | ||||
* - a pointer to the context, while acting like JSAutoRequest | * - a pointer to the context, while acting like JSAutoRequest | ||||
* - a pointer to the global object of the compartment, while acting like JSAutoCompartment | * - a pointer to the global object of the compartment, while acting like JSAutoCompartment | ||||
* | * | ||||
* This way, getting and using those pointers is safe with respect to the GC | * This way, getting and using those pointers is safe with respect to the GC | ||||
* and to the separation of compartments. | * and to the separation of compartments. | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | public: | ||||
* Load global scripts that most script interfaces need, | * Load global scripts that most script interfaces need, | ||||
* located in the /globalscripts directory. VFS must be initialized. | * located in the /globalscripts directory. VFS must be initialized. | ||||
*/ | */ | ||||
bool LoadGlobalScripts(); | bool LoadGlobalScripts(); | ||||
/** | /** | ||||
* Replace the default JS random number geenrator with a seeded, network-sync'd one. | * Replace the default JS random number geenrator with a seeded, network-sync'd one. | ||||
*/ | */ | ||||
bool ReplaceNondeterministicRNG(boost::rand48& rng); | bool ReplaceNondeterministicRNG(boost::random::rand48& rng); | ||||
/** | /** | ||||
* Call a constructor function, equivalent to JS "new ctor(arg)". | * Call a constructor function, equivalent to JS "new ctor(arg)". | ||||
* @param ctor An object that can be used as constructor | * @param ctor An object that can be used as constructor | ||||
* @param argv Constructor arguments | * @param argv Constructor arguments | ||||
* @param out The new object; On error an error message gets logged and out is Null (out.isNull() == true). | * @param out The new object; On error an error message gets logged and out is Null (out.isNull() == true). | ||||
*/ | */ | ||||
void CallConstructor(JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out) const; | void CallConstructor(JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out) const; | ||||
▲ Show 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | struct CustomType | ||||
JSNative m_Constructor; | JSNative m_Constructor; | ||||
}; | }; | ||||
void Register(const char* name, JSNative fptr, size_t nargs) const; | 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 | // Take care to keep this declaration before heap rooted members. Destructors of heap rooted | ||||
// members have to be called before the custom destructor of ScriptInterface_impl. | // members have to be called before the custom destructor of ScriptInterface_impl. | ||||
std::unique_ptr<ScriptInterface_impl> m; | std::unique_ptr<ScriptInterface_impl> m; | ||||
boost::rand48* m_rng; | boost::random::rand48* m_rng; | ||||
std::map<std::string, CustomType> m_CustomObjectTypes; | std::map<std::string, CustomType> m_CustomObjectTypes; | ||||
// The nasty macro/template bits are split into a separate file so you don't have to look at them | // The nasty macro/template bits are split into a separate file so you don't have to look at them | ||||
public: | public: | ||||
#include "NativeWrapperDecls.h" | #include "NativeWrapperDecls.h" | ||||
// This declares: | // This declares: | ||||
// | // | ||||
// template <R, T0..., TR (*fptr) (void* cbdata, T0...)> | // template <R, T0..., TR (*fptr) (void* cbdata, T0...)> | ||||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator