From bd48081e33fe84e7ad8a38966334732c4559720c Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 17 Dec 2018 03:04:40 +0100 Subject: Add loading of embedded resources --- Cargo.lock | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +- src/game.rs | 27 ++++++++++++++-- src/main.rs | 11 +++++-- 4 files changed, 139 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfdab08..761d816 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,6 +137,38 @@ dependencies = [ "miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quote" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rust-embed" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rust-embed-impl 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rust-embed-impl" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "same-file" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sfml" version = "0.14.0" @@ -158,10 +190,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "subconscious-rs" version = "0.1.0" dependencies = [ + "rust-embed 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "sfml 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiled 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "synom" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tiled" version = "0.8.0" @@ -172,6 +223,48 @@ dependencies = [ "xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "unicode-xid" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "walkdir" +version = "2.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "xml-rs" version = "0.3.6" @@ -200,7 +293,19 @@ dependencies = [ "checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649" "checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c" "checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e" +"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" +"checksum rust-embed 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a912353da1bd903d964629d832e73167f87a2311f70acda6d84e3bc21803ec19" +"checksum rust-embed-impl 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91a3b06f283e381fea57a57f9ea7bf3e671eba1e92aa43ae987aab27d48f5a0c" +"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum sfml 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "47b06f9db4d3f8b936d232d92bfbd6335060ae51ddcf1be2e79361aeb5c8fef1" "checksum sfml-build 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff35ae173aff95bc967d1b4f0e131a8aec384c317fd057738da4b0f71c8cf841" +"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" +"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum tiled 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e43db82e3c62f96d84482c1b69e8a9b9ceb1c5cd80bd2ee1669caec58f5831d" +"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" +"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7ec6c39eaa68382c8e31e35239402c0a9489d4141a8ceb0c716099a0b515b562" diff --git a/Cargo.toml b/Cargo.toml index 2cd823c..90e497e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2018" [dependencies] sfml = "0.14.0" -tiled = "0.8.0" \ No newline at end of file +tiled = "0.8.0" +rust-embed = "4.2.0" \ No newline at end of file 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(); } -- cgit v1.2.1