mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-10 00:08:03 +00:00
Restructure node graph proxy architecture
This commit is contained in:
parent
cb337fd338
commit
90e465b35c
11 changed files with 128 additions and 81 deletions
|
@ -1,56 +1,70 @@
|
|||
//#![feature(generic_associated_types)]
|
||||
use dyn_any::StaticType;
|
||||
use graphene_std::value::{AnyRefNode, ValueNode};
|
||||
use graphene_std::*;
|
||||
|
||||
/*fn mul(a: f32, b: f32) -> f32 {
|
||||
/*fn mul(#[dyn_any(default)] a: f32, b: f32) -> f32 {
|
||||
a * b
|
||||
}*/
|
||||
|
||||
mod mul {
|
||||
use graphene_std::{DynamicInput, Node};
|
||||
use std::any::Any;
|
||||
type F32Node<'n> = &'n (dyn Node<'n, (), Output = &'n (dyn Any + 'static)> + 'n);
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct MulNode<'n> {
|
||||
pub a: Option<F32Node<'n>>,
|
||||
pub b: Option<F32Node<'n>>,
|
||||
use dyn_any::{downcast_ref, DynAny, StaticType};
|
||||
use graphene_std::{DynAnyNode, DynNode, DynamicInput, Node};
|
||||
pub struct MulNodeInput<'n> {
|
||||
pub a: &'n f32,
|
||||
pub b: &'n f32,
|
||||
}
|
||||
impl<'n> Node<'n, ()> for MulNode<'n> {
|
||||
type Output = f32;
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct MulNodeAnyProxy<'n> {
|
||||
pub a: Option<DynAnyNode<'n>>,
|
||||
pub b: Option<DynAnyNode<'n>>,
|
||||
}
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct MulNodeTypedProxy<'n> {
|
||||
pub a: Option<DynNode<'n, &'n f32>>,
|
||||
pub b: Option<DynNode<'n, &'n f32>>,
|
||||
}
|
||||
impl<'n> Node<'n, ()> for MulNodeAnyProxy<'n> {
|
||||
type Output = MulNodeInput<'n>;
|
||||
fn eval(&'n self, _input: &'n ()) -> <Self as graphene_std::Node<'n, ()>>::Output {
|
||||
let a = self.a.unwrap().eval(&());
|
||||
let a: &f32 = self
|
||||
.a
|
||||
.map(|v| v.eval(&()).downcast_ref().unwrap())
|
||||
.unwrap_or(&2.);
|
||||
let b: &f32 = self
|
||||
.b
|
||||
.map(|v| v.eval(&()).downcast_ref().unwrap())
|
||||
.map(|v| downcast_ref(v.eval(&())).unwrap())
|
||||
.unwrap_or(&1.);
|
||||
a * b
|
||||
/*let b: &f32 = self
|
||||
.b
|
||||
.map(|v| v.eval(&()).downcast_ref::<&'n f32, &'n f32>().unwrap())
|
||||
.unwrap_or(&&2.);
|
||||
a * b*/
|
||||
MulNodeInput { a, b: a }
|
||||
}
|
||||
}
|
||||
macro_rules! new {
|
||||
impl<'n> Node<'n, ()> for MulNodeTypedProxy<'n> {
|
||||
type Output = MulNodeInput<'n>;
|
||||
fn eval(&'n self, _input: &'n ()) -> <Self as graphene_std::Node<'n, ()>>::Output {
|
||||
let a = self.a.unwrap().eval(&());
|
||||
let b = self.b.unwrap().eval(&());
|
||||
MulNodeInput { a, b }
|
||||
}
|
||||
}
|
||||
|
||||
/*macro_rules! new {
|
||||
() => {
|
||||
mul::MulNode { a: None, b: None }
|
||||
};
|
||||
}
|
||||
pub(crate) use new;
|
||||
}*/
|
||||
//pub(crate) use new;
|
||||
|
||||
impl<'i: 'f, 'f> DynamicInput<'f> for MulNode<'f> {
|
||||
fn set_kwarg_by_name(
|
||||
&mut self,
|
||||
name: &str,
|
||||
value: &'f dyn Node<'f, (), Output = &'f (dyn Any + 'static)>,
|
||||
) {
|
||||
impl<'n> DynamicInput<'n> for MulNodeAnyProxy<'n> {
|
||||
fn set_kwarg_by_name(&mut self, name: &str, value: DynAnyNode<'n>) {
|
||||
todo!()
|
||||
}
|
||||
fn set_arg_by_index(
|
||||
&mut self,
|
||||
index: usize,
|
||||
value: &'f dyn Node<'f, (), Output = &'f (dyn Any + 'static)>,
|
||||
) {
|
||||
fn set_arg_by_index(&mut self, index: usize, value: DynAnyNode<'n>) {
|
||||
match index {
|
||||
0 => self.a = Some(value),
|
||||
0 => {
|
||||
self.a = Some(value);
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
@ -59,20 +73,21 @@ mod mul {
|
|||
|
||||
fn main() {
|
||||
//let mut mul = mul::MulNode::new();
|
||||
let a = ValueNode::new(3.4f32);
|
||||
let f = (3.2f32, 3.1f32);
|
||||
let a = ValueNode::new(1.);
|
||||
let id = std::any::TypeId::of::<&f32>();
|
||||
let any_a = AnyRefNode::new(&a);
|
||||
let _mul2 = mul::MulNode {
|
||||
/*let _mul2 = mul::MulNodeInput {
|
||||
a: None,
|
||||
b: Some(&any_a),
|
||||
};
|
||||
let mut mul2 = mul::new!();
|
||||
//let cached = memo::CacheNode::new(&mul1);
|
||||
//let foo = value::AnyRefNode::new(&cached);
|
||||
mul2.set_arg_by_index(0, &any_a);
|
||||
|
||||
mul2.set_arg_by_index(0, &any_a);*/
|
||||
let int = value::IntNode::<32>;
|
||||
int.eval(&());
|
||||
println!("{}", mul2.eval(&()));
|
||||
int.exec();
|
||||
println!("{}", int.exec());
|
||||
//let _add: u32 = ops::AddNode::<u32>::default().eval((int.exec(), int.exec()));
|
||||
//let fnode = generic::FnNode::new(|(a, b): &(i32, i32)| a - b);
|
||||
//let sub = fnode.any(&("a", 2));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use graphene_core::Node;
|
||||
use graphene_core::{Cache, Node};
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
/// Caches the output of a given Node and acts as a proxy
|
||||
|
@ -24,3 +24,12 @@ impl<'n, CachedNode: Node<'n, Input>, Input> CacheNode<'n, CachedNode, Input> {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl<'n, CachedNode: Node<'n, Input>, Input> Cache for CacheNode<'n, CachedNode, Input> {
|
||||
fn clear(&mut self) {
|
||||
self.cache = OnceCell::new();
|
||||
}
|
||||
}
|
||||
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
#[derive(DynAny)]
|
||||
struct Boo<'a>(&'a u8);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue