From 94c050b4448e7add7cdf33bb7a46c13a08f930b6 Mon Sep 17 00:00:00 2001 From: Sofia Date: Wed, 29 Jul 2026 22:52:20 +0300 Subject: [PATCH] Move saving replay file to separate thread --- rust/src/replay.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rust/src/replay.rs b/rust/src/replay.rs index 2878eac..06b3676 100644 --- a/rust/src/replay.rs +++ b/rust/src/replay.rs @@ -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) {