Skip to content

Commit 667e15d

Browse files
committed
Context nullification, cached monitor nodes
1 parent 229607f commit 667e15d

File tree

83 files changed

+2226
-1684
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

+2226
-1684
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
@@ -43,7 +43,7 @@ impl MessageHandler<ExportDialogMessage, ExportDialogMessageData<'_>> for Export
4343
ExportDialogMessage::TransparentBackground(transparent_background) => self.transparent_background = transparent_background,
4444
ExportDialogMessage::ExportBounds(export_area) => self.bounds = export_area,
4545

46-
ExportDialogMessage::Submit => responses.add_front(PortfolioMessage::ActiveDocumentExport {
46+
ExportDialogMessage::Submit => responses.add_front(PortfolioMessage::ExportActiveDocument {
4747
file_name: portfolio.active_document().map(|document| document.name.clone()).unwrap_or_default(),
4848
file_type: self.file_type,
4949
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, ExtractField)]
@@ -24,17 +24,14 @@ impl MessageHandler<NewDocumentDialogMessage, ()> for NewDocumentDialogMessageHa
2424

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

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
#[derive(ExtractField)]
109
pub struct InputPreprocessorMessageData {

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,18 +35,16 @@ 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
#[derive(ExtractField)]
4441
pub struct DocumentMessageData<'a> {
45-
pub document_id: DocumentId,
4642
pub ipp: &'a InputPreprocessorMessageHandler,
4743
pub persistent_data: &'a PersistentData,
4844
pub current_tool: &'a ToolType,
4945
pub preferences: &'a PreferencesMessageHandler,
5046
pub device_pixel_ratio: f64,
51-
// pub introspected_inputs: &HashMap<CompiledProtonodeInput, Box<dyn std::any::Any + Send + Sync>>,
47+
// pub introspected_inputs: &HashMap<CompiledProtonodeInput, Arc<dyn std::any::Any + Send + Sync>>,
5248
// pub downcasted_inputs: &mut HashMap<CompiledProtonodeInput, TaggedValue>,
5349
}
5450

@@ -176,7 +172,6 @@ impl Default for DocumentMessageHandler {
176172
impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessageHandler {
177173
fn process_message(&mut self, message: DocumentMessage, responses: &mut VecDeque<Message>, data: DocumentMessageData) {
178174
let DocumentMessageData {
179-
document_id,
180175
ipp,
181176
persistent_data,
182177
current_tool,
@@ -222,11 +217,10 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
222217
);
223218
}
224219
DocumentMessage::PropertiesPanel(message) => {
225-
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {
220+
let properties_panel_message_handler_data = super::properties_panel::PropertiesPanelMessageHandlerData {
226221
network_interface: &mut self.network_interface,
227222
selection_network_path: &self.selection_network_path,
228223
document_name: self.name.as_str(),
229-
executor,
230224
};
231225
self.properties_panel_message_handler
232226
.process_message(message, responses, (persistent_data, properties_panel_message_handler_data));
@@ -239,7 +233,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
239233
network_interface: &mut self.network_interface,
240234
selection_network_path: &self.selection_network_path,
241235
breadcrumb_network_path: &self.breadcrumb_network_path,
242-
document_id,
243236
collapsed: &mut self.collapsed,
244237
ipp,
245238
graph_view_overlay_open: self.graph_view_overlay_open,
@@ -1432,7 +1425,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
14321425
center: Key::Alt,
14331426
duplicate: Key::Alt,
14341427
}));
1435-
responses.add(PortfolioMessage::CompileActiveDocument);
1428+
responses.add(PortfolioMessage::EvaluateActiveDocument);
14361429
} else {
14371430
let Some(network_metadata) = self.network_interface.network_metadata(&self.breadcrumb_network_path) else {
14381431
return;
@@ -1492,7 +1485,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
14921485
// Connect the current output data to the artboard's input data, and the artboard's output to the document output
14931486
responses.add(NodeGraphMessage::InsertNodeBetween {
14941487
node_id,
1495-
input_connector: network_interface::InputConnector::Export(0),
1488+
input_connector: InputConnector::Export(0),
14961489
insert_node_input_index: 1,
14971490
});
14981491

@@ -1909,13 +1902,14 @@ impl DocumentMessageHandler {
19091902
let previous_network = std::mem::replace(&mut self.network_interface, network_interface);
19101903

19111904
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
1905+
responses.add(PortfolioMessage::CompileActiveDocument);
1906+
responses.add(Message::StartEvaluationQueue);
19121907
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
19131908
responses.add(NodeGraphMessage::SelectedNodesUpdated);
1914-
// TODO: Remove once the footprint is used to load the imports/export distances from the edge
1915-
responses.add(NodeGraphMessage::UnloadWires);
19161909
responses.add(NodeGraphMessage::SetGridAlignedEdges);
1917-
responses.add(PortfolioMessage::CompileActiveDocument);
1918-
responses.add(Message::StartQueue);
1910+
responses.add(NodeGraphMessage::UnloadWires);
1911+
responses.add(NodeGraphMessage::SendWires);
1912+
responses.add(Message::EndEvaluationQueue);
19191913
Some(previous_network)
19201914
}
19211915
pub fn redo_with_history(&mut self, ipp: &InputPreprocessorMessageHandler, responses: &mut VecDeque<Message>) {
@@ -1941,12 +1935,14 @@ impl DocumentMessageHandler {
19411935
network_interface.set_document_to_viewport_transform(transform);
19421936

19431937
let previous_network = std::mem::replace(&mut self.network_interface, network_interface);
1938+
responses.add(PortfolioMessage::CompileActiveDocument);
1939+
responses.add(Message::StartEvaluationQueue);
19441940
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
19451941
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
19461942
responses.add(NodeGraphMessage::SelectedNodesUpdated);
1947-
responses.add(PortfolioMessage::CompileActiveDocument);
19481943
responses.add(NodeGraphMessage::UnloadWires);
19491944
responses.add(NodeGraphMessage::SendWires);
1945+
responses.add(Message::EndEvaluationQueue);
19501946
Some(previous_network)
19511947
}
19521948

@@ -2103,7 +2099,7 @@ impl DocumentMessageHandler {
21032099
/// Loads all of the fonts in the document.
21042100
pub fn load_layer_resources(&self, responses: &mut VecDeque<Message>) {
21052101
let mut fonts = HashSet::new();
2106-
for (_node_id, node, _) in self.document_network().recursive_nodes() {
2102+
for (_node_path, node) in self.document_network().recursive_nodes() {
21072103
for input in &node.inputs {
21082104
if let Some(TaggedValue::Font(font)) = input.as_value() {
21092105
fonts.insert(font.clone());
@@ -2576,7 +2572,7 @@ impl DocumentMessageHandler {
25762572
layout: Layout::WidgetLayout(document_bar_layout),
25772573
layout_target: LayoutTarget::DocumentBar,
25782574
});
2579-
responses.add(NodeGraphMessage::ForceRunDocumentGraph);
2575+
responses.add(PortfolioMessage::EvaluateActiveDocument);
25802576
}
25812577

25822578
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,12 +4,12 @@ use crate::messages::portfolio::document::utility_types::network_interface::Node
44
use crate::messages::prelude::*;
55
use bezier_rs::Subpath;
66
use glam::{DAffine2, IVec2};
7-
use graph_craft::document::NodeId;
87
use graphene_std::Artboard;
98
use graphene_std::brush::brush_stroke::BrushStroke;
109
use graphene_std::raster::BlendMode;
1110
use graphene_std::raster_types::{CPU, RasterDataTable};
1211
use graphene_std::text::{Font, TypesettingConfig};
12+
use graphene_std::uuid::NodeId;
1313
use graphene_std::vector::PointId;
1414
use graphene_std::vector::VectorModificationType;
1515
use graphene_std::vector::style::{Fill, Stroke};

0 commit comments

Comments
 (0)