Make the bsp disk data structures type size independent.

However, this assumes float is always 32 bits.

Also use size_t for the *size fields in bsp_t and clean up the mess.
This commit is contained in:
Bill Currie 2010-08-22 08:40:31 +09:00
parent 8808eba3ff
commit f4042c5b91
4 changed files with 69 additions and 69 deletions

View file

@ -75,8 +75,8 @@
#define TOOLVERSION 2
typedef struct lump_s {
int fileofs;
int filelen;
int32_t fileofs;
int32_t filelen;
} lump_t;
#define LUMP_ENTITIES 0
@ -99,26 +99,26 @@ typedef struct lump_s {
typedef struct dmodel_s {
float mins[3], maxs[3];
float origin[3];
int headnode[MAX_MAP_HULLS];
int visleafs; // not including the solid leaf 0
int firstface, numfaces;
int32_t headnode[MAX_MAP_HULLS];
int32_t visleafs; // not including the solid leaf 0
int32_t firstface, numfaces;
} dmodel_t;
typedef struct dheader_s {
int version;
int32_t version;
lump_t lumps[HEADER_LUMPS];
} dheader_t;
typedef struct dmiptexlump_s {
int nummiptex;
int dataofs[4]; // [nummiptex]
int32_t nummiptex;
int32_t dataofs[4]; // [nummiptex]
} dmiptexlump_t;
#define MIPLEVELS 4
typedef struct miptex_s {
char name[16];
unsigned int width, height;
unsigned int offsets[MIPLEVELS]; // four mip maps stored
uint32_t width, height;
uint32_t offsets[MIPLEVELS]; // four mip maps stored
} miptex_t;
@ -140,7 +140,7 @@ typedef struct dvertex_s {
typedef struct dplane_s {
float normal[3];
float dist;
int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
int32_t type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
} dplane_t;
#define CONTENTS_EMPTY -1
@ -162,45 +162,45 @@ typedef struct dplane_s {
// !!! if this is changed, it must be changed in asm_i386.h too !!!
typedef struct dnode_s {
int planenum;
short children[2]; // negative numbers are -(leafs+1), not nodes
short mins[3]; // for sphere culling
short maxs[3];
unsigned short firstface;
unsigned short numfaces; // counting both sides
int32_t planenum;
int16_t children[2]; // negative numbers are -(leafs+1), not nodes
int16_t mins[3]; // for sphere culling
int16_t maxs[3];
uint16_t firstface;
uint16_t numfaces; // counting both sides
} dnode_t;
typedef struct dclipnode_s {
int planenum;
short children[2]; // negative numbers are contents
int32_t planenum;
int16_t children[2]; // negative numbers are contents
} dclipnode_t;
typedef struct texinfo_s {
float vecs[2][4]; // [s/t][xyz offset]
int miptex;
int flags;
int32_t miptex;
int32_t flags;
} texinfo_t;
#define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision
// note that edge 0 is never used, because negative edge nums are used for
// counterclockwise use of the edge in a face
typedef struct dedge_s {
unsigned short v[2]; // vertex numbers
uint16_t v[2]; // vertex numbers
} dedge_t;
#define MAXLIGHTMAPS 4
typedef struct dface_s {
short planenum;
short side;
int16_t planenum;
int16_t side;
int firstedge; // we must support > 64k edges
short numedges;
short texinfo;
int32_t firstedge; // we must support > 64k edges
int16_t numedges;
int16_t texinfo;
// lighting info
byte styles[MAXLIGHTMAPS];
int lightofs; // start of [numstyles*surfsize] samples
int32_t lightofs; // start of [numstyles*surfsize] samples
} dface_t;
@ -214,14 +214,14 @@ typedef struct dface_s {
// leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
// all other leafs need visibility info
typedef struct dleaf_s {
int contents;
int visofs; // -1 = no visibility info
int32_t contents;
int32_t visofs; // -1 = no visibility info
short mins[3]; // for frustum culling
short maxs[3];
int16_t mins[3]; // for frustum culling
int16_t maxs[3];
unsigned short firstmarksurface;
unsigned short nummarksurfaces;
uint16_t firstmarksurface;
uint16_t nummarksurfaces;
byte ambient_level[NUM_AMBIENTS];
} dleaf_t;
@ -232,16 +232,16 @@ typedef struct bsp_s {
int nummodels;
dmodel_t *models;
int visdatasize;
size_t visdatasize;
byte *visdata;
int lightdatasize;
size_t lightdatasize;
byte *lightdata;
int texdatasize;
size_t texdatasize;
byte *texdata; // (dmiptexlump_t)
int entdatasize;
size_t entdatasize;
char *entdata;
int numleafs;
@ -269,14 +269,14 @@ typedef struct bsp_s {
dedge_t *edges;
int nummarksurfaces;
unsigned short *marksurfaces;
uint16_t *marksurfaces;
int numsurfedges;
int *surfedges;
int32_t *surfedges;
} bsp_t;
bsp_t *LoadBSPMem (void *mem, int size);
bsp_t *LoadBSPFile (QFile *file, int size);
bsp_t *LoadBSPMem (void *mem, size_t size);
bsp_t *LoadBSPFile (QFile *file, size_t size);
void WriteBSPFile (bsp_t *bsp, QFile *file);
bsp_t *BSP_New (void);
void BSP_AddPlane (bsp_t *bsp, dplane_t *plane);
@ -286,13 +286,13 @@ void BSP_AddNode (bsp_t *bsp, dnode_t *node);
void BSP_AddTexinfo (bsp_t *bsp, texinfo_t *texinfo);
void BSP_AddFace (bsp_t *bsp, dface_t *face);
void BSP_AddClipnode (bsp_t *bsp, dclipnode_t *clipnode);
void BSP_AddMarkSurface (bsp_t *bsp, unsigned short marksurface);
void BSP_AddMarkSurface (bsp_t *bsp, int marksurface);
void BSP_AddSurfEdge (bsp_t *bsp, int surfedge);
void BSP_AddEdge (bsp_t *bsp, dedge_t *edge);
void BSP_AddModel (bsp_t *bsp, dmodel_t *model);
void BSP_AddLighting (bsp_t *bsp, byte *lightdata, int lightdatasize);
void BSP_AddVisibility (bsp_t *bsp, byte *visdata, int visdatasize);
void BSP_AddEntities (bsp_t *bsp, char *entdata, int entdatasize);
void BSP_AddTextures (bsp_t *bsp, byte *texdata, int texdatasize);
void BSP_AddLighting (bsp_t *bsp, byte *lightdata, size_t lightdatasize);
void BSP_AddVisibility (bsp_t *bsp, byte *visdata, size_t visdatasize);
void BSP_AddEntities (bsp_t *bsp, char *entdata, size_t entdatasize);
void BSP_AddTextures (bsp_t *bsp, byte *texdata, size_t texdatasize);
#endif // __bspfile_h_

View file

@ -49,11 +49,11 @@ static __attribute__ ((used)) const char rcsid[] =
static void
swap_bsp (bsp_t *bsp, int todisk)
{
int c, i, j;
dmiptexlump_t *mtl;
dmodel_t *d;
int c, i, j;
dmiptexlump_t *mtl;
dmodel_t *d;
// models
// models
for (i=0 ; i<bsp->nummodels ; i++) {
d = &bsp->models[i];
@ -157,13 +157,13 @@ swap_bsp (bsp_t *bsp, int todisk)
// marksurfaces
for (i=0 ; i<bsp->nummarksurfaces ; i++) {
unsigned short *marksurface = &bsp->marksurfaces[i];
uint16_t *marksurface = &bsp->marksurfaces[i];
*marksurface = LittleShort (*marksurface);
}
// surfedges
for (i=0 ; i<bsp->numsurfedges ; i++) {
int *surfedge = &bsp->surfedges[i];
int32_t *surfedge = &bsp->surfedges[i];
*surfedge = LittleLong (*surfedge);
}
@ -176,7 +176,7 @@ swap_bsp (bsp_t *bsp, int todisk)
}
bsp_t *
LoadBSPMem (void *mem, int size)
LoadBSPMem (void *mem, size_t size)
{
dheader_t *header = mem;
bsp_t *bsp;
@ -235,7 +235,7 @@ do { \
}
VISIBLE bsp_t *
LoadBSPFile (QFile *file, int size)
LoadBSPFile (QFile *file, size_t size)
{
void *buf;
bsp_t *bsp;
@ -254,8 +254,8 @@ LoadBSPFile (QFile *file, int size)
*/
VISIBLE void
WriteBSPFile (bsp_t *bsp, QFile *file)
{
int size;
{
size_t size;
dheader_t *header;
byte *data;
@ -275,8 +275,8 @@ WriteBSPFile (bsp_t *bsp, QFile *file)
size += ROUND (bsp->numfaces * sizeof (dface_t));
size += ROUND (bsp->numclipnodes * sizeof (dclipnode_t));
size += ROUND (bsp->numedges * sizeof (dedge_t));
size += ROUND (bsp->nummarksurfaces * sizeof (unsigned short));
size += ROUND (bsp->numsurfedges * sizeof (int));
size += ROUND (bsp->nummarksurfaces * sizeof (uint16_t));
size += ROUND (bsp->numsurfedges * sizeof (uint32_t));
header = malloc (size);
memset (header, 0, size);
@ -390,11 +390,11 @@ BSP_AddClipnode (bsp_t *bsp, dclipnode_t *clipnode)
}
VISIBLE void
BSP_AddMarkSurface (bsp_t *bsp, unsigned short marksurface)
BSP_AddMarkSurface (bsp_t *bsp, int marksurface)
{
bsp->marksurfaces = realloc (bsp->marksurfaces,
(bsp->nummarksurfaces + 1)
* sizeof (unsigned short));
* sizeof (uint16_t));
bsp->marksurfaces[bsp->nummarksurfaces++] = marksurface;
}
@ -402,7 +402,7 @@ VISIBLE void
BSP_AddSurfEdge (bsp_t *bsp, int surfedge)
{
bsp->surfedges = realloc (bsp->surfedges,
(bsp->numsurfedges + 1) * sizeof (int));
(bsp->numsurfedges + 1) * sizeof (int32_t));
bsp->surfedges[bsp->numsurfedges++] = surfedge;
}
@ -423,7 +423,7 @@ BSP_AddModel (bsp_t *bsp, dmodel_t *model)
}
VISIBLE void
BSP_AddLighting (bsp_t *bsp, byte *lightdata, int lightdatasize)
BSP_AddLighting (bsp_t *bsp, byte *lightdata, size_t lightdatasize)
{
bsp->lightdatasize = lightdatasize;
bsp->lightdata = malloc (lightdatasize);
@ -431,7 +431,7 @@ BSP_AddLighting (bsp_t *bsp, byte *lightdata, int lightdatasize)
}
VISIBLE void
BSP_AddVisibility (bsp_t *bsp, byte *visdata, int visdatasize)
BSP_AddVisibility (bsp_t *bsp, byte *visdata, size_t visdatasize)
{
bsp->visdatasize = visdatasize;
bsp->visdata = malloc (visdatasize);
@ -439,7 +439,7 @@ BSP_AddVisibility (bsp_t *bsp, byte *visdata, int visdatasize)
}
VISIBLE void
BSP_AddEntities (bsp_t *bsp, char *entdata, int entdatasize)
BSP_AddEntities (bsp_t *bsp, char *entdata, size_t entdatasize)
{
bsp->entdatasize = entdatasize;
bsp->entdata = malloc (entdatasize);
@ -447,7 +447,7 @@ BSP_AddEntities (bsp_t *bsp, char *entdata, int entdatasize)
}
VISIBLE void
BSP_AddTextures (bsp_t *bsp, byte *texdata, int texdatasize)
BSP_AddTextures (bsp_t *bsp, byte *texdata, size_t texdatasize)
{
bsp->texdatasize = texdatasize;
bsp->texdata = malloc (texdatasize);

View file

@ -169,7 +169,7 @@ LightWorld (void)
BSP_AddLighting (bsp, (byte *) lightdata->str, lightdata->size);
if (options.verbosity >= 0)
printf ("lightdatasize: %i\n", bsp->lightdatasize);
printf ("lightdatasize: %zi\n", bsp->lightdatasize);
}
int

View file

@ -83,7 +83,7 @@ int c_vistest;
int numportals;
int portalclusters;
int numrealleafs;
int originalvismapsize;
size_t originalvismapsize;
int totalvis;
int count_sep;
int bitbytes; // (portalleafs + 63)>>3
@ -848,7 +848,7 @@ main (int argc, char **argv)
BSP_AddVisibility (bsp, (byte *) visdata->str, visdata->size);
if (options.verbosity >= 0)
printf ("visdatasize:%i compressed from %i\n", bsp->visdatasize,
printf ("visdatasize:%zi compressed from %zi\n", bsp->visdatasize,
originalvismapsize);
CalcAmbientSounds ();