0.11.3 • Published 5 years ago

game-ds v0.11.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

A bunch of random utils for game development in js.

Classes

ArrayList

An array that auto grows, and is preallocated. It won't shrink, but will try to reuse empty elements if they have been removed.

Kind: global class

new ArrayList()

Constructor.

arrayList.count ⇒ Number

Count how many defined values are in the array.

Kind: instance property of ArrayList
Returns: Number - Array elements that aren't undefined.

arrayList.pullExists() ⇒ Mixed

Get and remove the first existing value in the array.

Kind: instance method of ArrayList
Returns: Mixed - Existing value.

arrayList.push(item)

Add an item to the array. Either lengthens array, or uses an "empty" index.

Kind: instance method of ArrayList

ParamTypeDescription
item*The item to add to the array.

arrayList.add(array)

Add an array to the array. Either lengthens array or adds elements in "empty" indices.

Kind: instance method of ArrayList

ParamTypeDescription
arrayArrayArray to add.

arrayList.remove(fn)

Removes elements from the array matching the fn (returns true).

Kind: instance method of ArrayList

ParamTypeDescription
fnfunctionMatcher to remove elements.

arrayList.clear()

Sets all current elements in array to undefined.

Kind: instance method of ArrayList

BSP

BSP

Kind: global class

new BSP(height, width)

constructor

ParamType
heightNumber
widthNumber

bsP.makeNode(x, y, w, h, l, r) ⇒ Node

Create a node to put into the BSP.

Kind: instance method of BSP

ParamTypeDescription
xNumberX position of node.
yNumberY position of node.
wNumberWidth of node.
hNumberHeight of node.
lNodeThe left child of this node.
rNodeThe right child of this node.

bsP.makeTree(node, level)

Create a tree.

Kind: instance method of BSP

ParamTypeDefaultDescription
nodeNodeThe node to generate the tree starting at.
levelNumber0The current depth of the generation.

bsP.split(node)

Split the given node into two child nodes.

Kind: instance method of BSP

ParamTypeDescription
nodeNodeThe node to split.

bsP.traverseInOrder(cb)

Traverse the tree in order.

Kind: instance method of BSP

ParamTypeDescription
cbfunctionFunction to call per node.

bsP.traversePreOrder(cb)

Traverse the tree pre order.

Kind: instance method of BSP

ParamTypeDescription
cbfunctionFunction to call per node.

bsP.traversePostOrder(cb)

Traverse the tree post order.

Kind: instance method of BSP

ParamTypeDescription
cbfunctionFunction to call per node.

Graph

A graph data structure. Undirected and using an adjacency list.

Kind: global class

new Graph()

constructor

graph.addVertex(v) ⇒ *

Add a vertex to the graph. If it already exists, it does nothing.

Kind: instance method of Graph
Returns: * - The added vertex.

ParamTypeDescription
v*The vertex to add to the graph.

graph.addEdge(src, dest)

Add an edge between src and dest.

Kind: instance method of Graph

ParamTypeDescription
src*The source node.
dest*The destination node.

graph.getNeighbors(v) ⇒ Array

Get the neighbors of the given node.

Kind: instance method of Graph
Returns: Array - The array of neighbor nodes.

ParamTypeDescription
v*The node to get neighbors for.

graph.getWeightedNeighbors(v) ⇒ Array

Get the neighbor and wieights of the given node.

Kind: instance method of Graph
Returns: Array - The array of neighbor nodes.

ParamTypeDescription
v*The node to get neighbors for.

graph.bfs(startingNode, cb)

A breath first search through the graph, starting at the given node.

Kind: instance method of Graph

ParamTypeDescription
startingNode*The node to start the search at.
cbfunctionA callback for each node in the search.

graph.dfs(startingNode, cb)

A depth first search through the graph.

Kind: instance method of Graph

ParamTypeDescription
startingNode*The node to start at.
cbfunctionA callback for each node in the search.

graph.print()

For debugging, prints adjacency list.

Kind: instance method of Graph

Heap

A heap implemenation.

Kind: global class

new Heap(compare)

constructor

ParamType
comparefunction

heap.push(n)

Push an element onto the heap.

Kind: instance method of Heap

ParamTypeDescription
n*The element to push onto the heap.

heap.pop() ⇒ *

Remove and return the ximum element in the heap.

Kind: instance method of Heap
Returns: * - The ximum element on the heap.

0.11.3

5 years ago

0.11.2

5 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago