| 1 | /* |
|---|
| 2 | ================================================================================= |
|---|
| 3 | This file is part of Cafu, the open-source game engine and graphics engine |
|---|
| 4 | for multiplayer, cross-platform, real-time 3D action. |
|---|
| 5 | Copyright (C) 2002-2012 Carsten Fuchs Software. |
|---|
| 6 | |
|---|
| 7 | Cafu is free software: you can redistribute it and/or modify it under the terms |
|---|
| 8 | of the GNU General Public License as published by the Free Software Foundation, |
|---|
| 9 | either version 3 of the License, or (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 12 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|---|
| 13 | PURPOSE. See the GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with Cafu. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | For support and more information about Cafu, visit us at <http://www.cafu.de>. |
|---|
| 19 | ================================================================================= |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | /**********************/ |
|---|
| 23 | /*** World (Header) ***/ |
|---|
| 24 | /**********************/ |
|---|
| 25 | |
|---|
| 26 | #ifndef CAFU_WORLD_HPP_INCLUDED |
|---|
| 27 | #define CAFU_WORLD_HPP_INCLUDED |
|---|
| 28 | |
|---|
| 29 | #include "Templates/Array.hpp" |
|---|
| 30 | #include "Math3D/BoundingBox.hpp" |
|---|
| 31 | #include "Math3D/Plane3.hpp" |
|---|
| 32 | #include "Math3D/Polygon.hpp" |
|---|
| 33 | #include "SceneGraph/FaceNode.hpp" |
|---|
| 34 | #include "SceneGraph/LightMapMan.hpp" |
|---|
| 35 | #include "SceneGraph/SHLMapMan.hpp" |
|---|
| 36 | #include "Terrain/Terrain.hpp" |
|---|
| 37 | #include "Plants/PlantDescrMan.hpp" |
|---|
| 38 | |
|---|
| 39 | #include <string> |
|---|
| 40 | #include <map> |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | namespace cf { namespace SceneGraph { class BspTreeNodeT; } } |
|---|
| 44 | namespace cf { namespace ClipSys { class CollisionModelStaticT; } } |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | struct PointLightT |
|---|
| 48 | { |
|---|
| 49 | VectorT Origin; |
|---|
| 50 | VectorT Dir; ///< Direction of the cone. |
|---|
| 51 | float Angle; ///< Cone opening angle, in radians. |
|---|
| 52 | VectorT Intensity; ///< Intensity in [W/sr]. |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | struct MapT |
|---|
| 57 | { |
|---|
| 58 | // TODO: Move into FaceNodeT! |
|---|
| 59 | const static double RoundEpsilon; ///< The maximum amount that is allowed for geometry-related rounding errors. |
|---|
| 60 | const static double MinVertexDist; ///< The minimum distance that vertices of faces and portals must be apart. |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | struct InfoPlayerStartT |
|---|
| 65 | { |
|---|
| 66 | VectorT Origin; |
|---|
| 67 | unsigned short Heading; |
|---|
| 68 | unsigned short Pitch; |
|---|
| 69 | unsigned short Bank; |
|---|
| 70 | }; |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | class SharedTerrainT |
|---|
| 74 | { |
|---|
| 75 | public: |
|---|
| 76 | |
|---|
| 77 | // Note that these constructors can theoretically throw because the TerrainT constructor can throw. |
|---|
| 78 | // In practice this should never happen though, because otherwise a .cmap or .cw file contained an invalid terrain. |
|---|
| 79 | SharedTerrainT(const BoundingBox3dT& BB_, unsigned long SideLength_, const ArrayT<unsigned short>& HeightData_, MaterialT* Material_); |
|---|
| 80 | SharedTerrainT(std::istream& InFile); |
|---|
| 81 | |
|---|
| 82 | void WriteTo(std::ostream& OutFile) const; |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | BoundingBox3dT BB; ///< The lateral dimensions of the terrain. |
|---|
| 86 | unsigned long SideLength; ///< Side length of the terrain height data. |
|---|
| 87 | ArrayT<unsigned short> HeightData; ///< The height data this terrain is created from (size==SideLength*SideLength). |
|---|
| 88 | MaterialT* Material; ///< The material for the terrain surface. |
|---|
| 89 | TerrainT Terrain; |
|---|
| 90 | }; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | class GameEntityT |
|---|
| 94 | { |
|---|
| 95 | public: |
|---|
| 96 | |
|---|
| 97 | GameEntityT(unsigned long MFIndex_); |
|---|
| 98 | ~GameEntityT(); |
|---|
| 99 | |
|---|
| 100 | const unsigned long MFIndex; ///< This game entity corresponds to (was loaded from) this entity in the cmap file. This index must explicitly be kept here, because the array of GameEntityTs does usually not correspond to the array of cmap file entities, as the CaBSP loader code may rearrange it. Note that this index should always be checked for validity: It defaults to 0xFFFFFFFF when for any reason no corresponding cmap file entity is known. |
|---|
| 101 | VectorT Origin; |
|---|
| 102 | ArrayT<SharedTerrainT*> Terrains; ///< Terrains are shared among the BspTree (graphics world) and the CollModel (physics world). |
|---|
| 103 | cf::SceneGraph::BspTreeNodeT* BspTree; |
|---|
| 104 | cf::ClipSys::CollisionModelStaticT* CollModel; |
|---|
| 105 | std::map<std::string, std::string> Properties; |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | private: |
|---|
| 109 | |
|---|
| 110 | GameEntityT(const GameEntityT&); ///< Use of the Copy Constructor is not allowed. |
|---|
| 111 | void operator = (const GameEntityT&); ///< Use of the Assignment Operator is not allowed. |
|---|
| 112 | }; |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | class WorldT |
|---|
| 116 | { |
|---|
| 117 | public: |
|---|
| 118 | |
|---|
| 119 | struct LoadErrorT { const char* Msg; LoadErrorT(const char* Msg_) : Msg(Msg_) {} }; |
|---|
| 120 | struct SaveErrorT { const char* Msg; SaveErrorT(const char* Msg_) : Msg(Msg_) {} }; |
|---|
| 121 | |
|---|
| 122 | typedef void (*ProgressFunctionT)(float ProgressPercent, const char* ProgressText); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | /// Constructor for creating an empty world. |
|---|
| 126 | WorldT(); |
|---|
| 127 | |
|---|
| 128 | /// Destructor. |
|---|
| 129 | ~WorldT(); |
|---|
| 130 | |
|---|
| 131 | /// Constructor for creating a world from a .cw file. |
|---|
| 132 | WorldT(const char* FileName, ModelManagerT& ModelMan, ProgressFunctionT ProgressFunction=NULL) /*throw (LoadErrorT)*/; |
|---|
| 133 | |
|---|
| 134 | /// Saves the world to disk. |
|---|
| 135 | void SaveToDisk(const char* FileName) const /*throw (SaveErrorT)*/; |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | ArrayT<SharedTerrainT*> Terrains; |
|---|
| 139 | cf::SceneGraph::BspTreeNodeT* BspTree; |
|---|
| 140 | cf::ClipSys::CollisionModelStaticT* CollModel; |
|---|
| 141 | ArrayT<InfoPlayerStartT> InfoPlayerStarts; |
|---|
| 142 | ArrayT<PointLightT> PointLights; |
|---|
| 143 | ArrayT<GameEntityT*> GameEntities; |
|---|
| 144 | cf::SceneGraph::LightMapManT LightMapMan; |
|---|
| 145 | cf::SceneGraph::SHLMapManT SHLMapMan; |
|---|
| 146 | PlantDescrManT PlantDescrMan; |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | private: |
|---|
| 150 | |
|---|
| 151 | WorldT(const WorldT&); // Use of the Copy Constructor is not allowed. |
|---|
| 152 | void operator = (const WorldT&); // Use of the Assignment Operator is not allowed. |
|---|
| 153 | }; |
|---|
| 154 | |
|---|
| 155 | #endif |
|---|