Classes | Enumerations | Enumerator | Functions | Variables

Quake BSP Parsing Library

This is a simple library for parsing Quake's BSP file format. More...

Classes

struct  quake::lump_object_t
 an object in a lump. More...
struct  quake::entity_t
 a game entity in the bsp map More...
struct  quake::face_t
 a polygon face in the bsp map More...
struct  quake::node_t
 a node in the BSP tree Note that the indexing scheme is unusual:

  • A non-negative index refers to a node
  • A negative index is a leaf, -(leaf + 1)
More...
struct  quake::leaf_t
 a leaf in the BSP tree More...
struct  quake::leafface_t
 a leaf face in the BSP tree More...
struct  quake::meshvert_t
 a mesh vertex More...
struct  quake::plane_t
 a 2D plane in the BSP tree More...
struct  quake::texture_path_t
 texture information More...
struct  quake::color_t
 color struct TODO: centralize this somewhere? now redundant with glut::color_t More...
struct  quake::vertex_t
 vertex information More...
class  quake::Bsp
 The 3D space-partitioned map. More...

Enumerations

enum  quake::eFaceType {
  quake::eFace_Polygon = 1,
  quake::eFace_Patch = 2,
  quake::eFace_Mesh = 3,
  quake::eFace_Billboard = 4,
  quake::eFace_Invalid = 0
}
 

polygon face type

More...

Functions

virtual eLumpType quake::lump_object_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
virtual int quake::lump_object_t::getIndex (void) const throw ()
 returns the index of this object as stored in its lump
eLumpType quake::entity_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
eLumpType quake::face_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
eLumpType quake::node_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
eLumpType quake::leaf_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
eLumpType quake::leafface_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
eLumpType quake::meshvert_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
eLumpType quake::plane_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
eLumpType quake::texture_path_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
void quake::texture_path_t::dump (void) const throw ()
eLumpType quake::vertex_t::getType (void) const throw ()
 what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.
virtual BspVersion quake::Bsp::getVersion (void) const =0 throw ()
virtual const char * quake::Bsp::getName (void) const =0 throw ()
virtual const vec_lump_type_t & quake::Bsp::getLumps (void) const =0 throw ()
 returns the list of lump types normally expected in BSP maps for this vendor.
virtual int quake::Bsp::getLumpObjectCount (eLumpType type)=0
 returns 0 if lump does not exist, or if lump exists but is empty.
virtual void quake::Bsp::startLumpIteration (eLumpType type)=0
 resets lump object iteration to the first of the specified type.
virtual const lump_object_t * quake::Bsp::getNextLumpObject (void)=0
 call this to iterate.
static smart_ptr< Bsp > quake::Bsp::load (smart_ptr< nstream::Stream > &stream)

Variables

int quake::lump_object_t::index
Dictionary quake::entity_t::dictionary
 key/value pairs
int32_t quake::face_t::texture
 index to texture path object
int32_t quake::face_t::effect
 index to effect (or -1)
int32_t quake::face_t::type
 face type (eFaceType, above)
int32_t quake::face_t::vertex
 index of first vertex
int32_t quake::face_t::nVertices
 number of vertices
int32_t quake::face_t::meshvert
 index of first mesh vertex
int32_t quake::face_t::nMeshverts
 number of mesh vertices
int32_t quake::face_t::lmIndex
 light map index
int32_t quake::face_t::lmStart [2]
 corner of this face's lightmap
int32_t quake::face_t::lmSize [2]
 size of this face's lightmap
point3d_t quake::face_t::origin
 origin of lightmap
point3d_t quake::face_t::lmVecs [2]
 lightmap s and t vectors
point3d_t quake::face_t::normal
 surface normal
int32_t quake::face_t::size [2]
 patch dimensions
int32_t quake::node_t::plane
 index to plane
int32_t quake::node_t::children [2]
 left, right child
int32_t quake::node_t::min [3]
 bounding box min xyz coords
int32_t quake::node_t::max [3]
 bounding box max xyz coords
int32_t quake::leaf_t::cluster
 cluster index
int32_t quake::leaf_t::area
 map area (for portals?)
int32_t quake::leaf_t::min [3]
 bounding box min xyz coords
int32_t quake::leaf_t::max [3]
 bounding box max xyz coords
