Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements #1571 #1712

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/fj-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ libloading = "0.7.4"
notify = "5.1.0"
thiserror = "1.0.40"
tracing = "0.1.37"
winit = "0.28.3"
5 changes: 2 additions & 3 deletions crates/fj-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::thread::JoinHandle;

use crossbeam_channel::Sender;
use fj_operations::shape_processor::ShapeProcessor;
use winit::event_loop::EventLoopProxy;

use crate::{EventLoopClosed, HostThread, Model, ModelEvent};

Expand All @@ -18,10 +17,10 @@ impl Host {
/// loop.
pub fn new(
shape_processor: ShapeProcessor,
event_loop_proxy: EventLoopProxy<ModelEvent>,
model_event_tx: Sender<ModelEvent>,
) -> Self {
let (command_tx, host_thread) =
HostThread::spawn(shape_processor, event_loop_proxy);
HostThread::spawn(shape_processor, model_event_tx);

Self {
command_tx,
Expand Down
11 changes: 5 additions & 6 deletions crates/fj-host/src/host_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::thread::{self, JoinHandle};
use crossbeam_channel::{self, Receiver, Sender};
use fj_interop::processed_shape::ProcessedShape;
use fj_operations::shape_processor::ShapeProcessor;
use winit::event_loop::EventLoopProxy;

use crate::{Error, HostCommand, Model, Watcher};

Expand All @@ -14,7 +13,7 @@ pub(crate) struct EventLoopClosed;

pub(crate) struct HostThread {
shape_processor: ShapeProcessor,
event_loop_proxy: EventLoopProxy<ModelEvent>,
model_event_tx: Sender<ModelEvent>,
command_tx: Sender<HostCommand>,
command_rx: Receiver<HostCommand>,
}
Expand All @@ -23,14 +22,14 @@ impl HostThread {
// Spawn a background thread that will process models for an event loop.
pub(crate) fn spawn(
shape_processor: ShapeProcessor,
event_loop_proxy: EventLoopProxy<ModelEvent>,
event_loop_proxy: Sender<ModelEvent>,
) -> (Sender<HostCommand>, JoinHandle<Result<(), EventLoopClosed>>) {
let (command_tx, command_rx) = crossbeam_channel::unbounded();
let command_tx_2 = command_tx.clone();

let host_thread = Self {
shape_processor,
event_loop_proxy,
model_event_tx: event_loop_proxy,
command_tx,
command_rx,
};
Expand Down Expand Up @@ -117,8 +116,8 @@ impl HostThread {

// Send a message to the event loop.
fn send_event(&mut self, event: ModelEvent) -> Result<(), EventLoopClosed> {
self.event_loop_proxy
.send_event(event)
self.model_event_tx
.send(event)
.map_err(|_| EventLoopClosed)?;

Ok(())
Expand Down
17 changes: 16 additions & 1 deletion crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::{
error,
fmt::{self, Write},
thread,
};

use fj_host::{Host, Model, ModelEvent};
Expand All @@ -32,7 +33,21 @@ pub fn run(

let egui_winit_state = egui_winit::State::new(&event_loop);

let mut host = Host::new(shape_processor, event_loop.create_proxy());
let (model_event_tx, model_event_rx) = crossbeam_channel::unbounded();
let event_proxy = event_loop.create_proxy();

let _event_relay_join_handle = thread::Builder::new()
.name("event_relay".to_string())
.spawn(move || {
for event in model_event_rx {
if event_proxy.send_event(event).is_err() {
// Looks like the main window closed.
break;
}
}
});

let mut host = Host::new(shape_processor, model_event_tx);

if let Some(model) = model {
host.load_model(model);
Expand Down