Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 356e560

Browse files
committed
fix(client/zones): use arrays for temporary zone tables
Resolves #682.
1 parent 86f0d7b commit 356e560

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

imports/zones/client.lua

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,22 @@ end
9898

9999
---@type table<number, CZone>
100100
local insideZones = {}
101-
---@type table<number, CZone>
102-
local enteringZones = {}
103-
---@type table<number, CZone>
104-
local exitingZones = {}
105-
local enteringSize = 0
106-
local exitingSize = 0
101+
102+
---@type CZone[] | Array
103+
local exitingZones = lib.array:new()
104+
105+
---@type CZone[] | Array
106+
local enteringZones = lib.array:new()
107+
107108
local tick
108109
local glm_polygon_contains = glm.polygon.contains
109110

110-
local function removeZone(self)
111-
Zones[self.id] = nil
112-
insideZones[self.id] = nil
113-
enteringZones[self.id] = nil
114-
exitingZones[self.id] = nil
111+
local function removeZone(zone)
112+
Zones[zone.id] = nil
113+
insideZones[zone.id] = nil
114+
115+
table.remove(exitingZones, exitingZones:indexOf(zone))
116+
table.remove(enteringZones, enteringZones:indexOf(zone))
115117
end
116118

117119
CreateThread(function()
@@ -134,8 +136,7 @@ CreateThread(function()
134136
zone.insideZone = true
135137

136138
if zone.onEnter then
137-
enteringSize += 1
138-
enteringZones[enteringSize] = zone
139+
enteringZones:push(zone)
139140
end
140141

141142
if zone.inside or zone.debug then
@@ -148,8 +149,7 @@ CreateThread(function()
148149
insideZones[zone.id] = nil
149150

150151
if zone.onExit then
151-
exitingSize += 1
152-
exitingZones[exitingSize] = zone
152+
exitingZones:push(zone)
153153
end
154154
end
155155

@@ -159,6 +159,9 @@ CreateThread(function()
159159
end
160160
end
161161

162+
local exitingSize = #exitingZones
163+
local enteringSize = #enteringZones
164+
162165
if exitingSize > 0 then
163166
table.sort(exitingZones, function(a, b)
164167
return a.distance > b.distance
@@ -168,7 +171,6 @@ CreateThread(function()
168171
exitingZones[i]:onExit()
169172
end
170173

171-
exitingSize = 0
172174
table.wipe(exitingZones)
173175
end
174176

@@ -181,7 +183,6 @@ CreateThread(function()
181183
enteringZones[i]:onEnter()
182184
end
183185

184-
enteringSize = 0
185186
table.wipe(enteringZones)
186187
end
187188

0 commit comments

Comments
 (0)