コード例 #1
0
ファイル: r_bsp_model.c プロジェクト: darkshade9/aq2w
/*
 * R_LoadBspModel
 */
void R_LoadBspModel(r_model_t *mod, void *buffer) {
	extern void Cl_LoadProgress(int percent);
	d_bsp_header_t header;
	unsigned int i;

	if (r_world_model)
		Com_Error(ERR_DROP, "R_LoadBspModel: Loaded bsp model after world.");

	header = *(d_bsp_header_t *) buffer;
	for (i = 0; i < sizeof(d_bsp_header_t) / 4; i++)
		((int *) &header)[i] = LittleLong(((int *) &header)[i]);

	if (header.version != BSP_VERSION && header.version != BSP_VERSION_) {
		Com_Error(ERR_DROP, "R_LoadBspModel: %s has unsupported version: %d",
				mod->name, header.version);
	}

	mod->type = mod_bsp;
	mod->version = header.version;

	// set the base pointer for lump loading
	mod_base = (byte *) buffer;

	// load into heap
	R_LoadBspVertexes(&header.lumps[LUMP_VERTEXES]);
	Cl_LoadProgress(4);

	if (header.version == BSP_VERSION_) // enhanced format
		R_LoadBspNormals(&header.lumps[LUMP_NORMALS]);

	R_LoadBspEdges(&header.lumps[LUMP_EDGES]);
	Cl_LoadProgress(8);

	R_LoadBspSurfaceEdges(&header.lumps[LUMP_FACE_EDGES]);
	Cl_LoadProgress(12);

	R_LoadBspLightmaps(&header.lumps[LUMP_LIGHMAPS]);
	Cl_LoadProgress(16);

	R_LoadBspPlanes(&header.lumps[LUMP_PLANES]);
	Cl_LoadProgress(20);

	R_LoadBspTexinfo(&header.lumps[LUMP_TEXINFO]);
	Cl_LoadProgress(24);

	R_LoadBspSurfaces(&header.lumps[LUMP_FACES]);
	Cl_LoadProgress(28);

	R_LoadBspLeafSurfaces(&header.lumps[LUMP_LEAF_FACES]);
	Cl_LoadProgress(32);

	R_LoadBspVisibility(&header.lumps[LUMP_VISIBILITY]);
	Cl_LoadProgress(36);

	R_LoadBspLeafs(&header.lumps[LUMP_LEAFS]);
	Cl_LoadProgress(40);

	R_LoadBspNodes(&header.lumps[LUMP_NODES]);
	Cl_LoadProgress(44);

	R_LoadBspSubmodels(&header.lumps[LUMP_MODELS]);
	Cl_LoadProgress(48);

	R_SetupBspSubmodels();

	Com_Debug("================================\n");
	Com_Debug("R_LoadBspModel: %s\n", r_load_model->name);
	Com_Debug("  Verts:          %d\n", r_load_model->num_vertexes);
	Com_Debug("  Edges:          %d\n", r_load_model->num_edges);
	Com_Debug("  Surface edges:  %d\n", r_load_model->num_surface_edges);
	Com_Debug("  Faces:          %d\n", r_load_model->num_surfaces);
	Com_Debug("  Nodes:          %d\n", r_load_model->num_nodes);
	Com_Debug("  Leafs:          %d\n", r_load_model->num_leafs);
	Com_Debug("  Leaf surfaces:  %d\n", r_load_model->num_leaf_surfaces);
	Com_Debug("  Models:         %d\n", r_load_model->num_submodels);
	Com_Debug("  Lightmaps:      %d\n", r_load_model->lightmap_data_size);
	Com_Debug("  Vis:            %d\n", r_load_model->vis_size);

	if (r_load_model->vis)
		Com_Debug("  Clusters:   %d\n", r_load_model->vis->num_clusters);

	Com_Debug("================================\n");

	R_LoadBspVertexArrays();

	R_LoadBspSurfacesArrays();

	R_LoadBspLights();

	r_locals.old_cluster = -1; // force bsp iteration
}
コード例 #2
0
ファイル: r_model_brush.c プロジェクト: chrisglass/ufoai
/**
 * @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;

	/* get new model */
	if (r_numModels < 0 || r_numModels >= MAX_MOD_KNOWN)
		Com_Error(ERR_DROP, "R_ModAddMapTile: r_numModels >= MAX_MOD_KNOWN");

	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_models[r_numModels++];
	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;

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

	for (i = 0; i < (int)sizeof(dBspHeader_t) / 4; i++)
		((int *) header)[i] = LittleLong(((int *) header)[i]);

	/* 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_LoadBspVertexArrays(r_worldmodel);

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

	FS_FreeFile(buffer);
}
コード例 #3
0
ファイル: r_bsp_model.c プロジェクト: devilx4/quake2world
/*
 * @brief
 */
