engine: common: add generic trace_t initialize function

This commit is contained in:
Alibek Omarov 2022-06-26 04:39:15 +03:00
parent 87ce35b32d
commit c076f4ff8e
3 changed files with 22 additions and 24 deletions

View File

@ -40,6 +40,22 @@ int PM_TruePointContents( playermove_t *pmove, const vec3_t p );
int PM_PointContents( playermove_t *pmove, const vec3_t p );
void PM_ConvertTrace( trace_t *out, pmtrace_t *in, edict_t *ent );
static inline void PM_InitTrace( trace_t *trace, const vec3_t end )
{
memset( trace, 0, sizeof( *trace ));
VectorCopy( end, trace->endpos );
trace->allsolid = true;
trace->fraction = 1.0f;
}
static inline void PM_InitPMTrace( pmtrace_t *trace, const vec3_t end )
{
memset( trace, 0, sizeof( *trace ));
VectorCopy( end, trace->endpos );
trace->allsolid = true;
trace->fraction = 1.0f;
}
//
// pm_surface.c
//

View File

@ -446,10 +446,7 @@ pmtrace_t PM_PlayerTraceExt( playermove_t *pmove, vec3_t start, vec3_t end, int
VectorSubtract( end, offset, end_l );
}
memset( &trace_bbox, 0, sizeof( trace_bbox ));
VectorCopy( end, trace_bbox.endpos );
trace_bbox.allsolid = true;
trace_bbox.fraction = 1.0f;
PM_InitPMTrace( &trace_bbox, end );
if( hullcount < 1 )
{
@ -475,10 +472,7 @@ pmtrace_t PM_PlayerTraceExt( playermove_t *pmove, vec3_t start, vec3_t end, int
for( last_hitgroup = 0, j = 0; j < hullcount; j++ )
{
memset( &trace_hitbox, 0, sizeof( trace_hitbox ));
VectorCopy( end, trace_hitbox.endpos );
trace_hitbox.allsolid = true;
trace_hitbox.fraction = 1.0f;
PM_InitPMTrace( &trace_hitbox, end );
PM_RecursiveHullCheck( &hull[j], hull[j].firstclipnode, 0, 1, start_l, end_l, &trace_hitbox );
@ -622,10 +616,7 @@ int PM_TestPlayerPosition( playermove_t *pmove, vec3_t pos, pmtrace_t *ptrace, p
{
pmtrace_t trace;
memset( &trace, 0, sizeof( trace ));
VectorCopy( pos, trace.endpos );
trace.allsolid = true;
trace.fraction = 1.0f;
PM_InitPMTrace( &trace, pos );
// run custom sweep callback
if( pmove->server || Host_IsLocalClient( ))

View File

@ -871,10 +871,7 @@ void SV_ClipMoveToEntity( edict_t *ent, const vec3_t start, vec3_t mins, vec3_t
qboolean rotated, transform_bbox;
matrix4x4 matrix;
memset( trace, 0, sizeof( trace_t ));
VectorCopy( end, trace->endpos );
trace->fraction = 1.0f;
trace->allsolid = 1;
PM_InitTrace( trace, end );
model = SV_ModelHandle( ent->v.modelindex );
@ -945,10 +942,7 @@ void SV_ClipMoveToEntity( edict_t *ent, const vec3_t start, vec3_t mins, vec3_t
for( i = 0; i < hullcount; i++ )
{
memset( &trace_hitbox, 0, sizeof( trace_t ));
VectorCopy( end, trace_hitbox.endpos );
trace_hitbox.fraction = 1.0;
trace_hitbox.allsolid = 1;
PM_InitTrace( &trace_hitbox, end );
PM_RecursiveHullCheck( &hull[i], hull[i].firstclipnode, 0.0f, 1.0f, start_l, end_l, (pmtrace_t *)&trace_hitbox );
@ -1114,10 +1108,7 @@ or custom physics implementation
void SV_CustomClipMoveToEntity( edict_t *ent, const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, trace_t *trace )
{
// initialize custom trace
memset( trace, 0, sizeof( trace_t ));
VectorCopy( end, trace->endpos );
trace->allsolid = true;
trace->fraction = 1.0f;
PM_InitTrace( trace, end );
if( svgame.physFuncs.ClipMoveToEntity != NULL )
{