@skewedaspect/sage 0.10.0-rc.2 → 0.10.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { TransformNode, AbstractMesh } from '@babylonjs/core';
2
- import { GameEntity, Action, BehaviorClass, ComposedOf, DeepReadonly, GameEntityState, GameEntityType, GameSimulationContext, OpsFor, StateFor, ValidTuple } from '@skewedaspect/sage-core';
2
+ import { GameEntity, Action, BehaviorClass, ComposedOf, DeepReadonly, GameEntityState, GameEntityType, OpsFor, StateFor, ValidTuple } from '@skewedaspect/sage-core';
3
3
  import { AudioManager } from "../managers/audio.js";
4
4
  import { ColliderDebugConfig } from "../managers/colliderDebug.js";
5
5
  import { NodeSimulationContext } from "./nodeSimulationContext.js";
@@ -26,7 +26,7 @@ export interface NodeBehaviorHooks {
26
26
  onMeshLoaded?(): void;
27
27
  onDestroy?(): void;
28
28
  }
29
- export declare abstract class NodeEntity<Behaviors extends readonly BehaviorClass[] = readonly BehaviorClass[]> extends GameEntity {
29
+ export declare abstract class NodeEntity<Behaviors extends readonly BehaviorClass[] = readonly BehaviorClass[]> extends GameEntity<NodeSimulationContext> {
30
30
  #private;
31
31
  static readonly poolable: boolean;
32
32
  static readonly poolSize?: number;
@@ -47,6 +47,6 @@ export declare abstract class NodeEntity<Behaviors extends readonly BehaviorClas
47
47
  showCollider(config?: ColliderDebugConfig, color?: string): void;
48
48
  hideCollider(name?: string): void;
49
49
  protected declareComputedState(suppliedState: object): void;
50
- protected constructor(id: string, context: GameSimulationContext, providedState: object, runCreateHooks: boolean, name?: string);
50
+ protected constructor(id: string, context: NodeSimulationContext, providedState: object, runCreateHooks: boolean, name?: string);
51
51
  destroy(): void;
52
52
  }
@@ -1,4 +1,4 @@
1
- import { GameSimulationManager, GameEntityRegistry, GameSimulationOptions, GameSimulationSnapshot, StateBag, ValidEntityRegistry } from '@skewedaspect/sage-core';
1
+ import { GameSimulation, GameEntityRegistry, GameSimulationOptions, GameSimulationSnapshot, StateBag, ValidEntityRegistry } from '@skewedaspect/sage-core';
2
2
  import { AbstractMesh, Camera, Ray, Scene } from '@babylonjs/core';
3
3
  import { EntityPickFilter, EntityPickResult } from "./entityPicking.js";
4
4
  import { NodeEntity } from "./nodeEntity.js";
@@ -6,6 +6,7 @@ import { NodePool } from "./nodePool.js";
6
6
  import { MeshLoader, NodeSimulationContext } from "./nodeSimulationContext.js";
7
7
  import { AudioManager } from "../managers/audio.js";
8
8
  import { ColliderDebugManager } from "../managers/colliderDebug.js";
9
+ import { LoggerInterface } from "../interfaces/logger.js";
9
10
  export type NodeEntityRegistry = GameEntityRegistry<NodeSimulationContext>;
10
11
  export interface NodeSimulationOptions<Registry extends NodeEntityRegistry = NodeEntityRegistry> extends GameSimulationOptions<Registry> {
11
12
  scene: Scene;
@@ -13,14 +14,16 @@ export interface NodeSimulationOptions<Registry extends NodeEntityRegistry = Nod
13
14
  pool: NodePool;
14
15
  audio?: AudioManager;
15
16
  colliders: ColliderDebugManager;
17
+ logger?: LoggerInterface;
16
18
  }
17
- export declare class NodeSimulation<Registry extends NodeEntityRegistry = NodeEntityRegistry> extends GameSimulationManager<Registry, NodeSimulationContext> implements NodeSimulationContext {
19
+ export declare class NodeSimulation<Registry extends NodeEntityRegistry = NodeEntityRegistry> extends GameSimulation<Registry, NodeSimulationContext> implements NodeSimulationContext {
18
20
  #private;
19
21
  readonly scene: Scene;
20
22
  readonly pool: NodePool;
21
23
  readonly loadMesh: MeshLoader;
22
24
  readonly audio: AudioManager | undefined;
23
25
  readonly colliders: ColliderDebugManager;
26
+ readonly logger: LoggerInterface;
24
27
  constructor(options: NodeSimulationOptions<Registry> & {
25
28
  entityClasses: ValidEntityRegistry<Registry>;
26
29
  });
@@ -36,7 +39,6 @@ export declare class NodeSimulation<Registry extends NodeEntityRegistry = NodeEn
36
39
  pickEntity(x: number, y: number, filter?: EntityPickFilter): EntityPickResult | undefined;
37
40
  pickEntityForward(camera: Camera, range: number, filter?: EntityPickFilter): EntityPickResult | undefined;
38
41
  getEntityForMesh(mesh: AbstractMesh): NodeEntity | undefined;
39
- spawnByName(name: string, state?: StateBag, id?: string): NodeEntity;
40
42
  buildFromSnapshot(snapshot: GameSimulationSnapshot): NodeSimulation<Registry>;
41
43
  protected buildReplacementSimulation(options: GameSimulationOptions<Registry>): NodeSimulation<Registry>;
42
44
  }
@@ -1,5 +1,6 @@
1
1
  import { AbstractMesh, Scene, TransformNode } from '@babylonjs/core';
2
- import { GameSimulationContext, StateBag } from '@skewedaspect/sage-core';
2
+ import { GameSimulationView, StateBag } from '@skewedaspect/sage-core';
3
+ import { LoggerInterface } from "../interfaces/logger.js";
3
4
  import { AudioManager } from "../managers/audio.js";
4
5
  import { ColliderDebugManager } from "../managers/colliderDebug.js";
5
6
  import { NodePool } from "./nodePool.js";
@@ -8,10 +9,11 @@ export interface NodeSet {
8
9
  mesh: AbstractMesh | undefined;
9
10
  }
10
11
  export type MeshLoader = (scene: Scene, name: string, state: Readonly<StateBag>) => Promise<AbstractMesh | undefined>;
11
- export interface NodeSimulationContext extends GameSimulationContext {
12
+ export interface NodeSimulationContext extends GameSimulationView {
12
13
  readonly scene: Scene;
13
14
  readonly pool: NodePool;
14
15
  readonly loadMesh: MeshLoader;
15
16
  readonly audio?: AudioManager;
16
17
  readonly colliders: ColliderDebugManager;
18
+ readonly logger: LoggerInterface;
17
19
  }
@@ -1,8 +1,8 @@
1
- import { AbstractMesh, AssetContainer, Mesh } from '@babylonjs/core';
1
+ import { AbstractMesh, AssetContainer, Mesh, Scene } from '@babylonjs/core';
2
2
  import { GameEntityType } from '@skewedaspect/sage-core';
3
3
  import { MeshLoader } from "./nodeSimulationContext.js";
4
4
  export interface MeshAssetSource {
5
5
  load(path: string): Promise<AssetContainer | AbstractMesh>;
6
- clone(path: string): Mesh;
6
+ clone(path: string, into: Scene): Mesh;
7
7
  }
8
8
  export declare function buildStandardMeshSource(entityClasses: Readonly<Record<string, GameEntityType>>, assets: MeshAssetSource): MeshLoader;
@@ -1,4 +1,4 @@
1
- import { Action, GameSimulationContext } from '@skewedaspect/sage-core';
1
+ import { Action, GameSimulationView } from '@skewedaspect/sage-core';
2
2
  import { Binding } from "./binding.js";
3
- export declare function deliverAction<State>(binding: Binding<State>, state: State, context: GameSimulationContext, senderID: string): void;
4
- export declare function deliverValueAction(action: Action, value: number, context: GameSimulationContext, senderID: string): void;
3
+ export declare function deliverAction<State>(binding: Binding<State>, state: State, context: GameSimulationView, senderID: string): void;
4
+ export declare function deliverValueAction(action: Action, value: number, context: GameSimulationView, senderID: string): void;
@@ -1,4 +1,4 @@
1
- import { AbstractMesh, AssetContainer, InstancedMesh, Mesh } from '@babylonjs/core';
1
+ import { Mesh, AbstractMesh, AssetContainer, InstancedMesh, Scene } from '@babylonjs/core';
2
2
  import { EventBus } from '@skewedaspect/sage-core';
3
3
  import { SceneEngine } from "../engines/scene.js";
4
4
  import { Disposable } from "../interfaces/lifecycle.js";
@@ -32,6 +32,11 @@ export declare class AssetManager implements Disposable {
32
32
  private _loadContainer;
33
33
  /**
34
34
  * Read one container off disk and cache it, counting no references; `_loadContainer` does the counting.
35
+ *
36
+ * The scene the read goes into is cached beside the container and lives as long as it does. Babylon's
37
+ * `AssetContainer` subscribes to its scene's disposal and disposes itself, meshes and all, so disposing
38
+ * the scene early would leave an emptied container in the cache
39
+ * (design/engine.md#the-asset-manager).
35
40
  */
36
41
  private _fetchContainer;
37
42
  /**
@@ -52,9 +57,16 @@ export declare class AssetManager implements Disposable {
52
57
  */
53
58
  instance(path: string): InstancedMesh;
54
59
  /**
55
- * Clone a cached source mesh into an independent copy. The path must have been loaded first.
60
+ * Clone a cached source mesh into an independent copy, in the scene it is handed. The path must have been
61
+ * loaded first.
62
+ *
63
+ * `Mesh.clone` keeps the source's scene, and the source lives in the scene this manager read the file
64
+ * into, so a clone made that way would never draw in the level that asked for it. Building the copy
65
+ * against the scene it is handed is what puts it in the level's, and `doNotCloneChildren` keeps a mesh
66
+ * parented under the source from being left behind in the manager's
67
+ * (design/engine.md#the-asset-manager).
56
68
  */
57
- clone(path: string): Mesh;
69
+ clone(path: string, into: Scene): Mesh;
58
70
  /**
59
71
  * Preload a batch of asset paths, up to `MAX_CONCURRENT_LOADS` at a time, so a batch costs about as
60
72
  * long as its slowest asset rather than the sum of them all.
@@ -1,4 +1,4 @@
1
- import { GameSimulationContext, Unsubscribe } from '@skewedaspect/sage-core';
1
+ import { GameSimulationView, Unsubscribe } from '@skewedaspect/sage-core';
2
2
  import { Disposable } from "../interfaces/lifecycle.js";
3
3
  import { Binding, BindingDefinition, DeviceType } from "../input/binding.js";
4
4
  import { InputCapture } from "../input/inputCapture.js";
@@ -30,6 +30,6 @@ export declare class InputManager implements Disposable {
30
30
  bind(definition: BindingDefinition): Binding<unknown>;
31
31
  registerCapture(capture: InputCapture): Unsubscribe;
32
32
  getBindingsForAction(action: string, deviceType?: DeviceType, context?: string): readonly Binding<unknown>[];
33
- routeCapturedInput(context: GameSimulationContext): void;
33
+ routeCapturedInput(context: GameSimulationView): void;
34
34
  dispose(): Promise<void>;
35
35
  }
package/dist/sage.d.ts CHANGED
@@ -29,8 +29,8 @@ export * from "./interfaces/lifecycle.js";
29
29
  export * from "./utils/logger.js";
30
30
  export * from "./utils/timer.js";
31
31
  export * from "./utils/version.js";
32
- export { Behavior, EventBus, GameEntity, GameSimulationManager, NamedBehavior, StateMachineBehavior, defineStates, dilationLimit, drainPassLimit, operationCallDepthLimit, } from '@skewedaspect/sage-core';
33
- export type { BehaviorClass, ComposedOf, Computation, DeepReadonly, EventCallback, EventMap, EventSubscription, EventsMatching, GameEntityClass, GameEntityRegistry, GameEntitySnapshot, GameEntityState, GameEntityType, GameEvent, GameSimulationContext, GameSimulationOptions, GameSimulationSnapshot, IDAllocator, NamedState, NarrowedTo, OpsFor, OpsOf, StateBag, StateDefinition, StateFor, StateSliceOf, StateValue, Subscriber, Unsubscribe, ValidEntityRegistry, ValidTuple, } from '@skewedaspect/sage-core';
32
+ export { Behavior, EventBus, GameEntity, GameRandom, GameSimulation, NamedBehavior, StateMachineBehavior, defineStates, dilationLimit, drainPassLimit, operationCallDepthLimit, } from '@skewedaspect/sage-core';
33
+ export type { BehaviorClass, ComposedOf, Computation, DeepReadonly, EventCallback, EventMap, EventSubscription, EventsMatching, GameEntityClass, GameEntityRegistry, GameEntitySnapshot, GameEntityState, GameEntityType, GameEvent, GameSimulationOptions, GameSimulationSnapshot, GameSimulationView, IDAllocator, NamedState, NarrowedTo, OpsFor, OpsOf, RandomSeed, RandomState, SimulationFor, StateBag, StateDefinition, StateFor, StateSliceOf, StateValue, Subscriber, Unsubscribe, ValidEntityRegistry, ValidTuple, } from '@skewedaspect/sage-core';
34
34
  export { NodeEntity } from "./entities/nodeEntity.js";
35
35
  export type { NodeBehaviorHooks, NodeEntityState, QuaternionState, Vector3State } from "./entities/nodeEntity.js";
36
36
  export { NodePool } from "./entities/nodePool.js";