Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
ActorAngelscript.cpp
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2022 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Actor.h"
23#include "AngelScriptBindings.h"
24#include "ScriptEngine.h"
25#include "ScriptUtils.h"
26#include "SimData.h"
27#include <angelscript.h>
28
29using namespace AngelScript;
30
31void RoR::RegisterActorNative(asIScriptEngine *engine)
32{
33 int result;
34
35 // class Actor (historically Beam)
36 Actor::RegisterRefCountingObject(engine, "BeamClass");
37 ActorPtr::RegisterRefCountingObjectPtr(engine, "BeamClassPtr", "BeamClass");
38
39 // - physics state (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
40 result = engine->RegisterObjectMethod("BeamClass", "TruckState getTruckState()", asMETHOD(Actor,getTruckState), asCALL_THISCALL); ROR_ASSERT(result>=0);
41 result = engine->RegisterObjectMethod("BeamClass", "vector3 getPosition()", asMETHOD(Actor,getPosition), asCALL_THISCALL); ROR_ASSERT(result>=0);
42 /*alias:*/result = engine->RegisterObjectMethod("BeamClass", "vector3 getVehiclePosition()", asMETHOD(Actor,getPosition), asCALL_THISCALL); ROR_ASSERT(result>=0);
43 result = engine->RegisterObjectMethod("BeamClass", "float getRotation()", asMETHOD(Actor,getRotation), asCALL_THISCALL); ROR_ASSERT(result>=0);
44 /*alias:*/result = engine->RegisterObjectMethod("BeamClass", "float getHeadingDirectionAngle()", asMETHOD(Actor,getRotation), asCALL_THISCALL); ROR_ASSERT(result>=0);
45 result = engine->RegisterObjectMethod("BeamClass", "quaternion getOrientation()", asMETHOD(Actor,getOrientation), asCALL_THISCALL); ROR_ASSERT(result>=0);
46 result = engine->RegisterObjectMethod("BeamClass", "float getSpeed()", asMETHOD(Actor,getSpeed), asCALL_THISCALL); ROR_ASSERT(result>=0);
47 result = engine->RegisterObjectMethod("BeamClass", "vector3 getGForces()", asMETHOD(Actor,getGForces), asCALL_THISCALL); ROR_ASSERT(result>=0);
48 result = engine->RegisterObjectMethod("BeamClass", "float getTotalMass(bool)", asMETHOD(Actor,getTotalMass), asCALL_THISCALL); ROR_ASSERT(result>=0);
49 result = engine->RegisterObjectMethod("BeamClass", "float getDryMass()", asMETHOD(Actor, getDryMass), asCALL_THISCALL); ROR_ASSERT(result >= 0);
50 result = engine->RegisterObjectMethod("BeamClass", "float getLoadedMass()", asMETHOD(Actor, getLoadedMass), asCALL_THISCALL); ROR_ASSERT(result >= 0);
51 result = engine->RegisterObjectMethod("BeamClass", "float getInitialDryMass()", asMETHOD(Actor, getInitialDryMass), asCALL_THISCALL); ROR_ASSERT(result >= 0);
52 result = engine->RegisterObjectMethod("BeamClass", "float getInitialLoadedMass()", asMETHOD(Actor, getInitialLoadedMass), asCALL_THISCALL); ROR_ASSERT(result >= 0);
53 result = engine->RegisterObjectMethod("BeamClass", "int getNodeCount()", asMETHOD(Actor,getNodeCount), asCALL_THISCALL); ROR_ASSERT(result>=0);
54 result = engine->RegisterObjectMethod("BeamClass", "vector3 getNodePosition(int)", asMETHOD(Actor, getNodePosition), asCALL_THISCALL); ROR_ASSERT(result>=0);
55 result = engine->RegisterObjectMethod("BeamClass", "float getNodeInitialMass(int)", asMETHOD(Actor, getNodeInitialMass), asCALL_THISCALL); ROR_ASSERT(result>=0);
56 result = engine->RegisterObjectMethod("BeamClass", "float getNodeMass(int)", asMETHOD(Actor, getNodeMass), asCALL_THISCALL); ROR_ASSERT(result >= 0);
57 result = engine->RegisterObjectMethod("BeamClass", "vector3 getNodeVelocity(int)", asMETHOD(Actor, getNodeVelocity), asCALL_THISCALL); ROR_ASSERT(result>=0);
58 result = engine->RegisterObjectMethod("BeamClass", "vector3 getNodeForces(int)", asMETHOD(Actor, getNodeForces), asCALL_THISCALL); ROR_ASSERT(result >= 0);
59 result = engine->RegisterObjectMethod("BeamClass", "void getNodeMassOptions(int, bool&inout, bool&inout)", asMETHOD(Actor, getNodeMassOptions), asCALL_THISCALL); ROR_ASSERT(result >= 0);
60 result = engine->RegisterObjectMethod("BeamClass", "bool isNodeWheelRim(int)", asMETHOD(Actor,isNodeWheelRim), asCALL_THISCALL); ROR_ASSERT(result>=0);
61 result = engine->RegisterObjectMethod("BeamClass", "bool isNodeWheelTire(int)", asMETHOD(Actor,isNodeWheelTire), asCALL_THISCALL); ROR_ASSERT(result>=0);
62 result = engine->RegisterObjectMethod("BeamClass", "int getWheelNodeCount()", asMETHOD(Actor,getWheelNodeCount), asCALL_THISCALL); ROR_ASSERT(result>=0);
63 result = engine->RegisterObjectMethod("BeamClass", "float getWheelSpeed()", asMETHOD(Actor,getWheelSpeed), asCALL_THISCALL); ROR_ASSERT(result>=0);
64 result = engine->RegisterObjectMethod("BeamClass", "void reset(bool)", asMETHOD(Actor,reset), asCALL_THISCALL); ROR_ASSERT(result>=0);
65 result = engine->RegisterObjectMethod("BeamClass", "int getShockCount()", AngelScript::asMETHOD(Actor,getShockCount), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0);
66 result = engine->RegisterObjectMethod("BeamClass", "float getShockSpringRate(int)", AngelScript::asMETHOD(Actor,getShockSpringRate), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0);
67 result = engine->RegisterObjectMethod("BeamClass", "float getShockDamping(int)", AngelScript::asMETHOD(Actor,getShockDamping), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0);
68 result = engine->RegisterObjectMethod("BeamClass", "float getShockVelocity(int)", AngelScript::asMETHOD(Actor,getShockVelocity), AngelScript::asCALL_THISCALL); ROR_ASSERT(result>=0);
69 result = engine->RegisterObjectMethod("BeamClass", "int getShockNode1(int)", AngelScript::asMETHOD(Actor, getShockNode1), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0);
70 result = engine->RegisterObjectMethod("BeamClass", "int getShockNode2(int)", AngelScript::asMETHOD(Actor, getShockNode2), AngelScript::asCALL_THISCALL); ROR_ASSERT(result >= 0);
71 result = engine->RegisterObjectMethod("BeamClass", "float getAirbrakeIntensity()", asMETHOD(Actor,getAirbrakeIntensity), asCALL_THISCALL); ROR_ASSERT(result>=0);
72 result = engine->RegisterObjectMethod("BeamClass", "int getAircraftFlaps()", asMETHOD(Actor,getAircraftFlaps), asCALL_THISCALL); ROR_ASSERT(result>=0);
73 result = engine->RegisterObjectMethod("BeamClass", "void wakeUp()", asMETHOD(Actor, wakeUp), asCALL_THISCALL); ROR_ASSERT(result >= 0);
74 result = engine->RegisterObjectMethod("BeamClass", "void sendToSleep()", asMETHOD(Actor, sendToSleep), asCALL_THISCALL); ROR_ASSERT(result >= 0);
75
76 // - physics editing (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
77 result = engine->RegisterObjectMethod("BeamClass", "void scaleTruck(float)", asMETHOD(Actor,scaleTruck), asCALL_THISCALL); ROR_ASSERT(result>=0);
78 result = engine->RegisterObjectMethod("BeamClass", "void setMass(float)", asMETHOD(Actor,setMass), asCALL_THISCALL); ROR_ASSERT(result>=0);
79 result = engine->RegisterObjectMethod("BeamClass", "void setLoadedMass(float)", asMETHOD(Actor,setLoadedMass), asCALL_THISCALL); ROR_ASSERT(result>=0);
80 result = engine->RegisterObjectMethod("BeamClass", "void setNodeMass(int, float)", asMETHOD(Actor, setNodeMass), asCALL_THISCALL); ROR_ASSERT(result >= 0);
81 result = engine->RegisterObjectMethod("BeamClass", "void setNodeMassOptions(int, bool, bool)", asMETHOD(Actor, setNodeMassOptions), asCALL_THISCALL); ROR_ASSERT(result >= 0);
82 result = engine->RegisterObjectMethod("BeamClass", "void setSimAttribute(ActorSimAttr, float)", asMETHOD(Actor, setSimAttribute), asCALL_THISCALL); ROR_ASSERT(result >= 0);
83 result = engine->RegisterObjectMethod("BeamClass", "void setIndexedSimAttribute(ActorSimAttr, float, int)", asMETHOD(Actor, setIndexedSimAttribute), asCALL_THISCALL); ROR_ASSERT(result >= 0);
84 result = engine->RegisterObjectMethod("BeamClass", "float getSimAttribute(ActorSimAttr)", asMETHOD(Actor, getSimAttribute), asCALL_THISCALL); ROR_ASSERT(result >= 0);
85 result = engine->RegisterObjectMethod("BeamClass", "float getIndexedSimAttribute(ActorSimAttr, int)", asMETHOD(Actor, getIndexedSimAttribute), asCALL_THISCALL); ROR_ASSERT(result >= 0);
86 result = engine->RegisterObjectMethod("BeamClass", "void recalculateNodeMasses()", asMETHOD(Actor,recalculateNodeMasses), asCALL_THISCALL); ROR_ASSERT(result>=0);
87 result = engine->RegisterObjectMethod("BeamClass", "void setAirbrakeIntensity(float)", asMETHOD(Actor,setAirbrakeIntensity), asCALL_THISCALL); ROR_ASSERT(result>=0);
88 result = engine->RegisterObjectMethod("BeamClass", "void setAircraftFlaps(int)", asMETHOD(Actor,setAircraftFlaps), asCALL_THISCALL); ROR_ASSERT(result>=0);
89
90 // - user interaction (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
91 result = engine->RegisterObjectMethod("BeamClass", "bool getParkingBrake()", asMETHOD(Actor, getParkingBrake), asCALL_THISCALL); ROR_ASSERT(result >= 0);
92 result = engine->RegisterObjectMethod("BeamClass", "bool getTractionControl()", asMETHOD(Actor, getTractionControl), asCALL_THISCALL); ROR_ASSERT(result >= 0);
93 result = engine->RegisterObjectMethod("BeamClass", "bool getAntiLockBrake()", asMETHOD(Actor, getAntiLockBrake), asCALL_THISCALL); ROR_ASSERT(result >= 0);
94 result = engine->RegisterObjectMethod("BeamClass", "bool getCruiseControl()", asMETHOD(Actor, getCruiseControl), asCALL_THISCALL); ROR_ASSERT(result >= 0);
95 result = engine->RegisterObjectMethod("BeamClass", "void parkingbrakeToggle()", asMETHOD(Actor,parkingbrakeToggle), asCALL_THISCALL); ROR_ASSERT(result>=0);
96 result = engine->RegisterObjectMethod("BeamClass", "void tractioncontrolToggle()", asMETHOD(Actor,tractioncontrolToggle), asCALL_THISCALL); ROR_ASSERT(result>=0);
97 result = engine->RegisterObjectMethod("BeamClass", "void antilockbrakeToggle()", asMETHOD(Actor,antilockbrakeToggle), asCALL_THISCALL); ROR_ASSERT(result>=0);
98 result = engine->RegisterObjectMethod("BeamClass", "void cruisecontrolToggle()", asMETHOD(Actor, cruisecontrolToggle), asCALL_THISCALL); ROR_ASSERT(result>=0);
99 result = engine->RegisterObjectMethod("BeamClass", "void toggleCustomParticles()", asMETHOD(Actor,toggleCustomParticles), asCALL_THISCALL); ROR_ASSERT(result>=0);
100 result = engine->RegisterObjectMethod("BeamClass", "bool getCustomParticleMode()", asMETHOD(Actor,getCustomParticleMode), asCALL_THISCALL); ROR_ASSERT(result>=0);
101 result = engine->RegisterObjectMethod("BeamClass", "bool isLocked()", asMETHOD(Actor,isLocked), asCALL_THISCALL); ROR_ASSERT(result>=0);
102 result = engine->RegisterObjectMethod("BeamClass", "void setForcedCinecam(int, int)", asMETHOD(Actor, setForcedCinecam), asCALL_THISCALL); ROR_ASSERT(result >= 0);
103 result = engine->RegisterObjectMethod("BeamClass", "void clearForcedCinecam()", asMETHOD(Actor, clearForcedCinecam), asCALL_THISCALL); ROR_ASSERT(result >= 0);
104 result = engine->RegisterObjectMethod("BeamClass", "bool getForcedCinecam(int& inout, int& inout)", asMETHOD(Actor, getForcedCinecam), asCALL_THISCALL); ROR_ASSERT(result >= 0);
105 result = engine->RegisterObjectMethod("BeamClass", "int getNumCinecams() const", asMETHOD(Actor, getNumCinecams), asCALL_THISCALL); ROR_ASSERT(result >= 0);
106 result = engine->RegisterObjectMethod("BeamClass", "int getCameraCount() const", asMETHOD(Actor, getCameraCount), asCALL_THISCALL); ROR_ASSERT(result >= 0);
107 result = engine->RegisterObjectMethod("BeamClass", "int getCameraPosNode(int) const", asMETHOD(Actor, getCameraPosNode), asCALL_THISCALL); ROR_ASSERT(result >= 0);
108 result = engine->RegisterObjectMethod("BeamClass", "int getCameraDirNode(int) const", asMETHOD(Actor, getCameraDirNode), asCALL_THISCALL); ROR_ASSERT(result >= 0);
109 result = engine->RegisterObjectMethod("BeamClass", "int getCameraRollNode(int) const", asMETHOD(Actor, getCameraRollNode), asCALL_THISCALL); ROR_ASSERT(result >= 0);
110
111 // - input engine overrides (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
112 result = engine->RegisterObjectMethod("BeamClass", "float getEventValue(inputEvents, bool = false, inputSourceType = inputSourceType::IST_ANY)", asMETHOD(Actor, getEventValue), asCALL_THISCALL); ROR_ASSERT(result >= 0);
113 result = engine->RegisterObjectMethod("BeamClass", "bool getEventBoolValue(inputEvents)", asMETHOD(Actor, getEventBoolValue), asCALL_THISCALL); ROR_ASSERT(result >= 0);
114 result = engine->RegisterObjectMethod("BeamClass", "bool getEventBoolValueBounce(inputEvents, float = 0.2f)", asMETHOD(Actor, getEventBoolValueBounce), asCALL_THISCALL); ROR_ASSERT(result >= 0);
115 result = engine->RegisterObjectMethod("BeamClass", "void clearEventSimulatedValues()", asMETHOD(Actor, clearEventSimulatedValues), asCALL_THISCALL); ROR_ASSERT(result >= 0);
116 result = engine->RegisterObjectMethod("BeamClass", "bool hasEventSimulatedValue(inputEvents)", asMETHOD(Actor, hasEventSimulatedValue), asCALL_THISCALL); ROR_ASSERT(result >= 0);
117 result = engine->RegisterObjectMethod("BeamClass", "float getEventSimulatedValue(inputEvents)", asMETHOD(Actor, getEventSimulatedValue), asCALL_THISCALL); ROR_ASSERT(result >= 0);
118 result = engine->RegisterObjectMethod("BeamClass", "void setEventSimulatedValue(inputEvents, float)", asMETHOD(Actor, setEventSimulatedValue), asCALL_THISCALL); ROR_ASSERT(result >= 0);
119 result = engine->RegisterObjectMethod("BeamClass", "void resetEventSimulatedValue(inputEvents)", asMETHOD(Actor, resetEventSimulatedValue), asCALL_THISCALL); ROR_ASSERT(result >= 0);
120
121 // - subsystems (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
122 result = engine->RegisterObjectMethod("BeamClass", "DashBoardManagerClassPtr@ getDashboardManager()", asMETHOD(Actor, getDashboardManager), asCALL_THISCALL); ROR_ASSERT(result >= 0);
123 result = engine->RegisterObjectMethod("BeamClass", "VehicleAIClassPtr @getVehicleAI()", asMETHOD(Actor,getVehicleAI), asCALL_THISCALL); ROR_ASSERT(result>=0);
124 result = engine->RegisterObjectMethod("BeamClass", "EngineClassPtr @getEngine()", asMETHOD(Actor, getEngine), asCALL_THISCALL); ROR_ASSERT(result >= 0);
125 result = engine->RegisterObjectMethod("BeamClass", "int getAircraftEngineCount()", asMETHOD(Actor, getAircraftEngineCount), asCALL_THISCALL); ROR_ASSERT(result >= 0);
126 result = engine->RegisterObjectMethod("BeamClass", "AircraftEngineClassPtr@ getAircraftEngine(int)", asMETHOD(Actor, getAircraftEngine), asCALL_THISCALL); ROR_ASSERT(result >= 0);
127 result = engine->RegisterObjectMethod("BeamClass", "TurbojetClassPtr@ getTurbojet(int)", asMETHOD(Actor, getTurbojet), asCALL_THISCALL); ROR_ASSERT(result >= 0);
128 result = engine->RegisterObjectMethod("BeamClass", "TurbopropClassPtr@ getTurboprop(int)", asMETHOD(Actor, getTurboprop), asCALL_THISCALL); ROR_ASSERT(result >= 0);
129 result = engine->RegisterObjectMethod("BeamClass", "AutopilotClassPtr@ getAutopilot()", asMETHOD(Actor, getAutopilot), asCALL_THISCALL); ROR_ASSERT(result >= 0);
130 result = engine->RegisterObjectMethod("BeamClass", "int getScrewpropCount()", asMETHOD(Actor, getScrewpropCount), asCALL_THISCALL); ROR_ASSERT(result >= 0);
131 result = engine->RegisterObjectMethod("BeamClass", "ScrewpropClassPtr@ getScrewprop(int)", asMETHOD(Actor, getScrewprop), asCALL_THISCALL); ROR_ASSERT(result >= 0);
132 result = engine->RegisterObjectMethod("BeamClass", "Ogre::MaterialPtr getManagedMaterialInstance(const string &in)", asMETHOD(Actor, getManagedMaterialInstance), asCALL_THISCALL); ROR_ASSERT(result >= 0);
133 result = engine->RegisterObjectMethod("BeamClass", "array<string>@ getManagedMaterialNames()", asFUNCTIONPR([](Actor* self) -> CScriptArray*{
134 return RoR::VectorToScriptArray(self->getManagedMaterialNames(), "string"); }, (Actor*), CScriptArray*), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result>=0);
135
136 // - lights (PLEASE maintain the same ordering as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
137 result = engine->RegisterObjectMethod("BeamClass", "int getBlinkType()", asMETHOD(Actor, getBlinkType), asCALL_THISCALL); ROR_ASSERT(result >= 0);
138 result = engine->RegisterObjectMethod("BeamClass", "void setBlinkType(int)", asMETHOD(Actor, setBlinkType), asCALL_THISCALL); ROR_ASSERT(result >= 0);
139 result = engine->RegisterObjectMethod("BeamClass", "bool getCustomLightVisible(int)", asMETHOD(Actor, getCustomLightVisible), asCALL_THISCALL); ROR_ASSERT(result >= 0);
140 result = engine->RegisterObjectMethod("BeamClass", "void setCustomLightVisible(int, bool)", asMETHOD(Actor, setCustomLightVisible), asCALL_THISCALL); ROR_ASSERT(result >= 0);
141 result = engine->RegisterObjectMethod("BeamClass", "bool getBeaconMode()", asMETHOD(Actor, getBeaconMode), asCALL_THISCALL); ROR_ASSERT(result >= 0);
142 result = engine->RegisterObjectMethod("BeamClass", "void beaconsToggle()", asMETHOD(Actor, beaconsToggle), asCALL_THISCALL); ROR_ASSERT(result >= 0);
143 result = engine->RegisterObjectMethod("BeamClass", "bool getBrakeLightVisible()", asMETHOD(Actor, getBrakeLightVisible), asCALL_THISCALL); ROR_ASSERT(result >= 0);
144 result = engine->RegisterObjectMethod("BeamClass", "bool getReverseLightVisible()", asMETHOD(Actor, getReverseLightVisible), asCALL_THISCALL); ROR_ASSERT(result >= 0);
145 result = engine->RegisterObjectMethod("BeamClass", "int countCustomLights(int)", asMETHOD(Actor, countCustomLights), asCALL_THISCALL); ROR_ASSERT(result >= 0);
146 result = engine->RegisterObjectMethod("BeamClass", "int countFlaresByType(FlareType)", asMETHOD(Actor, countFlaresByType), asCALL_THISCALL); ROR_ASSERT(result >= 0);
147
148 // - organizational (PLEASE maintain the same ordering as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
149 result = engine->RegisterObjectMethod("BeamClass", "string getTruckName()", asMETHOD(Actor,getTruckName), asCALL_THISCALL); ROR_ASSERT(result>=0);
150 result = engine->RegisterObjectMethod("BeamClass", "string getTruckFileName()", asMETHOD(Actor,getTruckFileName), asCALL_THISCALL); ROR_ASSERT(result>=0);
151 result = engine->RegisterObjectMethod("BeamClass", "string getTruckFileResourceGroup()", asMETHOD(Actor, getTruckFileResourceGroup), asCALL_THISCALL); ROR_ASSERT(result >= 0);
152 result = engine->RegisterObjectMethod("BeamClass", "int getTruckType()", asMETHOD(Actor,getTruckType), asCALL_THISCALL); ROR_ASSERT(result>=0);
153 result = engine->RegisterObjectMethod("BeamClass", "string getSectionConfig()", asMETHOD(Actor, getSectionConfig), asCALL_THISCALL); ROR_ASSERT(result >= 0);
154 result = engine->RegisterObjectMethod("BeamClass", "int getInstanceId()", asMETHOD(Actor, getInstanceId), asCALL_THISCALL); ROR_ASSERT(result >= 0);
155}
#define ROR_ASSERT(_EXPR)
Definition Application.h:40
Core data structures for simulation; Everything affected by by either physics, network or user intera...
AngelScript::CScriptArray * VectorToScriptArray(const std::vector< T > &vec, const std::string &decl)
Definition ScriptUtils.h:44
void RegisterActorNative(AngelScript::asIScriptEngine *engine)