aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/sun_visibility.rs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fparkan-game/src/sun_visibility.rs')
-rw-r--r--apps/fparkan-game/src/sun_visibility.rs48
1 files changed, 44 insertions, 4 deletions
diff --git a/apps/fparkan-game/src/sun_visibility.rs b/apps/fparkan-game/src/sun_visibility.rs
index b66094f4..8df3e75e 100644
--- a/apps/fparkan-game/src/sun_visibility.rs
+++ b/apps/fparkan-game/src/sun_visibility.rs
@@ -9,6 +9,7 @@ pub(super) struct SunOcclusionMaterials<'a> {
pub materials: &'a [VulkanStaticMaterial],
pub active: &'a HashMap<usize, ActiveMaterialState>,
pub hidden: &'a HashSet<usize>,
+ pub inactive_building_ranges: &'a HashSet<usize>,
pub boarded_hero: Option<usize>,
}
@@ -87,10 +88,12 @@ fn world_mesh_sun_occluded(
continue;
};
let material = world.as_ref().and_then(|world| {
- if range.owner_scope.checked_sub(1).is_some_and(|owner| {
- world.hidden.contains(&(owner as usize))
- || world.boarded_hero == Some(owner as usize)
- }) {
+ if world.inactive_building_ranges.contains(&range_index)
+ || range.owner_scope.checked_sub(1).is_some_and(|owner| {
+ world.hidden.contains(&(owner as usize))
+ || world.boarded_hero == Some(owner as usize)
+ })
+ {
return None;
}
let active = world.active.get(&range_index);
@@ -267,6 +270,7 @@ mod tests {
materials: &materials,
active: &HashMap::new(),
hidden,
+ inactive_building_ranges: &HashSet::new(),
boarded_hero: None,
}),
)
@@ -277,4 +281,40 @@ mod tests {
assert!(!blocked(0.75, &hidden));
assert!(!blocked(0.25, &removed));
}
+
+ #[test]
+ fn only_the_visible_building_stage_blocks_the_sun() {
+ let mut mesh = VulkanStaticMesh::smoke_triangle();
+ mesh.vertices = [0.0, 2.0]
+ .into_iter()
+ .flat_map(|y| [[5.0, y, 0.0], [5.0, y + 1.0, 0.0], [5.0, y, 1.0]])
+ .map(|position| environment_vertex(position, [1.0; 3], [0.0; 2]))
+ .collect();
+ mesh.indices = vec![0, 1, 2, 3, 4, 5];
+ let mut damaged = mesh.draw_ranges[0];
+ damaged.first_index = 3;
+ mesh.draw_ranges.push(damaged);
+ let mut materials = Vec::new();
+ crate::append_shadow_material(&mut materials).unwrap();
+ let blocked = |y, inactive| {
+ world_mesh_sun_occluded(
+ &mesh,
+ &[0, 1],
+ [0.0, y, 0.1],
+ [10.0, 0.0, 0.0],
+ Some(SunOcclusionMaterials {
+ materials: &materials,
+ active: &HashMap::new(),
+ hidden: &HashSet::new(),
+ inactive_building_ranges: &HashSet::from([inactive]),
+ boarded_hero: None,
+ }),
+ )
+ };
+
+ assert!(blocked(0.25, 1));
+ assert!(!blocked(0.25, 0));
+ assert!(!blocked(2.25, 1));
+ assert!(blocked(2.25, 0));
+ }
}