Class: Engine
The engine that handles updating the various entity sub-systems.
Constructors
constructor
• new Engine(config?
): Engine
Create a new entity engine.
Parameters
Name | Type |
---|---|
config? |
EngineConfig |
Returns
Properties
nextId
• Private
nextId: number
systems
• Private
systems: System
<unknown
>[]
timeRemainder
• Private
timeRemainder: number
timeStep
• Private
timeStep: number
Methods
addEntity
▸ addEntity(): string
Create a new entity with an unique id.
Returns
string
addSystem
▸ addSystem<SystemT
>(system
): void
Add a new sub-system.
Type parameters
Name | Type |
---|---|
SystemT |
extends System <unknown > |
Parameters
Name | Type | Description |
---|---|---|
system |
SystemT |
The system to add |
Returns
void
destroy
▸ destroy(): void
Call destroy for all sub-systems and remove them from the engine.
Returns
void
getSystem
▸ getSystem<SystemT
>(type
): undefined
| SystemT
Get a sub-system by type.
Type parameters
Name | Type |
---|---|
SystemT |
extends System <unknown > |
Parameters
Name | Type | Description |
---|---|---|
type |
Type <SystemT > |
The type of the system |
Returns
undefined
| SystemT
getTimeRemainder
▸ getTimeRemainder(): number
Get the amount of time that has elapsed since the last time step that hasn’t yet warranted a new step update. This is always smaller than the time step.
Returns
number
getTimeStep
▸ getTimeStep(): number
Get the engine’s fixed time step.
Returns
number
removeEntity
▸ removeEntity(entity
): void
Remove an entity from the engine, ie. remove aspects bound to the entity from all systems.
Parameters
Name | Type | Description |
---|---|---|
entity |
string |
The entity to remove |
Returns
void
requireSystem
▸ requireSystem<SystemT
>(type
): SystemT
Get a sub-system by type. If the system is not found an exception is thrown.
Type parameters
Name | Type |
---|---|
SystemT |
extends System <unknown > |
Parameters
Name | Type | Description |
---|---|---|
type |
Type <SystemT > |
The type of the system |
Returns
SystemT
update
▸ update(dt
): void
Update all sub-systems. Every frame the engine calls updates in the following order for each system:
beginFrame(dt, engine, steps)
is called in the beginning of the frame withdt
being the total time elapsed since the last frame andsteps
being the total step count for the frame.step(dt, engine, step, steps)
is called n times each frame withdt
being the engine’s fixed timestep. Thestep
is the zero-based step counter for this frame andsteps
is the total number of steps for the frame. Note that the total time for the steps does not necessarily equal thedt
of a single frame as the remainder is saved over for the next frame.endFrame(dt, engine, steps)
is called in the end of the frame withdt
being the total time elapsed since the last frame andsteps
being the total step count for the frame.
Each of these updates is called for every sub-system before moving on to the next update,
for example beginFrame
is called for every sub-system before any of the step
updates
happen.
Parameters
Name | Type | Description |
---|---|---|
dt |
number |
Frame time in seconds |
Returns
void