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

OgreQuake3Level.cpp

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 © 2000-2002 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 #include "OgreQuake3Level.h"
00026 #include "OgreDataChunk.h"
00027 #include "OgreLogManager.h"
00028 #include "OgreTextureManager.h"
00029 
00030 namespace Ogre {
00031 
00032 
00033     Quake3Level::Quake3Level()
00034     {
00035 
00036     }
00037 
00038     void Quake3Level::loadFromChunk(DataChunk& inChunk)
00039     {
00040         mChunk = inChunk;
00041         initialise();
00042 
00043 #ifdef _DEBUG
00044         dumpContents();
00045 #endif
00046 
00047 
00048     }
00049 
00050     void Quake3Level::initialise(void)
00051     {
00052         mHeader = (bsp_header_t*)mChunk.getPtr();
00053         mLumpStart = ((unsigned char*)mHeader) + sizeof(mHeader);
00054 
00055         mEntities = (unsigned char*)getLump(BSP_ENTITIES_LUMP);
00056         mNumEntities = getLumpSize(BSP_ENTITIES_LUMP);
00057 
00058         mElements = (int*)getLump(BSP_ELEMENTS_LUMP);
00059         mNumElements = getLumpSize(BSP_ELEMENTS_LUMP) / sizeof(int);
00060 
00061         mFaces = (bsp_face_t*)getLump(BSP_FACES_LUMP);
00062         mNumFaces = getLumpSize(BSP_FACES_LUMP) / sizeof(bsp_face_t);
00063 
00064         mLeafFaces = (int*)getLump(BSP_LFACES_LUMP);
00065         mNumLeafFaces = getLumpSize(BSP_LFACES_LUMP) / sizeof(int);
00066 
00067         mLeaves = (bsp_leaf_t*)getLump(BSP_LEAVES_LUMP);
00068         mNumLeaves = getLumpSize(BSP_LEAVES_LUMP) / sizeof(bsp_leaf_t);
00069 
00070         mLightmaps = (unsigned char*)getLump(BSP_LIGHTMAPS_LUMP);
00071         mNumLightmaps = getLumpSize(BSP_LIGHTMAPS_LUMP)/BSP_LIGHTMAP_BANKSIZE;
00072 
00073         mModels = (bsp_model_t*)getLump(BSP_MODELS_LUMP);
00074         mNumModels = getLumpSize(BSP_MODELS_LUMP) / sizeof(bsp_model_t);
00075 
00076         mNodes = (bsp_node_t*)getLump(BSP_NODES_LUMP);
00077         mNumNodes = getLumpSize(BSP_NODES_LUMP) / sizeof(bsp_node_t);
00078 
00079         mPlanes = (bsp_plane_t*) getLump(BSP_PLANES_LUMP);
00080         mNumPlanes = getLumpSize(BSP_PLANES_LUMP)/sizeof(bsp_plane_t);
00081 
00082         mShaders = (bsp_shader_t*) getLump(BSP_SHADERS_LUMP);
00083         mNumShaders = getLumpSize(BSP_SHADERS_LUMP)/sizeof(bsp_shader_t);
00084 
00085         mVis = (bsp_vis_t*)getLump(BSP_VISIBILITY_LUMP);
00086 
00087         mVertices = (bsp_vertex_t*) getLump(BSP_VERTICES_LUMP);
00088         mNumVertices = getLumpSize(BSP_VERTICES_LUMP)/sizeof(bsp_vertex_t);
00089 
00090         mLeafBrushes = (int*)getLump(BSP_LBRUSHES_LUMP);
00091         mNumLeafBrushes = getLumpSize(BSP_LBRUSHES_LUMP)/sizeof(int);
00092 
00093         mBrushes = (bsp_brush_t*) getLump(BSP_BRUSH_LUMP);
00094         mNumBrushes = getLumpSize(BSP_BRUSH_LUMP)/sizeof(bsp_brush_t);
00095 
00096         mBrushSides = (bsp_brushside_t*) getLump(BSP_BRUSHSIDES_LUMP);
00097         mNumBrushSides = getLumpSize(BSP_BRUSHSIDES_LUMP)/sizeof(bsp_brushside_t);
00098 
00099     }
00100 
00101     void* Quake3Level::getLump(int lumpType)
00102     {
00103         return (unsigned char*)mHeader + mHeader->lumps[lumpType].offset;
00104     }
00105 
00106     int Quake3Level::getLumpSize(int lumpType)
00107     {
00108         return mHeader->lumps[lumpType].size;
00109     }
00110 
00111     void Quake3Level::dumpContents(void)
00112     {
00113         std::ofstream of;
00114         of.open("Quake3Level.log");
00115 
00116 
00117         of << "Quake3 level statistics" << std::endl;
00118         of << "-----------------------" << std::endl;
00119         of << "Entities     : " << mNumEntities << std::endl;
00120         of << "Faces        : " << mNumFaces << std::endl;
00121         of << "Leaf Faces   : " << mNumLeafFaces << std::endl;
00122         of << "Leaves       : " << mNumLeaves << std::endl;
00123         of << "Lightmaps    : " << mNumLightmaps << std::endl;
00124         of << "Elements     : " << mNumElements << std::endl;
00125         of << "Models       : " << mNumModels << std::endl;
00126         of << "Nodes        : " << mNumNodes << std::endl;
00127         of << "Planes       : " << mNumPlanes << std::endl;
00128         of << "Shaders      : " << mNumShaders << std::endl;
00129         of << "Vertices     : " << mNumVertices << std::endl;
00130         of << "Vis Clusters : " << mVis->cluster_count << std::endl;
00131 
00132         of << std::endl;
00133         of << "-= Shaders =-";
00134         of << std::endl;
00135         for (int i = 0; i < mNumShaders; ++i)
00136         {
00137             of << "Shader " << i << ": " << mShaders[i].name << std::endl;
00138         }
00139 
00140         of << std::endl;
00141         of << "-= Entities =-";
00142         of << std::endl;
00143         char* strEnt = strtok((char*)mEntities, "\0");
00144         while (strEnt != 0)
00145         {
00146             of << strEnt << std::endl;
00147             strEnt = strtok(0, "\0");
00148         }
00149 
00150 
00151 
00152 
00153         of.close();
00154     }
00155 
00156     void Quake3Level::extractLightmaps(void) const
00157     {
00158         // Lightmaps are always 128x128x24 (RGB)
00159         unsigned char* pLightmap = mLightmaps;
00160         for (int i = 0; i < mNumLightmaps; ++i)
00161         {
00162             char name[32];
00163             sprintf(name, "@lightmap%d", i);
00164 
00165             // Load, no mipmaps, brighten by factor 2.5
00166             Image img; img.loadRawData( DataChunk( pLightmap, 128 * 128 * 3 ), 128, 128, PF_R8G8B8 );
00167             TextureManager::getSingleton().loadImage( name, img, TEX_TYPE_2D, 0, 4.0f );
00168             pLightmap += BSP_LIGHTMAP_BANKSIZE;
00169         }
00170 
00171 
00172     }
00173 
00174 
00175 }

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:23 2004