I'm trying to optimise the pathfinding code because it is to slow now.
Jumper needs only to search inside a x1,y1,x2,y2 rect.
My first though was this.
Code: Select all
-- some variables
-- targetX
-- targetY
-- currentX
-- currentY
-- mapWidth = 4000
-- mapHeight = 768
-- this is for example the 'window/rect' where to do the pathfinding search
local x1 = 75
local y1 = 400
local x2 = 590
local y2 = 720
local w = x2 - x1
local h = y2 - y1
---
map = {}
for y = y1, y2 do
map[y] = {}
for x = x1, x2 do
if collision(x, y) then
map[y][x] = 1
else
map[y][x] = 0
end
end
end
local grid = Grid(map, true)
local myFinder = Pathfinder(grid, "JPS", 0)
myFinder:setHeuristic("MANHATTAN")
local path = myFinder:getPath(currentX, currentY, targetX, targetY)
Code: Select all
jumper/grid.lua:78: Bad argument #1. Not a valid map
stack traceback:
[C]: in function 'assert'
lib/jumper/grid.lua:78: in function 'Grid'
But how to fix this problem ?
Thanks !