RigsofRods
Soft-body Physics Simulation
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 #ifdef USE_PAGED
33 #include "PagedGeometry.h"
34 #include "TreeLoader2D.h"
35 #include "TreeLoader3D.h"
36 #include "BatchPage.h"
37 #include "GrassLoader.h"
38 #include "ImpostorPage.h"
39 #endif //USE_PAGED
40 
41 #include <map>
42 #include <unordered_map>
43 
44 namespace RoR {
45 
48 
50 {
51  friend class Terrain;
52 public:
53 
54  struct EditorObject
55  {
56  Ogre::String name;
57  Ogre::String instance_name;
58  Ogre::String type;
59  Ogre::Vector3 position = Ogre::Vector3::ZERO;
60  Ogre::Vector3 rotation = Ogre::Vector3::ZERO;
61  Ogre::Vector3 initial_position = Ogre::Vector3::ZERO;
62  Ogre::Vector3 initial_rotation = Ogre::Vector3::ZERO;
63  Ogre::SceneNode* node = nullptr;
64  bool enable_collisions = true;
65  int script_handler = -1;
66  };
67 
70 
71  std::vector<EditorObject>& GetEditorObjects() { return m_editor_objects; }
72  void LoadTObjFile(Ogre::String filename);
73  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);
74  bool LoadTerrainScript(const Ogre::String& filename);
75  void MoveObjectVisuals(const Ogre::String& instancename, const Ogre::Vector3& pos);
76  void unloadObject(const Ogre::String& instancename);
77  void LoadTelepoints();
78  void LoadPredefinedActors();
79  bool HasPredefinedActors() { return !m_predefined_actors.empty(); };
80  bool UpdateTerrainObjects(float dt);
81 
82  void ProcessTree(
83  float yawfrom, float yawto,
84  float scalefrom, float scaleto,
85  char* ColorMap, char* DensityMap, char* treemesh, char* treeCollmesh,
86  float gridspacing, float highdens,
87  int minDist, int maxDist, int mapsizex, int mapsizez);
88 
89  void ProcessGrass(
90  float SwaySpeed, float SwayLength, float SwayDistribution, float Density,
91  float minx, float miny, float minH, float maxx, float maxy, float maxH,
92  char* grassmat, char* colorMapFilename, char* densityMapFilename,
93  int growtechnique, int techn, int range, int mapsizex, int mapsizez);
94 
95  struct localizer_t
96  {
98  Ogre::Vector3 position;
99  Ogre::Quaternion rotation;
100  };
101 
102  struct object_t
103  {
104  Ogre::String name;
105  Ogre::Vector3 position;
106  Ogre::Vector3 rotation;
107  Ogre::Vector3 initial_position;
108  Ogre::Vector3 initial_rotation;
109  Ogre::SceneNode* node;
110  };
111 
112  std::vector<localizer_t> GetLocalizers() { return localizers; }
113 
115  Ogre::SceneNode* getGroupingSceneNode();
116 
117 protected:
118 
120  {
121  Ogre::Entity* ent;
122  Ogre::SceneNode* node;
123  Ogre::AnimationState* anim;
124  float speedfactor;
125  };
126 
128  {
129  float px;
130  float py;
131  float pz;
132  Ogre::Quaternion rotation;
133  std::string name;
134  bool ismachine;
136  };
137 
139  {
140  Ogre::SceneNode* sceneNode;
141  Ogre::String instanceName;
142  bool enabled;
143  std::vector<int> collBoxes;
144  std::vector<int> collTris;
145  };
146 
147  // ODef processing functions
148 
149  RoR::ODefFile* FetchODef(std::string const & odef_name);
150  void ProcessODefCollisionBoxes(StaticObject* obj, ODefFile* odef, const EditorObject& params, bool race_event);
151 
152  // Misc functions
153 
154  bool UpdateAnimatedObjects(float dt);
155 
156  // Variables
157 
158  std::vector<localizer_t> localizers;
159  std::unordered_map<std::string, std::shared_ptr<RoR::ODefFile>> m_odef_cache;
160  std::map<std::string, StaticObject> m_static_objects;
161  std::vector<EditorObject> m_editor_objects;
162  std::vector<PredefinedActor> m_predefined_actors;
163  std::vector<AnimatedObject> m_animated_objects;
164  std::vector<MeshObject*> m_mesh_objects;
169  Ogre::SceneNode* m_terrn2_grouping_node = nullptr;
170  Ogre::SceneNode* m_tobj_grouping_node = nullptr;
171  Ogre::SceneNode* m_angelscript_grouping_node = nullptr;
172 
173 #ifdef USE_PAGED
174  std::vector<Forests::PagedGeometry*> m_paged_geometry;
175 #endif //USE_PAGED
176 };
177 
179 
180 } // namespace RoR
RoR::TerrainObjectManager::EditorObject::rotation
Ogre::Vector3 rotation
Definition: TerrainObjectManager.h:60
RoR::TerrainObjectManager::localizer_t::type
LocalizerType type
Definition: TerrainObjectManager.h:97
RoR::TerrainObjectManager::UpdateAnimatedObjects
bool UpdateAnimatedObjects(float dt)
Definition: TerrainObjectManager.cpp:956
RoR::TerrainObjectManager::PredefinedActor::freePosition
bool freePosition
Definition: TerrainObjectManager.h:135
RoR::TerrainObjectManager::localizer_t::position
Ogre::Vector3 position
Definition: TerrainObjectManager.h:98
RoR::TerrainObjectManager::StaticObject::sceneNode
Ogre::SceneNode * sceneNode
Definition: TerrainObjectManager.h:140
RoR::TerrainObjectManager::LoadTelepoints
void LoadTelepoints()
Definition: TerrainObjectManager.cpp:974
RoR::TerrainObjectManager::getProceduralManager
ProceduralManagerPtr & getProceduralManager()
Definition: TerrainObjectManager.h:114
RoR::TerrainObjectManager::object_t::node
Ogre::SceneNode * node
Definition: TerrainObjectManager.h:109
RoR::TerrainObjectManager::object_t::position
Ogre::Vector3 position
Definition: TerrainObjectManager.h:105
RoR::TerrainObjectManager
Definition: TerrainObjectManager.h:49
RoR::TerrainObjectManager::m_map_entities
SurveyMapEntityVec m_map_entities
Definition: TerrainObjectManager.h:165
RoR::TerrainObjectManager::PredefinedActor::ismachine
bool ismachine
Definition: TerrainObjectManager.h:134
RoR::TerrainObjectManager::LoadTObjFile
void LoadTObjFile(Ogre::String filename)
Definition: TerrainObjectManager.cpp:149
RoR::TerrainObjectManager::EditorObject::name
Ogre::String name
Definition: TerrainObjectManager.h:56
RoR::TerrainObjectManager::m_editor_objects
std::vector< EditorObject > m_editor_objects
Definition: TerrainObjectManager.h:161
RoR::TerrainObjectManager::EditorObject
Definition: TerrainObjectManager.h:54
RoR::TerrainObjectManager::GetEditorObjects
std::vector< EditorObject > & GetEditorObjects()
Definition: TerrainObjectManager.h:71
SurveyMapEntity.h
MeshObject.h
RoR::TerrainObjectManager::terrainManager
Terrain * terrainManager
Definition: TerrainObjectManager.h:166
RoR::TerrainObjectManager::EditorObject::type
Ogre::String type
Definition: TerrainObjectManager.h:58
RoR::TerrainObjectManager::ProcessODefCollisionBoxes
void ProcessODefCollisionBoxes(StaticObject *obj, ODefFile *odef, const EditorObject &params, bool race_event)
Definition: TerrainObjectManager.cpp:1016
RoR::TerrainObjectManager::getGroupingSceneNode
Ogre::SceneNode * getGroupingSceneNode()
Definition: TerrainObjectManager.cpp:1049
RoR::TerrainObjectManager::object_t::initial_rotation
Ogre::Vector3 initial_rotation
Definition: TerrainObjectManager.h:108
RoR::TerrainObjectManager::LoadTerrainObject
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)
Definition: TerrainObjectManager.cpp:571
RoR::TerrainObjectManager::AnimatedObject
Definition: TerrainObjectManager.h:119
RoR::TerrainObjectManager::LoadTerrainScript
bool LoadTerrainScript(const Ogre::String &filename)
Definition: TerrainObjectManager.cpp:945
RoR::TerrainObjectManager::m_mesh_objects
std::vector< MeshObject * > m_mesh_objects
Definition: TerrainObjectManager.h:164
RoR::TerrainObjectManager::EditorObject::enable_collisions
bool enable_collisions
Definition: TerrainObjectManager.h:64
RefCountingObjectPtr< ProceduralManager >
RoR::TerrainObjectManager::LoadPredefinedActors
void LoadPredefinedActors()
Definition: TerrainObjectManager.cpp:982
RoR::TerrainObjectManager::localizer_t::rotation
Ogre::Quaternion rotation
Definition: TerrainObjectManager.h:99
RoR::TerrainObjectManager::MoveObjectVisuals
void MoveObjectVisuals(const Ogre::String &instancename, const Ogre::Vector3 &pos)
Definition: TerrainObjectManager.cpp:483
RoR::TerrainObjectManager::FetchODef
RoR::ODefFile * FetchODef(std::string const &odef_name)
Definition: TerrainObjectManager.cpp:529
RoR::TerrainObjectManager::HasPredefinedActors
bool HasPredefinedActors()
Definition: TerrainObjectManager.h:79
RoR::TerrainObjectManager::object_t::initial_position
Ogre::Vector3 initial_position
Definition: TerrainObjectManager.h:107
RoR::TerrainObjectManager::EditorObject::instance_name
Ogre::String instance_name
Definition: TerrainObjectManager.h:57
RoR::TerrainObjectManager::AnimatedObject::ent
Ogre::Entity * ent
Definition: TerrainObjectManager.h:121
RoR::SurveyMapEntityVec
std::vector< SurveyMapEntity > SurveyMapEntityVec
Definition: SurveyMapEntity.h:56
RoR::TerrainObjectManager::m_entity_counter
int m_entity_counter
Definition: TerrainObjectManager.h:168
RoR::TerrainObjectManager::StaticObject::instanceName
Ogre::String instanceName
Definition: TerrainObjectManager.h:141
RoR::TerrainObjectManager::GetLocalizers
std::vector< localizer_t > GetLocalizers()
Definition: TerrainObjectManager.h:112
ProceduralManager.h
RoR::TerrainObjectManager::ProcessGrass
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, int growtechnique, int techn, int range, int mapsizex, int mapsizez)
Definition: TerrainObjectManager.cpp:410
RoR::TerrainObjectManager::AnimatedObject::node
Ogre::SceneNode * node
Definition: TerrainObjectManager.h:122
RoR::TerrainObjectManager::m_terrn2_grouping_node
Ogre::SceneNode * m_terrn2_grouping_node
For a readable scene graph (via inspector script)
Definition: TerrainObjectManager.h:169
ODefFileFormat.h
RoR::TerrainObjectManager::object_t
Definition: TerrainObjectManager.h:102
RoR::TerrainObjectManager::m_predefined_actors
std::vector< PredefinedActor > m_predefined_actors
Definition: TerrainObjectManager.h:162
RoR::TerrainObjectManager::StaticObject::collTris
std::vector< int > collTris
Definition: TerrainObjectManager.h:144
Application.h
Central state/object manager and communications hub.
RoR::TerrainObjectManager::m_procedural_manager
ProceduralManagerPtr m_procedural_manager
Definition: TerrainObjectManager.h:167
RoR::TerrainObjectManager::m_animated_objects
std::vector< AnimatedObject > m_animated_objects
Definition: TerrainObjectManager.h:163
RoR::TerrainObjectManager::PredefinedActor::py
float py
Definition: TerrainObjectManager.h:130
RoR::TerrainObjectManager::object_t::name
Ogre::String name
Definition: TerrainObjectManager.h:104
RoR::TerrainObjectManager::PredefinedActor::name
std::string name
Definition: TerrainObjectManager.h:133
RoR::TerrainObjectManager::AnimatedObject::anim
Ogre::AnimationState * anim
Definition: TerrainObjectManager.h:123
RoR::TerrainObjectManager::TerrainObjectManager
TerrainObjectManager(Terrain *terrainManager)
Definition: TerrainObjectManager.cpp:67
RoR::TerrainObjectManager::localizers
std::vector< localizer_t > localizers
Definition: TerrainObjectManager.h:158
RoR::TerrainObjectManager::object_t::rotation
Ogre::Vector3 rotation
Definition: TerrainObjectManager.h:106
RoR::Terrain
Definition: Terrain.h:40
RoR::TerrainObjectManager::m_static_objects
std::map< std::string, StaticObject > m_static_objects
Definition: TerrainObjectManager.h:160
RoR::TerrainObjectManager::EditorObject::initial_rotation
Ogre::Vector3 initial_rotation
Definition: TerrainObjectManager.h:62
RoR::TerrainObjectManager::UpdateTerrainObjects
bool UpdateTerrainObjects(float dt)
Definition: TerrainObjectManager.cpp:1003
RoR::TerrainObjectManager::ProcessTree
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)
Definition: TerrainObjectManager.cpp:285
RoR::TerrainObjectManager::PredefinedActor::pz
float pz
Definition: TerrainObjectManager.h:131
RoR::TerrainObjectManager::PredefinedActor
Definition: TerrainObjectManager.h:127
RoR::TerrainObjectManager::PredefinedActor::px
float px
Definition: TerrainObjectManager.h:129
RoR::TerrainObjectManager::m_odef_cache
std::unordered_map< std::string, std::shared_ptr< RoR::ODefFile > > m_odef_cache
Definition: TerrainObjectManager.h:159
RoR::LocalizerType
LocalizerType
Definition: SimData.h:251
RoR::TerrainObjectManager::~TerrainObjectManager
~TerrainObjectManager()
Definition: TerrainObjectManager.cpp:75
RoR::TerrainObjectManager::unloadObject
void unloadObject(const Ogre::String &instancename)
Definition: TerrainObjectManager.cpp:499
RoR::TerrainObjectManager::localizer_t
Definition: TerrainObjectManager.h:95
RoR::TerrainObjectManager::m_angelscript_grouping_node
Ogre::SceneNode * m_angelscript_grouping_node
For even more readable scene graph (via inspector script)
Definition: TerrainObjectManager.h:171
RoR::TerrainObjectManager::EditorObject::position
Ogre::Vector3 position
Definition: TerrainObjectManager.h:59
RoR::ODefFile
Definition: ODefFileFormat.h:118
RoR::TerrainObjectManager::EditorObject::node
Ogre::SceneNode * node
Definition: TerrainObjectManager.h:63
RoR::TerrainObjectManager::StaticObject::collBoxes
std::vector< int > collBoxes
Definition: TerrainObjectManager.h:143
RoR::TerrainObjectManager::EditorObject::script_handler
int script_handler
Definition: TerrainObjectManager.h:65
RoR::TerrainObjectManager::StaticObject
Definition: TerrainObjectManager.h:138
RoR::TerrainObjectManager::PredefinedActor::rotation
Ogre::Quaternion rotation
Definition: TerrainObjectManager.h:132
RoR::TerrainObjectManager::AnimatedObject::speedfactor
float speedfactor
Definition: TerrainObjectManager.h:124
RoR
Definition: AppContext.h:36
RoR::TerrainObjectManager::m_tobj_grouping_node
Ogre::SceneNode * m_tobj_grouping_node
For even more readable scene graph (via inspector script)
Definition: TerrainObjectManager.h:170
RoR::TerrainObjectManager::StaticObject::enabled
bool enabled
Definition: TerrainObjectManager.h:142
RoR::TerrainObjectManager::EditorObject::initial_position
Ogre::Vector3 initial_position
Definition: TerrainObjectManager.h:61