From d846225d455f51e3dbd278ca5ae5535d876c1394 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 5 Aug 2022 19:44:30 +0200 Subject: [PATCH 01/12] Angelscript bindings moved to 'scripting/bindings/' Also unified `using namespace AngelScript`. --- source/main/CMakeLists.txt | 21 +- source/main/scripting/LocalStorage.cpp | 83 ------ source/main/scripting/LocalStorage.h | 5 - source/main/scripting/ScriptEngine.cpp | 249 +----------------- source/main/scripting/ScriptEngine.h | 15 +- .../scripting/bindings/ActorAngelscript.cpp | 89 +++++++ .../scripting/bindings/AngelScriptBindings.h | 67 +++++ .../scripting/bindings/ConsoleAngelscript.cpp | 56 ++++ .../bindings/GameScriptAngelscript.cpp | 123 +++++++++ .../{ => bindings}/ImGuiAngelscript.cpp | 2 +- .../{ => bindings}/InputEngineAngelscript.cpp | 22 +- .../bindings/LocalStorageAngelscript.cpp | 111 ++++++++ .../{ => bindings}/OgreAngelscript.cpp | 2 +- .../bindings/ScriptEventsAngelscript.cpp | 61 +++++ .../bindings/VehicleAiAngelscript.cpp | 52 ++++ 15 files changed, 595 insertions(+), 363 deletions(-) create mode 100644 source/main/scripting/bindings/ActorAngelscript.cpp create mode 100644 source/main/scripting/bindings/AngelScriptBindings.h create mode 100644 source/main/scripting/bindings/ConsoleAngelscript.cpp create mode 100644 source/main/scripting/bindings/GameScriptAngelscript.cpp rename source/main/scripting/{ => bindings}/ImGuiAngelscript.cpp (99%) rename source/main/scripting/{ => bindings}/InputEngineAngelscript.cpp (96%) create mode 100644 source/main/scripting/bindings/LocalStorageAngelscript.cpp rename source/main/scripting/{ => bindings}/OgreAngelscript.cpp (98%) create mode 100644 source/main/scripting/bindings/ScriptEventsAngelscript.cpp create mode 100644 source/main/scripting/bindings/VehicleAiAngelscript.cpp diff --git a/source/main/CMakeLists.txt b/source/main/CMakeLists.txt index b7526d8a44..92e0a2d912 100644 --- a/source/main/CMakeLists.txt +++ b/source/main/CMakeLists.txt @@ -199,7 +199,7 @@ set(SOURCE_FILES terrain/TerrainEditor.{h,cpp} terrain/TerrainGeometryManager.{h,cpp} terrain/TerrainManager.{h,cpp} - terrain/TerrainObjectManager.{h,cpp} + terrain/TerrainObjectManager.{h,cpp} threadpool/ThreadPool.h utils/ConfigFile.{h,cpp} utils/ErrorUtils.{h,cpp} @@ -220,11 +220,18 @@ if (USE_ANGELSCRIPT) list(APPEND SOURCE_FILES scripting/GameScript.{h,cpp} scripting/LocalStorage.{h,cpp} - scripting/OgreAngelscript.cpp - scripting/ImGuiAngelscript.cpp - scripting/InputEngineAngelscript.cpp scripting/OgreScriptBuilder.{h,cpp} scripting/ScriptEngine.{h,cpp} + scripting/bindings/AngelScriptBindings.h + scripting/bindings/ActorAngelscript.cpp + scripting/bindings/ConsoleAngelscript.cpp + scripting/bindings/GameScriptAngelscript.cpp + scripting/bindings/ImGuiAngelscript.cpp + scripting/bindings/InputEngineAngelscript.cpp + scripting/bindings/LocalStorageAngelscript.cpp + scripting/bindings/OgreAngelscript.cpp + scripting/bindings/ScriptEventsAngelscript.cpp + scripting/bindings/VehicleAiAngelscript.cpp ) endif () @@ -310,7 +317,6 @@ target_include_directories(${BINNAME} PRIVATE gfx/camera gfx/hydrax gfx/particle - gfx/procedural gfx/skyx gui gui/imgui @@ -321,8 +327,6 @@ target_include_directories(${BINNAME} PRIVATE physics/air physics/collision physics/flex - physics/mplatform - physics/threading physics/utils physics/water resources @@ -333,9 +337,8 @@ target_include_directories(${BINNAME} PRIVATE resources/terrn2_fileformat resources/tobj_fileformat system - rig_editor - rig_editor/rig_data scripting + scripting/bindings terrain terrain/map threadpool diff --git a/source/main/scripting/LocalStorage.cpp b/source/main/scripting/LocalStorage.cpp index c2845c5972..3e201eecdd 100644 --- a/source/main/scripting/LocalStorage.cpp +++ b/source/main/scripting/LocalStorage.cpp @@ -316,86 +316,3 @@ bool LocalStorage::exists(std::string &key) return hasSetting(key, sec); } -void scriptLocalStorageFactory_Generic(AngelScript::asIScriptGeneric *gen) -{ - std::string filename = **(std::string**)gen->GetAddressOfArg(0); - std::string sectionname = **(std::string**)gen->GetAddressOfArg(1); - - *(LocalStorage**)gen->GetAddressOfReturnLocation() = new LocalStorage(gen->GetEngine(), filename, sectionname); -} - -void scriptLocalStorageFactory2_Generic(AngelScript::asIScriptGeneric *gen) -{ - std::string filename = **(std::string**)gen->GetAddressOfArg(0); - *(LocalStorage**)gen->GetAddressOfReturnLocation() = new LocalStorage(gen->GetEngine(), filename, "common"); -} - -void scriptLocalStorageFactory3_Generic(AngelScript::asIScriptGeneric *gen) -{ - *(LocalStorage**)gen->GetAddressOfReturnLocation() = new LocalStorage(gen->GetEngine()); -} - -void registerLocalStorage(AngelScript::asIScriptEngine *engine) -{ - int r; - - r = engine->RegisterObjectType("LocalStorage", sizeof(LocalStorage), AngelScript::asOBJ_REF | AngelScript::asOBJ_GC); ROR_ASSERT( r >= 0 ); - // Use the generic interface to construct the object since we need the engine pointer, we could also have retrieved the engine pointer from the active context - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_FACTORY, "LocalStorage@ f(const string &in, const string &in)", AngelScript::asFUNCTION(scriptLocalStorageFactory_Generic), AngelScript::asCALL_GENERIC); ROR_ASSERT( r>= 0 ); - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_FACTORY, "LocalStorage@ f(const string &in)", AngelScript::asFUNCTION(scriptLocalStorageFactory2_Generic), AngelScript::asCALL_GENERIC); ROR_ASSERT( r>= 0 ); - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_FACTORY, "LocalStorage@ f()", AngelScript::asFUNCTION(scriptLocalStorageFactory3_Generic), AngelScript::asCALL_GENERIC); ROR_ASSERT( r>= 0 ); - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_ADDREF, "void f()", AngelScript::asMETHOD(LocalStorage,AddRef), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_RELEASE, "void f()", AngelScript::asMETHOD(LocalStorage,Release), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "LocalStorage &opAssign(LocalStorage &in)", AngelScript::asMETHODPR(LocalStorage, operator=, (LocalStorage &), LocalStorage&), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void changeSection(const string &in)", AngelScript::asMETHODPR(LocalStorage,changeSection,(const std::string&), void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "string get(string &in)", AngelScript::asMETHODPR(LocalStorage,get,(std::string&), std::string), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "string getString(string &in)", AngelScript::asMETHODPR(LocalStorage,get,(std::string&), std::string), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const string &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const std::string&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setString(string &in, const string &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const std::string&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "float getFloat(string &in)", AngelScript::asMETHODPR(LocalStorage,getFloat,(std::string&), float), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, float)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const float),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setFloat(string &in, float)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const float),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "vector3 getVector3(string &in)", AngelScript::asMETHODPR(LocalStorage,getVector3,(std::string&), Ogre::Vector3), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const vector3 &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Vector3&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setVector3(string &in, const vector3 &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Vector3&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "radian getRadian(string &in)", AngelScript::asMETHODPR(LocalStorage,getRadian,(std::string&), Ogre::Radian), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const radian &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Radian&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setRadian(string &in, const radian &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Radian&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "degree getDegree(string &in)", AngelScript::asMETHODPR(LocalStorage,getDegree,(std::string&), Ogre::Degree), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const degree &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Degree&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setDegree(string &in, const degree &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Degree&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "quaternion getQuaternion(string &in)", AngelScript::asMETHODPR(LocalStorage,getQuaternion,(std::string&), Ogre::Quaternion), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const quaternion &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Quaternion&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setQuaternion(string &in, const quaternion &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Quaternion&),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "bool getBool(string &in)", AngelScript::asMETHODPR(LocalStorage,getBool,(std::string&), bool), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const bool &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const bool),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setBool(string &in, const bool &in)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const bool),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "int getInt(string &in)", AngelScript::asMETHODPR(LocalStorage,getInt,(std::string&), int), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "int getInteger(string &in)", AngelScript::asMETHODPR(LocalStorage,getInt,(std::string&), int), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, int)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const int),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setInt(string &in, int)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const int),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void setInteger(string &in, int)", AngelScript::asMETHODPR(LocalStorage,set,(std::string&, const int),void), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "void save()", AngelScript::asMETHOD(LocalStorage,saveDict), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "bool reload()", AngelScript::asMETHOD(LocalStorage,loadDict), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - r = engine->RegisterObjectMethod("LocalStorage", "bool exists(string &in) const", AngelScript::asMETHOD(LocalStorage,exists), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("LocalStorage", "void delete(string &in)", AngelScript::asMETHOD(LocalStorage,eraseKey), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - - // Register GC behaviours - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_GETREFCOUNT, "int f()", AngelScript::asMETHOD(LocalStorage,GetRefCount), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_SETGCFLAG, "void f()", AngelScript::asMETHOD(LocalStorage,SetGCFlag), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_GETGCFLAG, "bool f()", AngelScript::asMETHOD(LocalStorage,GetGCFlag), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_ENUMREFS, "void f(int&in)", AngelScript::asMETHOD(LocalStorage,EnumReferences), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectBehaviour("LocalStorage", AngelScript::asBEHAVE_RELEASEREFS, "void f(int&in)", AngelScript::asMETHOD(LocalStorage,ReleaseAllReferences), AngelScript::asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - -} diff --git a/source/main/scripting/LocalStorage.h b/source/main/scripting/LocalStorage.h index cabc639abe..944089f603 100644 --- a/source/main/scripting/LocalStorage.h +++ b/source/main/scripting/LocalStorage.h @@ -28,11 +28,6 @@ /// @addtogroup Scripting /// @{ -void registerLocalStorage(AngelScript::asIScriptEngine* engine); -void scriptLocalStorageFactory_Generic(AngelScript::asIScriptGeneric* gen); -void scriptLocalStorageFactory2_Generic(AngelScript::asIScriptGeneric* gen); -void scriptLocalStorageFactory3_Generic(AngelScript::asIScriptGeneric* gen); - /** * @brief A class that allows scripts to store data persistently */ diff --git a/source/main/scripting/ScriptEngine.cpp b/source/main/scripting/ScriptEngine.cpp index 97f2bc3a5b..aea3467c48 100644 --- a/source/main/scripting/ScriptEngine.cpp +++ b/source/main/scripting/ScriptEngine.cpp @@ -131,250 +131,19 @@ void ScriptEngine::init() AngelScript::RegisterScriptAny(engine); AngelScript::RegisterScriptDictionary(engine); - // register some Ogre objects like the vector3 and the quaternion - RegisterOgreObjects(engine); - - // Register the local storage object. - // This needs to be done after the registration of the ogre objects! - registerLocalStorage(engine); - - registerInputEngine(engine); - - RegisterImGuiBindings(engine); - // some useful global functions result = engine->RegisterGlobalFunction("void log(const string &in)", AngelScript::asFUNCTION(logString), AngelScript::asCALL_CDECL); ROR_ASSERT( result >= 0 ); result = engine->RegisterGlobalFunction("void print(const string &in)", AngelScript::asFUNCTION(logString), AngelScript::asCALL_CDECL); ROR_ASSERT( result >= 0 ); - // enum aiEvents - result = engine->RegisterEnum("aiEvents"); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("aiEvents", "AI_LIGHTSTOGGLE", AI_LIGHTSTOGGLE); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("aiEvents", "AI_WAIT_SECONDS", AI_WAIT_SECONDS); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("aiEvents", "AI_BEACONSTOGGLE", AI_BEACONSTOGGLE); ROR_ASSERT(result >= 0); - - // enum aiEvents - result = engine->RegisterEnum("AiValues"); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("AiValues", "AI_SPEED", AI_SPEED); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("AiValues", "AI_POWER", AI_POWER); ROR_ASSERT(result >= 0); - - result = engine->RegisterObjectType("VehicleAIClass", sizeof(VehicleAI), AngelScript::asOBJ_REF); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("VehicleAIClass", "void addWaypoint(string &in, vector3 &in)", AngelScript::asMETHOD(VehicleAI, AddWaypoint), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("VehicleAIClass", "void addWaypoints(dictionary &in)", AngelScript::asMETHOD(VehicleAI, AddWaypoint), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("VehicleAIClass", "void setActive(bool)", AngelScript::asMETHOD(VehicleAI, SetActive), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("VehicleAIClass", "void addEvent(string &in,int &in)", AngelScript::asMETHOD(VehicleAI, AddEvent), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("VehicleAIClass", "void setValueAtWaypoint(string &in, int &in, float &in)", AngelScript::asMETHOD(VehicleAI, SetValueAtWaypoint), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectBehaviour("VehicleAIClass", AngelScript::asBEHAVE_ADDREF, "void f()", AngelScript::asMETHOD(VehicleAI, addRef), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectBehaviour("VehicleAIClass", AngelScript::asBEHAVE_RELEASE, "void f()", AngelScript::asMETHOD(VehicleAI, release), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - - // class CVar - result = engine->RegisterObjectType("CVarClass", sizeof(Console), AngelScript::asOBJ_REF | AngelScript::asOBJ_NOCOUNT); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("CVarClass", "const string& getName()", AngelScript::asMETHOD(CVar,getName), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("CVarClass", "const string& getStr()", AngelScript::asMETHOD(CVar,getStr), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("CVarClass", "int getInt()", AngelScript::asMETHOD(CVar,getInt), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("CVarClass", "float getFloat()", AngelScript::asMETHOD(CVar,getFloat), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("CVarClass", "bool getBool()", AngelScript::asMETHOD(CVar,getBool), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - // enum CVarFlags - result = engine->RegisterEnum("CVarFlags"); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("CVarFlags", "CVAR_TYPE_BOOL", CVAR_TYPE_BOOL); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("CVarFlags", "CVAR_TYPE_INT", CVAR_TYPE_INT); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("CVarFlags", "CVAR_TYPE_FLOAT", CVAR_TYPE_FLOAT); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("CVarFlags", "CVAR_ARCHIVE", CVAR_ARCHIVE); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("CVarFlags", "CVAR_NO_LOG", CVAR_NO_LOG); ROR_ASSERT(result >= 0); - - // class Console - result = engine->RegisterObjectType("ConsoleClass", sizeof(Console), AngelScript::asOBJ_REF | AngelScript::asOBJ_NOCOUNT); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("ConsoleClass", "CVarClass @cVarCreate(const string &in, const string &in, int, const string &in)", AngelScript::asMETHOD(Console,cVarCreate), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("ConsoleClass", "CVarClass @cVarFind(const string &in)", AngelScript::asMETHOD(Console,cVarFind), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("ConsoleClass", "CVarClass @cVarGet(const string &in, int)", AngelScript::asMETHOD(Console,cVarGet), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("ConsoleClass", "CVarClass @cVarSet(const string &in, const string &in)", AngelScript::asMETHOD(Console,cVarSet), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("ConsoleClass", "void cVarAssign(CVarClass@, const string &in)", AngelScript::asMETHOD(Console,cVarAssign), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - // class Actor (historically Beam) - result = engine->RegisterObjectType("BeamClass", sizeof(Actor), AngelScript::asOBJ_REF); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void scaleTruck(float)", AngelScript::asMETHOD(Actor,scaleTruck), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "string getTruckName()", AngelScript::asMETHOD(Actor,getTruckName), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "string getTruckFileName()", AngelScript::asMETHOD(Actor,getTruckFileName), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "string getSectionConfig()", AngelScript::asMETHOD(Actor, getSectionConfig), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("BeamClass", "int getTruckType()", AngelScript::asMETHOD(Actor,getTruckType), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void reset(bool)", AngelScript::asMETHOD(Actor,reset), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void parkingbrakeToggle()", AngelScript::asMETHOD(Actor,parkingbrakeToggle), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void tractioncontrolToggle()", AngelScript::asMETHOD(Actor,tractioncontrolToggle), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void antilockbrakeToggle()", AngelScript::asMETHOD(Actor,antilockbrakeToggle), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void beaconsToggle()", AngelScript::asMETHOD(Actor,beaconsToggle), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void toggleCustomParticles()", AngelScript::asMETHOD(Actor,toggleCustomParticles), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "int getNodeCount()", AngelScript::asMETHOD(Actor,getNodeCount), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "float getTotalMass(bool)", AngelScript::asMETHOD(Actor,getTotalMass), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "int getWheelNodeCount()", AngelScript::asMETHOD(Actor,getWheelNodeCount), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void setMass(float)", AngelScript::asMETHOD(Actor,setMass), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "bool getBrakeLightVisible()", AngelScript::asMETHOD(Actor,getBrakeLightVisible), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "bool getCustomLightVisible(int)", AngelScript::asMETHOD(Actor,getCustomLightVisible), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void setCustomLightVisible(int, bool)", AngelScript::asMETHOD(Actor,setCustomLightVisible), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "bool getBeaconMode()", AngelScript::asMETHOD(Actor,getBeaconMode), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "void setBlinkType(int)", AngelScript::asMETHOD(Actor,setBlinkType), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "int getBlinkType()", AngelScript::asMETHOD(Actor,getBlinkType), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "bool getCustomParticleMode()", AngelScript::asMETHOD(Actor,getCustomParticleMode), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "bool getReverseLightVisible()", AngelScript::asMETHOD(Actor,getCustomParticleMode), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "float getHeadingDirectionAngle()", AngelScript::asMETHOD(Actor,getRotation), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "bool isLocked()", AngelScript::asMETHOD(Actor,isLocked), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "float getWheelSpeed()", AngelScript::asMETHOD(Actor,getWheelSpeed), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "float getSpeed()", AngelScript::asMETHOD(Actor,getSpeed), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "vector3 getGForces()", AngelScript::asMETHOD(Actor,getGForces), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("BeamClass", "float getRotation()", AngelScript::asMETHOD(Actor,getRotation), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "vector3 getVehiclePosition()", AngelScript::asMETHOD(Actor,getPosition), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("BeamClass", "vector3 getNodePosition(int)", AngelScript::asMETHOD(Actor,getNodePosition), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("BeamClass", "VehicleAIClass @getVehicleAI()", AngelScript::asMETHOD(Actor,getVehicleAI), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - - /* - // impossible to use offsetof for derived classes - // unusable, read http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_class_hierarchy.html - */ - - result = engine->RegisterObjectBehaviour("BeamClass", AngelScript::asBEHAVE_ADDREF, "void f()", AngelScript::asMETHOD(Actor,addRef), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectBehaviour("BeamClass", AngelScript::asBEHAVE_RELEASE, "void f()", AngelScript::asMETHOD(Actor,release), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - // TODO: add Vector3 classes and other utility classes! - - // class GameScript - result = engine->RegisterObjectType("GameScriptClass", sizeof(GameScript), AngelScript::asOBJ_VALUE | AngelScript::asOBJ_POD | AngelScript::asOBJ_APP_CLASS); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void log(const string &in)", AngelScript::asMETHOD(GameScript,log), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "float getTime()", AngelScript::asMETHOD(GameScript,getTime), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "float rangeRandom(float, float)", AngelScript::asMETHOD(GameScript,rangeRandom), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void activateAllVehicles()", AngelScript::asMETHOD(GameScript,activateAllVehicles), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setTrucksForcedActive(bool forceActive)", AngelScript::asMETHOD(GameScript,SetTrucksForcedAwake), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void setBestLapTime(float time)", AngelScript::asMETHOD(GameScript,setBestLapTime), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setTimeDiff(float diff)", AngelScript::asMETHOD(GameScript,setTimeDiff), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void startTimer(int id)", AngelScript::asMETHOD(GameScript,startTimer), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void stopTimer()", AngelScript::asMETHOD(GameScript,stopTimer), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void flashMessage(const string &in, float, float)", AngelScript::asMETHOD(GameScript,flashMessage), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void message(const string &in, const string &in, float, bool)", AngelScript::asMETHOD(GameScript,message), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void UpdateDirectionArrow(const string &in, vector3 &in)", AngelScript::asMETHOD(GameScript,UpdateDirectionArrow), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void hideDirectionArrow()", AngelScript::asMETHOD(GameScript,hideDirectionArrow), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void showChooser(const string &in, const string &in, const string &in)", AngelScript::asMETHOD(GameScript,showChooser), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getChatFontSize()", AngelScript::asMETHOD(GameScript,getChatFontSize), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setChatFontSize(int)", AngelScript::asMETHOD(GameScript,setChatFontSize), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void loadTerrain(const string &in)", AngelScript::asMETHOD(GameScript,loadTerrain), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getLoadedTerrain(string &out)", AngelScript::asMETHOD(GameScript,getLoadedTerrain), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "bool getCaelumAvailable()", AngelScript::asMETHOD(GameScript,getCaelumAvailable), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "string getCaelumTime()", AngelScript::asMETHOD(GameScript,getCaelumTime), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCaelumTime(float)", AngelScript::asMETHOD(GameScript,setCaelumTime), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setWaterHeight(float)", AngelScript::asMETHOD(GameScript,setWaterHeight), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "float getWaterHeight()", AngelScript::asMETHOD(GameScript,getWaterHeight), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "float getGroundHeight(vector3 &in)", AngelScript::asMETHOD(GameScript,getGroundHeight), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "float getGravity()", AngelScript::asMETHOD(GameScript,getGravity), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setGravity(float)", AngelScript::asMETHOD(GameScript,setGravity), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void spawnObject(const string &in, const string &in, vector3 &in, vector3 &in, const string &in, bool)", AngelScript::asMETHOD(GameScript,spawnObject), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void MoveObjectVisuals(const string &in, vector3 &in)", AngelScript::asMETHOD(GameScript,MoveTerrainObjectVisuals), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void destroyObject(const string &in)", AngelScript::asMETHOD(GameScript,destroyObject), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialAmbient(const string &in, float, float, float)", AngelScript::asMETHOD(GameScript,setMaterialAmbient), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialDiffuse(const string &in, float, float, float, float)", AngelScript::asMETHOD(GameScript,setMaterialDiffuse), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialSpecular(const string &in, float, float, float, float)", AngelScript::asMETHOD(GameScript,setMaterialSpecular), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialEmissive(const string &in, float, float, float)", AngelScript::asMETHOD(GameScript,setMaterialEmissive), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureName(const string &in, int, int, int, const string &in)", AngelScript::asMETHOD(GameScript,setMaterialTextureName), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureRotate(const string &in, int, int, int, float)", AngelScript::asMETHOD(GameScript,setMaterialTextureRotate), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureScroll(const string &in, int, int, int, float, float)", AngelScript::asMETHOD(GameScript,setMaterialTextureScroll), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureScale(const string &in, int, int, int, float, float)", AngelScript::asMETHOD(GameScript,setMaterialTextureScale), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void repairVehicle(const string &in, const string &in, bool)", AngelScript::asMETHOD(GameScript,repairVehicle), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void removeVehicle(const string &in, const string &in)", AngelScript::asMETHOD(GameScript,removeVehicle), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getCurrentTruckNumber()", AngelScript::asMETHOD(GameScript,GetPlayerActorId), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void boostCurrentTruck(float)", AngelScript::asMETHOD(GameScript, boostCurrentTruck), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucks()", AngelScript::asMETHOD(GameScript,getNumTrucks), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @getCurrentTruck()", AngelScript::asMETHOD(GameScript,getCurrentTruck), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @getTruckByNum(int)", AngelScript::asMETHOD(GameScript,getTruckByNum), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucksByFlag(int)", AngelScript::asMETHOD(GameScript,getNumTrucksByFlag), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void setPersonPosition(vector3 &in)", AngelScript::asMETHOD(GameScript,setPersonPosition), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getPersonPosition()", AngelScript::asMETHOD(GameScript,getPersonPosition), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setPersonRotation(radian &in)", AngelScript::asMETHOD(GameScript,setPersonRotation), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "radian getPersonRotation()", AngelScript::asMETHOD(GameScript,getPersonRotation), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraPosition(vector3 &in)", AngelScript::asMETHOD(GameScript,setCameraPosition), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraDirection(vector3 &in)", AngelScript::asMETHOD(GameScript,setCameraDirection), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraYaw(float)", AngelScript::asMETHOD(GameScript,setCameraYaw), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraPitch(float)", AngelScript::asMETHOD(GameScript,setCameraPitch), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraRoll(float)", AngelScript::asMETHOD(GameScript,setCameraRoll), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraPosition()", AngelScript::asMETHOD(GameScript,getCameraPosition), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraDirection()", AngelScript::asMETHOD(GameScript,getCameraDirection), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void cameraLookAt(vector3 &in)", AngelScript::asMETHOD(GameScript,cameraLookAt), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraOrientation(vector3 &in)", AngelScript::asMETHOD(GameScript,setCameraOrientation), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraOrientation()", AngelScript::asMETHOD(GameScript,getCameraOrientation), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "int addScriptFunction(const string &in)", AngelScript::asMETHOD(GameScript,addScriptFunction), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int scriptFunctionExists(const string &in)", AngelScript::asMETHOD(GameScript,scriptFunctionExists), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int deleteScriptFunction(const string &in)", AngelScript::asMETHOD(GameScript,deleteScriptFunction), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int addScriptVariable(const string &in)", AngelScript::asMETHOD(GameScript,addScriptVariable), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int deleteScriptVariable(const string &in)", AngelScript::asMETHOD(GameScript,deleteScriptVariable), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void clearEventCache()", AngelScript::asMETHOD(GameScript,clearEventCache), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void registerForEvent(int)", AngelScript::asMETHOD(GameScript,registerForEvent), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void unRegisterEvent(int)", AngelScript::asMETHOD(GameScript,unRegisterEvent), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "int sendGameCmd(const string &in)", AngelScript::asMETHOD(GameScript,sendGameCmd), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int useOnlineAPI(const string &in, const dictionary &in, string &out)", AngelScript::asMETHOD(GameScript,useOnlineAPI), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "VehicleAIClass @getCurrentTruckAI()", AngelScript::asMETHOD(GameScript, getCurrentTruckAI), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("GameScriptClass", "VehicleAIClass @getTruckAIByNum(int)", AngelScript::asMETHOD(GameScript, getTruckAIByNum), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void showMessageBox(string &in, string &in, bool button1, string &in, bool AllowClose, bool button2,string &in)", AngelScript::asMETHOD(GameScript, showMessageBox), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @spawnTruck(string &in, vector3 &in, vector3 &in)", AngelScript::asMETHOD(GameScript, spawnTruck), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - - result = engine->RegisterObjectMethod("GameScriptClass", "float getFPS()", AngelScript::asMETHOD(GameScript, getFPS), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void backToMenu()", AngelScript::asMETHOD(GameScript, backToMenu), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("GameScriptClass", "void quitGame()", AngelScript::asMETHOD(GameScript, quitGame), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); - - - - // enum scriptEvents - result = engine->RegisterEnum("scriptEvents"); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_COLLISION_BOX_ENTER", SE_COLLISION_BOX_ENTER); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_COLLISION_BOX_LEAVE", SE_COLLISION_BOX_LEAVE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_ENTER", SE_TRUCK_ENTER); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_EXIT", SE_TRUCK_EXIT); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_ENGINE_DIED", SE_TRUCK_ENGINE_DIED); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_ENGINE_FIRE", SE_TRUCK_ENGINE_FIRE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_TOUCHED_WATER", SE_TRUCK_TOUCHED_WATER); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_BEAM_BROKE", SE_TRUCK_BEAM_BROKE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_LOCKED", SE_TRUCK_LOCKED); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_UNLOCKED", SE_TRUCK_UNLOCKED); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_LIGHT_TOGGLE", SE_TRUCK_LIGHT_TOGGLE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_SKELETON_TOGGLE", SE_TRUCK_SKELETON_TOGGLE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_TIE_TOGGLE", SE_TRUCK_TIE_TOGGLE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_PARKINGBREAK_TOGGLE", SE_TRUCK_PARKINGBREAK_TOGGLE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_RESET", SE_TRUCK_RESET); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_TELEPORT", SE_TRUCK_TELEPORT); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_BEACONS_TOGGLE", SE_TRUCK_BEACONS_TOGGLE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_CPARTICLES_TOGGLE", SE_TRUCK_CPARTICLES_TOGGLE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_GROUND_CONTACT_CHANGED", SE_TRUCK_GROUND_CONTACT_CHANGED); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_NEW_TRUCK", SE_GENERIC_NEW_TRUCK); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_DELETED_TRUCK", SE_GENERIC_DELETED_TRUCK); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_INPUT_EVENT", SE_GENERIC_INPUT_EVENT); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_MOUSE_BEAM_INTERACTION", SE_GENERIC_MOUSE_BEAM_INTERACTION); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_ANGELSCRIPT_MANIPULATIONS", SE_ANGELSCRIPT_MANIPULATIONS); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_MESSAGEBOX_CLICK", SE_GENERIC_MESSAGEBOX_CLICK); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("scriptEvents", "SE_ALL_EVENTS", SE_ALL_EVENTS); ROR_ASSERT(result>=0); - - // enum truckStates - result = engine->RegisterEnum("truckStates"); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckStates", "TS_SIMULATED", static_cast(ActorState::LOCAL_SIMULATED)); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckStates", "TS_SLEEPING", static_cast(ActorState::LOCAL_SLEEPING)); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckStates", "TS_NETWORKED", static_cast(ActorState::NETWORKED_OK)); ROR_ASSERT(result>=0); - - // enum truckTypes - result = engine->RegisterEnum("truckTypes"); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckTypes", "TT_NOT_DRIVEABLE", NOT_DRIVEABLE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckTypes", "TT_TRUCK", TRUCK); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckTypes", "TT_AIRPLANE", AIRPLANE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckTypes", "TT_BOAT", BOAT); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckTypes", "TT_MACHINE", MACHINE); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckTypes", "TT_AI", AI); ROR_ASSERT(result>=0); + RegisterOgreObjects(engine); // vector2/3, degree, radian, quaternion, color + RegisterLocalStorage(engine); // LocalStorage + RegisterInputEngine(engine); // InputEngineClass, inputEvents + RegisterImGuiBindings(engine); // ImGUi:: + RegisterVehicleAi(engine); // VehicleAIClass, aiEvents, AiValues + RegisterConsole(engine); // ConsoleClass, CVarClass, CVarFlags + RegisterActor(engine); // BeamClass + RegisterGameScript(engine); // GameScriptClass + RegisterScriptEvents(engine); // scriptEvents // now the global instances result = engine->RegisterGlobalProperty("GameScriptClass game", &m_game_script); ROR_ASSERT(result>=0); diff --git a/source/main/scripting/ScriptEngine.h b/source/main/scripting/ScriptEngine.h index 8210795304..def0951a79 100644 --- a/source/main/scripting/ScriptEngine.h +++ b/source/main/scripting/ScriptEngine.h @@ -31,6 +31,7 @@ #define DEFAULT_TERRAIN_SCRIPT "default.as" // Used when map creator doesn't provide custom script. +#include "AngelScriptBindings.h" #include "Application.h" #include "GameScript.h" #include "InterThreadStoreVector.h" @@ -202,20 +203,6 @@ class ScriptEngine : public Ogre::LogListener, public ZeroedMemoryAllocator InterThreadStoreVector stringExecutionQueue; //!< The string execution queue \see queueStringForExecution }; -// This function will register the following objects with the scriptengine: -// - Ogre::Vector3 -// - Ogre::Vector2 -// - Ogre::Radian -// - Ogre::Degree -// - Ogre::Quaternion -// - Ogre::ColourValue -void RegisterOgreObjects(AngelScript::asIScriptEngine* engine); - -void RegisterImGuiBindings(AngelScript::asIScriptEngine* engine); - -/// Registers RoR::InputEngine, defined in InputEngineAngelscript.cpp -void registerInputEngine(AngelScript::asIScriptEngine* engine); - /// @} //addtogroup Scripting } // namespace RoR diff --git a/source/main/scripting/bindings/ActorAngelscript.cpp b/source/main/scripting/bindings/ActorAngelscript.cpp new file mode 100644 index 0000000000..71eb71586e --- /dev/null +++ b/source/main/scripting/bindings/ActorAngelscript.cpp @@ -0,0 +1,89 @@ +/* + This source file is part of Rigs of Rods + Copyright 2005-2012 Pierre-Michel Ricordel + Copyright 2007-2012 Thomas Fischer + Copyright 2013-2022 Petr Ohlidal + + For more information, see http://www.rigsofrods.org/ + + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + +#include "Actor.h" +#include "AngelScriptBindings.h" +#include "SimData.h" +#include + +using namespace AngelScript; + +void RoR::RegisterActor(asIScriptEngine *engine) +{ + int result; + + // enum truckStates + result = engine->RegisterEnum("truckStates"); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckStates", "TS_SIMULATED", static_cast(ActorState::LOCAL_SIMULATED)); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckStates", "TS_SLEEPING", static_cast(ActorState::LOCAL_SLEEPING)); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckStates", "TS_NETWORKED", static_cast(ActorState::NETWORKED_OK)); ROR_ASSERT(result>=0); + + // enum truckTypes + result = engine->RegisterEnum("truckTypes"); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckTypes", "TT_NOT_DRIVEABLE", NOT_DRIVEABLE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckTypes", "TT_TRUCK", TRUCK); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckTypes", "TT_AIRPLANE", AIRPLANE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckTypes", "TT_BOAT", BOAT); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckTypes", "TT_MACHINE", MACHINE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckTypes", "TT_AI", AI); ROR_ASSERT(result>=0); + + + // class Actor (historically Beam) + result = engine->RegisterObjectType("BeamClass", sizeof(Actor), asOBJ_REF); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void scaleTruck(float)", asMETHOD(Actor,scaleTruck), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "string getTruckName()", asMETHOD(Actor,getTruckName), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "string getTruckFileName()", asMETHOD(Actor,getTruckFileName), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "string getSectionConfig()", asMETHOD(Actor, getSectionConfig), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("BeamClass", "int getTruckType()", asMETHOD(Actor,getTruckType), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void reset(bool)", asMETHOD(Actor,reset), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void parkingbrakeToggle()", asMETHOD(Actor,parkingbrakeToggle), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void tractioncontrolToggle()", asMETHOD(Actor,tractioncontrolToggle), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void antilockbrakeToggle()", asMETHOD(Actor,antilockbrakeToggle), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void beaconsToggle()", asMETHOD(Actor,beaconsToggle), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void toggleCustomParticles()", asMETHOD(Actor,toggleCustomParticles), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "int getNodeCount()", asMETHOD(Actor,getNodeCount), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "float getTotalMass(bool)", asMETHOD(Actor,getTotalMass), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "int getWheelNodeCount()", asMETHOD(Actor,getWheelNodeCount), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void setMass(float)", asMETHOD(Actor,setMass), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "bool getBrakeLightVisible()", asMETHOD(Actor,getBrakeLightVisible), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "bool getCustomLightVisible(int)", asMETHOD(Actor,getCustomLightVisible), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void setCustomLightVisible(int, bool)", asMETHOD(Actor,setCustomLightVisible), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "bool getBeaconMode()", asMETHOD(Actor,getBeaconMode), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "void setBlinkType(int)", asMETHOD(Actor,setBlinkType), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "int getBlinkType()", asMETHOD(Actor,getBlinkType), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "bool getCustomParticleMode()", asMETHOD(Actor,getCustomParticleMode), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "bool getReverseLightVisible()", asMETHOD(Actor,getCustomParticleMode), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "float getHeadingDirectionAngle()", asMETHOD(Actor,getRotation), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "bool isLocked()", asMETHOD(Actor,isLocked), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "float getWheelSpeed()", asMETHOD(Actor,getWheelSpeed), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "float getSpeed()", asMETHOD(Actor,getSpeed), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "vector3 getGForces()", asMETHOD(Actor,getGForces), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("BeamClass", "float getRotation()", asMETHOD(Actor,getRotation), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "vector3 getVehiclePosition()", asMETHOD(Actor,getPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("BeamClass", "vector3 getNodePosition(int)", asMETHOD(Actor,getNodePosition), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("BeamClass", "VehicleAIClass @getVehicleAI()", asMETHOD(Actor,getVehicleAI), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectBehaviour("BeamClass", asBEHAVE_ADDREF, "void f()", asMETHOD(Actor,addRef), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectBehaviour("BeamClass", asBEHAVE_RELEASE, "void f()", asMETHOD(Actor,release), asCALL_THISCALL); ROR_ASSERT(result>=0); + +} diff --git a/source/main/scripting/bindings/AngelScriptBindings.h b/source/main/scripting/bindings/AngelScriptBindings.h new file mode 100644 index 0000000000..7d20b1336e --- /dev/null +++ b/source/main/scripting/bindings/AngelScriptBindings.h @@ -0,0 +1,67 @@ +/* + This source file is part of Rigs of Rods + Copyright 2005-2012 Pierre-Michel Ricordel + Copyright 2007-2012 Thomas Fischer + Copyright 2013-2022 Petr Ohlidal + + For more information, see http://www.rigsofrods.org/ + + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + +#pragma once + +/// @file + +namespace RoR { + +/// @addtogroup Scripting +/// @{ + +/// defined in ActorAngelscript.cpp +void RegisterActor(AngelScript::asIScriptEngine* engine); + +/// defined in VehicleAiAngelscript.cpp +void RegisterVehicleAi(AngelScript::asIScriptEngine* engine); + +/// Registers RoR::InputEngine, defined in InputEngineAngelscript.cpp +void RegisterInputEngine(AngelScript::asIScriptEngine* engine); + +/// Registers RoR::Console, defined in ConsoleAngelscript.cpp +void RegisterConsole(AngelScript::asIScriptEngine* engine); + +/// Registers RoR::LocalStorage, defined in LocalStorageAngelscript.cpp +void RegisterLocalStorage(AngelScript::asIScriptEngine* engine); + +/// Registers RoR::GameScript, defined in GameScriptAngelscript.cpp +void RegisterGameScript(AngelScript::asIScriptEngine* engine); + +/// Registers enum scriptEvents, defined in ScriptEventsAngelscript.cpp +void RegisterScriptEvents(AngelScript::asIScriptEngine* engine); + +/// defined in ImGuiAngelscript.cpp +void RegisterImGuiBindings(AngelScript::asIScriptEngine* engine); + +// This function will register the following objects with the scriptengine: +// - Ogre::Vector3 +// - Ogre::Vector2 +// - Ogre::Radian +// - Ogre::Degree +// - Ogre::Quaternion +// - Ogre::ColourValue +/// defined in OgreAngelscript.cpp +void RegisterOgreObjects(AngelScript::asIScriptEngine* engine); + +/// @} //addtogroup Scripting + +} // namespace RoR diff --git a/source/main/scripting/bindings/ConsoleAngelscript.cpp b/source/main/scripting/bindings/ConsoleAngelscript.cpp new file mode 100644 index 0000000000..ad40934cf7 --- /dev/null +++ b/source/main/scripting/bindings/ConsoleAngelscript.cpp @@ -0,0 +1,56 @@ +/* + This source file is part of Rigs of Rods + Copyright 2005-2012 Pierre-Michel Ricordel + Copyright 2007-2012 Thomas Fischer + Copyright 2013-2022 Petr Ohlidal + + For more information, see http://www.rigsofrods.org/ + + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + +#include "Console.h" +#include "AngelScriptBindings.h" +#include + +using namespace AngelScript; + +void RoR::RegisterConsole(asIScriptEngine *engine) +{ + int result; + + // class CVar + result = engine->RegisterObjectType("CVarClass", sizeof(Console), asOBJ_REF | asOBJ_NOCOUNT); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("CVarClass", "const string& getName()", asMETHOD(CVar,getName), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("CVarClass", "const string& getStr()", asMETHOD(CVar,getStr), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("CVarClass", "int getInt()", asMETHOD(CVar,getInt), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("CVarClass", "float getFloat()", asMETHOD(CVar,getFloat), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("CVarClass", "bool getBool()", asMETHOD(CVar,getBool), asCALL_THISCALL); ROR_ASSERT(result>=0); + + // enum CVarFlags + result = engine->RegisterEnum("CVarFlags"); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("CVarFlags", "CVAR_TYPE_BOOL", CVAR_TYPE_BOOL); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("CVarFlags", "CVAR_TYPE_INT", CVAR_TYPE_INT); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("CVarFlags", "CVAR_TYPE_FLOAT", CVAR_TYPE_FLOAT); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("CVarFlags", "CVAR_ARCHIVE", CVAR_ARCHIVE); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("CVarFlags", "CVAR_NO_LOG", CVAR_NO_LOG); ROR_ASSERT(result >= 0); + + // class Console + result = engine->RegisterObjectType("ConsoleClass", sizeof(Console), asOBJ_REF | asOBJ_NOCOUNT); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("ConsoleClass", "CVarClass @cVarCreate(const string &in, const string &in, int, const string &in)", asMETHOD(Console,cVarCreate), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("ConsoleClass", "CVarClass @cVarFind(const string &in)", asMETHOD(Console,cVarFind), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("ConsoleClass", "CVarClass @cVarGet(const string &in, int)", asMETHOD(Console,cVarGet), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("ConsoleClass", "CVarClass @cVarSet(const string &in, const string &in)", asMETHOD(Console,cVarSet), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("ConsoleClass", "void cVarAssign(CVarClass@, const string &in)", asMETHOD(Console,cVarAssign), asCALL_THISCALL); ROR_ASSERT(result>=0); + +} diff --git a/source/main/scripting/bindings/GameScriptAngelscript.cpp b/source/main/scripting/bindings/GameScriptAngelscript.cpp new file mode 100644 index 0000000000..3b59dbeb5b --- /dev/null +++ b/source/main/scripting/bindings/GameScriptAngelscript.cpp @@ -0,0 +1,123 @@ +/* + This source file is part of Rigs of Rods + Copyright 2005-2012 Pierre-Michel Ricordel + Copyright 2007-2012 Thomas Fischer + Copyright 2013-2022 Petr Ohlidal + + For more information, see http://www.rigsofrods.org/ + + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + +#include "GameScript.h" +#include "AngelScriptBindings.h" +#include + +using namespace AngelScript; + +void RoR::RegisterGameScript(asIScriptEngine *engine) +{ + int result; + + // class GameScript + result = engine->RegisterObjectType("GameScriptClass", sizeof(GameScript), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void log(const string &in)", asMETHOD(GameScript,log), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getTime()", asMETHOD(GameScript,getTime), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "float rangeRandom(float, float)", asMETHOD(GameScript,rangeRandom), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void activateAllVehicles()", asMETHOD(GameScript,activateAllVehicles), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setTrucksForcedActive(bool forceActive)", asMETHOD(GameScript,SetTrucksForcedAwake), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void setBestLapTime(float time)", asMETHOD(GameScript,setBestLapTime), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setTimeDiff(float diff)", asMETHOD(GameScript,setTimeDiff), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void startTimer(int id)", asMETHOD(GameScript,startTimer), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void stopTimer()", asMETHOD(GameScript,stopTimer), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void flashMessage(const string &in, float, float)", asMETHOD(GameScript,flashMessage), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void message(const string &in, const string &in, float, bool)", asMETHOD(GameScript,message), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void UpdateDirectionArrow(const string &in, vector3 &in)", asMETHOD(GameScript,UpdateDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void hideDirectionArrow()", asMETHOD(GameScript,hideDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void showChooser(const string &in, const string &in, const string &in)", asMETHOD(GameScript,showChooser), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getChatFontSize()", asMETHOD(GameScript,getChatFontSize), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setChatFontSize(int)", asMETHOD(GameScript,setChatFontSize), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void loadTerrain(const string &in)", asMETHOD(GameScript,loadTerrain), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getLoadedTerrain(string &out)", asMETHOD(GameScript,getLoadedTerrain), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "bool getCaelumAvailable()", asMETHOD(GameScript,getCaelumAvailable), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "string getCaelumTime()", asMETHOD(GameScript,getCaelumTime), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCaelumTime(float)", asMETHOD(GameScript,setCaelumTime), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setWaterHeight(float)", asMETHOD(GameScript,setWaterHeight), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getWaterHeight()", asMETHOD(GameScript,getWaterHeight), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getGroundHeight(vector3 &in)", asMETHOD(GameScript,getGroundHeight), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getGravity()", asMETHOD(GameScript,getGravity), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setGravity(float)", asMETHOD(GameScript,setGravity), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void spawnObject(const string &in, const string &in, vector3 &in, vector3 &in, const string &in, bool)", asMETHOD(GameScript,spawnObject), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void MoveObjectVisuals(const string &in, vector3 &in)", asMETHOD(GameScript,MoveTerrainObjectVisuals), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void destroyObject(const string &in)", asMETHOD(GameScript,destroyObject), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialAmbient(const string &in, float, float, float)", asMETHOD(GameScript,setMaterialAmbient), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialDiffuse(const string &in, float, float, float, float)", asMETHOD(GameScript,setMaterialDiffuse), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialSpecular(const string &in, float, float, float, float)", asMETHOD(GameScript,setMaterialSpecular), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialEmissive(const string &in, float, float, float)", asMETHOD(GameScript,setMaterialEmissive), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureName(const string &in, int, int, int, const string &in)", asMETHOD(GameScript,setMaterialTextureName), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureRotate(const string &in, int, int, int, float)", asMETHOD(GameScript,setMaterialTextureRotate), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureScroll(const string &in, int, int, int, float, float)", asMETHOD(GameScript,setMaterialTextureScroll), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureScale(const string &in, int, int, int, float, float)", asMETHOD(GameScript,setMaterialTextureScale), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void repairVehicle(const string &in, const string &in, bool)", asMETHOD(GameScript,repairVehicle), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void removeVehicle(const string &in, const string &in)", asMETHOD(GameScript,removeVehicle), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getCurrentTruckNumber()", asMETHOD(GameScript,GetPlayerActorId), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void boostCurrentTruck(float)", asMETHOD(GameScript, boostCurrentTruck), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucks()", asMETHOD(GameScript,getNumTrucks), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @getCurrentTruck()", asMETHOD(GameScript,getCurrentTruck), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @getTruckByNum(int)", asMETHOD(GameScript,getTruckByNum), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucksByFlag(int)", asMETHOD(GameScript,getNumTrucksByFlag), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void setPersonPosition(vector3 &in)", asMETHOD(GameScript,setPersonPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getPersonPosition()", asMETHOD(GameScript,getPersonPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setPersonRotation(radian &in)", asMETHOD(GameScript,setPersonRotation), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "radian getPersonRotation()", asMETHOD(GameScript,getPersonRotation), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraPosition(vector3 &in)", asMETHOD(GameScript,setCameraPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraDirection(vector3 &in)", asMETHOD(GameScript,setCameraDirection), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraYaw(float)", asMETHOD(GameScript,setCameraYaw), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraPitch(float)", asMETHOD(GameScript,setCameraPitch), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraRoll(float)", asMETHOD(GameScript,setCameraRoll), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraPosition()", asMETHOD(GameScript,getCameraPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraDirection()", asMETHOD(GameScript,getCameraDirection), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void cameraLookAt(vector3 &in)", asMETHOD(GameScript,cameraLookAt), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraOrientation(vector3 &in)", asMETHOD(GameScript,setCameraOrientation), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraOrientation()", asMETHOD(GameScript,getCameraOrientation), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "int addScriptFunction(const string &in)", asMETHOD(GameScript,addScriptFunction), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int scriptFunctionExists(const string &in)", asMETHOD(GameScript,scriptFunctionExists), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int deleteScriptFunction(const string &in)", asMETHOD(GameScript,deleteScriptFunction), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int addScriptVariable(const string &in)", asMETHOD(GameScript,addScriptVariable), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int deleteScriptVariable(const string &in)", asMETHOD(GameScript,deleteScriptVariable), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void clearEventCache()", asMETHOD(GameScript,clearEventCache), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void registerForEvent(int)", asMETHOD(GameScript,registerForEvent), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void unRegisterEvent(int)", asMETHOD(GameScript,unRegisterEvent), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "int sendGameCmd(const string &in)", asMETHOD(GameScript,sendGameCmd), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int useOnlineAPI(const string &in, const dictionary &in, string &out)", asMETHOD(GameScript,useOnlineAPI), asCALL_THISCALL); ROR_ASSERT(result>=0); + + result = engine->RegisterObjectMethod("GameScriptClass", "VehicleAIClass @getCurrentTruckAI()", asMETHOD(GameScript, getCurrentTruckAI), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "VehicleAIClass @getTruckAIByNum(int)", asMETHOD(GameScript, getTruckAIByNum), asCALL_THISCALL); ROR_ASSERT(result >= 0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void showMessageBox(string &in, string &in, bool button1, string &in, bool AllowClose, bool button2,string &in)", asMETHOD(GameScript, showMessageBox), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @spawnTruck(string &in, vector3 &in, vector3 &in)", asMETHOD(GameScript, spawnTruck), asCALL_THISCALL); ROR_ASSERT(result >= 0); + + result = engine->RegisterObjectMethod("GameScriptClass", "float getFPS()", asMETHOD(GameScript, getFPS), asCALL_THISCALL); ROR_ASSERT(result >= 0); + + result = engine->RegisterObjectMethod("GameScriptClass", "void backToMenu()", asMETHOD(GameScript, backToMenu), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void quitGame()", asMETHOD(GameScript, quitGame), asCALL_THISCALL); ROR_ASSERT(result >= 0); +} diff --git a/source/main/scripting/ImGuiAngelscript.cpp b/source/main/scripting/bindings/ImGuiAngelscript.cpp similarity index 99% rename from source/main/scripting/ImGuiAngelscript.cpp rename to source/main/scripting/bindings/ImGuiAngelscript.cpp index 3212d8ccf8..7905ff98eb 100644 --- a/source/main/scripting/ImGuiAngelscript.cpp +++ b/source/main/scripting/bindings/ImGuiAngelscript.cpp @@ -2,7 +2,7 @@ This source file is part of Rigs of Rods Copyright 2005-2012 Pierre-Michel Ricordel Copyright 2007-2012 Thomas Fischer - Copyright 2013-2020 Petr Ohlidal + Copyright 2013-2022 Petr Ohlidal For more information, see http://www.rigsofrods.org/ diff --git a/source/main/scripting/InputEngineAngelscript.cpp b/source/main/scripting/bindings/InputEngineAngelscript.cpp similarity index 96% rename from source/main/scripting/InputEngineAngelscript.cpp rename to source/main/scripting/bindings/InputEngineAngelscript.cpp index cef4a5bf11..4bbb672669 100644 --- a/source/main/scripting/InputEngineAngelscript.cpp +++ b/source/main/scripting/bindings/InputEngineAngelscript.cpp @@ -26,25 +26,27 @@ #include "InputEngine.h" #include "ScriptEngine.h" -void registerInputEngineObject(AngelScript::asIScriptEngine* engine) +using namespace AngelScript; + +void registerInputEngineObject(asIScriptEngine* engine) { using namespace RoR; int result = 0; - result = engine->RegisterObjectType("InputEngineClass", sizeof(InputEngine), AngelScript::asOBJ_REF | AngelScript::asOBJ_NOCOUNT); ROR_ASSERT(result>=0); + result = engine->RegisterObjectType("InputEngineClass", sizeof(InputEngine), asOBJ_REF | asOBJ_NOCOUNT); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("InputEngineClass", "string getEventCommand(inputEvents ev)", AngelScript::asMETHOD(InputEngine,getEventCommand), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("InputEngineClass", "string getEventCommandTrimmed(inputEvents ev)", AngelScript::asMETHOD(InputEngine,getEventCommandTrimmed), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("InputEngineClass", "string getEventCommand(inputEvents ev)", asMETHOD(InputEngine,getEventCommand), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("InputEngineClass", "string getEventCommandTrimmed(inputEvents ev)", asMETHOD(InputEngine,getEventCommandTrimmed), asCALL_THISCALL); ROR_ASSERT(result>=0); // TODO: register OIS::KeyCode or port to SDL2 already (for Apple OSX support) -// result = engine->RegisterObjectMethod("InputEngineClass", "bool isKeyDown(int keycode)", AngelScript::asMETHOD(InputEngine,isKeyDown), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); -// result = engine->RegisterObjectMethod("InputEngineClass", "bool isKeyDownEffective(int keycode)", AngelScript::asMETHOD(InputEngine,isKeyDownEffective), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); +// result = engine->RegisterObjectMethod("InputEngineClass", "bool isKeyDown(int keycode)", asMETHOD(InputEngine,isKeyDown), asCALL_THISCALL); ROR_ASSERT(result>=0); +// result = engine->RegisterObjectMethod("InputEngineClass", "bool isKeyDownEffective(int keycode)", asMETHOD(InputEngine,isKeyDownEffective), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("InputEngineClass", "bool getEventBoolValue(inputEvents ev)", AngelScript::asMETHOD(InputEngine,getEventBoolValue), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("InputEngineClass", "bool getEventBoolValueBounce(inputEvents ev, float time = 0.2f)", AngelScript::asMETHOD(InputEngine,getEventBoolValueBounce), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("InputEngineClass", "bool getEventBoolValue(inputEvents ev)", asMETHOD(InputEngine,getEventBoolValue), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("InputEngineClass", "bool getEventBoolValueBounce(inputEvents ev, float time = 0.2f)", asMETHOD(InputEngine,getEventBoolValueBounce), asCALL_THISCALL); ROR_ASSERT(result>=0); } -void registerEventTypeEnum(AngelScript::asIScriptEngine* engine) +void registerEventTypeEnum(asIScriptEngine* engine) { using namespace RoR; int result = 0; @@ -368,7 +370,7 @@ void registerEventTypeEnum(AngelScript::asIScriptEngine* engine) result = engine->RegisterEnumValue("inputEvents", "EV_TRUCKEDIT_RELOAD", EV_TRUCKEDIT_RELOAD ); ROR_ASSERT(result >= 0); } -void RoR::registerInputEngine(AngelScript::asIScriptEngine* engine) +void RoR::RegisterInputEngine(asIScriptEngine* engine) { registerEventTypeEnum(engine); registerInputEngineObject(engine); diff --git a/source/main/scripting/bindings/LocalStorageAngelscript.cpp b/source/main/scripting/bindings/LocalStorageAngelscript.cpp new file mode 100644 index 0000000000..0a7f6c9c78 --- /dev/null +++ b/source/main/scripting/bindings/LocalStorageAngelscript.cpp @@ -0,0 +1,111 @@ +/* + This source file is part of Rigs of Rods + Copyright 2005-2012 Pierre-Michel Ricordel + Copyright 2007-2012 Thomas Fischer + Copyright 2013-2022 Petr Ohlidal + + For more information, see http://www.rigsofrods.org/ + + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + +#include "LocalStorage.h" +#include "AngelScriptBindings.h" +#include + +using namespace AngelScript; + +void scriptLocalStorageFactory_Generic(asIScriptGeneric *gen) +{ + std::string filename = **(std::string**)gen->GetAddressOfArg(0); + std::string sectionname = **(std::string**)gen->GetAddressOfArg(1); + + *(LocalStorage**)gen->GetAddressOfReturnLocation() = new LocalStorage(gen->GetEngine(), filename, sectionname); +} + +void scriptLocalStorageFactory2_Generic(asIScriptGeneric *gen) +{ + std::string filename = **(std::string**)gen->GetAddressOfArg(0); + *(LocalStorage**)gen->GetAddressOfReturnLocation() = new LocalStorage(gen->GetEngine(), filename, "common"); +} + +void scriptLocalStorageFactory3_Generic(asIScriptGeneric *gen) +{ + *(LocalStorage**)gen->GetAddressOfReturnLocation() = new LocalStorage(gen->GetEngine()); +} + + +void RoR::RegisterLocalStorage(asIScriptEngine *engine) +{ + int r; + + r = engine->RegisterObjectType("LocalStorage", sizeof(LocalStorage), asOBJ_REF | asOBJ_GC); ROR_ASSERT( r >= 0 ); + // Use the generic interface to construct the object since we need the engine pointer, we could also have retrieved the engine pointer from the active context + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_FACTORY, "LocalStorage@ f(const string &in, const string &in)", asFUNCTION(scriptLocalStorageFactory_Generic), asCALL_GENERIC); ROR_ASSERT( r>= 0 ); + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_FACTORY, "LocalStorage@ f(const string &in)", asFUNCTION(scriptLocalStorageFactory2_Generic), asCALL_GENERIC); ROR_ASSERT( r>= 0 ); + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_FACTORY, "LocalStorage@ f()", asFUNCTION(scriptLocalStorageFactory3_Generic), asCALL_GENERIC); ROR_ASSERT( r>= 0 ); + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_ADDREF, "void f()", asMETHOD(LocalStorage,AddRef), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_RELEASE, "void f()", asMETHOD(LocalStorage,Release), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "LocalStorage &opAssign(LocalStorage &in)", asMETHODPR(LocalStorage, operator=, (LocalStorage &), LocalStorage&), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void changeSection(const string &in)", asMETHODPR(LocalStorage,changeSection,(const std::string&), void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "string get(string &in)", asMETHODPR(LocalStorage,get,(std::string&), std::string), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "string getString(string &in)", asMETHODPR(LocalStorage,get,(std::string&), std::string), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const string &in)", asMETHODPR(LocalStorage,set,(std::string&, const std::string&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setString(string &in, const string &in)", asMETHODPR(LocalStorage,set,(std::string&, const std::string&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "float getFloat(string &in)", asMETHODPR(LocalStorage,getFloat,(std::string&), float), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, float)", asMETHODPR(LocalStorage,set,(std::string&, const float),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setFloat(string &in, float)", asMETHODPR(LocalStorage,set,(std::string&, const float),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "vector3 getVector3(string &in)", asMETHODPR(LocalStorage,getVector3,(std::string&), Ogre::Vector3), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const vector3 &in)", asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Vector3&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setVector3(string &in, const vector3 &in)", asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Vector3&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "radian getRadian(string &in)", asMETHODPR(LocalStorage,getRadian,(std::string&), Ogre::Radian), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const radian &in)", asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Radian&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setRadian(string &in, const radian &in)", asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Radian&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "degree getDegree(string &in)", asMETHODPR(LocalStorage,getDegree,(std::string&), Ogre::Degree), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const degree &in)", asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Degree&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setDegree(string &in, const degree &in)", asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Degree&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "quaternion getQuaternion(string &in)", asMETHODPR(LocalStorage,getQuaternion,(std::string&), Ogre::Quaternion), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const quaternion &in)", asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Quaternion&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setQuaternion(string &in, const quaternion &in)", asMETHODPR(LocalStorage,set,(std::string&, const Ogre::Quaternion&),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "bool getBool(string &in)", asMETHODPR(LocalStorage,getBool,(std::string&), bool), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, const bool &in)", asMETHODPR(LocalStorage,set,(std::string&, const bool),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setBool(string &in, const bool &in)", asMETHODPR(LocalStorage,set,(std::string&, const bool),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "int getInt(string &in)", asMETHODPR(LocalStorage,getInt,(std::string&), int), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "int getInteger(string &in)", asMETHODPR(LocalStorage,getInt,(std::string&), int), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void set(string &in, int)", asMETHODPR(LocalStorage,set,(std::string&, const int),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setInt(string &in, int)", asMETHODPR(LocalStorage,set,(std::string&, const int),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void setInteger(string &in, int)", asMETHODPR(LocalStorage,set,(std::string&, const int),void), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "void save()", asMETHOD(LocalStorage,saveDict), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "bool reload()", asMETHOD(LocalStorage,loadDict), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + r = engine->RegisterObjectMethod("LocalStorage", "bool exists(string &in) const", asMETHOD(LocalStorage,exists), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectMethod("LocalStorage", "void delete(string &in)", asMETHOD(LocalStorage,eraseKey), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + + // Register GC behaviours + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_GETREFCOUNT, "int f()", asMETHOD(LocalStorage,GetRefCount), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_SETGCFLAG, "void f()", asMETHOD(LocalStorage,SetGCFlag), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_GETGCFLAG, "bool f()", asMETHOD(LocalStorage,GetGCFlag), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_ENUMREFS, "void f(int&in)", asMETHOD(LocalStorage,EnumReferences), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + r = engine->RegisterObjectBehaviour("LocalStorage", asBEHAVE_RELEASEREFS, "void f(int&in)", asMETHOD(LocalStorage,ReleaseAllReferences), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); + +} diff --git a/source/main/scripting/OgreAngelscript.cpp b/source/main/scripting/bindings/OgreAngelscript.cpp similarity index 98% rename from source/main/scripting/OgreAngelscript.cpp rename to source/main/scripting/bindings/OgreAngelscript.cpp index 50f67c9278..9603d24e65 100644 --- a/source/main/scripting/OgreAngelscript.cpp +++ b/source/main/scripting/bindings/OgreAngelscript.cpp @@ -2,7 +2,7 @@ This source file is part of Rigs of Rods Copyright 2005-2012 Pierre-Michel Ricordel Copyright 2007-2012 Thomas Fischer - Copyright 2013-2020 Petr Ohlidal + Copyright 2013-2022 Petr Ohlidal For more information, see http://www.rigsofrods.org/ diff --git a/source/main/scripting/bindings/ScriptEventsAngelscript.cpp b/source/main/scripting/bindings/ScriptEventsAngelscript.cpp new file mode 100644 index 0000000000..63d796c270 --- /dev/null +++ b/source/main/scripting/bindings/ScriptEventsAngelscript.cpp @@ -0,0 +1,61 @@ +/* + This source file is part of Rigs of Rods + Copyright 2005-2012 Pierre-Michel Ricordel + Copyright 2007-2012 Thomas Fischer + Copyright 2013-2022 Petr Ohlidal + + For more information, see http://www.rigsofrods.org/ + + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + +#include "ScriptEvents.h" +#include "AngelScriptBindings.h" +#include + +using namespace AngelScript; + +void RoR::RegisterScriptEvents(asIScriptEngine *engine) +{ + int result; + + // enum scriptEvents + result = engine->RegisterEnum("scriptEvents"); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_COLLISION_BOX_ENTER", SE_COLLISION_BOX_ENTER); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_COLLISION_BOX_LEAVE", SE_COLLISION_BOX_LEAVE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_ENTER", SE_TRUCK_ENTER); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_EXIT", SE_TRUCK_EXIT); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_ENGINE_DIED", SE_TRUCK_ENGINE_DIED); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_ENGINE_FIRE", SE_TRUCK_ENGINE_FIRE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_TOUCHED_WATER", SE_TRUCK_TOUCHED_WATER); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_BEAM_BROKE", SE_TRUCK_BEAM_BROKE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_LOCKED", SE_TRUCK_LOCKED); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_UNLOCKED", SE_TRUCK_UNLOCKED); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_LIGHT_TOGGLE", SE_TRUCK_LIGHT_TOGGLE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_SKELETON_TOGGLE", SE_TRUCK_SKELETON_TOGGLE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_TIE_TOGGLE", SE_TRUCK_TIE_TOGGLE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_PARKINGBREAK_TOGGLE", SE_TRUCK_PARKINGBREAK_TOGGLE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_RESET", SE_TRUCK_RESET); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_TELEPORT", SE_TRUCK_TELEPORT); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_BEACONS_TOGGLE", SE_TRUCK_BEACONS_TOGGLE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_CPARTICLES_TOGGLE", SE_TRUCK_CPARTICLES_TOGGLE); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_TRUCK_GROUND_CONTACT_CHANGED", SE_TRUCK_GROUND_CONTACT_CHANGED); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_NEW_TRUCK", SE_GENERIC_NEW_TRUCK); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_DELETED_TRUCK", SE_GENERIC_DELETED_TRUCK); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_INPUT_EVENT", SE_GENERIC_INPUT_EVENT); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_MOUSE_BEAM_INTERACTION", SE_GENERIC_MOUSE_BEAM_INTERACTION); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_ANGELSCRIPT_MANIPULATIONS", SE_ANGELSCRIPT_MANIPULATIONS); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_GENERIC_MESSAGEBOX_CLICK", SE_GENERIC_MESSAGEBOX_CLICK); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("scriptEvents", "SE_ALL_EVENTS", SE_ALL_EVENTS); ROR_ASSERT(result>=0); + +} diff --git a/source/main/scripting/bindings/VehicleAiAngelscript.cpp b/source/main/scripting/bindings/VehicleAiAngelscript.cpp new file mode 100644 index 0000000000..2f70b9496f --- /dev/null +++ b/source/main/scripting/bindings/VehicleAiAngelscript.cpp @@ -0,0 +1,52 @@ +/* + This source file is part of Rigs of Rods + Copyright 2005-2012 Pierre-Michel Ricordel + Copyright 2007-2012 Thomas Fischer + Copyright 2013-2022 Petr Ohlidal + + For more information, see http://www.rigsofrods.org/ + + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + +#include "VehicleAI.h" +#include "AngelScriptBindings.h" +#include + +using namespace AngelScript; + +void RoR::RegisterVehicleAi(asIScriptEngine *engine) +{ + int result; + + // enum aiEvents + result = engine->RegisterEnum("aiEvents"); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("aiEvents", "AI_LIGHTSTOGGLE", AI_LIGHTSTOGGLE); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("aiEvents", "AI_WAIT_SECONDS", AI_WAIT_SECONDS); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("aiEvents", "AI_BEACONSTOGGLE", AI_BEACONSTOGGLE); ROR_ASSERT(result >= 0); + + // enum aiEvents + result = engine->RegisterEnum("AiValues"); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("AiValues", "AI_SPEED", AI_SPEED); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("AiValues", "AI_POWER", AI_POWER); ROR_ASSERT(result >= 0); + + result = engine->RegisterObjectType("VehicleAIClass", sizeof(VehicleAI), asOBJ_REF); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("VehicleAIClass", "void addWaypoint(string &in, vector3 &in)", asMETHOD(VehicleAI, AddWaypoint), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("VehicleAIClass", "void addWaypoints(dictionary &in)", asMETHOD(VehicleAI, AddWaypoint), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("VehicleAIClass", "void setActive(bool)", asMETHOD(VehicleAI, SetActive), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("VehicleAIClass", "void addEvent(string &in,int &in)", asMETHOD(VehicleAI, AddEvent), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("VehicleAIClass", "void setValueAtWaypoint(string &in, int &in, float &in)", asMETHOD(VehicleAI, SetValueAtWaypoint), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectBehaviour("VehicleAIClass", asBEHAVE_ADDREF, "void f()", asMETHOD(VehicleAI, addRef), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectBehaviour("VehicleAIClass", asBEHAVE_RELEASE, "void f()", asMETHOD(VehicleAI, release), asCALL_THISCALL); ROR_ASSERT(result >= 0); + +} From 0687084bf180da0f0ebe8f2b3bae8e8e1336811d Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Thu, 11 Aug 2022 22:36:35 +0200 Subject: [PATCH 02/12] GameScript - grouped functions in docs and code. --- doc/angelscript/Script2Game/GameScriptClass.h | 540 ++++++++++-------- resources/scripts/races.as | 4 +- source/main/scripting/GameScript.cpp | 11 +- source/main/scripting/GameScript.h | 374 +++++++----- .../bindings/GameScriptAngelscript.cpp | 151 ++--- 5 files changed, 604 insertions(+), 476 deletions(-) diff --git a/doc/angelscript/Script2Game/GameScriptClass.h b/doc/angelscript/Script2Game/GameScriptClass.h index 7168395cd8..c00e41298a 100644 --- a/doc/angelscript/Script2Game/GameScriptClass.h +++ b/doc/angelscript/Script2Game/GameScriptClass.h @@ -35,6 +35,11 @@ namespace Script2Game { class GameScriptClass { public: + // PLEASE maintain the same order as in GameScript.h and GameScriptAngelscript.cpp! + + /// @name General + /// @{ + /** * writes a message to the scripting logbook (AngelScript.log) * @param message string to log @@ -46,13 +51,183 @@ class GameScriptClass * @return time in seconds */ double getTime(); + + /** + * Generates a random number between from and to + * @param from The generated number will be higher than this number + * @param to The generated number will be lower than this number + * @return The random number between from and to + */ + float rangeRandom(float from, float to); /** - * sets the character position - * @param vec X, Y and Z coordinate of the position on the terrain + * Sends or request information from the master server */ - void setPersonPosition(vector3 vec); + int useOnlineAPI(const string apiquery, const dictionary dict, string result); + + /** + * Gets the Curent frames per second (FPS) + * @return The Current FPS + */ + void getFPS(); + + /** + * Gets the average frames per second (FPS) + * @return The average FPS + */ + void getAvgFPS(); + + /** + * Back to menu + */ + void backToMenu(); + + /** + * Quits the game + */ + void quitGame(); + + /// @} + /// @name GUI + /// @{ + + /** + * shows a message to the user + * @deprecated Use the game.message function instead. + * @param message The message to be shown + * @param time How long the message should be shown (in seconds) + * @param charHeight The font size to be used (use -1 for the default size) + */ + void flashMessage(string message, float time, float charHeight); + + /** + * shows a message to the user + * @param txt The message to be shown + * @param icon The filename of the icon to be shown in front of the message. + * @param timeMilliseconds How long the message should be shown (in milliseconds) + * @param forceVisible Set this to true if you want the message to be forced on the user's screen (~it will show, even when the GUI is hidden). + */ + void message(string txt, string icon, float timeMilliseconds, bool forceVisible); + + /** + * OBSOLETE - returns 0. + * @deprecated + * @return always 0 + */ + int getChatFontSize(); + + /** + * OBSOLETE - does nothing. + * @deprecated + * @param size font size in pixels + */ + void setChatFontSize(int size); + + /** + * Shows a message box + * + * @param mTitle The box title + * @param mText The box content text + * @param button1 Set to true to show the first button + * @param mButton1 The text in the first button + * @param AllowClose If set to true the user can close the box by pressing the X in the top-right + * @param button2 Set to true to show the second button + * @param mButton2 The text in the second button + * + * @see scriptEvents + */ + void showMessageBox(string mTitle, stringmText, bool button1, stringmButton1, bool AllowClose, bool button2, stringmButton2); + + /** + * This shows a vehicle chooser + * @param type A string specifying the type of the chooser. + * You can choose out of the following: + * - "vehicle" + * - "truck" + * - "car" + * - "boat" + * - "airplane" + * - "heli" + * - "trailer" + * - "load" + * - "extension" + * @param instance the unique name of the object with the event box in which the truck/load should be spawned + * @param box the name of the box in which the truck will be spawned + */ + void showChooser(string type, string instance, string box); + + /** + * set direction arrow + * @param text text to be displayed. "" to hide the text + * @param position The position to which the arrow should point. + * @see hideDirectionArrow + */ + void updateDirectionArrow(string text, vector3 position); + + /** + * Hides the direction arrow + * @see UpdateDirectionArrow + */ + void hideDirectionArrow(); + + /// @} + + /// @name Script management + /// @{ + + /** + * registers for a new event to be received by the scripting system + * @param eventValue \see enum scriptEvents + */ + void registerForEvent(int eventValue); + + /** + * unregisters from receiving event. + * @param eventValue \see enum scriptEvents + */ + void unRegisterEvent(int eventValue); + + /** + * Adds a global function to the script. + * @param func the function to be added, e.g.: "void func() { log('works'); }" + */ + int addScriptFunction(const string func); + + /** + * Checks if a global function exists + * @param func the declaration of the function that should be checked for existance, e.g.: "void func()" + */ + int scriptFunctionExists(const string func); + + /** + * Removes a global function from the script. + * @param func the declaration of the function that should be removed, e.g.: "void func()" + */ + int deleteScriptFunction(const string func); + + /** + * Adds a global variable to the script. + * @param var the declaration of the variable that should be added, e.g.: "int missionState;" + */ + int addScriptVariable(const string var); + + /** + * Removes a global variable from the script. + * @param var the declaration of the variable that should be removed, e.g.: "int missionState;" + */ + int deleteScriptVariable(const string var); + + /** + * Clears the event cache + */ + void clearEventCache(); + + /// @} + + /// @name Terrain + /// @{ + /** * Loads a terrain * @warning @@ -62,13 +237,25 @@ class GameScriptClass * @param terrain The name of the terrain */ void loadTerrain(string terrain); - + /** - * moves the person relative - * @param relative_movement X, Y and Z coordinate of the translation + * Gets the currently loaded terrain name + * @param result This string will contain the name of the terrain after you called this function + * @return 1 on success, 0 if terrain not loaded */ - void movePerson(vector3 relative_movement); - + int getLoadedTerrain(string result); + + /** + * Gets the currently loaded terrain instance + */ + TerrainClass@ getTerrain(); + + /** + * Checks if Caleum is enabled. + * @return true if Caleum is available + */ + bool getCaelumAvailable(); + /** * gets the time of the day in seconds * @return string with HH::MM::SS format @@ -79,8 +266,20 @@ class GameScriptClass * sets the time of the day in seconds * @param value day time in seconds */ - void setCaelumTime(float value); + void setCaelumTime(float value); + + /** + * returns the currently set upo gravity + * @return float number describing gravity terrain wide. + */ + float getGravity(); + /** + * sets the gravity terrain wide. This is an expensive call, since the masses of all trucks are recalculated. + * @param value new gravity terrain wide (default is -9.81) + */ + void setGravity(float value); + /** * returns the current base water level (without waves) * @return water height in meters @@ -98,7 +297,65 @@ class GameScriptClass * sets the base water height * @param value base height in meters */ - void setWaterHeight(float value); + void setWaterHeight(float value); + + /** + * This spawns an object + * @param objectName The name of the object (~the name of the odef file, but without the .odef extension) + * @param instanceName A unique name for this object (you can choose one, but make sure that you don't use the same name twice) + * @param pos The position where the object should be spawned + * @param rot The rotation in which the object should be spawned + * @param eventhandler A name of a function that should be called when an event happens (events, as defined in the object definition file). Enter empty string to ignore events. + * @param uniquifyMaterials Set this to true if you need to uniquify the materials + */ + void spawnObject(const string objectName, const string instanceName, vector3 pos, vector3 rot, const string eventhandler, bool uniquifyMaterials); + + /** + * This moves an object to a new position + * @note This doesn't update the collision box! + * @param instanceName The unique name that you chose when spawning this object + * @param pos The position where the object should be moved to + */ + void moveObjectVisuals(const string instanceName, const vector3 pos); + + /** + * This destroys an object + * @param instanceName The unique name that you chose when spawning this object + * @see spawnObject + */ + void destroyObject(const string instanceName); + + /// @} + + /// @name Character + /// @{ + + /** + * Returns the current position of the person + * @return A vector containing the X, Y and Z coordinate of the person or an empty vector if the user is in a truck + */ + vector3 getPersonPosition(); + + /** + * sets the character position + * @param vec X, Y and Z coordinate of the position on the terrain + */ + void setPersonPosition(vector3 vec); + + /** + * moves the person relative + * @param relative_movement X, Y and Z coordinate of the translation + */ + void movePerson(vector3 relative_movement); + + void setPersonRotation(radian &in); + + radian getPersonRotation(); + + /// @} + + /// @name Actors + /// @{ /** * returns the current selected truck, null if in person mode @@ -128,71 +385,42 @@ class GameScriptClass * @return integer truck number */ int getCurrentTruckNumber(); - - /** - * returns the currently set upo gravity - * @return float number describing gravity terrain wide. - */ - float getGravity(); - - /** - * sets the gravity terrain wide. This is an expensive call, since the masses of all trucks are recalculated. - * @param value new gravity terrain wide (default is -9.81) - */ - void setGravity(float value); - + /** - * registers for a new event to be received by the scripting system - * @param eventValue \see enum scriptEvents + * Spawns a truck by filename + * + * @param truckName The filename of the truck + * @param pos The position where the truck should be spawned + * @param rot The rotation in which the truck should be spawned + * @return reference to Beam object */ - void registerForEvent(int eventValue); + BeamClass @spawnTruck(stringtruckName, vector3 pos, vector3 rot); - /** - * unregisters from receiving event. - * @param eventValue \see enum scriptEvents - */ - void unRegisterEvent(int eventValue); - /** - * shows a message to the user - * @deprecated Use the game.message function instead. - * @param message The message to be shown - * @param time How long the message should be shown (in seconds) - * @param charHeight The font size to be used (use -1 for the default size) + * This method repairs the vehicle in the box */ - void flashMessage(string message, float time, float charHeight); + void repairVehicle(string instance, string box, bool keepPosition); /** - * shows a message to the user - * @param txt The message to be shown - * @param icon The filename of the icon to be shown in front of the message. - * @param timeMilliseconds How long the message should be shown (in milliseconds) - * @param forceVisible Set this to true if you want the message to be forced on the user's screen (~it will show, even when the GUI is hidden). + * This method removes the vehicle in the box */ - void message(string txt, string icon, float timeMilliseconds, bool forceVisible); + void removeVehicle(string instance, string box); /** - * set direction arrow - * @param text text to be displayed. "" to hide the text - * @param position The position to which the arrow should point. - * @see hideDirectionArrow + * Number of trucks with flag */ - void UpdateDirectionArrow(string text, vector3 position); - - + int getNumTrucksByFlag(int flag); + /** - * returns the size of the font used by the chat box - * @deprecated - * @return pixel size of the chat text + * Gives the currently used truck a boost in RPM. + * @param factor This factor determines by how much that the RPM of the truck will be increased ( rpm += 2000.0f * factor ). */ - int getChatFontSize(); + void boostCurrentTruck(float factor); + + ///@} - /** - * changes the font size of the chat box - * @deprecated - * @param size font size in pixels - */ - void setChatFontSize(int size); + /// @name Camera + /// @{ /** * Sets the camera's position. @@ -246,71 +474,10 @@ class GameScriptClass */ void cameraLookAt(vector3 targetPoint); - /** - * This shows a vehicle chooser - * @param type A string specifying the type of the chooser. - * You can choose out of the following: - * - "vehicle" - * - "truck" - * - "car" - * - "boat" - * - "airplane" - * - "heli" - * - "trailer" - * - "load" - * - "extension" - * @param instance the unique name of the object with the event box in which the truck/load should be spawned - * @param box the name of the box in which the truck will be spawned - */ - void showChooser(string type, string instance, string box); - - /** - * This method repairs the vehicle in the box - */ - void repairVehicle(string instance, string box, bool keepPosition); - - /** - * This method removes the vehicle in the box - */ - void removeVehicle(string instance, string box); - - /** - * This spawns an object - * @param objectName The name of the object (~the name of the odef file, but without the .odef extension) - * @param instanceName A unique name for this object (you can choose one, but make sure that you don't use the same name twice) - * @param pos The position where the object should be spawned - * @param rot The rotation in which the object should be spawned - * @param eventhandler A name of a function that should be called when an event happens (events, as defined in the object definition file). Enter empty string to ignore events. - * @param uniquifyMaterials Set this to true if you need to uniquify the materials - */ - void spawnObject(const string objectName, const string instanceName, vector3 pos, vector3 rot, const string eventhandler, bool uniquifyMaterials); - - /** - * This moves an object to a new position - * @note This doesn't update the collision box! - * @param instanceName The unique name that you chose when spawning this object - * @param pos The position where the object should be moved to - */ - void moveObjectVisuals(const string instanceName, const vector3 pos); - - /** - * This destroys an object - * @param instanceName The unique name that you chose when spawning this object - * @see spawnObject - */ - void destroyObject(const string instanceName); - + ///@} - /** - * Number of trucks with flag - */ - int getNumTrucksByFlag(int flag); - - /** - * Checks if Caleum is enabled. - * @return true if Caleum is available - */ - bool getCaelumAvailable(); + /// @name Race system + /// @{ /** * Stops the timer @@ -325,19 +492,10 @@ class GameScriptClass */ void startTimer(); - /** - * Gets a setting - * @param str The name of the setting - * @return the value of the setting - */ - string getSetting(string str); - - /** - * Hides the direction arrow - * @see UpdateDirectionArrow - */ - void hideDirectionArrow(); + ///@} + /// @name Material helpers + /// @{ int setMaterialAmbient(const string materialName, float red, float green, float blue); int setMaterialDiffuse(const string materialName, float red, float green, float blue, float alpha); @@ -349,113 +507,7 @@ class GameScriptClass int setMaterialTextureScroll(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float sx, float sy); int setMaterialTextureScale(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float u, float v); - /** - * Generates a random number between from and to - * @param from The generated number will be higher than this number - * @param to The generated number will be lower than this number - * @return The random number between from and to - */ - float rangeRandom(float from, float to); - - /** - * Sends or request information from the master server - */ - int useOnlineAPI(const string apiquery, const dictionary dict, string result); - - /** - * Gets the currently loaded terrain - * @param result This string will contain the name of the terrain after you called this function - * @return 0 on success - */ - int getLoadedTerrain(string result); - - /** - * Returns the current position of the person - * @return A vector containing the X, Y and Z coordinate of the person or an empty vector if the user is in a truck - */ - vector3 getPersonPosition(); - - /** - * Clears the event cache - */ - void clearEventCache(); - - /** - * Gives the currently used truck a boost in RPM. - * @param factor This factor determines by how much that the RPM of the truck will be increased ( rpm += 2000.0f * factor ). - */ - void boostCurrentTruck(float factor); - - /** - * Adds a global function to the script. - * @param func the function to be added, e.g.: "void func() { log('works'); }" - */ - int addScriptFunction(const string func); - - /** - * Checks if a global function exists - * @param func the declaration of the function that should be checked for existance, e.g.: "void func()" - */ - int scriptFunctionExists(const string func); - - /** - * Removes a global function from the script. - * @param func the declaration of the function that should be removed, e.g.: "void func()" - */ - int deleteScriptFunction(const string func); - - /** - * Adds a global variable to the script. - * @param var the declaration of the variable that should be added, e.g.: "int missionState;" - */ - int addScriptVariable(const string var); - - /** - * Removes a global variable from the script. - * @param var the declaration of the variable that should be removed, e.g.: "int missionState;" - */ - int deleteScriptVariable(const string var); - - /** - * Shows a message box - * - * @param mTitle The box title - * @param mText The box content text - * @param button1 Set to true to show the first button - * @param mButton1 The text in the first button - * @param AllowClose If set to true the user can close the box by pressing the X in the top-right - * @param button2 Set to true to show the second button - * @param mButton2 The text in the second button - * - * @see scriptEvents - */ - void showMessageBox(string mTitle, stringmText, bool button1, stringmButton1, bool AllowClose, bool button2, stringmButton2); - - /** - * Spawns a truck by filename - * - * @param truckName The filename of the truck - * @param pos The position where the truck should be spawned - * @param rot The rotation in which the truck should be spawned - * @return reference to Beam object - */ - BeamClass @spawnTruck(stringtruckName, vector3 pos, vector3 rot); - - /** - * Gets the Curent frames per second (FPS) - * @return The Current FPS - */ - void getFPS(); - - /** - * Back to menu - */ - void backToMenu(); - - /** - * Quits the game - */ - void quitGame(); + ///@} }; /// @} //addtogroup Script2Game diff --git a/resources/scripts/races.as b/resources/scripts/races.as index 2d302c4639..96c9edbb32 100644 --- a/resources/scripts/races.as +++ b/resources/scripts/races.as @@ -1051,12 +1051,12 @@ class racesManager { } if( this.raceList[this.currentRace].laps == this.LAPS_NoLaps ) - game.UpdateDirectionArrow(this.raceList[this.currentRace].raceName+" checkpoint "+position+" / "+(this.raceList[this.currentRace].checkPointsCount-1), vector3(v[0], v[1], v[2])); + game.updateDirectionArrow(this.raceList[this.currentRace].raceName+" checkpoint "+position+" / "+(this.raceList[this.currentRace].checkPointsCount-1), vector3(v[0], v[1], v[2])); else { if( position == 0 ) position = this.raceList[this.currentRace].checkPointsCount; - game.UpdateDirectionArrow(this.raceList[this.currentRace].raceName+" checkpoint "+position+" / "+(this.raceList[this.currentRace].checkPointsCount), vector3(v[0], v[1], v[2])); + game.updateDirectionArrow(this.raceList[this.currentRace].raceName+" checkpoint "+position+" / "+(this.raceList[this.currentRace].checkPointsCount), vector3(v[0], v[1], v[2])); } } diff --git a/source/main/scripting/GameScript.cpp b/source/main/scripting/GameScript.cpp index 0f342a4c2d..edf7704563 100644 --- a/source/main/scripting/GameScript.cpp +++ b/source/main/scripting/GameScript.cpp @@ -92,7 +92,7 @@ void GameScript::activateAllVehicles() App::GetGameContext()->GetActorManager()->WakeUpAllActors(); } -void GameScript::SetTrucksForcedAwake(bool forceActive) +void GameScript::setTrucksForcedAwake(bool forceActive) { App::GetGameContext()->GetActorManager()->SetTrucksForcedAwake(forceActive); } @@ -272,7 +272,7 @@ int GameScript::getNumTrucksByFlag(int flag) return result; } -int GameScript::GetPlayerActorId() +int GameScript::getCurrentTruckNumber() { Actor* actor = App::GetGameContext()->GetPlayerActor(); return (actor != nullptr) ? actor->ar_instance_id : -1; @@ -312,7 +312,7 @@ void GameScript::message(String& txt, String& icon) RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_SCRIPT, Console::CONSOLE_SYSTEM_NOTICE, txt, icon); } -void GameScript::UpdateDirectionArrow(String& text, Vector3& vec) +void GameScript::updateDirectionArrow(String& text, Vector3& vec) { App::GetGameContext()->GetRaceSystem().UpdateDirectionArrow(const_cast(text.c_str()), Vector3(vec.x, vec.y, vec.z)); } @@ -386,7 +386,7 @@ void GameScript::destroyObject(const String& instanceName) } } -void GameScript::MoveTerrainObjectVisuals(const String& instanceName, const Vector3& pos) +void GameScript::moveObjectVisuals(const String& instanceName, const Vector3& pos) { if (!this->HaveSimTerrain(__FUNCTION__)) return; @@ -626,6 +626,9 @@ int GameScript::getLoadedTerrain(String& result) void GameScript::clearEventCache() { + if (!this->HaveSimTerrain(__FUNCTION__)) + return; + if (App::GetSimTerrain()->GetCollisions() == nullptr) { this->logFormat("Cannot execute '%s', collisions not ready", __FUNCTION__); diff --git a/source/main/scripting/GameScript.h b/source/main/scripting/GameScript.h index 141bae344c..5b69aaf6a9 100644 --- a/source/main/scripting/GameScript.h +++ b/source/main/scripting/GameScript.h @@ -41,6 +41,10 @@ namespace RoR { class GameScript : public ZeroedMemoryAllocator { public: + // PLEASE maintain the same order as in GameScriptAngelscript.cpp! + + /// @name General + /// @{ /** * writes a message to the games log (RoR.log) @@ -49,56 +53,130 @@ class GameScript : public ZeroedMemoryAllocator void log(const Ogre::String& msg); /** - * writes a message to the games log (RoR.log) - * @param msg string to log + * returns the time in seconds since the game was started + * @return time in seconds */ - void logFormat(const char* fmt, ...); + float getTime(); + + void backToMenu(); + void quitGame(); + float getFPS(); + float getAvgFPS(); + float rangeRandom(float from, float to); + + int useOnlineAPI(const Ogre::String& apiquery, const AngelScript::CScriptDictionary& dict, Ogre::String& result); + + /// @} + + /// @name GUI + /// @{ /** - * moves the person relative - * @param vec translation vector + * DEPRECATED: use message() + * shows a message to the user */ - void activateAllVehicles(); + void flashMessage(Ogre::String& txt, float time, float charHeight); /** - * moves the person relative - * @param vec translation vector + * shows a message to the user over the console system */ - void SetTrucksForcedAwake(bool forceActive); + void message(Ogre::String& txt, Ogre::String& icon); /** - * returns the time in seconds since the game was started - * @return time in seconds + * OBSOLETE, returns 0; */ - float getTime(); + int getChatFontSize(); - //anglescript test - void boostCurrentTruck(float factor); + /** + * OBSOLETE, does nothing. + */ + void setChatFontSize(int size); + + void showMessageBox(Ogre::String& title, Ogre::String& text, bool use_btn1, Ogre::String& btn1_text, bool allow_close, bool use_btn2, Ogre::String& btn2_text); + + void showChooser(const Ogre::String& type, const Ogre::String& instance, const Ogre::String& box); /** - * sets the character position - * @param vec position vector on the terrain + * set direction arrow + * @param text text to be displayed. "" to hide the text */ - void setPersonPosition(const Ogre::Vector3& vec); + void updateDirectionArrow(Ogre::String& text, Ogre::Vector3& vec); + + void hideDirectionArrow(); + + /// @} + + /// @name Script management + /// @{ - void loadTerrain(const Ogre::String& terrain); /** - * moves the person relative - * @param vec translation vector + * registers for a new event to be received by the scripting system + * @param eventValue \see enum scriptEvents */ - void movePerson(const Ogre::Vector3& vec); + void registerForEvent(int eventValue); /** - * sets the character rotation - * @param rot the character rotation + * unregisters from receiving event. + * @param eventValue \see enum scriptEvents */ - void setPersonRotation(const Ogre::Radian& rot); + void unRegisterEvent(int eventValue); /** - * gets the character rotation - * @return character rotation + * Adds a global function to the script + * (Wrapper for ScriptEngine::addFunction) + * @param arg A declaration for the function. + */ + int addScriptFunction(const Ogre::String& arg); + + /** + * Checks if a global function exists in the script + * (Wrapper for ScriptEngine::functionExists) + * @param arg A declaration for the function. + */ + int scriptFunctionExists(const Ogre::String& arg); + + /** + * Deletes a global function from the script + * (Wrapper for ScriptEngine::deleteFunction) + * @param arg A declaration for the function. + */ + int deleteScriptFunction(const Ogre::String& arg); + + /** + * Adds a global variable to the script + * (Wrapper for ScriptEngine::addVariable) + * @param arg A declaration for the variable. + */ + int addScriptVariable(const Ogre::String& arg); + + /** + * Deletes a global variable from the script + * (Wrapper for ScriptEngine::deleteVariable) + * @param arg A declaration for the variable. + */ + int deleteScriptVariable(const Ogre::String& arg); + + void clearEventCache(); + + /** + * Multiplayer only: sends AngelScript snippet to all players. + */ + int sendGameCmd(const Ogre::String& message); + + /// @} + + /// @name Terrain + /// @{ + + void loadTerrain(const Ogre::String& terrain); + + /** + * gets the name of current terrain. + * @return 1 on success, 0 if terrain not loaded */ - Ogre::Radian getPersonRotation(); + int getLoadedTerrain(Ogre::String& result); + + bool getCaelumAvailable(); /** * gets the time of the day in seconds @@ -112,14 +190,29 @@ class GameScript : public ZeroedMemoryAllocator */ void setCaelumTime(float value); + /** + * returns the currently set upo gravity + * @return float number describing gravity terrain wide. + */ + float getGravity(); + + /** + * sets the gravity terrain wide. This is an expensive call, since the masses of all trucks are recalculated. + * @param value new gravity terrain wide (default is -9.81) + */ + void setGravity(float value); + + /** + * Gets terrain height at given coordinates. + */ + float getGroundHeight(Ogre::Vector3& v); + /** * returns the current base water level (without waves) * @return water height in meters */ float getWaterHeight(); - float getGroundHeight(Ogre::Vector3& v); - /** * sets the base water height * @param value base height in meters @@ -127,81 +220,121 @@ class GameScript : public ZeroedMemoryAllocator void setWaterHeight(float value); /** - * returns the current selected truck, 0 if in person mode - * @return reference to Beam object that is currently in use - */ - Actor* getCurrentTruck(); + * This spawns a static terrain object (.ODEF file) + * @param objectName The name of the object (~the name of the odef file, but without the .odef extension) + * @param instanceName A unique name for this object (you can choose one, but make sure that you don't use the same name twice) + * @param pos The position where the object should be spawned + * @param rot The rotation in which the object should be spawned + * @param eventhandler A name of a function that should be called when an event happens (events, as defined in the object definition file) + * @param uniquifyMaterials Set this to true if you need to uniquify the materials + */ + void spawnObject(const Ogre::String& objectName, const Ogre::String& instanceName, const Ogre::Vector3& pos, const Ogre::Vector3& rot, const Ogre::String& eventhandler, bool uniquifyMaterials); /** - * returns a truck by index, get max index by calling getNumTrucks - * @return reference to Beam object that the selected slot - */ - Actor* getTruckByNum(int num); + * This moves an object to a new position + * @note This doesn't update the collision box! + * @param instanceName The unique name that you chose when spawning this object + * @param pos The position where the object should be moved to + */ + void moveObjectVisuals(const Ogre::String& instanceName, const Ogre::Vector3& pos); /** - * returns the current amount of loaded trucks - * @return integer value representing the amount of loaded trucks - */ - int getNumTrucks(); + * This destroys an object + * @param instanceName The unique name that you chose when spawning this object + * @see spawnObject + */ + void destroyObject(const Ogre::String& instanceName); + + /// @} + /// @name Character + /// @{ + + Ogre::Vector3 getPersonPosition(); + /** - * returns the current truck number. >=0 when using a truck, -1 when in person mode - * @return integer truck number + * sets the character position + * @param vec position vector on the terrain */ - int GetPlayerActorId(); + void setPersonPosition(const Ogre::Vector3& vec); /** - * returns the currently set upo gravity - * @return float number describing gravity terrain wide. + * moves the person relative + * @param vec translation vector */ - float getGravity(); + void movePerson(const Ogre::Vector3& vec); /** - * sets the gravity terrain wide. This is an expensive call, since the masses of all trucks are recalculated. - * @param value new gravity terrain wide (default is -9.81) + * sets the character rotation + * @param rot the character rotation */ - void setGravity(float value); + void setPersonRotation(const Ogre::Radian& rot); /** - * registers for a new event to be received by the scripting system - * @param eventValue \see enum scriptEvents + * gets the character rotation + * @return character rotation */ - void registerForEvent(int eventValue); + Ogre::Radian getPersonRotation(); + + /// @} + + /// @name Actors + /// @{ /** - * unregisters from receiving event. - * @param eventValue \see enum scriptEvents + * moves the person relative + * @param vec translation vector */ - void unRegisterEvent(int eventValue); + void activateAllVehicles(); /** - * DEPRECATED: use message - * shows a message to the user + * moves the person relative + * @param vec translation vector */ - void flashMessage(Ogre::String& txt, float time, float charHeight); + void setTrucksForcedAwake(bool forceActive); + + //anglescript test + void boostCurrentTruck(float factor); /** - * shows a message to the user over the console system + * returns the current selected truck, 0 if in person mode + * @return reference to Beam object that is currently in use */ - void message(Ogre::String& txt, Ogre::String& icon); + Actor* getCurrentTruck(); /** - * set direction arrow - * @param text text to be displayed. "" to hide the text + * returns a truck by index, get max index by calling getNumTrucks + * @return reference to Beam object that the selected slot */ - void UpdateDirectionArrow(Ogre::String& text, Ogre::Vector3& vec); + Actor* getTruckByNum(int num); /** - * returns the size of the font used by the chat box - * @return pixel size of the chat text + * returns the current amount of loaded trucks + * @return integer value representing the amount of loaded trucks */ - int getChatFontSize(); + int getNumTrucks(); /** - * changes the font size of the chat box - * @param size font size in pixels + * returns the current truck number. >=0 when using a truck, -1 when in person mode + * @return integer truck number */ - void setChatFontSize(int size); + int getCurrentTruckNumber(); + + Actor* spawnTruck(Ogre::String& truckName, Ogre::Vector3& pos, Ogre::Vector3& rot); + + void repairVehicle(const Ogre::String& instance, const Ogre::String& box, bool keepPosition); + + void removeVehicle(const Ogre::String& instance, const Ogre::String& box); + + int getNumTrucksByFlag(int flag); + + VehicleAI* getCurrentTruckAI(); + VehicleAI* getTruckAIByNum(int num); + + ///@} + + /// @name Camera + /// @{ /** * Sets the camera's position. @@ -267,78 +400,21 @@ class GameScript : public ZeroedMemoryAllocator */ void cameraLookAt(const Ogre::Vector3& targetPoint); - /** - * Adds a global function to the script - * (Wrapper for ScriptEngine::addFunction) - * @param arg A declaration for the function. - */ - int addScriptFunction(const Ogre::String& arg); - - /** - * Checks if a global function exists in the script - * (Wrapper for ScriptEngine::functionExists) - * @param arg A declaration for the function. - */ - int scriptFunctionExists(const Ogre::String& arg); - - /** - * Deletes a global function from the script - * (Wrapper for ScriptEngine::deleteFunction) - * @param arg A declaration for the function. - */ - int deleteScriptFunction(const Ogre::String& arg); - - /** - * Adds a global variable to the script - * (Wrapper for ScriptEngine::addVariable) - * @param arg A declaration for the variable. - */ - int addScriptVariable(const Ogre::String& arg); - - /** - * Deletes a global variable from the script - * (Wrapper for ScriptEngine::deleteVariable) - * @param arg A declaration for the variable. - */ - int deleteScriptVariable(const Ogre::String& arg); - - /** - * This spawns an object - * @param objectName The name of the object (~the name of the odef file, but without the .odef extension) - * @param instanceName A unique name for this object (you can choose one, but make sure that you don't use the same name twice) - * @param pos The position where the object should be spawned - * @param rot The rotation in which the object should be spawned - * @param eventhandler A name of a function that should be called when an event happens (events, as defined in the object definition file) - * @param uniquifyMaterials Set this to true if you need to uniquify the materials - */ - void spawnObject(const Ogre::String& objectName, const Ogre::String& instanceName, const Ogre::Vector3& pos, const Ogre::Vector3& rot, const Ogre::String& eventhandler, bool uniquifyMaterials); - /** - * This destroys an object - * @param instanceName The unique name that you chose when spawning this object - * @see spawnObject - */ - void destroyObject(const Ogre::String& instanceName); - /** - * This moves an object to a new position - * @note This doesn't update the collision box! - * @param instanceName The unique name that you chose when spawning this object - * @param pos The position where the object should be moved to - */ - void MoveTerrainObjectVisuals(const Ogre::String& instanceName, const Ogre::Vector3& pos); + ///@} - // new things, not documented yet - void showChooser(const Ogre::String& type, const Ogre::String& instance, const Ogre::String& box); - void repairVehicle(const Ogre::String& instance, const Ogre::String& box, bool keepPosition); - void removeVehicle(const Ogre::String& instance, const Ogre::String& box); + /// @name Race system + /// @{ - int getNumTrucksByFlag(int flag); - bool getCaelumAvailable(); void stopTimer(); void startTimer(int id); void setTimeDiff(float diff); void setBestLapTime(float time); - Ogre::String getSetting(const Ogre::String& str); - void hideDirectionArrow(); + + ///@} + + /// @name Material helpers + /// @{ + int setMaterialAmbient(const Ogre::String& materialName, float red, float green, float blue); int setMaterialDiffuse(const Ogre::String& materialName, float red, float green, float blue, float alpha); int setMaterialSpecular(const Ogre::String& materialName, float red, float green, float blue, float alpha); @@ -349,31 +425,19 @@ class GameScript : public ZeroedMemoryAllocator int setMaterialTextureScroll(const Ogre::String& materialName, int techniqueNum, int passNum, int textureUnitNum, float sx, float sy); int setMaterialTextureScale(const Ogre::String& materialName, int techniqueNum, int passNum, int textureUnitNum, float u, float v); - float rangeRandom(float from, float to); - int useOnlineAPI(const Ogre::String& apiquery, const AngelScript::CScriptDictionary& dict, Ogre::String& result); - - int getLoadedTerrain(Ogre::String& result); - Ogre::Vector3 getPersonPosition(); - - void clearEventCache(); - int sendGameCmd(const Ogre::String& message); - - VehicleAI* getCurrentTruckAI(); - VehicleAI* getTruckAIByNum(int num); - - Actor* spawnTruck(Ogre::String& truckName, Ogre::Vector3& pos, Ogre::Vector3& rot); - - void showMessageBox(Ogre::String& title, Ogre::String& text, bool use_btn1, Ogre::String& btn1_text, bool allow_close, bool use_btn2, Ogre::String& btn2_text); - void backToMenu(); - void quitGame(); - float getFPS(); - float getAvgFPS(); + ///@} private: bool HaveSimTerrain(const char* func_name); //!< Helper; Check if SimController instance exists, log warning if not. bool HavePlayerAvatar(const char* func_name); //!< Helper; Check if local Character instance exists, log warning if not. bool HaveMainCamera(const char* func_name); //!< Helper; Check if main camera exists, log warning if not. + + /** + * writes a message to the games log (RoR.log) + * @param msg string to log + */ + void logFormat(const char* fmt, ...); }; /// @} //addtogroup Scripting diff --git a/source/main/scripting/bindings/GameScriptAngelscript.cpp b/source/main/scripting/bindings/GameScriptAngelscript.cpp index 3b59dbeb5b..c4d13fe471 100644 --- a/source/main/scripting/bindings/GameScriptAngelscript.cpp +++ b/source/main/scripting/bindings/GameScriptAngelscript.cpp @@ -30,40 +30,97 @@ void RoR::RegisterGameScript(asIScriptEngine *engine) int result; // class GameScript - result = engine->RegisterObjectType("GameScriptClass", sizeof(GameScript), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS); ROR_ASSERT(result>=0); + result = engine->RegisterObjectType("GameScriptClass", sizeof(GameScript), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS); ROR_ASSERT(result >= 0); + + // PLEASE maintain the same order as in GameScript.h! + + // > General result = engine->RegisterObjectMethod("GameScriptClass", "void log(const string &in)", asMETHOD(GameScript,log), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("GameScriptClass", "float getTime()", asMETHOD(GameScript,getTime), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void backToMenu()", asMETHOD(GameScript, backToMenu), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void quitGame()", asMETHOD(GameScript, quitGame), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getFPS()", asMETHOD(GameScript, getFPS), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getAvgFPS()", asMETHOD(GameScript, getAvgFPS), asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("GameScriptClass", "float rangeRandom(float, float)", asMETHOD(GameScript,rangeRandom), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "int useOnlineAPI(const string &in, const dictionary &in, string &out)", asMETHOD(GameScript, useOnlineAPI), asCALL_THISCALL); ROR_ASSERT(result >= 0); + + // > GUI + result = engine->RegisterObjectMethod("GameScriptClass", "void flashMessage(const string &in, float, float)", asMETHOD(GameScript, flashMessage), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void message(const string &in, const string &in, float, bool)", asMETHOD(GameScript, message), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getChatFontSize()", asMETHOD(GameScript, getChatFontSize), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setChatFontSize(int)", asMETHOD(GameScript, setChatFontSize), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void showMessageBox(string &in, string &in, bool button1, string &in, bool AllowClose, bool button2,string &in)", asMETHOD(GameScript, showMessageBox), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void showChooser(const string &in, const string &in, const string &in)", asMETHOD(GameScript, showChooser), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void updateDirectionArrow(const string &in, vector3 &in)", asMETHOD(GameScript, updateDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void hideDirectionArrow()", asMETHOD(GameScript, hideDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result >= 0); + + // > Script management + result = engine->RegisterObjectMethod("GameScriptClass", "void registerForEvent(int)", asMETHOD(GameScript, registerForEvent), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void unRegisterEvent(int)", asMETHOD(GameScript, unRegisterEvent), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int addScriptFunction(const string &in)", asMETHOD(GameScript, addScriptFunction), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int scriptFunctionExists(const string &in)", asMETHOD(GameScript, scriptFunctionExists), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int deleteScriptFunction(const string &in)", asMETHOD(GameScript, deleteScriptFunction), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int addScriptVariable(const string &in)", asMETHOD(GameScript, addScriptVariable), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int deleteScriptVariable(const string &in)", asMETHOD(GameScript, deleteScriptVariable), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void clearEventCache()", asMETHOD(GameScript, clearEventCache), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int sendGameCmd(const string &in)", asMETHOD(GameScript, sendGameCmd), asCALL_THISCALL); ROR_ASSERT(result >= 0); + // > Terrain + result = engine->RegisterObjectMethod("GameScriptClass", "void loadTerrain(const string &in)", asMETHOD(GameScript, loadTerrain), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getLoadedTerrain(string &out)", asMETHOD(GameScript, getLoadedTerrain), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "bool getCaelumAvailable()", asMETHOD(GameScript, getCaelumAvailable), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "string getCaelumTime()", asMETHOD(GameScript, getCaelumTime), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCaelumTime(float)", asMETHOD(GameScript, setCaelumTime), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getGravity()", asMETHOD(GameScript, getGravity), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setGravity(float)", asMETHOD(GameScript, setGravity), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getGroundHeight(vector3 &in)", asMETHOD(GameScript, getGroundHeight), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "float getWaterHeight()", asMETHOD(GameScript, getWaterHeight), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setWaterHeight(float)", asMETHOD(GameScript, setWaterHeight), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void spawnObject(const string &in, const string &in, vector3 &in, vector3 &in, const string &in, bool)", asMETHOD(GameScript, spawnObject), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void moveObjectVisuals(const string &in, vector3 &in)", asMETHOD(GameScript, moveObjectVisuals), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void destroyObject(const string &in)", asMETHOD(GameScript, destroyObject), asCALL_THISCALL); ROR_ASSERT(result >= 0); + + // > Character + result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getPersonPosition()", asMETHOD(GameScript, getPersonPosition), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setPersonPosition(vector3 &in)", asMETHOD(GameScript, setPersonPosition), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void movePerson(vector3 &in)", asMETHOD(GameScript, movePerson), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setPersonRotation(radian &in)", asMETHOD(GameScript, setPersonRotation), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "radian getPersonRotation()", asMETHOD(GameScript, getPersonRotation), asCALL_THISCALL); ROR_ASSERT(result >= 0); + + // > Actors result = engine->RegisterObjectMethod("GameScriptClass", "void activateAllVehicles()", asMETHOD(GameScript,activateAllVehicles), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setTrucksForcedActive(bool forceActive)", asMETHOD(GameScript,SetTrucksForcedAwake), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setTrucksForcedActive(bool forceActive)", asMETHOD(GameScript,setTrucksForcedAwake), asCALL_THISCALL); ROR_ASSERT(result>=0); + result = engine->RegisterObjectMethod("GameScriptClass", "void boostCurrentTruck(float)", asMETHOD(GameScript, boostCurrentTruck), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @getCurrentTruck()", asMETHOD(GameScript, getCurrentTruck), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @getTruckByNum(int)", asMETHOD(GameScript, getTruckByNum), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucks()", asMETHOD(GameScript, getNumTrucks), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getCurrentTruckNumber()", asMETHOD(GameScript, getCurrentTruckNumber), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @spawnTruck(string &in, vector3 &in, vector3 &in)", asMETHOD(GameScript, spawnTruck), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void repairVehicle(const string &in, const string &in, bool)", asMETHOD(GameScript, repairVehicle), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void removeVehicle(const string &in, const string &in)", asMETHOD(GameScript, removeVehicle), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucksByFlag(int)", asMETHOD(GameScript, getNumTrucksByFlag), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "VehicleAIClass @getCurrentTruckAI()", asMETHOD(GameScript, getCurrentTruckAI), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "VehicleAIClass @getTruckAIByNum(int)", asMETHOD(GameScript, getTruckAIByNum), asCALL_THISCALL); ROR_ASSERT(result >= 0); + + // > Camera + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraPosition(vector3 &in)", asMETHOD(GameScript, setCameraPosition), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraDirection(vector3 &in)", asMETHOD(GameScript, setCameraDirection), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraOrientation(vector3 &in)", asMETHOD(GameScript, setCameraOrientation), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraRoll(float)", asMETHOD(GameScript, setCameraRoll), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraYaw(float)", asMETHOD(GameScript, setCameraYaw), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraPitch(float)", asMETHOD(GameScript, setCameraPitch), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraPosition()", asMETHOD(GameScript, getCameraPosition), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraDirection()", asMETHOD(GameScript, getCameraDirection), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraOrientation()", asMETHOD(GameScript, getCameraOrientation), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "void cameraLookAt(vector3 &in)", asMETHOD(GameScript, cameraLookAt), asCALL_THISCALL); ROR_ASSERT(result >= 0); + // > Race system result = engine->RegisterObjectMethod("GameScriptClass", "void setBestLapTime(float time)", asMETHOD(GameScript,setBestLapTime), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("GameScriptClass", "void setTimeDiff(float diff)", asMETHOD(GameScript,setTimeDiff), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("GameScriptClass", "void startTimer(int id)", asMETHOD(GameScript,startTimer), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("GameScriptClass", "void stopTimer()", asMETHOD(GameScript,stopTimer), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void flashMessage(const string &in, float, float)", asMETHOD(GameScript,flashMessage), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void message(const string &in, const string &in, float, bool)", asMETHOD(GameScript,message), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void UpdateDirectionArrow(const string &in, vector3 &in)", asMETHOD(GameScript,UpdateDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void hideDirectionArrow()", asMETHOD(GameScript,hideDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void showChooser(const string &in, const string &in, const string &in)", asMETHOD(GameScript,showChooser), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getChatFontSize()", asMETHOD(GameScript,getChatFontSize), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setChatFontSize(int)", asMETHOD(GameScript,setChatFontSize), asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void loadTerrain(const string &in)", asMETHOD(GameScript,loadTerrain), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getLoadedTerrain(string &out)", asMETHOD(GameScript,getLoadedTerrain), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "bool getCaelumAvailable()", asMETHOD(GameScript,getCaelumAvailable), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "string getCaelumTime()", asMETHOD(GameScript,getCaelumTime), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCaelumTime(float)", asMETHOD(GameScript,setCaelumTime), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setWaterHeight(float)", asMETHOD(GameScript,setWaterHeight), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "float getWaterHeight()", asMETHOD(GameScript,getWaterHeight), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "float getGroundHeight(vector3 &in)", asMETHOD(GameScript,getGroundHeight), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "float getGravity()", asMETHOD(GameScript,getGravity), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setGravity(float)", asMETHOD(GameScript,setGravity), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void spawnObject(const string &in, const string &in, vector3 &in, vector3 &in, const string &in, bool)", asMETHOD(GameScript,spawnObject), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void MoveObjectVisuals(const string &in, vector3 &in)", asMETHOD(GameScript,MoveTerrainObjectVisuals), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void destroyObject(const string &in)", asMETHOD(GameScript,destroyObject), asCALL_THISCALL); ROR_ASSERT(result>=0); + // > Material helpers result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialAmbient(const string &in, float, float, float)", asMETHOD(GameScript,setMaterialAmbient), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialDiffuse(const string &in, float, float, float, float)", asMETHOD(GameScript,setMaterialDiffuse), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialSpecular(const string &in, float, float, float, float)", asMETHOD(GameScript,setMaterialSpecular), asCALL_THISCALL); ROR_ASSERT(result>=0); @@ -72,52 +129,4 @@ void RoR::RegisterGameScript(asIScriptEngine *engine) result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureRotate(const string &in, int, int, int, float)", asMETHOD(GameScript,setMaterialTextureRotate), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureScroll(const string &in, int, int, int, float, float)", asMETHOD(GameScript,setMaterialTextureScroll), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("GameScriptClass", "int setMaterialTextureScale(const string &in, int, int, int, float, float)", asMETHOD(GameScript,setMaterialTextureScale), asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void repairVehicle(const string &in, const string &in, bool)", asMETHOD(GameScript,repairVehicle), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void removeVehicle(const string &in, const string &in)", asMETHOD(GameScript,removeVehicle), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getCurrentTruckNumber()", asMETHOD(GameScript,GetPlayerActorId), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void boostCurrentTruck(float)", asMETHOD(GameScript, boostCurrentTruck), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucks()", asMETHOD(GameScript,getNumTrucks), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @getCurrentTruck()", asMETHOD(GameScript,getCurrentTruck), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @getTruckByNum(int)", asMETHOD(GameScript,getTruckByNum), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucksByFlag(int)", asMETHOD(GameScript,getNumTrucksByFlag), asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void setPersonPosition(vector3 &in)", asMETHOD(GameScript,setPersonPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getPersonPosition()", asMETHOD(GameScript,getPersonPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setPersonRotation(radian &in)", asMETHOD(GameScript,setPersonRotation), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "radian getPersonRotation()", asMETHOD(GameScript,getPersonRotation), asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraPosition(vector3 &in)", asMETHOD(GameScript,setCameraPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraDirection(vector3 &in)", asMETHOD(GameScript,setCameraDirection), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraYaw(float)", asMETHOD(GameScript,setCameraYaw), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraPitch(float)", asMETHOD(GameScript,setCameraPitch), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraRoll(float)", asMETHOD(GameScript,setCameraRoll), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraPosition()", asMETHOD(GameScript,getCameraPosition), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraDirection()", asMETHOD(GameScript,getCameraDirection), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void cameraLookAt(vector3 &in)", asMETHOD(GameScript,cameraLookAt), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void setCameraOrientation(vector3 &in)", asMETHOD(GameScript,setCameraOrientation), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getCameraOrientation()", asMETHOD(GameScript,getCameraOrientation), asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "int addScriptFunction(const string &in)", asMETHOD(GameScript,addScriptFunction), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int scriptFunctionExists(const string &in)", asMETHOD(GameScript,scriptFunctionExists), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int deleteScriptFunction(const string &in)", asMETHOD(GameScript,deleteScriptFunction), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int addScriptVariable(const string &in)", asMETHOD(GameScript,addScriptVariable), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int deleteScriptVariable(const string &in)", asMETHOD(GameScript,deleteScriptVariable), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void clearEventCache()", asMETHOD(GameScript,clearEventCache), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void registerForEvent(int)", asMETHOD(GameScript,registerForEvent), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "void unRegisterEvent(int)", asMETHOD(GameScript,unRegisterEvent), asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "int sendGameCmd(const string &in)", asMETHOD(GameScript,sendGameCmd), asCALL_THISCALL); ROR_ASSERT(result>=0); - result = engine->RegisterObjectMethod("GameScriptClass", "int useOnlineAPI(const string &in, const dictionary &in, string &out)", asMETHOD(GameScript,useOnlineAPI), asCALL_THISCALL); ROR_ASSERT(result>=0); - - result = engine->RegisterObjectMethod("GameScriptClass", "VehicleAIClass @getCurrentTruckAI()", asMETHOD(GameScript, getCurrentTruckAI), asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("GameScriptClass", "VehicleAIClass @getTruckAIByNum(int)", asMETHOD(GameScript, getTruckAIByNum), asCALL_THISCALL); ROR_ASSERT(result >= 0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void showMessageBox(string &in, string &in, bool button1, string &in, bool AllowClose, bool button2,string &in)", asMETHOD(GameScript, showMessageBox), asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("GameScriptClass", "BeamClass @spawnTruck(string &in, vector3 &in, vector3 &in)", asMETHOD(GameScript, spawnTruck), asCALL_THISCALL); ROR_ASSERT(result >= 0); - - result = engine->RegisterObjectMethod("GameScriptClass", "float getFPS()", asMETHOD(GameScript, getFPS), asCALL_THISCALL); ROR_ASSERT(result >= 0); - - result = engine->RegisterObjectMethod("GameScriptClass", "void backToMenu()", asMETHOD(GameScript, backToMenu), asCALL_THISCALL); ROR_ASSERT(result >= 0); - result = engine->RegisterObjectMethod("GameScriptClass", "void quitGame()", asMETHOD(GameScript, quitGame), asCALL_THISCALL); ROR_ASSERT(result >= 0); } From 8cf5032c379b4e3e7aa0d44b7015e8f220d15b94 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Wed, 10 Aug 2022 02:58:26 +0200 Subject: [PATCH 03/12] ImGuiAngelscript: added ImGuiWindowFlags, ImGui::SliderInt() --- .../scripting/bindings/ImGuiAngelscript.cpp | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/source/main/scripting/bindings/ImGuiAngelscript.cpp b/source/main/scripting/bindings/ImGuiAngelscript.cpp index 7905ff98eb..54ba81c7be 100644 --- a/source/main/scripting/bindings/ImGuiAngelscript.cpp +++ b/source/main/scripting/bindings/ImGuiAngelscript.cpp @@ -37,6 +37,35 @@ using namespace std; void RoR::RegisterImGuiBindings(AngelScript::asIScriptEngine* engine) { + // ENUMS (outside namespace) + + engine->RegisterEnum("ImGuiWindowFlags"); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_None", ImGuiWindowFlags_None); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoTitleBar", ImGuiWindowFlags_NoTitleBar); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoResize", ImGuiWindowFlags_NoResize); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoMove", ImGuiWindowFlags_NoMove); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoScrollbar", ImGuiWindowFlags_NoScrollbar); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoScrollWithMouse", ImGuiWindowFlags_NoScrollWithMouse); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoCollapse", ImGuiWindowFlags_NoCollapse); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_AlwaysAutoResize", ImGuiWindowFlags_AlwaysAutoResize); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoBackground", ImGuiWindowFlags_NoBackground); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoSavedSettings", ImGuiWindowFlags_NoSavedSettings); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoMouseInputs", ImGuiWindowFlags_NoMouseInputs); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_MenuBar", ImGuiWindowFlags_MenuBar); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_HorizontalScrollbar", ImGuiWindowFlags_HorizontalScrollbar); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoFocusOnAppearing", ImGuiWindowFlags_NoFocusOnAppearing); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoBringToFrontOnFocus", ImGuiWindowFlags_NoBringToFrontOnFocus); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_AlwaysVerticalScrollbar", ImGuiWindowFlags_AlwaysVerticalScrollbar); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_AlwaysHorizontalScrollbar", ImGuiWindowFlags_AlwaysHorizontalScrollbar); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_AlwaysUseWindowPadding", ImGuiWindowFlags_AlwaysUseWindowPadding); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoNavInputs", ImGuiWindowFlags_NoNavInputs); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoNavFocus", ImGuiWindowFlags_NoNavFocus); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_UnsavedDocument", ImGuiWindowFlags_UnsavedDocument); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoNav", ImGuiWindowFlags_NoNav); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoDecoration", ImGuiWindowFlags_NoDecoration); + engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoInputs", ImGuiWindowFlags_NoInputs); + + // FUNCTIONS (within namespace) engine->SetDefaultNamespace("ImGui"); engine->RegisterGlobalFunction("bool Begin(const string&in, bool, int=0)", asFUNCTIONPR([](const string& name, bool opened, int flags) { return ImGui::Begin(name.c_str(), &opened, flags); }, (const string&, bool, int), bool), asCALL_CDECL); @@ -269,11 +298,12 @@ void RoR::RegisterImGuiBindings(AngelScript::asIScriptEngine* engine) return ImGui::SliderFloat2(n.c_str(), &v.x, mn, mx); }, (const string&, Vector2&, float,float),bool), asCALL_CDECL); engine->RegisterGlobalFunction("bool SliderFloat3(const string&in, vector3&inout, float, float)", asFUNCTIONPR([](const string& n, Vector3& v, float mn, float mx) { return ImGui::SliderFloat3(n.c_str(), &v.x, mn, mx); }, (const string&, Vector3&, float,float),bool), asCALL_CDECL); + engine->RegisterGlobalFunction("bool SliderInt(const string&in, int&inout, int = 0, int = 0)", asFUNCTIONPR([](const string& n, int& v, int mn, int mx) { + return ImGui::SliderInt(n.c_str(), &v, mn, mx); }, (const string&, int&, int, int), bool), asCALL_CDECL); /* --- TODO: Register Vector4 engine->RegisterGlobalFunction("bool SliderFloat4(const string&in, Vector4&inout, float, float)", asFUNCTIONPR([](const string& n, Vector4& v, float mn, float mx) { return ImGui::SliderFloat4(n.c_str(), &v.x, mn, mx); }, (const string&, Vector4&,float,float),bool), asCALL_CDECL); - engine->RegisterGlobalFunction("bool SliderInt(const string&in, int&inout, int = 0, int = 0)", asFUNCTIONPR([](const string& n, int& v, int mn, int mx) { - return ImGui::SliderInt(n.c_str(), &v, mn, mx); }, (const string&, int&,int,int), bool), asCALL_CDECL); + engine->RegisterGlobalFunction("bool SliderInt2(const string&in, IntVector2&inout, int = 0, int = 0)", asFUNCTIONPR([](const string& n, IntVector2& v, int mn, int mx) { return ImGui::SliderInt2(n.c_str(), &v.x, mn, mx); }, (const string&, IntVector2&, int,int),bool), asCALL_CDECL); engine->RegisterGlobalFunction("bool SliderInt3(const string&in, IntVector3&inout, int = 0, int = 0)", asFUNCTIONPR([](const string& n, IntVector3& v, int mn, int mx) { From 06fd7fd90c7514d879d91251d1b174578577fb20 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Wed, 10 Aug 2022 03:03:09 +0200 Subject: [PATCH 04/12] OgreAngelscript: added default arg. value, like in C++. --- source/main/scripting/bindings/OgreAngelscript.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/main/scripting/bindings/OgreAngelscript.cpp b/source/main/scripting/bindings/OgreAngelscript.cpp index 9603d24e65..55121f6392 100644 --- a/source/main/scripting/bindings/OgreAngelscript.cpp +++ b/source/main/scripting/bindings/OgreAngelscript.cpp @@ -735,11 +735,11 @@ void registerOgreQuaternion(AngelScript::asIScriptEngine* engine) ROR_ASSERT( r >= 0 ); r = engine->RegisterObjectMethod("quaternion", "quaternion Log() const", asMETHOD(Quaternion,Log), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("quaternion", "radian getRoll(bool) const", asMETHOD(Quaternion,getRoll), asCALL_THISCALL); + r = engine->RegisterObjectMethod("quaternion", "radian getRoll(bool reprojectAxis = true) const", asMETHOD(Quaternion,getRoll), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("quaternion", "radian getPitch(bool) const", asMETHOD(Quaternion,getPitch), asCALL_THISCALL); + r = engine->RegisterObjectMethod("quaternion", "radian getPitch(bool reprojectAxis = true) const", asMETHOD(Quaternion,getPitch), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); - r = engine->RegisterObjectMethod("quaternion", "radian getYaw(bool) const", asMETHOD(Quaternion,getYaw), asCALL_THISCALL); + r = engine->RegisterObjectMethod("quaternion", "radian getYaw(bool reprojectAxis = true) const", asMETHOD(Quaternion,getYaw), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); r = engine->RegisterObjectMethod("quaternion", "bool equals(const quaternion &in, const radian &in) const", asMETHOD(Quaternion,equals), asCALL_THISCALL); ROR_ASSERT( r >= 0 ); From d2b03e823a492140e714c9004603737d52b83aab Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 12 Aug 2022 20:20:40 +0200 Subject: [PATCH 05/12] ScriptEngine: loading the same script multiple times is now safe. added ScriptUnitId_t/SCRIPTUNITID_INVALID, returned by loadScript() and used as param to unloadScript(). --- source/main/scripting/GameScript.cpp | 24 ++--- source/main/scripting/ScriptEngine.cpp | 135 +++++++++++++------------ source/main/scripting/ScriptEngine.h | 32 +++--- source/main/terrain/TerrainManager.cpp | 11 +- 4 files changed, 106 insertions(+), 96 deletions(-) diff --git a/source/main/scripting/GameScript.cpp b/source/main/scripting/GameScript.cpp index edf7704563..e66dfa8bf8 100644 --- a/source/main/scripting/GameScript.cpp +++ b/source/main/scripting/GameScript.cpp @@ -282,10 +282,10 @@ void GameScript::registerForEvent(int eventValue) { if (App::GetScriptEngine()) { - int unit_id = App::GetScriptEngine()->getCurrentlyExecutingScriptUnit(); - if (unit_id != -1) + ScriptUnitId_t unit_id = App::GetScriptEngine()->getCurrentlyExecutingScriptUnit(); + if (unit_id != SCRIPTUNITID_INVALID) { - App::GetScriptEngine()->getScriptUnits()[unit_id].eventMask |= eventValue; + App::GetScriptEngine()->getScriptUnit(unit_id).eventMask |= eventValue; } } } @@ -294,10 +294,10 @@ void GameScript::unRegisterEvent(int eventValue) { if (App::GetScriptEngine()) { - int unit_id = App::GetScriptEngine()->getCurrentlyExecutingScriptUnit(); - if (unit_id != -1) + ScriptUnitId_t unit_id = App::GetScriptEngine()->getCurrentlyExecutingScriptUnit(); + if (unit_id != SCRIPTUNITID_INVALID) { - App::GetScriptEngine()->getScriptUnits()[unit_id].eventMask &= ~eventValue; + App::GetScriptEngine()->getScriptUnit(unit_id).eventMask &= ~eventValue; } } } @@ -416,10 +416,10 @@ void GameScript::spawnObject(const String& objectName, const String& instanceNam try { - AngelScript::asIScriptModule* module = App::GetScriptEngine()->getScriptUnits()[App::GetScriptEngine()->getTerrainScriptUnit()].scriptModule; + AngelScript::asIScriptModule* module = App::GetScriptEngine()->getScriptUnit(App::GetScriptEngine()->getTerrainScriptUnit()).scriptModule; if (module == nullptr) { - this->logFormat("spawnObject(): Failed to fetch/create script module '%s'", module->GetName()); + this->logFormat("spawnObject(): Failed to fetch/create script module"); return; } @@ -726,8 +726,8 @@ int GameScript::useOnlineAPI(const String& apiquery, const AngelScript::CScriptD if (App::app_disable_online_api->getBool()) return 0; - int unit_id = App::GetScriptEngine()->getCurrentlyExecutingScriptUnit(); - if (unit_id == -1) + ScriptUnitId_t unit_id = App::GetScriptEngine()->getCurrentlyExecutingScriptUnit(); + if (unit_id == SCRIPTUNITID_INVALID) return 2; Actor* player_actor = App::GetGameContext()->GetPlayerActor(); @@ -742,8 +742,8 @@ int GameScript::useOnlineAPI(const String& apiquery, const AngelScript::CScriptD std::string terrain_name = App::GetSimTerrain()->getTerrainName(); - std::string script_name = App::GetScriptEngine()->getScriptUnits()[unit_id].scriptName; - std::string script_hash = App::GetScriptEngine()->getScriptUnits()[unit_id].scriptHash; + std::string script_name = App::GetScriptEngine()->getScriptUnit(unit_id).scriptName; + std::string script_hash = App::GetScriptEngine()->getScriptUnit(unit_id).scriptHash; rapidjson::Document j_doc; j_doc.SetObject(); diff --git a/source/main/scripting/ScriptEngine.cpp b/source/main/scripting/ScriptEngine.cpp index aea3467c48..370ff6d68e 100644 --- a/source/main/scripting/ScriptEngine.cpp +++ b/source/main/scripting/ScriptEngine.cpp @@ -58,6 +58,17 @@ using namespace Ogre; using namespace RoR; +const char* RoR::ScriptCategoryToString(ScriptCategory c) +{ + switch (c) + { + case ScriptCategory::TERRAIN: return "TERRAIN"; + case ScriptCategory::CUSTOM: return "CUSTOM"; + case ScriptCategory::INVALID: return "INVALID"; + default: return ""; + } +} + // some hacky functions void logString(const std::string &str) @@ -182,21 +193,22 @@ int ScriptEngine::framestep(Real dt) // framestep stuff below if (!engine || !context) return 0; - for (size_t i = 0; i < m_script_units.size(); i++) + for (auto& pair: m_script_units) { - if (!m_script_units[i].frameStepFunctionPtr) + ScriptUnitId_t id = pair.first; + if (!m_script_units[id].frameStepFunctionPtr) { continue; } - context->Prepare(m_script_units[i].frameStepFunctionPtr); + context->Prepare(m_script_units[id].frameStepFunctionPtr); // Set the function arguments context->SetArgFloat(0, dt); - m_currently_executing_script_unit = (int)i; + m_currently_executing_script_unit = id; int r = context->Execute(); - m_currently_executing_script_unit = -1; + m_currently_executing_script_unit = SCRIPTUNITID_INVALID; if ( r == AngelScript::asEXECUTION_FINISHED ) { // The return value is only valid if the execution finished successfully @@ -211,9 +223,10 @@ int ScriptEngine::fireEvent(std::string instanceName, float intensity) if (!engine || !context) return 0; - for (size_t i = 0; i < m_script_units.size(); i++) + for (auto& pair: m_script_units) { - AngelScript::asIScriptFunction* func = m_script_units[i].scriptModule->GetFunctionByDecl( + ScriptUnitId_t id = pair.first; + AngelScript::asIScriptFunction* func = m_script_units[id].scriptModule->GetFunctionByDecl( "void fireEvent(string, float)"); // TODO: this shouldn't be hard coded --neorej16 context->Prepare(func); @@ -222,9 +235,9 @@ int ScriptEngine::fireEvent(std::string instanceName, float intensity) context->SetArgObject(0, &instanceName); context->SetArgFloat (1, intensity); - m_currently_executing_script_unit = (int)i; + m_currently_executing_script_unit = id; int r = context->Execute(); - m_currently_executing_script_unit = -1; + m_currently_executing_script_unit = SCRIPTUNITID_INVALID; if ( r == AngelScript::asEXECUTION_FINISHED ) { // The return value is only valid if the execution finished successfully @@ -240,13 +253,14 @@ void ScriptEngine::envokeCallback(int _functionId, eventsource_t *source, node_t if (!engine || !context) return; - for (size_t i = 0; i < m_script_units.size(); i++) + for (auto& pair: m_script_units) { + ScriptUnitId_t id = pair.first; int functionId = _functionId; - if (functionId <= 0 && (m_script_units[i].defaultEventCallbackFunctionPtr != nullptr)) + if (functionId <= 0 && (m_script_units[id].defaultEventCallbackFunctionPtr != nullptr)) { // use the default event handler instead then - functionId = m_script_units[i].defaultEventCallbackFunctionPtr->GetId(); + functionId = m_script_units[id].defaultEventCallbackFunctionPtr->GetId(); } else if (functionId <= 0) { @@ -267,9 +281,9 @@ void ScriptEngine::envokeCallback(int _functionId, eventsource_t *source, node_t else context->SetArgDWord (3, static_cast(-1)); - m_currently_executing_script_unit = (int)i; + m_currently_executing_script_unit = id; int r = context->Execute(); - m_currently_executing_script_unit = -1; + m_currently_executing_script_unit = SCRIPTUNITID_INVALID; if ( r == AngelScript::asEXECUTION_FINISHED ) { @@ -290,7 +304,7 @@ int ScriptEngine::executeString(String command) return 1; // Only works with terrain script module (classic behavior) - if (m_terrain_script_unit < 0) + if (m_terrain_script_unit == SCRIPTUNITID_INVALID) return 1; AngelScript::asIScriptModule *mod = m_script_units[m_terrain_script_unit].scriptModule; @@ -311,7 +325,7 @@ int ScriptEngine::addFunction(const String &arg) // Only works with terrain script module (classic behavior) - if (m_terrain_script_unit < 0) + if (m_terrain_script_unit == SCRIPTUNITID_INVALID) return 1; AngelScript::asIScriptModule *mod = m_script_units[m_terrain_script_unit].scriptModule; @@ -359,7 +373,7 @@ int ScriptEngine::functionExists(const String &arg) return -1; // ... OK, I guess the author wanted the fn. to be usable both within script and C++, but IMO that's bad design (generally good, but bad for a game.. bad for RoR), really ~ only_a_ptr, 09/2017 // Only works with terrain script module (classic behavior) - if (m_terrain_script_unit < 0) + if (m_terrain_script_unit == SCRIPTUNITID_INVALID) return -1; AngelScript::asIScriptModule *mod = m_script_units[m_terrain_script_unit].scriptModule; @@ -384,7 +398,7 @@ int ScriptEngine::deleteFunction(const String &arg) return AngelScript::asERROR; // Only works with terrain script module (classic behavior) - if (m_terrain_script_unit < 0) + if (m_terrain_script_unit == SCRIPTUNITID_INVALID) return -1; AngelScript::asIScriptModule *mod = m_script_units[m_terrain_script_unit].scriptModule; @@ -433,7 +447,7 @@ int ScriptEngine::addVariable(const String &arg) { if (!engine || !context) return 1; // Only works with terrain script module (classic behavior) - if (m_terrain_script_unit < 0) + if (m_terrain_script_unit == SCRIPTUNITID_INVALID) return 1; AngelScript::asIScriptModule *mod = m_script_units[m_terrain_script_unit].scriptModule; @@ -453,7 +467,7 @@ int ScriptEngine::deleteVariable(const String &arg) { if (!engine || !context) return 1; // Only works with terrain script module (classic behavior) - if (m_terrain_script_unit < 0) + if (m_terrain_script_unit == SCRIPTUNITID_INVALID) return 1; AngelScript::asIScriptModule *mod = m_script_units[m_terrain_script_unit].scriptModule; @@ -484,22 +498,23 @@ void ScriptEngine::triggerEvent(int eventnum, int value) { if (!engine || !context) return; - for (size_t i = 0; i < m_script_units.size(); i++) + for (auto& pair: m_script_units) { - if (m_script_units[i].eventCallbackFunctionPtr==nullptr) + ScriptUnitId_t id = pair.first; + if (m_script_units[id].eventCallbackFunctionPtr==nullptr) continue; - if (m_script_units[i].eventMask & eventnum) + if (m_script_units[id].eventMask & eventnum) { // script registered for that event, so sent it - context->Prepare(m_script_units[i].eventCallbackFunctionPtr); + context->Prepare(m_script_units[id].eventCallbackFunctionPtr); // Set the function arguments context->SetArgDWord(0, eventnum); context->SetArgDWord(1, value); - m_currently_executing_script_unit = (int)i; + m_currently_executing_script_unit = id; int r = context->Execute(); - m_currently_executing_script_unit = -1; + m_currently_executing_script_unit = SCRIPTUNITID_INVALID; if ( r == AngelScript::asEXECUTION_FINISHED ) { // The return value is only valid if the execution finished successfully @@ -509,32 +524,28 @@ void ScriptEngine::triggerEvent(int eventnum, int value) } } -String ScriptEngine::composeModuleName(String const& scriptName, ScriptCategory origin) +String ScriptEngine::composeModuleName(String const& scriptName, ScriptCategory origin, ScriptUnitId_t id) { - switch (origin) - { - case ScriptCategory::TERRAIN: return fmt::format("TERRAIN:{}", scriptName); - - case ScriptCategory::CUSTOM: return fmt::format("CUSTOM:{}", scriptName); - - default: return ""; - } + return fmt::format("{}(category:{},unique ID:{})", scriptName, ScriptCategoryToString(origin), id); } -int ScriptEngine::loadScript(String scriptName, ScriptCategory category/* = ScriptCategory::TERRAIN*/) +ScriptUnitId_t ScriptEngine::loadScript(String scriptName, ScriptCategory category/* = ScriptCategory::TERRAIN*/) { // This function creates a new script unit, tries to set it up and removes it if setup fails. // ----------------------------------------------------------------------------------------- // A script unit is how Rigs of Rods organizes scripts from various sources. // Because the script is executed during loading, it's wrapping unit must // be created early, and removed if setup fails. - int unit_id = (int)m_script_units.size(); - m_script_units.resize(m_script_units.size() + 1); + static ScriptUnitId_t id_counter = 0; + + ScriptUnitId_t unit_id = id_counter++; + auto itor_pair = m_script_units.insert(std::make_pair(unit_id, ScriptUnit())); + m_script_units[unit_id].uniqueId = unit_id; m_script_units[unit_id].scriptName = scriptName; m_script_units[unit_id].scriptCategory = category; if (category == ScriptCategory::TERRAIN) { - m_terrain_script_unit = (int)m_script_units.size() - 1; + m_terrain_script_unit = unit_id; } // Perform the actual script loading, building and running main(). @@ -543,14 +554,15 @@ int ScriptEngine::loadScript(String scriptName, ScriptCategory category/* = Scri // If setup failed, remove the unit. if (result != 0) { - m_script_units.pop_back(); + m_script_units.erase(itor_pair.first); if (category == ScriptCategory::TERRAIN) { - m_terrain_script_unit = -1; - } + m_terrain_script_unit = SCRIPTUNITID_INVALID; + } + return SCRIPTUNITID_INVALID; } - return result; + return unit_id; } int ScriptEngine::setupScriptUnit(int unit_id) @@ -558,9 +570,7 @@ int ScriptEngine::setupScriptUnit(int unit_id) int result=0; String moduleName = this->composeModuleName( - m_script_units[unit_id].scriptName, m_script_units[unit_id].scriptCategory); - if (moduleName == "") - return -1; + m_script_units[unit_id].scriptName, m_script_units[unit_id].scriptCategory, m_script_units[unit_id].uniqueId); // The builder is a helper class that will load the script file, // search for #include directives, and load any included files as @@ -593,7 +603,7 @@ int ScriptEngine::setupScriptUnit(int unit_id) // the game must already be aware of the script, but only temporarily. m_currently_executing_script_unit = unit_id; // for `BuildModule()` below. result = builder.BuildModule(); - m_currently_executing_script_unit = -1; // Tidy up. + m_currently_executing_script_unit = SCRIPTUNITID_INVALID; // Tidy up. if ( result < 0 ) { App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_ERROR, @@ -642,7 +652,7 @@ int ScriptEngine::setupScriptUnit(int unit_id) SLOG(fmt::format("Executing main() in {}", moduleName)); m_currently_executing_script_unit = unit_id; // for `Execute()` below. result = context->Execute(); - m_currently_executing_script_unit = -1; // Tidy up. + m_currently_executing_script_unit = SCRIPTUNITID_INVALID; // Tidy up. if ( result != AngelScript::asEXECUTION_FINISHED ) { // The execution didn't complete as expected. Determine what happened. @@ -681,24 +691,16 @@ int ScriptEngine::setupScriptUnit(int unit_id) return 0; } -void ScriptEngine::unloadScript(String scriptName, ScriptCategory category) +void ScriptEngine::unloadScript(ScriptUnitId_t id) { - ROR_ASSERT(m_currently_executing_script_unit == -1); + ROR_ASSERT(id != SCRIPTUNITID_INVALID); + ROR_ASSERT(m_currently_executing_script_unit == SCRIPTUNITID_INVALID); - String module_name = this->composeModuleName(scriptName, category); - if (module_name == "") - return; - - for (size_t i = 0; i < m_script_units.size(); i++) + engine->DiscardModule(m_script_units[id].scriptModule->GetName()); + m_script_units.erase(id); + if (m_terrain_script_unit == id) { - if (m_script_units[i].scriptModule->GetName() == module_name) - { - m_script_units.erase(m_script_units.begin() + i); - if (i == (size_t)m_terrain_script_unit) - { - m_terrain_script_unit = -1; - } - } + m_terrain_script_unit = SCRIPTUNITID_INVALID; } } @@ -706,3 +708,10 @@ void ScriptEngine::activateLogging() { scriptLog->addListener(this); } + +ScriptUnit& ScriptEngine::getScriptUnit(ScriptUnitId_t unique_id) +{ + ROR_ASSERT(unique_id != SCRIPTUNITID_INVALID); + ROR_ASSERT(m_script_units.count(unique_id) != 0); + return m_script_units[unique_id]; +} diff --git a/source/main/scripting/ScriptEngine.h b/source/main/scripting/ScriptEngine.h index def0951a79..00f7302634 100644 --- a/source/main/scripting/ScriptEngine.h +++ b/source/main/scripting/ScriptEngine.h @@ -41,6 +41,8 @@ #include "scriptdictionary/scriptdictionary.h" #include "scriptbuilder/scriptbuilder.h" +#include + namespace RoR { /// @addtogroup Scripting @@ -53,9 +55,15 @@ enum class ScriptCategory CUSTOM }; +const char* ScriptCategoryToString(ScriptCategory c); + +typedef int ScriptUnitId_t; +static const ScriptUnitId_t SCRIPTUNITID_INVALID = -1; + /// Represents a loaded script and all associated resources/handles. struct ScriptUnit { + ScriptUnitId_t uniqueId = SCRIPTUNITID_INVALID; ScriptCategory scriptCategory = ScriptCategory::INVALID; unsigned int eventMask = 0; //!< filter mask for script events AngelScript::asIScriptModule* scriptModule = nullptr; @@ -66,7 +74,7 @@ struct ScriptUnit Ogre::String scriptHash; }; -typedef std::vector ScriptUnitVec; +typedef std::map ScriptUnitMap; /** * @brief This class represents the angelscript scripting interface. It can load and execute scripts. @@ -84,15 +92,15 @@ class ScriptEngine : public Ogre::LogListener, public ZeroedMemoryAllocator /** * Loads a script * @param scriptname filename to load - * @return 0 on success, everything else on error + * @return Unique ID of the script unit (because one script file can be loaded multiple times). */ - int loadScript(Ogre::String scriptname, ScriptCategory category = ScriptCategory::TERRAIN); + ScriptUnitId_t loadScript(Ogre::String scriptname, ScriptCategory category = ScriptCategory::TERRAIN); /** * Unloads a script - * @param scriptname filename to unload + * @param unique_id The script unit ID as returned by `loadScript()` */ - void unloadScript(Ogre::String scriptname, ScriptCategory category); + void unloadScript(ScriptUnitId_t unique_id); /** * Calls the script's framestep function to be able to use timed things inside the script @@ -165,9 +173,9 @@ class ScriptEngine : public Ogre::LogListener, public ZeroedMemoryAllocator inline void SLOG(const char* msg) { this->scriptLog->logMessage(msg); } //!< Replacement of macro inline void SLOG(std::string msg) { this->scriptLog->logMessage(msg); } //!< Replacement of macro - ScriptUnitVec& getScriptUnits() { return m_script_units; } - int getTerrainScriptUnit() const { return m_terrain_script_unit; } //!< @return -1 if none exists. - int getCurrentlyExecutingScriptUnit() const { return m_currently_executing_script_unit; } //!< @return -1 if none is executing right now. + ScriptUnit& getScriptUnit(ScriptUnitId_t unique_id); + ScriptUnitId_t getTerrainScriptUnit() const { return m_terrain_script_unit; } //!< @return SCRIPTUNITID_INVALID if none exists. + ScriptUnitId_t getCurrentlyExecutingScriptUnit() const { return m_currently_executing_script_unit; } //!< @return SCRIPTUNITID_INVALID if none is executing right now. protected: @@ -184,7 +192,7 @@ class ScriptEngine : public Ogre::LogListener, public ZeroedMemoryAllocator */ void msgCallback(const AngelScript::asSMessageInfo* msg); - Ogre::String composeModuleName(Ogre::String const& scriptName, ScriptCategory origin); + Ogre::String composeModuleName(Ogre::String const& scriptName, ScriptCategory origin, ScriptUnitId_t id); /** * Helper for `loadScript()`, does the actual building without worry about unit management. @@ -196,9 +204,9 @@ class ScriptEngine : public Ogre::LogListener, public ZeroedMemoryAllocator AngelScript::asIScriptContext* context; //!< context in which all scripting happens Ogre::Log* scriptLog; GameScript m_game_script; - ScriptUnitVec m_script_units; - int m_terrain_script_unit = -1; - int m_currently_executing_script_unit = -1; + ScriptUnitMap m_script_units; + ScriptUnitId_t m_terrain_script_unit = SCRIPTUNITID_INVALID; + ScriptUnitId_t m_currently_executing_script_unit = SCRIPTUNITID_INVALID; InterThreadStoreVector stringExecutionQueue; //!< The string execution queue \see queueStringForExecution }; diff --git a/source/main/terrain/TerrainManager.cpp b/source/main/terrain/TerrainManager.cpp index ddd60eadee..b9548bbea9 100644 --- a/source/main/terrain/TerrainManager.cpp +++ b/source/main/terrain/TerrainManager.cpp @@ -120,16 +120,9 @@ TerrainManager::~TerrainManager() m_collisions = nullptr; } - if (m_def.as_files.size() != 0) + if (App::GetScriptEngine()->getTerrainScriptUnit() != SCRIPTUNITID_INVALID) { - for (std::string as_filename : m_def.as_files) - { - App::GetScriptEngine()->unloadScript(as_filename, ScriptCategory::TERRAIN); - } - } - else - { - App::GetScriptEngine()->unloadScript(DEFAULT_TERRAIN_SCRIPT, ScriptCategory::TERRAIN); + App::GetScriptEngine()->unloadScript(App::GetScriptEngine()->getTerrainScriptUnit()); } } From aea16bbda88ca51c3978ce1b750fc8da4817ccdb Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 13 Aug 2022 04:36:29 +0200 Subject: [PATCH 06/12] AngelScript: Added `ImDrawList` --- .../scripting/bindings/ImGuiAngelscript.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/source/main/scripting/bindings/ImGuiAngelscript.cpp b/source/main/scripting/bindings/ImGuiAngelscript.cpp index 54ba81c7be..d347de13a6 100644 --- a/source/main/scripting/bindings/ImGuiAngelscript.cpp +++ b/source/main/scripting/bindings/ImGuiAngelscript.cpp @@ -22,6 +22,7 @@ /// @file /// @author https://gist.github.com/JSandusky/54b85068aa30390c91a0b377703f042e /// @author https://discourse.urho3d.io/t/dear-imgui-w-o-steamrolling/3960 +/// @author Petr Ohlidal (enums, ImDrawList) #include "OgreImGui.h" #include "scriptarray/scriptarray.h" @@ -37,7 +38,7 @@ using namespace std; void RoR::RegisterImGuiBindings(AngelScript::asIScriptEngine* engine) { - // ENUMS (outside namespace) + // ENUMS (global namespace) engine->RegisterEnum("ImGuiWindowFlags"); engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_None", ImGuiWindowFlags_None); @@ -65,7 +66,18 @@ void RoR::RegisterImGuiBindings(AngelScript::asIScriptEngine* engine) engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoDecoration", ImGuiWindowFlags_NoDecoration); engine->RegisterEnumValue("ImGuiWindowFlags", "ImGuiWindowFlags_NoInputs", ImGuiWindowFlags_NoInputs); - // FUNCTIONS (within namespace) + // ImDrawList object (global namespace) + engine->RegisterObjectType("ImDrawList", sizeof(ImDrawList), asOBJ_REF | asOBJ_NOCOUNT); + engine->RegisterObjectMethod("ImDrawList", "void AddLine(const vector2&in p1, const vector2&in p2, const color&in col, float thickness = 1.f)", asFUNCTIONPR([](ImDrawList* drawlist, Ogre::Vector2 const& p1, Ogre::Vector2 const& p2, Ogre::ColourValue const& col, float thickness) { drawlist->AddLine(ImVec2(p1.x, p1.y), ImVec2(p2.x, p2.y), ImColor(col.r, col.g, col.b, col.a), thickness); }, (ImDrawList * , Ogre::Vector2 const& , Ogre::Vector2 const& , Ogre::ColourValue const& , float ), void), asCALL_CDECL_OBJFIRST); + engine->RegisterObjectMethod("ImDrawList", "void AddTriangle(const vector2&in p1, const vector2&in p2, const vector2&in p3, const color&in col, float thickness = 1.f)", asFUNCTIONPR([](ImDrawList* drawlist, Ogre::Vector2 const& p1, Ogre::Vector2 const& p2, Ogre::Vector2 const& p3, Ogre::ColourValue const& col, float thickness) { drawlist->AddTriangle(ImVec2(p1.x, p1.y), ImVec2(p2.x, p2.y), ImVec2(p3.x, p3.y), ImColor(col.r, col.g, col.b, col.a), thickness); }, (ImDrawList*, Ogre::Vector2 const&, Ogre::Vector2 const&, Ogre::Vector2 const&, Ogre::ColourValue const&, float), void), asCALL_CDECL_OBJFIRST); + engine->RegisterObjectMethod("ImDrawList", "void AddTriangleFilled(const vector2&in p1, const vector2&in p2, const vector2&in p3, const color&in col)", asFUNCTIONPR([](ImDrawList* drawlist, Ogre::Vector2 const& p1, Ogre::Vector2 const& p2, Ogre::Vector2 const& p3, Ogre::ColourValue const& col) { drawlist->AddTriangleFilled(ImVec2(p1.x, p1.y), ImVec2(p2.x, p2.y), ImVec2(p3.x, p3.y), ImColor(col.r, col.g, col.b, col.a)); }, (ImDrawList*, Ogre::Vector2 const&, Ogre::Vector2 const&, Ogre::Vector2 const&, Ogre::ColourValue const&), void), asCALL_CDECL_OBJFIRST); + engine->RegisterObjectMethod("ImDrawList", "void AddRect(const vector2&in p_min, const vector2&in p_max, const color&in col, float rounding = 0.0f, int rounding_corners = 15, float thickness = 1.f)", asFUNCTIONPR([](ImDrawList* drawlist, Ogre::Vector2 const& p1, Ogre::Vector2 const& p2, Ogre::ColourValue const& col, float rounding, int rounding_corners, float thickness) { drawlist->AddRect(ImVec2(p1.x, p1.y), ImVec2(p2.x, p2.y), ImColor(col.r, col.g, col.b, col.a), rounding, rounding_corners, thickness); }, (ImDrawList * drawlist, Ogre::Vector2 const& , Ogre::Vector2 const& , Ogre::ColourValue const& , float , int , float ), void), asCALL_CDECL_OBJFIRST); + engine->RegisterObjectMethod("ImDrawList", "void AddRectFilled(const vector2&in p_min, const vector2&in p_max, const color&in col, float rounding = 0.0f, int rounding_corners = 15)", asFUNCTIONPR([](ImDrawList* drawlist, Ogre::Vector2 const& p1, Ogre::Vector2 const& p2, Ogre::ColourValue const& col, float rounding, int rounding_corners) { drawlist->AddRectFilled(ImVec2(p1.x, p1.y), ImVec2(p2.x, p2.y), ImColor(col.r, col.g, col.b, col.a), rounding, rounding_corners); }, (ImDrawList * drawlist, Ogre::Vector2 const&, Ogre::Vector2 const&, Ogre::ColourValue const&, float, int), void), asCALL_CDECL_OBJFIRST); + engine->RegisterObjectMethod("ImDrawList", "void AddCircle(const vector2&in center, float radius, const color&in col, int num_segments = 12, float thickness = 1.f)", asFUNCTIONPR([](ImDrawList* drawlist, Ogre::Vector2 const& center, float radius, Ogre::ColourValue const& col, int num_segments, float thickness) { drawlist->AddCircle(ImVec2(center.x, center.y), radius, ImColor(col.r, col.g, col.b, col.a), num_segments, thickness); }, (ImDrawList*, Ogre::Vector2 const&, float, Ogre::ColourValue const&, int, float), void), asCALL_CDECL_OBJFIRST); + engine->RegisterObjectMethod("ImDrawList", "void AddCircleFilled(const vector2&in center, float radius, const color&in col, int num_segments = 12)", asFUNCTIONPR([](ImDrawList* drawlist, Ogre::Vector2 const& center, float radius, Ogre::ColourValue const& col, int num_segments) { drawlist->AddCircleFilled(ImVec2(center.x, center.y), radius, ImColor(col.r, col.g, col.b, col.a), num_segments); }, (ImDrawList*, Ogre::Vector2 const&, float, Ogre::ColourValue const&, int), void), asCALL_CDECL_OBJFIRST); + engine->RegisterObjectMethod("ImDrawList", "void AddText(const vector2&in pos, const color&in col, const string&in text)", asFUNCTIONPR([](ImDrawList* drawlist, Ogre::Vector2 const& pos, Ogre::ColourValue const& col, std::string const& text) { drawlist->AddText(ImVec2(pos.x, pos.y), ImColor(col.r, col.g, col.b, col.a), text.c_str()); }, (ImDrawList * drawlist, Ogre::Vector2 const&, Ogre::ColourValue const&, std::string const&), void), asCALL_CDECL_OBJFIRST); + + // FUNCTIONS (namespace ImGui) engine->SetDefaultNamespace("ImGui"); engine->RegisterGlobalFunction("bool Begin(const string&in, bool, int=0)", asFUNCTIONPR([](const string& name, bool opened, int flags) { return ImGui::Begin(name.c_str(), &opened, flags); }, (const string&, bool, int), bool), asCALL_CDECL); @@ -73,6 +85,9 @@ void RoR::RegisterImGuiBindings(AngelScript::asIScriptEngine* engine) engine->RegisterGlobalFunction("bool BeginChild(const string&in)", asFUNCTIONPR([](const string& name) { return ImGui::Begin(name.c_str()); }, (const string&), bool), asCALL_CDECL); engine->RegisterGlobalFunction("void EndChild()", asFUNCTIONPR(ImGui::EndChild, (), void), asCALL_CDECL); + engine->RegisterGlobalFunction("ImDrawList@ GetWindowDrawList()", asFUNCTIONPR(ImGui::GetWindowDrawList, (), ImDrawList*), asCALL_CDECL); + engine->RegisterGlobalFunction("void PushStyleColor(int index, const color&in color)", asFUNCTIONPR([](int index, Ogre::ColourValue const& col) { ImGui::PushStyleColor(index, (ImU32)ImColor(col.r, col.g, col.b, col.a)); }, (int, Ogre::ColourValue const&), void), asCALL_CDECL); + engine->RegisterGlobalFunction("void PopStyleColor(int count)", asFUNCTIONPR(ImGui::PopStyleColor, (int), void), asCALL_CDECL); engine->RegisterGlobalFunction("vector2 GetContentRegionMax()", asFUNCTIONPR([]() { auto v = ImGui::GetContentRegionMax(); return Vector2(v.x, v.y); }, (), Vector2), asCALL_CDECL); From 83e305f41480121008058366de1d032371f12915 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 13 Aug 2022 04:37:32 +0200 Subject: [PATCH 07/12] AngelScript: added supporting API for ImGui drawing. --- doc/angelscript/Script2Game/GameScriptClass.h | 69 ++++++++++++------- source/main/scripting/GameScript.cpp | 37 ++++++++++ source/main/scripting/GameScript.h | 19 +++++ .../bindings/GameScriptAngelscript.cpp | 3 + .../scripting/bindings/OgreAngelscript.cpp | 2 + source/main/utils/InputEngine.cpp | 9 +++ source/main/utils/InputEngine.h | 1 + 7 files changed, 115 insertions(+), 25 deletions(-) diff --git a/doc/angelscript/Script2Game/GameScriptClass.h b/doc/angelscript/Script2Game/GameScriptClass.h index c00e41298a..5dfc63f7c2 100644 --- a/doc/angelscript/Script2Game/GameScriptClass.h +++ b/doc/angelscript/Script2Game/GameScriptClass.h @@ -21,11 +21,11 @@ namespace Script2Game { /** \addtogroup ScriptSideAPIs * @{ - */ + */ /** \addtogroup Script2Game * @{ - */ + */ /** * @brief Binding of RoR::GameScript; A general class that will provide you with general functions. @@ -63,7 +63,7 @@ class GameScriptClass /** * Sends or request information from the master server */ - int useOnlineAPI(const string apiquery, const dictionary dict, string result); + int useOnlineAPI(const string apiquery, const dictionary dict, string result); /** * Gets the Curent frames per second (FPS) @@ -75,7 +75,7 @@ class GameScriptClass * Gets the average frames per second (FPS) * @return The average FPS */ - void getAvgFPS(); + void getAvgFPS(); /** * Back to menu @@ -85,13 +85,13 @@ class GameScriptClass /** * Quits the game */ - void quitGame(); + void quitGame(); /// @} /// @name GUI /// @{ - + /** * shows a message to the user * @deprecated Use the game.message function instead. @@ -109,7 +109,7 @@ class GameScriptClass * @param forceVisible Set this to true if you want the message to be forced on the user's screen (~it will show, even when the GUI is hidden). */ void message(string txt, string icon, float timeMilliseconds, bool forceVisible); - + /** * OBSOLETE - returns 0. * @deprecated @@ -122,8 +122,8 @@ class GameScriptClass * @deprecated * @param size font size in pixels */ - void setChatFontSize(int size); - + void setChatFontSize(int size); + /** * Shows a message box * @@ -156,7 +156,7 @@ class GameScriptClass * @param box the name of the box in which the truck will be spawned */ void showChooser(string type, string instance, string box); - + /** * set direction arrow * @param text text to be displayed. "" to hide the text @@ -169,13 +169,25 @@ class GameScriptClass * Hides the direction arrow * @see UpdateDirectionArrow */ - void hideDirectionArrow(); + void hideDirectionArrow(); + + /** + * @param world_pos The world position to be converted, in meters. + * @param out_screen_pos The resulting screen position, in pixels. + * @return true if the world position is in front of the camera and the resulting screen position is valid. + */ + bool getScreenPosFromWorldPos(const vector3&in, vector2&out); + + /** + * Gets screen size in pixels. + */ + vector2 getDisplaySize(); /// @} /// @name Script management /// @{ - + /** * registers for a new event to be received by the scripting system * @param eventValue \see enum scriptEvents @@ -186,7 +198,7 @@ class GameScriptClass * unregisters from receiving event. * @param eventValue \see enum scriptEvents */ - void unRegisterEvent(int eventValue); + void unRegisterEvent(int eventValue); /** * Adds a global function to the script. @@ -216,12 +228,12 @@ class GameScriptClass * Removes a global variable from the script. * @param var the declaration of the variable that should be removed, e.g.: "int missionState;" */ - int deleteScriptVariable(const string var); + int deleteScriptVariable(const string var); /** * Clears the event cache */ - void clearEventCache(); + void clearEventCache(); /// @} @@ -248,13 +260,13 @@ class GameScriptClass /** * Gets the currently loaded terrain instance */ - TerrainClass@ getTerrain(); + TerrainClass@ getTerrain(); /** * Checks if Caleum is enabled. * @return true if Caleum is available */ - bool getCaelumAvailable(); + bool getCaelumAvailable(); /** * gets the time of the day in seconds @@ -266,7 +278,7 @@ class GameScriptClass * sets the time of the day in seconds * @param value day time in seconds */ - void setCaelumTime(float value); + void setCaelumTime(float value); /** * returns the currently set upo gravity @@ -278,7 +290,7 @@ class GameScriptClass * sets the gravity terrain wide. This is an expensive call, since the masses of all trucks are recalculated. * @param value new gravity terrain wide (default is -9.81) */ - void setGravity(float value); + void setGravity(float value); /** * returns the current base water level (without waves) @@ -297,7 +309,7 @@ class GameScriptClass * sets the base water height * @param value base height in meters */ - void setWaterHeight(float value); + void setWaterHeight(float value); /** * This spawns an object @@ -323,7 +335,14 @@ class GameScriptClass * @param instanceName The unique name that you chose when spawning this object * @see spawnObject */ - void destroyObject(const string instanceName); + void destroyObject(const string instanceName); + + /** + * Calculates mouse cursor position on terrain. + * @param out_pos Calculated position, in meters. + * @return true if mouse points to the terrain and output coordinates are valid. + */ + bool getMousePositionOnTerrain(vector3 &out); /// @} @@ -334,7 +353,7 @@ class GameScriptClass * Returns the current position of the person * @return A vector containing the X, Y and Z coordinate of the person or an empty vector if the user is in a truck */ - vector3 getPersonPosition(); + vector3 getPersonPosition(); /** * sets the character position @@ -394,7 +413,7 @@ class GameScriptClass * @param rot The rotation in which the truck should be spawned * @return reference to Beam object */ - BeamClass @spawnTruck(stringtruckName, vector3 pos, vector3 rot); + BeamClass @spawnTruck(stringtruckName, vector3 pos, vector3 rot); /** * This method repairs the vehicle in the box @@ -409,13 +428,13 @@ class GameScriptClass /** * Number of trucks with flag */ - int getNumTrucksByFlag(int flag); + int getNumTrucksByFlag(int flag); /** * Gives the currently used truck a boost in RPM. * @param factor This factor determines by how much that the RPM of the truck will be increased ( rpm += 2000.0f * factor ). */ - void boostCurrentTruck(float factor); + void boostCurrentTruck(float factor); ///@} diff --git a/source/main/scripting/GameScript.cpp b/source/main/scripting/GameScript.cpp index e66dfa8bf8..19197ff736 100644 --- a/source/main/scripting/GameScript.cpp +++ b/source/main/scripting/GameScript.cpp @@ -51,6 +51,7 @@ #include "ScriptEngine.h" #include "SkyManager.h" #include "TerrainManager.h" +#include "TerrainGeometryManager.h" #include "TerrainObjectManager.h" #include "Utils.h" #include "Water.h" @@ -454,6 +455,27 @@ void GameScript::hideDirectionArrow() App::GetGameContext()->GetRaceSystem().UpdateDirectionArrow(0, Vector3::ZERO); } +bool GameScript::getScreenPosFromWorldPos(Ogre::Vector3 const& world_pos, Ogre::Vector2& out_screen) +{ + ImVec2 screen_size = ImGui::GetIO().DisplaySize; + World2ScreenConverter world2screen( + App::GetCameraManager()->GetCamera()->getViewMatrix(true), App::GetCameraManager()->GetCamera()->getProjectionMatrix(), Ogre::Vector2(screen_size.x, screen_size.y)); + Ogre::Vector3 pos_xyz = world2screen.Convert(world_pos); + if (pos_xyz.z < 0.f) + { + out_screen.x = pos_xyz.x; + out_screen.y = pos_xyz.y; + return true; + } + return false; +} + +Ogre::Vector2 GameScript::getDisplaySize() +{ + ImVec2 size = ImGui::GetIO().DisplaySize; + return Vector2(size.x, size.y); +} + int GameScript::setMaterialAmbient(const String& materialName, float red, float green, float blue) { try @@ -934,6 +956,21 @@ float GameScript::getAvgFPS() return App::GetAppContext()->GetRenderWindow()->getStatistics().avgFPS; } +bool GameScript::getMousePositionOnTerrain(Ogre::Vector3& out_pos) +{ + if (!HaveSimTerrain(__FUNCTION__)) + return false; + + Ogre::Vector2 mouse_npos = App::GetInputEngine()->getMouseNormalizedScreenPos(); + Ogre::Ray ray = App::GetCameraManager()->GetCamera()->getCameraToViewportRay(mouse_npos.x, mouse_npos.y); + Ogre::TerrainGroup::RayResult ray_result = App::GetSimTerrain()->getGeometryManager()->getTerrainGroup()->rayIntersects(ray); + if (ray_result.hit) + { + out_pos = ray_result.position; + } + return ray_result.hit; +} + bool GameScript::HaveSimTerrain(const char* func_name) { if (App::GetSimTerrain() == nullptr) diff --git a/source/main/scripting/GameScript.h b/source/main/scripting/GameScript.h index 5b69aaf6a9..aa6c8dbc98 100644 --- a/source/main/scripting/GameScript.h +++ b/source/main/scripting/GameScript.h @@ -104,6 +104,18 @@ class GameScript : public ZeroedMemoryAllocator void hideDirectionArrow(); + /** + * @param world_pos The world position to be converted, in meters. + * @param out_screen_pos The resulting screen position, in pixels. + * @return true if the world position is in front of the camera and the resulting screen position is valid. + */ + bool getScreenPosFromWorldPos(Ogre::Vector3 const& world_pos, Ogre::Vector2& out_screen_pos); + + /** + * Gets screen size in pixels. + */ + Ogre::Vector2 getDisplaySize(); + /// @} /// @name Script management @@ -245,6 +257,13 @@ class GameScript : public ZeroedMemoryAllocator */ void destroyObject(const Ogre::String& instanceName); + /** + * Calculates mouse cursor position on terrain. + * @param out_pos Calculated position, in meters. + * @return true if mouse points to the terrain and output coordinates are valid. + */ + bool getMousePositionOnTerrain(Ogre::Vector3& out_pos); + /// @} /// @name Character diff --git a/source/main/scripting/bindings/GameScriptAngelscript.cpp b/source/main/scripting/bindings/GameScriptAngelscript.cpp index c4d13fe471..2211396e4f 100644 --- a/source/main/scripting/bindings/GameScriptAngelscript.cpp +++ b/source/main/scripting/bindings/GameScriptAngelscript.cpp @@ -53,6 +53,8 @@ void RoR::RegisterGameScript(asIScriptEngine *engine) result = engine->RegisterObjectMethod("GameScriptClass", "void showChooser(const string &in, const string &in, const string &in)", asMETHOD(GameScript, showChooser), asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("GameScriptClass", "void updateDirectionArrow(const string &in, vector3 &in)", asMETHOD(GameScript, updateDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("GameScriptClass", "void hideDirectionArrow()", asMETHOD(GameScript, hideDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "bool getScreenPosFromWorldPos(const vector3&in, vector2&out)", AngelScript::asMETHOD(GameScript, getScreenPosFromWorldPos), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector2 getDisplaySize()", AngelScript::asMETHOD(GameScript, getDisplaySize), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); // > Script management result = engine->RegisterObjectMethod("GameScriptClass", "void registerForEvent(int)", asMETHOD(GameScript, registerForEvent), asCALL_THISCALL); ROR_ASSERT(result >= 0); @@ -79,6 +81,7 @@ void RoR::RegisterGameScript(asIScriptEngine *engine) result = engine->RegisterObjectMethod("GameScriptClass", "void spawnObject(const string &in, const string &in, vector3 &in, vector3 &in, const string &in, bool)", asMETHOD(GameScript, spawnObject), asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("GameScriptClass", "void moveObjectVisuals(const string &in, vector3 &in)", asMETHOD(GameScript, moveObjectVisuals), asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("GameScriptClass", "void destroyObject(const string &in)", asMETHOD(GameScript, destroyObject), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "bool getMousePositionOnTerrain(vector3 &out)", AngelScript::asMETHOD(GameScript, getMousePositionOnTerrain), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); // > Character result = engine->RegisterObjectMethod("GameScriptClass", "vector3 getPersonPosition()", asMETHOD(GameScript, getPersonPosition), asCALL_THISCALL); ROR_ASSERT(result >= 0); diff --git a/source/main/scripting/bindings/OgreAngelscript.cpp b/source/main/scripting/bindings/OgreAngelscript.cpp index 55121f6392..1bf4da447b 100644 --- a/source/main/scripting/bindings/OgreAngelscript.cpp +++ b/source/main/scripting/bindings/OgreAngelscript.cpp @@ -223,6 +223,7 @@ void registerOgreRadian(AngelScript::asIScriptEngine* engine); void registerOgreDegree(AngelScript::asIScriptEngine* engine); void registerOgreQuaternion(AngelScript::asIScriptEngine* engine); void registerOgreTexture(AngelScript::asIScriptEngine* engine); +void registerOgreColourValue(AngelScript::asIScriptEngine* engine); // main registration method void RoR::RegisterOgreObjects(AngelScript::asIScriptEngine* engine) @@ -261,6 +262,7 @@ void RoR::RegisterOgreObjects(AngelScript::asIScriptEngine* engine) registerOgreVector2(engine); registerOgreQuaternion(engine); registerOgreTexture(engine); + registerOgreColourValue(engine); } // register Ogre::Vector3 diff --git a/source/main/utils/InputEngine.cpp b/source/main/utils/InputEngine.cpp index fc2161d82b..27d29a7e0d 100644 --- a/source/main/utils/InputEngine.cpp +++ b/source/main/utils/InputEngine.cpp @@ -1622,6 +1622,15 @@ int InputEngine::getCurrentPovValue(int& joystickNumber, int& pov, int& povdir) return 0; } +Ogre::Vector2 InputEngine::getMouseNormalizedScreenPos() +{ + OIS::MouseState const& mstate = mMouse->getMouseState(); + Ogre::Vector2 res; + res.x = static_cast(mstate.X.abs) / static_cast(mstate.width); + res.y = static_cast(mstate.Y.abs) / static_cast(mstate.height); + return res; +} + event_trigger_t InputEngine::newEvent() { event_trigger_t res; diff --git a/source/main/utils/InputEngine.h b/source/main/utils/InputEngine.h index 7ce200d396..566c87c21b 100644 --- a/source/main/utils/InputEngine.h +++ b/source/main/utils/InputEngine.h @@ -528,6 +528,7 @@ class InputEngine : public ZeroedMemoryAllocator int getCurrentKeyCombo(Ogre::String* combo); //!< Returns number of non-modifier keys pressed (or modifier count as negative number). int getCurrentJoyButton(int& joystickNumber, int& button); int getCurrentPovValue(int& joystickNumber, int& pov, int& povdir); + Ogre::Vector2 getMouseNormalizedScreenPos(); //!< Returns XY position in range from 0 (top/left) to 1 (bottom/right) // Event utils From 3fc27fbdd07132a515d74185c98e90d697f54df1 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 11 Jul 2022 01:18:31 +0200 Subject: [PATCH 08/12] Added `ImGui::PlotLines()` AngelScript binding. --- source/main/scripting/ScriptEngine.cpp | 4 +++- .../scripting/bindings/ImGuiAngelscript.cpp | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/source/main/scripting/ScriptEngine.cpp b/source/main/scripting/ScriptEngine.cpp index 370ff6d68e..9942459528 100644 --- a/source/main/scripting/ScriptEngine.cpp +++ b/source/main/scripting/ScriptEngine.cpp @@ -139,6 +139,8 @@ void ScriptEngine::init() AngelScript::RegisterStdString(engine); AngelScript::RegisterStdStringUtils(engine); AngelScript::RegisterScriptMath(engine); + static float SCRIPT_FLT_MAX = FLT_MAX; + result = engine->RegisterGlobalProperty("const float FLT_MAX", &SCRIPT_FLT_MAX); ROR_ASSERT( result >= 0 ); AngelScript::RegisterScriptAny(engine); AngelScript::RegisterScriptDictionary(engine); @@ -607,7 +609,7 @@ int ScriptEngine::setupScriptUnit(int unit_id) if ( result < 0 ) { App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_ERROR, - fmt::format("Could not load script '{}' - failed to build module.", moduleName)); + fmt::format("Could not load script '{}' - failed to build module. See 'Angelscript.log' for more info.", moduleName)); return result; } diff --git a/source/main/scripting/bindings/ImGuiAngelscript.cpp b/source/main/scripting/bindings/ImGuiAngelscript.cpp index d347de13a6..72529918d5 100644 --- a/source/main/scripting/bindings/ImGuiAngelscript.cpp +++ b/source/main/scripting/bindings/ImGuiAngelscript.cpp @@ -36,6 +36,20 @@ using namespace AngelScript; using namespace Ogre; using namespace std; +float ImGuiPlotLinesScriptValueGetterFunc(void* data, int index) +{ + CScriptArray* array_obj = static_cast(data); + void* value_raw = array_obj->At(index); + if (value_raw == nullptr) + { + return 0.f; // out of bounds + } + else + { + return *static_cast(value_raw); + } +} + void RoR::RegisterImGuiBindings(AngelScript::asIScriptEngine* engine) { // ENUMS (global namespace) @@ -487,6 +501,13 @@ void RoR::RegisterImGuiBindings(AngelScript::asIScriptEngine* engine) engine->RegisterGlobalFunction("string GetClipboardText()", asFUNCTIONPR([]() { return string(ImGui::GetClipboardText()); }, (), string), asCALL_CDECL); engine->RegisterGlobalFunction("void SetClipboardText(const string&in)", asFUNCTIONPR([](const string& a) { ImGui::SetClipboardText(a.empty() ? a.c_str() : 0x0); }, (const string&), void), asCALL_CDECL); + // Data plotting - we wrap the 'getter func' variant to resemble the 'float*' variant. + // PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float)); + engine->RegisterGlobalFunction("void PlotLines(const string&in label, array&in values, int values_count, int values_offset = 0, const string&in overlay_text = string(), float scale_min = FLT_MAX, float scale_max = FLT_MAX, vector2 graph_size = vector2(0,0))", + asFUNCTIONPR([](const string& label, CScriptArray* values, int values_count, int values_offset, const string& overlay_text, float scale_min, float scale_max, Vector2 graph_size) + { ImGui::PlotLines(label.c_str(), &ImGuiPlotLinesScriptValueGetterFunc, values, values_count, values_offset, overlay_text.c_str(), scale_min, scale_max, ImVec2(graph_size.x, graph_size.y)); }, + (const string&, CScriptArray*, int, int, const string&, float, float, Vector2), void), asCALL_CDECL); + engine->SetDefaultNamespace(""); } From 45baf29641d008946ac93cca34db0c9b00e48294 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 13 Aug 2022 15:19:10 +0200 Subject: [PATCH 09/12] AngelScript: added `game.getMouseScreenPosition()`, `INT_MAX` --- source/main/scripting/GameScript.cpp | 6 ++++++ source/main/scripting/GameScript.h | 5 +++++ source/main/scripting/ScriptEngine.cpp | 2 ++ source/main/scripting/bindings/GameScriptAngelscript.cpp | 1 + 4 files changed, 14 insertions(+) diff --git a/source/main/scripting/GameScript.cpp b/source/main/scripting/GameScript.cpp index 19197ff736..6ef2437bdf 100644 --- a/source/main/scripting/GameScript.cpp +++ b/source/main/scripting/GameScript.cpp @@ -476,6 +476,12 @@ Ogre::Vector2 GameScript::getDisplaySize() return Vector2(size.x, size.y); } +Ogre::Vector2 GameScript::getMouseScreenPosition() +{ + ImVec2 pos = ImGui::GetIO().MousePos; + return Vector2(pos.x, pos.y); +} + int GameScript::setMaterialAmbient(const String& materialName, float red, float green, float blue) { try diff --git a/source/main/scripting/GameScript.h b/source/main/scripting/GameScript.h index aa6c8dbc98..8335b9ed5a 100644 --- a/source/main/scripting/GameScript.h +++ b/source/main/scripting/GameScript.h @@ -116,6 +116,11 @@ class GameScript : public ZeroedMemoryAllocator */ Ogre::Vector2 getDisplaySize(); + /** + * Gets mouse position in pixels. + */ + Ogre::Vector2 getMouseScreenPosition(); + /// @} /// @name Script management diff --git a/source/main/scripting/ScriptEngine.cpp b/source/main/scripting/ScriptEngine.cpp index 9942459528..06fa07d0f0 100644 --- a/source/main/scripting/ScriptEngine.cpp +++ b/source/main/scripting/ScriptEngine.cpp @@ -140,7 +140,9 @@ void ScriptEngine::init() AngelScript::RegisterStdStringUtils(engine); AngelScript::RegisterScriptMath(engine); static float SCRIPT_FLT_MAX = FLT_MAX; + static int SCRIPT_INT_MAX = INT_MAX; result = engine->RegisterGlobalProperty("const float FLT_MAX", &SCRIPT_FLT_MAX); ROR_ASSERT( result >= 0 ); + result = engine->RegisterGlobalProperty("const int INT_MAX", &SCRIPT_INT_MAX); ROR_ASSERT(result >= 0); AngelScript::RegisterScriptAny(engine); AngelScript::RegisterScriptDictionary(engine); diff --git a/source/main/scripting/bindings/GameScriptAngelscript.cpp b/source/main/scripting/bindings/GameScriptAngelscript.cpp index 2211396e4f..4669816a14 100644 --- a/source/main/scripting/bindings/GameScriptAngelscript.cpp +++ b/source/main/scripting/bindings/GameScriptAngelscript.cpp @@ -55,6 +55,7 @@ void RoR::RegisterGameScript(asIScriptEngine *engine) result = engine->RegisterObjectMethod("GameScriptClass", "void hideDirectionArrow()", asMETHOD(GameScript, hideDirectionArrow), asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("GameScriptClass", "bool getScreenPosFromWorldPos(const vector3&in, vector2&out)", AngelScript::asMETHOD(GameScript, getScreenPosFromWorldPos), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("GameScriptClass", "vector2 getDisplaySize()", AngelScript::asMETHOD(GameScript, getDisplaySize), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("GameScriptClass", "vector2 getMouseScreenPosition()", AngelScript::asMETHOD(GameScript, getMouseScreenPosition), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0); // > Script management result = engine->RegisterObjectMethod("GameScriptClass", "void registerForEvent(int)", asMETHOD(GameScript, registerForEvent), asCALL_THISCALL); ROR_ASSERT(result >= 0); From a1a66ed6ed32ad8a2323c4e1ce954ad87a3a0a6a Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sun, 14 Aug 2022 01:01:42 +0200 Subject: [PATCH 10/12] Console: added script monitor UI and `loadscript` cmd. --- source/main/CMakeLists.txt | 1 + source/main/gui/panels/GUI_ConsoleWindow.cpp | 8 ++ source/main/gui/panels/GUI_ConsoleWindow.h | 14 ++- source/main/gui/panels/GUI_ScriptMonitor.cpp | 95 ++++++++++++++++++++ source/main/gui/panels/GUI_ScriptMonitor.h | 33 +++++++ source/main/scripting/ScriptEngine.h | 2 +- source/main/system/ConsoleCmd.cpp | 41 +++++++++ 7 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 source/main/gui/panels/GUI_ScriptMonitor.cpp create mode 100644 source/main/gui/panels/GUI_ScriptMonitor.h diff --git a/source/main/CMakeLists.txt b/source/main/CMakeLists.txt index 92e0a2d912..5c5ceea7b1 100644 --- a/source/main/CMakeLists.txt +++ b/source/main/CMakeLists.txt @@ -135,6 +135,7 @@ set(SOURCE_FILES gui/panels/GUI_MultiplayerClientList.{h,cpp} gui/panels/GUI_NodeBeamUtils.{h,cpp} gui/panels/GUI_SimActorStats.{h,cpp} + gui/panels/GUI_ScriptMonitor.{h,cpp} gui/panels/GUI_SimPerfStats.{h,cpp} gui/panels/GUI_SurveyMap.{h,cpp} gui/panels/GUI_VehicleDescription.{h,cpp} diff --git a/source/main/gui/panels/GUI_ConsoleWindow.cpp b/source/main/gui/panels/GUI_ConsoleWindow.cpp index ef5915d15e..541aef5a18 100644 --- a/source/main/gui/panels/GUI_ConsoleWindow.cpp +++ b/source/main/gui/panels/GUI_ConsoleWindow.cpp @@ -89,6 +89,14 @@ void ConsoleWindow::Draw() ImGui::Columns(1); // reset ImGui::EndMenu(); } + ImGui::SetNextWindowSize(ImVec2(0.f, 0.f)); // reset to auto-fit + + if (ImGui::BeginMenu(_LC("Console", "Script Monitor"))) + { + ImGui::Dummy(ImVec2(340.f, 1.f)); // Manually resize width (DearIMGUI bug workaround) + m_script_monitor.Draw(); + ImGui::EndMenu(); + } #endif ImGui::EndMenuBar(); } diff --git a/source/main/gui/panels/GUI_ConsoleWindow.h b/source/main/gui/panels/GUI_ConsoleWindow.h index 10e8bbe0ba..c89fb5e5b0 100644 --- a/source/main/gui/panels/GUI_ConsoleWindow.h +++ b/source/main/gui/panels/GUI_ConsoleWindow.h @@ -29,6 +29,7 @@ #include "GUI_ConsoleView.h" #include "OgreImGui.h" #include "GUI_AngelScriptExamples.h" +#include "GUI_ScriptMonitor.h" #include #include @@ -51,17 +52,22 @@ class ConsoleWindow private: - AngelScriptExamples m_angelscript_examples; - static int TextEditCallback(ImGuiTextEditCallbackData *data); void TextEditCallbackProc(ImGuiTextEditCallbackData *data); + // Window state + bool m_is_visible = false; + bool m_is_hovered = false; + + // Special panels + AngelScriptExamples m_angelscript_examples; + ScriptMonitor m_script_monitor; + + // Console context ConsoleView m_console_view; Str<500> m_cmd_buffer; std::vector m_cmd_history; int m_cmd_history_cursor = -1; - bool m_is_visible = false; - bool m_is_hovered = false; }; } // namespace GUI diff --git a/source/main/gui/panels/GUI_ScriptMonitor.cpp b/source/main/gui/panels/GUI_ScriptMonitor.cpp new file mode 100644 index 0000000000..c337fdb60b --- /dev/null +++ b/source/main/gui/panels/GUI_ScriptMonitor.cpp @@ -0,0 +1,95 @@ +/* + This source file is part of Rigs of Rods + Copyright 2021 tritonas00 + For more information, see http://www.rigsofrods.org/ + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + + +#include "GUI_ScriptMonitor.h" + +#include "ContentManager.h" +#include "ScriptEngine.h" + +#include + +using namespace RoR; +using namespace GUI; + +void ScriptMonitor::Draw() +{ + // Table setup + ImGui::Columns(3); + ImGui::SetColumnWidth(0, 30); + ImGui::SetColumnWidth(1, 200); + ImGui::SetColumnWidth(2, 100); + + // Header + ImGui::TextDisabled("ID"); + ImGui::NextColumn(); + ImGui::TextDisabled("File name"); + ImGui::NextColumn(); + ImGui::TextDisabled("Options"); + + ImGui::Separator(); + + ScriptUnitId_t id_to_reload = SCRIPTUNITID_INVALID; + ScriptUnitId_t id_to_stop = SCRIPTUNITID_INVALID; + + for (auto& pair : App::GetScriptEngine()->getScriptUnits()) + { + ScriptUnitId_t id = pair.first; + ScriptUnit const& unit = pair.second; + ImGui::NextColumn(); + ImGui::TextDisabled("%d", id); + ImGui::NextColumn(); + ImGui::Text("%s", unit.scriptName.c_str()); + ImGui::NextColumn(); + switch (unit.scriptCategory) + { + case ScriptCategory::TERRAIN: + ImGui::Text("(terrain)"); + break; + + case ScriptCategory::CUSTOM: + if (ImGui::Button("Reload")) + { + // Reloading here would mess up the hashmap we're iterating (plus invalidate the iterator). + id_to_reload = id; + } + ImGui::SameLine(); + if (ImGui::Button("Stop")) + { + // Stopping here would mess up the hashmap we're iterating (plus invalidate the iterator). + id_to_stop = id; + } + break; + default:; + } + } + + ImGui::Columns(1); // reset + + if (id_to_reload != SCRIPTUNITID_INVALID) + { + // Back up the data, the ScriptUnit object will be invalidated! + ScriptUnit const& unit = App::GetScriptEngine()->getScriptUnit(id_to_reload); + std::string filename = unit.scriptName; + ScriptCategory category = unit.scriptCategory; + App::GetScriptEngine()->unloadScript(id_to_reload); + App::GetScriptEngine()->loadScript(filename, category); + } + + if (id_to_stop != SCRIPTUNITID_INVALID) + { + App::GetScriptEngine()->unloadScript(id_to_stop); + } +} diff --git a/source/main/gui/panels/GUI_ScriptMonitor.h b/source/main/gui/panels/GUI_ScriptMonitor.h new file mode 100644 index 0000000000..ab5c0d7689 --- /dev/null +++ b/source/main/gui/panels/GUI_ScriptMonitor.h @@ -0,0 +1,33 @@ +/* + This source file is part of Rigs of Rods + Copyright 2021 tritonas00 + For more information, see http://www.rigsofrods.org/ + Rigs of Rods is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + Rigs of Rods is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Rigs of Rods. If not, see . +*/ + +/// @file + +#pragma once + +#include "Application.h" + +namespace RoR { +namespace GUI { + +class ScriptMonitor +{ +public: + void Draw(); +private: +}; + +} // namespace GUI +} // namespace RoR \ No newline at end of file diff --git a/source/main/scripting/ScriptEngine.h b/source/main/scripting/ScriptEngine.h index 00f7302634..cc97a94167 100644 --- a/source/main/scripting/ScriptEngine.h +++ b/source/main/scripting/ScriptEngine.h @@ -176,7 +176,7 @@ class ScriptEngine : public Ogre::LogListener, public ZeroedMemoryAllocator ScriptUnit& getScriptUnit(ScriptUnitId_t unique_id); ScriptUnitId_t getTerrainScriptUnit() const { return m_terrain_script_unit; } //!< @return SCRIPTUNITID_INVALID if none exists. ScriptUnitId_t getCurrentlyExecutingScriptUnit() const { return m_currently_executing_script_unit; } //!< @return SCRIPTUNITID_INVALID if none is executing right now. - + ScriptUnitMap const& getScriptUnits() const { return m_script_units; } protected: diff --git a/source/main/system/ConsoleCmd.cpp b/source/main/system/ConsoleCmd.cpp index e0cc748f60..1baab5e865 100644 --- a/source/main/system/ConsoleCmd.cpp +++ b/source/main/system/ConsoleCmd.cpp @@ -388,6 +388,46 @@ class HelpCmd: public ConsoleCmd } }; +class LoadScriptCmd : public ConsoleCmd +{ +public: + LoadScriptCmd() : ConsoleCmd("loadscript", "[filename]", _L("Runs an AngelScript file")) {} + + void Run(Ogre::StringVector const& args) override + { + Str<200> reply; + reply << m_name << ": "; + Console::MessageType reply_type; + +#ifdef USE_ANGELSCRIPT + if (args.size() == 1) + { + reply_type = Console::CONSOLE_SYSTEM_ERROR; + reply << _L("Missing parameter: ") << m_usage; + } + else + { + ScriptUnitId_t id = App::GetScriptEngine()->loadScript(args[1], ScriptCategory::CUSTOM); + if (id == SCRIPTUNITID_INVALID) + { + reply_type = Console::CONSOLE_SYSTEM_ERROR; + reply << _L("Failed to load script. See 'Angelscript.log' or use console command `log` and retry."); + } + else + { + reply_type = Console::CONSOLE_SYSTEM_REPLY; + reply << fmt::format(_L("Script '{}' running with ID '{}'"), args[1], id); + } + } +#else + reply_type = Console::CONSOLE_SYSTEM_ERROR; + reply << _L("Scripting disabled in this build"); +#endif + + App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, reply_type, reply.ToCStr()); + } +}; + // ------------------------------------------------------------------------------------- // CVar (builtin) console commmands @@ -620,6 +660,7 @@ void Console::regBuiltinCommands() cmd = new HelpCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd)); // Additions cmd = new ClearCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd)); + cmd = new LoadScriptCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd)); // CVars cmd = new SetCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd)); cmd = new SetstringCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd)); From f37303bd17eb1d6b9db56d6089a6df452cd40d89 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sun, 14 Aug 2022 01:59:43 +0200 Subject: [PATCH 11/12] Main menu UI: disable key navigation when other window (i.e. Console) has focus. --- source/main/gui/panels/GUI_GameMainMenu.cpp | 43 +++++++++++++-------- source/main/gui/panels/GUI_GameMainMenu.h | 1 + 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/source/main/gui/panels/GUI_GameMainMenu.cpp b/source/main/gui/panels/GUI_GameMainMenu.cpp index 4d472b035e..7b929f3182 100644 --- a/source/main/gui/panels/GUI_GameMainMenu.cpp +++ b/source/main/gui/panels/GUI_GameMainMenu.cpp @@ -82,20 +82,6 @@ void GameMainMenu::DrawMenuPanel() } } - // Keyboard updates - move up/down and wrap on top/bottom. Initial index is '-1' which means "no focus" - if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow))) - { - m_kb_focus_index = (m_kb_focus_index <= 0) ? (m_num_buttons - 1) : (m_kb_focus_index - 1); - } - if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow))) - { - m_kb_focus_index = (m_kb_focus_index < (m_num_buttons - 1)) ? (m_kb_focus_index + 1) : 0; - } - if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter))) - { - m_kb_enter_index = m_kb_focus_index; - } - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, BUTTON_PADDING); ImGui::PushStyleColor(ImGuiCol_TitleBg, ImGui::GetStyle().Colors[ImGuiCol_TitleBgActive]); ImGui::PushStyleColor(ImGuiCol_WindowBg, WINDOW_BG_COLOR); @@ -119,6 +105,8 @@ void GameMainMenu::DrawMenuPanel() int flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize; if (ImGui::Begin(_LC("MainMenu", title), nullptr, static_cast(flags))) { + this->HandleInputEvents(); + int button_index = 0; ImVec2 btn_size(WINDOW_WIDTH, 0.f); @@ -229,7 +217,7 @@ void GameMainMenu::DrawMenuPanel() cache_updated = false; } - App::GetGuiManager()->RequestGuiCaptureKeyboard(ImGui::IsWindowHovered()); + App::GetGuiManager()->RequestGuiCaptureKeyboard(ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows)); ImGui::End(); ImGui::PopStyleVar(); ImGui::PopStyleColor(3); @@ -295,4 +283,27 @@ void GameMainMenu::DrawNoticeBox() bool GameMainMenu::HighlightButton(const std::string& txt,ImVec2 btn_size, int index) const{ std::string button_txt = (m_kb_focus_index == index) ? fmt::format("--> {} <--", txt) : txt; return ImGui::Button(button_txt.c_str(), btn_size) || (m_kb_enter_index == index); -} \ No newline at end of file +} + +void GameMainMenu::HandleInputEvents() +{ + // Only handle keystrokes if keyboard capture is not requested or requested by us. + bool kb_capture_req = App::GetGuiManager()->IsGuiCaptureKeyboardRequested(); + bool window_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); + if (!kb_capture_req || window_hovered) + { + // Keyboard updates - move up/down and wrap on top/bottom. Initial index is '-1' which means "no focus" + if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow))) + { + m_kb_focus_index = (m_kb_focus_index <= 0) ? (m_num_buttons - 1) : (m_kb_focus_index - 1); + } + if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow))) + { + m_kb_focus_index = (m_kb_focus_index < (m_num_buttons - 1)) ? (m_kb_focus_index + 1) : 0; + } + if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter))) + { + m_kb_enter_index = m_kb_focus_index; + } + } +} diff --git a/source/main/gui/panels/GUI_GameMainMenu.h b/source/main/gui/panels/GUI_GameMainMenu.h index a90a007638..573d553b40 100644 --- a/source/main/gui/panels/GUI_GameMainMenu.h +++ b/source/main/gui/panels/GUI_GameMainMenu.h @@ -50,6 +50,7 @@ class GameMainMenu void DrawVersionBox(); void DrawNoticeBox(); bool HighlightButton(const std::string &text, ImVec2 btn_size, int index) const; + void HandleInputEvents(); bool m_is_visible = false; int m_num_buttons; int m_kb_focus_index = -1; // -1 = no focus; 0+ = button index From 6d2b6f3cb4ad0ab749e0da7acca66330bca34d13 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sun, 7 Aug 2022 18:09:32 +0200 Subject: [PATCH 12/12] Renamed `TerrainManager` (misleading) to `Terrain` (exact). --- source/main/Application.cpp | 6 +- source/main/Application.h | 4 +- source/main/CMakeLists.txt | 2 +- source/main/ForwardDeclarations.h | 2 +- source/main/GameContext.cpp | 4 +- source/main/GameContext.h | 2 +- source/main/gameplay/AutoPilot.cpp | 2 +- source/main/gameplay/Character.cpp | 2 +- source/main/gameplay/Landusemap.cpp | 2 +- source/main/gameplay/ProceduralRoad.cpp | 2 +- source/main/gfx/DustPool.cpp | 2 +- source/main/gfx/EnvironmentMap.cpp | 2 +- source/main/gfx/GfxActor.cpp | 2 +- source/main/gfx/GfxScene.cpp | 4 +- source/main/gfx/HydraxWater.cpp | 2 +- source/main/gfx/SkyManager.cpp | 2 +- source/main/gfx/SkyXManager.cpp | 2 +- source/main/gfx/SurveyMapTextureCreator.cpp | 2 +- source/main/gfx/Water.cpp | 2 +- source/main/gfx/camera/CameraManager.cpp | 2 +- source/main/gui/GUIManager.cpp | 2 +- source/main/gui/OverlayWrapper.cpp | 2 +- .../main/gui/panels/GUI_FrictionSettings.cpp | 2 +- source/main/gui/panels/GUI_SurveyMap.cpp | 2 +- source/main/gui/panels/GUI_TopMenubar.cpp | 2 +- source/main/main.cpp | 2 +- source/main/physics/Actor.cpp | 2 +- source/main/physics/ActorForcesEuler.cpp | 2 +- source/main/physics/ActorManager.cpp | 2 +- source/main/physics/ActorSpawner.cpp | 2 +- source/main/physics/Savegame.cpp | 2 +- source/main/physics/collision/Collisions.cpp | 2 +- source/main/physics/water/Buoyance.cpp | 2 +- source/main/physics/water/ScrewProp.cpp | 2 +- source/main/resources/CacheSystem.cpp | 2 +- source/main/scripting/GameScript.cpp | 2 +- source/main/system/ConsoleCmd.cpp | 2 +- .../{TerrainManager.cpp => Terrain.cpp} | 58 +++++++++---------- .../terrain/{TerrainManager.h => Terrain.h} | 8 +-- source/main/terrain/TerrainEditor.cpp | 2 +- .../main/terrain/TerrainGeometryManager.cpp | 10 ++-- source/main/terrain/TerrainGeometryManager.h | 4 +- source/main/terrain/TerrainObjectManager.cpp | 4 +- source/main/terrain/TerrainObjectManager.h | 4 +- 44 files changed, 87 insertions(+), 87 deletions(-) rename source/main/terrain/{TerrainManager.cpp => Terrain.cpp} (89%) rename source/main/terrain/{TerrainManager.h => Terrain.h} (93%) diff --git a/source/main/Application.cpp b/source/main/Application.cpp index 7b863c3ad5..add918157f 100644 --- a/source/main/Application.cpp +++ b/source/main/Application.cpp @@ -60,7 +60,7 @@ static GUIManager* g_gui_manager; static InputEngine* g_input_engine; static CacheSystem* g_cache_system; static MumbleIntegration* g_mumble; -static TerrainManager* g_sim_terrain; +static Terrain* g_sim_terrain; static ThreadPool* g_thread_pool; static CameraManager* g_camera_manager; static GfxScene g_gfx_scene; @@ -238,7 +238,7 @@ CVar* gfx_reduce_shadows; CVar* gfx_enable_rtshaders; // Instance management -void SetSimTerrain (TerrainManager* obj) { g_sim_terrain = obj;} +void SetSimTerrain (Terrain* obj) { g_sim_terrain = obj;} void SetCacheSystem (CacheSystem* obj) { g_cache_system = obj; } // Instance access @@ -250,7 +250,7 @@ Console* GetConsole () { return &g_console;} InputEngine* GetInputEngine () { return g_input_engine;} CacheSystem* GetCacheSystem () { return g_cache_system;} MumbleIntegration* GetMumble () { return g_mumble; } -TerrainManager* GetSimTerrain () { return g_sim_terrain; } +Terrain* GetSimTerrain () { return g_sim_terrain; } ThreadPool* GetThreadPool () { return g_thread_pool; } CameraManager* GetCameraManager () { return g_camera_manager; } GfxScene* GetGfxScene () { return &g_gfx_scene; } diff --git a/source/main/Application.h b/source/main/Application.h index 78ffc93211..966039b3c6 100644 --- a/source/main/Application.h +++ b/source/main/Application.h @@ -442,7 +442,7 @@ Console* GetConsole(); InputEngine* GetInputEngine(); CacheSystem* GetCacheSystem(); MumbleIntegration* GetMumble(); -TerrainManager* GetSimTerrain(); +Terrain* GetSimTerrain(); ThreadPool* GetThreadPool(); CameraManager* GetCameraManager(); GfxScene* GetGfxScene(); @@ -466,7 +466,7 @@ void CreateSoundScriptManager(); void CreateScriptEngine(); // Setters -void SetSimTerrain (TerrainManager* obj); +void SetSimTerrain (Terrain* obj); void SetCacheSystem (CacheSystem* obj); // Cleanups diff --git a/source/main/CMakeLists.txt b/source/main/CMakeLists.txt index 5c5ceea7b1..64bcf70f0f 100644 --- a/source/main/CMakeLists.txt +++ b/source/main/CMakeLists.txt @@ -199,7 +199,7 @@ set(SOURCE_FILES terrain/OgreTerrainPSSMMaterialGenerator.{h,cpp} terrain/TerrainEditor.{h,cpp} terrain/TerrainGeometryManager.{h,cpp} - terrain/TerrainManager.{h,cpp} + terrain/Terrain.{h,cpp} terrain/TerrainObjectManager.{h,cpp} threadpool/ThreadPool.h utils/ConfigFile.{h,cpp} diff --git a/source/main/ForwardDeclarations.h b/source/main/ForwardDeclarations.h index 2222906b04..a448509898 100644 --- a/source/main/ForwardDeclarations.h +++ b/source/main/ForwardDeclarations.h @@ -106,7 +106,7 @@ namespace RoR class Task; class TerrainEditor; class TerrainGeometryManager; - class TerrainManager; + class Terrain; class TerrainObjectManager; struct Terrn2Author; struct Terrn2Def; diff --git a/source/main/GameContext.cpp b/source/main/GameContext.cpp index 769111932a..3e6f234e89 100644 --- a/source/main/GameContext.cpp +++ b/source/main/GameContext.cpp @@ -41,7 +41,7 @@ #include "SkyManager.h" #include "SkyXManager.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Utils.h" #include "VehicleAI.h" #include "GUI_VehicleButtons.h" @@ -112,7 +112,7 @@ bool GameContext::LoadTerrain(std::string const& filename_part) App::GetCacheSystem()->LoadResource(*terrn_entry); // Perform the loading and setup - App::SetSimTerrain(TerrainManager::LoadAndPrepareTerrain(terrn_entry)); + App::SetSimTerrain(RoR::Terrain::LoadAndPrepareTerrain(terrn_entry)); if (!App::GetSimTerrain()) { return false; // Message box already displayed diff --git a/source/main/GameContext.h b/source/main/GameContext.h index 7bce891d08..a08077564f 100644 --- a/source/main/GameContext.h +++ b/source/main/GameContext.h @@ -65,7 +65,7 @@ typedef std::queue < Message, std::list> GameMsgQueue; /// Central game state manager. /// RoR's gameplay is quite simple in structure, it consists of: -/// - static terrain: static elevation map, managed by `TerrainManager`. +/// - static terrain: static elevation map, managed by `Terrain`. /// this includes static collision objects (or intrusion detection objects), managed by `TerrainObjectManager`. /// - softbody actors: a.k.a "trucks" or "vehicles" (local or remote), managed by `ActorManager`. They collide with static terrain and each other. /// this includes 'fixes' - actors with partially fixed position. diff --git a/source/main/gameplay/AutoPilot.cpp b/source/main/gameplay/AutoPilot.cpp index b45f327396..7c43dc371c 100644 --- a/source/main/gameplay/AutoPilot.cpp +++ b/source/main/gameplay/AutoPilot.cpp @@ -23,7 +23,7 @@ #include "Application.h" #include "SimData.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Water.h" using namespace Ogre; diff --git a/source/main/gameplay/Character.cpp b/source/main/gameplay/Character.cpp index 614f3b0446..eead1d49c3 100644 --- a/source/main/gameplay/Character.cpp +++ b/source/main/gameplay/Character.cpp @@ -31,7 +31,7 @@ #include "InputEngine.h" #include "MovableText.h" #include "Network.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Utils.h" #include "Water.h" diff --git a/source/main/gameplay/Landusemap.cpp b/source/main/gameplay/Landusemap.cpp index 9c133fcfa5..ad89d7adf3 100644 --- a/source/main/gameplay/Landusemap.cpp +++ b/source/main/gameplay/Landusemap.cpp @@ -25,7 +25,7 @@ #include "Console.h" #include "ErrorUtils.h" #include "Language.h" -#include "TerrainManager.h" +#include "Terrain.h" #ifdef USE_PAGED #include "PropertyMaps.h" #include "PagedGeometry.h" diff --git a/source/main/gameplay/ProceduralRoad.cpp b/source/main/gameplay/ProceduralRoad.cpp index 4799a70f03..a39f80c328 100644 --- a/source/main/gameplay/ProceduralRoad.cpp +++ b/source/main/gameplay/ProceduralRoad.cpp @@ -23,7 +23,7 @@ #include "Application.h" #include "Collisions.h" #include "GfxScene.h" -#include "TerrainManager.h" +#include "Terrain.h" using namespace Ogre; using namespace RoR; diff --git a/source/main/gfx/DustPool.cpp b/source/main/gfx/DustPool.cpp index c2fd872583..9f763d5e4e 100644 --- a/source/main/gfx/DustPool.cpp +++ b/source/main/gfx/DustPool.cpp @@ -23,7 +23,7 @@ #include #include "Application.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Water.h" using namespace Ogre; diff --git a/source/main/gfx/EnvironmentMap.cpp b/source/main/gfx/EnvironmentMap.cpp index fc28ec1703..0e42caf351 100644 --- a/source/main/gfx/EnvironmentMap.cpp +++ b/source/main/gfx/EnvironmentMap.cpp @@ -25,7 +25,7 @@ #include "GfxActor.h" #include "GfxScene.h" #include "SkyManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include #include diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index dfe5ef57ca..e7e8436b9b 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -44,7 +44,7 @@ #include "SlideNode.h" #include "SkyManager.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TurboJet.h" #include "TurboProp.h" #include "Utils.h" diff --git a/source/main/gfx/GfxScene.cpp b/source/main/gfx/GfxScene.cpp index 6f08ff1798..8d2c1806bb 100644 --- a/source/main/gfx/GfxScene.cpp +++ b/source/main/gfx/GfxScene.cpp @@ -35,7 +35,7 @@ #include "SkyManager.h" #include "SkyXManager.h" #include "TerrainGeometryManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TerrainObjectManager.h" #include "Utils.h" @@ -140,7 +140,7 @@ void GfxScene::UpdateScene(float dt_sec) // Terrain - animated meshes and paged geometry App::GetSimTerrain()->getObjectManager()->UpdateTerrainObjects(dt_sec); - // Terrain - lightmap; TODO: ported as-is from TerrainManager::update(), is it needed? ~ only_a_ptr, 05/2018 + // Terrain - lightmap; TODO: ported as-is from Terrain::update(), is it needed? ~ only_a_ptr, 05/2018 App::GetSimTerrain()->getGeometryManager()->UpdateMainLightPosition(); // TODO: Is this necessary? I'm leaving it here just in case ~ only_a_ptr, 04/2017 // Terrain - water diff --git a/source/main/gfx/HydraxWater.cpp b/source/main/gfx/HydraxWater.cpp index cd26c688cb..c2601d0790 100644 --- a/source/main/gfx/HydraxWater.cpp +++ b/source/main/gfx/HydraxWater.cpp @@ -24,7 +24,7 @@ #include "CameraManager.h" #include "GfxScene.h" #include "SkyManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #ifdef USE_CAELUM #include diff --git a/source/main/gfx/SkyManager.cpp b/source/main/gfx/SkyManager.cpp index f41d5cd8c4..9df0167b09 100644 --- a/source/main/gfx/SkyManager.cpp +++ b/source/main/gfx/SkyManager.cpp @@ -26,7 +26,7 @@ #include "AppContext.h" #include "CameraManager.h" #include "GfxScene.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TerrainGeometryManager.h" #include diff --git a/source/main/gfx/SkyXManager.cpp b/source/main/gfx/SkyXManager.cpp index 284eba69a9..4864fc7bdb 100644 --- a/source/main/gfx/SkyXManager.cpp +++ b/source/main/gfx/SkyXManager.cpp @@ -25,7 +25,7 @@ #include "CameraManager.h" #include "GfxScene.h" #include "HydraxWater.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TerrainGeometryManager.h" using namespace Ogre; diff --git a/source/main/gfx/SurveyMapTextureCreator.cpp b/source/main/gfx/SurveyMapTextureCreator.cpp index 62b691550f..768cdfbcfe 100644 --- a/source/main/gfx/SurveyMapTextureCreator.cpp +++ b/source/main/gfx/SurveyMapTextureCreator.cpp @@ -23,7 +23,7 @@ #include "Application.h" #include "GfxScene.h" #include "IWater.h" -#include "TerrainManager.h" +#include "Terrain.h" using namespace Ogre; using namespace RoR; diff --git a/source/main/gfx/Water.cpp b/source/main/gfx/Water.cpp index d491dd2670..1c83e0ce93 100644 --- a/source/main/gfx/Water.cpp +++ b/source/main/gfx/Water.cpp @@ -25,7 +25,7 @@ #include "CameraManager.h" #include "GfxScene.h" #include "PlatformUtils.h" // PathCombine -#include "TerrainManager.h" +#include "Terrain.h" #include diff --git a/source/main/gfx/camera/CameraManager.cpp b/source/main/gfx/camera/CameraManager.cpp index 8b7dbefc7e..4a03e1599e 100644 --- a/source/main/gfx/camera/CameraManager.cpp +++ b/source/main/gfx/camera/CameraManager.cpp @@ -34,7 +34,7 @@ #include "Language.h" #include "OverlayWrapper.h" #include "Replay.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "GUIManager.h" #include "PerVehicleCameraContext.h" #include "Water.h" diff --git a/source/main/gui/GUIManager.cpp b/source/main/gui/GUIManager.cpp index 20123c5998..c4c7ab04fd 100644 --- a/source/main/gui/GUIManager.cpp +++ b/source/main/gui/GUIManager.cpp @@ -37,7 +37,7 @@ #include "OverlayWrapper.h" #include "PlatformUtils.h" #include "RTTLayer.h" -#include "TerrainManager.h" +#include "Terrain.h" #include #include diff --git a/source/main/gui/OverlayWrapper.cpp b/source/main/gui/OverlayWrapper.cpp index 1cf174419f..7e7aa58c49 100644 --- a/source/main/gui/OverlayWrapper.cpp +++ b/source/main/gui/OverlayWrapper.cpp @@ -45,7 +45,7 @@ #include "RoRVersion.h" #include "ScrewProp.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TurboProp.h" #include "Utils.h" diff --git a/source/main/gui/panels/GUI_FrictionSettings.cpp b/source/main/gui/panels/GUI_FrictionSettings.cpp index 149680f4f6..2d6bc022b8 100644 --- a/source/main/gui/panels/GUI_FrictionSettings.cpp +++ b/source/main/gui/panels/GUI_FrictionSettings.cpp @@ -33,7 +33,7 @@ #include "GameContext.h" #include "GUIManager.h" #include "Language.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Utils.h" using namespace RoR; diff --git a/source/main/gui/panels/GUI_SurveyMap.cpp b/source/main/gui/panels/GUI_SurveyMap.cpp index 5cdf5da5a8..41d1356f55 100644 --- a/source/main/gui/panels/GUI_SurveyMap.cpp +++ b/source/main/gui/panels/GUI_SurveyMap.cpp @@ -35,7 +35,7 @@ #include "Language.h" #include "OgreImGui.h" #include "SurveyMapTextureCreator.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TerrainObjectManager.h" using namespace RoR; diff --git a/source/main/gui/panels/GUI_TopMenubar.cpp b/source/main/gui/panels/GUI_TopMenubar.cpp index 8e2f532ccd..147ba65de5 100644 --- a/source/main/gui/panels/GUI_TopMenubar.cpp +++ b/source/main/gui/panels/GUI_TopMenubar.cpp @@ -40,7 +40,7 @@ #include "PlatformUtils.h" #include "Replay.h" #include "SkyManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Water.h" #include diff --git a/source/main/main.cpp b/source/main/main.cpp index f0f36197fa..c158e2f375 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -52,7 +52,7 @@ #include "ScriptEngine.h" #include "Skidmark.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Utils.h" #include #include diff --git a/source/main/physics/Actor.cpp b/source/main/physics/Actor.cpp index 704e3eea53..bfb02a8e3f 100644 --- a/source/main/physics/Actor.cpp +++ b/source/main/physics/Actor.cpp @@ -61,7 +61,7 @@ #include "Skidmark.h" #include "SlideNode.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TurboJet.h" #include "TurboProp.h" #include "Utils.h" diff --git a/source/main/physics/ActorForcesEuler.cpp b/source/main/physics/ActorForcesEuler.cpp index beb0a0117a..4c294178e1 100644 --- a/source/main/physics/ActorForcesEuler.cpp +++ b/source/main/physics/ActorForcesEuler.cpp @@ -36,7 +36,7 @@ #include "Replay.h" #include "ScrewProp.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Water.h" using namespace Ogre; diff --git a/source/main/physics/ActorManager.cpp b/source/main/physics/ActorManager.cpp index dbac95d80c..7f2bd791d8 100644 --- a/source/main/physics/ActorManager.cpp +++ b/source/main/physics/ActorManager.cpp @@ -49,7 +49,7 @@ #include "ActorSpawner.h" #include "ScriptEngine.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "ThreadPool.h" #include "Utils.h" #include "VehicleAI.h" diff --git a/source/main/physics/ActorSpawner.cpp b/source/main/physics/ActorSpawner.cpp index a361397270..4b6445145b 100644 --- a/source/main/physics/ActorSpawner.cpp +++ b/source/main/physics/ActorSpawner.cpp @@ -63,7 +63,7 @@ #include "SkinFileFormat.h" #include "SlideNode.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TorqueCurve.h" #include "TurboJet.h" #include "TurboProp.h" diff --git a/source/main/physics/Savegame.cpp b/source/main/physics/Savegame.cpp index 281867b68b..38ac047c29 100644 --- a/source/main/physics/Savegame.cpp +++ b/source/main/physics/Savegame.cpp @@ -38,7 +38,7 @@ #include "ScrewProp.h" #include "Skidmark.h" #include "SkyManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include #include diff --git a/source/main/physics/collision/Collisions.cpp b/source/main/physics/collision/Collisions.cpp index 55f4c69fa1..a5e10df94e 100644 --- a/source/main/physics/collision/Collisions.cpp +++ b/source/main/physics/collision/Collisions.cpp @@ -33,7 +33,7 @@ #include "MovableText.h" #include "PlatformUtils.h" #include "ScriptEngine.h" -#include "TerrainManager.h" +#include "Terrain.h" using namespace RoR; diff --git a/source/main/physics/water/Buoyance.cpp b/source/main/physics/water/Buoyance.cpp index 818a03af42..15f0940940 100644 --- a/source/main/physics/water/Buoyance.cpp +++ b/source/main/physics/water/Buoyance.cpp @@ -25,7 +25,7 @@ #include "ActorManager.h" #include "GfxScene.h" #include "DustPool.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Water.h" using namespace Ogre; diff --git a/source/main/physics/water/ScrewProp.cpp b/source/main/physics/water/ScrewProp.cpp index bbb24dc306..e76b8dfe15 100644 --- a/source/main/physics/water/ScrewProp.cpp +++ b/source/main/physics/water/ScrewProp.cpp @@ -27,7 +27,7 @@ #include "DustPool.h" #include "GfxScene.h" #include "SoundScriptManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Water.h" using namespace Ogre; diff --git a/source/main/resources/CacheSystem.cpp b/source/main/resources/CacheSystem.cpp index 1201de5363..034bcb41e5 100644 --- a/source/main/resources/CacheSystem.cpp +++ b/source/main/resources/CacheSystem.cpp @@ -40,7 +40,7 @@ #include "RigDef_Parser.h" #include "SkinFileFormat.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "Terrn2FileFormat.h" #include "Utils.h" diff --git a/source/main/scripting/GameScript.cpp b/source/main/scripting/GameScript.cpp index 6ef2437bdf..4b71bf83c7 100644 --- a/source/main/scripting/GameScript.cpp +++ b/source/main/scripting/GameScript.cpp @@ -50,7 +50,7 @@ #include "RoRVersion.h" #include "ScriptEngine.h" #include "SkyManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TerrainGeometryManager.h" #include "TerrainObjectManager.h" #include "Utils.h" diff --git a/source/main/system/ConsoleCmd.cpp b/source/main/system/ConsoleCmd.cpp index 1baab5e865..b28dfd7397 100644 --- a/source/main/system/ConsoleCmd.cpp +++ b/source/main/system/ConsoleCmd.cpp @@ -35,7 +35,7 @@ #include "RoRnet.h" #include "RoRVersion.h" #include "ScriptEngine.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TerrainObjectManager.h" #include "Utils.h" diff --git a/source/main/terrain/TerrainManager.cpp b/source/main/terrain/Terrain.cpp similarity index 89% rename from source/main/terrain/TerrainManager.cpp rename to source/main/terrain/Terrain.cpp index b9548bbea9..25a0244d16 100644 --- a/source/main/terrain/TerrainManager.cpp +++ b/source/main/terrain/Terrain.cpp @@ -19,7 +19,7 @@ along with Rigs of Rods. If not, see . */ -#include "TerrainManager.h" +#include "Terrain.h" #include "ActorManager.h" #include "CacheSystem.h" @@ -45,7 +45,7 @@ using namespace RoR; using namespace Ogre; -TerrainManager::TerrainManager(CacheEntry* entry) +RoR::Terrain::Terrain(CacheEntry* entry) : m_collisions(0) , m_geometry_manager(0) , m_object_manager(0) @@ -61,7 +61,7 @@ TerrainManager::TerrainManager(CacheEntry* entry) { } -TerrainManager::~TerrainManager() +RoR::Terrain::~Terrain() { if (App::app_state->getEnum() == AppState::SHUTDOWN) { @@ -126,9 +126,9 @@ TerrainManager::~TerrainManager() } } -TerrainManager* TerrainManager::LoadAndPrepareTerrain(CacheEntry* entry) +RoR::Terrain* RoR::Terrain::LoadAndPrepareTerrain(CacheEntry* entry) { - auto terrn_mgr = std::unique_ptr(new TerrainManager(entry)); + auto terrn_mgr = std::unique_ptr(new RoR::Terrain(entry)); auto* loading_window = &App::GetGuiManager()->LoadingWindow; std::string const& filename = entry->fname; @@ -234,7 +234,7 @@ TerrainManager* TerrainManager::LoadAndPrepareTerrain(CacheEntry* entry) return terrn_mgr.release(); } -void TerrainManager::initCamera() +void RoR::Terrain::initCamera() { App::GetCameraManager()->GetCamera()->getViewport()->setBackgroundColour(m_def.ambient_color); App::GetCameraManager()->GetCameraNode()->setPosition(m_def.start_position); @@ -262,7 +262,7 @@ void TerrainManager::initCamera() } } -void TerrainManager::initSkySubSystem() +void RoR::Terrain::initSkySubSystem() { #ifdef USE_CAELUM // Caelum skies @@ -309,7 +309,7 @@ void TerrainManager::initSkySubSystem() } } -void TerrainManager::initLight() +void RoR::Terrain::initLight() { if (App::gfx_sky_mode->getEnum() == GfxSkyMode::CAELUM) { @@ -339,7 +339,7 @@ void TerrainManager::initLight() } } -void TerrainManager::initFog() +void RoR::Terrain::initFog() { if (m_sight_range >= UNLIMITED_SIGHTRANGE) App::GetGfxScene()->GetSceneManager()->setFog(FOG_NONE); @@ -347,7 +347,7 @@ void TerrainManager::initFog() App::GetGfxScene()->GetSceneManager()->setFog(FOG_LINEAR, m_def.ambient_color, 0.000f, m_sight_range * 0.65f, m_sight_range*0.9); } -void TerrainManager::initVegetation() +void RoR::Terrain::initVegetation() { switch (App::gfx_vegetation_mode->getEnum()) { @@ -366,7 +366,7 @@ void TerrainManager::initVegetation() } } -void TerrainManager::fixCompositorClearColor() +void RoR::Terrain::fixCompositorClearColor() { // hack // now with extensive error checking @@ -392,7 +392,7 @@ void TerrainManager::fixCompositorClearColor() } } -void TerrainManager::initWater() +void RoR::Terrain::initWater() { // disabled in global config if (App::gfx_water_mode->getEnum() == GfxWaterMode::NONE) @@ -423,7 +423,7 @@ void TerrainManager::initWater() TerrainGroup::TerrainIterator ti = m_geometry_manager->getTerrainGroup()->getTerrainIterator(); while (ti.hasMoreElements()) { - Terrain* t = ti.getNext()->instance; + Ogre::Terrain* t = ti.getNext()->instance; MaterialPtr ptr = t->getMaterial(); m_hydrax_water->GetHydrax()->getMaterialManager()->addDepthTechnique(ptr->createTechnique()); } @@ -436,13 +436,13 @@ void TerrainManager::initWater() } } -void TerrainManager::initShadows() +void RoR::Terrain::initShadows() { m_shadow_manager = new ShadowManager(); m_shadow_manager->loadConfiguration(); } -void TerrainManager::loadTerrainObjects() +void RoR::Terrain::loadTerrainObjects() { for (std::string tobj_filename : m_def.tobj_files) { @@ -452,7 +452,7 @@ void TerrainManager::loadTerrainObjects() m_object_manager->PostLoadTerrain(); // bakes the geometry and things } -void TerrainManager::initTerrainCollisions() +void RoR::Terrain::initTerrainCollisions() { if (!m_def.traction_map_file.empty()) { @@ -460,7 +460,7 @@ void TerrainManager::initTerrainCollisions() } } -void TerrainManager::initScripting() +void RoR::Terrain::initScripting() { #ifdef USE_ANGELSCRIPT bool loaded = false; @@ -481,68 +481,68 @@ void TerrainManager::initScripting() #endif //USE_ANGELSCRIPT } -void TerrainManager::setGravity(float value) +void RoR::Terrain::setGravity(float value) { m_cur_gravity = value; } -void TerrainManager::initObjects() +void RoR::Terrain::initObjects() { m_object_manager = new TerrainObjectManager(this); } -Ogre::AxisAlignedBox TerrainManager::getTerrainCollisionAAB() +Ogre::AxisAlignedBox RoR::Terrain::getTerrainCollisionAAB() { return m_collisions->getCollisionAAB(); } -Ogre::Vector3 TerrainManager::getMaxTerrainSize() +Ogre::Vector3 RoR::Terrain::getMaxTerrainSize() { if (!m_geometry_manager) return Vector3::ZERO; return m_geometry_manager->getMaxTerrainSize(); } -float TerrainManager::GetHeightAt(float x, float z) +float RoR::Terrain::GetHeightAt(float x, float z) { return m_geometry_manager->getHeightAt(x, z); } -Ogre::Vector3 TerrainManager::GetNormalAt(float x, float y, float z) +Ogre::Vector3 RoR::Terrain::GetNormalAt(float x, float y, float z) { return m_geometry_manager->getNormalAt(x, y, z); } -SkyManager* TerrainManager::getSkyManager() +SkyManager* RoR::Terrain::getSkyManager() { return m_sky_manager; } -bool TerrainManager::isFlat() +bool RoR::Terrain::isFlat() { return m_geometry_manager->isFlat(); } -void TerrainManager::LoadTelepoints() +void RoR::Terrain::LoadTelepoints() { if (m_object_manager) m_object_manager->LoadTelepoints(); } -void TerrainManager::LoadPredefinedActors() +void RoR::Terrain::LoadPredefinedActors() { if (m_object_manager) m_object_manager->LoadPredefinedActors(); } -bool TerrainManager::HasPredefinedActors() +bool RoR::Terrain::HasPredefinedActors() { if (m_object_manager) return m_object_manager->HasPredefinedActors(); return false; } -void TerrainManager::HandleException(const char* summary) +void RoR::Terrain::HandleException(const char* summary) { try { diff --git a/source/main/terrain/TerrainManager.h b/source/main/terrain/Terrain.h similarity index 93% rename from source/main/terrain/TerrainManager.h rename to source/main/terrain/Terrain.h index b1e89e8d92..65b2d052cb 100644 --- a/source/main/terrain/TerrainManager.h +++ b/source/main/terrain/Terrain.h @@ -33,15 +33,15 @@ namespace RoR { /// @addtogroup Terrain /// @{ -class TerrainManager : public ZeroedMemoryAllocator +class Terrain : public ZeroedMemoryAllocator { public: static const int UNLIMITED_SIGHTRANGE = 4999; - static TerrainManager* LoadAndPrepareTerrain(CacheEntry* entry); //!< Factory function + static Terrain* LoadAndPrepareTerrain(CacheEntry* entry); //!< Factory function - TerrainManager(CacheEntry* entry); - ~TerrainManager(); + Terrain(CacheEntry* entry); + ~Terrain(); // Terrain info diff --git a/source/main/terrain/TerrainEditor.cpp b/source/main/terrain/TerrainEditor.cpp index 82e16a7445..053839ba6b 100644 --- a/source/main/terrain/TerrainEditor.cpp +++ b/source/main/terrain/TerrainEditor.cpp @@ -29,7 +29,7 @@ #include "GfxScene.h" #include "InputEngine.h" #include "OgreImGui.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TerrainObjectManager.h" #include "PlatformUtils.h" diff --git a/source/main/terrain/TerrainGeometryManager.cpp b/source/main/terrain/TerrainGeometryManager.cpp index 474d3f8e3b..be68bb713a 100644 --- a/source/main/terrain/TerrainGeometryManager.cpp +++ b/source/main/terrain/TerrainGeometryManager.cpp @@ -27,7 +27,7 @@ #include "GfxScene.h" #include "GUIManager.h" #include "GUI_LoadingWindow.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "ShadowManager.h" #include "OgreTerrainPSSMMaterialGenerator.h" #include "OTCFileFormat.h" @@ -134,7 +134,7 @@ Ogre::MaterialPtr Terrn2CustomMaterial::Profile::generate(const Ogre::Terrain* t #define XZSTR(X,Z) String("[") + TOSTRING(X) + String(",") + TOSTRING(Z) + String("]") -TerrainGeometryManager::TerrainGeometryManager(TerrainManager* terrainManager) +TerrainGeometryManager::TerrainGeometryManager(Terrain* terrainManager) : mHeightData(nullptr) , mIsFlat(false) , mMinHeight(0.0f) @@ -310,7 +310,7 @@ bool TerrainGeometryManager::InitTerrain(std::string otc_filename) const std::string cache_filename_format = m_spec->cache_filename_base + "_OGRE_" + TOSTRING(OGRE_VERSION) + "_"; - m_ogre_terrain_group = OGRE_NEW TerrainGroup(App::GetGfxScene()->GetSceneManager(), Terrain::ALIGN_X_Z, m_spec->page_size, m_spec->world_size); + m_ogre_terrain_group = OGRE_NEW TerrainGroup(App::GetGfxScene()->GetSceneManager(), Ogre::Terrain::ALIGN_X_Z, m_spec->page_size, m_spec->world_size); m_ogre_terrain_group->setFilenameConvention(cache_filename_format, "mapbin"); m_ogre_terrain_group->setOrigin(m_spec->origin_pos); m_ogre_terrain_group->setResourceGroup(RGN_CACHE); @@ -326,7 +326,7 @@ bool TerrainGeometryManager::InitTerrain(std::string otc_filename) App::GetGuiManager()->LoadingWindow.SetProgress(44, _L("Loading terrain pages ...")); m_ogre_terrain_group->loadAllTerrains(true); - Terrain* terrain = m_ogre_terrain_group->getTerrain(0, 0); + Ogre::Terrain* terrain = m_ogre_terrain_group->getTerrain(0, 0); if (terrain == nullptr) return true; @@ -389,7 +389,7 @@ void TerrainGeometryManager::updateLightMap() while (ti.hasMoreElements()) { - Terrain* terrain = ti.getNext()->instance; + Ogre::Terrain* terrain = ti.getNext()->instance; if (!terrain) continue; diff --git a/source/main/terrain/TerrainGeometryManager.h b/source/main/terrain/TerrainGeometryManager.h index e6aead7460..d5e1501a9a 100644 --- a/source/main/terrain/TerrainGeometryManager.h +++ b/source/main/terrain/TerrainGeometryManager.h @@ -38,7 +38,7 @@ namespace RoR { class TerrainGeometryManager : public ZeroedMemoryAllocator { public: - TerrainGeometryManager(TerrainManager* terrainManager); + TerrainGeometryManager(Terrain* terrainManager); ~TerrainGeometryManager(); bool InitTerrain(std::string otc_filename); @@ -70,7 +70,7 @@ class TerrainGeometryManager : public ZeroedMemoryAllocator Ogre::DataStreamPtr getPageConfig(int x, int z); std::shared_ptr m_spec; - TerrainManager* terrainManager; + RoR::Terrain* terrainManager; Ogre::TerrainGroup* m_ogre_terrain_group; bool m_was_new_geometry_generated; diff --git a/source/main/terrain/TerrainObjectManager.cpp b/source/main/terrain/TerrainObjectManager.cpp index f8650a48df..d862dbc86d 100644 --- a/source/main/terrain/TerrainObjectManager.cpp +++ b/source/main/terrain/TerrainObjectManager.cpp @@ -39,7 +39,7 @@ #include "ProceduralRoad.h" #include "SoundScriptManager.h" #include "TerrainGeometryManager.h" -#include "TerrainManager.h" +#include "Terrain.h" #include "TObjFileFormat.h" #include "Utils.h" #include "WriteTextToTexture.h" @@ -63,7 +63,7 @@ inline float getTerrainHeight(Real x, Real z, void* unused = 0) return App::GetSimTerrain()->GetHeightAt(x, z); } -TerrainObjectManager::TerrainObjectManager(TerrainManager* terrainManager) : +TerrainObjectManager::TerrainObjectManager(Terrain* terrainManager) : terrainManager(terrainManager) { //prepare for baking diff --git a/source/main/terrain/TerrainObjectManager.h b/source/main/terrain/TerrainObjectManager.h index 5ca9435525..00829f673e 100644 --- a/source/main/terrain/TerrainObjectManager.h +++ b/source/main/terrain/TerrainObjectManager.h @@ -73,7 +73,7 @@ class TerrainObjectManager : public ZeroedMemoryAllocator int id; }; - TerrainObjectManager(TerrainManager* terrainManager); + TerrainObjectManager(Terrain* terrainManager); ~TerrainObjectManager(); std::vector& GetEditorObjects() { return m_editor_objects; } @@ -169,7 +169,7 @@ class TerrainObjectManager : public ZeroedMemoryAllocator std::vector m_animated_objects; std::vector m_mesh_objects; std::vector m_map_entities; - TerrainManager* terrainManager; + Terrain* terrainManager; Ogre::StaticGeometry* m_staticgeometry; ProceduralManager* m_procedural_mgr; Ogre::SceneNode* m_staticgeometry_bake_node;