mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Use MessagePack for more compact rtsim state persistence
This commit is contained in:
parent
a421c1239d
commit
0b06eaec6f
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -4318,6 +4318,12 @@ dependencies = [
|
|||||||
"regex",
|
"regex",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9423e2b32f7a043629287a536f21951e8c6a82482d0acb1eeebfc90bc2225b22"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peeking_take_while"
|
name = "peeking_take_while"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
@ -5096,6 +5102,28 @@ dependencies = [
|
|||||||
"syn 1.0.100",
|
"syn 1.0.100",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rmp"
|
||||||
|
version = "0.8.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44519172358fd6d58656c86ab8e7fbc9e1490c3e8f14d35ed78ca0dd07403c9f"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"num-traits",
|
||||||
|
"paste",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rmp-serde"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "25786b0d276110195fa3d6f3f31299900cf71dfbd6c28450f3f58a0e7f7a347e"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"rmp",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rodio"
|
name = "rodio"
|
||||||
version = "0.15.0"
|
version = "0.15.0"
|
||||||
@ -6913,6 +6941,7 @@ version = "0.10.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"enum-map",
|
"enum-map",
|
||||||
"hashbrown 0.12.3",
|
"hashbrown 0.12.3",
|
||||||
|
"rmp-serde",
|
||||||
"ron 0.8.0",
|
"ron 0.8.0",
|
||||||
"serde",
|
"serde",
|
||||||
"vek 0.15.8",
|
"vek 0.15.8",
|
||||||
|
@ -11,3 +11,4 @@ serde = { version = "1.0.110", features = ["derive"] }
|
|||||||
hashbrown = { version = "0.12", features = ["rayon", "serde", "nightly"] }
|
hashbrown = { version = "0.12", features = ["rayon", "serde", "nightly"] }
|
||||||
enum-map = { version = "2.4", features = ["serde"] }
|
enum-map = { version = "2.4", features = ["serde"] }
|
||||||
vek = { version = "0.15.8", features = ["serde"] }
|
vek = { version = "0.15.8", features = ["serde"] }
|
||||||
|
rmp-serde = "1.1.0"
|
||||||
|
@ -7,7 +7,6 @@ pub use self::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use self::helper::Latest;
|
use self::helper::Latest;
|
||||||
use ron::error::SpannedResult;
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
@ -17,12 +16,15 @@ pub struct Data {
|
|||||||
pub actors: Actors,
|
pub actors: Actors,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type ReadError = rmp_serde::decode::Error;
|
||||||
|
pub type WriteError = rmp_serde::encode::Error;
|
||||||
|
|
||||||
impl Data {
|
impl Data {
|
||||||
pub fn from_reader<R: Read>(reader: R) -> SpannedResult<Self> {
|
pub fn from_reader<R: Read>(reader: R) -> Result<Self, ReadError> {
|
||||||
ron::de::from_reader(reader)
|
rmp_serde::decode::from_read(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to<W: Write>(&self, writer: W) -> Result<(), ron::Error> {
|
pub fn write_to<W: Write>(&self, mut writer: W) -> Result<(), WriteError> {
|
||||||
ron::ser::to_writer(writer, self)
|
rmp_serde::encode::write(&mut writer, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use common::{
|
|||||||
vol::RectRasterableVol,
|
vol::RectRasterableVol,
|
||||||
};
|
};
|
||||||
use common_ecs::{dispatch, System};
|
use common_ecs::{dispatch, System};
|
||||||
use rtsim2::{data::Data, RtState};
|
use rtsim2::{data::{Data, ReadError}, RtState};
|
||||||
use specs::{DispatcherBuilder, WorldExt};
|
use specs::{DispatcherBuilder, WorldExt};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
@ -16,6 +16,7 @@ use std::{
|
|||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Instant,
|
time::Instant,
|
||||||
io::{self, Write},
|
io::{self, Write},
|
||||||
|
error::Error,
|
||||||
};
|
};
|
||||||
use enum_map::EnumMap;
|
use enum_map::EnumMap;
|
||||||
use tracing::{error, warn, info};
|
use tracing::{error, warn, info};
|
||||||
@ -51,7 +52,7 @@ impl RtSim {
|
|||||||
loop {
|
loop {
|
||||||
let mut backup_path = file_path.clone();
|
let mut backup_path = file_path.clone();
|
||||||
backup_path.set_extension(if i == 0 {
|
backup_path.set_extension(if i == 0 {
|
||||||
format!("ron_backup_{}", i)
|
format!("backup_{}", i)
|
||||||
} else {
|
} else {
|
||||||
"ron_backup".to_string()
|
"ron_backup".to_string()
|
||||||
});
|
});
|
||||||
@ -88,7 +89,7 @@ impl RtSim {
|
|||||||
data_dir.push("rtsim");
|
data_dir.push("rtsim");
|
||||||
data_dir
|
data_dir
|
||||||
});
|
});
|
||||||
path.push("state.ron");
|
path.push("state.dat");
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ impl RtSim {
|
|||||||
// TODO: Use slow job
|
// TODO: Use slow job
|
||||||
// slowjob_pool.spawn("RTSIM_SAVE", move || {
|
// slowjob_pool.spawn("RTSIM_SAVE", move || {
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let tmp_file_name = "state_tmp.ron";
|
let tmp_file_name = "state_tmp.dat";
|
||||||
if let Err(e) = file_path
|
if let Err(e) = file_path
|
||||||
.parent()
|
.parent()
|
||||||
.map(|dir| {
|
.map(|dir| {
|
||||||
@ -124,7 +125,7 @@ impl RtSim {
|
|||||||
.and_then(|tmp_file_path| {
|
.and_then(|tmp_file_path| {
|
||||||
Ok((File::create(&tmp_file_path)?, tmp_file_path))
|
Ok((File::create(&tmp_file_path)?, tmp_file_path))
|
||||||
})
|
})
|
||||||
.map_err(|e: io::Error| ron::Error::from(e))
|
.map_err(|e: io::Error| Box::new(e) as Box::<dyn Error>)
|
||||||
.and_then(|(mut file, tmp_file_path)| {
|
.and_then(|(mut file, tmp_file_path)| {
|
||||||
info!("Writing rtsim state to file...");
|
info!("Writing rtsim state to file...");
|
||||||
data.write_to(io::BufWriter::new(&mut file))?;
|
data.write_to(io::BufWriter::new(&mut file))?;
|
||||||
|
Loading…
Reference in New Issue
Block a user