Skip to content

Commit

Permalink
engine, ref: RefAPI 5. Simplify remap calls
Browse files Browse the repository at this point in the history
  • Loading branch information
a1batross committed Dec 5, 2023
1 parent f2be9f8 commit a7a10bf
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 96 deletions.
152 changes: 85 additions & 67 deletions engine/client/cl_remap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
4 changes: 1 addition & 3 deletions engine/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

//
Expand Down
4 changes: 1 addition & 3 deletions engine/client/ref_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions engine/ref_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 2 additions & 7 deletions ref/gl/gl_alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/*
Expand Down
7 changes: 1 addition & 6 deletions ref/gl/gl_studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
7 changes: 1 addition & 6 deletions ref/soft/r_studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit a7a10bf

Please sign in to comment.