# 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);
    00087
    00089     protected:
    00091         void loadImpl(void);
    00093         void unloadImpl(void);
    00095         size_t calculateSize(void) const;
    00102         BspNode* mRootNode;
    00103         int mNumNodes;
    00104         int mNumLeaves;
    00105         int mLeafStart; // the index at which leaf nodes begin
    00106
    00114         struct BspVertex
    00115         {
    00116             float position[3];
    00117             float normal[3];
    00118             int colour;
    00119             float texcoords[2];
    00120             float lightmap[2];
    00121         };
    00122         /*
    00124         BspVertex* mVertices;
    00125         int mNumVertices;
    00126         */
    00128         VertexData* mVertexData;
    00129
    00133         int* mLeafFaceGroups;
    00134         int mNumLeafFaceGroups;
    00135
    00137         StaticFaceGroup* mFaceGroups;
    00138         int mNumFaceGroups;
    00139
    00140
    00141         /*
    00143         int* mElements;
    00144         int mNumElements;
    00145         */
    00146
    00148         size_t mNumIndexes;
    00149         // system-memory buffer
    00150         HardwareIndexBufferSharedPtr mIndexes;
    00151
    00153         BspNode::Brush *mBrushes;
    00154
    00156         std::vector<ViewPoint> mPlayerStarts;
    00157
    00159         void loadQuake3Level(const Quake3Level& q3lvl);
    00175         struct VisData
    00176         {
    00177             unsigned char *tableData;
    00178             int numClusters;            // Number of clusters, therefore number of rows
    00179             int rowLength;                // Length in bytes of each row (num clusters / 8 rounded up)
    00180         };
    00181
    00182         VisData mVisData;
    00183
    00184
    00186         void loadEntities(const Quake3Level& q3lvl);
    00187
    00188         typedef std::map<const MovableObject*, std::list<BspNode*> > MovableToNodeMap;
    00190         MovableToNodeMap mMovableToNodeMap;
    00191
    00192         void tagNodesWithMovable(BspNode* node, const MovableObject* mov, const Vector3& pos);
    00193
    00194         // Storage of patches
    00195         typedef std::map<int, PatchSurface*> PatchMap;
    00196         PatchMap mPatches;
    00197         // Total number of vertices required for all patches
    00198         size_t mPatchVertexCount;
    00199         // Total number of indexes required for all patches
    00200         size_t mPatchIndexCount;
    00201
    00202         void initQuake3Patches(const Quake3Level & q3lvl, VertexDeclaration* decl);
    00203         void buildQuake3Patches(size_t vertOffset, size_t indexOffset);
    00204
    00205         void quakeVertexToBspVertex(const bsp_vertex_t* src, BspVertex* dest);
    00206
    00207
    00208     };
    00215     class BspLevelPtr : public SharedPtr<BspLevel>
    00216     {
    00217     public:
    00218         BspLevelPtr() : SharedPtr<BspLevel>() {}
    00219         explicit BspLevelPtr(BspLevel* rep) : SharedPtr<BspLevel>(rep) {}
    00220         BspLevelPtr(const BspLevelPtr& r) : SharedPtr<BspLevel>(r) {}
    00221         BspLevelPtr(const ResourcePtr& r) : SharedPtr<BspLevel>()
    00222         {
    00223             // lock & copy other mutex pointer
    00224             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00225             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00226             pRep = static_cast<BspLevel*>(r.getPointer());
    00227             pUseCount = r.useCountPointer();
    00228             if (pUseCount)
    00229             {
    00230                 ++(*pUseCount);
    00231             }
    00232         }
    00233
    00235         BspLevelPtr& operator=(const ResourcePtr& r)
    00236         {
    00237             if (pRep == static_cast<BspLevel*>(r.getPointer()))
    00238                 return *this;
    00239             release();
    00240             // lock & copy other mutex pointer
    00241             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00242             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00243             pRep = static_cast<BspLevel*>(r.getPointer());
    00244             pUseCount = r.useCountPointer();
    00245             if (pUseCount)
    00246             {
    00247                 ++(*pUseCount);
    00248             }
    00249             return *this;
    00250         }
    00251     };
    00252
    00253 }
    00254
    00255 #endif

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