quake2ts 0.0.284 → 0.0.288

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.
@@ -9589,6 +9589,91 @@ var DEMO_ITEM_MAPPING = [
9589
9589
  // IT_ITEM_COMPASS
9590
9590
  ];
9591
9591
 
9592
+ // src/entities.ts
9593
+ function lerp2(a, b, t) {
9594
+ return a + (b - a) * t;
9595
+ }
9596
+ function lerpAngle(a, b, t) {
9597
+ return lerp2(a, b, t);
9598
+ }
9599
+ function buildRenderableEntities(latestEntities, previousEntities, alpha, configStrings, imports) {
9600
+ const renderables = [];
9601
+ const assets = imports.engine.assets;
9602
+ if (!assets) return renderables;
9603
+ let prevMap;
9604
+ if (previousEntities instanceof Map) {
9605
+ prevMap = previousEntities;
9606
+ } else {
9607
+ prevMap = new Map(previousEntities.map((e) => [e.number, e]));
9608
+ }
9609
+ for (const ent of latestEntities) {
9610
+ const prev = prevMap.get(ent.number) ?? ent;
9611
+ const modelIndex = ent.modelIndex ?? ent.modelindex;
9612
+ const skinNum = ent.skinNum ?? ent.skinnum;
9613
+ if (modelIndex === void 0) continue;
9614
+ const modelName = configStrings.getModelName(modelIndex);
9615
+ if (!modelName) continue;
9616
+ const model = assets.getMd2Model(modelName) || assets.getMd3Model(modelName);
9617
+ if (!model) continue;
9618
+ const origin = {
9619
+ x: lerp2(prev.origin.x, ent.origin.x, alpha),
9620
+ y: lerp2(prev.origin.y, ent.origin.y, alpha),
9621
+ z: lerp2(prev.origin.z, ent.origin.z, alpha)
9622
+ };
9623
+ const angles = {
9624
+ x: lerpAngle(prev.angles.x, ent.angles.x, alpha),
9625
+ y: lerpAngle(prev.angles.y, ent.angles.y, alpha),
9626
+ z: lerpAngle(prev.angles.z, ent.angles.z, alpha)
9627
+ };
9628
+ const frame = ent.frame;
9629
+ const prevFrame = prev.frame;
9630
+ const scaleA = prev.scale !== void 0 ? prev.scale : 1;
9631
+ const scaleB = ent.scale !== void 0 ? ent.scale : 1;
9632
+ const scale3 = lerp2(scaleA, scaleB, alpha);
9633
+ const getAlpha = (val) => val === void 0 || val === 0 ? 255 : val;
9634
+ const alphaA = getAlpha(prev.alpha);
9635
+ const alphaB = getAlpha(ent.alpha);
9636
+ const alphaVal = lerp2(alphaA, alphaB, alpha);
9637
+ const normalizedAlpha = alphaVal / 255;
9638
+ const mat = mat4_exports.create();
9639
+ mat4_exports.translate(mat, mat, [origin.x, origin.y, origin.z]);
9640
+ mat4_exports.rotateZ(mat, mat, angles.z * Math.PI / 180);
9641
+ mat4_exports.rotateY(mat, mat, angles.y * Math.PI / 180);
9642
+ mat4_exports.rotateX(mat, mat, angles.x * Math.PI / 180);
9643
+ mat4_exports.scale(mat, mat, [scale3, scale3, scale3]);
9644
+ const skinName = skinNum !== void 0 && skinNum > 0 ? configStrings.getImageName(skinNum) : void 0;
9645
+ if (model.header.magic === 844121161) {
9646
+ renderables.push({
9647
+ type: "md2",
9648
+ model,
9649
+ // Cast to Md2Model
9650
+ blend: {
9651
+ frame0: prevFrame,
9652
+ frame1: frame,
9653
+ lerp: alpha
9654
+ },
9655
+ transform: mat,
9656
+ skin: skinName,
9657
+ alpha: normalizedAlpha
9658
+ });
9659
+ } else if (model.header.magic === 860898377) {
9660
+ renderables.push({
9661
+ type: "md3",
9662
+ model,
9663
+ blend: {
9664
+ frame0: prevFrame,
9665
+ frame1: frame,
9666
+ lerp: alpha
9667
+ },
9668
+ transform: mat,
9669
+ alpha: normalizedAlpha
9670
+ // Lighting? Skins?
9671
+ });
9672
+ }
9673
+ }
9674
+ return renderables;
9675
+ }
9676
+
9592
9677
  // src/demo/handler.ts
