@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
60 lines • 1.99 kB
TypeScript
/**
* Registry that maps `type_id ↔ SimAction subclass`, with a small per-type
* object pool to recycle action instances (avoids GC pressure on the hot path).
*
* Wire format: `type_id` is a `uint8`. The cap of 256 distinct action types is
* deliberate — if you need more, your design probably wants a generic
* `MutateComponentAction` rather than a bespoke action per case.
*
* Registration is order-sensitive: `type_id` is assigned in registration order
* starting from 0. To keep `type_id` stable across versions, register actions
* in a fixed order at engine init.
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class SimActionRegistry {
/**
* Maximum pool size per type. Beyond this, released instances are dropped.
* @type {number}
*/
max_pool_size: number;
/**
* Register a SimAction subclass and assign it a stable `type_id`.
* Returns the assigned id.
*
* @param {Function} klass
* @returns {number} assigned type_id
*/
register(klass: Function): number;
/**
* Look up an action class by type_id. Returns undefined if unknown.
*
* @param {number} type_id
* @returns {Function|undefined}
*/
klass_for(type_id: number): Function | undefined;
/**
* Acquire a recycled instance of the given action class, or create a fresh
* one if the pool is empty. The returned instance has had `reset()` called.
*
* @param {Function|{type_id:number}} klass
* @returns {SimAction}
*/
acquire(klass: Function | {
type_id: number;
}): SimAction;
/**
* Release an instance back to its pool. Drops on the floor if the pool is full.
*
* @param {SimAction} instance
*/
release(instance: SimAction): void;
/**
* Number of registered action types.
* @returns {number}
*/
type_count(): number;
#private;
}
//# sourceMappingURL=SimActionRegistry.d.ts.map