Skip to content

Commit

Permalink
Merge pull request #6 from farm-ng/preludes
Browse files Browse the repository at this point in the history
feat: preludes
  • Loading branch information
strasdat authored Apr 11, 2024
2 parents c94ce06 + bf5aa8e commit 089f4b1
Show file tree
Hide file tree
Showing 35 changed files with 433 additions and 559 deletions.
26 changes: 14 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@ keywords = ["actor", "compute", "graph", "pipeline"]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/farm-ng/hollywood/"
version = "0.5.0"
version = "0.5.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.51"
drawille = "0.3.0"
eframe = {version = "0.26", features = ["wgpu"], optional = true}
env_logger = {version = "0.11.1", optional = true}
grid = "0.13.0"
hollywood_macros = {version = "0.5.0", path = "hollywood_macros"}
async-trait = "0.1"
drawille = "0.3"
# hollywood intends to use only basic features of egui, hence
# future versions of egui will likely/hopefully work
eframe = {version = ">= 0.27, <1.0", features = ["wgpu"], optional = true}
env_logger = {version = "0.11", optional = true}
grid = "0.13"
hollywood_macros = {version = "0.5", path = "hollywood_macros"}
# hollywood intends to use only very basic features of nalgebra, hence
# future versions of nalgebra before the major < 1.0 release are likely to work
nalgebra = ">= 0.32, <1.0"
petgraph = "0.6.3"
rand = "0.8.4"
rand_distr = "0.4.3"
petgraph = "0.6"
rand = "0.8"
rand_distr = "0.4"
# executor feature needed
tokio = {version = "1.28.0", features = ["full"]}
tokio-stream = "0.1.14"
tokio = {version = "1.28", features = ["full"]}
tokio-stream = "0.1"

[features]
default = ["egui"]
Expand Down
50 changes: 22 additions & 28 deletions examples/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ use hollywood::actors::egui::EguiActor;
use hollywood::actors::egui::EguiAppFromBuilder;
use hollywood::actors::egui::GenericEguiBuilder;
use hollywood::actors::egui::Stream;
use hollywood::compute::Context;
use hollywood::core::request::RequestMessage;
use hollywood::core::*;
use hollywood_macros::*;
use hollywood::prelude::*;

#[derive(Clone, Debug)]
#[actor_inputs(ContentGeneratorInbound,{NullProp, ContentGeneratorState, ContentGeneratorOutbound, NullRequest})]
#[actor_inputs(
ContentGeneratorInbound,
{NullProp, ContentGeneratorState, ContentGeneratorOutbound, NullRequest})]
pub enum ContentGeneratorInboundMessage {
Tick(f64),
}

