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>
- .onEntityRemoved :
Signal
- .isEntityComponentDataset :
boolean
- .promiseComponent(entity, componentType) ⇒
Promise.<R>
- .addObserver(observer, [immediate]) ⇒
boolean
- .removeObserver(observer, [immediate]) ⇒
boolean
- .getEntityCount() ⇒
number
- .getComponentTypeCount() ⇒
number
- .getComponents(entity, componentClasses) ⇒
Array
- .getAllComponents(entityIndex) ⇒
Array
- .setComponentTypeMap(map)
- .areComponentTypesRegistered(types) ⇒
boolean
- .isComponentTypeRegistered(type) ⇒
boolean
- .getComponentTypeMap() ⇒
Array.<Class>
- .registerManyComponentTypes(types) ⇒
boolean
- .registerComponentType(type) ⇒
boolean
- .unregisterComponentType(type) ⇒
boolean
- .enlargeGenerationTable(min_size)
- .getEntityGeneration(entity_id) ⇒
number
- .createEntity() ⇒
number
- .createEntitySpecific(entity_id)
- .entityExists(entityIndex) ⇒
boolean
- .componentIndexExists(componentIndex) ⇒
boolean
- .removeEntity(entity_id) ⇒
boolean
- .removeEntities(entityIndices)
- .removeComponentFromEntity(entityIndex, klass)
- .removeComponentFromEntityByIndex(entityIndex, componentIndex)
- .computeComponentTypeIndex(klass) ⇒
number
- .computeComponentCount(klass) ⇒
number
- .getAnyComponent(componentType) ⇒
Object
- .addComponentToEntity(entityIndex, componentInstance)
- .addComponentToEntityByIndex(entityIndex, componentIndex, componentInstance)
- .getComponentByIndex(entityIndex, componentIndex) ⇒
C
|undefined
- .hasComponent(entityIndex, klass) ⇒
boolean
- .getComponent(entity_id, klass) ⇒
T
|undefined
- .getComponentSafe(entityIndex, klass) ⇒
C
- .getComponentAsync(entityId, componentClass, callback, [thisArg])
- .traverseEntities(classes, visitor, [thisArg])
- .traverseEntitiesExact(classes, visitor, [thisArg])
- .createEntityIterator() ⇒
Generator.<number>
- .traverseComponents(klass, visitor, [thisArg])
- .traverseComponentsByIndex(componentTypeIndex, visitor, [thisArg])
- .__traverseComponentsByIndex_via_bitset(componentTypeIndex, visitor, [thisArg])
- .__traverseComponentsByIndex_via_property(componentTypeIndex, visitor, [thisArg])
- .addEntityAnyEventListener(entity, listener, [thisArg])
- .removeAnyEventListener(entity, listener, [thisArg]) ⇒
boolean
- .addEntityEventListener(entity, eventName, listener, [thisArg])
- .removeEntityEventListener(entity, eventName, listener, [thisArg]) ⇒
boolean
- .sendEvent(entity, name, [event])
- .entityHasComponents(entityIndex) ⇒
boolean
- .clear()
- .dropData()
- .getComponentClassByName(className) ⇒
null
|function
|Class.<T>
- .maskedCopy(componentClasses, source)
- .traverseEntitiesCompactedFiltered(componentClasses, visitor)
- .isEmpty() ⇒
boolean
- .traverseEntityIndices(visitor)
- .onEntityCreated :
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
Param | Type |
---|---|
entity | int |
componentType | T |
entityComponentDataset.addObserver(observer, [immediate]) ⇒ boolean
Kind: instance method of EntityComponentDataset
Param | Type | Default | Description |
---|---|---|---|
observer | EntityObserver | ||
[immediate] | boolean | false | whenever pre-existing matches should be processed |
entityComponentDataset.removeObserver(observer, [immediate]) ⇒ boolean
Kind: instance method of EntityComponentDataset
Param | Type | Default | Description |
---|---|---|---|
observer | EntityObserver | ||
[immediate] | boolean | false | if 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
Param | Type | Description |
---|---|---|
entity | number | ID of the entity |
componentClasses | Array | Classes of components to extract |
entityComponentDataset.getAllComponents(entityIndex) ⇒ Array
Get all components associated with a given entity
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
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
Param | Type | Description |
---|---|---|
map | Array.<Class> | collection of component classes |
entityComponentDataset.areComponentTypesRegistered(types) ⇒ boolean
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
types | Array.<Class> |
entityComponentDataset.isComponentTypeRegistered(type) ⇒ boolean
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
type | Class | 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
Param | Type |
---|---|
types | Array.<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
Param | Type |
---|---|
type | Class | function |
entityComponentDataset.unregisterComponentType(type) ⇒ boolean
Attempt to remove a component class from the registry
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
type | Class |
entityComponentDataset.enlargeGenerationTable(min_size)
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
min_size | number |
entityComponentDataset.getEntityGeneration(entity_id) ⇒ number
Produces generation ID for a given entity
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entity_id | number |
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
Param | Type |
---|---|
entity_id | number |
entityComponentDataset.entityExists(entityIndex) ⇒ boolean
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
entityComponentDataset.componentIndexExists(componentIndex) ⇒ boolean
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
componentIndex | number |
entityComponentDataset.removeEntity(entity_id) ⇒ boolean
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entity_id | number |
entityComponentDataset.removeEntities(entityIndices)
Convenience method for removal of multiple entities
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndices | Array.<number> |
entityComponentDataset.removeComponentFromEntity(entityIndex, klass)
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
klass | Class |
entityComponentDataset.removeComponentFromEntityByIndex(entityIndex, componentIndex)
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
componentIndex | number |
entityComponentDataset.computeComponentTypeIndex(klass) ⇒ number
Kind: instance method of EntityComponentDataset
Param |
---|
klass |
entityComponentDataset.computeComponentCount(klass) ⇒ number
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
klass | T |
entityComponentDataset.getAnyComponent(componentType) ⇒ Object
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
componentType | Class.<T> |
entityComponentDataset.addComponentToEntity(entityIndex, componentInstance)
Associate a component with a particular entity
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
componentInstance | C |
entityComponentDataset.addComponentToEntityByIndex(entityIndex, componentIndex, componentInstance)
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
componentIndex | number |
componentInstance | C |
entityComponentDataset.getComponentByIndex(entityIndex, componentIndex) ⇒ C
| undefined
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
componentIndex | number |
entityComponentDataset.hasComponent(entityIndex, klass) ⇒ boolean
Whether or not a given entity has a component of the specified class attached
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
klass | Class.<C> |
entityComponentDataset.getComponent(entity_id, klass) ⇒ T
| undefined
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entity_id | number |
klass | Class.<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
Param | Type |
---|---|
entityIndex | number |
klass | Class.<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
Param | Type |
---|---|
entityId | Number |
componentClass | Class |
callback | function |
[thisArg] | * |
entityComponentDataset.traverseEntities(classes, visitor, [thisArg])
Performs traversal on a subset of entities which have specified components.
Kind: instance method of EntityComponentDataset
Param | Type | Description |
---|---|---|
classes | Array | |
visitor | function | Visitor can return optional "false" to terminate traversal earlier |
[thisArg] | object | specifies 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
Param | Type | Description |
---|---|---|
classes | Array.<class> | |
visitor | function | |
[thisArg] | Object | specifies 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
Param | Type |
---|---|
klass | Class.<T> |
visitor | function |
[thisArg] | * |
entityComponentDataset.traverseComponentsByIndex(componentTypeIndex, visitor, [thisArg])
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
componentTypeIndex | number |
visitor | function |
[thisArg] | * |
entityComponentDataset.__traverseComponentsByIndex_via_bitset(componentTypeIndex, visitor, [thisArg])
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
componentTypeIndex | number |
visitor | function |
[thisArg] | * |
entityComponentDataset.__traverseComponentsByIndex_via_property(componentTypeIndex, visitor, [thisArg])
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
componentTypeIndex | number |
visitor | function |
[thisArg] | * |
entityComponentDataset.addEntityAnyEventListener(entity, listener, [thisArg])
Captures all events for a given entity
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entity | number |
listener | function |
[thisArg] | * |
entityComponentDataset.removeAnyEventListener(entity, listener, [thisArg]) ⇒ boolean
Removed listener attached via #addEntityAnyEventListener
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entity | number |
listener | function |
[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
Param | Type |
---|---|
entity | number |
eventName | string |
listener | function |
[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
Param | Type |
---|---|
entity | number |
eventName | string |
listener | function |
[thisArg] | * |
entityComponentDataset.sendEvent(entity, name, [event])
Notifies every component of specified entity with given event
Kind: instance method of EntityComponentDataset
Param | Type | Description |
---|---|---|
entity | Number | |
name | String | event name |
[event] | Object |
entityComponentDataset.entityHasComponents(entityIndex) ⇒ boolean
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
entityIndex | number |
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
Param | Type |
---|---|
className | string |
entityComponentDataset.maskedCopy(componentClasses, source)
Copy entities from a supplied input dataset. Only components present in the mask are copied
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
componentClasses | Array |
source | EntityComponentDataset |
entityComponentDataset.traverseEntitiesCompactedFiltered(componentClasses, visitor)
Main utility of this method is to facilitate serialization.
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
componentClasses | Array |
visitor | function |
entityComponentDataset.isEmpty() ⇒ boolean
Tells whether or not dataset has any entities
Kind: instance method of EntityComponentDataset
entityComponentDataset.traverseEntityIndices(visitor)
Kind: instance method of EntityComponentDataset
Param | Type |
---|---|
visitor | function |
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
Param | Type |
---|---|
entityIndex | number |
validateComponentIndex(componentIndex) ⇒ boolean
Kind: global function
Param | Type |
---|---|
componentIndex | number |
validateIndexValue(index, name) ⇒ boolean
Kind: global function
Param | Type |
---|---|
index | number |
name | string |
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
Param | Type |
---|---|
componentOccupancy | BitSet |
entityIndex | number |
componentTypeCount | number |
mask | BitSet |
buildObserverCallbackArgs(entityIndex, mask, componentIndexMap, components, result)
Kind: global function
Param | Type |
---|---|
entityIndex | |
mask | BitSet |
componentIndexMap | |
components | |
result |
dispatchEntityEventListeners(evl, entity, name, event)
Kind: global function
Param | Type |
---|---|
evl | Array.<Object.<Array.<SignalHandler>>> |
entity | number |
name | string |
event | * |
dispatchEventListenersByHash(hash, entity, name, event)
Kind: global function
Param | Type |
---|---|
hash | Object.<Array.<SignalHandler>> |
entity | number |
name | string |
event | * |
dispatchAnyEventListenersByHash(listeners, entity, name, event)
Kind: global function
Param | Type |
---|---|
listeners | Array.<SignalHandler> |
entity | number |
name | string |
event | * |