/* ============= Q3_LoadBSPFile ============= */ void Q3_LoadBSPFile(struct quakefile_s *qf) { dheader_t *header; // load the file header //LoadFile(filename, (void **)&header, offset, length); // LoadQuakeFile(qf, (void **)&header); // swap the header Q3_SwapBlock( (int *)header, sizeof(*header) ); if ( header->ident != BSP_IDENT ) { Error( "%s is not a 2015 file", qf->filename ); } if ( header->version != BSP_VERSION ) { Error( "%s is version %i, not %i", qf->filename, header->version, BSP_VERSION ); } q3_numShaders = Q3_CopyLump( header, LUMP_SHADERS, (void *) &dshaders, sizeof(dshader_t) ); q3_nummodels = Q3_CopyLump( header, LUMP_MODELS, (void *) &dmodels, sizeof(dmodel_t) ); q3_numplanes = Q3_CopyLump( header, LUMP_PLANES, (void *) &dplanes, sizeof(dplane_t) ); q3_numleafs = Q3_CopyLump( header, LUMP_LEAFS, (void *) &dleafs, sizeof(dleaf_t) ); q3_numnodes = Q3_CopyLump( header, LUMP_NODES, (void *) &dnodes, sizeof(dnode_t) ); q3_numleafsurfaces = Q3_CopyLump( header, LUMP_LEAFSURFACES, (void *) &dleafsurfaces, sizeof(dleafsurfaces[0]) ); q3_numleafbrushes = Q3_CopyLump( header, LUMP_LEAFBRUSHES, (void *) &dleafbrushes, sizeof(dleafbrushes[0]) ); q3_numbrushes = Q3_CopyLump( header, LUMP_BRUSHES, (void *) &dbrushes, sizeof(dbrush_t) ); q3_numbrushsides = Q3_CopyLump( header, LUMP_BRUSHSIDES, (void *) &dbrushsides, sizeof(dbrushside_t) ); q3_numDrawVerts = Q3_CopyLump( header, LUMP_DRAWVERTS, (void *) &drawVerts, sizeof(drawVert_t) ); q3_numDrawSurfaces = Q3_CopyLump( header, LUMP_SURFACES, (void *) &drawSurfaces, sizeof(dsurface_t) ); // q3_numFogs = Q3_CopyLump( header, LUMP_FOGS, (void *) &dfogs, sizeof(dfog_t) ); q3_numDrawIndexes = Q3_CopyLump( header, LUMP_DRAWINDEXES, (void *) &drawIndexes, sizeof(drawIndexes[0]) ); q3_numVisBytes = Q3_CopyLump( header, LUMP_VISIBILITY, (void *) &q3_visBytes, 1 ); q3_numLightBytes = Q3_CopyLump( header, LUMP_LIGHTMAPS, (void *) &q3_lightBytes, 1 ); q3_entdatasize = Q3_CopyLump( header, LUMP_ENTITIES, (void *) &dentdata, 1); // q3_numGridPoints = Q3_CopyLump( header, LUMP_LIGHTGRID, (void *) &q3_gridData, 8 ); CountTriangles(); FreeMemory( header ); // everything has been copied out // swap everything Q3_SwapBSPFile(); Q3_FindVisibleBrushSides(); //Q3_PrintBSPFileSizes(); }
/* ============= Q3_SwapBSPFile Byte swaps all data in a bsp file. ============= */ void Q3_SwapBSPFile( void ) { int i; // models Q3_SwapBlock( (int *)dmodels, q3_nummodels * sizeof( dmodels[0] ) ); // shaders (don't swap the name) for ( i = 0 ; i < q3_numShaders ; i++ ) { dshaders[i].contentFlags = LittleLong( dshaders[i].contentFlags ); dshaders[i].surfaceFlags = LittleLong( dshaders[i].surfaceFlags ); } // planes Q3_SwapBlock( (int *)dplanes, q3_numplanes * sizeof( dplanes[0] ) ); // nodes Q3_SwapBlock( (int *)dnodes, q3_numnodes * sizeof( dnodes[0] ) ); // leafs Q3_SwapBlock( (int *)dleafs, q3_numleafs * sizeof( dleafs[0] ) ); // leaffaces Q3_SwapBlock( (int *)dleafsurfaces, q3_numleafsurfaces * sizeof( dleafsurfaces[0] ) ); // leafbrushes Q3_SwapBlock( (int *)dleafbrushes, q3_numleafbrushes * sizeof( dleafbrushes[0] ) ); // brushes Q3_SwapBlock( (int *)dbrushes, q3_numbrushes * sizeof( dbrushes[0] ) ); // brushsides Q3_SwapBlock( (int *)dbrushsides, q3_numbrushsides * sizeof( dbrushsides[0] ) ); // vis ((int *)&q3_visBytes)[0] = LittleLong( ((int *)&q3_visBytes)[0] ); ((int *)&q3_visBytes)[1] = LittleLong( ((int *)&q3_visBytes)[1] ); // drawverts (don't swap colors ) for ( i = 0 ; i < q3_numDrawVerts ; i++ ) { drawVerts[i].lightmap[0] = LittleFloat( drawVerts[i].lightmap[0] ); drawVerts[i].lightmap[1] = LittleFloat( drawVerts[i].lightmap[1] ); drawVerts[i].st[0] = LittleFloat( drawVerts[i].st[0] ); drawVerts[i].st[1] = LittleFloat( drawVerts[i].st[1] ); drawVerts[i].xyz[0] = LittleFloat( drawVerts[i].xyz[0] ); drawVerts[i].xyz[1] = LittleFloat( drawVerts[i].xyz[1] ); drawVerts[i].xyz[2] = LittleFloat( drawVerts[i].xyz[2] ); drawVerts[i].normal[0] = LittleFloat( drawVerts[i].normal[0] ); drawVerts[i].normal[1] = LittleFloat( drawVerts[i].normal[1] ); drawVerts[i].normal[2] = LittleFloat( drawVerts[i].normal[2] ); } // drawindexes Q3_SwapBlock( (int *)drawIndexes, q3_numDrawIndexes * sizeof( drawIndexes[0] ) ); // drawsurfs Q3_SwapBlock( (int *)drawSurfaces, q3_numDrawSurfaces * sizeof( drawSurfaces[0] ) ); // fogs for ( i = 0 ; i < q3_numFogs ; i++ ) { dfogs[i].brushNum = LittleLong( dfogs[i].brushNum ); } }
/* ============= Q3_SwapBSPFile Byte swaps all data in a bsp file. ============= */ void Q3_SwapBSPFile( void ) { int i; // models Q3_SwapBlock( (int *)q3_dmodels, q3_nummodels * sizeof( q3_dmodels[0] ) ); // shaders (don't swap the name) for ( i = 0 ; i < q3_numShaders ; i++ ) { q3_dshaders[i].contentFlags = LittleLong( q3_dshaders[i].contentFlags ); q3_dshaders[i].surfaceFlags = LittleLong( q3_dshaders[i].surfaceFlags ); // RF, HACK, clipweap causes problems, so convert to plain solid if ( !strcmp( q3_dshaders[i].shader, "textures/common/clipweap" ) ) { q3_dshaders[i].contentFlags = CONTENTS_MONSTERCLIP; //q3_dshaders[i].surfaceFlags = SURF_NODRAW; } // // RF, only keep content flags that are consistent with q3map q3_dshaders[i].contentFlags &= ( CONTENTS_SOLID | CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER | CONTENTS_AREAPORTAL | CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP | CONTENTS_DETAIL | CONTENTS_CLUSTERPORTAL ); } // planes Q3_SwapBlock( (int *)q3_dplanes, q3_numplanes * sizeof( q3_dplanes[0] ) ); // nodes Q3_SwapBlock( (int *)q3_dnodes, q3_numnodes * sizeof( q3_dnodes[0] ) ); // leafs Q3_SwapBlock( (int *)q3_dleafs, q3_numleafs * sizeof( q3_dleafs[0] ) ); // leaffaces Q3_SwapBlock( (int *)q3_dleafsurfaces, q3_numleafsurfaces * sizeof( q3_dleafsurfaces[0] ) ); // leafbrushes Q3_SwapBlock( (int *)q3_dleafbrushes, q3_numleafbrushes * sizeof( q3_dleafbrushes[0] ) ); // brushes Q3_SwapBlock( (int *)q3_dbrushes, q3_numbrushes * sizeof( q3_dbrushes[0] ) ); // brushsides Q3_SwapBlock( (int *)q3_dbrushsides, q3_numbrushsides * sizeof( q3_dbrushsides[0] ) ); // vis ( (int *)&q3_visBytes )[0] = LittleLong( ( (int *)&q3_visBytes )[0] ); ( (int *)&q3_visBytes )[1] = LittleLong( ( (int *)&q3_visBytes )[1] ); // drawverts (don't swap colors ) for ( i = 0 ; i < q3_numDrawVerts ; i++ ) { q3_drawVerts[i].lightmap[0] = LittleFloat( q3_drawVerts[i].lightmap[0] ); q3_drawVerts[i].lightmap[1] = LittleFloat( q3_drawVerts[i].lightmap[1] ); q3_drawVerts[i].st[0] = LittleFloat( q3_drawVerts[i].st[0] ); q3_drawVerts[i].st[1] = LittleFloat( q3_drawVerts[i].st[1] ); q3_drawVerts[i].xyz[0] = LittleFloat( q3_drawVerts[i].xyz[0] ); q3_drawVerts[i].xyz[1] = LittleFloat( q3_drawVerts[i].xyz[1] ); q3_drawVerts[i].xyz[2] = LittleFloat( q3_drawVerts[i].xyz[2] ); q3_drawVerts[i].normal[0] = LittleFloat( q3_drawVerts[i].normal[0] ); q3_drawVerts[i].normal[1] = LittleFloat( q3_drawVerts[i].normal[1] ); q3_drawVerts[i].normal[2] = LittleFloat( q3_drawVerts[i].normal[2] ); } // drawindexes Q3_SwapBlock( (int *)q3_drawIndexes, q3_numDrawIndexes * sizeof( q3_drawIndexes[0] ) ); // drawsurfs Q3_SwapBlock( (int *)q3_drawSurfaces, q3_numDrawSurfaces * sizeof( q3_drawSurfaces[0] ) ); // fogs for ( i = 0 ; i < q3_numFogs ; i++ ) { q3_dfogs[i].brushNum = LittleLong( q3_dfogs[i].brushNum ); } }