From: Dr. Jaska Date: Thu, 3 Oct 2024 12:47:18 +0000 (+0000) Subject: Optimise sending survival statuses X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4a2a50d82661a4fac5b53b1f7d075d2b0eeba808;p=xonotic%2Fxonotic-data.pk3dir.git Optimise sending survival statuses --- diff --git a/qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc b/qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc index deaae435c..9958bd621 100644 --- a/qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc +++ b/qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc @@ -11,30 +11,28 @@ void nades_Clear(entity player); entity survivalStatuses; void SurvivalStatuses_Init(); -void SurvivalStatuses_Send() -{ - // SendFlags can be set to anything != 0, SurvivalStatuses_SendEntity won't use its value - // Dr. Jaska: this was a lie, the flags were not reset until now - survivalStatuses.SendFlags = 1; -} +#define STATUS_SEND_RESET 1 +#define STATUS_SEND_HUNTERS 2 bool SurvivalStatuses_SendEntity(entity this, entity dest, float sendflags) { Stream out = MSG_ENTITY; WriteHeader(out, ENT_CLIENT_SURVIVALSTATUSES); - // TODO: optimize this instead of always setting it on - sendflags = BIT(0); // reset all flags and make all players survivors - - if ((dest.survival_status == SURV_STATUS_HUNTER) || round_handler_AwaitingNextRound()) - sendflags |= BIT(1); // send hunter statuses + // always send hunters their own status and their allies + if (dest.survival_status == SURV_STATUS_HUNTER) + sendflags |= STATUS_SEND_HUNTERS; serialize(byte, out, sendflags); - if (sendflags & BIT(1)) { - for (int i = 1; i <= maxclients; i += 8) { + if (sendflags & STATUS_SEND_HUNTERS) + { + for (int i = 1; i <= maxclients; i += 8) + { int f = 0; entity e = edict_num(i); - for (int b = 0; b < 8; ++b, e = nextent(e)) { + + for (int b = 0; b < 8; ++b, e = nextent(e)) + { bool is_hunter = (INGAME(e) && e.survival_status == SURV_STATUS_HUNTER); if (is_hunter) f |= BIT(b); @@ -98,7 +96,7 @@ float Surv_CheckWinner() allowed_to_spawn = false; game_stopped = true; round_handler_Init(5, autocvar_g_survival_warmup, autocvar_g_survival_round_timelimit); - SurvivalStatuses_Send(); + survivalStatuses.SendFlags = STATUS_SEND_HUNTERS; return 1; } @@ -156,7 +154,7 @@ float Surv_CheckWinner() allowed_to_spawn = false; game_stopped = true; round_handler_Init(5, autocvar_g_survival_warmup, autocvar_g_survival_round_timelimit); - SurvivalStatuses_Send(); + survivalStatuses.SendFlags = STATUS_SEND_HUNTERS; FOREACH_CLIENT(true, { @@ -191,7 +189,7 @@ void Surv_RoundStart() total_hunters++; it.survival_status = SURV_STATUS_HUNTER; }); - SurvivalStatuses_Send(); + survivalStatuses.SendFlags = STATUS_SEND_RESET; FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), { @@ -335,7 +333,7 @@ MUTATOR_HOOKFUNCTION(surv, reset_map_players) } }); bot_relinkplayerlist(); - SurvivalStatuses_Send(); + survivalStatuses.SendFlags = STATUS_SEND_RESET; return true; } diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index 7c490fd15..af44475ce 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -114,6 +114,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } #ifdef SVQC const int MSG_ENTITY = 5; + // If SendFlags is set to non-0 it is networked .int SendFlags; IntrusiveList g_uncustomizables;