UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

90 lines (89 loc) 2.26 kB
/** * Represents an infinite space filled with objects. * * @type **O** The type of objects the space will contain * @type **S** The type of solvers the space can use */ export default abstract class Space<O, S> { objects: O[]; solvers: { [index: string]: { cb: S; iterations: number; }; }; /** * Creates a {@link Space} instance. */ /** * Executes a solver on every object in the space. * * @param id The id of the solver to execute */ abstract solve(id: string, ...args: any): void; /** * Steps the space forward by the given delta time. * * @param delta The time since the last frame */ /** * Gets all objects in the space. * * @returns All objects in the space */ getObjects(): O[]; /** * Removes all objects from the space. */ clearObjects(): void; /** * Adds an object to the space. * * @param obj The object to add */ addObject(obj: O): void; /** * Removes an object from the space. * * @param obj The object to remove * @returns Wether or not the object was removed */ removeObject(obj: O): boolean; /** * Gets all solvers in the space. * * @returns All solvers in the space */ getSolvers(): { [index: string]: { cb: S; iterations: number; }; }; /** * Removes all solvers from the space. */ clearSolvers(): void; /** * Adds a solver to the space. * * @param id The solver's identifier * @param cb The solver to add * @param iterations The number of times to run the solver, per time step */ addSolver(id: string, cb: S, iterations: number): void; /** * Removes a solver from the space. * * @param id The id of the solver to remove * @returns Wether or not the solver was removed */ removeSolver(id: string): boolean; /** * Sets the number of iterations a solver should run. * * @param id The id of the solver to update * @param iterations The new number of iterations */ setSolverIterations(id: string, iterations: number): void; }