Class: EcsWorld
Defined in: ecs/ecs-world.ts:47
Represents an object that can be updated over time.
Implements
Constructors
Constructor
new EcsWorld():
EcsWorld
Defined in: ecs/ecs-world.ts:64
Returns
EcsWorld
Properties
onEntityRemoved
readonlyonEntityRemoved:ParameterizedForgeEvent<number>
Defined in: ecs/ecs-world.ts:48
Accessors
defaultSystemGroup
Get Signature
get defaultSystemGroup():
EcsSystemGroup
Defined in: ecs/ecs-world.ts:82
The system group systems are registered into when addSystem is called
without a group option. Order your own groups relative to it (via
addSystemGroup's before/after) to run consistently before or after
every system a caller registers without specifying a group.
Returns
Methods
addComponent()
addComponent<
T>(entity,componentKey,componentData):T
Defined in: ecs/ecs-world.ts:234
Type Parameters
T
T
Parameters
entity
number
componentKey
ComponentKey<T>
componentData
T
Returns
T
addSystem()
addSystem<
T>(system,options?):void
Defined in: ecs/ecs-world.ts:122
Registers a system, optionally ordering it relative to other systems in its group.
Type Parameters
T
T extends readonly unknown[]
Parameters
system
EcsSystem<T>
The system to register.
options?
AddSystemOptions = {}
Which group to register the system in, and before/
after systems (within that same group) to order it against.
Returns
void
addSystemGroup()
addSystemGroup(
group,options?):void
Defined in: ecs/ecs-world.ts:98
Registers a system group, ordering it relative to other groups.
Parameters
group
The group to register.
options?
before/after groups to order this group against.
Every referenced group must already be registered.
Returns
void
addTag()
addTag(
entity,tagKey):void
Defined in: ecs/ecs-world.ts:245
Parameters
entity
number
tagKey
Returns
void
createEntity()
createEntity():
number
Defined in: ecs/ecs-world.ts:221
Returns
number
getComponent()
getComponent<
T>(entity,componentKey):T|null
Defined in: ecs/ecs-world.ts:250
Type Parameters
T
T
Parameters
entity
number
componentKey
ComponentKey<T>
Returns
T | null
getComponentAccessor()
getComponentAccessor<
T>(componentKey): (entity) =>T|null
Defined in: ecs/ecs-world.ts:277
Returns a fast accessor for a single component type, resolving its
underlying storage once instead of on every call - useful when a
system needs to look up the same optional component (one not every
entity has, so it can't just be added to query's required keys) for
many entities in a tight loop. getComponent re-resolves componentKey
to its storage on every single call; this instead does that resolution
once and returns a function that goes straight to the resolved storage.
Type Parameters
T
T
Parameters
componentKey
ComponentKey<T>
The component's key.
Returns
A function mapping an entity to its component for
componentKey, or null if that entity doesn't have one. Reflects
components added to componentKey after this call, as long as at
least one entity in the world already had componentKey at the time
this was called - so call it fresh (e.g. once per system update) rather
than caching it across ticks of a world that might not have used
componentKey yet on the first call.
(entity) => T | null
getComponentRequired()
getComponentRequired<
T>(entity,componentKey):T
Defined in: ecs/ecs-world.ts:300
Reads a component the caller expects to already exist, throwing instead
of returning null if it doesn't - for the common case of re-reading a
component this same call site just attached, where a null would mean a
broken invariant rather than a legitimate "doesn't have it" case.
Type Parameters
T
T
Parameters
entity
number
The entity to read the component from.
componentKey
ComponentKey<T>
The component's key.
Returns
T
The component.
Throws
An error if entity doesn't have a component for componentKey.
query()
query<
T>(componentKeys,tags?):QueryResult<T>
Defined in: ecs/ecs-world.ts:183
Type Parameters
T
T extends readonly unknown[]
Parameters
componentKeys
readonly ComponentKey<unknown>[]
tags?
readonly TagKey[] = []
Returns
QueryResult<T>
removeComponent()
removeComponent<
T>(entity,componentKey):void
Defined in: ecs/ecs-world.ts:315
Type Parameters
T
T
Parameters
entity
number
componentKey
ComponentKey<T>
Returns
void
removeEntity()
removeEntity(
entity):void
Defined in: ecs/ecs-world.ts:225
Parameters
entity
number
Returns
void
removeSystem()
removeSystem<
T>(system):void
Defined in: ecs/ecs-world.ts:163
Type Parameters
T
T extends readonly unknown[]
Parameters
system
EcsSystem<T>
Returns
void
stop()
stop():
void
Defined in: ecs/ecs-world.ts:86
Returns
void
Implementation of
update()
update():
void
Defined in: ecs/ecs-world.ts:176
Updates the object with the given time.
Returns
void