Browse Source

ref_api: fix remap code

pull/2/head
mittorn 5 years ago
parent
commit
2e2a716710
  1. 62
      engine/client/cl_remap.c
  2. 4
      engine/client/client.h
  3. 7
      engine/ref_api.h
  4. 4
      ref_gl/gl_alias.c
  5. 4
      ref_gl/gl_studio.c

62
engine/client/cl_remap.c

@ -98,7 +98,7 @@ CL_DuplicateTexture @@ -98,7 +98,7 @@ CL_DuplicateTexture
Dupliacte texture with remap pixels
====================
*/
void CL_DuplicateTexture( mstudiotexture_t *ptexture, int topcolor, int bottomcolor )
void CL_DuplicateTexture( cl_entity_t *entity, mstudiotexture_t *ptexture, int topcolor, int bottomcolor )
{
const char *name;
texture_t *tx = NULL;
@ -111,12 +111,12 @@ void CL_DuplicateTexture( mstudiotexture_t *ptexture, int topcolor, int bottomco @@ -111,12 +111,12 @@ void CL_DuplicateTexture( mstudiotexture_t *ptexture, int topcolor, int bottomco
// save off the real texture index
index = ptexture->index;
name = ref.dllFuncs.GL_TextureName( index );
Q_snprintf( texname, sizeof( texname ), "#%i_%s", refState.currententity->curstate.number, name + 1 );
Q_snprintf( texname, sizeof( texname ), "#%i_%s", entity->curstate.number, name + 1 );
// search for pixels
for( i = 0; i < refState.currentmodel->numtextures; i++ )
for( i = 0; i < entity->model->numtextures; i++ )
{
tx = refState.currentmodel->textures[i];
tx = entity->model->textures[i];
if( tx->gl_texturenum == index )
break; // found
}
@ -141,7 +141,7 @@ CL_UpdateStudioTexture @@ -141,7 +141,7 @@ CL_UpdateStudioTexture
Update texture top and bottom colors
====================
*/
void CL_UpdateStudioTexture( mstudiotexture_t *ptexture, int topcolor, int bottomcolor )
void CL_UpdateStudioTexture( cl_entity_t *entity, mstudiotexture_t *ptexture, int topcolor, int bottomcolor )
{
rgbdata_t *pic;
texture_t *tx = NULL;
@ -156,7 +156,7 @@ void CL_UpdateStudioTexture( mstudiotexture_t *ptexture, int topcolor, int botto @@ -156,7 +156,7 @@ void CL_UpdateStudioTexture( mstudiotexture_t *ptexture, int topcolor, int botto
origtexname = ref.dllFuncs.GL_TextureName( ptexture->index );
// build name of original texture
Q_strncpy( mdlname, refState.currentmodel->name, sizeof( mdlname ));
Q_strncpy( mdlname, entity->model->name, sizeof( mdlname ));
COM_FileBase( ptexture->name, name );
COM_StripExtension( mdlname );
@ -165,9 +165,9 @@ void CL_UpdateStudioTexture( mstudiotexture_t *ptexture, int topcolor, int botto @@ -165,9 +165,9 @@ void CL_UpdateStudioTexture( mstudiotexture_t *ptexture, int topcolor, int botto
if( !index ) return; // couldn't find texture
// search for pixels
for( i = 0; i < refState.currentmodel->numtextures; i++ )
for( i = 0; i < entity->model->numtextures; i++ )
{
tx = refState.currentmodel->textures[i];
tx = entity->model->textures[i];
if( tx->gl_texturenum == index )
break; // found
}
@ -202,21 +202,21 @@ CL_UpdateAliasTexture @@ -202,21 +202,21 @@ CL_UpdateAliasTexture
Update texture top and bottom colors
====================
*/
void CL_UpdateAliasTexture( unsigned short *texture, int skinnum, int topcolor, int bottomcolor )
void CL_UpdateAliasTexture( cl_entity_t *entity, unsigned short *texture, int skinnum, int topcolor, int bottomcolor )
{
char texname[MAX_QPATH];
rgbdata_t skin, *pic;
texture_t *tx;
if( !texture || !refState.currentmodel->textures )
if( !texture || !entity->model->textures )
return; // no remapinfo in model
tx = refState.currentmodel->textures[skinnum];
tx = entity->model->textures[skinnum];
if( !tx ) return; // missing texture ?
if( *texture == 0 )
{
Q_snprintf( texname, sizeof( texname ), "%s:remap%i_%i", refState.currentmodel->name, skinnum, refState.currententity->index );
Q_snprintf( texname, sizeof( texname ), "%s:remap%i_%i", entity->model->name, skinnum, entity->index );
skin.width = tx->width;
skin.height = tx->height;
skin.depth = skin.numMips = 1;
@ -242,7 +242,7 @@ Allocate new remap info per entity @@ -242,7 +242,7 @@ Allocate new remap info per entity
and make copy of remap textures
====================
*/
void CL_AllocRemapInfo( int topcolor, int bottomcolor )
void CL_AllocRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor )
{
remap_info_t *info;
studiohdr_t *phdr;
@ -250,10 +250,10 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) @@ -250,10 +250,10 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor )
mstudiotexture_t *src, *dst;
int i, size;
if( !refState.currententity ) return;
i = ( refState.currententity == &clgame.viewent ) ? clgame.maxEntities : refState.currententity->curstate.number;
if( !entity ) return;
i = ( entity == &clgame.viewent ) ? clgame.maxEntities : entity->curstate.number;
if( !refState.currentmodel || ( refState.currentmodel->type != mod_alias && refState.currentmodel->type != mod_studio ))
if( !entity->model || ( entity->model->type != mod_alias && entity->model->type != mod_studio ))
{
// entity has changed model by another type, release remap info
if( clgame.remap_info[i] )
@ -265,7 +265,7 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) @@ -265,7 +265,7 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor )
}
// model doesn't contains remap textures
if( refState.currentmodel->numtextures <= 0 )
if( entity->model->numtextures <= 0 )
{
// entity has changed model with no remap textures
if( clgame.remap_info[i] )
@ -276,16 +276,16 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) @@ -276,16 +276,16 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor )
return;
}
if( refState.currentmodel->type == mod_studio )
if( entity->model->type == mod_studio )
{
phdr = (studiohdr_t *)Mod_StudioExtradata( refState.currentmodel );
phdr = (studiohdr_t *)Mod_StudioExtradata( entity->model );
if( !phdr ) return; // bad model?
src = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex);
dst = (clgame.remap_info[i] ? clgame.remap_info[i]->ptexture : NULL);
// NOTE: we must copy all the structures 'mstudiotexture_t' for easy access when model is rendering
if( !CL_CmpStudioTextures( phdr->numtextures, src, dst ) || clgame.remap_info[i]->model != refState.currentmodel )
if( !CL_CmpStudioTextures( phdr->numtextures, src, dst ) || clgame.remap_info[i]->model != entity->model )
{
// this code catches studiomodel change with another studiomodel with remap textures
// e.g. playermodel 'barney' with playermodel 'gordon'
@ -314,16 +314,16 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) @@ -314,16 +314,16 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor )
for( i = 0; i < info->numtextures; i++ )
{
if( dst[i].flags & STUDIO_NF_COLORMAP )
CL_DuplicateTexture( &dst[i], topcolor, bottomcolor );
CL_DuplicateTexture( entity, &dst[i], topcolor, bottomcolor );
}
}
else if( refState.currentmodel->type == mod_alias )
else if( entity->model->type == mod_alias )
{
ahdr = (aliashdr_t *)Mod_AliasExtradata( refState.currentmodel );
ahdr = (aliashdr_t *)Mod_AliasExtradata( entity->model );
if( !ahdr ) return; // bad model?
// NOTE: we must copy all the structures 'mstudiotexture_t' for easy access when model is rendering
if( !clgame.remap_info[i] || clgame.remap_info[i]->model != refState.currentmodel )
if( !clgame.remap_info[i] || clgame.remap_info[i]->model != entity->model )
{
// this code catches studiomodel change with another studiomodel with remap textures
// e.g. playermodel 'barney' with playermodel 'gordon'
@ -336,10 +336,10 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) @@ -336,10 +336,10 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor )
return;
}
info->numtextures = refState.currentmodel->numtextures;
info->numtextures = entity->model->numtextures;
// alias remapping is easy
CL_UpdateRemapInfo( topcolor, bottomcolor );
CL_UpdateRemapInfo( entity, topcolor, bottomcolor );
}
else
{
@ -347,7 +347,7 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) @@ -347,7 +347,7 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor )
return;
}
info->model = refState.currentmodel;
info->model = entity->model;
}
/*
@ -357,12 +357,12 @@ CL_UpdateRemapInfo @@ -357,12 +357,12 @@ CL_UpdateRemapInfo
Update all remaps per entity
====================
*/
void CL_UpdateRemapInfo( int topcolor, int bottomcolor )
void CL_UpdateRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor )
{
remap_info_t *info;
int i;
i = ( refState.currententity == &clgame.viewent ) ? clgame.maxEntities : refState.currententity->curstate.number;
i = ( entity == &clgame.viewent ) ? clgame.maxEntities : entity->curstate.number;
info = clgame.remap_info[i];
if( !info ) return; // no remap info
@ -374,9 +374,9 @@ void CL_UpdateRemapInfo( int topcolor, int bottomcolor ) @@ -374,9 +374,9 @@ void CL_UpdateRemapInfo( int topcolor, int bottomcolor )
if( info->ptexture != NULL )
{
if( FBitSet( info->ptexture[i].flags, STUDIO_NF_COLORMAP ))
CL_UpdateStudioTexture( &info->ptexture[i], topcolor, bottomcolor );
CL_UpdateStudioTexture( entity, &info->ptexture[i], topcolor, bottomcolor );
}
else CL_UpdateAliasTexture( &info->textures[i], i, topcolor, bottomcolor );
else CL_UpdateAliasTexture( entity, &info->textures[i], i, topcolor, bottomcolor );
}
info->topcolor = topcolor;

