-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed wire add bug, added all_nodes! macro
wasm
- Loading branch information
Showing
5 changed files
with
85 additions
and
37 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod cleanup_sys; | ||
pub mod draw_systems; | ||
pub mod place_node_sys; | ||
pub mod place_wire_sys; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::Connected; | ||
use std::marker::PhantomData; | ||
|
||
use crate::components::Node; | ||
use specs::prelude::*; | ||
|
||
#[derive(Default)] | ||
pub struct CleanupWires<N, const I: usize, const O: usize> | ||
where | ||
N: Node<I, O> + 'static, | ||
{ | ||
node: PhantomData<N>, | ||
} | ||
impl<'a, N, const I: usize, const O: usize> System<'a> for CleanupWires<N, I, O> | ||
where | ||
N: Node<I, O> + 'static, | ||
{ | ||
type SystemData = (WriteStorage<'a, Connected<N, I, O>>, Entities<'a>); | ||
|
||
fn run(&mut self, (mut nodes, entities): Self::SystemData) { | ||
(&mut nodes).join().for_each(|node| { | ||
node.inputs | ||
.iter_mut() | ||
.chain(node.outputs.iter_mut()) | ||
.filter(|wire_opt| wire_opt.is_some()) | ||
.for_each(|o: &mut Option<Entity>| { | ||
let wire_e = o.unwrap(); | ||
dbg!(wire_e); | ||
if !entities.is_alive(wire_e) { | ||
*o = None; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
pub fn run_cleanup_sys(world: &mut World) { | ||
use crate::nodes::*; | ||
|
||
macro_rules! cleanup_nodes { | ||
( $([$node:ident, $i:expr, $o:expr]),*, $(,)? ) => { | ||
$(CleanupWires::<$node, $i, $o>::default().run_now(world);)* | ||
}; | ||
} | ||
|
||
use crate::all_nodes; | ||
all_nodes!(cleanup_nodes); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters