Skip to main content

EntityComponentDataset

Classes

EntityComponentDataset

Represents a storage for entities and their associated components Entities are just integer IDs and components are stored in a virtual table, where each component type has a separate column and each entity is a row in that table It is valid for entities to have no components or to have every possible component Generally the entity IDs are compacted, meaning that when an entity is removed - it's ID will be later reused

Members

entityListenersProxyPointer : number

Keep track of the stack pointer to allow recursive dispatching

Constants

entityListenersProxy : Array.<SignalHandler>

Functions

validateEntityIndex(entityIndex)boolean
validateComponentIndex(componentIndex)boolean
validateIndexValue(index, name)boolean
matchComponentMask(componentOccupancy, entityIndex, componentTypeCount, mask)boolean

Matches a supplies component mask against a larger set

buildObserverCallbackArgs(entityIndex, mask, componentIndexMap, components, result)
dispatchEntityEventListeners(evl, entity, name, event)
dispatchEventListenersByHash(hash, entity, name, event)
dispatchAnyEventListenersByHash(listeners, entity, name, event)

EntityComponentDataset

Represents a storage for entities and their associated components Entities are just integer IDs and components are stored in a virtual table, where each component type has a separate column and each entity is a row in that table It is valid for entities to have no components or to have every possible component Generally the entity IDs are compacted, meaning that when an entity is removed - it's ID will be later reused

Kind: global class

entityComponentDataset.onEntityCreated : Signal.<number>

Kind: instance property of EntityComponentDataset
Read only: true

entityComponentDataset.onEntityRemoved : Signal

Kind: instance property of EntityComponentDataset
Read only: true

entityComponentDataset.isEntityComponentDataset : boolean

Kind: instance property of EntityComponentDataset
Read only: true

entityComponentDataset.promiseComponent(entity, componentType) ⇒ Promise.<R>

returns a promise of a component instance based on a given type

Kind: instance method of EntityComponentDataset

ParamType
entityint
componentTypeT

entityComponentDataset.addObserver(observer, [immediate]) ⇒ boolean

Kind: instance method of EntityComponentDataset

ParamTypeDefaultDescription
observerEntityObserver
[immediate]booleanfalsewhenever pre-existing matches should be processed

entityComponentDataset.removeObserver(observer, [immediate]) ⇒ boolean

Kind: instance method of EntityComponentDataset

ParamTypeDefaultDescription
observerEntityObserver
[immediate]booleanfalseif flag set, matches will be broken after observer is removed

entityComponentDataset.getEntityCount() ⇒ number

Kind: instance method of EntityComponentDataset

entityComponentDataset.getComponentTypeCount() ⇒ number

Kind: instance method of EntityComponentDataset

entityComponentDataset.getComponents(entity, componentClasses) ⇒ Array

Convenience method for retrieving a collection of components for a given entity

Kind: instance method of EntityComponentDataset

ParamTypeDescription
entitynumberID of the entity
componentClassesArrayClasses of components to extract

entityComponentDataset.getAllComponents(entityIndex) ⇒ Array

Get all components associated with a given entity

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber

entityComponentDataset.setComponentTypeMap(map)

Modify dataset component mapping. Algorithm will attempt to mutate dataset even if entities exist, however, it will not remove component classes for which instances exist in the dataset.

Kind: instance method of EntityComponentDataset
Throws:

  • Error when attempting to remove component classes with live instances
ParamTypeDescription
mapArray.<Class>collection of component classes

entityComponentDataset.areComponentTypesRegistered(types) ⇒ boolean

Kind: instance method of EntityComponentDataset

ParamType
typesArray.<Class>

entityComponentDataset.isComponentTypeRegistered(type) ⇒ boolean

Kind: instance method of EntityComponentDataset

ParamType
typeClass | function

entityComponentDataset.getComponentTypeMap() ⇒ Array.<Class>

Kind: instance method of EntityComponentDataset

entityComponentDataset.registerManyComponentTypes(types) ⇒ boolean

Kind: instance method of EntityComponentDataset
Returns: boolean - false if no new classes were added, true if at least one new class was added

ParamType
typesArray.<Class>

entityComponentDataset.registerComponentType(type) ⇒ boolean

Attempt to add a component class to dataset registry

Kind: instance method of EntityComponentDataset
Returns: boolean - true if component successfully added, false otherwise

ParamType
typeClass | function

entityComponentDataset.unregisterComponentType(type) ⇒ boolean

Attempt to remove a component class from the registry

Kind: instance method of EntityComponentDataset

ParamType
typeClass

entityComponentDataset.enlargeGenerationTable(min_size)

Kind: instance method of EntityComponentDataset

ParamType
min_sizenumber

entityComponentDataset.getEntityGeneration(entity_id) ⇒ number

Produces generation ID for a given entity

Kind: instance method of EntityComponentDataset

ParamType
entity_idnumber

entityComponentDataset.createEntity() ⇒ number

Kind: instance method of EntityComponentDataset
Returns: number - entityIndex

entityComponentDataset.createEntitySpecific(entity_id)

Kind: instance method of EntityComponentDataset
Throws:

  • Error if entity index is already in use
ParamType
entity_idnumber

entityComponentDataset.entityExists(entityIndex) ⇒ boolean

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber

entityComponentDataset.componentIndexExists(componentIndex) ⇒ boolean

Kind: instance method of EntityComponentDataset

ParamType
componentIndexnumber

entityComponentDataset.removeEntity(entity_id) ⇒ boolean

Kind: instance method of EntityComponentDataset

ParamType
entity_idnumber

entityComponentDataset.removeEntities(entityIndices)

Convenience method for removal of multiple entities

Kind: instance method of EntityComponentDataset

ParamType
entityIndicesArray.<number>

entityComponentDataset.removeComponentFromEntity(entityIndex, klass)

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber
klassClass

entityComponentDataset.removeComponentFromEntityByIndex(entityIndex, componentIndex)

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber
componentIndexnumber

entityComponentDataset.computeComponentTypeIndex(klass) ⇒ number

Kind: instance method of EntityComponentDataset

Param
klass

entityComponentDataset.computeComponentCount(klass) ⇒ number

Kind: instance method of EntityComponentDataset

ParamType
klassT

entityComponentDataset.getAnyComponent(componentType) ⇒ Object

Kind: instance method of EntityComponentDataset

ParamType
componentTypeClass.<T>

entityComponentDataset.addComponentToEntity(entityIndex, componentInstance)

Associate a component with a particular entity

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber
componentInstanceC

entityComponentDataset.addComponentToEntityByIndex(entityIndex, componentIndex, componentInstance)

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber
componentIndexnumber
componentInstanceC

entityComponentDataset.getComponentByIndex(entityIndex, componentIndex) ⇒ C | undefined

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber
componentIndexnumber

entityComponentDataset.hasComponent(entityIndex, klass) ⇒ boolean

Whether or not a given entity has a component of the specified class attached

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber
klassClass.<C>

entityComponentDataset.getComponent(entity_id, klass) ⇒ T | undefined

Kind: instance method of EntityComponentDataset

ParamType
entity_idnumber
klassClass.<T>

entityComponentDataset.getComponentSafe(entityIndex, klass) ⇒ C

Always returns non-null value, if the component is not found - an error is thrown instead

Kind: instance method of EntityComponentDataset
Throws:

  • Error when component not found
ParamType
entityIndexnumber
klassClass.<C>

entityComponentDataset.getComponentAsync(entityId, componentClass, callback, [thisArg])

same as getComponent when component exists, if component is not associated with the entity, callback will be invoked once when it is added.

Kind: instance method of EntityComponentDataset

ParamType
entityIdNumber
componentClassClass
callbackfunction
[thisArg]*

entityComponentDataset.traverseEntities(classes, visitor, [thisArg])

Performs traversal on a subset of entities which have specified components.

Kind: instance method of EntityComponentDataset

ParamTypeDescription
classesArray
visitorfunctionVisitor can return optional "false" to terminate traversal earlier
[thisArg]objectspecifies context object on which callbacks are to be called, optional

Example

traverseEntities([Transform,Renderable,Tag],function(transform, renderable, tag, entity){ ... }, this);

entityComponentDataset.traverseEntitiesExact(classes, visitor, [thisArg])

Performs traversal on a subset of entities which have only the specified components and no others

Kind: instance method of EntityComponentDataset

ParamTypeDescription
classesArray.<class>
visitorfunction
[thisArg]Objectspecifies context object on which callbacks are to be called, optional

Example

traverseEntitiesExact([Transform,Renderable,Tag],function(transform, renderable, tag, entity){ ... }, this);

entityComponentDataset.createEntityIterator() ⇒ Generator.<number>

Kind: instance method of EntityComponentDataset

entityComponentDataset.traverseComponents(klass, visitor, [thisArg])

Kind: instance method of EntityComponentDataset

ParamType
klassClass.<T>
visitorfunction
[thisArg]*

entityComponentDataset.traverseComponentsByIndex(componentTypeIndex, visitor, [thisArg])

Kind: instance method of EntityComponentDataset

ParamType
componentTypeIndexnumber
visitorfunction
[thisArg]*

entityComponentDataset.__traverseComponentsByIndex_via_bitset(componentTypeIndex, visitor, [thisArg])

