@skewedaspect/sage 0.9.6 → 0.10.0-beta.2

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.
Files changed (74) hide show
  1. package/dist/behaviors/sound.d.ts +12 -127
  2. package/dist/classes/debugConsole.d.ts +1 -0
  3. package/dist/classes/gameEngine.d.ts +31 -46
  4. package/dist/classes/gameLevel.d.ts +21 -12
  5. package/dist/classes/level.d.ts +24 -29
  6. package/dist/entities/constants.d.ts +1 -0
  7. package/dist/entities/defineEntity.d.ts +17 -0
  8. package/dist/entities/entityPicking.d.ts +15 -0
  9. package/dist/entities/meshConfig.d.ts +14 -0
  10. package/dist/entities/nodeEntity.d.ts +43 -0
  11. package/dist/entities/nodePool.d.ts +8 -0
  12. package/dist/entities/nodeSimulation.d.ts +30 -0
  13. package/dist/entities/nodeSimulationContext.d.ts +17 -0
  14. package/dist/entities/standardMeshSource.d.ts +8 -0
  15. package/dist/events/payloads.d.ts +0 -42
  16. package/dist/events/types.d.ts +2 -23
  17. package/dist/input/actionContext.d.ts +13 -0
  18. package/dist/input/actionRegistry.d.ts +7 -0
  19. package/dist/input/binding.d.ts +33 -0
  20. package/dist/input/bindings/delta.d.ts +23 -0
  21. package/dist/input/bindings/toggle.d.ts +25 -0
  22. package/dist/input/bindings/trigger.d.ts +23 -0
  23. package/dist/input/bindings/value.d.ts +26 -0
  24. package/dist/input/configuration.d.ts +15 -0
  25. package/dist/input/deliverAction.d.ts +4 -0
  26. package/dist/input/deviceReader.d.ts +5 -0
  27. package/dist/input/deviceReaders/gamepad.d.ts +9 -0
  28. package/dist/input/deviceReaders/keyboard.d.ts +8 -0
  29. package/dist/input/deviceReaders/mouse.d.ts +9 -0
  30. package/dist/input/deviceState.d.ts +24 -0
  31. package/dist/input/inputCapture.d.ts +21 -0
  32. package/dist/input/resolveBinding.d.ts +4 -0
  33. package/dist/interfaces/game.d.ts +21 -5
  34. package/dist/interfaces/level.d.ts +21 -3
  35. package/dist/managers/asset.d.ts +17 -3
  36. package/dist/managers/game.d.ts +15 -5
  37. package/dist/managers/input.d.ts +31 -51
  38. package/dist/managers/level.d.ts +20 -4
  39. package/dist/managers/outline.d.ts +4 -4
  40. package/dist/managers/simulationSave.d.ts +38 -0
  41. package/dist/{postProcessingFrameGraph-CaMgQzR-.js → postProcessingFrameGraph-C3Og4kaS.js} +34 -26
  42. package/dist/postProcessingFrameGraph-C3Og4kaS.js.map +1 -0
  43. package/dist/sage.d.ts +54 -16
  44. package/dist/sage.es.js +1868 -2424
  45. package/dist/sage.es.js.map +1 -1
  46. package/dist/sage.umd.js +1 -1
  47. package/dist/sage.umd.js.map +1 -1
  48. package/dist/utils/bounds.d.ts +11 -0
  49. package/dist/utils/physics.d.ts +4 -1
  50. package/package.json +29 -66
  51. package/LICENSE +0 -21
  52. package/Readme.md +0 -73
  53. package/dist/behaviors/index.d.ts +0 -2
  54. package/dist/behaviors/stateMachine.d.ts +0 -76
  55. package/dist/classes/bindings/toggle.d.ts +0 -116
  56. package/dist/classes/bindings/trigger.d.ts +0 -81
  57. package/dist/classes/bindings/value.d.ts +0 -104
  58. package/dist/classes/entity.d.ts +0 -332
  59. package/dist/classes/input/gamepad.d.ts +0 -94
  60. package/dist/classes/input/keyboard.d.ts +0 -66
  61. package/dist/classes/input/mouse.d.ts +0 -91
  62. package/dist/classes/input/readers/gamepad.d.ts +0 -73
  63. package/dist/classes/input/readers/keyboard.d.ts +0 -56
  64. package/dist/classes/input/readers/mouse.d.ts +0 -41
  65. package/dist/interfaces/action.d.ts +0 -22
  66. package/dist/interfaces/binding.d.ts +0 -123
  67. package/dist/interfaces/entity.d.ts +0 -97
  68. package/dist/interfaces/input.d.ts +0 -180
  69. package/dist/managers/binding.d.ts +0 -233
  70. package/dist/managers/entity.d.ts +0 -264
  71. package/dist/managers/save.d.ts +0 -75
  72. package/dist/postProcessingFrameGraph-CaMgQzR-.js.map +0 -1
  73. package/dist/utils/entityProxy.d.ts +0 -2
  74. package/dist/utils/raycast.d.ts +0 -26