int32_t quake::leaf_t::leafface
 first leaf face for leaf
int32_t quake::leaf_t::n_leaffaces
 number of faces
int32_t quake::leaf_t::leafbrush
 first leaf brush for leaf
int32_t quake::leaf_t::n_leafbrushes
 number of brushes
int32_t quake::leafface_t::face
 face index
int32_t quake::meshvert_t::vertex
 vertex index
point3d_t quake::plane_t::n
 plane normal
float quake::plane_t::d
 distance from origin along normal
char quake::texture_path_t::name [64]
 name
int32_t quake::texture_path_t::flags
int32_t quake::texture_path_t::contents
byte_t quake::color_t::green
byte_t quake::color_t::blue
byte_t quake::color_t::alpha
point3d_t quake::vertex_t::position
point3d_t quake::vertex_t::normal
float quake::vertex_t::texcoord [2][2]
color_t quake::vertex_t::color



enum  quake::eBspVendor {
  quake::eBspVendor_Id = 1,
  quake::eBspVendor_Valve = 2,
  quake::eBspVendor_Invalid = 0
}
enum  quake::eBspVersion {
  quake::eBspVersion_IdQuake3 = 1001,
  quake::eBspVersion_Invalid = 0
}
enum  quake::eLumpType {
  quake::eLump_Entities = 1,
  quake::eLump_Textures = 2,
  quake::eLump_Planes = 3,
  quake::eLump_Nodes = 4,
  quake::eLump_Leafs = 5,
  quake::eLump_Leaffaces = 6,
  quake::eLump_Leafbrushes = 7,
  quake::eLump_Models = 8,
  quake::eLump_Brushes = 9,
  quake::eLump_Brushsides = 10,
  quake::eLump_Vertices = 11,
  quake::eLump_Meshverts = 12,
  quake::eLump_Effects = 13,
  quake::eLump_Faces = 14,
  quake::eLump_Lightmaps = 15,
  quake::eLump_Lightvols = 16,
  quake::eLump_Visdata = 17,
  quake::eLump_Invalid = 0
}
 

types of lumps in BSP maps.

More...
const char * quake::getLumpName (eLumpType type)
 for debugging
int quake::readInt (std::istream &stream)
 read an integer. These are stored as little-endian in BSP files.
float quake::readFloat (std::istream &stream)
 read a float. These are stored as little-endian in BSP files.
point3d_t quake::readPoint3d (std::istream &stream)
 read a vector/point (helper function using readFloat() above)
typedef std::vector< eLumpType > quake::vec_lump_type_t

Detailed Description

This is a simple library for parsing Quake's BSP file format.

A BSP file contains a 3D map (BSP stands for Binary Space Partitioning). Typically the file contains several "lumps", and each lump contains a list of objects. Example lumps are textures, polygons, vertices, map entities, effects, etc.

How to use this parsing library: The library is designed to handle a wide range of BSP formats. In general, different vendors (game companies) have slightly different BSP formats. They'll use different lumps, and maybe even have slightly different objects in lumps with the same name.

This library will attempt to determine the vendor that created the BSP based on the BSP header, then allow the caller to iterate over available lumps, and likewise iterate over objects in each lump. You should write your code to expect some common lumps always (nodes, faces, textures, ...) but treat other vendor-specific lumps as optional. The more flexible you are, the more likely it is you can handle BSP files from multiple vendors.

Warning: do not use the objects defined here (texture_t, face_t, etc.) in your rendering code. These objects are defined for convenience and safety in parsing, not high-speed rendering. For instance, they have a high per-object overhead due to vtables. Just use these objects for parsing, and have your own simple structs to store thousands of vertices, for instance.

See these links for references on the BSP format:


Typedef Documentation

typedef std::vector<eLumpType> quake::vec_lump_type_t

Definition at line 98 of file bsp-version.h.


Enumeration Type Documentation

Enumerator:
eBspVendor_Id 

Id Software, magic = "IBSP".

eBspVendor_Valve 

Valve Softare, magic = "VBSP".

eBspVendor_Invalid 

Definition at line 48 of file bsp-version.h.

polygon face type

Enumerator:
eFace_Polygon 

standard polygon using vertices

eFace_Patch 

bezier patches

