Name: Pathfinding
Summary: API and algorithms to find paths between two blocks.
Scope: Engine
Current Goal: Implement a proof of concept and develop a nice API for it.
Phase: Implementation
Curator: synopia
Related: wiki
Repository: https://github.com/synopia/Terasology/tree/pathfinder2
Try it
Check out sources, build, run, start a new world with pathfinding mod enabled. Ingame, use F5 to get a "StartBlock" and a "TargetBlock".
Now the pathfinder will find the shortest path between the start block and any target block.
Algorithm concept
What it actually does:
1. Each chunk is preprocessed to extract path relevant blocks and connections between them.
2. Multiple path relevant blocks (adjacent) are combined into regions.
3. Multiple regions are combined into non-overlapping floors.
4. Contour for each floor is constructed (all blocks, that are neighbors of a block of an other floor).
Now we have for each chunk a small number of floors. Floors and path relevant blocks form a graph, with connections between those elements.
The pathfinding itself uses a hierarchical A* algorithm, to find the path in the constructed graph. Hierarchical means, there are (actual) two levels:
a) Find a (local) path in one floor from block B1 to block B2.
b) Find a (global) path from floor F1 to F2.
Done
Summary: API and algorithms to find paths between two blocks.
Scope: Engine
Current Goal: Implement a proof of concept and develop a nice API for it.
Phase: Implementation
Curator: synopia
Related: wiki
Repository: https://github.com/synopia/Terasology/tree/pathfinder2
Try it
Check out sources, build, run, start a new world with pathfinding mod enabled. Ingame, use F5 to get a "StartBlock" and a "TargetBlock".
Now the pathfinder will find the shortest path between the start block and any target block.
Algorithm concept
What it actually does:
1. Each chunk is preprocessed to extract path relevant blocks and connections between them.
2. Multiple path relevant blocks (adjacent) are combined into regions.
3. Multiple regions are combined into non-overlapping floors.
4. Contour for each floor is constructed (all blocks, that are neighbors of a block of an other floor).
Now we have for each chunk a small number of floors. Floors and path relevant blocks form a graph, with connections between those elements.
The pathfinding itself uses a hierarchical A* algorithm, to find the path in the constructed graph. Hierarchical means, there are (actual) two levels:
a) Find a (local) path in one floor from block B1 to block B2.
b) Find a (global) path from floor F1 to F2.
Done
- Preprocessing chunks and graph construction
- Find walkable blocks (solid blocks with at least 2 air blocks above)
- Find regions (small rectangular 2D areas (looking top-down), non overlapping)
- Find floors (multiple non overlapping regions, that form a flat, walkable area; connected to neighbor floors)
- Find contour (blocks at the edges of an floor; each of those blocks is connected to each other block of the contour and its path is cached)
- Pathfinding
- Basic hierarchical A*
- Currently only operational on two levels (floors and blocks)
- Contour optimization
- Path cache
- Write more automated tests!
- Fix more, upcoming bugs
- Move code from mod to core (maybe only the API should move to core and implementation stays as a mod?)
- Develop a cool API for pathfinding (use callbacks to enable threaded pathfinding behind the API)
- Optimize, optimize, optimize ...