@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
78 lines • 2.59 kB
TypeScript
/**
* Bidirectional map between local entity IDs and stable, peer-shared network IDs.
*
* The same entity is represented by different local IDs on different peers (each
* peer's `EntityComponentDataset` assigns IDs independently). The network ID is
* the peer-shared identifier for "this object" in serialized form.
*
* Network IDs are recyclable: when a slot is freed, its `generation` counter
* increments. A stale reference like `(network_id=5, generation=2)` will not
* match the live `(network_id=5, generation=3)` slot, so use-after-free can
* be detected at parse time on the receiving peer.
*
* Storage is two parallel typed arrays indexed by `network_id`, plus a small
* free-list of reusable IDs. No JS object per slot.
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class ReplicationSlotTable {
/**
* @param {{ initial_capacity?: number }} [options]
*/
constructor({ initial_capacity }?: {
initial_capacity?: number;
});
/**
* Allocate a network_id for the given entity_id. Returns the new id.
* Throws if the entity already has a network_id.
*
* @param {number} entity_id
* @returns {number} network_id
*/
allocate(entity_id: number): number;
/**
* Allocate using an explicit network_id (for the receiving peer that takes its
* IDs from the wire). Bumps the slot's generation if it was reused. Throws
* if the slot is currently in use.
*
* @param {number} network_id
* @param {number} entity_id
*/
allocate_at(network_id: number, entity_id: number): void;
/**
* Free the slot for `network_id`. Bumps the slot's generation. Slot becomes
* available for re-allocation.
*
* @param {number} network_id
*/
free(network_id: number): void;
/**
* Local entity for a network_id, or -1 if the slot is free.
*
* @param {number} network_id
* @returns {number}
*/
entity_for(network_id: number): number;
/**
* Network_id for a local entity, or -1 if not registered.
*
* @param {number} entity_id
* @returns {number}
*/
network_for(entity_id: number): number;
/**
* Generation of the slot. Useful for stale-reference detection.
*
* @param {number} network_id
* @returns {number}
*/
generation_of(network_id: number): number;
/**
* Number of currently-allocated slots.
* @returns {number}
*/
live_count(): number;
#private;
}
//# sourceMappingURL=ReplicationSlotTable.d.ts.map