RigsofRods
Soft-body Physics Simulation
|
This class represents the angelscript scripting interface. More...
#include <ScriptEngine.h>
Public Member Functions | |
ScriptEngine () | |
~ScriptEngine () | |
ScriptUnitId_t | loadScript (Ogre::String scriptname, ScriptCategory category=ScriptCategory::TERRAIN, ActorPtr associatedActor=nullptr, std::string buffer="") |
Loads a script. More... | |
void | unloadScript (ScriptUnitId_t unique_id) |
Unloads a script. More... | |
void | framestep (Ogre::Real dt) |
Calls the script's framestep function to be able to use timed things inside the script. More... | |
void | setForwardScriptLogToConsole (bool doForward) |
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. More... | |
void | setEventsEnabled (bool val) |
int | executeString (Ogre::String command) |
executes a string (useful for the console) More... | |
void | queueStringForExecution (const Ogre::String command) |
Queues a string for execution. More... | |
int | addFunction (const Ogre::String &arg) |
Adds a global function to the script. More... | |
int | functionExists (const Ogre::String &arg) |
Checks if a global function exists. More... | |
int | deleteFunction (const Ogre::String &arg) |
Deletes a global function from the script. More... | |
int | addVariable (const Ogre::String &arg) |
Adds a global variable to the script. More... | |
int | deleteVariable (const Ogre::String &arg) |
Deletes a global variable from the script. More... | |
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 Angelscript.log. More... | |
int | fireEvent (std::string instanceName, float intensity) |
void | envokeCallback (int functionId, eventsource_t *source, NodeNum_t nodenum=NODENUM_INVALID, int type=0) |
void | forwardExceptionAsScriptEvent (const std::string &from) |
Forwards useful info from C++ try{}catch{} exceptions to script in the form of game event. More... | |
AngelScript::asIScriptEngine * | getEngine () |
void | messageLogged (const Ogre::String &message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool &skipThisMessage) |
bool | scriptUnitExists (ScriptUnitId_t unique_id) |
ScriptUnit & | getScriptUnit (ScriptUnitId_t unique_id) |
ScriptUnitMap const & | getScriptUnits () const |
Protected Member Functions | |
Housekeeping | |
void | init () |
This function initialzies the engine and registeres all types. More... | |
Ogre::String | composeModuleName (Ogre::String const &scriptName, ScriptCategory origin, ScriptUnitId_t id) |
Packs name + important info to one string, for logging and reporting purposes. More... | |
int | setupScriptUnit (int unit_id) |
Helper for loadScript() , does the actual building without worry about unit management. More... | |
bool | prepareContextAndHandleErrors (ScriptUnitId_t nid, int asFunctionID) |
Helper for executing any script function/snippet; does asIScriptContext::Prepare() and reports any error. More... | |
int | executeContextAndHandleErrors (ScriptUnitId_t nid) |
Helper for executing any script function/snippet; registers Line/Exception callbacks (on demand) and set currently executed NID; The asIScriptContext::Prepare() and setting args must be already done. More... | |
Script diagnostics | |
void | msgCallback (const AngelScript::asSMessageInfo *msg) |
Optional (but very recommended!) callback providing diagnostic info when things fail to start (most notably script errors). More... | |
void | lineCallback (AngelScript::asIScriptContext *ctx) |
Optional callback which receives diagnostic info for every executed statement. More... | |
void | exceptionCallback (AngelScript::asIScriptContext *ctx) |
Optional callback invoked when the script critically fails, allowing debugging. More... | |
Protected Attributes | |
AngelScript::asIScriptEngine * | engine |
instance of the scripting engine More... | |
AngelScript::asIScriptContext * | context |
context in which all scripting happens More... | |
Ogre::Log * | scriptLog |
GameScript | m_game_script |
ScriptUnitMap | m_script_units |
ScriptUnitId_t | m_terrain_script_unit = SCRIPTUNITID_INVALID |
ScriptUnitId_t | m_currently_executing_script_unit = SCRIPTUNITID_INVALID |
scriptEvents | m_currently_executing_event_trigger = SE_NO_EVENTS |
bool | m_events_enabled = true |
Hack to enable fast shutdown without cleanup. More... | |
InterThreadStoreVector< Ogre::String > | stringExecutionQueue |
The string execution queue. More... | |
Friends | |
class | GameScript |
This class represents the angelscript scripting interface.
It can load and execute scripts.
Definition at line 119 of file ScriptEngine.h.
ScriptEngine::ScriptEngine | ( | ) |
ScriptEngine::~ScriptEngine | ( | ) |
Definition at line 106 of file ScriptEngine.cpp.
int ScriptEngine::addFunction | ( | const Ogre::String & | arg | ) |
Adds a global function to the script.
arg | A declaration for the function. |
Definition at line 501 of file ScriptEngine.cpp.
int ScriptEngine::addVariable | ( | const Ogre::String & | arg | ) |
Adds a global variable to the script.
arg | A declaration for the variable. |
Definition at line 639 of file ScriptEngine.cpp.
|
protected |
Packs name + important info to one string, for logging and reporting purposes.
Definition at line 754 of file ScriptEngine.cpp.
int ScriptEngine::deleteFunction | ( | const Ogre::String & | arg | ) |
Deletes a global function from the script.
arg | A declaration for the function. |
Definition at line 585 of file ScriptEngine.cpp.
int ScriptEngine::deleteVariable | ( | const Ogre::String & | arg | ) |
Deletes a global variable from the script.
arg | A declaration for the variable. |
Definition at line 659 of file ScriptEngine.cpp.
void ScriptEngine::envokeCallback | ( | int | functionId, |
eventsource_t * | source, | ||
NodeNum_t | nodenum = NODENUM_INVALID , |
||
int | type = 0 |
||
) |
Definition at line 443 of file ScriptEngine.cpp.
|
protected |
Optional callback invoked when the script critically fails, allowing debugging.
https://www.angelcode.com/angelscript/sdk/docs/manual/doc_call_script_func.html#doc_call_script_4
Definition at line 233 of file ScriptEngine.cpp.
|
protected |
Helper for executing any script function/snippet; registers Line/Exception callbacks (on demand) and set currently executed NID; The asIScriptContext::Prepare()
and setting args must be already done.
Definition at line 277 of file ScriptEngine.cpp.
int ScriptEngine::executeString | ( | Ogre::String | command | ) |
executes a string (useful for the console)
command | string to execute |
Definition at line 483 of file ScriptEngine.cpp.
int ScriptEngine::fireEvent | ( | std::string | instanceName, |
float | intensity | ||
) |
void ScriptEngine::forwardExceptionAsScriptEvent | ( | const std::string & | from | ) |
Forwards useful info from C++ try{}catch{}
exceptions to script in the form of game event.
AngelScript doesn't have exceptions in this sense (in AS jargon, 'Exception' means basically 'panic' as in Lua/Rust...) and most exceptions this game encounters (Ogre::Exception
) are trivially recoverable, so it doesn't make sense to panic AngelScript when they happen.
Definition at line 246 of file ScriptEngine.cpp.
void ScriptEngine::framestep | ( | Ogre::Real | dt | ) |
Calls the script's framestep function to be able to use timed things inside the script.
dt | time passed since the last call to this function in seconds |
Definition at line 384 of file ScriptEngine.cpp.
int ScriptEngine::functionExists | ( | const Ogre::String & | arg | ) |
Checks if a global function exists.
arg | A declaration for the function. |
Definition at line 560 of file ScriptEngine.cpp.
|
inline |
asIScriptFunction * ScriptEngine::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 Angelscript.log.
Definition at line 690 of file ScriptEngine.cpp.
ScriptUnit & ScriptEngine::getScriptUnit | ( | ScriptUnitId_t | unique_id | ) |
Definition at line 1000 of file ScriptEngine.cpp.
|
inline |
|
protected |
This function initialzies the engine and registeres all types.
Definition at line 119 of file ScriptEngine.cpp.
|
protected |
Optional callback which receives diagnostic info for every executed statement.
Definition at line 215 of file ScriptEngine.cpp.
ScriptUnitId_t ScriptEngine::loadScript | ( | Ogre::String | scriptname, |
ScriptCategory | category = ScriptCategory::TERRAIN , |
||
ActorPtr | associatedActor = nullptr , |
||
std::string | buffer = "" |
||
) |
Loads a script.
scriptname | filename to load; if buffer is supplied, this is only a display name. |
category | How to treat the script? |
associatedActor | Only for category ACTOR |
buffer | String with full script body; if empty, a file will be loaded as usual. |
Definition at line 759 of file ScriptEngine.cpp.
void ScriptEngine::messageLogged | ( | const Ogre::String & | message, |
Ogre::LogMessageLevel | lml, | ||
bool | maskDebug, | ||
const Ogre::String & | logName, | ||
bool & | skipThisMessage | ||
) |
|
protected |
Optional (but very recommended!) callback providing diagnostic info when things fail to start (most notably script errors).
Definition at line 196 of file ScriptEngine.cpp.
|
protected |
Helper for executing any script function/snippet; does asIScriptContext::Prepare()
and reports any error.
Definition at line 364 of file ScriptEngine.cpp.
void ScriptEngine::queueStringForExecution | ( | const Ogre::String | command | ) |
Queues a string for execution.
Use this when you want to execute a script statement from another thread.
command | string to queue for execution |
Definition at line 478 of file ScriptEngine.cpp.
bool ScriptEngine::scriptUnitExists | ( | ScriptUnitId_t | unique_id | ) |
|
inline |
void ScriptEngine::setForwardScriptLogToConsole | ( | bool | doForward | ) |
|
protected |
Helper for loadScript()
, does the actual building without worry about unit management.
Definition at line 808 of file ScriptEngine.cpp.
void ScriptEngine::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.
Runs either eventCallbackEx()
, if registered, or eventCallback()
, if registered, in this order.
Definition at line 712 of file ScriptEngine.cpp.
void ScriptEngine::unloadScript | ( | ScriptUnitId_t | unique_id | ) |
Unloads a script.
unique_id | The script unit ID as returned by loadScript() |
Definition at line 964 of file ScriptEngine.cpp.
|
friend |
Definition at line 121 of file ScriptEngine.h.
|
protected |
context in which all scripting happens
Definition at line 295 of file ScriptEngine.h.
|
protected |
instance of the scripting engine
Definition at line 294 of file ScriptEngine.h.
|
protected |
Definition at line 301 of file ScriptEngine.h.
|
protected |
Definition at line 300 of file ScriptEngine.h.
|
protected |
Hack to enable fast shutdown without cleanup.
Definition at line 302 of file ScriptEngine.h.
|
protected |
Definition at line 297 of file ScriptEngine.h.
|
protected |
Definition at line 298 of file ScriptEngine.h.
|
protected |
Definition at line 299 of file ScriptEngine.h.
|
protected |
Definition at line 296 of file ScriptEngine.h.
|
protected |
The string execution queue.
Definition at line 304 of file ScriptEngine.h.