diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-16 21:58:06 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-16 21:58:06 +0200 |
commit | 58b8df3f51ade9d8c689e0421272295038757d06 (patch) | |
tree | f529cb841b839a3d4f6a1e800d0f1d897b125a2f /engine/src/object.rs | |
parent | d343bbd9c14d152ab8523718f5de309842b667b4 (diff) |
feat(engine): store objects in engine
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 } + } +} |