From: lordhavoc Date: Fri, 17 Nov 2000 10:33:37 +0000 (+0000) Subject: speedups to R_WorldNode, and some shrinkage on the surface struct X-Git-Tag: RELEASE_0_2_0_RC1~942 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1d84e5d2c4212a98cc575ac1fce00160e53b6e62;p=xonotic%2Fdarkplaces.git speedups to R_WorldNode, and some shrinkage on the surface struct git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@78 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_rmain.c b/gl_rmain.c index e880dbd5..94cf4e36 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -63,7 +63,7 @@ mleaf_t *r_viewleaf, *r_oldviewleaf; texture_t *r_notexture_mip; -int d_lightstylevalue[256]; // 8.8 fraction of base light value +unsigned short d_lightstylevalue[256]; // 8.8 fraction of base light value void R_MarkLeaves (void); diff --git a/gl_rsurf.c b/gl_rsurf.c index be07117c..3d0b4c2d 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -821,6 +821,12 @@ e->angles[0] = -e->angles[0]; // stupid quake bug void R_StoreEfrags (efrag_t **ppefrag); +struct nodestack_s +{ + int side; + mnode_t *node; +} nodestack[8192]; + /* ================ R_WorldNode @@ -828,14 +834,14 @@ R_WorldNode */ void R_WorldNode () { - int c, side, s = 0; - double dot; - struct - { - double dot; - mnode_t *node; - } nodestack[8192]; + int side, texsort, vertex; + struct nodestack_s *nstack; mnode_t *node; + mleaf_t *pleaf; + msurface_t *surf, *endsurf, **mark, **endmark; + nstack = nodestack; + texsort = gl_texsort.value; + vertex = gl_vertex.value; if (!(node = cl.worldmodel->nodes)) return; @@ -847,19 +853,19 @@ void R_WorldNode () { if (node->contents != CONTENTS_SOLID) { - mleaf_t *pleaf; pleaf = (mleaf_t *)node; c_leafs++; - if ((c = pleaf->nummarksurfaces)) + if (pleaf->nummarksurfaces) { - msurface_t **mark; mark = pleaf->firstmarksurface; + endmark = mark + pleaf->nummarksurfaces; do { (*mark)->visframe = r_framecount; mark++; - } while (--c); + } + while (mark < endmark); } // deal with model fragments in this leaf @@ -867,69 +873,89 @@ void R_WorldNode () R_StoreEfrags (&pleaf->efrags); } - if (!s) + if (nstack <= nodestack) break; - node = nodestack[--s].node; - dot = nodestack[s].dot; + nstack--; + node = nstack->node; + side = nstack->side; goto loc0; } c_nodes++; - // node is just a decision point, so go down the apropriate sides + // node is just a decision point, so go down the apropriate sides - // find which side of the node we are on - dot = (node->plane->type < 3 ? modelorg[node->plane->type] : DotProduct (modelorg, node->plane->normal)) - node->plane->dist; + // find which side of the node we are on + side = PlaneDist(modelorg, node->plane) < node->plane->dist; - // recurse down the children, front side first - side = dot < 0; + // recurse down the children, front side first if (node->children[side]->visframe == r_visframecount && R_NotCulledBox(node->children[side]->minmaxs, node->children[side]->minmaxs+3)) { - nodestack[s].node = node; - nodestack[s++].dot = dot; + nstack->node = node; + nstack->side = !side; // go down back side when we come back up + nstack++; node = node->children[side]; continue; } + side = !side; loc0: - // backside - side = dot >= 0; // draw stuff - if ((c = node->numsurfaces)) + if (node->numsurfaces) { - msurface_t *surf; surf = cl.worldmodel->surfaces + node->firstsurface; + endsurf = surf + node->numsurfaces; - if (side) + if (texsort) { - for (;c;c--, surf++) + if (side) { - if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK)) + do { - if (gl_texsort.value) + if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK)) { surf->texturechain = surf->texinfo->texture->texturechain; surf->texinfo->texture->texturechain = surf; } - else - R_DrawSurf(surf, false, gl_vertex.value); + surf++; } + while (surf < endsurf); } - } - else - { - for (;c;c--, surf++) + else { - if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK)) + do { - if (gl_texsort.value) + if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK)) { surf->texturechain = surf->texinfo->texture->texturechain; surf->texinfo->texture->texturechain = surf; } - else - R_DrawSurf(surf, false, gl_vertex.value); + surf++; + } + while (surf < endsurf); + } + } + else + { + if (side) + { + do + { + if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK)) + R_DrawSurf(surf, false, vertex); + surf++; + } + while (surf < endsurf); + } + else + { + do + { + if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK)) + R_DrawSurf(surf, false, vertex); + surf++; } + while (surf < endsurf); } } } @@ -941,10 +967,11 @@ loc0: continue; } - if (!s) + if (nstack <= nodestack) break; - node = nodestack[--s].node; - dot = nodestack[s].dot; + nstack--; + node = nstack->node; + side = nstack->side; goto loc0; } } @@ -1048,7 +1075,7 @@ void R_MarkLeaves (void) */ // returns a texture number and the position inside it -int AllocBlock (int w, int h, int *x, int *y) +int AllocBlock (int w, int h, short *x, short *y) { int i, j; int best, best2; diff --git a/glquake.h b/glquake.h index bab055b6..d58f2be5 100644 --- a/glquake.h +++ b/glquake.h @@ -100,7 +100,7 @@ extern vec3_t r_origin; extern refdef_t r_refdef; extern mleaf_t *r_viewleaf, *r_oldviewleaf; extern texture_t *r_notexture_mip; -extern int d_lightstylevalue[256]; // 8.8 fraction of base light value +extern unsigned short d_lightstylevalue[256]; // 8.8 fraction of base light value extern qboolean envmap; diff --git a/model_brush.h b/model_brush.h index 49db6dae..ec31becd 100644 --- a/model_brush.h +++ b/model_brush.h @@ -118,7 +118,7 @@ typedef struct msurface_s short texturemins[2]; short extents[2]; - int light_s, light_t; // gl lightmap coordinates + short light_s, light_t; // gl lightmap coordinates glpoly_t *polys; // multiple if warped struct msurface_s *texturechain; @@ -133,9 +133,8 @@ typedef struct msurface_s int lightmaptexturenum; byte styles[MAXLIGHTMAPS]; - int cached_light[MAXLIGHTMAPS]; // values currently used in lightmap -// qboolean cached_dlight; // true if dynamic light in cache - qboolean cached_lighthalf; // LordHavoc: to cause lightmap to be rerendered when lighthalf changes + unsigned short cached_light[MAXLIGHTMAPS]; // values currently used in lightmap + int cached_lighthalf; // LordHavoc: to cause lightmap to be rerendered when lighthalf changes float cached_ambient; // LordHavoc: rerender lightmaps when r_ambient changes byte *samples; // [numstyles*surfsize] } msurface_t;