RigsofRods
Soft-body Physics Simulation
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 
29 using namespace AngelScript;
30 
31 void RoR::RegisterActor(asIScriptEngine *engine)
32 {
33  int result;
34 
35  // enum truckStates
36  result = engine->RegisterEnum("TruckState"); ROR_ASSERT(result>=0);
37  result = engine->RegisterEnumValue("TruckState", "TS_SIMULATED", static_cast<int>(ActorState::LOCAL_SIMULATED)); ROR_ASSERT(result>=0);
38  result = engine->RegisterEnumValue("TruckState", "TS_SLEEPING", static_cast<int>(ActorState::LOCAL_SLEEPING)); ROR_ASSERT(result>=0);
39  result = engine->RegisterEnumValue("TruckState", "TS_NETWORKED", static_cast<int>(ActorState::NETWORKED_OK)); ROR_ASSERT(result>=0);
40 
41  // enum truckTypes
42  result = engine->RegisterEnum("truckTypes"); ROR_ASSERT(result>=0);
43  result = engine->RegisterEnumValue("truckTypes", "TT_NOT_DRIVEABLE", NOT_DRIVEABLE); ROR_ASSERT(result>=0);
44  result = engine->RegisterEnumValue("truckTypes", "TT_TRUCK", TRUCK); ROR_ASSERT(result>=0);
45  result = engine->RegisterEnumValue("truckTypes", "TT_AIRPLANE", AIRPLANE); ROR_ASSERT(result>=0);
46  result = engine->RegisterEnumValue("truckTypes", "TT_BOAT", BOAT); ROR_ASSERT(result>=0);
47  result = engine->RegisterEnumValue("truckTypes", "TT_MACHINE", MACHINE); ROR_ASSERT(result>=0);
48  result = engine->RegisterEnumValue("truckTypes", "TT_AI", AI); ROR_ASSERT(result>=0);
49 
50  // enum FlareType
51  result = engine->RegisterEnum("FlareType"); ROR_ASSERT(result >= 0);
52  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_NONE", (int)FlareType::NONE); ROR_ASSERT(result >= 0);
53  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_HEADLIGHT", (int)FlareType::HEADLIGHT); ROR_ASSERT(result >= 0);
54  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_HIGH_BEAM", (int)FlareType::HIGH_BEAM); ROR_ASSERT(result >= 0);
55  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_FOG_LIGHT", (int)FlareType::FOG_LIGHT); ROR_ASSERT(result >= 0);
56  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_TAIL_LIGHT", (int)FlareType::TAIL_LIGHT); ROR_ASSERT(result >= 0);
57  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_BRAKE_LIGHT", (int)FlareType::BRAKE_LIGHT); ROR_ASSERT(result >= 0);
58  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_REVERSE_LIGHT", (int)FlareType::REVERSE_LIGHT); ROR_ASSERT(result >= 0);
59  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_SIDELIGHT", (int)FlareType::SIDELIGHT); ROR_ASSERT(result >= 0);
60  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_BLINKER_LEFT", (int)FlareType::BLINKER_LEFT); ROR_ASSERT(result >= 0);
61  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_BLINKER_RIGHT", (int)FlareType::BLINKER_RIGHT); ROR_ASSERT(result >= 0);
62  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_USER", (int)FlareType::USER); ROR_ASSERT(result >= 0);
63  result = engine->RegisterEnumValue("FlareType", "FLARE_TYPE_DASHBOARD", (int)FlareType::DASHBOARD); ROR_ASSERT(result >= 0);
64 
65  // enum BlinkType
66  result = engine->RegisterEnum("BlinkType"); ROR_ASSERT(result >= 0);
67  result = engine->RegisterEnumValue("BlinkType", "BLINK_NONE", (int)BLINK_NONE); ROR_ASSERT(result >= 0);
68  result = engine->RegisterEnumValue("BlinkType", "BLINK_LEFT", (int)BLINK_LEFT); ROR_ASSERT(result >= 0);
69  result = engine->RegisterEnumValue("BlinkType", "BLINK_RIGHT", (int)BLINK_RIGHT); ROR_ASSERT(result >= 0);
70  result = engine->RegisterEnumValue("BlinkType", "BLINK_WARN", (int)BLINK_WARN); ROR_ASSERT(result >= 0);
71 
72  // enum ActorModifyRequestType
73  result = engine->RegisterEnum("ActorModifyRequestType"); ROR_ASSERT(result >= 0);
74  result = engine->RegisterEnumValue("ActorModifyRequestType", "ACTOR_MODIFY_REQUEST_INVALID", (int)ActorModifyRequest::Type::INVALID); ROR_ASSERT(result >= 0);
75  result = engine->RegisterEnumValue("ActorModifyRequestType", "ACTOR_MODIFY_REQUEST_RELOAD", (int)ActorModifyRequest::Type::RELOAD); ROR_ASSERT(result >= 0);
76  result = engine->RegisterEnumValue("ActorModifyRequestType", "ACTOR_MODIFY_REQUEST_RESET_ON_INIT_POS", (int)ActorModifyRequest::Type::RESET_ON_INIT_POS); ROR_ASSERT(result >= 0);
77  result = engine->RegisterEnumValue("ActorModifyRequestType", "ACTOR_MODIFY_REQUEST_RESET_ON_SPOT", (int)ActorModifyRequest::Type::RESET_ON_SPOT); ROR_ASSERT(result >= 0);
78  result = engine->RegisterEnumValue("ActorModifyRequestType", "ACTOR_MODIFY_REQUEST_SOFT_RESET", (int)ActorModifyRequest::Type::SOFT_RESET); ROR_ASSERT(result >= 0);
79  result = engine->RegisterEnumValue("ActorModifyRequestType", "ACTOR_MODIFY_REQUEST_RESTORE_SAVED", (int)ActorModifyRequest::Type::RESTORE_SAVED); ROR_ASSERT(result >= 0);
80  result = engine->RegisterEnumValue("ActorModifyRequestType", "ACTOR_MODIFY_REQUEST_WAKE_UP", (int)ActorModifyRequest::Type::WAKE_UP); ROR_ASSERT(result >= 0);
81 
82  // class Actor (historically Beam)
83  Actor::RegisterRefCountingObject(engine, "BeamClass");
84  ActorPtr::RegisterRefCountingObjectPtr(engine, "BeamClassPtr", "BeamClass");
85 
86  // - physics state (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
87  result = engine->RegisterObjectMethod("BeamClass", "TruckState getTruckState()", asMETHOD(Actor,getTruckState), asCALL_THISCALL); ROR_ASSERT(result>=0);
88  result = engine->RegisterObjectMethod("BeamClass", "vector3 getPosition()", asMETHOD(Actor,getPosition), asCALL_THISCALL); ROR_ASSERT(result>=0);
89  /*alias:*/result = engine->RegisterObjectMethod("BeamClass", "vector3 getVehiclePosition()", asMETHOD(Actor,getPosition), asCALL_THISCALL); ROR_ASSERT(result>=0);
90  result = engine->RegisterObjectMethod("BeamClass", "float getRotation()", asMETHOD(Actor,getRotation), asCALL_THISCALL); ROR_ASSERT(result>=0);
91  /*alias:*/result = engine->RegisterObjectMethod("BeamClass", "float getHeadingDirectionAngle()", asMETHOD(Actor,getRotation), asCALL_THISCALL); ROR_ASSERT(result>=0);
92  result = engine->RegisterObjectMethod("BeamClass", "quaternion getOrientation()", asMETHOD(Actor,getOrientation), asCALL_THISCALL); ROR_ASSERT(result>=0);
93  result = engine->RegisterObjectMethod("BeamClass", "float getSpeed()", asMETHOD(Actor,getSpeed), asCALL_THISCALL); ROR_ASSERT(result>=0);
94  result = engine->RegisterObjectMethod("BeamClass", "vector3 getGForces()", asMETHOD(Actor,getGForces), asCALL_THISCALL); ROR_ASSERT(result>=0);
95  result = engine->RegisterObjectMethod("BeamClass", "float getTotalMass(bool)", asMETHOD(Actor,getTotalMass), asCALL_THISCALL); ROR_ASSERT(result>=0);
96  result = engine->RegisterObjectMethod("BeamClass", "int getNodeCount()", asMETHOD(Actor,getNodeCount), asCALL_THISCALL); ROR_ASSERT(result>=0);
97  result = engine->RegisterObjectMethod("BeamClass", "vector3 getNodePosition(int)", asMETHOD(Actor,getNodePosition), asCALL_THISCALL); ROR_ASSERT(result>=0);
98  result = engine->RegisterObjectMethod("BeamClass", "bool isNodeWheelRim(int)", asMETHOD(Actor,isNodeWheelRim), asCALL_THISCALL); ROR_ASSERT(result>=0);
99  result = engine->RegisterObjectMethod("BeamClass", "bool isNodeWheelTire(int)", asMETHOD(Actor,isNodeWheelTire), asCALL_THISCALL); ROR_ASSERT(result>=0);
100  result = engine->RegisterObjectMethod("BeamClass", "int getWheelNodeCount()", asMETHOD(Actor,getWheelNodeCount), asCALL_THISCALL); ROR_ASSERT(result>=0);
101  result = engine->RegisterObjectMethod("BeamClass", "float getWheelSpeed()", asMETHOD(Actor,getWheelSpeed), asCALL_THISCALL); ROR_ASSERT(result>=0);
102  result = engine->RegisterObjectMethod("BeamClass", "void reset(bool)", asMETHOD(Actor,reset), asCALL_THISCALL); ROR_ASSERT(result>=0);
103 
104  // - physics editing (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
105  result = engine->RegisterObjectMethod("BeamClass", "void scaleTruck(float)", asMETHOD(Actor,scaleTruck), asCALL_THISCALL); ROR_ASSERT(result>=0);
106  result = engine->RegisterObjectMethod("BeamClass", "void setMass(float)", asMETHOD(Actor,setMass), asCALL_THISCALL); ROR_ASSERT(result>=0);
107 
108  // - user interaction (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
109  result = engine->RegisterObjectMethod("BeamClass", "void parkingbrakeToggle()", asMETHOD(Actor,parkingbrakeToggle), asCALL_THISCALL); ROR_ASSERT(result>=0);
110  result = engine->RegisterObjectMethod("BeamClass", "void tractioncontrolToggle()", asMETHOD(Actor,tractioncontrolToggle), asCALL_THISCALL); ROR_ASSERT(result>=0);
111  result = engine->RegisterObjectMethod("BeamClass", "void antilockbrakeToggle()", asMETHOD(Actor,antilockbrakeToggle), asCALL_THISCALL); ROR_ASSERT(result>=0);
112  result = engine->RegisterObjectMethod("BeamClass", "void toggleCustomParticles()", asMETHOD(Actor,toggleCustomParticles), asCALL_THISCALL); ROR_ASSERT(result>=0);
113  result = engine->RegisterObjectMethod("BeamClass", "bool getCustomParticleMode()", asMETHOD(Actor,getCustomParticleMode), asCALL_THISCALL); ROR_ASSERT(result>=0);
114  result = engine->RegisterObjectMethod("BeamClass", "bool isLocked()", asMETHOD(Actor,isLocked), asCALL_THISCALL); ROR_ASSERT(result>=0);
115 
116  // - subsystems (PLEASE maintain the same order as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
117  result = engine->RegisterObjectMethod("BeamClass", "VehicleAIClassPtr @getVehicleAI()", asMETHOD(Actor,getVehicleAI), asCALL_THISCALL); ROR_ASSERT(result>=0);
118  result = engine->RegisterObjectMethod("BeamClass", "Ogre::MaterialPtr getManagedMaterialInstance(const string &in)", asMETHOD(Actor,getManagedMaterialInstance), asCALL_THISCALL); ROR_ASSERT(result>=0);
119  result = engine->RegisterObjectMethod("BeamClass", "array<string>@ getManagedMaterialNames()", asFUNCTIONPR([](Actor* self) -> CScriptArray*{
120  return RoR::VectorToScriptArray(self->getManagedMaterialNames(), "string"); }, (Actor*), CScriptArray*), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result>=0);
121 
122  // - lights (PLEASE maintain the same ordering as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
123  result = engine->RegisterObjectMethod("BeamClass", "int getBlinkType()", asMETHOD(Actor, getBlinkType), asCALL_THISCALL); ROR_ASSERT(result >= 0);
124  result = engine->RegisterObjectMethod("BeamClass", "void setBlinkType(int)", asMETHOD(Actor, setBlinkType), asCALL_THISCALL); ROR_ASSERT(result >= 0);
125  result = engine->RegisterObjectMethod("BeamClass", "bool getCustomLightVisible(int)", asMETHOD(Actor, getCustomLightVisible), asCALL_THISCALL); ROR_ASSERT(result >= 0);
126  result = engine->RegisterObjectMethod("BeamClass", "void setCustomLightVisible(int, bool)", asMETHOD(Actor, setCustomLightVisible), asCALL_THISCALL); ROR_ASSERT(result >= 0);
127  result = engine->RegisterObjectMethod("BeamClass", "bool getBeaconMode()", asMETHOD(Actor, getBeaconMode), asCALL_THISCALL); ROR_ASSERT(result >= 0);
128  result = engine->RegisterObjectMethod("BeamClass", "void beaconsToggle()", asMETHOD(Actor, beaconsToggle), asCALL_THISCALL); ROR_ASSERT(result >= 0);
129  result = engine->RegisterObjectMethod("BeamClass", "bool getBrakeLightVisible()", asMETHOD(Actor, getBrakeLightVisible), asCALL_THISCALL); ROR_ASSERT(result >= 0);
130  result = engine->RegisterObjectMethod("BeamClass", "bool getReverseLightVisible()", asMETHOD(Actor, getReverseLightVisible), asCALL_THISCALL); ROR_ASSERT(result >= 0);
131  result = engine->RegisterObjectMethod("BeamClass", "int countCustomLights(int)", asMETHOD(Actor, countCustomLights), asCALL_THISCALL); ROR_ASSERT(result >= 0);
132  result = engine->RegisterObjectMethod("BeamClass", "int countFlaresByType(FlareType)", asMETHOD(Actor, countFlaresByType), asCALL_THISCALL); ROR_ASSERT(result >= 0);
133 
134  // - organizational (PLEASE maintain the same ordering as 'Actor.h' and 'doc/angelscript/.../BeamClass.h')
135  result = engine->RegisterObjectMethod("BeamClass", "string getTruckName()", asMETHOD(Actor,getTruckName), asCALL_THISCALL); ROR_ASSERT(result>=0);
136  result = engine->RegisterObjectMethod("BeamClass", "string getTruckFileName()", asMETHOD(Actor,getTruckFileName), asCALL_THISCALL); ROR_ASSERT(result>=0);
137  result = engine->RegisterObjectMethod("BeamClass", "string getTruckFileResourceGroup()", asMETHOD(Actor, getTruckFileResourceGroup), asCALL_THISCALL); ROR_ASSERT(result >= 0);
138  result = engine->RegisterObjectMethod("BeamClass", "int getTruckType()", asMETHOD(Actor,getTruckType), asCALL_THISCALL); ROR_ASSERT(result>=0);
139  result = engine->RegisterObjectMethod("BeamClass", "string getSectionConfig()", asMETHOD(Actor, getSectionConfig), asCALL_THISCALL); ROR_ASSERT(result >= 0);
140  result = engine->RegisterObjectMethod("BeamClass", "int getInstanceId()", asMETHOD(Actor, getInstanceId), asCALL_THISCALL); ROR_ASSERT(result >= 0);
141 }
ROR_ASSERT
#define ROR_ASSERT(_EXPR)
Definition: Application.h:40
RoR::VectorToScriptArray
AngelScript::CScriptArray * VectorToScriptArray(const std::vector< T > &vec, const std::string &decl)
Definition: ScriptUtils.h:42
RoR::MACHINE
@ MACHINE
its a machine
Definition: SimData.h:95
RoR::TRUCK
@ TRUCK
its a truck (or other land vehicle)
Definition: SimData.h:92
AngelScriptBindings.h
RoR::NOT_DRIVEABLE
@ NOT_DRIVEABLE
not drivable at all
Definition: SimData.h:91
Actor.h
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
RoR::RegisterActor
void RegisterActor(AngelScript::asIScriptEngine *engine)
defined in ActorAngelscript.cpp
ScriptEngine.h
RoR::BLINK_RIGHT
@ BLINK_RIGHT
Definition: SimData.h:124
RoR::BLINK_WARN
@ BLINK_WARN
Definition: SimData.h:125
RoR::AIRPLANE
@ AIRPLANE
its an airplane
Definition: SimData.h:93
RoR::BLINK_LEFT
@ BLINK_LEFT
Definition: SimData.h:123
RoR::BLINK_NONE
@ BLINK_NONE
Definition: SimData.h:122
ScriptUtils.h
RoR::BOAT
@ BOAT
its a boat
Definition: SimData.h:94
RoR::AI
@ AI
machine controlled by an Artificial Intelligence
Definition: SimData.h:96