quake2ts 0.0.519 → 0.0.520

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.
@@ -14180,33 +14180,65 @@ var DemoPlaybackController = class {
14180
14180
  });
14181
14181
  }
14182
14182
  }
14183
- async playRangeWithTracking(start, end, tracker) {
14183
+ async playRangeWithTracking(start, end, tracker, options = {}) {
14184
14184
  this.tracker = tracker;
14185
14185
  tracker.startTracking();
14186
- return new Promise((resolve, reject) => {
14187
- const originalComplete = this.callbacks?.onPlaybackComplete;
14188
- const originalError = this.callbacks?.onPlaybackError;
14189
- const cleanup = () => {
14190
- this.setCallbacks({ ...this.callbacks, onPlaybackComplete: originalComplete, onPlaybackError: originalError });
14186
+ const startFrame = start.type === "frame" ? start.frame : this.timeToFrame(start.seconds);
14187
+ const endFrame = end.type === "frame" ? end.frame : this.timeToFrame(end.seconds);
14188
+ if (options.fastForward) {
14189
+ try {
14190
+ this.playFrom(start);
14191
+ this.transitionState(1 /* Playing */);
14192
+ const CHUNK_SIZE = 100;
14193
+ const processChunk = async () => {
14194
+ if (this.state !== 1 /* Playing */) {
14195
+ throw new Error("Playback stopped unexpectedly during fast forward");
14196
+ }
14197
+ let count = 0;
14198
+ while (count < CHUNK_SIZE) {
14199
+ if (this.currentFrameIndex >= endFrame || !this.processNextFrame()) {
14200
+ const log = tracker.stopTracking();
14201
+ this.tracker = null;
14202
+ if (this.callbacks?.onPlaybackComplete) this.callbacks.onPlaybackComplete();
14203
+ return log;
14204
+ }
14205
+ count++;
14206
+ }
14207
+ await new Promise((resolve) => setTimeout(resolve, 0));
14208
+ return processChunk();
14209
+ };
14210
+ return await processChunk();
14211
+ } catch (e) {
14212
+ tracker.stopTracking();
14191
14213
  this.tracker = null;
14192
- };
14193
- this.setCallbacks({
14194
- ...this.callbacks,
14195
- onPlaybackComplete: () => {
14196
- const log = tracker.stopTracking();
14197
- if (originalComplete) originalComplete();
14198
- cleanup();
14199
- resolve(log);
14200
- },
14201
- onPlaybackError: (err2) => {
14202
- tracker.stopTracking();
14203
- if (originalError) originalError(err2);
14204
- cleanup();
14205
- reject(err2);
14206
- }
14214
+ throw e;
14215
+ }
14216
+ } else {
14217
+ return new Promise((resolve, reject) => {
14218
+ const originalComplete = this.callbacks?.onPlaybackComplete;
14219
+ const originalError = this.callbacks?.onPlaybackError;
14220
+ const cleanup = () => {
14221
+ this.setCallbacks({ ...this.callbacks, onPlaybackComplete: originalComplete, onPlaybackError: originalError });
14222
+ this.tracker = null;
14223
+ };
14224
+ this.setCallbacks({
14225
+ ...this.callbacks,
14226
+ onPlaybackComplete: () => {
14227
+ const log = tracker.stopTracking();
14228
+ if (originalComplete) originalComplete();
14229
+ cleanup();
14230
+ resolve(log);
14231
+ },
14232
+ onPlaybackError: (err2) => {
14233
+ tracker.stopTracking();
14234
+ if (originalError) originalError(err2);
14235
+ cleanup();
14236
+ reject(err2);
14237
+ }
14238
+ });
14239
+ this.playRange(start, end);
14207
14240
  });
14208
- this.playRange(start, end);
14209
- });
14241
+ }
14210
14242
  }
14211
14243
  };
14212
14244