9593
9678
  var MAX_CONFIGSTRINGS3 = 32768;
9594
9679
  var ClientNetworkHandler = class {
@@ -9596,6 +9681,8 @@ var ClientNetworkHandler = class {
9596
9681
  this.configstrings = new Array(MAX_CONFIGSTRINGS3).fill("");
9597
9682
  this.entities = /* @__PURE__ */ new Map();
9598
9683
  // Current frame entities
9684
+ this.previousEntities = /* @__PURE__ */ new Map();
9685
+ // Previous frame entities
9599
9686
  this.baselines = /* @__PURE__ */ new Map();
9600
9687
  this.previousFrame = null;
9601
9688
  this.latestFrame = null;
@@ -9619,8 +9706,10 @@ var ClientNetworkHandler = class {
9619
9706
  console.log(`Demo: Server Data - Protocol: ${protocol}, Level: ${levelName}, Tick: ${tickRate ?? 10}`);
9620
9707
  this.configstrings.fill("");
9621
9708
  this.entities.clear();
9709
+ this.previousEntities.clear();
9622
9710
  this.baselines.clear();
9623
9711
  this.latestFrame = null;
9712
+ this.previousFrame = null;
9624
9713
  this.playerNum = playerNum;
9625
9714
  if (this.callbacks?.onServerData) {
9626
9715
  this.callbacks.onServerData(protocol, tickRate);
@@ -9638,6 +9727,7 @@ var ClientNetworkHandler = class {
9638
9727
  onFrame(frame) {
9639
9728
  if (this.latestFrame) {
9640
9729
  this.previousFrame = this.latestFrame;
9730
+ this.previousEntities = this.entities;
9641
9731
  }
9642
9732
  this.latestFrame = frame;
9643
9733
  this.stats = [...frame.playerState.stats];
@@ -9948,7 +10038,10 @@ var ClientNetworkHandler = class {
9948
10038
  if (this.previousFrame && timeMs !== void 0) {
9949
10039
  const latestServerTime = this.latestFrame.serverFrame * 100;
9950
10040
  const previousServerTime = this.previousFrame.serverFrame * 100;
9951
- if (timeMs >= previousServerTime && timeMs <= latestServerTime) {
10041
+ if (timeMs <= 1) {
10042
+ const previousState = this.convertFrameToPredictionState(this.previousFrame);
10043
+ return (0, import_cgame.interpolatePredictionState)(previousState, latestState, Math.max(0, Math.min(1, timeMs)));
10044
+ } else if (timeMs >= previousServerTime && timeMs <= latestServerTime) {
9952
10045
  const alpha = (timeMs - previousServerTime) / (latestServerTime - previousServerTime);
9953
10046
  const previousState = this.convertFrameToPredictionState(this.previousFrame);
9954
10047
  return (0, import_cgame.interpolatePredictionState)(previousState, latestState, Math.max(0, Math.min(1, alpha)));
@@ -9956,6 +10049,27 @@ var ClientNetworkHandler = class {
9956
10049
  }
9957
10050
  return latestState;
9958
10051
  }
10052
+ getRenderableEntities(alpha, configStrings) {
10053
+ if (!this.latestFrame) return [];
10054
+ if (!this.imports) return [];
10055
+ const latest = Array.from(this.entities.values());
10056
+ const previous = this.previousEntities.size > 0 ? this.previousEntities : latest;
10057
+ return buildRenderableEntities(
10058
+ latest,
10059
+ previous,
10060
+ alpha,
10061
+ configStrings,
10062
+ this.imports
10063
+ );
10064
+ }
10065
+ getDemoCamera(alpha) {
10066
+ const ps = this.getPredictionState(alpha);
10067
+ return {
10068
+ origin: ps.origin,
10069
+ angles: ps.viewAngles,
10070
+ fov: ps.fov ?? 90
10071
+ };
10072
+ }
9959
10073
  get latestServerFrame() {
9960
10074
  return this.latestFrame?.serverFrame ?? 0;
9961
10075
  }
@@ -10874,82 +10988,6 @@ var WheelMenuSystem = class {
10874
10988
  }
10875
10989
  };
10876
10990
 
10877
- // src/entities.ts
10878
- function lerp2(a, b, t) {
10879
- return a + (b - a) * t;
10880
- }
10881
- function lerpAngle(a, b, t) {
10882
- return lerp2(a, b, t);
10883
- }
10884
- function buildRenderableEntities(latestEntities, previousEntities, alpha, configStrings, imports) {
10885
- const renderables = [];
10886
- const assets = imports.engine.assets;
10887
- if (!assets) return renderables;
10888
- const prevMap = new Map(previousEntities.map((e) => [e.number, e]));
10889
- for (const ent of latestEntities) {
10890
- const prev = prevMap.get(ent.number) ?? ent;
10891
- const modelName = configStrings.getModelName(ent.modelIndex);
10892
- if (!modelName) continue;
10893
- const model = assets.getMd2Model(modelName) || assets.getMd3Model(modelName);
10894
- if (!model) continue;
10895
- const origin = {
10896
- x: lerp2(prev.origin.x, ent.origin.x, alpha),
10897
- y: lerp2(prev.origin.y, ent.origin.y, alpha),
10898
- z: lerp2(prev.origin.z, ent.origin.z, alpha)
10899
- };
10900
- const angles = {
10901
- x: lerpAngle(prev.angles.x, ent.angles.x, alpha),
10902
- y: lerpAngle(prev.angles.y, ent.angles.y, alpha),
10903
- z: lerpAngle(prev.angles.z, ent.angles.z, alpha)
10904
- };
10905
- const frame = ent.frame;
10906
- const prevFrame = prev.frame;
10907
- const scaleA = prev.scale !== void 0 ? prev.scale : 1;
10908
- const scaleB = ent.scale !== void 0 ? ent.scale : 1;
10909
- const scale3 = lerp2(scaleA, scaleB, alpha);
10910
- const getAlpha = (val) => val === void 0 || val === 0 ? 255 : val;
10911
- const alphaA = getAlpha(prev.alpha);
10912
- const alphaB = getAlpha(ent.alpha);
10913
- const alphaVal = lerp2(alphaA, alphaB, alpha);
10914
- const normalizedAlpha = alphaVal / 255;
10915
- const mat = mat4_exports.create();
10916
- mat4_exports.translate(mat, mat, [origin.x, origin.y, origin.z]);
10917
- mat4_exports.rotateZ(mat, mat, angles.z * Math.PI / 180);
10918
- mat4_exports.rotateY(mat, mat, angles.y * Math.PI / 180);
10919
- mat4_exports.rotateX(mat, mat, angles.x * Math.PI / 180);
10920
- mat4_exports.scale(mat, mat, [scale3, scale3, scale3]);
10921
- if (model.header.magic === 844121161) {
10922
- renderables.push({
10923
- type: "md2",
10924
- model,
10925
- // Cast to Md2Model
10926
- blend: {
10927
- frame0: prevFrame,
10928
- frame1: frame,
10929
- lerp: alpha
10930
- },
10931
- transform: mat,
10932
- skin: ent.skinNum > 0 ? configStrings.getImageName(ent.skinNum) : void 0,
10933
- alpha: normalizedAlpha
10934
- });
10935
- } else if (model.header.magic === 860898377) {
10936
- renderables.push({
10937
- type: "md3",
10938
- model,
10939
- blend: {
10940
- frame0: prevFrame,
10941
- frame1: frame,
10942
- lerp: alpha
10943
- },
10944
- transform: mat,
10945
- alpha: normalizedAlpha
10946
- // Lighting? Skins?
10947
- });
10948
- }
10949
- }
10950
- return renderables;
10951
- }
10952
-
10953
10991
  // src/net/browserWsDriver.ts
10954
10992
  var BrowserWebSocketNetDriver = class {
10955
10993
  constructor() {