Skip to content

Commit fd45084

Browse files
EntranceJewTimGollHistalek
authored
upstream changes (#1453)
- Iterator changes (won't be live until next release) - Read/WritePlayer [these were not thoroughly tested] - game.CleanUpMap changes - replace self.Weapon/self.Entity - use less bits for radar net message --------- Co-authored-by: Tim Goll <github@timgoll.de> Co-authored-by: Histalek <16392835+Histalek@users.noreply.github.com>
1 parent c2bc8b3 commit fd45084

43 files changed

Lines changed: 136 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
2626
- The binoculars now use the default crosshair as well
2727
- Tracers are now drawn for every shot/pellet instead of only 25% of shots/pellets
2828
- The ConVar "ttt_debug_preventwin" will now also prevent the time limit from ending the round (by @NickCloudAT)
29+
- Micro optimizations
30+
- switched from `player.GetAll()` to `select(2, player.Iterator())`
31+
- use `net.ReadPlayer` / `net.WritePlayer` if applicable instead of `net.Read|WriteEntity`
32+
- Reduced radar bit size for net message
2933

3034
### Fixed
3135

gamemodes/terrortown/entities/entities/ttt_base_placeable.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ if SERVER then
179179
end
180180

181181
local pos = self:GetPos()
182-
local ignore = player.GetAll()
182+
local ignore = select(2, player.Iterator())
183183

184184
ignore[#ignore + 1] = self
185185

gamemodes/terrortown/entities/entities/ttt_c4/shared.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local hook = hook
88
local table = table
99
local net = net
1010
local IsValid = IsValid
11+
local playerIterator = player.Iterator
1112

1213
local defuserNearRadius = 90000
1314

@@ -171,11 +172,10 @@ function ENT:SphereDamage(dmgowner, center, radius)
171172
local d = 0.0
172173
local diff = nil
173174
local dmg = 0
174-
local plys = player.GetAll()
175175

176+
local plys = select(2, playerIterator())
176177
for i = 1, #plys do
177178
local ply = plys[i]
178-
179179
if ply:Team() ~= TEAM_TERROR then
180180
continue
181181
end
@@ -321,11 +321,10 @@ function ENT:IsDefuserInRange()
321321
local center = self:GetPos()
322322
local d = 0.0
323323
local diff = nil
324-
local plys = player.GetAll()
325324

325+
local plys = select(2, playerIterator())
326326
for i = 1, #plys do
327327
local ply = plys[i]
328-
329328
if not ply:IsActive() or not ply:GetSubRoleData().isPolicingRole then
330329
continue
331330
end

gamemodes/terrortown/entities/entities/ttt_traitor_check.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function ENT:CountValidPlayers(activator, caller, data)
3232
local mins = self:LocalToWorld(self:OBBMins())
3333
local maxs = self:LocalToWorld(self:OBBMaxs())
3434

35-
local plys = player.GetAll()
35+
local plys = select(2, player.Iterator())
3636
local count = 0
3737

3838
for i = 1, #plys do

gamemodes/terrortown/entities/entities/ttt_weapon_check.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ function ENT:TestWeapons(weptype)
109109
return 0
110110
end
111111

112-
for _, ply in ipairs(player.GetAll()) do
112+
local plys = select(2, player.Iterator())
113+
114+
for i = 1, #plys do
115+
local ply = plys[i]
113116
if IsValid(ply) and ply:IsTerror() then
114117
local pos = ply:GetPos()
115118
local center = ply:LocalToWorld(ply:OBBCenter())

gamemodes/terrortown/entities/weapons/weapon_ttt_phammer.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function SWEP:PrimaryAttack()
147147
local tr = util.TraceLine({
148148
start = ply:GetShootPos(),
149149
endpos = ply:GetShootPos() + ply:GetAimVector() * self.MaxRange,
150-
filter = { ply, self.Entity },
150+
filter = { ply, self },
151151
mask = MASK_SOLID,
152152
})
153153

@@ -191,7 +191,7 @@ function SWEP:SecondaryAttack()
191191
local tr = util.TraceLine({
192192
start = ply:GetShootPos(),
193193
endpos = ply:GetShootPos() + ply:GetAimVector() * range,
194-
filter = { ply, self.Entity },
194+
filter = { ply, self },
195195
mask = MASK_SOLID,
196196
})
197197

gamemodes/terrortown/entities/weapons/weapon_ttt_teleport.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ local function CanTeleportToPos(ply, pos)
176176
start = pos,
177177
endpos = pos,
178178
mask = MASK_PLAYERSOLID,
179-
filter = player.GetAll(),
179+
filter = select(2, player.Iterator()),
180180
}
181181
local collide = false
182182

gamemodes/terrortown/entities/weapons/weapon_zm_carry.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ function SWEP:CheckValidity()
273273
end
274274

275275
local function PlayerStandsOn(ent)
276-
local plys = player.GetAll()
276+
local plys = select(2, player.Iterator())
277277

278278
for i = 1, #plys do
279279
local ply = plys[i]

gamemodes/terrortown/gamemode/client/cl_chat.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ local color_4 = Color(255, 200, 20)
1616
local color_5 = Color(255, 255, 200)
1717

1818
local function LastWordsRecv()
19-
local sender = net.ReadEntity()
19+
local sender = net.ReadPlayer()
2020
local words = net.ReadString()
2121

2222
local validSender = IsValid(sender)
@@ -36,7 +36,7 @@ end
3636
net.Receive("TTT_LastWordsMsg", LastWordsRecv)
3737

3838
local function TTT_RoleChat()
39-
local sender = net.ReadEntity()
39+
local sender = net.ReadPlayer()
4040
if not IsValid(sender) then
4141
return
4242
end

gamemodes/terrortown/gamemode/client/cl_main.lua

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local util = util
99
local IsValid = IsValid
1010
local surface = surface
1111
local hook = hook
12+
local playerIterator = player.Iterator
1213

1314
-- Define GM12 fonts for compatibility
1415
surface.CreateFont("DefaultBold", { font = "Tahoma", size = 13, weight = 1000 })
@@ -348,8 +349,7 @@ function GM:InitPostEntity()
348349
end
349350

350351
-- cache players avatar
351-
local plys = player.GetAll()
352-
352+
local plys = select(2, playerIterator())
353353
for i = 1, #plys do
354354
local plyid64 = plys[i]:SteamID64()
355355

@@ -452,8 +452,6 @@ function GetRoundState()
452452
end
453453

454454
local function RoundStateChange(o, n)
455-
local plys = player.GetAll()
456-
457455
if n == ROUND_PREP then
458456
-- prep starts
459457
GAMEMODE:ClearClientState()
@@ -489,6 +487,7 @@ local function RoundStateChange(o, n)
489487
CLSCORE:ClearPanel()
490488

491489
-- people may have died and been searched during prep
490+
local plys = select(2, playerIterator())
492491
for i = 1, #plys do
493492
bodysearch.ResetSearchResult(plys[i])
494493
end
@@ -529,11 +528,10 @@ local function RoundStateChange(o, n)
529528
-- whatever round state we get, clear out the voice flags
530529
local winTeams = roles.GetWinTeams()
531530

531+
local plys = select(2, playerIterator())
532532
for i = 1, #plys do
533-
local pl = plys[i]
534-
535533
for k = 1, #winTeams do
536-
pl[winTeams[k] .. "_gvoice"] = false
534+
plys[i][winTeams[k] .. "_gvoice"] = false
537535
end
538536
end
539537
end
@@ -565,8 +563,7 @@ end
565563
net.Receive("TTT_Role", ReceiveRole)
566564

567565
local function ReceiveRoleReset()
568-
local plys = player.GetAll()
569-
566+
local plys = select(2, playerIterator())
570567
for i = 1, #plys do
571568
plys[i]:SetRole(ROLE_NONE, TEAM_NONE)
572569
end
@@ -651,8 +648,7 @@ function GM:ClearClientState()
651648

652649
VOICE.InitBattery()
653650

654-
local plys = player.GetAll()
655-
651+
local plys = select(2, playerIterator())
656652
for i = 1, #plys do
657653
local pl = plys[i]
658654
if not IsValid(pl) then

0 commit comments

Comments
 (0)