diff --git a/engine/client/cl_remap.c b/engine/client/cl_remap.c index 00fb2dcd..c16f58c1 100644 --- a/engine/client/cl_remap.c +++ b/engine/client/cl_remap.c @@ -78,7 +78,7 @@ CL_CreateRawTextureFromPixels Convert texture_t struct into mstudiotexture_t prototype ==================== */ -byte *CL_CreateRawTextureFromPixels( texture_t *tx, size_t *size, int topcolor, int bottomcolor ) +static byte *CL_CreateRawTextureFromPixels( texture_t *tx, size_t *size, int topcolor, int bottomcolor ) { static mstudiotexture_t pin; byte *pal; @@ -111,7 +111,7 @@ CL_DuplicateTexture Dupliacte texture with remap pixels ==================== */ -void CL_DuplicateTexture( cl_entity_t *entity, model_t *model, mstudiotexture_t *ptexture, int topcolor, int bottomcolor ) +static void CL_DuplicateTexture( cl_entity_t *entity, model_t *model, mstudiotexture_t *ptexture, int topcolor, int bottomcolor ) { const char *name; texture_t *tx = NULL; @@ -154,7 +154,7 @@ CL_UpdateStudioTexture Update texture top and bottom colors ==================== */ -void CL_UpdateStudioTexture( cl_entity_t *entity, mstudiotexture_t *ptexture, int topcolor, int bottomcolor ) +static void CL_UpdateStudioTexture( cl_entity_t *entity, mstudiotexture_t *ptexture, int topcolor, int bottomcolor ) { rgbdata_t *pic; texture_t *tx = NULL; @@ -215,7 +215,7 @@ CL_UpdateAliasTexture Update texture top and bottom colors ==================== */ -void CL_UpdateAliasTexture( cl_entity_t *entity, unsigned short *texture, int skinnum, int topcolor, int bottomcolor ) +static void CL_UpdateAliasTexture( cl_entity_t *entity, unsigned short *texture, int skinnum, int topcolor, int bottomcolor ) { char texname[MAX_QPATH]; rgbdata_t skin, *pic; @@ -247,6 +247,68 @@ void CL_UpdateAliasTexture( cl_entity_t *entity, unsigned short *texture, int sk ref.dllFuncs.GL_ProcessTexture( *texture, -1.0f, topcolor, bottomcolor ); } +/* +==================== +CL_FreeRemapInfo + +Release remap info per entity +==================== +*/ +static void CL_FreeRemapInfo( remap_info_t *info ) +{ + int i; + + Assert( info != NULL ); + + // release all colormap texture copies + for( i = 0; i < info->numtextures; i++ ) + { + if( info->ptexture != NULL ) + { + if( FBitSet( info->ptexture[i].flags, STUDIO_NF_COLORMAP )) + ref.dllFuncs.GL_FreeTexture( info->ptexture[i].index ); + } + + if( info->textures[i] != 0 ) + ref.dllFuncs.GL_FreeTexture( info->textures[i] ); + } + + Mem_Free( info ); // release struct +} + +/* +==================== +CL_UpdateRemapInfo + +Update all remaps per entity +==================== +*/ +static void CL_UpdateRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor ) +{ + remap_info_t *info; + int i; + + i = ( entity == &clgame.viewent ) ? clgame.maxEntities : entity->curstate.number; + info = clgame.remap_info[i]; + if( !info ) return; // no remap info + + if( info->topcolor == topcolor && info->bottomcolor == bottomcolor ) + return; // values is valid + + for( i = 0; i < info->numtextures; i++ ) + { + if( info->ptexture != NULL ) + { + if( FBitSet( info->ptexture[i].flags, STUDIO_NF_COLORMAP )) + CL_UpdateStudioTexture( entity, &info->ptexture[i], topcolor, bottomcolor ); + } + else CL_UpdateAliasTexture( entity, &info->textures[i], i, topcolor, bottomcolor ); + } + + info->topcolor = topcolor; + info->bottomcolor = bottomcolor; +} + /* ==================== CL_AllocRemapInfo @@ -255,7 +317,7 @@ Allocate new remap info per entity and make copy of remap textures ==================== */ -void CL_AllocRemapInfo( cl_entity_t *entity, model_t *model, int topcolor, int bottomcolor ) +static void CL_AllocRemapInfo( cl_entity_t *entity, model_t *model, int topcolor, int bottomcolor ) { remap_info_t *info; studiohdr_t *phdr; @@ -362,68 +424,6 @@ void CL_AllocRemapInfo( cl_entity_t *entity, model_t *model, int topcolor, int b info->model = model; } -/* -==================== -CL_UpdateRemapInfo - -Update all remaps per entity -==================== -*/ -void CL_UpdateRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor ) -{ - remap_info_t *info; - int i; - - i = ( entity == &clgame.viewent ) ? clgame.maxEntities : entity->curstate.number; - info = clgame.remap_info[i]; - if( !info ) return; // no remap info - - if( info->topcolor == topcolor && info->bottomcolor == bottomcolor ) - return; // values is valid - - for( i = 0; i < info->numtextures; i++ ) - { - if( info->ptexture != NULL ) - { - if( FBitSet( info->ptexture[i].flags, STUDIO_NF_COLORMAP )) - CL_UpdateStudioTexture( entity, &info->ptexture[i], topcolor, bottomcolor ); - } - else CL_UpdateAliasTexture( entity, &info->textures[i], i, topcolor, bottomcolor ); - } - - info->topcolor = topcolor; - info->bottomcolor = bottomcolor; -} - -/* -==================== -CL_FreeRemapInfo - -Release remap info per entity -==================== -*/ -void CL_FreeRemapInfo( remap_info_t *info ) -{ - int i; - - Assert( info != NULL ); - - // release all colormap texture copies - for( i = 0; i < info->numtextures; i++ ) - { - if( info->ptexture != NULL ) - { - if( FBitSet( info->ptexture[i].flags, STUDIO_NF_COLORMAP )) - ref.dllFuncs.GL_FreeTexture( info->ptexture[i].index ); - } - - if( info->textures[i] != 0 ) - ref.dllFuncs.GL_FreeTexture( info->textures[i] ); - } - - Mem_Free( info ); // release struct -} - /* ==================== CL_ClearAllRemaps @@ -446,3 +446,21 @@ void CL_ClearAllRemaps( void ) } clgame.remap_info = NULL; } + +/* +============= +CL_EntitySetRemapColors +============= +*/ +qboolean CL_EntitySetRemapColors( cl_entity_t *e, model_t *mod, int top, int bottom ) +{ + CL_AllocRemapInfo( e, mod, top, bottom ); + + if( CL_GetRemapInfoForEntity( e )) + { + CL_UpdateRemapInfo( e, top, bottom ); + return true; + } + + return false; +} diff --git a/engine/client/client.h b/engine/client/client.h index c1e8aba7..a3a3c5d6 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -996,9 +996,7 @@ void CL_EmitEntities( void ); // cl_remap.c // remap_info_t *CL_GetRemapInfoForEntity( cl_entity_t *e ); -void CL_AllocRemapInfo( cl_entity_t *entity, model_t *model, int topcolor, int bottomcolor ); -void CL_FreeRemapInfo( remap_info_t *info ); -void CL_UpdateRemapInfo( cl_entity_t *ent, int topcolor, int bottomcolor ); +qboolean CL_EntitySetRemapColors( cl_entity_t *e, model_t *mod, int top, int bottom ); void CL_ClearAllRemaps( void ); // diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 9d89aa81..7b66b5f1 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -272,10 +272,8 @@ static ref_api_t gEngfuncs = pfnMod_Extradata, pfnGetModels, + CL_EntitySetRemapColors, CL_GetRemapInfoForEntity, - CL_AllocRemapInfo, - CL_FreeRemapInfo, - CL_UpdateRemapInfo, CL_ExtraUpdate, Host_Error, diff --git a/engine/ref_api.h b/engine/ref_api.h index 47e89292..722f1ed4 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -34,8 +34,9 @@ GNU General Public License for more details. // 2. FS functions are removed, instead we have full fs_api_t // 3. SlerpBones, CalcBonePosition/Quaternion calls were moved to libpublic/mathlib // 4. R_StudioEstimateFrame now has time argument -// 5. Removed GetSomethingByIndex calls, renderers are supposed to cache pointer values. +// 5. Removed GetSomethingByIndex calls, renderers are supposed to cache pointer values // Removed previously unused calls +// Simplified remapping calls #define REF_API_VERSION 5 @@ -332,10 +333,8 @@ typedef struct ref_api_s struct model_s **(*pfnGetModels)( void ); // remap + qboolean (*CL_EntitySetRemapColors)( cl_entity_t *e, model_t *mod, int top, int bottom ); struct remap_info_s *(*CL_GetRemapInfoForEntity)( cl_entity_t *e ); - void (*CL_AllocRemapInfo)( cl_entity_t *entity, model_t *model, int topcolor, int bottomcolor ); - void (*CL_FreeRemapInfo)( struct remap_info_s *info ); - void (*CL_UpdateRemapInfo)( cl_entity_t *entity, int topcolor, int bottomcolor ); // utils void (*CL_ExtraUpdate)( void ); diff --git a/ref/gl/gl_alias.c b/ref/gl/gl_alias.c index 09103b31..550d5a64 100644 --- a/ref/gl/gl_alias.c +++ b/ref/gl/gl_alias.c @@ -1002,15 +1002,10 @@ R_AliasSetRemapColors =============== */ -void R_AliasSetRemapColors( int newTop, int newBottom ) +static void R_AliasSetRemapColors( int newTop, int newBottom ) { - gEngfuncs.CL_AllocRemapInfo( RI.currententity, RI.currentmodel, newTop, newBottom ); - - if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity )) - { - gEngfuncs.CL_UpdateRemapInfo( RI.currententity, newTop, newBottom ); + if( gEngfuncs.CL_EntitySetRemapColors( RI.currententity, RI.currentmodel, newTop, newBottom )) m_fDoRemap = true; - } } /* diff --git a/ref/gl/gl_studio.c b/ref/gl/gl_studio.c index abea6cfe..6e09674e 100644 --- a/ref/gl/gl_studio.c +++ b/ref/gl/gl_studio.c @@ -2624,13 +2624,8 @@ R_StudioSetRemapColors */ static void R_StudioSetRemapColors( int newTop, int newBottom ) { - gEngfuncs.CL_AllocRemapInfo( RI.currententity, RI.currentmodel, newTop, newBottom ); - - if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity )) - { - gEngfuncs.CL_UpdateRemapInfo( RI.currententity, newTop, newBottom ); + if( gEngfuncs.CL_EntitySetRemapColors( RI.currententity, RI.currentmodel, newTop, newBottom )) m_fDoRemap = true; - } } void R_StudioResetPlayerModels( void ) diff --git a/ref/soft/r_studio.c b/ref/soft/r_studio.c index 1b01ccda..b82c1f5d 100644 --- a/ref/soft/r_studio.c +++ b/ref/soft/r_studio.c @@ -2384,13 +2384,8 @@ R_StudioSetRemapColors */ static void R_StudioSetRemapColors( int newTop, int newBottom ) { - gEngfuncs.CL_AllocRemapInfo( RI.currententity, RI.currentmodel, newTop, newBottom ); - - if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity )) - { - gEngfuncs.CL_UpdateRemapInfo( RI.currententity, newTop, newBottom ); + if( gEngfuncs.CL_EntitySetRemapColors( RI.currententity, RI.currentmodel, newTop, newBottom )) m_fDoRemap = true; - } } void R_StudioResetPlayerModels( void )