UNPKG

@rpgjs/physic

Version:

A deterministic 2D top-down physics library for RPG, sandbox and MMO games

124 lines 3.05 kB
import { Region } from './Region'; import { Entity } from '../physics/Entity'; import { AABB } from '../core/math/AABB'; import { Vector2 } from '../core/math/Vector2'; /** * Region manager configuration */ export interface RegionManagerConfig { /** World bounds */ worldBounds: AABB; /** Region size (width and height) */ regionSize: number; /** Overlap between regions */ overlap?: number; /** Auto-activate regions based on entity presence (default: true) */ autoActivate?: boolean; } /** * Region manager * * Manages multiple regions in a distributed physics world. * Handles entity migration between regions and region activation/deactivation. * * @example * ```typescript * const manager = new RegionManager({ * worldBounds: new AABB(0, 0, 1000, 1000), * regionSize: 200, * overlap: 20 * }); * ``` */ export declare class RegionManager { private regions; private regionMap; private config; private entityRegionMap; /** * Creates a new region manager * * @param config - Manager configuration */ constructor(config: RegionManagerConfig); /** * Creates the grid of regions */ private createRegions; /** * Gets a region key from grid coordinates * * @param col - Column index * @param row - Row index * @returns Region key string */ private getRegionKey; /** * Gets the region containing a point * * @param point - Point to find region for * @returns Region or null */ getRegionAt(point: Vector2): Region | null; /** * Gets all regions that overlap with an AABB * * @param bounds - AABB to check * @returns Array of overlapping regions */ getRegionsInBounds(bounds: AABB): Region[]; /** * Adds an entity to the appropriate region * * @param entity - Entity to add */ addEntity(entity: Entity): void; /** * Removes an entity from its region * * @param entity - Entity to remove */ removeEntity(entity: Entity): void; /** * Updates entity positions and migrates them between regions if needed */ updateEntities(): void; /** * Steps all active regions */ step(): void; /** * Gets all regions * * @returns Array of all regions */ getRegions(): Region[]; /** * Gets active regions * * @returns Array of active regions */ getActiveRegions(): Region[]; /** * Gets the region containing an entity * * @param entity - Entity to find region for * @returns Region or null */ getEntityRegion(entity: Entity): Region | null; /** * Clears all entities from all regions */ clear(): void; /** * Gets statistics about regions * * @returns Statistics object */ getStats(): { totalRegions: number; activeRegions: number; totalEntities: number; }; } //# sourceMappingURL=RegionManager.d.ts.map