@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.
package/build/meep.cjs CHANGED
@@ -95606,6 +95606,8 @@ class Ticker {
95606
95606
  */
95607
95607
  #isRunning = false;
95608
95608
 
95609
+ #animationFrameHandle = -1;
95610
+ #timeoutHandle = -1;
95609
95611
 
95610
95612
  /**
95611
95613
  * Dispatches time delta in seconds since last tick
@@ -95635,6 +95637,7 @@ class Ticker {
95635
95637
  * @param {*} [thisArg]
95636
95638
  */
95637
95639
  subscribe(callback, thisArg) {
95640
+
95638
95641
  this.onTick.add(callback, thisArg);
95639
95642
  }
95640
95643
 
@@ -95644,17 +95647,23 @@ class Ticker {
95644
95647
  * @param {*} [thisArg]
95645
95648
  */
95646
95649
  unsubscribe(callback, thisArg) {
95650
+
95647
95651
  this.onTick.remove(callback, thisArg);
95648
95652
  }
95649
95653
 
95654
+ #isUpdateLoopActive() {
95655
+ return this.#timeoutHandle !== -1 && this.#animationFrameHandle !== -1;
95656
+ }
95657
+
95650
95658
  /**
95651
95659
  *
95652
95660
  * @param {number} [maxTimeout]
95653
95661
  */
95654
95662
  start({ maxTimeout = 100 } = {}) {
95655
95663
 
95656
- let timeout = null;
95657
- let animationFrame = null;
95664
+ if (this.#isUpdateLoopActive()) {
95665
+ throw new Error("Already running");
95666
+ }
95658
95667
 
95659
95668
  this.#isRunning = true;
95660
95669
 
@@ -95668,23 +95677,25 @@ class Ticker {
95668
95677
  this.onTick.send1(delta);
95669
95678
  };
95670
95679
 
95671
- function timeoutCallback() {
95672
- cancelAnimationFrame(animationFrame);
95680
+ const timeoutCallback = () => {
95681
+ cancelAnimationFrame(this.#animationFrameHandle);
95673
95682
  animate();
95674
- }
95683
+ };
95675
95684
 
95676
- function animationFrameCallback() {
95677
- clearTimeout(timeout);
95685
+ const animationFrameCallback = () => {
95686
+ clearTimeout(this.#timeoutHandle);
95678
95687
 
95679
95688
  //push tick beyond animation frame stack allowing draw to happen
95680
- setTimeout(animate, 0);
95681
- }
95689
+ this.#timeoutHandle = setTimeout(animate, 0);
95690
+ };
95691
+
95692
+ const animate = () => {
95693
+ this.#animationFrameHandle = requestAnimationFrame(animationFrameCallback);
95682
95694
 
95683
- function animate() {
95684
- animationFrame = requestAnimationFrame(animationFrameCallback);
95685
95695
  update();
95686
- timeout = setTimeout(timeoutCallback, maxTimeout);
95687
- }
95696
+
95697
+ this.#timeoutHandle = setTimeout(timeoutCallback, maxTimeout);
95698
+ };
95688
95699
 
95689
95700
  this.clock.getDelta(); //purge delta
95690
95701
  this.clock.start();
@@ -95693,12 +95704,32 @@ class Ticker {
95693
95704
  }
95694
95705
 
95695
95706
  pause() {
95707
+
95708
+ if (!this.#isUpdateLoopActive()) {
95709
+ throw new Error("Not currently running");
95710
+ }
95711
+
95696
95712
  this.#isRunning = false;
95697
95713
  }
95698
95714
 
95699
95715
  resume() {
95716
+
95717
+ if (!this.#isUpdateLoopActive()) {
95718
+ throw new Error("Not currently running");
95719
+ }
95720
+
95721
+
95700
95722
  this.#isRunning = true;
95701
95723
  }
95724
+
95725
+ stop() {
95726
+ clearTimeout(this.#timeoutHandle);
95727
+ cancelAnimationFrame(this.#animationFrameHandle);
95728
+ this.#isRunning = false;
95729
+
95730
+ this.#timeoutHandle = -1;
95731
+ this.#animationFrameHandle = -1;
95732
+ }
95702
95733
  }
95703
95734
 
95704
95735
  /**