fix(client/zones): use arrays for temporary zone tables

Resolves #682.
This commit is contained in:
Linden
2025-01-20 02:04:21 +11:00
parent 86f0d7b789
commit 356e560a5d

View File

@@ -98,20 +98,22 @@ end
---@type table<number, CZone>
local insideZones = {}
---@type table<number, CZone>
local enteringZones = {}
---@type table<number, CZone>
local exitingZones = {}
local enteringSize = 0
local exitingSize = 0
---@type CZone[] | Array
local exitingZones = lib.array:new()
---@type CZone[] | Array
local enteringZones = lib.array:new()
local tick
local glm_polygon_contains = glm.polygon.contains
local function removeZone(self)
Zones[self.id] = nil
insideZones[self.id] = nil
enteringZones[self.id] = nil
exitingZones[self.id] = nil
local function removeZone(zone)
Zones[zone.id] = nil
insideZones[zone.id] = nil
table.remove(exitingZones, exitingZones:indexOf(zone))
table.remove(enteringZones, enteringZones:indexOf(zone))
end
CreateThread(function()
@@ -134,8 +136,7 @@ CreateThread(function()
zone.insideZone = true
if zone.onEnter then
enteringSize += 1
enteringZones[enteringSize] = zone
enteringZones:push(zone)
end
if zone.inside or zone.debug then
@@ -148,8 +149,7 @@ CreateThread(function()
insideZones[zone.id] = nil
if zone.onExit then
exitingSize += 1
exitingZones[exitingSize] = zone
exitingZones:push(zone)
end
end
@@ -159,6 +159,9 @@ CreateThread(function()
end
end
local exitingSize = #exitingZones
local enteringSize = #enteringZones
if exitingSize > 0 then
table.sort(exitingZones, function(a, b)
return a.distance > b.distance
@@ -168,7 +171,6 @@ CreateThread(function()
exitingZones[i]:onExit()
end
exitingSize = 0
table.wipe(exitingZones)
end
@@ -181,7 +183,6 @@ CreateThread(function()
enteringZones[i]:onEnter()
end
enteringSize = 0
table.wipe(enteringZones)
end