Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refapi 5 #1520

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions engine/client/cl_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,12 +1109,12 @@ void CL_InitEdicts( int maxclients )
clgame.remap_info = (remap_info_t **)Mem_Calloc( clgame.mempool, sizeof( remap_info_t* ) * clgame.maxRemapInfos );
}

ref.dllFuncs.R_ProcessEntData( true );
ref.dllFuncs.R_ProcessEntData( true, clgame.entities, clgame.maxEntities );
}

void CL_FreeEdicts( void )
{
ref.dllFuncs.R_ProcessEntData( false );
ref.dllFuncs.R_ProcessEntData( false, NULL, 0 );

if( clgame.entities )
Mem_Free( clgame.entities );
Expand Down
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
26 changes: 10 additions & 16 deletions engine/client/ref_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ static void pfnGetPredictedOrigin( vec3_t v )
VectorCopy( cl.simorg, v );
}

static color24 *pfnCL_GetPaletteColor( int color ) // clgame.palette[color]
static color24 *pfnCL_GetPaletteColor( void ) // clgame.palette[color]
{
return &clgame.palette[color];
return clgame.palette;
}

static void pfnCL_GetScreenInfo( int *width, int *height ) // clgame.scrInfo, ptrs may be NULL
Expand Down Expand Up @@ -158,11 +158,6 @@ static int pfnGetStudioModelInterface( int version, struct r_studio_interface_s
0;
}

static poolhandle_t pfnImage_GetPool( void )
{
return host.imagepool;
}

static const bpc_desc_t *pfnImage_GetPFDesc( int idx )
{
return &PFDesc[idx];
Expand Down Expand Up @@ -212,6 +207,11 @@ static qboolean R_Init_Video_( const int type )
return R_Init_Video( type );
}

static model_t **pfnGetModels( void )
{
return cl.models;
}

static ref_api_t gEngfuncs =
{
pfnEngineGetParm,
Expand Down Expand Up @@ -246,9 +246,7 @@ static ref_api_t gEngfuncs =
Con_DrawString,
CL_DrawCenterPrint,

CL_GetLocalPlayer,
CL_GetViewModel,
CL_GetEntityByIndex,
R_BeamGetEntity,
CL_GetWaterEntity,
CL_AddVisibleEntity,
Expand All @@ -272,20 +270,17 @@ static ref_api_t gEngfuncs =

Mod_ForName,
pfnMod_Extradata,
CL_ModelHandle,
pfnGetModels,

CL_EntitySetRemapColors,
CL_GetRemapInfoForEntity,
CL_AllocRemapInfo,
CL_FreeRemapInfo,
CL_UpdateRemapInfo,

CL_ExtraUpdate,
Host_Error,
COM_SetRandomSeed,
COM_RandomFloat,
COM_RandomLong,
pfnRefGetScreenFade,
CL_TextMessageGet,
pfnGetPredictedOrigin,
pfnCL_GetPaletteColor,
pfnCL_GetScreenInfo,
Expand Down Expand Up @@ -349,7 +344,6 @@ static ref_api_t gEngfuncs =
FS_CopyImage,
FS_FreeImage,
Image_SetMDLPointer,
pfnImage_GetPool,
pfnImage_GetPFDesc,

pfnDrawNormalTriangles,
Expand Down Expand Up @@ -431,7 +425,7 @@ static qboolean R_LoadProgs( const char *name )
// make local copy of engfuncs to prevent overwrite it with user dll
memcpy( &gpEngfuncs, &gEngfuncs, sizeof( gpEngfuncs ));

if( !GetRefAPI( REF_API_VERSION, &ref.dllFuncs, &gpEngfuncs, &refState ))
if( GetRefAPI( REF_API_VERSION, &ref.dllFuncs, &gpEngfuncs, &refState ) != REF_API_VERSION )
{
COM_FreeLibrary( ref.hInstance );
Con_Reportf( "R_LoadProgs: can't init renderer API: wrong version\n" );
Expand Down
22 changes: 11 additions & 11 deletions engine/ref_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ 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
#define REF_API_VERSION 4
// 5. Removed GetSomethingByIndex calls, renderers are supposed to cache pointer values
// Removed previously unused calls
// Simplified remapping calls
// GetRefAPI is now expected to return REF_API_VERSION
#define REF_API_VERSION 5


#define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP)
Expand Down Expand Up @@ -299,9 +303,7 @@ typedef struct ref_api_s
void (*CL_DrawCenterPrint)( void );

// entity management
struct cl_entity_s *(*GetLocalPlayer)( void );
struct cl_entity_s *(*GetViewModel)( void );
struct cl_entity_s *(*GetEntityByIndex)( int idx );
struct cl_entity_s *(*R_BeamGetEntity)( int index );
struct cl_entity_s *(*CL_GetWaterEntity)( const vec3_t p );
qboolean (*CL_AddVisibleEntity)( cl_entity_t *ent, int entityType );
Expand Down Expand Up @@ -329,13 +331,11 @@ typedef struct ref_api_s
// model management
model_t *(*Mod_ForName)( const char *name, qboolean crash, qboolean trackCRC );
void *(*Mod_Extradata)( int type, model_t *model );
struct model_s *(*pfnGetModelByIndex)( int index ); // CL_ModelHandle
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 All @@ -344,9 +344,8 @@ typedef struct ref_api_s
float (*COM_RandomFloat)( float rmin, float rmax );
int (*COM_RandomLong)( int rmin, int rmax );
struct screenfade_s *(*GetScreenFade)( void );
struct client_textmessage_s *(*pfnTextMessageGet)( const char *pName );
void (*GetPredictedOrigin)( vec3_t v );
color24 *(*CL_GetPaletteColor)(int color); // clgame.palette[color]
color24 *(*CL_GetPaletteColor)( void ); // clgame.palette[color]
void (*CL_GetScreenInfo)( int *width, int *height ); // clgame.scrInfo, ptrs may be NULL
void (*SetLocalLightLevel)( int level ); // cl.local.light_level
int (*Sys_CheckParm)( const char *flag );
Expand Down Expand Up @@ -420,7 +419,6 @@ typedef struct ref_api_s
rgbdata_t *(*FS_CopyImage)( rgbdata_t *in );
void (*FS_FreeImage)( rgbdata_t *pack );
void (*Image_SetMDLPointer)( byte *p );
poolhandle_t (*Image_GetPool)( void );
const struct bpc_desc_s *(*Image_GetPFDesc)( int idx );

// client exports
Expand Down Expand Up @@ -449,6 +447,7 @@ typedef struct ref_interface_s
void (*GL_InitExtensions)( void );
void (*GL_ClearExtensions)( void );

// scene rendering
void (*R_BeginFrame)( qboolean clearScene );
void (*R_RenderScene)( void );
void (*R_EndFrame)( void );
Expand All @@ -463,7 +462,8 @@ typedef struct ref_interface_s

qboolean (*R_AddEntity)( struct cl_entity_s *clent, int type );
void (*CL_AddCustomBeam)( cl_entity_t *pEnvBeam );
void (*R_ProcessEntData)( qboolean allocate );
void (*R_ProcessEntData)( qboolean allocate, cl_entity_t *entities, unsigned int max_entities );
void (*R_Flush)( unsigned int flush_flags );

// debug
void (*R_ShowTextures)( void );
Expand Down
Loading
Loading