fix a bunch of warnings, inventory dimming

This commit is contained in:
Alula 2021-10-10 02:11:58 +02:00
parent 481f61a705
commit cd959f8f7c
No known key found for this signature in database
GPG Key ID: 3E00485503A1D8BA
21 changed files with 140 additions and 133 deletions

View File

@ -30,7 +30,6 @@ struct InvWeaponData {
pub struct InventoryUI {
tick: usize,
text_y_pos: u16,
current_script: u16,
selected_weapon: u16,
selected_item: u16,
weapon_count: u16,
@ -45,7 +44,6 @@ impl InventoryUI {
InventoryUI {
text_y_pos: 16,
tick: 0,
current_script: 0,
selected_weapon: 0,
selected_item: 0,
weapon_count: 0,
@ -336,7 +334,7 @@ impl GameEntity<(&mut Context, &mut Player, &mut Inventory)> for InventoryUI {
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "ItemImage")?;
for (idx, (item_id, amount)) in self.item_data.iter().enumerate() {
for (idx, (item_id, _amount)) in self.item_data.iter().enumerate() {
if *item_id == 0 {
break;
}
@ -355,8 +353,6 @@ impl GameEntity<(&mut Context, &mut Player, &mut Inventory)> for InventoryUI {
batch.draw(ctx)?;
let batch = (); // unbind batch to make borrow checker happy
for (idx, weapon) in self.weapon_data.iter().enumerate() {
if weapon.wtype == WeaponType::None {
break;

View File

@ -56,34 +56,34 @@ impl DynamicWater {
col.tick(DAMPENING, TENSION);
}
static mut l_deltas: Vec<f32> = Vec::new();
static mut r_deltas: Vec<f32> = Vec::new();
static mut L_DELTAS: Vec<f32> = Vec::new();
static mut R_DELTAS: Vec<f32> = Vec::new();
// we assume tick() is never called from other threads.
unsafe {
l_deltas.resize(self.columns.len(), 0.0);
r_deltas.resize(self.columns.len(), 0.0);
L_DELTAS.resize(self.columns.len(), 0.0);
R_DELTAS.resize(self.columns.len(), 0.0);
for _ in 0..2 {
for i in 0..self.columns.len() {
if i > 0 {
l_deltas[i] = SPREAD * (self.columns[i].height - self.columns[i - 1].height);
self.columns[i - 1].speed += l_deltas[i];
L_DELTAS[i] = SPREAD * (self.columns[i].height - self.columns[i - 1].height);
self.columns[i - 1].speed += L_DELTAS[i];
}
if i < self.columns.len() - 1 {
r_deltas[i] = SPREAD * (self.columns[i].height - self.columns[i + 1].height);
self.columns[i + 1].speed += r_deltas[i];
R_DELTAS[i] = SPREAD * (self.columns[i].height - self.columns[i + 1].height);
self.columns[i + 1].speed += R_DELTAS[i];
}
}
for i in 0..self.columns.len() {
if i > 0 {
self.columns[i - 1].height += l_deltas[i];
self.columns[i - 1].height += L_DELTAS[i];
}
if i < self.columns.len() - 1 {
self.columns[i + 1].height += r_deltas[i];
self.columns[i + 1].height += R_DELTAS[i];
}
}
}
@ -238,7 +238,7 @@ impl GameEntity<(&[&Player], &NPCList)> for WaterRenderer {
vertices.push(VertexData { position: (x_right, bottom), uv, color: color_btm_rgba });
}
graphics::draw_triangle_list(ctx, vertices, None, BackendShader::Fill);
graphics::draw_triangle_list(ctx, vertices, None, BackendShader::Fill)?;
}
Ok(())

View File

@ -1,3 +0,0 @@
struct DifficultyModifier {
}

View File

@ -1531,7 +1531,7 @@ impl EngineConstants {
],
};
sound_manager.set_sample_params(2, typewriter_sample);
let _ = sound_manager.set_sample_params(2, typewriter_sample);
}
pub fn apply_csplus_nx_patches(&mut self) {

View File

@ -1,13 +1,17 @@
use crate::framework::backend::{Backend, BackendEventLoop, BackendRenderer, BackendTexture, SpriteBatchCommand, VertexData, BackendShader};
use crate::framework::error::GameResult;
use crate::framework::context::Context;
use crate::Game;
use crate::common::{Rect, Color};
use imgui::{DrawData};
use crate::framework::graphics::BlendMode;
use std::cell::RefCell;
use std::mem;
use imgui::DrawData;
use crate::common::{Color, Rect};
use crate::framework::backend::{
Backend, BackendEventLoop, BackendRenderer, BackendShader, BackendTexture, SpriteBatchCommand, VertexData,
};
use crate::framework::context::Context;
use crate::framework::error::GameResult;
use crate::framework::graphics::BlendMode;
use crate::Game;
pub struct NullBackend;
impl NullBackend {
@ -33,10 +37,12 @@ impl BackendEventLoop for NullEventLoop {
loop {
game.update(ctx).unwrap();
if state_ref.shutdown {
log::info!("Shutting down...");
break;
}
if state_ref.next_scene.is_some() {
mem::swap(&mut game.scene, &mut state_ref.next_scene);
state_ref.next_scene = None;
@ -66,13 +72,9 @@ impl BackendTexture for NullTexture {
(self.0, self.1)
}
fn add(&mut self, _command: SpriteBatchCommand) {
fn add(&mut self, _command: SpriteBatchCommand) {}
}
fn clear(&mut self) {
}
fn clear(&mut self) {}
fn draw(&mut self) -> GameResult<()> {
Ok(())
@ -86,9 +88,7 @@ impl BackendRenderer for NullRenderer {
"Null".to_owned()
}
fn clear(&mut self, _color: Color) {
}
fn clear(&mut self, _color: Color) {}
fn present(&mut self) -> GameResult {
Ok(())
@ -126,7 +126,12 @@ impl BackendRenderer for NullRenderer {
Ok(())
}
fn draw_triangle_list(&mut self, vertices: Vec<VertexData>, texture: Option<&Box<dyn BackendTexture>>, shader: BackendShader) -> GameResult<()> {
fn draw_triangle_list(
&mut self,
_vertices: Vec<VertexData>,
_texture: Option<&Box<dyn BackendTexture>>,
_shader: BackendShader,
) -> GameResult<()> {
Ok(())
}
}

View File

@ -12,8 +12,8 @@ use sdl2::keyboard::Scancode;
use sdl2::mouse::{Cursor, SystemCursor};
use sdl2::pixels::PixelFormatEnum;
use sdl2::render::{Texture, TextureCreator, WindowCanvas};
use sdl2::video::WindowContext;
use sdl2::video::GLProfile;
use sdl2::video::WindowContext;
use sdl2::{keyboard, pixels, EventPump, Sdl, VideoSubsystem};
use crate::common::{Color, Rect};
@ -68,7 +68,7 @@ impl SDL2EventLoop {
let event_pump = sdl.event_pump().map_err(|e| GameError::WindowError(e))?;
let video = sdl.video().map_err(|e| GameError::WindowError(e))?;
let gl_attr = video.gl_attr();
gl_attr.set_context_profile(GLProfile::Core);
gl_attr.set_context_version(3, 0);
@ -77,10 +77,9 @@ impl SDL2EventLoop {
window.resizable();
#[cfg(feature = "render-opengl")]
window.opengl();
window.opengl();
let window = window.build()
.map_err(|e| GameError::WindowError(e.to_string()))?;
let window = window.build().map_err(|e| GameError::WindowError(e.to_string()))?;
let canvas = window
.into_canvas()
@ -127,7 +126,6 @@ impl BackendEventLoop for SDL2EventLoop {
}
loop {
#[cfg(target_os = "macos")]
unsafe {
use objc::*;
@ -148,7 +146,7 @@ impl BackendEventLoop for SDL2EventLoop {
style_mask |= 1 << 15; // NSWindowStyleMaskFullSizeContentView
let _: () = msg_send![window, setStyleMask:style_mask];
let _: () = msg_send![window, setStyleMask: style_mask];
}
}
@ -244,7 +242,7 @@ impl BackendEventLoop for SDL2EventLoop {
let mut refs = self.refs.borrow_mut();
match refs.canvas.window().gl_create_context() {
Ok(gl_ctx) => {
refs.canvas.window().gl_make_current(&gl_ctx);
refs.canvas.window().gl_make_current(&gl_ctx).map_err(|e| GameError::RenderError(e.to_string()))?;
refs.gl_context = Some(gl_ctx);
}
Err(err) => {
@ -256,7 +254,7 @@ impl BackendEventLoop for SDL2EventLoop {
#[cfg(feature = "render-opengl")]
if *self.opengl_available.borrow() {
let mut imgui = init_imgui()?;
let imgui = init_imgui()?;
let refs = self.refs.clone();
@ -426,7 +424,7 @@ impl BackendRenderer for SDL2Renderer {
fn prepare_draw(&mut self, width: f32, height: f32) -> GameResult {
let mut refs = self.refs.borrow_mut();
refs.canvas.set_clip_rect(Some(sdl2::rect::Rect::new(0, 0, width as u32, height as u32, )));
refs.canvas.set_clip_rect(Some(sdl2::rect::Rect::new(0, 0, width as u32, height as u32)));
//refs.canvas.set_clip_rect(None);
Ok(())
@ -702,9 +700,9 @@ impl BackendRenderer for SDL2Renderer {
fn draw_triangle_list(
&mut self,
vertices: Vec<VertexData>,
texture: Option<&Box<dyn BackendTexture>>,
shader: BackendShader,
_vertices: Vec<VertexData>,
_texture: Option<&Box<dyn BackendTexture>>,
_shader: BackendShader,
) -> GameResult<()> {
Err(GameError::RenderError("Unsupported operation".to_string()))
}

View File

@ -65,6 +65,7 @@ impl io::Seek for File {
}
}
#[allow(unused)]
impl Filesystem {
pub fn new() -> Filesystem {
// Set up VFS to merge resource path, root path, and zip path.

View File

@ -36,6 +36,7 @@ pub fn present(ctx: &mut Context) -> GameResult {
Ok(())
}
#[allow(unused)]
pub fn renderer_initialized(ctx: &mut Context) -> bool {
ctx.renderer.is_some()
}
@ -60,6 +61,7 @@ pub fn screen_size(ctx: &mut Context) -> (f32, f32) {
ctx.screen_size
}
#[allow(unused)]
pub fn screen_insets(ctx: &mut Context) -> (f32, f32, f32, f32) {
ctx.screen_insets
}
@ -92,6 +94,7 @@ pub fn draw_rect(ctx: &mut Context, rect: Rect, color: Color) -> GameResult {
Err(GameError::RenderError("Rendering backend hasn't been initialized yet.".to_string()))
}
#[allow(unused)]
pub fn draw_outline_rect(ctx: &mut Context, rect: Rect, line_width: usize, color: Color) -> GameResult {
if let Some(renderer) = ctx.renderer.as_mut() {
return renderer.draw_outline_rect(rect, line_width, color);

View File

@ -215,6 +215,7 @@ pub enum ScanCode {
bitfield! {
/// Bitflags describing the state of keyboard modifiers, such as `Control` or `Shift`.
#[derive(Debug, Copy, Clone)]
#[allow(unused)]
pub struct KeyMods(u8);
/// No modifiers; equivalent to `KeyMods::default()` and

View File

@ -914,7 +914,7 @@ impl BackendRenderer for OpenGLRenderer {
}
}
fn draw_outline_rect(&mut self, rect: Rect<isize>, line_width: usize, color: Color) -> GameResult {
fn draw_outline_rect(&mut self, _rect: Rect<isize>, _line_width: usize, _color: Color) -> GameResult {
Ok(())
}

View File

@ -107,7 +107,7 @@ pub fn init_imgui() -> GameResult<imgui::Context> {
}
impl UI {
pub fn new(ctx: &mut Context) -> GameResult<Self> {
pub fn new(_ctx: &mut Context) -> GameResult<Self> {
Ok(Self {
components: Components {
live_debugger: LiveDebugger::new(),

View File

@ -45,6 +45,7 @@ pub struct OpenOptions {
pub truncate: bool,
}
#[allow(unused)]
impl OpenOptions {
/// Create a new instance
pub fn new() -> OpenOptions {

View File

@ -17,21 +17,22 @@ pub struct TouchPlayerController {
}
bitfield! {
#[derive(Clone, Copy)]
pub struct KeyState(u16);
impl Debug;
#[allow(unused)]
#[derive(Clone, Copy)]
pub struct KeyState(u16);
impl Debug;
pub left, set_left: 0;
pub right, set_right: 1;
pub up, set_up: 2;
pub down, set_down: 3;
pub map, set_map: 4;
pub inventory, set_inventory: 5;
pub jump, set_jump: 6;
pub shoot, set_shoot: 7;
pub next_weapon, set_next_weapon: 8;
pub prev_weapon, set_prev_weapon: 9;
pub pause, set_pause: 10;
pub left, set_left: 0;
pub right, set_right: 1;
pub up, set_up: 2;
pub down, set_down: 3;
pub map, set_map: 4;
pub inventory, set_inventory: 5;
pub jump, set_jump: 6;
pub shoot, set_shoot: 7;
pub next_weapon, set_next_weapon: 8;
pub prev_weapon, set_prev_weapon: 9;
pub pause, set_pause: 10;
}
impl TouchPlayerController {
@ -58,7 +59,7 @@ impl PlayerController for TouchPlayerController {
}
}
TouchControlType::Controls => {
let (left, top, right, bottom) = screen_insets_scaled(ctx, state.scale);
let (left, _top, right, bottom) = screen_insets_scaled(ctx, state.scale);
let left = 4 + left as isize;
let top = 4 + bottom as isize;
@ -183,9 +184,7 @@ impl PlayerController for TouchPlayerController {
self.state.set_inventory(
self.state.inventory()
|| state
.touch_controls
.consume_click_in(Rect::new_size(
|| state.touch_controls.consume_click_in(Rect::new_size(
state.canvas_size.0 as isize - 48 - right,
top,
48,

View File

@ -34,7 +34,6 @@ mod builtin_fs;
mod caret;
mod common;
mod components;
mod difficulty_modifier;
mod encoding;
mod engine_constants;
mod entity;

View File

@ -1458,7 +1458,7 @@ impl NPC {
npc.vel_x = self.rng.range(-8..-2) * 0x200;
npc.vel_y = self.rng.range(-3..3) * 0x200;
npc_list.spawn(0x100, npc.clone());
let _ = npc_list.spawn(0x100, npc.clone());
}
state.sound_manager.play_sfx(72);

View File

@ -442,10 +442,10 @@ impl BossNPC {
self.tick_b04_core_small_head(3, state, &players, npc_list, stage);
self.tick_b04_core_small_head(6, state, &players, npc_list, stage);
self.tick_b04_core_small_head(7, state, &players, npc_list, stage);
self.tick_b04_core_hitbox(8, state);
self.tick_b04_core_hitbox(9, state);
self.tick_b04_core_hitbox(10, state);
self.tick_b04_core_hitbox(11, state);
self.tick_b04_core_hitbox(8);
self.tick_b04_core_hitbox(9);
self.tick_b04_core_hitbox(10);
self.tick_b04_core_hitbox(11);
}
fn tick_b04_core_face(&mut self, i: usize, state: &mut SharedGameState) {
@ -652,7 +652,7 @@ impl BossNPC {
part.anim_rect = state.constants.npc.b04_core[7 + part.anim_num as usize];
}
fn tick_b04_core_hitbox(&mut self, i: usize, state: &mut SharedGameState) {
fn tick_b04_core_hitbox(&mut self, i: usize) {
let (head, tail) = self.parts.split_at_mut(i);
let base = &mut head[0];
let part = &mut tail[0];

View File

@ -197,6 +197,7 @@ impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &mut BulletManager, &mu
&mut Flash,
),
) -> GameResult {
#[allow(unused_assignments)]
let mut npc_hook_ran = false;
#[cfg(feature = "scripting")]
{

View File

@ -5,11 +5,12 @@ pub mod basic;
pub mod pxchar;
bitfield! {
#[derive(Clone, Copy)]
pub struct PlayerSkinFlags(u16);
impl Debug;
#[derive(Clone, Copy)]
#[allow(unused)]
pub struct PlayerSkinFlags(u16);
impl Debug;
pub supports_color, set_supports_color: 0;
pub supports_color, set_supports_color: 0;
}
#[derive(Clone, Copy, PartialEq, Eq)]

View File

@ -76,7 +76,6 @@ pub enum TileLayer {
Snack,
}
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum LightingMode {
None,
@ -1291,18 +1290,8 @@ impl GameScene {
if layer == TileLayer::Foreground && self.stage.data.background_type == BackgroundType::Water {
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, &self.tex_background_name)?;
let rect_top = Rect {
left: 0,
top: 0,
right: 32,
bottom: 16
};
let rect_middle = Rect {
left: 0,
top: 16,
right: 32,
bottom: 48
};
let rect_top = Rect { left: 0, top: 0, right: 32, bottom: 16 };
let rect_middle = Rect { left: 0, top: 16, right: 32, bottom: 48 };
let tile_start_x = frame_x as i32 / 32;
let tile_end_x = (frame_x + 16.0 + state.canvas_size.0) as i32 / 32 + 1;
@ -1310,18 +1299,10 @@ impl GameScene {
let tile_count_y = (frame_y + 16.0 + state.canvas_size.1 - water_y) as i32 / 32 + 1;
for x in tile_start_x..tile_end_x {
batch.add_rect(
(x as f32 * 32.0) - frame_x,
water_y - frame_y,
&rect_top,
);
batch.add_rect((x as f32 * 32.0) - frame_x, water_y - frame_y, &rect_top);
for y in 0..tile_count_y {
batch.add_rect(
(x as f32 * 32.0) - frame_x,
(y as f32 * 32.0) + water_y - frame_y,
&rect_middle,
);
batch.add_rect((x as f32 * 32.0) - frame_x, (y as f32 * 32.0) + water_y - frame_y, &rect_middle);
}
}
@ -1833,15 +1814,26 @@ impl Scene for GameScene {
self.lighting_mode = match () {
_ if self.intro_mode => LightingMode::None,
_ if !state.constants.is_switch && (self.stage.data.background_type == BackgroundType::Black
|| self.stage.data.background.name() == "bkBlack") => LightingMode::Ambient,
_ if state.constants.is_switch && (self.stage.data.background_type == BackgroundType::Black
|| self.stage.data.background.name() == "bkBlack") => LightingMode::None,
_ if !state.constants.is_switch
&& (self.stage.data.background_type == BackgroundType::Black
|| self.stage.data.background.name() == "bkBlack") =>
{
LightingMode::Ambient
}
_ if state.constants.is_switch
&& (self.stage.data.background_type == BackgroundType::Black
|| self.stage.data.background.name() == "bkBlack") =>
{
LightingMode::None
}
_ if self.stage.data.background.name() == "bkFall" => LightingMode::None,
_ if self.stage.data.background_type != BackgroundType::Black
&& self.stage.data.background_type != BackgroundType::Outside
&& self.stage.data.background_type != BackgroundType::OutsideWind
&& self.stage.data.background.name() != "bkBlack" => LightingMode::BackgroundOnly,
&& self.stage.data.background.name() != "bkBlack" =>
{
LightingMode::BackgroundOnly
}
_ => LightingMode::None,
};
@ -1900,15 +1892,24 @@ impl Scene for GameScene {
}
for _ in 0..ticks {
TextScriptVM::run(state, self, ctx)?;
match state.textscript_vm.mode {
ScriptMode::Map if state.control_flags.tick_world() => self.tick_world(state)?,
ScriptMode::StageSelect => self.stage_select.tick(state, (ctx, &self.player1, &self.player2))?,
ScriptMode::Inventory => {
self.inventory_ui.tick(state, (ctx, &mut self.player1, &mut self.inventory_player1))?
ScriptMode::Map => {
TextScriptVM::run(state, self, ctx)?;
if state.control_flags.tick_world() {
self.tick_world(state)?;
}
}
ScriptMode::StageSelect => {
self.stage_select.tick(state, (ctx, &self.player1, &self.player2))?;
TextScriptVM::run(state, self, ctx)?;
}
ScriptMode::Inventory => {
self.inventory_ui.tick(state, (ctx, &mut self.player1, &mut self.inventory_player1))?;
TextScriptVM::run(state, self, ctx)?;
}
_ => {}
}
match state.fade_state {
@ -1982,6 +1983,14 @@ impl Scene for GameScene {
}
}
self.inventory_dim += 0.1 * if state.textscript_vm.mode == ScriptMode::Inventory {
state.frame_time as f32
} else {
-(state.frame_time as f32)
};
self.inventory_dim = self.inventory_dim.clamp(0.0, 1.0);
Ok(())
}
@ -2016,6 +2025,13 @@ impl Scene for GameScene {
self.draw_black_bars(state, ctx)?;
if self.inventory_dim > 0.0 {
let rect = Rect::new(0, 0, state.screen_size.0 as isize + 1, state.screen_size.1 as isize + 1);
let mut dim_color = state.constants.inventory_dim_color;
dim_color.a *= self.inventory_dim;
graphics::draw_rect(ctx, rect, dim_color)?;
}
match state.textscript_vm.mode {
ScriptMode::Map if state.control_flags.control_enabled() => {
self.hud_player1.draw(state, ctx, &self.frame)?;

View File

@ -190,6 +190,7 @@ pub struct PixTonePlayback {
pub table: [PixToneParameters; 256],
}
#[allow(unused)]
impl PixTonePlayback {
pub fn new() -> PixTonePlayback {
let mut table = [PixToneParameters::empty(); 256];

View File

@ -78,11 +78,7 @@ impl SizedBatch {
self.batch.clear();
}
pub fn add(&mut self, mut x: f32, mut y: f32) {
/*unsafe {
x = (x * G_MAG).floor() / G_MAG;
y = (y * G_MAG).floor() / G_MAG;
}*/
pub fn add(&mut self, x: f32, y: f32) {
let mag = unsafe { I_MAG };
self.batch.add(SpriteBatchCommand::DrawRect(
@ -101,7 +97,7 @@ impl SizedBatch {
self.add_rect_scaled(x, y, 1.0, 1.0, rect)
}
pub fn add_rect_flip(&mut self, mut x: f32, mut y: f32, flip_x: bool, flip_y: bool, rect: &common::Rect<u16>) {
pub fn add_rect_flip(&mut self, x: f32, y: f32, flip_x: bool, flip_y: bool, rect: &common::Rect<u16>) {
if (rect.right - rect.left) == 0 || (rect.bottom - rect.top) == 0 {
return;
}
@ -131,15 +127,11 @@ impl SizedBatch {
self.add_rect_scaled_tinted(x, y, color, 1.0, 1.0, rect)
}
pub fn add_rect_scaled(&mut self, mut x: f32, mut y: f32, scale_x: f32, scale_y: f32, rect: &common::Rect<u16>) {
pub fn add_rect_scaled(&mut self, x: f32, y: f32, scale_x: f32, scale_y: f32, rect: &common::Rect<u16>) {
if (rect.right.saturating_sub(rect.left)) == 0 || (rect.bottom.saturating_sub(rect.top)) == 0 {
return;
}
/*unsafe {
x = (x * G_MAG).floor() / G_MAG;
y = (y * G_MAG).floor() / G_MAG;
}*/
let mag = unsafe { I_MAG };
self.batch.add(SpriteBatchCommand::DrawRect(
@ -160,8 +152,8 @@ impl SizedBatch {
pub fn add_rect_scaled_tinted(
&mut self,
mut x: f32,
mut y: f32,
x: f32,
y: f32,
color: (u8, u8, u8, u8),
scale_x: f32,
scale_y: f32,
@ -171,10 +163,6 @@ impl SizedBatch {
return;
}
/*unsafe {
x = (x * G_MAG).floor() / G_MAG;
y = (y * G_MAG).floor() / G_MAG;
}*/
let mag = unsafe { I_MAG };
self.batch.add(SpriteBatchCommand::DrawRectTinted(