Skip to content

Commit

Permalink
Fix player colors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Oct 27, 2024
1 parent 91f2f85 commit 3d83428
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
10 changes: 10 additions & 0 deletions Quake/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ void CL_PrintEntities_f (void)
}
}

/*
===============
CL_IsPlayerEnt
===============
*/
qboolean CL_IsPlayerEnt (const entity_t *ent)
{
return (uintptr_t)ent - (uintptr_t)(cl_entities + 1) < (uintptr_t)cl.maxclients;
}

/*
===============
CL_SetLightstyle
Expand Down
2 changes: 2 additions & 0 deletions Quake/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ void CL_AdjustAngles (void);
void CL_BaseMove (usercmd_t *cmd);
qboolean CL_InCutscene (void);

qboolean CL_IsPlayerEnt (const entity_t *ent);

void CL_ParseTEnt (void);
void CL_UpdateTEnts (void);

Expand Down
71 changes: 40 additions & 31 deletions Quake/r_alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ typedef struct aliasinstance_s {

struct ibuf_s {
int count;
int skinnum;
entity_t *ent;

struct {
Expand Down Expand Up @@ -298,7 +297,7 @@ void R_FlushAliasInstances (qboolean showtris)
qmodel_t *model;
aliashdr_t *paliashdr;
qboolean alphatest, translucent, oit, md5;
int anim, mode;
int skinnum, anim, mode;
unsigned state;
GLuint buf;
GLbyte *ofs;
Expand All @@ -318,10 +317,18 @@ void R_FlushAliasInstances (qboolean showtris)
// set up textures
//
anim = (int)(cl.time*10) & 3;
textures[0] = paliashdr->gltextures[ibuf.skinnum][anim];
textures[1] = paliashdr->fbtextures[ibuf.skinnum][anim];
skinnum = ibuf.ent->skinnum;
if ((skinnum >= paliashdr->numskins) || (skinnum < 0))
{
Con_DPrintf ("R_DrawAliasModel: no such skin # %d for '%s'\n", skinnum, model->name);
// ericw -- display skin 0 for winquake compatibility
skinnum = 0;
}

textures[0] = paliashdr->gltextures[skinnum][anim];
textures[1] = paliashdr->fbtextures[skinnum][anim];
if (ibuf.ent->colormap != vid.colormap && !gl_nocolors.value)
if (PTR_IN_RANGE (ibuf.ent, cl_entities + 1, cl_entities + cl.maxclients)) /* && !strcmp (ibuf.ent->model->name, "progs/player.mdl") */
if (CL_IsPlayerEnt (ibuf.ent)) /* && !strcmp (ibuf.ent->model->name, "progs/player.mdl") */
textures[0] = playertextures[ibuf.ent - cl_entities - 1];

if (!gl_fullbrights.value)
Expand Down Expand Up @@ -430,6 +437,32 @@ void R_FlushAliasInstances (qboolean showtris)
GL_EndGroup();
}

/*
=================
R_Alias_CanAddToBatch
=================
*/
static qboolean R_Alias_CanAddToBatch (const entity_t *e)
{
// empty batch
if (!ibuf.count)
return true;

// full batch
if (ibuf.count == countof (ibuf.inst))
return false;

// different models/skins
if (ibuf.ent->model != e->model || ibuf.ent->skinnum != e->skinnum)
return false;

// players have custom colors
if (!gl_nocolors.value && CL_IsPlayerEnt (ibuf.ent))
return false;

return true;
}

/*
=================
R_DrawAliasModel_Real
Expand All @@ -438,7 +471,6 @@ R_DrawAliasModel_Real
static void R_DrawAliasModel_Real (entity_t *e, qboolean showtris)
{
aliashdr_t *paliashdr;
int skinnum;
lerpdata_t lerpdata;
float fovscale = 1.0f;
float model_matrix[16];
Expand Down Expand Up @@ -501,19 +533,6 @@ static void R_DrawAliasModel_Real (entity_t *e, qboolean showtris)
rs_aliaspolys += paliashdr->numtris;
R_SetupAliasLighting (e);

//
// set up textures
//
skinnum = e->skinnum;
if ((skinnum >= paliashdr->numskins) || (skinnum < 0))
{
Con_DPrintf ("R_DrawAliasModel: no such skin # %d for '%s'\n", skinnum, e->model->name);
// ericw -- display skin 0 for winquake compatibility
skinnum = 0;
}
if (r_lightmap_cheatsafe || showtris)
skinnum = 0;

//
// draw it
//
Expand All @@ -524,21 +543,11 @@ static void R_DrawAliasModel_Real (entity_t *e, qboolean showtris)
if (showtris)
entalpha = 1.f;

if (ibuf.count)
{
if (ibuf.count == countof(ibuf.inst) ||
ibuf.ent->model != e->model ||
ibuf.skinnum != skinnum)
{
R_FlushAliasInstances (showtris);
}
}
if (!R_Alias_CanAddToBatch (e))
R_FlushAliasInstances (showtris);

if (!ibuf.count)
{
ibuf.ent = e;
ibuf.skinnum = skinnum;
}

instance = &ibuf.inst[ibuf.count++];

Expand Down

0 comments on commit 3d83428

Please sign in to comment.