mindustry logic execution, map- and schematic- parsing and rendering
remove the want_context function
| -rw-r--r-- | src/block/distribution.rs | 9 | ||||
| -rw-r--r-- | src/block/liquid.rs | 22 | ||||
| -rw-r--r-- | src/block/mod.rs | 20 | ||||
| -rw-r--r-- | src/block/simple.rs | 13 |
4 files changed, 32 insertions, 32 deletions
diff --git a/src/block/distribution.rs b/src/block/distribution.rs index d4fe4d1..e185d3a 100644 --- a/src/block/distribution.rs +++ b/src/block/distribution.rs @@ -22,8 +22,7 @@ make_simple!( buff.skip(4)?; } Ok(()) - }, - true + } ); make_simple!( @@ -33,8 +32,7 @@ make_simple!( // format: // - rec_dir: `i8` buff.skip(1) - }, - true + } ); make_simple!(JunctionBlock => |_, _, _, buff| { read_directional_item_buffer(buff) }); @@ -120,8 +118,7 @@ make_simple!( // format: // - link: `i32` // - cooldown: `f32` - |_, _, _, buff: &mut DataRead| buff.skip(8), - true + |_, _, _, buff: &mut DataRead| buff.skip(8) ); make_simple!(SurgeRouter, |_, _, _, _, r: Rotation, s| { let mut base = load!("surge-router", s); diff --git a/src/block/liquid.rs b/src/block/liquid.rs index 9a6d0b3..d20fb47 100644 --- a/src/block/liquid.rs +++ b/src/block/liquid.rs @@ -10,16 +10,18 @@ use crate::data::renderer::load; use crate::fluid; use crate::utils::ImageUtils; -make_simple!( - ConduitBlock, - |_, name, _, ctx: Option<&RenderingContext>, rot, s| { - let ctx = ctx.unwrap(); - let mask = mask(ctx, rot, name); - // TODO caps. stopped trying bcz too complex - mask2tile(mask, rot, name, s) - }, - true -); +make_simple!(ConduitBlock, |_, + name, + _, + ctx: Option<&RenderingContext>, + rot, + s| { + let ctx = ctx.unwrap(); + + let mask = mask(ctx, rot, name); + // TODO caps. stopped trying bcz too complex + mask2tile(mask, rot, name, s) +}); make_register! { "reinforced-pump" -> BasicBlock::new(2, true, cost!(Beryllium: 40, Tungsten: 30, Silicon: 20)); diff --git a/src/block/mod.rs b/src/block/mod.rs index 518e059..15b6d97 100644 --- a/src/block/mod.rs +++ b/src/block/mod.rs @@ -208,10 +208,6 @@ pub trait BlockLogic { unimplemented!("{name}") } - fn want_context(&self) -> bool { - false - } - #[allow(unused_variables)] fn read( &self, @@ -315,8 +311,9 @@ impl PartialEq for Block { } impl Block { - #[must_use] /// create a new block + #[must_use] + #[inline] pub(crate) const fn new( name: &'static str, logic: BlockLogicEnum, @@ -330,18 +327,25 @@ impl Block { /// assert!(mindus::block::distribution::DISTRIBUTOR.name() == "distributor") /// ``` #[must_use] + #[inline] pub const fn name(&self) -> &'static str { self.name } /// should you send context to [`image`]? #[must_use] + #[inline] pub fn wants_context(&self) -> bool { - self.logic.want_context() + use BlockLogicEnum::*; + matches!( + self.logic, + ConveyorBlock(..) | DuctBlock(..) | StackConveyor(..) | ConduitBlock(..) + ) } /// draw this block, with this state #[must_use] + #[inline] pub fn image( &self, state: Option<&State>, @@ -357,18 +361,21 @@ impl Block { /// size. #[must_use] + #[inline] pub fn get_size(&self) -> u8 { self.logic.get_size() } /// does it matter if its rotated #[must_use] + #[inline] pub fn is_symmetric(&self) -> bool { self.logic.is_symmetric() } /// cost #[must_use] + #[inline] pub fn get_build_cost(&self) -> Option<ItemStorage> { self.logic.create_build_cost() } @@ -400,6 +407,7 @@ impl Block { self.logic.serialize_state(state) } + #[inline] pub(crate) fn read( &self, build: &mut Build, diff --git a/src/block/simple.rs b/src/block/simple.rs index af4047e..5c4c326 100644 --- a/src/block/simple.rs +++ b/src/block/simple.rs @@ -25,7 +25,7 @@ pub(crate) use state_impl; /// draw is called with self, name, state, context, rotation /// read is called with build, reg, `entity_mapping`, buff macro_rules! make_simple { - ($name: ident, $draw: expr, $read: expr, $wants_context: literal) => { + ($name: ident, $draw: expr, $read: expr) => { pub struct $name { size: u8, symmetric: bool, @@ -92,10 +92,6 @@ macro_rules! make_simple { $draw(self, name, state, context, rot, scale) } - fn want_context(&self) -> bool { - $wants_context - } - fn read( &self, build: &mut crate::data::map::Build, @@ -109,13 +105,10 @@ macro_rules! make_simple { } }; ($name: ident, $draw: expr) => { - crate::block::simple::make_simple!($name, $draw, |_, _, _, _| Ok(()), false); - }; - ($name: ident, $draw: expr, $wants_context: literal) => { - crate::block::simple::make_simple!($name, $draw, |_, _, _, _| Ok(()), $wants_context); + crate::block::simple::make_simple!($name, $draw, |_, _, _, _| Ok(())); }; ($name: ident, $draw: expr, $read: expr) => { - crate::block::simple::make_simple!($name, $draw, $read, false); + crate::block::simple::make_simple!($name, $draw, $read); }; ($name: ident => $read: expr) => { crate::block::simple::make_simple!($name, |_, n, _, _, _, _| unimplemented!("{n}"), $read); |