Skip to content

Commit 01b4c1f

Browse files
committed
Include pointer position in cache key
1 parent f237657 commit 01b4c1f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

node-graph/nodes/gstd/src/render_cache.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use core_types::math::bbox::AxisAlignedBbox;
44
use core_types::transform::{Footprint, RenderQuality, Transform};
5-
use core_types::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractAnimationTime, ExtractRealTime, OwnedContextImpl};
5+
use core_types::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractAnimationTime, ExtractPointerPosition, ExtractRealTime, OwnedContextImpl};
66
use glam::{DVec2, IVec2, UVec2};
77
use graph_craft::document::value::RenderOutput;
88
use graph_craft::wasm_application_io::WasmEditorApi;
@@ -47,10 +47,11 @@ pub struct CacheKey {
4747
pub override_paint_order: bool,
4848
pub animation_time_ms: i64,
4949
pub real_time_ms: i64,
50+
pub pointer: [u8; 16],
5051
}
5152

5253
impl CacheKey {
53-
pub fn from_times(
54+
pub fn new(
5455
render_mode_hash: u64,
5556
hide_artboards: bool,
5657
for_export: bool,
@@ -60,7 +61,16 @@ impl CacheKey {
6061
override_paint_order: bool,
6162
animation_time: f64,
6263
real_time: f64,
64+
pointer: Option<DVec2>,
6365
) -> Self {
66+
let pointer_bytes = pointer
67+
.map(|p| {
68+
let mut bytes = [0u8; 16];
69+
bytes[..8].copy_from_slice(&p.x.to_le_bytes());
70+
bytes[8..].copy_from_slice(&p.y.to_le_bytes());
71+
bytes
72+
})
73+
.unwrap_or([0u8; 16]);
6474
Self {
6575
render_mode_hash,
6676
hide_artboards,
@@ -71,6 +81,7 @@ impl CacheKey {
7181
override_paint_order,
7282
animation_time_ms: (animation_time * 1000.0).round() as i64,
7383
real_time_ms: (real_time * 1000.0).round() as i64,
84+
pointer: pointer_bytes,
7485
}
7586
}
7687
}
@@ -87,6 +98,7 @@ impl Default for CacheKey {
8798
override_paint_order: false,
8899
animation_time_ms: 0,
89100
real_time_ms: 0,
101+
pointer: [0u8; 16],
90102
}
91103
}
92104
}
@@ -316,7 +328,7 @@ fn flood_fill(start: &TileCoord, tile_set: &HashSet<TileCoord>, visited: &mut Ha
316328

317329
#[node_macro::node(category(""))]
318330
pub async fn render_output_cache<'a: 'n>(
319-
ctx: impl Ctx + ExtractAll + CloneVarArgs + ExtractRealTime + ExtractAnimationTime + Sync,
331+
ctx: impl Ctx + ExtractAll + CloneVarArgs + ExtractRealTime + ExtractAnimationTime + ExtractPointerPosition + Sync,
320332
editor_api: &'a WasmEditorApi,
321333
data: impl Node<Context<'static>, Output = RenderOutput> + Send + Sync,
322334
#[data] tile_cache: TileCache,
@@ -339,7 +351,7 @@ pub async fn render_output_cache<'a: 'n>(
339351
let physical_scale = logical_scale * device_scale;
340352
let viewport_bounds = footprint.viewport_bounds_in_local_space();
341353

342-
let cache_key = CacheKey::from_times(
354+
let cache_key = CacheKey::new(
343355
render_params.render_mode as u64,
344356
render_params.hide_artboards,
345357
render_params.for_export,
@@ -349,6 +361,7 @@ pub async fn render_output_cache<'a: 'n>(
349361
render_params.override_paint_order,
350362
ctx.try_animation_time().unwrap_or(0.0),
351363
ctx.try_real_time().unwrap_or(0.0),
364+
ctx.try_pointer_position(),
352365
);
353366

354367
let cache_query = tile_cache.query(&viewport_bounds, logical_scale, &cache_key);

0 commit comments

Comments
 (0)