Skip to content

Commit

Permalink
Revert player iterator (TTT-2#1500)
Browse files Browse the repository at this point in the history
partially reverts TTT-2#1453

Not sure if this is the best solution or if we should still keep some
player.Iterator() calls. Feel free to discuss.

See [this discussion on the GMod
Discord](https://discord.com/channels/565105920414318602/567617926991970306/1224041147962228746)
for more context on this issue.

---------

Co-authored-by: saibotk <[email protected]>
  • Loading branch information
TimGoll and saibotk authored Apr 12, 2024
1 parent 48e66d3 commit 297be1b
Show file tree
Hide file tree
Showing 36 changed files with 99 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ if SERVER then
end

local pos = self:GetPos()
local ignore = select(2, player.Iterator())
local ignore = player.GetAll()

ignore[#ignore + 1] = self

Expand Down
6 changes: 3 additions & 3 deletions gamemodes/terrortown/entities/entities/ttt_c4/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local hook = hook
local table = table
local net = net
local IsValid = IsValid
local playerIterator = player.Iterator
local playerGetAll = player.GetAll

local defuserNearRadius = 90000

Expand Down Expand Up @@ -173,7 +173,7 @@ function ENT:SphereDamage(dmgowner, center, radius)
local diff = nil
local dmg = 0

local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
local ply = plys[i]
if ply:Team() ~= TEAM_TERROR then
Expand Down Expand Up @@ -322,7 +322,7 @@ function ENT:IsDefuserInRange()
local d = 0.0
local diff = nil

local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
local ply = plys[i]
if not ply:IsActive() or not ply:GetSubRoleData().isPolicingRole then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function ENT:CountValidPlayers(activator, caller, data)
local mins = self:LocalToWorld(self:OBBMins())
local maxs = self:LocalToWorld(self:OBBMaxs())

local plys = select(2, player.Iterator())
local plys = player.GetAll()
local count = 0

for i = 1, #plys do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function ENT:TestWeapons(weptype)
return 0
end

local plys = select(2, player.Iterator())
local plys = player.GetAll()

for i = 1, #plys do
local ply = plys[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ local function CanTeleportToPos(ply, pos)
start = pos,
endpos = pos,
mask = MASK_PLAYERSOLID,
filter = select(2, player.Iterator()),
filter = player.GetAll(),
}
local collide = false

Expand Down
2 changes: 1 addition & 1 deletion gamemodes/terrortown/entities/weapons/weapon_zm_carry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function SWEP:CheckValidity()
end

local function PlayerStandsOn(ent)
local plys = select(2, player.Iterator())
local plys = player.GetAll()

for i = 1, #plys do
local ply = plys[i]
Expand Down
12 changes: 6 additions & 6 deletions gamemodes/terrortown/gamemode/client/cl_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local util = util
local IsValid = IsValid
local surface = surface
local hook = hook
local playerIterator = player.Iterator
local playerGetAll = player.GetAll

-- Define GM12 fonts for compatibility
surface.CreateFont("DefaultBold", { font = "Tahoma", size = 13, weight = 1000 })
Expand Down Expand Up @@ -349,7 +349,7 @@ function GM:InitPostEntity()
end

-- cache players avatar
local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
local plyid64 = plys[i]:SteamID64()

Expand Down Expand Up @@ -487,7 +487,7 @@ local function RoundStateChange(o, n)
CLSCORE:ClearPanel()

-- people may have died and been searched during prep
local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
bodysearch.ResetSearchResult(plys[i])
end
Expand Down Expand Up @@ -528,7 +528,7 @@ local function RoundStateChange(o, n)
-- whatever round state we get, clear out the voice flags
local winTeams = roles.GetWinTeams()

local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
for k = 1, #winTeams do
plys[i][winTeams[k] .. "_gvoice"] = false
Expand Down Expand Up @@ -563,7 +563,7 @@ end
net.Receive("TTT_Role", ReceiveRole)

local function ReceiveRoleReset()
local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
plys[i]:SetRole(ROLE_NONE, TEAM_NONE)
end
Expand Down Expand Up @@ -648,7 +648,7 @@ function GM:ClearClientState()

VOICE.InitBattery()

local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
local pl = plys[i]
if not IsValid(pl) then
Expand Down
6 changes: 3 additions & 3 deletions gamemodes/terrortown/gamemode/client/cl_targetid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local math = math
local IsValid = IsValid
local hook = hook
local targetid = targetid
local playerIterator = player.Iterator
local playerGetAll = player.GetAll

---
-- Make sure local TargetID Variables are initialized
Expand Down Expand Up @@ -143,7 +143,7 @@ function GM:PostDrawTranslucentRenderables(bDrawingDepth, bDrawingSkybox)
local client = LocalPlayer()
local clientTarget = client:GetObserverTarget()
local clientObsMode = client:GetObserverMode()
local plys = select(2, playerIterator())
local plys = playerGetAll()

if client:Team() == TEAM_SPEC and cvEnableSpectatorsoutline:GetBool() then
cam.Start3D(EyePos(), EyeAngles())
Expand Down Expand Up @@ -224,7 +224,7 @@ local function DrawPropSpecLabels(client)
end

local tgt, scrpos, color, _
local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
local ply = plys[i]
Expand Down
2 changes: 1 addition & 1 deletion gamemodes/terrortown/gamemode/client/cl_transfer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function CreateTransferMenu(parent)
dpick:SetSortItems(false)

-- fill combobox
local plys = select(2, player.Iterator())
local plys = player.GetAll()

table.sort(plys, function(a, b)
return a:IsInTeam(client) and not b:IsInTeam(client)
Expand Down
4 changes: 2 additions & 2 deletions gamemodes/terrortown/gamemode/client/vgui/cl_sb_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local pairs = pairs
local ipairs = ipairs
local timer = timer
local IsValid = IsValid
local playerIterator = player.Iterator
local playerGetAll = player.GetAll

ttt_include("vgui__cl_sb_team")

Expand Down Expand Up @@ -530,7 +530,7 @@ function PANEL:UpdateScoreboard(force)

-- Put players where they belong. Groups will dump them as soon as they don't
-- anymore.
local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
local p = plys[i]
if IsValid(p) then
Expand Down
6 changes: 3 additions & 3 deletions gamemodes/terrortown/gamemode/server/sv_admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local pairs = pairs
local ipairs = ipairs
local util = util
local IsValid = IsValid
local playerIterator = player.Iterator
local playerGetAll = player.GetAll

local function GetPrintFn(ply)
if IsValid(ply) then
Expand Down Expand Up @@ -55,7 +55,7 @@ function PrintTraitors(ply)
ServerLog(Format("%s used ttt_print_traitors\n", IsValid(ply) and ply:Nick() or "console"))

local pr = GetPrintFn(ply)
local ps = select(2, playerIterator())
local ps = playerGetAll()

table.sort(ps, TraitorSort)

Expand All @@ -75,7 +75,7 @@ function PrintGroups(ply)

pr("User", "-", "Group")

local plys = select(2, playerIterator())
local plys = playerGetAll()
for i = 1, #plys do
local p = plys[i]
pr(p:Nick(), "-", p:GetNWString("UserGroup"))
Expand Down
2 changes: 1 addition & 1 deletion gamemodes/terrortown/gamemode/server/sv_armor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ end)
-- @realm server
-- @internal
function ARMOR:InitPlayerArmor()
local plys = select(2, player.Iterator())
local plys = player.GetAll()

for i = 1, #plys do
local ply = plys[i]
Expand Down
6 changes: 3 additions & 3 deletions gamemodes/terrortown/gamemode/server/sv_gamemsg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local net = net
local string = string
local table = table
local IsValid = IsValid
local playerIterator = player.Iterator
local playerGetAll = player.GetAll

---
-- Sends a GameMessage to every @{Player}
Expand Down Expand Up @@ -104,7 +104,7 @@ end
-- @realm server
-- @internal
function ShowRoundStartPopup()
local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
local ply = plys[i]
Expand All @@ -124,7 +124,7 @@ end
-- @realm server
function GetPlayerFilter(pred)
local filter = {}
local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
local ply = plys[i]
Expand Down
16 changes: 8 additions & 8 deletions gamemodes/terrortown/gamemode/server/sv_karma.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ KARMA.reason = {

local IsValid = IsValid
local hook = hook
local playerIterator = player.Iterator
local playerGetAll = player.GetAll

local function IsDebug()
return config.debug:GetBool()
Expand Down Expand Up @@ -571,7 +571,7 @@ function KARMA.RoundIncrement()
local healbonus = config.roundheal:GetFloat()
local cleanbonus = config.clean:GetFloat()

local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
local ply = plys[i]
Expand All @@ -592,7 +592,7 @@ end
-- When a new round starts, Live karma becomes Base karma
-- @realm server
function KARMA.Rebase()
local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
local ply = plys[i]
Expand All @@ -609,7 +609,7 @@ end
-- Apply karma to damage factor for all players
-- @realm server
function KARMA.ApplyKarmaAll()
local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
KARMA.ApplyKarma(plys[i])
Expand Down Expand Up @@ -674,7 +674,7 @@ function KARMA.RoundPrepare()
return
end

local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
local ply = plys[i]
Expand All @@ -693,7 +693,7 @@ function KARMA.CheckAutoKickAll()
return
end

local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
KARMA.CheckAutoKick(plys[i])
Expand Down Expand Up @@ -777,7 +777,7 @@ end
-- @realm server
-- @see KARMA.Remember
function KARMA.RememberAll()
local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
KARMA.Remember(plys[i])
Expand Down Expand Up @@ -826,7 +826,7 @@ end
-- @param function printfn
-- @realm server
function KARMA.PrintAll(printfn)
local plys = select(2, playerIterator())
local plys = playerGetAll()

for i = 1, #plys do
local ply = plys[i]
Expand Down
Loading

0 comments on commit 297be1b

Please sign in to comment.