From dc3b20a1011dd0fa843d211cb30e11e97ce0a4b6 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 24 Dec 2015 16:20:07 +1000 Subject: [PATCH] Kill most uses of FOR_EACH_REALCLIENT --- qcsrc/common/effects/qc/gibs.qc | 2 +- qcsrc/common/effects/qc/globalsound.qc | 14 ++--- .../mutators/mutator/damagetext/damagetext.qc | 35 ++++++------ qcsrc/common/mutators/mutator/itemstime.qc | 4 +- qcsrc/common/net_notice.qc | 5 +- qcsrc/common/notifications.qc | 10 ++-- qcsrc/common/playerstats.qc | 4 +- qcsrc/common/weapons/weapon/tuba.qc | 11 ++-- qcsrc/server/cl_client.qc | 9 +--- qcsrc/server/mapvoting.qc | 54 +++++++++---------- qcsrc/server/mutators/mutator/gamemode_lms.qc | 13 ++--- qcsrc/server/t_items.qc | 8 +-- 12 files changed, 69 insertions(+), 100 deletions(-) diff --git a/qcsrc/common/effects/qc/gibs.qc b/qcsrc/common/effects/qc/gibs.qc index 2e248096b..2e54f4396 100644 --- a/qcsrc/common/effects/qc/gibs.qc +++ b/qcsrc/common/effects/qc/gibs.qc @@ -43,7 +43,7 @@ void Violence_GibSplash_At(vector org, vector dir, float type, float amount, ent e.oldorigin_x = compressShortVector(e.velocity); - entity cl; FOR_EACH_REALCLIENT(cl) Violence_GibSplash_SendEntity(e, cl, 0); + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(Violence_GibSplash_SendEntity(e, it, 0))); remove(e); } diff --git a/qcsrc/common/effects/qc/globalsound.qc b/qcsrc/common/effects/qc/globalsound.qc index 83a2440cf..7f77d8400 100644 --- a/qcsrc/common/effects/qc/globalsound.qc +++ b/qcsrc/common/effects/qc/globalsound.qc @@ -342,10 +342,10 @@ if (fake) { msg_entity = this; X(); } else { - FOR_EACH_REALCLIENT(msg_entity) - { - if (!teamplay || msg_entity.team == this.team) X(); - } + FOREACH_CLIENT(IS_REAL_CLIENT(it) && (!teamplay || msg_entity.team == this.team), LAMBDA( + msg_entity = it; + X(); + )); } #undef X break; @@ -381,10 +381,10 @@ } else { - FOR_EACH_REALCLIENT(msg_entity) - { + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( + msg_entity = it; X(); - } + )); } #undef X break; diff --git a/qcsrc/common/mutators/mutator/damagetext/damagetext.qc b/qcsrc/common/mutators/mutator/damagetext/damagetext.qc index 923ca3bcc..e8f3a54bf 100644 --- a/qcsrc/common/mutators/mutator/damagetext/damagetext.qc +++ b/qcsrc/common/mutators/mutator/damagetext/damagetext.qc @@ -88,23 +88,24 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) { const int armor = MUTATOR_ARGV(1, int); const int deathtype = MUTATOR_ARGV(2, int); const vector location = hit.origin; - entity e; - FOR_EACH_REALCLIENT(e) if ( - (SV_DAMAGETEXT_ALL()) || - (SV_DAMAGETEXT_PLAYERS() && e == attacker) || - (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_SPEC(e) && e.enemy == attacker) || - (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_OBSERVER(e)) - ) { - msg_entity = e; - WriteHeader(MSG_ONE, damagetext); - WriteShort(MSG_ONE, health); - WriteShort(MSG_ONE, armor); - WriteEntity(MSG_ONE, hit); - WriteCoord(MSG_ONE, location.x); - WriteCoord(MSG_ONE, location.y); - WriteCoord(MSG_ONE, location.z); - WriteInt24_t(MSG_ONE, deathtype); - } + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( + if ( + (SV_DAMAGETEXT_ALL()) || + (SV_DAMAGETEXT_PLAYERS() && it == attacker) || + (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_SPEC(it) && it.enemy == attacker) || + (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_OBSERVER(it)) + ) { + msg_entity = it; + WriteHeader(MSG_ONE, damagetext); + WriteShort(MSG_ONE, health); + WriteShort(MSG_ONE, armor); + WriteEntity(MSG_ONE, hit); + WriteCoord(MSG_ONE, location.x); + WriteCoord(MSG_ONE, location.y); + WriteCoord(MSG_ONE, location.z); + WriteInt24_t(MSG_ONE, deathtype); + } + )); } #endif diff --git a/qcsrc/common/mutators/mutator/itemstime.qc b/qcsrc/common/mutators/mutator/itemstime.qc index 975eb29f3..20b430323 100644 --- a/qcsrc/common/mutators/mutator/itemstime.qc +++ b/qcsrc/common/mutators/mutator/itemstime.qc @@ -110,9 +110,7 @@ void Item_ItemsTime_SetTime(entity e, float t) void Item_ItemsTime_SetTimesForAllPlayers() { - entity e; - FOR_EACH_REALCLIENT(e) if (warmup_stage || !IS_PLAYER(e)) - Item_ItemsTime_SetTimesForPlayer(e); + FOREACH_CLIENT(IS_REAL_CLIENT(it) && (warmup_stage || !IS_PLAYER(it)), LAMBDA(Item_ItemsTime_SetTimesForPlayer(it))); } float Item_ItemsTime_UpdateTime(entity e, float t) diff --git a/qcsrc/common/net_notice.qc b/qcsrc/common/net_notice.qc index 06f310799..59061e5a9 100644 --- a/qcsrc/common/net_notice.qc +++ b/qcsrc/common/net_notice.qc @@ -30,10 +30,7 @@ void sv_notice_to(entity _to, string _notice, float _howlong, float _modal) void sv_notice_toall(string _notice, float _howlong, float _modal) { - entity _head; - FOR_EACH_REALCLIENT(_head) - sv_notice_to(_head, _notice, _howlong, _modal); - + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(sv_notice_to(it, _notice, _howlong, _modal))); } #endif // SVQC diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index c8664e7af..2343206ca 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -2083,14 +2083,12 @@ void Send_Notification( } default: { - entity to; - FOR_EACH_REALCLIENT(to) - { - if(Notification_ShouldSend(broadcast, to, client)) + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( + if(Notification_ShouldSend(broadcast, it, client)) { - RECURSE_FROM_CHOICE(to, continue); + RECURSE_FROM_CHOICE(it, continue); } - } + )); break; } } diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index 2d9398ad7..f4657d968 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -456,12 +456,10 @@ void PlayerStats_PlayerBasic(entity joiningplayer, float newrequest) // server has this disabled, kill the DB and set status to idle if(PS_B_IN_DB >= 0) { - entity player; - db_close(PS_B_IN_DB); PS_B_IN_DB = -1; - FOR_EACH_REALCLIENT(player) { player.playerstats_basicstatus = PS_B_STATUS_IDLE; } + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(it.playerstats_basicstatus = PS_B_STATUS_IDLE)); } } } diff --git a/qcsrc/common/weapons/weapon/tuba.qc b/qcsrc/common/weapons/weapon/tuba.qc index ef2e5e261..084c5cff4 100644 --- a/qcsrc/common/weapons/weapon/tuba.qc +++ b/qcsrc/common/weapons/weapon/tuba.qc @@ -287,7 +287,6 @@ void W_Tuba_NoteThink() float vol0, vol1; vector dir0, dir1; vector v; - entity e; if(time > self.teleport_time) { W_Tuba_NoteOff(); @@ -295,13 +294,11 @@ void W_Tuba_NoteThink() } self.nextthink = time; dist_mult = WEP_CVAR(tuba, attenuation) / autocvar_snd_soundradius; - FOR_EACH_REALCLIENT(e) - if(e != self.realowner) - { - v = self.origin - (e.origin + e.view_ofs); + FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != self.realowner, LAMBDA( + v = self.origin - (it.origin + it.view_ofs); vol0 = max(0, 1 - vlen(v) * dist_mult); dir0 = normalize(v); - v = self.realowner.origin - (e.origin + e.view_ofs); + v = self.realowner.origin - (it.origin + it.view_ofs); vol1 = max(0, 1 - vlen(v) * dist_mult); dir1 = normalize(v); if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume @@ -316,7 +313,7 @@ void W_Tuba_NoteThink() self.SendFlags |= 2; break; } - } + )); } void W_Tuba_NoteOn(float hittype) diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 32ec6eb03..0c72e878e 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -103,14 +103,7 @@ void ClientData_Touch(entity e) e.clientdata.SendFlags = 1; // make it spectatable - entity e2; - FOR_EACH_REALCLIENT(e2) - { - if(e2 != e) - if(IS_SPEC(e2)) - if(e2.enemy == e) - e2.clientdata.SendFlags = 1; - } + FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != e && IS_SPEC(it) && it.enemy == e, LAMBDA(it.clientdata.SendFlags = 1)); } .string netname_previous; diff --git a/qcsrc/server/mapvoting.qc b/qcsrc/server/mapvoting.qc index ed17d86e8..a08272010 100644 --- a/qcsrc/server/mapvoting.qc +++ b/qcsrc/server/mapvoting.qc @@ -99,8 +99,7 @@ string GameTypeVote_MapInfo_FixName(string m) void MapVote_ClearAllVotes() { - FOR_EACH_CLIENT(other) - other.mapvote = 0; + FOREACH_CLIENT(true, LAMBDA(it.mapvote = 0)); } void MapVote_UnzoneStrings() @@ -454,8 +453,7 @@ float MapVote_Finished(float mappos) GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos])); } - FOR_EACH_REALCLIENT(other) - FixClientCvars(other); + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(FixClientCvars(it))); if(gametypevote) { @@ -494,16 +492,15 @@ void MapVote_CheckRules_1() } mapvote_voters = 0; - FOR_EACH_REALCLIENT(other) - { + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( ++mapvote_voters; - if(other.mapvote) + if(it.mapvote) { - i = other.mapvote - 1; - //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n"); + i = it.mapvote - 1; + //dprint("Player ", it.netname, " vote = ", ftos(it.mapvote - 1), "\n"); mapvote_selections[i] = mapvote_selections[i] + 1; } - } + )); } float MapVote_CheckRules_2() @@ -604,36 +601,33 @@ void MapVote_Tick() return; totalvotes = 0; - FOR_EACH_REALCLIENT(other) - { + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( // hide scoreboard again - if(other.health != 2342) + if(it.health != 2342) { - other.health = 2342; - other.impulse = 0; - if(IS_REAL_CLIENT(other)) - { - msg_entity = other; - WriteByte(MSG_ONE, SVC_FINALE); - WriteString(MSG_ONE, ""); - } + it.health = 2342; + it.impulse = 0; + + msg_entity = it; + WriteByte(MSG_ONE, SVC_FINALE); + WriteString(MSG_ONE, ""); } // clear possibly invalid votes - if ( !(mapvote_maps_flags[other.mapvote-1] & GTV_AVAILABLE) ) - other.mapvote = 0; + if ( !(mapvote_maps_flags[it.mapvote-1] & GTV_AVAILABLE) ) + it.mapvote = 0; // use impulses as new vote - if(other.impulse >= 1 && other.impulse <= mapvote_count) - if( mapvote_maps_flags[other.impulse - 1] & GTV_AVAILABLE ) + if(it.impulse >= 1 && it.impulse <= mapvote_count) + if( mapvote_maps_flags[it.impulse - 1] & GTV_AVAILABLE ) { - other.mapvote = other.impulse; - MapVote_TouchVotes(other); + it.mapvote = it.impulse; + MapVote_TouchVotes(it); } - other.impulse = 0; + it.impulse = 0; - if(other.mapvote) + if(it.mapvote) ++totalvotes; - } + )); MapVote_CheckRules_1(); // just count } diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qc b/qcsrc/server/mutators/mutator/gamemode_lms.qc index 575bc6904..6b293a064 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qc +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qc @@ -161,13 +161,8 @@ MUTATOR_HOOKFUNCTION(lms, reset_map_global) MUTATOR_HOOKFUNCTION(lms, reset_map_players) {SELFPARAM(); - entity e; if(restart_mapalreadyrestarted || (time < game_starttime)) - FOR_EACH_CLIENT(e) - if(IS_PLAYER(e)) - { - WITH(entity, self, e, PlayerScore_Add(e, SP_LMS_LIVES, LMS_NewPlayerLives())); - } + FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(WITH(entity, self, it, PlayerScore_Add(it, SP_LMS_LIVES, LMS_NewPlayerLives())))); return false; } @@ -343,12 +338,10 @@ MUTATOR_HOOKFUNCTION(lms, ItemTouch) MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE) { - entity head; - FOR_EACH_REALCLIENT(head) - { + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( ++bot_activerealplayers; ++bot_realplayers; - } + )); return true; } diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 8bce02ca1..fbb733405 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -532,13 +532,13 @@ void Item_RespawnCountdown () if(self.waypointsprite_attached) { setself(self.waypointsprite_attached); - entity e; - FOR_EACH_REALCLIENT(e) - if(self.waypointsprite_visible_for_player(e)) + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( + if(self.waypointsprite_visible_for_player(it)) { - msg_entity = e; + msg_entity = it; soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM); // play respawn sound } + )); setself(this); WaypointSprite_Ping(self.waypointsprite_attached); -- 2.39.2