[1] | 1 | /* |
---|
| 2 | ----------------------------------------------------------------------------- |
---|
| 3 | This source file is part of OGRE |
---|
| 4 | (Object-oriented Graphics Rendering Engine) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #ifndef __Quake3Level_H__ |
---|
| 30 | #define __Quake3Level_H__ |
---|
| 31 | |
---|
| 32 | #include "OgreBspPrerequisites.h" |
---|
| 33 | #include "OgreQuake3Types.h" |
---|
| 34 | #include "OgreDataStream.h" |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | namespace Ogre { |
---|
| 38 | |
---|
| 39 | /** Support for loading and extracting data from a Quake3 level file. |
---|
| 40 | This class implements the required methods for opening Quake3 level files |
---|
| 41 | and extracting the pertinent data within. Ogre supports BSP based levels |
---|
| 42 | through it's own BspLevel class, which is not specific to any file format, |
---|
| 43 | so this class is here to source that data from the Quake3 format.</p> |
---|
| 44 | Quake3 levels include far more than just data for rendering - typically the |
---|
| 45 | <strong>leaves</strong> of the tree are used for rendering, and <strong>brushes,</strong> |
---|
| 46 | are used to define convex hulls made of planes for collision detection. There are also |
---|
| 47 | <strong>entities</strong> which define non-visual elements like player start |
---|
| 48 | points, triggers etc and <strong>models</strong> which are used for movable |
---|
| 49 | scenery like doors and platforms. <strong>Shaders</strong> meanwhile are textures |
---|
| 50 | with extra effects and 'content flags' indicating special properties like |
---|
| 51 | water or lava.</p> |
---|
| 52 | I will try to support as much of this as I can in Ogre, but I won't duplicate |
---|
| 53 | the structure or necesarily use the same terminology. Quake3 is designed for a very specific |
---|
| 54 | purpose and code structure, whereas Ogre is designed to be more flexible, |
---|
| 55 | so for example I'm likely to separate game-related properties like surface flags |
---|
| 56 | from the generics of materials in my implementation.</p> |
---|
| 57 | This is a utility class only - a single call to loadFromChunk should be |
---|
| 58 | enough. You should not expect the state of this object to be consistent |
---|
| 59 | between calls, since it uses pointers to memory which may no longer |
---|
| 60 | be valid after the original call. This is why it has no accessor methods |
---|
| 61 | for reading it's internal state. |
---|
| 62 | */ |
---|
| 63 | class Quake3Level |
---|
| 64 | { |
---|
| 65 | public: |
---|
| 66 | Quake3Level(); |
---|
| 67 | |
---|
| 68 | /** Load just the header information from a Quake3 file. |
---|
| 69 | @remarks |
---|
| 70 | This method loads just the header information from the |
---|
| 71 | Quake3 file, in order to estimate the loading time. |
---|
| 72 | */ |
---|
| 73 | void loadHeaderFromStream(DataStreamPtr& inStream); |
---|
| 74 | |
---|
| 75 | /** Reads Quake3 bsp data from a stream as read from the file. |
---|
| 76 | Since ResourceManagers generally locate data in a variety of |
---|
| 77 | places they typically manipulate them as a chunk of data, rather than |
---|
| 78 | a file pointer since this is unsupported through compressed archives.</p> |
---|
| 79 | Quake3 files are made up of a header (which contains version info and |
---|
| 80 | a table of the contents) and 17 'lumps' i.e. sections of data, |
---|
| 81 | the offsets to which are kept in the table of contents. The 17 types |
---|
| 82 | are predefined (You can find them in OgreQuake3Types.h) |
---|
| 83 | |
---|
| 84 | @param inStream Stream containing Quake3 data |
---|
| 85 | */ |
---|
| 86 | void loadFromStream(DataStreamPtr& inStream); |
---|
| 87 | |
---|
| 88 | /* Extracts the embedded lightmap texture data and loads them as textures. |
---|
| 89 | Calling this method makes the lightmap texture data embedded in |
---|
| 90 | the .bsp file available to the renderer. Lightmaps are extracted |
---|
| 91 | and loaded as Texture objects (subclass specific to RenderSystem |
---|
| 92 | subclass) and are named "@lightmap1", "@lightmap2" etc. |
---|
| 93 | */ |
---|
| 94 | void extractLightmaps(void) const; |
---|
| 95 | |
---|
| 96 | /** Utility function read the header and set up pointers. */ |
---|
| 97 | void initialise(bool headerOnly = false); |
---|
| 98 | /** Utility function read the header and set up counters. */ |
---|
| 99 | void initialiseCounts(void); |
---|
| 100 | /** Utility function read the header and set up pointers. */ |
---|
| 101 | void initialisePointers(void); |
---|
| 102 | |
---|
| 103 | /** Utility function to return a pointer to a lump. */ |
---|
| 104 | void* getLump(int lumpType); |
---|
| 105 | int getLumpSize(int lumpType); |
---|
| 106 | |
---|
| 107 | /** Debug method. */ |
---|
| 108 | void dumpContents(void); |
---|
| 109 | |
---|
| 110 | // Internal storage |
---|
| 111 | // This is ALL temporary. Don't rely on it being static |
---|
| 112 | MemoryDataStreamPtr mChunk; |
---|
| 113 | |
---|
| 114 | // NB no brushes, fog or local lightvolumes yet |
---|
| 115 | bsp_header_t* mHeader; |
---|
| 116 | unsigned char* mLumpStart; |
---|
| 117 | |
---|
| 118 | int* mElements; // vertex indexes for faces |
---|
| 119 | int mNumElements; |
---|
| 120 | |
---|
| 121 | void* mEntities; |
---|
| 122 | int mNumEntities; |
---|
| 123 | |
---|
| 124 | bsp_model_t* mModels; |
---|
| 125 | int mNumModels; |
---|
| 126 | |
---|
| 127 | bsp_node_t* mNodes; |
---|
| 128 | int mNumNodes; |
---|
| 129 | |
---|
| 130 | bsp_leaf_t* mLeaves; |
---|
| 131 | int mNumLeaves; |
---|
| 132 | |
---|
| 133 | int* mLeafFaces; // Indexes to face groups by leaf |
---|
| 134 | int mNumLeafFaces; |
---|
| 135 | |
---|
| 136 | bsp_plane_t* mPlanes; |
---|
| 137 | int mNumPlanes; |
---|
| 138 | |
---|
| 139 | bsp_face_t* mFaces; // Groups of faces |
---|
| 140 | int mNumFaces; |
---|
| 141 | |
---|
| 142 | bsp_vertex_t* mVertices; |
---|
| 143 | int mNumVertices; |
---|
| 144 | |
---|
| 145 | bsp_shader_t* mShaders; |
---|
| 146 | int mNumShaders; |
---|
| 147 | |
---|
| 148 | unsigned char* mLightmaps; |
---|
| 149 | int mNumLightmaps; |
---|
| 150 | |
---|
| 151 | bsp_vis_t* mVis; |
---|
| 152 | |
---|
| 153 | bsp_brush_t* mBrushes; |
---|
| 154 | int mNumBrushes; |
---|
| 155 | |
---|
| 156 | bsp_brushside_t* mBrushSides; |
---|
| 157 | int mNumBrushSides; |
---|
| 158 | |
---|
| 159 | int* mLeafBrushes; // Groups of indexes to brushes by leaf |
---|
| 160 | int mNumLeafBrushes; |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | }; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | #endif |
---|