impl OnMessage for ContentGeneratorInboundMessage {
impl HasOnMessage for ContentGeneratorInboundMessage {
/// Process the inbound tick message.
fn on_message(
self,
Expand All @@ -26,11 +25,8 @@ impl OnMessage for ContentGeneratorInboundMessage {
) {
match &self {
ContentGeneratorInboundMessage::Tick(new_value) => {
match state.reset_request.try_recv() {
Ok(_) => {
state.offset = -*new_value;
}
Err(_) => {}
if state.reset_request.try_recv().is_ok() {
state.offset = -*new_value;
}

let x = *new_value + state.offset;
Expand All @@ -48,7 +44,7 @@ impl OnMessage for ContentGeneratorInboundMessage {
}
}

impl InboundMessageNew<f64> for ContentGeneratorInboundMessage {
impl IsInboundMessageNew<f64> for ContentGeneratorInboundMessage {
fn new(_inbound_name: String, msg: f64) -> Self {
ContentGeneratorInboundMessage::Tick(msg)
}
Expand Down Expand Up @@ -121,22 +117,18 @@ impl EguiAppFromBuilder<EguiAppExampleBuilder> for EguiAppExample {
type State = String;
}
use eframe::egui;
use hollywood::RequestMessage;
impl eframe::App for EguiAppExample {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
loop {
match self.message_recv.try_recv() {
Ok(value) => match value.msg {
PlotMessage::SinPlot((x, y)) => {
self.x = x;
self.sin_value = y;
}
PlotMessage::CosPlot((x, y)) => {
self.x = x;
self.cos_value = y;
}
},
Err(_) => {
break;
while let Ok(value) = self.message_recv.try_recv() {
match value.msg {
PlotMessage::SinPlot((x, y)) => {
self.x = x;
self.sin_value = y;
}
PlotMessage::CosPlot((x, y)) => {
self.x = x;
self.cos_value = y;
}
}
}
Expand Down Expand Up @@ -169,7 +161,7 @@ pub async fn run_viewer_example() {
});

// Pipeline configuration
let pipeline = hollywood::compute::Context::configure(&mut |context| {
let pipeline = Hollywood::configure(&mut |context| {
// Actor creation:
// 1. Periodic timer to drive the simulation
let mut timer = hollywood::actors::Periodic::new_with_period(context, 0.1);
Expand Down Expand Up @@ -198,7 +190,9 @@ pub async fn run_viewer_example() {
});

// The cancel_requester is used to cancel the pipeline.
builder.cancel_request_sender = pipeline.cancel_request_sender_template.clone();
builder
.cancel_request_sender
.clone_from(&pipeline.cancel_request_sender_template);

// Plot the pipeline graph to the console.
pipeline.print_flow_graph();
Expand Down
9 changes: 3 additions & 6 deletions examples/moving_average.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use hollywood::actors::printer::PrinterProp;
use hollywood::actors::Periodic;
use hollywood::actors::Printer;
use hollywood::compute::Context;
use hollywood::core::FromPropState;
use hollywood::core::NullState;

use hollywood::example_actors::moving_average::MovingAverage;
use hollywood::example_actors::moving_average::MovingAverageProp;
use hollywood::example_actors::moving_average::MovingAverageState;
use hollywood::prelude::*;

///
/// Run the moving average example
pub async fn run_moving_average_example() {
let pipeline = Context::configure(&mut |context| {
let pipeline = Hollywood::configure(&mut |context| {
let mut timer = Periodic::new_with_period(context, 1.0);
let mut moving_average = MovingAverage::from_prop_and_state(
context,
Expand Down
5 changes: 2 additions & 3 deletions examples/nudge.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use hollywood::actors::printer::PrinterProp;
use hollywood::actors::Nudge;
use hollywood::actors::Printer;
use hollywood::compute::Context;
use hollywood::core::*;
use hollywood::prelude::*;

pub async fn run_tick_print_example() {
let pipeline = Context::configure(&mut |context| {
let pipeline = Hollywood::configure(&mut |context| {
let mut nudge = Nudge::<String>::new(context, "nudge".to_owned());
let mut nudge_printer = Printer::<String>::from_prop_and_state(
context,
Expand Down
6 changes: 2 additions & 4 deletions examples/one_dim_robot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use hollywood::actors::zip::ZipPair;
use hollywood::actors::Periodic;
use hollywood::actors::Printer;
use hollywood::actors::Zip3;
use hollywood::compute::Context;
use hollywood::core::*;

use hollywood::example_actors::one_dim_robot::draw::DrawState;
use hollywood::example_actors::one_dim_robot::filter::FilterState;
use hollywood::example_actors::one_dim_robot::DrawActor;
Expand All @@ -16,9 +13,10 @@ use hollywood::example_actors::one_dim_robot::Robot;
use hollywood::example_actors::one_dim_robot::Sim;
use hollywood::example_actors::one_dim_robot::SimState;
use hollywood::example_actors::one_dim_robot::Stamped;
use hollywood::prelude::*;

async fn run_robot_example() {
let pipeline = Context::configure(&mut |context| {
let pipeline = Hollywood::configure(&mut |context| {
let mut timer = Periodic::new_with_period(context, 0.1);
let mut sim = Sim::from_prop_and_state(
context,
Expand Down
7 changes: 3 additions & 4 deletions examples/print_ticks.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use hollywood::actors::printer::PrinterProp;
use hollywood::actors::Periodic;
use hollywood::actors::Printer;
use hollywood::compute::Context;
use hollywood::core::*;
use hollywood::prelude::*;

///
/// Run the tick print example
pub async fn run_tick_print_example() {
let pipeline = Context::configure(&mut |context| {
let pipeline = Hollywood::configure(&mut |context| {
let mut timer = Periodic::new_with_period(context, 1.0);
let mut time_printer = Printer::<f64>::from_prop_and_state(
context,
Expand Down
5 changes: 2 additions & 3 deletions examples/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use hollywood::actors::zip::Zip2State;
use hollywood::actors::zip::ZipPair;
use hollywood::actors::Printer;
use hollywood::actors::Zip2;
use hollywood::compute::Context;
use hollywood::core::*;
use hollywood::prelude::*;

pub async fn run_tick_print_example() {
let pipeline = Context::configure(&mut |context| {
let pipeline = Hollywood::configure(&mut |context| {
let mut periodic = periodic::Periodic::new_with_period(context, 1.0);

let mut zip = Zip2::<u64, String, String>::from_prop_and_state(
Expand Down
9 changes: 4 additions & 5 deletions hollywood_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ keywords = ["actor", "compute", "graph", "pipeline"]
license = "Apache-2.0"
readme = "../README.md"
repository = "https://github.com/farm-ng/hollywood/tree/main/hollywood_macros"
version = "0.5.0"
version = "0.5.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
proc-macro = true

[dependencies]
convert_case = "0.6.0"
convert_case = "0.6"
proc-macro2 = "1.0"
quote = "1.0.9"
syn = {version = "2.0.18", features = ["full"]}
quote = "1.0"
syn = {version = "2.0", features = ["full"]}
26 changes: 13 additions & 13 deletions hollywood_macros/src/actors/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(crate) fn zip_outbound_n_impl(input: TokenStream) -> TokenStream {
}

impl<Key: Default + Debug+Clone+Sync + Send + 'static, #( #params_with_bounds_seq2 ),*>
Activate for #outbound_struct<Key, #( #params_seq3 ),*>
HasActivate for #outbound_struct<Key, #( #params_seq3 ),*>
{
fn extract(&mut self) -> Self {
Self {
Expand All @@ -132,9 +132,9 @@ pub(crate) fn zip_outbound_n_impl(input: TokenStream) -> TokenStream {
}

impl<Key: Default + Debug+Clone+Sync + Send + 'static, #( #params_with_bounds_seq3 ),*>
OutboundHub for #outbound_struct<Key, #( #params_seq4 ),*>
IsOutboundHub for #outbound_struct<Key, #( #params_seq4 ),*>
{
fn from_context_and_parent(context: &mut Context, actor_name: &str) -> Self {
fn from_context_and_parent(context: &mut Hollywood, actor_name: &str) -> Self {
Self {
zipped: OutboundChannel::<#tuple_struct<Key, #( #params_seq5 ),*>>::new(
context,
Expand Down Expand Up @@ -189,7 +189,7 @@ pub(crate) fn zip_inbound_message_n_impl(input: TokenStream) -> TokenStream {
Err(err) => return TokenStream::from(err.to_compile_error()),
};

let inbound_message_enum = format_ident!("Zip{}InboundMessage", num_fields);
let inbound_message_enum = format_ident!("Zip{}IsInboundMessage", num_fields);
let state_struct = format_ident!("Zip{}State", num_fields);
let outbound_struct = format_ident!("Zip{}Outbound", num_fields);

Expand Down Expand Up @@ -232,7 +232,7 @@ pub(crate) fn zip_inbound_message_n_impl(input: TokenStream) -> TokenStream {
+ Send
+ 'static,
#( #type_with_bounds_seq ),*
> InboundMessageNew<ZipPair<#i, Key, #item>>
> IsInboundMessageNew<ZipPair<#i, Key, #item>>
for #inbound_message_enum<Key, #( #type_seq ),*>
{
fn new(_inbound_name: String, msg: ZipPair<#i, Key, #item>) -> Self {
Expand Down Expand Up @@ -262,7 +262,7 @@ pub(crate) fn zip_inbound_message_n_impl(input: TokenStream) -> TokenStream {
Key: Default + Clone + Debug + PartialEq + Eq + PartialOrd + Ord
+ Sync + Send + 'static,
#( #type_with_bounds_seq ),*
> InboundMessage for #inbound_message_enum<Key, #(#type_seq2),*>
> IsInboundMessage for #inbound_message_enum<Key, #(#type_seq2),*>
{
type Prop = NullProp;
type State = #state_struct<Key, #(#type_seq3),*>;
Expand Down Expand Up @@ -290,7 +290,7 @@ pub(crate) fn zip_n_impl(input: TokenStream) -> TokenStream {
let state_struct = format_ident!("Zip{}State", num_fields);
let inbound_struct = format_ident!("Zip{}Inbound", num_fields);
let outbound_struct = format_ident!("Zip{}Outbound", num_fields);
let inbound_message_enum = format_ident!("Zip{}InboundMessage", num_fields);
let inbound_message_enum = format_ident!("Zip{}IsInboundMessage", num_fields);

let type_seq = (0..num_fields).map(|i| format_ident!("Item{}", i));
let type_seq2 = type_seq.clone();
Expand Down Expand Up @@ -329,7 +329,7 @@ pub(crate) fn zip_n_impl(input: TokenStream) -> TokenStream {
+ Sync + Send + 'static,
#( #type_with_bounds_seq ),*
>
FromPropState<
HasFromPropState<
NullProp,
#inbound_struct<Key, #( #type_seq5), *>,
#state_struct<Key, #( #type_seq6), *>,
Expand Down Expand Up @@ -364,7 +364,7 @@ pub(crate) fn zip_inbound_n_impl(input: TokenStream) -> TokenStream {
let inbound_struct = format_ident!("Zip{}Inbound", num_fields);
let state_struct = format_ident!("Zip{}State", num_fields);
let outbound_struct = format_ident!("Zip{}Outbound", num_fields);
let inbound_message_enum = format_ident!("Zip{}InboundMessage", num_fields);
let inbound_message_enum = format_ident!("Zip{}IsInboundMessage", num_fields);

let type_seq = (0..num_fields).map(|i| format_ident!("Item{}", i));
let type_seq4 = type_seq.clone();
Expand Down Expand Up @@ -422,7 +422,7 @@ pub(crate) fn zip_inbound_n_impl(input: TokenStream) -> TokenStream {
+ Sync + Send + 'static,
#( #type_with_bounds_seq ),*
>
InboundHub<
IsInboundHub<
NullProp,
#state_struct<Key, #( #type_seq4),*>,
#outbound_struct<Key, #( #type_seq5),*>,
Expand All @@ -431,7 +431,7 @@ pub(crate) fn zip_inbound_n_impl(input: TokenStream) -> TokenStream {
> for #inbound_struct<Key, #( #type_seq7),*>
{
fn from_builder(
builder: &mut crate::core::ActorBuilder<
builder: &mut ActorBuilder<
NullProp,
#state_struct<Key, #( #type_seq8),*>,
#outbound_struct<Key, #( #type_seq9),*>,
Expand Down Expand Up @@ -467,7 +467,7 @@ pub(crate) fn zip_onmessage_n_impl(input: TokenStream) -> TokenStream {
};

let tuple_struct = format_ident!("Tuple{}", num_fields);
let inbound_message_enum = format_ident!("Zip{}InboundMessage", num_fields);
let inbound_message_enum = format_ident!("Zip{}IsInboundMessage", num_fields);

let type_seq = (0..num_fields).map(|i| format_ident!("Item{}", i));

Expand Down Expand Up @@ -521,7 +521,7 @@ pub(crate) fn zip_onmessage_n_impl(input: TokenStream) -> TokenStream {
let expanded = quote! {

impl<Key: Default + Clone + Debug + PartialEq + Eq + PartialOrd + Ord + Sync + Send,
#( #type_with_bounds_seq ),*> OnMessage for #inbound_message_enum<Key, #(#type_seq), *>
#( #type_with_bounds_seq ),*> HasOnMessage for #inbound_message_enum<Key, #(#type_seq), *>
{
fn on_message(
self,
Expand Down
Loading

0 comments on commit 089f4b1

Please sign in to comment.