Add various refactorings (#48)
This commit is contained in:
parent
529a1c122d
commit
c8115df285
|
@ -546,18 +546,14 @@ impl<T> SliceExt for [T] {
|
|||
type Item = T;
|
||||
|
||||
fn get_two_mut(&mut self, a: usize, b: usize) -> Option<(&mut Self::Item, &mut Self::Item)> {
|
||||
if a == b {
|
||||
None
|
||||
} else {
|
||||
if a >= self.len() || b >= self.len() {
|
||||
None
|
||||
} else {
|
||||
unsafe {
|
||||
let ar = &mut *(self.get_unchecked_mut(a) as *mut _);
|
||||
let br = &mut *(self.get_unchecked_mut(b) as *mut _);
|
||||
Some((ar, br))
|
||||
}
|
||||
}
|
||||
if a == b || a >= self.len() || b >= self.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let ar = &mut *(self.get_unchecked_mut(a) as *mut _);
|
||||
let br = &mut *(self.get_unchecked_mut(b) as *mut _);
|
||||
Some((ar, br))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ impl GameEntity<()> for Credits {
|
|||
}
|
||||
|
||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "Casts")?;
|
||||
for line in state.creditscript_vm.lines.iter() {
|
||||
for line in &state.creditscript_vm.lines {
|
||||
let x = (line.cast_id % 13) * 24;
|
||||
let y = ((line.cast_id / 13) & 0xff) * 24;
|
||||
let rect = Rect::new_size(x, y, 24, 24);
|
||||
|
@ -69,7 +69,7 @@ impl GameEntity<()> for Credits {
|
|||
}
|
||||
batch.draw(ctx)?;
|
||||
|
||||
for line in state.creditscript_vm.lines.iter() {
|
||||
for line in &state.creditscript_vm.lines {
|
||||
state.font.draw_text_with_shadow(
|
||||
line.text.chars(),
|
||||
line.pos_x,
|
||||
|
|
|
@ -65,10 +65,7 @@ impl GameEntity<()> for NumberPopup {
|
|||
let x = interpolate_fix9_scale(self.prev_x, self.x, state.frame_time) - frame_x;
|
||||
let y = interpolate_fix9_scale(self.prev_y, self.y, state.frame_time) - frame_y - y_offset;
|
||||
|
||||
let mut n = self.value.to_string();
|
||||
if self.value > 0 {
|
||||
n = "+".to_owned() + n.as_str();
|
||||
};
|
||||
let n = format!("{:+}", self.value);
|
||||
|
||||
let x = x - n.len() as f32 * 4.0;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Tilemap {
|
|||
};
|
||||
|
||||
let (layer_offset, layer_width, layer_height, uses_layers) =
|
||||
if let Some(pxpack_data) = stage.data.pxpack_data.as_ref() {
|
||||
if let Some(pxpack_data) = &stage.data.pxpack_data {
|
||||
match layer {
|
||||
TileLayer::Background => {
|
||||
(pxpack_data.offset_bg as usize, pxpack_data.size_bg.0, pxpack_data.size_bg.1, true)
|
||||
|
@ -68,7 +68,7 @@ impl Tilemap {
|
|||
let mut rect = Rect::new(0, 0, tile_size as u16, tile_size as u16);
|
||||
let (mut frame_x, mut frame_y) = frame.xy_interpolated(state.frame_time);
|
||||
|
||||
if let Some(pxpack_data) = stage.data.pxpack_data.as_ref() {
|
||||
if let Some(pxpack_data) = &stage.data.pxpack_data {
|
||||
let (fx, fy) = match layer {
|
||||
TileLayer::Background => pxpack_data.scroll_bg.transform_camera_pos(frame_x, frame_y),
|
||||
TileLayer::Middleground => pxpack_data.scroll_mg.transform_camera_pos(frame_x, frame_y),
|
||||
|
|
|
@ -52,7 +52,7 @@ impl DynamicWater {
|
|||
}
|
||||
|
||||
pub fn tick(&mut self) {
|
||||
for col in self.columns.iter_mut() {
|
||||
for col in &mut self.columns {
|
||||
col.tick(DAMPENING, TENSION);
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ impl GameEntity<(&[&Player], &NPCList)> for WaterRenderer {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
for surf in self.water_surfaces.iter_mut() {
|
||||
for surf in &mut self.water_surfaces {
|
||||
let line_x = surf.x as f32 * 16.0;
|
||||
let line_y = surf.y as f32 * 16.0;
|
||||
|
||||
|
@ -143,7 +143,7 @@ impl GameEntity<(&[&Player], &NPCList)> for WaterRenderer {
|
|||
let col_idx_right = (col_idx_center + (obj.hit_bounds().left as i32 / (8 * 0x200)))
|
||||
.clamp(0, surf.columns.len() as i32) as usize;
|
||||
|
||||
for col in surf.columns[col_idx_left..=col_idx_right].iter_mut() {
|
||||
for col in &mut surf.columns[col_idx_left..=col_idx_right] {
|
||||
col.speed = (obj.vel_y() as f32 / 512.0) * (obj.hit_rect_size() as f32 * 0.25).clamp(0.1, 1.0);
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ impl GameEntity<(&[&Player], &NPCList)> for WaterRenderer {
|
|||
let water_color_top = Color::from_rgba(102, 153, 204, 150);
|
||||
let water_color = Color::from_rgba(102, 153, 204, 75);
|
||||
|
||||
for region in self.depth_regions.iter() {
|
||||
for region in &self.depth_regions {
|
||||
out_rect.left = ((region.left as f32 * 16.0 - o_x - 8.0) * state.scale) as isize;
|
||||
out_rect.top = ((region.top as f32 * 16.0 - o_y - 8.0) * state.scale) as isize;
|
||||
out_rect.right = ((region.right as f32 * 16.0 - o_x + 8.0) * state.scale) as isize;
|
||||
|
@ -183,7 +183,7 @@ impl GameEntity<(&[&Player], &NPCList)> for WaterRenderer {
|
|||
}
|
||||
|
||||
if !state.settings.shader_effects || !graphics::supports_vertex_draw(ctx)? {
|
||||
for region in self.surf_regions.iter() {
|
||||
for region in &self.surf_regions {
|
||||
out_rect.left = ((region.left as f32 * 16.0 - o_x - 8.0) * state.scale) as isize;
|
||||
out_rect.top = ((region.top as f32 * 16.0 - o_y - 5.0) * state.scale) as isize;
|
||||
out_rect.right = ((region.right as f32 * 16.0 - o_x + 8.0) * state.scale) as isize;
|
||||
|
@ -199,7 +199,7 @@ impl GameEntity<(&[&Player], &NPCList)> for WaterRenderer {
|
|||
let color_mid_rgba = water_color.to_rgba();
|
||||
let color_btm_rgba = water_color.to_rgba();
|
||||
|
||||
for surf in self.water_surfaces.iter() {
|
||||
for surf in &self.water_surfaces {
|
||||
let pos_x = surf.x as f32 * 16.0;
|
||||
let pos_y = surf.y as f32 * 16.0;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ impl GameEntity<(&Player, &mut BulletManager)> for WhimsicalStar {
|
|||
) -> GameResult {
|
||||
if !player.equip.has_whimsical_star() {
|
||||
return Ok(());
|
||||
} else if self.equipped == false && player.equip.has_whimsical_star() {
|
||||
} else if !self.equipped && player.equip.has_whimsical_star() {
|
||||
for iter in 0..2 {
|
||||
self.star[iter].x = player.x;
|
||||
self.star[iter].y = player.y;
|
||||
|
|
|
@ -191,7 +191,7 @@ impl BackendEventLoop for GlutinEventLoop {
|
|||
Event::WindowEvent { event: WindowEvent::Resized(size), window_id }
|
||||
if window_id == window.window().id() =>
|
||||
{
|
||||
if let Some(renderer) = ctx.renderer.as_ref() {
|
||||
if let Some(renderer) = &ctx.renderer {
|
||||
if let Ok(imgui) = renderer.imgui() {
|
||||
imgui.io_mut().display_size = [size.width as f32, size.height as f32];
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ pub struct SDL2Backend {
|
|||
|
||||
impl SDL2Backend {
|
||||
pub fn new(size_hint: (u16, u16)) -> GameResult<Box<dyn Backend>> {
|
||||
let context = sdl2::init().map_err(|e| GameError::WindowError(e))?;
|
||||
let context = sdl2::init().map_err(GameError::WindowError)?;
|
||||
|
||||
let backend = SDL2Backend { context, size_hint };
|
||||
|
||||
|
@ -69,8 +69,8 @@ struct SDL2Context {
|
|||
|
||||
impl SDL2EventLoop {
|
||||
pub fn new(sdl: &Sdl, size_hint: (u16, u16)) -> GameResult<Box<dyn BackendEventLoop>> {
|
||||
let event_pump = sdl.event_pump().map_err(|e| GameError::WindowError(e))?;
|
||||
let video = sdl.video().map_err(|e| GameError::WindowError(e))?;
|
||||
let event_pump = sdl.event_pump().map_err(GameError::WindowError)?;
|
||||
let video = sdl.video().map_err(GameError::WindowError)?;
|
||||
let gl_attr = video.gl_attr();
|
||||
|
||||
gl_attr.set_context_profile(GLProfile::Core);
|
||||
|
@ -177,7 +177,7 @@ impl BackendEventLoop for SDL2EventLoop {
|
|||
WindowEvent::SizeChanged(width, height) => {
|
||||
ctx.screen_size = (width.max(1) as f32, height.max(1) as f32);
|
||||
|
||||
if let Some(renderer) = ctx.renderer.as_ref() {
|
||||
if let Some(renderer) = &ctx.renderer {
|
||||
if let Ok(imgui) = renderer.imgui() {
|
||||
imgui.io_mut().display_size = [ctx.screen_size.0, ctx.screen_size.1];
|
||||
}
|
||||
|
@ -186,21 +186,17 @@ impl BackendEventLoop for SDL2EventLoop {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
Event::KeyDown { scancode, repeat, .. } => {
|
||||
if let Some(scancode) = scancode {
|
||||
if let Some(drs_scan) = conv_scancode(scancode) {
|
||||
if !repeat {
|
||||
state.process_debug_keys(drs_scan);
|
||||
}
|
||||
ctx.keyboard_context.set_key(drs_scan, true);
|
||||
Event::KeyDown { scancode: Some(scancode), repeat, .. } => {
|
||||
if let Some(drs_scan) = conv_scancode(scancode) {
|
||||
if !repeat {
|
||||
state.process_debug_keys(drs_scan);
|
||||
}
|
||||
ctx.keyboard_context.set_key(drs_scan, true);
|
||||
}
|
||||
}
|
||||
Event::KeyUp { scancode, .. } => {
|
||||
if let Some(scancode) = scancode {
|
||||
if let Some(drs_scan) = conv_scancode(scancode) {
|
||||
ctx.keyboard_context.set_key(drs_scan, false);
|
||||
}
|
||||
Event::KeyUp { scancode: Some(scancode), .. } => {
|
||||
if let Some(drs_scan) = conv_scancode(scancode) {
|
||||
ctx.keyboard_context.set_key(drs_scan, false);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -491,7 +487,7 @@ impl BackendRenderer for SDL2Renderer {
|
|||
.ok_or(RenderError("This texture was not created by OpenGL backend.".to_string()))?;
|
||||
|
||||
unsafe {
|
||||
if let Some(target) = sdl2_texture.texture.as_ref() {
|
||||
if let Some(target) = &sdl2_texture.texture {
|
||||
set_raw_target(renderer, target.raw())?;
|
||||
} else {
|
||||
set_raw_target(renderer, std::ptr::null_mut())?;
|
||||
|
@ -769,11 +765,11 @@ impl BackendTexture for SDL2Texture {
|
|||
}
|
||||
|
||||
fn draw(&mut self) -> GameResult {
|
||||
match self.texture.as_mut() {
|
||||
match &mut self.texture {
|
||||
None => Ok(()),
|
||||
Some(texture) => {
|
||||
let mut refs = self.refs.borrow_mut();
|
||||
for command in self.commands.iter() {
|
||||
for command in &self.commands {
|
||||
match command {
|
||||
SpriteBatchCommand::DrawRect(src, dest) => {
|
||||
texture.set_color_mod(255, 255, 255);
|
||||
|
|
|
@ -63,8 +63,8 @@ impl fmt::Display for GameError {
|
|||
|
||||
impl Error for GameError {
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
match *self {
|
||||
GameError::IOError(ref e) => Some(&**e),
|
||||
match self {
|
||||
GameError::IOError(e) => Some(e as &dyn Error),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ pub enum BlendMode {
|
|||
}
|
||||
|
||||
pub fn clear(ctx: &mut Context, color: Color) {
|
||||
if let Some(renderer) = ctx.renderer.as_mut() {
|
||||
if let Some(renderer) = &mut ctx.renderer {
|
||||
renderer.clear(color)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ impl BackendTexture for OpenGLTexture {
|
|||
|
||||
fn draw(&mut self) -> GameResult {
|
||||
unsafe {
|
||||
if let Some(gl) = GL_PROC.as_ref() {
|
||||
if let Some(gl) = &GL_PROC {
|
||||
if self.texture_id == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ impl Drop for OpenGLTexture {
|
|||
fn drop(&mut self) {
|
||||
if *self.context_active.as_ref().borrow() {
|
||||
unsafe {
|
||||
if let Some(gl) = GL_PROC.as_ref() {
|
||||
if let Some(gl) = &GL_PROC {
|
||||
if self.texture_id != 0 {
|
||||
let texture_id = &self.texture_id;
|
||||
gl.gl.DeleteTextures(1, texture_id as *const _);
|
||||
|
@ -564,7 +564,7 @@ static mut GL_PROC: Option<Gl> = None;
|
|||
|
||||
pub fn load_gl(gl_context: &mut GLContext) -> &'static Gl {
|
||||
unsafe {
|
||||
if let Some(gl) = GL_PROC.as_ref() {
|
||||
if let Some(gl) = &GL_PROC {
|
||||
return gl;
|
||||
}
|
||||
|
||||
|
@ -891,7 +891,7 @@ impl BackendRenderer for OpenGLRenderer {
|
|||
let gl_texture = texture
|
||||
.as_any()
|
||||
.downcast_ref::<OpenGLTexture>()
|
||||
.ok_or(RenderError("This texture was not created by OpenGL backend.".to_string()))?;
|
||||
.ok_or_else(|| RenderError("This texture was not created by OpenGL backend.".to_string()))?;
|
||||
|
||||
self.curr_matrix = [
|
||||
[2.0 / (gl_texture.width as f32), 0.0, 0.0, 0.0],
|
||||
|
@ -947,7 +947,7 @@ impl BackendRenderer for OpenGLRenderer {
|
|||
|
||||
fn draw_rect(&mut self, rect: Rect<isize>, color: Color) -> GameResult {
|
||||
unsafe {
|
||||
if let Some(gl) = GL_PROC.as_ref() {
|
||||
if let Some(gl) = &GL_PROC {
|
||||
let color = color.to_rgba();
|
||||
let mut uv = self.imgui_data.font_tex_size;
|
||||
uv.0 = 0.0 / uv.0;
|
||||
|
@ -1054,7 +1054,7 @@ impl BackendRenderer for OpenGLRenderer {
|
|||
let gl_texture = texture
|
||||
.as_any()
|
||||
.downcast_ref::<OpenGLTexture>()
|
||||
.ok_or(RenderError("This texture was not created by OpenGL backend.".to_string()))?;
|
||||
.ok_or_else(|| RenderError("This texture was not created by OpenGL backend.".to_string()))?;
|
||||
|
||||
Ok(TextureId::new(gl_texture.texture_id as usize))
|
||||
}
|
||||
|
@ -1213,7 +1213,7 @@ impl OpenGLRenderer {
|
|||
texture: Option<&Box<dyn BackendTexture>>,
|
||||
shader: BackendShader,
|
||||
) -> GameResult<()> {
|
||||
if vertices.len() == 0 {
|
||||
if vertices.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -1221,7 +1221,7 @@ impl OpenGLRenderer {
|
|||
let gl_texture = texture
|
||||
.as_any()
|
||||
.downcast_ref::<OpenGLTexture>()
|
||||
.ok_or(RenderError("This texture was not created by OpenGL backend.".to_string()))?;
|
||||
.ok_or_else(|| RenderError("This texture was not created by OpenGL backend.".to_string()))?;
|
||||
|
||||
gl_texture.texture_id
|
||||
} else {
|
||||
|
@ -1238,7 +1238,7 @@ impl OpenGLRenderer {
|
|||
texture: u32,
|
||||
shader: BackendShader,
|
||||
) -> GameResult<()> {
|
||||
if let Some(gl) = GL_PROC.as_ref() {
|
||||
if let Some(gl) = &GL_PROC {
|
||||
match shader {
|
||||
BackendShader::Fill => {
|
||||
gl.gl.UseProgram(self.imgui_data.program_fill);
|
||||
|
|
|
@ -246,16 +246,14 @@ impl PhysicalFS {
|
|||
}
|
||||
|
||||
if let Ok(entries) = root_path2.read_dir() {
|
||||
for entry in entries {
|
||||
if let Ok(entry) = entry {
|
||||
let name = entry.file_name();
|
||||
if name.to_ascii_lowercase() != node.to_ascii_lowercase() {
|
||||
continue;
|
||||
}
|
||||
|
||||
root_path2.push(name);
|
||||
continue 'citer;
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name();
|
||||
if name.to_ascii_lowercase() != node.to_ascii_lowercase() {
|
||||
continue;
|
||||
}
|
||||
|
||||
root_path2.push(name);
|
||||
continue 'citer;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ impl CombinedMenuController {
|
|||
}
|
||||
|
||||
pub fn update(&mut self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
|
||||
for cont in self.controllers.iter_mut() {
|
||||
for cont in &mut self.controllers {
|
||||
cont.update(state, ctx)?;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ impl CombinedMenuController {
|
|||
}
|
||||
|
||||
pub fn update_trigger(&mut self) {
|
||||
for cont in self.controllers.iter_mut() {
|
||||
for cont in &mut self.controllers {
|
||||
cont.update_trigger();
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ impl CombinedMenuController {
|
|||
}
|
||||
|
||||
pub fn trigger_up(&self) -> bool {
|
||||
for cont in self.controllers.iter() {
|
||||
for cont in &self.controllers {
|
||||
if cont.trigger_up() {
|
||||
return true;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ impl CombinedMenuController {
|
|||
}
|
||||
|
||||
pub fn trigger_down(&self) -> bool {
|
||||
for cont in self.controllers.iter() {
|
||||
for cont in &self.controllers {
|
||||
if cont.trigger_down() {
|
||||
return true;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ impl CombinedMenuController {
|
|||
}
|
||||
|
||||
pub fn trigger_left(&self) -> bool {
|
||||
for cont in self.controllers.iter() {
|
||||
for cont in &self.controllers {
|
||||
if cont.trigger_left() {
|
||||
return true;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ impl CombinedMenuController {
|
|||
}
|
||||
|
||||
pub fn trigger_right(&self) -> bool {
|
||||
for cont in self.controllers.iter() {
|
||||
for cont in &self.controllers {
|
||||
if cont.trigger_right() {
|
||||
return true;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ impl CombinedMenuController {
|
|||
}
|
||||
|
||||
pub fn trigger_ok(&self) -> bool {
|
||||
for cont in self.controllers.iter() {
|
||||
for cont in &self.controllers {
|
||||
if cont.trigger_menu_ok() {
|
||||
return true;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ impl CombinedMenuController {
|
|||
}
|
||||
|
||||
pub fn trigger_back(&self) -> bool {
|
||||
for cont in self.controllers.iter() {
|
||||
for cont in &self.controllers {
|
||||
if cont.trigger_menu_back() {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ impl TouchControls {
|
|||
}
|
||||
|
||||
pub fn point_in(&self, bounds: Rect) -> Option<u64> {
|
||||
for point in self.points.iter() {
|
||||
for point in &self.points {
|
||||
if (point.position.0 as isize) > bounds.left
|
||||
&& (point.position.0 as isize) < bounds.right
|
||||
&& (point.position.1 as isize) > bounds.top
|
||||
|
@ -56,7 +56,7 @@ impl TouchControls {
|
|||
pub fn consume_click_in(&mut self, bounds: Rect) -> bool {
|
||||
self.clicks.retain(|p| p.touch_id != 0);
|
||||
|
||||
for point in self.clicks.iter_mut() {
|
||||
for point in &mut self.clicks {
|
||||
if (point.position.0 as isize) > bounds.left
|
||||
&& (point.position.0 as isize) < bounds.right
|
||||
&& (point.position.1 as isize) > bounds.top
|
||||
|
|
|
@ -38,11 +38,8 @@ impl Inventory {
|
|||
pub fn add_item(&mut self, item_id: u16) {
|
||||
if !self.has_item(item_id) {
|
||||
self.items.push(Item(item_id, 1));
|
||||
} else {
|
||||
if let Some(item) = self.get_item(item_id) {
|
||||
item.1 += 1;
|
||||
return;
|
||||
}
|
||||
} else if let Some(item) = self.get_item(item_id) {
|
||||
item.1 += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,28 +270,28 @@ fn inventory_test() {
|
|||
let mut inventory = Inventory::new();
|
||||
|
||||
inventory.add_item(3);
|
||||
assert_eq!(inventory.has_item(2), false);
|
||||
assert_eq!(inventory.has_item(3), true);
|
||||
assert!(!inventory.has_item(2));
|
||||
assert!(inventory.has_item(3));
|
||||
|
||||
assert_eq!(inventory.has_item_amount(3, Ordering::Equal, 1), true);
|
||||
assert_eq!(inventory.has_item_amount(3, Ordering::Less, 2), true);
|
||||
assert!(inventory.has_item_amount(3, Ordering::Equal, 1));
|
||||
assert!(inventory.has_item_amount(3, Ordering::Less, 2));
|
||||
inventory.consume_item(3);
|
||||
|
||||
assert_eq!(inventory.has_item_amount(3, Ordering::Equal, 0), true);
|
||||
assert_eq!(inventory.has_item_amount(3, Ordering::Less, 2), true);
|
||||
assert!(inventory.has_item_amount(3, Ordering::Equal, 0));
|
||||
assert!(inventory.has_item_amount(3, Ordering::Less, 2));
|
||||
|
||||
inventory.add_item(2);
|
||||
assert_eq!(inventory.has_item(2), true);
|
||||
assert_eq!(inventory.has_item_amount(2, Ordering::Equal, 1), true);
|
||||
assert_eq!(inventory.has_item_amount(2, Ordering::Less, 1), false);
|
||||
assert!(inventory.has_item(2));
|
||||
assert!(inventory.has_item_amount(2, Ordering::Equal, 1));
|
||||
assert!(!inventory.has_item_amount(2, Ordering::Less, 1));
|
||||
|
||||
inventory.add_item(4);
|
||||
inventory.add_item(4);
|
||||
inventory.add_item(4);
|
||||
inventory.add_item(4);
|
||||
|
||||
assert_eq!(inventory.has_item(4), true);
|
||||
assert_eq!(inventory.has_item_amount(4, Ordering::Greater, 3), true);
|
||||
assert_eq!(inventory.has_item_amount(4, Ordering::Equal, 4), true);
|
||||
assert_eq!(inventory.has_item_amount(4, Ordering::Less, 2), false);
|
||||
assert!(inventory.has_item(4));
|
||||
assert!(inventory.has_item_amount(4, Ordering::Greater, 3));
|
||||
assert!(inventory.has_item_amount(4, Ordering::Equal, 4));
|
||||
assert!(!inventory.has_item_amount(4, Ordering::Less, 2));
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ impl Game {
|
|||
}
|
||||
|
||||
fn update(&mut self, ctx: &mut Context) -> GameResult {
|
||||
if let Some(scene) = self.scene.as_mut() {
|
||||
if let Some(scene) = &mut self.scene {
|
||||
let state_ref = unsafe { &mut *self.state.get() };
|
||||
|
||||
let speed =
|
||||
|
@ -179,7 +179,7 @@ impl Game {
|
|||
graphics::prepare_draw(ctx)?;
|
||||
graphics::clear(ctx, [0.0, 0.0, 0.0, 1.0].into());
|
||||
|
||||
if let Some(scene) = self.scene.as_mut() {
|
||||
if let Some(scene) = &mut self.scene {
|
||||
scene.draw(state_ref, ctx)?;
|
||||
if state_ref.settings.touch_controls {
|
||||
state_ref.touch_controls.draw(
|
||||
|
@ -270,7 +270,7 @@ pub fn init(options: LaunchOptions) -> GameResult {
|
|||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
if let Ok(_) = crate::framework::filesystem::open(&mut context, "/.drs_localstorage") {
|
||||
if crate::framework::filesystem::open(&context, "/.drs_localstorage").is_ok() {
|
||||
let mut user_dir = resource_dir.clone();
|
||||
user_dir.push("_drs_profile");
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ impl LiveDebugger {
|
|||
.size([240.0, 280.0], Condition::Appearing)
|
||||
.build(ui, || {
|
||||
if self.stages.is_empty() {
|
||||
for s in state.stages.iter() {
|
||||
for s in &state.stages {
|
||||
self.stages.push(ImString::new(s.name.to_owned()));
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ impl LiveDebugger {
|
|||
.position([80.0, 80.0], Condition::FirstUseEver)
|
||||
.size([280.0, 300.0], Condition::FirstUseEver)
|
||||
.build(ui, || {
|
||||
if CollapsingHeader::new("Control flags").default_open(false).build(&ui) {
|
||||
if CollapsingHeader::new("Control flags").default_open(false).build(ui) {
|
||||
ui.checkbox_flags("Tick world", &mut state.control_flags.0, 1);
|
||||
ui.checkbox_flags("Control enabled", &mut state.control_flags.0, 2);
|
||||
ui.checkbox_flags("Interactions disabled", &mut state.control_flags.0, 4);
|
||||
|
@ -310,11 +310,11 @@ impl LiveDebugger {
|
|||
ui.checkbox_flags("[Internal] Windy level", &mut state.control_flags.0, 15);
|
||||
}
|
||||
|
||||
if CollapsingHeader::new("Player condition flags").default_open(false).build(&ui) {
|
||||
cond_flags(&ui, &mut game_scene.player1.cond);
|
||||
if CollapsingHeader::new("Player condition flags").default_open(false).build(ui) {
|
||||
cond_flags(ui, &mut game_scene.player1.cond);
|
||||
}
|
||||
|
||||
if CollapsingHeader::new("Player equipment").default_open(false).build(&ui) {
|
||||
if CollapsingHeader::new("Player equipment").default_open(false).build(ui) {
|
||||
ui.checkbox_flags("Booster 0.8", &mut game_scene.player1.equip.0, 1);
|
||||
ui.checkbox_flags("Map System", &mut game_scene.player1.equip.0, 2);
|
||||
ui.checkbox_flags("Arms Barrier", &mut game_scene.player1.equip.0, 4);
|
||||
|
@ -338,7 +338,7 @@ impl LiveDebugger {
|
|||
for npc in game_scene.npc_list.iter_alive() {
|
||||
if CollapsingHeader::new(&ImString::from(format!("id={} type={}", npc.id, npc.npc_type)))
|
||||
.default_open(false)
|
||||
.build(&ui)
|
||||
.build(ui)
|
||||
{
|
||||
let mut position = [npc.x as f32 / 512.0, npc.y as f32 / 512.0];
|
||||
ui.input_float2("Position:", &mut position).build();
|
||||
|
@ -376,7 +376,7 @@ impl LiveDebugger {
|
|||
));
|
||||
ui.text_wrapped(content);
|
||||
|
||||
cond_flags(&ui, &mut npc.cond);
|
||||
cond_flags(ui, &mut npc.cond);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
23
src/map.rs
23
src/map.rs
|
@ -136,13 +136,13 @@ impl Map {
|
|||
map_data.read_u8()?; // ignored
|
||||
let scroll_bg = PxPackScroll::from(map_data.read_u8()?);
|
||||
|
||||
if tileset_fg == "" {
|
||||
if tileset_fg.is_empty() {
|
||||
tileset_fg = data.tileset.filename()
|
||||
}
|
||||
if tileset_mg == "" {
|
||||
if tileset_mg.is_empty() {
|
||||
tileset_mg = data.tileset.filename()
|
||||
}
|
||||
if tileset_bg == "" {
|
||||
if tileset_bg.is_empty() {
|
||||
tileset_bg = data.tileset.filename()
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ impl Map {
|
|||
log::warn!("Map attribute data is shorter than 256 bytes!");
|
||||
}
|
||||
|
||||
for attr in attrib.iter_mut() {
|
||||
for attr in &mut attrib {
|
||||
*attr = match *attr {
|
||||
1 | 45 => 0x41,
|
||||
2 | 66 => 0x44,
|
||||
|
@ -270,7 +270,7 @@ impl Map {
|
|||
);
|
||||
}
|
||||
|
||||
if map_name != "" {
|
||||
if !map_name.is_empty() {
|
||||
data.name = map_name;
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,7 @@ impl Map {
|
|||
return 0;
|
||||
}
|
||||
|
||||
self.attrib[*self.tiles.get(self.width as usize * y + x).unwrap_or_else(|| &0u8) as usize]
|
||||
self.attrib[*self.tiles.get(self.width as usize * y + x).unwrap_or(&0u8) as usize]
|
||||
}
|
||||
|
||||
pub fn find_water_regions(&self) -> Vec<(WaterRegionType, Rect<u16>)> {
|
||||
|
@ -325,8 +325,7 @@ impl Map {
|
|||
|
||||
walked[idx] = true;
|
||||
let mut rect = Rect::new(x, y, x, y);
|
||||
let mut queue = Vec::new();
|
||||
queue.push((0b1100, x, y));
|
||||
let mut queue = vec![(0b1100, x, y)];
|
||||
|
||||
while let Some((flow_flags, fx, fy)) = queue.pop() {
|
||||
let idx = self.width as usize * fy as usize + fx as usize;
|
||||
|
@ -521,7 +520,7 @@ impl WaterParams {
|
|||
}
|
||||
|
||||
pub fn load_from<R: io::Read>(&mut self, data: R) -> GameResult {
|
||||
fn next_u8(s: &mut std::str::Split<&str>, error_msg: &str) -> GameResult<u8> {
|
||||
fn next_u8<'a>(s: &mut impl Iterator<Item = &'a str>, error_msg: &str) -> GameResult<u8> {
|
||||
match s.next() {
|
||||
None => Err(GameError::ParseError("Out of range.".to_string())),
|
||||
Some(v) => v.trim().parse::<u8>().map_err(|_| GameError::ParseError(error_msg.to_string())),
|
||||
|
@ -531,7 +530,7 @@ impl WaterParams {
|
|||
for line in BufReader::new(data).lines() {
|
||||
match line {
|
||||
Ok(line) => {
|
||||
let mut splits = line.split(":");
|
||||
let mut splits = line.split(':');
|
||||
|
||||
if splits.clone().count() != 5 {
|
||||
return Err(GameError::ParseError("Invalid count of delimiters.".to_string()));
|
||||
|
@ -546,11 +545,11 @@ impl WaterParams {
|
|||
|
||||
let mut read_color = || -> GameResult<Color> {
|
||||
let cstr = splits.next().unwrap().trim();
|
||||
if !cstr.starts_with("[") || !cstr.ends_with("]") {
|
||||
if !cstr.starts_with('[') || !cstr.ends_with(']') {
|
||||
return Err(GameError::ParseError("Invalid format of color value.".to_string()));
|
||||
}
|
||||
|
||||
let mut csplits = cstr[1..cstr.len() - 1].split(",");
|
||||
let mut csplits = cstr[1..cstr.len() - 1].split(',');
|
||||
|
||||
if csplits.clone().count() != 4 {
|
||||
return Err(GameError::ParseError("Invalid count of delimiters.".to_string()));
|
||||
|
|
|
@ -98,7 +98,7 @@ impl Menu {
|
|||
pub fn update_height(&mut self) {
|
||||
let mut height = 6.0;
|
||||
|
||||
for entry in self.entries.iter() {
|
||||
for entry in &self.entries {
|
||||
height += entry.height();
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,7 @@ impl Menu {
|
|||
}
|
||||
|
||||
y = self.y as f32 + 6.0;
|
||||
for entry in self.entries.iter() {
|
||||
for entry in &self.entries {
|
||||
match entry {
|
||||
MenuEntry::Active(name) | MenuEntry::DisabledWhite(name) => {
|
||||
state.font.draw_text(
|
||||
|
@ -274,7 +274,7 @@ impl Menu {
|
|||
)?;
|
||||
}
|
||||
MenuEntry::Options(name, index, value) => {
|
||||
let value_text = if let Some(text) = value.get(*index) { text.as_str() } else { "???" };
|
||||
let value_text = if let Some(text) = value.get(*index) { text } else { "???" };
|
||||
let name_text_len = state.font.text_width(name.chars(), &state.constants);
|
||||
|
||||
state.font.draw_text(
|
||||
|
@ -296,8 +296,8 @@ impl Menu {
|
|||
)?;
|
||||
}
|
||||
MenuEntry::DescriptiveOptions(name, index, value, description) => {
|
||||
let value_text = if let Some(text) = value.get(*index) { text.as_str() } else { "???" };
|
||||
let description_text = if let Some(text) = description.get(*index) { text.as_str() } else { "???" };
|
||||
let value_text = if let Some(text) = value.get(*index) { text } else { "???" };
|
||||
let description_text = if let Some(text) = description.get(*index) { text } else { "???" };
|
||||
let name_text_len = state.font.text_width(name.chars(), &state.constants);
|
||||
|
||||
state.font.draw_text(
|
||||
|
|
|
@ -678,21 +678,19 @@ impl NPC {
|
|||
if self.action_counter > 80 {
|
||||
self.action_num = 10;
|
||||
self.action_counter = 0;
|
||||
} else if self.direction != Direction::Left {
|
||||
if self.action_counter == 50 {
|
||||
self.anim_num = 1;
|
||||
}
|
||||
if self.action_counter == 60 {
|
||||
self.anim_num = 0;
|
||||
}
|
||||
} else {
|
||||
if self.direction != Direction::Left {
|
||||
if self.action_counter == 50 {
|
||||
self.anim_num = 1;
|
||||
}
|
||||
if self.action_counter == 60 {
|
||||
self.anim_num = 0;
|
||||
}
|
||||
} else {
|
||||
if self.action_counter == 30 {
|
||||
self.anim_num = 1;
|
||||
}
|
||||
if self.action_counter == 40 {
|
||||
self.anim_num = 0;
|
||||
}
|
||||
if self.action_counter == 30 {
|
||||
self.anim_num = 1;
|
||||
}
|
||||
if self.action_counter == 40 {
|
||||
self.anim_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ impl NPC {
|
|||
self.action_num = 1;
|
||||
self.vel_x = 0;
|
||||
self.vel_y = 0;
|
||||
self.y = self.y + -0x1000;
|
||||
self.y += -0x1000;
|
||||
}
|
||||
|
||||
if !self.flags.hit_bottom_wall() {
|
||||
|
@ -24,7 +24,7 @@ impl NPC {
|
|||
self.anim_num = 0;
|
||||
}
|
||||
|
||||
self.vel_y = self.vel_y + 0x40;
|
||||
self.vel_y += 0x40;
|
||||
}
|
||||
10 | 11 => {
|
||||
if self.action_num == 10 {
|
||||
|
@ -34,15 +34,15 @@ impl NPC {
|
|||
self.action_counter3 = 0;
|
||||
}
|
||||
|
||||
self.anim_counter = self.anim_counter + 1;
|
||||
self.anim_counter += 1;
|
||||
if 6 < self.anim_counter {
|
||||
self.anim_counter = 0;
|
||||
self.anim_num = self.anim_num + 1;
|
||||
self.anim_num += 1;
|
||||
}
|
||||
|
||||
if 1 < self.anim_num {
|
||||
self.anim_num = 0;
|
||||
self.action_counter3 = self.action_counter3 + 1;
|
||||
self.action_counter3 += 1;
|
||||
}
|
||||
|
||||
if 8 < self.action_counter3 {
|
||||
|
@ -59,9 +59,9 @@ impl NPC {
|
|||
}
|
||||
|
||||
if self.y < self.target_y {
|
||||
self.vel_y = self.vel_y + 0x20;
|
||||
self.vel_y += 0x20;
|
||||
} else {
|
||||
self.vel_y = self.vel_y + -0x20;
|
||||
self.vel_y += -0x20;
|
||||
}
|
||||
|
||||
self.vel_y = self.vel_y.clamp(-0x200, 0x200);
|
||||
|
@ -91,7 +91,7 @@ impl NPC {
|
|||
state.sound_manager.play_sfx(0x1d);
|
||||
}
|
||||
self.anim_num = 2;
|
||||
self.action_counter = self.action_counter + 1;
|
||||
self.action_counter += 1;
|
||||
if 0x3f < self.action_counter {
|
||||
self.action_num = 0x14;
|
||||
}
|
||||
|
|
|
@ -868,10 +868,8 @@ impl NPC {
|
|||
&& self.y + 0xa000 > player.y
|
||||
{
|
||||
self.anim_num = 1;
|
||||
} else {
|
||||
if self.action_counter < 8 {
|
||||
self.action_counter += 1;
|
||||
}
|
||||
} else if self.action_counter < 8 {
|
||||
self.action_counter += 1;
|
||||
}
|
||||
|
||||
if self.shock > 0 {
|
||||
|
|
|
@ -685,7 +685,7 @@ impl NPC {
|
|||
pub(crate) fn tick_n096_fan_left(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
mut players: [&mut Player; 2],
|
||||
players: [&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
) -> GameResult {
|
||||
match self.action_num {
|
||||
|
@ -721,7 +721,7 @@ impl NPC {
|
|||
}
|
||||
}
|
||||
|
||||
for player in players.iter_mut() {
|
||||
for player in players {
|
||||
if !player.cond.alive() || player.cond.hidden() {
|
||||
continue;
|
||||
}
|
||||
|
@ -745,7 +745,7 @@ impl NPC {
|
|||
pub(crate) fn tick_n097_fan_up(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
mut players: [&mut Player; 2],
|
||||
players: [&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
) -> GameResult {
|
||||
match self.action_num {
|
||||
|
@ -781,7 +781,7 @@ impl NPC {
|
|||
}
|
||||
}
|
||||
|
||||
for player in players.iter_mut() {
|
||||
for player in players {
|
||||
if !player.cond.alive() || player.cond.hidden() {
|
||||
continue;
|
||||
}
|
||||
|
@ -804,7 +804,7 @@ impl NPC {
|
|||
pub(crate) fn tick_n098_fan_right(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
mut players: [&mut Player; 2],
|
||||
players: [&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
) -> GameResult {
|
||||
match self.action_num {
|
||||
|
@ -840,7 +840,7 @@ impl NPC {
|
|||
}
|
||||
}
|
||||
|
||||
for player in players.iter_mut() {
|
||||
for player in players {
|
||||
if (player.y - self.y).abs() < 0x1000 && player.x > self.x && player.x < self.x + 96 * 0x200 {
|
||||
player.vel_x += 0x88;
|
||||
player.cond.set_increase_acceleration(true);
|
||||
|
@ -860,7 +860,7 @@ impl NPC {
|
|||
pub(crate) fn tick_n099_fan_down(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
mut players: [&mut Player; 2],
|
||||
players: [&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
) -> GameResult {
|
||||
match self.action_num {
|
||||
|
@ -896,7 +896,7 @@ impl NPC {
|
|||
}
|
||||
}
|
||||
|
||||
for player in players.iter_mut() {
|
||||
for player in players {
|
||||
if (player.x - self.x).abs() < 0x1000 && player.y > self.y && player.y < self.y + 96 * 0x200 {
|
||||
player.vel_y += 0x88;
|
||||
}
|
||||
|
@ -963,7 +963,7 @@ impl NPC {
|
|||
10 => {
|
||||
self.animate(2, 2, 2);
|
||||
|
||||
for player in players.iter() {
|
||||
for player in players {
|
||||
if player.y > self.y {
|
||||
self.npc_flags.set_solid_hard(false);
|
||||
self.damage = 127;
|
||||
|
@ -1806,7 +1806,7 @@ impl NPC {
|
|||
self.y -= 0x800;
|
||||
}
|
||||
|
||||
for player in players.iter() {
|
||||
for player in players {
|
||||
if player.x < self.x + 0x1000
|
||||
&& player.x > self.x - 0x1000
|
||||
&& player.y > self.y + 0x1000
|
||||
|
@ -1826,7 +1826,7 @@ impl NPC {
|
|||
10 => {
|
||||
self.animate(2, 2, 2);
|
||||
|
||||
for player in players.iter() {
|
||||
for player in players {
|
||||
if player.y > self.y {
|
||||
self.npc_flags.set_solid_hard(false);
|
||||
self.damage = 127;
|
||||
|
|
|
@ -1311,12 +1311,10 @@ impl NPC {
|
|||
} else {
|
||||
self.action_counter2 = (self.action_counter2 + 1) & 0xff;
|
||||
}
|
||||
} else if direction - radians < std::f64::consts::PI {
|
||||
self.action_counter2 = (self.action_counter2 + 1) & 0xff;
|
||||
} else {
|
||||
if direction - radians < std::f64::consts::PI {
|
||||
self.action_counter2 = (self.action_counter2 + 1) & 0xff;
|
||||
} else {
|
||||
self.action_counter2 = self.action_counter2.wrapping_sub(1) & 0xff;
|
||||
}
|
||||
self.action_counter2 = self.action_counter2.wrapping_sub(1) & 0xff;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
|
|
@ -412,10 +412,8 @@ impl NPC {
|
|||
pub(crate) fn tick_n050_skeleton_projectile(&mut self, state: &mut SharedGameState) -> GameResult {
|
||||
match self.action_num {
|
||||
0 | 1 => {
|
||||
if self.action_num == 0 {
|
||||
if self.direction == Direction::Right {
|
||||
self.action_num = 2;
|
||||
}
|
||||
if self.action_num == 0 && self.direction == Direction::Right {
|
||||
self.action_num = 2;
|
||||
}
|
||||
|
||||
self.x += self.vel_x;
|
||||
|
@ -606,7 +604,7 @@ impl NPC {
|
|||
}
|
||||
|
||||
self.direction = parent.direction;
|
||||
self.anim_num = if angle < 0x14 || angle > 0x6c { 1 } else { 0 };
|
||||
self.anim_num = if !(0x14..=0x6c).contains(&angle) { 1 } else { 0 };
|
||||
|
||||
let dir_offset = if self.direction == Direction::Left { 0 } else { 2 };
|
||||
|
||||
|
@ -1164,7 +1162,7 @@ impl NPC {
|
|||
|
||||
// why
|
||||
self.npc_flags.set_interactable(false);
|
||||
for player in players.iter() {
|
||||
for player in players {
|
||||
if player.controller.trigger_down() {
|
||||
self.npc_flags.set_interactable(true);
|
||||
}
|
||||
|
|
|
@ -596,8 +596,8 @@ impl NPC {
|
|||
if 1 < self.action_num {
|
||||
if self.action_num == 10 {
|
||||
if (self.flags.0 & 0xf) == 0 {
|
||||
self.x = self.x + self.vel_x;
|
||||
self.y = self.y + self.vel_y;
|
||||
self.x += self.vel_x;
|
||||
self.y += self.vel_y;
|
||||
} else {
|
||||
self.action_num = 0x14;
|
||||
self.action_counter = 0;
|
||||
|
@ -617,9 +617,9 @@ impl NPC {
|
|||
}
|
||||
}
|
||||
} else if self.action_num == 0x14 {
|
||||
self.x = self.x + self.vel_x;
|
||||
self.y = self.y + self.vel_y;
|
||||
self.action_counter = self.action_counter + 1;
|
||||
self.x += self.vel_x;
|
||||
self.y += self.vel_y;
|
||||
self.action_counter += 1;
|
||||
if 4 < self.action_counter {
|
||||
let mut npc = NPC::create(4, &state.npc_table);
|
||||
npc.cond.set_alive(true);
|
||||
|
@ -676,7 +676,7 @@ impl NPC {
|
|||
}
|
||||
}
|
||||
|
||||
self.anim_num = self.anim_num + 1;
|
||||
self.anim_num += 1;
|
||||
if 1 < self.anim_num {
|
||||
self.anim_num = 0;
|
||||
}
|
||||
|
|
|
@ -790,7 +790,7 @@ impl NPC {
|
|||
self.npc_flags.set_ignore_solidity(false);
|
||||
self.npc_flags.set_shootable(false);
|
||||
self.damage = 0;
|
||||
self.action_counter2 = self.action_counter2 / 4;
|
||||
self.action_counter2 /= 4;
|
||||
self.exp = 0;
|
||||
}
|
||||
if self.action_counter2 > 0 {
|
||||
|
@ -1508,7 +1508,7 @@ impl BossNPC {
|
|||
let _ = npc_list.spawn(0x100, npc);
|
||||
}
|
||||
|
||||
if self.parts[0].flags.hit_bottom_wall() == true {
|
||||
if self.parts[0].flags.hit_bottom_wall() {
|
||||
self.parts[0].vel_y = -0x200;
|
||||
}
|
||||
}
|
||||
|
@ -1597,7 +1597,7 @@ impl BossNPC {
|
|||
let _ = npc_list.spawn(0x100, npc);
|
||||
}
|
||||
|
||||
if self.parts[0].flags.hit_bottom_wall() == true {
|
||||
if self.parts[0].flags.hit_bottom_wall() {
|
||||
self.parts[0].vel_y = -0x200;
|
||||
}
|
||||
}
|
||||
|
@ -2043,7 +2043,7 @@ impl BossNPC {
|
|||
part.y = base.y - 0x4800;
|
||||
|
||||
if part.action_num < 300 {
|
||||
part.npc_flags.set_shootable(if part.anim_num != 3 { false } else { true });
|
||||
part.npc_flags.set_shootable(part.anim_num == 3);
|
||||
}
|
||||
|
||||
let dir_offset = if part.direction == Direction::Left { 0 } else { 5 };
|
||||
|
|
|
@ -181,7 +181,7 @@ impl BossNPC {
|
|||
self.parts[7].x = self.parts[0].x - 0x6000;
|
||||
self.parts[7].y = self.parts[0].y + 0x4000;
|
||||
|
||||
for part in self.parts.iter_mut() {
|
||||
for part in &mut self.parts {
|
||||
part.prev_x = part.x;
|
||||
part.prev_y = part.y;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ impl BossNPC {
|
|||
let mut parts = unsafe {
|
||||
let mut parts_uninit: [NPC; 20] = MaybeUninit::uninit().assume_init();
|
||||
|
||||
for part in parts_uninit.iter_mut() {
|
||||
for part in &mut parts_uninit {
|
||||
*part = NPC::empty();
|
||||
part.cond.set_drs_boss(true);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager, &mut Fl
|
|||
_ => {}
|
||||
}
|
||||
|
||||
for part in self.parts.iter_mut() {
|
||||
for part in &mut self.parts {
|
||||
if part.shock > 0 {
|
||||
part.shock -= 1;
|
||||
}
|
||||
|
|
|
@ -46,12 +46,10 @@ impl NPC {
|
|||
} else {
|
||||
self.action_counter2 = (self.action_counter2 + 1) & 0xff;
|
||||
}
|
||||
} else if direction - radians < std::f64::consts::PI {
|
||||
self.action_counter2 = (self.action_counter2 + 1) & 0xff;
|
||||
} else {
|
||||
if direction - radians < std::f64::consts::PI {
|
||||
self.action_counter2 = (self.action_counter2 + 1) & 0xff;
|
||||
} else {
|
||||
self.action_counter2 = self.action_counter2.wrapping_sub(1) & 0xff;
|
||||
}
|
||||
self.action_counter2 = self.action_counter2.wrapping_sub(1) & 0xff;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -263,7 +261,7 @@ impl BossNPC {
|
|||
self.parts[16].display_bounds.left = 42 * 0x200;
|
||||
self.parts[16].display_bounds.right = 30 * 0x200;
|
||||
|
||||
for npc in self.parts.iter_mut() {
|
||||
for npc in &mut self.parts {
|
||||
npc.init_rng();
|
||||
}
|
||||
}
|
||||
|
@ -489,7 +487,7 @@ impl BossNPC {
|
|||
self.parts[0].action_counter += 1;
|
||||
|
||||
if self.parts[0].action_counter > 50 {
|
||||
for part in self.parts.iter_mut() {
|
||||
for part in &mut self.parts {
|
||||
part.cond.set_alive(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -366,7 +366,7 @@ impl BossNPC {
|
|||
self.parts[i].shock = self.parts[0].shock;
|
||||
}
|
||||
|
||||
for &i in [3, 4].iter() {
|
||||
for &i in &[3, 4] {
|
||||
match self.parts[i].action_num {
|
||||
0 | 1 => {
|
||||
if self.parts[i].action_num == 0 {
|
||||
|
@ -403,7 +403,7 @@ impl BossNPC {
|
|||
self.parts[i].anim_rect = state.constants.npc.b01_omega[6 + dir_offset + self.parts[i].anim_num as usize];
|
||||
}
|
||||
|
||||
for &i in [1, 2].iter() {
|
||||
for &i in &[1, 2] {
|
||||
self.parts[i].x = self.parts[0].x + self.parts[i].direction.vector_x() * 0x2000;
|
||||
self.parts[i].y = (self.parts[0].y + self.parts[i + 2].y - 0x1000) / 2;
|
||||
|
||||
|
|
|
@ -112,18 +112,16 @@ impl BossNPC {
|
|||
*actr2 -= 2;
|
||||
} else if self.parts[0].action_counter < self.parts[0].action_counter2 + 60 {
|
||||
*actr2 -= 1;
|
||||
} else if self.parts[0].life >= 300 {
|
||||
self.parts[0].action_counter = 0;
|
||||
self.parts[0].action_num = 100;
|
||||
*actr2 = self.parts[0].rng.range(400..700) as i16;
|
||||
} else {
|
||||
if self.parts[0].life >= 300 {
|
||||
self.parts[0].action_counter = 0;
|
||||
self.parts[0].action_num = 100;
|
||||
*actr2 = self.parts[0].rng.range(400..700) as i16;
|
||||
} else {
|
||||
self.parts[0].action_counter = 0;
|
||||
self.parts[0].action_num = 400;
|
||||
self.parts[2].action_num = 400;
|
||||
self.parts[4].action_num = 400;
|
||||
b = false;
|
||||
}
|
||||
self.parts[0].action_counter = 0;
|
||||
self.parts[0].action_num = 400;
|
||||
self.parts[2].action_num = 400;
|
||||
self.parts[4].action_num = 400;
|
||||
b = false;
|
||||
}
|
||||
|
||||
if b && *actr2 <= 0 {
|
||||
|
|
|
@ -24,7 +24,7 @@ impl NPCList {
|
|||
npcs: Box::new(UnsafeCell::new(unsafe {
|
||||
let mut parts_uninit: [NPC; NPC_LIST_MAX_CAP] = MaybeUninit::uninit().assume_init();
|
||||
|
||||
for part in parts_uninit.iter_mut() {
|
||||
for part in &mut parts_uninit {
|
||||
*part = NPC::empty();
|
||||
}
|
||||
|
||||
|
|
|
@ -819,46 +819,46 @@ impl NPCTable {
|
|||
});
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.npc_flags.0 = f.read_u16::<LE>()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.life = f.read_u16::<LE>()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.spritesheet_id = f.read_u8()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.death_sound = f.read_u8()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.hurt_sound = f.read_u8()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.size = f.read_u8()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.experience = f.read_u32::<LE>()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.damage = f.read_u32::<LE>()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.hit_bounds.left = f.read_u8()?;
|
||||
npc.hit_bounds.top = f.read_u8()?;
|
||||
npc.hit_bounds.right = f.read_u8()?;
|
||||
npc.hit_bounds.bottom = f.read_u8()?;
|
||||
}
|
||||
|
||||
for npc in table.entries.iter_mut() {
|
||||
for npc in &mut table.entries {
|
||||
npc.display_bounds.left = f.read_u8()?;
|
||||
npc.display_bounds.top = f.read_u8()?;
|
||||
npc.display_bounds.right = f.read_u8()?;
|
||||
|
|
|
@ -156,7 +156,7 @@ impl NPC {
|
|||
|
||||
/// Returns a reference to closest player.
|
||||
pub fn get_closest_player_ref<'a, 'b: 'a>(&self, players: &'a [&'a mut Player; 2]) -> &'b &'a mut Player {
|
||||
let idx = self.get_closest_player_idx_mut(&players);
|
||||
let idx = self.get_closest_player_idx_mut(players);
|
||||
|
||||
&players[idx]
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ impl Player {
|
|||
self.tick_npc_collision(id, state, npc, npc_list, inventory);
|
||||
}
|
||||
|
||||
for boss_npc in boss.parts.iter_mut() {
|
||||
for boss_npc in &mut boss.parts {
|
||||
if boss_npc.cond.alive() {
|
||||
self.tick_npc_collision(id, state, boss_npc, npc_list, inventory);
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ impl PlayerSkin for BasicPlayerSkin {
|
|||
}
|
||||
|
||||
fn get_skin_texture_name(&self) -> &str {
|
||||
self.texture_name.as_str()
|
||||
&self.texture_name
|
||||
}
|
||||
|
||||
fn get_mask_texture_name(&self) -> &str {
|
||||
|
|
|
@ -56,7 +56,7 @@ impl GameProfile {
|
|||
|
||||
game_scene.inventory_player1.current_weapon = self.current_weapon as u16;
|
||||
game_scene.inventory_player1.current_item = self.current_item as u16;
|
||||
for weapon in self.weapon_data.iter() {
|
||||
for weapon in &self.weapon_data {
|
||||
if weapon.weapon_id == 0 {
|
||||
continue;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ impl GameProfile {
|
|||
game_scene.inventory_player1.add_item(item as u16);
|
||||
}
|
||||
|
||||
for slot in self.teleporter_slots.iter() {
|
||||
for slot in &self.teleporter_slots {
|
||||
if slot.event_num == 0 {
|
||||
break;
|
||||
}
|
||||
|
@ -214,9 +214,9 @@ impl GameProfile {
|
|||
let mut flags = [0u8; 1000];
|
||||
for bits in state.game_flags.as_raw_slice() {
|
||||
let bytes = bits.to_le_bytes();
|
||||
for b in bytes.iter() {
|
||||
for b in bytes {
|
||||
if let Some(out) = flags.get_mut(bidx) {
|
||||
*out = *b;
|
||||
*out = b;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ impl GameProfile {
|
|||
data.write_u32::<LE>(self.control_mode)?;
|
||||
data.write_u32::<LE>(self.counter)?;
|
||||
|
||||
for weapon in self.weapon_data.iter() {
|
||||
for weapon in &self.weapon_data {
|
||||
data.write_u32::<LE>(weapon.weapon_id)?;
|
||||
data.write_u32::<LE>(weapon.level)?;
|
||||
data.write_u32::<LE>(weapon.exp)?;
|
||||
|
@ -276,7 +276,7 @@ impl GameProfile {
|
|||
data.write_u32::<LE>(item)?;
|
||||
}
|
||||
|
||||
for slot in self.teleporter_slots.iter() {
|
||||
for slot in &self.teleporter_slots {
|
||||
data.write_u32::<LE>(slot.index)?;
|
||||
data.write_u32::<LE>(slot.event_num)?;
|
||||
}
|
||||
|
@ -332,21 +332,21 @@ impl GameProfile {
|
|||
TeleporterSlotData { index: 0, event_num: 0 },
|
||||
];
|
||||
|
||||
for weap in weapon_data.iter_mut() {
|
||||
weap.weapon_id = data.read_u32::<LE>()?;
|
||||
weap.level = data.read_u32::<LE>()?;
|
||||
weap.exp = data.read_u32::<LE>()?;
|
||||
weap.max_ammo = data.read_u32::<LE>()?;
|
||||
weap.ammo = data.read_u32::<LE>()?;
|
||||
for WeaponData { weapon_id, level, exp, max_ammo, ammo } in &mut weapon_data {
|
||||
*weapon_id = data.read_u32::<LE>()?;
|
||||
*level = data.read_u32::<LE>()?;
|
||||
*exp = data.read_u32::<LE>()?;
|
||||
*max_ammo = data.read_u32::<LE>()?;
|
||||
*ammo = data.read_u32::<LE>()?;
|
||||
}
|
||||
|
||||
for item in items.iter_mut() {
|
||||
for item in &mut items {
|
||||
*item = data.read_u32::<LE>()?;
|
||||
}
|
||||
|
||||
for slot in teleporter_slots.iter_mut() {
|
||||
slot.index = data.read_u32::<LE>()?;
|
||||
slot.event_num = data.read_u32::<LE>()?;
|
||||
for TeleporterSlotData { index, event_num } in &mut teleporter_slots {
|
||||
*index = data.read_u32::<LE>()?;
|
||||
*event_num = data.read_u32::<LE>()?;
|
||||
}
|
||||
|
||||
let mut map_flags = [0u8; 0x80];
|
||||
|
|
|
@ -442,14 +442,13 @@ impl GameScene {
|
|||
|
||||
fn draw_light_map(&self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
|
||||
{
|
||||
let canvas = state.lightmap_canvas.as_mut();
|
||||
let maybe_canvas = state.lightmap_canvas.as_ref();
|
||||
|
||||
if let None = canvas {
|
||||
if maybe_canvas.is_some() {
|
||||
graphics::set_render_target(ctx, maybe_canvas)?;
|
||||
} else {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let canvas = canvas.unwrap();
|
||||
graphics::set_render_target(ctx, Some(canvas))?;
|
||||
}
|
||||
|
||||
graphics::set_blend_mode(ctx, BlendMode::Add)?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::common::{Color, Rect, VERSION_BANNER};
|
||||
use crate::common::{Color, VERSION_BANNER};
|
||||
use crate::components::background::Background;
|
||||
use crate::frame::Frame;
|
||||
use crate::framework::context::Context;
|
||||
|
@ -208,7 +208,7 @@ impl Scene for TitleScene {
|
|||
batch.draw(ctx)?;
|
||||
}
|
||||
|
||||
self.draw_text_centered(VERSION_BANNER.as_str(), state.canvas_size.1 - 15.0, state, ctx)?;
|
||||
self.draw_text_centered(&VERSION_BANNER, state.canvas_size.1 - 15.0, state, ctx)?;
|
||||
self.draw_text_centered(COPYRIGHT_PIXEL, state.canvas_size.1 - 30.0, state, ctx)?;
|
||||
|
||||
match self.current_menu {
|
||||
|
|
|
@ -476,7 +476,7 @@ impl Doukutsu {
|
|||
let lua_vfs_path = format!("@/Scripts/{}.lua", name);
|
||||
|
||||
fn raise_error(name: &str, state: &mut State, err: &str) {
|
||||
let error_msg = format!("module '{}' not found: {}", name, err.to_string());
|
||||
let error_msg = format!("module '{}' not found: {}", name, err);
|
||||
state.error(&error_msg);
|
||||
}
|
||||
|
||||
|
@ -538,7 +538,7 @@ impl LuaScriptingState {
|
|||
pub fn try_run_npc_hook(&mut self, npc_id: u16, npc_type: u16) -> bool {
|
||||
let mut result = false;
|
||||
|
||||
if let Some(state) = self.state.as_mut() {
|
||||
if let Some(state) = &mut self.state {
|
||||
state.get_global(DRS_RUNTIME_GLOBAL);
|
||||
state.get_field(-1, "_tryNPCHook");
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ impl LuaScriptingState {
|
|||
self.game_scene = game_scene;
|
||||
}
|
||||
|
||||
fn load_script(mut state: &mut State, path: &str, mut script: File) -> bool {
|
||||
fn load_script(state: &mut State, path: &str, mut script: File) -> bool {
|
||||
let mut buf = Vec::new();
|
||||
let res = script.read_to_end(&mut buf);
|
||||
|
||||
|
@ -85,7 +85,7 @@ impl LuaScriptingState {
|
|||
|
||||
let name = format!("@{}", path);
|
||||
let res = state.load_buffer(&buf, &name);
|
||||
let res = check_status(res, &mut state);
|
||||
let res = check_status(res, state);
|
||||
if let Err(err) = res {
|
||||
log::warn!("Error loading script {}: {}", path, err);
|
||||
return false;
|
||||
|
@ -130,7 +130,7 @@ impl LuaScriptingState {
|
|||
|
||||
match filesystem::open(ctx, file) {
|
||||
Ok(script) => {
|
||||
if LuaScriptingState::load_script(&mut state, path.to_string_lossy().as_ref(), script) {
|
||||
if LuaScriptingState::load_script(&mut state, &path.to_string_lossy(), script) {
|
||||
script_count += 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ impl LuaObject for LuaGameScene {
|
|||
|
||||
impl LuaScriptingState {
|
||||
pub fn scene_tick(&mut self) {
|
||||
if let Some(state) = self.state.as_mut() {
|
||||
if let Some(state) = &mut self.state {
|
||||
let val = LuaGameScene::new(self.game_scene);
|
||||
|
||||
state.get_global(DRS_RUNTIME_GLOBAL);
|
||||
|
|
|
@ -24,7 +24,7 @@ pub fn put_varint(val: i32, out: &mut Vec<u8>) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_cur_varint(cursor: &mut Cursor<&Vec<u8>>) -> GameResult<i32> {
|
||||
pub fn read_cur_varint(cursor: &mut Cursor<&[u8]>) -> GameResult<i32> {
|
||||
let mut result = 0u32;
|
||||
|
||||
for o in 0..5 {
|
||||
|
@ -59,7 +59,7 @@ pub fn read_varint<I: Iterator<Item = u8>>(iter: &mut I) -> GameResult<i32> {
|
|||
}
|
||||
|
||||
pub fn put_string(buffer: &mut Vec<u8>, out: &mut Vec<u8>, encoding: TextScriptEncoding) {
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ fn test_varint() {
|
|||
|
||||
let result = read_varint(&mut out.iter().copied()).unwrap();
|
||||
assert_eq!(result, n);
|
||||
let mut cur = Cursor::new(&out);
|
||||
let mut cur: Cursor<&[u8]> = Cursor::new(&out);
|
||||
let result = read_cur_varint(&mut cur).unwrap();
|
||||
assert_eq!(result, n);
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ impl TextScript {
|
|||
|
||||
let code = String::from_utf8_lossy(&n);
|
||||
|
||||
TextScript::compile_code(code.as_ref(), strict, iter, &mut bytecode)?;
|
||||
TextScript::compile_code(&code, strict, iter, &mut bytecode)?;
|
||||
}
|
||||
b'\r' => {
|
||||
iter.next();
|
||||
|
|
|
@ -89,7 +89,7 @@ impl CreditScriptVM {
|
|||
|
||||
pub fn run(state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
|
||||
if state.creditscript_vm.state != CreditScriptExecutionState::Ended {
|
||||
for line in state.creditscript_vm.lines.iter_mut() {
|
||||
for line in &mut state.creditscript_vm.lines {
|
||||
line.pos_y -= 0.5;
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ impl CreditScriptVM {
|
|||
break;
|
||||
}
|
||||
CreditScriptExecutionState::Running(ip) => {
|
||||
let mut cursor = Cursor::new(&state.creditscript_vm.script.bytecode);
|
||||
let mut cursor: Cursor<&[u8]> = Cursor::new(&state.creditscript_vm.script.bytecode);
|
||||
cursor.seek(SeekFrom::Start(ip as u64))?;
|
||||
|
||||
let op: CreditOpCode = if let Some(op) = FromPrimitive::from_i32(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::fmt::Write;
|
||||
use std::io::Cursor;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
|
@ -12,7 +13,7 @@ impl TextScript {
|
|||
pub fn decompile_event(&self, id: u16) -> GameResult<String> {
|
||||
if let Some(bytecode) = self.event_map.get(&id) {
|
||||
let mut result = String::new();
|
||||
let mut cursor = Cursor::new(bytecode);
|
||||
let mut cursor: Cursor<&[u8]> = Cursor::new(bytecode);
|
||||
|
||||
while let Ok(op_num) = read_cur_varint(&mut cursor) {
|
||||
let op_maybe: Option<TSCOpCode> = FromPrimitive::from_i32(op_num);
|
||||
|
@ -59,7 +60,7 @@ impl TextScript {
|
|||
| TSCOpCode::POP
|
||||
| TSCOpCode::KE2
|
||||
| TSCOpCode::FR2 => {
|
||||
result.push_str(format!("{:?}()\n", op).as_str());
|
||||
writeln!(&mut result, "{:?}()", op).unwrap();
|
||||
}
|
||||
// One operand codes
|
||||
TSCOpCode::BOA
|
||||
|
@ -105,7 +106,7 @@ impl TextScript {
|
|||
| TSCOpCode::PSH => {
|
||||
let par_a = read_cur_varint(&mut cursor)?;
|
||||
|
||||
result.push_str(format!("{:?}({})\n", op, par_a).as_str());
|
||||
writeln!(&mut result, "{:?}({})", op, par_a).unwrap();
|
||||
}
|
||||
// Two operand codes
|
||||
TSCOpCode::FON
|
||||
|
@ -124,7 +125,7 @@ impl TextScript {
|
|||
let par_a = read_cur_varint(&mut cursor)?;
|
||||
let par_b = read_cur_varint(&mut cursor)?;
|
||||
|
||||
result.push_str(format!("{:?}({}, {})\n", op, par_a, par_b).as_str());
|
||||
writeln!(&mut result, "{:?}({}, {})", op, par_a, par_b).unwrap();
|
||||
}
|
||||
// Three operand codes
|
||||
TSCOpCode::ANP | TSCOpCode::CNP | TSCOpCode::INP | TSCOpCode::TAM | TSCOpCode::CMP | TSCOpCode::INJ => {
|
||||
|
@ -132,7 +133,7 @@ impl TextScript {
|
|||
let par_b = read_cur_varint(&mut cursor)?;
|
||||
let par_c = read_cur_varint(&mut cursor)?;
|
||||
|
||||
result.push_str(format!("{:?}({}, {}, {})\n", op, par_a, par_b, par_c).as_str());
|
||||
writeln!(&mut result, "{:?}({}, {}, {})", op, par_a, par_b, par_c).unwrap();
|
||||
}
|
||||
// Four operand codes
|
||||
TSCOpCode::TRA | TSCOpCode::MNP | TSCOpCode::SNP => {
|
||||
|
@ -141,12 +142,12 @@ impl TextScript {
|
|||
let par_c = read_cur_varint(&mut cursor)?;
|
||||
let par_d = read_cur_varint(&mut cursor)?;
|
||||
|
||||
result.push_str(format!("{:?}({}, {}, {}, {})\n", op, par_a, par_b, par_c, par_d).as_str());
|
||||
writeln!(&mut result, "{:?}({}, {}, {}, {})", op, par_a, par_b, par_c, par_d).unwrap();
|
||||
}
|
||||
TSCOpCode::_STR => {
|
||||
let len = read_cur_varint(&mut cursor)?;
|
||||
|
||||
result.push_str(format!("%string(len = {}, value = \"", len).as_str());
|
||||
write!(&mut result, "%string(len = {}, value = \"", len).unwrap();
|
||||
for _ in 0..len {
|
||||
let chr = std::char::from_u32(read_cur_varint(&mut cursor)? as u32).unwrap_or('?');
|
||||
match chr {
|
||||
|
@ -160,7 +161,7 @@ impl TextScript {
|
|||
result.push_str("\\t");
|
||||
}
|
||||
'\u{0000}'..='\u{001f}' | '\u{0080}'..='\u{ffff}' => {
|
||||
result.push_str(chr.escape_unicode().to_string().as_str());
|
||||
result.push_str(&chr.escape_unicode().to_string());
|
||||
}
|
||||
_ => {
|
||||
result.push(chr);
|
||||
|
|
|
@ -324,7 +324,7 @@ impl TextScriptVM {
|
|||
}
|
||||
|
||||
if let Some((_, bytecode)) = cached_event {
|
||||
let mut cursor = Cursor::new(bytecode);
|
||||
let mut cursor: Cursor<&[u8]> = Cursor::new(bytecode);
|
||||
let mut new_line = false;
|
||||
cursor.seek(SeekFrom::Start(ip as u64))?;
|
||||
|
||||
|
@ -586,7 +586,7 @@ impl TextScriptVM {
|
|||
}
|
||||
|
||||
pub fn execute(
|
||||
bytecode: &Vec<u8>,
|
||||
bytecode: &[u8],
|
||||
event: u16,
|
||||
ip: u32,
|
||||
state: &mut SharedGameState,
|
||||
|
@ -1593,9 +1593,9 @@ impl TextScriptVM {
|
|||
state.textscript_vm.current_illustration = None;
|
||||
state.textscript_vm.illustration_state = IllustrationState::FadeIn(-160.0);
|
||||
|
||||
for path in state.constants.credit_illustration_paths.iter() {
|
||||
for path in &state.constants.credit_illustration_paths {
|
||||
let path = format!("{}Credit{:02}", path, number);
|
||||
if let Some(_) = state.texture_set.find_texture(ctx, &path) {
|
||||
if state.texture_set.find_texture(ctx, &path).is_some() {
|
||||
state.textscript_vm.current_illustration = Some(path);
|
||||
break;
|
||||
}
|
||||
|
@ -1605,7 +1605,7 @@ impl TextScriptVM {
|
|||
}
|
||||
TSCOpCode::CIL => {
|
||||
log::warn!("<CIL");
|
||||
state.textscript_vm.illustration_state = if let Some(_) = state.textscript_vm.current_illustration {
|
||||
state.textscript_vm.illustration_state = if state.textscript_vm.current_illustration.is_some() {
|
||||
IllustrationState::FadeOut(0.0)
|
||||
} else {
|
||||
IllustrationState::Hidden
|
||||
|
|
|
@ -280,7 +280,7 @@ impl SharedGameState {
|
|||
}
|
||||
|
||||
pub fn reload_textures(&mut self) {
|
||||
let mut texture_set = TextureSet::new(self.base_path.as_str());
|
||||
let mut texture_set = TextureSet::new(&self.base_path);
|
||||
|
||||
if self.constants.is_cs_plus {
|
||||
texture_set.apply_seasonal_content(self.season, &self.settings);
|
||||
|
@ -408,7 +408,7 @@ impl SharedGameState {
|
|||
}
|
||||
|
||||
pub fn tick_carets(&mut self) {
|
||||
for caret in self.carets.iter_mut() {
|
||||
for caret in &mut self.carets {
|
||||
caret.tick(&self.effect_rng, &self.constants);
|
||||
}
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ impl SoundManager {
|
|||
// we're sure that there's one element
|
||||
let path = unsafe { paths.get_unchecked(0) };
|
||||
|
||||
match filesystem::open(ctx, path).map(|f| organya::Song::load_from(f)) {
|
||||
match filesystem::open(ctx, path).map(organya::Song::load_from) {
|
||||
Ok(Ok(org)) => {
|
||||
log::info!("Playing Organya BGM: {} {}", song_id, path);
|
||||
|
||||
|
@ -304,32 +304,28 @@ impl SoundManager {
|
|||
let mut params = PixToneParameters::empty();
|
||||
|
||||
fn next_string<T: FromStr, R: io::Read>(reader: &mut Lines<BufReader<R>>) -> GameResult<T> {
|
||||
loop {
|
||||
if let Some(Ok(str)) = reader.next() {
|
||||
let str = str.trim();
|
||||
if str == "" || str.starts_with("#") {
|
||||
continue;
|
||||
}
|
||||
while let Some(Ok(str)) = reader.next() {
|
||||
let str = str.trim();
|
||||
if str.is_empty() || str.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut splits = str.split(":");
|
||||
let mut splits = str.split(':');
|
||||
|
||||
let _ = splits.next();
|
||||
if let Some(str) = splits.next() {
|
||||
return str.trim().parse::<T>().map_err(|_| {
|
||||
GameError::ParseError("failed to parse the value as specified type.".to_string())
|
||||
});
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
let _ = splits.next();
|
||||
if let Some(str) = splits.next() {
|
||||
return str.trim().parse::<T>().map_err(|_| {
|
||||
GameError::ParseError("failed to parse the value as specified type.".to_string())
|
||||
});
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Err(GameError::ParseError("unexpected end.".to_string()));
|
||||
Err(GameError::ParseError("unexpected end.".to_string()))
|
||||
}
|
||||
|
||||
for channel in params.channels.iter_mut() {
|
||||
for channel in &mut params.channels {
|
||||
channel.enabled = next_string::<u8, R>(&mut reader)? != 0;
|
||||
channel.length = next_string::<u32, R>(&mut reader)?;
|
||||
|
||||
|
@ -617,9 +613,7 @@ where
|
|||
pxt_index += 1;
|
||||
} else {
|
||||
pxt_index = 0;
|
||||
for i in pxt_buf.iter_mut() {
|
||||
*i = 0x8000
|
||||
}
|
||||
pxt_buf.fill(0x8000);
|
||||
pixtone.mix(&mut pxt_buf, sample_rate / speed);
|
||||
}
|
||||
|
||||
|
@ -671,10 +665,8 @@ where
|
|||
if let Err(e) = stream.pause() {
|
||||
log::error!("Failed to pause the stream: {:?}", e);
|
||||
}
|
||||
} else {
|
||||
if let Err(e) = stream.play() {
|
||||
log::error!("Failed to unpause the stream: {:?}", e);
|
||||
}
|
||||
} else if let Err(e) = stream.play() {
|
||||
log::error!("Failed to unpause the stream: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,12 +77,12 @@ impl OggPlaybackEngine {
|
|||
}
|
||||
|
||||
pub fn rewind(&mut self) {
|
||||
if let Some(music) = self.intro_music.as_ref() {
|
||||
if let Some(music) = &self.intro_music {
|
||||
let _ = music.write().unwrap().seek_absgp_pg(0);
|
||||
self.position = 0;
|
||||
self.playing_intro = true;
|
||||
} else {
|
||||
if let Some(music) = self.loop_music.as_ref() {
|
||||
if let Some(music) = &self.loop_music {
|
||||
let _ = music.write().unwrap().seek_absgp_pg(0);
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ impl OggPlaybackEngine {
|
|||
|
||||
fn decode(&mut self) {
|
||||
if self.playing_intro {
|
||||
if let Some(music) = self.intro_music.as_ref() {
|
||||
if let Some(music) = &self.intro_music {
|
||||
let mut music = music.write().unwrap();
|
||||
|
||||
let mut buf = match music.read_dec_packet_itl() {
|
||||
|
@ -119,35 +119,33 @@ impl OggPlaybackEngine {
|
|||
} else {
|
||||
self.playing_intro = false;
|
||||
}
|
||||
} else if let Some(music) = &self.loop_music {
|
||||
let mut music = music.write().unwrap();
|
||||
|
||||
let mut buf = match music.read_dec_packet_itl() {
|
||||
Ok(Some(buf)) => buf,
|
||||
Ok(None) => {
|
||||
if music.seek_absgp_pg(0).is_ok() {
|
||||
return;
|
||||
}
|
||||
|
||||
vec![0, 1000]
|
||||
}
|
||||
Err(_) => {
|
||||
vec![0, 1000]
|
||||
}
|
||||
};
|
||||
|
||||
self.position = music.get_last_absgp().unwrap_or(0);
|
||||
buf = self.resample_buffer(
|
||||
buf,
|
||||
music.ident_hdr.audio_sample_rate,
|
||||
music.ident_hdr.audio_channels,
|
||||
);
|
||||
self.buffer.append(&mut buf);
|
||||
} else {
|
||||
if let Some(music) = self.loop_music.as_ref() {
|
||||
let mut music = music.write().unwrap();
|
||||
|
||||
let mut buf = match music.read_dec_packet_itl() {
|
||||
Ok(Some(buf)) => buf,
|
||||
Ok(None) => {
|
||||
if let Err(_) = music.seek_absgp_pg(0) {
|
||||
vec![0, 1000]
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
vec![0, 1000]
|
||||
}
|
||||
};
|
||||
|
||||
self.position = music.get_last_absgp().unwrap_or(0);
|
||||
buf = self.resample_buffer(
|
||||
buf,
|
||||
music.ident_hdr.audio_sample_rate,
|
||||
music.ident_hdr.audio_channels,
|
||||
);
|
||||
self.buffer.append(&mut buf);
|
||||
} else {
|
||||
let mut buf = vec![0; 1000];
|
||||
self.buffer.append(&mut buf);
|
||||
}
|
||||
let mut buf = vec![0; 1000];
|
||||
self.buffer.append(&mut buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,9 +65,7 @@ impl OrgPlaybackEngine {
|
|||
pub fn new() -> Self {
|
||||
let mut buffers: [MaybeUninit<RenderBuffer>; 136] = unsafe { MaybeUninit::uninit().assume_init() };
|
||||
|
||||
for buffer in buffers.iter_mut() {
|
||||
*buffer = MaybeUninit::new(RenderBuffer::empty());
|
||||
}
|
||||
buffers.fill_with(|| MaybeUninit::new(RenderBuffer::empty()));
|
||||
|
||||
let song = Organya::empty();
|
||||
let frames_per_tick = (44100 / 1000) * song.time.wait as usize;
|
||||
|
@ -135,15 +133,9 @@ impl OrgPlaybackEngine {
|
|||
self.play_pos = 0;
|
||||
self.frames_per_tick = (self.output_format.sample_rate as usize / 1000) * self.song.time.wait as usize;
|
||||
self.frames_this_tick = 0;
|
||||
for i in self.lengths.iter_mut() {
|
||||
*i = 0
|
||||
}
|
||||
for i in self.swaps.iter_mut() {
|
||||
*i = 0
|
||||
}
|
||||
for i in self.keys.iter_mut() {
|
||||
*i = 255
|
||||
}
|
||||
self.lengths.fill(0);
|
||||
self.swaps.fill(0);
|
||||
self.keys.fill(255);
|
||||
}
|
||||
|
||||
pub fn set_position(&mut self, position: i32) {
|
||||
|
@ -249,15 +241,13 @@ impl OrgPlaybackEngine {
|
|||
}
|
||||
}
|
||||
|
||||
if self.lengths[track] == 0 {
|
||||
if self.keys[track] != 255 {
|
||||
let octave = (self.keys[track] / 12) * 8;
|
||||
let j = octave as usize + track + self.swaps[track];
|
||||
if self.song.tracks[track].inst.pipi == 0 {
|
||||
self.track_buffers[j].looping = false;
|
||||
}
|
||||
self.keys[track] = 255;
|
||||
if self.lengths[track] == 0 && self.keys[track] != 255 {
|
||||
let octave = (self.keys[track] / 12) * 8;
|
||||
let j = octave as usize + track + self.swaps[track];
|
||||
if self.song.tracks[track].inst.pipi == 0 {
|
||||
self.track_buffers[j].looping = false;
|
||||
}
|
||||
self.keys[track] = 255;
|
||||
}
|
||||
|
||||
self.lengths[track] = self.lengths[track].saturating_sub(1);
|
||||
|
@ -305,7 +295,7 @@ impl OrgPlaybackEngine {
|
|||
let freq = self.output_format.sample_rate as f64;
|
||||
|
||||
if self.interpolation == InterpolationMode::Polyphase {
|
||||
for buf in self.track_buffers.iter_mut() {
|
||||
for buf in &mut self.track_buffers {
|
||||
buf.fir.ensure_initialized();
|
||||
}
|
||||
}
|
||||
|
@ -315,7 +305,7 @@ impl OrgPlaybackEngine {
|
|||
self.update_play_state()
|
||||
}
|
||||
|
||||
for buf in self.track_buffers.iter_mut() {
|
||||
for buf in &mut self.track_buffers {
|
||||
if buf.playing {
|
||||
let is_16bit = buf.sample.format.bit_depth == 16;
|
||||
let is_stereo = buf.sample.format.channels == 2;
|
||||
|
|
|
@ -142,7 +142,7 @@ impl Song {
|
|||
Mu::uninit().assume_init()
|
||||
};
|
||||
|
||||
for i in insts.iter_mut() {
|
||||
for i in &mut insts {
|
||||
let freq = f.read_u16::<LE>()?;
|
||||
let inst = f.read_u8()?;
|
||||
let pipi = f.read_u8()?;
|
||||
|
@ -181,23 +181,23 @@ impl Song {
|
|||
vec![Mu::uninit().assume_init(); count]
|
||||
};
|
||||
|
||||
for note in notes.iter_mut() {
|
||||
for note in &mut notes {
|
||||
note.pos = Mu::new(f.read_i32::<LE>()?);
|
||||
}
|
||||
|
||||
for note in notes.iter_mut() {
|
||||
for note in &mut notes {
|
||||
note.key = Mu::new(f.read_u8()?);
|
||||
}
|
||||
|
||||
for note in notes.iter_mut() {
|
||||
for note in &mut notes {
|
||||
note.len = Mu::new(f.read_u8()?);
|
||||
}
|
||||
|
||||
for note in notes.iter_mut() {
|
||||
for note in &mut notes {
|
||||
note.vol = Mu::new(f.read_u8()?);
|
||||
}
|
||||
|
||||
for note in notes.iter_mut() {
|
||||
for note in &mut notes {
|
||||
note.pan = Mu::new(f.read_u8()?);
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ impl PixToneParameters {
|
|||
|
||||
let mut samples = vec![0i16; length];
|
||||
|
||||
for channel in self.channels.iter() {
|
||||
for channel in &self.channels {
|
||||
if !channel.enabled {
|
||||
continue;
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ impl PixTonePlayback {
|
|||
}
|
||||
|
||||
pub fn play_sfx(&mut self, id: u8) {
|
||||
for state in self.playback_state.iter_mut() {
|
||||
for state in &mut self.playback_state {
|
||||
if state.id == id && state.tag == 0 {
|
||||
state.pos = 0.0;
|
||||
state.looping = false;
|
||||
|
@ -230,7 +230,7 @@ impl PixTonePlayback {
|
|||
}
|
||||
|
||||
pub fn loop_sfx(&mut self, id: u8) {
|
||||
for state in self.playback_state.iter_mut() {
|
||||
for state in &mut self.playback_state {
|
||||
if state.id == id && state.tag == 0 {
|
||||
state.looping = true;
|
||||
return;
|
||||
|
|
|
@ -13,7 +13,7 @@ impl fmt::Display for SoundBank {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f, "WAVE100: {:2X?}...", &self.wave100[..8])?;
|
||||
|
||||
for sample in self.samples.iter() {
|
||||
for sample in &self.samples {
|
||||
writeln!(f, "{}", sample)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -613,7 +613,7 @@ impl StageTexturePaths {
|
|||
|
||||
pub fn update(&mut self, stage: &Stage) {
|
||||
self.background = stage.data.background.filename();
|
||||
let (tileset_fg, tileset_mg, tileset_bg) = if let Some(pxpack_data) = stage.data.pxpack_data.as_ref() {
|
||||
let (tileset_fg, tileset_mg, tileset_bg) = if let Some(pxpack_data) = &stage.data.pxpack_data {
|
||||
let t_fg = ["Stage/", &pxpack_data.tileset_fg].join("");
|
||||
let t_mg = ["Stage/", &pxpack_data.tileset_mg].join("");
|
||||
let t_bg = ["Stage/", &pxpack_data.tileset_bg].join("");
|
||||
|
|
|
@ -351,11 +351,7 @@ impl SpriteBatch for CombinedBatch {
|
|||
}
|
||||
|
||||
fn glow(&mut self) -> Option<&mut dyn SpriteBatch> {
|
||||
if let Some(batch) = self.glow_batch.as_mut() {
|
||||
Some(batch)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.glow_batch.as_mut().map(|batch| batch as &mut dyn SpriteBatch)
|
||||
}
|
||||
|
||||
fn to_rect(&self) -> Rect<usize> {
|
||||
|
@ -481,14 +477,14 @@ impl TextureSet {
|
|||
.find_texture(ctx, name)
|
||||
.ok_or_else(|| GameError::ResourceLoadError(format!("Texture {} does not exist.", name)))?;
|
||||
|
||||
let glow_path = self.find_texture(ctx, [name, ".glow"].join("").as_str());
|
||||
let glow_path = self.find_texture(ctx, &[name, ".glow"].join(""));
|
||||
|
||||
info!("Loading texture: {} -> {}", name, path);
|
||||
|
||||
fn make_batch(name: &str, constants: &EngineConstants, batch: Box<dyn BackendTexture>) -> SubBatch {
|
||||
let size = batch.dimensions();
|
||||
|
||||
let orig_dimensions = constants.tex_sizes.get(name).unwrap_or_else(|| &size);
|
||||
let orig_dimensions = constants.tex_sizes.get(name).unwrap_or(&size);
|
||||
let scale = orig_dimensions.0 as f32 / size.0 as f32;
|
||||
let width = (size.0 as f32 * scale) as _;
|
||||
let height = (size.1 as f32 * scale) as _;
|
||||
|
|
|
@ -69,7 +69,7 @@ impl BulletManager {
|
|||
bullet.tick_map_collisions(state, npc_list, stage);
|
||||
}
|
||||
|
||||
for bullet in self.new_bullets.iter_mut() {
|
||||
for bullet in &mut self.new_bullets {
|
||||
bullet.rng = Xoroshiro32PlusPlus::new(self.seeder.next_u32());
|
||||
}
|
||||
|
||||
|
|
|
@ -38,11 +38,9 @@ impl Weapon {
|
|||
WeaponLevel::None => unreachable!(),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if self.counter1 > 0 {
|
||||
shoot = true;
|
||||
self.counter1 = 0;
|
||||
}
|
||||
} else if self.counter1 > 0 {
|
||||
shoot = true;
|
||||
self.counter1 = 0;
|
||||
}
|
||||
|
||||
if let (_, _, true) = self.get_max_exp(&state.constants) {
|
||||
|
|
Loading…
Reference in New Issue