Exemplo n.º 1
0
/**
 * @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;
}
Exemplo n.º 2
0
/**
 * @sa CM_AddMapTile
 * @sa R_ModBeginLoading
 * @param[in] name The name of the map. Relative to maps/ and without extension
 * @param[in] day Load the day lightmap
 * @param[in] sX Shift x grid units
 * @param[in] sY Shift y grid units
 * @param[in] sZ Shift z grid units
 * @sa UNIT_SIZE
 */
static void R_ModAddMapTile (const char *name, qboolean day, int sX, int sY, int sZ)
{
	int i;
	byte *buffer;
	dBspHeader_t *header;
	const int lightingLump = day ? LUMP_LIGHTING_DAY : LUMP_LIGHTING_NIGHT;

	if (r_numMapTiles < 0 || r_numMapTiles >= MAX_MAPTILES)
		Com_Error(ERR_DROP, "R_ModAddMapTile: Too many map tiles");

	/* alloc model and tile */
	r_worldmodel = R_AllocModelSlot();
	r_mapTiles[r_numMapTiles++] = r_worldmodel;
	OBJZERO(*r_worldmodel);
	Com_sprintf(r_worldmodel->name, sizeof(r_worldmodel->name), "maps/%s.bsp", name);

	/* load the file */
	FS_LoadFile(r_worldmodel->name, &buffer);
	if (!buffer)
		Com_Error(ERR_DROP, "R_ModAddMapTile: %s not found", r_worldmodel->name);

	/* init */
	r_worldmodel->type = mod_bsp;
	r_worldmodel->bsp.maptile = r_numMapTiles - 1;

	/* prepare shifting */
	VectorSet(shift, sX * UNIT_SIZE, sY * UNIT_SIZE, sZ * UNIT_SIZE);

	/* test version */
	header = (dBspHeader_t *) buffer;
	i = LittleLong(header->version);
	if (i != BSPVERSION)
		Com_Error(ERR_DROP, "R_ModAddMapTile: %s has wrong version number (%i should be %i)", r_worldmodel->name, i, BSPVERSION);

	/* swap all the lumps */
	mod_base = (byte *) header;

	BSP_SwapHeader(header, r_worldmodel->name);

	/* load into heap */
	R_ModLoadVertexes(&header->lumps[LUMP_VERTEXES]);
	R_ModLoadNormals(&header->lumps[LUMP_NORMALS]);
	R_ModLoadEdges(&header->lumps[LUMP_EDGES]);
	R_ModLoadSurfedges(&header->lumps[LUMP_SURFEDGES]);
	R_ModLoadLighting(&header->lumps[lightingLump]);
	R_ModLoadPlanes(&header->lumps[LUMP_PLANES]);
	R_ModLoadTexinfo(&header->lumps[LUMP_TEXINFO]);
	R_ModLoadSurfaces(day, &header->lumps[LUMP_FACES]);
	R_ModLoadLeafs(&header->lumps[LUMP_LEAFS]);
	R_ModLoadNodes(&header->lumps[LUMP_NODES]);
	R_ModLoadSubmodels(&header->lumps[LUMP_MODELS]);

	R_SetupSubmodels();
	R_SetupWorldModel();

	R_LoadBspVertexArrays(r_worldmodel);

	/* in case of random map assembly shift some vectors */
	if (VectorNotEmpty(shift))
		R_ModShiftTile();

	FS_FreeFile(buffer);
}