Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EntityAdmin

The manager of a World. It cantains systems, entities and the components. Components can be divided into two types: one is assigned to entities to describe the entities's attributes, and the other is common singleton components, which are used to share data between different systems.

export
class

EntityAdmin

Hierarchy

  • EntityAdmin

Index

Properties

Protected comptcontain

comptcontain: Map<ComponentType, Set<Component>> = new Map()

Protected comptowners

comptowners: Map<ComponentType, Set<Entity>> = new Map()

Protected deferments

deferments: Array<object> = []

Protected empty_set

empty_set: Set<any> = new Set()

Protected entities

entities: Map<Entity, Map<ComponentType, Component>> = new Map()

Protected entity_cidmap

entity_cidmap: Map<Entity, number> = new Map()

Protected lastupdate

lastupdate: number = 0

Protected next_cid

next_cid: number = 1

Protected next_entity

next_entity: Entity = 0

Protected pubcoms

pubcoms: Map<ComponentType, Component> = new Map()

Protected running

running: boolean = false

Protected systems

systems: Array<object> = []

Protected tuple_cache

tuple_cache: Map<number, Set<Component>> = new Map()

Protected tuple_dirty

tuple_dirty: Map<ComponentType, boolean> = new Map()

Protected watch_compts

watch_compts: Map<ComponentType, Set<IFilter>> = new Map()

Protected watch_ents

watch_ents: Map<IFilter, Set<Entity>> = new Map()

Protected watch_fid

watch_fid: Map<IFilter, IFilterID> = new Map()

Protected watch_open

watch_open: boolean = false

Methods

AddSystem

  • AddSystem(system: SystemType, priority?: number): void
  • Add a System, generally be called before EntityAdmin.start().

    memberof

    EntityAdmin

    Parameters

    • system: SystemType

      A system class. This class will not be instantiated, but EntityAdmin will call the system's static method Update().

    • Default value priority: number = 0

    Returns void

AddWatchings

  • AddWatchings(...fts: [IFilter, Array]): void
  • Sometimes it may be necessary to traverse entities with some complex conditions. For example, you might want to traverse entities that have components A, B, C, but no components D, E, and have any one of G, F components. Lipstick-ecs provides the ability to traverse complex component combinations. Before this, should call the method AddWatchings() to specify the component combinations.

    memberof

    EntityAdmin

    Parameters

    • Rest ...fts: [IFilter, Array]

      List of filters.

    Returns void

AssignComponents

  • Assign component objects to an entity. If you assign the same type component object to an entity, the latter will replace the former.

    memberof

    EntityAdmin

    Parameters

    Returns void

ClearAllEntity

  • ClearAllEntity(): void

CreateEntity

  • Create an entity. And optional for assigning a list of components at the same time.

    memberof

    EntityAdmin

    Parameters

    • Rest ...args: Component[]

      Component object list.

    Returns Entity

    Entity ID. It's a number actually.

DeleteEntity

  • DeleteEntity(e: Entity): void
  • Delete an entity. And the components the entity owns will be removed at the same time.

    memberof

    EntityAdmin

    Parameters

    Returns void

GetComponentByEntity

  • GetComponentByEntity<T>(entity: Entity, cclass: CLASS<T>): T | undefined
  • Get an entity's component object.

    template

    T

    memberof

    EntityAdmin

    Type parameters

    Parameters

    Returns T | undefined

    The component instance or undefined if the entity doesn't own this type of component.

GetComponentSize

  • Returns the number of entities that have the given components. If you want to get the number of entities that match more complex combinations of components, see MatchCountByFilter().

    memberof

    EntityAdmin

    Parameters

    Returns number

GetComponents

  • GetComponents<T>(cclass: CLASS<T>): IterableIterator<T>
  • Returns the iterator of components by your specified class.

    template

    T

    memberof

    EntityAdmin

    Type parameters

    Parameters

    • cclass: CLASS<T>

      Component class.

    Returns IterableIterator<T>

    Iterator of component.

