aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-runtime/src/capture_barrier.rs18
-rw-r--r--crates/fparkan-runtime/src/factory_release.rs3
-rw-r--r--crates/fparkan-runtime/src/projectile.rs19
-rw-r--r--crates/fparkan-runtime/src/projectile_parts.rs29
4 files changed, 50 insertions, 19 deletions
diff --git a/crates/fparkan-runtime/src/capture_barrier.rs b/crates/fparkan-runtime/src/capture_barrier.rs
index 4375e379..de14c6be 100644
--- a/crates/fparkan-runtime/src/capture_barrier.rs
+++ b/crates/fparkan-runtime/src/capture_barrier.rs
@@ -4,7 +4,7 @@ use crate::projectile_parts::{model_triangle_hit, root_model};
use crate::{Engine, LoadedMissionState, MissionAssets, ProjectileNode, TransformState};
use fparkan_animation::AnimationTime;
use fparkan_assets::{PreparedComponentControl, PreparedControlTimelineRow};
-use fparkan_msh::node38_sampled_hierarchy_at_times;
+use fparkan_msh::{node38_sampled_hierarchy_at_times, Lod};
use fparkan_world::{transform_state, ObjectHandle, World};
pub(super) struct CaptureBarrier {
@@ -148,8 +148,20 @@ pub(super) fn projectile_contact(
segment: [[f32; 3]; 2],
) -> Option<(f32, ProjectileNode)> {
let assets = &mission.mission_assets;
+ let table = mission
+ .control_device_tables
+ .iter()
+ .find(|table| table.handle == building);
+ let node_stage = |node| {
+ let stage = table
+ .and_then(|table| crate::control_node_provider_row(table, node).ok())
+ .filter(|row| row.unit_component_index == 0 && row.source_row_index == node as usize)
+ .and_then(|row| row.mesh_state)
+ .map_or(0, |state| state.visible_stage);
+ Some(Lod(u8::try_from(stage).ok()?))
+ };
let fallback = || {
- crate::projectile_parts::root_triangle_hit(assets, index, state, segment, |_| true)
+ crate::projectile_parts::root_triangle_hit(assets, index, state, segment, node_stage)
.map(|(fraction, node)| (fraction, ProjectileNode::Building(node)))
};
let Some(control) = control(assets, index).filter(|control| rows(control).next().is_some())
@@ -167,7 +179,7 @@ pub(super) fn projectile_contact(
let Some(poses) = node38_sampled_hierarchy_at_times(model, &times) else {
return fallback();
};
- let (fraction, node) = model_triangle_hit(model, poses, state, segment, |_| true)?;
+ let (fraction, node) = model_triangle_hit(model, poses, state, segment, node_stage)?;
let node = if times[node as usize].is_some() {
ProjectileNode::CaptureBarrier
} else {
diff --git a/crates/fparkan-runtime/src/factory_release.rs b/crates/fparkan-runtime/src/factory_release.rs
index 7a3b724f..93eb0c79 100644
--- a/crates/fparkan-runtime/src/factory_release.rs
+++ b/crates/fparkan-runtime/src/factory_release.rs
@@ -9,6 +9,7 @@ use crate::{
route_traffic::{body_radius, FrameTraffic},
EngineError, LoadedMissionState, ObjectHandle, TransformState, World,
};
+use fparkan_msh::Lod;
use fparkan_terrain::SurfaceQuery;
use fparkan_world::transform_state;
use std::collections::VecDeque;
@@ -81,7 +82,7 @@ pub(super) fn clear_release_position(
plant_index,
plant_pose,
[[x, y, top], [x, y, terrain]],
- |_| true,
+ |_| Some(Lod(0)),
) {
let roof = top + fraction * (terrain - top);
site.exit = Some(site.exit.unwrap_or([site.position[0], site.position[1]]));
diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs
index 51adc045..55e5da46 100644
--- a/crates/fparkan-runtime/src/projectile.rs
+++ b/crates/fparkan-runtime/src/projectile.rs
@@ -702,6 +702,22 @@ mod tests {
device.class9_values_bits = Some([0; 6]);
}
}
+ let pose = transform_state(&engine.world, plant).unwrap();
+ let assets = &engine.loaded.as_ref().unwrap().mission_assets;
+ let ([x, y, z], radius) = unit_sphere(assets, 5, pose).unwrap();
+ let shooter = crate::starting_cockpit(&engine).unwrap().handle;
+ let intact_roof = (-8..=8)
+ .flat_map(|i| (-8..=8).map(move |j| (i, j)))
+ .filter_map(|(i, j)| {
+ let x = x + radius * i as f32 / 8.0;
+ let y = y + radius * j as f32 / 8.0;
+ let start = [x, y, z + radius];
+ let hit = projectile_unit_hit(&engine, shooter, [start, [x, y, z - radius]])?;
+ (hit.handle == plant && hit.node == Some(ProjectileNode::Building(1)))
+ .then_some([start, [x, y, hit.position[2] - 0.25]])
+ })
+ .collect::<Vec<_>>();
+ assert!(!intact_roof.is_empty());
let stage_contact = ProjectileContact {
handle: plant,
fraction: 0.5,
@@ -733,6 +749,9 @@ mod tests {
.visible_stage,
0
);
+ assert!(intact_roof
+ .iter()
+ .any(|&ray| projectile_unit_hit(&engine, shooter, ray).is_none()));
let contact = ProjectileContact {
handle: plant,
fraction: 0.5,
diff --git a/crates/fparkan-runtime/src/projectile_parts.rs b/crates/fparkan-runtime/src/projectile_parts.rs
index 8094ba0b..2a035e2f 100644
--- a/crates/fparkan-runtime/src/projectile_parts.rs
+++ b/crates/fparkan-runtime/src/projectile_parts.rs
@@ -81,11 +81,13 @@ pub(super) fn chassis_part_contact(
};
let chassis = sphere_fraction.and_then(|_| {
root_triangle_hit(&mission.mission_assets, index, state, segment, |node| {
- rows.get(node as usize).is_some_and(|row| {
- row.unit_component_index == 0
- && row.source_row_index == node as usize
- && viable(row)
- })
+ rows.get(node as usize)
+ .filter(|row| {
+ row.unit_component_index == 0
+ && row.source_row_index == node as usize
+ && viable(row)
+ })
+ .map(|_| Lod(0))
})
.map(|(fraction, node)| (fraction, ProjectileNode::Chassis(node)))
});
@@ -187,7 +189,7 @@ fn mounted_triangle_hit(
model_segment,
[1.0; 3],
squared_length(model_segment),
- |node| key(node).is_some(),
+ |node| key(node).map(|_| Lod(0)),
)?;
Some((
fraction,
@@ -207,12 +209,12 @@ pub(super) fn root_triangle_hit(
index: usize,
state: TransformState,
segment: [[f32; 3]; 2],
- accept_node: impl Fn(u32) -> bool,
+ node_stage: impl Fn(u32) -> Option<Lod>,
) -> Option<(f32, u32)> {
let model = &root_model(assets, index)?.validated;
// shortcut: use root MSH fallback poses until combat shares live component transforms.
let poses = node38_fallback_hierarchy(model)?;
- model_triangle_hit(model, poses, state, segment, accept_node)
+ model_triangle_hit(model, poses, state, segment, node_stage)
}
pub(super) fn model_triangle_hit(
@@ -220,7 +222,7 @@ pub(super) fn model_triangle_hit(
poses: NodePoseBuffer,
state: TransformState,
segment: [[f32; 3]; 2],
- accept_node: impl Fn(u32) -> bool,
+ node_stage: impl Fn(u32) -> Option<Lod>,
) -> Option<(f32, u32)> {
let root = LegacyIron3dEulerTransform {
translation: state.position.map(f32::from_bits),
@@ -241,7 +243,7 @@ pub(super) fn model_triangle_hit(
body_segment,
scale,
squared_length(segment),
- accept_node,
+ node_stage,
)
}
@@ -257,7 +259,7 @@ fn triangle_hit(
body_segment: [[f32; 3]; 2],
scale: [f32; 3],
squared_length: f32,
- accept_node: impl Fn(u32) -> bool,
+ node_stage: impl Fn(u32) -> Option<Lod>,
) -> Option<(f32, u32)> {
if squared_length == 0.0 {
return None;
@@ -269,10 +271,7 @@ fn triangle_hit(
.enumerate()
.filter_map(|(i, pose)| {
let node = NodeId(u32::try_from(i).ok()?);
- if !accept_node(node.0) {
- return None;
- }
- let slot = selected_slot(model, node, Lod(0), Group(0))?;
+ let slot = selected_slot(model, node, node_stage(node.0)?, Group(0))?;
let mut inverse = pose;
inverse.translation = [0.0; 3];
for component in &mut inverse.rotation[..3] {