use std::sync::atomic::{AtomicUsize, Ordering}; use ecs::Component; use crate::util::builder; static CURRENT_BUNDLE_ID: AtomicUsize = AtomicUsize::new(0); builder! { /// Flags for how a object should be drawn. #[builder(name = Builder, derives = (Debug, Default, Clone))] #[derive(Debug, Default, Clone, Component)] #[non_exhaustive] pub struct DrawFlags { pub polygon_mode_config: PolygonModeConfig, } } impl DrawFlags { pub fn builder() -> Builder { Builder::default() } } #[derive(Debug, Default, Clone)] pub struct PolygonModeConfig { pub face: PolygonModeFace, pub mode: PolygonMode, } #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum PolygonMode { Point, Line, #[default] Fill, } #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum PolygonModeFace { Front, Back, #[default] FrontAndBack, } /// Metadata for how a object should be drawn together with other objects. #[derive(Debug, Clone, Component)] pub struct DrawingBundled { pub bundle_id: DrawingBundleId, pub order: usize, } /// The ID of a object drawing bundle. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DrawingBundleId { inner: usize, } impl DrawingBundleId { /// Creates a new unique bundle ID. pub fn new() -> Self { Self { inner: CURRENT_BUNDLE_ID.fetch_add(1, Ordering::Relaxed), } } pub fn inner(&self) -> usize { self.inner } }