| 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 | #ifndef CAFU_MAPFILE_HPP_INCLUDED |
|---|
| 23 | #define CAFU_MAPFILE_HPP_INCLUDED |
|---|
| 24 | |
|---|
| 25 | #include <map> |
|---|
| 26 | |
|---|
| 27 | #include "Templates/Array.hpp" |
|---|
| 28 | #include "Math3D/Vector3.hpp" |
|---|
| 29 | #include "Math3D/Plane3.hpp" |
|---|
| 30 | #include "Math3D/BoundingBox.hpp" |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | class MaterialT; |
|---|
| 34 | class TextParserT; |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | namespace cf |
|---|
| 38 | { |
|---|
| 39 | extern const double CA3DE_SCALE; |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | /// This struct describes a plane (and thus one side) of a map brush. |
|---|
| 43 | /// The members U, V, ShiftU and ShiftV together define the planar projection |
|---|
| 44 | /// for computing the (u, v) texture coordinates at the vertices of the brush. |
|---|
| 45 | struct MapFilePlaneT |
|---|
| 46 | { |
|---|
| 47 | // ArrayT<VectorT> Points; |
|---|
| 48 | Plane3dT Plane; |
|---|
| 49 | MaterialT* Material; ///< The planes material. |
|---|
| 50 | Vector3dT U; ///< The first span vector of the texture projection plane. |
|---|
| 51 | Vector3dT V; ///< The second span vector of the texture projection plane. |
|---|
| 52 | double ShiftU; ///< Texture "scroll offset" in direction of U. |
|---|
| 53 | double ShiftV; ///< Texture "scroll offset" in direction of V. |
|---|
| 54 | }; |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | struct MapFileBrushT |
|---|
| 58 | { |
|---|
| 59 | /// The default constructor. |
|---|
| 60 | MapFileBrushT() { } |
|---|
| 61 | |
|---|
| 62 | /// @throws TextParserT::ParseError on problems. |
|---|
| 63 | MapFileBrushT(TextParserT& TP, unsigned long BrushNr); |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | ArrayT<MapFilePlaneT> MFPlanes; |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | struct MapFileBezierPatchT |
|---|
| 71 | { |
|---|
| 72 | /// The default constructor. |
|---|
| 73 | MapFileBezierPatchT() { } |
|---|
| 74 | |
|---|
| 75 | /// @throws TextParserT::ParseError on problems. |
|---|
| 76 | MapFileBezierPatchT(TextParserT& TP); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | // TODO: Remove the SizeX, SizeY and ControlsPoints members, use a cf::math::BezierPatchT<float> instead! |
|---|
| 80 | unsigned long SizeX; ///< Nr of columns. |
|---|
| 81 | unsigned long SizeY; ///< Nr of rows. |
|---|
| 82 | |
|---|
| 83 | int SubdivsHorz; ///< Number of subdivisions in horizontal direction, or auto-detection if -1. |
|---|
| 84 | int SubdivsVert; ///< Number of subdivisions in vertical direction, or auto-detection if -1. |
|---|
| 85 | |
|---|
| 86 | MaterialT* Material; ///< The patches material. |
|---|
| 87 | ArrayT<float> ControlPoints; ///< The SizeX*SizeY*5 control points. |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | struct MapFileTerrainT |
|---|
| 92 | { |
|---|
| 93 | /// The default constructor. |
|---|
| 94 | MapFileTerrainT() { } |
|---|
| 95 | |
|---|
| 96 | /// @throws TextParserT::ParseError on problems. |
|---|
| 97 | MapFileTerrainT(TextParserT& TP); |
|---|
| 98 | |
|---|
| 99 | /// Returns the spatial coordinate for the given (logical) height field position. |
|---|
| 100 | /// Note that for processing all vertices of a terrain quickly, specialized loops |
|---|
| 101 | /// should be preferred over this relatively slow (repetitive) method. |
|---|
| 102 | /// @param x The horizontal component of the logical height field position. |
|---|
| 103 | /// @param y The vertical component of the logical height field position. |
|---|
| 104 | /// @returns the spatial coordinate for the given (logical) height field position. |
|---|
| 105 | Vector3dT GetSpatial(unsigned long x, unsigned long y) const |
|---|
| 106 | { |
|---|
| 107 | Vector3dT Pos=Bounds.Min; |
|---|
| 108 | |
|---|
| 109 | Pos.x+=(Bounds.Max.x-Bounds.Min.x)*double(x)/double(SideLength-1); |
|---|
| 110 | Pos.y+=(Bounds.Max.y-Bounds.Min.y)*double(y)/double(SideLength-1); |
|---|
| 111 | Pos.z+=(Bounds.Max.z-Bounds.Min.z)*double(HeightData[SideLength*y+x])/65535.0; |
|---|
| 112 | |
|---|
| 113 | return Pos; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | BoundingBox3dT Bounds; ///< The terrains bounds. |
|---|
| 118 | MaterialT* Material; ///< The terrains material. |
|---|
| 119 | unsigned long SideLength; ///< Side length of the terrains height data. |
|---|
| 120 | ArrayT<unsigned short> HeightData; ///< The SideLength*SideLength array of height data. |
|---|
| 121 | }; |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | struct MapFilePlantT |
|---|
| 125 | { |
|---|
| 126 | /// The default constructor. |
|---|
| 127 | MapFilePlantT() { } |
|---|
| 128 | |
|---|
| 129 | /// @throws TextParserT::ParseError on problems. |
|---|
| 130 | MapFilePlantT(TextParserT& TP); |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | std::string DescrFileName; |
|---|
| 134 | unsigned int RandomSeed; |
|---|
| 135 | Vector3dT Position; |
|---|
| 136 | Vector3fT Angles; |
|---|
| 137 | }; |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | struct MapFileModelT |
|---|
| 141 | { |
|---|
| 142 | /// The default constructor. |
|---|
| 143 | MapFileModelT() { } |
|---|
| 144 | |
|---|
| 145 | /// @throws TextParserT::ParseError on problems. |
|---|
| 146 | MapFileModelT(TextParserT& TP); |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | std::string Model; |
|---|
| 150 | std::string CollModel; |
|---|
| 151 | std::string Label; |
|---|
| 152 | Vector3fT Origin; |
|---|
| 153 | Vector3fT Angles; |
|---|
| 154 | float Scale; |
|---|
| 155 | int SeqNumber; |
|---|
| 156 | float FrameOffset; |
|---|
| 157 | float FrameTimeScale; |
|---|
| 158 | bool Animate; |
|---|
| 159 | }; |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | struct MapFileEntityT |
|---|
| 163 | { |
|---|
| 164 | /// The default constructor. |
|---|
| 165 | MapFileEntityT() : MFIndex(0) { } |
|---|
| 166 | |
|---|
| 167 | /// @throws TextParserT::ParseError on problems. |
|---|
| 168 | MapFileEntityT(unsigned long Index, TextParserT& TP); |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | unsigned long MFIndex; ///< In the source cmap file, this was/is the MFIndex-th entity. Normally (e.g. immediately after loading the cmap file) this is identical to the index of this MapFileEntityT into the array of all entities. It is kept explicitly here in case the array of all entities is rearranged, as is done e.g. by the CaBSP loader. |
|---|
| 172 | ArrayT<MapFileBrushT> MFBrushes; |
|---|
| 173 | ArrayT<MapFileBezierPatchT> MFPatches; |
|---|
| 174 | ArrayT<MapFileTerrainT> MFTerrains; |
|---|
| 175 | ArrayT<MapFilePlantT> MFPlants; |
|---|
| 176 | ArrayT<MapFileModelT> MFModels; |
|---|
| 177 | std::map<std::string, std::string> MFProperties; |
|---|
| 178 | }; |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | /// @throws TextParserT::ParseError on problems (and writes additional diagnostics to the console). |
|---|
| 182 | void MapFileReadHeader(TextParserT& TP); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | #endif |
|---|