Skip to content

Commit

Permalink
SERVER: Support FTE_PEXT_COLOURMOD.
Browse files Browse the repository at this point in the history
Allows entities to add three bytes of color modifiers where 0
is unset, 32 is 1.0f thus no color changes, and above 1.0 goes
into overbright territory.
  • Loading branch information
dsvensson committed Nov 13, 2024
1 parent 076fa66 commit 4943850
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/pr2_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,14 @@ void PF2_makestatic(edict_t *ent)
VectorCopy(ent->v->angles, s->angles);
#ifdef FTE_PEXT_TRANS
s->trans = ent->xv.alpha >= 1.0f ? 0 : bound(0, (byte)(ent->xv.alpha * 254.0), 254);
#endif
#ifdef FTE_PEXT_COLOURMOD
if (ent->xv.colourmod[0] != 1.0f && ent->xv.colourmod[1] != 1.0f && ent->xv.colourmod[2] != 1.0f)
{
s->colourmod[0] = bound(0, ent->xv.colourmod[0] * (256.0f / 8.0f), 255);
s->colourmod[1] = bound(0, ent->xv.colourmod[1] * (256.0f / 8.0f), 255);
s->colourmod[2] = bound(0, ent->xv.colourmod[2] * (256.0f / 8.0f), 255);
}
#endif
++sv.static_entity_count;

Expand Down Expand Up @@ -2049,6 +2057,10 @@ static intptr_t EXT_MapExtFieldPtr(intptr_t *args)
{
return offsetof(ext_entvars_t, alpha) | GetExtFieldCookie();
}
if (!strcmp(key, "colormod"))
{
return offsetof(ext_entvars_t, colourmod) | GetExtFieldCookie();
}
}

return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/pr_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,14 @@ void PF_makestatic (void)
VectorCopy(ent->v->angles, s->angles);
#ifdef FTE_PEXT_TRANS
s->trans = ent->xv.alpha >= 1.0f ? 0 : bound(0, (byte)(ent->xv.alpha * 254.0), 254);
#endif
#ifdef FTE_PEXT_COLOURMOD
if (ent->xv.colourmod[0] != 1.0f && ent->xv.colourmod[1] != 1.0f && ent->xv.colourmod[2] != 1.0f)
{
s->colourmod[0] = bound(0, ent->xv.colourmod[0] * (256.0f / 8.0f), 255);
s->colourmod[1] = bound(0, ent->xv.colourmod[1] * (256.0f / 8.0f), 255);
s->colourmod[2] = bound(0, ent->xv.colourmod[2] * (256.0f / 8.0f), 255);
}
#endif
++sv.static_entity_count;

Expand Down
13 changes: 13 additions & 0 deletions src/pr_edict.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,19 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
ent->xv.alpha = bound(0.0f, atof (com_token), 1.0f);
continue;
}
if (!strcmp(keyname, "colormod"))
{
float v[3];
int ret = sscanf(com_token, "%f %f %f", &v[0], &v[1], &v[2]);
if (ret == 3 && v[0] > 0.0f && v[1] > 0.0f && v[2] > 0.0f)
{
ent->xv.colourmod[0] = max(0.0f, v[0]);
ent->xv.colourmod[1] = max(0.0f, v[1]);
ent->xv.colourmod[2] = max(0.0f, v[2]);
}
continue;
}

