UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

59 lines 2.31 kB
/** * Maps replicated component classes to compact `uint8` type IDs and to their * replication adapters. Sits on top of the engine's existing * {@link BinarySerializationRegistry}, which keys adapters by class name (string). * * Two reasons this exists separately: * 1. The action-log wire format wants 1-byte type tags, not strings. * 2. The "set of components that get replicated" is a strict subset of "all * classes that have a binary adapter" (e.g. save-game components that we * don't replicate). Registering for replication is an explicit opt-in. * * Registration is order-sensitive: `type_id` is assigned in registration order * starting from 0. To keep `type_id` stable across versions, register in a * fixed order at engine init. * * @author Alex Goldring * @copyright Company Named Limited (c) 2025 */ export class ReplicatedComponentRegistry { /** * @param {BinarySerializationRegistry} binary_registry */ constructor(binary_registry: BinarySerializationRegistry); /** * Register a component class for replication. Looks up the adapter from the * underlying binary registry by class typeName and assigns a stable type_id. * * @param {Function} component_class must have `typeName` static and be registered * in the binary serialization registry * @returns {number} assigned type_id */ register(component_class: Function): number; /** * @param {Function} component_class * @returns {number} type_id, or -1 if unregistered */ type_id_of(component_class: Function): number; /** * @param {number} type_id * @returns {Function|undefined} */ class_of(type_id: number): Function | undefined; /** * @param {number} type_id * @returns {BinaryClassSerializationAdapter|undefined} */ adapter_for_id(type_id: number): BinaryClassSerializationAdapter | undefined; /** * @param {Function} component_class * @returns {BinaryClassSerializationAdapter|undefined} */ adapter_for_class(component_class: Function): BinaryClassSerializationAdapter | undefined; /** * @returns {number} */ type_count(): number; #private; } //# sourceMappingURL=ReplicatedComponentRegistry.d.ts.map