aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fparkan-game/src/main.rs')
-rw-r--r--apps/fparkan-game/src/main.rs136
1 files changed, 40 insertions, 96 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 475ed8b3..b8536c48 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -16,6 +16,7 @@ mod control_effects;
use control_effects::advance_control_effect_instances;
mod damage_visibility;
mod debris;
+mod designer_geometry;
mod designer_projects;
mod destruction_effects;
mod factory_menu;
@@ -27,6 +28,7 @@ mod mission_loading;
mod mission_notices;
mod mission_overlay;
mod mission_pause;
+mod model_mounts;
mod motion_effects;
mod player_collision;
mod satellite_map;
@@ -2686,17 +2688,9 @@ fn mounted_shadow_sphere(
.then_some(ShadowComponentSphere { center, radius })
}
-fn aggregate_shadow_caster(
- id: u32,
- native_kind: u32,
- transform: LegacyIron3dEulerTransform,
- scale: [f32; 3],
- triangles: Vec<ShadowTriangle>,
+fn aggregate_component_sphere(
component_spheres: &[ShadowComponentSphere],
-) -> Option<ShadowCaster> {
- if triangles.is_empty() {
- return None;
- }
+) -> Option<ShadowComponentSphere> {
let weight = component_spheres
.iter()
.map(|sphere| sphere.radius)
@@ -2714,15 +2708,37 @@ fn aggregate_shadow_caster(
.iter()
.map(|sphere| length3(sub3(sphere.center, aggregate_center)).unwrap_or(0.0) + sphere.radius)
.fold(0.0, f32::max);
- let max_scale = scale.iter().copied().fold(f32::NEG_INFINITY, f32::max);
if !aggregate_center.iter().all(|value| value.is_finite())
|| !radius.is_finite()
|| radius <= f32::EPSILON
- || !max_scale.is_finite()
- || max_scale <= 0.0
{
return None;
}
+ Some(ShadowComponentSphere {
+ center: aggregate_center,
+ radius,
+ })
+}
+
+fn aggregate_shadow_caster(
+ id: u32,
+ native_kind: u32,
+ transform: LegacyIron3dEulerTransform,
+ scale: [f32; 3],
+ triangles: Vec<ShadowTriangle>,
+ component_spheres: &[ShadowComponentSphere],
+) -> Option<ShadowCaster> {
+ if triangles.is_empty() {
+ return None;
+ }
+ let ShadowComponentSphere {
+ center: aggregate_center,
+ radius,
+ } = aggregate_component_sphere(component_spheres)?;
+ let max_scale = scale.iter().copied().fold(f32::NEG_INFINITY, f32::max);
+ if !max_scale.is_finite() || max_scale <= 0.0 {
+ return None;
+ }
// The native scale flag applies to the aggregate exactly once. The
// mission Euler transform then rotates/translates that scaled sphere.
let scaled_center = [
@@ -8309,89 +8325,17 @@ fn static_preview_mesh_and_materials(
// geometry. Internal INTO components use controller/equipment
// slots, whose `parent_or_link` values are not MSH node indices.
// Do not ask the MSH hierarchy to resolve hidden internal parts.
- let mount_pose = if should_render {
- if let Some(tree) = tree.as_ref() {
- let record = records.get(component_index).ok_or_else(|| {
- format!("unit component {component_index} is outside decoded records")
- })?;
- let parent_index = tree[component_index].parent_index;
- match parent_index {
- None => None,
- Some(parent_index) => {
- let parent_visible = component_refs.get(parent_index).is_some_and(
- |(parent_visual, _)| {
- unit_component_is_visible(
- parent_index,
- parent_visual.source_type,
- )
- },
- );
- if !parent_visible {
- None
- } else {
- let parent_model = component_refs
- .get(parent_index)
- .and_then(|(_, model)| *model)
- .ok_or_else(|| {
- format!(
- "unit component {component_index} parent {parent_index} has no model for mount socket"
- )
- })?;
- let parent_hierarchy = component_pose_buffers
- .get(parent_index)
- .and_then(Option::as_ref);
- let parent_is_mounted =
- component_mount_poses[parent_index].is_some();
- let socket =
- usize::try_from(record.parent_or_link).map_err(|_| {
- format!(
- "unit component {component_index} has negative mount socket {}",
- record.parent_or_link
- )
- })?;
- let parent_socket = match parent_hierarchy {
- Some(hierarchy) if parent_is_mounted => {
- node38_pose_relative_to_root_from_hierarchy(
- hierarchy, socket,
- )
- }
- Some(hierarchy) => {
- node38_pose_from_hierarchy(hierarchy, socket)
- }
- None if parent_is_mounted => node38_pose_relative_to_root(
- &parent_model.validated,
- static_animation_frame,
- socket,
- ),
- None => node38_pose(
- &parent_model.validated,
- static_animation_frame,
- socket,
- ),
- }
- .ok_or_else(|| {
- format!(
- "unit component {component_index} mount socket {socket} is absent from parent {parent_index} (parent source={:?}, node_count={}, slots={}, animation={})",
- parent_model.source,
- parent_model.validated.node_count,
- parent_model.validated.slots.len(),
- parent_model.validated.animation.is_some(),
- )
- })?;
- let parent_root_pose = component_mount_poses[parent_index]
- .unwrap_or(VulkanNodePose {
- translation: [0.0; 3],
- rotation: [0.0, 0.0, 0.0, 1.0],
- });
- Some(compose_unit_pose(parent_root_pose, parent_socket))
- }
- }
- }
- } else {
- None
- }
- } else {
- None
+ let mount_pose = match tree.as_deref().filter(|_| should_render) {
+ Some(tree) => model_mounts::initial_mount(
+ component_index,
+ records,
+ tree,
+ &component_refs,
+ &component_pose_buffers,
+ &component_mount_poses,
+ static_animation_frame,
+ )?,
+ None => None,
};
if let Some(mount_pose) = mount_pose {
component_mount_poses[component_index] = Some(mount_pose);