eFace_Mesh 

triangle mesh using meshverts

eFace_Billboard 

2D billboard, location only

eFace_Invalid 

Definition at line 109 of file bsp.h.

Enumerator:
eBspVersion_IdQuake3 
eBspVersion_Invalid 

Definition at line 58 of file bsp-version.h.

types of lumps in BSP maps.

There are many types of lumps, and no vendor seems to 100% agree on what they are! Some examples:

Enumerator:
eLump_Entities 

game objects in map

eLump_Textures 

surface descriptions

eLump_Planes 

planes used by map/BSP geometry

eLump_Nodes 

BSP tree nodes.

eLump_Leafs 

leaves in the BSP tree

eLump_Leaffaces 

list of face indices, one list per leaf

eLump_Leafbrushes 

list of brush indices, one list per leaf

eLump_Models 

rigid world models

eLump_Brushes 

convex polyhedra for collisions

eLump_Brushsides 

brush surfaces

eLump_Vertices 

vertices used to describe faces

eLump_Meshverts 

lists of offsets, one per mesh

eLump_Effects 

special map effects

eLump_Faces 

surface geometry

eLump_Lightmaps 

packed lightmap data

eLump_Lightvols 

local illumination data

eLump_Visdata 

cluster-cluster visibility map

eLump_Invalid 

Definition at line 74 of file bsp-version.h.


Function Documentation

virtual eLumpType quake::lump_object_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented in quake::entity_t, quake::face_t, quake::node_t, quake::leaf_t, quake::leafface_t, quake::meshvert_t, quake::plane_t, quake::texture_path_t, and quake::vertex_t.

Definition at line 97 of file bsp.h.

virtual int quake::lump_object_t::getIndex ( void   )  const throw () [inline, virtual, inherited]

returns the index of this object as stored in its lump

Definition at line 100 of file bsp.h.

eLumpType quake::entity_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 124 of file bsp.h.

eLumpType quake::face_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 135 of file bsp.h.

eLumpType quake::node_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 162 of file bsp.h.

eLumpType quake::leaf_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 176 of file bsp.h.

eLumpType quake::leafface_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 194 of file bsp.h.

eLumpType quake::meshvert_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 205 of file bsp.h.

eLumpType quake::plane_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 216 of file bsp.h.

eLumpType quake::texture_path_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 228 of file bsp.h.

void quake::texture_path_t::dump ( void   )  const throw () [inline, inherited]

Definition at line 229 of file bsp.h.

eLumpType quake::vertex_t::getType ( void   )  const throw () [inline, virtual, inherited]

what sort of lump object is this really? Can use this information to perform a dynamic cast to the correct leaf class.

Reimplemented from quake::lump_object_t.

Definition at line 256 of file bsp.h.

virtual BspVersion quake::Bsp::getVersion ( void   )  const throw () [pure virtual, inherited]
virtual const char* quake::Bsp::getName ( void   )  const throw () [pure virtual, inherited]
virtual const vec_lump_type_t& quake::Bsp::getLumps ( void   )  const throw () [pure virtual, inherited]

returns the list of lump types normally expected in BSP maps for this vendor.

Sometimes the lumps are empty or missing anyway.

virtual int quake::Bsp::getLumpObjectCount ( eLumpType  type  )  [pure virtual, inherited]

returns 0 if lump does not exist, or if lump exists but is empty.

returns -1 if lump exists but contains an unknown number of objects.

virtual void quake::Bsp::startLumpIteration ( eLumpType  type  )  [pure virtual, inherited]

resets lump object iteration to the first of the specified type.

Will silently fail if lump type does not exist.

virtual const lump_object_t* quake::Bsp::getNextLumpObject ( void   )  [pure virtual, inherited]

call this to iterate.

Returns NULL at end of iteration. Returns NULL immediately if lump does not exist or is empty.

static smart_ptr<Bsp> quake::Bsp::load ( smart_ptr< nstream::Stream > &  stream  )  [static, inherited]
const char * quake::getLumpName ( eLumpType  type  ) 

for debugging

int32_t quake::readInt ( std::istream &  in  ) 

read an integer. These are stored as little-endian in BSP files.

float quake::readFloat ( std::istream &  in  ) 

read a float. These are stored as little-endian in BSP files.

