Skip to main content

jellyflow_runtime/io/tuning/
runtime.rs

1use serde::{Deserialize, Serialize};
2
3use super::{NodeGraphPaintCachePruneTuning, NodeGraphSpatialIndexTuning};
4
5/// Persisted runtime-heavy tuning for the node graph editor.
6///
7/// Backend-specific payloads are configuration compatibility commitments; runtime reads still
8/// choose a supported implementation from the resolved interaction state.
9#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
10pub struct NodeGraphRuntimeTuning {
11    /// Optional cached spatial-query backend tuning. Disabled by default.
12    #[serde(default = "default_spatial_index_tuning")]
13    pub spatial_index: NodeGraphSpatialIndexTuning,
14    /// Cull renderer-facing visibility lists to the current viewport when possible.
15    #[serde(default = "default_only_render_visible_elements")]
16    pub only_render_visible_elements: bool,
17    /// Reserved paint-cache pruning tuning for adapters or future runtime-owned cache plumbing.
18    #[serde(default = "default_paint_cache_prune_tuning")]
19    pub paint_cache_prune: NodeGraphPaintCachePruneTuning,
20}
21
22impl NodeGraphRuntimeTuning {
23    pub fn is_default(this: &Self) -> bool {
24        this == &Self::default()
25    }
26
27    pub fn with_spatial_index_enabled(mut self, enabled: bool) -> Self {
28        self.spatial_index.enabled = enabled;
29        self
30    }
31
32    pub fn with_only_render_visible_elements(mut self, enabled: bool) -> Self {
33        self.only_render_visible_elements = enabled;
34        self
35    }
36}
37
38impl Default for NodeGraphRuntimeTuning {
39    fn default() -> Self {
40        Self {
41            spatial_index: default_spatial_index_tuning(),
42            only_render_visible_elements: default_only_render_visible_elements(),
43            paint_cache_prune: default_paint_cache_prune_tuning(),
44        }
45    }
46}
47
48fn default_spatial_index_tuning() -> NodeGraphSpatialIndexTuning {
49    NodeGraphSpatialIndexTuning::default()
50}
51
52fn default_paint_cache_prune_tuning() -> NodeGraphPaintCachePruneTuning {
53    NodeGraphPaintCachePruneTuning::default()
54}
55
56pub(crate) fn default_only_render_visible_elements() -> bool {
57    true
58}