diff --git a/crates/fj-host/src/evaluator.rs b/crates/fj-host/src/evaluator.rs deleted file mode 100644 index 4be4ff05a5..0000000000 --- a/crates/fj-host/src/evaluator.rs +++ /dev/null @@ -1,99 +0,0 @@ -//use std::thread; - -//use crossbeam_channel::{Receiver, SendError, Sender}; -use fj_interop::processed_shape::ProcessedShape; - -use crate::Error; // Model}; - -// ----------------- -// This file becomes unnecessary because all the processing happens directly -// in `host.rs`. -// ----------------- - -/* -/// Evaluates a model in a background thread -pub struct Evaluator { - trigger_tx: Sender, - event_rx: Receiver, -} - -impl Evaluator { - /// Create an `Evaluator` from a model - //pub fn new(event_tx: EventLoopProxy, model: Model) -> Self { - pub fn from_model(model: Model) -> Self { - let (event_tx, event_rx) = crossbeam_channel::bounded(0); - let (trigger_tx, trigger_rx) = crossbeam_channel::bounded(0); - - thread::spawn(move || { - while matches!(trigger_rx.recv(), Ok(TriggerEvaluation)) { - if let Err(SendError(_)) = - event_tx.send(ModelEvent::ChangeDetected) - { - break; - } - - let _evaluation = match model.evaluate() { - Ok(evaluation) => evaluation, - Err(err) => { - if let Err(SendError(_)) = - event_tx.send(ModelEvent::Error(err)) - { - break; - } - continue; - } - }; - - /* - if let Err(SendError(_)) = - event_tx.send(ModelEvent::Evaluation(evaluation)) - { - break; - }; - */ - } - - // The channel is disconnected, which means this instance of - // `Evaluator`, as well as all `Sender`s created from it, have been - // dropped. We're done. - }); - - Self { - trigger_tx, - event_rx, - } - } - - /// Access a channel for triggering evaluations - pub fn trigger(&self) -> Sender { - self.trigger_tx.clone() - } - - /// Access a channel for receiving status updates - pub fn events(&self) -> Receiver { - self.event_rx.clone() - } -} - -/// Command received by [`Evaluator`] through its channel -pub struct TriggerEvaluation; -*/ - -/// An event emitted by the host thread -#[derive(Debug)] -pub enum ModelEvent { - /// A new model is being watched - StartWatching, - - /// A change in the model has been detected - ChangeDetected, - - /// The model has been evaluated - Evaluated, - - /// The model has been processed - ProcessedShape(ProcessedShape), - - /// An error - Error(Error), -} diff --git a/crates/fj-host/src/host.rs b/crates/fj-host/src/host.rs index b0a14ad7a0..c8a7bc0387 100644 --- a/crates/fj-host/src/host.rs +++ b/crates/fj-host/src/host.rs @@ -1,10 +1,11 @@ use std::thread; use crossbeam_channel::{unbounded, Receiver, Sender}; +use fj_interop::processed_shape::ProcessedShape; use fj_operations::shape_processor::ShapeProcessor; use winit::event_loop::EventLoopProxy; -use crate::{HostCommand, HostHandle, Model, ModelEvent, Watcher}; +use crate::{Error, HostCommand, HostHandle, Model, Watcher}; // Use a zero-sized error type to silence `#[warn(clippy::result_large_err)]`. // The only error from `EventLoopProxy::send_event` is `EventLoopClosed`, @@ -117,3 +118,22 @@ impl Host { Ok(()) } } + +/// An event emitted by the host thread +#[derive(Debug)] +pub enum ModelEvent { + /// A new model is being watched + StartWatching, + + /// A change in the model has been detected + ChangeDetected, + + /// The model has been evaluated + Evaluated, + + /// The model has been processed + ProcessedShape(ProcessedShape), + + /// An error + Error(Error), +} diff --git a/crates/fj-host/src/lib.rs b/crates/fj-host/src/lib.rs index 0fb56e7acd..0420c25b5f 100644 --- a/crates/fj-host/src/lib.rs +++ b/crates/fj-host/src/lib.rs @@ -15,7 +15,6 @@ #![warn(missing_docs)] -mod evaluator; mod host; mod host_handle; mod model; @@ -24,8 +23,7 @@ mod platform; mod watcher; pub use self::{ - evaluator::ModelEvent, - host::{EventLoopClosed, Host}, + host::{EventLoopClosed, Host, ModelEvent}, host_handle::{HostCommand, HostHandle}, model::{Error, Evaluation, Model}, parameters::Parameters,