Reference Source
private class | source

PathwaySingleton

TODO:

  • Test on server
  • Make debugging class

Static Member Summary

Static Private Members
private static

The base FPS to base calculations from.

private static

The minimum distance away from a node before this system determines it has made it to that node.

private static

The default mode this pathway system uses.

private static

The default amount of pixels per second to move the instance when using position mode.

private static

The default step pixels per second to use.

private static

The default step size for this instance to use on the path.

private static

The tile size to use if no tile size has been assigned.

private static

A static weight to be applied when a tile should be not be traveled to at all.

private static

The max amount of delta time between ticks.

private static

The maximum amount of ticks an instance can be in the same position before the pathfinder deems it "stuck".

private static

The weight that indicates that this tile is walkable.

private static

An object that stores the map tiles in normal format and in 2D format.

Constructor Summary

Private Constructor
private

Member Summary

Public Members
public

version: *

The version of the module.

Private Members
private

An array of active instances that are currently pathfinding.

private

The delta time between the current and last tick.

private

The time in ms between the current and last tick.

private

A weakmap storing the data of instances used in this pathfinder.

private

The last tracked time in the ticker.

private

The logger module this module uses to log errors / logs

private

The tile size to use for this system.

Method Summary

Public Methods
public

end(pInstance: Object)

Ends the current pathfinding for pInstance.

public

setTileSize(pTileSize: number)

Sets the tilesize of this system.

public

to(pInstance: Object, pDestination: Object, pOptions: Object)

Moves pInstance to the destination position with pOptions in mind.

Private Methods
private

getIndexOf2DArray(pArray: Array, pValue: any): Array<number>

Finds the index of a value in a 2D array.

private

getPath(pInstance: Object, pOrigin: Object, pDestination: Object)

Generates a path from the origin point to the end point with obstacles in mind.

private

Gets the position from the instance based on the pathfinding info.

private

isTileAccessible(pTile: Object, pExclusionList: Array): boolean

Checks to see if pTile is accessible for movement.

private

mapTilesToGrid(pMapName: string, pExclusionList: Array): Object | undefined

Converts map tiles to grids.

private

moveInstance(pInstance: Object, pInstanceData: Object, pInstancePosition: Object)

Moves the specified instance to the next node.

private

nodeToTile(pMapName: string, pNode: Object): Object

Converts a node to a tile.

private

tileToNode(pTile: Object}): Object

Converts a tile to a node position.

private

toTwoDimensionalArray(pArray: Array, pLengthOfSubArray: number): Array

Converts an array to an 2D array.

private

track(pInstance: Object)

Tracks this instance as active.

private

untrack(pInstance: Object)

Untracks this instance.

private

update()

Updates active instances on the pathfinder.

Static Private Members

private static DEFAULT_BASE_FPS: number source

The base FPS to base calculations from.

private static DEFAULT_MINIMUM_DISTANCE: number source

The minimum distance away from a node before this system determines it has made it to that node.

private static DEFAULT_MODE: string source

The default mode this pathway system uses.

private static DEFAULT_PIXELS_PER_SECOND: number source

The default amount of pixels per second to move the instance when using position mode.

private static DEFAULT_STEP_PIXELS_PER_SECOND: number source

The default step pixels per second to use.

private static DEFAULT_STEP_SIZE: number source

The default step size for this instance to use on the path.

private static DEFAULT_TILE_SIZE: number source

The tile size to use if no tile size has been assigned.

private static IMPASSABLE_WEIGHT: number source

A static weight to be applied when a tile should be not be traveled to at all.

private static MAX_DELTA_TIME: number source

The max amount of delta time between ticks. If this limit is passed, it will be clamped.

private static MAX_STUCK_COUNTER: number source

The maximum amount of ticks an instance can be in the same position before the pathfinder deems it "stuck". The user will be able to tweak values up to this max value.

private static PASSABLE_WEIGHT: number source

The weight that indicates that this tile is walkable. This is used as the default weight of every instance unless otherwise stated.

