quake2ts 0.0.307 → 0.0.309

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.
@@ -7250,9 +7250,31 @@ function spawnTrail(context) {
7250
7250
  // src/demo/demoReader.ts
7251
7251
  var DemoReader = class {
7252
7252
  constructor(buffer) {
7253
+ this.messageOffsets = [];
7253
7254
  this.buffer = buffer;
7254
7255
  this.view = new DataView(buffer);
7255
7256
  this.offset = 0;
7257
+ this.scan();
7258
+ }
7259
+ /**
7260
+ * Scans the buffer to build an index of message offsets.
7261
+ */
7262
+ scan() {
7263
+ let scanOffset = 0;
7264
+ this.messageOffsets = [];
7265
+ while (scanOffset + 4 <= this.buffer.byteLength) {
7266
+ const length = this.view.getInt32(scanOffset, true);
7267
+ if (length < 0 || length > 2097152) {
7268
+ console.warn(`DemoReader: Invalid block length ${length} at offset ${scanOffset} during scan`);
7269
+ break;
7270
+ }
7271
+ if (scanOffset + 4 + length > this.buffer.byteLength) {
7272
+ console.warn(`DemoReader: Incomplete block at offset ${scanOffset} during scan`);
7273
+ break;
7274
+ }
7275
+ this.messageOffsets.push(scanOffset);
7276
+ scanOffset += 4 + length;
7277
+ }
7256
7278
  }
7257
7279
  /**
7258
7280
  * Checks if there are more blocks to read.
@@ -7270,15 +7292,10 @@ var DemoReader = class {
7270
7292
  return null;
7271
7293
  }
7272
7294
  const length = this.view.getInt32(this.offset, true);
7273
- this.offset += 4;
7274
- if (length < 0 || length > 2097152) {
7275
- console.warn(`DemoReader: Invalid block length ${length} at offset ${this.offset - 4}`);
7276
- return null;
7277
- }
7278
- if (this.offset + length > this.buffer.byteLength) {
7279
- console.warn(`DemoReader: Incomplete block. Expected ${length} bytes, but only ${this.buffer.byteLength - this.offset} remain.`);
7295
+ if (length < 0 || this.offset + 4 + length > this.buffer.byteLength) {
7280
7296
  return null;
7281
7297
  }
7298
+ this.offset += 4;
7282
7299
  const blockData = this.buffer.slice(this.offset, this.offset + length);
7283
7300
  this.offset += length;
7284
7301
  return {
@@ -7292,6 +7309,23 @@ var DemoReader = class {
7292
7309
  reset() {
7293
7310
  this.offset = 0;
7294
7311
  }
7312
+ /**
7313
+ * Seeks to a specific message index.
7314
+ * Returns true if successful, false if index is out of bounds.
7315
+ */
7316
+ seekToMessage(index) {
7317
+ if (index < 0 || index >= this.messageOffsets.length) {
7318
+ return false;
7319
+ }
7320
+ this.offset = this.messageOffsets[index];
7321
+ return true;
7322
+ }
7323
+ /**
7324
+ * Returns the total number of messages in the demo.
7325
+ */
7326
+ getMessageCount() {
7327
+ return this.messageOffsets.length;
7328
+ }
7295
7329
  getOffset() {
7296
7330
  return this.offset;
7297
7331
  }
@@ -12449,6 +12483,7 @@ var DemoPlaybackController = class {
12449
12483
  this.state = 0 /* Stopped */;
12450
12484
  this.playbackSpeed = 1;
12451
12485
  this.currentProtocolVersion = 0;
12486
+ this.currentFrameIndex = 0;
12452
12487
  // Timing
12453
12488
  this.accumulatedTime = 0;
12454
12489
  this.frameDuration = 100;
@@ -12461,6 +12496,7 @@ var DemoPlaybackController = class {
12461
12496
  this.state = 0 /* Stopped */;
12462
12497
  this.accumulatedTime = 0;
12463
12498
  this.currentProtocolVersion = 0;
12499
+ this.currentFrameIndex = 0;
12464
12500
  }
12465
12501
  play() {
12466
12502
  if (this.reader) {
@@ -12479,6 +12515,7 @@ var DemoPlaybackController = class {
12479
12515
  }
12480
12516
  this.accumulatedTime = 0;
12481
12517
  this.currentProtocolVersion = 0;
12518
+ this.currentFrameIndex = 0;
12482
12519
  }
12483
12520
  setFrameDuration(ms) {
12484
12521
  this.frameDuration = ms;
@@ -12509,6 +12546,19 @@ var DemoPlaybackController = class {
12509
12546
  stepBackward() {
12510
12547
  console.warn("stepBackward not implemented");
12511
12548
  }
12549
+ /**
12550
+ * Seeks to a specific frame number.
12551
+ */
12552
+ seek(frameNumber) {
12553
+ if (!this.reader) return;
12554
+ const total = this.getTotalFrames();
12555
+ if (frameNumber < 0) frameNumber = 0;
12556
+ if (frameNumber >= total) frameNumber = total - 1;
12557
+ if (this.reader.seekToMessage(frameNumber)) {
12558
+ this.currentFrameIndex = frameNumber;
12559
+ this.accumulatedTime = 0;
12560
+ }
12561
+ }
12512
12562
  processNextFrame() {
12513
12563
  if (!this.reader || !this.reader.hasMore()) {
12514
12564
  this.state = 3 /* Finished */;
@@ -12519,6 +12569,7 @@ var DemoPlaybackController = class {
12519
12569
  this.state = 3 /* Finished */;
12520
12570
  return false;
12521
12571
  }
12572
+ this.currentFrameIndex++;
12522
12573
  const parser = new NetworkMessageParser(block.data, this.handler);
12523
12574
  parser.setProtocolVersion(this.currentProtocolVersion);
12524
12575
  parser.parseMessage();
@@ -12531,6 +12582,18 @@ var DemoPlaybackController = class {
12531
12582
  getCurrentTime() {
12532
12583
  return this.accumulatedTime;
12533
12584
  }
12585
+ getTotalFrames() {
12586
+ return this.reader ? this.reader.getMessageCount() : 0;
12587
+ }
12588
+ getCurrentFrame() {
12589
+ return this.currentFrameIndex;
12590
+ }
12591
+ /**
12592
+ * Returns estimated duration in seconds based on frame count and frame duration.
12593
+ */
12594
+ getDuration() {
12595
+ return this.getTotalFrames() * this.frameDuration / 1e3;
12596
+ }
12534
12597
  };
12535
12598
 
12536
12599
  // src/index.ts