aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 0f87d5b..b4adbd3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,8 +3,9 @@ use std::time::Duration;
use minifb::{Key, Window, WindowOptions};
mod actor;
+mod basic_actors;
mod number;
-mod system;
+mod world;
const WIDTH: usize = 1600;
const HEIGHT: usize = 900;
@@ -21,6 +22,82 @@ fn main() {
window.limit_update_rate(Some(Duration::from_millis(16)));
+ // hard code this for now
+ let mut world = world::World::default();
+
+ let nonnegative_int = actor::Type::NumberInRange {
+ min: Some(number::Number::from(0)),
+ max: None,
+ };
+ let screen_position_type = actor::Type::Record {
+ name: "Screen Position".to_string(),
+ fields: vec![
+ actor::Slot { name: "X".to_string(), r#type: nonnegative_int.clone() },
+ actor::Slot { name: "Y".to_string(), r#type: nonnegative_int.clone() },
+ ],
+ };
+ let system_inputs = vec![actor::Slot { name: "mouse_position".to_string(), r#type: screen_position_type.clone() }];
+
+ let u24 = actor::Type::NumberInRange {
+ min: Some(number::Number::from(0)),
+ max: Some(number::Number::from(1 << 24 - 1)),
+ };
+ let system_outputs = vec![actor::Slot { name: "screen_buffer".to_string(), r#type: actor::Type::List { contents: Box::new(u24.clone()) }}];
+
+ let mut system = actor::ProgrammableActor {
+ inputs: system_inputs,
+ outputs: system_outputs,
+ ..Default::default()
+ };
+
+ let deconstruct_record = basic_actors::DeconstructRecord {
+ record_type: screen_position_type,
+ };
+ world.upsert_actor_type("Deconstruct Screen Position".to_string(), Box::new(deconstruct_record));
+ let deconstruct_record = system.add_child("Deconstruct Screen Position".to_string());
+ system.add_cable(
+ actor::ProducerSlotID::Input("mouse_position".to_string()),
+ actor::ConsumerSlotID::ChildInput(deconstruct_record, "Record".to_string())
+ );
+
+ world.upsert_actor_type("Add".to_string(), Box::new(basic_actors::Add));
+ let add = system.add_child("Add".to_string());
+ system.add_cable(
+ actor::ProducerSlotID::ChildOutput(deconstruct_record, "X".to_string()),
+ actor::ConsumerSlotID::ChildInput(add, "N1".to_string())
+ );
+ system.add_cable(
+ actor::ProducerSlotID::ChildOutput(deconstruct_record, "Y".to_string()),
+ actor::ConsumerSlotID::ChildInput(add, "N2".to_string())
+ );
+
+ let buffer_size_constant = basic_actors::Constant {
+ r#type: nonnegative_int.clone(),
+ value: actor::Value::Number(number::Number::from(WIDTH * HEIGHT)),
+ };
+ world.upsert_actor_type("Buffer Size Constant".to_string(), Box::new(buffer_size_constant));
+ let buffer_size_constant = system.add_child("Buffer Size Constant".to_string());
+
+ let repeat_u24 = basic_actors::RepeatValue {
+ r#type: u24,
+ };
+ world.upsert_actor_type("Repeat u24".to_string(), Box::new(repeat_u24));
+ let repeat_u24 = system.add_child("Repeat u24".to_string());
+ system.add_cable(
+ actor::ProducerSlotID::ChildOutput(add, "Result".to_string()),
+ actor::ConsumerSlotID::ChildInput(repeat_u24, "Value".to_string())
+ );
+ system.add_cable(
+ actor::ProducerSlotID::ChildOutput(buffer_size_constant, "Value".to_string()),
+ actor::ConsumerSlotID::ChildInput(repeat_u24, "Count".to_string())
+ );
+ system.add_cable(
+ actor::ProducerSlotID::ChildOutput(repeat_u24, "List".to_string()),
+ actor::ConsumerSlotID::Output("screen_buffer".to_string())
+ );
+
+ world.upsert_actor_type("System".to_string(), Box::new(system));
+
while window.is_open() && !window.is_key_down(Key::Escape) {
window
.update_with_buffer(&buffer, WIDTH, HEIGHT)