point3d_t quake::readPoint3d ( std::istream &  in  ) 

read a vector/point (helper function using readFloat() above)


Variable Documentation

int quake::lump_object_t::index [inherited]

Definition at line 103 of file bsp.h.

key/value pairs

Definition at line 127 of file bsp.h.

int32_t quake::face_t::texture [inherited]

index to texture path object

Definition at line 138 of file bsp.h.

int32_t quake::face_t::effect [inherited]

index to effect (or -1)

Definition at line 139 of file bsp.h.

int32_t quake::face_t::type [inherited]

face type (eFaceType, above)

Definition at line 140 of file bsp.h.

int32_t quake::face_t::vertex [inherited]

index of first vertex

Definition at line 141 of file bsp.h.

int32_t quake::face_t::nVertices [inherited]

number of vertices

Definition at line 142 of file bsp.h.

int32_t quake::face_t::meshvert [inherited]

index of first mesh vertex

Definition at line 143 of file bsp.h.

int32_t quake::face_t::nMeshverts [inherited]

number of mesh vertices

Definition at line 144 of file bsp.h.

int32_t quake::face_t::lmIndex [inherited]

light map index

Definition at line 145 of file bsp.h.

int32_t quake::face_t::lmStart[2] [inherited]

corner of this face's lightmap

Definition at line 146 of file bsp.h.

int32_t quake::face_t::lmSize[2] [inherited]

size of this face's lightmap

Definition at line 147 of file bsp.h.

origin of lightmap

Definition at line 148 of file bsp.h.

lightmap s and t vectors

Definition at line 149 of file bsp.h.

surface normal

Definition at line 150 of file bsp.h.

int32_t quake::face_t::size[2] [inherited]

patch dimensions

Definition at line 151 of file bsp.h.

int32_t quake::node_t::plane [inherited]

index to plane

Definition at line 165 of file bsp.h.

int32_t quake::node_t::children[2] [inherited]

left, right child

Definition at line 166 of file bsp.h.

int32_t quake::node_t::min[3] [inherited]

bounding box min xyz coords

Definition at line 167 of file bsp.h.

int32_t quake::node_t::max[3] [inherited]

bounding box max xyz coords

Definition at line 168 of file bsp.h.

int32_t quake::leaf_t::cluster [inherited]

cluster index

Definition at line 179 of file bsp.h.

int32_t quake::leaf_t::area [inherited]

map area (for portals?)

Definition at line 180 of file bsp.h.

int32_t quake::leaf_t::min[3] [inherited]

bounding box min xyz coords

Definition at line 181 of file bsp.h.

int32_t quake::leaf_t::max[3] [inherited]

bounding box max xyz coords

Definition at line 182 of file bsp.h.

int32_t quake::leaf_t::leafface [inherited]

first leaf face for leaf

Definition at line 183 of file bsp.h.

int32_t quake::leaf_t::n_leaffaces [inherited]

number of faces

Definition at line 184 of file bsp.h.

int32_t quake::leaf_t::leafbrush [inherited]

first leaf brush for leaf

Definition at line 185 of file bsp.h.

int32_t quake::leaf_t::n_leafbrushes [inherited]

number of brushes

Definition at line 186 of file bsp.h.

int32_t quake::leafface_t::face [inherited]

face index

Definition at line 197 of file bsp.h.

int32_t quake::meshvert_t::vertex [inherited]

vertex index

Definition at line 208 of file bsp.h.

plane normal

Definition at line 219 of file bsp.h.

float quake::plane_t::d [inherited]

distance from origin along normal

Definition at line 220 of file bsp.h.

char quake::texture_path_t::name[64] [inherited]

name

Definition at line 235 of file bsp.h.

int32_t quake::texture_path_t::flags [inherited]

Definition at line 236 of file bsp.h.

int32_t quake::texture_path_t::contents [inherited]

Definition at line 237 of file bsp.h.

Definition at line 246 of file bsp.h.

Definition at line 247 of file bsp.h.

Definition at line 248 of file bsp.h.

Definition at line 259 of file bsp.h.

Definition at line 260 of file bsp.h.

float quake::vertex_t::texcoord[2][2] [inherited]

Definition at line 261 of file bsp.h.

Definition at line 262 of file bsp.h.