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.
@@ -115,10 +115,11 @@ declare function interpolatePredictionState(previous: PredictionState, latest: P
115
115
  declare class ClientPrediction {
116
116
  private readonly settings;
117
117
  private readonly trace;
118
+ private readonly pointContents;
118
119
  private baseFrame;
119
120
  private commands;
120
121
  private predicted;
121
- constructor(trace: PmoveTraceFn, settings?: Partial<PredictionSettings>);
122
+ constructor(trace: PmoveTraceFn, pointContents: (p: Vec3) => number, settings?: Partial<PredictionSettings>);
122
123
  setAuthoritative(frame: GameFrameResult<PredictionState>): PredictionState;
123
124
  enqueueCommand(cmd: UserCommand): PredictionState;
124
125
  getPredictedState(): PredictionState;
@@ -1,4 +1,4 @@
1
- import { angleVectors, clampViewAngles, ZERO_VEC3, hasPmFlag, PmFlag, dotVec3, PmType, WaterLevel, angleMod, applyPmoveFriction, buildWaterWish, buildAirGroundWish, applyPmoveAccelerate, applyPmoveAirAccelerate, addVec3, scaleVec3, applyPmove, ConfigStringIndex, MAX_MODELS, MAX_SOUNDS, MAX_IMAGES, PlayerStat } from '@quake2ts/shared';
1
+ import { angleVectors, clampViewAngles, ZERO_VEC3, hasPmFlag, PmFlag, dotVec3, PmType, WaterLevel, angleMod, applyPmove, ConfigStringIndex, MAX_MODELS, MAX_SOUNDS, MAX_IMAGES, PlayerStat } from '@quake2ts/shared';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __export = (target, all) => {
@@ -928,7 +928,6 @@ var DEFAULTS = {
928
928
  };
929
929
  var DEFAULT_GRAVITY = 800;
930
930
  var ZERO_VEC32 = { x: 0, y: 0, z: 0 };
931
- var MSEC_MAX = 250;
932
931
  function defaultPredictionState() {
933
932
  return {
934
933
  origin: ZERO_VEC32,
@@ -1028,69 +1027,26 @@ function interpolatePredictionState(previous, latest, alpha) {
1028
1027
  ammo: lerp2(previous.ammo || 0, latest.ammo || 0, clamped)
1029
1028
  };
1030
1029
  }
1031
- function simulateCommand(state, cmd, settings, trace) {
1032
- const frametime = Math.min(Math.max(cmd.msec, 0), MSEC_MAX) / 1e3;
1033
- const onGround = hasPmFlag(state.pmFlags, PmFlag.OnGround);
1034
- const onLadder = hasPmFlag(state.pmFlags, PmFlag.OnLadder);
1035
- let velocity = applyPmoveFriction({
1036
- velocity: state.velocity,
1037
- frametime,
1038
- onGround,
1039
- groundIsSlick: settings.groundIsSlick,
1040
- onLadder,
1041
- waterlevel: state.waterLevel,
1042
- pmFriction: settings.pmFriction,
1043
- pmStopSpeed: settings.pmStopSpeed,
1044
- pmWaterFriction: settings.pmWaterFriction
1045
- });
1046
- const { viewangles, forward, right } = clampViewAngles({
1030
+ function simulateCommand(state, cmd, settings, trace, pointContents) {
1031
+ const pmoveCmd = {
1032
+ forwardmove: cmd.forwardmove,
1033
+ sidemove: cmd.sidemove,
1034
+ upmove: cmd.upmove,
1035
+ buttons: cmd.buttons
1036
+ };
1037
+ const newState = applyPmove(state, pmoveCmd, trace, pointContents);
1038
+ const { viewangles } = clampViewAngles({
1047
1039
  pmFlags: state.pmFlags,
1048
1040
  cmdAngles: cmd.angles,
1049
1041
  deltaAngles: state.deltaAngles ?? ZERO_VEC32
1050
1042
  });
1051
- const wish = state.waterLevel > WaterLevel.None ? buildWaterWish({ forward, right, cmd, maxSpeed: settings.pmWaterSpeed }) : buildAirGroundWish({ forward, right, cmd, maxSpeed: settings.pmMaxSpeed });
1052
- if (state.waterLevel > WaterLevel.None) {
1053
- velocity = applyPmoveAccelerate({
1054
- velocity,
1055
- wishdir: wish.wishdir,
1056
- wishspeed: wish.wishspeed,
1057
- accel: settings.pmWaterAccelerate,
1058
- frametime
1059
- });
1060
- } else if (onGround || onLadder) {
1061
- const maxSpeed = hasPmFlag(state.pmFlags, PmFlag.Ducked) ? settings.pmDuckSpeed : settings.pmMaxSpeed;
1062
- const clampedWish = wish.wishspeed > maxSpeed ? {
1063
- wishdir: wish.wishdir,
1064
- wishspeed: maxSpeed
1065
- } : wish;
1066
- velocity = applyPmoveAccelerate({
1067
- velocity,
1068
- wishdir: clampedWish.wishdir,
1069
- wishspeed: clampedWish.wishspeed,
1070
- accel: settings.pmAccelerate,
1071
- frametime
1072
- });
1073
- } else {
1074
- velocity = applyPmoveAirAccelerate({
1075
- velocity,
1076
- wishdir: wish.wishdir,
1077
- wishspeed: wish.wishspeed,
1078
- accel: settings.pmAirAccelerate,
1079
- frametime
1080
- });
1081
- velocity = { ...velocity, z: velocity.z - (state.gravity ?? DEFAULT_GRAVITY) * frametime };
1082
- }
1083
- const traceResult = trace(state.origin, addVec3(state.origin, scaleVec3(velocity, frametime)));
1084
- const origin = traceResult.endpos;
1085
1043
  return {
1086
- ...state,
1087
- origin,
1088
- velocity,
1044
+ ...newState,
1089
1045
  viewAngles: viewangles
1090
1046
  };
1091
1047
  }
1092
1048
  var ClientPrediction = class {
1093
- constructor(trace, settings = {}) {
1049
+ constructor(trace, pointContents, settings = {}) {
1094
1050
  this.baseFrame = {
1095
1051
  frame: 0,
1096
1052
  timeMs: 0,
@@ -1100,6 +1056,7 @@ var ClientPrediction = class {
1100
1056
  this.predicted = defaultPredictionState();
1101
1057
  this.settings = { ...DEFAULTS, ...settings };
1102
1058
  this.trace = trace;
1059
+ this.pointContents = pointContents;
1103
1060
  this.predicted = this.baseFrame.state ?? defaultPredictionState();
1104
1061
  }
1105
1062
  setAuthoritative(frame) {
@@ -1118,7 +1075,7 @@ var ClientPrediction = class {
1118
1075
  recompute() {
1119
1076
  let state = normalizeState(this.baseFrame.state);
1120
1077
  for (const cmd of this.commands) {
1121
- state = simulateCommand(state, cmd, this.settings, this.trace);
1078
+ state = simulateCommand(state, cmd, this.settings, this.trace, this.pointContents);
1122
1079
  }
1123
1080
  this.predicted = state;
1124
1081
  return state;