-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathmain.rs
More file actions
82 lines (65 loc) · 2.28 KB
/
main.rs
File metadata and controls
82 lines (65 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use std::process::exit;
use std::time::Instant;
use std::{fmt::Debug, time::Duration};
use graphite_editor::messages::prelude::Message;
use tracing_subscriber::EnvFilter;
use winit::event_loop::EventLoop;
pub(crate) mod consts;
mod cef;
use cef::{Setup, WindowSize};
mod render;
use render::WgpuContext;
mod app;
use app::WinitApp;
mod dirs;
mod dialogs;
#[derive(Debug)]
pub(crate) enum CustomEvent {
UiUpdate(wgpu::Texture),
ScheduleBrowserWork(Instant),
DispatchMessage(Message),
MessageReceived(Message),
NodeGraphRan(Option<wgpu::Texture>),
}
fn main() {
tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init();
let cef_context = match cef::Context::<Setup>::new() {
Ok(c) => c,
Err(cef::SetupError::Subprocess) => exit(0),
Err(cef::SetupError::SubprocessFailed(t)) => {
tracing::error!("Subprocess of type {t} failed");
exit(1);
}
};
let event_loop = EventLoop::<CustomEvent>::with_user_event().build().unwrap();
let (window_size_sender, window_size_receiver) = std::sync::mpsc::channel();
let wgpu_context = futures::executor::block_on(WgpuContext::new()).unwrap();
let cef_context = match cef_context.init(cef::CefHandler::new(window_size_receiver, event_loop.create_proxy(), wgpu_context.clone())) {
Ok(c) => c,
Err(cef::InitError::AlreadyRunning) => {
tracing::error!("Another instance is already running, Exiting.");
exit(0);
}
Err(cef::InitError::InitializationFailed(code)) => {
tracing::error!("Cef initialization failed with code: {code}");
exit(1);
}
};
tracing::info!("Cef initialized successfully");
let rendering_loop_proxy = event_loop.create_proxy();
let target_fps = 60;
std::thread::spawn(move || {
loop {
let last_render = Instant::now();
let (has_run, texture) = futures::executor::block_on(graphite_editor::node_graph_executor::run_node_graph());
if has_run {
let _ = rendering_loop_proxy.send_event(CustomEvent::NodeGraphRan(texture.map(|t| (*t.texture).clone())));
}
let frame_time = Duration::from_secs_f32((target_fps as f32).recip());
let sleep = last_render + frame_time - Instant::now();
std::thread::sleep(sleep);
}
});
let mut winit_app = WinitApp::new(cef_context, window_size_sender, wgpu_context, event_loop.create_proxy());
event_loop.run_app(&mut winit_app).unwrap();
}