From d4d1b9a0d85bfa07a5f5baa9a01b11533b943e8d Mon Sep 17 00:00:00 2001 From: = Date: Wed, 22 Jun 2022 08:40:56 +0300 Subject: [PATCH] Add object itself to the collision set instead of checking it each iteration --- shash.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shash.lua b/shash.lua index ce33a93..d91f15c 100644 --- a/shash.lua +++ b/shash.lua @@ -187,7 +187,7 @@ local function each_overlapping_in_cell(self, idx, e, set, fn, ...) return end 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], ...) set[v] = true end @@ -198,6 +198,7 @@ end local function each_overlapping_entity(self, e, fn, ...) -- Init set for keeping track of which entities have already been handled local set = table_remove(self.tablepool) or {} + set[e] = true -- do not check object itself -- Do overlap checks each_overlapping_cell(self, e, each_overlapping_in_cell, e, set, fn, ...) -- Clear set and return to pool