Skip to content

Commit

Permalink
SPECTATE: improve spectator reporting
Browse files Browse the repository at this point in the history
Instead of spamming the server every 2 seconds, only send updates during track change events.
  • Loading branch information
dusty-qw committed Sep 1, 2024
1 parent ea92a73 commit 00e48b6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
47 changes: 30 additions & 17 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void ImpulseCommands(void);
void StartDie(void);
void ZeroFpsStats(void);
void item_megahealth_rot(void);

void SendSpecInfo(gedict_t *spec, gedict_t *target_client);
void del_from_specs_favourites(gedict_t *rm);
void item_megahealth_rot(void);

Expand Down Expand Up @@ -1714,6 +1714,8 @@ void ClientConnect(void)
}
}

SendSpecInfo(NULL, self); // get all spectator info

MakeMOTD();

#ifdef BOT_SUPPORT
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/spectate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -357,6 +361,8 @@ void SpecGoalChanged(void)
}

WS_OnSpecPovChange(self, false); // refresh "new weapon stats"

SendSpecInfo(self, NULL); // update tracking info with all clients
}

////////////////
Expand Down
2 changes: 0 additions & 2 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 00e48b6

Please sign in to comment.