From 23ec203375f09526664e5d3f07d1a69fb80c9faf Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 11:56:35 +0200 Subject: [PATCH 01/23] R_RecursiveWorldNode: bikeshedding --- src/engine/renderer/tr_world.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 2698ef71a7..9a18def61a 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -450,14 +450,11 @@ static void R_RecursiveWorldNode( bspNode_t *node, int planeBits, int decalBits // inside can be visible if ( !r_nocull->integer ) { - int i; - int r; - - for ( i = 0; i < FRUSTUM_PLANES; i++ ) + for ( size_t i = 0; i < FRUSTUM_PLANES; i++ ) { if ( planeBits & ( 1 << i ) ) { - r = BoxOnPlaneSide( node->mins, node->maxs, &tr.viewParms.frustums[ 0 ][ i ] ); + int r = BoxOnPlaneSide( node->mins, node->maxs, &tr.viewParms.frustums[ 0 ][ i ] ); if ( r == 2 ) { @@ -477,9 +474,7 @@ static void R_RecursiveWorldNode( bspNode_t *node, int planeBits, int decalBits // ydnar: cull decals if ( decalBits ) { - int i; - - for ( i = 0; i < tr.refdef.numDecalProjectors; i++ ) + for ( int i = 0; i < tr.refdef.numDecalProjectors; i++ ) { if ( decalBits & ( 1 << i ) ) { @@ -500,7 +495,7 @@ static void R_RecursiveWorldNode( bspNode_t *node, int planeBits, int decalBits float d = DotProduct(tr.viewParms.orientation.viewOrigin, node->plane->normal) - node->plane->dist; - uint32_t side = d <= 0; + uint32 side = d <= 0.0; // recurse down the children, front side first R_RecursiveWorldNode( node->children[ side ], planeBits, decalBits ); From 692e8e33e6bd281b68583210deda96681454d554 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 11 May 2024 07:10:02 +0200 Subject: [PATCH 02/23] R_RecursiveWorldNode: bool --- src/engine/renderer/tr_world.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 9a18def61a..f0510a1911 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -495,13 +495,13 @@ static void R_RecursiveWorldNode( bspNode_t *node, int planeBits, int decalBits float d = DotProduct(tr.viewParms.orientation.viewOrigin, node->plane->normal) - node->plane->dist; - uint32 side = d <= 0.0; + bool side = d <= 0.0; // recurse down the children, front side first R_RecursiveWorldNode( node->children[ side ], planeBits, decalBits ); // tail recurse - node = node->children[ side ^ 1 ]; + node = node->children[ !side ]; } while ( true ); From ab961d08724fa669aa2fe552e2e99e1560aea1b4 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 11:58:56 +0200 Subject: [PATCH 03/23] R_CullBox: bikeshedding --- src/engine/renderer/tr_main.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/engine/renderer/tr_main.cpp b/src/engine/renderer/tr_main.cpp index 3b538ec3d9..c6d9f12376 100644 --- a/src/engine/renderer/tr_main.cpp +++ b/src/engine/renderer/tr_main.cpp @@ -337,23 +337,19 @@ Returns CULL_IN, CULL_CLIP, or CULL_OUT */ cullResult_t R_CullBox( vec3_t worldBounds[ 2 ] ) { - bool anyClip; - cplane_t *frust; - int i, r; - if ( r_nocull->integer ) { return cullResult_t::CULL_CLIP; } // check against frustum planes - anyClip = false; + bool anyClip = false; - for ( i = 0; i < FRUSTUM_PLANES; i++ ) + for ( size_t i = 0; i < FRUSTUM_PLANES; i++ ) { - frust = &tr.viewParms.frustums[ 0 ][ i ]; + cplane_t *frust = &tr.viewParms.frustums[ 0 ][ i ]; - r = BoxOnPlaneSide( worldBounds[ 0 ], worldBounds[ 1 ], frust ); + int r = BoxOnPlaneSide( worldBounds[ 0 ], worldBounds[ 1 ], frust ); if ( r == 2 ) { From 589c23bad0356e601b0367f40d154da66b7cea1b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 12:02:41 +0200 Subject: [PATCH 04/23] R_CullBox: iter frust --- src/engine/renderer/tr_main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/engine/renderer/tr_main.cpp b/src/engine/renderer/tr_main.cpp index c6d9f12376..9157fcdf60 100644 --- a/src/engine/renderer/tr_main.cpp +++ b/src/engine/renderer/tr_main.cpp @@ -345,10 +345,11 @@ cullResult_t R_CullBox( vec3_t worldBounds[ 2 ] ) // check against frustum planes bool anyClip = false; - for ( size_t i = 0; i < FRUSTUM_PLANES; i++ ) - { - cplane_t *frust = &tr.viewParms.frustums[ 0 ][ i ]; + cplane_t *frust = &tr.viewParms.frustums[ 0 ][ 0 ]; + cplane_t *lastFrust = frust + FRUSTUM_PLANES; + for ( ; frust < lastFrust; frust++ ) + { int r = BoxOnPlaneSide( worldBounds[ 0 ], worldBounds[ 1 ], frust ); if ( r == 2 ) From 8459794f70e113af1f2d05efc4d85f453820a51e Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:08:50 +0200 Subject: [PATCH 05/23] R_AddLeafSurfaces: bikeshedding --- src/engine/renderer/tr_world.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index f0510a1911..ff031635e9 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -367,10 +367,6 @@ void R_AddBSPModelSurfaces( trRefEntity_t *ent ) static void R_AddLeafSurfaces( bspNode_t *node, int decalBits, int planeBits ) { - int c; - bspSurface_t **mark; - bspSurface_t **view; - tr.pc.c_leafs++; // add to z buffer bounds @@ -405,9 +401,9 @@ static void R_AddLeafSurfaces( bspNode_t *node, int decalBits, int planeBits ) } // add the individual surfaces - mark = tr.world->markSurfaces + node->firstMarkSurface; - c = node->numMarkSurfaces; - view = tr.world->viewSurfaces + node->firstMarkSurface; + bspSurface_t **mark = tr.world->markSurfaces + node->firstMarkSurface; + int c = node->numMarkSurfaces; + bspSurface_t **view = tr.world->viewSurfaces + node->firstMarkSurface; while ( c-- ) { From 478a8b4a9b828c42dcc4b50ffa69d135249883f3 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:09:53 +0200 Subject: [PATCH 06/23] R_AddDecalSurface: bikeshedding --- src/engine/renderer/tr_world.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index ff031635e9..e8ebbe43bd 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -263,13 +263,11 @@ static void R_AddInteractionSurface( bspSurface_t *surf, trRefLight_t *light, in static void R_AddDecalSurface( bspSurface_t *surf, int decalBits ) { - int i; - // add decals if ( decalBits ) { // ydnar: project any decals - for ( i = 0; i < tr.refdef.numDecalProjectors; i++ ) + for ( int i = 0; i < tr.refdef.numDecalProjectors; i++ ) { if ( decalBits & ( 1 << i ) ) { From 4e4145f43f9dfb011a0e6f03352a21b1fcdaa79f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:10:33 +0200 Subject: [PATCH 07/23] R_AddDecalSurface: return --- src/engine/renderer/tr_world.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index e8ebbe43bd..4481c7eb48 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -263,16 +263,17 @@ static void R_AddInteractionSurface( bspSurface_t *surf, trRefLight_t *light, in static void R_AddDecalSurface( bspSurface_t *surf, int decalBits ) { - // add decals - if ( decalBits ) + if ( !decalBits ) { - // ydnar: project any decals - for ( int i = 0; i < tr.refdef.numDecalProjectors; i++ ) + return; + } + + // ydnar: project any decals + for ( int i = 0; i < tr.refdef.numDecalProjectors; i++ ) + { + if ( decalBits & ( 1 << i ) ) { - if ( decalBits & ( 1 << i ) ) - { - R_ProjectDecalOntoSurface( &tr.refdef.decalProjectors[ i ], surf, &tr.world->models[ 0 ] ); - } + R_ProjectDecalOntoSurface( &tr.refdef.decalProjectors[ i ], surf, &tr.world->models[ 0 ] ); } } } From 961e452d1887dba9f4feaa5ce5b89afeab85cece Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:14:06 +0200 Subject: [PATCH 08/23] R_AddDecalSurface: bikeshedding --- src/engine/renderer/tr_decals.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/engine/renderer/tr_decals.cpp b/src/engine/renderer/tr_decals.cpp index 6bdeb76e56..a318d8975b 100644 --- a/src/engine/renderer/tr_decals.cpp +++ b/src/engine/renderer/tr_decals.cpp @@ -846,10 +846,6 @@ adds a decal surface to the scene void R_AddDecalSurface( decal_t *decal ) { - int i; - float fade; - srfDecal_t *srf; - /* early outs */ if ( decal->shader == nullptr || decal->parent->viewCount != tr.viewCountNoReset || tr.refdef.numDecals >= MAX_DECALS ) { @@ -857,20 +853,20 @@ void R_AddDecalSurface( decal_t *decal ) } /* get decal surface */ - srf = &tr.refdef.decals[ tr.refdef.numDecals ]; + srfDecal_t *srf = &tr.refdef.decals[ tr.refdef.numDecals ]; tr.refdef.numDecals++; /* set it up */ srf->surfaceType = surfaceType_t::SF_DECAL; srf->numVerts = decal->numVerts; - memcpy( srf->verts, decal->verts, srf->numVerts * sizeof( *srf->verts ) ); + memcpy( srf->verts, decal->verts, srf->numVerts * sizeof( polyVert_t ) ); /* fade colors */ if ( decal->fadeStartTime < tr.refdef.time && decal->fadeStartTime < decal->fadeEndTime ) { - fade = ( float )( decal->fadeEndTime - tr.refdef.time ) / ( float )( decal->fadeEndTime - decal->fadeStartTime ); + float fade = ( float )( decal->fadeEndTime - tr.refdef.time ) / ( float )( decal->fadeEndTime - decal->fadeStartTime ); - for ( i = 0; i < decal->numVerts; i++ ) + for ( size_t i = 0; i < decal->numVerts; i++ ) { decal->verts[ i ].modulate[ 0 ] *= fade; decal->verts[ i ].modulate[ 1 ] *= fade; From c7a0e8b9880780f86dda11726fc5005594e8953f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:18:17 +0200 Subject: [PATCH 09/23] R_AddDecalSurface: iter vert --- src/engine/renderer/tr_decals.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/engine/renderer/tr_decals.cpp b/src/engine/renderer/tr_decals.cpp index a318d8975b..1022dcd0b1 100644 --- a/src/engine/renderer/tr_decals.cpp +++ b/src/engine/renderer/tr_decals.cpp @@ -866,12 +866,15 @@ void R_AddDecalSurface( decal_t *decal ) { float fade = ( float )( decal->fadeEndTime - tr.refdef.time ) / ( float )( decal->fadeEndTime - decal->fadeStartTime ); - for ( size_t i = 0; i < decal->numVerts; i++ ) + polyVert_t *vert = decal->verts; + polyVert_t *lastVert = vert + decal->numVerts; + + for ( ; vert < lastVert; vert++ ) { - decal->verts[ i ].modulate[ 0 ] *= fade; - decal->verts[ i ].modulate[ 1 ] *= fade; - decal->verts[ i ].modulate[ 2 ] *= fade; - decal->verts[ i ].modulate[ 3 ] *= fade; + vert->modulate[ 0 ] *= fade; + vert->modulate[ 1 ] *= fade; + vert->modulate[ 2 ] *= fade; + vert->modulate[ 3 ] *= fade; } } From ab189bbbfe3730a9d27bf261e051c11d8f1f131f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:24:44 +0200 Subject: [PATCH 10/23] R_AddDrawSurf: bikeshedding --- src/engine/renderer/tr_main.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/engine/renderer/tr_main.cpp b/src/engine/renderer/tr_main.cpp index 9157fcdf60..35bbe4905f 100644 --- a/src/engine/renderer/tr_main.cpp +++ b/src/engine/renderer/tr_main.cpp @@ -1968,14 +1968,11 @@ R_AddDrawSurf */ void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int lightmapNum, int fogNum, bool bspSurface ) { - int index; - drawSurf_t *drawSurf; - // instead of checking for overflow, we just mask the index // so it wraps around - index = tr.refdef.numDrawSurfs & DRAWSURF_MASK; + int index = tr.refdef.numDrawSurfs & DRAWSURF_MASK; - drawSurf = &tr.refdef.drawSurfs[ index ]; + drawSurf_t *drawSurf = &tr.refdef.drawSurfs[ index ]; drawSurf->entity = tr.currentEntity; drawSurf->surface = surface; From edd52ce3722db0d74c9032215220aaa9cd5ce4bb Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:25:40 +0200 Subject: [PATCH 11/23] R_AddDrawSurf: return --- src/engine/renderer/tr_main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/engine/renderer/tr_main.cpp b/src/engine/renderer/tr_main.cpp index 35bbe4905f..3057480633 100644 --- a/src/engine/renderer/tr_main.cpp +++ b/src/engine/renderer/tr_main.cpp @@ -1999,9 +1999,11 @@ void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int lightmapNum, i tr.refdef.numDrawSurfs++; - if ( shader->depthShader != nullptr ) { - R_AddDrawSurf( surface, shader->depthShader, 0, 0, bspSurface ); + if ( !shader->depthShader ) { + return; } + + R_AddDrawSurf( surface, shader->depthShader, 0, 0, bspSurface ); } /* From 726e14ee7e40892963f10b2d43312c8fd11f1c36 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:26:38 +0200 Subject: [PATCH 12/23] R_AddDrawSurf: simplification --- src/engine/renderer/tr_main.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/engine/renderer/tr_main.cpp b/src/engine/renderer/tr_main.cpp index 3057480633..b52b9f784e 100644 --- a/src/engine/renderer/tr_main.cpp +++ b/src/engine/renderer/tr_main.cpp @@ -1979,13 +1979,9 @@ void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int lightmapNum, i drawSurf->shader = shader; drawSurf->bspSurface = bspSurface; - int entityNum; + int entityNum = -1; - if ( tr.currentEntity == &tr.worldEntity ) - { - entityNum = -1; - } - else + if ( tr.currentEntity != &tr.worldEntity ) { entityNum = tr.currentEntity - tr.refdef.entities; } From 29c55fc14e535cadde80d5d5d7d77ee1e71d9eb0 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:28:52 +0200 Subject: [PATCH 13/23] R_PointInLeaf: bikeshedding --- src/engine/renderer/tr_world.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 4481c7eb48..884342c498 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -618,16 +618,12 @@ R_PointInLeaf */ static bspNode_t *R_PointInLeaf( const vec3_t p ) { - bspNode_t *node; - float d; - cplane_t *plane; - if ( !tr.world ) { Sys::Drop( "R_PointInLeaf: bad model" ); } - node = tr.world->nodes; + bspNode_t *node = tr.world->nodes; while ( true ) { @@ -636,8 +632,9 @@ static bspNode_t *R_PointInLeaf( const vec3_t p ) break; } - plane = node->plane; - d = DotProduct( p, plane->normal ) - plane->dist; + cplane_t *plane = node->plane; + + float d = DotProduct( p, plane->normal ) - plane->dist; if ( d > 0 ) { From 812a030e1cec5c2deb592b4cec7698de5589b80a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 13:40:18 +0200 Subject: [PATCH 14/23] R_PointInLeaf: loop --- src/engine/renderer/tr_world.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 884342c498..bd9d02e2af 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -625,13 +625,8 @@ static bspNode_t *R_PointInLeaf( const vec3_t p ) bspNode_t *node = tr.world->nodes; - while ( true ) + while ( node->contents == -1 ) { - if ( node->contents != -1 ) - { - break; - } - cplane_t *plane = node->plane; float d = DotProduct( p, plane->normal ) - plane->dist; From dcaeded5a7f1d30e5bfe71506320c7ef0f0a8633 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 23:38:39 +0200 Subject: [PATCH 15/23] R_PointInLeaf: skip test --- src/engine/renderer/tr_world.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index bd9d02e2af..f4c60a6635 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -631,14 +631,13 @@ static bspNode_t *R_PointInLeaf( const vec3_t p ) float d = DotProduct( p, plane->normal ) - plane->dist; - if ( d > 0 ) - { - node = node->children[ 0 ]; - } - else - { - node = node->children[ 1 ]; - } +#if 1 + bool side = d <= 0.0; + node = node->children[ side ]; +#else + if ( d > 0 ) node = node->children[ 0 ]; + else node = node->children[ 1 ]; +#endif } return node; From f561164f6a6afbc981789e3b3b4161b66c6c6c3a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 23:36:02 +0200 Subject: [PATCH 16/23] R_RecursiveInteractionNode: bikeshedding --- src/engine/renderer/tr_world.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index f4c60a6635..fc3bbceaf4 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -514,9 +514,6 @@ R_RecursiveInteractionNode */ static void R_RecursiveInteractionNode( bspNode_t *node, trRefLight_t *light, int planeBits, int interactionBits ) { - int i; - int r; - do { // surfaces that arn't potentially visible may still cast shadows @@ -533,11 +530,11 @@ static void R_RecursiveInteractionNode( bspNode_t *node, trRefLight_t *light, in // can cast shadows into the view frustum if ( !r_nocull->integer ) { - for ( i = 0; i < FRUSTUM_PLANES; i++ ) + for ( size_t i = 0; i < FRUSTUM_PLANES; i++ ) { if ( planeBits & ( 1 << i ) ) { - r = BoxOnPlaneSide( node->mins, node->maxs, &tr.viewParms.frustums[ 0 ][ i ] ); + int r = BoxOnPlaneSide( node->mins, node->maxs, &tr.viewParms.frustums[ 0 ][ i ] ); if ( r == 2 ) { @@ -567,7 +564,7 @@ static void R_RecursiveInteractionNode( bspNode_t *node, trRefLight_t *light, in // node is just a decision point, so go down both sides // since we don't care about sort orders, just go positive to negative - r = BoxOnPlaneSide( light->worldBounds[ 0 ], light->worldBounds[ 1 ], node->plane ); + int r = BoxOnPlaneSide( light->worldBounds[ 0 ], light->worldBounds[ 1 ], node->plane ); switch ( r ) { @@ -593,18 +590,16 @@ static void R_RecursiveInteractionNode( bspNode_t *node, trRefLight_t *light, in { // leaf node, so add mark surfaces - int c; - bspSurface_t *surf, **mark; // add the individual surfaces - mark = tr.world->markSurfaces + node->firstMarkSurface; - c = node->numMarkSurfaces; + bspSurface_t **mark = tr.world->markSurfaces + node->firstMarkSurface; + int c = node->numMarkSurfaces; while ( c-- ) { // the surface may have already been added if it // spans multiple leafs - surf = *mark; + bspSurface_t *surf = *mark; R_AddInteractionSurface( surf, light, interactionBits ); mark++; } From 38c67c72d9e5445e225e04380b2d80de953744f8 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 23:36:22 +0200 Subject: [PATCH 17/23] R_RecursiveInteractionNode: skip test --- src/engine/renderer/tr_world.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index fc3bbceaf4..12d7d36483 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -566,6 +566,16 @@ static void R_RecursiveInteractionNode( bspNode_t *node, trRefLight_t *light, in // since we don't care about sort orders, just go positive to negative int r = BoxOnPlaneSide( light->worldBounds[ 0 ], light->worldBounds[ 1 ], node->plane ); +#if 1 + if ( r > 2 ) + { + // recurse down the children, front side first + R_RecursiveInteractionNode( node->children[ 0 ], light, planeBits, interactionBits ); + } + + bool side = r > 1; + node = node->children[ side ]; +#else switch ( r ) { case 1: @@ -585,6 +595,7 @@ static void R_RecursiveInteractionNode( bspNode_t *node, trRefLight_t *light, in node = node->children[ 1 ]; break; } +#endif } while ( true ); From 4203d426986f4f14bb10dd77a4b3e6ff850e95e3 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 May 2024 23:41:26 +0200 Subject: [PATCH 18/23] R_inPVS: direct return --- src/engine/renderer/tr_world.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 12d7d36483..f585456309 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -693,12 +693,7 @@ bool R_inPVS( const vec3_t p1, const vec3_t p2 ) vis = R_ClusterPVS( leaf->cluster ); leaf = R_PointInLeaf( p2 ); - if ( !( vis[ leaf->cluster >> 3 ] & ( 1 << ( leaf->cluster & 7 ) ) ) ) - { - return false; - } - - return true; + return ( vis[ leaf->cluster >> 3 ] & ( 1 << ( leaf->cluster & 7 ) ) ); } /* From 6644410f828fd373c72c56df46a5c6d10f82767f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 11 May 2024 07:11:05 +0200 Subject: [PATCH 19/23] R_inPVVS: direct return --- src/engine/renderer/tr_world.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index f585456309..1a999d49a6 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -710,12 +710,7 @@ bool R_inPVVS( const vec3_t p1, const vec3_t p2 ) vis = R_ClusterPVVS( leaf->cluster ); leaf = R_PointInLeaf( p2 ); - if ( !( vis[ leaf->cluster >> 3 ] & ( 1 << ( leaf->cluster & 7 ) ) ) ) - { - return false; - } - - return true; + return ( vis[ leaf->cluster >> 3 ] & ( 1 << ( leaf->cluster & 7 ) ) ); } /* From 73ef9c2f8a3064e5ba016fe5ab0ac7dfd2baad5f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 11 May 2024 00:00:54 +0200 Subject: [PATCH 20/23] R_AddPrecachedWorldInteractions: simplifies --- src/engine/renderer/tr_world.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 1a999d49a6..3e9af623b8 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -1038,10 +1038,8 @@ void R_AddPrecachedWorldInteractions( trRefLight_t *light ) { continue; } - else - { - iaType = IA_SHADOW; - } + + iaType = IA_SHADOW; } else { @@ -1073,10 +1071,8 @@ void R_AddPrecachedWorldInteractions( trRefLight_t *light ) { continue; } - else - { - iaType = IA_SHADOW; - } + + iaType = IA_SHADOW; } else { From 17f868d6cd4a94ae3b825ff02dac6032fecacc73 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 11 May 2024 00:07:44 +0200 Subject: [PATCH 21/23] R_AddWorldSurfaces: iter node --- src/engine/renderer/tr_world.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 3e9af623b8..3879399499 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -875,10 +875,10 @@ void R_AddWorldSurfaces() // render sky or world? if ( tr.refdef.rdflags & RDF_SKYBOXPORTAL && tr.world->numSkyNodes > 0 ) { - int i; - bspNode_t **node; + bspNode_t **node = tr.world->skyNodes; + bspNode_t **lastNode = node + tr.world->numSkyNodes; - for ( i = 0, node = tr.world->skyNodes; i < tr.world->numSkyNodes; i++, node++ ) + for ( ; node < lastNode; node++ ) { R_AddLeafSurfaces( *node, 0, FRUSTUM_CLIPALL ); // no decals on skybox nodes } From ac7340fda2f595e4ebf4a57a0d67877b182a929e Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 11 May 2024 00:09:25 +0200 Subject: [PATCH 22/23] R_AddWorldSurfaces: simplifies --- src/engine/renderer/tr_world.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 3879399499..3d0283ec94 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -882,21 +882,21 @@ void R_AddWorldSurfaces() { R_AddLeafSurfaces( *node, 0, FRUSTUM_CLIPALL ); // no decals on skybox nodes } + + return; } - else - { - // determine which leaves are in the PVS / areamask - R_MarkLeaves(); - // clear traversal list - backEndData[ tr.smpFrame ]->traversalLength = 0; + // determine which leaves are in the PVS / areamask + R_MarkLeaves(); - // update visbounds and add surfaces that weren't cached with VBOs - R_RecursiveWorldNode( tr.world->nodes, FRUSTUM_CLIPALL, tr.refdef.decalBits ); + // clear traversal list + backEndData[ tr.smpFrame ]->traversalLength = 0; - // ydnar: add decal surfaces - R_AddDecalSurfaces( tr.world->models ); - } + // update visbounds and add surfaces that weren't cached with VBOs + R_RecursiveWorldNode( tr.world->nodes, FRUSTUM_CLIPALL, tr.refdef.decalBits ); + + // ydnar: add decal surfaces + R_AddDecalSurfaces( tr.world->models ); } /* From f122bc9baa2d57b0bcbbd41a7f785aa2ccb47275 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 11 May 2024 00:45:17 +0200 Subject: [PATCH 23/23] R_MarkLeaves: memset --- src/engine/renderer/tr_world.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 3d0283ec94..614771ad75 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -745,9 +745,7 @@ static void R_MarkLeaves() // hasn't changed, we don't need to mark everything again if( tr.refdef.areamaskModified ) { // remark ALL cached visClusters - for ( i = 0; i < MAX_VISCOUNTS; i++ ) { - tr.visClusters[ i ] = -1; - } + memset( tr.visClusters, -1, MAX_VISCOUNTS * sizeof( int ) ); tr.visIndex = 0; } else { for ( i = 0; i < MAX_VISCOUNTS; i++ ) {