[client] Extend sbar's api

I think this makes the purpose of the functions more clear and makes the
protocol logic less dependent on the meaning of some of the updates.
Most of the update functions are not fully implemented yet.
This commit is contained in:
Bill Currie 2022-11-09 19:41:59 +09:00
parent 73e62de2fb
commit 1b90f2320e
5 changed files with 72 additions and 45 deletions

View file

@ -58,6 +58,10 @@ void Sbar_SetTeamplay (int teamplay);
void Sbar_SetActive (int active);
void Sbar_Update (double time);
void Sbar_UpdatePings (void);
void Sbar_UpdateFrags (int playernum);
void Sbar_UpdateInfo (int playernum);
void Sbar_UpdateStats (int stat);
void Sbar_Damage (double time);
void Sbar_Changed (sbar_changed change);

View file

@ -1565,23 +1565,17 @@ Sbar_DeathmatchOverlay (view_t view)
count = 0;
}
double cur_time = sbar_intermission ? sbar_completed_time : sbar_time;
for (i = 0; i < count; i++, y += 10) {
int k = fragsort[i];
player_info_t *p = &sbar_players[k];
if (!View_Valid (sb_views[k])) {
sb_views[k] = make_dmo_line (view, k);
}
write_charbuff (sb_ping[k], 0, 0, va (0, "%3d", p->ping));
write_charbuff (sb_pl[k], 0, 0, va (0, "%3d", p->pl));
int total = (sbar_intermission ? sbar_completed_time : sbar_time)
- p->entertime;
int total = cur_time - p->entertime;
write_charbuff (sb_fph[k], 0, 0, va (0, "%3d",
calc_fph (p->frags, total)));
write_charbuff (sb_time[k], 0, 0, va (0, "%3d", total / 60));
//FIXME update top/bottom color
write_charbuff (sb_frags[k], 0, 0, va (0, "%3d", p->frags));
write_charbuff (sb_uid[k], 0, 0, va (0, "%3d", p->userid));
write_charbuff (sb_name[k], 0, 0, p->name->value);
View_SetPos (sb_views[k], 0, y);
}
for (; i < MAX_PLAYERS; i++) {
@ -2145,6 +2139,46 @@ Sbar_Update (double time)
sb_update_flags = 0;
}
void
Sbar_UpdatePings ()
{
for (int i = 0; i < sbar_maxplayers; i++) {
player_info_t *p = &sbar_players[i];
if (!p->name || !p->name->value) {
continue;
}
write_charbuff (sb_ping[i], 0, 0, va (0, "%3d", p->ping));
write_charbuff (sb_pl[i], 0, 0, va (0, "%3d", p->pl));
}
}
void
Sbar_UpdateFrags (int playernum)
{
player_info_t *p = &sbar_players[playernum];
write_charbuff (sb_frags[playernum], 0, 0, va (0, "%3d", p->frags));
}
void
Sbar_UpdateInfo (int playernum)
{
player_info_t *p = &sbar_players[playernum];
//FIXME update top/bottom color
write_charbuff (sb_uid[playernum], 0, 0, va (0, "%3d", p->userid));
write_charbuff (sb_name[playernum], 0, 0, p->name->value);
if (sbar_teamplay) {
write_charbuff (sb_team[playernum], 0, 0, p->team->value);
}
}
void
Sbar_UpdateStats (int stat)
{
if (stat == -1) {
} else {
}
}
void
Sbar_Damage (double time)
{
@ -2167,16 +2201,20 @@ Sbar_SetViewEntity (int viewentity)
void
Sbar_SetLevelName (const char *levelname, const char *servername)
{
sbar_levelname = levelname;
sbar_servername = servername;
}
void
Sbar_SetTeamplay (int teamplay)
{
sbar_teamplay = teamplay;
}
void
Sbar_SetActive (int active)
{
sbar_active = active;
}
static void

View file

@ -585,9 +585,9 @@ CL_ParseClientdata (void)
if ((i & (1 << j)) && !(cl.stats[STAT_ITEMS] & (1 << j)))
cl.item_gettime[j] = cl.time;
cl.stats[STAT_ITEMS] = i;
Sbar_Changed (sbc_items);
#define IT_POWER (IT_QUAD | IT_SUIT | IT_INVULNERABILITY | IT_INVISIBILITY)
cl.viewstate.powerup_index = (cl.stats[STAT_ITEMS] & IT_POWER) >> 19;
Sbar_UpdateStats (STAT_ITEMS);
}
cl.viewstate.onground = (bits & SU_ONGROUND) ? 0 : -1;
@ -605,7 +605,7 @@ CL_ParseClientdata (void)
i = 0;
if (cl.stats[STAT_ARMOR] != i) {
cl.stats[STAT_ARMOR] = i;
Sbar_Changed (sbc_armor);
Sbar_UpdateStats (STAT_ITEMS);
}
if (bits & SU_WEAPON)
@ -615,26 +615,26 @@ CL_ParseClientdata (void)
if (cl.stats[STAT_WEAPON] != i) {
cl.stats[STAT_WEAPON] = i;
cl.viewstate.weapon_model = cl_world.models.a[cl.stats[STAT_WEAPON]];
Sbar_Changed (sbc_weapon);
Sbar_UpdateStats (STAT_WEAPON);
}
i = (short) MSG_ReadShort (net_message);
if (cl.stats[STAT_HEALTH] != i) {
cl.stats[STAT_HEALTH] = i;
Sbar_Changed (sbc_health);
Sbar_UpdateStats (STAT_HEALTH);
}
i = MSG_ReadByte (net_message);
if (cl.stats[STAT_AMMO] != i) {
cl.stats[STAT_AMMO] = i;
Sbar_Changed (sbc_ammo);
Sbar_UpdateStats (STAT_AMMO);
}
for (i = 0; i < 4; i++) {
j = MSG_ReadByte (net_message);
if (cl.stats[STAT_SHELLS + i] != j) {
cl.stats[STAT_SHELLS + i] = j;
Sbar_Changed (sbc_ammo);
Sbar_UpdateStats (STAT_SHELLS + i);
}
}
@ -643,13 +643,13 @@ CL_ParseClientdata (void)
if (standard_quake) {
if (cl.stats[STAT_ACTIVEWEAPON] != i) {
cl.stats[STAT_ACTIVEWEAPON] = i;
Sbar_Changed (sbc_weapon);
Sbar_UpdateStats (STAT_ACTIVEWEAPON);
}
} else {
// hipnotic/rogue weapon "bit field" (stupid idea)
if (cl.stats[STAT_ACTIVEWEAPON] != (1 << i)) {
cl.stats[STAT_ACTIVEWEAPON] = (1 << i);
Sbar_Changed (sbc_weapon);
Sbar_UpdateStats (STAT_ACTIVEWEAPON);
}
}
@ -870,22 +870,22 @@ CL_ParseServerMessage (void)
break;
case svc_updatename:
Sbar_Changed (sbc_info);
i = MSG_ReadByte (net_message);
if (i >= cl.maxclients)
Host_Error ("CL_ParseServerMessage: svc_updatename > "
"MAX_SCOREBOARD");
Info_SetValueForKey (cl.players[i].userinfo, "name",
MSG_ReadString (net_message), 0);
Sbar_UpdateInfo (i);
break;
case svc_updatefrags:
Sbar_Changed (sbc_frags);
i = MSG_ReadByte (net_message);
if (i >= cl.maxclients)
Host_Error ("CL_ParseServerMessage: svc_updatefrags > "
"MAX_SCOREBOARD");
cl.players[i].frags = (short) MSG_ReadShort (net_message);
Sbar_UpdateFrags (i);
break;
case svc_clientdata:
@ -898,7 +898,6 @@ CL_ParseServerMessage (void)
break;
case svc_updatecolors:
Sbar_Changed (sbc_info);
i = MSG_ReadByte (net_message);
if (i >= cl.maxclients) {
Host_Error ("CL_ParseServerMessage: svc_updatecolors > "
@ -916,6 +915,7 @@ CL_ParseServerMessage (void)
cl.players[i].bottomcolor = bot;
renderer->skin
= mod_funcs->Skin_SetColormap (renderer->skin, i + 1);
Sbar_UpdateInfo (i);
}
break;

View file

@ -199,14 +199,7 @@ Cam_Unlock (void)
}
autocam = CAM_NONE;
locked = false;
Sbar_Changed (sbc_ammo);
Sbar_Changed (sbc_armor);
Sbar_Changed (sbc_frags);
Sbar_Changed (sbc_health);
Sbar_Changed (sbc_info);
Sbar_Changed (sbc_items);
Sbar_Changed (sbc_weapon);
Sbar_Changed (sbc_server);
Sbar_UpdateStats (-1); // update all stats
}
}
@ -228,14 +221,7 @@ Cam_Lock (int playernum)
last_lock = realtime;
cam_forceview = true;
locked = false;
Sbar_Changed (sbc_ammo);
Sbar_Changed (sbc_armor);
Sbar_Changed (sbc_frags);
Sbar_Changed (sbc_health);
Sbar_Changed (sbc_info);
Sbar_Changed (sbc_items);
Sbar_Changed (sbc_weapon);
Sbar_Changed (sbc_server);
Sbar_UpdateStats (-1); // update all stats
}
static trace_t

