diff --git a/include/QF/model.h b/include/QF/model.h index a05d489a4..b65a5ad18 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -179,8 +179,6 @@ typedef struct mnode_s { float minmaxs[6]; // for bounding box culling - struct mnode_s *parent; - // node specific plane_t *plane; struct mnode_s *children[2]; @@ -198,8 +196,6 @@ typedef struct mleaf_s { float mins[3]; float maxs[3]; - struct mnode_s *parent; - // leaf specific byte *compressed_vis; efrag_t *efrags; @@ -274,6 +270,9 @@ typedef struct mod_brush_s { byte *lightdata; char *entities; //FIXME should not be here + mnode_t **node_parents; + mnode_t **leaf_parents; + unsigned int checksum; unsigned int checksum2; } mod_brush_t; diff --git a/libs/models/brush/model_brush.c b/libs/models/brush/model_brush.c index 8a703050d..b18de9076 100644 --- a/libs/models/brush/model_brush.c +++ b/libs/models/brush/model_brush.c @@ -585,13 +585,15 @@ Mod_LoadFaces (model_t *mod, bsp_t *bsp) } static void -Mod_SetParent (mnode_t *node, mnode_t *parent) +Mod_SetParent (mod_brush_t *brush, mnode_t *node, mnode_t *parent) { - node->parent = parent; - if (node->contents < 0) + if (node->contents < 0) { + brush->leaf_parents[(mleaf_t *)node - brush->leafs] = parent; return; - Mod_SetParent (node->children[0], node); - Mod_SetParent (node->children[1], node); + } + brush->node_parents[node - brush->nodes] = parent; + Mod_SetParent (brush, node->children[0], node); + Mod_SetParent (brush, node->children[1], node); } static void @@ -646,7 +648,10 @@ Mod_LoadNodes (model_t *mod, bsp_t *bsp) } } - Mod_SetParent (brush->nodes, NULL); // sets nodes and leafs + size_t size = (brush->numleafs + brush->numnodes) * sizeof (mnode_t *); + brush->node_parents = Hunk_AllocName (size, mod->name); + brush->leaf_parents = brush->node_parents + brush->numnodes; + Mod_SetParent (brush, brush->nodes, NULL); // sets nodes and leafs } static void diff --git a/libs/video/renderer/r_bsp.c b/libs/video/renderer/r_bsp.c index 2475873a5..47b78a643 100644 --- a/libs/video/renderer/r_bsp.c +++ b/libs/video/renderer/r_bsp.c @@ -54,6 +54,7 @@ R_MarkLeaves (void) mleaf_t *leaf; mnode_t *node; msurface_t **mark; + mod_brush_t *brush = &r_worldentity.model->brush; if (r_oldviewleaf == r_viewleaf && !r_novis->int_val) return; @@ -67,13 +68,13 @@ R_MarkLeaves (void) r_oldviewleaf = 0; // so vis will be recalcualted when novis gets // turned off vis = solid; - memset (solid, 0xff, (r_worldentity.model->brush.numleafs + 7) >> 3); + memset (solid, 0xff, (brush->numleafs + 7) >> 3); } else vis = Mod_LeafPVS (r_viewleaf, r_worldentity.model); - for (i = 0; (int) i < r_worldentity.model->brush.numleafs; i++) { + for (i = 0; (int) i < brush->numleafs; i++) { if (vis[i >> 3] & (1 << (i & 7))) { - leaf = &r_worldentity.model->brush.leafs[i + 1]; + leaf = &brush->leafs[i + 1]; if ((c = leaf->nummarksurfaces)) { mark = leaf->firstmarksurface; do { @@ -81,13 +82,14 @@ R_MarkLeaves (void) mark++; } while (--c); } - node = (mnode_t *) leaf; - do { + leaf->visframe = r_visframecount; + node = brush->leaf_parents[leaf - brush->leafs]; + while (node) { if (node->visframe == r_visframecount) break; node->visframe = r_visframecount; - node = node->parent; - } while (node); + node = brush->node_parents[node - brush->nodes]; + } } } }