private static storedMapTiles: Object source

An object that stores the map tiles in normal format and in 2D format.

Private Constructors

private constructor() source

Public Members

public version: * source

The version of the module.

Private Members

private activeInstances: Array source

An array of active instances that are currently pathfinding.

private deltaTime: number source

The delta time between the current and last tick.

private elapsedMS: number source

The time in ms between the current and last tick.

private instanceWeakMap: WeakMap source

A weakmap storing the data of instances used in this pathfinder.

private lastTime: number source

The last tracked time in the ticker.

private logger: Object source

The logger module this module uses to log errors / logs

private tileSize: Object source

The tile size to use for this system.

Public Methods

public end(pInstance: Object) source

Ends the current pathfinding for pInstance.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to terminate pathfinding on.

public setTileSize(pTileSize: number) source

Sets the tilesize of this system.

Params:

NameTypeAttributeDescription
pTileSize number

The tilesize of the game.

public to(pInstance: Object, pDestination: Object, pOptions: Object) source

Moves pInstance to the destination position with pOptions in mind.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to move to the destination. The origin position will be retrived from this instance as well.

pDestination Object

The end position to travel to.

pOptions Object

An object of settings on how to move pInstance to pDestination.

Private Methods

private getIndexOf2DArray(pArray: Array, pValue: any): Array<number> source

Finds the index of a value in a 2D array.

Params:

NameTypeAttributeDescription
pArray Array

The 2D array to search in.

pValue any

The value to find in the 2D array.

Return:

Array<number>

Returns an array containing the row and column indices of the found value, or undefined if not found.

private getPath(pInstance: Object, pOrigin: Object, pDestination: Object) source

Generates a path from the origin point to the end point with obstacles in mind.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to grab data from.

pOrigin Object

An object containing the start x and y position.

pDestination Object

An object containing the end x and y position to travel to.

private getPositionFromInstance(pInstance: Object): Object source

Gets the position from the instance based on the pathfinding info. Centered position from the geometrical.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to get the position from.

Return:

Object

The position of the instance.

private isTileAccessible(pTile: Object, pExclusionList: Array): boolean source

Checks to see if pTile is accessible for movement.

Params:

NameTypeAttributeDescription
pTile Object

The tile to check the validity of.

pExclusionList Array

The list of excluded tiles/instances.

Return:

boolean

If this tile is accessible.

private mapTilesToGrid(pMapName: string, pExclusionList: Array): Object | undefined source

Converts map tiles to grids.

Params:

NameTypeAttributeDescription
pMapName string

The mapname where the tile should come from.

pExclusionList Array

The exclude list to use for this grid.

Return:

Object | undefined

An object containing the grid created, an array of tiles that are to be accepted in the pathfinding system, and the weights of each tile.

private moveInstance(pInstance: Object, pInstanceData: Object, pInstancePosition: Object) source

Moves the specified instance to the next node.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to move.

pInstanceData Object

The instance data for this instance.

pInstancePosition Object

The position of the instance.

private nodeToTile(pMapName: string, pNode: Object): Object source

Converts a node to a tile.

Params:

NameTypeAttributeDescription
pMapName string

The mapname where the tile should come from.

pNode Object

The node to convert into a tile.

Return:

Object

The tile.

private tileToNode(pTile: Object}): Object source

Converts a tile to a node position.

Params:

NameTypeAttributeDescription
pTile Object}

The tile to convert into a node position.

Return:

Object

The node.

private toTwoDimensionalArray(pArray: Array, pLengthOfSubArray: number): Array source

Converts an array to an 2D array.

Params:

NameTypeAttributeDescription
pArray Array

The array to convert to a 2D array.

pLengthOfSubArray number

The length of the subarray.

Return:

Array

The 2D array.

private track(pInstance: Object) source

Tracks this instance as active.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to track.

private untrack(pInstance: Object) source

Untracks this instance. It is no longer considered active.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to untrack.

private update() source

Updates active instances on the pathfinder.