Class NodeList<TNode>

A collection of nodes.

Systems within the engine access the components of entities via NodeLists. A NodeList contains a node for each Entity in the engine that has all the components required by the node. To iterate over a NodeList, start from the head and step to the next on each loop, until the returned value is null.

for (let node:Node = nodeList.head; node; node = node.next) {
// do stuff
}

It is safe to remove items from a nodelist during the loop. When a Node is removed form the NodeList it's previous and next properties still point to the nodes that were before and after it in the NodeList just before it was removed.

Type Parameters

Hierarchy

  • NodeList

Constructors

Properties

head: null | TNode = null

The first item in the node list, or null if the list contains no nodes.

nodeAdded: Signal<[TNode]>

A signal that is dispatched whenever a node is added to the node list.

The signal will pass a single parameter to the listeners - the node that was added.

nodeRemoved: Signal<[TNode]>

A signal that is dispatched whenever a node is removed from the node list.

The signal will pass a single parameter to the listeners - the node that was removed.

tail: null | TNode = null

The last item in the node list, or null if the list contains no nodes.

Accessors

Methods

  • Performs an insertion sort on the node list. In general, insertion sort is very efficient with short lists and with lists that are mostly sorted, but is inefficient with large lists that are randomly ordered.

    The sort function takes two nodes and returns a Number.

    function sortFunction(node1:MockNode, node2:MockNode):number
    

    If the returned number is less than zero, the first node should be before the second. If it is greater than zero the second node should be before the first. If it is zero the order of the nodes doesn't matter and the original order will be retained.

    This insertion sort implementation runs in place so no objects are created during the sort.

    Parameters

    • sortFunction: ((a, b) => number)
        • (a, b): number
        • Parameters

          • a: TNode
          • b: TNode

          Returns number

    Returns void

  • Performs a merge sort on the node list. In general, merge sort is more efficient than insertion sort with long lists that are very unsorted.

    The sort function takes two nodes and returns a Number.

    function sortFunction(node1:MockNode, node2:MockNode):number
    

    If the returned number is less than zero, the first node should be before the second. If it is greater than zero the second node should be before the first. If it is zero the order of the nodes doesn't matter.

    This merge sort implementation creates and uses a single array during the sort operation.

    Parameters

    • sortFunction: ((a, b) => number)
        • (a, b): number
        • Parameters

          • a: TNode
          • b: TNode

          Returns number

    Returns void

  • Swaps the positions of two nodes in the list. Useful when sorting a list.

    Parameters

    • node1: TNode
    • node2: TNode

    Returns void

Generated using TypeDoc