Move saving replay file to separate thread
This commit is contained in:
parent
a6c346ddb9
commit
94c050b444
@ -1,4 +1,4 @@
|
||||
use std::{collections::HashMap, io::Cursor};
|
||||
use std::{collections::HashMap, fs, io::Cursor, thread};
|
||||
|
||||
use flate2::{Compression, bufread::GzDecoder, write::GzEncoder};
|
||||
use godot::{
|
||||
@ -546,12 +546,14 @@ impl INode for ReplayRecorder {
|
||||
|
||||
impl ReplayRecorder {
|
||||
pub fn save_to(&self, path: &GString) {
|
||||
if let Some(mut file) = FileAccess::open(path, ModeFlags::WRITE) {
|
||||
let path = path.to_string();
|
||||
let replay = self.replay.clone();
|
||||
thread::spawn(move || {
|
||||
let mut bytes = Vec::new();
|
||||
let encoder = GzEncoder::new(&mut bytes, Compression::default());
|
||||
ciborium::into_writer(&self.replay, encoder).ok();
|
||||
file.store_buffer(&PackedArray::from_iter(bytes));
|
||||
}
|
||||
ciborium::into_writer(&replay, encoder).ok();
|
||||
fs::write(path, bytes).ok();
|
||||
});
|
||||
}
|
||||
|
||||
pub fn record_event(&mut self, event: ReplayEvent) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user