Add object itself to the collision set instead of checking it each iteration

This commit is contained in:
= 2022-06-22 08:40:56 +03:00
parent 56a0dc8d5f
commit d4d1b9a0d8

View File

@ -187,7 +187,7 @@ local function each_overlapping_in_cell(self, idx, e, set, fn, ...)
return return
end end
for i, v in ipairs(t) do for i, v in ipairs(t) do
if e ~= v and overlaps(e, v) and not set[v] then if overlaps(e, v) and not set[v] then
fn(v[5], ...) fn(v[5], ...)
set[v] = true set[v] = true
end end
@ -198,6 +198,7 @@ end
local function each_overlapping_entity(self, e, fn, ...) local function each_overlapping_entity(self, e, fn, ...)
-- Init set for keeping track of which entities have already been handled -- Init set for keeping track of which entities have already been handled
local set = table_remove(self.tablepool) or {} local set = table_remove(self.tablepool) or {}
set[e] = true -- do not check object itself
-- Do overlap checks -- Do overlap checks
each_overlapping_cell(self, e, each_overlapping_in_cell, e, set, fn, ...) each_overlapping_cell(self, e, each_overlapping_in_cell, e, set, fn, ...)
-- Clear set and return to pool -- Clear set and return to pool