Skip to content

Commit 11b54ae

Browse files
committed
Build evaluation loop
1 parent fe65044 commit 11b54ae

2 files changed

Lines changed: 35 additions & 18 deletions

File tree

desktop/src/app.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,6 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
7373
self.cef_context.work();
7474

7575
let (_has_run, texture) = futures::executor::block_on(graphite_editor::node_graph_executor::run_node_graph());
76-
if _has_run {
77-
let mut responses = VecDeque::new();
78-
let err = self.editor.poll_node_graph_evaluation(&mut responses);
79-
if let Err(e) = err {
80-
tracing::error!("Error poling node graph: {}", e);
81-
}
82-
let frontend_messages = responses
83-
.into_iter()
84-
.flat_map(|response| if let Message::Frontend(frontend) = response { Some(frontend) } else { None })
85-
.collect();
86-
self.send_messages_to_editor(frontend_messages);
87-
}
88-
if let Some(texture) = texture
89-
&& let Some(graphics_state) = &mut self.graphics_state
90-
{
91-
graphics_state.bind_viewport_texture(texture.texture.as_ref());
92-
}
9376

9477
event_loop.set_control_flow(ControlFlow::WaitUntil(wait_until));
9578
}
@@ -225,6 +208,24 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
225208
}
226209
self.dispatch_message(message);
227210
}
211+
CustomEvent::NodeGraphRan { texture } => {
212+
if let Some(texture) = texture
213+
&& let Some(graphics_state) = &mut self.graphics_state
214+
{
215+
graphics_state.bind_viewport_texture(texture.texture.as_ref());
216+
}
217+
let mut responses = VecDeque::new();
218+
let err = self.editor.poll_node_graph_evaluation(&mut responses);
219+
if let Err(e) = err {
220+
if e != "No active document" {
221+
tracing::error!("Error poling node graph: {}", e);
222+
}
223+
}
224+
225+
for message in responses {
226+
self.dispatch_message(message);
227+
}
228+
}
228229
}
229230
}
230231

desktop/src/main.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::fmt::Debug;
21
use std::process::exit;
32
use std::time::Instant;
3+
use std::{fmt::Debug, time::Duration};
44

55
use graphite_editor::messages::prelude::Message;
66
use tracing_subscriber::EnvFilter;
@@ -22,6 +22,7 @@ pub(crate) enum CustomEvent {
2222
UiUpdate(wgpu::Texture),
2323
ScheduleBrowserWork(Instant),
2424
MessageReceived { message: Message },
25+
NodeGraphRan { texture: Option<graphene_application_io::ImageTexture> },
2526
}
2627

2728
fn main() {
@@ -55,6 +56,21 @@ fn main() {
5556

5657
tracing::info!("Cef initialized successfully");
5758

59+
let rendering_loop_proxy = event_loop.create_proxy();
60+
let target_fps = 60;
61+
std::thread::spawn(move || {
62+
loop {
63+
let last_render = Instant::now();
64+
let (has_run, texture) = futures::executor::block_on(graphite_editor::node_graph_executor::run_node_graph());
65+
if has_run {
66+
rendering_loop_proxy.send_event(CustomEvent::NodeGraphRan { texture });
67+
}
68+
let frame_time = Duration::from_secs_f32((target_fps as f32).recip());
69+
let sleep = last_render + frame_time - Instant::now();
70+
std::thread::sleep(sleep);
71+
}
72+
});
73+
5874
let mut winit_app = WinitApp::new(cef_context, window_size_sender, wgpu_context);
5975

6076
event_loop.run_app(&mut winit_app).unwrap();

0 commit comments

Comments
 (0)