common: make bspfile.h use stdint types, reformat the file

This commit is contained in:
Alibek Omarov
2025-11-22 13:40:11 +05:00
parent 3fc59104f3
commit 86dfbc3e34

View File

@@ -12,10 +12,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
*/ */
#ifndef BSPFILE_H #ifndef BSPFILE_H
#define BSPFILE_H #define BSPFILE_H
#include <stdint.h>
/* /*
============================================================================== ==============================================================================
@@ -26,288 +27,294 @@ BRUSH MODELS
*/ */
// header // header
#define Q1BSP_VERSION 29 // quake1 regular version (beta is 28) #define Q1BSP_VERSION 29 // quake1 regular version (beta is 28)
#define HLBSP_VERSION 30 // half-life regular version #define HLBSP_VERSION 30 // half-life regular version
#define QBSP2_VERSION (('B' << 0) | ('S' << 8) | ('P' << 16) | ('2'<<24)) #define QBSP2_VERSION (( 'B' << 0 ) | ('S' << 8 ) | ( 'P' << 16 ) | ( '2' << 24 ))
#define IDEXTRAHEADER (('H'<<24)+('S'<<16)+('A'<<8)+'X') // little-endian "XASH" #define IDEXTRAHEADER (( 'X' << 0 ) | ('A' << 8 ) | ( 'S' << 16 ) | ( 'H' << 24 ))
#define EXTRA_VERSION 4 // ver. 1 was occupied by old versions of XashXT, ver. 2 was occupied by old vesrions of P2:savior #define EXTRA_VERSION 4 // ver. 1 was occupied by old versions of XashXT
// ver. 3 was occupied by experimental versions of P2:savior change fmt // ver. 2 was occupied by old vesrions of P2:savior
// ver. 3 was occupied by experimental versions of P2:savior change fmt
#define DELUXEMAP_VERSION 1 #define DELUXEMAP_VERSION 1
#define IDDELUXEMAPHEADER (('T'<<24)+('I'<<16)+('L'<<8)+'Q') // little-endian "QLIT" #define IDDELUXEMAPHEADER (( 'Q' << 0 ) | ('L' << 8 ) | ( 'I' << 16 ) | ( 'T' << 24 ))
// worldcraft predefined angles // worldcraft predefined angles
#define ANGLE_UP -1 #define ANGLE_UP -1
#define ANGLE_DOWN -2 #define ANGLE_DOWN -2
// bmodel limits // bmodel limits
#define MAX_MAP_HULLS 4 // MAX_HULLS #define MAX_MAP_HULLS 4 // MAX_HULLS
#define SURF_PLANEBACK BIT( 1 ) // plane should be negated #define SURF_PLANEBACK BIT( 1 ) // plane should be negated
#define SURF_DRAWSKY BIT( 2 ) // sky surface #define SURF_DRAWSKY BIT( 2 ) // sky surface
#define SURF_DRAWTURB_QUADS BIT( 3 ) // all subidivided polygons are quads #define SURF_DRAWTURB_QUADS BIT( 3 ) // all subidivided polygons are quads
#define SURF_DRAWTURB BIT( 4 ) // warp surface #define SURF_DRAWTURB BIT( 4 ) // warp surface
#define SURF_DRAWTILED BIT( 5 ) // face without lighmap #define SURF_DRAWTILED BIT( 5 ) // face without lighmap
#define SURF_CONVEYOR BIT( 6 ) // scrolled texture (was SURF_DRAWBACKGROUND) #define SURF_CONVEYOR BIT( 6 ) // scrolled texture (was SURF_DRAWBACKGROUND)
#define SURF_UNDERWATER BIT( 7 ) // caustics #define SURF_UNDERWATER BIT( 7 ) // caustics
#define SURF_TRANSPARENT BIT( 8 ) // it's a transparent texture (was SURF_DONTWARP) #define SURF_TRANSPARENT BIT( 8 ) // it's a transparent texture (was SURF_DONTWARP)
// lightstyle management // lightstyle management
#define LM_STYLES 4 // MAXLIGHTMAPS #define LM_STYLES 4 // MAXLIGHTMAPS
#define LS_NORMAL 0x00 #define LS_NORMAL 0x00
#define LS_UNUSED 0xFE #define LS_UNUSED 0xFE
#define LS_NONE 0xFF #define LS_NONE 0xFF
#define MAX_MAP_CLIPNODES_HLBSP 32767 #define MAX_MAP_CLIPNODES_HLBSP 32767
#define MAX_MAP_CLIPNODES_BSP2 524288 #define MAX_MAP_CLIPNODES_BSP2 524288
// these limis not using by modelloader but only for displaying 'mapstats' correctly // these limis not using by modelloader but only for displaying 'mapstats' correctly
#define MAX_MAP_MODELS 2048 // embedded models #define MAX_MAP_MODELS 2048 // embedded models
#define MAX_MAP_ENTSTRING 0x200000 // 2 Mb should be enough #define MAX_MAP_ENTSTRING 0x200000 // 2 Mb should be enough
#define MAX_MAP_PLANES 131072 // can be increased without problems #define MAX_MAP_PLANES 131072 // can be increased without problems
#define MAX_MAP_NODES 262144 // can be increased without problems #define MAX_MAP_NODES 262144 // can be increased without problems
#define MAX_MAP_CLIPNODES MAX_MAP_CLIPNODES_BSP2 // can be increased without problems #define MAX_MAP_CLIPNODES MAX_MAP_CLIPNODES_BSP2 // can be increased without problems
#define MAX_MAP_LEAFS 131072 // CRITICAL STUFF to run ad_sepulcher!!! #define MAX_MAP_LEAFS 131072 // CRITICAL STUFF to run ad_sepulcher!!!
#define MAX_MAP_VERTS 524288 // can be increased without problems #define MAX_MAP_VERTS 524288 // can be increased without problems
#define MAX_MAP_FACES 262144 // can be increased without problems #define MAX_MAP_FACES 262144 // can be increased without problems
#define MAX_MAP_MARKSURFACES 524288 // can be increased without problems #define MAX_MAP_MARKSURFACES 524288 // can be increased without problems
#define MAX_MAP_ENTITIES 8192 // network limit #define MAX_MAP_ENTITIES 8192 // network limit
#define MAX_MAP_TEXINFO MAX_MAP_FACES // in theory each face may have personal texinfo #define MAX_MAP_TEXINFO MAX_MAP_FACES // in theory each face may have personal texinfo
#define MAX_MAP_EDGES 0x100000 // can be increased but not needs #define MAX_MAP_EDGES 0x100000 // can be increased but not needed
#define MAX_MAP_SURFEDGES 0x200000 // can be increased but not needs #define MAX_MAP_SURFEDGES 0x200000 // can be increased but not needed
#define MAX_MAP_TEXTURES 2048 // can be increased but not needs #define MAX_MAP_TEXTURES 2048 // can be increased but not needed
#define MAX_MAP_MIPTEX 0x2000000 // 32 Mb internal textures data #define MAX_MAP_MIPTEX 0x2000000 // 32 Mb internal textures data
#define MAX_MAP_LIGHTING 0x2000000 // 32 Mb lightmap raw data (can contain deluxemaps) #define MAX_MAP_LIGHTING 0x2000000 // 32 Mb lightmap raw data (can contain deluxemaps)
#define MAX_MAP_VISIBILITY 0x1000000 // 16 Mb visdata #define MAX_MAP_VISIBILITY 0x1000000 // 16 Mb visdata
#define MAX_MAP_FACEINFO 8192 // can be increased but not needs #define MAX_MAP_FACEINFO 8192 // can be increased but not needed
// quake lump ordering // quake lump ordering
#define LUMP_ENTITIES 0 enum
#define LUMP_PLANES 1 {
#define LUMP_TEXTURES 2 // internal textures LUMP_ENTITIES = 0,
#define LUMP_VERTEXES 3 LUMP_PLANES = 1,
#define LUMP_VISIBILITY 4 LUMP_TEXTURES = 2, // internal textures
#define LUMP_NODES 5 LUMP_VERTEXES = 3,
#define LUMP_TEXINFO 6 LUMP_VISIBILITY = 4,
#define LUMP_FACES 7 LUMP_NODES = 5,
#define LUMP_LIGHTING 8 LUMP_TEXINFO = 6,
#define LUMP_CLIPNODES 9 LUMP_FACES = 7,
#define LUMP_LEAFS 10 LUMP_LIGHTING = 8,
#define LUMP_MARKSURFACES 11 LUMP_CLIPNODES = 9,
#define LUMP_EDGES 12 LUMP_LEAFS = 10,
#define LUMP_SURFEDGES 13 LUMP_MARKSURFACES = 11,
#define LUMP_MODELS 14 // internal submodels LUMP_EDGES = 12,
#define HEADER_LUMPS 15 LUMP_SURFEDGES = 13,
LUMP_MODELS = 14, // internal submodels
HEADER_LUMPS = 15,
};
// extra lump ordering // extra lump ordering
#define LUMP_LIGHTVECS 0 // deluxemap data enum
#define LUMP_FACEINFO 1 // landscape and lightmap resolution info {
#define LUMP_CUBEMAPS 2 // cubemap description LUMP_LIGHTVECS = 0, // deluxemap data
#define LUMP_VERTNORMALS 3 // phong shaded vertex normals LUMP_FACEINFO = 1, // landscape and lightmap resolution info
#define LUMP_LEAF_LIGHTING 4 // store vertex lighting for statics LUMP_CUBEMAPS = 2, // cubemap description
#define LUMP_WORLDLIGHTS 5 // list of all the virtual and real lights (used to relight models in-game) LUMP_VERTNORMALS = 3, // phong shaded vertex normals
#define LUMP_COLLISION 6 // physics engine collision hull dump (userdata) LUMP_LEAF_LIGHTING = 4, // store vertex lighting for statics
#define LUMP_AINODEGRAPH 7 // node graph that stored into the bsp (userdata) LUMP_WORLDLIGHTS = 5, // list of all the virtual and real lights (used to relight models in-game)
#define LUMP_SHADOWMAP 8 // contains shadow map for direct light LUMP_COLLISION = 6, // physics engine collision hull dump (userdata)
#define LUMP_VERTEX_LIGHT 9 // store vertex lighting for statics LUMP_AINODEGRAPH = 7, // node graph that stored into the bsp (userdata)
#define LUMP_UNUSED0 10 // one lump reserved for me LUMP_SHADOWMAP = 8, // contains shadow map for direct light
#define LUMP_UNUSED1 11 // one lump reserved for me LUMP_VERTEX_LIGHT = 9, // store vertex lighting for statics
#define EXTRA_LUMPS 12 // count of the extra lumps LUMP_UNUSED0 = 10, // one lump reserved for me
LUMP_UNUSED1 = 11, // one lump reserved for me
EXTRA_LUMPS = 12, // count of the extra lumps
};
// texture flags // texture flags
#define TEX_SPECIAL BIT( 0 ) // sky or slime, no lightmap or 256 subdivision #define TEX_SPECIAL BIT( 0 ) // sky or slime, no lightmap or 256 subdivision
#define TEX_WORLD_LUXELS BIT( 1 ) // alternative lightmap matrix will be used (luxels per world units instead of luxels per texels) #define TEX_WORLD_LUXELS BIT( 1 ) // alternative lightmap matrix will be used (luxels per world units instead of luxels per texels)
#define TEX_AXIAL_LUXELS BIT( 2 ) // force world luxels to axial positive scales #define TEX_AXIAL_LUXELS BIT( 2 ) // force world luxels to axial positive scales
#define TEX_EXTRA_LIGHTMAP BIT( 3 ) // bsp31 legacy - using 8 texels per luxel instead of 16 texels per luxel #define TEX_EXTRA_LIGHTMAP BIT( 3 ) // bsp31 legacy - using 8 texels per luxel instead of 16 texels per luxel
#define TEX_SCROLL BIT( 6 ) // Doom special FX #define TEX_SCROLL BIT( 6 ) // Doom special FX
#define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA ) #define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA )
// ambient sound types // ambient sound types
enum enum
{ {
AMBIENT_WATER = 0, // waterfall AMBIENT_WATER = 0, // waterfall
AMBIENT_SKY, // wind AMBIENT_SKY, // wind
AMBIENT_SLIME, // never used in quake AMBIENT_SLIME, // never used in quake
AMBIENT_LAVA, // never used in quake AMBIENT_LAVA, // never used in quake
NUM_AMBIENTS, // automatic ambient sounds NUM_AMBIENTS, // automatic ambient sounds
}; };
// //
// BSP File Structures // BSP File Structures
// //
typedef struct typedef struct
{ {
int fileofs; int32_t fileofs;
int filelen; int32_t filelen;
} dlump_t; } dlump_t;
typedef struct typedef struct
{ {
int version; int32_t version;
dlump_t lumps[HEADER_LUMPS]; dlump_t lumps[HEADER_LUMPS];
} dheader_t; } dheader_t;
typedef struct typedef struct
{ {
int id; // must be little endian XASH int32_t id; // must be little endian XASH
int version; int32_t version;
dlump_t lumps[EXTRA_LUMPS]; dlump_t lumps[EXTRA_LUMPS];
} dextrahdr_t; } dextrahdr_t;
typedef struct typedef struct
{ {
vec3_t mins; vec3_t mins;
vec3_t maxs; vec3_t maxs;
vec3_t origin; // for sounds or lights vec3_t origin; // for sounds or lights
int headnode[MAX_MAP_HULLS]; int32_t headnode[MAX_MAP_HULLS];
int visleafs; // not including the solid leaf 0 int32_t visleafs; // not including the solid leaf 0
int firstface; int32_t firstface;
int numfaces; int32_t numfaces;
} dmodel_t; } dmodel_t;
typedef struct typedef struct
{ {
int nummiptex; int32_t nummiptex;
int dataofs[4]; // [nummiptex] int32_t dataofs[4]; // [nummiptex]
} dmiptexlump_t; } dmiptexlump_t;
typedef struct typedef struct
{ {
vec3_t point; vec3_t point;
} dvertex_t; } dvertex_t;
typedef struct typedef struct
{ {
vec3_t normal; vec3_t normal;
float dist; float dist;
int type; // PLANE_X - PLANE_ANYZ ? int32_t type; // PLANE_X - PLANE_ANYZ ?
} dplane_t; } dplane_t;
typedef struct typedef struct
{ {
int planenum; int32_t planenum;
short children[2]; // negative numbers are -(leafs + 1), not nodes int16_t children[2]; // negative numbers are -(leafs + 1), not nodes
short mins[3]; // for sphere culling int16_t mins[3]; // for sphere culling
short maxs[3]; int16_t maxs[3];
word firstface; uint16_t firstface;
word numfaces; // counting both sides uint16_t numfaces; // counting both sides
} dnode_t; } dnode_t;
typedef struct typedef struct
{ {
int planenum; int32_t planenum;
int children[2]; // negative numbers are -(leafs+1), not nodes int32_t children[2]; // negative numbers are -(leafs+1), not nodes
float mins[3]; // for sphere culling float mins[3]; // for sphere culling
float maxs[3]; float maxs[3];
int firstface; int32_t firstface;
int numfaces; // counting both sides int32_t numfaces; // counting both sides
} dnode32_t; } dnode32_t;
// leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas // leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
// all other leafs need visibility info // all other leafs need visibility info
typedef struct typedef struct
{ {
int contents; int32_t contents;
int visofs; // -1 = no visibility info int32_t visofs; // -1 = no visibility info
short mins[3]; // for frustum culling int16_t mins[3]; // for frustum culling
short maxs[3]; int16_t maxs[3];
word firstmarksurface; uint16_t firstmarksurface;
word nummarksurfaces; uint16_t nummarksurfaces;
// automatic ambient sounds // automatic ambient sounds
byte ambient_level[NUM_AMBIENTS]; // ambient sound level (0 - 255) uint8_t ambient_level[NUM_AMBIENTS]; // ambient sound level (0 - 255)
} dleaf_t; } dleaf_t;
typedef struct typedef struct
{ {
int contents; int32_t contents;
int visofs; // -1 = no visibility info int32_t visofs; // -1 = no visibility info
float mins[3]; // for frustum culling float mins[3]; // for frustum culling
float maxs[3]; float maxs[3];
int firstmarksurface; int32_t firstmarksurface;
int nummarksurfaces; int32_t nummarksurfaces;
byte ambient_level[NUM_AMBIENTS]; uint8_t ambient_level[NUM_AMBIENTS];
} dleaf32_t; } dleaf32_t;
typedef struct typedef struct
{ {
int planenum; int32_t planenum;
short children[2]; // negative numbers are contents int16_t children[2]; // negative numbers are contents
} dclipnode_t; } dclipnode_t;
typedef struct typedef struct
{ {
int planenum; int32_t planenum;
int children[2]; // negative numbers are contents int32_t children[2]; // negative numbers are contents
} dclipnode32_t; } dclipnode32_t;
typedef struct typedef struct
{ {
float vecs[2][4]; // texmatrix [s/t][xyz offset] float vecs[2][4]; // texmatrix [s/t][xyz offset]
int miptex; int32_t miptex;
short flags; int16_t flags;
short faceinfo; // -1 no face info otherwise dfaceinfo_t int16_t faceinfo; // -1 no face info otherwise dfaceinfo_t
} dtexinfo_t; } dtexinfo_t;
typedef struct typedef struct
{ {
char landname[16]; // name of decsription in mapname_land.txt char landname[16]; // name of decsription in mapname_land.txt
unsigned short texture_step; // default is 16, pixels\luxels ratio uint16_t texture_step; // default is 16, pixels\luxels ratio
unsigned short max_extent; // default is 16, subdivision step ((texture_step * max_extent) - texture_step) uint16_t max_extent; // default is 16, subdivision step ((texture_step * max_extent) - texture_step)
short groupid; // to determine equal landscapes from various groups, -1 - no group int16_t groupid; // to determine equal landscapes from various groups, -1 - no group
} dfaceinfo_t; } dfaceinfo_t;
typedef word dmarkface_t; // leaf marksurfaces indexes typedef uint16_t dmarkface_t; // leaf marksurfaces indexes
typedef int dmarkface32_t; // leaf marksurfaces indexes typedef int32_t dmarkface32_t; // leaf marksurfaces indexes
typedef int dsurfedge_t; // map surfedges typedef int32_t dsurfedge_t; // map surfedges
// NOTE: that edge 0 is never used, because negative edge nums // NOTE: that edge 0 is never used, because negative edge nums
// are used for counterclockwise use of the edge in a face // are used for counterclockwise use of the edge in a face
typedef struct typedef struct
{ {
word v[2]; // vertex numbers uint16_t v[2]; // vertex numbers
} dedge_t; } dedge_t;
typedef struct typedef struct
{ {
int v[2]; // vertex numbers int32_t v[2]; // vertex numbers
} dedge32_t; } dedge32_t;
typedef struct typedef struct
{ {
word planenum; uint16_t planenum;
short side; int16_t side;
int firstedge; // we must support > 64k edges int32_t firstedge; // we must support > 64k edges
short numedges; int16_t numedges;
short texinfo; int16_t texinfo;
// lighting info // lighting info
byte styles[LM_STYLES]; uint8_t styles[LM_STYLES];
int lightofs; // start of [numstyles*surfsize] samples int32_t lightofs; // start of [numstyles*surfsize] samples
} dface_t; } dface_t;
typedef struct typedef struct
{ {
int planenum; int32_t planenum;
int side; int32_t side;
int firstedge; // we must support > 64k edges int32_t firstedge; // we must support > 64k edges
int numedges; int32_t numedges;
int texinfo; int32_t texinfo;
// lighting info // lighting info
byte styles[LM_STYLES]; uint8_t styles[LM_STYLES];
int lightofs; // start of [numstyles*surfsize] samples int32_t lightofs; // start of [numstyles*surfsize] samples
} dface32_t; } dface32_t;
#endif//BSPFILE_H #endif // BSPFILE_H