Esempio n. 1
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);
}
Esempio n. 2
0
/*
=============
SwapBSPFile

Byte swaps all data in a bsp file.
=============
*/
void SwapBSPFile( void ) {
	int				i;
	
	// models	
//	SwapBlock( (int *)dmodels, nummodels * sizeof( dmodels[0] ) );

	// shaders (don't swap the name)
//	for ( i = 0 ; i < numShaders ; i++ ) {
//		dshaders[i].contentFlags = LittleLong( dshaders[i].contentFlags );
//		dshaders[i].surfaceFlags = LittleLong( dshaders[i].surfaceFlags );
//	}

	// planes
	SwapBlock( (int *)dplanes, numplanes * sizeof( dplanes[0] ) );
	
	// nodes
	SwapBlock( (int *)dnodes, numnodes * sizeof( dnodes[0] ) );

	// leafs
	SwapBlock( (int *)dleafs, numleafs * sizeof( dleafs[0] ) );

	// leaffaces
	SwapBlock( (int *)dleafsurfaces, numleafsurfaces * sizeof( dleafsurfaces[0] ) );

	// leafbrushes
	SwapBlock( (int *)dleafbrushes, numleafbrushes * sizeof( dleafbrushes[0] ) );

	// brushes
	SwapBlock( (int *)dbrushes, numbrushes * sizeof( dbrushes[0] ) );

	// brushsides
	SwapBlock( (int *)dbrushsides, numbrushsides * sizeof( dbrushsides[0] ) );

	// vis
	((int *)&visBytes)[0] = LittleLong( ((int *)&visBytes)[0] );
	((int *)&visBytes)[1] = LittleLong( ((int *)&visBytes)[1] );

	// drawverts (don't swap colors )
	for ( i = 0 ; i < 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
//	SwapBlock( (int *)drawIndexes, numDrawIndexes * sizeof( drawIndexes[0] ) );

	// drawsurfs
	SwapBlock( (int *)drawSurfaces, numDrawSurfaces * sizeof( drawSurfaces[0] ) );

	// fogs
//	for ( i = 0 ; i < numFogs ; i++ ) {
//		dfogs[i].brushNum = LittleLong( dfogs[i].brushNum );
//		dfogs[i].visibleSide = LittleLong( dfogs[i].visibleSide );
//	}
}
Esempio n. 3
0
void SwapBSPFile(void)
{
	int             i, j;


	/* models */
	SwapBlock((int *)bspModels, numBSPModels * sizeof(bspModels[0]));

	/* shaders (don't swap the name) */
	for(i = 0; i < numBSPShaders; i++)
	{
		bspShaders[i].contentFlags = LittleLong(bspShaders[i].contentFlags);
		bspShaders[i].surfaceFlags = LittleLong(bspShaders[i].surfaceFlags);
	}

	/* planes */
	SwapBlock((int *)bspPlanes, numBSPPlanes * sizeof(bspPlanes[0]));

	/* nodes */
	SwapBlock((int *)bspNodes, numBSPNodes * sizeof(bspNodes[0]));

	/* leafs */
	SwapBlock((int *)bspLeafs, numBSPLeafs * sizeof(bspLeafs[0]));

	/* leaffaces */
	SwapBlock((int *)bspLeafSurfaces, numBSPLeafSurfaces * sizeof(bspLeafSurfaces[0]));

	/* leafbrushes */
	SwapBlock((int *)bspLeafBrushes, numBSPLeafBrushes * sizeof(bspLeafBrushes[0]));

	// brushes
	SwapBlock((int *)bspBrushes, numBSPBrushes * sizeof(bspBrushes[0]));

	// brushsides
	SwapBlock((int *)bspBrushSides, numBSPBrushSides * sizeof(bspBrushSides[0]));

	// vis
	((int *)&bspVisBytes)[0] = LittleLong(((int *)&bspVisBytes)[0]);
	((int *)&bspVisBytes)[1] = LittleLong(((int *)&bspVisBytes)[1]);

	/* drawverts (don't swap colors) */
	for(i = 0; i < numBSPDrawVerts; i++)
	{
		bspDrawVerts[i].xyz[0] = LittleFloat(bspDrawVerts[i].xyz[0]);
		bspDrawVerts[i].xyz[1] = LittleFloat(bspDrawVerts[i].xyz[1]);
		bspDrawVerts[i].xyz[2] = LittleFloat(bspDrawVerts[i].xyz[2]);
		bspDrawVerts[i].normal[0] = LittleFloat(bspDrawVerts[i].normal[0]);
		bspDrawVerts[i].normal[1] = LittleFloat(bspDrawVerts[i].normal[1]);
		bspDrawVerts[i].normal[2] = LittleFloat(bspDrawVerts[i].normal[2]);
		bspDrawVerts[i].st[0] = LittleFloat(bspDrawVerts[i].st[0]);
		bspDrawVerts[i].st[1] = LittleFloat(bspDrawVerts[i].st[1]);
		for(j = 0; j < MAX_LIGHTMAPS; j++)
		{
			bspDrawVerts[i].lightmap[j][0] = LittleFloat(bspDrawVerts[i].lightmap[j][0]);
			bspDrawVerts[i].lightmap[j][1] = LittleFloat(bspDrawVerts[i].lightmap[j][1]);
		}
	}

	/* drawindexes */
	SwapBlock((int *)bspDrawIndexes, numBSPDrawIndexes * sizeof(bspDrawIndexes[0]));

	/* drawsurfs */
	/* note: rbsp files (and hence q3map2 abstract bsp) have byte lightstyles index arrays, this follows sof2map convention */
	SwapBlock((int *)bspDrawSurfaces, numBSPDrawSurfaces * sizeof(bspDrawSurfaces[0]));

	/* fogs */
	for(i = 0; i < numBSPFogs; i++)
	{
		bspFogs[i].brushNum = LittleLong(bspFogs[i].brushNum);
		bspFogs[i].visibleSide = LittleLong(bspFogs[i].visibleSide);
	}

	/* advertisements */
	for(i = 0; i < numBSPAds; i++)
	{
		bspAds[i].cellId = LittleLong(bspAds[i].cellId);
		bspAds[i].normal[0] = LittleFloat(bspAds[i].normal[0]);
		bspAds[i].normal[1] = LittleFloat(bspAds[i].normal[1]);
		bspAds[i].normal[2] = LittleFloat(bspAds[i].normal[2]);

		for(j = 0; j < 4; j++)
		{
			bspAds[i].rect[j][0] = LittleFloat(bspAds[i].rect[j][0]);
			bspAds[i].rect[j][1] = LittleFloat(bspAds[i].rect[j][1]);
			bspAds[i].rect[j][2] = LittleFloat(bspAds[i].rect[j][2]);
		}

		//bspAds[ i ].model[ MAX_QPATH ];
	}
}