Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Limeth committed Apr 6, 2024
1 parent 473507f commit e445cbe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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;
Expand Down
41 changes: 23 additions & 18 deletions src/node/behaviour.rs
Original file line number Diff line number Diff line change
@@ -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 {}

Expand Down Expand Up @@ -67,24 +65,32 @@ impl<M: NodeBehaviourMessage> NodeEvent<M> {

// FIXME: Maybe just store `Box<dyn NodeExecutor<'static>>` instead?
pub struct NodeStateContainer<'state> {
ptr: Box<dyn NodeExecutor<'state> + 'state>,
ptr: Box<dyn NodeExecutor<'state> + 'static>,
}

impl<'state> NodeStateContainer<'state> {
pub fn from<T: NodeBehaviour>(state: T::State<'state>) -> Self {
Self { ptr: Box::new(state) as Box<dyn NodeExecutor<'state> + '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<T: NodeBehaviour>(&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<T: NodeBehaviour>(&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>(
Expand All @@ -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;
}
Expand All @@ -129,10 +135,9 @@ pub trait TransientTrait: Debug + Send + Sync {}
impl<T> 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<dyn ExecutorClosure<'state, Transient> + 'state>
+ Send
+ Sync;
pub trait ExecutorClosureConstructor<'state, T, Transient: TransientTrait + 'state = ()> = Fn(&T, &ApplicationContext, &mut Transient) -> Box<dyn ExecutorClosure<'state, Transient> + 'state>
+ Send
+ Sync;

/// Invoked once per node per graph execution.
pub trait ExecutorClosure<'state, Transient: TransientTrait + 'state = ()> =
Expand Down
2 changes: 1 addition & 1 deletion src/node/behaviour/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
ApplicationContext, ExecutionContext, ExecutorClosure, NodeBehaviour, NodeCommand, NodeEvent,
NodeStateClosure,
},
Channel, NodeConfiguration, OptionRefMutExt, PrimitiveType, PrimitiveTypeEnum,
Channel, NodeConfiguration, OptionRefMutExt, PrimitiveTypeEnum,
},
style::Theme,
};
Expand Down

0 comments on commit e445cbe

Please sign in to comment.