4
engine/client/client.h

@ -953,9 +953,9 @@ void CL_EmitEntities( void ); @@ -953,9 +953,9 @@ void CL_EmitEntities( void );
// cl_remap.c
//
remap_info_t *CL_GetRemapInfoForEntity( cl_entity_t *e );
void CL_AllocRemapInfo( int topcolor, int bottomcolor );
void CL_AllocRemapInfo( cl_entity_t *ent, int topcolor, int bottomcolor );
void CL_FreeRemapInfo( remap_info_t *info );
void CL_UpdateRemapInfo( int topcolor, int bottomcolor );
void CL_UpdateRemapInfo( cl_entity_t *ent, int topcolor, int bottomcolor );
void CL_ClearAllRemaps( void );
//

7
engine/ref_api.h

@ -96,9 +96,6 @@ typedef struct ref_globals_s @@ -96,9 +96,6 @@ typedef struct ref_globals_s
vec3_t viewangles;
vec3_t vforward, vright, vup;
cl_entity_t *currententity;
model_t *currentmodel;
// todo: fill this without engine help
// move to local
@ -332,9 +329,9 @@ typedef struct ref_api_s @@ -332,9 +329,9 @@ typedef struct ref_api_s
// remap
struct remap_info_s *(*CL_GetRemapInfoForEntity)( cl_entity_t *e );
void (*CL_AllocRemapInfo)( int topcolor, int bottomcolor );
void (*CL_AllocRemapInfo)( cl_entity_t *ent, int topcolor, int bottomcolor );
void (*CL_FreeRemapInfo)( struct remap_info_s *info );
void (*CL_UpdateRemapInfo)( int topcolor, int bottomcolor );
void (*CL_UpdateRemapInfo)( cl_entity_t *ent, int topcolor, int bottomcolor );
// utils
void (*CL_ExtraUpdate)( void );

