aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 02:25:58 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 02:25:58 +0300
commitd92cde8b7209b83572aeabd5dab657149ed78d99 (patch)
tree2f29d6872ff2f3d7466308c5142cd0bff63b93b0 /crates/fparkan-runtime/src
parentfd0c4eb23337953895ec3b7ac23178b495128930 (diff)
downloadfparkan-d92cde8b7209b83572aeabd5dab657149ed78d99.tar.xz
fparkan-d92cde8b7209b83572aeabd5dab657149ed78d99.zip
feat(diagnostics): count unit motion gaps by object
Track temporary-controller updates and frame time discarded at waypoint boundaries for each object slot, generation and original TMA ID. Preserve completed/dead object records, expose them in --sim-report, and print the same counters when the game window closes. Movement and RNG decisions are unchanged. A bounded Ghidra inspection identifies Go at Behavior.dll RVA 0x2b670 and the MWalker empty-state helper at 0x3dd80. Restoring the MWalker/Control handoff remains open; no fixed-step or remainder-carry rule is substituted for native behavior. Document this explicit stub and bind the addresses to the verified GOG module hash. The licensed stock AutoDemo test first failed with empty observations and now reports actual controller updates and nonzero discarded time. A normal 91-second window run also emits per-generation totals after closure. All 29 stock --sim-report 900 runs preserve the preceding commit's world and combat summaries. At 60 Hz, AutoDemo's largest recorded loss for a single object lifetime is 492516 us; losses are observations of FParkan, not original-game timings. Validation: cargo fmt --all -- --check; cargo check --workspace; cargo test --workspace; release build; focused unit and ignored licensed-stock tests; stock AutoDemo window; all 29 mission coverage runs. The native movement solver and original chronology are not accepted by this diagnostic change.
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/lib.rs5
-rw-r--r--crates/fparkan-runtime/src/unit_motion.rs135
-rw-r--r--crates/fparkan-runtime/src/unit_patrol.rs12
3 files changed, 152 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 81fad53a..83ef99bc 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -98,6 +98,8 @@ mod script_patrol;
mod script_time;
mod unit_chassis;
mod unit_combat;
+mod unit_motion;
+pub use unit_motion::{loaded_mission_unit_motion_report, UnitMotionReport, UnitMotionSample};
mod unit_patrol;
mod unit_size_class;
mod unit_spawn;
@@ -3010,6 +3012,7 @@ pub struct SimulationReport {
pub control_profiles: ControlProfileReport,
pub mobile_budget: MobileBudgetReport,
pub combat: CombatReport,
+ pub unit_motion: UnitMotionReport,
/// Approximate clan strength queries, grouped by caller and target clan.
pub script_strength_queries: Vec<(usize, u16, u64)>,
pub script_capture_queries: Vec<(usize, u64)>,
@@ -3092,6 +3095,7 @@ pub fn simulate_mission_report(
control_profiles: ControlProfileReport::default(),
mobile_budget: MobileBudgetReport::default(),
combat: CombatReport::default(),
+ unit_motion: UnitMotionReport::default(),
script_strength_queries: Vec::new(),
script_capture_queries: Vec::new(),
script_attack_queries: Vec::new(),
@@ -3204,6 +3208,7 @@ pub fn simulate_mission_report(
if let Some(patrol) = &loaded.unit_patrol {
report.patrol_points = patrol.point_report.clone();
report.patrol_speeds = patrol.speed_report.clone();
+ report.unit_motion = patrol.motion_report.clone();
}
report
.control_resource_ticks
diff --git a/crates/fparkan-runtime/src/unit_motion.rs b/crates/fparkan-runtime/src/unit_motion.rs
new file mode 100644
index 00000000..101a6208
--- /dev/null
+++ b/crates/fparkan-runtime/src/unit_motion.rs
@@ -0,0 +1,135 @@
+//! Observations of the temporary unit controller, not a native motion solver.
+
+use crate::{CombatObject, Engine};
+use std::collections::BTreeMap;
+
+/// Work performed by the temporary controller for one retained object identity.
+#[derive(Clone, Debug, Default, Eq, PartialEq)]
+pub struct UnitMotionSample {
+ pub updates: u64,
+ pub first_ms: u32,
+ pub last_ms: u32,
+ pub discarded_waypoints: u64,
+ /// Sum of unused frame intervals, individually rounded to microseconds.
+ pub discarded_time_us: u64,
+}
+
+/// Counts persist after orders end or the object leaves the world.
+#[derive(Clone, Debug, Default, Eq, PartialEq)]
+pub struct UnitMotionReport {
+ pub objects: BTreeMap<CombatObject, UnitMotionSample>,
+}
+
+impl UnitMotionReport {
+ pub(super) fn update(&mut self, object: CombatObject, now: u32) {
+ let sample = self.objects.entry(object).or_insert_with(|| {
+ eprintln!("sim_coverage unit_motion_controller_stub=1 object={object} original_id={:?} first_ms={now}", object.original_id);
+ UnitMotionSample {
+ first_ms: now,
+ ..Default::default()
+ }
+ });
+ sample.updates += 1;
+ sample.last_ms = now;
+ }
+
+ pub(super) fn discard_waypoint_time(&mut self, object: CombatObject, seconds: f32) {
+ let time_us = (f64::from(seconds.max(0.0)) * 1_000_000.0).round() as u64;
+ if time_us == 0 {
+ return;
+ }
+ let sample = self
+ .objects
+ .get_mut(&object)
+ .expect("recorded motion update");
+ sample.discarded_waypoints += 1;
+ sample.discarded_time_us += time_us;
+ }
+}
+
+/// Reads observations shared by the interactive and headless mission paths.
+#[must_use]
+pub fn loaded_mission_unit_motion_report(engine: &Engine) -> Option<&UnitMotionReport> {
+ Some(&engine.loaded.as_ref()?.unit_patrol.as_ref()?.motion_report)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn counts_updates_and_unused_time_separately_for_reused_slots() {
+ let object = CombatObject {
+ slot: 4,
+ generation: 1,
+ original_id: Some(17),
+ };
+ let replacement = CombatObject {
+ generation: 2,
+ ..object
+ };
+ let mut report = UnitMotionReport::default();
+ report.update(object, 0);
+ report.discard_waypoint_time(object, 0.125);
+ report.update(object, 500);
+ report.discard_waypoint_time(object, 0.0);
+ report.update(replacement, 1_000);
+ assert_eq!(
+ report.objects[&object],
+ UnitMotionSample {
+ updates: 2,
+ first_ms: 0,
+ last_ms: 500,
+ discarded_waypoints: 1,
+ discarded_time_us: 125_000,
+ }
+ );
+ assert_eq!(report.objects[&replacement].updates, 1);
+ assert_eq!(report.objects[&replacement].discarded_time_us, 0);
+ }
+
+ #[test]
+ #[ignore = "requires licensed corpus"]
+ fn licensed_stock_patrol_reports_controller_updates_and_lost_time() {
+ use crate::{
+ create, load_gameplay_mission, simulate_mission_report, EngineServices, MissionMode,
+ MissionRequest, MissionStartupInput,
+ };
+ use fparkan_vfs::DirectoryVfs;
+ use std::sync::Arc;
+ let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus");
+ let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap();
+ load_gameplay_mission(
+ &mut engine,
+ MissionRequest {
+ key: "MISSIONS/Autodemo.00/data.tma".into(),
+ mode: MissionMode::AutoDemo,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ None,
+ )
+ .unwrap();
+ let report = simulate_mission_report(&mut engine, 120_000).unwrap();
+ assert_eq!(
+ &report.unit_motion,
+ loaded_mission_unit_motion_report(&engine).unwrap()
+ );
+ assert!(!report.unit_motion.objects.is_empty());
+ assert!(report
+ .unit_motion
+ .objects
+ .keys()
+ .all(|object| object.original_id.is_some()));
+ assert!(report
+ .unit_motion
+ .objects
+ .values()
+ .any(|sample| sample.updates > 1
+ && sample.last_ms > sample.first_ms
+ && sample.discarded_waypoints > 0
+ && sample.discarded_time_us > 0));
+ }
+}
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs
index a8d0e438..dbef0c5a 100644
--- a/crates/fparkan-runtime/src/unit_patrol.rs
+++ b/crates/fparkan-runtime/src/unit_patrol.rs
@@ -27,6 +27,7 @@ pub(super) struct UnitPatrol {
rng: u32,
pub(super) point_report: PatrolPointReport,
pub(super) speed_report: PatrolSpeedReport,
+ pub(super) motion_report: crate::UnitMotionReport,
pub(super) factory_raid_clans: usize,
}
@@ -154,6 +155,7 @@ impl UnitPatrol {
rng: 1,
point_report: PatrolPointReport::default(),
speed_report: PatrolSpeedReport::default(),
+ motion_report: crate::UnitMotionReport::default(),
factory_raid_clans: 0,
}
}
@@ -396,6 +398,7 @@ impl UnitPatrol {
rng: 1,
point_report: PatrolPointReport::default(),
speed_report: PatrolSpeedReport::default(),
+ motion_report: crate::UnitMotionReport::default(),
factory_raid_clans: 0,
})
}
@@ -535,6 +538,8 @@ impl UnitPatrol {
if seconds == 0.0 {
continue;
}
+ let motion_object = crate::CombatObject::read(world, unit.handle);
+ state.motion_report.update(motion_object, now_ms);
if let Some(enemy) = enemy.filter(|enemy| enemy.in_range) {
let mut after = before;
let (yaw, _) = turn_toward(
@@ -588,6 +593,9 @@ impl UnitPatrol {
let distance = dx.hypot(dy);
if distance <= 0.05 {
unit.points.pop_front();
+ state
+ .motion_report
+ .discard_waypoint_time(motion_object, seconds);
continue;
}
let mut after = before;
@@ -619,6 +627,10 @@ impl UnitPatrol {
after.position = [xy[0], xy[1], z].map(f32::to_bits);
if fraction == 1.0 {
unit.points.pop_front();
+ state.motion_report.discard_waypoint_time(
+ motion_object,
+ seconds - turn_seconds - distance / speed,
+ );
}
} else {
unit.points.clear();