quake2ts 0.0.298 → 0.0.299

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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/packages/cgame/dist/index.cjs +52 -1
  3. package/packages/cgame/dist/index.cjs.map +1 -1
  4. package/packages/cgame/dist/index.d.cts +7 -0
  5. package/packages/cgame/dist/index.d.ts +7 -0
  6. package/packages/cgame/dist/index.js +53 -2
  7. package/packages/cgame/dist/index.js.map +1 -1
  8. package/packages/client/dist/browser/index.global.js +13 -13
  9. package/packages/client/dist/browser/index.global.js.map +1 -1
  10. package/packages/client/dist/cjs/index.cjs +67 -10
  11. package/packages/client/dist/cjs/index.cjs.map +1 -1
  12. package/packages/client/dist/esm/index.js +62 -5
  13. package/packages/client/dist/esm/index.js.map +1 -1
  14. package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
  15. package/packages/client/dist/types/cgameBridge.d.ts.map +1 -1
  16. package/packages/client/dist/types/input/controller.d.ts +1 -0
  17. package/packages/client/dist/types/input/controller.d.ts.map +1 -1
  18. package/packages/client/dist/types/net/connection.d.ts +3 -0
  19. package/packages/client/dist/types/net/connection.d.ts.map +1 -1
  20. package/packages/engine/dist/browser/index.global.js.map +1 -1
  21. package/packages/engine/dist/cjs/index.cjs.map +1 -1
  22. package/packages/engine/dist/esm/index.js.map +1 -1
  23. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
  24. package/packages/game/dist/browser/index.global.js.map +1 -1
  25. package/packages/game/dist/cjs/index.cjs.map +1 -1
  26. package/packages/game/dist/esm/index.js.map +1 -1
  27. package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
  28. package/packages/server/dist/index.cjs +9 -2
  29. package/packages/server/dist/index.js +9 -2
  30. package/packages/shared/dist/browser/index.global.js.map +1 -1
  31. package/packages/shared/dist/cjs/index.cjs.map +1 -1
  32. package/packages/shared/dist/esm/index.js.map +1 -1
  33. package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
  34. package/packages/shared/dist/types/protocol/usercmd.d.ts +3 -0
  35. package/packages/shared/dist/types/protocol/usercmd.d.ts.map +1 -1
  36. package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quake2ts",
3
- "version": "0.0.298",
3
+ "version": "0.0.299",
4
4
  "description": "Quake II re-release port to TypeScript with WebGL renderer - A complete game engine with physics, networking, and BSP rendering",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@8.15.7",
@@ -930,6 +930,7 @@ var DEFAULTS = {
930
930
  };
931
931
  var DEFAULT_GRAVITY = 800;
932
932
  var ZERO_VEC32 = { x: 0, y: 0, z: 0 };
933
+ var CMD_BACKUP = 64;
933
934
  function defaultPredictionState() {
934
935
  return {
935
936
  origin: ZERO_VEC32,
@@ -1058,6 +1059,7 @@ var ClientPrediction = class {
1058
1059
  };
1059
1060
  this.commands = [];
1060
1061
  this.predicted = defaultPredictionState();
1062
+ this.predictionError = ZERO_VEC32;
1061
1063
  this.settings = { ...DEFAULTS, ...settings };
1062
1064
  this.trace = trace;
1063
1065
  this.pointContents = pointContents;
@@ -1065,14 +1067,57 @@ var ClientPrediction = class {
1065
1067
  }
1066
1068
  setAuthoritative(frame) {
1067
1069
  const normalized = normalizeState(frame.state);
1070
+ if (frame.frame <= this.baseFrame.frame) {
1071
+ return this.predicted;
1072
+ }
1073
+ let predictedAtFrame;
1074
+ const relevantCommands = this.commands.filter((c) => c.sequence <= frame.frame && c.sequence > this.baseFrame.frame);
1075
+ if (relevantCommands.length > 0 || this.baseFrame.frame === frame.frame) {
1076
+ let tempState = normalizeState(this.baseFrame.state);
1077
+ for (const cmd of relevantCommands) {
1078
+ tempState = simulateCommand(tempState, cmd, this.settings, this.trace, this.pointContents);
1079
+ }
1080
+ predictedAtFrame = tempState;
1081
+ }
1082
+ if (predictedAtFrame) {
1083
+ const error = shared.subtractVec3(predictedAtFrame.origin, normalized.origin);
1084
+ const errorLen = shared.lengthVec3(error);
1085
+ if (errorLen > 10) {
1086
+ this.predictionError = ZERO_VEC32;
1087
+ } else if (errorLen > 0.1) {
1088
+ this.predictionError = error;
1089
+ } else {
1090
+ this.predictionError = ZERO_VEC32;
1091
+ }
1092
+ } else {
1093
+ this.predictionError = ZERO_VEC32;
1094
+ }
1068
1095
  this.baseFrame = { ...frame, state: normalized };
1069
- this.commands = this.commands.filter((cmd) => (cmd.serverFrame ?? Number.MAX_SAFE_INTEGER) > frame.frame);
1096
+ this.commands = this.commands.filter((cmd) => cmd.sequence > frame.frame);
1070
1097
  return this.recompute();
1071
1098
  }
1099
+ getPredictionError() {
1100
+ return this.predictionError;
1101
+ }
1102
+ // Decay error over time - usually called once per client frame
1103
+ decayError(frametime) {
1104
+ const len2 = shared.lengthVec3(this.predictionError);
1105
+ if (len2 > 0) {
1106
+ const decay = len2 * 10 * frametime;
1107
+ const scale2 = Math.max(0, len2 - decay) / len2;
1108
+ this.predictionError = shared.scaleVec3(this.predictionError, scale2);
1109
+ }
1110
+ }
1072
1111
  enqueueCommand(cmd) {
1073
1112
  this.commands.push(cmd);
1113
+ if (this.commands.length > CMD_BACKUP) {
1114
+ this.commands.shift();
1115
+ }
1074
1116
  return this.recompute();
1075
1117
  }
1118
+ getCommand(sequence) {
1119
+ return this.commands.find((c) => c.sequence === sequence);
1120
+ }
1076
1121
  getPredictedState() {
1077
1122
  return this.predicted;
1078
1123
  }
@@ -1088,6 +1133,7 @@ var ClientPrediction = class {
1088
1133
 
1089
1134
  // src/index.ts
1090
1135
  var cgi2 = null;
1136
+ var cg_predict = null;
1091
1137
  function Init() {
1092
1138
  if (!cgi2) {
1093
1139
  console.error("CGame Init: cgame imports not set");
@@ -1095,6 +1141,8 @@ function Init() {
1095
1141
  }
1096
1142
  cgi2.Com_Print("===== CGame Initialization =====\n");
1097
1143
  CG_InitScreen(cgi2);
1144
+ cg_predict = cgi2.Cvar_Get("cg_predict", "1", 0);
1145
+ cgi2.Cvar_Get("cg_showmiss", "0", 0);
1098
1146
  cgi2.Com_Print("CGame initialized\n");
1099
1147
  }
1100
1148
  function Shutdown() {
@@ -1156,6 +1204,9 @@ function Pmove(pmove) {
1156
1204
  if (!pm || !pm.s || !pm.cmd || !cgi2) {
1157
1205
  return;
1158
1206
  }
1207
+ if (cg_predict && cg_predict.value === 0) {
1208
+ return;
1209
+ }
1159
1210
  const traceAdapter = (start, end, mins, maxs) => {
1160
1211
  const zero2 = { x: 0, y: 0, z: 0 };
1161
1212
  return cgi2.PM_Trace(