source: GTP/trunk/App/Demos/Geom/OgreStuff/include/opt/OgreQuake3Level.h @ 1812

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