QuakeForge  0.7.2.210-815cf
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
bspfile.c File Reference

Macros

#define FREE(X)
 
#define OWN(X)
 
#define REALLOC(X)
 
#define ROUND(x)   (((x) + 3) & ~3)
 
#define SET_LUMP(l, n)
 
#define SET_LUMP(l, n)
 
#define SET_LUMP(l, n)
 
#define SET_LUMP(l, n)
 
#define SET_LUMP(n)
 
#define SET_LUMP(l, n)
 
#define SET_LUMP(l, n)
 
#define SET_LUMP(l, n)
 
#define SET_LUMP(l, n)
 

Typedefs

typedef struct bsp29_s bsp29_t
 
typedef struct dclipnode29_s dclipnode29_t
 
typedef struct dedge29_s dedge29_t
 
typedef struct dface29_s dface29_t
 
typedef struct dleaf29_s dleaf29_t
 
typedef struct dnode29_s dnode29_t
 

Functions

void BSP_AddClipnode (bsp_t *bsp, const dclipnode_t *clipnode)
 
void BSP_AddEdge (bsp_t *bsp, const dedge_t *edge)
 
void BSP_AddEntities (bsp_t *bsp, const char *entdata, size_t entdatasize)
 
void BSP_AddFace (bsp_t *bsp, const dface_t *face)
 
void BSP_AddLeaf (bsp_t *bsp, const dleaf_t *leaf)
 
void BSP_AddLighting (bsp_t *bsp, const byte *lightdata, size_t lightdatasize)
 
void BSP_AddMarkSurface (bsp_t *bsp, int marksurface)
 
void BSP_AddModel (bsp_t *bsp, const dmodel_t *model)
 
void BSP_AddNode (bsp_t *bsp, const dnode_t *node)
 
void BSP_AddPlane (bsp_t *bsp, const dplane_t *plane)
 
void BSP_AddSurfEdge (bsp_t *bsp, int surfedge)
 
void BSP_AddTexinfo (bsp_t *bsp, const texinfo_t *texinfo)
 
void BSP_AddTextures (bsp_t *bsp, const byte *texdata, size_t texdatasize)
 
void BSP_AddVertex (bsp_t *bsp, const dvertex_t *vertex)
 
void BSP_AddVisibility (bsp_t *bsp, const byte *visdata, size_t visdatasize)
 
void BSP_Free (bsp_t *bsp)
 
bsp_tBSP_New (void)
 
bsp_tLoadBSPFile (QFile *file, size_t size)
 
bsp_tLoadBSPMem (void *mem, size_t mem_size, void(*cb)(const bsp_t *, void *), void *cbdata)
 Create a bsp structure from a memory buffer. More...
 
void WriteBSPFile (const bsp_t *bsp, QFile *file)
 

Macro Definition Documentation

