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 #include <vector>
44 
45 namespace RoR {
46 
49 
50 struct Localizer
51 {
53  Ogre::Vector3 position;
54  Ogre::Quaternion rotation;
55 };
56 typedef std::vector<Localizer> LocalizerVec;
57 
58 class TerrainObjectManager: public RefCountingObject<TerrainObjectManager>
59 {
60  friend class Terrain;
61 public:
62 
65 
67  std::vector<TObjDocumentPtr>& GetTobjCache() { return m_tobj_cache; }
68  void LoadTObjFile(Ogre::String filename);
69  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);
70  bool LoadTerrainScript(const Ogre::String& filename);
71  void moveObjectVisuals(const Ogre::String& instancename, const Ogre::Vector3& pos);
72  void destroyObject(const Ogre::String& instancename);
73  void LoadTelepoints();
76  void LoadPredefinedActors();
78  bool UpdateTerrainObjects(float dt);
79 
80  void ProcessTree(
81  float yawfrom, float yawto,
82  float scalefrom, float scaleto,
83  char* ColorMap, char* DensityMap, char* treemesh, char* treeCollmesh,
84  float gridspacing, float highdens,
85  int minDist, int maxDist, int mapsizex, int mapsizez);
86 
87  void ProcessGrass(
88  float SwaySpeed, float SwayLength, float SwayDistribution, float Density,
89  float minx, float miny, float minH, float maxx, float maxy, float maxH,
90  char* grassmat, char* colorMapFilename, char* densityMapFilename,
91  int growtechnique, int techn, int range, int mapsizex, int mapsizez);
92 
93  void ProcessPredefinedActor(int tobj_cache_id, const std::string& name, const Ogre::Vector3 position, const Ogre::Vector3 rotation, const TObjSpecialObject type);
94 
96 
98  Ogre::SceneNode* getGroupingSceneNode();
99 
100 protected:
101 
103  {
104  Ogre::Entity* ent;
105  Ogre::SceneNode* node;
106  Ogre::AnimationState* anim;
107  float speedfactor;
108  };
109 
111  {
112  Ogre::ParticleSystem* psys = nullptr;
113  Ogre::SceneNode* node = nullptr;
114  };
115 
116  // ODef processing functions
117 
118  RoR::ODefDocument* FetchODef(std::string const & odef_name);
119  void ProcessODefCollisionBoxes(TerrainEditorObjectPtr obj, ODefDocument* odef, const TerrainEditorObjectPtr& params, bool race_event);
120 
121  // Update functions
122 
123  void UpdateAnimatedObjects(float dt);
125 
126  // Helpers
127 
128  TerrainEditorObjectID_t FindEditorObjectByInstanceName(std::string const& instance_name);
129 
130  // Variables
131 
133  std::unordered_map<std::string, std::shared_ptr<RoR::ODefDocument>> m_odef_cache;
134  std::vector<TObjDocumentPtr> m_tobj_cache;
138  std::vector<AnimatedObject> m_animated_objects;
139  std::vector<ParticleEffectObject> m_particle_effect_objects;
140  std::vector<MeshObject*> m_mesh_objects;
145  Ogre::SceneNode* m_terrn2_grouping_node = nullptr;
146  Ogre::SceneNode* m_tobj_grouping_node = nullptr;
147  Ogre::SceneNode* m_angelscript_grouping_node = nullptr;
148 
149 #ifdef USE_PAGED
150  std::vector<Forests::PagedGeometry*> m_paged_geometry;
151 #endif //USE_PAGED
152 };
153 
155 
156 } // namespace RoR
RoR::TerrainObjectManager::GetLocalizers
LocalizerVec & GetLocalizers()
Definition: TerrainObjectManager.h:95
RoR::TerrainObjectManager::ProcessPredefinedActor
void ProcessPredefinedActor(int tobj_cache_id, const std::string &name, const Ogre::Vector3 position, const Ogre::Vector3 rotation, const TObjSpecialObject type)
Definition: TerrainObjectManager.cpp:473
RoR::TerrainObjectManager::m_has_predefined_actors
bool m_has_predefined_actors
Definition: TerrainObjectManager.h:137
RoR::TerrainObjectManager::UpdateParticleEffectObjects
void UpdateParticleEffectObjects()
Definition: TerrainObjectManager.cpp:1001
RoR::TerrainObjectManager::m_tobj_cache
std::vector< TObjDocumentPtr > m_tobj_cache
Definition: TerrainObjectManager.h:134
RoR::TerrainObjectManager::LoadTelepoints
void LoadTelepoints()
Definition: TerrainObjectManager.cpp:1012
RoR::TerrainObjectManager::getProceduralManager
ProceduralManagerPtr & getProceduralManager()
Definition: TerrainObjectManager.h:97
RoR::TerrainObjectManager
Definition: TerrainObjectManager.h:58
RoR::TerrainObjectManager::m_map_entities
SurveyMapEntityVec m_map_entities
Definition: TerrainObjectManager.h:141
RoR::TerrainObjectManager::LoadTObjFile
void LoadTObjFile(Ogre::String filename)
Definition: TerrainObjectManager.cpp:150
RoR::TObjSpecialObject
TObjSpecialObject
Definition: Application.h:326
SurveyMapEntity.h
RoR::TerrainEditorObjectPtrVec
std::vector< TerrainEditorObjectPtr > TerrainEditorObjectPtrVec
Definition: ForwardDeclarations.h:238
MeshObject.h
RoR::TerrainObjectManager::terrainManager
Terrain * terrainManager
Definition: TerrainObjectManager.h:142
RoR::TerrainObjectManager::ParticleEffectObject::psys
Ogre::ParticleSystem * psys
Definition: TerrainObjectManager.h:112
RoR::TerrainObjectManager::getGroupingSceneNode
Ogre::SceneNode * getGroupingSceneNode()
Definition: TerrainObjectManager.cpp:1143
RoR::TerrainObjectManager::m_localizers
LocalizerVec m_localizers
Definition: TerrainObjectManager.h:132
RoR::TerrainObjectManager::destroyObject
void destroyObject(const Ogre::String &instancename)
Definition: TerrainObjectManager.cpp:504
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:600
RoR::TerrainObjectManager::AnimatedObject
Definition: TerrainObjectManager.h:102
RoR::TerrainObjectManager::LoadTerrainScript
bool LoadTerrainScript(const Ogre::String &filename)
Definition: TerrainObjectManager.cpp:973
RoR::TerrainObjectManager::m_mesh_objects
std::vector< MeshObject * > m_mesh_objects
Definition: TerrainObjectManager.h:140
RefCountingObjectPtr
Definition: RefCountingObjectPtr.h:24
RoR::TerrainObjectManager::LoadPredefinedActors
void LoadPredefinedActors()
Definition: TerrainObjectManager.cpp:1072
RoR::TerrainObjectManager::HasPredefinedActors
bool HasPredefinedActors()
Definition: TerrainObjectManager.h:77
RoR::TerrainObjectManager::m_odef_cache
std::unordered_map< std::string, std::shared_ptr< RoR::ODefDocument > > m_odef_cache
Definition: TerrainObjectManager.h:133
RoR::TerrainObjectManager::AnimatedObject::ent
Ogre::Entity * ent
Definition: TerrainObjectManager.h:104
RoR::SurveyMapEntityVec
std::vector< SurveyMapEntity > SurveyMapEntityVec
Definition: SurveyMapEntity.h:56
RoR::TerrainObjectManager::m_entity_counter
int m_entity_counter
Definition: TerrainObjectManager.h:144
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:400
RoR::TerrainObjectManager::FetchODef
RoR::ODefDocument * FetchODef(std::string const &odef_name)
Definition: TerrainObjectManager.cpp:558
RoR::TerrainObjectManager::AnimatedObject::node
Ogre::SceneNode * node
Definition: TerrainObjectManager.h:105
RoR::TerrainObjectManager::m_terrn2_grouping_node
Ogre::SceneNode * m_terrn2_grouping_node
For a readable scene graph (via inspector script)
Definition: TerrainObjectManager.h:145
RoR::TerrainObjectManager::GetEditorObjectFlagRotYXZ
bool GetEditorObjectFlagRotYXZ(TerrainEditorObjectPtr const &object)
Definition: TerrainObjectManager.cpp:1020
RoR::TerrainObjectManager::UpdateAnimatedObjects
void UpdateAnimatedObjects(float dt)
Definition: TerrainObjectManager.cpp:984
ODefFileFormat.h
RoR::TerrainObjectManager::ParticleEffectObject
Definition: TerrainObjectManager.h:110
Application.h
Central state/object manager and communications hub.
RoR::TerrainObjectManager::m_procedural_manager
ProceduralManagerPtr m_procedural_manager
Definition: TerrainObjectManager.h:143
RoR::TerrainObjectManager::m_animated_objects
std::vector< AnimatedObject > m_animated_objects
Definition: TerrainObjectManager.h:138
RoR::TerrainObjectManager::GetEditorObjects
TerrainEditorObjectPtrVec & GetEditorObjects()
Definition: TerrainObjectManager.h:66
RoR::TerrainObjectManager::m_editor_objects
TerrainEditorObjectPtrVec m_editor_objects
Definition: TerrainObjectManager.h:136
RoR::TerrainObjectManager::AnimatedObject::anim
Ogre::AnimationState * anim
Definition: TerrainObjectManager.h:106
RoR::TerrainObjectManager::TerrainObjectManager
TerrainObjectManager(Terrain *terrainManager)
Definition: TerrainObjectManager.cpp:68
RoR::ODefDocument
Definition: ODefFileFormat.h:118
RoR::Terrain
Definition: Terrain.h:39
RoR::TerrainEditorObjectID_t
int TerrainEditorObjectID_t
Offset into RoR::TerrainObjectManager::m_editor_objects, use RoR::TERRAINEDITOROBJECTID_INVALID as em...
Definition: ForwardDeclarations.h:84
RoR::TerrainObjectManager::UpdateTerrainObjects
bool UpdateTerrainObjects(float dt)
Definition: TerrainObjectManager.cpp:1096
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:275
RoR::Localizer
Definition: TerrainObjectManager.h:50
RoR::TerrainObjectManager::ProcessODefCollisionBoxes
void ProcessODefCollisionBoxes(TerrainEditorObjectPtr obj, ODefDocument *odef, const TerrainEditorObjectPtr &params, bool race_event)
Definition: TerrainObjectManager.cpp:1110
RoR::TerrainObjectManager::moveObjectVisuals
void moveObjectVisuals(const Ogre::String &instancename, const Ogre::Vector3 &pos)
Definition: TerrainObjectManager.cpp:489
RoR::LocalizerType
LocalizerType
Definition: SimData.h:251
RoR::TerrainObjectManager::~TerrainObjectManager
~TerrainObjectManager()
Definition: TerrainObjectManager.cpp:76
RoR::TerrainObjectManager::m_particle_effect_objects
std::vector< ParticleEffectObject > m_particle_effect_objects
Definition: TerrainObjectManager.h:139
RoR::Localizer::type
LocalizerType type
Definition: TerrainObjectManager.h:52
RoR::TerrainObjectManager::m_angelscript_grouping_node
Ogre::SceneNode * m_angelscript_grouping_node
For even more readable scene graph (via inspector script)
Definition: TerrainObjectManager.h:147
RefCountingObject
Self reference-counting objects, as requred by AngelScript garbage collector.
Definition: RefCountingObject.h:26
RoR::TerrainObjectManager::ParticleEffectObject::node
Ogre::SceneNode * node
Definition: TerrainObjectManager.h:113
RoR::TerrainObjectManager::AnimatedObject::speedfactor
float speedfactor
Definition: TerrainObjectManager.h:107
RoR::LocalizerVec
std::vector< Localizer > LocalizerVec
Definition: TerrainObjectManager.h:56
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:146
RoR::TerrainObjectManager::GetTobjCache
std::vector< TObjDocumentPtr > & GetTobjCache()
Definition: TerrainObjectManager.h:67
RoR::Localizer::rotation
Ogre::Quaternion rotation
Definition: TerrainObjectManager.h:54
RoR::TerrainObjectManager::SpawnSinglePredefinedActor
void SpawnSinglePredefinedActor(TerrainEditorObjectPtr const &object)
Definition: TerrainObjectManager.cpp:1036
RoR::Localizer::position
Ogre::Vector3 position
Definition: TerrainObjectManager.h:53
RoR::TerrainObjectManager::m_tobj_cache_active_id
int m_tobj_cache_active_id
Definition: TerrainObjectManager.h:135
RoR::TerrainObjectManager::FindEditorObjectByInstanceName
TerrainEditorObjectID_t FindEditorObjectByInstanceName(std::string const &instance_name)
Returns offset to m_editor_objects or -1 if not found.
Definition: TerrainObjectManager.cpp:1158