aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/cockpit_instruments.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/cockpit_instruments.rs')
-rw-r--r--crates/fparkan-runtime/src/cockpit_instruments.rs63
1 files changed, 61 insertions, 2 deletions
diff --git a/crates/fparkan-runtime/src/cockpit_instruments.rs b/crates/fparkan-runtime/src/cockpit_instruments.rs
index 6aa2e3f6..88ea8df5 100644
--- a/crates/fparkan-runtime/src/cockpit_instruments.rs
+++ b/crates/fparkan-runtime/src/cockpit_instruments.rs
@@ -3,8 +3,10 @@
use crate::{
control_device_provider_value, control_device_selector_zero,
projectile::unit_sphere,
+ projectile_shield::{enclosing_sphere, world_sphere},
query_control_device_table_selector,
strategic_map_readout::{contact_readout, ContactReadout},
+ weapon_pose::WeaponPoses,
Engine, MissionControlDeviceTableStatus, StartingCockpit, HERO_UNIT_CLASS,
};
use fparkan_world::{identity_metadata, transform_state, ObjectHandle};
@@ -87,15 +89,27 @@ pub fn instrument_readout(
})
}
-/// The same root sphere used for the live object's spatial queries.
+/// Local sphere used by AniMesh selector 2 with the targeter's node filter.
+pub fn instrument_bounds(engine: &Engine, object_index: usize) -> Option<([f32; 3], f32)> {
+ let mission = engine.loaded.as_ref()?;
+ let draft = mission.object_drafts.get(object_index)?;
+ let poses = WeaponPoses::new(draft, &mission.mission_assets, object_index);
+ enclosing_sphere(&poses.instrument_node_spheres(&mission.mission_assets, object_index))
+}
+
+/// Places the sphere in the object's current world pose.
pub fn instrument_sphere(
engine: &Engine,
subject: ObjectHandle,
object_index: usize,
+ bounds: Option<([f32; 3], f32)>,
) -> Option<([f32; 3], f32)> {
let mission = engine.loaded.as_ref()?;
let pose = transform_state(&engine.world, subject).ok()?;
- unit_sphere(&mission.mission_assets, object_index, pose)
+ bounds.map_or_else(
+ || unit_sphere(&mission.mission_assets, object_index, pose),
+ |bounds| world_sphere(bounds, pose),
+ )
}
/// Targeter distance is the 3D separation of the two centers in world units.
@@ -138,3 +152,48 @@ fn targeter_distance_includes_height_and_rounds_to_even() {
assert_eq!(instrument_distance([0.0; 3], [0.0, 0.0, 4.5]), Some(4));
assert_eq!(instrument_distance([0.0; 3], [0.0; 3]), None);
}
+
+#[cfg(test)]
+#[test]
+#[ignore = "requires licensed corpus"]
+fn licensed_targeter_bounds_match_the_original_hero_and_bunker() {
+ use crate::{
+ create, load_gameplay_mission, starting_cockpit, 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/Single.01/data.tma".into(),
+ mode: MissionMode::SingleMission,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ None,
+ )
+ .unwrap();
+
+ // Local bounds observed on the stock start, AniMesh+0xf3b0.
+ let hero = starting_cockpit(&engine).unwrap();
+ for (index, expected_center, expected_radius) in [
+ (
+ hero.object_index,
+ [-0.001875045, -0.17754595, 0.0161541],
+ 1.5871644,
+ ),
+ (0, [-0.00038418506, -0.036218945, 5.9308352], 54.111202),
+ ] {
+ let (center, radius) = instrument_bounds(&engine, index).unwrap();
+ for (actual, expected) in center.into_iter().zip(expected_center) {
+ assert!((actual - expected).abs() < 0.0001, "{center:?}");
+ }
+ assert!((radius - expected_radius).abs() < 0.0001, "{radius}");
+ }
+}