diff --git a/fj-app/src/main.rs b/fj-app/src/main.rs index 6589f1553..39c79a531 100644 --- a/fj-app/src/main.rs +++ b/fj-app/src/main.rs @@ -8,7 +8,7 @@ mod window; use std::path::PathBuf; use std::{collections::HashMap, time::Instant}; -use fj_host::Model; +use fj_host::{Model, Parameters}; use fj_interop::{debug::DebugInfo, mesh::Mesh}; use fj_kernel::algorithms::{triangulate, Tolerance}; use fj_math::{Aabb, Point, Scalar}; @@ -83,7 +83,7 @@ fn main() -> anyhow::Result<()> { }; if let Some(path) = args.export { - let shape = model.load_once(¶meters)?; + let shape = model.load_once(&Parameters(parameters))?; let shape = shape_processor.process(&shape); let vertices = @@ -111,7 +111,7 @@ fn main() -> anyhow::Result<()> { return Ok(()); } - let watcher = model.load_and_watch(parameters)?; + let watcher = model.load_and_watch(Parameters(parameters))?; let event_loop = EventLoop::new(); let window = Window::new(&event_loop); diff --git a/fj-host/src/lib.rs b/fj-host/src/lib.rs index 9689a68cb..64ba006e7 100644 --- a/fj-host/src/lib.rs +++ b/fj-host/src/lib.rs @@ -74,7 +74,7 @@ impl Model { /// model for changes, reloading it continually. pub fn load_once( &self, - arguments: &HashMap, + arguments: &Parameters, ) -> Result { let manifest_path = self.manifest_path.display().to_string(); @@ -120,7 +120,7 @@ impl Model { /// be queried for changes to the model. pub fn load_and_watch( self, - parameters: HashMap, + parameters: Parameters, ) -> Result { let (tx, rx) = mpsc::sync_channel(0); let tx2 = tx.clone(); @@ -202,7 +202,7 @@ pub struct Watcher { _watcher: Box, channel: mpsc::Receiver<()>, model: Model, - parameters: HashMap, + parameters: Parameters, } impl Watcher { @@ -243,6 +243,16 @@ impl Watcher { } } +/// Parameters that are passed to a model +pub struct Parameters(pub HashMap); + +impl Parameters { + /// Construct an empty instance of `Parameters` + pub fn empty() -> Self { + Self(HashMap::new()) + } +} + /// An error that can occur when loading or reloading a model #[derive(Debug, Error)] pub enum Error { @@ -263,5 +273,4 @@ pub enum Error { Notify(#[from] notify::Error), } -type ModelFn = - unsafe extern "C" fn(args: &HashMap) -> fj::Shape; +type ModelFn = unsafe extern "C" fn(args: &Parameters) -> fj::Shape;