Rigs of Rods 2026.01
Soft-body Physics Simulation
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 "AngelScriptBindings.h"
24#include "ProceduralManager.h"
25#include "ProceduralRoad.h"
26#include "ScriptEngine.h"
28
29using namespace RoR;
30using namespace AngelScript;
32
33void RoR::RegisterProceduralRoadNative(asIScriptEngine* engine)
34{
35 int result = 0;
36
37 // NOTE: enums RoadType and TextureFit are registered in RegisterProceduralRoadCommon()
38
39 // struct ProceduralPoint (ref)
40 ProceduralPoint::RegisterRefCountingObject(engine, "ProceduralPointClass");
41 ProceduralPointPtr::RegisterRefCountingObjectPtr(engine, "ProceduralPointClassPtr", "ProceduralPointClass");
42 result = engine->RegisterObjectBehaviour("ProceduralPointClass", asBEHAVE_FACTORY, "ProceduralPointClass@+ f()", asFUNCTION(ProceduralPointFactory), asCALL_CDECL); ROR_ASSERT(result >= 0);
43 //get:
44 result = engine->RegisterObjectMethod("ProceduralPointClass", "vector3& get_position() property", asFUNCTION(ProceduralPoint_get_position), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
45 result = engine->RegisterObjectMethod("ProceduralPointClass", "quaternion& get_rotation() property", asFUNCTION(ProceduralPoint_get_rotation), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
46 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_width() property", asFUNCTION(ProceduralPoint_get_width), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
47 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_border_width() property", asFUNCTION(ProceduralPoint_get_border_width), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
48 result = engine->RegisterObjectMethod("ProceduralPointClass", "float get_border_height() property", asFUNCTION(ProceduralPoint_get_border_height), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
49 result = engine->RegisterObjectMethod("ProceduralPointClass", "RoadType get_type() property", asFUNCTION(ProceduralPoint_get_type), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
50 result = engine->RegisterObjectMethod("ProceduralPointClass", "int get_pillar_type() property", asFUNCTION(ProceduralPoint_get_pillar_type), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
51 //set:
52 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_position(const vector3& in pos) property", asFUNCTION(ProceduralPoint_set_position), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
53 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_rotation(const quaternion& in rot) property", asFUNCTION(ProceduralPoint_set_rotation), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
54 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_width(float width) property", asFUNCTION(ProceduralPoint_set_width), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
55 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_border_width(float bwidth) property", asFUNCTION(ProceduralPoint_set_border_width), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
56 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_border_height(float bheight) property", asFUNCTION(ProceduralPoint_set_border_height), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
57 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_type(RoadType type) property", asFUNCTION(ProceduralPoint_set_type), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
58 result = engine->RegisterObjectMethod("ProceduralPointClass", "void set_pillar_type(int type) property", asFUNCTION(ProceduralPoint_set_pillar_type), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
59
60 // class ProceduralRoad (ref)
61 ProceduralRoad::RegisterRefCountingObject(engine, "ProceduralRoadClass");
62 ProceduralRoadPtr::RegisterRefCountingObjectPtr(engine, "ProceduralRoadClassPtr", "ProceduralRoadClass");
63 result = engine->RegisterObjectBehaviour("ProceduralRoadClass", asBEHAVE_FACTORY, "ProceduralRoadClass@+ f(const string&in groundmodelName = \"\")", asFUNCTION(ProceduralRoadFactory), asCALL_CDECL); ROR_ASSERT(result >= 0);
64 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);
65 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);
66 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);
67 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void finish(Ogre::SceneNode& groupingSceneNode, const string&in materialName = \"\")", asMETHOD(RoR::ProceduralRoad, finish), asCALL_THISCALL); ROR_ASSERT(result >= 0);
68 result = engine->RegisterObjectMethod("ProceduralRoadClass", "void setCollisionEnabled(bool v)", asMETHOD(RoR::ProceduralRoad, setCollisionEnabled), asCALL_THISCALL); ROR_ASSERT(result >= 0);
69
70 // class ProceduralObject (ref)
71 ProceduralObject::RegisterRefCountingObject(engine, "ProceduralObjectClass");
72 ProceduralObjectPtr::RegisterRefCountingObjectPtr(engine, "ProceduralObjectClassPtr", "ProceduralObjectClass");
73 result = engine->RegisterObjectBehaviour("ProceduralObjectClass", asBEHAVE_FACTORY, "ProceduralObjectClass@+ f()", asFUNCTION(ProceduralObjectFactory), asCALL_CDECL); ROR_ASSERT(result >= 0);
74 result = engine->RegisterObjectMethod("ProceduralObjectClass", "string getName()", asMETHOD(RoR::ProceduralObject, getName), asCALL_THISCALL); ROR_ASSERT(result >= 0);
75 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void setName(const string&in)", asMETHOD(RoR::ProceduralObject, setName), asCALL_THISCALL); ROR_ASSERT(result >= 0);
76 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void addPoint(ProceduralPointClassPtr @)", asMETHOD(RoR::ProceduralObject, addPoint), asCALL_THISCALL); ROR_ASSERT(result >= 0);
77 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void insertPoint(int pos, ProceduralPointClassPtr @)", asMETHOD(RoR::ProceduralObject, insertPoint), asCALL_THISCALL); ROR_ASSERT(result >= 0);
78 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void deletePoint(int pos)", asMETHOD(RoR::ProceduralObject, deletePoint), asCALL_THISCALL); ROR_ASSERT(result >= 0);
79 result = engine->RegisterObjectMethod("ProceduralObjectClass", "ProceduralPointClassPtr @getPoint(int pos)", asMETHOD(RoR::ProceduralObject, getPoint), asCALL_THISCALL); ROR_ASSERT(result >= 0);
80 result = engine->RegisterObjectMethod("ProceduralObjectClass", "int getNumPoints()", asMETHOD(RoR::ProceduralObject, getNumPoints), asCALL_THISCALL); ROR_ASSERT(result >= 0);
81 result = engine->RegisterObjectMethod("ProceduralObjectClass", "ProceduralRoadClassPtr @getRoad()", asMETHOD(ProceduralObject, getRoad), asCALL_THISCALL); ROR_ASSERT(result >= 0);
82 result = engine->RegisterObjectMethod("ProceduralObjectClass", "int get_smoothing_num_splits() property", asFUNCTION(ProceduralObject_get_smoothing_num_splits), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
83 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_smoothing_num_splits(int) property", asFUNCTION(ProceduralObject_set_smoothing_num_splits), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
84 result = engine->RegisterObjectMethod("ProceduralObjectClass", "bool get_collision_enabled() property", asFUNCTION(ProceduralObject_get_collision_enabled), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
85 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_collision_enabled(bool) property", asFUNCTION(ProceduralObject_set_collision_enabled), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
86 result = engine->RegisterObjectMethod("ProceduralObjectClass", "string get_custom_material() property", asFUNCTION(ProceduralObject_get_custom_material), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
87 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_custom_material(const string&in) property", asFUNCTION(ProceduralObject_set_custom_material), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
88 result = engine->RegisterObjectMethod("ProceduralObjectClass", "string get_custom_groundmodel() property", asFUNCTION(ProceduralObject_get_custom_groundmodel), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
89 result = engine->RegisterObjectMethod("ProceduralObjectClass", "void set_custom_groundmodel(const string&in) property", asFUNCTION(ProceduralObject_set_custom_groundmodel), asCALL_CDECL_OBJFIRST); ROR_ASSERT(result >= 0);
90
91 // class ProceduralManager (ref)
92 ProceduralManager::RegisterRefCountingObject(engine, "ProceduralManagerClass");
93 ProceduralManagerPtr::RegisterRefCountingObjectPtr(engine, "ProceduralManagerClassPtr", "ProceduralManagerClass");
94 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void addObject(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, addObject), asCALL_THISCALL); ROR_ASSERT(result>=0);
95 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void removeObject(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, removeObject), asCALL_THISCALL); ROR_ASSERT(result >= 0);
96 result = engine->RegisterObjectMethod("ProceduralManagerClass", "int getNumObjects()", asMETHOD(RoR::ProceduralManager, getNumObjects), asCALL_THISCALL); ROR_ASSERT(result >= 0);
97 result = engine->RegisterObjectMethod("ProceduralManagerClass", "ProceduralObjectClassPtr @getObject(int pos)", asMETHOD(ProceduralManager, getObject), asCALL_THISCALL); ROR_ASSERT(result >= 0);
98 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void rebuildObjectMesh(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, rebuildObjectMesh), asCALL_THISCALL); ROR_ASSERT(result >= 0);
99 result = engine->RegisterObjectMethod("ProceduralManagerClass", "void deleteObjectMesh(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, deleteObjectMesh), asCALL_THISCALL); ROR_ASSERT(result >= 0);
100}
#define ROR_ASSERT(_EXPR)
Definition Application.h:40
Helper/wrapper functions shared by native (ProceduralRoadAngelscript.cpp) and generic (ProceduralRoad...
static void RegisterRefCountingObjectPtr(AS_NAMESPACE_QUALIFIER asIScriptEngine *engine, const char *handle_name, const char *obj_name)
void RegisterProceduralRoadNative(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 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)