Skip to content

Commit 5043799

Browse files
committed
Fix compile issues and code generation
1 parent 806f9df commit 5043799

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

node-graph/gcore/src/ops.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ where
332332
fn eval(&'i self, input: I) -> Self::Output {
333333
self.0.eval(input)
334334
}
335+
336+
fn reset(&self) {
337+
self.0.reset();
338+
}
339+
340+
fn serialize(&self) -> Option<std::sync::Arc<dyn core::any::Any>> {
341+
self.0.serialize()
342+
}
335343
}
336344
impl<'i, N: for<'a> Node<'a, I>, I: 'i> TypeNode<N, I, <N as Node<'i, I>>::Output> {
337345
pub fn new(node: N) -> Self {

node-graph/gcore/src/registry.rs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,17 @@ where
160160
N: Node<'i, T, Output: WasmNotSend> + WasmNotSend,
161161
{
162162
type Output = DynFuture<'i, N::Output>;
163+
#[inline(always)]
163164
fn eval(&'i self, input: T) -> Self::Output {
164165
let result = self.node.eval(input);
165166
Box::pin(async move { result })
166167
}
168+
#[inline(always)]
167169
fn reset(&self) {
168170
self.node.reset();
169171
}
170172

173+
#[inline(always)]
171174
fn serialize(&self) -> Option<std::sync::Arc<dyn core::any::Any>> {
172175
self.node.serialize()
173176
}
@@ -231,37 +234,38 @@ where
231234
}
232235
}
233236

237+
async fn construct_vector2<'n, IY: Into<f64> + Send + 'n, IC: Into<u64> + Send + 'n>(_: (), x: f64, y: IY, c: impl Node<'n, (), Output: core::future::Future<Output = IC>>) -> glam::DVec2 {
238+
glam::DVec2::new(x, y.into())
239+
}
234240
mod construct_vector2 {
235241
use super::*;
236-
use crate::registry::{DowncastBothNode, DynAnyNode, FieldMetadata, FutureWrapperNode, NodeMetadata, NODE_METADATA, NODE_REGISTRY};
237-
use crate::{concrete, fn_type, Node, NodeIOTypes, ProtoNodeIdentifier};
238-
use core::future::Future;
242+
use crate as gcore;
239243
use ctor::ctor;
244+
use gcore::ops::TypeNode;
245+
use gcore::registry::{DowncastBothNode, DynAnyNode, DynFuture, FieldMetadata, NodeMetadata, TypeErasedBox, NODE_METADATA, NODE_REGISTRY};
246+
use gcore::value::ClonedNode;
247+
use gcore::{concrete, fn_type, Node, NodeIOTypes, ProtoNodeIdentifier, WasmNotSync};
240248
pub struct ConstructVector2<Node0, Node1, Node2> {
241249
x: Node0,
242250
y: Node1,
243251
c: Node2,
244252
}
245-
#[allow(non_snake_case)]
246-
async fn construct_vector2<'n, IY: Into<f64>>(_: (), x: f64, y: IY, c: impl Node<'n, (), Output: Future<Output = u32>>) -> glam::DVec2 {
247-
glam::DVec2::new(x, y.into())
248-
}
249-
impl<'n, IY: Into<f64>, Node0, Node1, Node2> Node<'n, ()> for ConstructVector2<Node0, Node1, Node2>
253+
#[automatically_derived]
254+
impl<'n, IY: Into<f64> + Send + 'n, IC: Into<u64> + Send + 'n, Node0, Node1, Node2> Node<'n, ()> for ConstructVector2<Node0, Node1, Node2>
250255
where
251256
Node0: Node<'n, (), Output = f64>,
252257
Node1: Node<'n, (), Output = IY>,
253-
Node2: Node<'n, (), Output: Future<Output = u32>>,
258+
Node2: Node<'n, (), Output: core::future::Future<Output = IC>> + WasmNotSync + 'n,
254259
{
255-
type Output = Pin<Box<dyn Future<Output = glam::DVec2> + 'n>>;
260+
type Output = DynFuture<'n, glam::DVec2>;
256261
fn eval(&'n self, input: ()) -> Self::Output {
257-
Box::pin(async move {
258-
let x = self.x.eval(());
259-
let y = self.y.eval(());
260-
let c = &self.c;
261-
construct_vector2(input, x, y, c).await
262-
})
262+
let x = self.x.eval(());
263+
let y = self.y.eval(());
264+
let c = &self.c;
265+
Box::pin(construct_vector2(input, x, y, c))
263266
}
264267
}
268+
#[automatically_derived]
265269
impl<'n, Node0, Node1, Node2> ConstructVector2<Node0, Node1, Node2> {
266270
pub fn new(x: Node0, y: Node1, c: Node2) -> Self {
267271
Self { x, y, c }
@@ -277,28 +281,40 @@ mod construct_vector2 {
277281
|args| {
278282
Box::pin(async move {
279283
let x: DowncastBothNode<(), f64> = DowncastBothNode::new(args[0usize].clone());
284+
let value = x.eval(()).await;
285+
let x = ClonedNode::new(value);
286+
let x: TypeNode<_, (), f64> = TypeNode::new(x);
280287
let y: DowncastBothNode<(), f32> = DowncastBothNode::new(args[1usize].clone());
288+
let value = y.eval(()).await;
289+
let y = ClonedNode::new(value);
290+
let y: TypeNode<_, (), f32> = TypeNode::new(y);
281291
let c: DowncastBothNode<(), u32> = DowncastBothNode::new(args[2usize].clone());
282292
let node = ConstructVector2::new(x, y, c);
283293
let any: DynAnyNode<(), _, _> = DynAnyNode::new(node);
284-
any.into_type_erased()
294+
Box::new(any) as TypeErasedBox<'_>
285295
})
286296
},
287-
NodeIOTypes::new(concrete!(()), concrete!(glam::DVec2), vec![fn_type!((), f64), fn_type!((), f32), fn_type!((), u32),],)
288-
);
297+
NodeIOTypes::new(concrete!(()), concrete!(glam::DVec2), vec![fn_type!((), f64), fn_type!((), f32), fn_type!((), u32)]),
298+
),
289299
(
290300
|args| {
291301
Box::pin(async move {
292302
let x: DowncastBothNode<(), f64> = DowncastBothNode::new(args[0usize].clone());
303+
let value = x.eval(()).await;
304+
let x = ClonedNode::new(value);
305+
let x: TypeNode<_, (), f64> = TypeNode::new(x);
293306
let y: DowncastBothNode<(), f64> = DowncastBothNode::new(args[1usize].clone());
307+
let value = y.eval(()).await;
308+
let y = ClonedNode::new(value);
309+
let y: TypeNode<_, (), f64> = TypeNode::new(y);
294310
let c: DowncastBothNode<(), u64> = DowncastBothNode::new(args[2usize].clone());
295311
let node = ConstructVector2::new(x, y, c);
296312
let any: DynAnyNode<(), _, _> = DynAnyNode::new(node);
297-
any.into_type_erased()
313+
Box::new(any) as TypeErasedBox<'_>
298314
})
299315
},
300-
NodeIOTypes::new(concrete!(()), concrete!(glam::DVec2), vec![fn_type!((), f64), fn_type!((), f64), fn_type!((), u64),],)
301-
)
316+
NodeIOTypes::new(concrete!(()), concrete!(glam::DVec2), vec![fn_type!((), f64), fn_type!((), f64), fn_type!((), u64)]),
317+
),
302318
],
303319
);
304320
}

0 commit comments

Comments
 (0)