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 dbbea89
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
67 changes: 40 additions & 27 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Check failure on line 46 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void CheckAll();

Check failure on line 47 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void PlayerStats();

Check failure on line 48 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void ExitCaptain();

Check failure on line 49 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void CheckFinishCaptain();

Check failure on line 50 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void MakeMOTD();

Check failure on line 51 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void ImpulseCommands();

Check failure on line 52 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void StartDie();

Check failure on line 53 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void ZeroFpsStats();

Check failure on line 54 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void item_megahealth_rot();

Check failure on line 55 in src/client.c

View workflow job for this annotation

GitHub Actions / verify-macos

a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
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 dbbea89

Please sign in to comment.