engine: hack mnode_t struct so we can have 24-bit face and children indices to support BSP2 format in runtime

This commit is contained in:
Alibek Omarov
2025-01-08 07:35:22 +03:00
parent ced8744ac9
commit 47aff9e30b
19 changed files with 388 additions and 181 deletions

View File

@@ -112,6 +112,9 @@ msurface_t *PM_RecursiveSurfCheck( model_t *mod, mnode_t *node, vec3_t p1, vec3_
int i, side;
msurface_t *surf;
vec3_t mid;
mnode_t *children[2];
int numsurfaces, firstsurface;
loc0:
if( node->contents < 0 )
return NULL;
@@ -119,15 +122,17 @@ loc0:
t1 = PlaneDiff( p1, node->plane );
t2 = PlaneDiff( p2, node->plane );
node_children( children, node, mod );
if( t1 >= -FRAC_EPSILON && t2 >= -FRAC_EPSILON )
{
node = node->children[0];
node = children[0];
goto loc0;
}
if( t1 < FRAC_EPSILON && t2 < FRAC_EPSILON )
{
node = node->children[1];
node = children[1];
goto loc0;
}
@@ -137,13 +142,15 @@ loc0:
VectorLerp( p1, frac, p2, mid );
if(( surf = PM_RecursiveSurfCheck( mod, node->children[side], p1, mid )) != NULL )
if(( surf = PM_RecursiveSurfCheck( mod, children[side], p1, mid )) != NULL )
return surf;
// walk through real faces
for( i = 0; i < node->numsurfaces; i++ )
numsurfaces = node_numsurfaces( node, mod );
firstsurface = node_firstsurface( node, mod );
for( i = 0; i < numsurfaces; i++ )
{
msurface_t *surf = &mod->surfaces[node->firstsurface + i];
msurface_t *surf = &mod->surfaces[firstsurface + i];
mextrasurf_t *info = surf->info;
mfacebevel_t *fb = info->bevel;
int j, contents;
@@ -172,7 +179,7 @@ loc0:
return NULL; // through the fence
}
return PM_RecursiveSurfCheck( mod, node->children[side^1], mid, p2 );
return PM_RecursiveSurfCheck( mod, children[side^1], mid, p2 );
}
/*
@@ -227,6 +234,9 @@ static int PM_TestLine_r( model_t *mod, mnode_t *node, vec_t p1f, vec_t p2f, con
float frac, midf;
int i, r, side;
vec3_t mid;
mnode_t *children[2];
int numsurfaces, firstsurface;
loc0:
if( node->contents < 0 )
{
@@ -242,15 +252,17 @@ loc0:
front = PlaneDiff( start, node->plane );
back = PlaneDiff( stop, node->plane );
node_children( children, node, mod );
if( front >= -FRAC_EPSILON && back >= -FRAC_EPSILON )
{
node = node->children[0];
node = children[0];
goto loc0;
}
if( front < FRAC_EPSILON && back < FRAC_EPSILON )
{
node = node->children[1];
node = children[1];
goto loc0;
}
@@ -261,7 +273,7 @@ loc0:
VectorLerp( start, frac, stop, mid );
midf = p1f + ( p2f - p1f ) * frac;
r = PM_TestLine_r( mod, node->children[side], p1f, midf, start, mid, trace );
r = PM_TestLine_r( mod, children[side], p1f, midf, start, mid, trace );
if( r != CONTENTS_EMPTY )
{
@@ -272,9 +284,11 @@ loc0:
}
// walk through real faces
for( i = 0; i < node->numsurfaces; i++ )
numsurfaces = node_numsurfaces( node, mod );
firstsurface = node_firstsurface( node, mod );
for( i = 0; i < numsurfaces; i++ )
{
msurface_t *surf = &mod->surfaces[node->firstsurface + i];
msurface_t *surf = &mod->surfaces[firstsurface + i];
mextrasurf_t *info = surf->info;
mfacebevel_t *fb = info->bevel;
int j, contents;
@@ -308,7 +322,7 @@ loc0:
return contents;
}
return PM_TestLine_r( mod, node->children[!side], midf, p2f, mid, stop, trace );
return PM_TestLine_r( mod, children[!side], midf, p2f, mid, stop, trace );
}
int PM_TestLineExt( playermove_t *pmove, physent_t *ents, int numents, const vec3_t start, const vec3_t end, int flags )