Browse Source

ref_api: fix remap info allocation (fixes #200)

pull/2/head
Velaron 4 years ago committed by Alibek Omarov #SupportRMS
parent
commit
4f31d7504a
  1. 30
      engine/client/cl_remap.c
  2. 2
      engine/client/client.h
  3. 4
      engine/ref_api.h
  4. 2
      ref_gl/gl_alias.c
  5. 2
      ref_gl/gl_studio.c
  6. 2
      ref_soft/r_studio.c

30
engine/client/cl_remap.c

@ -98,7 +98,7 @@ CL_DuplicateTexture
Dupliacte texture with remap pixels Dupliacte texture with remap pixels
==================== ====================
*/ */
void CL_DuplicateTexture( cl_entity_t *entity, mstudiotexture_t *ptexture, int topcolor, int bottomcolor ) void CL_DuplicateTexture( cl_entity_t *entity, model_t *model, mstudiotexture_t *ptexture, int topcolor, int bottomcolor )
{ {
const char *name; const char *name;
texture_t *tx = NULL; texture_t *tx = NULL;
@ -114,9 +114,9 @@ void CL_DuplicateTexture( cl_entity_t *entity, mstudiotexture_t *ptexture, int t
Q_snprintf( texname, sizeof( texname ), "#%i_%s", entity->curstate.number, name + 1 ); Q_snprintf( texname, sizeof( texname ), "#%i_%s", entity->curstate.number, name + 1 );
// search for pixels // search for pixels
for( i = 0; i < entity->model->numtextures; i++ ) for( i = 0; i < model->numtextures; i++ )
{ {
tx = entity->model->textures[i]; tx = model->textures[i];
if( tx->gl_texturenum == index ) if( tx->gl_texturenum == index )
break; // found break; // found
} }
@ -242,7 +242,7 @@ Allocate new remap info per entity
and make copy of remap textures and make copy of remap textures
==================== ====================
*/ */
void CL_AllocRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor ) void CL_AllocRemapInfo( cl_entity_t *entity, model_t *model, int topcolor, int bottomcolor )
{ {
remap_info_t *info; remap_info_t *info;
studiohdr_t *phdr; studiohdr_t *phdr;
@ -253,7 +253,7 @@ void CL_AllocRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor )
if( !entity ) return; if( !entity ) return;
i = ( entity == &clgame.viewent ) ? clgame.maxEntities : entity->curstate.number; i = ( entity == &clgame.viewent ) ? clgame.maxEntities : entity->curstate.number;
if( !entity->model || ( entity->model->type != mod_alias && entity->model->type != mod_studio )) if( !model || ( model->type != mod_alias && model->type != mod_studio ))
{ {
// entity has changed model by another type, release remap info // entity has changed model by another type, release remap info
if( clgame.remap_info[i] ) if( clgame.remap_info[i] )
@ -265,7 +265,7 @@ void CL_AllocRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor )
} }
// model doesn't contains remap textures // model doesn't contains remap textures
if( entity->model->numtextures <= 0 ) if( model->numtextures <= 0 )
{ {
// entity has changed model with no remap textures // entity has changed model with no remap textures
if( clgame.remap_info[i] ) if( clgame.remap_info[i] )
@ -276,16 +276,16 @@ void CL_AllocRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor )
return; return;
} }
if( entity->model->type == mod_studio ) if( model->type == mod_studio )
{ {
phdr = (studiohdr_t *)Mod_StudioExtradata( entity->model ); phdr = (studiohdr_t *)Mod_StudioExtradata( model );
if( !phdr ) return; // bad model? if( !phdr ) return; // bad model?
src = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); src = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex);
dst = (clgame.remap_info[i] ? clgame.remap_info[i]->ptexture : NULL); 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 // 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 != entity->model ) if( !CL_CmpStudioTextures( phdr->numtextures, src, dst ) || clgame.remap_info[i]->model != model )
{ {
// this code catches studiomodel change with another studiomodel with remap textures // this code catches studiomodel change with another studiomodel with remap textures
// e.g. playermodel 'barney' with playermodel 'gordon' // e.g. playermodel 'barney' with playermodel 'gordon'
@ -314,16 +314,16 @@ void CL_AllocRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor )
for( i = 0; i < info->numtextures; i++ ) for( i = 0; i < info->numtextures; i++ )
{ {
if( dst[i].flags & STUDIO_NF_COLORMAP ) if( dst[i].flags & STUDIO_NF_COLORMAP )
CL_DuplicateTexture( entity, &dst[i], topcolor, bottomcolor ); CL_DuplicateTexture( entity, model, &dst[i], topcolor, bottomcolor );
} }
} }
else if( entity->model->type == mod_alias ) else if( model->type == mod_alias )
{ {
ahdr = (aliashdr_t *)Mod_AliasExtradata( entity->model ); ahdr = (aliashdr_t *)Mod_AliasExtradata( model );
if( !ahdr ) return; // bad model? if( !ahdr ) return; // bad model?
// NOTE: we must copy all the structures 'mstudiotexture_t' for easy access when model is rendering // 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 != entity->model ) if( !clgame.remap_info[i] || clgame.remap_info[i]->model != model )
{ {
// this code catches studiomodel change with another studiomodel with remap textures // this code catches studiomodel change with another studiomodel with remap textures
// e.g. playermodel 'barney' with playermodel 'gordon' // e.g. playermodel 'barney' with playermodel 'gordon'
@ -336,7 +336,7 @@ void CL_AllocRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor )
return; return;
} }
info->numtextures = entity->model->numtextures; info->numtextures = model->numtextures;
// alias remapping is easy // alias remapping is easy
CL_UpdateRemapInfo( entity, topcolor, bottomcolor ); CL_UpdateRemapInfo( entity, topcolor, bottomcolor );
@ -347,7 +347,7 @@ void CL_AllocRemapInfo( cl_entity_t *entity, int topcolor, int bottomcolor )
return; return;
} }
info->model = entity->model; info->model = model;
} }
/* /*

2
engine/client/client.h

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

4
engine/ref_api.h

@ -329,9 +329,9 @@ typedef struct ref_api_s
// remap // remap
struct remap_info_s *(*CL_GetRemapInfoForEntity)( cl_entity_t *e ); struct remap_info_s *(*CL_GetRemapInfoForEntity)( cl_entity_t *e );
void (*CL_AllocRemapInfo)( cl_entity_t *ent, int topcolor, int bottomcolor ); void (*CL_AllocRemapInfo)( cl_entity_t *entity, model_t *model, int topcolor, int bottomcolor );
void (*CL_FreeRemapInfo)( struct remap_info_s *info ); void (*CL_FreeRemapInfo)( struct remap_info_s *info );
void (*CL_UpdateRemapInfo)( cl_entity_t *ent, int topcolor, int bottomcolor ); void (*CL_UpdateRemapInfo)( cl_entity_t *entity, int topcolor, int bottomcolor );
// utils // utils
void (*CL_ExtraUpdate)( void ); void (*CL_ExtraUpdate)( void );

2
ref_gl/gl_alias.c

@ -1005,7 +1005,7 @@ R_AliasSetRemapColors
*/ */
void R_AliasSetRemapColors( int newTop, int newBottom ) void R_AliasSetRemapColors( int newTop, int newBottom )
{ {
gEngfuncs.CL_AllocRemapInfo( RI.currententity, newTop, newBottom ); gEngfuncs.CL_AllocRemapInfo( RI.currententity, RI.currentmodel, newTop, newBottom );
if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity )) if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity ))
{ {

2
ref_gl/gl_studio.c

@ -2670,7 +2670,7 @@ R_StudioSetRemapColors
*/ */
static void R_StudioSetRemapColors( int newTop, int newBottom ) static void R_StudioSetRemapColors( int newTop, int newBottom )
{ {
gEngfuncs.CL_AllocRemapInfo( RI.currententity, newTop, newBottom ); gEngfuncs.CL_AllocRemapInfo( RI.currententity, RI.currentmodel, newTop, newBottom );
if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity )) if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity ))
{ {

2
ref_soft/r_studio.c

@ -2434,7 +2434,7 @@ R_StudioSetRemapColors
*/ */
static void R_StudioSetRemapColors( int newTop, int newBottom ) static void R_StudioSetRemapColors( int newTop, int newBottom )
{ {
gEngfuncs.CL_AllocRemapInfo( RI.currententity, newTop, newBottom ); gEngfuncs.CL_AllocRemapInfo( RI.currententity, RI.currentmodel, newTop, newBottom );
if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity )) if( gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity ))
{ {

Loading…
Cancel
Save