Skip to content

Commit 3d83428

Browse files
Fix player colors
1 parent 91f2f85 commit 3d83428

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

Quake/cl_main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ void CL_PrintEntities_f (void)
306306
}
307307
}
308308

309+
/*
310+
===============
311+
CL_IsPlayerEnt
312+
===============
313+
*/
314+
qboolean CL_IsPlayerEnt (const entity_t *ent)
315+
{
316+
return (uintptr_t)ent - (uintptr_t)(cl_entities + 1) < (uintptr_t)cl.maxclients;
317+
}
318+
309319
/*
310320
===============
311321
CL_SetLightstyle

Quake/client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ void CL_AdjustAngles (void);
360360
void CL_BaseMove (usercmd_t *cmd);
361361
qboolean CL_InCutscene (void);
362362

363+
qboolean CL_IsPlayerEnt (const entity_t *ent);
364+
363365
void CL_ParseTEnt (void);
364366
void CL_UpdateTEnts (void);
365367

Quake/r_alias.c

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ typedef struct aliasinstance_s {
6363

6464
struct ibuf_s {
6565
int count;
66-
int skinnum;
6766
entity_t *ent;
6867

6968
struct {
@@ -298,7 +297,7 @@ void R_FlushAliasInstances (qboolean showtris)
298297
qmodel_t *model;
299298
aliashdr_t *paliashdr;
300299
qboolean alphatest, translucent, oit, md5;
301-
int anim, mode;
300+
int skinnum, anim, mode;
302301
unsigned state;
303302
GLuint buf;
304303
GLbyte *ofs;
@@ -318,10 +317,18 @@ void R_FlushAliasInstances (qboolean showtris)
318317
// set up textures
319318
//
320319
anim = (int)(cl.time*10) & 3;
321-
textures[0] = paliashdr->gltextures[ibuf.skinnum][anim];
322-
textures[1] = paliashdr->fbtextures[ibuf.skinnum][anim];
320+
skinnum = ibuf.ent->skinnum;
321+
if ((skinnum >= paliashdr->numskins) || (skinnum < 0))
322+
{
323+
Con_DPrintf ("R_DrawAliasModel: no such skin # %d for '%s'\n", skinnum, model->name);
324+
// ericw -- display skin 0 for winquake compatibility
325+
skinnum = 0;
326+
}
327+
328+
textures[0] = paliashdr->gltextures[skinnum][anim];
329+
textures[1] = paliashdr->fbtextures[skinnum][anim];
323330
if (ibuf.ent->colormap != vid.colormap && !gl_nocolors.value)
324-
if (PTR_IN_RANGE (ibuf.ent, cl_entities + 1, cl_entities + cl.maxclients)) /* && !strcmp (ibuf.ent->model->name, "progs/player.mdl") */
331+
if (CL_IsPlayerEnt (ibuf.ent)) /* && !strcmp (ibuf.ent->model->name, "progs/player.mdl") */
325332
textures[0] = playertextures[ibuf.ent - cl_entities - 1];
326333

327334
if (!gl_fullbrights.value)
@@ -430,6 +437,32 @@ void R_FlushAliasInstances (qboolean showtris)
430437
GL_EndGroup();
431438
}
432439

440+
/*
441+
=================
442+
R_Alias_CanAddToBatch
443+
=================
444+
*/
445+
static qboolean R_Alias_CanAddToBatch (const entity_t *e)
446+
{
447+
// empty batch
448+
if (!ibuf.count)
449+
return true;
450+
451+
// full batch
452+
if (ibuf.count == countof (ibuf.inst))
453+
return false;
454+
455+
// different models/skins
456+
if (ibuf.ent->model != e->model || ibuf.ent->skinnum != e->skinnum)
457+
return false;
458+
459+
// players have custom colors
460+
if (!gl_nocolors.value && CL_IsPlayerEnt (ibuf.ent))
461+
return false;
462+
463+
return true;
464+
}
465+
433466
/*
434467
=================
435468
R_DrawAliasModel_Real
@@ -438,7 +471,6 @@ R_DrawAliasModel_Real
438471
static void R_DrawAliasModel_Real (entity_t *e, qboolean showtris)
439472
{
440473
aliashdr_t *paliashdr;
441-
int skinnum;
442474
lerpdata_t lerpdata;
443475
float fovscale = 1.0f;
444476
float model_matrix[16];
@@ -501,19 +533,6 @@ static void R_DrawAliasModel_Real (entity_t *e, qboolean showtris)
501533
rs_aliaspolys += paliashdr->numtris;
502534
R_SetupAliasLighting (e);
503535

504-
//
505-
// set up textures
506-
//
507-
skinnum = e->skinnum;
508-
if ((skinnum >= paliashdr->numskins) || (skinnum < 0))
509-
{
510-
Con_DPrintf ("R_DrawAliasModel: no such skin # %d for '%s'\n", skinnum, e->model->name);
511-
// ericw -- display skin 0 for winquake compatibility
512-
skinnum = 0;
513-
}
514-
if (r_lightmap_cheatsafe || showtris)
515-
skinnum = 0;
516-
517536
//
518537
// draw it
519538
//
@@ -524,21 +543,11 @@ static void R_DrawAliasModel_Real (entity_t *e, qboolean showtris)
524543
if (showtris)
525544
entalpha = 1.f;
526545

527-
if (ibuf.count)
528-
{
529-
if (ibuf.count == countof(ibuf.inst) ||
530-
ibuf.ent->model != e->model ||
531-
ibuf.skinnum != skinnum)
532-
{
533-
R_FlushAliasInstances (showtris);
534-
}
535-
}
546+
if (!R_Alias_CanAddToBatch (e))
547+
R_FlushAliasInstances (showtris);
536548

537549
if (!ibuf.count)
538-
{
539550
ibuf.ent = e;
540-
ibuf.skinnum = skinnum;
541-
}
542551

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

0 commit comments

Comments
 (0)