aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-14 05:40:01 +0300
committerValentin Popov <valentin@popov.link>2026-11-14 05:40:01 +0300
commit8065381152e2d4f89279fd662e7376013ad13e82 (patch)
tree27bcf4b04ddb71fc8df23a53514f87a3dc509ef7 /crates/fparkan-runtime/src
parent520273dbe04fc1c9ea40127fb198d2bb5f0813f9 (diff)
downloadfparkan-8065381152e2d4f89279fd662e7376013ad13e82.tar.xz
fparkan-8065381152e2d4f89279fd662e7376013ad13e82.zip
feat(game): tilt the cockpit view from vertical mouse input
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/lib.rs30
-rw-r--r--crates/fparkan-runtime/src/player_motion.rs31
2 files changed, 53 insertions, 8 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 32a4d8d1..883e5554 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -1261,6 +1261,8 @@ pub struct FrameResult {
pub snapshot: WorldSnapshot,
/// Periodic script event attempted on this step, if due.
pub mission_event: Option<MissionEventTick>,
+ /// Vertical aim of the controlled hero as an IEEE-754 radian value.
+ pub player_pitch_bits: u32,
}
/// Engine.
@@ -1293,6 +1295,7 @@ struct LoadedMissionState {
script_init_states: Vec<MissionScriptInitState>,
script_varset_states: Vec<MissionScriptVarSetState>,
mission_events: MissionEvents,
+ player_pitch_bits: u32,
script_host_mode: MissionMode,
script_host_status: u32,
script_outcome: MissionScriptOutcome,
@@ -2232,6 +2235,7 @@ fn load_mission_with_options(
script_init_states: loaded_scripts.init_states,
script_varset_states: loaded_scripts.varset_states,
mission_events,
+ player_pitch_bits: 0,
script_host_mode: request.mode,
// Fresh IGame construction seeds this field with 5; this is not the
// later status-4 transition performed after native game initialization.
@@ -2283,6 +2287,10 @@ pub fn step_headless(
Ok(FrameResult {
snapshot,
mission_event,
+ player_pitch_bits: engine
+ .loaded
+ .as_ref()
+ .map_or(0, |mission| mission.player_pitch_bits),
})
}
@@ -2314,11 +2322,19 @@ pub fn frame_with_player_motion(
pose.position = previous.position;
}
set_transform(&mut engine.world, cockpit.handle, pose)?;
- let result = frame(engine, queue_time_ms);
- if result.is_err() {
- set_transform(&mut engine.world, cockpit.handle, previous)?;
+ match frame(engine, queue_time_ms) {
+ Ok(mut frame) => {
+ if let Some(mission) = &mut engine.loaded {
+ mission.player_pitch_bits = motion.pitch_bits;
+ frame.player_pitch_bits = motion.pitch_bits;
+ }
+ Ok(frame)
+ }
+ Err(error) => {
+ set_transform(&mut engine.world, cockpit.handle, previous)?;
+ Err(error)
+ }
}
- result
}
/// Coverage entries for the subsystems still absent from the mission loop.
@@ -17133,6 +17149,7 @@ mod tests {
let input = PlayerMotion {
movement: [0.0, 1.0],
mouse_x: 100.0,
+ mouse_y: -500.0,
delta_seconds: 0.1,
};
let proposed = plan_player_motion(&engine, cockpit, input)
@@ -17152,8 +17169,11 @@ mod tests {
let turned = pose(&blocked);
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 movement = PlayerMotion {
mouse_x: 0.0,
+ mouse_y: 0.0,
..input
};
let proposed = plan_player_motion(&engine, cockpit, movement)
@@ -17172,6 +17192,8 @@ mod tests {
.unwrap()
};
assert!(((z1 - ground([x1, y1])) - (z0 - ground([x0, y0]))).abs() < 1e-5);
+ let idle = frame(&mut engine, 300).unwrap();
+ assert_eq!(idle.player_pitch_bits, blocked.player_pitch_bits);
}
#[test]
diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs
index 291b0451..439429cd 100644
--- a/crates/fparkan-runtime/src/player_motion.rs
+++ b/crates/fparkan-runtime/src/player_motion.rs
@@ -8,6 +8,8 @@ pub struct PlayerMotion {
pub movement: [f32; 2],
/// Relative horizontal mouse motion for this step.
pub mouse_x: f32,
+ /// Relative vertical mouse motion for this step, positive down.
+ pub mouse_y: f32,
/// Time spent on this simulation step, excluding time spent paused.
pub delta_seconds: f32,
}
@@ -16,6 +18,7 @@ pub struct PlayerMotion {
#[derive(Clone, Copy, Debug)]
pub struct PlayerMotionStep {
pub(super) pose: TransformState,
+ pub(super) pitch_bits: u32,
/// Sweep segment when the step translates the hero.
pub sweep: Option<[[f32; 3]; 2]>,
}
@@ -30,7 +33,7 @@ pub fn plan_player_motion(
cockpit: StartingCockpit,
input: PlayerMotion,
) -> Result<Option<PlayerMotionStep>, EngineError> {
- if input.movement == [0.0; 2] && input.mouse_x == 0.0 {
+ if input.movement == [0.0; 2] && input.mouse_x == 0.0 && input.mouse_y == 0.0 {
return Ok(None);
}
let (Some(mission), Ok(pose)) = (
@@ -39,12 +42,19 @@ pub fn plan_player_motion(
) else {
return Ok(None);
};
- plan_motion(&mission.terrain, pose, input).map(Some)
+ plan_motion(
+ &mission.terrain,
+ pose,
+ f32::from_bits(mission.player_pitch_bits),
+ input,
+ )
+ .map(Some)
}
fn plan_motion(
terrain: &TerrainWorld,
mut pose: TransformState,
+ pitch: f32,
input: PlayerMotion,
) -> Result<PlayerMotionStep, EngineError> {
let from = pose.position.map(f32::from_bits);
@@ -52,7 +62,13 @@ fn plan_motion(
if !input
.movement
.into_iter()
- .chain([input.mouse_x, input.delta_seconds, yaw])
+ .chain([
+ input.mouse_x,
+ input.mouse_y,
+ input.delta_seconds,
+ yaw,
+ pitch,
+ ])
.chain(from)
.all(f32::is_finite)
|| input.delta_seconds < 0.0
@@ -96,5 +112,12 @@ fn plan_motion(
]);
}
}
- Ok(PlayerMotionStep { pose, sweep })
+ // 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(),
+ sweep,
+ })
}