Skip to content

Commit

Permalink
Merge pull request #1244 from hannobraun/host
Browse files Browse the repository at this point in the history
Don't block window thread when compiling model
  • Loading branch information
hannobraun authored Oct 20, 2022
2 parents f57cd28 + 413524c commit a7fb5a4
Show file tree
Hide file tree
Showing 13 changed files with 594 additions and 544 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions crates/fj-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::path::PathBuf;

use anyhow::{anyhow, Context as _};
use fj_export::export;
use fj_host::{Model, Parameters};
use fj_host::{Model, Parameters, Watcher};
use fj_interop::status_report::StatusReport;
use fj_operations::shape_processor::ShapeProcessor;
use fj_window::run::run;
Expand All @@ -29,7 +29,7 @@ use tracing_subscriber::EnvFilter;
use crate::{args::Args, config::Config};

fn main() -> anyhow::Result<()> {
let mut status = StatusReport::new();
let status = StatusReport::new();
// Respect `RUST_LOG`. If that's not defined or erroneous, log warnings and
// above.
//
Expand Down Expand Up @@ -58,7 +58,7 @@ fn main() -> anyhow::Result<()> {
{
let mut model_path = path;
model_path.push(model);
Model::from_path(model_path.clone()).with_context(|| {
Model::new(model_path.clone(), parameters).with_context(|| {
if path_of_model.as_os_str().is_empty() {
format!(
"Model is not defined, can't find model defined inside the default-model also, add model like \n cargo run -- -m {}", model.display()
Expand All @@ -80,8 +80,8 @@ fn main() -> anyhow::Result<()> {
if let Some(export_path) = args.export {
// export only mode. just load model, process, export and exit

let shape = model.load_once(&parameters, &mut status)?;
let shape = shape_processor.process(&shape)?;
let shape = model.load()?;
let shape = shape_processor.process(&shape.shape)?;

export(&shape.mesh, &export_path)?;

Expand All @@ -90,7 +90,7 @@ fn main() -> anyhow::Result<()> {

let invert_zoom = config.invert_zoom.unwrap_or(false);

let watcher = model.load_and_watch(parameters)?;
let watcher = Watcher::watch_model(model)?;
run(watcher, shape_processor, status, invert_zoom)?;

Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/fj-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ categories.workspace = true

[dependencies]
cargo_metadata = "0.15.0"
crossbeam-channel = "0.5.6"
fj.workspace = true
fj-interop.workspace = true
libloading = "0.7.2"
Expand Down
31 changes: 31 additions & 0 deletions crates/fj-host/src/host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::Parameters;

pub struct Host<'a> {
args: &'a Parameters,
model: Option<Box<dyn fj::models::Model>>,
}

impl<'a> Host<'a> {
pub fn new(parameters: &'a Parameters) -> Self {
Self {
args: parameters,
model: None,
}
}

pub fn take_model(&mut self) -> Option<Box<dyn fj::models::Model>> {
self.model.take()
}
}

impl<'a> fj::models::Host for Host<'a> {
fn register_boxed_model(&mut self, model: Box<dyn fj::models::Model>) {
self.model = Some(model);
}
}

impl<'a> fj::models::Context for Host<'a> {
fn get_argument(&self, name: &str) -> Option<&str> {
self.args.get(name).map(|s| s.as_str())
}
}
Loading

0 comments on commit a7fb5a4

Please sign in to comment.