faster hot reload

This commit is contained in:
me 2025-12-21 15:00:13 +02:00
parent c89b06fb31
commit 3a23a9f218
2 changed files with 10 additions and 5 deletions

View file

@ -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);

View file

@ -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
}
}