From 3a23a9f218b9f9305feb9f5276e264260fa4951d Mon Sep 17 00:00:00 2001 From: me Date: Sun, 21 Dec 2025 15:00:13 +0200 Subject: [PATCH] faster hot reload --- src/main.rs | 11 ++++++++--- src/runtime/runtime.rs | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7585145..b089049 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,10 @@ use hotwatch::{ notify::event::{DataChange, ModifyKind}, }; use macroquad::prelude::*; -use std::sync::{Arc, RwLock}; +use std::{ + sync::{Arc, RwLock}, + time::Duration, +}; fn window_conf() -> Conf { Conf { @@ -30,7 +33,8 @@ async fn main() { let writer = Arc::new(RwLock::new(None)); let reader = writer.clone(); - let mut hotwatch = hotwatch::Hotwatch::new().expect("hotwatch failed to initialize!"); + let mut hotwatch = hotwatch::Hotwatch::new_with_custom_delay(Duration::from_millis(10)) + .expect("hotwatch failed to initialize!"); hotwatch .watch(file.clone(), move |event: hotwatch::Event| { if let hotwatch::EventKind::Modify(ModifyKind::Data(DataChange::Content)) = event.kind { @@ -69,8 +73,9 @@ async fn main() { } }; if let Some(new_program) = new_program { - state = migrate(state, new_program).await; + state = migrate(state, new_program); } + let events = fetch_events(&mut state); update(&mut state, events); draw(&mut state); diff --git a/src/runtime/runtime.rs b/src/runtime/runtime.rs index ec22aad..44c7be5 100644 --- a/src/runtime/runtime.rs +++ b/src/runtime/runtime.rs @@ -32,7 +32,7 @@ pub async fn setup(code: ast::Program) -> State { } } -pub async fn migrate(mut state: State, code: ast::Program) -> State { +pub fn migrate(mut state: State, code: ast::Program) -> State { println!("Migrating..."); match interpret::setup(code, primitive_funcs()) { Err(err) => { @@ -56,9 +56,9 @@ pub async fn migrate(mut state: State, code: ast::Program) -> State { state } Ok(result) => { - println!("Success!"); state.game_state = result; state.state = new_program_state; + println!("Success!"); state } }