Skip to content

Commit 92f63c9

Browse files
committed
Context nullification, cached monitor nodes
1 parent d2edc38 commit 92f63c9

File tree

83 files changed

+2191
-1728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2191
-1728
lines changed

editor/src/dispatcher.rs

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use crate::messages::prelude::*;
55

66
#[derive(Debug, Default)]
77
pub struct Dispatcher {
8-
buffered_queue: Vec<Message>,
9-
queueing_messages: bool,
8+
evaluation_queue: Vec<Message>,
9+
introspection_queue: Vec<Message>,
10+
queueing_evaluation_messages: bool,
11+
queueing_introspection_messages: bool,
1012
message_queues: Vec<VecDeque<Message>>,
1113
pub responses: Vec<FrontendMessage>,
1214
pub message_handlers: DispatcherMessageHandlers,
@@ -41,6 +43,9 @@ impl DispatcherMessageHandlers {
4143
/// The last occurrence of the message in the message queue is sufficient to ensure correct behavior.
4244
/// In addition, these messages do not change any state in the backend (aside from caches).
4345
const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
46+
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::CompileActiveDocument),
47+
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::EvaluateActiveDocument),
48+
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::IntrospectActiveDocument),
4449
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::PropertiesPanel(
4550
PropertiesPanelMessageDiscriminant::Refresh,
4651
))),
@@ -91,13 +96,6 @@ impl Dispatcher {
9196

9297
pub fn handle_message<T: Into<Message>>(&mut self, message: T, process_after_all_current: bool) {
9398
let message = message.into();
94-
// Add all additional messages to the queue if it exists (except from the end queue message)
95-
if !matches!(message, Message::EndQueue) {
96-
if self.queueing_messages {
97-
self.buffered_queue.push(message);
98-
return;
99-
}
100-
}
10199

102100
// If we are not maintaining the buffer, simply add to the current queue
103101
Self::schedule_execution(&mut self.message_queues, process_after_all_current, [message]);
@@ -117,7 +115,21 @@ impl Dispatcher {
117115
continue;
118116
}
119117
}
118+
// Add all messages to the queue if queuing messages (except from the end queue message)
119+
if !matches!(message, Message::EndEvaluationQueue) {
120+
if self.queueing_evaluation_messages {
121+
self.evaluation_queue.push(message);
122+
return;
123+
}
124+
}
120125

126+
// Add all messages to the queue if queuing messages (except from the end queue message)
127+
if !matches!(message, Message::EndIntrospectionQueue) {
128+
if self.queueing_introspection_messages {
129+
self.introspection_queue.push(message);
130+
return;
131+
}
132+
}
121133
// Print the message at a verbosity level of `info`
122134
self.log_message(&message, &self.message_queues, self.message_handlers.debug_message_handler.message_logging_verbosity);
123135

@@ -126,22 +138,40 @@ impl Dispatcher {
126138

127139
// Process the action by forwarding it to the relevant message handler, or saving the FrontendMessage to be sent to the frontend
128140
match message {
129-
Message::StartQueue => {
130-
self.queueing_messages = true;
141+
Message::StartEvaluationQueue => {
142+
self.queueing_evaluation_messages = true;
131143
}
132-
Message::EndQueue => {
133-
self.queueing_messages = false;
144+
Message::EndEvaluationQueue => {
145+
self.queueing_evaluation_messages = false;
134146
}
135-
Message::ProcessQueue((render_output_metadata, introspected_inputs)) => {
136-
let message = PortfolioMessage::ProcessEvaluationResponse {
147+
Message::ProcessEvaluationQueue(render_output_metadata) => {
148+
let update_message = PortfolioMessage::ProcessEvaluationResponse {
137149
evaluation_metadata: render_output_metadata,
138-
introspected_inputs,
139-
};
140-
// Add the message to update the state with the render output
141-
Self::schedule_execution(&mut self.message_queues, true, [message]);
150+
}
151+
.into();
152+
// Update the state with the render output and introspected inputs
153+
Self::schedule_execution(&mut self.message_queues, true, [update_message]);
154+
155+
// Schedule all queued messages to be run, which use the introspected inputs (in the order they were added)
156+
Self::schedule_execution(&mut self.message_queues, true, std::mem::take(&mut self.evaluation_queue));
157+
}
158+
Message::StartIntrospectionQueue => {
159+
self.queueing_introspection_messages = true;
160+
}
161+
Message::EndIntrospectionQueue => {
162+
self.queueing_introspection_messages = false;
163+
}
164+
Message::ProcessIntrospectionQueue(introspected_inputs) => {
165+
let update_message = PortfolioMessage::ProcessIntrospectionResponse { introspected_inputs }.into();
166+
// Update the state with the render output and introspected inputs
167+
Self::schedule_execution(&mut self.message_queues, true, [update_message]);
168+
169+
// Schedule all queued messages to be run, which use the introspected inputs (in the order they were added)
170+
Self::schedule_execution(&mut self.message_queues, true, std::mem::take(&mut self.introspection_queue));
142171

143-
// Schedule all queued messages to be run (in the order they were added)
144-
Self::schedule_execution(&mut self.message_queues, true, std::mem::take(&mut self.buffered_queue));
172+
let clear_message = PortfolioMessage::ClearIntrospectedData.into();
173+
// Clear the introspected inputs since they are no longer required, and will cause a memory leak if not removed
174+
Self::schedule_execution(&mut self.message_queues, true, [clear_message]);
145175
}
146176
Message::NoOp => {}
147177
Message::Init => {

editor/src/messages/dialog/export_dialog/export_dialog_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl MessageHandler<ExportDialogMessage, ExportDialogMessageData<'_>> for Export
4141
ExportDialogMessage::TransparentBackground(transparent_background) => self.transparent_background = transparent_background,
4242
ExportDialogMessage::ExportBounds(export_area) => self.bounds = export_area,
4343

44-
ExportDialogMessage::Submit => responses.add_front(PortfolioMessage::ActiveDocumentExport {
44+
ExportDialogMessage::Submit => responses.add_front(PortfolioMessage::ExportActiveDocument {
4545
file_name: portfolio.active_document().map(|document| document.name.clone()).unwrap_or_default(),
4646
file_type: self.file_type,
4747
scale_factor: self.scale_factor,

editor/src/messages/dialog/new_document_dialog/new_document_dialog_message_handler.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::messages::layout::utility_types::widget_prelude::*;
22
use crate::messages::prelude::*;
33
use glam::{IVec2, UVec2};
4-
use graph_craft::document::NodeId;
4+
use graphene_std::uuid::NodeId;
55

66
/// A dialog to allow users to set some initial options about a new document.
77
#[derive(Debug, Clone, Default)]
@@ -23,17 +23,14 @@ impl MessageHandler<NewDocumentDialogMessage, ()> for NewDocumentDialogMessageHa
2323

2424
let create_artboard = !self.infinite && self.dimensions.x > 0 && self.dimensions.y > 0;
2525
if create_artboard {
26-
responses.add(Message::StartQueue);
2726
responses.add(GraphOperationMessage::NewArtboard {
2827
id: NodeId::new(),
2928
artboard: graphene_std::Artboard::new(IVec2::ZERO, self.dimensions.as_ivec2()),
3029
});
3130
}
32-
33-
// TODO: Figure out how to get StartBuffer to work here so we can delete this and use `DocumentMessage::ZoomCanvasToFitAll` instead
34-
// Currently, it is necessary to use `FrontendMessage::TriggerDelayedZoomCanvasToFitAll` rather than `DocumentMessage::ZoomCanvasToFitAll` because the size of the viewport is not yet populated
35-
responses.add(Message::StartQueue);
36-
responses.add(FrontendMessage::TriggerDelayedZoomCanvasToFitAll);
31+
responses.add(Message::StartEvaluationQueue);
32+
responses.add(DocumentMessage::ZoomCanvasToFitAll);
33+
responses.add(Message::EndEvaluationQueue);
3734
responses.add(DocumentMessage::DeselectAllLayers);
3835
}
3936
}

editor/src/messages/frontend/frontend_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::messages::portfolio::document::utility_types::nodes::{JsRawBuffer, La
77
use crate::messages::portfolio::document::utility_types::wires::{WirePath, WirePathUpdate};
88
use crate::messages::prelude::*;
99
use crate::messages::tool::utility_types::HintData;
10-
use graph_craft::document::NodeId;
10+
use graphene_std::uuid::NodeId;
1111
use graphene_std::raster::color::Color;
1212
use graphene_std::text::Font;
1313

editor/src/messages/input_preprocessor/input_preprocessor_message_handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use crate::messages::input_mapper::utility_types::input_mouse::{MouseButton, Mou
33
use crate::messages::input_mapper::utility_types::misc::FrameTimeInfo;
44
use crate::messages::portfolio::utility_types::KeyboardPlatformLayout;
55
use crate::messages::prelude::*;
6-
use glam::DVec2;
7-
use std::time::Duration;
6+
use glam::{DAffine2, DVec2};
87

98
pub struct InputPreprocessorMessageData {
109
pub keyboard_platform: KeyboardPlatformLayout,

editor/src/messages/message.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
use std::sync::Arc;
2-
3-
use crate::messages::prelude::*;
4-
use graphene_std::{IntrospectMode, uuid::CompiledProtonodeInput};
1+
use crate::{messages::prelude::*, node_graph_executor::IntrospectionResponse};
52
use graphite_proc_macros::*;
63

74
#[impl_message]
8-
#[derive(Clone, Debug, PartialEq)]
5+
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
96
pub enum Message {
107
NoOp,
118
Init,
129
Batched(Box<[Message]>),
1310
// Adds any subsequent messages to the queue
14-
StartQueue,
11+
StartEvaluationQueue,
1512
// Stop adding messages to the queue.
16-
EndQueue,
17-
// Processes all messages that are queued, which occurs on the evaluation response. This allows a message to be run with data from after the evaluation is complete
18-
ProcessQueue(
19-
(
20-
graphene_std::renderer::RenderMetadata,
21-
Vec<(CompiledProtonodeInput, IntrospectMode, Box<dyn std::any::Any + Send + Sync>)>,
22-
),
23-
),
24-
13+
EndEvaluationQueue,
14+
// Processes all messages that are queued to be run after evaluation, which occurs on the evaluation response. This allows a message to be run with data from after the evaluation is complete
15+
#[serde(skip)]
16+
ProcessEvaluationQueue(graphene_std::renderer::RenderMetadata),
17+
StartIntrospectionQueue,
18+
EndIntrospectionQueue,
19+
// Processes all messages that are queued to be run after introspection, which occurs on the evaluation response. This allows a message to be run with data from after the evaluation is complete
20+
#[serde(skip)]
21+
ProcessIntrospectionQueue(IntrospectionResponse),
2522
#[child]
2623
Animation(AnimationMessage),
2724
#[child]

editor/src/messages/portfolio/document/document_message.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate,
77
use crate::messages::portfolio::utility_types::PanelType;
88
use crate::messages::prelude::*;
99
use glam::DAffine2;
10-
use graphene_std::uuid::CompiledProtonodeInput;
10+
use graphene_std::vector::click_target::ClickTarget;
1111
use graphene_std::Color;
1212
use graphene_std::raster::BlendMode;
1313
use graphene_std::raster::Image;
14-
use graphene_std::renderer::ClickTarget;
1514
use graphene_std::transform::Footprint;
1615
use graphene_std::uuid::NodeId;
1716
use graphene_std::vector::style::ViewMode;

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::node_graph::utility_types::Transform;
33
use super::overlays::utility_types::Pivot;
44
use super::utility_types::error::EditorError;
55
use super::utility_types::misc::{GroupFolderType, SNAP_FUNCTIONS_FOR_BOUNDING_BOXES, SNAP_FUNCTIONS_FOR_PATHS, SnappingOptions, SnappingState};
6-
use super::utility_types::network_interface::{self, NodeNetworkInterface, TransactionStatus};
6+
use super::utility_types::network_interface::{NodeNetworkInterface, TransactionStatus};
77
use super::utility_types::nodes::{CollapsedLayers, SelectedNodes};
88
use crate::application::{GRAPHITE_GIT_COMMIT_HASH, generate_uuid};
99
use crate::consts::{ASYMPTOTIC_EFFECT, COLOR_OVERLAY_GRAY, DEFAULT_DOCUMENT_NAME, FILE_SAVE_SUFFIX, SCALE_EFFECT, SCROLLBAR_SPACING, VIEWPORT_ROTATE_SNAP_INTERVAL};
@@ -13,22 +13,20 @@ use crate::messages::portfolio::document::graph_operation::utility_types::Transf
1313
use crate::messages::portfolio::document::node_graph::NodeGraphHandlerData;
1414
use crate::messages::portfolio::document::overlays::grid_overlays::{grid_overlay, overlay_options};
1515
use crate::messages::portfolio::document::overlays::utility_types::{OverlaysType, OverlaysVisibilitySettings};
16-
use crate::messages::portfolio::document::properties_panel::utility_types::PropertiesPanelMessageHandlerData;
1716
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
1817
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis, PTZ};
19-
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, InputConnector, NodeTemplate};
18+
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, NodeTemplate};
2019
use crate::messages::portfolio::document::utility_types::nodes::RawBuffer;
2120
use crate::messages::portfolio::utility_types::PersistentData;
2221
use crate::messages::prelude::*;
2322
use crate::messages::tool::common_functionality::graph_modification_utils::{self, get_blend_mode, get_fill, get_opacity};
2423
use crate::messages::tool::tool_messages::select_tool::SelectToolPointerKeys;
2524
use crate::messages::tool::tool_messages::tool_prelude::Key;
2625
use crate::messages::tool::utility_types::ToolType;
27-
use crate::node_graph_executor::NodeGraphExecutor;
2826
use bezier_rs::Subpath;
2927
use glam::{DAffine2, DVec2, IVec2};
3028
use graph_craft::document::value::TaggedValue;
31-
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
29+
use graph_craft::document::{InputConnector, NodeInput, NodeNetwork, OldNodeNetwork};
3230
use graphene_std::math::quad::Quad;
3331
use graphene_std::path_bool::{boolean_intersect, path_bool_lib};
3432
use graphene_std::raster::BlendMode;
@@ -37,17 +35,15 @@ use graphene_std::uuid::NodeId;
3735
use graphene_std::vector::PointId;
3836
use graphene_std::vector::click_target::{ClickTarget, ClickTargetType};
3937
use graphene_std::vector::style::ViewMode;
40-
use std::sync::Arc;
4138
use std::time::Duration;
4239

4340
pub struct DocumentMessageData<'a> {
44-
pub document_id: DocumentId,
4541
pub ipp: &'a InputPreprocessorMessageHandler,
4642
pub persistent_data: &'a PersistentData,
4743
pub current_tool: &'a ToolType,
4844
pub preferences: &'a PreferencesMessageHandler,
4945
pub device_pixel_ratio: f64,
50-
// pub introspected_inputs: &HashMap<CompiledProtonodeInput, Box<dyn std::any::Any + Send + Sync>>,
46+
// pub introspected_inputs: &HashMap<CompiledProtonodeInput, Arc<dyn std::any::Any + Send + Sync>>,
5147
// pub downcasted_inputs: &mut HashMap<CompiledProtonodeInput, TaggedValue>,
5248
}
5349

@@ -174,7 +170,6 @@ impl Default for DocumentMessageHandler {
174170
impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessageHandler {
175171
fn process_message(&mut self, message: DocumentMessage, responses: &mut VecDeque<Message>, data: DocumentMessageData) {
176172
let DocumentMessageData {
177-
document_id,
178173
ipp,
179174
persistent_data,
180175
current_tool,
@@ -220,11 +215,10 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
220215
);
221216
}
222217
DocumentMessage::PropertiesPanel(message) => {
223-
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {
218+
let properties_panel_message_handler_data = super::properties_panel::PropertiesPanelMessageHandlerData {
224219
network_interface: &mut self.network_interface,
225220
selection_network_path: &self.selection_network_path,
226221
document_name: self.name.as_str(),
227-
executor,
228222
};
229223
self.properties_panel_message_handler
230224
.process_message(message, responses, (persistent_data, properties_panel_message_handler_data));
@@ -237,7 +231,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
237231
network_interface: &mut self.network_interface,
238232
selection_network_path: &self.selection_network_path,
239233
breadcrumb_network_path: &self.breadcrumb_network_path,
240-
document_id,
241234
collapsed: &mut self.collapsed,
242235
ipp,
243236
graph_view_overlay_open: self.graph_view_overlay_open,
@@ -1426,7 +1419,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
14261419
center: Key::Alt,
14271420
duplicate: Key::Alt,
14281421
}));
1429-
responses.add(PortfolioMessage::CompileActiveDocument);
1422+
responses.add(PortfolioMessage::EvaluateActiveDocument);
14301423
} else {
14311424
let Some(network_metadata) = self.network_interface.network_metadata(&self.breadcrumb_network_path) else {
14321425
return;
@@ -1486,7 +1479,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
14861479
// Connect the current output data to the artboard's input data, and the artboard's output to the document output
14871480
responses.add(NodeGraphMessage::InsertNodeBetween {
14881481
node_id,
1489-
input_connector: network_interface::InputConnector::Export(0),
1482+
input_connector: InputConnector::Export(0),
14901483
insert_node_input_index: 1,
14911484
});
14921485

@@ -1895,13 +1888,14 @@ impl DocumentMessageHandler {
18951888
let previous_network = std::mem::replace(&mut self.network_interface, network_interface);
18961889

18971890
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
1891+
responses.add(PortfolioMessage::CompileActiveDocument);
1892+
responses.add(Message::StartEvaluationQueue);
18981893
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
18991894
responses.add(NodeGraphMessage::SelectedNodesUpdated);
1900-
// TODO: Remove once the footprint is used to load the imports/export distances from the edge
1901-
responses.add(NodeGraphMessage::UnloadWires);
19021895
responses.add(NodeGraphMessage::SetGridAlignedEdges);
1903-
responses.add(PortfolioMessage::CompileActiveDocument);
1904-
responses.add(Message::StartQueue);
1896+
responses.add(NodeGraphMessage::UnloadWires);
1897+
responses.add(NodeGraphMessage::SendWires);
1898+
responses.add(Message::EndEvaluationQueue);
19051899
Some(previous_network)
19061900
}
19071901
pub fn redo_with_history(&mut self, ipp: &InputPreprocessorMessageHandler, responses: &mut VecDeque<Message>) {
@@ -1927,12 +1921,14 @@ impl DocumentMessageHandler {
19271921
network_interface.set_document_to_viewport_transform(transform);
19281922

19291923
let previous_network = std::mem::replace(&mut self.network_interface, network_interface);
1924+
responses.add(PortfolioMessage::CompileActiveDocument);
1925+
responses.add(Message::StartEvaluationQueue);
19301926
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
19311927
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
19321928
responses.add(NodeGraphMessage::SelectedNodesUpdated);
1933-
responses.add(PortfolioMessage::CompileActiveDocument);
19341929
responses.add(NodeGraphMessage::UnloadWires);
19351930
responses.add(NodeGraphMessage::SendWires);
1931+
responses.add(Message::EndEvaluationQueue);
19361932
Some(previous_network)
19371933
}
19381934

@@ -2089,7 +2085,7 @@ impl DocumentMessageHandler {
20892085
/// Loads all of the fonts in the document.
20902086
pub fn load_layer_resources(&self, responses: &mut VecDeque<Message>) {
20912087
let mut fonts = HashSet::new();
2092-
for (_node_id, node, _) in self.document_network().recursive_nodes() {
2088+
for (_node_path, node) in self.document_network().recursive_nodes() {
20932089
for input in &node.inputs {
20942090
if let Some(TaggedValue::Font(font)) = input.as_value() {
20952091
fonts.insert(font.clone());
@@ -2544,7 +2540,7 @@ impl DocumentMessageHandler {
25442540
layout: Layout::WidgetLayout(document_bar_layout),
25452541
layout_target: LayoutTarget::DocumentBar,
25462542
});
2547-
responses.add(NodeGraphMessage::ForceRunDocumentGraph);
2543+
responses.add(PortfolioMessage::EvaluateActiveDocument);
25482544
}
25492545

25502546
pub fn update_layers_panel_control_bar_widgets(&self, responses: &mut VecDeque<Message>) {

editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::messages::portfolio::document::utility_types::network_interface::Node
44
use crate::messages::prelude::*;
55
use bezier_rs::Subpath;
66
use glam::{DAffine2, DVec2, IVec2};
7-
use graph_craft::document::NodeId;
7+
use graphene_std::uuid::NodeId;
88
use graphene_std::Artboard;
99
use graphene_std::brush::brush_stroke::BrushStroke;
1010
use graphene_std::raster::BlendMode;

0 commit comments

Comments
 (0)