aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src/culling.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:21 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:21 +0100
commit2111c1248b08236a839dcf22036f92735bceb31c (patch)
tree9313da344b7134a913d1d917162e55b35fe1e74f /stockton-render/src/culling.rs
parent102e166b040030b590df83888a1d1a47d0130f10 (diff)
chore(all): style formatting and clippy fixes
Diffstat (limited to 'stockton-render/src/culling.rs')
-rw-r--r--stockton-render/src/culling.rs90
1 files changed, 46 insertions, 44 deletions
diff --git a/stockton-render/src/culling.rs b/stockton-render/src/culling.rs
index 8240701..dbe5a1e 100644
--- a/stockton-render/src/culling.rs
+++ b/stockton-render/src/culling.rs
@@ -20,59 +20,61 @@ use stockton_levels::prelude::*;
use stockton_levels::traits::tree::{BSPNode, BSPNodeValue};
use stockton_types::Vector3;
-
/// Get the visible faces according to visdata and frustum culling
// TODO: Write this. For now, just render all faces
pub fn get_visible_faces<X: CoordSystem, T: MinBSPFeatures<X>>(pos: Vector3, file: &T) -> Vec<u32> {
- let vis_cluster = get_cluster_id(pos, file);
-
- if (vis_cluster & 0x80000000) != 0 { // Negative = Invalid camera position
- return vec![];
- }
+ let vis_cluster = get_cluster_id(pos, file);
+
+ if (vis_cluster & 0x80000000) != 0 {
+ // Negative = Invalid camera position
+ return vec![];
+ }
- let mut visible = Vec::with_capacity(file.faces_len() as usize);
- walk_bsp_tree(file.get_bsp_root(), vis_cluster, &mut visible, file);
+ let mut visible = Vec::with_capacity(file.faces_len() as usize);
+ walk_bsp_tree(file.get_bsp_root(), vis_cluster, &mut visible, file);
- return visible;
+ visible
}
-pub fn walk_bsp_tree<X: CoordSystem, T: MinBSPFeatures<X>>(node: &BSPNode, vis_cluster: u32, visible_faces: &mut Vec<u32>, file: &T) -> () {
- if let BSPNodeValue::Children(front, back) = &node.value {
- walk_bsp_tree(back, vis_cluster, visible_faces, file);
- walk_bsp_tree(front, vis_cluster, visible_faces, file);
- } else if let BSPNodeValue::Leaf(leaf) = &node.value {
- if (leaf.cluster_id & 0x80000000) != 0 { // Negative means invalid leaf
- return;
- } else if file.cluster_visible_from(vis_cluster, leaf.cluster_id) {
- for face_idx in leaf.faces_idx.iter() {
- // TODO: Culling or something
- visible_faces.push(*face_idx);
- }
- }
- }
+pub fn walk_bsp_tree<X: CoordSystem, T: MinBSPFeatures<X>>(
+ node: &BSPNode,
+ vis_cluster: u32,
+ visible_faces: &mut Vec<u32>,
+ file: &T,
+) {
+ if let BSPNodeValue::Children(front, back) = &node.value {
+ walk_bsp_tree(back, vis_cluster, visible_faces, file);
+ walk_bsp_tree(front, vis_cluster, visible_faces, file);
+ } else if let BSPNodeValue::Leaf(leaf) = &node.value {
+ if (leaf.cluster_id & 0x80000000) != 0 {
+ // Negative means invalid leaf
+ return;
+ } else if file.cluster_visible_from(vis_cluster, leaf.cluster_id) {
+ for face_idx in leaf.faces_idx.iter() {
+ // TODO: Culling or something
+ visible_faces.push(*face_idx);
+ }
+ }
+ }
}
-/// Get the viscluster pos lies in
+/// Get the viscluster pos lies in
fn get_cluster_id<X: CoordSystem, T: MinBSPFeatures<X>>(pos: Vector3, file: &T) -> u32 {
- let mut node = file.get_bsp_root();
- loop {
- if let BSPNodeValue::Children(front, back) = &node.value {
- let plane = file.get_plane(node.plane_idx);
- let dist = plane.normal.dot(&pos) - plane.dist;
+ let mut node = file.get_bsp_root();
+ while let BSPNodeValue::Children(front, back) = &node.value {
+ let plane = file.get_plane(node.plane_idx);
+ let dist = plane.normal.dot(&pos) - plane.dist;
- if dist >= 0.0 {
- node = front;
- } else {
- node = back;
- }
- } else {
- break;
- }
- }
+ if dist >= 0.0 {
+ node = front;
+ } else {
+ node = back;
+ }
+ }
- if let BSPNodeValue::Leaf(leaf) = &node.value {
- leaf.cluster_id
- } else {
- panic!("should have had a leaf but didn't");
- }
-} \ No newline at end of file
+ if let BSPNodeValue::Leaf(leaf) = &node.value {
+ leaf.cluster_id
+ } else {
+ panic!("should have had a leaf but didn't");
+ }
+}