GetComponentsByTuple

  • GetComponentsByTuple<T>(...cclass: [CLASS<T>, Array]): IterableIterator<T>
  • Returns the iterator of components by the first type you give. In this case, you can use EntityAdmin.SureSibling() to get other type components. Example:

    for (const a of admin.GetComponentsByTuple(ComponentA, ComponentB, ComponentC)) {
        // In this case, ComponentB and ComponentC must exist in a's owner entity. The a,b,c have the same owner entity.
        const b: ComponentB = a.SureSibling(admin, ComponentB);
        const c: ComponentC = a.SureSibling(admin, ComponentC);
        // Can't confirm whether ComponentD exists.
        const d: ComponentD | undefined = a.GetSibling(ComponentD);
    }
    template

    T

    memberof

    EntityAdmin

    Type parameters

    Parameters

    • Rest ...cclass: [CLASS<T>, Array]

      A list of component class.

    Returns IterableIterator<T>

    The iterator of T component instances.

GetEnttsByFilter

  • Returns the iterator of entities by your given IFilter.

    Attention: The filter you given should be specified by EntityAdmin.AddWatchings() before.

    memberof

    EntityAdmin

    Parameters

    • f: IFilter

      Component combinations.

    Returns IterableIterator<Entity>

    Iterator of entities.

GetPubComponent

  • GetPubComponent<T>(cclass: CLASS<T>): undefined | T
  • Get a public component. See EntityAdmin.SetPubComponent().

    template

    T

    memberof

    EntityAdmin

    Type parameters

    Parameters

    • cclass: CLASS<T>

      A Component class

    Returns undefined | T

HasComponent

  • Determine whether the entity owns the specified type component or not.

    memberof

    EntityAdmin

    Parameters

    Returns boolean

    True means the type of component exist.

MatchCountByFilter

  • MatchCountByFilter(f: IFilter): number
  • Returns the number of entities the filter matched.

    Attention: The filter you given should be specified by EntityAdmin.AddWatchings() before.

    memberof

    EntityAdmin

    Parameters

    • f: IFilter

      Component combinations.

    Returns number

PushDeferment

  • PushDeferment(func: Function, ...args: any): void
  • Push a deferment item. The deferment items will be processed in queue order at the end of each frame and then be cleared out. One EntityAdmin.UpdateSystems() call is one frame.

    memberof

    EntityAdmin

    Parameters

    • func: Function

      your function to deal delayed things

    • Rest ...args: any

      parameter list for your function

    Returns void

RemoveComponents

  • Remove component objects from an entity. If the entity or components do not exist, this method just do nothing, won't throw error.

    memberof

    EntityAdmin

    Parameters

    Returns void

SetPubComponent

  • Set a public component. Public component is Singleton pattern. It used for sharing data between Systems, but not for assigning to entity.

    Parameters

    Returns void

SureComponentByEntity

  • SureComponentByEntity<T>(entity: Entity, cclass: CLASS<T>): T
  • Actually the same as EntityAdmin.GetComponentByEntity(), but returns by a type assertion(not union undefined). It is used when you are sure the entity has the component.

    template

    T

    memberof

    EntityAdmin

    Type parameters

    Parameters

    • entity: Entity

      Entity ID.

    • cclass: CLASS<T>

      Component class.

    Returns T

SurePubComponent

  • SurePubComponent<T>(cclass: CLASS<T>): T
  • Actually the same as EntityAdmin.GetPubComponent(), but returns by a type assertion(not union undefined). If you are sure this type of component exist, call this method maybe better than EntityAdmin.GetPubComponent().

    template

    T

    memberof

    EntityAdmin

    Type parameters

    Parameters

    • cclass: CLASS<T>

      A Component class

    Returns T

UpdateSystems

  • UpdateSystems(curtime?: number): void
  • Call all systems Update() method in order of their priority, and then deal deferment items you pushed before, at last clear deferment buffer. If the running state is false, it will do nothing.

    memberof

    EntityAdmin

    Parameters

    • Default value curtime: number = present()

    Returns void

ValidEntity

  • ValidEntity(e: Entity): boolean
  • Identify an entity exist or not.

    memberof

    EntityAdmin

    Parameters

    Returns boolean

    Return true means the entity exist.

Protected afterMultiComptChange

  • afterMultiComptChange(e: Entity): void

Protected afterSingleComptChange

Protected matchFilter

start

  • start(curtime?: number): void
  • The default running state is false. This method set it true. EntityAdmin.UpdateSystems() can work only in running===true state.

    memberof

    EntityAdmin

    Parameters

    • Default value curtime: number = present()

    Returns void

stop

  • stop(): void
  • Set running state false. In this state, EntityAdmin.UpdateSystems() do nothing.

    memberof

    EntityAdmin

    Returns void

Protected tryGetTupleCache

Protected updateTupleCache