void R_LoadBspModel(r_model_t *mod, void *buffer) {
	extern void Cl_LoadProgress(int32_t percent);
	d_bsp_header_t header;
	uint32_t i;

	header = *(d_bsp_header_t *) buffer;
	for (i = 0; i < sizeof(d_bsp_header_t) / sizeof(int32_t); i++)
		((int32_t *) &header)[i] = LittleLong(((int32_t *) &header)[i]);

	if (header.version != BSP_VERSION && header.version != BSP_VERSION_Q2W) {
		Com_Error(ERR_DROP, "%s has unsupported version: %d\n", mod->media.name, header.version);
	}

	mod->bsp = Z_LinkMalloc(sizeof(r_bsp_model_t), mod);
	mod->bsp->version = header.version;

	// set the base pointer for lump loading
	mod_base = (byte *) buffer;

	// load into heap
	R_LoadBspVertexes(mod->bsp, &header.lumps[BSP_LUMP_VERTEXES]);
	Cl_LoadProgress(4);

	if (header.version == BSP_VERSION_Q2W) // enhanced format
		R_LoadBspNormals(mod->bsp, &header.lumps[BSP_LUMP_NORMALS]);

	R_LoadBspEdges(mod->bsp, &header.lumps[BSP_LUMP_EDGES]);
	Cl_LoadProgress(8);

	R_LoadBspSurfaceEdges(mod->bsp, &header.lumps[BSP_LUMP_FACE_EDGES]);
	Cl_LoadProgress(12);

	R_LoadBspLightmaps(mod->bsp, &header.lumps[BSP_LUMP_LIGHMAPS]);
	Cl_LoadProgress(16);

	R_LoadBspPlanes(mod->bsp, &header.lumps[BSP_LUMP_PLANES]);
	Cl_LoadProgress(20);

	R_LoadBspTexinfo(mod->bsp, &header.lumps[BSP_LUMP_TEXINFO]);
	Cl_LoadProgress(24);

	R_LoadBspSurfaces(mod->bsp, &header.lumps[BSP_LUMP_FACES]);
	Cl_LoadProgress(28);

	R_LoadBspLeafSurfaces(mod->bsp, &header.lumps[BSP_LUMP_LEAF_FACES]);
	Cl_LoadProgress(32);

	R_LoadBspLeafs(mod->bsp, &header.lumps[BSP_LUMP_LEAFS]);
	Cl_LoadProgress(36);

	R_LoadBspNodes(mod->bsp, &header.lumps[BSP_LUMP_NODES]);
	Cl_LoadProgress(40);

	R_LoadBspClusters(mod->bsp, &header.lumps[BSP_LUMP_VISIBILITY]);
	Cl_LoadProgress(44);

	R_LoadBspInlineModels(mod->bsp, &header.lumps[BSP_LUMP_MODELS]);
	Cl_LoadProgress(48);

	R_LoadBspLights(mod->bsp);
	Cl_LoadProgress(50);

	Com_Debug("!================================\n");
	Com_Debug("!R_LoadBspModel: %s\n", mod->media.name);
	Com_Debug("!  Verts:          %d\n", mod->bsp->num_vertexes);
	Com_Debug("!  Edges:          %d\n", mod->bsp->num_edges);
	Com_Debug("!  Surface edges:  %d\n", mod->bsp->num_surface_edges);
	Com_Debug("!  Faces:          %d\n", mod->bsp->num_surfaces);
	Com_Debug("!  Nodes:          %d\n", mod->bsp->num_nodes);
	Com_Debug("!  Leafs:          %d\n", mod->bsp->num_leafs);
	Com_Debug("!  Leaf surfaces:  %d\n", mod->bsp->num_leaf_surfaces);
	Com_Debug("!  Clusters:       %d\n", mod->bsp->num_clusters);
	Com_Debug("!  Inline models   %d\n", mod->bsp->num_inline_models);
	Com_Debug("!  Lights:         %d\n", mod->bsp->num_bsp_lights);
	Com_Debug("!================================\n");

	R_SetupBspInlineModels(mod);
	Cl_LoadProgress(52);

	R_LoadBspVertexArrays(mod);
	Cl_LoadProgress(54);

	R_LoadBspSurfacesArrays(mod);
	Cl_LoadProgress(58);

	r_locals.old_cluster = -1; // force bsp iteration
}