From 56c19c4f5ac89044765266f658af4ec8d24d8944 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 17 Nov 2024 13:37:32 +0300 Subject: [PATCH] engine: client: make some simple functions, like querying entity by index, getting local player, inline --- engine/client/cl_frame.c | 12 -------- engine/client/cl_game.c | 66 +--------------------------------------- engine/client/client.h | 46 ++++++++++++++++++++++++---- engine/common/common.h | 1 - 4 files changed, 41 insertions(+), 84 deletions(-) diff --git a/engine/client/cl_frame.c b/engine/client/cl_frame.c index be252543..299d4d93 100644 --- a/engine/client/cl_frame.c +++ b/engine/client/cl_frame.c @@ -26,18 +26,6 @@ GNU General Public License for more details. // #define STUDIO_INTERPOLATION_FIX -/* -================== -CL_IsPlayerIndex - -detect player entity -================== -*/ -qboolean CL_IsPlayerIndex( int idx ) -{ - return ( idx >= 1 && idx <= cl.maxclients ); -} - /* ========================================================================= diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 95f45b15..b08f4d9a 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -96,53 +96,6 @@ static const dllfunc_t cdll_new_exports[] = // allowed only in SDK 2.3 and high static void pfnSPR_DrawHoles( int frame, int x, int y, const wrect_t *prc ); -/* -==================== -CL_GetEntityByIndex - -Render callback for studio models -==================== -*/ -cl_entity_t *CL_GetEntityByIndex( int index ) -{ - if( !clgame.entities ) // not in game yet - return NULL; - - if( index < 0 || index >= clgame.maxEntities ) - return NULL; - - if( index == 0 ) - return clgame.entities; - - return CL_EDICT_NUM( index ); -} - -/* -================ -CL_ModelHandle - -get model handle by index -================ -*/ -model_t *CL_ModelHandle( int modelindex ) -{ - if( modelindex < 0 || modelindex >= MAX_MODELS ) - return NULL; - return cl.models[modelindex]; -} - -/* -==================== -CL_IsThirdPerson - -returns true if thirdperson is enabled -==================== -*/ -qboolean CL_IsThirdPerson( void ) -{ - return clgame.dllFuncs.CL_IsThirdPerson() ? true : false; -} - /* ==================== CL_CreatePlaylist @@ -733,23 +686,6 @@ void CL_ParseFinaleCutscene( sizebuf_t *msg, int level ) CL_HudMessage( text->pName ); } -/* -==================== -CL_GetLocalPlayer - -Render callback for studio models -==================== -*/ -cl_entity_t *CL_GetLocalPlayer( void ) -{ - cl_entity_t *player; - - player = CL_EDICT_NUM( cl.playernum + 1 ); - Assert( player != NULL ); - - return player; -} - /* ==================== CL_GetMaxlients @@ -2697,7 +2633,7 @@ pfnGetMovevars ============= */ -movevars_t *pfnGetMoveVars( void ) +static movevars_t *pfnGetMoveVars( void ) { return &clgame.movevars; } diff --git a/engine/client/client.h b/engine/client/client.h index 8fae639f..58ec1177 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -825,9 +825,7 @@ void CL_ClearSpriteTextures( void ); void CL_CenterPrint( const char *text, float y ); void CL_TextMessageParse( byte *pMemFile, int fileSize ); client_textmessage_t *CL_TextMessageGet( const char *pName ); -model_t *CL_ModelHandle( int modelindex ); void NetAPI_CancelAllRequests( void ); -cl_entity_t *CL_GetLocalPlayer( void ); model_t *CL_LoadClientSprite( const char *filename ); model_t *CL_LoadModel( const char *modelname, int *index ); HSPRITE pfnSPR_LoadExt( const char *szPicName, uint texFlags ); @@ -838,13 +836,11 @@ const char *PM_CL_TraceTexture( int ground, float *vstart, float *vend ); int PM_CL_PointContents( const float *p, int *truecontents ); physent_t *pfnGetPhysent( int idx ); struct msurface_s *pfnTraceSurface( int ground, float *vstart, float *vend ); -movevars_t *pfnGetMoveVars( void ); void CL_EnableScissor( scissor_state_t *scissor, int x, int y, int width, int height ); void CL_DisableScissor( scissor_state_t *scissor ); qboolean CL_Scissor( const scissor_state_t *scissor, float *x, float *y, float *width, float *height, float *u0, float *v0, float *u1, float *v1 ); -struct cl_entity_s *CL_GetEntityByIndex( int index ); -_inline cl_entity_t *CL_EDICT_NUM( int n ) +static inline cl_entity_t *CL_EDICT_NUM( int n ) { if( !clgame.entities ) { @@ -859,6 +855,40 @@ _inline cl_entity_t *CL_EDICT_NUM( int n ) return NULL; } +static inline cl_entity_t *CL_GetEntityByIndex( int index ) +{ + if( !clgame.entities ) // not in game yet + return NULL; + + if( index < 0 || index >= clgame.maxEntities ) + return NULL; + + if( index == 0 ) + return clgame.entities; + + return CL_EDICT_NUM( index ); +} + +static inline model_t *CL_ModelHandle( int modelindex ) +{ + return modelindex >= 0 && modelindex < MAX_MODELS ? cl.models[modelindex] : NULL; +} + +static inline qboolean CL_IsThirdPerson( void ) +{ + return clgame.dllFuncs.CL_IsThirdPerson() ? true : false; +} + +static inline cl_entity_t *CL_GetLocalPlayer( void ) +{ + cl_entity_t *player; + + player = CL_EDICT_NUM( cl.playernum + 1 ); + Assert( player != NULL ); + + return player; +} + // // cl_parse.c // @@ -989,9 +1019,13 @@ qboolean CL_GetMovieSpatialization( struct rawchan_s *ch ); void CL_ComputePlayerOrigin( cl_entity_t *clent ); void CL_ProcessPacket( frame_t *frame ); void CL_MoveThirdpersonCamera( void ); -qboolean CL_IsPlayerIndex( int idx ); void CL_EmitEntities( void ); +static inline qboolean CL_IsPlayerIndex( int idx ) +{ + return idx >= 1 && idx <= cl.maxclients ? true : false; +} + // // cl_remap.c // diff --git a/engine/common/common.h b/engine/common/common.h index 4bf40ef4..39045637 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -687,7 +687,6 @@ struct sv_client_s; typedef struct sizebuf_s sizebuf_t; qboolean CL_IsInGame( void ); qboolean CL_IsInConsole( void ); -qboolean CL_IsThirdPerson( void ); qboolean CL_IsIntermission( void ); qboolean CL_Initialized( void ); char *CL_Userinfo( void );