@@ -1,233 +0,0 @@
1
- import { GameEventBus } from "../classes/eventBus.d.ts";
2
- import { Binding, BindingDefinition, CaptureInputOptions, Context, InputDefinition } from "../interfaces/binding.d.ts";
3
- import { Disposable } from "../interfaces/lifecycle.d.ts";
4
- import { DeviceType, InputDevice, InputState } from "../interfaces/input.d.ts";
5
- import { Action } from "../interfaces/action.d.ts";
6
- import { LoggingUtility } from "../utils/logger.d.ts";
7
- /**
8
- * Configuration object structure for binding manager
9
- */
10
- export interface BindingConfiguration {
11
- /** All registered actions */
12
- actions: Action[];
13
- /** All registered bindings */
14
- bindings: BindingDefinition[];
15
- /** All registered contexts */
16
- contexts: {
17
- name: string;
18
- exclusive: boolean;
19
- active: boolean;
20
- }[];
21
- }
22
- /**
23
- * Manages input bindings and actions for the game
24
- */
25
- export declare class BindingManager implements Disposable {
26
- /** Map of device IDs to their bindings */
27
- private _bindings;
28
- /** Map of action names to their action definitions */
29
- private _actions;
30
- /** Map of all registered contexts by name for O(1) lookup */
31
- private _contexts;
32
- /**
33
- * Set of all active contexts (both exclusive and non-exclusive)
34
- */
35
- private _activeContexts;
36
- /** The most recent device type that produced intentional input */
37
- private _lastActiveDeviceType;
38
- /** Last input state per device, used to prime edge state on context activation */
39
- private _lastInputState;
40
- /** Active captureInput() state, or null when not capturing */
41
- private _captureState;
42
- /** Event bus for handling game events */
43
- private _eventBus;
44
- /** Unsubscribe function for input events */
45
- private _inputUnsubscribe;
46
- /** Logger instance */
47
- private _log;
48
- /**
49
- * Creates an instance of BindingManager.
50
- * Automatically subscribes to 'input:changed' events on the event bus.
51
- *
52
- * @param eventBus
53
- * @param logger
54
- */
55
- constructor(eventBus: GameEventBus, logger?: LoggingUtility);
56
- /**
57
- * Checks if a binding's context is currently active.
58
- * Bindings with no context are always considered active.
59
- *
60
- * @param binding
61
- */
62
- private _isBindingContextActive;
63
- /**
64
- * Get a context by name, creating it if it doesn't exist.
65
- *
66
- * @param contextName
67
- * @param exclusive - Only used when creating a new context
68
- */
69
- private _getOrCreateContext;
70
- /**
71
- * Deactivate all exclusive contexts except the specified one.
72
- * Non-exclusive contexts are left untouched.
73
- *
74
- * @param exceptContextName
75
- */
76
- private _deactivateExclusiveContexts;
77
- /**
78
- * Determines whether an input event represents intentional activity that should
79
- * update the last-active device type. Filters out noise like idle mousemove.
80
- *
81
- * @param state
82
- */
83
- private _shouldUpdateActiveDevice;
84
- /**
85
- * Create a binding from a binding definition.
86
- *
87
- * @param definition
88
- * @returns Null if the action is not registered or the binding type is unsupported
89
- */
90
- private _createBindingFromDefinition;
91
- /**
92
- * Create a device value reader from a definition object.
93
- *
94
- * @param definition
95
- * @throws Error if the reader type is not supported
96
- */
97
- private _createInputSourceFromDefinition;
98
- /**
99
- * Evaluates an input event during capture mode. If the event matches the capture criteria,
100
- * resolves the capture promise and cleans up. Otherwise does nothing and waits for the next event.
101
- *
102
- * @param device
103
- * @param state
104
- */
105
- private _processCaptureInput;
106
- /**
107
- * Tears down capture state, deactivates the temporary context, and restores the
108
- * snapshotted contexts. Does not resolve or reject — the caller handles that.
109
- */
110
- private _cleanupCapture;
111
- /**
112
- * Handle input from a device and process all relevant bindings.
113
- *
114
- * **Internal API**: This method is prefixed with `$` to indicate it is intended for internal
115
- * engine use only. While it is public for testing purposes, external code should not call
116
- * this method directly. Input handling is triggered automatically via the event bus.
117
- *
118
- * @param device - The input device
119
- * @param state - Current input state
120
- *
121
- * @internal
122
- */
123
- $handleInput(device: InputDevice, state: InputState): void;
124
- /**
125
- * Registers an action.
126
- *
127
- * @param action
128
- * @throws Error if action is already registered
129
- */
130
- registerAction(action: Action): void;
131
- /**
132
- * Gets an action by name.
133
- *
134
- * @param actionName
135
- */
136
- getAction(actionName: string): Action | null;
137
- /**
138
- * Returns the device type that most recently produced intentional input,
139
- * or `null` if no input has been received yet.
140
- */
141
- get lastActiveDeviceType(): DeviceType | null;
142
- /**
143
- * Waits for the next intentional input event and returns a descriptor suitable for constructing
144
- * a binding. While capturing, all normal bindings are suppressed via a temporary exclusive context.
145
- * Previous context state is restored when the capture completes or is cancelled.
146
- *
147
- * @param options
148
- * @throws Error if a capture is already in progress
149
- */
150
- captureInput(options: CaptureInputOptions): Promise<InputDefinition>;
151
- /**
152
- * Registers a context with specific options.
153
- * Updates exclusivity if the context already exists.
154
- *
155
- * @param contextName
156
- * @param exclusive
157
- */
158
- registerContext(contextName: string, exclusive?: boolean): Context;
159
- /**
160
- * Activates a context, enabling all bindings associated with it.
161
- * If the context is exclusive, all other exclusive contexts will be deactivated.
162
- *
163
- * @param contextName
164
- */
165
- activateContext(contextName: string): void;
166
- /**
167
- * Deactivates a context, disabling all bindings associated with it.
168
- *
169
- * @param contextName
170
- */
171
- deactivateContext(contextName: string): void;
172
- /**
173
- * Returns a list of all active contexts.
174
- */
175
- getActiveContexts(): string[];
176
- /**
177
- * Returns whether a context is active.
178
- *
179
- * @param contextName
180
- */
181
- isContextActive(contextName: string): boolean;
182
- /**
183
- * Gets a context by name.
184
- *
185
- * @param contextName
186
- */
187
- getContext(contextName: string): Context | null;
188
- /**
189
- * Register a binding for an input device.
190
- * Auto-registers the binding's context if not already known.
191
- *
192
- * @param binding
193
- * @throws Error if binding type is invalid
194
- */
195
- $registerBinding(binding: Binding): void;
196
- /**
197
- * Register a binding using a binding definition object.
198
- * Creates the appropriate Binding subclass and registers it.
199
- *
200
- * @param definition
201
- */
202
- registerBinding(definition: BindingDefinition): void;
203
- /**
204
- * Unregister all bindings for an action within a context.
205
- *
206
- * @param actionName
207
- * @param context - Pass null (default) to target context-free bindings
208
- */
209
- unregisterBindings(actionName: string, context?: string | null): void;
210
- /**
211
- * Gets all bindings for a specific action, optionally filtered by device type and/or context.
212
- *
213
- * @param actionName
214
- * @param deviceType - If provided, filters to only bindings for that device type
215
- * @param context - If provided, filters to only bindings in that context
216
- */
217
- getBindingsForAction(actionName: string, deviceType?: DeviceType, context?: string | null): Binding[];
218
- /**
219
- * Exports the current configuration to a serializable object.
220
- * Includes all actions, bindings, contexts, and their active states.
221
- */
222
- exportConfiguration(): BindingConfiguration;
223
- /**
224
- * Imports a configuration, replacing all current actions, bindings, and contexts.
225
- *
226
- * @param config
227
- */
228
- importConfiguration(config: BindingConfiguration): void;
229
- /**
230
- * Tears down the binding manager and cleans up any resources
231
- */
232
- $teardown(): Promise<void>;
233
- }
@@ -1,264 +0,0 @@
1
- import { TransformNode } from '@babylonjs/core';
2
- import { GameEntity, RequestResult } from "../classes/entity.d.ts";
3
- import { GameEventBus } from "../classes/eventBus.d.ts";
4
- import { GameEngine } from "../classes/gameEngine.d.ts";
5
- import { GameEntityDefinition } from "../interfaces/entity.d.ts";
6
- import { Disposable } from "../interfaces/lifecycle.d.ts";
7
- import { BindingManager } from "../managers/binding.d.ts";
8
- import { LoggingUtility } from "../utils/logger.d.ts";
9
- /**
10
- * Options for creating an entity instance.
11
- */
12
- export interface CreateEntityOptions<State extends object = object> {
13
- /** Initial state to merge with defaultState. */
14
- initialState?: Partial<State>;
15
- /** Override name from entity definition. */
16
- name?: string;
17
- /** Additional tags to add (merged with definition tags). */
18
- tags?: string[];
19
- /** Scene node to attach the entity to. */
20
- node?: TransformNode;
21
- /**
22
- * Build the definition's mesh via the current level ('disabled' loads it setEnabled(false)).
23
- * Mutually exclusive with `node`.
24
- */
25
- mesh?: 'enabled' | 'disabled';
26
- }
27
- export declare class GameEntityManager implements Disposable {
28
- /** The event bus for the entity manager. */
29
- private eventBus;
30
- /** A map of entities managed by the entity manager. */
31
- private entities;
32
- /** A map of entity definitions registered with the entity manager. */
33
- private entityDefinitions;
34
- /** Late-bound GameEngine reference */
35
- private _gameEngine;
36
- /** Reference to the binding manager for registering actions */
37
- private bindingManager;
38
- /** Logger instance */
39
- private _log;
40
- /** Index: name -> entity (names are not unique, first match returned by getByName) */
41
- private _entitiesByName;
42
- /** Index: type -> entities */
43
- private _entitiesByType;
44
- /** Index: tag -> entities */
45
- private _entitiesByTag;
46
- /** Index: node -> entity (one entity per node) */
47
- private _entitiesByNode;
48
- /** Object pool storage: type -> pooled entities */
49
- private _pools;
50
- /**
51
- * Creates an instance of EntityManager.
52
- * @param eventBus
53
- * @param logger
54
- * @param bindingManager
55
- */
56
- constructor(eventBus: GameEventBus, logger: LoggingUtility | undefined, bindingManager: BindingManager);
57
- /**
58
- * Late-bind the GameEngine after construction.
59
- * Called by createGameEngine() after the GameEngine instance is created.
60
- */
61
- $setGameEngine(gameEngine: GameEngine): void;
62
- private get _engine();
63
- /**
64
- * Gets or creates a Set in a Map, returning the Set.
65
- */
66
- private _getOrCreateSet;
67
- /**
68
- * Adds an entity to all relevant indices.
69
- */
70
- private _indexEntity;
71
- /**
72
- * Removes an entity from all indices.
73
- */
74
- private _unindexEntity;
75
- /**
76
- * Resolves an entity definition that extends a base definition by merging according to inheritance rules.
77
- * The base definition must already be registered.
78
- */
79
- private _resolveInheritance;
80
- /**
81
- * Checks if two actions are compatible (same type and non-conflicting options).
82
- * @param existingAction - The action already registered
83
- * @param newAction - The action being registered
84
- */
85
- private _areActionsCompatible;
86
- /**
87
- * Registers actions defined in the entity definition with the binding manager.
88
- * Skips actions already registered with compatible options; warns on conflicts.
89
- * @param entityDef
90
- */
91
- private _registerEntityActions;
92
- $frameUpdate(dt: number): void;
93
- /**
94
- * Deep-clone a definition's defaultState for a new instance.
95
- *
96
- * A shallow spread would hand every instance of a type the same nested arrays and objects — mutate one
97
- * entity's inventory slots and you mutate its neighbor's. Definitions must keep defaultState as plain,
98
- * structured-cloneable data.
99
- */
100
- private _cloneDefaultState;
101
- /**
102
- * Honor the `mesh` create option by building the definition's mesh on the current level.
103
- */
104
- private _buildDefinitionMesh;
105
- /**
106
- * Registers a new entity definition.
107
- * Also registers any actions declared in the definition with the binding manager.
108
- * @param entityDef
109
- */
110
- registerEntityDefinition(entityDef: GameEntityDefinition): void;
111
- /**
112
- * Retrieve an entity definition by type.
113
- * @param type
114
- */
115
- getDefinition(type: string): GameEntityDefinition | undefined;
116
- /**
117
- * Creates a new entity of the given type.
118
- * Runs onBeforeCreate/onCreate lifecycle hooks, merges state, applies tags, and indexes the entity.
119
- * @param type - Must match a previously registered entity definition
120
- * @param options
121
- */
122
- createEntity<State extends object = object>(type: string, options?: CreateEntityOptions<State>): Promise<GameEntity<State>>;
123
- /**
124
- * Destroys the entity with the given ID.
125
- * Runs onBeforeDestroy/onDestroy lifecycle hooks, unindexes, and removes the entity.
126
- * @param entityID
127
- */
128
- destroyEntity(entityID: string): Promise<void>;
129
- /**
130
- * Gets the entity with the given ID.
131
- * @param entityID
132
- */
133
- getEntity(entityID: string): GameEntity | null;
134
- /**
135
- * Adds an existing entity to the entity manager and indexes it.
136
- * @param entity
137
- */
138
- addEntity(entity: GameEntity): void;
139
- /**
140
- * Removes the entity with the given ID, without destroying it.
141
- * @param entityID
142
- */
143
- removeEntity(entityID: string): void;
144
- /**
145
- * Adds a child entity to a parent entity.
146
- * @param parentId - ID of the parent entity
147
- * @param childId - ID of the child entity
148
- * @returns False if either entity is not found
149
- */
150
- addChild(parentId: string, childId: string): boolean;
151
- /**
152
- * Removes a child entity from a parent entity.
153
- * @param parentId - ID of the parent entity
154
- * @param childId - ID of the child entity
155
- * @returns False if either entity is not found
156
- */
157
- removeChild(parentId: string, childId: string): boolean;
158
- /**
159
- * Gets the first entity with the given name.
160
- * Names are not unique; use getEntitiesByName() to retrieve all matches.
161
- * @param name
162
- */
163
- getByName(name: string): GameEntity | undefined;
164
- /**
165
- * Gets all entities with the given name.
166
- * @param name
167
- */
168
- getEntitiesByName(name: string): GameEntity[];
169
- /**
170
- * Gets all entities of the given type.
171
- * @param type
172
- */
173
- getByType(type: string): GameEntity[];
174
- /**
175
- * Gets all entities with the given tag.
176
- * @param tag
177
- */
178
- getByTag(tag: string): GameEntity[];
179
- /**
180
- * Gets all entities matching multiple tags.
181
- * @param tags
182
- * @param mode - 'all' requires every tag (intersection), 'any' requires at least one (union)
183
- */
184
- getByTags(tags: string[], mode?: 'all' | 'any'): GameEntity[];
185
- /**
186
- * Returns an iterator over all entities.
187
- * More memory-efficient than returning an array for large entity counts.
188
- */
189
- getAllEntities(): IterableIterator<GameEntity>;
190
- /**
191
- * Gets the total number of entities.
192
- */
193
- get entityCount(): number;
194
- /**
195
- * Sends a fire-and-forget event directly to a specific entity's behaviors, bypassing the event bus.
196
- * Resolves the target by entity ID first (O(1)), then falls back to name lookup (O(1)).
197
- *
198
- * @param target - Entity ID or name
199
- * @param type - Event type string
200
- * @param payload - Optional event payload
201
- */
202
- send(target: string, type: string, payload?: unknown, senderID?: string): Promise<void>;
203
- /**
204
- * Sends a request to a specific entity's behaviors and returns the first response.
205
- * Resolves the target by entity ID first (O(1)), then falls back to name lookup (O(1)).
206
- *
207
- * @param target - Entity ID or name
208
- * @param type - Request type string
209
- * @param payload - Optional request payload
210
- * @param senderID - Optional sender entity ID (stamped on the event)
211
- */
212
- request<T>(target: string, type: string, payload?: unknown, senderID?: string): Promise<RequestResult<T>>;
213
- /**
214
- * Adds a tag to an entity and updates the tag index.
215
- * @param entity - Entity instance or entity ID
216
- * @param tag
217
- * @returns False if already present or entity not found
218
- */
219
- addTag(entity: GameEntity | string, tag: string): boolean;
220
- /**
221
- * Removes a tag from an entity and updates the tag index.
222
- * @param entity - Entity instance or entity ID
223
- * @param tag
224
- * @returns False if not present or entity not found
225
- */
226
- removeTag(entity: GameEntity | string, tag: string): boolean;
227
- /**
228
- * Gets an entity by its attached scene node.
229
- * @param node
230
- */
231
- getByNode(node: TransformNode): GameEntity | undefined;
232
- /**
233
- * Attaches an entity to a scene node.
234
- * The entity will reference this node and can be looked up via getByNode().
235
- *
236
- * @param entity - Entity instance or entity ID
237
- * @param node
238
- * @returns False if entity not found or node already has an entity
239
- */
240
- attachToNode(entity: GameEntity | string, node: TransformNode): boolean;
241
- /**
242
- * Detaches an entity from its scene node.
243
- *
244
- * @param entity - Entity instance or entity ID
245
- * @returns False if entity not found or had no node
246
- */
247
- detachFromNode(entity: GameEntity | string): boolean;
248
- /**
249
- * Pre-creates entities and pools them for fast recycling.
250
- * @param type - Entity type to prewarm
251
- * @param count - Number of entities to create and pool
252
- */
253
- prewarm(type: string, count: number): Promise<void>;
254
- /**
255
- * Drains the pool for a given type, actually destroying all pooled entities.
256
- * @param type - Entity type whose pool to drain
257
- */
258
- drainPool(type: string): Promise<void>;
259
- /**
260
- * Tears down all entities and releases resources.
261
- * Destroys entities individually (running lifecycle hooks), then clears definitions and indices.
262
- */
263
- $teardown(): Promise<void>;
264
- }
@@ -1,75 +0,0 @@
1
- import { Disposable } from "../interfaces/lifecycle.d.ts";
2
- import { GameEntityManager } from "./entity.d.ts";
3
- import { LevelManager } from "./level.d.ts";
4
- import { LoggingUtility } from "../utils/logger.d.ts";
5
- export interface SaveData {
6
- version: number;
7
- levelName: string;
8
- entities: SerializedEntity[];
9
- custom: Record<string, unknown>;
10
- }
11
- export interface SerializedEntity {
12
- id: string;
13
- type: string;
14
- name?: string;
15
- tags: string[];
16
- state: object;
17
- parentId?: string;
18
- transform?: {
19
- position: {
20
- x: number;
21
- y: number;
22
- z: number;
23
- };
24
- rotation: {
25
- x: number;
26
- y: number;
27
- z: number;
28
- };
29
- scaling: {
30
- x: number;
31
- y: number;
32
- z: number;
33
- };
34
- };
35
- }
36
- type BeforeSerializeHook = () => Record<string, unknown>;
37
- type AfterDeserializeHook = (custom: Record<string, unknown>) => void;
38
- export declare class SaveManager implements Disposable {
39
- private _entityManager;
40
- private _levelManager;
41
- private _log;
42
- private _beforeSerializeHooks;
43
- private _afterDeserializeHooks;
44
- constructor(entityManager: GameEntityManager, levelManager: LevelManager, logger?: LoggingUtility);
45
- /**
46
- * Register a hook that returns custom data to include in save data.
47
- * Multiple hooks can be registered; their results are merged into the `custom` field.
48
- */
49
- onBeforeSerialize(hook: BeforeSerializeHook): void;
50
- /**
51
- * Register a hook to process custom data when loading a save.
52
- * Multiple hooks can be registered; each receives the full custom data object.
53
- */
54
- onAfterDeserialize(hook: AfterDeserializeHook): void;
55
- /**
56
- * Captures the current game state as a serializable SaveData object.
57
- * Iterates all entities, captures transforms, state, tags, and parent references.
58
- * Calls all beforeSerialize hooks to gather custom data.
59
- */
60
- serialize(): SaveData;
61
- /**
62
- * Restores game state from a SaveData object.
63
- *
64
- * Flow:
65
- * 1. Transition to the saved level
66
- * 2. Destroy all existing entities (level-spawned ones)
67
- * 3. Recreate entities from save data
68
- * 4. Restore transforms on entities with nodes
69
- * 5. Re-establish parent-child hierarchy
70
- * 6. Call afterDeserialize hooks
71
- */
72
- deserialize(data: SaveData): Promise<void>;
73
- $teardown(): Promise<void>;
74
- }
75
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"postProcessingFrameGraph-CaMgQzR-.js","names":[],"sources":["../src/handlers/postProcessingFrameGraph.ts"],"sourcesContent":["//----------------------------------------------------------------------------------------------------------------------\n// Frame Graph Post-Processing Backend\n//\n// Builds a directed task chain using BabylonJS Frame Graph system.\n// Each post-processing effect is a separate task chained via texture handles.\n//----------------------------------------------------------------------------------------------------------------------\n\nimport {\n Constants,\n FrameGraph,\n FrameGraphBloomTask,\n FrameGraphChromaticAberrationTask,\n FrameGraphClearTextureTask,\n FrameGraphCopyToBackbufferColorTask,\n FrameGraphGeometryRendererTask,\n FrameGraphGrainTask,\n FrameGraphImageProcessingTask,\n FrameGraphObjectRendererTask,\n FrameGraphSSAO2RenderingPipelineTask,\n FrameGraphSharpenTask,\n type FrameGraphTextureHandle,\n ImageProcessingConfiguration,\n type Scene,\n} from '@babylonjs/core';\n\nimport type { PostProcessingConfig } from '../interfaces/level.ts';\n\n//----------------------------------------------------------------------------------------------------------------------\n\n/**\n * Map from user-facing tonemap operator names to BabylonJS constants.\n * BabylonJS only has STANDARD (0) and ACES (1) — the other names all map to STANDARD.\n */\nconst TONEMAP_OPERATORS : Record<string, number> = {\n hable: ImageProcessingConfiguration.TONEMAPPING_STANDARD,\n reinhard: ImageProcessingConfiguration.TONEMAPPING_STANDARD,\n hejidawson: ImageProcessingConfiguration.TONEMAPPING_STANDARD,\n photographic: ImageProcessingConfiguration.TONEMAPPING_STANDARD,\n aces: ImageProcessingConfiguration.TONEMAPPING_ACES,\n};\n\n//----------------------------------------------------------------------------------------------------------------------\n\nexport async function applyFrameGraphPostProcessing(scene : Scene, config : PostProcessingConfig) : Promise<void>\n{\n const camera = scene.activeCamera;\n if(!camera)\n {\n return;\n }\n\n const engine = scene.getEngine();\n const fg = new FrameGraph(scene);\n\n // Create the main render target texture\n const colorTexture = fg.textureManager.createRenderTargetTexture('sage-fg-color', {\n size: { width: 100, height: 100 },\n sizeIsPercentage: true,\n options: { formats: [ Constants.TEXTUREFORMAT_RGBA ], samples: 4 },\n });\n\n // 1. Clear\n const clearTask = new FrameGraphClearTextureTask('sage-clear', fg);\n clearTask.targetTexture = colorTexture;\n fg.addTask(clearTask);\n\n // 2. Render objects\n const renderTask = new FrameGraphObjectRendererTask('sage-render', fg, scene);\n renderTask.targetTexture = clearTask.outputTexture;\n renderTask.depthTexture = clearTask.outputDepthTexture;\n renderTask.camera = camera;\n renderTask.objectList = { meshes: scene.meshes, particleSystems: scene.particleSystems };\n renderTask.isMainObjectRenderer = true;\n fg.addTask(renderTask);\n\n // Track the current output texture through the chain\n let currentTexture : FrameGraphTextureHandle = renderTask.outputTexture;\n\n // 3. SSAO (needs geometry renderer for depth/normals)\n if(config.ssao)\n {\n const geoTask = new FrameGraphGeometryRendererTask('sage-geometry', fg, scene);\n fg.addTask(geoTask);\n\n const ssaoTask = new FrameGraphSSAO2RenderingPipelineTask('sage-ssao', fg, 0.5, 1.0);\n ssaoTask.sourceTexture = currentTexture;\n ssaoTask.depthTexture = geoTask.geometryViewDepthTexture;\n ssaoTask.normalTexture = geoTask.geometryViewNormalTexture;\n ssaoTask.camera = camera;\n fg.addTask(ssaoTask);\n\n if(config.ssao.radius !== undefined) { ssaoTask.ssao.radius = config.ssao.radius; }\n if(config.ssao.samples !== undefined) { ssaoTask.ssao.samples = config.ssao.samples; }\n if(config.ssao.totalStrength !== undefined) { ssaoTask.ssao.totalStrength = config.ssao.totalStrength; }\n\n currentTexture = ssaoTask.outputTexture;\n }\n\n // 4. Bloom\n if(config.bloom)\n {\n const bloomTask = new FrameGraphBloomTask(\n 'sage-bloom',\n fg,\n config.bloom.weight ?? 0.5,\n config.bloom.kernel ?? 128,\n config.bloom.threshold ?? 0.1,\n true,\n config.bloom.scale ?? 0.5\n );\n bloomTask.sourceTexture = currentTexture;\n fg.addTask(bloomTask);\n\n currentTexture = bloomTask.outputTexture;\n }\n\n // 5. Grain\n if(config.grain)\n {\n const grainTask = new FrameGraphGrainTask('sage-grain', fg);\n grainTask.sourceTexture = currentTexture;\n fg.addTask(grainTask);\n\n if(config.grain.intensity !== undefined) { grainTask.postProcess.intensity = config.grain.intensity; }\n if(config.grain.animated !== undefined) { grainTask.postProcess.animated = config.grain.animated; }\n\n currentTexture = grainTask.outputTexture;\n }\n\n // 6. Sharpen\n if(config.sharpen)\n {\n const sharpenTask = new FrameGraphSharpenTask('sage-sharpen', fg);\n sharpenTask.sourceTexture = currentTexture;\n fg.addTask(sharpenTask);\n\n if(config.sharpen.edge !== undefined) { sharpenTask.postProcess.edgeAmount = config.sharpen.edge; }\n if(config.sharpen.color !== undefined) { sharpenTask.postProcess.colorAmount = config.sharpen.color; }\n\n currentTexture = sharpenTask.outputTexture;\n }\n\n // 7. Chromatic aberration\n if(config.chromaticAberration)\n {\n const chromTask = new FrameGraphChromaticAberrationTask('sage-chromab', fg);\n chromTask.sourceTexture = currentTexture;\n fg.addTask(chromTask);\n\n if(config.chromaticAberration.amount !== undefined)\n {\n chromTask.postProcess.aberrationAmount = config.chromaticAberration.amount;\n }\n\n currentTexture = chromTask.outputTexture;\n }\n\n // 8. Image processing (tonemap + vignette)\n if(config.tonemap || config.vignette)\n {\n const imgTask = new FrameGraphImageProcessingTask('sage-imgproc', fg);\n imgTask.sourceTexture = currentTexture;\n fg.addTask(imgTask);\n\n if(config.tonemap)\n {\n imgTask.postProcess.toneMappingEnabled = true;\n\n if(config.tonemap.operator)\n {\n imgTask.postProcess.toneMappingType\n = TONEMAP_OPERATORS[config.tonemap.operator]\n ?? ImageProcessingConfiguration.TONEMAPPING_STANDARD;\n }\n }\n\n if(config.vignette)\n {\n imgTask.postProcess.vignetteEnabled = true;\n\n if(config.vignette.weight !== undefined) { imgTask.postProcess.vignetteWeight = config.vignette.weight; }\n if(config.vignette.stretch !== undefined)\n {\n imgTask.postProcess.vignetteStretch = config.vignette.stretch;\n }\n if(config.vignette.color)\n {\n const vc = config.vignette.color;\n imgTask.postProcess.vignetteColor.set(vc.r, vc.g, vc.b, 1);\n }\n }\n\n currentTexture = imgTask.outputTexture;\n }\n\n // 9. Volumetric lighting — not yet wired up for automatic light detection\n if(config.volumetric)\n {\n console.warn(\n '[SAGE] Volumetric lighting config is recognized but automatic light detection is not yet supported. '\n + 'Use scene.frameGraph to add FrameGraphVolumetricLightingTask manually.'\n );\n }\n\n // 10. Output to screen\n const copyTask = new FrameGraphCopyToBackbufferColorTask('sage-output', fg);\n copyTask.sourceTexture = currentTexture;\n fg.addTask(copyTask);\n\n // Wire up the scene — cameraToUseForPointers is needed because activeCamera becomes null between tasks\n scene.cameraToUseForPointers = camera;\n scene.frameGraph = fg;\n\n // Rebuild on resize\n engine.onResizeObservable.add(async () =>\n {\n await fg.buildAsync();\n });\n\n // Initial build\n await fg.buildAsync();\n}\n\n//----------------------------------------------------------------------------------------------------------------------\n"],"mappings":";;AAiCA,IAAM,IAA6C;CAC/C,OAAO,EAA6B;CACpC,UAAU,EAA6B;CACvC,YAAY,EAA6B;CACzC,cAAc,EAA6B;CAC3C,MAAM,EAA6B;CACtC;AAID,eAAsB,EAA8B,GAAe,GACnE;CACI,IAAM,IAAS,EAAM;AACrB,KAAG,CAAC,EAEA;CAGJ,IAAM,IAAS,EAAM,WAAW,EAC1B,IAAK,IAAI,EAAW,EAAM,EAG1B,IAAe,EAAG,eAAe,0BAA0B,iBAAiB;EAC9E,MAAM;GAAE,OAAO;GAAK,QAAQ;GAAK;EACjC,kBAAkB;EAClB,SAAS;G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I,EAAG,GAAG,EAAG,GAAG,EAAG,GAAG,EAAE;;AAIlE,MAAiB,EAAQ;;AAI7B,CAAG,EAAO,cAEN,QAAQ,KACJ,6KAEH;CAIL,IAAM,IAAW,IAAI,EAAoC,eAAe,EAAG;AAe3E,CAdA,EAAS,gBAAgB,GACzB,EAAG,QAAQ,EAAS,EAGpB,EAAM,yBAAyB,GAC/B,EAAM,aAAa,GAGnB,EAAO,mBAAmB,IAAI,YAC9B;AACI,QAAM,EAAG,YAAY;GACvB,EAGF,MAAM,EAAG,YAAY"}
@@ -1,2 +0,0 @@
1
- import { GameEntityManager } from "../managers/entity.d.ts";
2
- export declare function createEntityProxy(entityManager: GameEntityManager): GameEntityManager & Record<string, unknown>;
@@ -1,26 +0,0 @@
1
- import { AbstractMesh, Camera, PickingInfo, Ray, Scene, Vector3 } from '@babylonjs/core';
2
- import { GameEntity } from "../classes/entity.d.ts";
3
- import { GameEntityManager } from "../managers/entity.d.ts";
4
- export interface EntityPickResult {
5
- entity: GameEntity;
6
- point: Vector3;
7
- distance: number;
8
- normal: Vector3;
9
- mesh: AbstractMesh;
10
- pickingInfo: PickingInfo;
11
- }
12
- export interface EntityPickFilter {
13
- type?: string;
14
- tags?: string[];
15
- predicate?: (entity: GameEntity) => boolean;
16
- }
17
- export declare class RaycastHelper {
18
- private _entityManager;
19
- constructor(entityManager: GameEntityManager);
20
- pickEntity(scene: Scene, x: number, y: number, filter?: EntityPickFilter): EntityPickResult | null;
21
- pickEntities(scene: Scene, x: number, y: number, filter?: EntityPickFilter): EntityPickResult[];
22
- pickEntityWithRay(scene: Scene, ray: Ray, filter?: EntityPickFilter): EntityPickResult | null;
23
- pickEntitiesWithRay(scene: Scene, ray: Ray, filter?: EntityPickFilter): EntityPickResult[];
24
- pickEntityForward(scene: Scene, camera: Camera, maxDistance?: number, filter?: EntityPickFilter): EntityPickResult | null;
25
- private _toEntityResult;
26
- }