aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/control_resources.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-25 23:57:43 +0300
committerValentin Popov <valentin@popov.link>2026-11-25 23:57:43 +0300
commit530afea388f4e487a5a1320381c59e7d217717d8 (patch)
tree535b5722ff694d3d666c18aa143a8447d86c068a /crates/fparkan-runtime/src/control_resources.rs
parent2d7c17b13b0dc2e4a4712fee25aa8f06161a141b (diff)
downloadfparkan-530afea388f4e487a5a1320381c59e7d217717d8.tar.xz
fparkan-530afea388f4e487a5a1320381c59e7d217717d8.zip
fix(control): refresh motion limits after node damage
Run the supported dirty Control profile branch on the resource clock, before the existing factory/laboratory budget pass. Mobile owners now participate in these clocks. Root hits reduce the drive's current E00 value and the next place-patrol speed request uses the updated limit. Keep mutable node-group means and publish profile words atomically. Move FCA0 projection into control_profile rather than extending lib.rs. Count clock checks, publications and unsupported updates per object; alarm damage, activation and mobile device budgets remain explicit gaps. Native Control.dll RVA 0x12a40 -> 0xfca0 confirms mean retention, clean-call behavior and the healthy-critical-group branch that bypasses the aggregate threshold. Golden outputs are covered by Rust tests. SHA-256: bcb86318089028548a178b03a21accdce15df0cc85ddd91674cf3c2f55012c6e. Validated fmt, workspace check/tests, release, licensed stock damage, combat and patrol regressions, plus all 29 stock missions for 900 seconds without new profile-update stops. Stock window AI hits change limits. The additional live native interception yielded no usable sample; its supported calculation branches were executed directly in the DLL.
Diffstat (limited to 'crates/fparkan-runtime/src/control_resources.rs')
-rw-r--r--crates/fparkan-runtime/src/control_resources.rs66
1 files changed, 56 insertions, 10 deletions
diff --git a/crates/fparkan-runtime/src/control_resources.rs b/crates/fparkan-runtime/src/control_resources.rs
index 18af1975..86a402e1 100644
--- a/crates/fparkan-runtime/src/control_resources.rs
+++ b/crates/fparkan-runtime/src/control_resources.rs
@@ -1,4 +1,6 @@
-use crate::{control_resource_budget_pass, LoadedMissionState};
+use crate::{
+ control_profile, control_resource_budget_pass, ControlProfileReport, LoadedMissionState,
+};
use fparkan_world::{transform_state, ObjectHandle, World};
use std::collections::BTreeMap;
@@ -8,6 +10,7 @@ pub(super) struct Resources {
rng: u32,
ticks: BTreeMap<u32, u64>,
stops: BTreeMap<u32, (u64, String)>,
+ pub(super) profiles: ControlProfileReport,
}
impl Default for Resources {
@@ -18,6 +21,7 @@ impl Default for Resources {
rng: 1,
ticks: BTreeMap::new(),
stops: BTreeMap::new(),
+ profiles: ControlProfileReport::default(),
}
}
}
@@ -40,17 +44,16 @@ pub(super) fn tick(mission: &mut LoadedMissionState, world: &World, now_ms: u32)
.clocks
.retain(|(handle, _)| transform_state(world, *handle).is_ok());
for table in &mut mission.control_device_tables {
- if !table
+ let flags = table
.original_id
.and_then(|id| mission.object_drafts.get(id.0 as usize))
- .is_some_and(|draft| {
- matches!(
- draft.unit_dat_header_flags,
- Some(crate::autodemo::PLANT_CLASS | crate::laboratory::LAB_CLASS)
- )
- })
- || transform_state(world, table.handle).is_err()
- {
+ .and_then(|draft| draft.unit_dat_header_flags);
+ let budget_owner = matches!(
+ flags,
+ Some(crate::autodemo::PLANT_CLASS | crate::laboratory::LAB_CLASS)
+ );
+ let mobile_owner = flags.is_some_and(|flags| flags & crate::autodemo::MOBILE_UNIT != 0);
+ if (!budget_owner && !mobile_owner) || transform_state(world, table.handle).is_err() {
continue;
}
let clock = if let Some(index) = state
@@ -78,6 +81,49 @@ pub(super) fn tick(mission: &mut LoadedMissionState, world: &World, now_ms: u32)
let Some(seconds) = clock.step(now_ms as f32, true, 250.0, &mut state.rng) else {
continue;
};
+ let object = table.original_id.map_or(table.handle.slot, |id| id.0);
+ let ticks = state.profiles.ticks.entry(object).or_default();
+ *ticks += 1;
+ if *ticks == 1 {
+ eprintln!("control_profile_clock_approx object={object} (Control RNG seed, owner order and activation remain open)");
+ }
+ let before = table
+ .owner_profile
+ .as_ref()
+ .map_or(0, |profile| profile.current_words[7]);
+ match control_profile::refresh(table) {
+ Ok(true) => {
+ let after = table
+ .owner_profile
+ .as_ref()
+ .expect("refreshed profile")
+ .current_words[7];
+ let update = state.profiles.updates.entry(object).or_default();
+ *update = (update.0 + 1, before, after);
+ if before != after {
+ eprintln!(
+ "control_profile_updated object={object} forward_limit={} -> {}",
+ f32::from_bits(before),
+ f32::from_bits(after)
+ );
+ }
+ }
+ Ok(false) => {}
+ Err(reason) => {
+ let count = state
+ .profiles
+ .stubs
+ .entry((object, reason.clone()))
+ .or_default();
+ *count += 1;
+ if *count == 1 {
+ eprintln!("control_profile_update_stub object={object} reason={reason}");
+ }
+ }
+ }
+ if !budget_owner {
+ continue;
+ }
match control_resource_budget_pass(table, seconds) {
Ok(()) => {
let count = state.ticks.entry(table.handle.slot).or_default();