Skip to content

Commit

Permalink
Replace ents.GetAll and player.GetAll
Browse files Browse the repository at this point in the history
Replace all ents.GetAll and player.GetAll to ents.Iterator and player.Iterator for performance reasons
  • Loading branch information
Winkarst-cpu committed May 23, 2024
1 parent 6e3011a commit ed92319
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions gamemode/config/sh_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ ix.config.Add("saveInterval", 300, "How often characters save in seconds.", nil,
category = "characters"
})
ix.config.Add("walkSpeed", 130, "How fast a player normally walks.", function(oldValue, newValue)
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
v:SetWalkSpeed(newValue)
end
end, {
data = {min = 75, max = 500},
category = "characters"
})
ix.config.Add("runSpeed", 235, "How fast a player normally runs.", function(oldValue, newValue)
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
v:SetRunSpeed(newValue)
end
end, {
Expand Down
12 changes: 6 additions & 6 deletions gamemode/core/hooks/sv_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function GM:PlayerInitialSpawn(client)
client.ixLoaded = true
client:SetData("intro", true)

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v:GetCharacter()) then
v:GetCharacter():Sync(client)
end
Expand Down Expand Up @@ -451,7 +451,7 @@ local function CalcPlayerCanHearPlayersVoice(listener)
listener.ixVoiceHear = listener.ixVoiceHear or {}

local eyePos = listener:EyePos()
for _, speaker in ipairs(player.GetAll()) do
for _, speaker in player.Iterator() do
local speakerEyePos = speaker:EyePos()
listener.ixVoiceHear[speaker] = eyePos:DistToSqr(speakerEyePos) < voiceDistance
end
Expand All @@ -465,7 +465,7 @@ function GM:InitializedConfig()
end

function GM:VoiceToggled(bAllowVoice)
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
local uniqueID = v:SteamID64() .. "ixCanHearPlayersVoice"

if (bAllowVoice) then
Expand Down Expand Up @@ -724,7 +724,7 @@ function GM:PlayerDisconnected(client)
return
end

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (!v.ixVoiceHear) then
continue
end
Expand Down Expand Up @@ -771,7 +771,7 @@ function GM:ShutDown()

hook.Run("SaveData")

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
v:SaveData()

if (v:GetCharacter()) then
Expand Down Expand Up @@ -877,7 +877,7 @@ function GM:CharacterPreSave(character)
end

timer.Create("ixLifeGuard", 1, 0, function()
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v:GetCharacter() and v:Alive() and hook.Run("ShouldPlayerDrowned", v) != false) then
if (v:WaterLevel() >= 3) then
if (!v.drowningTime) then
Expand Down
2 changes: 1 addition & 1 deletion gamemode/core/libs/sh_chatbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ if (SERVER) then
if (class.CanHear and !receivers) then
receivers = {}

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v:GetCharacter() and class:CanHear(speaker, v, data) != false) then
receivers[#receivers + 1] = v
end
Expand Down
2 changes: 1 addition & 1 deletion gamemode/core/libs/sh_class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ end
function ix.class.GetPlayers(class)
local players = {}

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
local char = v:GetCharacter()

if (char and char:GetClass() == class) then
Expand Down
4 changes: 2 additions & 2 deletions gamemode/core/meta/sh_character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ if (SERVER) then
function CHAR:Sync(receiver)
-- Broadcast the character information if receiver is not set.
if (receiver == nil) then
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
self:Sync(v)
end
-- Send all character information if the receiver is the character's owner.
Expand Down Expand Up @@ -250,7 +250,7 @@ function CHAR:GetPlayer()
elseif (self.steamID) then
local steamID = self.steamID

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v:SteamID64() == steamID) then
self.player = v

Expand Down
4 changes: 2 additions & 2 deletions gamemode/core/meta/sh_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ if (SERVER) then
self.ignoreUse = false
self.ixIsMuted = false

for _, v in ipairs(ents.GetAll()) do
for _, v in ents.Iterator() do
if (v:GetParent() == self) then
v:SetNotSolid(false)
v:SetNoDraw(false)
Expand Down Expand Up @@ -150,7 +150,7 @@ if (SERVER) then
dummy:SetBodygroup(v.id, self:GetBodygroup(v.id))
end

for _, v in ipairs(ents.GetAll()) do
for _, v in ents.Iterator() do
if (v:GetParent() == self) then
v:SetNotSolid(true)
v:SetNoDraw(true)
Expand Down
4 changes: 2 additions & 2 deletions gamemode/core/meta/sh_inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ end
-- @treturn[1] Player Owning player
-- @treturn[2] nil If no connected player owns this inventory
function META:GetOwner()
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v:GetCharacter() and v:GetCharacter().id == self.owner) then
return v
end
Expand All @@ -170,7 +170,7 @@ function META:SetOwner(owner, fullUpdate)

if (SERVER) then
if (fullUpdate) then
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v:GetNetVar("char") == owner) then
self:Sync(v, true)

Expand Down
2 changes: 1 addition & 1 deletion gamemode/core/meta/sh_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function ITEM:GetOwner()

local id = self:GetID()

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
local character = v:GetCharacter()

