#pragma once typedef struct // A Directory entry { long offset; // Offset to entry, in bytes, from start of file long size; // Size of entry in file, in bytes } dentry_t; typedef struct // The BSP file header { long version; // Model version, must be 0x17 (23). dentry_t entities; // List of Entities. dentry_t planes; // Map Planes. // numplanes = size/sizeof(plane_t) dentry_t miptex; // Wall Textures. dentry_t vertices; // Map Vertices. // numvertices = size/sizeof(vertex_t) dentry_t visilist; // Leaves Visibility lists. dentry_t nodes; // BSP Nodes. // numnodes = size/sizeof(node_t) dentry_t texinfo; // Texture Info for faces. // numtexinfo = size/sizeof(texinfo_t) dentry_t faces; // Faces of each surface. // numfaces = size/sizeof(face_t) dentry_t lightmaps; // Wall Light Maps. dentry_t clipnodes; // clip nodes, for Models. // numclips = size/sizeof(clipnode_t) dentry_t leaves; // BSP Leaves. // numlaves = size/sizeof(leaf_t) dentry_t lface; // List of Faces. dentry_t edges; // Edges of faces. // numedges = Size/sizeof(edge_t) dentry_t ledges; // List of Edges. dentry_t models; // List of Models. // nummodels = Size/sizeof(model_t) } dheader_t; typedef float scalar_t; // Scalar value, typedef struct Vec3 // Vector or Position { scalar_t x; // horizontal scalar_t y; // horizontal scalar_t z; // vertical Vec3() : x(0), y(0), z(0) { } Vec3(float x, float y, float z) : x(x), y(y), z(z) { } } vec3_t; typedef struct { vec3_t normal; // Vector orthogonal to plane (Nx,Ny,Nz) // with Nx2+Ny2+Nz2 = 1 scalar_t dist; // Offset to plane, along the normal vector. // Distance from (0,0,0) to the plane long type; // Type of plane, depending on normal vector. } plane_t; typedef struct BoundBox // Bounding Box, Float values { vec3_t min; // minimum values of X,Y,Z vec3_t max; // maximum values of X,Y,Z BoundBox() { } void init(vec3_t point) { min = point; max = point; } void includePoint(vec3_t point) { if (point.x < min.x) min.x = point.x; if (point.y < min.y) min.y = point.y; if (point.z < min.z) min.z = point.z; if (point.x > max.x) max.x = point.x; if (point.y > max.y) max.y = point.y; if (point.z > max.z) max.z = point.z; } } boundbox_t; typedef struct // Bounding Box, Short values { short min[3]; // minimum values of X,Y,Z short max[3]; // maximum values of X,Y,Z } bboxshort_t; typedef struct // Mip texture list header { long numtex; // Number of textures in Mip Texture list long *offset; // Offset to each of the individual texture } mipheader_t; // from the beginning of mipheader_t typedef struct // Mip Texture { char name[16]; // Name of the texture. unsigned long width; // width of picture, must be a multiple of 8 unsigned long height; // height of picture, must be a multiple of 8 unsigned long offset1; // offset to u_char Pix[width * height] unsigned long offset2; // offset to u_char Pix[width/2 * height/2] unsigned long offset4; // offset to u_char Pix[width/4 * height/4] unsigned long offset8; // offset to u_char Pix[width/8 * height/8] } miptex_t; typedef struct Vertex { float X; // X,Y,Z coordinates of the vertex float Y; // usually some integer value float Z; // but coded in floating point vec3_t toVec() const { return vec3_t(X, Y, Z); } } vertex_t; typedef struct { unsigned short vertex0; // index of the start vertex // must be in [0,numvertices[ unsigned short vertex1; // index of the end vertex // must be in [0,numvertices[ } edge_t; typedef struct { unsigned short plane_id; // The plane in which the face lies // must be in [0,numplanes[ unsigned short side; // 0 if in front of the plane, 1 if behind the plane long ledge_id; // first edge in the List of edges // must be in [0,numledges[ unsigned short ledge_num; // number of edges in the List of edges unsigned short texinfo_id; // index of the Texture info the face is part of // must be in [0,numtexinfos[ unsigned char typelight; // type of lighting, for the face unsigned char baselight; // from 0xFF (dark) to 0 (bright) unsigned char light[2]; // two additional light models long lightmap; // Pointer inside the general light map, or -1 // this define the start of the face light map } face_t; typedef struct { long plane_id; // The plane that splits the node // must be in [0,numplanes[ short front; // If bit15==0, index of Front child node // If bit15==1, ~front = index of child leaf short back; // If bit15==0, id of Back child node // If bit15==1, ~back = id of child leaf bboxshort_t box; // Bounding box of node and all childs unsigned short face_id; // Index of first Polygons in the node unsigned short face_num; // Number of faces in the node } node_t; typedef struct { long type; // Special type of leaf long vislist; // Beginning of visibility lists // must be -1 or in [0,numvislist[ bboxshort_t bound; // Bounding box of the leaf unsigned short lface_id; // First item of the list of faces // must be in [0,numlfaces[ unsigned short lface_num; // Number of faces in the leaf unsigned char sndwater; // level of the four ambient sounds: unsigned char sndsky; // 0 is no sound unsigned char sndslime; // 0xFF is maximum volume unsigned char sndlava; // } dleaf_t; typedef struct { const char* name; dheader_t header; mipheader_t mipheader; miptex_t* miptexes; unsigned char** textures; int numPlanes; plane_t* planes; int numVertices; vertex_t* vertices; int numEdges; edge_t* edges; int edgeListLength; int* edgeList; int numFaces; face_t* faces; int faceListLength; unsigned short* faceList; int visListLength; unsigned char *visList; int numNodes; node_t* nodes; int numLeaves; dleaf_t* leaves; int entitiesLength; char* entities; int lightmapLength; unsigned char* lightmap; } world_t;