Kind: instance method of EntityComponentDataset

ParamType
componentTypeIndexnumber
visitorfunction
[thisArg]*

entityComponentDataset.__traverseComponentsByIndex_via_property(componentTypeIndex, visitor, [thisArg])

Kind: instance method of EntityComponentDataset

ParamType
componentTypeIndexnumber
visitorfunction
[thisArg]*

entityComponentDataset.addEntityAnyEventListener(entity, listener, [thisArg])

Captures all events for a given entity

Kind: instance method of EntityComponentDataset

ParamType
entitynumber
listenerfunction
[thisArg]*

entityComponentDataset.removeAnyEventListener(entity, listener, [thisArg]) ⇒ boolean

Removed listener attached via #addEntityAnyEventListener

Kind: instance method of EntityComponentDataset

ParamType
entitynumber
listenerfunction
[thisArg]*

entityComponentDataset.addEntityEventListener(entity, eventName, listener, [thisArg])

Registers an event listener to a specific entity and event type, specified by eventName string.

Kind: instance method of EntityComponentDataset

ParamType
entitynumber
eventNamestring
listenerfunction
[thisArg]*

entityComponentDataset.removeEntityEventListener(entity, eventName, listener, [thisArg]) ⇒ boolean

Remove existing event listener associated with a specific entity. Does nothing if listener isn't registered.

Kind: instance method of EntityComponentDataset

ParamType
entitynumber
eventNamestring
listenerfunction
[thisArg]*

entityComponentDataset.sendEvent(entity, name, [event])

Notifies every component of specified entity with given event

Kind: instance method of EntityComponentDataset

ParamTypeDescription
entityNumber
nameStringevent name
[event]Object

entityComponentDataset.entityHasComponents(entityIndex) ⇒ boolean

Kind: instance method of EntityComponentDataset

ParamType
entityIndexnumber

entityComponentDataset.clear()

Remove all entities, triggers all relevant removal events for each entity/component

Kind: instance method of EntityComponentDataset

entityComponentDataset.dropData()

Drops all data, bypassing standard workflow, no events are dispatched. Data is simply ejected. This method is very efficient but is intended to be used only when associated data is no needed as it may produce unintended consequences if the data is re-used

Kind: instance method of EntityComponentDataset

entityComponentDataset.getComponentClassByName(className) ⇒ null | function | Class.<T>

Kind: instance method of EntityComponentDataset

ParamType
classNamestring

entityComponentDataset.maskedCopy(componentClasses, source)

Copy entities from a supplied input dataset. Only components present in the mask are copied

Kind: instance method of EntityComponentDataset

ParamType
componentClassesArray
sourceEntityComponentDataset

entityComponentDataset.traverseEntitiesCompactedFiltered(componentClasses, visitor)

Main utility of this method is to facilitate serialization.

Kind: instance method of EntityComponentDataset

ParamType
componentClassesArray
visitorfunction

entityComponentDataset.isEmpty() ⇒ boolean

Tells whether or not dataset has any entities

Kind: instance method of EntityComponentDataset

entityComponentDataset.traverseEntityIndices(visitor)

Kind: instance method of EntityComponentDataset

ParamType
visitorfunction

entityListenersProxyPointer : number

Keep track of the stack pointer to allow recursive dispatching

Kind: global variable

entityListenersProxy : Array.<SignalHandler>

Kind: global constant

validateEntityIndex(entityIndex) ⇒ boolean

Kind: global function

ParamType
entityIndexnumber

validateComponentIndex(componentIndex) ⇒ boolean

Kind: global function

ParamType
componentIndexnumber

validateIndexValue(index, name) ⇒ boolean

Kind: global function

ParamType
indexnumber
namestring

matchComponentMask(componentOccupancy, entityIndex, componentTypeCount, mask) ⇒ boolean

Matches a supplies component mask against a larger set

Kind: global function
Returns: boolean - true if mask matches completely, false otherwise

ParamType
componentOccupancyBitSet
entityIndexnumber
componentTypeCountnumber
maskBitSet

buildObserverCallbackArgs(entityIndex, mask, componentIndexMap, components, result)

Kind: global function

ParamType
entityIndex
maskBitSet
componentIndexMap
components
result

dispatchEntityEventListeners(evl, entity, name, event)

Kind: global function

ParamType
evlArray.<Object.<Array.<SignalHandler>>>
entitynumber
namestring
event*

dispatchEventListenersByHash(hash, entity, name, event)

Kind: global function

ParamType
hashObject.<Array.<SignalHandler>>
entitynumber
namestring
event*

dispatchAnyEventListenersByHash(listeners, entity, name, event)

Kind: global function

ParamType
listenersArray.<SignalHandler>
entitynumber
namestring
event*