engine: consolidate all box clipnodes used in studio models, pmove and server in a single place

This commit is contained in:
Alibek Omarov 2025-01-08 08:17:21 +03:00
parent e70ba7ad64
commit a0b46da04b
5 changed files with 45 additions and 80 deletions

View file

@ -385,6 +385,35 @@ static const mlumpinfo_t extlumps[EXTRA_LUMPS] =
},
};
#define BOX_CLIPNODES_INITIALIZER \
{ \
.planenum = 0, \
.children = { CONTENTS_EMPTY, 1 }, \
}, \
{ \
.planenum = 1, \
.children = { 2, CONTENTS_EMPTY }, \
}, \
{ \
.planenum = 2, \
.children = { CONTENTS_EMPTY, 3 }, \
}, \
{ \
.planenum = 3, \
.children = { 4, CONTENTS_EMPTY }, \
}, \
{ \
.planenum = 4, \
.children = { CONTENTS_EMPTY, 5 }, \
}, \
{ \
.planenum = 5, \
.children = { CONTENTS_SOLID, CONTENTS_EMPTY }, \
}, \
const mclipnode16_t box_clipnodes16[6] = { BOX_CLIPNODES_INITIALIZER };
const mclipnode32_t box_clipnodes32[6] = { BOX_CLIPNODES_INITIALIZER };
/*
===============================================================================

View file

@ -135,6 +135,8 @@ extern poolhandle_t com_studiocache;
extern convar_t mod_studiocache;
extern convar_t r_wadtextures;
extern convar_t r_showhull;
extern const mclipnode16_t box_clipnodes16[6];
extern const mclipnode32_t box_clipnodes32[6];
//
// model.c

View file

@ -50,10 +50,8 @@ static matrix3x4 studio_bones[MAXSTUDIOBONES];
static uint studio_hull_hitgroup[MAXSTUDIOBONES];
static uint cache_hull_hitgroup[MAXSTUDIOBONES];
static mstudiocache_t cache_studio[STUDIO_CACHESIZE];
static mclipnode16_t studio_clipnodes16[6];
static mclipnode32_t studio_clipnodes32[6];
static mplane_t studio_planes[768];
static mplane_t cache_planes[768];
static mplane_t studio_planes[MAXSTUDIOBONES * 6];
static mplane_t cache_planes[MAXSTUDIOBONES * 6];
// current cache state
static int cache_current;
@ -67,36 +65,14 @@ Mod_InitStudioHull
*/
void Mod_InitStudioHull( void )
{
int i, side;
int i;
if( studio_hull[0].planes != NULL )
return; // already initailized
for( i = 0; i < 6; i++ )
{
studio_clipnodes16[i].planenum = i;
studio_clipnodes32[i].planenum = i;
side = i & 1;
studio_clipnodes16[i].children[side] = CONTENTS_EMPTY;
studio_clipnodes32[i].children[side] = CONTENTS_EMPTY;
if( i != 5 )
{
studio_clipnodes16[i].children[side^1] = i + 1;
studio_clipnodes32[i].children[side^1] = i + 1;
}
else
{
studio_clipnodes16[i].children[side^1] = CONTENTS_SOLID;
studio_clipnodes32[i].children[side^1] = CONTENTS_SOLID;
}
}
for( i = 0; i < MAXSTUDIOBONES; i++ )
{
studio_hull[i].clipnodes16 = studio_clipnodes16;
studio_hull[i].clipnodes16 = (mclipnode16_t *)box_clipnodes16;
studio_hull[i].planes = &studio_planes[i*6];
studio_hull[i].firstclipnode = 0;
studio_hull[i].lastclipnode = 5;
@ -283,9 +259,9 @@ hull_t *Mod_HullForStudio( model_t *model, float frame, int sequence, vec3_t ang
for( i = j = 0; i < mod_studiohdr->numhitboxes; i++, j += 6 )
{
if( world.version == QBSP2_VERSION )
studio_hull[i].clipnodes32 = studio_clipnodes32;
studio_hull[i].clipnodes32 = (mclipnode32_t *)box_clipnodes32;
else
studio_hull[i].clipnodes16 = studio_clipnodes16;
studio_hull[i].clipnodes16 = (mclipnode16_t *)box_clipnodes16;
if( bSkipShield && i == 21 )
continue; // CS stuff

View file

@ -25,8 +25,6 @@ GNU General Public License for more details.
#define PM_AllowHitBoxTrace( model, hull ) ( model && model->type == mod_studio && ( FBitSet( model->flags, STUDIO_TRACE_HITBOX ) || hull == 2 ))
static mplane_t pm_boxplanes[6];
static mclipnode16_t pm_boxclipnodes16[6];
static mclipnode32_t pm_boxclipnodes32[6];
static hull_t pm_boxhull;
// default hullmins
@ -66,34 +64,15 @@ can just be stored out and get a proper hull_t structure.
*/
void PM_InitBoxHull( void )
{
int i, side;
int i;
pm_boxhull.clipnodes16 = pm_boxclipnodes16;
pm_boxhull.clipnodes16 = (mclipnode16_t *)box_clipnodes16;
pm_boxhull.planes = pm_boxplanes;
pm_boxhull.firstclipnode = 0;
pm_boxhull.lastclipnode = 5;
for( i = 0; i < 6; i++ )
{
pm_boxclipnodes16[i].planenum = i;
pm_boxclipnodes32[i].planenum = i;
side = i & 1;
pm_boxclipnodes16[i].children[side] = CONTENTS_EMPTY;
pm_boxclipnodes32[i].children[side] = CONTENTS_EMPTY;
if( i != 5 )
{
pm_boxclipnodes16[i].children[side^1] = i + 1;
pm_boxclipnodes32[i].children[side^1] = i + 1;
}
else
{
pm_boxclipnodes16[i].children[side^1] = CONTENTS_SOLID;
pm_boxclipnodes32[i].children[side^1] = i + 1;
}
pm_boxplanes[i].type = i>>1;
pm_boxplanes[i].normal[i>>1] = 1.0f;
pm_boxplanes[i].signbits = 0;
@ -119,9 +98,9 @@ static hull_t *PM_HullForBox( const vec3_t mins, const vec3_t maxs )
pm_boxplanes[5].dist = mins[2];
if( world.version == QBSP2_VERSION )
pm_boxhull.clipnodes32 = pm_boxclipnodes32;
pm_boxhull.clipnodes32 = (mclipnode32_t *)box_clipnodes32;
else
pm_boxhull.clipnodes16 = pm_boxclipnodes16;
pm_boxhull.clipnodes16 = (mclipnode16_t *)box_clipnodes16;
return &pm_boxhull;
}

View file

@ -41,8 +41,6 @@ HULL BOXES
*/
static hull_t box_hull;
static mclipnode16_t box_clipnodes16[6];
static mclipnode32_t box_clipnodes32[6];
static mplane_t box_planes[6];
/*
@ -55,34 +53,15 @@ can just be stored out and get a proper hull_t structure.
*/
static void SV_InitBoxHull( void )
{
int i, side;
int i;
box_hull.clipnodes16 = box_clipnodes16;
box_hull.clipnodes16 = (mclipnode16_t *)box_clipnodes16;
box_hull.planes = box_planes;
box_hull.firstclipnode = 0;
box_hull.lastclipnode = 5;
for( i = 0; i < 6; i++ )
{
box_clipnodes16[i].planenum = i;
box_clipnodes32[i].planenum = i;
side = i & 1;
box_clipnodes16[i].children[side] = CONTENTS_EMPTY;
box_clipnodes32[i].children[side] = CONTENTS_EMPTY;
if( i != 5 )
{
box_clipnodes16[i].children[side^1] = i + 1;
box_clipnodes32[i].children[side^1] = i + 1;
}
else
{
box_clipnodes16[i].children[side^1] = CONTENTS_SOLID;
box_clipnodes32[i].children[side^1] = CONTENTS_SOLID;
}
box_planes[i].type = i>>1;
box_planes[i].normal[i>>1] = 1;
box_planes[i].signbits = 0;
@ -180,9 +159,9 @@ static hull_t *SV_HullForBox( const vec3_t mins, const vec3_t maxs )
box_planes[5].dist = mins[2];
if( world.version == QBSP2_VERSION )
box_hull.clipnodes32 = box_clipnodes32;
box_hull.clipnodes32 = (mclipnode32_t *)box_clipnodes32;
else
box_hull.clipnodes16 = box_clipnodes16;
box_hull.clipnodes16 = (mclipnode16_t *)box_clipnodes16;
return &box_hull;
}