From 8c002604430998ae4a7930f9d620becf4786adbc Mon Sep 17 00:00:00 2001 From: Thomas Versteeg Date: Fri, 8 Mar 2024 22:07:58 +0100 Subject: [PATCH] chore(deps): update rust dependencies --- Cargo.toml | 12 ++++++------ rust-toolchain.toml | 6 +++--- src/assets.rs | 1 - src/debug.rs | 16 +++++++-------- src/main.rs | 47 +++++++++++---------------------------------- src/projectile.rs | 2 +- src/unit.rs | 10 +++++----- 7 files changed, 34 insertions(+), 60 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 891d203..059357b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,11 +19,10 @@ debug = ["drawille"] [dependencies] blit = "0.8" -miette = { version = "5", features = ["fancy"] } +miette = { version = "7", features = ["fancy"] } image = { version = "0.24", default-features = false, features = ["png"] } rotsprite = "0.1" vek = "0.16" -assets_manager = { version = "0.10", features = ["embedded", "hot-reloading", "toml", "png"], default-features = false } serde = "1" itertools = "0.12" parry2d-f64 = { version = "0.13", features = ["simd-stable"] } @@ -34,16 +33,17 @@ bitvec = "1" line_drawing = "1" drawille = { version = "0.3", optional = true } spiral = "0.2" -pixel-game-lib = "0.4" +pixel-game-lib = "0.8" +assets_manager = "0.11" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] fastrand = "2" -puffin = "0.17" -puffin_http = "0.14" +puffin = "0.19" +puffin_http = "0.16" [target.'cfg(target_arch = "wasm32")'.dependencies] fastrand = { version = "2", default-features = false, features = ["js"] } -puffin = "0.17" +puffin = "0.19" [workspace] members = ["run-wasm"] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 429cb93..961fdb4 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -# We need 1.70 because we use OnceLock -channel = "1.70" -targets = ["wasm32-unknown-unknown"] \ No newline at end of file +# We need 1.72.1 due to pixel-game-lib +channel = "1.72.1" +targets = ["wasm32-unknown-unknown"] diff --git a/src/assets.rs b/src/assets.rs index d145286..e7b300e 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -1,4 +1,3 @@ -use assets_manager::{AssetCache, AssetGuard, Compound}; use crate::game::Settings; diff --git a/src/debug.rs b/src/debug.rs index 53922a4..82bfecf 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -6,7 +6,7 @@ use pixel_game_lib::{ rigidbody::{RigidBodyBuilder, RigidBodyHandle}, Physics, }, - window::{Input, KeyCode}, + window::{Input, KeyCode, MouseButton}, }; use serde::Deserialize; use vek::{Extent2, Vec2}; @@ -162,15 +162,15 @@ impl DebugDraw { self.physics.step(dt, &crate::settings().physics); } - if input.mouse_released(0) { + if input.mouse_released(MouseButton::Left) { // Spawn a projectile at the mouse coordinates, camera doesn't apply to local physics engine - let object = crate::asset::(CRATE); + let object = pixel_game_lib::asset::(CRATE); self.boxes .push(object.rigidbody_builder(mouse).spawn(&mut self.physics)); } } - if self.screen == DebugScreen::SpawnProjectiles && input.mouse_released(0) { + if self.screen == DebugScreen::SpawnProjectiles && input.mouse_released(MouseButton::Left) { // Spawn a projectile at the mouse coordinates projectiles.push(Projectile::new( camera.translate_from_screen(self.mouse), @@ -179,12 +179,12 @@ impl DebugDraw { )); } - if self.screen == DebugScreen::Terrain && input.mouse_released(0) { + if self.screen == DebugScreen::Terrain && input.mouse_released(MouseButton::Left) { // Click to slice the terrain terrain.remove_circle(camera.translate_from_screen(mouse), 10.0, physics); } - if self.screen == DebugScreen::Shape && input.mouse_released(0) { + if self.screen == DebugScreen::Shape && input.mouse_released(MouseButton::Left) { // Click to slice the terrain let mut new_shapes = Vec::new(); for shape in self.shapes.iter_mut() { @@ -251,13 +251,13 @@ impl DebugDraw { } DebugScreen::Collisions => { // Draw collision between rotated rectangles - let object = crate::asset::(SPEAR); + let object = pixel_game_lib::asset::(SPEAR); let shape = object.shape(); let mouse_iso = Iso::new(self.mouse.as_(), Rotation::from_degrees(-23f64)); // Detect collisions with the heightmap - let level_object = crate::asset::(LEVEL); + let level_object = pixel_game_lib::asset::(LEVEL); let level_pos = Vec2::new(0.0, 100.0); let level_iso = Iso::from_pos(level_pos); diff --git a/src/main.rs b/src/main.rs index 44458c0..3573bc1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -mod assets; mod camera; #[cfg(feature = "debug")] mod debug; @@ -17,8 +16,7 @@ mod unit; use std::sync::OnceLock; -use assets::Assets; -use assets_manager::{AssetGuard, Compound}; +use assets_manager::{AssetReadGuard, Compound}; use font::Font; use game::{GameState, Settings}; use miette::Result; @@ -33,50 +31,27 @@ pub const SIZE: Extent2 = Extent2::new(640, 360); /// Updates per second of the update loop. const UPDATES_PER_SECOND: u32 = 60; -/// The assets as a 'static reference. -pub static ASSETS: OnceLock = OnceLock::new(); - -/// Load an generic asset. -pub fn asset(path: &str) -> AssetGuard -where - T: Compound, -{ - puffin::profile_function!(); - - ASSETS - .get() - .expect("Asset handling not initialized yet") - .asset(path) -} - -/// Load the global settings. -pub fn settings() -> AssetGuard<'static, Settings> { - ASSETS - .get() - .expect("Asset handling not initialized yet") - .settings() +/// Load the settings. +pub fn settings() -> AssetReadGuard<'static, Settings> { + pixel_game_lib::asset("settings") } /// Load a sprite. -pub fn sprite(path: &str) -> AssetGuard { - crate::asset(path) +pub fn sprite(path: &str) -> AssetReadGuard { + pixel_game_lib::asset(path) } /// Load a rotatable sprite. -pub fn rotatable_sprite(path: &str) -> AssetGuard { - crate::asset(path) +pub fn rotatable_sprite(path: &str) -> AssetReadGuard { + pixel_game_lib::asset(path) } /// Load a font. -pub fn font(path: &str) -> AssetGuard { - crate::asset(path) +pub fn font(path: &str) -> AssetReadGuard { + pixel_game_lib::asset(path) } fn main() -> Result<()> { - // Initialize the asset loader - let assets = ASSETS.get_or_init(Assets::load); - assets.enable_hot_reloading(); - // Construct the game let state = GameState::new(); @@ -98,7 +73,7 @@ fn main() -> Result<()> { buffer_size: SIZE, title: "Castle Game".to_string(), updates_per_second: UPDATES_PER_SECOND, - scaling: 2, + scaling: 4, }, |g, input, mouse, dt| { puffin::profile_scope!("Update"); diff --git a/src/projectile.rs b/src/projectile.rs index eb5ba14..13d6977 100644 --- a/src/projectile.rs +++ b/src/projectile.rs @@ -29,7 +29,7 @@ impl Projectile { puffin::profile_function!(); // Load the object definition for properties of the object - let object = crate::asset::(ASSET_PATH); + let object = pixel_game_lib::asset::(ASSET_PATH); let rigidbody = object .rigidbody_builder(pos) diff --git a/src/unit.rs b/src/unit.rs index 4b79b8c..01a2ad1 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -1,4 +1,4 @@ -use assets_manager::{loader::TomlLoader, Asset, AssetGuard}; +use assets_manager::{loader::TomlLoader, Asset, AssetReadGuard}; use pixel_game_lib::physics::{rigidbody::RigidBodyHandle, Physics}; use serde::Deserialize; use vek::{Extent2, Vec2}; @@ -17,14 +17,14 @@ pub enum UnitType { impl UnitType { /// Settings path to load for this type. - pub fn settings(&self) -> AssetGuard { + pub fn settings(&self) -> AssetReadGuard { // Settings asset path let path = match self { Self::PlayerSpear => "unit.spear", Self::EnemySpear => "unit.enemy-spear", }; - crate::asset(path) + pixel_game_lib::asset(path) } /// Asset path based on what type to load. @@ -62,7 +62,7 @@ impl Unit { let health = r#type.settings().health; // Load the object definition for properties of the object - let object = crate::asset::(r#type.asset_path()); + let object = pixel_game_lib::asset::(r#type.asset_path()); let rigidbody = object.rigidbody_builder(pos).spawn(physics); Self { @@ -169,7 +169,7 @@ impl Unit { } /// The settings for this unit. - fn settings(&self) -> AssetGuard { + fn settings(&self) -> AssetReadGuard { self.r#type.settings() } }