Files
esengine/packages/core/src/ECS/IScene.ts

319 lines
6.9 KiB
TypeScript
Raw Normal View History

2025-08-12 09:39:07 +08:00
import { Entity } from './Entity';
import { EntityList } from './Utils/EntityList';
import { IdentifierPool } from './Utils/IdentifierPool';
import { EntitySystem } from './Systems/EntitySystem';
import { ComponentStorageManager } from './Core/ComponentStorage';
import { QuerySystem } from './Core/QuerySystem';
import { TypeSafeEventSystem } from './Core/EventSystem';
import type { ReferenceTracker } from './Core/ReferenceTracker';
2025-10-20 17:24:56 +08:00
import type { ServiceContainer, ServiceType } from '../Core/ServiceContainer';
import type { TypedQueryBuilder } from './Core/Query/TypedQuery';
import type { SceneSerializationOptions, SceneDeserializationOptions } from './Serialization/SceneSerializer';
import type { IncrementalSnapshot, IncrementalSerializationOptions } from './Serialization/IncrementalSerializer';
2025-08-12 09:39:07 +08:00
/**
*
2025-10-08 18:34:15 +08:00
*
2025-08-12 09:39:07 +08:00
* 使
*/
export interface IScene {
/**
*
*/
name: string;
2025-08-12 09:39:07 +08:00
2025-10-08 18:34:15 +08:00
/**
*
*
*
* -
* -
* -
* -
* -
*
* @example
* ```typescript
* scene.sceneData.set('weather', 'rainy');
* scene.sceneData.set('timeOfDay', 14.5);
* scene.sceneData.set('checkpoint', { x: 100, y: 200 });
* ```
*/
readonly sceneData: Map<string, any>;
2025-08-12 09:39:07 +08:00
/**
*
*/
readonly entities: EntityList;
2025-10-10 21:52:43 +08:00
2025-08-12 09:39:07 +08:00
/**
*
*/
readonly identifierPool: IdentifierPool;
/**
*
*/
readonly componentStorageManager: ComponentStorageManager;
/**
*
*/
readonly querySystem: QuerySystem;
/**
*
*/
readonly eventSystem: TypeSafeEventSystem;
/**
*
*/
readonly referenceTracker: ReferenceTracker;
/**
*
*
*
*/
readonly services: ServiceContainer;
2025-08-12 09:39:07 +08:00
/**
*
*/
readonly systems: EntitySystem[];
/**
*
*/
initialize(): void;
/**
*
*/
onStart(): void;
/**
*
*/
unload(): void;
/**
*
*/
begin(): void;
/**
*
*/
end(): void;
/**
*
*/
update(): void;
/**
*
*/
createEntity(name: string): Entity;
/**
* EntitySystem的实体缓存
*/
clearSystemEntityCaches(): void;
2025-08-12 09:39:07 +08:00
/**
*
*/
addEntity(entity: Entity, deferCacheClear?: boolean): Entity;
/**
*
*/
createEntities(count: number, namePrefix?: string): Entity[];
/**
*
*/
destroyAllEntities(): void;
/**
*
*/
findEntity(name: string): Entity | null;
/**
*
*/
findEntitiesByTag(tag: number): Entity[];
/**
*
*/
addEntityProcessor(processor: EntitySystem): EntitySystem;
/**
*
*/
removeEntityProcessor(processor: EntitySystem): void;
/**
*
*/
getEntityProcessor<T extends EntitySystem>(type: new (...args: any[]) => T): T | null;
2025-10-20 17:24:56 +08:00
/**
* ID查找实体
*/
findEntityById(id: number): Entity | null;
/**
*
*/
getEntityByName(name: string): Entity | null;
/**
*
*/
getEntitiesByTag(tag: number): Entity[];
/**
*
*/
destroyEntities(entities: Entity[]): void;
/**
*
*/
queryAll(...componentTypes: any[]): { entities: readonly Entity[] };
/**
*
*/
queryAny(...componentTypes: any[]): { entities: readonly Entity[] };
/**
*
*/
queryNone(...componentTypes: any[]): { entities: readonly Entity[] };
/**
*
*/
query(): TypedQueryBuilder;
/**
* System实例
*/
getSystem<T extends EntitySystem>(systemType: ServiceType<T>): T | null;
/**
* EntitySystem到场景
*/
registerSystems(systemTypes: Array<ServiceType<EntitySystem>>): EntitySystem[];
/**
*
*/
addSystem(system: EntitySystem): EntitySystem;
/**
*
*/
removeSystem(system: EntitySystem): void;
/**
*
*/
getStats(): {
entityCount: number;
processorCount: number;
componentStorageStats: Map<string, any>;
};
/**
*
*/
getDebugInfo(): {
name: string;
entityCount: number;
processorCount: number;
isRunning: boolean;
entities: Array<{
name: string;
id: number;
componentCount: number;
componentTypes: string[];
}>;
processors: Array<{
name: string;
updateOrder: number;
entityCount: number;
}>;
componentStats: Map<string, any>;
};
/**
*
*/
serialize(options?: SceneSerializationOptions): string | Uint8Array;
/**
*
*/
deserialize(saveData: string | Uint8Array, options?: SceneDeserializationOptions): void;
/**
*
*/
createIncrementalSnapshot(options?: IncrementalSerializationOptions): void;
/**
*
*/
serializeIncremental(options?: IncrementalSerializationOptions): IncrementalSnapshot;
/**
*
*/
applyIncremental(
incremental: IncrementalSnapshot | string | Uint8Array,
componentRegistry?: Map<string, any>
): void;
/**
*
*/
updateIncrementalSnapshot(options?: IncrementalSerializationOptions): void;
/**
*
*/
clearIncrementalSnapshot(): void;
/**
*
*/
hasIncrementalSnapshot(): boolean;
2025-08-12 09:39:07 +08:00
}
/**
*
*/
export interface ISceneFactory<T extends IScene> {
/**
*
*/
createScene(): T;
}
/**
*
*/
export interface ISceneConfig {
/**
*
*/
name?: string;
}