|
|
|
@ -1,12 +1,12 @@
|
|
|
|
|
use std::sync::mpsc;
|
|
|
|
|
use crate::error::Error;
|
|
|
|
|
use crate::layouts::Entry;
|
|
|
|
|
use crate::CompiledShaders;
|
|
|
|
|
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
|
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
use std::sync::mpsc;
|
|
|
|
|
use std::sync::mpsc::{Receiver, Sender};
|
|
|
|
|
use std::thread;
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
use crate::layouts::Entry;
|
|
|
|
|
use crate::CompiledShaders;
|
|
|
|
|
use std::sync::mpsc::{Sender, Receiver};
|
|
|
|
|
use crate::error::Error;
|
|
|
|
|
|
|
|
|
|
pub struct Watch {
|
|
|
|
|
_handler: Handler,
|
|
|
|
@ -29,8 +29,14 @@ impl Watch {
|
|
|
|
|
where
|
|
|
|
|
T: AsRef<Path>,
|
|
|
|
|
{
|
|
|
|
|
let (handler, rx) = create_watch(vertex.as_ref().to_path_buf(), fragment.as_ref().to_path_buf());
|
|
|
|
|
Watch{_handler: handler, rx}
|
|
|
|
|
let (handler, rx) = create_watch(
|
|
|
|
|
vertex.as_ref().to_path_buf(),
|
|
|
|
|
fragment.as_ref().to_path_buf(),
|
|
|
|
|
);
|
|
|
|
|
Watch {
|
|
|
|
|
_handler: handler,
|
|
|
|
|
rx,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -51,7 +57,7 @@ impl Loader {
|
|
|
|
|
Ok(shaders) => {
|
|
|
|
|
let entry = crate::parse(&shaders);
|
|
|
|
|
self.tx.send(Ok(Message { shaders, entry })).ok()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
Err(e) => self.tx.send(Err(e)).ok(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
@ -72,8 +78,10 @@ impl Drop for Handler {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn create_watch(vert_path: PathBuf, frag_path: PathBuf) -> (Handler, mpsc::Receiver<Result<Message, Error>>) {
|
|
|
|
|
fn create_watch(
|
|
|
|
|
vert_path: PathBuf,
|
|
|
|
|
frag_path: PathBuf,
|
|
|
|
|
) -> (Handler, mpsc::Receiver<Result<Message, Error>>) {
|
|
|
|
|
let (notify_tx, notify_rx) = mpsc::channel();
|
|
|
|
|
let (thread_tx, thread_rx) = mpsc::channel();
|
|
|
|
|
let mut watcher: RecommendedWatcher =
|
|
|
|
@ -86,14 +94,15 @@ fn create_watch(vert_path: PathBuf, frag_path: PathBuf) -> (Handler, mpsc::Recei
|
|
|
|
|
.watch(&frag_path, RecursiveMode::NonRecursive)
|
|
|
|
|
.expect("failed to add fragment shader to notify");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let (loader, rx) = Loader::create(vert_path, frag_path);
|
|
|
|
|
|
|
|
|
|
let handle = thread::spawn(move || 'watch_loop: loop {
|
|
|
|
|
if let Ok(_) = thread_rx.try_recv() {
|
|
|
|
|
break 'watch_loop;
|
|
|
|
|
}
|
|
|
|
|
if let Ok(notify::DebouncedEvent::Create(_)) = notify_rx.recv_timeout(Duration::from_secs(1)) {
|
|
|
|
|
if let Ok(notify::DebouncedEvent::Create(_)) =
|
|
|
|
|
notify_rx.recv_timeout(Duration::from_secs(1))
|
|
|
|
|
{
|
|
|
|
|
loader.reload();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|