98
98
99
99
--- @type table<number , CZone>
100
100
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
+
107
108
local tick
108
109
local glm_polygon_contains = glm .polygon .contains
109
110
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 ))
115
117
end
116
118
117
119
CreateThread (function ()
@@ -134,8 +136,7 @@ CreateThread(function()
134
136
zone .insideZone = true
135
137
136
138
if zone .onEnter then
137
- enteringSize += 1
138
- enteringZones [enteringSize ] = zone
139
+ enteringZones :push (zone )
139
140
end
140
141
141
142
if zone .inside or zone .debug then
@@ -148,8 +149,7 @@ CreateThread(function()
148
149
insideZones [zone .id ] = nil
149
150
150
151
if zone .onExit then
151
- exitingSize += 1
152
- exitingZones [exitingSize ] = zone
152
+ exitingZones :push (zone )
153
153
end
154
154
end
155
155
@@ -159,6 +159,9 @@ CreateThread(function()
159
159
end
160
160
end
161
161
162
+ local exitingSize = # exitingZones
163
+ local enteringSize = # enteringZones
164
+
162
165
if exitingSize > 0 then
163
166
table.sort (exitingZones , function (a , b )
164
167
return a .distance > b .distance
@@ -168,7 +171,6 @@ CreateThread(function()
168
171
exitingZones [i ]:onExit ()
169
172
end
170
173
171
- exitingSize = 0
172
174
table .wipe (exitingZones )
173
175
end
174
176
@@ -181,7 +183,6 @@ CreateThread(function()
181
183
enteringZones [i ]:onEnter ()
182
184
end
183
185
184
- enteringSize = 0
185
186
table .wipe (enteringZones )
186
187
end
187
188
0 commit comments