quake2ts 0.0.297 → 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 (52) hide show
  1. package/package.json +1 -1
  2. package/packages/cgame/dist/index.cjs +55 -2
  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 +56 -3
  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 +76 -19
  11. package/packages/client/dist/cjs/index.cjs.map +1 -1
  12. package/packages/client/dist/esm/index.js +71 -14
  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 +8 -8
  21. package/packages/engine/dist/browser/index.global.js.map +1 -1
  22. package/packages/engine/dist/cjs/index.cjs.map +1 -1
  23. package/packages/engine/dist/esm/index.js.map +1 -1
  24. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
  25. package/packages/game/dist/browser/index.global.js +4 -4
  26. package/packages/game/dist/browser/index.global.js.map +1 -1
  27. package/packages/game/dist/cjs/index.cjs +67 -20
  28. package/packages/game/dist/cjs/index.cjs.map +1 -1
  29. package/packages/game/dist/esm/index.js +67 -20
  30. package/packages/game/dist/esm/index.js.map +1 -1
  31. package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
  32. package/packages/game/dist/types/ai/movement.d.ts.map +1 -1
  33. package/packages/server/dist/index.cjs +9 -2
  34. package/packages/server/dist/index.js +9 -2
  35. package/packages/shared/dist/browser/index.global.js +1 -1
  36. package/packages/shared/dist/browser/index.global.js.map +1 -1
  37. package/packages/shared/dist/cjs/index.cjs +1342 -1038
  38. package/packages/shared/dist/cjs/index.cjs.map +1 -1
  39. package/packages/shared/dist/esm/index.js +1340 -1038
  40. package/packages/shared/dist/esm/index.js.map +1 -1
  41. package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
  42. package/packages/shared/dist/types/pmove/jump.d.ts +2 -0
  43. package/packages/shared/dist/types/pmove/jump.d.ts.map +1 -1
  44. package/packages/shared/dist/types/pmove/move.d.ts +20 -0
  45. package/packages/shared/dist/types/pmove/move.d.ts.map +1 -1
  46. package/packages/shared/dist/types/pmove/pmove.d.ts +5 -1
  47. package/packages/shared/dist/types/pmove/pmove.d.ts.map +1 -1
  48. package/packages/shared/dist/types/pmove/types.d.ts +25 -1
  49. package/packages/shared/dist/types/pmove/types.d.ts.map +1 -1
  50. package/packages/shared/dist/types/protocol/usercmd.d.ts +3 -0
  51. package/packages/shared/dist/types/protocol/usercmd.d.ts.map +1 -1
  52. 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.297",
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,
@@ -1034,7 +1035,9 @@ function simulateCommand(state, cmd, settings, trace, pointContents) {
1034
1035
  forwardmove: cmd.forwardmove,
1035
1036
  sidemove: cmd.sidemove,
1036
1037
  upmove: cmd.upmove,
1037
- buttons: cmd.buttons
1038
+ buttons: cmd.buttons,
1039
+ angles: cmd.angles
1040
+ // Added missing property
1038
1041
  };
1039
1042
  const newState = shared.applyPmove(state, pmoveCmd, trace, pointContents);
1040
1043
  const { viewangles } = shared.clampViewAngles({
@@ -1056,6 +1059,7 @@ var ClientPrediction = class {
1056
1059
  };
1057
1060
  this.commands = [];
1058
1061
  this.predicted = defaultPredictionState();
1062
+ this.predictionError = ZERO_VEC32;
1059
1063
  this.settings = { ...DEFAULTS, ...settings };
1060
1064
  this.trace = trace;
1061
1065
  this.pointContents = pointContents;
@@ -1063,14 +1067,57 @@ var ClientPrediction = class {
1063
1067
  }
1064
1068
  setAuthoritative(frame) {
1065
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
+ }
1066
1095
  this.baseFrame = { ...frame, state: normalized };
1067
- 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);
1068
1097
  return this.recompute();
1069
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
+ }
1070
1111
  enqueueCommand(cmd) {
1071
1112
  this.commands.push(cmd);
1113
+ if (this.commands.length > CMD_BACKUP) {
1114
+ this.commands.shift();
1115
+ }
1072
1116
  return this.recompute();
1073
1117
  }
1118
+ getCommand(sequence) {
1119
+ return this.commands.find((c) => c.sequence === sequence);
1120
+ }
1074
1121
  getPredictedState() {
1075
1122
  return this.predicted;
1076
1123
  }
@@ -1086,6 +1133,7 @@ var ClientPrediction = class {
1086
1133
 
1087
1134
  // src/index.ts
1088
1135
  var cgi2 = null;
1136
+ var cg_predict = null;
1089
1137
  function Init() {
1090
1138
  if (!cgi2) {
1091
1139
  console.error("CGame Init: cgame imports not set");
@@ -1093,6 +1141,8 @@ function Init() {
1093
1141
  }
1094
1142
  cgi2.Com_Print("===== CGame Initialization =====\n");
1095
1143
  CG_InitScreen(cgi2);
1144
+ cg_predict = cgi2.Cvar_Get("cg_predict", "1", 0);
1145
+ cgi2.Cvar_Get("cg_showmiss", "0", 0);
1096
1146
  cgi2.Com_Print("CGame initialized\n");
1097
1147
  }
1098
1148
  function Shutdown() {
@@ -1154,6 +1204,9 @@ function Pmove(pmove) {
1154
1204
  if (!pm || !pm.s || !pm.cmd || !cgi2) {
1155
1205
  return;
1156
1206
  }
1207
+ if (cg_predict && cg_predict.value === 0) {
1208
+ return;
1209
+ }
1157
1210
  const traceAdapter = (start, end, mins, maxs) => {
1158
1211
  const zero2 = { x: 0, y: 0, z: 0 };
1159
1212
  return cgi2.PM_Trace(