Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
ProceduralRoadAngelscriptGeneric.cpp
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2022 Petr Ohlidal
4
5 For more information, see http://www.rigsofrods.org/
6
7 Rigs of Rods is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3, as
9 published by the Free Software Foundation.
10
11 Rigs of Rods is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
18*/
19
21
22#include "../../autowrapper/aswrappedcall.h"
23#include "AngelScriptBindings.h"
24#include "ProceduralManager.h"
25#include "ProceduralRoad.h"
26#include "ScriptEngine.h"
28
29#include <angelscript.h>
30
31using namespace RoR;
32using namespace AngelScript;
34
35// We need to manually define a wrap function for addQuad()
36// since aswrappedcall.h has no support for methods with more than 8 parameters.
37static void ProceduralRoad_addQuad_Generic(asIScriptGeneric* gen)
38{
39 ProceduralRoad* obj = static_cast<ProceduralRoad*>(gen->GetObject());
40 obj->addQuad(
41 *static_cast<Ogre::Vector3*>(gen->GetArgObject(0)), // p1
42 *static_cast<Ogre::Vector3*>(gen->GetArgObject(1)), // p2
43 *static_cast<Ogre::Vector3*>(gen->GetArgObject(2)), // p3
44 *static_cast<Ogre::Vector3*>(gen->GetArgObject(3)), // p4
45 static_cast<TextureFit>(gen->GetArgDWord(4)), // texfit
46 *static_cast<Ogre::Vector3*>(gen->GetArgObject(5)), // pos
47 *static_cast<Ogre::Vector3*>(gen->GetArgObject(6)), // lastpos
48 gen->GetArgFloat(7), // width
49 gen->GetArgByte(8) != 0); // flip
50}
51
52void RoR::RegisterProceduralRoadGeneric(asIScriptEngine* engine)
53{
54 int result = 0;
55
56 // NOTE: enums RoadType and TextureFit are registered in RegisterProceduralRoadCommon()
57
58 // struct ProceduralPoint (ref)
59 ProceduralPoint::RegisterRefCountingObjectGeneric(engine, "ProceduralPointClass");
60 ProceduralPointPtr::RegisterRefCountingObjectPtrGeneric(engine, "ProceduralPointClassPtr", "ProceduralPointClass");
61 result = engine->RegisterObjectBehaviour("ProceduralPointClass", asBEHAVE_FACTORY, "ProceduralPointClass@+ f()", WRAP_FN(ProceduralPointFactory), asCALL_GENERIC); ROR_ASSERT(result >= 0);
62 //get:
63 result = engine->RegisterObjectMethod("ProceduralPointClass", "vector3& get_position() property", WRAP_OBJ_FIRST(ProceduralPoint_get_position), asCALL_GENERIC); ROR_ASSERT(result >= 0);
64 result = engine->RegisterObjectMethod("ProceduralPointClass", "quaternion& get_rotation() property", WRAP_OBJ_FIRST(ProceduralPoint_get_rotation), asCALL_GENERIC); ROR_ASSERT(result >= 0);
65 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_width() property", WRAP_OBJ_FIRST(ProceduralPoint_get_width), asCALL_GENERIC); ROR_ASSERT(result >= 0);
66 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_border_width() property", WRAP_OBJ_FIRST(ProceduralPoint_get_border_width), asCALL_GENERIC); ROR_ASSERT(result >= 0);
67 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_border_height() property", WRAP_OBJ_FIRST(ProceduralPoint_get_border_height), asCALL_GENERIC); ROR_ASSERT(result >= 0);
68 result = engine->RegisterObjectMethod("ProceduralPointClass", "RoadType get_type() property", WRAP_OBJ_FIRST(ProceduralPoint_get_type), asCALL_GENERIC); ROR_ASSERT(result >= 0);
69 result = engine->RegisterObjectMethod("ProceduralPointClass", "int get_pillar_type() property", WRAP_OBJ_FIRST(ProceduralPoint_get_pillar_type), asCALL_GENERIC); ROR_ASSERT(result >= 0);
70 //set:
71 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_position(const vector3& in pos) property", WRAP_OBJ_FIRST(ProceduralPoint_set_position), asCALL_GENERIC); ROR_ASSERT(result >= 0);
72 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_rotation(const quaternion& in rot) property", WRAP_OBJ_FIRST(ProceduralPoint_set_rotation), asCALL_GENERIC); ROR_ASSERT(result >= 0);
73 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_width(float width) property", WRAP_OBJ_FIRST(ProceduralPoint_set_width), asCALL_GENERIC); ROR_ASSERT(result >= 0);
74 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_border_width(float bwidth) property", WRAP_OBJ_FIRST(ProceduralPoint_set_border_width), asCALL_GENERIC); ROR_ASSERT(result >= 0);
75 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_border_height(float bheight) property", WRAP_OBJ_FIRST(ProceduralPoint_set_border_height), asCALL_GENERIC); ROR_ASSERT(result >= 0);
76 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_type(RoadType type) property", WRAP_OBJ_FIRST(ProceduralPoint_set_type), asCALL_GENERIC); ROR_ASSERT(result >= 0);
77 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_pillar_type(int type) property", WRAP_OBJ_FIRST(ProceduralPoint_set_pillar_type), asCALL_GENERIC); ROR_ASSERT(result >= 0);
78
79 // class ProceduralRoad (ref)
80 ProceduralRoad::RegisterRefCountingObjectGeneric(engine, "ProceduralRoadClass");
81 ProceduralRoadPtr::RegisterRefCountingObjectPtrGeneric(engine, "ProceduralRoadClassPtr", "ProceduralRoadClass");
82 result = engine->RegisterObjectBehaviour("ProceduralRoadClass", asBEHAVE_FACTORY, "ProceduralRoadClass@+ f()", WRAP_FN(ProceduralRoadFactory), asCALL_GENERIC); ROR_ASSERT(result >= 0);
83 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void addBlock(vector3 pos, quaternion rot, RoadType type, float width, float border_width, float border_height, int pillar_type = 1)", WRAP_MFN(RoR::ProceduralRoad, addBlock), asCALL_GENERIC); ROR_ASSERT(result >= 0);
84 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void addQuad(vector3 p1, vector3 p2, vector3 p3, vector3 p4, TextureFit texfit, vector3 pos, vector3 lastpos, float width, bool flip = false)", asFUNCTION(ProceduralRoad_addQuad_Generic), asCALL_GENERIC); ROR_ASSERT(result >= 0);
85 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void addCollisionQuad(vector3 p1, vector3 p2, vector3 p3, vector3 p4, const string&in gm_name, bool flip = false)", WRAP_MFN_PR(RoR::ProceduralRoad, addCollisionQuad, (Ogre::Vector3, Ogre::Vector3, Ogre::Vector3, Ogre::Vector3, std::string const&, bool), void), asCALL_GENERIC); ROR_ASSERT(result >= 0);
86 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void finish()", WRAP_OBJ_FIRST(ProceduralRoad_finish), asCALL_GENERIC); ROR_ASSERT(result >= 0);
87 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void setCollisionEnabled(bool v)", WRAP_MFN(RoR::ProceduralRoad, setCollisionEnabled), asCALL_GENERIC); ROR_ASSERT(result >= 0);
88
89 // class ProceduralObject (ref)
90 ProceduralObject::RegisterRefCountingObjectGeneric(engine, "ProceduralObjectClass");
91 ProceduralObjectPtr::RegisterRefCountingObjectPtrGeneric(engine, "ProceduralObjectClassPtr", "ProceduralObjectClass");
92 result = engine->RegisterObjectBehaviour("ProceduralObjectClass", asBEHAVE_FACTORY, "ProceduralObjectClass@+ f()", WRAP_FN(ProceduralObjectFactory), asCALL_GENERIC); ROR_ASSERT(result >= 0);
93 result = engine->RegisterObjectMethod("ProceduralObjectClass", "string getName()", WRAP_MFN(RoR::ProceduralObject, getName), asCALL_GENERIC); ROR_ASSERT(result >= 0);
94 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void setName(const string&in)", WRAP_MFN(RoR::ProceduralObject, setName), asCALL_GENERIC); ROR_ASSERT(result >= 0);
95 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void addPoint(ProceduralPointClassPtr @)", WRAP_MFN(RoR::ProceduralObject, addPoint), asCALL_GENERIC); ROR_ASSERT(result >= 0);
96 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void insertPoint(int pos, ProceduralPointClassPtr @)", WRAP_MFN(RoR::ProceduralObject, insertPoint), asCALL_GENERIC); ROR_ASSERT(result >= 0);
97 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void deletePoint(int pos)", WRAP_MFN(RoR::ProceduralObject, deletePoint), asCALL_GENERIC); ROR_ASSERT(result >= 0);
98 result = engine->RegisterObjectMethod("ProceduralObjectClass", "ProceduralPointClassPtr @getPoint(int pos)", WRAP_MFN(RoR::ProceduralObject, getPoint), asCALL_GENERIC); ROR_ASSERT(result >= 0);
99 result = engine->RegisterObjectMethod("ProceduralObjectClass", "int getNumPoints()", WRAP_MFN(RoR::ProceduralObject, getNumPoints), asCALL_GENERIC); ROR_ASSERT(result >= 0);
100 result = engine->RegisterObjectMethod("ProceduralObjectClass", "ProceduralRoadClassPtr @getRoad()", WRAP_MFN(ProceduralObject, getRoad), asCALL_GENERIC); ROR_ASSERT(result >= 0);
101 result = engine->RegisterObjectMethod("ProceduralObjectClass", "int get_smoothing_num_splits() property", WRAP_OBJ_FIRST(ProceduralObject_get_smoothing_num_splits), asCALL_GENERIC); ROR_ASSERT(result >= 0);
102 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_smoothing_num_splits(int) property", WRAP_OBJ_FIRST(ProceduralObject_set_smoothing_num_splits), asCALL_GENERIC); ROR_ASSERT(result >= 0);
103 result = engine->RegisterObjectMethod("ProceduralObjectClass", "bool get_collision_enabled() property", WRAP_OBJ_FIRST(ProceduralObject_get_collision_enabled), asCALL_GENERIC); ROR_ASSERT(result >= 0);
104 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_collision_enabled(bool) property", WRAP_OBJ_FIRST(ProceduralObject_set_collision_enabled), asCALL_GENERIC); ROR_ASSERT(result >= 0);
105 result = engine->RegisterObjectMethod("ProceduralObjectClass", "string get_custom_material() property", asFUNCTION(ProceduralObject_get_custom_material), asCALL_GENERIC); ROR_ASSERT(result >= 0);
106 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_custom_material(const string&in) property", WRAP_OBJ_FIRST(ProceduralObject_set_custom_material), asCALL_GENERIC); ROR_ASSERT(result >= 0);
107 result = engine->RegisterObjectMethod("ProceduralObjectClass", "string get_custom_groundmodel() property", WRAP_OBJ_FIRST(ProceduralObject_get_custom_groundmodel), asCALL_GENERIC); ROR_ASSERT(result >= 0);
108 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_custom_groundmodel(const string&in) property", WRAP_OBJ_FIRST(ProceduralObject_set_custom_groundmodel), asCALL_GENERIC); ROR_ASSERT(result >= 0);
109
110 // class ProceduralManager (ref)
111 ProceduralManager::RegisterRefCountingObjectGeneric(engine, "ProceduralManagerClass");
112 ProceduralManagerPtr::RegisterRefCountingObjectPtrGeneric(engine, "ProceduralManagerClassPtr", "ProceduralManagerClass");
113 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void addObject(ProceduralObjectClassPtr@)", WRAP_MFN(ProceduralManager, addObject), asCALL_GENERIC); ROR_ASSERT(result>=0);
114 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void removeObject(ProceduralObjectClassPtr@)", WRAP_MFN(ProceduralManager, removeObject), asCALL_GENERIC); ROR_ASSERT(result >= 0);
115 result = engine->RegisterObjectMethod("ProceduralManagerClass", "int getNumObjects()", WRAP_MFN(RoR::ProceduralManager, getNumObjects), asCALL_GENERIC); ROR_ASSERT(result >= 0);
116 result = engine->RegisterObjectMethod("ProceduralManagerClass", "ProceduralObjectClassPtr @getObject(int pos)", WRAP_MFN(ProceduralManager, getObject), asCALL_GENERIC); ROR_ASSERT(result >= 0);
117 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void rebuildObjectMesh(ProceduralObjectClassPtr@)", WRAP_MFN(ProceduralManager, rebuildObjectMesh), asCALL_GENERIC); ROR_ASSERT(result >= 0);
118 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void deleteObjectMesh(ProceduralObjectClassPtr@)", WRAP_MFN(ProceduralManager, deleteObjectMesh), asCALL_GENERIC); ROR_ASSERT(result >= 0);
119}
#define ROR_ASSERT(_EXPR)
Definition Application.h:40
static void ProceduralRoad_addQuad_Generic(asIScriptGeneric *gen)
Helper/wrapper functions shared by native (ProceduralRoadAngelscript.cpp) and generic (ProceduralRoad...
#define WRAP_MFN(ClassType, name)
#define WRAP_OBJ_FIRST(name)
#define WRAP_MFN_PR(ClassType, name, Parameters, ReturnType)
#define WRAP_FN(name)
static void RegisterRefCountingObjectPtrGeneric(AS_NAMESPACE_QUALIFIER asIScriptEngine *engine, const char *handle_name, const char *obj_name)
Same as RegisterRefCountingObjectPtr() but uses the generic calling convention (for platforms with AS...
void addQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, TextureFit texfit, Ogre::Vector3 pos, Ogre::Vector3 lastpos, float width, bool flip=false)
void RegisterProceduralRoadGeneric(AngelScript::asIScriptEngine *engine)
static Ogre::Vector3 & ProceduralPoint_get_position(ProceduralPoint *self)
static void ProceduralPoint_set_position(ProceduralPoint *self, const Ogre::Vector3 &pos)
static void ProceduralPoint_set_width(ProceduralPoint *self, float width)
static void ProceduralPoint_set_type(ProceduralPoint *self, RoadType type)
static void ProceduralPoint_set_rotation(ProceduralPoint *self, const Ogre::Quaternion &rot)
static void ProceduralRoad_finish(ProceduralRoad *self)
The script API has no scene node parameter - the road mesh is attached under the grouping scene node ...
static void ProceduralPoint_set_border_height(ProceduralPoint *self, float bheight)
static float ProceduralPoint_get_width(ProceduralPoint *self)
static int ProceduralPoint_get_pillar_type(ProceduralPoint *self)
static void ProceduralObject_set_custom_groundmodel(ProceduralObject *self, const std::string &n)
static std::string ProceduralObject_get_custom_material(ProceduralObject *self)
static bool ProceduralObject_get_collision_enabled(ProceduralObject *self)
static void ProceduralObject_set_custom_material(ProceduralObject *self, const std::string &n)
static void ProceduralPoint_set_pillar_type(ProceduralPoint *self, int type)
static void ProceduralObject_set_smoothing_num_splits(ProceduralObject *self, int n)
static ProceduralRoad * ProceduralRoadFactory(const std::string &groundmodelName="")
static std::string ProceduralObject_get_custom_groundmodel(ProceduralObject *self)
static void ProceduralPoint_set_border_width(ProceduralPoint *self, float bwidth)
static Ogre::Quaternion & ProceduralPoint_get_rotation(ProceduralPoint *self)
static RoadType ProceduralPoint_get_type(ProceduralPoint *self)
static float ProceduralPoint_get_border_height(ProceduralPoint *self)
static void ProceduralObject_set_collision_enabled(ProceduralObject *self, bool n)
static float ProceduralPoint_get_border_width(ProceduralPoint *self)
static int ProceduralObject_get_smoothing_num_splits(ProceduralObject *self)