00001 /* 00002 * bsp-version.h 00003 * 00004 * Copyright (C) 2010 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * 00031 */ 00032 00033 #ifndef WAVEPACKET_QUAKE_BSP_VERSION_H__ 00034 #define WAVEPACKET_QUAKE_BSP_VERSION_H__ 00035 00036 // includes -------------------------------------------------------------------- 00037 #include "geometry/geometry_3d.h" 00038 00039 #include <iostream> 00040 00041 00042 namespace quake { 00043 00044 /// \ingroup quake_bsp 00045 /*@{*/ 00046 00047 00048 enum eBspVendor { 00049 eBspVendor_Id = 1, ///< Id Software, magic = "IBSP" 00050 eBspVendor_Valve = 2, ///< Valve Softare, magic = "VBSP" 00051 00052 // keep this last! 00053 eBspVendor_Invalid = 0 00054 }; 00055 00056 00057 00058 enum eBspVersion { 00059 // ID versions 00060 eBspVersion_IdQuake3 = 1001, 00061 00062 // Valve versions 00063 00064 // keep this last! 00065 eBspVersion_Invalid = 0 00066 }; 00067 00068 00069 00070 /// types of lumps in BSP maps. There are many types of lumps, and no vendor 00071 /// seems to 100% agree on what they are! Some examples: 00072 /// - ID Quake3: http://www.mralligator.com/q3/ 00073 /// - Valve: http://developer.valvesoftware.com/wiki/The_Source_Engine_BSP_File_Format 00074 enum eLumpType { 00075 // lumps in the Quake3 bsp format 00076 eLump_Entities = 1, ///< game objects in map 00077 eLump_Textures = 2, ///< surface descriptions 00078 eLump_Planes = 3, ///< planes used by map/BSP geometry 00079 eLump_Nodes = 4, ///< BSP tree nodes 00080 eLump_Leafs = 5, ///< leaves in the BSP tree 00081 eLump_Leaffaces = 6, ///< list of face indices, one list per leaf 00082 eLump_Leafbrushes = 7, ///< list of brush indices, one list per leaf 00083 eLump_Models = 8, ///< rigid world models 00084 eLump_Brushes = 9, ///< convex polyhedra for collisions 00085 eLump_Brushsides = 10, ///< brush surfaces 00086 eLump_Vertices = 11, ///< vertices used to describe faces 00087 eLump_Meshverts = 12, ///< lists of offsets, one per mesh 00088 eLump_Effects = 13, ///< special map effects 00089 eLump_Faces = 14, ///< surface geometry 00090 eLump_Lightmaps = 15, ///< packed lightmap data 00091 eLump_Lightvols = 16, ///< local illumination data 00092 eLump_Visdata = 17, ///< cluster-cluster visibility map 00093 00094 // keep this last! 00095 eLump_Invalid = 0 00096 }; 00097 00098 typedef std::vector<eLumpType> vec_lump_type_t; 00099 00100 /// for debugging 00101 const char * getLumpName(IN eLumpType type); 00102 00103 00104 00105 //////////////////////////////////////////////////////////////////////////////// 00106 // 00107 // basic parsing 00108 // 00109 //////////////////////////////////////////////////////////////////////////////// 00110 00111 /// read an integer. These are stored as little-endian in BSP files. 00112 int32_t readInt(IO std::istream& stream); 00113 00114 /// read a float. These are stored as little-endian in BSP files. 00115 float readFloat(IO std::istream& stream); 00116 00117 /// read a vector/point (helper function using readFloat() above) 00118 point3d_t readPoint3d(IO std::istream& stream); 00119 00120 00121 /// bsp version object 00122 class BspVersion { 00123 public: 00124 // constructor, destructor --------------------------------------------- 00125 BspVersion(void) throw() { this->clear(); } 00126 00127 // quake::BspVersion public class methods ------------------------------ 00128 void clear(void) throw(); 00129 bool isValid(void) const throw(); 00130 void read(IO std::istream& stream); 00131 eBspVendor getVendor(void) const throw() { return m_vendor; } 00132 eBspVersion getVersion(void) const throw() { return m_version; } 00133 bool getLumpTypes(OUT vec_lump_type_t& lumps) const; 00134 00135 protected: 00136 eBspVendor m_vendor; 00137 eBspVersion m_version; 00138 }; 00139 00140 00141 00142 }; // media namespace 00143 00144 00145 00146 #endif // WAVEPACKET_QUAKE_BSP_VERSION_H__ 00147