I've been actively working on this project the past hours, and i came up with a new iteration of Jumper.
Here's the
1.8.0 release. The detailed changelog can be found
here.
Some little changes were brought to the interface. Mostly because I wasn't satisfied with the relationship that was existing between the Grid class and the Pathfinder class, that is, encapsulating the grid object within the pathfinder. That was a bad design choice, just because it was preventing a user from handling efficiently map with multiple terrain types.
So, as of this new release, Jumper offers now to its users two main modules, at the top level : a
Grid class, and a
Pathfinder class.
Code: Select all
local Grid = require('jumper.grid')
local Pathfinder = require('jumper.pathfinder')
To create a Grid, it is still fairly simple, just pass a collision map to the
Grid class. Then, pass the Grid object to the
Pathfinder.
The
Pathfinder class takes three args upon instantiation: the finder name, referring to the search algorithm to be used, the grid and the value/function for walkable tiles.
Code: Select all
local map = {
{1,1,1,1,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,1,1,1,1},
}
local grid = Grid(map)
local myFinder = Pathfinder('JPS', grid, 0)
What makes that layout very interesting is that you can stick to a unique grid object, and then easily simulate multiple terrain types. In the example above, let's consider '1' represents a specific terrain type, like 'land', and 0 stands for 'water'. That way, one can design a finder that will look for path on 'lands', and another that will search for paths on 'water'. We can even have a pathfinder for both (land and water, as walkable can also be a function).
Code: Select all
local finderLand = Pathfinder('ASTAR', grid, 1)
local finderWater = Pathfinder('ASTAR', grid, 0)
local finderAmphibia = Pathfinder('ASTAR', grid, function(v) return v == 0 or v==1 end)
Added to that, I have included some new search algorithms. Well, they may all not be fast, by essence, but the duty of a library is to offer choices, not to limit. So far, Jumper implements five well-know search algorithms:
A-star, Dijkstra, Breadth first Search, Depth first search and Jump Point Search (the fastest one actually).
The
Pathfinder class and the
Grid class have also been extended with some new methods, mostly for their convenient use. You can check out the online documentation for more details.
Last point, some methods such as
Pathfinder:filter() and
Pathfinder:fill() were removed from the Pathfinder class. For now on, using
Pathfinder:getPath returns a
path, which would be an instance or an internal class named Path. To alter the returned path (interpolate, or compress it), you will just have to call these methods from the returned object:
Code: Select all
local path = myFinder:getPath(startX, startY, endX, endY)
if path then
path:fill() -- or path:filter()
-- iterating along the path
for node, count in path:iter() do
-- etc
end
end
Documentation is available online, and source. Check out the
Readme, as it provides all informations you need to easily get started.
Source:
Github
Documentation:
Jumper
Thanks reading.