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 flate2::{Compression, bufread::GzDecoder, write::GzEncoder};
|
||||||
use godot::{
|
use godot::{
|
||||||
@ -546,12 +546,14 @@ impl INode for ReplayRecorder {
|
|||||||
|
|
||||||
impl ReplayRecorder {
|
impl ReplayRecorder {
|
||||||
pub fn save_to(&self, path: &GString) {
|
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 mut bytes = Vec::new();
|
||||||
let encoder = GzEncoder::new(&mut bytes, Compression::default());
|
let encoder = GzEncoder::new(&mut bytes, Compression::default());
|
||||||
ciborium::into_writer(&self.replay, encoder).ok();
|
ciborium::into_writer(&replay, encoder).ok();
|
||||||
file.store_buffer(&PackedArray::from_iter(bytes));
|
fs::write(path, bytes).ok();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn record_event(&mut self, event: ReplayEvent) {
|
pub fn record_event(&mut self, event: ReplayEvent) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user