Skip to content

Commit

Permalink
Codechange: Clarified SE_ANGELSCRIPT_MANIPULATIONS a bit.
Browse files Browse the repository at this point in the history
MANIP_ enum fields got renamed to ASMANIP_ to match C++ with AngelScript.
Doxygen docs were added.
Manip type 'UNLOADED' got renamed to 'UNLOADING' to signify it's delivered to all scripts, even the one to be unloaded.
  • Loading branch information
ohlidalp committed Oct 17, 2023
1 parent 00a2f6b commit 6d0a2d3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
10 changes: 9 additions & 1 deletion doc/angelscript/Script2Game/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void print(const string message);
SE_TRUCK_TELEPORT //!< triggered when the user teleports the truck, the argument refers to the Actor Instance ID (use `game.getTruckByNum()`)
SE_TRUCK_MOUSE_GRAB //!< triggered when the user uses the mouse to interact with the actor, the argument refers to the Actor Instance ID (use `game.getTruckByNum()`)

SE_ANGELSCRIPT_MANIPULATIONS //!< triggered when the user tries to dynamically use the scripting capabilities (prevent cheating)
SE_ANGELSCRIPT_MANIPULATIONS //!< triggered when the user tries to dynamically use the scripting capabilities (prevent cheating) args: #1 angelScriptManipulationType, #2 ScriptUnitId_t, #3 RoR::ScriptCategory, #4 unused, #5 script file name (*.as), #6 associated file name (i.e. *.mission), #7 associated file resource group (i.e. *.mission).
SE_ANGELSCRIPT_MSGCALLBACK //!< The diagnostic info directly from AngelScript engine (see `asSMessageInfo`), args: #1 ScriptUnitID, #2 asEMsgType, #3 row, #4 col, #5 sectionName, #6 message
SE_ANGELSCRIPT_LINECALLBACK //!< The diagnostic info directly from AngelScript engine (see `SetLineCallback()`), args: #1 ScriptUnitID, #2 LineNumber, #3 CallstackSize, #4 unused, #5 FunctionName, #6 FunctionObjectTypeName #7 ObjectName
SE_ANGELSCRIPT_EXCEPTIONCALLBACK //!< The diagnostic info directly from AngelScript engine (see `SetExceptionCallback()`), args: #1 ScriptUnitID, #2 unused, #3 row (`GetExceptionLineNumber()`), #4 unused, #5 funcName, #6 message (`GetExceptionString()`)
Expand All @@ -79,6 +79,14 @@ void print(const string message);

};

/// Argument #2 of script event `SE_ANGELSCRIPT_MANIPULATIONS`
enum angelScriptManipulationType
{
ASMANIP_CONSOLE_SNIPPET_EXECUTED = 0, // 0 for Backwards compatibility.
ASMANIP_SCRIPT_LOADED, //!< Triggered after the script's `main()` completed; may trigger additional processing (for example, it delivers the *.mission file to mission system script).
ASMANIP_SCRIPT_UNLOADING //!< Triggered before unloading the script to let it clean up (important for missions).
};

enum angelScriptManipulationType
{
MANIP_CONSOLE_SNIPPET_EXECUTED = 0, // Backwards compat
Expand Down
7 changes: 4 additions & 3 deletions source/main/gameplay/ScriptEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ enum scriptEvents

};

/// Argument #2 of script event `SE_ANGELSCRIPT_MANIPULATIONS`
enum angelScriptManipulationType
{
MANIP_CONSOLE_SNIPPET_EXECUTED = 0, // Backwards compat
MANIP_SCRIPT_LOADED,
MANIP_SCRIPT_UNLOADED
ASMANIP_CONSOLE_SNIPPET_EXECUTED = 0, // 0 for Backwards compatibility.
ASMANIP_SCRIPT_LOADED, //!< Triggered after the script's `main()` completed; may trigger additional processing (for example, it delivers the *.mission file to mission system script).
ASMANIP_SCRIPT_UNLOADING //!< Triggered before unloading the script to let it clean up (important for missions).
};

enum angelScriptThreadStatus
Expand Down
4 changes: 2 additions & 2 deletions source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ int main(int argc, char *argv[])
ScriptUnitId_t nid = App::GetScriptEngine()->loadScript(request->lsr_filename, request->lsr_category, actor, request->lsr_buffer);
// we want to notify any running scripts that we might change something (prevent cheating)
App::GetScriptEngine()->triggerEvent(SE_ANGELSCRIPT_MANIPULATIONS,
MANIP_SCRIPT_LOADED, nid, (int)request->lsr_category, 0, request->lsr_filename);
ASMANIP_SCRIPT_LOADED, nid, (int)request->lsr_category, 0, request->lsr_filename);
delete request;
break;
}
Expand All @@ -416,7 +416,7 @@ int main(int argc, char *argv[])
ScriptUnit& unit = App::GetScriptEngine()->getScriptUnit(*id);
// we want to notify any running scripts that we might change something (prevent cheating)
App::GetScriptEngine()->triggerEvent(SE_ANGELSCRIPT_MANIPULATIONS,
MANIP_SCRIPT_UNLOADED, *id, (int)unit.scriptCategory, 0, unit.scriptName);
ASMANIP_SCRIPT_UNLOADING, *id, (int)unit.scriptCategory, 0, unit.scriptName);
App::GetScriptEngine()->unloadScript(*id);
delete id;
break;
Expand Down
6 changes: 3 additions & 3 deletions source/main/scripting/bindings/ScriptEventsAngelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ void RoR::RegisterScriptEvents(asIScriptEngine *engine)
// enum angelScriptManipulationType
result = engine->RegisterEnum("angelScriptManipulationType"); ROR_ASSERT(result>=0);

result = engine->RegisterEnumValue("angelScriptManipulationType", "ASMANIP_CONSOLE_SNIPPET_EXECUTED", MANIP_CONSOLE_SNIPPET_EXECUTED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("angelScriptManipulationType", "ASMANIP_SCRIPT_LOADED", MANIP_SCRIPT_LOADED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("angelScriptManipulationType", "ASMANIP_SCRIPT_UNLOADED", MANIP_SCRIPT_UNLOADED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("angelScriptManipulationType", "ASMANIP_CONSOLE_SNIPPET_EXECUTED", ASMANIP_CONSOLE_SNIPPET_EXECUTED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("angelScriptManipulationType", "ASMANIP_SCRIPT_LOADED", ASMANIP_SCRIPT_LOADED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("angelScriptManipulationType", "ASMANIP_SCRIPT_UNLOADING", ASMANIP_SCRIPT_UNLOADING); ROR_ASSERT(result >= 0);

// enum angelScriptThreadStatus
result = engine->RegisterEnum("angelScriptThreadStatus"); ROR_ASSERT(result>=0);
Expand Down
2 changes: 1 addition & 1 deletion source/main/system/ConsoleCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class AsCmd: public ConsoleCmd

#ifdef USE_ANGELSCRIPT
// we want to notify any running scripts that we might change something (prevent cheating)
App::GetScriptEngine()->triggerEvent(SE_ANGELSCRIPT_MANIPULATIONS, MANIP_CONSOLE_SNIPPET_EXECUTED);
App::GetScriptEngine()->triggerEvent(SE_ANGELSCRIPT_MANIPULATIONS, ASMANIP_CONSOLE_SNIPPET_EXECUTED);

// Re-compose the code snippet
Str<1000> code;
Expand Down

0 comments on commit 6d0a2d3

Please sign in to comment.