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.
@@ -14395,33 +14395,65 @@ var DemoPlaybackController = class {
14395
14395
  });
14396
14396
  }
14397
14397
  }
14398
- async playRangeWithTracking(start, end, tracker) {
14398
+ async playRangeWithTracking(start, end, tracker, options = {}) {
14399
14399
  this.tracker = tracker;
14400
14400
  tracker.startTracking();
14401
- return new Promise((resolve, reject) => {
14402
- const originalComplete = this.callbacks?.onPlaybackComplete;
14403
- const originalError = this.callbacks?.onPlaybackError;
14404
- const cleanup = () => {
14405
- this.setCallbacks({ ...this.callbacks, onPlaybackComplete: originalComplete, onPlaybackError: originalError });
14401
+ const startFrame = start.type === "frame" ? start.frame : this.timeToFrame(start.seconds);
14402
+ const endFrame = end.type === "frame" ? end.frame : this.timeToFrame(end.seconds);
14403
+ if (options.fastForward) {
14404
+ try {
14405
+ this.playFrom(start);
14406
+ this.transitionState(1 /* Playing */);
14407
+ const CHUNK_SIZE = 100;
14408
+ const processChunk = async () => {
14409
+ if (this.state !== 1 /* Playing */) {
14410
+ throw new Error("Playback stopped unexpectedly during fast forward");
14411
+ }
14412
+ let count = 0;
14413
+ while (count < CHUNK_SIZE) {
14414
+ if (this.currentFrameIndex >= endFrame || !this.processNextFrame()) {
14415
+ const log = tracker.stopTracking();
14416
+ this.tracker = null;
14417
+ if (this.callbacks?.onPlaybackComplete) this.callbacks.onPlaybackComplete();
14418
+ return log;
14419
+ }
14420
+ count++;
14421
+ }
14422
+ await new Promise((resolve) => setTimeout(resolve, 0));
14423
+ return processChunk();
14424
+ };
14425
+ return await processChunk();
14426
+ } catch (e) {
14427
+ tracker.stopTracking();
14406
14428
  this.tracker = null;
14407
- };
14408
- this.setCallbacks({
14409
- ...this.callbacks,
14410
- onPlaybackComplete: () => {
14411
- const log = tracker.stopTracking();
14412
- if (originalComplete) originalComplete();
14413
- cleanup();
14414
- resolve(log);
14415
- },
14416
- onPlaybackError: (err2) => {
14417
- tracker.stopTracking();
14418
- if (originalError) originalError(err2);
14419
- cleanup();
14420
- reject(err2);
14421
- }
14429
+ throw e;
14430
+ }
14431
+ } else {
14432
+ return new Promise((resolve, reject) => {
14433
+ const originalComplete = this.callbacks?.onPlaybackComplete;
14434
+ const originalError = this.callbacks?.onPlaybackError;
14435
+ const cleanup = () => {
14436
+ this.setCallbacks({ ...this.callbacks, onPlaybackComplete: originalComplete, onPlaybackError: originalError });
14437
+ this.tracker = null;
14438
+ };
14439
+ this.setCallbacks({
14440
+ ...this.callbacks,
14441
+ onPlaybackComplete: () => {
14442
+ const log = tracker.stopTracking();
14443
+ if (originalComplete) originalComplete();
14444
+ cleanup();
14445
+ resolve(log);
14446
+ },
14447
+ onPlaybackError: (err2) => {
14448
+ tracker.stopTracking();
14449
+ if (originalError) originalError(err2);
14450
+ cleanup();
14451
+ reject(err2);
14452
+ }
14453
+ });
14454
+ this.playRange(start, end);
14422
14455
  });
14423
- this.playRange(start, end);
14424
- });
14456
+ }
14425
14457
  }
14426
14458
  };
14427
14459