mindustry logic execution, map- and schematic- parsing and rendering
why
| -rw-r--r-- | mindus/src/data/map.rs | 34 | ||||
| -rw-r--r-- | mindus/src/data/mod.rs | 9 | ||||
| -rw-r--r-- | mindus/src/data/renderer.rs | 58 |
3 files changed, 50 insertions, 51 deletions
diff --git a/mindus/src/data/map.rs b/mindus/src/data/map.rs index a0276fc..c9c8f76 100644 --- a/mindus/src/data/map.rs +++ b/mindus/src/data/map.rs @@ -77,7 +77,7 @@ //! - id: `u32` //! - entity read //! - markers section (v8) -use atools::ArrayTools; +use fimg::DynImage; use std::collections::HashMap; use std::ops::CoroutineState::*; use std::ops::{Coroutine, Index, IndexMut}; @@ -111,23 +111,23 @@ pub struct Tile { macro_rules! lo { ($v:expr => [$(|)? $($k:literal $(|)?)+], $scale: ident) => { paste::paste! { match $v { - $(BlockEnum::[<$k:camel>] => load!(raw $k, $scale),)+ - n => unreachable!("{n:?}"), + $(BlockEnum::[<$k:camel>] => Some(load!(raw $k, $scale)),)+ + _ => None, } } }; } #[inline] -pub(crate) fn ore(ore: BlockEnum, s: Scale) -> Image<&'static [u8], 4> { - lo!(ore => ["ore-copper" | "ore-beryllium" | "ore-lead" | "ore-scrap" | "ore-coal" | "ore-thorium" | "ore-titanium" | "ore-tungsten" | "pebbles" | "tendrils" | "ore-wall-tungsten" | "ore-wall-beryllium" | "ore-wall-thorium" | "spawn" | "ore-crystal-thorium" | "molten-slag" | "grass"], s) +pub(crate) fn ore(ore: BlockEnum, s: Scale) -> DynImage<&'static [u8]> { + lo!(ore => ["ore-copper" | "ore-beryllium" | "ore-lead" | "ore-scrap" | "ore-coal" | "ore-thorium" | "ore-titanium" | "ore-tungsten" | "pebbles" | "tendrils" | "ore-wall-tungsten" | "ore-wall-beryllium" | "ore-wall-thorium" | "spawn" | "ore-crystal-thorium" | "molten-slag"], s).map(DynImage::Rgba).unwrap_or_else(|| floor(ore, s)) } #[inline] -pub(crate) fn floor(tile: BlockEnum, s: Scale) -> Image<&'static [u8], 3> { +pub(crate) fn floor(tile: BlockEnum, s: Scale) -> DynImage<&'static [u8]> { macro_rules! x { ($($x:literal)+) => { paste::paste! { match tile { - $(BlockEnum::[<$x:camel>] => return load!(raw $x, s),)+ + $(BlockEnum::[<$x:camel>] => return DynImage::Rgb(load!(raw $x, s)),)+ _ => {} } }}; @@ -167,7 +167,7 @@ pub(crate) fn floor(tile: BlockEnum, s: Scale) -> Image<&'static [u8], 3> { | "red-stone" | "red-stone-vent" | "dense-red-stone" | "carbon-stone" | "carbon-vent" | "crystal-floor" | "crystalline-stone" | "crystalline-vent" - | "empty"], s) + | "empty"], s).map(DynImage::Rgb).unwrap_or_else(|| ore(tile, s)) } impl Tile { @@ -210,13 +210,13 @@ impl Tile { } #[inline] - pub(crate) fn floor(&self, s: Scale) -> Image<&'static [u8], 3> { + pub(crate) fn floor(&self, s: Scale) -> DynImage<&'static [u8]> { floor(self.floor, s) } #[must_use] #[inline] - pub(crate) fn ore(&self, s: Scale) -> Image<&'static [u8], 4> { + pub(crate) fn ore(&self, s: Scale) -> DynImage<&'static [u8]> { ore(self.ore, s) } @@ -226,16 +226,6 @@ impl Tile { self.ore != BlockEnum::Air } - /// Draw the floor of this tile - #[must_use] - pub fn floor_image(&self, s: Scale) -> ImageHolder<3> { - let mut floor = ImageHolder::from(self.floor(s)); - if self.has_ore() { - unsafe { floor.overlay(&self.ore(s)) }; - } - floor - } - /// Draw this tiles build. #[must_use] #[inline] @@ -588,10 +578,6 @@ macro_rules! tiles { let overlay_id = $me.buff.read_u16()?; let &(mut floor) = $r.get(floor_id as usize).unwrap_or(&BlockEnum::Stone); let &(mut ore) = $r.get(overlay_id as usize).unwrap_or(&BlockEnum::Air); - if let BlockEnum::MoltenSlag | BlockEnum::Grass = floor { - ore = floor; - floor = BlockEnum::Stone; - } yield $w::Tile { floor, ore }; let consecutives = $me.buff.read_u8()? as usize; for _ in 0..consecutives { diff --git a/mindus/src/data/mod.rs b/mindus/src/data/mod.rs index 43d57c8..20f19e0 100644 --- a/mindus/src/data/mod.rs +++ b/mindus/src/data/mod.rs @@ -311,11 +311,8 @@ impl<'d> DataWrite<'d> { }; let mut comp = Compress::new(Compression::default(), true); // compress the immediate buffer into a temp buffer to copy it to buff? no thanks - match to.data { - WriteBuff::Ref { - raw: ref mut dst, - ref mut pos, - } => { + match &mut to.data { + WriteBuff::Ref { raw: dst, pos } => { match comp.compress(&raw, &mut dst[*pos..], FlushCompress::Finish)? { // there's no more input (and the flush mode says so), but we can't resize the output Status::Ok | Status::BufError => { @@ -326,7 +323,7 @@ impl<'d> DataWrite<'d> { Status::StreamEnd => (), } } - WriteBuff::Vec(ref mut dst) => { + WriteBuff::Vec(dst) => { let mut input = raw.as_ref(); dst.reserve(1024); loop { diff --git a/mindus/src/data/renderer.rs b/mindus/src/data/renderer.rs index 0d0c5b0..493500c 100644 --- a/mindus/src/data/renderer.rs +++ b/mindus/src/data/renderer.rs @@ -20,7 +20,7 @@ use crate::{ }; use atools::ArrayTools; use either::Either; -use fimg::{BlendingOverlay, BlendingOverlayAt, uninit}; +use fimg::{BlendingOverlay, BlendingOverlayAt, DynImage, uninit}; include!(concat!(env!("OUT_DIR"), "/full.rs")); include!(concat!(env!("OUT_DIR"), "/quar.rs")); @@ -380,9 +380,15 @@ impl Renderable for Map { unsafe { img.overlay_at(i, scale * x as u32, scale * y as u32) }; } } else { - unsafe { - img.overlay_at(&tile.floor(scale), scale * x as u32, scale * y as u32) - }; + match tile.floor(scale) { + DynImage::Rgba(i) => unsafe { + img.overlay_at(&i, scale * x as u32, scale * y as u32); + }, + DynImage::Rgb(i) => unsafe { + img.overlay_at(&i, scale * x as u32, scale * y as u32); + }, + _ => unreachable!(), + } } if tile.has_ore() { if tile.ore == Type::CharacterOverlay || tile.ore == Type::CharacterOverlayWhite @@ -405,9 +411,15 @@ impl Renderable for Map { ) }; } else { - unsafe { - img.overlay_at(&tile.ore(scale), scale * x as u32, scale * y as u32) - }; + match tile.ore(scale) { + DynImage::Rgba(i) => unsafe { + img.overlay_at(&i, scale * x as u32, scale * y as u32); + }, + DynImage::Rgb(i) => unsafe { + img.overlay_at(&i, scale * x as u32, scale * y as u32); + }, + _ => unreachable!(), + } } } } @@ -630,21 +642,25 @@ pub fn draw_map_single( }; let y = h - y - 1; // println!("draw tile {floor} {ore} @ {x} {y}"); - unsafe { - img.overlay_at( - &crate::data::map::floor(floor, scale), - scale * x as u32, - scale * y as u32, - ) - }; + match crate::data::map::floor(floor, scale) { + DynImage::Rgba(i) => unsafe { + img.overlay_at(&i, scale * x as u32, scale * y as u32); + }, + DynImage::Rgb(i) => unsafe { + img.overlay_at(&i, scale * x as u32, scale * y as u32); + }, + _ => unreachable!(), + } if ore != Type::Air { - unsafe { - img.overlay_at( - &crate::data::map::ore(ore, scale), - scale * x as u32, - scale * y as u32, - ) - }; + match crate::data::map::ore(ore, scale) { + DynImage::Rgba(i) => unsafe { + img.overlay_at(&i, scale * x as u32, scale * y as u32); + }, + DynImage::Rgb(i) => unsafe { + img.overlay_at(&i, scale * x as u32, scale * y as u32); + }, + _ => unreachable!(), + } } } } |