From 58b8df3f51ade9d8c689e0421272295038757d06 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 16 Oct 2023 21:58:06 +0200 Subject: feat(engine): store objects in engine --- engine/src/object.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'engine/src/object.rs') diff --git a/engine/src/object.rs b/engine/src/object.rs index a650abc..11ba7e6 100644 --- a/engine/src/object.rs +++ b/engine/src/object.rs @@ -10,6 +10,7 @@ use crate::vertex::Vertex; #[derive(Debug)] pub struct Object { + id: Id, renderable: Renderable, } @@ -19,7 +20,7 @@ impl Object /// /// # Errors /// Will return `Err` if shader creation fails or if shader program linking fails. - pub fn new(vertices: &[Vertex]) -> Result + pub fn new(id: Id, vertices: &[Vertex]) -> Result { let vertex_shader = Shader::new(ShaderKind::Vertex); @@ -52,7 +53,14 @@ impl Object let renderable = Renderable::new(shader_program, vertices); - Ok(Self { renderable }) + Ok(Self { id, renderable }) + } + + /// Returns the object ID. + #[must_use] + pub fn id(&self) -> Id + { + self.id } pub(crate) fn renderable(&self) -> &Renderable @@ -74,3 +82,20 @@ pub enum Error #[error("Failed to link shader program")] LinkShaderProgramFailed(#[source] ShaderError), } + +/// Object ID. +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Id +{ + id: u16, +} + +impl Id +{ + /// Returns a new object ID. + #[must_use] + pub fn new(id: u16) -> Self + { + Self { id } + } +} -- cgit v1.2.3-18-g5258