From 4793e4411d98d97f879023dc072f3847201d49da Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 22 Jun 2024 23:00:37 +0200 Subject: feat(engine): add support for drawing objects as a bundle --- engine/src/draw_flags.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'engine/src/draw_flags.rs') diff --git a/engine/src/draw_flags.rs b/engine/src/draw_flags.rs index c8c11c9..1352fe2 100644 --- a/engine/src/draw_flags.rs +++ b/engine/src/draw_flags.rs @@ -1,7 +1,11 @@ +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))] @@ -47,3 +51,34 @@ pub enum PolygonModeFace #[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 + } +} -- cgit v1.2.3-18-g5258