Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreBspLevel.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2005 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef _BspLevel_H__
00026 #define _BspLevel_H__
00027 
00028 #include "OgreBspPrerequisites.h"
00029 #include "OgreResource.h"
00030 #include "OgreStaticFaceGroup.h"
00031 #include "OgreSceneManager.h"
00032 #include "OgreBspNode.h"
00033 #include "OgreHardwareBufferManager.h"
00034 #include "OgreDefaultHardwareBufferManager.h"
00035 #include "OgreQuake3Level.h"
00036 
00037 
00038 namespace Ogre {
00039 
00053     class BspLevel : public Resource
00054     {
00055         friend class BspSceneManager;
00056     public:
00058         BspLevel(ResourceManager* creator, const String& name, ResourceHandle handle,
00059             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
00060         ~BspLevel();
00061 
00063         bool isLeafVisible(const BspNode* from, const BspNode* to) const;
00064 
00066         const BspNode* getRootNode(void);
00067 
00071         BspNode* findLeaf(const Vector3& point) const;
00072 
00076         void _notifyObjectMoved(const MovableObject* mov, 
00077             const Vector3& pos);
00079         void _notifyObjectDetached(const MovableObject* mov);
00081         BspNode* getLeafStart(void) {return &mRootNode[mLeafStart]; }
00083         int getNumLeaves(void) const { return mNumLeaves; }
00084 
00086         static size_t calculateLoadingStages(const String& levelName);
00088         static size_t calculateLoadingStages(DataStreamPtr& stream);
00089 
00091         void load(DataStreamPtr& stream);
00092 
00094         bool isSkyEnabled(void) const;
00096         const String& getSkyMaterialName(void) const;
00098         Real getSkyCurvature(void) const;
00099 
00101     protected:
00103         void loadImpl(void);
00105         void unloadImpl(void);
00107         size_t calculateSize(void) const;
00114         BspNode* mRootNode;
00115         int mNumNodes;
00116         int mNumLeaves;
00117         int mLeafStart; // the index at which leaf nodes begin
00118 
00126         struct BspVertex
00127         {
00128             float position[3];
00129             float normal[3];
00130             int colour;
00131             float texcoords[2];
00132             float lightmap[2];
00133         };
00134         /*
00136         BspVertex* mVertices;
00137         int mNumVertices;
00138         */
00140         VertexData* mVertexData;
00141 
00145         int* mLeafFaceGroups;
00146         int mNumLeafFaceGroups;
00147 
00149         StaticFaceGroup* mFaceGroups;
00150         int mNumFaceGroups;
00151 
00152 
00153         /*
00155         int* mElements;
00156         int mNumElements;
00157         */
00158 
00160         size_t mNumIndexes;
00161         // system-memory buffer
00162         HardwareIndexBufferSharedPtr mIndexes;
00163 
00165         BspNode::Brush *mBrushes;
00166 
00168         std::vector<ViewPoint> mPlayerStarts;
00169 
00171         void loadQuake3Level(const Quake3Level& q3lvl);
00187         struct VisData
00188         {
00189             unsigned char *tableData;
00190             int numClusters;            // Number of clusters, therefore number of rows
00191             int rowLength;                // Length in bytes of each row (num clusters / 8 rounded up)
00192         };
00193 
00194         VisData mVisData;
00195 
00196 
00198         void loadEntities(const Quake3Level& q3lvl);
00199 
00200         typedef std::map<const MovableObject*, std::list<BspNode*> > MovableToNodeMap;
00202         MovableToNodeMap mMovableToNodeMap;
00203 
00204         void tagNodesWithMovable(BspNode* node, const MovableObject* mov, const Vector3& pos);
00205 
00206         // Storage of patches 
00207         typedef std::map<int, PatchSurface*> PatchMap;
00208         PatchMap mPatches;
00209         // Total number of vertices required for all patches
00210         size_t mPatchVertexCount;
00211         // Total number of indexes required for all patches
00212         size_t mPatchIndexCount;
00213         // Sky enabled?
00214         bool mSkyEnabled;
00215         // Sky material
00216         String mSkyMaterial;
00217         // Sky details
00218         Real mSkyCurvature;
00219 
00220 
00221         void initQuake3Patches(const Quake3Level & q3lvl, VertexDeclaration* decl);
00222         void buildQuake3Patches(size_t vertOffset, size_t indexOffset);
00223 
00224         void quakeVertexToBspVertex(const bsp_vertex_t* src, BspVertex* dest);
00225 
00226 
00227     };
00234     class BspLevelPtr : public SharedPtr<BspLevel> 
00235     {
00236     public:
00237         BspLevelPtr() : SharedPtr<BspLevel>() {}
00238         explicit BspLevelPtr(BspLevel* rep) : SharedPtr<BspLevel>(rep) {}
00239         BspLevelPtr(const BspLevelPtr& r) : SharedPtr<BspLevel>(r) {} 
00240         BspLevelPtr(const ResourcePtr& r) : SharedPtr<BspLevel>()
00241         {
00242             // lock & copy other mutex pointer
00243             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00244             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00245             pRep = static_cast<BspLevel*>(r.getPointer());
00246             pUseCount = r.useCountPointer();
00247             if (pUseCount)
00248             {
00249                 ++(*pUseCount);
00250             }
00251         }
00252 
00254         BspLevelPtr& operator=(const ResourcePtr& r)
00255         {
00256             if (pRep == static_cast<BspLevel*>(r.getPointer()))
00257                 return *this;
00258             release();
00259             // lock & copy other mutex pointer
00260             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00261             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00262             pRep = static_cast<BspLevel*>(r.getPointer());
00263             pUseCount = r.useCountPointer();
00264             if (pUseCount)
00265             {
00266                 ++(*pUseCount);
00267             }
00268             return *this;
00269         }
00270     };
00271 
00272 }
00273 
00274 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:37 2006