summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-20 20:19:47 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-20 20:19:47 +0100
commitd5d2cf91f6c019d4b491e7ec245278a7703a5b03 (patch)
treea6027216ee84392fb8a81fb194e45047f8ec9ecc /shared
parentc2af119485fd62956d15bdf1155a0fdd7d0cf73e (diff)
downloadweareserver-d5d2cf91f6c019d4b491e7ec245278a7703a5b03.tar
weareserver-d5d2cf91f6c019d4b491e7ec245278a7703a5b03.tar.bz2
weareserver-d5d2cf91f6c019d4b491e7ec245278a7703a5b03.tar.zst
update armature types
Diffstat (limited to 'shared')
-rw-r--r--shared/src/helper.rs68
-rw-r--r--shared/src/lib.rs2
-rw-r--r--shared/src/packets.rs4
-rw-r--r--shared/src/resources.rs19
4 files changed, 88 insertions, 5 deletions
diff --git a/shared/src/helper.rs b/shared/src/helper.rs
index 723f91e..14fb2bd 100644
--- a/shared/src/helper.rs
+++ b/shared/src/helper.rs
@@ -220,6 +220,63 @@ impl ReadWrite for Vec<f32> {
.collect())
}
}
+impl ReadWrite for Vec<u16> {
+ fn write(&self, w: &mut dyn Write) -> Result<()> {
+ for e in self {
+ e.write(w)?;
+ }
+ Ok(())
+ }
+ fn read(r: &mut dyn Read) -> Result<Self> {
+ let mut buf = Vec::new();
+ r.read_to_end(&mut buf)?;
+ Ok(buf
+ .into_iter()
+ .array_chunks::<{ size_of::<u16>() }>()
+ .map(u16::from_be_bytes)
+ .collect())
+ }
+}
+impl ReadWrite for Vec<Affine3A> {
+ fn write(&self, w: &mut dyn Write) -> Result<()> {
+ for e in self {
+ e.write(w)?;
+ }
+ Ok(())
+ }
+ fn read(r: &mut dyn Read) -> Result<Self> {
+ let mut buf = Vec::new();
+ r.read_to_end(&mut buf)?;
+ Ok(buf
+ .into_iter()
+ .array_chunks::<{ size_of::<f32>() }>()
+ .map(f32::from_be_bytes)
+ .array_chunks::<12>()
+ .map(|m| Affine3A::from_cols_array(&m))
+ .collect())
+ }
+}
+impl ReadWrite for Vec<String> {
+ fn write(&self, w: &mut dyn Write) -> Result<()> {
+ for e in self {
+ w.write_all(&(e.len() as u16).to_le_bytes())?;
+ w.write_all(e.as_bytes())?;
+ }
+ Ok(())
+ }
+ fn read(r: &mut dyn Read) -> Result<Self> {
+ let mut buf = Vec::new();
+ r.read_to_end(&mut buf)?;
+ let mut buf = buf.as_slice();
+ let mut out = Vec::new();
+ while !buf.is_empty() {
+ let size = u16::read(&mut buf)? as usize;
+ out.push(String::read(&mut &buf[..size])?);
+ buf = &buf[size..];
+ }
+ Ok(out)
+ }
+}
impl ReadWrite for String {
fn write(&self, w: &mut dyn Write) -> Result<()> {
w.write_all(self.as_bytes())?;
@@ -364,3 +421,14 @@ impl ReadWrite for u8 {
Ok(buf[0])
}
}
+impl ReadWrite for u16 {
+ fn write(&self, w: &mut dyn Write) -> Result<()> {
+ w.write_all(&self.to_be_bytes())?;
+ Ok(())
+ }
+ fn read(r: &mut dyn Read) -> Result<Self> {
+ let mut buf = [0u8; 2];
+ r.read_exact(&mut buf)?;
+ Ok(u16::from_be_bytes(buf))
+ }
+}
diff --git a/shared/src/lib.rs b/shared/src/lib.rs
index 11ed2ce..2c26486 100644
--- a/shared/src/lib.rs
+++ b/shared/src/lib.rs
@@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#![feature(iter_array_chunks, array_try_map)]
+#![feature(iter_array_chunks, array_try_map, debug_closure_helpers)]
pub mod helper;
pub mod packets;
diff --git a/shared/src/packets.rs b/shared/src/packets.rs
index de69ffd..1f0dab1 100644
--- a/shared/src/packets.rs
+++ b/shared/src/packets.rs
@@ -208,6 +208,8 @@ impl Debug for Data {
}
impl Display for Object {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_tuple("Object").field(&self.0).finish()
+ f.debug_tuple("Object")
+ .field_with(|f| write!(f, "{:016x}", self.0))
+ .finish()
}
}
diff --git a/shared/src/resources.rs b/shared/src/resources.rs
index 59d88b6..1b2136d 100644
--- a/shared/src/resources.rs
+++ b/shared/src/resources.rs
@@ -89,7 +89,7 @@ pub struct MeshPart {
#[derive(Debug, Default, Clone)]
pub struct Armature {
- pub parent: Option<Vec<u32>>,
+ pub parent: Option<Vec<u16>>,
pub transform: Option<Vec<Affine3A>>,
pub name: Option<Vec<String>>,
}
@@ -135,10 +135,23 @@ impl ReadWrite for PrefabIndex {
impl ReadWrite for Armature {
fn write(&self, w: &mut dyn Write) -> Result<()> {
- todo!()
+ write_kv_opt(w, b"parent", &self.parent)?;
+ write_kv_opt(w, b"transform", &self.transform)?;
+ write_kv_opt(w, b"name", &self.name)?;
+ Ok(())
}
fn read(r: &mut dyn Read) -> Result<Self> {
- todo!()
+ let mut s = Self::default();
+ read_kv_iter(r, |k, v| match k {
+ b"parent" => Ok(s.parent = Some(read_slice(v)?)),
+ b"name" => Ok(s.name = Some(read_slice(v)?)),
+ b"transform" => Ok(s.transform = Some(read_slice(v)?)),
+ x => Ok(warn!(
+ "unknown armature key: {:?}",
+ String::from_utf8_lossy(x)
+ )),
+ })?;
+ Ok(s)
}
}
impl ReadWrite for CollisionPart {