quake2ts 0.0.308 → 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.
@@ -3235,9 +3235,31 @@ var Camera = class {
3235
3235
  };
3236
3236
  var DemoReader = class {
3237
3237
  constructor(buffer) {
3238
+ this.messageOffsets = [];
3238
3239
  this.buffer = buffer;
3239
3240
  this.view = new DataView(buffer);
3240
3241
  this.offset = 0;
3242
+ this.scan();
3243
+ }
3244
+ /**
3245
+ * Scans the buffer to build an index of message offsets.
3246
+ */
3247
+ scan() {
3248
+ let scanOffset = 0;
3249
+ this.messageOffsets = [];
3250
+ while (scanOffset + 4 <= this.buffer.byteLength) {
3251
+ const length2 = this.view.getInt32(scanOffset, true);
3252
+ if (length2 < 0 || length2 > 2097152) {
3253
+ console.warn(`DemoReader: Invalid block length ${length2} at offset ${scanOffset} during scan`);
3254
+ break;
3255
+ }
3256
+ if (scanOffset + 4 + length2 > this.buffer.byteLength) {
3257
+ console.warn(`DemoReader: Incomplete block at offset ${scanOffset} during scan`);
3258
+ break;
3259
+ }
3260
+ this.messageOffsets.push(scanOffset);
3261
+ scanOffset += 4 + length2;
3262
+ }
3241
3263
  }
3242
3264
  /**
3243
3265
  * Checks if there are more blocks to read.
@@ -3255,15 +3277,10 @@ var DemoReader = class {
3255
3277
  return null;
3256
3278
  }
3257
3279
  const length2 = this.view.getInt32(this.offset, true);
3258
- this.offset += 4;
3259
- if (length2 < 0 || length2 > 2097152) {
3260
- console.warn(`DemoReader: Invalid block length ${length2} at offset ${this.offset - 4}`);
3261
- return null;
3262
- }
3263
- if (this.offset + length2 > this.buffer.byteLength) {
3264
- console.warn(`DemoReader: Incomplete block. Expected ${length2} bytes, but only ${this.buffer.byteLength - this.offset} remain.`);
3280
+ if (length2 < 0 || this.offset + 4 + length2 > this.buffer.byteLength) {
3265
3281
  return null;
3266
3282
  }
3283
+ this.offset += 4;
3267
3284
  const blockData = this.buffer.slice(this.offset, this.offset + length2);
3268
3285
  this.offset += length2;
3269
3286
  return {
@@ -3277,6 +3294,23 @@ var DemoReader = class {
3277
3294
  reset() {
3278
3295
  this.offset = 0;
3279
3296
  }
3297
+ /**
3298
+ * Seeks to a specific message index.
3299
+ * Returns true if successful, false if index is out of bounds.
3300
+ */
3301
+ seekToMessage(index) {
3302
+ if (index < 0 || index >= this.messageOffsets.length) {
3303
+ return false;
3304
+ }
3305
+ this.offset = this.messageOffsets[index];
3306
+ return true;
3307
+ }
3308
+ /**
3309
+ * Returns the total number of messages in the demo.
3310
+ */
3311
+ getMessageCount() {
3312
+ return this.messageOffsets.length;
3313
+ }
3280
3314
  getOffset() {
3281
3315
  return this.offset;
3282
3316
  }
@@ -8427,6 +8461,7 @@ var DemoPlaybackController = class {
8427
8461
  this.state = 0;
8428
8462
  this.playbackSpeed = 1;
8429
8463
  this.currentProtocolVersion = 0;
8464
+ this.currentFrameIndex = 0;
8430
8465
  this.accumulatedTime = 0;
8431
8466
  this.frameDuration = 100;
8432
8467
  }
@@ -8438,6 +8473,7 @@ var DemoPlaybackController = class {
8438
8473
  this.state = 0;
8439
8474
  this.accumulatedTime = 0;
8440
8475
  this.currentProtocolVersion = 0;
8476
+ this.currentFrameIndex = 0;
8441
8477
  }
8442
8478
  play() {
8443
8479
  if (this.reader) {
@@ -8456,6 +8492,7 @@ var DemoPlaybackController = class {
8456
8492
  }
8457
8493
  this.accumulatedTime = 0;
8458
8494
  this.currentProtocolVersion = 0;
8495
+ this.currentFrameIndex = 0;
8459
8496
  }
8460
8497
  setFrameDuration(ms) {
8461
8498
  this.frameDuration = ms;
@@ -8486,6 +8523,19 @@ var DemoPlaybackController = class {
8486
8523
  stepBackward() {
8487
8524
  console.warn("stepBackward not implemented");
8488
8525
  }
8526
+ /**
8527
+ * Seeks to a specific frame number.
8528
+ */
8529
+ seek(frameNumber) {
8530
+ if (!this.reader) return;
8531
+ const total = this.getTotalFrames();
8532
+ if (frameNumber < 0) frameNumber = 0;
8533
+ if (frameNumber >= total) frameNumber = total - 1;
8534
+ if (this.reader.seekToMessage(frameNumber)) {
8535
+ this.currentFrameIndex = frameNumber;
8536
+ this.accumulatedTime = 0;
8537
+ }
8538
+ }
8489
8539
  processNextFrame() {
8490
8540
  if (!this.reader || !this.reader.hasMore()) {
8491
8541
  this.state = 3;
@@ -8496,6 +8546,7 @@ var DemoPlaybackController = class {
8496
8546
  this.state = 3;
8497
8547
  return false;
8498
8548
  }
8549
+ this.currentFrameIndex++;
8499
8550
  const parser = new NetworkMessageParser(block.data, this.handler);
8500
8551
  parser.setProtocolVersion(this.currentProtocolVersion);
8501
8552
  parser.parseMessage();
@@ -8508,6 +8559,18 @@ var DemoPlaybackController = class {
8508
8559
  getCurrentTime() {
8509
8560
  return this.accumulatedTime;
8510
8561
  }
8562
+ getTotalFrames() {
8563
+ return this.reader ? this.reader.getMessageCount() : 0;
8564
+ }
8565
+ getCurrentFrame() {
8566
+ return this.currentFrameIndex;
8567
+ }
8568
+ /**
8569
+ * Returns estimated duration in seconds based on frame count and frame duration.
8570
+ */
8571
+ getDuration() {
8572
+ return this.getTotalFrames() * this.frameDuration / 1e3;
8573
+ }
8511
8574
  };
8512
8575
 
8513
8576
  // ../shared/dist/esm/index.js