4
ref_gl/gl_alias.c

@ -1005,11 +1005,11 @@ R_AliasSetRemapColors @@ -1005,11 +1005,11 @@ R_AliasSetRemapColors
*/
void R_AliasSetRemapColors( int newTop, int newBottom )
{
gEngfuncs.CL_AllocRemapInfo( newTop, newBottom );
gEngfuncs.CL_AllocRemapInfo( RI.currententity, newTop, newBottom );
if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity ))
{
gEngfuncs.CL_UpdateRemapInfo( newTop, newBottom );
gEngfuncs.CL_UpdateRemapInfo( RI.currententity, newTop, newBottom );
m_fDoRemap = true;
}
}

4
ref_gl/gl_studio.c

@ -2672,11 +2672,11 @@ R_StudioSetRemapColors @@ -2672,11 +2672,11 @@ R_StudioSetRemapColors
*/
static void R_StudioSetRemapColors( int newTop, int newBottom )
{
gEngfuncs.CL_AllocRemapInfo( newTop, newBottom );
gEngfuncs.CL_AllocRemapInfo( RI.currententity, newTop, newBottom );
if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity ))
{
gEngfuncs.CL_UpdateRemapInfo( newTop, newBottom );
gEngfuncs.CL_UpdateRemapInfo( RI.currententity, newTop, newBottom );
m_fDoRemap = true;
}
}

Loading…
Cancel
Save