int CopyLump_Allocate(bspHeader_t * header, int lump, void **dest, int size, int *allocationVariable) { /* get lump length and offset */ *allocationVariable = header->lumps[lump].length / size; *dest = realloc(*dest, size * *allocationVariable); return CopyLump(header, lump, *dest, size); }
/* ============= LoadBSPFile ============= */ bool LoadBSPFile( const char *filename ) { dheader_t *header; // load the file header if(!LoadFile (filename, (byte **)&header)) return false; // swap the header SwapBlock( (int *)header, sizeof(*header) ); if ( header->ident != BSP_IDENT ) { DoMessageBox( "Cant find a valid IBSP file", "Error", eMB_OK); return false; } if ( (header->version != Q3_BSP_VERSION) && (header->version != WOLF_BSP_VERSION) ) { DoMessageBox( "File is incorrect version", "Error", eMB_OK); return false; } numbrushsides = CopyLump( header, LUMP_BRUSHES, (void**)&dbrushsides, sizeof(dbrushside_t) ); numbrushes = CopyLump( header, LUMP_BRUSHES, (void**)&dbrushes, sizeof(dbrush_t) ); numplanes = CopyLump( header, LUMP_PLANES, (void**)&dplanes, sizeof(dplane_t) ); numleafs = CopyLump( header, LUMP_LEAFS, (void**)&dleafs, sizeof(dleaf_t) ); numnodes = CopyLump( header, LUMP_NODES, (void**)&dnodes, sizeof(dnode_t) ); numDrawVerts = CopyLump( header, LUMP_DRAWVERTS, (void**)&drawVerts, sizeof(qdrawVert_t) ); numDrawSurfaces = CopyLump( header, LUMP_SURFACES, (void**)&drawSurfaces, sizeof(dsurface_t) ); numleafsurfaces = CopyLump( header, LUMP_LEAFSURFACES, (void**)&dleafsurfaces, sizeof(int) ); numVisBytes = CopyLump( header, LUMP_VISIBILITY, (void**)&visBytes, 1 ); numleafbrushes = CopyLump( header, LUMP_LEAFBRUSHES, (void**)&dleafbrushes, sizeof(int) ); delete header; // everything has been copied out // swap everything SwapBSPFile(); return true; }
/* ============= LoadBSPFile ============= */ void LoadBSPFile( const char *filename ) { dheader_t *header; // load the file header LoadFile (filename, (void **)&header); // swap the header SwapBlock( (int *)header, sizeof(*header) ); if ( header->ident != BSP_IDENT ) { Error( "%s is not a IBSP file", filename ); } if ( header->version != BSP_VERSION ) { Error( "%s is version %i, not %i", filename, header->version, BSP_VERSION ); } numShaders = CopyLump( header, LUMP_SHADERS, dshaders, sizeof(dshader_t) ); nummodels = CopyLump( header, LUMP_MODELS, dmodels, sizeof(dmodel_t) ); numplanes = CopyLump( header, LUMP_PLANES, dplanes, sizeof(dplane_t) ); numleafs = CopyLump( header, LUMP_LEAFS, dleafs, sizeof(dleaf_t) ); numnodes = CopyLump( header, LUMP_NODES, dnodes, sizeof(dnode_t) ); numleafsurfaces = CopyLump( header, LUMP_LEAFSURFACES, dleafsurfaces, sizeof(dleafsurfaces[0]) ); numleafbrushes = CopyLump( header, LUMP_LEAFBRUSHES, dleafbrushes, sizeof(dleafbrushes[0]) ); numbrushes = CopyLump( header, LUMP_BRUSHES, dbrushes, sizeof(dbrush_t) ); numbrushsides = CopyLump( header, LUMP_BRUSHSIDES, dbrushsides, sizeof(dbrushside_t) ); numDrawVerts = CopyLump( header, LUMP_DRAWVERTS, drawVerts, sizeof(drawVert_t) ); numDrawSurfaces = CopyLump( header, LUMP_SURFACES, drawSurfaces, sizeof(dsurface_t) ); //numFogs = CopyLump( header, LUMP_FOGS, dfogs, sizeof(dfog_t) ); numDrawIndexes = CopyLump( header, LUMP_DRAWINDEXES, drawIndexes, sizeof(drawIndexes[0]) ); numVisBytes = CopyLump( header, LUMP_VISIBILITY, visBytes, 1 ); numLightBytes = CopyLump( header, LUMP_LIGHTMAPS, lightBytes, 1 ); entdatasize = CopyLump( header, LUMP_ENTITIES, dentdata, 1); // numGridPoints = CopyLump( header, LUMP_LIGHTGRID, gridData, 8 ); // su44: MoHAA lumps numStaticModels = CopyLump( header, LUMP_STATICMODELDEF, staticModels, sizeof(staticModels[0])); numLeafStaticModels = CopyLump( header, LUMP_STATICMODELINDEXES, dleafStaticModels, sizeof(dleafStaticModels[0])); numStaticModelVertColors = CopyLump( header, LUMP_STATICMODELDATA, staticModelVertColors, 3); numTerraPatches = CopyLump( header, LUMP_TERRAIN, terraPatches, sizeof(terraPatches[0])); numSideEquations = CopyLump( header, LUMP_SIDEEQUATIONS, sideEquations, sizeof(sideEquations[0])); numSphereLights = CopyLump( header, LUMP_SPHERELIGHTS, sphereLights, sizeof(sphereLights[0])); numLightDefs = CopyLump( header, LUMP_LIGHTDEFS, lightDefs, sizeof(lightDefs[0])); free( header ); // everything has been copied out // swap everything SwapBSPFile(); }
/* ============= LoadBSPFile ============= */ void LoadBSPFile (char *filename) { int i; // // load the file header // LoadFile (filename, (void **)&header); // swap the header for (i=0 ; i< sizeof(dheader_t)/4 ; i++) ((int *)header)[i] = LittleLong ( ((int *)header)[i]); if (header->version != BSPVERSION) Error ("%s is version %i, not %i", filename, header->version, BSPVERSION); nummodels = CopyLump (LUMP_MODELS, dmodels, sizeof(dmodel_t)); numvertexes = CopyLump (LUMP_VERTEXES, dvertexes, sizeof(dvertex_t)); numplanes = CopyLump (LUMP_PLANES, dplanes, sizeof(dplane_t)); numleafs = CopyLump (LUMP_LEAFS, dleafs, sizeof(dleaf_t)); numnodes = CopyLump (LUMP_NODES, dnodes, sizeof(dnode_t)); numtexinfo = CopyLump (LUMP_TEXINFO, texinfo, sizeof(texinfo_t)); numclipnodes = CopyLump (LUMP_CLIPNODES, dclipnodes, sizeof(dclipnode_t)); numfaces = CopyLump (LUMP_FACES, dfaces, sizeof(dface_t)); nummarksurfaces = CopyLump (LUMP_MARKSURFACES, dmarksurfaces, sizeof(dmarksurfaces[0])); numsurfedges = CopyLump (LUMP_SURFEDGES, dsurfedges, sizeof(dsurfedges[0])); numedges = CopyLump (LUMP_EDGES, dedges, sizeof(dedge_t)); texdatasize = CopyLump (LUMP_TEXTURES, dtexdata, 1); visdatasize = CopyLump (LUMP_VISIBILITY, dvisdata, 1); lightdatasize = CopyLump (LUMP_LIGHTING, dlightdata, 1); entdatasize = CopyLump (LUMP_ENTITIES, dentdata, 1); free (header); // everything has been copied out // // swap everything // SwapBSPFile (false); dmodels_checksum = FastChecksum( dmodels, nummodels*sizeof(dmodels[0]) ); dvertexes_checksum = FastChecksum( dvertexes, numvertexes*sizeof(dvertexes[0]) ); dplanes_checksum = FastChecksum( dplanes, numplanes*sizeof(dplanes[0]) ); dleafs_checksum = FastChecksum( dleafs, numleafs*sizeof(dleafs[0]) ); dnodes_checksum = FastChecksum( dnodes, numnodes*sizeof(dnodes[0]) ); texinfo_checksum = FastChecksum( texinfo, numtexinfo*sizeof(texinfo[0]) ); dclipnodes_checksum = FastChecksum( dclipnodes, numclipnodes*sizeof(dclipnodes[0]) ); dfaces_checksum = FastChecksum( dfaces, numfaces*sizeof(dfaces[0]) ); dmarksurfaces_checksum = FastChecksum( dmarksurfaces, nummarksurfaces*sizeof(dmarksurfaces[0]) ); dsurfedges_checksum = FastChecksum( dsurfedges, numsurfedges*sizeof(dsurfedges[0]) ); dedges_checksum = FastChecksum( dedges, numedges*sizeof(dedges[0]) ); dtexdata_checksum = FastChecksum( dtexdata, numedges*sizeof(dtexdata[0]) ); dvisdata_checksum = FastChecksum( dvisdata, visdatasize*sizeof(dvisdata[0]) ); dlightdata_checksum = FastChecksum( dlightdata, lightdatasize*sizeof(dlightdata[0]) ); dentdata_checksum = FastChecksum( dentdata, entdatasize*sizeof(dentdata[0]) ); }
void LoadXBSPFile(const char *filename) { xbspHeader_t *header; /* load the file header */ LoadFile(filename, (void **)&header); /* swap the header (except the first 4 bytes) */ SwapBlock((int *)((byte *) header + sizeof(int)), sizeof(*header) - sizeof(int)); /* make sure it matches the format we're trying to load */ if(force == qfalse && *((int *)header->ident) != *((int *)game->bspIdent)) Error("%s is not a %s file", filename, game->bspIdent); if(force == qfalse && header->version != game->bspVersion) Error("%s is version %d, not %d", filename, header->version, game->bspVersion); /* load/convert lumps */ numBSPShaders = CopyLump_Allocate((bspHeader_t *) header, LUMP_SHADERS, (void **)&bspShaders, sizeof(bspShader_t), &allocatedBSPShaders); numBSPModels = CopyLump_Allocate((bspHeader_t *) header, LUMP_MODELS, (void **)&bspModels, sizeof(bspModel_t), &allocatedBSPModels); numBSPPlanes = CopyLump_Allocate((bspHeader_t *) header, LUMP_PLANES, (void **)&bspPlanes, sizeof(bspPlane_t), &allocatedBSPPlanes); numBSPLeafs = CopyLump((bspHeader_t *) header, LUMP_LEAFS, bspLeafs, sizeof(bspLeaf_t)); numBSPNodes = CopyLump_Allocate((bspHeader_t *) header, LUMP_NODES, (void **)&bspNodes, sizeof(bspNode_t), &allocatedBSPNodes); numBSPLeafSurfaces = CopyLump_Allocate((bspHeader_t *) header, LUMP_LEAFSURFACES, (void **)&bspLeafSurfaces, sizeof(bspLeafSurfaces[0]), &allocatedBSPLeafSurfaces); numBSPLeafBrushes = CopyLump_Allocate((bspHeader_t *) header, LUMP_LEAFBRUSHES, (void **)&bspLeafBrushes, sizeof(bspLeafBrushes[0]), &allocatedBSPLeafBrushes); numBSPBrushes = CopyLump_Allocate((bspHeader_t *) header, LUMP_BRUSHES, (void **)&bspBrushes, sizeof(bspBrush_t), &allocatedBSPLeafBrushes); CopyBrushSidesLump(header); CopyDrawVertsLump(header); CopyDrawSurfacesLump(header); numBSPFogs = CopyLump((bspHeader_t *) header, LUMP_FOGS, bspFogs, sizeof(bspFog_t)); numBSPDrawIndexes = CopyLump((bspHeader_t *) header, LUMP_DRAWINDEXES, bspDrawIndexes, sizeof(bspDrawIndexes[0])); numBSPVisBytes = CopyLump((bspHeader_t *) header, LUMP_VISIBILITY, bspVisBytes, 1); numBSPLightBytes = GetLumpElements((bspHeader_t *) header, LUMP_LIGHTMAPS, 1); bspLightBytes = safe_malloc(numBSPLightBytes); CopyLump((bspHeader_t *) header, LUMP_LIGHTMAPS, bspLightBytes, 1); bspEntDataSize = CopyLump_Allocate((bspHeader_t *) header, LUMP_ENTITIES, (void **)&bspEntData, 1, &allocatedBSPEntData); CopyLightGridLumps(header); /* free the file buffer */ free(header); }
/* ============= LoadBSPFile ============= */ void LoadBSPFile( char *filename ){ int i; // // load the file header // LoadFile( filename, (void **)&header ); // swap the header for ( i = 0 ; i < sizeof( dheader_t ) / 4 ; i++ ) ( (int *)header )[i] = LittleLong( ( (int *)header )[i] ); if ( header->ident != IDBSPHEADER ) { Error( "%s is not a IBSP file", filename ); } if ( header->version != BSPVERSION ) { Error( "%s is version %i, not %i", filename, header->version, BSPVERSION ); } nummodels = CopyLump( LUMP_MODELS, dmodels, sizeof( dmodel_t ) ); numvertexes = CopyLump( LUMP_VERTEXES, dvertexes, sizeof( dvertex_t ) ); numplanes = CopyLump( LUMP_PLANES, dplanes, sizeof( dplane_t ) ); numleafs = CopyLump( LUMP_LEAFS, dleafs, sizeof( dleaf_t ) ); numnodes = CopyLump( LUMP_NODES, dnodes, sizeof( dnode_t ) ); numtexinfo = CopyLump( LUMP_TEXINFO, texinfo, sizeof( texinfo_t ) ); numfaces = CopyLump( LUMP_FACES, dfaces, sizeof( dface_t ) ); numleaffaces = CopyLump( LUMP_LEAFFACES, dleaffaces, sizeof( dleaffaces[0] ) ); numleafbrushes = CopyLump( LUMP_LEAFBRUSHES, dleafbrushes, sizeof( dleafbrushes[0] ) ); numsurfedges = CopyLump( LUMP_SURFEDGES, dsurfedges, sizeof( dsurfedges[0] ) ); numedges = CopyLump( LUMP_EDGES, dedges, sizeof( dedge_t ) ); numbrushes = CopyLump( LUMP_BRUSHES, dbrushes, sizeof( dbrush_t ) ); numbrushsides = CopyLump( LUMP_BRUSHSIDES, dbrushsides, sizeof( dbrushside_t ) ); numareas = CopyLump( LUMP_AREAS, dareas, sizeof( darea_t ) ); numareaportals = CopyLump( LUMP_AREAPORTALS, dareaportals, sizeof( dareaportal_t ) ); visdatasize = CopyLump( LUMP_VISIBILITY, dvisdata, 1 ); lightdatasize = CopyLump( LUMP_LIGHTING, dlightdata, 1 ); entdatasize = CopyLump( LUMP_ENTITIES, dentdata, 1 ); CopyLump( LUMP_POP, dpop, 1 ); free( header ); // everything has been copied out // // swap everything // SwapBSPFile( false ); }
/** * @sa WriteBSPFile */ dMapTile_t* LoadBSPFile (const char* filename) { dBspHeader_t* header; /* Create this shortcut to mapTiles[0] */ curTile = &mapTiles.mapTiles[0]; /* Set the number of tiles to 1. */ mapTiles.numTiles = 1; /* load the file header */ int size = FS_LoadFile(filename, (byte**)&header); if (size == -1) Sys_Error("'%s' doesn't exist", filename); /* swap the header */ BSP_SwapHeader(header, filename); if (header->ident != IDBSPHEADER) Sys_Error("%s is not a IBSP file", filename); if (header->version != BSPVERSION) Sys_Error("%s is version %i, not %i", filename, header->version, BSPVERSION); curTile->nummodels = CopyLump(header, LUMP_MODELS, curTile->models, sizeof(dBspModel_t)); curTile->numvertexes = CopyLump(header, LUMP_VERTEXES, curTile->vertexes, sizeof(dBspVertex_t)); curTile->numplanes = CopyLump(header, LUMP_PLANES, curTile->planes, sizeof(dBspPlane_t)); curTile->numleafs = CopyLump(header, LUMP_LEAFS, curTile->leafs, sizeof(dBspLeaf_t)); curTile->numnormals = CopyLump(header, LUMP_NORMALS, curTile->normals, sizeof(dBspNormal_t)); curTile->numnodes = CopyLump(header, LUMP_NODES, curTile->nodes, sizeof(dBspNode_t)); curTile->numtexinfo = CopyLump(header, LUMP_TEXINFO, curTile->texinfo, sizeof(dBspTexinfo_t)); curTile->numfaces = CopyLump(header, LUMP_FACES, curTile->faces, sizeof(dBspSurface_t)); curTile->numleafbrushes = CopyLump(header, LUMP_LEAFBRUSHES, curTile->leafbrushes, sizeof(curTile->leafbrushes[0])); curTile->numsurfedges = CopyLump(header, LUMP_SURFEDGES, curTile->surfedges, sizeof(curTile->surfedges[0])); curTile->numedges = CopyLump(header, LUMP_EDGES, curTile->edges, sizeof(dBspEdge_t)); curTile->numbrushes = CopyLump(header, LUMP_BRUSHES, curTile->dbrushes, sizeof(dBspBrush_t)); curTile->numbrushsides = CopyLump(header, LUMP_BRUSHSIDES, curTile->brushsides, sizeof(dBspBrushSide_t)); curTile->routedatasize = CopyLump(header, LUMP_ROUTING, curTile->routedata, 1); curTile->lightdatasize[LIGHTMAP_NIGHT] = CopyLump(header, LUMP_LIGHTING_NIGHT, curTile->lightdata[LIGHTMAP_NIGHT], 1); curTile->lightdatasize[LIGHTMAP_DAY] = CopyLump(header, LUMP_LIGHTING_DAY, curTile->lightdata[LIGHTMAP_DAY], 1); curTile->entdatasize = CopyLump(header, LUMP_ENTITIES, curTile->entdata, 1); /* Because the tracing functions use cBspBrush_t and not dBspBrush_t, * copy data from curTile->dbrushes into curTile->cbrushes */ OBJZERO(curTile->brushes); for (int i = 0; i < curTile->numbrushes; i++) { dBspBrush_t* dbrush = &curTile->dbrushes[i]; cBspBrush_t* brush = &curTile->brushes[i]; brush->firstbrushside = dbrush->firstbrushside; brush->numsides = dbrush->numsides; brush->brushContentFlags = dbrush->brushContentFlags; } /* everything has been copied out */ FS_FreeFile(header); /* swap everything */ SwapBSPFile(); return curTile; }
bspFile_t *BSP_LoadEF2( const bspFormat_t *format, const char *name, const void *data, int length ) { int i, j, k; dheader_t header; bspFile_t *bsp; BSP_SwapBlock( (int *) &header, (int *)data, sizeof ( dheader_t ) ); if ( header.ident != format->ident || header.version != format->version ) { return NULL; } bsp = malloc( sizeof ( bspFile_t ) ); Com_Memset( bsp, 0, sizeof ( bspFile_t ) ); // ... bsp->checksum = header.checksum; bsp->defaultLightGridSize[0] = LIGHTING_GRIDSIZE_X; bsp->defaultLightGridSize[1] = LIGHTING_GRIDSIZE_Y; bsp->defaultLightGridSize[2] = LIGHTING_GRIDSIZE_Z; // // count and alloc // bsp->entityStringLength = GetLumpElements( &header, LUMP_ENTITIES, 1 ); bsp->entityString = malloc( bsp->entityStringLength ); bsp->numShaders = GetLumpElements( &header, LUMP_SHADERS, sizeof ( realDshader_t ) ); bsp->shaders = malloc( bsp->numShaders * sizeof ( *bsp->shaders ) ); bsp->numPlanes = GetLumpElements( &header, LUMP_PLANES, sizeof ( realDplane_t ) ); bsp->planes = malloc( bsp->numPlanes * sizeof ( *bsp->planes ) ); bsp->numNodes = GetLumpElements( &header, LUMP_NODES, sizeof ( realDnode_t ) ); bsp->nodes = malloc( bsp->numNodes * sizeof ( *bsp->nodes ) ); bsp->numLeafs = GetLumpElements( &header, LUMP_LEAFS, sizeof ( realDleaf_t ) ); bsp->leafs = malloc( bsp->numLeafs * sizeof ( *bsp->leafs ) ); bsp->numLeafSurfaces = GetLumpElements( &header, LUMP_LEAFSURFACES, sizeof ( int ) ); bsp->leafSurfaces = malloc( bsp->numLeafSurfaces * sizeof ( *bsp->leafSurfaces ) ); bsp->numLeafBrushes = GetLumpElements( &header, LUMP_LEAFBRUSHES, sizeof ( int ) ); bsp->leafBrushes = malloc( bsp->numLeafBrushes * sizeof ( *bsp->leafBrushes ) ); bsp->numSubmodels = GetLumpElements( &header, LUMP_MODELS, sizeof ( realDmodel_t ) ); bsp->submodels = malloc( bsp->numSubmodels * sizeof ( *bsp->submodels ) ); bsp->numBrushes = GetLumpElements( &header, LUMP_BRUSHES, sizeof ( realDbrush_t ) ); bsp->brushes = malloc( bsp->numBrushes * sizeof ( *bsp->brushes ) ); bsp->numBrushSides = GetLumpElements( &header, LUMP_BRUSHSIDES, sizeof ( realDbrushside_t ) ); bsp->brushSides = malloc( bsp->numBrushSides * sizeof ( *bsp->brushSides ) ); bsp->numDrawVerts = GetLumpElements( &header, LUMP_DRAWVERTS, sizeof ( realDrawVert_t ) ); bsp->drawVerts = malloc( bsp->numDrawVerts * sizeof ( *bsp->drawVerts ) ); bsp->numDrawIndexes = GetLumpElements( &header, LUMP_DRAWINDEXES, sizeof ( int ) ); bsp->drawIndexes = malloc( bsp->numDrawIndexes * sizeof ( *bsp->drawIndexes ) ); bsp->numFogs = GetLumpElements( &header, LUMP_FOGS, sizeof ( realDfog_t ) ); bsp->fogs = malloc( bsp->numFogs * sizeof ( *bsp->fogs ) ); bsp->numSurfaces = GetLumpElements( &header, LUMP_SURFACES, sizeof ( realDsurface_t ) ); bsp->surfaces = malloc( bsp->numSurfaces * sizeof ( *bsp->surfaces ) ); bsp->numLightmaps = GetLumpElements( &header, LUMP_LIGHTMAPS, 128 * 128 * 3 ); bsp->lightmapData = malloc( bsp->numLightmaps * 128 * 128 * 3 ); bsp->numGridPoints = GetLumpElements( &header, LUMP_LIGHTGRID, 8 ); bsp->lightGridData = malloc( bsp->numGridPoints * 8 ); bsp->visibilityLength = GetLumpElements( &header, LUMP_VISIBILITY, 1 ) - VIS_HEADER; if ( bsp->visibilityLength > 0 ) bsp->visibility = malloc( bsp->visibilityLength ); else bsp->visibilityLength = 0; // // copy and swap and convert data // CopyLump( &header, LUMP_ENTITIES, data, (void *) bsp->entityString, sizeof ( *bsp->entityString ), qfalse ); /* NO SWAP */ { realDshader_t *in = GetLump( &header, data, LUMP_SHADERS ); dshader_t *out = bsp->shaders; for ( i = 0; i < bsp->numShaders; i++, in++, out++ ) { Q_strncpyz( out->shader, in->shader, sizeof ( out->shader ) ); out->contentFlags = LittleLong( in->contentFlags ); out->surfaceFlags = LittleLong( in->surfaceFlags ); } } { realDplane_t *in = GetLump( &header, data, LUMP_PLANES ); dplane_t *out = bsp->planes; for ( i = 0; i < bsp->numPlanes; i++, in++, out++) { for (j=0 ; j<3 ; j++) { out->normal[j] = LittleFloat (in->normal[j]); } out->dist = LittleFloat (in->dist); } } { realDnode_t *in = GetLump( &header, data, LUMP_NODES ); dnode_t *out = bsp->nodes; for ( i = 0; i < bsp->numNodes; i++, in++, out++ ) { out->planeNum = LittleLong( in->planeNum ); for ( j = 0; j < 2; j++ ) { out->children[j] = LittleLong( in->children[j] ); } for ( j = 0; j < 3; j++ ) { out->mins[j] = LittleLong( in->mins[j] ); out->maxs[j] = LittleLong( in->maxs[j] ); } } } { realDleaf_t *in = GetLump( &header, data, LUMP_LEAFS ); dleaf_t *out = bsp->leafs; for ( i = 0; i < bsp->numLeafs; i++, in++, out++ ) { out->cluster = LittleLong (in->cluster); out->area = LittleLong (in->area); for ( j = 0; j < 3; j++ ) { out->mins[j] = LittleLong( in->mins[j] ); out->maxs[j] = LittleLong( in->maxs[j] ); } out->firstLeafBrush = LittleLong (in->firstLeafBrush); out->numLeafBrushes = LittleLong (in->numLeafBrushes); out->firstLeafSurface = LittleLong (in->firstLeafSurface); out->numLeafSurfaces = LittleLong (in->numLeafSurfaces); } } CopyLump( &header, LUMP_LEAFSURFACES, data, (void *) bsp->leafSurfaces, sizeof ( *bsp->leafSurfaces ), qtrue ); CopyLump( &header, LUMP_LEAFBRUSHES, data, (void *) bsp->leafBrushes, sizeof ( *bsp->leafBrushes ), qtrue ); { realDmodel_t *in = GetLump( &header, data, LUMP_MODELS ); dmodel_t *out = bsp->submodels; for ( i = 0; i < bsp->numSubmodels; i++, in++, out++ ) { for ( j = 0; j < 3; j++ ) { out->mins[j] = LittleFloat( in->mins[j] ); out->maxs[j] = LittleFloat( in->maxs[j] ); } out->firstSurface = LittleLong (in->firstSurface); out->numSurfaces = LittleLong (in->numSurfaces); out->firstBrush = LittleLong (in->firstBrush); out->numBrushes = LittleLong (in->numBrushes); } } { realDbrush_t *in = GetLump( &header, data, LUMP_BRUSHES ); dbrush_t *out = bsp->brushes; for ( i = 0; i < bsp->numBrushes; i++, in++, out++ ) { out->firstSide = LittleLong (in->firstSide); out->numSides = LittleLong (in->numSides); out->shaderNum = LittleLong (in->shaderNum); } } { realDbrushside_t *in = GetLump( &header, data, LUMP_BRUSHSIDES ); dbrushside_t *out = bsp->brushSides; for ( i = 0; i < bsp->numBrushSides; i++, in++, out++ ) { out->planeNum = LittleLong (in->planeNum); out->shaderNum = LittleLong (in->shaderNum); out->surfaceNum = -1; } } { realDrawVert_t *in = GetLump( &header, data, LUMP_DRAWVERTS ); drawVert_t *out = bsp->drawVerts; for ( i = 0; i < bsp->numDrawVerts; i++, in++, out++ ) { for ( j = 0 ; j < 3 ; j++ ) { out->xyz[j] = LittleFloat( in->xyz[j] ); out->normal[j] = LittleFloat( in->normal[j] ); } for ( j = 0 ; j < 2 ; j++ ) { out->st[j] = LittleFloat( in->st[j] ); out->lightmap[j] = LittleFloat( in->lightmap[j] ); } /* NO SWAP */ for ( j = 0; j < 4; j++ ) { out->color[j] = in->color[j]; } } } CopyLump( &header, LUMP_DRAWINDEXES, data, (void *) bsp->drawIndexes, sizeof ( *bsp->drawIndexes ), qtrue ); { realDfog_t *in = GetLump( &header, data, LUMP_FOGS ); dfog_t *out = bsp->fogs; for ( i = 0; i < bsp->numFogs; i++, in++, out++ ) { Q_strncpyz( out->shader, in->shader, sizeof ( out->shader ) ); out->brushNum = LittleLong (in->brushNum); out->visibleSide = LittleLong (in->visibleSide); } } { realDsurface_t *in = GetLump( &header, data, LUMP_SURFACES ); dsurface_t *out = bsp->surfaces; for ( i = 0; i < bsp->numSurfaces; i++, in++, out++ ) { out->shaderNum = LittleLong (in->shaderNum); out->fogNum = LittleLong (in->fogNum); out->surfaceType = LittleLong (in->surfaceType); if ( out->surfaceType == REAL_MST_TERRAIN ) { out->surfaceType = MST_TERRAIN; } else if ( out->surfaceType == REAL_MST_FOLIAGE ) { out->surfaceType = MST_FOLIAGE; } out->firstVert = LittleLong (in->firstVert); out->numVerts = LittleLong (in->numVerts); out->firstIndex = LittleLong (in->firstIndex); out->numIndexes = LittleLong (in->numIndexes); out->lightmapNum = LittleLong (in->lightmapNum); out->lightmapX = LittleLong (in->lightmapX); out->lightmapY = LittleLong (in->lightmapY); out->lightmapWidth = LittleLong (in->lightmapWidth); out->lightmapHeight = LittleLong (in->lightmapHeight); for ( j = 0; j < 3; j++ ) { out->lightmapOrigin[j] = LittleFloat( in->lightmapOrigin[j] ); for ( k = 0; k < 3; k++ ) { out->lightmapVecs[j][k] = LittleFloat( in->lightmapVecs[j][k] ); } } out->patchWidth = LittleLong (in->patchWidth); out->patchHeight = LittleLong (in->patchHeight); out->subdivisions = LittleFloat( in->subdivisions ); } } CopyLump( &header, LUMP_LIGHTMAPS, data, (void *) bsp->lightmapData, sizeof ( *bsp->lightmapData ), qfalse ); /* NO SWAP */ CopyLump( &header, LUMP_LIGHTGRID, data, (void *) bsp->lightGridData, sizeof ( *bsp->lightGridData ), qfalse ); /* NO SWAP */ if ( bsp->visibilityLength ) { byte *in = GetLump( &header, data, LUMP_VISIBILITY ); bsp->numClusters = LittleLong( ((int *)in)[0] ); bsp->clusterBytes = LittleLong( ((int *)in)[1] ); Com_Memcpy( bsp->visibility, in + VIS_HEADER, bsp->visibilityLength ); /* NO SWAP */ } return bsp; }
/* * ============= * LoadBSPFile * ============= */ int LoadBSPFile(const char *filename) { int i, bsp_version; /* load the file header */ LoadFile(filename, (void *)&header); /* swap the header */ for (i = 0; i < sizeof(dheader_t) / 4; i++) ((int *)header)[i] = LittleLong(((int *)header)[i]); bsp_version = (int)header->version; logprint("BSP is version %i\n", bsp_version); if (bsp_version != 29 && bsp_version != 30) Error("Sorry, only bsp versions 29 & 30 supported."); nummodels = CopyLump(LUMP_MODELS, dmodels, sizeof(dmodel_t)); numvertexes = CopyLump(LUMP_VERTEXES, dvertexes, sizeof(dvertex_t)); numplanes = CopyLump(LUMP_PLANES, dplanes, sizeof(dplane_t)); numleafs = CopyLump(LUMP_LEAFS, dleafs, sizeof(dleaf_t)); numnodes = CopyLump(LUMP_NODES, dnodes, sizeof(dnode_t)); numtexinfo = CopyLump(LUMP_TEXINFO, texinfo, sizeof(texinfo_t)); numclipnodes = CopyLump(LUMP_CLIPNODES, dclipnodes, sizeof(dclipnode_t)); numfaces = CopyLump(LUMP_FACES, dfaces, sizeof(dface_t)); nummarksurfaces = CopyLump(LUMP_MARKSURFACES, dmarksurfaces, sizeof(dmarksurfaces[0])); numsurfedges = CopyLump(LUMP_SURFEDGES, dsurfedges, sizeof(dsurfedges[0])); numedges = CopyLump(LUMP_EDGES, dedges, sizeof(dedge_t)); texdatasize = CopyLump(LUMP_TEXTURES, dtexdata, 1); visdatasize = CopyLump(LUMP_VISIBILITY, dvisdata, 1); lightdatasize = CopyLump(LUMP_LIGHTING, dlightdata, 1); entdatasize = CopyLump(LUMP_ENTITIES, dentdata, 1); free(header); /* everything has been copied out */ /* swap everything */ SwapBSPFile(false); /* Return the version */ return bsp_version; }