From e445cbeb6fcf023274fa2dcfb9702ddbca5e8f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hlusi=C4=8Dka?= Date: Sun, 7 Apr 2024 00:10:11 +0200 Subject: [PATCH] WIP --- Cargo.lock | 2 ++ src/graph/mod.rs | 13 +++++------ src/main.rs | 6 ++--- src/node/behaviour.rs | 41 ++++++++++++++++++++--------------- src/node/behaviour/counter.rs | 2 +- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60bb952..8953f9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "ab_glyph" version = "0.2.5" diff --git a/src/graph/mod.rs b/src/graph/mod.rs index 71932de..e068bb0 100644 --- a/src/graph/mod.rs +++ b/src/graph/mod.rs @@ -5,8 +5,8 @@ use crate::node::behaviour::{ }; use crate::node::ty::{BorrowedRef, BorrowedRefMut, OptionRefExt, OptionType, TypeEnum, TypeExt}; use crate::node::{ - ChannelDirection, ChannelPassBy, ChannelRef, ChannelValueRefs, ChannelValues, ConnectionPassBy, - DynTypeTrait, ListDescriptor, NodeConfiguration, NodeStateRefcounter, OptionRefMutExt, RefAnyExt, + ChannelDirection, ChannelPassBy, ChannelRef, ConnectionPassBy, DynTypeTrait, NodeConfiguration, + NodeStateRefcounter, OptionRefMutExt, RefAnyExt, }; use crate::style::{self, consts, Theme, Themeable}; use crate::widgets::{ @@ -21,9 +21,8 @@ use arc_swap::ArcSwapOption; use iced::{Element, Settings}; use iced_futures::futures; use iced_wgpu::wgpu; -use petgraph::{algo::Cycle, stable_graph::StableGraph, visit::EdgeRef, Directed, Direction}; +use petgraph::{stable_graph::StableGraph, visit::EdgeRef, Directed, Direction}; use std::borrow::Cow; -use std::cell::RefCell; use std::collections::{hash_map::Entry, HashMap, HashSet}; use std::fmt::Debug; use std::fmt::Display; @@ -988,10 +987,8 @@ impl GraphExecutor { let prepared_execution = prepared_execution.as_mut().unwrap(); prepared_execution.execute(active_schedule, &mut self.application_context); - } else { - if let Some(prepared_execution) = prepared_execution.take() { - last_prepared_execution = Some(prepared_execution); - } + } else if let Some(prepared_execution) = prepared_execution.take() { + last_prepared_execution = Some(prepared_execution); } } } diff --git a/src/main.rs b/src/main.rs index c4ddc76..f6b3bdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,9 @@ #![feature(array_windows)] #![feature(associated_type_bounds)] #![feature(never_type)] -#![feature(raw)] -#![feature(generic_associated_types)] +#![feature(ptr_metadata)] #![feature(negative_impls)] #![feature(const_fn_floating_point_arithmetic)] -#![feature(bindings_after_at)] -#![feature(iterator_fold_self)] #![feature(trivial_bounds)] #![feature(associated_type_defaults)] #![feature(trait_alias)] @@ -33,6 +30,7 @@ use graph::{ }; use iced::{window, Application, Command, Settings}; use iced_winit::winit; +use node::behaviour::counter::CounterNodeBehaviour; use node::behaviour::*; use node::*; use petgraph::graph::NodeIndex; diff --git a/src/node/behaviour.rs b/src/node/behaviour.rs index 49b00cb..4397b89 100644 --- a/src/node/behaviour.rs +++ b/src/node/behaviour.rs @@ -1,24 +1,22 @@ use crate::graph::{ApplicationContext, NodeIndex}; -use crate::node::{ - BorrowedRef, BorrowedRefMut, ChannelValueRefs, ChannelValues, DynTypeTrait, NodeConfiguration, OptionType, -}; +use crate::node::{BorrowedRef, BorrowedRefMut, DynTypeTrait, NodeConfiguration, OptionType}; use crate::style::Theme; use downcast_rs::{impl_downcast, Downcast}; use dyn_clone::DynClone; use iced::Element; use iced_winit::winit::event_loop::EventLoopWindowTarget; +use std::any::Any; use std::fmt::Debug; use std::marker::PhantomData; pub use array_constructor::*; pub use binary_op::*; pub use constant::*; -pub use counter::*; pub use debug::*; pub use list_constructor::*; pub use window::*; -use super::{OwnedRefMut, SizedTypeExt, TypeEnum, TypeTrait, Unique}; +use super::{OwnedRefMut, Unique}; pub struct Inputs {} @@ -67,7 +65,7 @@ impl NodeEvent { // FIXME: Maybe just store `Box>` instead? pub struct NodeStateContainer<'state> { - ptr: Box + 'state>, + ptr: Box + 'static>, } impl<'state> NodeStateContainer<'state> { @@ -75,16 +73,24 @@ impl<'state> NodeStateContainer<'state> { Self { ptr: Box::new(state) as Box + 'state> } } - /// Safety: The returned value must not outlive self. - unsafe fn as_trait_object(&mut self) -> std::raw::TraitObject { - let raw: *mut dyn NodeExecutor<'state> = &mut *self.ptr as *mut _; + // /// Safety: The returned value must not outlive self. + // unsafe fn as_trait_object(&mut self) -> std::raw::TraitObject { + // let raw: *mut dyn NodeExecutor<'state> = &mut *self.ptr as *mut _; - std::mem::transmute(raw) - } + // std::mem::transmute(raw) + // } + + // unsafe fn downcast_mut(&mut self) -> &mut T::State<'state> { + // let trait_object = self.as_trait_object(); + // &mut *(trait_object.data as *mut T::State<'state>) + // } unsafe fn downcast_mut(&mut self) -> &mut T::State<'state> { - let trait_object = self.as_trait_object(); - &mut *(trait_object.data as *mut T::State<'state>) + //let reference: &mut dyn NodeExecutor<'state> = &mut *self.ptr; + let mut reference = self.ptr.as_mut(); + reference.as_any_mut().downcast_mut().unwrap() + //let raw: *mut dyn NodeExecutor<'state> = &mut *self.ptr as *mut _; + //&mut *(trait_object.data as *mut T::State<'state>) } pub fn update<'invocation, T: NodeBehaviour>( @@ -109,7 +115,7 @@ impl<'state> NodeStateContainer<'state> { // } } -pub trait NodeExecutor<'state>: Debug + Send + Sync { +pub trait NodeExecutor<'state>: Debug + Send + Sync + Any { fn execute<'invocation>(&'invocation mut self, context: ExecutionContext<'invocation, 'state>) where 'state: 'invocation; } @@ -129,10 +135,9 @@ pub trait TransientTrait: Debug + Send + Sync {} impl TransientTrait for T where T: Debug + Send + Sync {} /// Constructs an executor. Invoked every time the execution graph is recreated. -pub trait ExecutorClosureConstructor<'state, T, Transient: TransientTrait + 'state = ()> = - Fn(&T, &ApplicationContext, &mut Transient) -> Box + 'state> - + Send - + Sync; +pub trait ExecutorClosureConstructor<'state, T, Transient: TransientTrait + 'state = ()> = Fn(&T, &ApplicationContext, &mut Transient) -> Box + 'state> + + Send + + Sync; /// Invoked once per node per graph execution. pub trait ExecutorClosure<'state, Transient: TransientTrait + 'state = ()> = diff --git a/src/node/behaviour/counter.rs b/src/node/behaviour/counter.rs index fa7fd54..8ab3686 100644 --- a/src/node/behaviour/counter.rs +++ b/src/node/behaviour/counter.rs @@ -4,7 +4,7 @@ use crate::{ ApplicationContext, ExecutionContext, ExecutorClosure, NodeBehaviour, NodeCommand, NodeEvent, NodeStateClosure, }, - Channel, NodeConfiguration, OptionRefMutExt, PrimitiveType, PrimitiveTypeEnum, + Channel, NodeConfiguration, OptionRefMutExt, PrimitiveTypeEnum, }, style::Theme, };