View file

@ -1034,7 +1034,7 @@ CL_ProcessUserInfo (int slot, player_info_t *player)
player->skinname->value);
player->skin = mod_funcs->Skin_SetColormap (player->skin, slot + 1);
Sbar_Changed (sbc_info);
Sbar_UpdateInfo (slot);
}
static void
@ -1157,7 +1157,6 @@ CL_SetStat (int stat, int value)
case STAT_ITEMS:
#define IT_POWER (IT_QUAD | IT_SUIT | IT_INVULNERABILITY | IT_INVISIBILITY)
cl.viewstate.powerup_index = (cl.stats[STAT_ITEMS]&IT_POWER) >> 19;
Sbar_Changed (sbc_items);
break;
case STAT_HEALTH:
if (cl_player_health_e->func)
@ -1166,13 +1165,6 @@ CL_SetStat (int stat, int value)
if (value <= 0)
Team_Dead ();
break;
default:
//FIXME smarter checks
Sbar_Changed (sbc_ammo);
Sbar_Changed (sbc_armor);
Sbar_Changed (sbc_frags);
Sbar_Changed (sbc_weapon);
break;
}
cl.stats[stat] = value;
cl.viewstate.weapon_model = cl_world.models.a[cl.stats[STAT_WEAPON]];
@ -1181,6 +1173,7 @@ CL_SetStat (int stat, int value)
} else {
cl.viewstate.height = DEFAULT_VIEWHEIGHT; // view height
}
Sbar_UpdateStats (stat);
}
static void
@ -1220,6 +1213,7 @@ void
CL_ParseServerMessage (void)
{
int cmd = 0, i, j;
int update_pings = 0;
const char *str;
static dstring_t *stuffbuf;
TEntContext_t tentCtx = {
@ -1396,7 +1390,7 @@ CL_ParseServerMessage (void)
Host_Error ("CL_ParseServerMessage: svc_updatefrags > "
"MAX_SCOREBOARD");
cl.players[i].frags = (short) MSG_ReadShort (net_message);
Sbar_Changed (sbc_frags);
Sbar_UpdateFrags (i);
break;
// svc_clientdata
@ -1521,6 +1515,7 @@ CL_ParseServerMessage (void)
Host_Error ("CL_ParseServerMessage: svc_updateping > "
"MAX_SCOREBOARD");
cl.players[i].ping = MSG_ReadShort (net_message);
update_pings = 1;
break;
case svc_updateentertime:
@ -1604,6 +1599,7 @@ CL_ParseServerMessage (void)
Host_Error ("CL_ParseServerMessage: svc_updatepl > "
"MAX_SCOREBOARD");
cl.players[i].pl = MSG_ReadByte (net_message);
update_pings = 1;
break;
case svc_nails2: // FIXME from qwex
@ -1611,6 +1607,9 @@ CL_ParseServerMessage (void)
break;
}
}
if (update_pings) {
Sbar_UpdatePings ();
}
CL_SetSolidEntities ();
}