Cafu Engine
World.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 /**********************/
8 /*** World (Header) ***/
9 /**********************/
10 
11 #ifndef CAFU_WORLD_HPP_INCLUDED
12 #define CAFU_WORLD_HPP_INCLUDED
13 
14 #include "Templates/Array.hpp"
15 #include "Math3D/BoundingBox.hpp"
16 #include "Math3D/Plane3.hpp"
17 #include "Math3D/Polygon.hpp"
18 #include "SceneGraph/FaceNode.hpp"
19 #include "SceneGraph/LightMapMan.hpp"
20 #include "SceneGraph/SHLMapMan.hpp"
21 #include "Terrain/Terrain.hpp"
22 #include "Plants/PlantDescrMan.hpp"
23 
24 #include <string>
25 
26 
27 namespace cf { namespace SceneGraph { class BspTreeNodeT; } }
28 namespace cf { namespace ClipSys { class CollisionModelStaticT; } }
29 namespace cf { namespace GameSys { class WorldT; } }
30 namespace cf { namespace GuiSys { class GuiResourcesT; } }
31 
32 
33 struct MapT
34 {
35  // TODO: Move into FaceNodeT!
36  const static double RoundEpsilon; ///< The maximum amount that is allowed for geometry-related rounding errors.
37  const static double MinVertexDist; ///< The minimum distance that vertices of faces and portals must be apart.
38 };
39 
40 
42 {
43  public:
44 
45  // Note that these constructors can theoretically throw because the TerrainT constructor can throw.
46  // In practice this should never happen though, because otherwise a .cmap or .cw file contained an invalid terrain.
47  SharedTerrainT(const BoundingBox3dT& BB_, unsigned long SideLength_, const ArrayT<unsigned short>& HeightData_, MaterialT* Material_);
48  SharedTerrainT(std::istream& InFile);
49 
50  void WriteTo(std::ostream& OutFile) const;
51 
52 
53  BoundingBox3dT BB; ///< The lateral dimensions of the terrain.
54  unsigned long SideLength; ///< Side length of the terrain height data.
55  ArrayT<unsigned short> HeightData; ///< The height data this terrain is created from (size==SideLength*SideLength).
56  MaterialT* Material; ///< The material for the terrain surface.
57  TerrainT Terrain;
58 };
59 
60 
62 {
63  public:
64 
66  StaticEntityDataT(std::istream& InFile, cf::SceneGraph::aux::PoolT& Pool, ModelManagerT& ModelMan, cf::SceneGraph::LightMapManT& LightMapMan, cf::SceneGraph::SHLMapManT& SHLMapMan, PlantDescrManT& PlantDescrMan);
67 
69 
70  void WriteTo(std::ostream& OutFile, cf::SceneGraph::aux::PoolT& Pool) const;
71 
72 
73  ArrayT<SharedTerrainT*> m_Terrains; ///< Terrains are shared among the BspTree (graphics world) and the CollModel (physics world).
76 
77 
78  private:
79 
80  StaticEntityDataT(const StaticEntityDataT&); ///< Use of the Copy Constructor is not allowed.
81  void operator = (const StaticEntityDataT&); ///< Use of the Assignment Operator is not allowed.
82 };
83 
84 
85 class WorldT
86 {
87  public:
88 
89  struct LoadErrorT { const char* Msg; LoadErrorT(const char* Msg_) : Msg(Msg_) {} };
90  struct SaveErrorT { const char* Msg; SaveErrorT(const char* Msg_) : Msg(Msg_) {} };
91 
92  typedef void (*ProgressFunctionT)(float ProgressPercent, const char* ProgressText);
93 
94 
95  /// Constructor for creating an empty world.
96  WorldT();
97 
98  /// Constructor for creating a world from a .cw file.
99  WorldT(const char* FileName, ModelManagerT& ModelMan, cf::GuiSys::GuiResourcesT& GuiRes, ProgressFunctionT ProgressFunction=NULL) /*throw (LoadErrorT)*/;
100 
101  /// Destructor.
102  ~WorldT();
103 
104  /// Saves the world to disk.
105  void SaveToDisk(const char* FileName) const /*throw (SaveErrorT)*/;
106 
107 
108  ArrayT<StaticEntityDataT*> m_StaticEntityData;
109  cf::SceneGraph::LightMapManT LightMapMan;
110  cf::SceneGraph::SHLMapManT SHLMapMan;
111  PlantDescrManT PlantDescrMan;
112 
113 
114  private:
115 
116  WorldT(const WorldT&); // Use of the Copy Constructor is not allowed.
117  void operator = (const WorldT&); // Use of the Assignment Operator is not allowed.
118 };
119 
120 #endif
unsigned long SideLength
Side length of the terrain height data.
Definition: World.hpp:54
WorldT()
Constructor for creating an empty world.
Definition: World.cpp:167
This class manages lightmaps, e.g. by "allocating" rectangular areas in larger bitmaps.
Definition: LightMapMan.hpp:25
This class represents terrains, offering methods for LoD rendering and collision detection.
Definition: Terrain.hpp:17
void SaveToDisk(const char *FileName) const
Saves the world to disk.
Definition: World.cpp:244
~WorldT()
Destructor.
Definition: World.cpp:172
Definition: _aux.hpp:111
This class manages SHL maps, e.g. by "allocating" rectangular areas in larger coefficient maps...
Definition: SHLMapMan.hpp:25
The plant description manager holds and manages all plant descriptions so they can be shared with mul...
Definition: PlantDescrMan.hpp:19
ArrayT< SharedTerrainT * > m_Terrains
Terrains are shared among the BspTree (graphics world) and the CollModel (physics world)...
Definition: World.hpp:73
BoundingBox3dT BB
The lateral dimensions of the terrain.
Definition: World.hpp:53
Definition: World.hpp:41
This class represents a surface material ("A datastructural representation of a scripts material def...
Definition: Material.hpp:22
Definition: World.hpp:85
The class represents a BSP Tree node, implementing the Composite design pattern.
Definition: BspTreeNode.hpp:30
Definition: World.hpp:90
This class represents a static collision model.
Definition: CollisionModel_static.hpp:25
This class is used for managing model instances.
Definition: ModelManager.hpp:31
static const double RoundEpsilon
The maximum amount that is allowed for geometry-related rounding errors.
Definition: World.hpp:36
Definition: World.hpp:61
Definition: World.hpp:33
ArrayT< unsigned short > HeightData
The height data this terrain is created from (size==SideLength*SideLength).
Definition: World.hpp:55
MaterialT * Material
The material for the terrain surface.
Definition: World.hpp:56
Definition: World.hpp:89
This class manages and provides resources (fonts and models) for GuiImplT instances.
Definition: GuiResources.hpp:26
static const double MinVertexDist
The minimum distance that vertices of faces and portals must be apart.
Definition: World.hpp:37