quake2ts 0.0.268 → 0.0.270

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quake2ts",
3
- "version": "0.0.268",
3
+ "version": "0.0.270",
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,7 +930,6 @@ var DEFAULTS = {
930
930
  };
931
931
  var DEFAULT_GRAVITY = 800;
932
932
  var ZERO_VEC32 = { x: 0, y: 0, z: 0 };
933
- var MSEC_MAX = 250;
934
933
  function defaultPredictionState() {
935
934
  return {
936
935
  origin: ZERO_VEC32,
@@ -1030,69 +1029,26 @@ function interpolatePredictionState(previous, latest, alpha) {
1030
1029
  ammo: lerp2(previous.ammo || 0, latest.ammo || 0, clamped)
1031
1030
  };
1032
1031
  }
1033
- function simulateCommand(state, cmd, settings, trace) {
1034
- const frametime = Math.min(Math.max(cmd.msec, 0), MSEC_MAX) / 1e3;
1035
- const onGround = shared.hasPmFlag(state.pmFlags, shared.PmFlag.OnGround);
1036
- const onLadder = shared.hasPmFlag(state.pmFlags, shared.PmFlag.OnLadder);
1037
- let velocity = shared.applyPmoveFriction({
1038
- velocity: state.velocity,
1039
- frametime,
1040
- onGround,
1041
- groundIsSlick: settings.groundIsSlick,
1042
- onLadder,
1043
- waterlevel: state.waterLevel,
1044
- pmFriction: settings.pmFriction,
1045
- pmStopSpeed: settings.pmStopSpeed,
1046
- pmWaterFriction: settings.pmWaterFriction
1047
- });
1048
- const { viewangles, forward, right } = shared.clampViewAngles({
1032
+ function simulateCommand(state, cmd, settings, trace, pointContents) {
1033
+ const pmoveCmd = {
1034
+ forwardmove: cmd.forwardmove,
1035
+ sidemove: cmd.sidemove,
1036
+ upmove: cmd.upmove,
1037
+ buttons: cmd.buttons
1038
+ };
1039
+ const newState = shared.applyPmove(state, pmoveCmd, trace, pointContents);
1040
+ const { viewangles } = shared.clampViewAngles({
1049
1041
  pmFlags: state.pmFlags,
1050
1042
  cmdAngles: cmd.angles,
1051
1043
  deltaAngles: state.deltaAngles ?? ZERO_VEC32
1052
1044
  });
1053
- const wish = state.waterLevel > shared.WaterLevel.None ? shared.buildWaterWish({ forward, right, cmd, maxSpeed: settings.pmWaterSpeed }) : shared.buildAirGroundWish({ forward, right, cmd, maxSpeed: settings.pmMaxSpeed });
1054
- if (state.waterLevel > shared.WaterLevel.None) {
1055
- velocity = shared.applyPmoveAccelerate({
1056
- velocity,
1057
- wishdir: wish.wishdir,
1058
- wishspeed: wish.wishspeed,
1059
- accel: settings.pmWaterAccelerate,
1060
- frametime
1061
- });
1062
- } else if (onGround || onLadder) {
1063
- const maxSpeed = shared.hasPmFlag(state.pmFlags, shared.PmFlag.Ducked) ? settings.pmDuckSpeed : settings.pmMaxSpeed;
1064
- const clampedWish = wish.wishspeed > maxSpeed ? {
1065
- wishdir: wish.wishdir,
1066
- wishspeed: maxSpeed
1067
- } : wish;
1068
- velocity = shared.applyPmoveAccelerate({
1069
- velocity,
1070
- wishdir: clampedWish.wishdir,
1071
- wishspeed: clampedWish.wishspeed,
1072
- accel: settings.pmAccelerate,
1073
- frametime
1074
- });
1075
- } else {
1076
- velocity = shared.applyPmoveAirAccelerate({
1077
- velocity,
1078
- wishdir: wish.wishdir,
1079
- wishspeed: wish.wishspeed,
1080
- accel: settings.pmAirAccelerate,
1081
- frametime
1082
- });
1083
- velocity = { ...velocity, z: velocity.z - (state.gravity ?? DEFAULT_GRAVITY) * frametime };
1084
- }
1085
- const traceResult = trace(state.origin, shared.addVec3(state.origin, shared.scaleVec3(velocity, frametime)));
1086
- const origin = traceResult.endpos;
1087
1045
  return {
1088
- ...state,
1089
- origin,
1090
- velocity,
1046
+ ...newState,
1091
1047
  viewAngles: viewangles
1092
1048
  };
1093
1049
  }
1094
1050
  var ClientPrediction = class {
1095
- constructor(trace, settings = {}) {
1051
+ constructor(trace, pointContents, settings = {}) {
1096
1052
  this.baseFrame = {
1097
1053
  frame: 0,
1098
1054
  timeMs: 0,
@@ -1102,6 +1058,7 @@ var ClientPrediction = class {
1102
1058
  this.predicted = defaultPredictionState();
1103
1059
  this.settings = { ...DEFAULTS, ...settings };
1104
1060
  this.trace = trace;
1061
+ this.pointContents = pointContents;
1105
1062
  this.predicted = this.baseFrame.state ?? defaultPredictionState();
1106
1063
  }
1107
1064
  setAuthoritative(frame) {
@@ -1120,7 +1077,7 @@ var ClientPrediction = class {
1120
1077
  recompute() {
1121
1078
  let state = normalizeState(this.baseFrame.state);
1122
1079
  for (const cmd of this.commands) {
1123
- state = simulateCommand(state, cmd, this.settings, this.trace);
1080
+ state = simulateCommand(state, cmd, this.settings, this.trace, this.pointContents);
1124
1081
  }
1125
1082
  this.predicted = state;
1126
1083
  return state;