minerender 2.1.0-alpha.51 → 2.1.0-alpha.52

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/dist/bundle.js CHANGED
@@ -86781,7 +86781,7 @@ property list uchar int vertex_index
86781
86781
  }
86782
86782
  init() {
86783
86783
  this.statsContainer.classList.add("minerender-stats");
86784
- setInterval(() => {
86784
+ this.interval = setInterval(() => {
86785
86785
  for (let line of this.lines) {
86786
86786
  line.update();
86787
86787
  }
@@ -86790,6 +86790,13 @@ property list uchar int vertex_index
86790
86790
  appendTo(el) {
86791
86791
  el.append(this.statsContainer);
86792
86792
  }
86793
+ dispose() {
86794
+ clearInterval(this.interval);
86795
+ this.interval = void 0;
86796
+ this.lines.length = 0;
86797
+ this.statsContainer.replaceChildren();
86798
+ this.statsContainer.remove();
86799
+ }
86793
86800
  add(line) {
86794
86801
  if (typeof line !== "undefined") {
86795
86802
  this.lines.push(line);
@@ -92921,7 +92928,10 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
92921
92928
  constructor(options) {
92922
92929
  this._dirty = true;
92923
92930
  this._resizeListener = void 0;
92931
+ this._running = false;
92932
+ this._inAnimationLoop = false;
92924
92933
  this._disposed = false;
92934
+ this._frameCallbacks = /* @__PURE__ */ new Map();
92925
92935
  this._debugHelpers = [];
92926
92936
  this._eventDispatchers = /* @__PURE__ */ new Map();
92927
92937
  this._changeListener = () => {
@@ -92932,7 +92942,14 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
92932
92942
  if (!Number.isFinite(pixelRatio) || pixelRatio <= 0) {
92933
92943
  throw new RangeError("render.pixelRatio must be a finite positive number");
92934
92944
  }
92935
- this._animationLoop = this.animate.bind(this);
92945
+ this._animationLoop = (time) => {
92946
+ this._inAnimationLoop = true;
92947
+ try {
92948
+ this.animate(time);
92949
+ } finally {
92950
+ this._inAnimationLoop = false;
92951
+ }
92952
+ };
92936
92953
  this._frameInterval = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
92937
92954
  this._scene = this.createScene();
92938
92955
  this._camera = this.createCamera();
@@ -93107,15 +93124,39 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
93107
93124
  this._dirty = dirty;
93108
93125
  this.scene.dirty = dirty;
93109
93126
  }
93127
+ /**
93128
+ * Calls a synchronous animation update before each FPS-limited draw while started.
93129
+ * Subscriptions keep the scene drawing without manual dirty flags. Returns an unsubscribe function.
93130
+ * Registering the same callback twice has no effect. Image exports do not invoke callbacks.
93131
+ */
93132
+ onFrame(callback) {
93133
+ if (this._disposed) return () => {
93134
+ };
93135
+ const subscription = this._frameCallbacks.get(callback) ?? {};
93136
+ this._frameCallbacks.set(callback, subscription);
93137
+ return () => {
93138
+ if (this._frameCallbacks.get(callback) === subscription) this._frameCallbacks.delete(callback);
93139
+ };
93140
+ }
93110
93141
  start() {
93111
93142
  if (this._disposed) return;
93112
93143
  this.stop();
93113
- this.renderer.setAnimationLoop(this._animationLoop);
93144
+ this._running = true;
93145
+ if (!this._inAnimationLoop) this.renderer.setAnimationLoop(this._animationLoop);
93114
93146
  }
93115
93147
  stop() {
93116
93148
  if (this._disposed) return;
93117
- this.renderer.setAnimationLoop(null);
93149
+ this._running = false;
93150
+ if (this._inAnimationLoop) {
93151
+ queueMicrotask(() => {
93152
+ this.renderer.setAnimationLoop(null);
93153
+ if (this._running) this.renderer.setAnimationLoop(this._animationLoop);
93154
+ });
93155
+ } else {
93156
+ this.renderer.setAnimationLoop(null);
93157
+ }
93118
93158
  this._nextFrameTime = void 0;
93159
+ for (const subscription of this._frameCallbacks.values()) subscription.previous = void 0;
93119
93160
  }
93120
93161
  /**
93121
93162
  * Stops rendering and releases owned resources. Repeated calls have no effect, and a disposed
@@ -93126,6 +93167,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
93126
93167
  if (this._disposed) return;
93127
93168
  this.stop();
93128
93169
  this._disposed = true;
93170
+ this._frameCallbacks.clear();
93129
93171
  if (this._resizeListener) {
93130
93172
  window.removeEventListener("resize", this._resizeListener);
93131
93173
  this._resizeListener = void 0;
@@ -93160,18 +93202,25 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
93160
93202
  this.renderer.forceContextLoss();
93161
93203
  }
93162
93204
  animate(t5 = performance.now()) {
93163
- if (this._disposed) return;
93205
+ if (!this._running) return;
93164
93206
  if (this._controls?.enabled) {
93165
93207
  this._controls.update();
93166
93208
  }
93167
- if (this._disposed) return;
93168
- if (!this.dirty && !this.options.render.renderAlways) return;
93209
+ if (!this._running) return;
93210
+ if (!this.dirty && !this.options.render.renderAlways && !this._frameCallbacks.size) return;
93169
93211
  const interval = this._frameInterval;
93170
93212
  if (interval) {
93171
93213
  const next = this._nextFrameTime;
93172
93214
  if (next !== void 0 && t5 + 0.1 < next) return;
93173
93215
  this._nextFrameTime = next !== void 0 && t5 - next < interval ? next + interval : t5 + interval;
93174
93216
  }
93217
+ for (const [callback, subscription] of [...this._frameCallbacks]) {
93218
+ if (this._frameCallbacks.get(callback) !== subscription) continue;
93219
+ const previous = subscription.previous;
93220
+ subscription.previous = t5;
93221
+ callback({ time: t5 / 1e3, delta: previous === void 0 ? 0 : (t5 - previous) / 1e3 });
93222
+ if (!this._running) return;
93223
+ }
93175
93224
  this.drawFrame();
93176
93225
  }
93177
93226
  drawFrame() {