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 Aug 8, 2024
1 parent a4c8848 commit 78a8755
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
46 changes: 30 additions & 16 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ 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);
Expand Down Expand Up @@ -1846,6 +1847,8 @@ void ClientConnect()
}
}

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

self->antilag_data = antilag_create_player(self);
WeaponPrediction_CreateEnt();

Expand Down Expand Up @@ -4673,35 +4676,46 @@ void CheckTeamStatus()
}
}

void SendSpecInfo()
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)
{
return;
}

lastupdate = g_globalvars.time;

for (t = world; (t = find_spc(t));)
if (spec) // if spec has a value, we only want to send that spec's info
{
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 Bot_Print_Thinking(void);

void SendSpecInfo(gedict_t *spec, gedict_t *target_client);

qbool TrackChangeCoach(gedict_t *p);

int GetSpecWizard()
Expand Down Expand Up @@ -199,6 +201,8 @@ void SpectatorConnect()
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()
}

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

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

////////////////
Expand Down
3 changes: 0 additions & 3 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,6 @@ extern float intermission_exittime;
void CheckTiming();
void check_fcheck();
void CheckTeamStatus();
void SendSpecInfo();
void DoMVDAutoTrack(void);
void antilag_updateworld();

Expand Down Expand Up @@ -1889,8 +1888,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 78a8755

Please sign in to comment.