@woosh/meep-engine 2.94.7 → 2.94.8

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.
@@ -95604,6 +95604,8 @@ class Ticker {
95604
95604
  */
95605
95605
  #isRunning = false;
95606
95606
 
95607
+ #animationFrameHandle = -1;
95608
+ #timeoutHandle = -1;
95607
95609
 
95608
95610
  /**
95609
95611
  * Dispatches time delta in seconds since last tick
@@ -95633,6 +95635,7 @@ class Ticker {
95633
95635
  * @param {*} [thisArg]
95634
95636
  */
95635
95637
  subscribe(callback, thisArg) {
95638
+
95636
95639
  this.onTick.add(callback, thisArg);
95637
95640
  }
95638
95641
 
@@ -95642,17 +95645,23 @@ class Ticker {
95642
95645
  * @param {*} [thisArg]
95643
95646
  */
95644
95647
  unsubscribe(callback, thisArg) {
95648
+
95645
95649
  this.onTick.remove(callback, thisArg);
95646
95650
  }
95647
95651
 
95652
+ #isUpdateLoopActive() {
95653
+ return this.#timeoutHandle !== -1 && this.#animationFrameHandle !== -1;
95654
+ }
95655
+
95648
95656
  /**
95649
95657
  *
95650
95658
  * @param {number} [maxTimeout]
95651
95659
  */
95652
95660
  start({ maxTimeout = 100 } = {}) {
95653
95661
 
95654
- let timeout = null;
95655
- let animationFrame = null;
95662
+ if (this.#isUpdateLoopActive()) {
95663
+ throw new Error("Already running");
95664
+ }
95656
95665
 
95657
95666
  this.#isRunning = true;
95658
95667
 
@@ -95666,23 +95675,25 @@ class Ticker {
95666
95675
  this.onTick.send1(delta);
95667
95676
  };
95668
95677
 
95669
- function timeoutCallback() {
95670
- cancelAnimationFrame(animationFrame);
95678
+ const timeoutCallback = () => {
95679
+ cancelAnimationFrame(this.#animationFrameHandle);
95671
95680
  animate();
95672
- }
95681
+ };
95673
95682
 
95674
- function animationFrameCallback() {
95675
- clearTimeout(timeout);
95683
+ const animationFrameCallback = () => {
95684
+ clearTimeout(this.#timeoutHandle);
95676
95685
 
95677
95686
  //push tick beyond animation frame stack allowing draw to happen
95678
- setTimeout(animate, 0);
95679
- }
95687
+ this.#timeoutHandle = setTimeout(animate, 0);
95688
+ };
95689
+
95690
+ const animate = () => {
95691
+ this.#animationFrameHandle = requestAnimationFrame(animationFrameCallback);
95680
95692
 
95681
- function animate() {
95682
- animationFrame = requestAnimationFrame(animationFrameCallback);
95683
95693
  update();
95684
- timeout = setTimeout(timeoutCallback, maxTimeout);
95685
- }
95694
+
95695
+ this.#timeoutHandle = setTimeout(timeoutCallback, maxTimeout);
95696
+ };
95686
95697
 
95687
95698
  this.clock.getDelta(); //purge delta
95688
95699
  this.clock.start();
@@ -95691,12 +95702,32 @@ class Ticker {
95691
95702
  }
95692
95703
 
95693
95704
  pause() {
95705
+
95706
+ if (!this.#isUpdateLoopActive()) {
95707
+ throw new Error("Not currently running");
95708
+ }
95709
+
95694
95710
  this.#isRunning = false;
95695
95711
  }
95696
95712
 
95697
95713
  resume() {
95714
+
95715
+ if (!this.#isUpdateLoopActive()) {
95716
+ throw new Error("Not currently running");
95717
+ }
95718
+
95719
+
95698
95720
  this.#isRunning = true;
95699
95721
  }
95722
+
95723
+ stop() {
95724
+ clearTimeout(this.#timeoutHandle);
95725
+ cancelAnimationFrame(this.#animationFrameHandle);
95726
+ this.#isRunning = false;
95727
+
95728
+ this.#timeoutHandle = -1;
95729
+ this.#animationFrameHandle = -1;
95730
+ }
95700
95731
  }
95701
95732
 
95702
95733
  /**
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.94.7",
8
+ "version": "2.94.8",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -3,13 +3,12 @@ import Signal from "../../core/events/signal/Signal";
3
3
  export default class Ticker {
4
4
  readonly onTick: Signal<number>
5
5
 
6
- /**
7
- * @deprecated
8
- */
9
- subscribe(f: (timeDelta: number) => any, thisArg?: any): void
10
-
11
- /**
12
- * @deprecated
13
- */
14
- unsubscribe(f: (timeDelta: number) => any, thisArg?: any): void
6
+ start(): void
7
+
8
+ stop(): void
9
+
10
+ pause(): void
11
+
12
+ resume(): void
13
+
15
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Ticker.d.ts","sourceRoot":"","sources":["../../../../src/engine/simulation/Ticker.js"],"names":[],"mappings":";AAOA;;;;GAIG;AACH;IACI;;;OAGG;IACH,gBAFU,KAAK,CAEK;IASpB;;;;OAIG;IACH,iBAFU,OAAO,MAAM,CAAC,CAEF;IAEtB;;OAEG;IACH,sBAEC;IAUD;;;;OAIG;IACH,mDAEC;IAED;;;;OAIG;IACH,qDAEC;IAED;;;OAGG;IACH,uBAFW,MAAM,QA2ChB;IAED,cAEC;IAED,eAEC;;CACJ;kBAnHiB,aAAa;mBADZ,oCAAoC"}
1
+ {"version":3,"file":"Ticker.d.ts","sourceRoot":"","sources":["../../../../src/engine/simulation/Ticker.js"],"names":[],"mappings":";AAOA;;;;GAIG;AACH;IACI;;;OAGG;IACH,gBAFU,KAAK,CAEK;IAWpB;;;;OAIG;IACH,iBAFU,OAAO,MAAM,CAAC,CAEF;IAEtB;;OAEG;IACH,sBAEC;IAUD;;;;OAIG;IACH,mDAIC;IAED;;;;OAIG;IACH,qDAIC;IAMD;;;OAGG;IACH,uBAFW,MAAM,QA8ChB;IAED,cAOC;IAED,eAQC;IAED,aAOC;;CACJ;kBApJiB,aAAa;mBADZ,oCAAoC"}
@@ -23,6 +23,8 @@ class Ticker {
23
23
  */
24
24
  #isRunning = false;
25
25
 
26
+ #animationFrameHandle = -1;
27
+ #timeoutHandle = -1;
26
28
 
27
29
  /**
28
30
  * Dispatches time delta in seconds since last tick
@@ -52,6 +54,8 @@ class Ticker {
52
54
  * @param {*} [thisArg]
53
55
  */
54
56
  subscribe(callback, thisArg) {
57
+ console.warn('deprecated use onTick signal directly instead');
58
+
55
59
  this.onTick.add(callback, thisArg);
56
60
  }
57
61
 
@@ -61,9 +65,15 @@ class Ticker {
61
65
  * @param {*} [thisArg]
62
66
  */
63
67
  unsubscribe(callback, thisArg) {
68
+ console.warn('deprecated use onTick signal directly instead');
69
+
64
70
  this.onTick.remove(callback, thisArg);
65
71
  }
66
72
 
73
+ #isUpdateLoopActive() {
74
+ return this.#timeoutHandle !== -1 && this.#animationFrameHandle !== -1;
75
+ }
76
+
67
77
  /**
68
78
  *
69
79
  * @param {number} [maxTimeout]
@@ -72,8 +82,9 @@ class Ticker {
72
82
  assert.isNumber(maxTimeout, 'maxTimeout');
73
83
  assert.greaterThan(maxTimeout, 0);
74
84
 
75
- let timeout = null;
76
- let animationFrame = null;
85
+ if (this.#isUpdateLoopActive()) {
86
+ throw new Error("Already running");
87
+ }
77
88
 
78
89
  this.#isRunning = true;
79
90
 
@@ -87,22 +98,24 @@ class Ticker {
87
98
  this.onTick.send1(delta);
88
99
  }
89
100
 
90
- function timeoutCallback() {
91
- cancelAnimationFrame(animationFrame);
101
+ const timeoutCallback = () => {
102
+ cancelAnimationFrame(this.#animationFrameHandle);
92
103
  animate();
93
104
  }
94
105
 
95
- function animationFrameCallback() {
96
- clearTimeout(timeout);
106
+ const animationFrameCallback = () => {
107
+ clearTimeout(this.#timeoutHandle);
97
108
 
98
109
  //push tick beyond animation frame stack allowing draw to happen
99
- setTimeout(animate, 0);
110
+ this.#timeoutHandle = setTimeout(animate, 0);
100
111
  }
101
112
 
102
- function animate() {
103
- animationFrame = requestAnimationFrame(animationFrameCallback);
113
+ const animate = () => {
114
+ this.#animationFrameHandle = requestAnimationFrame(animationFrameCallback);
115
+
104
116
  update();
105
- timeout = setTimeout(timeoutCallback, maxTimeout);
117
+
118
+ this.#timeoutHandle = setTimeout(timeoutCallback, maxTimeout);
106
119
  }
107
120
 
108
121
  this.clock.getDelta(); //purge delta
@@ -112,12 +125,32 @@ class Ticker {
112
125
  }
113
126
 
114
127
  pause() {
128
+
129
+ if (!this.#isUpdateLoopActive()) {
130
+ throw new Error("Not currently running");
131
+ }
132
+
115
133
  this.#isRunning = false;
116
134
  }
117
135
 
118
136
  resume() {
137
+
138
+ if (!this.#isUpdateLoopActive()) {
139
+ throw new Error("Not currently running");
140
+ }
141
+
142
+
119
143
  this.#isRunning = true;
120
144
  }
145
+
146
+ stop() {
147
+ clearTimeout(this.#timeoutHandle);
148
+ cancelAnimationFrame(this.#animationFrameHandle);
149
+ this.#isRunning = false;
150
+
151
+ this.#timeoutHandle = -1;
152
+ this.#animationFrameHandle = -1;
153
+ }
121
154
  }
122
155
 
123
156
  export default Ticker;