faster hot reload
This commit is contained in:
parent
c89b06fb31
commit
3a23a9f218
2 changed files with 10 additions and 5 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -4,7 +4,10 @@ use hotwatch::{
|
||||||
notify::event::{DataChange, ModifyKind},
|
notify::event::{DataChange, ModifyKind},
|
||||||
};
|
};
|
||||||
use macroquad::prelude::*;
|
use macroquad::prelude::*;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::{
|
||||||
|
sync::{Arc, RwLock},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
fn window_conf() -> Conf {
|
fn window_conf() -> Conf {
|
||||||
Conf {
|
Conf {
|
||||||
|
|
@ -30,7 +33,8 @@ async fn main() {
|
||||||
|
|
||||||
let writer = Arc::new(RwLock::new(None));
|
let writer = Arc::new(RwLock::new(None));
|
||||||
let reader = writer.clone();
|
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
|
hotwatch
|
||||||
.watch(file.clone(), move |event: hotwatch::Event| {
|
.watch(file.clone(), move |event: hotwatch::Event| {
|
||||||
if let hotwatch::EventKind::Modify(ModifyKind::Data(DataChange::Content)) = event.kind {
|
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 {
|
if let Some(new_program) = new_program {
|
||||||
state = migrate(state, new_program).await;
|
state = migrate(state, new_program);
|
||||||
}
|
}
|
||||||
|
|
||||||
let events = fetch_events(&mut state);
|
let events = fetch_events(&mut state);
|
||||||
update(&mut state, events);
|
update(&mut state, events);
|
||||||
draw(&mut state);
|
draw(&mut state);
|
||||||
|
|
|
||||||
|
|
@ -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...");
|
println!("Migrating...");
|
||||||
match interpret::setup(code, primitive_funcs()) {
|
match interpret::setup(code, primitive_funcs()) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -56,9 +56,9 @@ pub async fn migrate(mut state: State, code: ast::Program) -> State {
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
println!("Success!");
|
|
||||||
state.game_state = result;
|
state.game_state = result;
|
||||||
state.state = new_program_state;
|
state.state = new_program_state;
|
||||||
|
println!("Success!");
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue