dopaminejs 2.5.0 → 3.0.0

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 (81) hide show
  1. package/README.md +40 -50
  2. package/dist/DataService-E4pGQ1V3.cjs +1 -0
  3. package/dist/DataService-MfmvkqXR.js +737 -0
  4. package/dist/core.cjs +1 -1
  5. package/dist/core.js +2 -2
  6. package/dist/dopamine.cjs +1 -37
  7. package/dist/dopamine.js +3 -635
  8. package/dist/games.cjs +1 -0
  9. package/dist/games.js +82 -0
  10. package/dist/host-CkRL74ck.js +814 -0
  11. package/dist/host-Pzb-QBPU.cjs +37 -0
  12. package/dist/style.css +395 -2
  13. package/dist/testing.cjs +1 -0
  14. package/dist/testing.js +474 -0
  15. package/package.json +24 -9
  16. package/spec/README.md +227 -0
  17. package/spec/VERSION +1 -0
  18. package/spec/fixtures/achievements.json +611 -0
  19. package/spec/fixtures/levels.json +421 -0
  20. package/spec/fixtures/merge.json +1739 -0
  21. package/spec/fixtures/migrate.json +916 -0
  22. package/spec/fixtures/scores.json +755 -0
  23. package/spec/fixtures/streaks.json +924 -0
  24. package/spec/schema.json +61 -0
  25. package/src/dopamine/audio/SoundManager.js +54 -24
  26. package/src/dopamine/core/DopamineError.js +7 -0
  27. package/src/dopamine/core/RewardSystem.js +323 -373
  28. package/src/dopamine/core/achievements.js +49 -0
  29. package/src/dopamine/core/clock.js +11 -0
  30. package/src/dopamine/core/levels.js +4 -0
  31. package/src/dopamine/core/merge.js +68 -0
  32. package/src/dopamine/core/middleware.js +58 -0
  33. package/src/dopamine/core/store.js +261 -0
  34. package/src/dopamine/core/streaks.js +55 -0
  35. package/src/dopamine/effects/ParticleSystem.js +30 -0
  36. package/src/dopamine/host.js +358 -0
  37. package/src/dopamine/ui/{GameUI.js → RewardUI.js} +166 -202
  38. package/src/games.js +138 -0
  39. package/src/index.js +11 -34
  40. package/src/progression.js +3 -0
  41. package/src/testing.js +489 -0
  42. package/types/core.d.ts +9 -1
  43. package/types/games.d.ts +46 -0
  44. package/types/index.d.ts +291 -384
  45. package/types/testing.d.ts +96 -0
  46. package/dist/DataService-BPXCldpo.cjs +0 -1
  47. package/dist/DataService-CH9_gv_8.js +0 -398
  48. package/dist/ScreenShake-9jgNXPS6.cjs +0 -1
  49. package/dist/ScreenShake-CLvO1wx4.js +0 -827
  50. package/dist/engine.cjs +0 -1
  51. package/dist/engine.js +0 -2
  52. package/src/core/Animator.js +0 -62
  53. package/src/core/Collider.js +0 -86
  54. package/src/core/Component.js +0 -38
  55. package/src/core/DopamineKernel.js +0 -170
  56. package/src/core/EventBus.js +0 -206
  57. package/src/core/Game.js +0 -90
  58. package/src/core/GameObject.js +0 -99
  59. package/src/core/PluginRegistry.js +0 -359
  60. package/src/core/Scene.js +0 -107
  61. package/src/core/Sprite.js +0 -51
  62. package/src/core/SystemRegistry.js +0 -263
  63. package/src/core/Vector2.js +0 -50
  64. package/src/dopamine/components/ParticleEmitter.js +0 -50
  65. package/src/dopamine/components/ScreenShake.js +0 -50
  66. package/src/dopamine/components/index.js +0 -2
  67. package/src/dopamine/index.js +0 -93
  68. package/src/dopamine/utils/TextureGenerator.js +0 -90
  69. package/src/engine.js +0 -38
  70. package/src/interfaces/IAudioSystem.js +0 -58
  71. package/src/interfaces/IParticleSystem.js +0 -51
  72. package/src/interfaces/IPhysicsSystem.js +0 -52
  73. package/src/interfaces/ISystem.js +0 -48
  74. package/src/interfaces/index.js +0 -7
  75. package/src/renderer/Renderer.js +0 -45
  76. package/src/systems/Director.js +0 -34
  77. package/src/systems/Input.js +0 -81
  78. package/src/systems/Loader.js +0 -48
  79. package/src/systems/Physics.js +0 -210
  80. package/src/systems/Ticker.js +0 -91
  81. package/src/systems/deprecate.js +0 -38
