コード例 #1
0
ファイル: r_bsp_model.c プロジェクト: darkshade9/aq2w
/*
 * R_SetupBspNode
 */
static void R_SetupBspNode(r_bsp_node_t *node, r_bsp_node_t *parent) {

	node->parent = parent;

	if (node->contents != CONTENTS_NODE) // leaf
		return;

	R_SetupBspNode(node->children[0], node);
	R_SetupBspNode(node->children[1], node);
}
コード例 #2
0
ファイル: r_bsp_model.c プロジェクト: darkshade9/aq2w
/*
 * R_LoadBspNodes
 */
static void R_LoadBspNodes(const d_bsp_lump_t *l) {
	int i, j, count, p;
	const d_bsp_node_t *in;
	r_bsp_node_t *out;

	in = (const void *) (mod_base + l->file_ofs);
	if (l->file_len % sizeof(*in)) {
		Com_Error(ERR_DROP, "R_LoadBspNodes: Funny lump size in %s.",
				r_load_model->name);
	}

	count = l->file_len / sizeof(*in);
	out = R_HunkAlloc(count * sizeof(*out));

	r_load_model->nodes = out;
	r_load_model->num_nodes = count;

	for (i = 0; i < count; i++, in++, out++) {

		for (j = 0; j < 3; j++) {
			out->mins[j] = LittleShort(in->mins[j]);
			out->maxs[j] = LittleShort(in->maxs[j]);
		}

		p = LittleLong(in->plane_num);
		out->plane = r_load_model->planes + p;

		out->first_surface = LittleShort(in->first_face);
		out->num_surfaces = LittleShort(in->num_faces);

		out->contents = CONTENTS_NODE; // differentiate from leafs

		for (j = 0; j < 2; j++) {
			p = LittleLong(in->children[j]);
			if (p >= 0)
				out->children[j] = r_load_model->nodes + p;
			else
				out->children[j] = (r_bsp_node_t *) (r_load_model->leafs + (-1
						- p));
		}
	}

	R_SetupBspNode(r_load_model->nodes, NULL); // sets nodes and leafs
}
コード例 #3
0
ファイル: r_bsp_model.c プロジェクト: devilx4/quake2world
/*
 * @brief Loads all r_bsp_node_t for the specified BSP model.
 */
static void R_LoadBspNodes(r_bsp_model_t *bsp, const d_bsp_lump_t *l) {
	uint16_t i, j;
	r_bsp_node_t *out;

	const d_bsp_node_t *in = (const void *) (mod_base + l->file_ofs);
	if (l->file_len % sizeof(*in)) {
		Com_Error(ERR_DROP, "Funny lump size\n");
	}

	bsp->num_nodes = l->file_len / sizeof(*in);
	bsp->nodes = out = Z_LinkMalloc(bsp->num_nodes * sizeof(*out), bsp);

	for (i = 0; i < bsp->num_nodes; i++, in++, out++) {

		for (j = 0; j < 3; j++) {
			out->mins[j] = LittleShort(in->mins[j]);
			out->maxs[j] = LittleShort(in->maxs[j]);
		}

		const int32_t p = LittleLong(in->plane_num);
		out->plane = bsp->planes + p;

		out->first_surface = (uint16_t) LittleShort(in->first_face);
		out->num_surfaces = (uint16_t) LittleShort(in->num_faces);

		out->contents = CONTENTS_NODE; // differentiate from leafs

		for (j = 0; j < 2; j++) {
			const int32_t c = LittleLong(in->children[j]);
			if (c >= 0)
				out->children[j] = bsp->nodes + c;
			else
				out->children[j] = (r_bsp_node_t *) (bsp->leafs + (-1 - c));
		}
	}

	R_SetupBspNode(bsp->nodes, NULL); // sets nodes and leafs
}