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
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionboolean(package private) Set<Sparse2DTiledSurface_NavGraph.Tile>(package private) booleanIf true, the pathfinder will assume that the whole navgraph has been "seen", so no vertex would count as unreacahble because it is still unseen.intThe x coordinates of the this tiled-surface starts from 0 until sizeX-1intThe y coordinates of the this tiled-surface starts from 0 until sizeY-1 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a non-navigable tile (obstacle).floatThe distance between two neighboring tiles.(package private) floatdistSq(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.booleanhasbeenSeen(int x, int y)booleanCheck is the given node is marked as "has been seen".floatThe estimated distance between two arbitrary vertices.booleanThe tile is blocking (true) if it is a wall or a closed door.booleanisDoor(int x, int y)booleanisWall(int x, int y)voidMark the given node as "has been seen".voidmarkAsSeen(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.voidRemove a non-navigable tile (obstacle).voidsetBlockingState(Sparse2DTiledSurface_NavGraph.Tile tile, boolean isBlocking)Set the the state of this obstacle to blocking or unblocking.voidWhen true then the pathfinder will consider all nodes in the graph to have been seen.toString()booleanWhen true then the pathfinder will consider all nodes in the graph to have been seen.voidMark all vertices as "unseen".Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface eu.iv4xr.framework.extensions.pathfinding.CanDealWithDynamicObstacle
toggleBlockingOff, toggleBlockingOnMethods inherited from interface eu.iv4xr.framework.extensions.pathfinding.Pathfinder2
isReachableFromMethods 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:XPathfinderMark a bunch of nodes as "has been seen".- Specified by:
markAsSeenin 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:
usingPerfectMemoryPathfindingin interfaceXPathfinder<Sparse2DTiledSurface_NavGraph.Tile>
-
setPerfectMemoryPathfinding
When true then the pathfinder will consider all nodes in the graph to have been seen.- Specified by:
setPerfectMemoryPathfindingin interfaceXPathfinder<Sparse2DTiledSurface_NavGraph.Tile>
-
wipeOutMemory
public void wipeOutMemory()Mark all vertices as "unseen".- Specified by:
wipeOutMemoryin 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:
getFrontierin 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