diff --git a/space-crush-app/src/debug/fleets.rs b/space-crush-app/src/debug/fleets.rs index df31ae6..2a03a2e 100644 --- a/space-crush-app/src/debug/fleets.rs +++ b/space-crush-app/src/debug/fleets.rs @@ -1,6 +1,5 @@ use space_crush_common::{ components::{Fleet, MeetingPoint, Position}, - continue_if_none, misc::LogResult, }; use specs::{prelude::*, ReadExpect, ReadStorage, System, World}; @@ -58,8 +57,11 @@ impl<'a> System<'a> for Fleets { gl::enable(gl::BLEND); for (position, meeting_point) in (&positions, &meeting_points).join() { - let fleet_id = continue_if_none!(meeting_point.fleet(player_index)); - let fleet = continue_if_none!(fleets.get(fleet_id)); + let fleet_id = match meeting_point.fleet(player_index) { + Some(fleet_id) => fleet_id, + None => continue, + }; + let fleet = fleets.get(fleet_id).unwrap(); gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); gl::blend_equation(gl::FUNC_SUBTRACT); diff --git a/space-crush-app/src/debug/ships.rs b/space-crush-app/src/debug/ships.rs index ee991a5..596d495 100644 --- a/space-crush-app/src/debug/ships.rs +++ b/space-crush-app/src/debug/ships.rs @@ -1,8 +1,5 @@ use glc::vector::Vector4f; -use space_crush_common::{ - components::{Player, PlayerOwned, Position, Ship, ShipObstacle}, - continue_if_none, -}; +use space_crush_common::components::{Player, PlayerOwned, Position, Ship, ShipObstacle}; use specs::{prelude::*, ReadStorage, System, World, WriteExpect}; use crate::resources::Geometry; @@ -38,7 +35,7 @@ impl<'a> System<'a> for Ships { let ship_pos = position.get(); let type_ = ship.type_(); let player_id = player_owned.owner(); - let player = continue_if_none!(players.get(player_id)); + let player = players.get(player_id).unwrap(); let ship_data = player.ship_data(type_); geometry.render_lines( @@ -55,8 +52,7 @@ impl<'a> System<'a> for Ships { ); if let ShipObstacle::Known(obstacle) = ship.obstacle() { - let obstacle_pos = continue_if_none!(positions.get(obstacle)); - let obstacle_pos = obstacle_pos.get(); + let obstacle_pos = positions.get(obstacle).unwrap().get(); geometry.render_lines( Vector4f::new(0.0, 1.0, 0.0, 0.2), diff --git a/space-crush-app/src/render/fleet_move.rs b/space-crush-app/src/render/fleet_move.rs index 8a6508c..afac336 100644 --- a/space-crush-app/src/render/fleet_move.rs +++ b/space-crush-app/src/render/fleet_move.rs @@ -1,7 +1,6 @@ use shrev::{EventChannel, ReaderId}; use space_crush_common::{ components::{MeetingPoint, Position}, - continue_if_none, misc::WorldHelper, systems::FleetControlEvent, }; @@ -77,10 +76,14 @@ impl<'a> System<'a> for FleetMove { } } MouseEvent::ButtonUp(button) if button == &config.input.fleet_move_button => { - let selection = game_state.selection_mut().take(); - let selection = continue_if_none!(selection); - let Selection { fleet, count } = selection; - let target = continue_if_none!(self.target_meeting_point); + let Selection { fleet, count } = match game_state.selection_mut().take() { + Some(selection) => selection, + None => continue, + }; + let target = match self.target_meeting_point { + Some(target) => target, + None => continue, + }; let player = game_state.player_id(); let event = FleetControlEvent::MoveToMeetingPoint { player, diff --git a/space-crush-app/src/render/fleet_select.rs b/space-crush-app/src/render/fleet_select.rs index 516d9e5..6cb4415 100644 --- a/space-crush-app/src/render/fleet_select.rs +++ b/space-crush-app/src/render/fleet_select.rs @@ -12,10 +12,8 @@ use shrev::{EventChannel, ReaderId}; use space_crush_common::{ components::{Fleet, FleetOrbiting, MeetingPoint, Position, Shape, ShipCount}, constants::VECTOR_2F_POS_X, - continue_if_none, misc::{LogResult, WorldHelper as _}, resources::Global, - return_if_none, }; use specs::{prelude::*, ReadExpect, ReadStorage, System, World}; @@ -165,7 +163,10 @@ impl FleetSelect { let r = meeting_point.max() * meeting_point.max(); if (position.get() - pos).length_sqr() <= r { let player_index = d.game_state.player_index(); - let fleet_id = continue_if_none!(meeting_point.fleet(player_index)); + let fleet_id = match meeting_point.fleet(player_index) { + Some(fleet_id) => fleet_id, + None => continue, + }; *d.game_state.selection_mut() = match selection { Some(s) if s.fleet == fleet_id => { @@ -199,22 +200,21 @@ impl FleetSelect { MouseEvent::ButtonUp(button) if button == &d.config.input.fleet_select_button => { self.select_mode = match self.select_mode { SelectMode::Simple(progress) => { - continue_if_none!(d.game_state.selection_mut()).count = self.count; + d.game_state.selection_mut().as_mut().unwrap().count = self.count; self.mouse_pos = d.input_state.mouse_pos; SelectMode::SimpleClose(progress) } SelectMode::Detail(progress) => { - continue_if_none!(d.game_state.selection_mut()).count = self.count; + d.game_state.selection_mut().as_mut().unwrap().count = self.count; self.mouse_pos = d.input_state.mouse_pos; SelectMode::DetailClose(progress) } SelectMode::Init(_) if self.is_new_selection => { - continue_if_none!(d.game_state.selection_mut()).count = - ShipCount::all(); + d.game_state.selection_mut().as_mut().unwrap().count = ShipCount::all(); SelectMode::None } @@ -246,7 +246,7 @@ impl FleetSelect { } /* calculate values */ - let selection = return_if_none!(d.game_state.selection()); + let selection = d.game_state.selection().as_ref().unwrap(); let fleet_id = selection.fleet; let fleet = d.fleets.get(fleet_id).unwrap(); let fleet_orbiting = d.fleets_orbiting.get(fleet_id).unwrap(); @@ -403,7 +403,7 @@ impl FleetSelect { }; /* extract system data */ - let selection = return_if_none!(d.game_state.selection()); + let selection = d.game_state.selection().as_ref().unwrap(); let fleet_id = selection.fleet; let fleet_orbiting = d .fleets_orbiting diff --git a/space-crush-common/src/lib.rs b/space-crush-common/src/lib.rs index 0cdd993..bd1d553 100644 --- a/space-crush-common/src/lib.rs +++ b/space-crush-common/src/lib.rs @@ -3,7 +3,6 @@ pub mod components; pub mod constants; pub mod dispatcher; pub mod error; -pub mod macros; pub mod misc; pub mod resources; pub mod systems; diff --git a/space-crush-common/src/macros.rs b/space-crush-common/src/macros.rs deleted file mode 100644 index 0b3df90..0000000 --- a/space-crush-common/src/macros.rs +++ /dev/null @@ -1,29 +0,0 @@ -#[macro_export] -macro_rules! return_if_none { - ($value:expr) => { - match $value { - Some(value) => value, - None => return, - } - }; -} - -#[macro_export] -macro_rules! break_if_none { - ($value:expr) => { - match $value { - Some(value) => value, - None => break, - } - }; -} - -#[macro_export] -macro_rules! continue_if_none { - ($value:expr) => { - match $value { - Some(value) => value, - None => continue, - } - }; -} diff --git a/space-crush-common/src/systems/fleet_orbiting_update.rs b/space-crush-common/src/systems/fleet_orbiting_update.rs index af39438..8cf8b63 100644 --- a/space-crush-common/src/systems/fleet_orbiting_update.rs +++ b/space-crush-common/src/systems/fleet_orbiting_update.rs @@ -8,7 +8,6 @@ use specs::{ use crate::{ components::{FleetOrbiting, MeetingPoint, Player, PlayerOwned}, - continue_if_none, misc::{ComponentEvent, StorageHelper, StorageHelperMut}, }; @@ -123,7 +122,7 @@ impl<'a> System<'a> for FleetOrbitingUpdate { }; let player_id = player_owned.owner(); - let player = continue_if_none!(players.get(player_id)); + let player = players.get(player_id).unwrap(); let player_index = player.index(); if old_match && !new_match { diff --git a/space-crush-common/src/systems/ship_movement.rs b/space-crush-common/src/systems/ship_movement.rs index 142069e..f82beff 100644 --- a/space-crush-common/src/systems/ship_movement.rs +++ b/space-crush-common/src/systems/ship_movement.rs @@ -5,7 +5,6 @@ use specs::{prelude::*, ParJoin, Read, ReadStorage, System, WriteStorage}; use crate::{ components::{Player, PlayerOwned, Position, Ship}, resources::Global, - return_if_none, }; #[derive(Default)] @@ -38,7 +37,7 @@ impl<'a> System<'a> for ShipMovement { let position = position.get_mut(); let type_ = ship.type_(); let player_id = player_owned.owner(); - let player = return_if_none!(players.get(player_id)); + let player = players.get(player_id).unwrap(); let ship_data = player.ship_data(type_); *position += ship.dir() * ship_data.speed * delta; diff --git a/space-crush-common/src/systems/ships.rs b/space-crush-common/src/systems/ships.rs index 8be1684..f8c2526 100644 --- a/space-crush-common/src/systems/ships.rs +++ b/space-crush-common/src/systems/ships.rs @@ -20,7 +20,6 @@ use crate::{ }, misc::{ComponentEvent, StorageHelper, StorageHelperMut}, resources::Global, - return_if_none, }; pub struct Ships { @@ -134,10 +133,10 @@ impl Processor<'_> { fleet_owned: &FleetOwned, ) { let fleet_id = fleet_owned.owner(); - let fleet_orbiting = return_if_none!(self.fleet_orbiting.get(fleet_id)); + let fleet_orbiting = self.fleet_orbiting.get(fleet_id).unwrap(); let meeting_point_id = fleet_orbiting.meeting_point(); - let meeting_point = return_if_none!(self.meeting_points.get(meeting_point_id)); - let meeting_point_pos = return_if_none!(self.positions.get(meeting_point_id)).get(); + let meeting_point = self.meeting_points.get(meeting_point_id).unwrap(); + let meeting_point_pos = self.positions.get(meeting_point_id).unwrap().get(); let ship_pos = position.get(); let target_pos = ship.target_pos(); let target_dir = ship.target_dir();