#define FREE (   X)
Value:
do { \
if (bsp->own_##X && bsp->X) \
free (bsp->X); \
} while (0)
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
#define X
Definition: bsp2img.c:58
void free(void *)
#define OWN (   X)
Value:
do { \
bsp->own_##X = 1; \
} while (0)
bsp_t * bsp
Definition: qfbsp.c:65
#define X
Definition: bsp2img.c:58
#define FREE(X)
#define REALLOC (   X)
Value:
do { \
if (!bsp->own_##X) { \
bsp->own_##X = 1; \
bsp->X = 0; \
} \
bsp->X = realloc (bsp->X, (bsp->num##X + 1) * sizeof (bsp->X[0])); \
} while (0)
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
#define X
Definition: bsp2img.c:58
char * realloc()
#define ROUND (   x)    (((x) + 3) & ~3)
#define SET_LUMP (   l,
  n 
)
Value:
do { \
size_t size = LittleLong (bsp->header->lumps[l].filelen); \
size_t offs = LittleLong (bsp->header->lumps[l].fileofs); \
void *data = (byte *) mem + offs; \
if (offs >= mem_size || (offs + size) > mem_size) \
Sys_Error ("invalid lump"); \
if (size % sizeof (bsp->n[0])) \
Sys_Error ("funny lump size"); \
bsp->n = 0; \
if (size) \
bsp->n = (void *) data; \
bsp->num##n = size / sizeof (bsp->n[0]); \
} while (0)
int32_t filelen
Definition: bspfile.h:54
uint8_t byte
Definition: qtypes.h:51
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
#define n(x, y)
void Sys_Error(const char *error,...)
Definition: sys.c:505
dheader_t * header
Definition: bspfile.h:212
lump_t lumps[HEADER_LUMPS]
Definition: bspfile.h:84
#define LittleLong
Definition: qendian.h:64
int32_t fileofs
Definition: bspfile.h:53
byte data[MAX_DATAGRAM]
Definition: net_dgrm.c:88
#define SET_LUMP (   l,
  n 
)
Value:
do { \
size_t size = LittleLong (bsp->header->lumps[l].filelen); \
size_t offs = LittleLong (bsp->header->lumps[l].fileofs); \
void *data = (byte *) mem + offs; \
if (offs >= mem_size || (offs + size) > mem_size) \
Sys_Error ("invalid lump"); \
bsp->n = 0; \
if (size) \
bsp->n = (void *) data; \
bsp->n##size = size; \
} while (0)
int32_t filelen
Definition: bspfile.h:54
uint8_t byte
Definition: qtypes.h:51
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
void Sys_Error(const char *error,...)
Definition: sys.c:505
dheader_t * header
Definition: bspfile.h:212
lump_t lumps[HEADER_LUMPS]
Definition: bspfile.h:84
#define LittleLong
Definition: qendian.h:64
int32_t fileofs
Definition: bspfile.h:53
byte data[MAX_DATAGRAM]
Definition: net_dgrm.c:88
#define SET_LUMP (   l,
  n 
)
Value:
do { \
size_t size = LittleLong (bsp29->header->lumps[l].filelen); \
size_t offs = LittleLong (bsp29->header->lumps[l].fileofs); \
void *data = (byte *) mem + offs; \
if (offs >= mem_size || (offs + size) > mem_size) \
Sys_Error ("invalid lump"); \
if (size % sizeof (bsp29->n[0])) \
Sys_Error ("funny lump size"); \
bsp29->n = 0; \
if (size) \
bsp29->n = (void *) data; \
bsp29->num##n = size / sizeof (bsp29->n[0]); \
} while (0)
uint8_t byte
Definition: qtypes.h:51
if(!(yy_init))
Definition: qp-lex.c:893
#define n(x, y)
void Sys_Error(const char *error,...)
Definition: sys.c:505
#define LittleLong
Definition: qendian.h:64
byte data[MAX_DATAGRAM]
Definition: net_dgrm.c:88
#define SET_LUMP (   l,
  n 
)
Value:
do { \
size_t size = LittleLong (bsp29->header->lumps[l].filelen); \
size_t offs = LittleLong (bsp29->header->lumps[l].fileofs); \
void *data = (byte *) mem + offs; \
if (offs >= mem_size || (offs + size) > mem_size) \
Sys_Error ("invalid lump"); \
bsp29->n = 0; \
if (size) \
bsp29->n = (void *) data; \
bsp29->n##size = size; \
} while (0)
uint8_t byte
Definition: qtypes.h:51
if(!(yy_init))
Definition: qp-lex.c:893
void Sys_Error(const char *error,...)
Definition: sys.c:505
#define LittleLong
Definition: qendian.h:64
byte data[MAX_DATAGRAM]
Definition: net_dgrm.c:88
#define SET_LUMP (   n)
Value:
do { \
if (bsp->num##n) {\
bsp->n = (void *) malloc (bsp->num##n * sizeof (bsp->n[0])); \
bsp->own_##n = 1; \
} \
} while (0)
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
char * malloc()
#define n(x, y)
#define SET_LUMP (   l,
  n 
)
Value:
do { \
tbsp->num##n = bsp->num##n; \
if (tbsp->num##n) {\
tbsp->n = (void *) data; \
tbsp->header->lumps[l].fileofs = data - (byte *) tbsp->header; \
tbsp->header->lumps[l].filelen = tbsp->num##n * sizeof (tbsp->n[0]); \
memcpy (data, bsp->n, tbsp->header->lumps[l].filelen); \
data += ROUND (tbsp->header->lumps[l].filelen); \
} else {\
tbsp->n = 0; \
tbsp->header->lumps[l].fileofs = 0; \
tbsp->header->lumps[l].filelen = 0; \
} \
} while (0)
int32_t filelen
Definition: bspfile.h:54
uint8_t byte
Definition: qtypes.h:51
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
#define n(x, y)
#define ROUND(x)
Definition: bspfile.c:766
dheader_t * header
Definition: bspfile.h:212
lump_t lumps[HEADER_LUMPS]
Definition: bspfile.h:84
byte data[MAX_DATAGRAM]
Definition: net_dgrm.c:88
#define SET_LUMP (   l,
  n 
)
Value:
do { \
tbsp->n##size = bsp->n##size; \
if (tbsp->n##size) { \
tbsp->n = (void *) data; \
tbsp->header->lumps[l].fileofs = data - (byte *) tbsp->header; \
tbsp->header->lumps[l].filelen = tbsp->n##size; \
memcpy (data, bsp->n, tbsp->n##size); \
data += ROUND (tbsp->header->lumps[l].filelen); \
} else {\
tbsp->n = 0; \
tbsp->header->lumps[l].fileofs = 0; \
tbsp->header->lumps[l].filelen = 0; \
} \
} while (0)
uint8_t byte
Definition: qtypes.h:51
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
#define ROUND(x)
Definition: bspfile.c:766
byte data[MAX_DATAGRAM]
Definition: net_dgrm.c:88
#define SET_LUMP (   l,
  n 
)
Value:
do { \
tbsp->num##n = bsp->num##n; \
if (tbsp->num##n) {\
tbsp->n = (void *) data; \
tbsp->header->lumps[l].fileofs = data - (byte *) tbsp->header; \
tbsp->header->lumps[l].filelen = tbsp->num##n * sizeof (tbsp->n[0]); \
memcpy (data, bsp->n, tbsp->header->lumps[l].filelen); \
data += ROUND (tbsp->header->lumps[l].filelen); \
} else {\
tbsp->n = 0; \
tbsp->header->lumps[l].fileofs = 0; \
tbsp->header->lumps[l].filelen = 0; \
} \
} while (0)
int32_t filelen
Definition: bspfile.h:54
uint8_t byte
Definition: qtypes.h:51
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
#define n(x, y)
#define ROUND(x)
Definition: bspfile.c:766
dheader_t * header
Definition: bspfile.h:212
lump_t lumps[HEADER_LUMPS]
Definition: bspfile.h:84
byte data[MAX_DATAGRAM]
Definition: net_dgrm.c:88
#define SET_LUMP (   l,
  n 
)
Value:
do { \
tbsp->n##size = bsp->n##size; \
if (tbsp->n##size) { \
tbsp->n = (void *) data; \
tbsp->header->lumps[l].fileofs = data - (byte *) tbsp->header; \
tbsp->header->lumps[l].filelen = tbsp->n##size; \
memcpy (data, bsp->n, tbsp->n##size); \
data += ROUND (tbsp->header->lumps[l].filelen); \
} else {\
tbsp->n = 0; \
tbsp->header->lumps[l].fileofs = 0; \
tbsp->header->lumps[l].filelen = 0; \
} \
} while (0)
uint8_t byte
Definition: qtypes.h:51
if(!(yy_init))
Definition: qp-lex.c:893
bsp_t * bsp
Definition: qfbsp.c:65
#define ROUND(x)
Definition: bspfile.c:766
byte data[MAX_DATAGRAM]
Definition: net_dgrm.c:88

Typedef Documentation

typedef struct bsp29_s bsp29_t
typedef struct dclipnode29_s dclipnode29_t
typedef struct dedge29_s dedge29_t
typedef struct dface29_s dface29_t
typedef struct dleaf29_s dleaf29_t
typedef struct dnode29_s dnode29_t

Function Documentation

void BSP_AddClipnode ( bsp_t bsp,
const dclipnode_t clipnode 
)
void BSP_AddEdge ( bsp_t bsp,
const dedge_t edge 
)
void BSP_AddEntities ( bsp_t bsp,
const char *  entdata,
size_t  entdatasize 
)
void BSP_AddFace ( bsp_t bsp,
const dface_t face 
)
void BSP_AddLeaf ( bsp_t bsp,
const dleaf_t leaf 
)
void BSP_AddLighting ( bsp_t bsp,
const byte lightdata,
size_t  lightdatasize 
)
void BSP_AddMarkSurface ( bsp_t bsp,
int  marksurface 
)
void BSP_AddModel ( bsp_t bsp,
const dmodel_t model 
)
void BSP_AddNode ( bsp_t bsp,
const dnode_t node 
)
void BSP_AddPlane ( bsp_t bsp,
const dplane_t plane 
)
void BSP_AddSurfEdge ( bsp_t bsp,
int  surfedge 
)
void BSP_AddTexinfo ( bsp_t bsp,
const texinfo_t texinfo 
)
void BSP_AddTextures ( bsp_t bsp,
const byte texdata,
size_t  texdatasize 
)
void BSP_AddVertex ( bsp_t bsp,
const dvertex_t vertex 
)
void BSP_AddVisibility ( bsp_t bsp,
const byte visdata,
size_t  visdatasize 
)
void BSP_Free ( bsp_t bsp)
bsp_t* BSP_New ( void  )
bsp_t* LoadBSPFile ( QFile file,
size_t  size 
)
bsp_t* LoadBSPMem ( void *  mem,
size_t  size,
void(*)(const bsp_t *, void *)  cb,
void *  cbdata 
)

Create a bsp structure from a memory buffer.

The returned structure will be setup to point into the supplied buffer. All structures within the bsp will be byte-swapped. For this reason, if a callback is provided, the callback be called after byteswapping the header, but before byteswapping any data in the lumps.

Parameters
memThe buffer holding the bsp data.
sizeThe size of the buffer. This is used for sanity checking.
cbPointer to the callback function.
cbdataPointer to extra data for the callback.
Returns
Initialized bsp structure.
Note
The caller maintains ownership of the memory buffer. BSP_Free will free only the bsp structure itself. However, if the caller wishes to relinquish ownership of the buffer, set bsp_t::own_header to true.
void WriteBSPFile ( const bsp_t bsp,
QFile file 
)