aboutsummaryrefslogtreecommitdiff
path: root/stockton-levels/src/parts/faces.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:23 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:23 +0100
commit439219e74090c7158f8dbc33fed4107a5eb7c003 (patch)
tree7ba62254b2d888578ff6c1c8de4f0f35c01c75dd /stockton-levels/src/parts/faces.rs
parent04f17923d38171f07f72603a54237f20ca3572dd (diff)
refactor(levels): no longer q3 specific
Diffstat (limited to 'stockton-levels/src/parts/faces.rs')
-rw-r--r--stockton-levels/src/parts/faces.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/stockton-levels/src/parts/faces.rs b/stockton-levels/src/parts/faces.rs
new file mode 100644
index 0000000..0168cd8
--- /dev/null
+++ b/stockton-levels/src/parts/faces.rs
@@ -0,0 +1,43 @@
+use super::{textures::TextureRef, vertices::Vertex};
+use serde::{Deserialize, Serialize};
+
+pub type FaceRef = u32;
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub enum Geometry {
+ Vertices(Vertex, Vertex, Vertex),
+}
+
+pub trait IsFace<C: HasFaces + ?Sized> {
+ fn index(&self, container: &C) -> FaceRef;
+ fn geometry(&self, container: &C) -> Geometry;
+ fn texture_idx(&self, container: &C) -> TextureRef;
+}
+
+pub trait HasFaces {
+ type Face: IsFace<Self>;
+
+ fn get_face(&self, index: FaceRef) -> Option<&Self::Face>;
+ fn iter_faces(&self) -> Faces<Self> {
+ Faces {
+ next: 0,
+ container: self,
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct Faces<'a, T: HasFaces + ?Sized> {
+ next: FaceRef,
+ container: &'a T,
+}
+
+impl<'a, T: HasFaces> Iterator for Faces<'a, T> {
+ type Item = &'a T::Face;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ let res = self.container.get_face(self.next);
+ self.next += 1;
+ res
+ }
+}