@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
104 lines • 3.13 kB
TypeScript
/**
* Uniquely identifies an entity by both its ID and generation.
* Lets us uniquely distinguish between two entities, even those with the same ID that were created at different times
* @example
* // 1. Get your EntityComponentDataset to where you manager entities.
* const ecd = ... ; // EntityComponentDataset
*
* // 2. Create an entity (we'll get an ID).
* const entityId = ecd.createEntity();
*
* // 3. Create an EntityReference and bind it to the entity.
* const entityRef = EntityReference.bind(ecd, entityId);
*
* // 4. After you no longer need the entity - destroy the entity via reference.
* entityRef.destroy(ecd);
*
* @see {@link EntityComponentDataset}
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class EntityReference {
/**
*
* @param {number} id
* @param {number} generation
* @return {EntityReference}
*/
static from(id: number, generation: number): EntityReference;
/**
*
* @param {EntityComponentDataset} ecd
* @param {number} id
* @returns {EntityReference}
*/
static bind(ecd: EntityComponentDataset, id: number): EntityReference;
/**
* Entity ID
* When entity is live - this is the entity ID inside associated `EntityComponentDataset`, when the entity is not live - it's set to -1
* @type {number}
*/
id: number;
/**
* Entity generation number. This uniquely identifies an entity in combination with the ID
* Generation of an existing entity must match for it to be considered "the same".
* @see {@link EntityComponentDataset.getEntityGeneration}
* @type {number}
*/
generation: number;
/**
*
* @param {EntityReference} other
*/
copy(other: EntityReference): void;
/**
*
* @returns {EntityReference}
*/
clone(): EntityReference;
/**
*
* @return {number}
*/
hash(): number;
/**
*
* @param {EntityReference} other
* @return {boolean}
*/
equals(other: EntityReference): boolean;
/**
* Checks whether referenced entity exists and the generation matches
* @param {EntityComponentDataset} ecd
* @returns {boolean}
*/
verify(ecd: EntityComponentDataset): boolean;
/**
* Destroys entity bound to this reference
* If the reference is invalid for the given dataset - does nothing
* @param {EntityComponentDataset} ecd
* @returns {boolean} true if entity was destroyed, false otherwise
*/
destroy(ecd: EntityComponentDataset): boolean;
/**
* Bind reference to a specific entity
* @param {EntityComponentDataset} ecd
* @param {number} entity
*/
bind(ecd: EntityComponentDataset, entity: number): void;
/**
*
* @param {number} id
* @param {number} generation
*/
from(id: number, generation: number): void;
/**
* @readonly
* @type {boolean}
*/
readonly isEntityReference: boolean;
}
export namespace EntityReference {
let NULL: EntityReference;
}
//# sourceMappingURL=EntityReference.d.ts.map