game-ds
v0.11.3
Published
A bunch of random utils for game development in js.
Downloads
4
Readme
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
| Param | Type | Description | | --- | --- | --- | | 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
| Param | Type | Description | | --- | --- | --- | | array | Array | Array to add. |
arrayList.remove(fn)
Removes elements from the array matching the fn (returns true).
Kind: instance method of ArrayList
| Param | Type | Description | | --- | --- | --- | | fn | function | Matcher 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
| Param | Type | | --- | --- | | height | Number | | width | Number |
bsP.makeNode(x, y, w, h, l, r) ⇒ Node
Create a node to put into the BSP.
Kind: instance method of BSP
| Param | Type | Description | | --- | --- | --- | | x | Number | X position of node. | | y | Number | Y position of node. | | w | Number | Width of node. | | h | Number | Height of node. | | l | Node | The left child of this node. | | r | Node | The right child of this node. |
bsP.makeTree(node, level)
Create a tree.
Kind: instance method of BSP
| Param | Type | Default | Description | | --- | --- | --- | --- | | node | Node | | The node to generate the tree starting at. | | level | Number | 0 | The current depth of the generation. |
bsP.split(node)
Split the given node into two child nodes.
Kind: instance method of BSP
| Param | Type | Description | | --- | --- | --- | | node | Node | The node to split. |
bsP.traverseInOrder(cb)
Traverse the tree in order.
Kind: instance method of BSP
| Param | Type | Description | | --- | --- | --- | | cb | function | Function to call per node. |
bsP.traversePreOrder(cb)
Traverse the tree pre order.
Kind: instance method of BSP
| Param | Type | Description | | --- | --- | --- | | cb | function | Function to call per node. |
bsP.traversePostOrder(cb)
Traverse the tree post order.
Kind: instance method of BSP
| Param | Type | Description | | --- | --- | --- | | cb | function | Function 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.
| Param | Type | Description | | --- | --- | --- | | v | * | The vertex to add to the graph. |
graph.addEdge(src, dest)
Add an edge between src and dest.
Kind: instance method of Graph
| Param | Type | Description | | --- | --- | --- | | 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.
| Param | Type | Description | | --- | --- | --- | | 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.
| Param | Type | Description | | --- | --- | --- | | 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
| Param | Type | Description | | --- | --- | --- | | startingNode | * | The node to start the search at. | | cb | function | A callback for each node in the search. |
graph.dfs(startingNode, cb)
A depth first search through the graph.
Kind: instance method of Graph
| Param | Type | Description | | --- | --- | --- | | startingNode | * | The node to start at. | | cb | function | A 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
| Param | Type | | --- | --- | | compare | function |
heap.push(n)
Push an element onto the heap.
Kind: instance method of Heap
| Param | Type | Description | | --- | --- | --- | | 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.