diff --git a/Cargo.lock b/Cargo.lock index 7aee2ce..1a68979 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -911,6 +911,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + [[package]] name = "cocoa" version = "0.24.1" @@ -2081,8 +2087,8 @@ name = "planet" version = "0.3.0" dependencies = [ "bevy", + "postcard", "rand", - "ron", "serde", ] @@ -2098,6 +2104,16 @@ dependencies = [ "miniz_oxide 0.3.7", ] +[[package]] +name = "postcard" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c2b180dc0bade59f03fd005cb967d3f1e5f69b13922dad0cd6e047cb8af2363" +dependencies = [ + "cobs", + "serde", +] + [[package]] name = "pp-rs" version = "0.2.1" diff --git a/planet/Cargo.toml b/planet/Cargo.toml index 24f2cf6..8954728 100644 --- a/planet/Cargo.toml +++ b/planet/Cargo.toml @@ -23,5 +23,7 @@ version = "1.0" default-features = false features = ["derive"] -[dependencies.ron] -version = "0.8.0" \ No newline at end of file +[dependencies.postcard] +version = "1.0.2" +default-features = false +features = ["use-std"] \ No newline at end of file diff --git a/planet/src/world_manager.rs b/planet/src/world_manager.rs index df9698c..274005e 100644 --- a/planet/src/world_manager.rs +++ b/planet/src/world_manager.rs @@ -19,7 +19,7 @@ use { #[derive(Debug)] pub enum LoadError { MissingSave(io::Error), - InvalidSave(ron::error::SpannedError), + InvalidSave(postcard::Error), } impl Error for LoadError { fn source(&self) -> Option<&(dyn Error + 'static)> { @@ -49,7 +49,7 @@ impl Display for LoadError { #[derive(Debug)] pub enum SaveError { MissingWorld, - SerializationError(ron::Error), + SerializationError(postcard::Error), FailedToWrite(io::Error), } impl Error for SaveError { @@ -94,30 +94,20 @@ impl WorldManager { } pub fn save_world>(&self, path: P) -> Result<(), SaveError> { - let world = match self.get_world() { - Some(world) => world, - None => { - warn!("No world to save"); - return Err(SaveError::MissingWorld); - }, + let Some(world) = self.get_world() else { + warn!("No world to save"); + return Err(SaveError::MissingWorld); }; - #[cfg(feature = "logging")] - let serialized = match ron::ser::to_string_pretty(world, default()) { + + + let serialized = match postcard::to_stdvec(world) { Ok(serialized) => serialized, Err(err) => { return Err(SaveError::SerializationError(err)); }, }; - #[cfg(not(feature = "logging"))] - let serialized = match ron::to_string(world) { - Ok(serialized) => serialized, - Err(err) => { - return Err(SaveError::SerializationError(err)); - }, - }; - - match File::create(path).unwrap().write_all(serialized.as_bytes()) { + match File::create(path).unwrap().write_all(serialized.as_slice()) { Ok(_) => Ok(()), Err(err) => Err(SaveError::FailedToWrite(err)), } @@ -130,14 +120,12 @@ impl WorldManager { return Err(LoadError::MissingSave(err)); }, }; - let mut buf = String::new(); - match file.read_to_string(&mut buf) { - Ok(_) => {}, - Err(err) => { - return Err(LoadError::MissingSave(err)); - }, + let mut buf = vec![]; + if let Err(err) = file.read_to_end(&mut buf) { + return Err(LoadError::MissingSave(err)); }; - match ron::from_str(buf.as_str()) { + + match postcard::from_bytes(buf.as_slice()) { Ok(world) => { self.world = Some(world); Ok(()) @@ -146,17 +134,6 @@ impl WorldManager { } } - // #[cfg(feature = "render")] - // pub fn toggle_contours(&mut self) { - // #[cfg(feature = "logging")] - // if self.contours { - // debug!("Turning terrain contours off"); - // } else { - // debug!("Turning terrain contours on"); - // } - // self.contours = !self.contours; - // } - #[must_use] pub fn get_world(&self) -> Option<&World> { self.world.as_ref()