diff options
Diffstat (limited to 'crates/fparkan-runtime/src/control_resources.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/control_resources.rs | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/crates/fparkan-runtime/src/control_resources.rs b/crates/fparkan-runtime/src/control_resources.rs index e34a3dfc..0b1f853b 100644 --- a/crates/fparkan-runtime/src/control_resources.rs +++ b/crates/fparkan-runtime/src/control_resources.rs @@ -1,11 +1,11 @@ use crate::{ - control_profile, control_resource_budget_pass, repair_zone, ControlProfileReport, Engine, - MissionControlDeviceTableStatus, MobileBudgetReport, + control_profile, control_resource_budget_pass_with_motion, mobile_budget::DriveMotion, + repair_zone, ControlProfileReport, Engine, MissionControlDeviceTableStatus, MobileBudgetReport, }; -use fparkan_world::{transform_state, ObjectHandle}; +use fparkan_world::{transform_state, ObjectHandle, TransformState}; use std::collections::BTreeMap; -/// Supported Control budgets; motion callbacks and global RNG ordering remain open. +/// Supported Control budgets and per-owner resource clocks. pub(super) struct Resources { clocks: Vec<(ObjectHandle, ResourceClock)>, rng: u32, @@ -109,6 +109,8 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) { .expect("new Control resource clock") .1 }; + let frame_seconds = (now_ms as f32 - clock.frame_ms) * 0.001; + let previous_pose = clock.previous_pose.replace(pose); // Control.dll+0x42480: default resource period; this is a separate RNG from Behavior. let Some(seconds) = clock.step(now_ms as f32, true, 250.0, &mut state.rng) else { continue; @@ -160,7 +162,20 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) { } } } - match control_resource_budget_pass(table, seconds) { + let motion = previous_pose.filter(|_| mobile_owner).and_then(|previous| { + let can_fly = table + .original_id + .and_then(|id| mission.unit_chassis_flags.get(&id.0)) + .and_then(|flags| flags.can_fly)?; + DriveMotion::sample( + table, + &mission.mission_assets, + [previous, pose], + frame_seconds, + can_fly, + ) + }); + match control_resource_budget_pass_with_motion(table, seconds, motion) { Ok(()) => { state .blocked_budgets @@ -169,10 +184,11 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) { *state.mobile.ticks.entry(object).or_default() += 1; if let MissionControlDeviceTableStatus::Available(devices) = &table.status { for device in devices { - if device.factory_tag == 5 && device.native_word_50_bits != Some(0) { - state - .mobile - .stub(object, format!("motion_factory_{}", device.factory_tag)); + if motion.is_none() + && device.factory_tag == 5 + && device.native_word_50_bits != Some(0) + { + state.mobile.stub(object, "motion_factory_5".into()); } if matches!(device.factory_tag, 2 | 30) && f32::from_bits(device.descriptor.fixed_words[8]) != 0.0 @@ -220,6 +236,7 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) { #[derive(Default)] struct ResourceClock { frame_ms: f32, + previous_pose: Option<TransformState>, resource_ms: f32, forced: u32, alarm: control_profile::DamageAlarm, |
