diff options
Diffstat (limited to 'engine/src/object.rs')
-rw-r--r-- | engine/src/object.rs | 29 |
1 files changed, 27 insertions, 2 deletions
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<Self, Error> + pub fn new(id: Id, vertices: &[Vertex]) -> Result<Self, Error> { 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 } + } +} |