Class Sparse2DTiledSurface_NavGraph
java.lang.Object
eu.iv4xr.framework.extensions.pathfinding.Sparse2DTiledSurface_NavGraph
- All Implemented Interfaces:
CanDealWithDynamicObstacle<Sparse2DTiledSurface_NavGraph.Tile>
,Navigatable<Sparse2DTiledSurface_NavGraph.Tile>
,Pathfinder2<Sparse2DTiledSurface_NavGraph.Tile>
,XPathfinder<Sparse2DTiledSurface_NavGraph.Tile>
public class Sparse2DTiledSurface_NavGraph
extends Object
implements Navigatable<Sparse2DTiledSurface_NavGraph.Tile>, XPathfinder<Sparse2DTiledSurface_NavGraph.Tile>, CanDealWithDynamicObstacle<Sparse2DTiledSurface_NavGraph.Tile>
Representing a navigation graph over a 2D tiled-world. The world is assumed to
be made of tiles/squares, arranged from tile (0,0) to tile (maxX-1,maxY-1) to
form a rectangle world.
The tiles are not explicitly stored. Rather, we only store non-navigable tiles. These are tiles that block movement through them. There are two types: Wall and Door. A wall is always non-navigable. A door can be made blocking/unblocking.
The class also implements XPathfinder
, so it offers methods to do
pathfinding and exploration over the world.
- Author:
- Wish
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
-
Field Summary
Modifier and TypeFieldDescriptionboolean
(package private) Set<Sparse2DTiledSurface_NavGraph.Tile>
(package private) boolean
If true, the pathfinder will assume that the whole navgraph has been "seen", so no vertex would count as unreacahble because it is still unseen.int
The x coordinates of the this tiled-surface starts from 0 until sizeX-1int
The y coordinates of the this tiled-surface starts from 0 until sizeY-1 -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a non-navigable tile (obstacle).float
The distance between two neighboring tiles.(package private) float
distSq(int x1, int y1, int x2, int y2)
explore(int x, int y, int heuristicX, int heuristicY)
explore(Sparse2DTiledSurface_NavGraph.Tile startingLocation, Sparse2DTiledSurface_NavGraph.Tile heuristicLocation)
Return a path from the start node to either a frontier-node or an unexplored node (the implementation decides this).findPath(int fromX, int fromY, int toX, int toY)
Return a path between "from", to "to".This returns the set of frontier-tiles.boolean
hasbeenSeen(int x, int y)
boolean
Check is the given node is marked as "has been seen".float
The estimated distance between two arbitrary vertices.boolean
The tile is blocking (true) if it is a wall or a closed door.boolean
isDoor(int x, int y)
boolean
isWall(int x, int y)
void
Mark the given node as "has been seen".void
markAsSeen(List<Sparse2DTiledSurface_NavGraph.Tile> newlyseen)
Mark a bunch of nodes as "has been seen".Return the neighbors of a tile.neighbours_(int x, int y)
Return the neighbors of a tile.physicalNeighbours(int x, int y)
Return the neighbors of a tile.void
Remove a non-navigable tile (obstacle).void
setBlockingState(Sparse2DTiledSurface_NavGraph.Tile tile, boolean isBlocking)
Set the the state of this obstacle to blocking or unblocking.void
When true then the pathfinder will consider all nodes in the graph to have been seen.toString()
boolean
When true then the pathfinder will consider all nodes in the graph to have been seen.void
Mark all vertices as "unseen".Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface eu.iv4xr.framework.extensions.pathfinding.CanDealWithDynamicObstacle
toggleBlockingOff, toggleBlockingOn
Methods inherited from interface eu.iv4xr.framework.extensions.pathfinding.Pathfinder2
isReachableFrom
Methods inherited from interface eu.iv4xr.framework.extensions.pathfinding.XPathfinder
explore
-
Field Details
-
sizeX
public int sizeXThe x coordinates of the this tiled-surface starts from 0 until sizeX-1 -
sizeY
public int sizeYThe y coordinates of the this tiled-surface starts from 0 until sizeY-1 -
diagonalMovementPossible
public boolean diagonalMovementPossible -
perfect_memory_pathfinding
boolean perfect_memory_pathfindingIf true, the pathfinder will assume that the whole navgraph has been "seen", so no vertex would count as unreacahble because it is still unseen. This essentially turns off memory-based path finding. The default of this flag is false. -
obstacles
-
seen
-
frontierCandidates
Set<Sparse2DTiledSurface_NavGraph.Tile> frontierCandidates -
pathfinder
-
-
Constructor Details
-
Sparse2DTiledSurface_NavGraph
public Sparse2DTiledSurface_NavGraph()
-
-
Method Details
-
markAsSeen
Description copied from interface:XPathfinder
Mark a bunch of nodes as "has been seen".- Specified by:
markAsSeen
in interfaceXPathfinder<Sparse2DTiledSurface_NavGraph.Tile>
-
hasbeenSeen
public boolean hasbeenSeen(int x, int y) -
isDoor
public boolean isDoor(int x, int y) -
isWall
public boolean isWall(int x, int y) -
usingPerfectMemoryPathfinding
public boolean usingPerfectMemoryPathfinding()When true then the pathfinder will consider all nodes in the graph to have been seen.- Specified by:
usingPerfectMemoryPathfinding
in interfaceXPathfinder<Sparse2DTiledSurface_NavGraph.Tile>
-
setPerfectMemoryPathfinding
When true then the pathfinder will consider all nodes in the graph to have been seen.- Specified by:
setPerfectMemoryPathfinding
in interfaceXPathfinder<Sparse2DTiledSurface_NavGraph.Tile>
-
wipeOutMemory
public void wipeOutMemory()Mark all vertices as "unseen".- Specified by:
wipeOutMemory
in interfaceXPathfinder<Sparse2DTiledSurface_NavGraph.Tile>
-
physicalNeighbours
Return the neighbors of a tile. A tile u is a neighbor of a tile t if u is adjacent to t. This method does not consider whether u has been seen or not, nor whether u is navigable. -
neighbours_
Return the neighbors of a tile. A tile u is a neighbor of a tile t if u is adjacent to t, and moreover u is navigable (e.g. it is not a wall or a closed door). If the flag diagonalMovementPossible is true, then tiles that are diagonally touching t are also considered neighbors.Only neighbors that have been seen before will be included.
-
findPath
-
getFrontier
This returns the set of frontier-tiles. A tile is a frontier tile if it is a seen/explored tile and it has at least one unexplored and unblocked neighbor. Note that under this definition a frontier does not have to be reachable. You can usefindPath(eu.iv4xr.framework.extensions.pathfinding.Sparse2DTiledSurface_NavGraph.Tile,eu.iv4xr.framework.extensions.pathfinding.Sparse2DTiledSurface_NavGraph.Tile)
to check which frontiers are reachable.- Specified by:
getFrontier
in interfaceXPathfinder<Sparse2DTiledSurface_NavGraph.Tile>
-
distSq
float distSq(int x1, int y1, int x2, int y2) -
explore
public List<Sparse2DTiledSurface_NavGraph.Tile> explore(int x, int y, int heuristicX, int heuristicY) -
toString