5
5
// on the dispatcher messaging system and more complex Rust data types.
6
6
//
7
7
use crate :: helpers:: translate_key;
8
- use crate :: { EDITOR_HANDLE , EDITOR_HAS_CRASHED , Error , MESSAGE_BUFFER } ;
8
+ #[ cfg( not( feature = "native" ) ) ]
9
+ use crate :: wasm_node_graph_ui_executor:: WasmNodeGraphUIExecutor ;
10
+ use crate :: { EDITOR_HANDLE , EDITOR_HAS_CRASHED , Error , MESSAGE_BUFFER , WASM_NODE_GRAPH_EXECUTOR } ;
9
11
use editor:: consts:: FILE_EXTENSION ;
10
12
use editor:: messages:: input_mapper:: utility_types:: input_keyboard:: ModifierKeys ;
11
13
use editor:: messages:: input_mapper:: utility_types:: input_mouse:: { EditorMouseState , ScrollDelta , ViewportBounds } ;
@@ -17,6 +19,7 @@ use editor::messages::tool::tool_messages::tool_prelude::WidgetId;
17
19
use graph_craft:: document:: NodeId ;
18
20
use graphene_std:: raster:: Image ;
19
21
use graphene_std:: raster:: color:: Color ;
22
+ use interpreted_executor:: ui_runtime:: CompilationRequest ;
20
23
use js_sys:: { Object , Reflect } ;
21
24
use serde:: Serialize ;
22
25
use serde_wasm_bindgen:: { self , from_value} ;
@@ -149,9 +152,13 @@ impl EditorHandle {
149
152
pub fn new ( frontend_message_handler_callback : js_sys:: Function ) -> Self {
150
153
let editor = Editor :: new ( ) ;
151
154
let editor_handle = EditorHandle { frontend_message_handler_callback } ;
155
+ let node_graph_executor = WasmNodeGraphUIExecutor :: new ( ) ;
152
156
if EDITOR . with ( |handle| handle. lock ( ) . ok ( ) . map ( |mut guard| * guard = Some ( editor) ) ) . is_none ( ) {
153
157
log:: error!( "Attempted to initialize the editor more than once" ) ;
154
158
}
159
+ if WASM_NODE_GRAPH_EXECUTOR . with ( |handle| handle. lock ( ) . ok ( ) . map ( |mut guard| * guard = Some ( node_graph_executor) ) ) . is_none ( ) {
160
+ log:: error!( "Attempted to initialize the editor more than once" ) ;
161
+ }
155
162
if EDITOR_HANDLE . with ( |handle| handle. lock ( ) . ok ( ) . map ( |mut guard| * guard = Some ( editor_handle. clone ( ) ) ) ) . is_none ( ) {
156
163
log:: error!( "Attempted to initialize the editor handle more than once" ) ;
157
164
}
@@ -208,6 +215,17 @@ impl EditorHandle {
208
215
209
216
// Sends a FrontendMessage to JavaScript
210
217
fn send_frontend_message_to_js ( & self , mut message : FrontendMessage ) {
218
+ // Intercept any requests to render the node graph overlay
219
+ if message == FrontendMessage :: RequestNativeNodeGraphRender {
220
+ executor_editor_and_handle ( |executor, editor, _handle| {
221
+ if let Some ( node_graph_overlay_network) = editor. generate_node_graph_overlay_network ( ) {
222
+ let compilation_request = CompilationRequest { network : node_graph_overlay_network } ;
223
+ executor. compilation_request ( compilation_request) ;
224
+ }
225
+ } ) ;
226
+ return ;
227
+ }
228
+
211
229
if let FrontendMessage :: UpdateImageData { ref image_data } = message {
212
230
let new_hash = calculate_hash ( image_data) ;
213
231
let prev_hash = IMAGE_DATA_HASH . load ( Ordering :: Relaxed ) ;
@@ -264,6 +282,18 @@ impl EditorHandle {
264
282
#[ cfg( not( feature = "native" ) ) ]
265
283
wasm_bindgen_futures:: spawn_local ( poll_node_graph_evaluation ( ) ) ;
266
284
285
+ // Poll the UI node graph
286
+ #[ cfg( not( feature = "native" ) ) ]
287
+ executor_editor_and_handle ( |executor, editor, handle| {
288
+ for frontend_message in executor
289
+ . poll_node_graph_ui_evaluation ( editor)
290
+ . into_iter ( )
291
+ . flat_map ( |runtime_response| editor. handle_message ( runtime_response) )
292
+ {
293
+ handle. send_frontend_message_to_js ( frontend_message) ;
294
+ }
295
+ } ) ;
296
+
267
297
if !EDITOR_HAS_CRASHED . load ( Ordering :: SeqCst ) {
268
298
handle ( |handle| {
269
299
// Process all messages that have been queued up
@@ -989,6 +1019,31 @@ fn editor<T: Default>(callback: impl FnOnce(&mut editor::application::Editor) ->
989
1019
} )
990
1020
}
991
1021
1022
+ #[ cfg( not( feature = "native" ) ) ]
1023
+ fn executor < T : Default > ( callback : impl FnOnce ( & mut WasmNodeGraphUIExecutor ) -> T ) -> T {
1024
+ WASM_NODE_GRAPH_EXECUTOR . with ( |executor| {
1025
+ let mut guard = executor. try_lock ( ) ;
1026
+ let Ok ( Some ( executor) ) = guard. as_deref_mut ( ) else {
1027
+ log:: error!( "Failed to borrow editor" ) ;
1028
+ return T :: default ( ) ;
1029
+ } ;
1030
+
1031
+ callback ( executor)
1032
+ } )
1033
+ }
1034
+
1035
+ #[ cfg( not( feature = "native" ) ) ]
1036
+ pub ( crate ) fn executor_editor_and_handle ( callback : impl FnOnce ( & mut WasmNodeGraphUIExecutor , & mut Editor , & mut EditorHandle ) ) {
1037
+ executor ( |executor| {
1038
+ handle ( |editor_handle| {
1039
+ editor ( |editor| {
1040
+ // Call the closure with the editor and its handle
1041
+ callback ( executor, editor, editor_handle) ;
1042
+ } )
1043
+ } ) ;
1044
+ } )
1045
+ }
1046
+
992
1047
/// Provides access to the `Editor` and its `EditorHandle` by calling the given closure with them as arguments.
993
1048
#[ cfg( not( feature = "native" ) ) ]
994
1049
pub ( crate ) fn editor_and_handle ( callback : impl FnOnce ( & mut Editor , & mut EditorHandle ) ) {
@@ -1046,7 +1101,6 @@ async fn poll_node_graph_evaluation() {
1046
1101
// If the editor cannot be borrowed then it has encountered a panic - we should just ignore new dispatches
1047
1102
} ) ;
1048
1103
}
1049
-
1050
1104
fn auto_save_all_documents ( ) {
1051
1105
// Process no further messages after a crash to avoid spamming the console
1052
1106
if EDITOR_HAS_CRASHED . load ( Ordering :: SeqCst ) {
0 commit comments