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.
@@ -3203,9 +3203,31 @@ var Camera = class {
3203
3203
  };
3204
3204
  var DemoReader = class {
3205
3205
  constructor(buffer) {
3206
+ this.messageOffsets = [];
3206
3207
  this.buffer = buffer;
3207
3208
  this.view = new DataView(buffer);
3208
3209
  this.offset = 0;
3210
+ this.scan();
3211
+ }
3212
+ /**
3213
+ * Scans the buffer to build an index of message offsets.
3214
+ */
3215
+ scan() {
3216
+ let scanOffset = 0;
3217
+ this.messageOffsets = [];
3218
+ while (scanOffset + 4 <= this.buffer.byteLength) {
3219
+ const length2 = this.view.getInt32(scanOffset, true);
3220
+ if (length2 < 0 || length2 > 2097152) {
3221
+ console.warn(`DemoReader: Invalid block length ${length2} at offset ${scanOffset} during scan`);
3222
+ break;
3223
+ }
3224
+ if (scanOffset + 4 + length2 > this.buffer.byteLength) {
3225
+ console.warn(`DemoReader: Incomplete block at offset ${scanOffset} during scan`);
3226
+ break;
3227
+ }
3228
+ this.messageOffsets.push(scanOffset);
3229
+ scanOffset += 4 + length2;
3230
+ }
3209
3231
  }
3210
3232
  /**
3211
3233
  * Checks if there are more blocks to read.
@@ -3223,15 +3245,10 @@ var DemoReader = class {
3223
3245
  return null;
3224
3246
  }
3225
3247
  const length2 = this.view.getInt32(this.offset, true);
3226
- this.offset += 4;
3227
- if (length2 < 0 || length2 > 2097152) {
3228
- console.warn(`DemoReader: Invalid block length ${length2} at offset ${this.offset - 4}`);
3229
- return null;
3230
- }
3231
- if (this.offset + length2 > this.buffer.byteLength) {
3232
- console.warn(`DemoReader: Incomplete block. Expected ${length2} bytes, but only ${this.buffer.byteLength - this.offset} remain.`);
3248
+ if (length2 < 0 || this.offset + 4 + length2 > this.buffer.byteLength) {
3233
3249
  return null;
3234
3250
  }
3251
+ this.offset += 4;
3235
3252
  const blockData = this.buffer.slice(this.offset, this.offset + length2);
3236
3253
  this.offset += length2;
3237
3254
  return {
@@ -3245,6 +3262,23 @@ var DemoReader = class {
3245
3262
  reset() {
3246
3263
  this.offset = 0;
3247
3264
  }
3265
+ /**
3266
+ * Seeks to a specific message index.
3267
+ * Returns true if successful, false if index is out of bounds.
3268
+ */
3269
+ seekToMessage(index) {
3270
+ if (index < 0 || index >= this.messageOffsets.length) {
3271
+ return false;
3272
+ }
3273
+ this.offset = this.messageOffsets[index];
3274
+ return true;
3275
+ }
3276
+ /**
3277
+ * Returns the total number of messages in the demo.
3278
+ */
3279
+ getMessageCount() {
3280
+ return this.messageOffsets.length;
3281
+ }
3248
3282
  getOffset() {
3249
3283
  return this.offset;
3250
3284
  }
@@ -8395,6 +8429,7 @@ var DemoPlaybackController = class {
8395
8429
  this.state = 0;
8396
8430
  this.playbackSpeed = 1;
8397
8431
  this.currentProtocolVersion = 0;
8432
+ this.currentFrameIndex = 0;
8398
8433
  this.accumulatedTime = 0;
8399
8434
  this.frameDuration = 100;
8400
8435
  }
@@ -8406,6 +8441,7 @@ var DemoPlaybackController = class {
8406
8441
  this.state = 0;
8407
8442
  this.accumulatedTime = 0;
8408
8443
  this.currentProtocolVersion = 0;
8444
+ this.currentFrameIndex = 0;
8409
8445
  }
8410
8446
  play() {
8411
8447
  if (this.reader) {
@@ -8424,6 +8460,7 @@ var DemoPlaybackController = class {
8424
8460
  }
8425
8461
  this.accumulatedTime = 0;
8426
8462
  this.currentProtocolVersion = 0;
8463
+ this.currentFrameIndex = 0;
8427
8464
  }
8428
8465
  setFrameDuration(ms) {
8429
8466
  this.frameDuration = ms;
@@ -8454,6 +8491,19 @@ var DemoPlaybackController = class {
8454
8491
  stepBackward() {
8455
8492
  console.warn("stepBackward not implemented");
8456
8493
  }
8494
+ /**
8495
+ * Seeks to a specific frame number.
8496
+ */
8497
+ seek(frameNumber) {
8498
+ if (!this.reader) return;
8499
+ const total = this.getTotalFrames();
8500
+ if (frameNumber < 0) frameNumber = 0;
8501
+ if (frameNumber >= total) frameNumber = total - 1;
8502
+ if (this.reader.seekToMessage(frameNumber)) {
8503
+ this.currentFrameIndex = frameNumber;
8504
+ this.accumulatedTime = 0;
8505
+ }
8506
+ }
8457
8507
  processNextFrame() {
8458
8508
  if (!this.reader || !this.reader.hasMore()) {
8459
8509
  this.state = 3;
@@ -8464,6 +8514,7 @@ var DemoPlaybackController = class {
8464
8514
  this.state = 3;
8465
8515
  return false;
8466
8516
  }
8517
+ this.currentFrameIndex++;
8467
8518
  const parser = new NetworkMessageParser(block.data, this.handler);
8468
8519
  parser.setProtocolVersion(this.currentProtocolVersion);
8469
8520
  parser.parseMessage();
@@ -8476,6 +8527,18 @@ var DemoPlaybackController = class {
8476
8527
  getCurrentTime() {
8477
8528
  return this.accumulatedTime;
8478
8529
  }
8530
+ getTotalFrames() {
8531
+ return this.reader ? this.reader.getMessageCount() : 0;
8532
+ }
8533
+ getCurrentFrame() {
8534
+ return this.currentFrameIndex;
8535
+ }
8536
+ /**
8537
+ * Returns estimated duration in seconds based on frame count and frame duration.
8538
+ */
8539
+ getDuration() {
8540
+ return this.getTotalFrames() * this.frameDuration / 1e3;
8541
+ }
8479
8542
  };
8480
8543
 
8481
8544
  // ../shared/dist/esm/index.js