From dbbea8911fe5347983fa19c2b794dff998284464 Mon Sep 17 00:00:00 2001 From: dusty-qw <71472647+dusty-qw@users.noreply.github.com> Date: Sun, 4 Aug 2024 15:58:03 -0700 Subject: [PATCH] SPECTATE: improve spectator reporting Instead of spamming the server every 2 seconds, only send updates during track change events. --- src/client.c | 67 ++++++++++++++++++++++++++++++-------------------- src/spectate.c | 6 +++++ src/world.c | 2 -- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/client.c b/src/client.c index 21747c89..f19b9685 100644 --- a/src/client.c +++ b/src/client.c @@ -43,17 +43,17 @@ vec3_t VEC_HULL2_MAX = int modelindex_eyes, modelindex_player, vwep_index; qbool can_prewar(qbool fire); -void IdlebotCheck(void); -void CheckAll(void); -void PlayerStats(void); -void ExitCaptain(void); -void CheckFinishCaptain(void); -void MakeMOTD(void); -void ImpulseCommands(void); -void StartDie(void); -void ZeroFpsStats(void); -void item_megahealth_rot(void); - +void IdlebotCheck(); +void CheckAll(); +void PlayerStats(); +void ExitCaptain(); +void CheckFinishCaptain(); +void MakeMOTD(); +void ImpulseCommands(); +void StartDie(); +void ZeroFpsStats(); +void item_megahealth_rot(); +void SendSpecInfo(gedict_t *spec, gedict_t *target_client); void del_from_specs_favourites(gedict_t *rm); void item_megahealth_rot(void); @@ -1714,6 +1714,8 @@ void ClientConnect(void) } } + SendSpecInfo(NULL, self); // get all spectator info + MakeMOTD(); #ifdef BOT_SUPPORT @@ -4454,35 +4456,46 @@ void CheckTeamStatus(void) } } -void SendSpecInfo(void) +void SendSpecInfo(gedict_t *spec, gedict_t *target_client) { gedict_t *t, *p; int cl, tr; - static double lastupdate = 0; - - if (g_globalvars.time - lastupdate < 2) + if (spec) // if spec has a value, we only want to send that spec's info { - return; - } - - lastupdate = g_globalvars.time; - - for (t = world; (t = find_spc(t));) - { - cl = NUM_FOR_EDICT(t) - 1; - tr = NUM_FOR_EDICT(PROG_TO_EDICT(t->s.v.goalentity)) - 1; // num for player spec is tracking + cl = NUM_FOR_EDICT(spec) - 1; + tr = NUM_FOR_EDICT(PROG_TO_EDICT(spec->s.v.goalentity)) - 1; // num for player spec is tracking for (p = world; (p = find_client(p));) { - if (p == t) - { + if (p == spec) continue; // ignore self - } stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "//spi %d %d\n", cl, tr); } } + else { + for (t = world; (t = find_spc(t));) + { + cl = NUM_FOR_EDICT(t) - 1; + tr = NUM_FOR_EDICT(PROG_TO_EDICT(t->s.v.goalentity)) - 1; // num for player spec is tracking + + if (target_client && target_client != t) + { + stuffcmd_flags(target_client, STUFFCMD_IGNOREINDEMO, "//spi %d %d\n", cl, tr); + } + else // if no target client is specified, send to everyone + { + for (p = world; (p = find_client(p));) + { + if (p == t) + continue; // ignore self + + stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "//spi %d %d\n", cl, tr); + } + } + } + } } void TookWeaponHandler(gedict_t *p, int new_wp, qbool from_backpack) diff --git a/src/spectate.c b/src/spectate.c index 24c8b7aa..b501ab12 100644 --- a/src/spectate.c +++ b/src/spectate.c @@ -37,6 +37,8 @@ void AutoTrackRestore(void); void Bot_Print_Thinking(void); +void SendSpecInfo(gedict_t *spec, gedict_t *target_client); + qbool TrackChangeCoach(gedict_t *p); int GetSpecWizard(void) @@ -199,6 +201,8 @@ void SpectatorConnect(void) self->wizard->s.v.nextthink = g_globalvars.time + 0.1; } + SendSpecInfo(NULL, self); // Get all spectator info + // Wait until you do stuffing MakeMOTD(); } @@ -357,6 +361,8 @@ void SpecGoalChanged(void) } WS_OnSpecPovChange(self, false); // refresh "new weapon stats" + + SendSpecInfo(self, NULL); // update tracking info with all clients } //////////////// diff --git a/src/world.c b/src/world.c index 66aa2425..239f8c83 100644 --- a/src/world.c +++ b/src/world.c @@ -1881,8 +1881,6 @@ void StartFrame(int time) CheckTeamStatus(); - SendSpecInfo(); - CheckAutoXonX(true); // switch XonX mode dependant on players + specs count Check_LongMapUptime(); // reload map after some long up time, so our float time variables are happy