summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-12-17 03:04:40 +0100
committerNao Pross <naopross@thearcway.org>2018-12-17 03:04:40 +0100
commitbd48081e33fe84e7ad8a38966334732c4559720c (patch)
treedf7df83021e2aa3dfd354735cf322a42a69eb531 /src
parentAdd game state object shared across threads (diff)
downloadSubconscious-rs-bd48081e33fe84e7ad8a38966334732c4559720c.tar.gz
Subconscious-rs-bd48081e33fe84e7ad8a38966334732c4559720c.zip
Add loading of embedded resources
Diffstat (limited to 'src')
-rw-r--r--src/game.rs27
-rw-r--r--src/main.rs11
2 files changed, 32 insertions, 6 deletions
diff --git a/src/game.rs b/src/game.rs
index ab04b21..335e9da 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -1,15 +1,36 @@
+use std::error::Error;
+
+use tiled::Map;
+
+// embedded resources
+#[derive(RustEmbed)]
+#[folder = "res/maps"]
+pub struct MapAssets;
+
+// game state
pub struct State {
- pub running: bool
+ pub running: bool,
+ pub map: Map,
}
+pub fn new() -> State {
+ // load demo map
+ let demo_map_asset = match MapAssets::get("demo.tmx") {
+ Some(asset) => asset,
+ None => panic!("Failed to load demo map asset"),
+ };
+ let demo_map = match tiled::parse(demo_map_asset.as_ref()) {
+ Ok(map) => map,
+ Err(e) => panic!("Failed to parse demo map: {}", e.description()),
+ };
-pub fn new() -> State {
return State {
running: true,
+ map: demo_map
};
}
-pub fn update(state: &mut State) {
+pub fn update(_state: &mut State) {
} \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index e2353e7..4d32b95 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,6 @@
+#[macro_use]
+extern crate rust_embed;
+
mod game;
mod graphics;
@@ -5,9 +8,9 @@ use std::thread;
use std::sync::{Arc, Mutex};
fn main() {
- let state_ = Arc::new(Mutex::new(game::new()));
+ let state_mutex = Arc::new(Mutex::new(game::new()));
- let state = state_.clone();
+ let state = state_mutex.clone();
let game_thread = thread::spawn(move || {
loop {
// aquire state resource
@@ -25,7 +28,7 @@ fn main() {
});
- let state = state_.clone();
+ let state = state_mutex.clone();
let graphics_thread = thread::spawn(move || {
let mut window = graphics::start();
@@ -40,9 +43,11 @@ fn main() {
Err(poisoned) => poisoned.into_inner(),
};
+ // stop game thread
state.running = false;
});
+ // wait for both thread to die
graphics_thread.join().unwrap();
game_thread.join().unwrap();
}