summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 2679ac4..e2353e7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,13 +1,48 @@
mod game;
mod graphics;
+use std::thread;
+use std::sync::{Arc, Mutex};
fn main() {
- game::start();
+ let state_ = Arc::new(Mutex::new(game::new()));
- let graphics_thread = std::thread::spawn(move || {
- graphics::start();
+ let state = state_.clone();
+ let game_thread = thread::spawn(move || {
+ loop {
+ // aquire state resource
+ let mut state = match state.lock() {
+ Ok(state) => state,
+ Err(poisoned) => poisoned.into_inner(),
+ };
+
+ if state.running == false {
+ break;
+ }
+
+ game::update(&mut state);
+ }
+ });
+
+
+ let state = state_.clone();
+ let graphics_thread = thread::spawn(move || {
+ let mut window = graphics::start();
+
+ while window.is_open() {
+ graphics::render(&mut window);
+ graphics::update(&mut window);
+ }
+
+ // aquire state resource
+ let mut state = match state.lock() {
+ Ok(state) => state,
+ Err(poisoned) => poisoned.into_inner(),
+ };
+
+ state.running = false;
});
graphics_thread.join().unwrap();
+ game_thread.join().unwrap();
}