Browse Source

engine, ref: RefAPI 5. Simplify remap calls

pull/2/head
Alibek Omarov 1 year ago
parent
commit
26d229c8ca
  1. 152
      engine/client/cl_remap.c
  2. 4
      engine/client/client.h
  3. 4
      engine/client/ref_common.c
  4. 7
      engine/ref_api.h
  5. 9
      ref/gl/gl_alias.c
  6. 7
      ref/gl/gl_studio.c
  7. 7
      ref/soft/r_studio.c

152
engine/client/cl_remap.c

@ -78,7 +78,7 @@ CL_CreateRawTextureFromPixels @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ) @@ -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
engine/client/client.h

@ -996,9 +996,7 @@ void CL_EmitEntities( void ); @@ -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 );
//

4
engine/client/ref_common.c

@ -272,10 +272,8 @@ static ref_api_t gEngfuncs = @@ -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,

7
engine/ref_api.h

@ -34,8 +34,9 @@ GNU General Public License for more details. @@ -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 @@ -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 );

9
ref/gl/gl_alias.c

@ -1002,15 +1002,10 @@ R_AliasSetRemapColors @@ -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;
}
}
/*

7
ref/gl/gl_studio.c

@ -2624,13 +2624,8 @@ R_StudioSetRemapColors @@ -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 )

7
ref/soft/r_studio.c

@ -2384,13 +2384,8 @@ R_StudioSetRemapColors @@ -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 )

Loading…
Cancel
Save