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
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
45namespace RoR {
46
49
51{
53 Ogre::Vector3 position;
54 Ogre::Quaternion rotation;
55};
56typedef std::vector<Localizer> LocalizerVec;
57
58class TerrainObjectManager: public RefCountingObject<TerrainObjectManager>
59{
60 friend class Terrain;
61public:
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();
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
100protected:
101
103 {
104 Ogre::Entity* ent;
105 Ogre::SceneNode* node;
106 Ogre::AnimationState* anim;
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
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 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)
std::vector< MeshObject * > m_mesh_objects
ProceduralManagerPtr & getProceduralManager()
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 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)
void destroyObject(const Ogre::String &instancename)
Ogre::SceneNode * m_angelscript_grouping_node
For even more readable scene graph (via inspector script)
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
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