aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-03-07 09:49:58 -0700
committerMelody Horn <melody@boringcactus.com>2021-03-07 09:49:58 -0700
commitc8cfeabc011bfabb6303023a969155ded926d95c (patch)
tree0c8ca2f7b6e8d6923e8daafa7c87c5d31764f0c1 /src/main.rs
parent36d5ff553a1d65d70da5251b8865d62294c929f6 (diff)
downloadhope-c8cfeabc011bfabb6303023a969155ded926d95c.tar.gz
hope-c8cfeabc011bfabb6303023a969155ded926d95c.zip
another crumb or two of architecture tweaks
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index b4adbd3..6bf920b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
use std::time::Duration;
-use minifb::{Key, Window, WindowOptions};
+use minifb::{Key, Window, WindowOptions, MouseMode};
mod actor;
mod basic_actors;
@@ -98,9 +98,40 @@ fn main() {
world.upsert_actor_type("System".to_string(), Box::new(system));
+ let (_, mut system_inputs, mut system_outputs) = world.spawn_actor("System");
+
+ let mouse_position = system_inputs.remove("mouse_position").unwrap();
+ let screen_buffer = system_outputs.remove("screen_buffer").unwrap();
+
while window.is_open() && !window.is_key_down(Key::Escape) {
- window
- .update_with_buffer(&buffer, WIDTH, HEIGHT)
- .unwrap();
+ if let Some((mouse_x, mouse_y)) = window.get_mouse_pos(MouseMode::Discard) {
+ let mouse_x = mouse_x as u16;
+ let mouse_y = mouse_y as u16;
+ let value = actor::Value::Record(vec![
+ ("X".to_string(), actor::Value::Number(number::Number::from(mouse_x))),
+ ("Y".to_string(), actor::Value::Number(number::Number::from(mouse_y))),
+ ]);
+ mouse_position.send(value).unwrap();
+ }
+
+ if let Ok(value) = screen_buffer.try_recv() {
+ if let actor::Value::List(data) = value {
+ let u32_data: Vec<u32> = data.into_iter()
+ .map(|x| {
+ if let actor::Value::Number(x) = x {
+ format!("{}", x).parse().unwrap()
+ } else {
+ panic!("bruh")
+ }
+ })
+ .collect();
+ if u32_data.len() != WIDTH * HEIGHT {
+ panic!("bruhhhhhhhhhhhhhh");
+ }
+ window.update_with_buffer(&u32_data, WIDTH, HEIGHT).unwrap();
+ }
+ } else {
+ window.update();
+ }
}
}