static void CopyBrushSidesLump(xbspHeader_t * header) { int i; xbspBrushSide_t *in; bspBrushSide_t *out; /* get count */ numBSPBrushSides = GetLumpElements((bspHeader_t *) header, LUMP_BRUSHSIDES, sizeof(*in)); /* copy */ in = GetLump((bspHeader_t *) header, LUMP_BRUSHSIDES); for(i = 0; i < numBSPBrushSides; i++) { AUTOEXPAND_BY_REALLOC(bspBrushSides, i, allocatedBSPBrushSides, 1024); out = &bspBrushSides[i]; out->planeNum = in->planeNum; out->shaderNum = in->shaderNum; out->surfaceNum = -1; in++; } }
static void CopyBrushSidesLump( ibspHeader_t *header ) { int i; ibspBrushSide_t *in; bspBrushSide_t *out; /* get count */ numBSPBrushSides = GetLumpElements( (bspHeader_t*) header, LUMP_BRUSHSIDES, sizeof( *in ) ); /* copy */ in = GetLump( (bspHeader_t*) header, LUMP_BRUSHSIDES ); out = bspBrushSides; for( i = 0; i < numBSPBrushSides; i++ ) { out->planeNum = in->planeNum; out->shaderNum = in->shaderNum; out->surfaceNum = -1; in++; out++; } }
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; }