summaryrefslogtreecommitdiff
path: root/shared/src/resources.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-05 20:31:28 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-05 20:31:28 +0100
commita6f57036bc954bab45d61fb41c1bd0a27001bad6 (patch)
tree2d01687549003cd2c38c9fc772e4ba543cd1b646 /shared/src/resources.rs
parentf2fa92e701b8da8e9d2e091ade21784623710374 (diff)
downloadweareserver-a6f57036bc954bab45d61fb41c1bd0a27001bad6.tar
weareserver-a6f57036bc954bab45d61fb41c1bd0a27001bad6.tar.bz2
weareserver-a6f57036bc954bab45d61fb41c1bd0a27001bad6.tar.zst
a
Diffstat (limited to 'shared/src/resources.rs')
-rw-r--r--shared/src/resources.rs33
1 files changed, 17 insertions, 16 deletions
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<Resource>,
}
-pub struct VertexAttributes(Vec<f32>);
-pub struct Indecies(Vec<[u16; 3]>);
+#[derive(Debug, Default, Clone)]
+pub struct VertexAttributes(pub Vec<f32>);
+#[derive(Debug, Default, Clone)]
+pub struct Indecies(pub Vec<[u16; 3]>);
impl Prefab {
pub fn serialize(&self, w: &mut Vec<u8>) -> Result<()> {
@@ -69,28 +71,28 @@ impl VertexAttributes {
impl Part {
pub fn serialize(&self, w: &mut Vec<u8>) -> 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<u8>, Vec<u8>)> {
r.read_exact(&mut key)?;
Ok((key, value))
}
-fn write_kv(w: &mut Vec<u8>, 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<u8>, 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);
}