key = ED_FindField (keyname);
if (!key)
{
Expand Down
1 change: 1 addition & 0 deletions src/progs.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef struct sv_edict_s
typedef struct
{
float alpha; // 0 = opaque, 1 = opaque, 0 < x < 1 translucent
float colourmod[3]; // r,g,b [0.0 .. 1.0], > 1 overbright
} ext_entvars_t;

typedef struct edict_s
Expand Down
44 changes: 42 additions & 2 deletions src/sv_ents.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ void SV_WriteDelta(client_t* client, entity_state_t *from, entity_state_t *to, s
evenmorebits |= U_FTE_TRANS;
#endif

#ifdef U_FTE_COLOURMOD
if ((to->colourmod[0] != from->colourmod[0] ||
to->colourmod[1] != from->colourmod[1] ||
to->colourmod[2] != from->colourmod[2]) && (fte_extensions & FTE_PEXT_COLOURMOD))
evenmorebits |= U_FTE_COLOURMOD;
#endif

if (evenmorebits&0xff00)
evenmorebits |= U_FTE_YETMORE;
if (evenmorebits&0x00ff)
Expand Down Expand Up @@ -299,6 +306,15 @@ void SV_WriteDelta(client_t* client, entity_state_t *from, entity_state_t *to, s
if (evenmorebits & U_FTE_TRANS)
MSG_WriteByte (msg, to->trans);
#endif

#ifdef U_FTE_COLOURMOD
if (evenmorebits & U_FTE_COLOURMOD)
{
MSG_WriteByte (msg, to->colourmod[0]);
MSG_WriteByte (msg, to->colourmod[1]);
MSG_WriteByte (msg, to->colourmod[2]);
}
#endif
}

/*
Expand Down Expand Up @@ -628,6 +644,14 @@ static void SV_WritePlayersToClient (client_t *client, client_frame_t *frame, by
pflags |= PF_TRANS_Z;
}
#endif
#ifdef FTE_PEXT_COLOURMOD
if (client->fteprotocolextensions & FTE_PEXT_COLOURMOD &&
(ent->xv.colourmod[0] > 0.0f && ent->xv.colourmod[1] > 0.0f && ent->xv.colourmod[2] > 0.0f) &&
!(ent->xv.colourmod[0] == 1.0f && ent->xv.colourmod[1] == 1.0f && ent->xv.colourmod[2] == 1.0f))
{
pflags |= PF_COLOURMOD;
}
#endif

// Z_EXT_PM_TYPE protocol extension
// encode pm_type and jump_held into pm_code
Expand Down Expand Up @@ -680,8 +704,8 @@ static void SV_WritePlayersToClient (client_t *client, client_frame_t *frame, by
MSG_WriteByte (msg, svc_playerinfo);
MSG_WriteByte (msg, j);

#ifdef FTE_PEXT_TRANS
if (client->fteprotocolextensions & FTE_PEXT_TRANS)
#if defined(FTE_PEXT_TRANS) && defined(FTE_PEXT_COLOURMOD)
if (client->fteprotocolextensions & (FTE_PEXT_TRANS | FTE_PEXT_COLOURMOD))
{
if (pflags & 0xff0000)
{
Expand Down Expand Up @@ -775,6 +799,14 @@ static void SV_WritePlayersToClient (client_t *client, client_frame_t *frame, by
{
MSG_WriteByte (msg, bound(1, (byte)(ent->xv.alpha * 254.0f), 254));
}
#endif
#ifdef FTE_PEXT_COLOURMOD
if (pflags & PF_COLOURMOD)
{
MSG_WriteByte(msg, bound(0, ent->xv.colourmod[0] * (256.0f / 8.0f), 255));
MSG_WriteByte(msg, bound(0, ent->xv.colourmod[1] * (256.0f / 8.0f), 255));
MSG_WriteByte(msg, bound(0, ent->xv.colourmod[2] * (256.0f / 8.0f), 255));
}
#endif
}
}
Expand Down Expand Up @@ -1003,6 +1035,14 @@ void SV_WriteEntitiesToClient (client_t *client, sizebuf_t *msg, qbool recorder)
state->effects = TranslateEffects(ent);
#ifdef FTE_PEXT_TRANS
state->trans = ent->xv.alpha >= 1.0f ? 0 : bound(0, (byte)(ent->xv.alpha * 254.0f), 254);
#endif
#ifdef FTE_PEXT_COLOURMOD
if (ent->xv.colourmod[0] != 1.0f && ent->xv.colourmod[1] != 1.0f && ent->xv.colourmod[2] != 1.0f)
{
state->colourmod[0] = bound(0, ent->xv.colourmod[0] * (256.0f / 8.0f), 255);
state->colourmod[1] = bound(0, ent->xv.colourmod[1] * (256.0f / 8.0f), 255);
state->colourmod[2] = bound(0, ent->xv.colourmod[2] * (256.0f / 8.0f), 255);
}
#endif
}
} // server flash
Expand Down
3 changes: 3 additions & 0 deletions src/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,9 @@ void SV_InitLocal (void)
#ifdef FTE_PEXT_TRANS
svs.fteprotocolextensions |= FTE_PEXT_TRANS;
#endif
#ifdef FTE_PEXT_COLOURMOD
svs.fteprotocolextensions |= FTE_PEXT_COLOURMOD;
#endif
#ifdef FTE_PEXT2_VOICECHAT
svs.fteprotocolextensions2 |= FTE_PEXT2_VOICECHAT;
#endif
Expand Down

0 comments on commit 4943850

Please sign in to comment.