Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
TerrainObjectManager.h
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-2023 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
23#pragma once
24
25#include "Application.h"
26
27#include "ODefFileFormat.h"
28#include "MeshObject.h"
29#include "ProceduralManager.h"
30#include "SurveyMapEntity.h"
31
32
33#include "PagedGeometry.h"
34
35
36#include <map>
37#include <unordered_map>
38#include <vector>
39
40namespace RoR {
41
44
46{
48 Ogre::Vector3 position;
49 Ogre::Quaternion rotation;
50};
51typedef std::vector<Localizer> LocalizerVec;
52
53class TerrainObjectManager: public RefCountingObject<TerrainObjectManager>
54{
55 friend class Terrain;
56public:
57
60
62 std::vector<TObjDocumentPtr>& GetTobjCache() { return m_tobj_cache; }
63 void LoadTObjFile(Ogre::String filename);
64 bool LoadTerrainObject(const Ogre::String& name, const Ogre::Vector3& pos, const Ogre::Vector3& rot, const Ogre::String& instancename, const Ogre::String& type, float rendering_distance = 0, bool enable_collisions = true, int scripthandler = -1, bool uniquifyMaterial = false);
65 bool LoadTerrainScript(const Ogre::String& filename);
66 void moveObjectVisuals(const Ogre::String& instancename, const Ogre::Vector3& pos);
67 void destroyObject(const Ogre::String& instancename);
68 void LoadTelepoints();
73 bool UpdateTerrainObjects(float dt);
74
75 void ProcessTree(
76 float yawfrom, float yawto,
77 float scalefrom, float scaleto,
78 char* ColorMap, char* DensityMap, char* treemesh, char* treeCollmesh,
79 float gridspacing, float highdens,
80 int minDist, int maxDist, int mapsizex, int mapsizez,
81 Ogre::SceneNode* pagedGroupingNode);
82
83 void ProcessGrass(
84 float SwaySpeed, float SwayLength, float SwayDistribution, float Density,
85 float minx, float miny, float minH, float maxx, float maxy, float maxH,
86 char* grassmat, char* colorMapFilename, char* densityMapFilename,
88 int range, int mapsizex, int mapsizez,
89 Ogre::SceneNode* pagedGroupingNode);
90
91 void ProcessPredefinedActor(int tobj_cache_id, const std::string& name, const Ogre::Vector3 position, const Ogre::Vector3 rotation, const TObjSpecialObject type);
92
94
96 Ogre::SceneNode* getGroupingSceneNode();
97
98protected:
99
101 {
102 Ogre::Entity* ent;
103 Ogre::SceneNode* node;
104 Ogre::AnimationState* anim;
106 };
107
109 {
110 Ogre::ParticleSystem* psys = nullptr;
111 Ogre::SceneNode* node = nullptr;
112 };
113
114 // ODef processing functions
115
116 RoR::ODefDocument* FetchODef(std::string const & odef_name);
117 void ProcessODefCollisionBoxes(TerrainEditorObjectPtr obj, ODefDocument* odef, const TerrainEditorObjectPtr& params, bool race_event);
118
119 // Update functions
120
121 void UpdateAnimatedObjects(float dt);
123
124 // Helpers
125
126 TerrainEditorObjectID_t FindEditorObjectByInstanceName(std::string const& instance_name);
127
128 // Variables
129
131 std::unordered_map<std::string, std::shared_ptr<RoR::ODefDocument>> m_odef_cache;
132 std::vector<TObjDocumentPtr> m_tobj_cache;
136 std::vector<AnimatedObject> m_animated_objects;
137 std::vector<ParticleEffectObject> m_particle_effect_objects;
138 std::vector<MeshObject*> m_mesh_objects;
143 Ogre::SceneNode* m_terrn2_grouping_node = nullptr;
144 Ogre::SceneNode* m_tobj_grouping_node = nullptr;
145 Ogre::SceneNode* m_angelscript_grouping_node = nullptr;
146
147
148 std::vector<Forests::PagedGeometry*> m_paged_geometry;
149
150};
151
153
154} // namespace RoR
Central state/object manager and communications hub.
Self reference-counting objects, as requred by AngelScript garbage collector.
Ogre::SceneNode * getGroupingSceneNode()
RoR::ODefDocument * FetchODef(std::string const &odef_name)
bool LoadTerrainObject(const Ogre::String &name, const Ogre::Vector3 &pos, const Ogre::Vector3 &rot, const Ogre::String &instancename, const Ogre::String &type, float rendering_distance=0, bool enable_collisions=true, int scripthandler=-1, bool uniquifyMaterial=false)
TerrainEditorObjectID_t FindEditorObjectByInstanceName(std::string const &instance_name)
Returns offset to m_editor_objects or -1 if not found.
void ProcessODefCollisionBoxes(TerrainEditorObjectPtr obj, ODefDocument *odef, const TerrainEditorObjectPtr &params, bool race_event)
std::vector< TObjDocumentPtr > m_tobj_cache
void ProcessTree(float yawfrom, float yawto, float scalefrom, float scaleto, char *ColorMap, char *DensityMap, char *treemesh, char *treeCollmesh, float gridspacing, float highdens, int minDist, int maxDist, int mapsizex, int mapsizez, Ogre::SceneNode *pagedGroupingNode)
std::vector< MeshObject * > m_mesh_objects
ProceduralManagerPtr & getProceduralManager()
std::vector< Forests::PagedGeometry * > m_paged_geometry
Ogre::SceneNode * m_terrn2_grouping_node
For a readable scene graph (via inspector script)
void LoadTObjFile(Ogre::String filename)
TerrainEditorObjectPtrVec & GetEditorObjects()
std::unordered_map< std::string, std::shared_ptr< RoR::ODefDocument > > m_odef_cache
ProceduralManagerPtr m_procedural_manager
bool GetEditorObjectFlagRotYXZ(TerrainEditorObjectPtr const &object)
TerrainEditorObjectPtrVec m_editor_objects
std::vector< TObjDocumentPtr > & GetTobjCache()
std::vector< ParticleEffectObject > m_particle_effect_objects
void moveObjectVisuals(const Ogre::String &instancename, const Ogre::Vector3 &pos)
Ogre::SceneNode * m_tobj_grouping_node
For even more readable scene graph (via inspector script)
bool LoadTerrainScript(const Ogre::String &filename)
std::vector< AnimatedObject > m_animated_objects
void SpawnSinglePredefinedActor(TerrainEditorObjectPtr const &object)
void destroyObject(const Ogre::String &instancename)
Ogre::SceneNode * m_angelscript_grouping_node
For even more readable scene graph (via inspector script)
void ProcessGrass(float SwaySpeed, float SwayLength, float SwayDistribution, float Density, float minx, float miny, float minH, float maxx, float maxy, float maxH, char *grassmat, char *colorMapFilename, char *densityMapFilename, Forests::FadeTechnique fadetech, Forests::GrassTechnique techn, int range, int mapsizex, int mapsizez, Ogre::SceneNode *pagedGroupingNode)
void ProcessPredefinedActor(int tobj_cache_id, const std::string &name, const Ogre::Vector3 position, const Ogre::Vector3 rotation, const TObjSpecialObject type)
LocalizerType
Definition SimData.h:225
std::vector< Localizer > LocalizerVec
std::vector< SurveyMapEntity > SurveyMapEntityVec
GrassTechnique
A technique used to render grass.
FadeTechnique
A technique used to fade grass into the distance.
int TerrainEditorObjectID_t
Offset into RoR::TerrainObjectManager::m_editor_objects, use RoR::TERRAINEDITOROBJECTID_INVALID as em...
TObjSpecialObject
std::vector< TerrainEditorObjectPtr > TerrainEditorObjectPtrVec
Ogre::Vector3 position
Ogre::Quaternion rotation