quake2ts 0.0.286 → 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.
- package/package.json +1 -1
- package/packages/client/dist/browser/index.global.js +9 -9
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs +115 -77
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js +115 -77
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/client/dist/types/demo/handler.d.ts +9 -1
- package/packages/client/dist/types/demo/handler.d.ts.map +1 -1
- package/packages/client/dist/types/entities.d.ts +22 -2
- package/packages/client/dist/types/entities.d.ts.map +1 -1
|
@@ -9557,6 +9557,91 @@ var DEMO_ITEM_MAPPING = [
|
|
|
9557
9557
|
// IT_ITEM_COMPASS
|
|
9558
9558
|
];
|
|
9559
9559
|
|
|
9560
|
+
// src/entities.ts
|
|
9561
|
+
function lerp2(a, b, t) {
|
|
9562
|
+
return a + (b - a) * t;
|
|
9563
|
+
}
|
|
9564
|
+
function lerpAngle(a, b, t) {
|
|
9565
|
+
return lerp2(a, b, t);
|
|
9566
|
+
}
|
|
9567
|
+
function buildRenderableEntities(latestEntities, previousEntities, alpha, configStrings, imports) {
|
|
9568
|
+
const renderables = [];
|
|
9569
|
+
const assets = imports.engine.assets;
|
|
9570
|
+
if (!assets) return renderables;
|
|
9571
|
+
let prevMap;
|
|
9572
|
+
if (previousEntities instanceof Map) {
|
|
9573
|
+
prevMap = previousEntities;
|
|
9574
|
+
} else {
|
|
9575
|
+
prevMap = new Map(previousEntities.map((e) => [e.number, e]));
|
|
9576
|
+
}
|
|
9577
|
+
for (const ent of latestEntities) {
|
|
9578
|
+
const prev = prevMap.get(ent.number) ?? ent;
|
|
9579
|
+
const modelIndex = ent.modelIndex ?? ent.modelindex;
|
|
9580
|
+
const skinNum = ent.skinNum ?? ent.skinnum;
|
|
9581
|
+
if (modelIndex === void 0) continue;
|
|
9582
|
+
const modelName = configStrings.getModelName(modelIndex);
|
|
9583
|
+
if (!modelName) continue;
|
|
9584
|
+
const model = assets.getMd2Model(modelName) || assets.getMd3Model(modelName);
|
|
9585
|
+
if (!model) continue;
|
|
9586
|
+
const origin = {
|
|
9587
|
+
x: lerp2(prev.origin.x, ent.origin.x, alpha),
|
|
9588
|
+
y: lerp2(prev.origin.y, ent.origin.y, alpha),
|
|
9589
|
+
z: lerp2(prev.origin.z, ent.origin.z, alpha)
|
|
9590
|
+
};
|
|
9591
|
+
const angles = {
|
|
9592
|
+
x: lerpAngle(prev.angles.x, ent.angles.x, alpha),
|
|
9593
|
+
y: lerpAngle(prev.angles.y, ent.angles.y, alpha),
|
|
9594
|
+
z: lerpAngle(prev.angles.z, ent.angles.z, alpha)
|
|
9595
|
+
};
|
|
9596
|
+
const frame = ent.frame;
|
|
9597
|
+
const prevFrame = prev.frame;
|
|
9598
|
+
const scaleA = prev.scale !== void 0 ? prev.scale : 1;
|
|
9599
|
+
const scaleB = ent.scale !== void 0 ? ent.scale : 1;
|
|
9600
|
+
const scale3 = lerp2(scaleA, scaleB, alpha);
|
|
9601
|
+
const getAlpha = (val) => val === void 0 || val === 0 ? 255 : val;
|
|
9602
|
+
const alphaA = getAlpha(prev.alpha);
|
|
9603
|
+
const alphaB = getAlpha(ent.alpha);
|
|
9604
|
+
const alphaVal = lerp2(alphaA, alphaB, alpha);
|
|
9605
|
+
const normalizedAlpha = alphaVal / 255;
|
|
9606
|
+
const mat = mat4_exports.create();
|
|
9607
|
+
mat4_exports.translate(mat, mat, [origin.x, origin.y, origin.z]);
|
|
9608
|
+
mat4_exports.rotateZ(mat, mat, angles.z * Math.PI / 180);
|
|
9609
|
+
mat4_exports.rotateY(mat, mat, angles.y * Math.PI / 180);
|
|
9610
|
+
mat4_exports.rotateX(mat, mat, angles.x * Math.PI / 180);
|
|
9611
|
+
mat4_exports.scale(mat, mat, [scale3, scale3, scale3]);
|
|
9612
|
+
const skinName = skinNum !== void 0 && skinNum > 0 ? configStrings.getImageName(skinNum) : void 0;
|
|
9613
|
+
if (model.header.magic === 844121161) {
|
|
9614
|
+
renderables.push({
|
|
9615
|
+
type: "md2",
|
|
9616
|
+
model,
|
|
9617
|
+
// Cast to Md2Model
|
|
9618
|
+
blend: {
|
|
9619
|
+
frame0: prevFrame,
|
|
9620
|
+
frame1: frame,
|
|
9621
|
+
lerp: alpha
|
|
9622
|
+
},
|
|
9623
|
+
transform: mat,
|
|
9624
|
+
skin: skinName,
|
|
9625
|
+
alpha: normalizedAlpha
|
|
9626
|
+
});
|
|
9627
|
+
} else if (model.header.magic === 860898377) {
|
|
9628
|
+
renderables.push({
|
|
9629
|
+
type: "md3",
|
|
9630
|
+
model,
|
|
9631
|
+
blend: {
|
|
9632
|
+
frame0: prevFrame,
|
|
9633
|
+
frame1: frame,
|
|
9634
|
+
lerp: alpha
|
|
9635
|
+
},
|
|
9636
|
+
transform: mat,
|
|
9637
|
+
alpha: normalizedAlpha
|
|
9638
|
+
// Lighting? Skins?
|
|
9639
|
+
});
|
|
9640
|
+
}
|
|
9641
|
+
}
|
|
9642
|
+
return renderables;
|
|
9643
|
+
}
|
|
9644
|
+
|
|
9560
9645
|
// src/demo/handler.ts
|
|
9561
9646
|
var MAX_CONFIGSTRINGS3 = 32768;
|
|
9562
9647
|
var ClientNetworkHandler = class {
|
|
@@ -9564,6 +9649,8 @@ var ClientNetworkHandler = class {
|
|
|
9564
9649
|
this.configstrings = new Array(MAX_CONFIGSTRINGS3).fill("");
|
|
9565
9650
|
this.entities = /* @__PURE__ */ new Map();
|
|
9566
9651
|
// Current frame entities
|
|
9652
|
+
this.previousEntities = /* @__PURE__ */ new Map();
|
|
9653
|
+
// Previous frame entities
|
|
9567
9654
|
this.baselines = /* @__PURE__ */ new Map();
|
|
9568
9655
|
this.previousFrame = null;
|
|
9569
9656
|
this.latestFrame = null;
|
|
@@ -9587,8 +9674,10 @@ var ClientNetworkHandler = class {
|
|
|
9587
9674
|
console.log(`Demo: Server Data - Protocol: ${protocol}, Level: ${levelName}, Tick: ${tickRate ?? 10}`);
|
|
9588
9675
|
this.configstrings.fill("");
|
|
9589
9676
|
this.entities.clear();
|
|
9677
|
+
this.previousEntities.clear();
|
|
9590
9678
|
this.baselines.clear();
|
|
9591
9679
|
this.latestFrame = null;
|
|
9680
|
+
this.previousFrame = null;
|
|
9592
9681
|
this.playerNum = playerNum;
|
|
9593
9682
|
if (this.callbacks?.onServerData) {
|
|
9594
9683
|
this.callbacks.onServerData(protocol, tickRate);
|
|
@@ -9606,6 +9695,7 @@ var ClientNetworkHandler = class {
|
|
|
9606
9695
|
onFrame(frame) {
|
|
9607
9696
|
if (this.latestFrame) {
|
|
9608
9697
|
this.previousFrame = this.latestFrame;
|
|
9698
|
+
this.previousEntities = this.entities;
|
|
9609
9699
|
}
|
|
9610
9700
|
this.latestFrame = frame;
|
|
9611
9701
|
this.stats = [...frame.playerState.stats];
|
|
@@ -9916,7 +10006,10 @@ var ClientNetworkHandler = class {
|
|
|
9916
10006
|
if (this.previousFrame && timeMs !== void 0) {
|
|
9917
10007
|
const latestServerTime = this.latestFrame.serverFrame * 100;
|
|
9918
10008
|
const previousServerTime = this.previousFrame.serverFrame * 100;
|
|
9919
|
-
if (timeMs
|
|
10009
|
+
if (timeMs <= 1) {
|
|
10010
|
+
const previousState = this.convertFrameToPredictionState(this.previousFrame);
|
|
10011
|
+
return interpolatePredictionState(previousState, latestState, Math.max(0, Math.min(1, timeMs)));
|
|
10012
|
+
} else if (timeMs >= previousServerTime && timeMs <= latestServerTime) {
|
|
9920
10013
|
const alpha = (timeMs - previousServerTime) / (latestServerTime - previousServerTime);
|
|
9921
10014
|
const previousState = this.convertFrameToPredictionState(this.previousFrame);
|
|
9922
10015
|
return interpolatePredictionState(previousState, latestState, Math.max(0, Math.min(1, alpha)));
|
|
@@ -9924,6 +10017,27 @@ var ClientNetworkHandler = class {
|
|
|
9924
10017
|
}
|
|
9925
10018
|
return latestState;
|
|
9926
10019
|
}
|
|
10020
|
+
getRenderableEntities(alpha, configStrings) {
|
|
10021
|
+
if (!this.latestFrame) return [];
|
|
10022
|
+
if (!this.imports) return [];
|
|
10023
|
+
const latest = Array.from(this.entities.values());
|
|
10024
|
+
const previous = this.previousEntities.size > 0 ? this.previousEntities : latest;
|
|
10025
|
+
return buildRenderableEntities(
|
|
10026
|
+
latest,
|
|
10027
|
+
previous,
|
|
10028
|
+
alpha,
|
|
10029
|
+
configStrings,
|
|
10030
|
+
this.imports
|
|
10031
|
+
);
|
|
10032
|
+
}
|
|
10033
|
+
getDemoCamera(alpha) {
|
|
10034
|
+
const ps = this.getPredictionState(alpha);
|
|
10035
|
+
return {
|
|
10036
|
+
origin: ps.origin,
|
|
10037
|
+
angles: ps.viewAngles,
|
|
10038
|
+
fov: ps.fov ?? 90
|
|
10039
|
+
};
|
|
10040
|
+
}
|
|
9927
10041
|
get latestServerFrame() {
|
|
9928
10042
|
return this.latestFrame?.serverFrame ?? 0;
|
|
9929
10043
|
}
|
|
@@ -10842,82 +10956,6 @@ var WheelMenuSystem = class {
|
|
|
10842
10956
|
}
|
|
10843
10957
|
};
|
|
10844
10958
|
|
|
10845
|
-
// src/entities.ts
|
|
10846
|
-
function lerp2(a, b, t) {
|
|
10847
|
-
return a + (b - a) * t;
|
|
10848
|
-
}
|
|
10849
|
-
function lerpAngle(a, b, t) {
|
|
10850
|
-
return lerp2(a, b, t);
|
|
10851
|
-
}
|
|
10852
|
-
function buildRenderableEntities(latestEntities, previousEntities, alpha, configStrings, imports) {
|
|
10853
|
-
const renderables = [];
|
|
10854
|
-
const assets = imports.engine.assets;
|
|
10855
|
-
if (!assets) return renderables;
|
|
10856
|
-
const prevMap = new Map(previousEntities.map((e) => [e.number, e]));
|
|
10857
|
-
for (const ent of latestEntities) {
|
|
10858
|
-
const prev = prevMap.get(ent.number) ?? ent;
|
|
10859
|
-
const modelName = configStrings.getModelName(ent.modelIndex);
|
|
10860
|
-
if (!modelName) continue;
|
|
10861
|
-
const model = assets.getMd2Model(modelName) || assets.getMd3Model(modelName);
|
|
10862
|
-
if (!model) continue;
|
|
10863
|
-
const origin = {
|
|
10864
|
-
x: lerp2(prev.origin.x, ent.origin.x, alpha),
|
|
10865
|
-
y: lerp2(prev.origin.y, ent.origin.y, alpha),
|
|
10866
|
-
z: lerp2(prev.origin.z, ent.origin.z, alpha)
|
|
10867
|
-
};
|
|
10868
|
-
const angles = {
|
|
10869
|
-
x: lerpAngle(prev.angles.x, ent.angles.x, alpha),
|
|
10870
|
-
y: lerpAngle(prev.angles.y, ent.angles.y, alpha),
|
|
10871
|
-
z: lerpAngle(prev.angles.z, ent.angles.z, alpha)
|
|
10872
|
-
};
|
|
10873
|
-
const frame = ent.frame;
|
|
10874
|
-
const prevFrame = prev.frame;
|
|
10875
|
-
const scaleA = prev.scale !== void 0 ? prev.scale : 1;
|
|
10876
|
-
const scaleB = ent.scale !== void 0 ? ent.scale : 1;
|
|
10877
|
-
const scale3 = lerp2(scaleA, scaleB, alpha);
|
|
10878
|
-
const getAlpha = (val) => val === void 0 || val === 0 ? 255 : val;
|
|
10879
|
-
const alphaA = getAlpha(prev.alpha);
|
|
10880
|
-
const alphaB = getAlpha(ent.alpha);
|
|
10881
|
-
const alphaVal = lerp2(alphaA, alphaB, alpha);
|
|
10882
|
-
const normalizedAlpha = alphaVal / 255;
|
|
10883
|
-
const mat = mat4_exports.create();
|
|
10884
|
-
mat4_exports.translate(mat, mat, [origin.x, origin.y, origin.z]);
|
|
10885
|
-
mat4_exports.rotateZ(mat, mat, angles.z * Math.PI / 180);
|
|
10886
|
-
mat4_exports.rotateY(mat, mat, angles.y * Math.PI / 180);
|
|
10887
|
-
mat4_exports.rotateX(mat, mat, angles.x * Math.PI / 180);
|
|
10888
|
-
mat4_exports.scale(mat, mat, [scale3, scale3, scale3]);
|
|
10889
|
-
if (model.header.magic === 844121161) {
|
|
10890
|
-
renderables.push({
|
|
10891
|
-
type: "md2",
|
|
10892
|
-
model,
|
|
10893
|
-
// Cast to Md2Model
|
|
10894
|
-
blend: {
|
|
10895
|
-
frame0: prevFrame,
|
|
10896
|
-
frame1: frame,
|
|
10897
|
-
lerp: alpha
|
|
10898
|
-
},
|
|
10899
|
-
transform: mat,
|
|
10900
|
-
skin: ent.skinNum > 0 ? configStrings.getImageName(ent.skinNum) : void 0,
|
|
10901
|
-
alpha: normalizedAlpha
|
|
10902
|
-
});
|
|
10903
|
-
} else if (model.header.magic === 860898377) {
|
|
10904
|
-
renderables.push({
|
|
10905
|
-
type: "md3",
|
|
10906
|
-
model,
|
|
10907
|
-
blend: {
|
|
10908
|
-
frame0: prevFrame,
|
|
10909
|
-
frame1: frame,
|
|
10910
|
-
lerp: alpha
|
|
10911
|
-
},
|
|
10912
|
-
transform: mat,
|
|
10913
|
-
alpha: normalizedAlpha
|
|
10914
|
-
// Lighting? Skins?
|
|
10915
|
-
});
|
|
10916
|
-
}
|
|
10917
|
-
}
|
|
10918
|
-
return renderables;
|
|
10919
|
-
}
|
|
10920
|
-
|
|
10921
10959
|
// src/net/browserWsDriver.ts
|
|
10922
10960
|
var BrowserWebSocketNetDriver = class {
|
|
10923
10961
|
constructor() {
|