Skip to content

Commit dbbea89

Browse files
committed
SPECTATE: improve spectator reporting
Instead of spamming the server every 2 seconds, only send updates during track change events.
1 parent ea92a73 commit dbbea89

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

src/client.c

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ vec3_t VEC_HULL2_MAX =
4343
int modelindex_eyes, modelindex_player, vwep_index;
4444

4545
qbool can_prewar(qbool fire);
46-
void IdlebotCheck(void);
47-
void CheckAll(void);
48-
void PlayerStats(void);
49-
void ExitCaptain(void);
50-
void CheckFinishCaptain(void);
51-
void MakeMOTD(void);
52-
void ImpulseCommands(void);
53-
void StartDie(void);
54-
void ZeroFpsStats(void);
55-
void item_megahealth_rot(void);
56-
46+
void IdlebotCheck();
47+
void CheckAll();
48+
void PlayerStats();
49+
void ExitCaptain();
50+
void CheckFinishCaptain();
51+
void MakeMOTD();
52+
void ImpulseCommands();
53+
void StartDie();
54+
void ZeroFpsStats();
55+
void item_megahealth_rot();
56+
void SendSpecInfo(gedict_t *spec, gedict_t *target_client);
5757
void del_from_specs_favourites(gedict_t *rm);
5858
void item_megahealth_rot(void);
5959

@@ -1714,6 +1714,8 @@ void ClientConnect(void)
17141714
}
17151715
}
17161716

1717+
SendSpecInfo(NULL, self); // get all spectator info
1718+
17171719
MakeMOTD();
17181720

17191721
#ifdef BOT_SUPPORT
@@ -4454,35 +4456,46 @@ void CheckTeamStatus(void)
44544456
}
44554457
}
44564458

4457-
void SendSpecInfo(void)
4459+
void SendSpecInfo(gedict_t *spec, gedict_t *target_client)
44584460
{
44594461
gedict_t *t, *p;
44604462
int cl, tr;
44614463

4462-
static double lastupdate = 0;
4463-
4464-
if (g_globalvars.time - lastupdate < 2)
4464+
if (spec) // if spec has a value, we only want to send that spec's info
44654465
{
4466-
return;
4467-
}
4468-
4469-
lastupdate = g_globalvars.time;
4470-
4471-
for (t = world; (t = find_spc(t));)
4472-
{
4473-
cl = NUM_FOR_EDICT(t) - 1;
4474-
tr = NUM_FOR_EDICT(PROG_TO_EDICT(t->s.v.goalentity)) - 1; // num for player spec is tracking
4466+
cl = NUM_FOR_EDICT(spec) - 1;
4467+
tr = NUM_FOR_EDICT(PROG_TO_EDICT(spec->s.v.goalentity)) - 1; // num for player spec is tracking
44754468

44764469
for (p = world; (p = find_client(p));)
44774470
{
4478-
if (p == t)
4479-
{
4471+
if (p == spec)
44804472
continue; // ignore self
4481-
}
44824473

44834474
stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "//spi %d %d\n", cl, tr);
44844475
}
44854476
}
4477+
else {
4478+
for (t = world; (t = find_spc(t));)
4479+
{
4480+
cl = NUM_FOR_EDICT(t) - 1;
4481+
tr = NUM_FOR_EDICT(PROG_TO_EDICT(t->s.v.goalentity)) - 1; // num for player spec is tracking
4482+
4483+
if (target_client && target_client != t)
4484+
{
4485+
stuffcmd_flags(target_client, STUFFCMD_IGNOREINDEMO, "//spi %d %d\n", cl, tr);
4486+
}
4487+
else // if no target client is specified, send to everyone
4488+
{
4489+
for (p = world; (p = find_client(p));)
4490+
{
4491+
if (p == t)
4492+
continue; // ignore self
4493+
4494+
stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "//spi %d %d\n", cl, tr);
4495+
}
4496+
}
4497+
}
4498+
}
44864499
}
44874500

44884501
void TookWeaponHandler(gedict_t *p, int new_wp, qbool from_backpack)

src/spectate.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void AutoTrackRestore(void);
3737

3838
void Bot_Print_Thinking(void);
3939

40+
void SendSpecInfo(gedict_t *spec, gedict_t *target_client);
41+
4042
qbool TrackChangeCoach(gedict_t *p);
4143

4244
int GetSpecWizard(void)
@@ -199,6 +201,8 @@ void SpectatorConnect(void)
199201
self->wizard->s.v.nextthink = g_globalvars.time + 0.1;
200202
}
201203

204+
SendSpecInfo(NULL, self); // Get all spectator info
205+
202206
// Wait until you do stuffing
203207
MakeMOTD();
204208
}
@@ -357,6 +361,8 @@ void SpecGoalChanged(void)
357361
}
358362

359363
WS_OnSpecPovChange(self, false); // refresh "new weapon stats"
364+
365+
SendSpecInfo(self, NULL); // update tracking info with all clients
360366
}
361367

362368
////////////////

src/world.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,8 +1881,6 @@ void StartFrame(int time)
18811881

18821882
CheckTeamStatus();
18831883

1884-
SendSpecInfo();
1885-
18861884
CheckAutoXonX(true); // switch XonX mode dependant on players + specs count
18871885

18881886
Check_LongMapUptime(); // reload map after some long up time, so our float time variables are happy

0 commit comments

Comments
 (0)