Skip to content

Commit

Permalink
engine: common: make some simple functions inlined
Browse files Browse the repository at this point in the history
  • Loading branch information
a1batross committed Oct 14, 2024
1 parent f52c825 commit 43e06cc
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 117 deletions.
19 changes: 0 additions & 19 deletions engine/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,25 +759,6 @@ void GAME_EXPORT COM_FreeFile( void *buffer )
free( buffer );
}

/*
=============
COM_NormalizeAngles
=============
*/
void COM_NormalizeAngles( vec3_t angles )
{
int i;

for( i = 0; i < 3; i++ )
{
if( angles[i] > 180.0f )
angles[i] -= 360.0f;
else if( angles[i] < -180.0f )
angles[i] += 360.0f;
}
}

/*
=============
pfnGetModelType
Expand Down
14 changes: 13 additions & 1 deletion engine/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,25 @@ void UI_ShowConnectionWarning( void );
void Cmd_Null_f( void );
void Rcon_Print( host_redirect_t *rd, const char *pMsg );
qboolean COM_ParseVector( char **pfile, float *v, size_t size );
void COM_NormalizeAngles( vec3_t angles );
int COM_FileSize( const char *filename );
void COM_FreeFile( void *buffer );
int COM_CompareFileTime( const char *filename1, const char *filename2, int *iCompare );
char *va( const char *format, ... ) _format( 1 );
qboolean CRC32_MapFile( dword *crcvalue, const char *filename, qboolean multiplayer );

static inline void COM_NormalizeAngles( vec3_t angles )
{
int i;

for( i = 0; i < 3; i++ )
{
if( angles[i] > 180.0f )
angles[i] -= 360.0f;
else if( angles[i] < -180.0f )
angles[i] += 360.0f;
}
}

#if !XASH_DEDICATED
connprotocol_t CL_Protocol( void );
#else
Expand Down
25 changes: 23 additions & 2 deletions engine/common/pm_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ typedef int (*pfnIgnore)( physent_t *pe ); // custom trace filter
// pm_trace.c
//
void Pmove_Init( void );
void PM_ClearPhysEnts( playermove_t *pmove );
void PM_InitBoxHull( void );
hull_t *PM_HullForBsp( physent_t *pe, playermove_t *pmove, float *offset );
qboolean PM_RecursiveHullCheck( hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, pmtrace_t *trace );
Expand All @@ -40,7 +39,29 @@ struct msurface_s *PM_TraceSurfacePmove( playermove_t *pmove, int ground, float
const char *PM_TraceTexture( playermove_t *pmove, int ground, float *vstart, float *vend );
int PM_PointContentsPmove( playermove_t *pmove, const float *p, int *truecontents );
void PM_StuckTouch( playermove_t *pmove, int hitent, pmtrace_t *tr );
void PM_ConvertTrace( trace_t *out, pmtrace_t *in, edict_t *ent );

static inline void PM_ConvertTrace( trace_t *out, pmtrace_t *in, edict_t *ent )
{
out->allsolid = in->allsolid;
out->startsolid = in->startsolid;
out->inopen = in->inopen;
out->inwater = in->inwater;
out->fraction = in->fraction;
out->plane.dist = in->plane.dist;
out->hitgroup = in->hitgroup;
out->ent = ent;

VectorCopy( in->endpos, out->endpos );
VectorCopy( in->plane.normal, out->plane.normal );
}

static inline void PM_ClearPhysEnts( playermove_t *pmove )
{
pmove->nummoveent = 0;
pmove->numphysent = 0;
pmove->numvisent = 0;
pmove->numtouch = 0;
}

static inline void PM_InitTrace( trace_t *trace, const vec3_t end )
{
Expand Down
23 changes: 0 additions & 23 deletions engine/common/pm_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ void Pmove_Init( void )
memcpy( host.player_maxs, pm_hullmaxs, sizeof( pm_hullmaxs ));
}

void PM_ClearPhysEnts( playermove_t *pmove )
{
pmove->nummoveent = 0;
pmove->numphysent = 0;
pmove->numvisent = 0;
pmove->numtouch = 0;
}

/*
===================
PM_InitBoxHull
Expand Down Expand Up @@ -117,21 +109,6 @@ static hull_t *PM_HullForBox( const vec3_t mins, const vec3_t maxs )
return &pm_boxhull;
}

void PM_ConvertTrace( trace_t *out, pmtrace_t *in, edict_t *ent )
{
out->allsolid = in->allsolid;
out->startsolid = in->startsolid;
out->inopen = in->inopen;
out->inwater = in->inwater;
out->fraction = in->fraction;
out->plane.dist = in->plane.dist;
out->hitgroup = in->hitgroup;
out->ent = ent;

VectorCopy( in->endpos, out->endpos );
VectorCopy( in->plane.normal, out->plane.normal );
}

/*
==================
PM_HullPointContents
Expand Down
69 changes: 0 additions & 69 deletions engine/common/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,6 @@ GNU General Public License for more details.
#include "xash3d_mathlib.h"
#include "studio.h"

/*
==================
World_MoveBounds
==================
*/
void World_MoveBounds( const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, vec3_t boxmins, vec3_t boxmaxs )
{
int i;

for( i = 0; i < 3; i++ )
{
if( end[i] > start[i] )
{
boxmins[i] = start[i] + mins[i] - 1.0f;
boxmaxs[i] = end[i] + maxs[i] + 1.0f;
}
else
{
boxmins[i] = end[i] + mins[i] - 1.0f;
boxmaxs[i] = start[i] + maxs[i] + 1.0f;
}
}
}

