1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! # A02: Two-plate door
//!
//! Combine two Boolean senses and expose a door request owned by the host.
//!
//! ```
//! use wyrd::{weave, tick_once, BindOpts, KnotKind, Runtime, ScriptedHost, SignalDomain, ONE, ZERO};
//!
//! let weave = weave! {
//! id: "a02";
//! knots {
//! plate_a = KnotKind::signal_in(SignalDomain::Bool);
//! plate_b = KnotKind::signal_in(SignalDomain::Bool);
//! both = KnotKind::and2();
//! door = KnotKind::signal_out("door.open", SignalDomain::Bool);
//! }
//! threads {
//! plate_a.out -> both.in_0;
//! plate_b.out -> both.in_1;
//! both.out -> door.in;
//! }
//! }?;
//!
//! let mut runtime = Runtime::bind(weave, BindOpts::default())?;
//! let a = runtime.required_sense("plate_a")?;
//! let b = runtime.required_sense("plate_b")?;
//! let door = runtime.required_path("door.open")?;
//! let mut host = ScriptedHost::new();
//!
//! host.push_frame([(a, ONE), (b, ZERO)]);
//! tick_once(&mut host, &mut runtime)?;
//! assert_eq!(runtime.outbox().signals()[0].value, ZERO);
//!
//! host.push_frame([(a, ONE), (b, ONE)]);
//! tick_once(&mut host, &mut runtime)?;
//! assert_eq!(runtime.outbox().signals()[0].path, door);
//! assert_eq!(runtime.outbox().signals()[0].value, ONE);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! The graph decides whether the door should open. The host applies that
//! request to its animation, collision, and persistence systems.
//!
//! Next: [`a03_bind_sample_loom`](super::a03_bind_sample_loom).