small mistake
got rid of cellkey as it was clamped to a 10 meter radius, replaced with id
This commit is contained in:
1 parent
972399ebf6
commit
6106f76b2d
1 file changed
+6
-13
@@ -32,12 +32,7 @@ end
|
|||||||
function Grid.GetCellByCoords(coords)
|
function Grid.GetCellByCoords(coords)
|
||||||
local cellX = math.floor(coords.x / CELL_SIZE) + 1
|
local cellX = math.floor(coords.x / CELL_SIZE) + 1
|
||||||
local cellY = math.floor(coords.y / CELL_SIZE) + 1
|
local cellY = math.floor(coords.y / CELL_SIZE) + 1
|
||||||
|
return Grids[cellX][cellY]
|
||||||
if Grids[cellX] and Grids[cellX][cellY] then
|
|
||||||
return Grids[cellX][cellY]
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local Points = {}
|
local Points = {}
|
||||||
@@ -102,8 +97,7 @@ function Point.Register(id, target, distance, args, _onEnter, _onExit)
|
|||||||
self.inside = false -- Track if player is inside
|
self.inside = false -- Track if player is inside
|
||||||
self.args = args or {}
|
self.args = args or {}
|
||||||
local grid = Grid.GetCellByCoords(coords)
|
local grid = Grid.GetCellByCoords(coords)
|
||||||
self.cellKey = Grid.GetCellId(coords)
|
grid[id] = self
|
||||||
grid[self.cellKey] = self
|
|
||||||
Point.All[id] = self
|
Point.All[id] = self
|
||||||
Point.StartLoop()
|
Point.StartLoop()
|
||||||
return self
|
return self
|
||||||
@@ -116,7 +110,7 @@ function Point.Remove(id)
|
|||||||
-- Remove from grid
|
-- Remove from grid
|
||||||
local grid = Grid.GetCellByCoords(point.coords)
|
local grid = Grid.GetCellByCoords(point.coords)
|
||||||
if grid then
|
if grid then
|
||||||
grid[point.cellKey] = nil
|
grid[point.id] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
Point.All[id] = nil
|
Point.All[id] = nil
|
||||||
@@ -132,15 +126,14 @@ function Point.UpdateCoords(id, coords)
|
|||||||
if not point then return end
|
if not point then return end
|
||||||
|
|
||||||
local newGrid = Grid.GetCellByCoords(coords)
|
local newGrid = Grid.GetCellByCoords(coords)
|
||||||
if not newGrid or newGrid[point.cellKey] then return end
|
if not newGrid or newGrid[point.id] then return end
|
||||||
local oldGrid = Grid.GetCellByCoords(point.coords)
|
local oldGrid = Grid.GetCellByCoords(point.coords)
|
||||||
if oldGrid then
|
if oldGrid then
|
||||||
oldGrid[point.cellKey] = nil
|
oldGrid[point.id] = nil
|
||||||
end
|
end
|
||||||
-- Add to new grid
|
-- Add to new grid
|
||||||
point.coords = coords
|
point.coords = coords
|
||||||
point.cellKey = string.format("%d_%d", newGrid.x, newGrid.y)
|
newGrid[point.id] = point
|
||||||
newGrid[point.cellKey] = point
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user