#[macro_use] extern crate rust_embed; extern crate sfml; extern crate tiled; mod game; mod graphics; use std::thread; use std::sync::{Arc, Mutex}; fn main() { let game_state_mutex = Arc::new(Mutex::new(game::new())); let game_state = game_state_mutex.clone(); let game_thread = thread::spawn(move || { loop { // aquire state resource let mut game_state = match game_state.lock() { Ok(game_state) => game_state, Err(poisoned) => poisoned.into_inner(), }; if game_state.running == false { break; } game::update(&mut game_state); } }); let game_state = game_state_mutex.clone(); let graphics_thread = thread::spawn(move || { let mut window = graphics::start(); while window.is_open() { // 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 game_state = match game_state.lock() { Ok(game_state) => game_state, Err(poisoned) => poisoned.into_inner(), }; // stop game thread game_state.running = false; } }); // wait for both thread to die graphics_thread.join().unwrap(); game_thread.join().unwrap(); }