Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve spectator reporting #363

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -53,10 +53,10 @@
{
bodyque[i] = spawn();
bodyque[i]->classname = "bodyque";
bodyque[i - 1]->s.v.owner = EDICT_TO_PROG(bodyque[i]);

Check warning on line 56 in src/world.c

View workflow job for this annotation

GitHub Actions / verify-macos

implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
}

bodyque[MAX_BODYQUE - 1]->s.v.owner = EDICT_TO_PROG(bodyque[0]);

Check warning on line 59 in src/world.c

View workflow job for this annotation

GitHub Actions / verify-macos

implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
bodyque_head = 0;
}

Expand Down Expand Up @@ -144,7 +144,7 @@
e = spawn();

e->classname = "mapguard";
e->s.v.owner = EDICT_TO_PROG(world);

Check warning on line 147 in src/world.c

View workflow job for this annotation

GitHub Actions / verify-macos

implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
e->think = (func_t) CheckDefMap;
e->s.v.nextthink = g_globalvars.time + max(0.0001, timeout);
}
Expand Down Expand Up @@ -582,7 +582,7 @@

self = spawn();
setorigin(self, -912.6f, -898.9f, 248.0f); // oh, ktpro like
self->s.v.owner = EDICT_TO_PROG(world);

Check warning on line 585 in src/world.c

View workflow job for this annotation

GitHub Actions / verify-macos

implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
SP_item_artifact_super_damage();

self = swp; // restore self
Expand Down Expand Up @@ -1881,8 +1881,6 @@

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
Loading