if (character and character:GetInventory():GetItemByID(id)) then
Expand Down
26 changes: 13 additions & 13 deletions gamemode/core/sh_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ix.command.Add("CharGiveFlag", {

target:GiveFlags(flags)

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("flagGive", client:GetName(), target:GetName(), flags)
end
Expand All @@ -125,7 +125,7 @@ ix.command.Add("CharTakeFlag", {

target:TakeFlags(flags)

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("flagTake", client:GetName(), flags, target:GetName())
end
Expand Down Expand Up @@ -155,7 +155,7 @@ ix.command.Add("CharSetModel", {
target:SetModel(model)
target:GetPlayer():SetupHands()

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("cChangeModel", client:GetName(), target:GetName(), model)
end
Expand All @@ -174,7 +174,7 @@ ix.command.Add("CharSetSkin", {
target:SetData("skin", skin)
target:GetPlayer():SetSkin(skin or 0)

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("cChangeSkin", client:GetName(), target:GetName(), skin or 0)
end
Expand Down Expand Up @@ -267,7 +267,7 @@ ix.command.Add("CharSetName", {
end, target:GetName())
end

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("cChangeName", client:GetName(), target:GetName(), newName)
end
Expand Down Expand Up @@ -322,7 +322,7 @@ ix.command.Add("CharKick", {
target:Kick()
end)

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("charKick", client:GetName(), target:GetName())
end
Expand All @@ -346,7 +346,7 @@ ix.command.Add("CharBan", {
target:Ban(minutes)
target:Save()

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("charBan", client:GetName(), target:GetName())
end
Expand All @@ -372,7 +372,7 @@ ix.command.Add("CharUnban", {
return "@charNotBanned"
end

for _, v2 in ipairs(player.GetAll()) do
for _, v2 in player.Iterator() do
if (self:OnCheckAccess(v2) or v2 == v:GetPlayer()) then
v2:NotifyLocalized("charUnBan", client:GetName(), v:GetName())
end
Expand Down Expand Up @@ -409,7 +409,7 @@ ix.command.Add("CharUnban", {
updateQuery:Where("id", characterID)
updateQuery:Execute()

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v)) then
v:NotifyLocalized("charUnBan", client:GetName(), name)
end
Expand Down Expand Up @@ -529,7 +529,7 @@ ix.command.Add("PlyWhitelist", {

if (faction) then
if (target:SetWhitelisted(faction.index, true)) then
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target) then
v:NotifyLocalized("whitelist", client:GetName(), target:GetName(), L(faction.name, v))
end
Expand Down Expand Up @@ -590,7 +590,7 @@ ix.command.Add("PlyUnwhitelist", {
local targetPlayer = ix.util.FindPlayer(target)

if (IsValid(targetPlayer) and targetPlayer:SetWhitelisted(faction.index, false)) then
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == targetPlayer) then
v:NotifyLocalized("unwhitelist", client:GetName(), targetPlayer:GetName(), L(faction.name, v))
end
Expand All @@ -617,7 +617,7 @@ ix.command.Add("PlyUnwhitelist", {
updateQuery:Where("steamid", steamID64)
updateQuery:Execute()

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v)) then
v:NotifyLocalized("unwhitelist", client:GetName(), target, L(faction.name, v))
end
Expand Down Expand Up @@ -739,7 +739,7 @@ ix.command.Add("PlyTransfer", {
faction:OnTransferred(target)
end

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("cChangeFaction", client:GetName(), target:GetName(), L(faction.name, v))
end
Expand Down
2 changes: 1 addition & 1 deletion gamemode/core/sh_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function ix.util.FindPlayer(identifier, bAllowPatterns)
identifier = string.PatternSafe(identifier)
end

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (ix.util.StringMatches(v:Name(), identifier)) then
return v
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/area/sv_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function PLUGIN:PlayerSpawn(client)
end

function PLUGIN:AreaThink()
for _, client in ipairs(player.GetAll()) do
for _, client in player.Iterator() do
local character = client:GetCharacter()

if (!client:Alive() or !character) then
Expand Down
2 changes: 1 addition & 1 deletion plugins/doors/derma/cl_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function PANEL:SetDoor(door, access, door2)
self.accessData = access
self.door = door

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v != LocalPlayer() and v:GetCharacter()) then
self.access:AddLine(v:Name(), L(ACCESS_LABELS[access[v] or 0])).player = v
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/doors/sv_plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function PLUGIN:SaveDoorData()
local data = {}
local doors = {}

for _, v in ipairs(ents.GetAll()) do
for _, v in ents.Iterator() do
if (v:IsDoor()) then
doors[v:MapCreationID()] = v
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/observer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (CLIENT) then
!client:InVehicle() and CAMI.PlayerHasAccess(client, "Helix - Observer", nil)) then
local scrW, scrH = ScrW(), ScrH()

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v == client or !v:GetCharacter() or client:GetAimVector():Dot((v:GetPos() - client:GetPos()):GetNormal()) < 0.65) then
continue
end
Expand Down
4 changes: 2 additions & 2 deletions plugins/pac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ else
end

if (IsValid(pac.LocalPlayer)) then
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
local character = v:GetCharacter()

if (character) then
Expand Down Expand Up @@ -302,7 +302,7 @@ else
end

if (class:find("HL2MPRagdoll")) then
for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v:GetRagdollEntity() == entity) then
entity.objCache = v
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/recognition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ else

class = ix.chat.classes[class]

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (client != v and v:GetCharacter() and class:CanHear(client, v)) then
targets[#targets + 1] = v
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/typing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ if (CLIENT) then
local client = LocalPlayer()
local position = client:GetPos()

for _, v in ipairs(player.GetAll()) do
for _, v in player.Iterator() do
if (v == client) then
continue
end
Expand Down

0 comments on commit ed92319

Please sign in to comment.