From 6d9ed166687a5e30d166c39d68eade503871e826 Mon Sep 17 00:00:00 2001 From: Alula <6276139+alula@users.noreply.github.com> Date: Mon, 16 Aug 2021 08:51:21 +0200 Subject: [PATCH] slight cleanup --- build.rs | 2 +- src/components/water_renderer.rs | 5 ++-- src/framework/render_opengl.rs | 2 +- src/map.rs | 43 ++++++++++++++++++++++---------- src/physics.rs | 2 -- src/shared_game_state.rs | 1 - 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/build.rs b/build.rs index d26903c..f026d96 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,7 @@ use std::env; fn main() { // let dest = PathBuf::from(&env::var("OUT_DIR").unwrap()); - let target = env::var("TARGET").unwrap_or_else(|e| panic!(e)); + let target = env::var("TARGET").unwrap_or_else(|e| panic!("{}", e)); let is_android = cfg!(target_os = "android") || (cfg!(target_os = "linux") && target.contains("android")); // hack println!("cargo:rerun-if-changed=build.rs"); diff --git a/src/components/water_renderer.rs b/src/components/water_renderer.rs index 073cba5..ac1cce5 100644 --- a/src/components/water_renderer.rs +++ b/src/components/water_renderer.rs @@ -8,7 +8,6 @@ use crate::framework::graphics; use crate::map::WaterRegionType; use crate::player::Player; use crate::shared_game_state::SharedGameState; -use crate::framework::graphics::BlendMode; const TENSION: f32 = 0.03; const DAMPENING: f32 = 0.01; @@ -116,8 +115,8 @@ impl WaterRenderer { } } -impl GameEntity<(&Player)> for WaterRenderer { - fn tick(&mut self, state: &mut SharedGameState, (player): (&Player)) -> GameResult<()> { +impl GameEntity<&Player> for WaterRenderer { + fn tick(&mut self, state: &mut SharedGameState, player: &Player) -> GameResult<()> { let player_x = player.x as f32 / 512.0 + 8.0; let player_y = player.y as f32 / 512.0 + 8.0; diff --git a/src/framework/render_opengl.rs b/src/framework/render_opengl.rs index 6934111..1e25dd7 100644 --- a/src/framework/render_opengl.rs +++ b/src/framework/render_opengl.rs @@ -479,7 +479,7 @@ pub fn load_gl(gl_context: &mut GLContext) -> &'static Gl { let gl = gl::Gles2::load_with(|ptr| (gl_context.get_proc_address)(&mut gl_context.user_data, ptr)); - let version = unsafe { + let version = { let p = gl.GetString(gl::VERSION); if p.is_null() { "unknown".to_owned() diff --git a/src/map.rs b/src/map.rs index c342d07..4d11c2c 100644 --- a/src/map.rs +++ b/src/map.rs @@ -7,13 +7,13 @@ use byteorder::{ReadBytesExt, LE}; use crate::common::{Color, Rect}; use crate::encoding::read_cur_shift_jis; +use crate::framework::context::Context; use crate::framework::error::GameError::ResourceLoadError; use crate::framework::error::{GameError, GameResult}; -use crate::shared_game_state::TileSize; -use crate::stage::{StageData, PxPackScroll, PxPackStageData}; -use crate::str; use crate::framework::filesystem; -use crate::framework::context::Context; +use crate::shared_game_state::TileSize; +use crate::stage::{PxPackScroll, PxPackStageData, StageData}; +use crate::str; static SUPPORTED_PXM_VERSIONS: [u8; 1] = [0x10]; static SUPPORTED_PXE_VERSIONS: [u8; 2] = [0, 0x10]; @@ -67,7 +67,12 @@ impl Map { Ok(Map { width, height, tiles, attrib, tile_size: TileSize::Tile16x16 }) } - pub fn load_pxpack(mut map_data: R, root: &str, data: &mut StageData, ctx: &mut Context) -> GameResult { + pub fn load_pxpack( + mut map_data: R, + root: &str, + data: &mut StageData, + ctx: &mut Context, + ) -> GameResult { let mut magic = [0u8; 16]; map_data.read_exact(&mut magic)?; @@ -95,7 +100,7 @@ impl Map { } Ok(chars.iter().collect()) - }; + } fn skip_string(map_data: &mut R) -> GameResult { let bytes = map_data.read_u8()? as u32; @@ -104,7 +109,7 @@ impl Map { } Ok(()) - }; + } let map_name = read_string(&mut map_data)?; skip_string(&mut map_data)?; // left, right, up, down @@ -131,9 +136,15 @@ impl Map { map_data.read_u8()?; // ignored let scroll_bg = PxPackScroll::from(map_data.read_u8()?); - if tileset_fg == "" { tileset_fg = data.tileset.filename() } - if tileset_mg == "" { tileset_mg = data.tileset.filename() } - if tileset_bg == "" { tileset_bg = data.tileset.filename() } + if tileset_fg == "" { + tileset_fg = data.tileset.filename() + } + if tileset_mg == "" { + tileset_mg = data.tileset.filename() + } + if tileset_bg == "" { + tileset_bg = data.tileset.filename() + } let mut tiles = Vec::new(); let mut attrib = [0u8; 0x100]; @@ -189,7 +200,10 @@ impl Map { if size_bg != 0 { map_data.read_u8()?; tiles.resize(size_fg as usize + size_mg as usize + size_bg as usize, 0u8); - map_data.read_exact(&mut tiles[(size_fg as usize + size_mg as usize)..(size_fg as usize + size_mg as usize + size_bg as usize)])?; + map_data.read_exact( + &mut tiles + [(size_fg as usize + size_mg as usize)..(size_fg as usize + size_mg as usize + size_bg as usize)], + )?; } if let Ok(mut attrib_data) = filesystem::open(ctx, [root, "Stage/", &tileset_fg, ".pxa"].join("")) { @@ -250,7 +264,10 @@ impl Map { }; } } else { - log::warn!("No tile attribute data found for foreground tileset {}, collision might be broken.", tileset_fg); + log::warn!( + "No tile attribute data found for foreground tileset {}, collision might be broken.", + tileset_fg + ); } if map_name != "" { @@ -269,7 +286,7 @@ impl Map { size_mg: (width_mg, height_mg), size_bg: (width_bg, height_bg), offset_mg: size_fg, - offset_bg: size_fg + size_mg + offset_bg: size_fg + size_mg, }); Ok(Map { width: width_fg, height: height_fg, tiles, attrib, tile_size: TileSize::Tile8x8 }) diff --git a/src/physics.rs b/src/physics.rs index eaa2aa2..703413e 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -1,5 +1,3 @@ -use num_traits::clamp; - use crate::caret::CaretType; use crate::common::{Condition, Direction, Flag, Rect}; use crate::npc::list::NPCList; diff --git a/src/shared_game_state.rs b/src/shared_game_state.rs index 5342007..166d517 100644 --- a/src/shared_game_state.rs +++ b/src/shared_game_state.rs @@ -1,6 +1,5 @@ use std::ops::Div; -use bitvec::array::BitArray; use bitvec::vec::BitVec; use chrono::{Datelike, Local};