Skip to content

Commit

Permalink
Only send onEntitiesCreated data on change
Browse files Browse the repository at this point in the history
Relevant for #325
  • Loading branch information
FPtje committed Mar 16, 2024
1 parent 2638f8d commit d7f8cda
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lua/fpp/server/ownability.lua
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ end
On entity created
---------------------------------------------------------------------------]]
local function onEntitiesCreated(ents)
local send = {}
-- Table from player to list of entities that need to be networked
local sendToPlayers = {}

for _, ent in pairs(ents) do
if not IsValid(ent) then continue end
Expand All @@ -391,13 +392,16 @@ local function onEntitiesCreated(ents)
if blockedEnts[ent:GetClass()] then continue end

for _, ply in ipairs(player.GetAll()) do
FPP.calculateCanTouch(ply, ent)
local changed = FPP.calculateCanTouch(ply, ent)
-- Only send data that has been changed
if not changed then continue end
sendToPlayers[ply] = sendToPlayers[ply] or {}
table.insert(sendToPlayers[ply], ent)
end
table.insert(send, ent)
end

for _, ply in ipairs(player.GetAll()) do
FPP.plySendTouchData(ply, send)
for ply, entsToSend in pairs(sendToPlayers) do
FPP.plySendTouchData(ply, entsToSend)
end
end

Expand Down

0 comments on commit d7f8cda

Please sign in to comment.