From a6f57036bc954bab45d61fb41c1bd0a27001bad6 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 5 Jan 2025 20:31:28 +0100 Subject: a --- shared/src/resources.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'shared/src/resources.rs') diff --git a/shared/src/resources.rs b/shared/src/resources.rs index c54d10b..651eb4b 100644 --- a/shared/src/resources.rs +++ b/shared/src/resources.rs @@ -18,8 +18,10 @@ pub struct Part { pub texture: Option, } -pub struct VertexAttributes(Vec); -pub struct Indecies(Vec<[u16; 3]>); +#[derive(Debug, Default, Clone)] +pub struct VertexAttributes(pub Vec); +#[derive(Debug, Default, Clone)] +pub struct Indecies(pub Vec<[u16; 3]>); impl Prefab { pub fn serialize(&self, w: &mut Vec) -> Result<()> { @@ -69,28 +71,28 @@ impl VertexAttributes { impl Part { pub fn serialize(&self, w: &mut Vec) -> Result<()> { for x in &self.vertex { - write_kv(w, b"vertex", &x.0)?; + write_kv(w, b"vertex", &x.0); } if let Some(x) = &self.index { - write_kv(w, b"index", &x.0)?; + write_kv(w, b"index", &x.0); } if let Some(x) = &self.armature { - write_kv(w, b"armature", &x.0)?; + write_kv(w, b"armature", &x.0); } if let Some(x) = &self.fragment_shader { - write_kv(w, b"fragment_shader", &x.0)?; + write_kv(w, b"fragment_shader", &x.0); } if let Some(x) = &self.fragment_shader_data { - write_kv(w, b"fragment_shader_data", &x.0)?; + write_kv(w, b"fragment_shader_data", &x.0); } if let Some(x) = &self.vertex_shader { - write_kv(w, b"vertex_shader", &x.0)?; + write_kv(w, b"vertex_shader", &x.0); } if let Some(x) = &self.vertex_shader_data { - write_kv(w, b"vertex_shader_data", &x.0)?; + write_kv(w, b"vertex_shader_data", &x.0); } if let Some(x) = &self.texture { - write_kv(w, b"texture", &x.0)?; + write_kv(w, b"texture", &x.0); } Ok(()) } @@ -132,10 +134,9 @@ fn read_kv(r: &mut &[u8]) -> Result<(Vec, Vec)> { r.read_exact(&mut key)?; Ok((key, value)) } -fn write_kv(w: &mut Vec, key: &[u8], value: &[u8]) -> Result<()> { - w.write_all(&(key.len() as u16).to_be_bytes())?; - w.write_all(&(value.len() as u16).to_be_bytes())?; - w.write_all(key)?; - w.write_all(value)?; - Ok(()) +fn write_kv(w: &mut Vec, key: &[u8], value: &[u8]) { + w.extend(&(key.len() as u16).to_be_bytes()); + w.extend(&(value.len() as u16).to_be_bytes()); + w.extend(key); + w.extend(value); } -- cgit v1.2.3-70-g09d2