aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 20:10:24 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 20:10:24 +0300
commit75dcc70912d4e6feb14d9370452914ff826849f7 (patch)
tree06c5577b02e92daff7deb4c1cd544ebd210323ed /crates/fparkan-runtime/src
parent07a90f035ebd935ad9705a5f8a8916638a4a8f4f (diff)
downloadfparkan-75dcc70912d4e6feb14d9370452914ff826849f7.tar.xz
fparkan-75dcc70912d4e6feb14d9370452914ff826849f7.zip
fix(input): use the original hero turret elevation range
Apply the World3D mouse Y filter and reverse setting, update the normalized turret request, and use the authored neutral and span to share pitch with the cockpit and elevation tracks. Original World3D dispatch and Control manual mode confirmed the gain and clamp. Stock Firing Range captures show both endpoints and the licensed Constructor test checks the camera and turret together.
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/hero_look.rs221
-rw-r--r--crates/fparkan-runtime/src/lib.rs3
-rw-r--r--crates/fparkan-runtime/src/player_motion.rs45
3 files changed, 180 insertions, 89 deletions
diff --git a/crates/fparkan-runtime/src/hero_look.rs b/crates/fparkan-runtime/src/hero_look.rs
index 57bd62b1..8e15effd 100644
--- a/crates/fparkan-runtime/src/hero_look.rs
+++ b/crates/fparkan-runtime/src/hero_look.rs
@@ -4,9 +4,11 @@ use std::f32::consts::TAU;
#[derive(Clone, Copy, Debug)]
pub(super) struct HeroLook {
- turns: f32,
+ yaw_turns: f32,
+ pitch_blend: f32,
+ reverse_y: bool,
sensitivity: f32,
- filtered_x: f32,
+ filtered: [f32; 2],
phase: f32,
}
@@ -16,47 +18,67 @@ impl HeroLook {
let path = normalize_relative(name, PathPolicy::StrictLegacy).ok()?;
vfs.read(&path).ok()
};
- let table = read(b"hero.tbl");
- let settings = read(b"Iron_3D.ini");
+ let table_bytes = read(b"hero.tbl");
+ let settings_bytes = read(b"Iron_3D.ini");
+ let table = String::from_utf8_lossy(table_bytes.as_deref().unwrap_or_default());
+ let settings = String::from_utf8_lossy(settings_bytes.as_deref().unwrap_or_default());
Self {
- turns: table
- .as_deref()
- .and_then(|bytes| horizontal_binding(&String::from_utf8_lossy(bytes)))
- .unwrap_or(0.15),
- sensitivity: settings
- .as_deref()
- .and_then(|bytes| mouse_sensitivity(&String::from_utf8_lossy(bytes)))
- .unwrap_or(1.0),
- filtered_x: 0.0,
+ yaw_turns: mouse_binding(
+ &table,
+ "SCAN_MOUSE_X",
+ "CICLS_UNKNOWN",
+ "MCMD_ANGLE_Z",
+ "MAN_WRAP",
+ )
+ .unwrap_or(0.15),
+ pitch_blend: mouse_binding(
+ &table,
+ "SCAN_MOUSE_Y",
+ "CICLS_TURRET",
+ "MCMD_ANGLE_Y",
+ "MAN_NOTWRAP",
+ )
+ .unwrap_or(0.25),
+ reverse_y: control_setting(&settings, "MOUSE_REV_Y").unwrap_or(0) != 0,
+ sensitivity: control_setting(&settings, "MOUSE_SENS")
+ .map_or(1.0, |value| value as f32 * 0.01),
+ filtered: [0.0; 2],
phase: 0.5,
}
}
pub(super) fn reset(&mut self) {
- self.filtered_x = 0.0;
+ self.filtered = [0.0; 2];
self.phase = 0.5;
}
pub(super) fn has_state(self) -> bool {
- self.filtered_x != 0.0 || self.phase != 0.5
+ self.filtered != [0.0; 2] || self.phase != 0.5
}
- /// Samples the input once and returns the yaw delivered by this tick.
- pub(super) fn advance(&mut self, dx: f32, dy: f32, max_angle: f32) -> f32 {
- self.filtered_x = if dx == 0.0 && dy == 0.0 {
- 0.0
+ /// Returns delivered yaw in radians and the requested change in turret blend.
+ pub(super) fn advance(&mut self, raw: [f32; 2], max_angle: f32) -> [f32; 2] {
+ self.filtered = if raw == [0.0; 2] {
+ [0.0; 2]
} else {
- dx.clamp(i32::MIN as f32, i32::MAX as f32) * self.sensitivity * 0.95
- + self.filtered_x * 0.05
+ std::array::from_fn(|axis| {
+ raw[axis].clamp(i32::MIN as f32, i32::MAX as f32)
+ * self.sensitivity
+ * [1.0, 1.2][axis]
+ * 0.95
+ + self.filtered[axis] * 0.05
+ })
};
- let scaled = self.filtered_x * 0.006;
- let axis = if scaled.abs() > 0.999 {
- scaled.signum()
- } else {
- scaled
- };
- if axis != 0.0 {
- let phase = self.phase + axis * self.turns;
+ let [x, y] = self.filtered.map(|filtered| {
+ let scaled = filtered * 0.006;
+ if scaled.abs() > 0.999 {
+ scaled.signum()
+ } else {
+ scaled
+ }
+ });
+ if x != 0.0 {
+ let phase = self.phase + x * self.yaw_turns;
self.phase = if phase >= 1.0 {
phase - 1.0
} else if phase <= 0.0 {
@@ -73,32 +95,40 @@ impl HeroLook {
} else {
(self.phase + delivered * (1.0 / TAU)).rem_euclid(1.0)
};
- delivered
+ let pitch = y * self.pitch_blend;
+ [delivered, if self.reverse_y { -pitch } else { pitch }]
+ }
+}
+
+pub(super) fn turret_pitch(
+ row: &fparkan_assets::PreparedControlTimelineRow,
+ previous: f32,
+ blend_delta: f32,
+) -> Option<f32> {
+ let neutral = row.initial_blend;
+ let span = f32::from_bits(row.raw_parameters[3]);
+ if row.flags & 4 != 0 || !span.is_finite() || span <= 0.0 || !(0.0..=1.0).contains(&neutral) {
+ return None;
}
+ let target = (neutral + previous / span + blend_delta).clamp(0.0, 1.0);
+ Some((target - neutral) * span)
}
-fn horizontal_binding(table: &str) -> Option<f32> {
+fn mouse_binding(table: &str, axis: &str, class: &str, command: &str, wrap: &str) -> Option<f32> {
table.lines().find_map(|line| {
let line = line.split_once("//").map_or(line, |(binding, _)| binding);
let mut words = line.split_ascii_whitespace();
- for name in [
- "MOUSE",
- "SCAN_NULL",
- "SCAN_MOUSE_X",
- "1",
- "CICLS_UNKNOWN",
- "MCMD_ANGLE_Z",
- ] {
+ for name in ["MOUSE", "SCAN_NULL", axis, "1", class, command] {
if !words.next()?.eq_ignore_ascii_case(name) {
return None;
}
}
let turns = words.next()?.parse::<f32>().ok()?;
- (turns.abs() <= 1.0 && words.nth(1)?.eq_ignore_ascii_case("MAN_WRAP")).then_some(turns)
+ (turns.abs() <= 1.0 && words.nth(1)?.eq_ignore_ascii_case(wrap)).then_some(turns)
})
}
-fn mouse_sensitivity(settings: &str) -> Option<f32> {
+fn control_setting(settings: &str, key: &str) -> Option<i32> {
let mut controls = false;
for line in settings.lines().map(str::trim) {
if let Some(section) = line.strip_prefix('[').and_then(|line| line.split_once(']')) {
@@ -106,8 +136,8 @@ fn mouse_sensitivity(settings: &str) -> Option<f32> {
}
if controls {
if let Some((name, value)) = line.split_once('=') {
- if name.trim().eq_ignore_ascii_case("MOUSE_SENS") {
- return Some(value.trim().parse::<i32>().ok()? as f32 * 0.01);
+ if name.trim().eq_ignore_ascii_case(key) {
+ return value.trim().parse().ok();
}
}
}
@@ -119,49 +149,102 @@ fn mouse_sensitivity(settings: &str) -> Option<f32> {
mod tests {
use super::*;
+ fn stock_look() -> HeroLook {
+ HeroLook {
+ yaw_turns: 0.15,
+ pitch_blend: 0.25,
+ reverse_y: true,
+ sensitivity: 1.0,
+ filtered: [0.0; 2],
+ phase: 0.5,
+ }
+ }
+
#[test]
- fn horizontal_profile_reads_only_unmodified_body_turn() {
- let bindings =
- "+MOUSE SCAN_SHIFT SCAN_MOUSE_X 1 CICLS_UNKNOWN MCMD_ANGLE_Z 0.10 0 MAN_WRAP 0.0 0
+ fn hero_profile_reads_body_yaw_and_turret_pitch_without_shift() {
+ let bindings = "\
+MOUSE SCAN_LSHIFT SCAN_MOUSE_X 1 CICLS_CAMERA MCMD_ANGLE_X 0.10 1 MAN_WRAP 0.0 0
+MOUSE SCAN_LSHIFT SCAN_MOUSE_Y 1 CICLS_CAMERA MCMD_ANGLE_Y 0.15 1 MAN_NOTWRAP 0.0 0
MOUSE SCAN_NULL SCAN_MOUSE_Y 1 CICLS_UNKNOWN MCMD_ANGLE_Z 0.25 0 MAN_WRAP 0.0 0
-MOUSE SCAN_NULL SCAN_MOUSE_X 1 CICLS_UNKNOWN MCMD_ANGLE_Z 0.20 0 MAN_WRAP 0.0 0 // body";
- assert_eq!(horizontal_binding(bindings), Some(0.20));
- let settings = "[VIDEO]\nMOUSE_SENS=100\n[cs]\n mouse_sens = 50";
- assert_eq!(mouse_sensitivity(settings), Some(0.5));
+MOUSE SCAN_NULL SCAN_MOUSE_X 1 CICLS_UNKNOWN MCMD_ANGLE_Z 0.20 0 MAN_WRAP 0.0 0 // body
+MOUSE SCAN_NULL SCAN_MOUSE_Y 1 CICLS_TURRET MCMD_ANGLE_Y 0.30 1 MAN_NOTWRAP 0.0 0 // turret";
+ assert_eq!(
+ mouse_binding(
+ bindings,
+ "SCAN_MOUSE_X",
+ "CICLS_UNKNOWN",
+ "MCMD_ANGLE_Z",
+ "MAN_WRAP"
+ ),
+ Some(0.20)
+ );
+ assert_eq!(
+ mouse_binding(
+ bindings,
+ "SCAN_MOUSE_Y",
+ "CICLS_TURRET",
+ "MCMD_ANGLE_Y",
+ "MAN_NOTWRAP"
+ ),
+ Some(0.30)
+ );
+ let settings = "[VIDEO]\nMOUSE_SENS=100\n[cs]\n mouse_sens = 50\n mouse_rev_y=1";
+ assert_eq!(control_setting(settings, "MOUSE_SENS"), Some(50));
+ assert_eq!(control_setting(settings, "MOUSE_REV_Y"), Some(1));
}
#[test]
fn hero_mouse_matches_world3d_dispatch() {
- let mut look = HeroLook {
- turns: 0.15,
- sensitivity: 1.0,
- filtered_x: 0.0,
- phase: 0.5,
- };
+ let mut look = stock_look();
for (dx, expected) in [(100.0, 0.0855), (-100.0, -0.0855), (250.0, 0.15)] {
look.reset();
- assert!((look.advance(dx, 0.0, TAU) / -TAU - expected).abs() < 1e-6);
+ assert!((look.advance([dx, 0.0], TAU)[0] / -TAU - expected).abs() < 1e-6);
}
look.reset();
- look.advance(100.0, 0.0, TAU);
- assert!((look.advance(0.0, 1.0, TAU) / -TAU - 0.004275).abs() < 1e-6);
- assert_eq!(look.filtered_x, 4.75);
- assert_eq!(look.advance(0.0, 0.0, TAU), 0.0);
+ look.advance([100.0, 0.0], TAU);
+ assert!((look.advance([0.0, 1.0], TAU)[0] / -TAU - 0.004275).abs() < 1e-6);
+ assert_eq!(look.filtered[0], 4.75);
+ assert_eq!(look.advance([0.0; 2], TAU), [0.0; 2]);
assert!(!look.has_state());
}
#[test]
fn hero_finishes_a_capped_turn_on_the_next_tick_without_mouse_input() {
- let mut look = HeroLook {
- turns: 0.15,
- sensitivity: 1.0,
- filtered_x: 0.0,
- phase: 0.5,
- };
+ let mut look = stock_look();
let max_angle = 50.22849 * 0.01;
- assert!((look.advance(250.0, 0.0, max_angle) + 0.5022847).abs() < 1e-6);
+ assert!((look.advance([250.0, 0.0], max_angle)[0] + 0.5022847).abs() < 1e-6);
assert!((look.phase - 0.5700589).abs() < 1e-6);
- assert!((look.advance(0.0, 0.0, max_angle) + 0.44019294).abs() < 1e-6);
+ assert!((look.advance([0.0; 2], max_angle)[0] + 0.44019294).abs() < 1e-6);
assert!(!look.has_state());
}
+
+ #[test]
+ fn hero_turret_uses_world3d_axis_and_control_elevation_endpoints() {
+ let mut look = stock_look();
+ let row = fparkan_assets::PreparedControlTimelineRow {
+ row_index: 2,
+ node_index: 34,
+ frame_a: 55.0,
+ frame_b: 57.0,
+ initial_blend: 0.27272728,
+ raw_parameters: [0, 0, 0, 1.9198622_f32.to_bits()],
+ flags: 0,
+ };
+ let pitch = |previous, blend| turret_pitch(&row, previous, blend).unwrap().to_degrees();
+ let upward = look.advance([0.0, -100.0], TAU)[1];
+ assert!((upward - 0.171).abs() < 1e-6);
+ assert!((pitch(0.0, upward) - 18.81).abs() < 1e-5);
+ let tail = look.advance([1.0, 0.0], TAU)[1];
+ assert!((tail - 0.00855).abs() < 1e-6);
+
+ look.reset();
+ let downward = look.advance([0.0, 300.0], TAU)[1];
+ assert_eq!(downward, -0.25);
+ assert!((pitch(-25.0_f32.to_radians(), downward) + 30.0).abs() < 1e-5);
+ assert!((pitch(70.0_f32.to_radians(), upward) - 80.0).abs() < 1e-5);
+
+ look.reset();
+ look.reverse_y = false;
+ assert!((look.advance([0.0, 100.0], TAU)[1] - upward).abs() < 1e-6);
+ }
}
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 527f2f85..f62c0784 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -18006,7 +18006,8 @@ mod tests {
assert_eq!(turned.position, original.position);
assert_ne!(turned.orientation[2], original.orientation[2]);
assert_eq!(turned.orientation[..2], original.orientation[..2]);
- assert_eq!(f32::from_bits(blocked.player_pitch_bits), 1.0);
+ let pitch = f32::from_bits(blocked.player_pitch_bits);
+ assert!((pitch.abs().to_degrees() - 27.5).abs() < 1e-4);
let movement = PlayerMotion {
mouse_x: 0.0,
mouse_y: 0.0,
diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs
index b2f91270..de988a89 100644
--- a/crates/fparkan-runtime/src/player_motion.rs
+++ b/crates/fparkan-runtime/src/player_motion.rs
@@ -1,5 +1,5 @@
use super::{transform_state, Engine, EngineError, StartingCockpit, SurfaceQuery, TransformState};
-use crate::hero_look::HeroLook;
+use crate::hero_look::{turret_pitch, HeroLook};
use crate::manual_flight::{FlightDrive, FlightProfile};
use crate::{hero_walk::WalkingDrive, TerrainWorld};
use fparkan_resource::CachedResourceRepository;
@@ -472,15 +472,35 @@ fn plan_player_steps(
return Err(EngineError::Movement("invalid player step".into()));
}
let mut hero_look = hero_control.then_some(mission.hero_look);
- let mut yaw_delta = if let Some(look) = hero_look.as_mut() {
+ // shortcut: mounted chassis use fixed gains until their bindings are wired.
+ let fallback_pitch = || (pitch - input.mouse_y * 0.005).clamp(-1.0, 1.0);
+ let (mut yaw_delta, pitch) = if let Some(look) = hero_look.as_mut() {
let max_angle = hero_profile
.map(|words| f32::from_bits(words[11]))
.filter(|speed| speed.is_finite() && *speed >= 0.0)
.map_or(f32::INFINITY, |speed| speed * input.delta_seconds);
- look.advance(input.mouse_x, input.mouse_y, max_angle)
+ let [yaw, blend_delta] = look.advance([input.mouse_x, input.mouse_y], max_angle);
+ let next_pitch = || {
+ let control = mission
+ .mission_assets
+ .object_component_controls
+ .get(cockpit.object_index)?
+ .get(cockpit.component_index)?
+ .as_ref()?;
+ let row = fparkan_assets::turret_elevation_row(control)?;
+ turret_pitch(row, pitch, blend_delta)
+ };
+ let pitch = if blend_delta != 0.0 {
+ next_pitch().unwrap_or_else(fallback_pitch)
+ } else {
+ pitch
+ };
+ (yaw, pitch)
} else {
- // shortcut: mounted chassis still use a constant mouse gain.
- -input.mouse_x.clamp(-1_000.0, 1_000.0) * 0.003
+ (
+ -input.mouse_x.clamp(-1_000.0, 1_000.0) * 0.003,
+ fallback_pitch(),
+ )
};
let speeds = if boarded.is_some() && !flying {
crate::manual_chassis::speed_limits(mission, cockpit.handle)
@@ -514,7 +534,6 @@ fn plan_player_steps(
input.delta_seconds /= count as f32;
let mut previous = pose;
let mut previous_surface = WalkingSurface::Ground;
- let mut pitch = pitch;
for index in 0..count {
let mut propose = |walk: Option<([f32; 2], [f32; 2])>| {
let ground_displacement = walk.map_or_else(
@@ -561,8 +580,6 @@ fn plan_player_steps(
return Ok(Some(step));
}
yaw_delta = 0.0;
- input.mouse_y = 0.0;
- pitch = f32::from_bits(step.pitch_bits);
previous = step.pose;
previous_surface = step.surface;
if let (Some(drive), Some(velocity)) = (walking.as_mut(), step.hero_walk_velocity) {
@@ -618,14 +635,7 @@ fn plan_motion(
if !input
.movement
.into_iter()
- .chain([
- input.mouse_y,
- input.climb,
- input.delta_seconds,
- yaw,
- yaw_delta,
- pitch,
- ])
+ .chain([input.climb, input.delta_seconds, yaw, yaw_delta, pitch])
.chain(from)
.all(f32::is_finite)
|| input.delta_seconds < 0.0
@@ -698,9 +708,6 @@ fn plan_motion(
}
}
}
- // shortcut: use a bounded camera aim until the native turret travel and
- // sensitivity are recovered. The body remains aligned to the terrain.
- let pitch = (pitch - input.mouse_y * 0.005).clamp(-1.0, 1.0);
Ok(PlayerMotionStep {
pose,
pitch_bits: pitch.to_bits(),