@adatechnology/game-player 0.15.1 → 0.16.0

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/dist/index.js CHANGED
@@ -861,15 +861,20 @@ function createVehicleBoarding(ports, rules = {}) {
861
861
  }
862
862
 
863
863
  // src/driving-hands.ts
864
- var DRIVING_HANDS_DEFAULTS = { regripAt: 1.75, firstAt: 0.7, lead: 0.9, stillRate: 0.3, settleAt: 0.25, reachLimit: 2.3, regripSeconds: 0.24, leverReachSeconds: 0.22, leverHoldSeconds: 0.26 };
864
+ var DRIVING_HANDS_DEFAULTS = { regripAt: 1.75, firstAt: 0.7, lead: 0.9, stillRate: 0.3, settleAt: 0.25, reachLimit: 2.3, regripSeconds: 0.24, leverReachSeconds: 0.22, leverHoldSeconds: 0.26, controlReachSeconds: 0.2, controlHoldSeconds: 0.14 };
865
865
  var smooth = (k) => k * k * (3 - 2 * k);
866
+ var MAX_WAITING = 4;
867
+ var AT_REST = { at: 0, hold: 1, toLever: 0, toControl: 0, control: null, regrip: -1, from: 0, to: 0 };
866
868
  function createDrivingHands(rules = {}) {
867
869
  const r = { ...DRIVING_HANDS_DEFAULTS, ...rules };
868
- const hands = { left: { at: 0, hold: 1, toLever: 0, regrip: -1, from: 0, to: 0 }, right: { at: 0, hold: 1, toLever: 0, regrip: -1, from: 0, to: 0 } };
870
+ const hands = { left: { ...AT_REST }, right: { ...AT_REST } };
869
871
  let last = 0;
870
872
  let shifting = null;
871
- const busy = (h) => h.regrip >= 0 || h.toLever > 0;
873
+ let working = null;
874
+ const waiting = [];
875
+ const busy = (h) => h.regrip >= 0 || h.toLever > 0 || h.toControl > 0;
872
876
  const total = r.leverReachSeconds * 2 + r.leverHoldSeconds;
877
+ const workTotal = r.controlReachSeconds * 2 + r.controlHoldSeconds;
873
878
  return {
874
879
  left: hands.left,
875
880
  right: hands.right,
@@ -877,15 +882,29 @@ function createDrivingHands(rules = {}) {
877
882
  if (!shifting) return 1;
878
883
  return smooth(Math.max(0, Math.min(1, (shifting.clock - r.leverReachSeconds) / r.leverHoldSeconds)));
879
884
  },
885
+ work(hand, control, held, place = control) {
886
+ const other = hands[hand === "left" ? "right" : "left"];
887
+ if (shifting || working || busy(other)) {
888
+ if (held || waiting.length >= MAX_WAITING) return false;
889
+ waiting.push({ hand, control, place });
890
+ return true;
891
+ }
892
+ working = { hand, clock: 0, acted: false, held, place };
893
+ hands[hand].regrip = -1;
894
+ hands[hand].control = control;
895
+ return true;
896
+ },
880
897
  shift(hand) {
881
- if (shifting) return;
898
+ if (shifting || working) return;
882
899
  shifting = { hand, clock: 0 };
883
900
  hands[hand].regrip = -1;
884
901
  },
885
902
  reset(wheel) {
886
903
  last = wheel;
887
904
  shifting = null;
888
- for (const h of [hands.left, hands.right]) Object.assign(h, { at: 0, hold: 1, toLever: 0, regrip: -1, from: 0, to: 0 });
905
+ working = null;
906
+ waiting.length = 0;
907
+ for (const h of [hands.left, hands.right]) Object.assign(h, AT_REST);
889
908
  },
890
909
  update(dt, wheel) {
891
910
  const turned = wheel - last;
@@ -905,10 +924,45 @@ function createDrivingHands(rules = {}) {
905
924
  shifting = null;
906
925
  }
907
926
  }
927
+ let acted = null;
928
+ if (working) {
929
+ working.clock += dt;
930
+ if (working.acted && working.held?.()) working.clock = Math.min(working.clock, r.controlReachSeconds);
931
+ const h = hands[working.hand];
932
+ const c = working.clock;
933
+ const out = smooth(Math.min(1, c / r.controlReachSeconds));
934
+ const back = smooth(Math.max(0, Math.min(1, (c - r.controlReachSeconds - r.controlHoldSeconds) / r.controlReachSeconds)));
935
+ h.toControl = Math.max(out * (1 - back), 1e-6);
936
+ h.hold = 1 - h.toControl;
937
+ h.at = 0;
938
+ if (!working.acted && c >= r.controlReachSeconds) {
939
+ working.acted = true;
940
+ acted = h.control;
941
+ }
942
+ const next = waiting[0];
943
+ if (working.acted && acted === null && !working.held?.() && c >= r.controlReachSeconds + r.controlHoldSeconds && next && next.hand === working.hand && next.place === working.place) {
944
+ waiting.shift();
945
+ h.control = next.control;
946
+ working.clock = r.controlReachSeconds;
947
+ working.acted = false;
948
+ working.held = void 0;
949
+ } else if (c >= workTotal) {
950
+ h.toControl = 0;
951
+ h.control = null;
952
+ h.hold = 1;
953
+ working = null;
954
+ }
955
+ }
956
+ if (!working && !shifting && waiting.length > 0 && !busy(hands.left) && !busy(hands.right)) {
957
+ const next = waiting.shift();
958
+ working = { hand: next.hand, clock: 0, acted: false, held: void 0, place: next.place };
959
+ hands[next.hand].regrip = -1;
960
+ hands[next.hand].control = next.control;
961
+ }
908
962
  for (const side of ["left", "right"]) {
909
963
  const h = hands[side];
910
964
  const other = hands[side === "left" ? "right" : "left"];
911
- if (h.toLever > 0) continue;
965
+ if (h.toLever > 0 || h.toControl > 0) continue;
912
966
  if (h.regrip >= 0) {
913
967
  h.regrip += dt;
914
968
  const k = Math.min(1, h.regrip / r.regripSeconds);
@@ -933,6 +987,7 @@ function createDrivingHands(rules = {}) {
933
987
  h.to = turning ? -Math.sign(rate) * r.lead : 0;
934
988
  }
935
989
  }
990
+ return acted;
936
991
  }
937
992
  };
938
993
  }