trace_t World_CombineTraces( trace_t *cliptrace, trace_t *trace, edict_t *touch )
{
if( trace->allsolid || trace->startsolid || trace->fraction < cliptrace->fraction )
{
trace->ent = touch;

if( cliptrace->startsolid )
{
*cliptrace = *trace;
cliptrace->startsolid = true;
}
else *cliptrace = *trace;
}

return *cliptrace;
}

/*
==================
World_TransformAABB
Expand Down Expand Up @@ -107,31 +66,3 @@ void World_TransformAABB( matrix4x4 transform, const vec3_t mins, const vec3_t m
}
}
}

/*
==================
RankForContents
Used for determine contents priority
==================
*/
int RankForContents( int contents )
{
switch( contents )
{
case CONTENTS_EMPTY: return 0;
case CONTENTS_WATER: return 1;
case CONTENTS_TRANSLUCENT: return 2;
case CONTENTS_CURRENT_0: return 3;
case CONTENTS_CURRENT_90: return 4;
case CONTENTS_CURRENT_180: return 5;
case CONTENTS_CURRENT_270: return 6;
case CONTENTS_CURRENT_UP: return 7;
case CONTENTS_CURRENT_DOWN: return 8;
case CONTENTS_SLIME: return 9;
case CONTENTS_LAVA: return 10;
case CONTENTS_SKY: return 11;
case CONTENTS_SOLID: return 12;
default: return 13; // any user contents has more priority than default
}
}
67 changes: 64 additions & 3 deletions engine/common/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,71 @@ ENTITY AREA CHECKING
#include "lightstyle.h"

// trace common
void World_MoveBounds( const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, vec3_t boxmins, vec3_t boxmaxs );
static inline void World_MoveBounds( const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, vec3_t boxmins, vec3_t boxmaxs )
{
int i;

for( i = 0; i < 3; i++ )
{
if( end[i] > start[i] )
{
boxmins[i] = start[i] + mins[i] - 1.0f;
boxmaxs[i] = end[i] + maxs[i] + 1.0f;
}
else
{
boxmins[i] = end[i] + mins[i] - 1.0f;
boxmaxs[i] = start[i] + maxs[i] + 1.0f;
}
}
}

static inline trace_t World_CombineTraces( trace_t *cliptrace, trace_t *trace, edict_t *touch )
{
if( trace->allsolid || trace->startsolid || trace->fraction < cliptrace->fraction )
{
trace->ent = touch;

if( cliptrace->startsolid )
{
*cliptrace = *trace;
cliptrace->startsolid = true;
}
else *cliptrace = *trace;
}

return *cliptrace;
}

/*
==================
RankForContents
Used for determine contents priority
==================
*/
static inline int RankForContents( int contents )
{
switch( contents )
{
case CONTENTS_EMPTY: return 0;
case CONTENTS_WATER: return 1;
case CONTENTS_TRANSLUCENT: return 2;
case CONTENTS_CURRENT_0: return 3;
case CONTENTS_CURRENT_90: return 4;
case CONTENTS_CURRENT_180: return 5;
case CONTENTS_CURRENT_270: return 6;
case CONTENTS_CURRENT_UP: return 7;
case CONTENTS_CURRENT_DOWN: return 8;
case CONTENTS_SLIME: return 9;
case CONTENTS_LAVA: return 10;
case CONTENTS_SKY: return 11;
case CONTENTS_SOLID: return 12;
default: return 13; // any user contents has more priority than default
}
}

void World_TransformAABB( matrix4x4 transform, const vec3_t mins, const vec3_t maxs, vec3_t outmins, vec3_t outmaxs );
trace_t World_CombineTraces( trace_t *cliptrace, trace_t *trace, edict_t *touch );
int RankForContents( int contents );

#define check_angles( x ) ( (int)x == 90 || (int)x == 180 || (int)x == 270 || (int)x == -90 || (int)x == -180 || (int)x == -270 )

Expand Down

0 comments on commit 43e06cc

Please sign in to comment.