Example #1
0
/*
=============
LoadBSPFileTexinfo

Only loads the texinfo lump, so qdata can scan for textures
=============
*/
void	Q2_LoadBSPFileTexinfo (char *filename)
{
	int			i;
	FILE		*f;
	int		length, ofs;

	header = GetMemory(sizeof(dheader_t));

	f = fopen (filename, "rb");
	fread (header, sizeof(dheader_t), 1, f);

// 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);


	length = header->lumps[LUMP_TEXINFO].filelen;
	ofs = header->lumps[LUMP_TEXINFO].fileofs;

	fseek (f, ofs, SEEK_SET);
	fread (texinfo, length, 1, f);
	fclose (f);

	numtexinfo = length / sizeof(texinfo_t);

	FreeMemory(header);		// everything has been copied out
		
	Q2_SwapBSPFile (false);
} //end of the function Q2_LoadBSPFileTexinfo
Example #2
0
/*
=============
LoadBSPFile
=============
*/
void Q2_LoadBSPFile( char *filename, int offset, int length ) {
	int i;

//
// load the file header
//
	LoadFile( filename, (void **)&header, offset, length );

// 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 an IBSP file", filename );
	}
	if ( header->version != BSPVERSION ) {
		Error( "%s is version %i, not %i", filename, header->version, BSPVERSION );
	}

	nummodels = Q2_CopyLump( LUMP_MODELS, dmodels, sizeof( dmodel_t ), MAX_MAP_MODELS );
	numvertexes = Q2_CopyLump( LUMP_VERTEXES, dvertexes, sizeof( dvertex_t ), MAX_MAP_VERTS );
	numplanes = Q2_CopyLump( LUMP_PLANES, dplanes, sizeof( dplane_t ), MAX_MAP_PLANES );
	numleafs = Q2_CopyLump( LUMP_LEAFS, dleafs, sizeof( dleaf_t ), MAX_MAP_LEAFS );
	numnodes = Q2_CopyLump( LUMP_NODES, dnodes, sizeof( dnode_t ), MAX_MAP_NODES );
	numtexinfo = Q2_CopyLump( LUMP_TEXINFO, texinfo, sizeof( texinfo_t ), MAX_MAP_TEXINFO );
	numfaces = Q2_CopyLump( LUMP_FACES, dfaces, sizeof( dface_t ), MAX_MAP_FACES );
	numleaffaces = Q2_CopyLump( LUMP_LEAFFACES, dleaffaces, sizeof( dleaffaces[0] ), MAX_MAP_LEAFFACES );
	numleafbrushes = Q2_CopyLump( LUMP_LEAFBRUSHES, dleafbrushes, sizeof( dleafbrushes[0] ), MAX_MAP_LEAFBRUSHES );
	numsurfedges = Q2_CopyLump( LUMP_SURFEDGES, dsurfedges, sizeof( dsurfedges[0] ), MAX_MAP_SURFEDGES );
	numedges = Q2_CopyLump( LUMP_EDGES, dedges, sizeof( dedge_t ), MAX_MAP_EDGES );
	numbrushes = Q2_CopyLump( LUMP_BRUSHES, dbrushes, sizeof( dbrush_t ), MAX_MAP_BRUSHES );
	numbrushsides = Q2_CopyLump( LUMP_BRUSHSIDES, dbrushsides, sizeof( dbrushside_t ), MAX_MAP_BRUSHSIDES );
	numareas = Q2_CopyLump( LUMP_AREAS, dareas, sizeof( darea_t ), MAX_MAP_AREAS );
	numareaportals = Q2_CopyLump( LUMP_AREAPORTALS, dareaportals, sizeof( dareaportal_t ), MAX_MAP_AREAPORTALS );

	visdatasize = Q2_CopyLump( LUMP_VISIBILITY, dvisdata, 1, MAX_MAP_VISIBILITY );
	lightdatasize = Q2_CopyLump( LUMP_LIGHTING, dlightdata, 1, MAX_MAP_LIGHTING );
	entdatasize = Q2_CopyLump( LUMP_ENTITIES, dentdata, 1, MAX_MAP_ENTSTRING );

	Q2_CopyLump( LUMP_POP, dpop, 1, MAX_MAP_DPOP );

	FreeMemory( header );     // everything has been copied out

//
// swap everything
//
	Q2_SwapBSPFile( false );

	Q2_FixTextureReferences();
} //end of the function Q2_LoadBSPFile
Example #3
0
/*
=============
WriteBSPFile

Swaps the bsp file in place, so it should not be referenced again
=============
*/
void	Q2_WriteBSPFile (char *filename)
{		
	header = &outheader;
	memset (header, 0, sizeof(dheader_t));
	
	Q2_SwapBSPFile (true);

	header->ident = LittleLong (IDBSPHEADER);
	header->version = LittleLong (BSPVERSION);
	
	wadfile = SafeOpenWrite (filename);
	SafeWrite (wadfile, header, sizeof(dheader_t));	// overwritten later

	Q2_AddLump (LUMP_PLANES, dplanes, numplanes*sizeof(dplane_t));
	Q2_AddLump (LUMP_LEAFS, dleafs, numleafs*sizeof(dleaf_t));
	Q2_AddLump (LUMP_VERTEXES, dvertexes, numvertexes*sizeof(dvertex_t));
	Q2_AddLump (LUMP_NODES, dnodes, numnodes*sizeof(dnode_t));
	Q2_AddLump (LUMP_TEXINFO, texinfo, numtexinfo*sizeof(texinfo_t));
	Q2_AddLump (LUMP_FACES, dfaces, numfaces*sizeof(dface_t));
	Q2_AddLump (LUMP_BRUSHES, dbrushes, numbrushes*sizeof(dbrush_t));
	Q2_AddLump (LUMP_BRUSHSIDES, dbrushsides, numbrushsides*sizeof(dbrushside_t));
	Q2_AddLump (LUMP_LEAFFACES, dleaffaces, numleaffaces*sizeof(dleaffaces[0]));
	Q2_AddLump (LUMP_LEAFBRUSHES, dleafbrushes, numleafbrushes*sizeof(dleafbrushes[0]));
	Q2_AddLump (LUMP_SURFEDGES, dsurfedges, numsurfedges*sizeof(dsurfedges[0]));
	Q2_AddLump (LUMP_EDGES, dedges, numedges*sizeof(dedge_t));
	Q2_AddLump (LUMP_MODELS, dmodels, nummodels*sizeof(dmodel_t));
	Q2_AddLump (LUMP_AREAS, dareas, numareas*sizeof(darea_t));
	Q2_AddLump (LUMP_AREAPORTALS, dareaportals, numareaportals*sizeof(dareaportal_t));

	Q2_AddLump (LUMP_LIGHTING, dlightdata, lightdatasize);
	Q2_AddLump (LUMP_VISIBILITY, dvisdata, visdatasize);
	Q2_AddLump (LUMP_ENTITIES, dentdata, entdatasize);
	Q2_AddLump (LUMP_POP, dpop, sizeof(dpop));
	
	fseek (wadfile, 0, SEEK_SET);
	SafeWrite (wadfile, header, sizeof(dheader_t));
	fclose (wadfile);	
} //end of the function Q2_WriteBSPFile