Skip to content

Commit 529022c

Browse files
Merge branch 'master' into qr-code-node
2 parents 499d087 + 910fb54 commit 529022c

File tree

5 files changed

+98
-4
lines changed

5 files changed

+98
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ web-sys = { version = "=0.3.77", features = [
179179
winit = { git = "https://github.com/rust-windowing/winit.git" }
180180
keyboard-types = "0.8"
181181
url = "2.5"
182-
tokio = { version = "1.29", features = ["fs", "macros", "io-std", "rt"] }
182+
tokio = { version = "1.29", features = ["fs", "macros", "io-std", "rt", "rt-multi-thread"] }
183183
# Linebender ecosystem (BEGIN)
184184
kurbo = { version = "0.12", features = ["serde"] }
185185
vello = { git = "https://github.com/linebender/vello" }

desktop/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ winit = { workspace = true, features = [
3131
] }
3232
thiserror = { workspace = true }
3333
futures = { workspace = true }
34+
tokio = { workspace = true }
3435
cef = { workspace = true }
3536
cef-dll-sys = { workspace = true }
3637
tracing-subscriber = { workspace = true }

desktop/src/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ impl App {
7070
let rendering_app_event_scheduler = app_event_scheduler.clone();
7171
let (start_render_sender, start_render_receiver) = std::sync::mpsc::sync_channel(1);
7272
std::thread::spawn(move || {
73+
let runtime = tokio::runtime::Runtime::new().unwrap();
7374
loop {
74-
let result = futures::executor::block_on(DesktopWrapper::execute_node_graph());
75+
let result = runtime.block_on(DesktopWrapper::execute_node_graph());
7576
rendering_app_event_scheduler.schedule(AppEvent::NodeGraphExecutionResult(result));
7677
let _ = start_render_receiver.recv();
7778
}

node-graph/nodes/gcore/src/animation.rs

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
use core_types::{Ctx, ExtractAnimationTime, ExtractPointerPosition, ExtractRealTime};
2-
use glam::DVec2;
1+
use core_types::table::Table;
2+
use core_types::transform::Footprint;
3+
use core_types::uuid::NodeId;
4+
use core_types::{CloneVarArgs, Color, Context, Ctx, ExtractAll, ExtractAnimationTime, ExtractPointerPosition, ExtractRealTime, OwnedContextImpl};
5+
use glam::{DAffine2, DVec2};
6+
use graphic_types::{Artboard, Graphic, Vector, vector_types::GradientStops};
7+
use raster_types::{CPU, GPU, Raster};
38

49
const DAY: f64 = 1000. * 3600. * 24.;
510

@@ -54,6 +59,92 @@ fn animation_time(
5459
ctx.try_animation_time().unwrap_or_default() * rate
5560
}
5661

62+
#[node_macro::node(category("Animation"))]
63+
async fn quantize_real_time<T>(
64+
ctx: impl Ctx + ExtractAll + CloneVarArgs,
65+
#[implementations(
66+
Context -> bool,
67+
Context -> u32,
68+
Context -> u64,
69+
Context -> f32,
70+
Context -> f64,
71+
Context -> String,
72+
Context -> DAffine2,
73+
Context -> Footprint,
74+
Context -> DVec2,
75+
Context -> Vec<DVec2>,
76+
Context -> Vec<NodeId>,
77+
Context -> Vec<f64>,
78+
Context -> Vec<f32>,
79+
Context -> Vec<String>,
80+
Context -> Table<Vector>,
81+
Context -> Table<Graphic>,
82+
Context -> Table<Raster<CPU>>,
83+
Context -> Table<Raster<GPU>>,
84+
Context -> Table<Color>,
85+
Context -> Table<Artboard>,
86+
Context -> Table<GradientStops>,
87+
Context -> GradientStops,
88+
Context -> (),
89+
)]
90+
value: impl Node<'n, Context<'static>, Output = T>,
91+
#[default(1)]
92+
#[unit("sec")]
93+
quantum: f64,
94+
) -> T {
95+
let time = ctx.try_real_time().unwrap_or_default();
96+
let time = time / 1000.;
97+
let mut quantized_time = (time * quantum.recip()).round() / quantum.recip();
98+
if !quantized_time.is_finite() {
99+
quantized_time = time;
100+
}
101+
let quantized_time = quantized_time * 1000.;
102+
let new_context = OwnedContextImpl::from(ctx).with_real_time(quantized_time);
103+
value.eval(Some(new_context.into())).await
104+
}
105+
106+
#[node_macro::node(category("Animation"))]
107+
async fn quantize_animation_time<T>(
108+
ctx: impl Ctx + ExtractAll + CloneVarArgs,
109+
#[implementations(
110+
Context -> bool,
111+
Context -> u32,
112+
Context -> u64,
113+
Context -> f32,
114+
Context -> f64,
115+
Context -> String,
116+
Context -> DAffine2,
117+
Context -> Footprint,
118+
Context -> DVec2,
119+
Context -> Vec<DVec2>,
120+
Context -> Vec<NodeId>,
121+
Context -> Vec<f64>,
122+
Context -> Vec<f32>,
123+
Context -> Vec<String>,
124+
Context -> Table<Vector>,
125+
Context -> Table<Graphic>,
126+
Context -> Table<Raster<CPU>>,
127+
Context -> Table<Raster<GPU>>,
128+
Context -> Table<Color>,
129+
Context -> Table<Artboard>,
130+
Context -> Table<GradientStops>,
131+
Context -> GradientStops,
132+
Context -> (),
133+
)]
134+
value: impl Node<'n, Context<'static>, Output = T>,
135+
#[default(1)]
136+
#[unit("sec")]
137+
quantum: f64,
138+
) -> T {
139+
let time = ctx.try_animation_time().unwrap_or_default();
140+
let mut quantized_time = (time * quantum.recip()).round() / quantum.recip();
141+
if !quantized_time.is_finite() {
142+
quantized_time = time;
143+
}
144+
let new_context = OwnedContextImpl::from(ctx).with_animation_time(quantized_time);
145+
value.eval(Some(new_context.into())).await
146+
}
147+
57148
/// Produces the current position of the user's pointer within the document canvas.
58149
#[node_macro::node(category("Animation"))]
59150
fn pointer_position(ctx: impl Ctx + ExtractPointerPosition) -> DVec2 {

0 commit comments

Comments
 (0)