summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs
index 4d32b95..9eb709f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,43 +8,49 @@ use std::thread;
use std::sync::{Arc, Mutex};
fn main() {
- let state_mutex = Arc::new(Mutex::new(game::new()));
+ let game_state_mutex = Arc::new(Mutex::new(game::new()));
- let state = state_mutex.clone();
+ let game_state = game_state_mutex.clone();
let game_thread = thread::spawn(move || {
loop {
// aquire state resource
- let mut state = match state.lock() {
- Ok(state) => state,
+ let mut game_state = match game_state.lock() {
+ Ok(game_state) => game_state,
Err(poisoned) => poisoned.into_inner(),
};
- if state.running == false {
+ if game_state.running == false {
break;
}
- game::update(&mut state);
+ game::update(&mut game_state);
}
});
- let state = state_mutex.clone();
+ let game_state = game_state_mutex.clone();
let graphics_thread = thread::spawn(move || {
let mut window = graphics::start();
while window.is_open() {
- graphics::render(&mut window);
+ // aquire state resource
+ let game_state = match game_state.lock() {
+ Ok(game_state) => game_state,
+ Err(poisoned) => poisoned.into_inner(),
+ };
+
+ graphics::render(&mut window, &game_state);
graphics::update(&mut window);
}
// aquire state resource
- let mut state = match state.lock() {
- Ok(state) => state,
+ let mut game_state = match game_state.lock() {
+ Ok(game_state) => game_state,
Err(poisoned) => poisoned.into_inner(),
};
// stop game thread
- state.running = false;
+ game_state.running = false;
});
// wait for both thread to die