import { GameBase } from '../core/game.base'; import { Entity } from './entity'; import { EntityManagerConfig } from './entity.manager.config'; /** * Abstract core EntityManager; implementing the abstractable behaviour for the management, update, retrieval and rendering of Entities * * Entities are any object existing in a Game's World, Text or UI * * Three concrete EntityManagers are utilised by the core Game - World for world objects, UI for ui elements and Text for strings. These * are broken down into specific 2D and 3D variants for type safety in 2D and 3D Games * * Handles the management of Entity vertex lists, communicating with the Renderer to manage and draw scenes * * Receives and works with a single TextureAtlas, thereby allowing for texture sources per Entity use-case * * The concrete EntityManagers are available on the Game instance at `game.[world|ui|text]` * * @typeparam Config the configuration object type, extending the core EntityManagerConfig, used by concrete extensions */ export declare abstract class EntityManager { protected readonly config: Config & { name: string; }; /** Flat list of all Entities currently in play, used for efficiently executing frame ticks and in filtering */ private entities; /** Entities with Shaders and Models, grouped by the same, used for optimising vertex compilation and gl API call handling */ private readonly renderableEntities; /** Flat list of Entities to be added on the next frame */ private addList; /** Flat list of Entities to be removed on the next frame */ private removeList; /** Map of VBOs constructed and used in rendering, used to reduce the number of vertex compilations for Entities and gl buffer calls */ private readonly vbos; /** Cached Entity filters, used in optimising filters */ private readonly entityFilterCache; /** * Cached specific-source Entity filters, used in optimising filters from specific sources * * Separated from regular filters so as not to produce conflicts between similar filters of all Entities and subsets */ private readonly sourcedEntityFilterCache; /** * Constructor. Take the type-correct EntityManagerConfig, and initialise the Texture Atlas if provided * * @param config the type-correct EntityManagerConfig */ constructor(config: Config & { name: string; }); /** * Retrieve the number of Entities in play * * @returns the number of active Entities */ get entityCount(): number; /** * Prepare an Entity to be added to the Game on the next frame * * @param entity the Entity to add */ addEntity(entity: Entity): void; /** * Prepare a list of Entities to be added to the Game on the next frame * * @param entities the Entities to add */ addEntities(...entities: Array): void; /** * Prepare an Entity to be removed from the Game on the next frame * * @param entity the Entity to remove */ removeEntity(entity: Entity): void; /** * Prepare a list of Entities to be removed from the Game on the next frame * * @param entities the Entities to remove */ removeEntities(...entities: Array): void; /** * Purge all active Entities immediately */ clearEntities(): void; /** * Frame update method. Process the Entity addList and removeList, then run all active Entities' frame update methods * * @param game the Game the EntityManager is running within * @param frameDelta the frame delta as calculated by the Game */ tick(game: GameBase, frameDelta: number): void; /** * Frame render method. Render all active and renderable Entities. * * Processes Entities grouped by shader+model combinations so as to reduce the amount of GL buffering required and render in batches */ render(): void; /** * Filter the active Entities by a given Component name. Filter results are cached to optimise frame-to-frame filters * * @param component the name of the Component to filter by * * @returns the list of Entities with the Component */ filterEntitiesByComponentName(component: string): Array; /** * Filter the active Entities by a given list of Component names. Filter results are cached to optimise frame-to-frame filters * * @param components the names of the Components to filter by * * @returns the list of Entities with the Components */ filterEntitiesByComponentNames(...components: Array): Array; /** * Filter Entities from a given source by a given Component name. Filter results are cached to optimise frame-to-frame filters * * @param source the Entity list to treat as the filter source * @param filterId an identifier for the filter result, used to avoid conflicts for similar filters across disparate sources * @param components the name of the Component to filter by * * @returns the list of Entities from the source with the Component */ filterEntitiesByComponentNameFromSource(source: Array, filterId: string, component: string): Array; /** * Filter the Entities from a given source by a given list of Component names. Filter results are cached to optimise frame-to-frame * filters * * @param source the Entity list to treat as the filter source * @param filterId an identifier for the filter result, used to avoid conflicts for similar filters across disparate sources * @param components the names of the Components to filter by * * @returns the list of Entities from the source with the Components */ filterEntitiesByComponentNamesFromSource(source: Array, filterId: string, ...components: Array): Array; /** * Filter the active Entities by a given tag. Filter results are cached to optimise frame-to-frame filters * * @param tag the tag to filter by * * @returns the list of Entities with the tag */ filterEntitiesByTag(tag: string): Array; /** * Filter the active Entities by a given list of tags. Filter results are cached to optimise frame-to-frame filters * * @param tags the tags to filter by * * @returns the list of Entities with the tags */ filterEntitiesByTags(...tags: Array): Array; /** * Process the addList by adding Entities both to the grouped store and the flat store, facilitating both fast filters and efficient * rendering * * @returns whether or not the Entity lists were changed, signalling the need to invalidate cached filters */ private loadEntities; /** * Clean the list of active Entities by removing all those in the removeList * * @returns whether or not the Entity lists were changed, signalling the need to invalidate cached filters */ private cleanEntities; /** * Compile any vertex lists and update relevant VBOs for a given set of shader+model combinations altered in Entity list changes * * @param changes the set of shader+model combinations that were altered and require compiling */ private compileVertices; /** * Retrieve a set of Entities by filtering by the given predicate, caching the result to reduce frame-to-frame filtering operations * * Support filtering from a specific source as well as from all Entities, separating the two filter types to avoid set conflicts * * @param filter a string representation of the Entity filter, to be used as a cache key * @param predicate the filter predicate for matching Entities * @param filterId optional filter ID for sourced filters, to be used as a cache key extension. Must be provided for sourced filters * @param source the source to filter from, defaulting to the flat list of all Entities * * @returns the array of Entities matching the filter */ private memoizeFilter; /** * Clear all filter caches in the event of an Entity list chang, ensuring that filters do not become out of date */ private invalidateFilterCaches; }