Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
ProceduralRoadAngelscript.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
22
23#include "ProceduralManager.h"
24#include "ProceduralRoad.h"
25#include "ScriptEngine.h"
26
27using namespace RoR;
28using namespace AngelScript;
29
31{
32 return new ProceduralPoint();
33}
34
39
41{
42 return new ProceduralRoad();
43}
44
45void RoR::RegisterProceduralRoad(asIScriptEngine* engine)
46{
47 int result = 0;
48
49 // enum RoadType
50 result = engine->RegisterEnum("RoadType"); ROR_ASSERT(result >= 0);
51 result = engine->RegisterEnumValue("RoadType", "ROAD_AUTOMATIC", (int)RoadType::ROAD_AUTOMATIC); ROR_ASSERT(result >= 0);
52 result = engine->RegisterEnumValue("RoadType", "ROAD_FLAT", (int)RoadType::ROAD_FLAT); ROR_ASSERT(result >= 0);
53 result = engine->RegisterEnumValue("RoadType", "ROAD_LEFT", (int)RoadType::ROAD_LEFT); ROR_ASSERT(result >= 0);
54 result = engine->RegisterEnumValue("RoadType", "ROAD_RIGHT", (int)RoadType::ROAD_RIGHT); ROR_ASSERT(result >= 0);
55 result = engine->RegisterEnumValue("RoadType", "ROAD_BOTH", (int)RoadType::ROAD_BOTH); ROR_ASSERT(result >= 0);
56 result = engine->RegisterEnumValue("RoadType", "ROAD_BRIDGE", (int)RoadType::ROAD_BRIDGE); ROR_ASSERT(result >= 0);
57 result = engine->RegisterEnumValue("RoadType", "ROAD_MONORAIL", (int)RoadType::ROAD_MONORAIL); ROR_ASSERT(result >= 0);
58
59 // enum TextureFit
60 result = engine->RegisterEnum("TextureFit"); ROR_ASSERT(result >= 0);
61 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_NONE", (int)TextureFit::TEXFIT_NONE); ROR_ASSERT(result >= 0);
62 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_BRICKWALL", (int)TextureFit::TEXFIT_BRICKWALL); ROR_ASSERT(result >= 0);
63 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_ROADS1", (int)TextureFit::TEXFIT_ROADS1); ROR_ASSERT(result >= 0);
64 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_ROADS2", (int)TextureFit::TEXFIT_ROADS2); ROR_ASSERT(result >= 0);
65 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_ROAD", (int)TextureFit::TEXFIT_ROAD); ROR_ASSERT(result >= 0);
66 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_ROADS3", (int)TextureFit::TEXFIT_ROADS3); ROR_ASSERT(result >= 0);
67 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_ROADS4", (int)TextureFit::TEXFIT_ROADS4); ROR_ASSERT(result >= 0);
68 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_CONCRETEWALL", (int)TextureFit::TEXFIT_CONCRETEWALL); ROR_ASSERT(result >= 0);
69 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_CONCRETEWALLI", (int)TextureFit::TEXFIT_CONCRETEWALLI); ROR_ASSERT(result >= 0);
70 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_CONCRETETOP", (int)TextureFit::TEXFIT_CONCRETETOP); ROR_ASSERT(result >= 0);
71 result = engine->RegisterEnumValue("TextureFit", "TEXFIT_CONCRETEUNDER", (int)TextureFit::TEXFIT_CONCRETEUNDER); ROR_ASSERT(result >= 0);
72
73 // struct ProceduralPoint (ref)
74 // NOTE: Using property-accessors because `offsetof()` cannot be used with derived classes (see https://stackoverflow.com/q/1129894)
75 // NOTE: Using lambdas to define the property-accessor functions because #lazy.
76 ProceduralPoint::RegisterRefCountingObject(engine, "ProceduralPointClass");
77 ProceduralPointPtr::RegisterRefCountingObjectPtr(engine, "ProceduralPointClassPtr", "ProceduralPointClass");
78 result = engine->RegisterObjectBehaviour("ProceduralPointClass", asBEHAVE_FACTORY, "ProceduralPointClass@+ f()", asFUNCTION(ProceduralPointFactory), asCALL_CDECL); ROR_ASSERT(result >= 0);
79 //get (note: for compound data types like vector3 we must return non-const references so that expressions like `ppoint.position.y = 100.f` still compile and work):
80 result = engine->RegisterObjectMethod("ProceduralPointClass", "vector3& get_position() property", asFUNCTIONPR([](ProceduralPoint* self) -> Ogre::Vector3& { return self->position; }, (ProceduralPoint*), Ogre::Vector3&), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
81 result = engine->RegisterObjectMethod("ProceduralPointClass", "quaternion& get_rotation() property", asFUNCTIONPR([](ProceduralPoint* self) -> Ogre::Quaternion& { return self->rotation; }, (ProceduralPoint*), Ogre::Quaternion&), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
82 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_width() property", asFUNCTIONPR([](ProceduralPoint* self) { return self->width; }, (ProceduralPoint*), float), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
83 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_border_width() property", asFUNCTIONPR([](ProceduralPoint* self) { return self->bwidth; }, (ProceduralPoint*), float), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
84 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_border_height() property", asFUNCTIONPR([](ProceduralPoint* self) { return self->bheight; }, (ProceduralPoint*), float), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
85 result = engine->RegisterObjectMethod("ProceduralPointClass", "RoadType get_type() property", asFUNCTIONPR([](ProceduralPoint* self) { return self->type; }, (ProceduralPoint*), RoadType), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
86 result = engine->RegisterObjectMethod("ProceduralPointClass", "int get_pillar_type() property", asFUNCTIONPR([](ProceduralPoint* self) { return self->pillartype; }, (ProceduralPoint*), int), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
87 //set:
88 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_position(const vector3& in pos) property", asFUNCTIONPR([](ProceduralPoint* self, const Ogre::Vector3& pos) { self->position = pos; }, (ProceduralPoint*, const Ogre::Vector3&), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
89 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_rotation(const quaternion& in rot) property", asFUNCTIONPR([](ProceduralPoint* self, const Ogre::Quaternion& rot) { self->rotation = rot; }, (ProceduralPoint*, const Ogre::Quaternion&), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
90 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_width(float width) property", asFUNCTIONPR([](ProceduralPoint* self, float width) { self->width = width; }, (ProceduralPoint*, float), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
91 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_border_width(float bwidth) property", asFUNCTIONPR([](ProceduralPoint* self, float bwidth) { self->bwidth = bwidth; }, (ProceduralPoint*, float), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
92 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_border_height(float bheight) property", asFUNCTIONPR([](ProceduralPoint* self, float bheight) { self->bheight = bheight; }, (ProceduralPoint*, float), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
93 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_type(RoadType type) property", asFUNCTIONPR([](ProceduralPoint* self, RoadType type) { self->type = type; }, (ProceduralPoint*, RoadType), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
94 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_pillar_type(int type) property", asFUNCTIONPR([](ProceduralPoint* self, int type) { self->pillartype = type; }, (ProceduralPoint*, int), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
95
96 // class ProceduralRoad (ref)
97 ProceduralRoad::RegisterRefCountingObject(engine, "ProceduralRoadClass");
98 ProceduralRoadPtr::RegisterRefCountingObjectPtr(engine, "ProceduralRoadClassPtr", "ProceduralRoadClass");
99 result = engine->RegisterObjectBehaviour("ProceduralRoadClass", asBEHAVE_FACTORY, "ProceduralRoadClass@+ f()", asFUNCTION(ProceduralRoadFactory), asCALL_CDECL); ROR_ASSERT(result >= 0);
100 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void addBlock(vector3 pos, quaternion rot, RoadType type, float width, float border_width, float border_height, int pillar_type = 1)", asMETHOD(RoR::ProceduralRoad, addBlock), asCALL_THISCALL); ROR_ASSERT(result >= 0);
101 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)", asMETHOD(RoR::ProceduralRoad, addQuad), asCALL_THISCALL); ROR_ASSERT(result >= 0);
102 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void addCollisionQuad(vector3 p1, vector3 p2, vector3 p3, vector3 p4, const string&in gm_name, bool flip = false)", asMETHODPR(RoR::ProceduralRoad, addCollisionQuad, (Ogre::Vector3, Ogre::Vector3, Ogre::Vector3, Ogre::Vector3, std::string const&, bool), void), asCALL_THISCALL); ROR_ASSERT(result >= 0);
103 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void createMesh()", asMETHOD(RoR::ProceduralRoad, createMesh), asCALL_THISCALL); ROR_ASSERT(result >= 0);
104 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void finish()", asMETHOD(RoR::ProceduralRoad, finish), asCALL_THISCALL); ROR_ASSERT(result >= 0);
105 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void setCollisionEnabled(bool v)", asMETHOD(RoR::ProceduralRoad, setCollisionEnabled), asCALL_THISCALL); ROR_ASSERT(result >= 0);
106
107 // class ProceduralObject (ref)
108 ProceduralObject::RegisterRefCountingObject(engine, "ProceduralObjectClass");
109 ProceduralObjectPtr::RegisterRefCountingObjectPtr(engine, "ProceduralObjectClassPtr", "ProceduralObjectClass");
110 result = engine->RegisterObjectBehaviour("ProceduralObjectClass", asBEHAVE_FACTORY, "ProceduralObjectClass@+ f()", asFUNCTION(ProceduralObjectFactory), asCALL_CDECL); ROR_ASSERT(result >= 0);
111 result = engine->RegisterObjectMethod("ProceduralObjectClass", "string getName()", asMETHOD(RoR::ProceduralObject, getName), asCALL_THISCALL); ROR_ASSERT(result >= 0);
112 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void setName(const string&in)", asMETHOD(RoR::ProceduralObject, setName), asCALL_THISCALL); ROR_ASSERT(result >= 0);
113 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void addPoint(ProceduralPointClassPtr @)", asMETHOD(RoR::ProceduralObject, addPoint), asCALL_THISCALL); ROR_ASSERT(result >= 0);
114 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void insertPoint(int pos, ProceduralPointClassPtr @)", asMETHOD(RoR::ProceduralObject, insertPoint), asCALL_THISCALL); ROR_ASSERT(result >= 0);
115 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void deletePoint(int pos)", asMETHOD(RoR::ProceduralObject, deletePoint), asCALL_THISCALL); ROR_ASSERT(result >= 0);
116 result = engine->RegisterObjectMethod("ProceduralObjectClass", "ProceduralPointClassPtr @getPoint(int pos)", asMETHOD(RoR::ProceduralObject, getPoint), asCALL_THISCALL); ROR_ASSERT(result >= 0);
117 result = engine->RegisterObjectMethod("ProceduralObjectClass", "int getNumPoints()", asMETHOD(RoR::ProceduralObject, getNumPoints), asCALL_THISCALL); ROR_ASSERT(result >= 0);
118 result = engine->RegisterObjectMethod("ProceduralObjectClass", "ProceduralRoadClassPtr @getRoad()", asMETHOD(ProceduralObject, getRoad), asCALL_THISCALL); ROR_ASSERT(result >= 0);
119 result = engine->RegisterObjectMethod("ProceduralObjectClass", "int get_smoothing_num_splits() property", asFUNCTIONPR([](ProceduralObject* self) { return self->smoothing_num_splits; },(ProceduralObject*),int ), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
120 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_smoothing_num_splits(int) property", asFUNCTIONPR([](ProceduralObject* self, int n) { self->smoothing_num_splits = n; }, (ProceduralObject*, int), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
121 result = engine->RegisterObjectMethod("ProceduralObjectClass", "bool get_collision_enabled() property", asFUNCTIONPR([](ProceduralObject* self) { return self->collision_enabled; }, (ProceduralObject*), bool), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
122 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_collision_enabled(bool) property", asFUNCTIONPR([](ProceduralObject* self, bool n) { self->collision_enabled = n; }, (ProceduralObject*, bool), void), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
123
124 // class ProceduralManager (ref)
125 ProceduralManager::RegisterRefCountingObject(engine, "ProceduralManagerClass");
126 ProceduralManagerPtr::RegisterRefCountingObjectPtr(engine, "ProceduralManagerClassPtr", "ProceduralManagerClass");
127 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void addObject(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, addObject), asCALL_THISCALL); ROR_ASSERT(result>=0);
128 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void removeObject(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, removeObject), asCALL_THISCALL); ROR_ASSERT(result >= 0);
129 result = engine->RegisterObjectMethod("ProceduralManagerClass", "int getNumObjects()", asMETHOD(RoR::ProceduralManager, getNumObjects), asCALL_THISCALL); ROR_ASSERT(result >= 0);
130 result = engine->RegisterObjectMethod("ProceduralManagerClass", "ProceduralObjectClassPtr @getObject(int pos)", asMETHOD(ProceduralManager, getObject), asCALL_THISCALL); ROR_ASSERT(result >= 0);
131 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void rebuildObjectMesh(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, rebuildObjectMesh), asCALL_THISCALL); ROR_ASSERT(result >= 0);
132 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void deleteObjectMesh(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, deleteObjectMesh), asCALL_THISCALL); ROR_ASSERT(result >= 0);
133}
#define ROR_ASSERT(_EXPR)
Definition Application.h:40
static ProceduralPoint * ProceduralPointFactory()
static ProceduralObject * ProceduralObjectFactory()
static ProceduralRoad * ProceduralRoadFactory()
static void RegisterRefCountingObjectPtr(AS_NAMESPACE_QUALIFIER asIScriptEngine *engine, const char *handle_name, const char *obj_name)
void RegisterProceduralRoad(AngelScript::asIScriptEngine *engine)
defined in ProceduralRoadAngelscript.cpp
bool collision_enabled
Generate collision triangles?
Ogre::Quaternion rotation