@@ -1,51 +0,0 @@
1
- import { ISystem } from './ISystem.js';
2
-
3
- /**
4
- * IParticleSystem - Interface for particle system implementations
5
- *
6
- * Allows different renderers (Canvas, WebGL, custom) to be swapped
7
- */
8
- export const IParticleSystem = {
9
- ...ISystem,
10
-
11
- /**
12
- * Register a sprite for particles
13
- * @param {string} key - Sprite identifier
14
- * @param {string} url - Path to image
15
- */
16
- registerSprite(key, url) { },
17
-
18
- /**
19
- * Register a custom effect
20
- * @param {string} name - Effect name
21
- * @param {Function} callback - Effect function (x, y, ...args) => void
22
- */
23
- registerEffect(name, callback) { },
24
-
25
- /**
26
- * Play a registered effect
27
- * @param {string} name - Effect name
28
- * @param {number} x - X position
29
- * @param {number} y - Y position
30
- * @param {...any} args - Additional arguments
31
- */
32
- play(name, x, y, ...args) { },
33
-
34
- /**
35
- * Emit particles with custom configuration
36
- * @param {Object} config - Particle configuration
37
- */
38
- emit(config) { },
39
-
40
- /**
41
- * Clear all particles
42
- */
43
- clear() { },
44
-
45
- // Built-in effects (optional, but recommended)
46
- confetti(x, y, count) { },
47
- coinShower(x, y, count) { },
48
- sparkle(x, y, count, color) { },
49
- fire(x, y, count) { },
50
- starBurst(x, y, count) { },
51
- };
@@ -1,52 +0,0 @@
1
- import { ISystem } from './ISystem.js';
2
-
3
- /**
4
- * IPhysicsSystem - Interface for physics implementations
5
- *
6
- * Allows different physics engines (custom, Matter.js, Box2D) to be swapped
7
- */
8
- export const IPhysicsSystem = {
9
- ...ISystem,
10
-
11
- /**
12
- * Add a physics body to the simulation
13
- * @param {Object} body - Physics body (implementation-specific)
14
- */
15
- addBody(body) { },
16
-
17
- /**
18
- * Remove a physics body from the simulation
19
- * @param {Object} body - Physics body to remove
20
- */
21
- removeBody(body) { },
22
-
23
- /**
24
- * Check collision between two bodies
25
- * @param {Object} a - First body
26
- * @param {Object} b - Second body
27
- * @returns {boolean} - True if colliding
28
- */
29
- checkCollision(a, b) { },
30
-
31
- /**
32
- * Perform a raycast
33
- * @param {Object} origin - Ray origin {x, y}
34
- * @param {Object} direction - Ray direction {x, y}
35
- * @param {number} distance - Maximum ray distance
36
- * @returns {Object|null} - Hit result or null
37
- */
38
- raycast(origin, direction, distance) { },
39
-
40
- /**
41
- * Set gravity for the physics world
42
- * @param {number} x - Gravity X component
43
- * @param {number} y - Gravity Y component
44
- */
45
- setGravity(x, y) { },
46
-
47
- /**
48
- * Step the physics simulation
49
- * @param {number} dt - Delta time
50
- */
51
- step(dt) { },
52
- };
@@ -1,48 +0,0 @@
1
- /**
2
- * ISystem - Base interface for all systems
3
- *
4
- * All systems should implement this interface.
5
- * Methods are optional - only implement what you need.
6
- */
7
- export const ISystem = {
8
- /**
9
- * Called when system is registered to the kernel
10
- * @param {DopamineKernel} kernel - The kernel instance
11
- */
12
- init(kernel) { },
13
-
14
- /**
15
- * Called each frame (variable timestep)
16
- * @param {number} dt - Delta time in seconds
17
- */
18
- update(dt) { },
19
-
20
- /**
21
- * Called at fixed timestep (for physics)
22
- * @param {number} dt - Fixed delta time
23
- */
24
- fixedUpdate(dt) { },
25
-
26
- /**
27
- * Called when system is unregistered
28
- */
29
- destroy() { },
30
- };
31
-
32
- /**
33
- * Base System class that implements ISystem
34
- * Systems can extend this for convenience
35
- */
36
- export class System {
37
- constructor() {
38
- this.kernel = null;
39
- }
40
-
41
- init(kernel) {
42
- this.kernel = kernel;
43
- }
44
-
45
- update(dt) { }
46
- fixedUpdate(dt) { }
47
- destroy() { }
48
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Export all system interfaces
3
- */
4
- export { ISystem, System } from './ISystem.js';
5
- export { IPhysicsSystem } from './IPhysicsSystem.js';
6
- export { IAudioSystem } from './IAudioSystem.js';
7
- export { IParticleSystem } from './IParticleSystem.js';
@@ -1,45 +0,0 @@
1
- /**
2
- * Handles the Canvas and Context for rendering.
3
- */
4
- export class Renderer {
5
- constructor(options = {}) {
6
- this.width = options.width || 800;
7
- this.height = options.height || 600;
8
- this.backgroundColor = options.backgroundColor || '#000000';
9
-
10
- // Use existing canvas if provided, otherwise create new one
11
- if (options.canvas) {
12
- this.canvas = options.canvas;
13
- this.canvas.width = this.width;
14
- this.canvas.height = this.height;
15
- } else {
16
- this.canvas = document.createElement('canvas');
17
- this.canvas.width = this.width;
18
- this.canvas.height = this.height;
19
-
20
- // Append to body or specified container
21
- const parent = options.parent ?
22
- (typeof options.parent === 'string' ? document.querySelector(options.parent) : options.parent)
23
- : document.body;
24
-
25
- parent.appendChild(this.canvas);
26
- }
27
-
28
- this.ctx = this.canvas.getContext('2d');
29
- }
30
-
31
- /**
32
- * Clear the canvas.
33
- */
34
- clear() {
35
- this.ctx.fillStyle = this.backgroundColor;
36
- this.ctx.fillRect(0, 0, this.width, this.height);
37
- }
38
-
39
- resize(width, height) {
40
- this.width = width;
41
- this.height = height;
42
- this.canvas.width = width;
43
- this.canvas.height = height;
44
- }
45
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Manages Scene transitions and state.
3
- */
4
- export class Director {
5
- constructor(game) {
6
- this.game = game;
7
- this.currentScene = null;
8
- }
9
-
10
- /**
11
- * Switch to a new scene.
12
- * @param {Scene} scene
13
- */
14
- run(scene) {
15
- if (this.currentScene) {
16
- this.currentScene.onExit();
17
-
18
- // Its colliders would keep colliding with the next scene.
19
- this.currentScene.kernel = null;
20
- }
21
-
22
- this.currentScene = scene;
23
- this.currentScene.game = this.game;
24
-
25
- if (this.game?.kernel) {
26
- scene.kernel = this.game.kernel;
27
- }
28
-
29
- // Let the game know (if game engine needs to reference it directly)
30
- this.game.scene = scene;
31
-
32
- scene.onEnter();
33
- }
34
- }
@@ -1,81 +0,0 @@
1
- import { deprecatedGlobal } from './deprecate.js';
2
-
3
- /**
4
- * Input System
5
- * Tracks keyboard and mouse input.
6
- */
7
- export class Input {
8
- constructor() {
9
- this.keys = new Map();
10
- this.mouse = { x: 0, y: 0, buttons: new Map() };
11
- this.kernel = null;
12
-
13
- // Bind event listeners
14
- this._onKeyDown = this._onKeyDown.bind(this);
15
- this._onKeyUp = this._onKeyUp.bind(this);
16
- this._onMouseMove = this._onMouseMove.bind(this);
17
- this._onMouseDown = this._onMouseDown.bind(this);
18
- this._onMouseUp = this._onMouseUp.bind(this);
19
- }
20
-
21
- /**
22
- * ISystem interface - called when registered
23
- */
24
- init(kernel) {
25
- this.kernel = kernel;
26
-
27
- // Attach event listeners
28
- window.addEventListener('keydown', this._onKeyDown);
29
- window.addEventListener('keyup', this._onKeyUp);
30
- window.addEventListener('mousemove', this._onMouseMove);
31
- window.addEventListener('mousedown', this._onMouseDown);
32
- window.addEventListener('mouseup', this._onMouseUp);
33
- }
34
-
35
- /**
36
- * ISystem interface - cleanup
37
- */
38
- destroy() {
39
- window.removeEventListener('keydown', this._onKeyDown);
40
- window.removeEventListener('keyup', this._onKeyUp);
41
- window.removeEventListener('mousemove', this._onMouseMove);
42
- window.removeEventListener('mousedown', this._onMouseDown);
43
- window.removeEventListener('mouseup', this._onMouseUp);
44
- }
45
-
46
- _onKeyDown(e) {
47
- this.keys.set(e.key, true);
48
- }
49
-
50
- _onKeyUp(e) {
51
- this.keys.set(e.key, false);
52
- }
53
-
54
- _onMouseMove(e) {
55
- this.mouse.x = e.clientX;
56
- this.mouse.y = e.clientY;
57
- }
58
-
59
- _onMouseDown(e) {
60
- this.mouse.buttons.set(e.button, true);
61
- }
62
-
63
- _onMouseUp(e) {
64
- this.mouse.buttons.set(e.button, false);
65
- }
66
-
67
- isKeyDown(key) {
68
- return this.keys.get(key) || false;
69
- }
70
-
71
- isMouseButtonDown(button = 0) {
72
- return this.mouse.buttons.get(button) || false;
73
- }
74
- }
75
-
76
- // DEPRECATED: kept for v1 compatibility. Warns on first use, not on import.
77
- // Note: listeners are not attached unless init() is called.
78
- export const GlobalInput = deprecatedGlobal(
79
- new Input(),
80
- '[DopamineJS] GlobalInput is deprecated. Use kernel.input instead.'
81
- );
@@ -1,48 +0,0 @@
1
- import { deprecatedGlobal } from './deprecate.js';
2
-
3
- /**
4
- * Asset Loader
5
- * Loads and caches images, audio, etc.
6
- */
7
- export class Loader {
8
- constructor() {
9
- this.assets = new Map();
10
- this.kernel = null;
11
- }
12
-
13
- /**
14
- * ISystem interface - called when registered
15
- */
16
- init(kernel) {
17
- this.kernel = kernel;
18
- }
19
-
20
- /**
21
- * ISystem interface - cleanup
22
- */
23
- destroy() {
24
- this.assets.clear();
25
- }
26
-
27
- async loadImage(key, url) {
28
- return new Promise((resolve, reject) => {
29
- const img = new Image();
30
- img.onload = () => {
31
- this.assets.set(key, img);
32
- resolve(img);
33
- };
34
- img.onerror = reject;
35
- img.src = url;
36
- });
37
- }
38
-
39
- get(key) {
40
- return this.assets.get(key);
41
- }
42
- }
43
-
44
- // DEPRECATED: kept for v1 compatibility. Warns on first use, not on import.
45
- export const GlobalLoader = deprecatedGlobal(
46
- new Loader(),
47
- '[DopamineJS] GlobalLoader is deprecated. Use kernel.loader instead.'
48
- );
@@ -1,210 +0,0 @@
1
- import { deprecatedGlobal } from './deprecate.js';
2
-
3
- import { Collider } from '../core/Collider.js';
4
- import { EventBus } from '../core/EventBus.js';
5
-
6
- export class Physics {
7
- constructor() {
8
- this.colliders = [];
9
- this.kernel = null;
10
-
11
- // Map<Collider, Map<Collider, step>>: the pairs that overlapped as of
12
- // the last step, each with the step that last saw it. Without it
13
- // there is no telling a new overlap from one that is still going.
14
- this._pairs = new Map();
15
- this._step = 0;
16
- }
17
-
18
- /**
19
- * ISystem interface - called when registered
20
- */
21
- init(kernel) {
22
- this.kernel = kernel;
23
- }
24
-
25
- /**
26
- * ISystem interface - called at fixed timestep
27
- */
28
- fixedUpdate(dt) {
29
- this.step();
30
- }
31
-
32
- /**
33
- * ISystem interface - cleanup
34
- */
35
- destroy() {
36
- this.colliders = [];
37
- this._pairs.clear();
38
- }
39
-
40
- add(collider) {
41
- this.colliders.push(collider);
42
- }
43
-
44
- remove(collider) {
45
- const idx = this.colliders.indexOf(collider);
46
- if (idx > -1) this.colliders.splice(idx, 1);
47
-
48
- // A removed collider overlaps nothing, so its pairs end here. Left
49
- // in the map they would also keep the collider alive.
50
- const others = this._pairs.get(collider);
51
- if (others) {
52
- this._pairs.delete(collider);
53
-
54
- // Emptied before emitting: step() may be part way through this
55
- // map when an exit listener removes the collider, and would end
56
- // the same pairs again.
57
- const ended = [...others.keys()];
58
- others.clear();
59
- for (const other of ended) {
60
- this._emit(EventBus.Events.COLLISION_EXIT, collider, other);
61
- }
62
- }
63
- for (const [first, seconds] of this._pairs) {
64
- if (seconds.delete(collider)) {
65
- this._emit(EventBus.Events.COLLISION_EXIT, first, collider);
66
- }
67
- }
68
- }
69
-
70
- /**
71
- * Main Physics Step.
72
- * Checks all pairs and triggers callbacks.
73
- *
74
- * Emits `collision_enter` on the kernel event bus when a pair starts to
75
- * overlap and `collision_exit` when it stops, each with `{ a, b }` (the
76
- * two colliders). `onCollisionEnter` on a component is older and runs on
77
- * every step while the pair overlaps.
78
- */
79
- step() {
80
- const step = ++this._step;
81
-
82
- // Naive O(N^2)
83
- for (let i = 0; i < this.colliders.length; i++) {
84
- for (let j = i + 1; j < this.colliders.length; j++) {
85
- const a = this.colliders[i];
86
- const b = this.colliders[j];
87
-
88
- if (this._intersects(a, a.getBounds(), b, b.getBounds())) {
89
- this._seen(a, b, step);
90
-
91
- // Notify GameObjects
92
- this._notifyCollision(a.gameObject, b.gameObject);
93
- this._notifyCollision(b.gameObject, a.gameObject);
94
- }
95
- }
96
- }
97
-
98
- for (const [a, others] of this._pairs) {
99
- for (const [b, seen] of others) {
100
- if (seen === step) continue;
101
-
102
- // A collider removed during the loop above shifts the list,
103
- // and the loop then passes over some pairs. Not being seen
104
- // is not enough to end one.
105
- if (this._intersects(a, a.getBounds(), b, b.getBounds())) {
106
- others.set(b, step);
107
- continue;
108
- }
109
-
110
- others.delete(b);
111
- this._emit(EventBus.Events.COLLISION_EXIT, a, b);
112
- }
113
- if (others.size === 0) this._pairs.delete(a);
114
- }
115
- }
116
-
117
- /**
118
- * Record that a pair overlaps on this step. Emits `collision_enter` when
119
- * it did not overlap on the step before.
120
- * @private
121
- */
122
- _seen(a, b, step) {
123
- // A pair is stored under the collider that was first in the list
124
- // when it began. `colliders` is public and can be reordered, so look
125
- // under the other one too.
126
- if (this._pairs.get(b)?.has(a)) {
127
- this._pairs.get(b).set(a, step);
128
- return;
129
- }
130
-
131
- let others = this._pairs.get(a);
132
- if (!others) {
133
- others = new Map();
134
- this._pairs.set(a, others);
135
- }
136
-
137
- const known = others.has(b);
138
- others.set(b, step);
139
- if (!known) this._emit(EventBus.Events.COLLISION_ENTER, a, b);
140
- }
141
-
142
- /**
143
- * @private
144
- */
145
- _emit(event, a, b) {
146
- // GlobalPhysics and a Physics built by hand have no kernel.
147
- this.kernel?.events?.emit(event, { a, b });
148
- }
149
-
150
- _notifyCollision(go, other) {
151
- if (!go || !go.components) return;
152
- go.components.forEach(c => {
153
- if (c.onCollisionEnter) c.onCollisionEnter(other);
154
- });
155
- }
156
-
157
- /**
158
- * Check if a specific collider overlaps with anything in the target group (tag).
159
- * @param {Collider} source
160
- * @param {string} targetTag
161
- */
162
- checkOverlap(source, targetTag) {
163
- // ... (Keep existing manual check for flexibility)
164
- const hits = [];
165
- const sourceBounds = source.getBounds();
166
-
167
- for (const target of this.colliders) {
168
- if (target === source) continue;
169
- if (targetTag && target.tag !== targetTag) continue;
170
-
171
- const targetBounds = target.getBounds();
172
-
173
- if (this._intersects(source, sourceBounds, target, targetBounds)) {
174
- hits.push(target);
175
- }
176
- }
177
- return hits;
178
- }
179
-
180
- _intersects(a, bA, b, bB) {
181
- // Box vs Box
182
- if (a.type === 'box' && b.type === 'box') {
183
- return (bA.left < bB.right && bA.right > bB.left &&
184
- bA.top < bB.bottom && bA.bottom > bB.top);
185
- }
186
- // Circle vs Circle
187
- if (a.type === 'circle' && b.type === 'circle') {
188
- const dx = bA.x - bB.x;
189
- const dy = bA.y - bB.y;
190
- const dist = Math.sqrt(dx * dx + dy * dy);
191
- return dist < (bA.radius + bB.radius);
192
- }
193
-
194
- // TODO: Box vs Circle
195
- return false;
196
- }
197
-
198
- // IPhysicsSystem interface methods (for plugin compatibility)
199
- addBody(body) { this.add(body); }
200
- removeBody(body) { this.remove(body); }
201
- checkCollision(a, b) { return this._intersects(a, a.getBounds(), b, b.getBounds()); }
202
- raycast(origin, direction, distance) { /* TODO */ return null; }
203
- setGravity(x, y) { /* TODO: Add gravity support */ }
204
- }
205
-
206
- // DEPRECATED: kept for v1 compatibility. Warns on first use, not on import.
207
- export const GlobalPhysics = deprecatedGlobal(
208
- new Physics(),
209
- '[DopamineJS] GlobalPhysics is deprecated. Use kernel.physics instead.'
210
- );
@@ -1,91 +0,0 @@
1
- /**
2
- * The Ticker class manages the game loop.
3
- * It uses requestAnimationFrame to provide a smooth loop.
4
- */
5
- export class Ticker {
6
- constructor() {
7
- this.running = false;
8
- this.lastTime = 0;
9
- this.callbacks = new Set();
10
- this._frameHandle = null;
11
- this._tick = this._tick.bind(this);
12
- this._failed = new WeakSet();
13
- }
14
-
15
- /**
16
- * Add a callback to the loop.
17
- * @param {Function} callback - Function to call each frame (receives dt).
18
- */
19
- add(callback) {
20
- this.callbacks.add(callback);
21
- }
22
-
23
- /**
24
- * Remove a callback from the loop.
25
- * @param {Function} callback
26
- */
27
- remove(callback) {
28
- this.callbacks.delete(callback);
29
- }
30
-
31
- /**
32
- * Start the loop.
33
- */
34
- start() {
35
- if (this.running) return;
36
- this.running = true;
37
- this.lastTime = performance.now();
38
-
39
- // Cancel first: a frame queued before the last stop() may still be
40
- // pending, and letting it through would leave two live loops running
41
- // the game at double speed.
42
- if (this._frameHandle !== null) {
43
- cancelAnimationFrame(this._frameHandle);
44
- }
45
- this._frameHandle = requestAnimationFrame(this._tick);
46
- }
47
-
48
- /**
49
- * Stop the loop.
50
- */
51
- stop() {
52
- this.running = false;
53
-
54
- if (this._frameHandle !== null) {
55
- cancelAnimationFrame(this._frameHandle);
56
- this._frameHandle = null;
57
- }
58
- }
59
-
60
- _tick(time) {
61
- this._frameHandle = null;
62
-
63
- if (!this.running) return;
64
-
65
- const dt = (time - this.lastTime) / 1000; // Delta time in seconds
66
- this.lastTime = time;
67
-
68
- // Cap dt to prevent huge jumps if tab was inactive. Floored at 0: the
69
- // first frame's timestamp can predate the performance.now() in start().
70
- const safeDt = Math.max(0, Math.min(dt, 0.1));
71
-
72
- // Snapshot: a callback may add or remove callbacks mid-frame.
73
- for (const callback of [...this.callbacks]) {
74
- try {
75
- callback(safeDt);
76
- } catch (error) {
77
- // A throw here used to skip the re-queue below with `running`
78
- // still true, so the loop died and start() refused to revive it.
79
- if (!this._failed.has(callback)) {
80
- this._failed.add(callback);
81
- console.error('[Ticker] Callback threw:', error);
82
- }
83
- }
84
- }
85
-
86
- // A callback may have called stop(); don't queue another frame if so.
87
- if (this.running) {
88
- this._frameHandle = requestAnimationFrame(this._tick);
89
- }
90
- }
91
- }