mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-28 10:05:52 +00:00
Add model::Watcher
This commit is contained in:
parent
4e46824e77
commit
c2dbbf36c0
@ -8,7 +8,7 @@ mod model;
|
|||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{collections::HashMap, sync::mpsc, time::Instant};
|
use std::{collections::HashMap, time::Instant};
|
||||||
|
|
||||||
use fj_debug::DebugInfo;
|
use fj_debug::DebugInfo;
|
||||||
use fj_math::{Aabb, Scalar, Triangle};
|
use fj_math::{Aabb, Scalar, Triangle};
|
||||||
@ -130,8 +130,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let (watcher_tx, watcher_rx) = mpsc::sync_channel(0);
|
let watcher = model.watch(parameters)?;
|
||||||
let _watcher = model.watch(watcher_tx, parameters)?;
|
|
||||||
|
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let window = Window::new(&event_loop);
|
let window = Window::new(&event_loop);
|
||||||
@ -154,20 +153,9 @@ fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
|
||||||
match watcher_rx.try_recv() {
|
if let Some(shape) = watcher.receive() {
|
||||||
Ok(shape) => {
|
processed_shape = shape_processor.process(&shape);
|
||||||
processed_shape = shape_processor.process(&shape);
|
processed_shape.update_geometry(&mut renderer);
|
||||||
processed_shape.update_geometry(&mut renderer);
|
|
||||||
}
|
|
||||||
Err(mpsc::TryRecvError::Empty) => {
|
|
||||||
// Nothing to receive from the channel. We don't care.
|
|
||||||
}
|
|
||||||
Err(mpsc::TryRecvError::Disconnected) => {
|
|
||||||
// The other end has disconnected. This is probably the result
|
|
||||||
// of a panic on the other thread, or a program shutdown in
|
|
||||||
// progress. In any case, not much we can do here.
|
|
||||||
panic!();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
@ -97,9 +97,9 @@ impl Model {
|
|||||||
|
|
||||||
pub fn watch(
|
pub fn watch(
|
||||||
self,
|
self,
|
||||||
tx: mpsc::SyncSender<fj::Shape>,
|
|
||||||
parameters: HashMap<String, String>,
|
parameters: HashMap<String, String>,
|
||||||
) -> Result<impl notify::Watcher, Error> {
|
) -> Result<Watcher, Error> {
|
||||||
|
let (tx, rx) = mpsc::sync_channel(0);
|
||||||
let watch_path = self.src_path.clone();
|
let watch_path = self.src_path.clone();
|
||||||
|
|
||||||
let mut watcher = notify::recommended_watcher(
|
let mut watcher = notify::recommended_watcher(
|
||||||
@ -169,7 +169,33 @@ impl Model {
|
|||||||
|
|
||||||
watcher.watch(&watch_path, notify::RecursiveMode::Recursive)?;
|
watcher.watch(&watch_path, notify::RecursiveMode::Recursive)?;
|
||||||
|
|
||||||
Ok(watcher)
|
Ok(Watcher {
|
||||||
|
_watcher: Box::new(watcher),
|
||||||
|
channel: rx,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Watcher {
|
||||||
|
_watcher: Box<dyn notify::Watcher>,
|
||||||
|
channel: mpsc::Receiver<fj::Shape>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Watcher {
|
||||||
|
pub fn receive(&self) -> Option<fj::Shape> {
|
||||||
|
match self.channel.try_recv() {
|
||||||
|
Ok(shape) => Some(shape),
|
||||||
|
Err(mpsc::TryRecvError::Empty) => {
|
||||||
|
// Nothing to receive from the channel.
|
||||||
|
None
|
||||||
|
}
|
||||||
|
Err(mpsc::TryRecvError::Disconnected) => {
|
||||||
|
// The other end has disconnected. This is probably the result
|
||||||
|
// of a panic on the other thread, or a program shutdown in
|
||||||
|
// progress. In any case, not much we can do here.
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user