Skip to content

Commit

Permalink
upstream changes (#1453)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
Co-authored-by: Histalek <[email protected]>
  • Loading branch information
3 people authored Mar 10, 2024
1 parent c2bc8b3 commit fd45084
Show file tree
Hide file tree
Showing 43 changed files with 136 additions and 117 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- The binoculars now use the default crosshair as well
- Tracers are now drawn for every shot/pellet instead of only 25% of shots/pellets
- The ConVar "ttt_debug_preventwin" will now also prevent the time limit from ending the round (by @NickCloudAT)
- Micro optimizations
- switched from `player.GetAll()` to `select(2, player.Iterator())`
- use `net.ReadPlayer` / `net.WritePlayer` if applicable instead of `net.Read|WriteEntity`
- Reduced radar bit size for net message

### Fixed

Expand Down
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 = player.GetAll()
local ignore = select(2, player.Iterator())

ignore[#ignore + 1] = self

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

local defuserNearRadius = 90000

Expand Down Expand Up @@ -171,11 +172,10 @@ function ENT:SphereDamage(dmgowner, center, radius)
local d = 0.0
local diff = nil
local dmg = 0
local plys = player.GetAll()

local plys = select(2, playerIterator())
for i = 1, #plys do
local ply = plys[i]

if ply:Team() ~= TEAM_TERROR then
continue
end
Expand Down Expand Up @@ -321,11 +321,10 @@ function ENT:IsDefuserInRange()
local center = self:GetPos()
local d = 0.0
local diff = nil
local plys = player.GetAll()

local plys = select(2, playerIterator())
for i = 1, #plys do
local ply = plys[i]

if not ply:IsActive() or not ply:GetSubRoleData().isPolicingRole then
continue
end
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 = player.GetAll()
local plys = select(2, player.Iterator())
local count = 0

for i = 1, #plys do
Expand Down
5 changes: 4 additions & 1 deletion gamemodes/terrortown/entities/entities/ttt_weapon_check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ function ENT:TestWeapons(weptype)
return 0
end

for _, ply in ipairs(player.GetAll()) do
local plys = select(2, player.Iterator())

for i = 1, #plys do
local ply = plys[i]
if IsValid(ply) and ply:IsTerror() then
local pos = ply:GetPos()
local center = ply:LocalToWorld(ply:OBBCenter())
Expand Down
4 changes: 2 additions & 2 deletions gamemodes/terrortown/entities/weapons/weapon_ttt_phammer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function SWEP:PrimaryAttack()
local tr = util.TraceLine({
start = ply:GetShootPos(),
endpos = ply:GetShootPos() + ply:GetAimVector() * self.MaxRange,
filter = { ply, self.Entity },
filter = { ply, self },
mask = MASK_SOLID,
})

Expand Down Expand Up @@ -191,7 +191,7 @@ function SWEP:SecondaryAttack()
local tr = util.TraceLine({
start = ply:GetShootPos(),
endpos = ply:GetShootPos() + ply:GetAimVector() * range,
filter = { ply, self.Entity },
filter = { ply, self },
mask = MASK_SOLID,
})

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 = player.GetAll(),
filter = select(2, player.Iterator()),
}
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 = player.GetAll()
local plys = select(2, player.Iterator())

for i = 1, #plys do
local ply = plys[i]
Expand Down
4 changes: 2 additions & 2 deletions gamemodes/terrortown/gamemode/client/cl_chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local color_4 = Color(255, 200, 20)
local color_5 = Color(255, 255, 200)

local function LastWordsRecv()
local sender = net.ReadEntity()
local sender = net.ReadPlayer()
local words = net.ReadString()

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

local function TTT_RoleChat()
local sender = net.ReadEntity()
local sender = net.ReadPlayer()
if not IsValid(sender) then
return
end
Expand Down
18 changes: 7 additions & 11 deletions gamemodes/terrortown/gamemode/client/cl_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local util = util
local IsValid = IsValid
local surface = surface
local hook = hook
local playerIterator = player.Iterator

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

-- cache players avatar
local plys = player.GetAll()

local plys = select(2, playerIterator())
for i = 1, #plys do
local plyid64 = plys[i]:SteamID64()

Expand Down Expand Up @@ -452,8 +452,6 @@ function GetRoundState()
end

local function RoundStateChange(o, n)
local plys = player.GetAll()

if n == ROUND_PREP then
-- prep starts
GAMEMODE:ClearClientState()
Expand Down Expand Up @@ -489,6 +487,7 @@ local function RoundStateChange(o, n)
CLSCORE:ClearPanel()

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

local plys = select(2, playerIterator())
for i = 1, #plys do
local pl = plys[i]

for k = 1, #winTeams do
pl[winTeams[k] .. "_gvoice"] = false
plys[i][winTeams[k] .. "_gvoice"] = false
end
end
end
Expand Down Expand Up @@ -565,8 +563,7 @@ end
net.Receive("TTT_Role", ReceiveRole)

local function ReceiveRoleReset()
local plys = player.GetAll()

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

VOICE.InitBattery()

local plys = player.GetAll()

local plys = select(2, playerIterator())
for i = 1, #plys do
local pl = plys[i]
if not IsValid(pl) then
Expand Down
4 changes: 2 additions & 2 deletions gamemodes/terrortown/gamemode/client/cl_player_ext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ end
function GM:GrabEarAnimation(ply) end

local function TTT_PerformGesture()
local ply = net.ReadEntity()
local ply = net.ReadPlayer()
local act = net.ReadUInt(16)

if not IsValid(ply) or act == nil then
Expand All @@ -159,7 +159,7 @@ net.Receive("StartDrowning", StartDrowning)

local function TargetPlayer()
local client = LocalPlayer()
local target = net.ReadEntity()
local target = net.ReadPlayer()

if not IsValid(client) then
return
Expand Down
2 changes: 1 addition & 1 deletion gamemodes/terrortown/gamemode/client/cl_radio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ end
concommand.Add("ttt_radio", RadioCommand, RadioComplete)

local function RadioMsgRecv()
local sender = net.ReadEntity()
local sender = net.ReadPlayer()
local msg = net.ReadString()
local param = net.ReadString()

Expand Down
5 changes: 3 additions & 2 deletions gamemodes/terrortown/gamemode/client/cl_targetid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local math = math
local IsValid = IsValid
local hook = hook
local targetid = targetid
local playerIterator = player.Iterator

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

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

local tgt, scrpos, color, _
local plys = player.GetAll()
local plys = select(2, playerIterator())

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 = player.GetAll()
local plys = select(2, player.Iterator())

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

ttt_include("vgui__cl_sb_team")

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

-- Put players where they belong. Groups will dump them as soon as they don't
-- anymore.
for _, p in ipairs(player.GetAll()) do
local plys = select(2, playerIterator())
for i = 1, #plys do
local p = plys[i]
if IsValid(p) then
local group = ScoreGroup(p)

Expand Down
7 changes: 5 additions & 2 deletions gamemodes/terrortown/gamemode/server/sv_admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local pairs = pairs
local ipairs = ipairs
local util = util
local IsValid = IsValid
local playerIterator = player.Iterator

local function GetPrintFn(ply)
if IsValid(ply) then
Expand Down Expand Up @@ -54,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 = player.GetAll()
local ps = select(2, playerIterator())

table.sort(ps, TraitorSort)

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

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

for _, p in ipairs(player.GetAll()) do
local plys = select(2, playerIterator())
for i = 1, #plys do
local p = plys[i]
pr(p:Nick(), "-", p:GetNWString("UserGroup"))
end
end
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 = player.GetAll()
local plys = select(2, player.Iterator())

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

---
-- Sends a GameMessage to every @{Player}
Expand Down Expand Up @@ -93,7 +94,7 @@ local function RoleChatMsg(sender, msg)
end

net.Start("TTT_RoleChat")
net.WriteEntity(sender)
net.WritePlayer(sender)
net.WriteString(msg)
net.Send(GetTeamChatFilter(senderTeam))
end
Expand All @@ -103,7 +104,7 @@ end
-- @realm server
-- @internal
function ShowRoundStartPopup()
local plys = player.GetAll()
local plys = select(2, playerIterator())

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

for i = 1, #plys do
local ply = plys[i]
Expand Down Expand Up @@ -427,7 +428,7 @@ local function LastWordsMsg(ply, words)
local context = LastWordContext[ply.death_type] or ""

net.Start("TTT_LastWordsMsg")
net.WriteEntity(ply)
net.WritePlayer(ply)
net.WriteString(words .. (final and "" or "--") .. context)
net.Broadcast()
end
Expand Down Expand Up @@ -527,7 +528,7 @@ local function ttt_radio_send(ply, cmd, args)
if hook.Run("TTTPlayerRadioCommand", ply, msgName, msgTarget) then return end

net.Start("TTT_RadioMsg")
net.WriteEntity(ply)
net.WritePlayer(ply)
net.WriteString(msgName)
net.WriteString(name)

Expand Down
Loading

0 comments on commit fd45084

Please sign in to comment.