30#define DEFAULT_TERRAIN_SCRIPT "default.as"
37#include "ScriptEvents.h"
40#include "scriptdictionary/scriptdictionary.h"
41#include "scriptbuilder/scriptbuilder.h"
51inline void TRIGGER_EVENT_ASYNC(
scriptEvents type,
int arg1,
int arg2ex = 0,
int arg3ex = 0,
int arg4ex = 0, std::string arg5ex =
"", std::string arg6ex =
"", std::string arg7ex =
"", std::string arg8ex =
"")
51inline void TRIGGER_EVENT_ASYNC(
scriptEvents type,
int arg1,
int arg2ex = 0,
int arg3ex = 0,
int arg4ex = 0, std::string arg5ex =
"", std::string arg6ex =
"", std::string arg7ex =
"", std::string arg8ex =
"") {
…}
193 ActorPtr associatedActor =
nullptr, std::string buffer =
"");
213 void triggerEvent(
scriptEvents eventnum,
int arg1=0,
int arg2ex=0,
int arg3ex=0,
int arg4ex=0, std::string arg5ex=
"", std::string arg6ex=
"", std::string arg7ex=
"", std::string arg8ex=
"");
279 int fireEvent(std::string instanceName,
float intensity);
294 void messageLogged(
const Ogre::String& message, Ogre::LogMessageLevel lml,
bool maskDebug,
const Ogre::String& logName,
bool& skipThisMessage);
352 void msgCallback(
const AngelScript::asSMessageInfo* msg);
386inline void TRIGGER_EVENT_ASYNC(scriptEvents type,
int arg1,
int arg2ex = 0,
int arg3ex = 0,
int arg4ex = 0, std::string arg5ex =
"", std::string arg6ex =
"", std::string arg7ex =
"", std::string arg8ex =
"")
Central state/object manager and communications hub.
Game state manager and message-queue provider.
this class is a helper to exchange data in a class between different threads, it can be pushed and pu...
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
Proxy class that can be called by script functions.
This class represents the angelscript scripting interface.
ScriptUnit & getScriptUnit(ScriptUnitID_t unique_id)
ScriptUnitID_t getTerrainScriptUnit() const
ScriptRetCode_t variableExists(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Adds a global variable to the script.
ScriptUnitID_t m_terrain_script_unit
void exceptionCallback(AngelScript::asIScriptContext *ctx)
Optional callback invoked when the script critically fails, allowing debugging.
bool m_events_enabled
Hack to enable fast shutdown without cleanup.
ScriptRetCode_t deleteVariable(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Deletes a global variable from the script.
void forwardExceptionAsScriptEvent(const std::string &from)
Forwards useful info from C++ try{}catch{} exceptions to script in the form of game event.
ScriptRetCode_t addVariable(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Adds a global variable to the script.
scriptEvents m_currently_executing_event_trigger
ScriptUnitMap m_script_units
void setEventsEnabled(bool val)
int setupScriptUnit(int unit_id)
Helper for loadScript(), does the actual building without worry about unit management.
AngelScript::asIScriptEngine * engine
instance of the scripting engine
ScriptUnitID_t loadScript(Ogre::String filename, ScriptCategory category=ScriptCategory::TERRAIN, ActorPtr associatedActor=nullptr, std::string buffer="")
Loads a script.
bool scriptUnitExists(ScriptUnitID_t unique_id)
int fireEvent(std::string instanceName, float intensity)
ScriptRetCode_t deleteFunction(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Deletes a global function from the script.
int executeContextAndHandleErrors(ScriptUnitID_t nid)
Helper for executing any script function/snippet; registers Line/Exception callbacks (on demand) and ...
InterThreadStoreVector< Ogre::String > stringExecutionQueue
The string execution queue.
ScriptUnitMap const & getScriptUnits() const
void msgCallback(const AngelScript::asSMessageInfo *msg)
Optional (but very recommended!) callback providing diagnostic info when things fail to start (most n...
void SLOG(const char *msg)
Replacement of macro.
ScriptRetCode_t getVariable(const Ogre::String &varName, void *ref, int typeID, ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Retrieves a global variable from any running script.
ScriptRetCode_t addFunction(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Adds a global function to the script.
ScriptUnitID_t getCurrentlyExecutingScriptUnit() const
ScriptRetCode_t executeString(Ogre::String command)
executes a string (useful for the console)
ScriptRetCode_t validateScriptModule(const ScriptUnitID_t nid, AngelScript::asIScriptModule *&out_mod)
Helper for all manipulations with functions/variables; ensures the script unit exists and is fully se...
AngelScript::asIScriptContext * context
context in which all scripting happens
void queueStringForExecution(const Ogre::String command)
Queues a string for execution.
void envokeCallback(int functionId, eventsource_t *source, NodeNum_t nodenum=NODENUM_INVALID, int type=0)
void messageLogged(const Ogre::String &message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool &skipThisMessage)
ScriptUnitID_t m_currently_executing_script_unit
AngelScript::asIScriptFunction * getFunctionByDeclAndLogCandidates(ScriptUnitID_t nid, GetFuncFlags_t flags, const std::string &funcName, const std::string &fmtFuncDecl)
Finds a function by full declaration, and if not found, finds candidates by name and logs them to Ang...
void lineCallback(AngelScript::asIScriptContext *ctx)
Optional callback which receives diagnostic info for every executed statement.
Ogre::String composeModuleName(Ogre::String const &scriptName, ScriptCategory origin, ScriptUnitID_t id)
Packs name + important info to one string, for logging and reporting purposes.
ScriptRetCode_t functionExists(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Checks if a global function exists.
AngelScript::asIScriptEngine * getEngine()
bool prepareContextAndHandleErrors(ScriptUnitID_t nid, int asFunctionID)
Helper for executing any script function/snippet; does asIScriptContext::Prepare() and reports any er...
void setForwardScriptLogToConsole(bool doForward)
void init()
This function initialzies the engine and registeres all types.
void framestep(Ogre::Real dt)
Calls the script's framestep function to be able to use timed things inside the script.
void triggerEvent(scriptEvents eventnum, int arg1=0, int arg2ex=0, int arg3ex=0, int arg4ex=0, std::string arg5ex="", std::string arg6ex="", std::string arg7ex="", std::string arg8ex="")
triggers an event; Not to be used by the end-user.
void unloadScript(ScriptUnitID_t unique_id)
Unloads a script.
void SLOG(std::string msg)
Replacement of macro.
@ MSG_SIM_SCRIPT_EVENT_TRIGGERED
Payload = RoR::ScriptEventArgs* (owner)
ScriptCategory
Note: Either of these can be loaded from script using game.pushMessage(MSG_APP_LOAD_SCRIPT_REQUESTED....
const std::string GETFUNC_DEFAULTEVENTCALLBACK_NAME
ScriptRetCode
Common return codes for script manipulation funcs (add/get/delete | funcs/variables)
BitMask_t GetFuncFlags_t
Flags for RoR::ScriptEngine::getFunctionByDeclAndLogCandidates()
void TRIGGER_EVENT_ASYNC(scriptEvents type, int arg1, int arg2ex=0, int arg3ex=0, int arg4ex=0, std::string arg5ex="", std::string arg6ex="", std::string arg7ex="", std::string arg8ex="")
Asynchronously (via MSG_SIM_SCRIPT_EVENT_TRIGGERED) invoke script function eventCallbackEx(),...
std::map< ScriptUnitID_t, ScriptUnit > ScriptUnitMap
const GetFuncFlags_t GETFUNCFLAG_OPTIONAL
Only logs warning if candidate is found, to help modder find a typo.
const std::string GETFUNC_DEFAULTEVENTCALLBACK_SIGFMT
const GetFuncFlags_t GETFUNCFLAG_REQUIRED
Always logs warning that function was not found.
const GetFuncFlags_t GETFUNCFLAG_SILENT
Never logs.
const char * ScriptCategoryToString(ScriptCategory c)
@ CUSTOM
Loaded by user via either: A) ingame console 'loadscript'; B) RoR.cfg 'app_custom_scripts'; C) comman...
@ GADGET
Associated with a .gadget mod file, launched via UI or any method given below for CUSTOM scripts (use...
@ TERRAIN
Defined in terrn2 file under '[Scripts]', receives terrain eventbox notifications.
@ ACTOR
Defined in truck file under 'scripts', contains global variable BeamClass@ thisActor.
@ SCRIPTRETCODE_AS_CONTEXT_ACTIVE
@ SCRIPTRETCODE_AS_INVALID_TYPE
@ SCRIPTRETCODE_AS_CANT_BIND_ALL_FUNCTIONS
@ SCRIPTRETCODE_AS_MODULE_IS_IN_USE
@ SCRIPTRETCODE_AS_INVALID_NAME
@ SCRIPTRETCODE_AS_NAME_TAKEN
@ SCRIPTRETCODE_ENGINE_NOT_CREATED
@ SCRIPTRETCODE_AS_WRONG_CALLING_CONV
@ SCRIPTRETCODE_AS_ILLEGAL_BEHAVIOUR_FOR_TYPE
@ SCRIPTRETCODE_SCRIPTUNIT_NOT_EXISTS
@ SCRIPTRETCODE_AS_LOWER_ARRAY_DIMENSION_NOT_REGISTERED
@ SCRIPTRETCODE_AS_OUT_OF_MEMORY
@ SCRIPTRETCODE_UNSPECIFIED_ERROR
@ SCRIPTRETCODE_AS_NO_GLOBAL_VAR
@ SCRIPTRETCODE_AS_INVALID_ARG
@ SCRIPTRETCODE_AS_NO_FUNCTION
@ SCRIPTRETCODE_AS_MULTIPLE_FUNCTIONS
@ SCRIPTRETCODE_AS_BUILD_IN_PROGRESS
@ SCRIPTRETCODE_AS_NO_MODULE
@ SCRIPTRETCODE_AS_WRONG_CONFIG_GROUP
@ SCRIPTRETCODE_AS_CONTEXT_NOT_FINISHED
@ SCRIPTRETCODE_AS_INVALID_INTERFACE
@ SCRIPTRETCODE_AS_CONTEXT_NOT_PREPARED
@ SCRIPTRETCODE_CONTEXT_NOT_CREATED
@ SCRIPTRETCODE_AS_INVALID_DECLARATION
@ SCRIPTRETCODE_AS_INVALID_CONFIGURATION
@ SCRIPTRETCODE_AS_NOT_SUPPORTED
@ SCRIPTRETCODE_AS_ALREADY_REGISTERED
@ SCRIPTRETCODE_AS_INVALID_OBJECT
@ SCRIPTRETCODE_AS_CONFIG_GROUP_IS_IN_USE
@ SCRIPTRETCODE_AS_INIT_GLOBAL_VARS_FAILED
@ SCRIPTRETCODE_SCRIPTUNIT_NO_MODULE
@ SCRIPTRETCODE_FUNCTION_NOT_EXISTS
GameContext * GetGameContext()
static const NodeNum_t NODENUM_INVALID
int ActorInstanceID_t
Unique sequentially generated ID of an actor in session. Use ActorManager::GetActorById()
int ScriptRetCode_t
see enum RoR::ScriptRetCode - combines AngelScript codes and RoR internal codes.
int ScriptUnitID_t
Unique sequentially generated ID of a loaded and running scriptin session. Use ScriptEngine::getScrip...
static const ActorInstanceID_t ACTORINSTANCEID_INVALID
static const ScriptUnitID_t SCRIPTUNITID_INVALID
scriptEvents
This enum describes what events are existing. The script can register to receive events.
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
static const ScriptUnitID_t SCRIPTUNITID_DEFAULT
The script defined in .terrn2 [Scripts], or 'default.as' ~ classic behavior.
std::string lsr_filename
Load from resource ('.as' file or '.gadget' file); If buffer is supplied, use this as display name on...
ScriptCategory lsr_category
std::string lsr_buffer
Load from memory buffer.
ActorInstanceID_t lsr_associated_actor
For ScriptCategory::ACTOR.
Unified game event system - all requests and state changes are reported using a message.
eventsource_t * eventsource
ScriptCallbackArgs(eventsource_t *evs, NodeNum_t nd)
Args for eventCallbackEx() queued via MSG_SIM_SCRIPT_EVENT_TRIGGERED See descriptions at enum RoR::sc...
Represents a loaded script and all associated resources/handles.
CacheEntryPtr originatingGadget
For ScriptCategory::GADGET ~ determines resource group.
ScriptCategory scriptCategory
AngelScript::asIScriptFunction * frameStepFunctionPtr
script function pointer to the frameStep function
unsigned int eventMask
filter mask for script events
Ogre::String scriptBuffer
AngelScript::asIScriptFunction * defaultEventCallbackFunctionPtr
script function pointer for spawner events
Ogre::String scriptName
Name of the '.as' file exclusively.
AngelScript::asIScriptFunction * eventCallbackFunctionPtr
script function pointer to the event callback function
AngelScript::asIScriptModule * scriptModule
AngelScript::asIScriptFunction * eventCallbackExFunctionPtr
script function pointer to the event callback function
ActorPtr associatedActor
For ScriptCategory::ACTOR.