Entities · class
EntityAllocator
Slots, their generations, and a queue of the ones that are free.
Explained in Entities.
class EntityAllocatorimport { EntityAllocator } from '@driftengine/entities';In depth
The free list is first-in-first-out, and that is what makes the generation ceiling a number about the pool rather than about one slot. A stack hands the same slot straight back, so one spawn-and-destroy pair in a loop burns that slot's whole range while every other slot sits unused. A queue spreads the wear.
The cost is that a freed slot is not reused until every other freed slot has been, so a workload that churns a handful of entities touches more of the arrays than a stack would. That is a cache argument against a correctness one, and correctness wins.
Constructor
new
constructor(options?: EntityAllocatorOptions)| Parameter | Type | Description |
|---|---|---|
options? | EntityAllocatorOptions |
Accessors
| Name | Type | Description |
|---|---|---|
liveCountget | number |
Methods
create
create(): Entitydestroy
destroy(entity: Entity): booleanFree an entity's slot. false when the handle was already stale, which is not an error.
| Parameter | Type | Description |
|---|---|---|
entity | Entity |
More
A caller destroying something twice is a caller that lost track, and the honest answer is that
there was nothing to destroy — the same shape patchModule and Scope.leave use.
alive
alive(entity: Entity): boolean| Parameter | Type | Description |
|---|---|---|
entity | Entity |
saveInto
saveInto(slot: AllocatorSnapshot): voidCopy this allocator's position into a slot, growing the slot's arrays if it has not held one this large before.
| Parameter | Type | Description |
|---|---|---|
slot | AllocatorSnapshot |
More
highWater bounds every copy, because slots beyond it have never been handed out and their
generations are zero on both sides. That is what keeps the cost proportional to the world rather
than to the arrays' capacity.
loadFrom
loadFrom(slot: AllocatorSnapshot): voidPut this allocator back to a saved position.
| Parameter | Type | Description |
|---|---|---|
slot | AllocatorSnapshot |
More
Slots between the saved highWater and the current one are cleared rather than left, and
that is the whole difference between a restore and a partial one. An entity created after the
save has a live slot the save knows nothing about; leaving it live would leave an entity in the
world that the snapshot says does not exist, and its handle would keep answering alive.