mindustry logic execution, map- and schematic- parsing and rendering
use Image<Box<[u8]>> more
bendn 2023-10-05
parent 0c931f0 · commit 744a897
-rw-r--r--mindus/Cargo.toml2
-rw-r--r--mindus/src/block/logic.rs10
-rw-r--r--mindus/src/block/mod.rs2
-rw-r--r--mindus/src/utils/image/holder.rs14
4 files changed, 15 insertions, 13 deletions
diff --git a/mindus/Cargo.toml b/mindus/Cargo.toml
index 7d0aa9c..b10ae99 100644
--- a/mindus/Cargo.toml
+++ b/mindus/Cargo.toml
@@ -25,7 +25,7 @@ bobbin-bits = "0.1"
blurslice = { version = "0.1" }
enum_dispatch = "0.3"
phf = { version = "0.11", features = ["macros"] }
-fimg = { version = "0.4.5", default-features = false }
+fimg = { version = "0.4.15", default-features = false }
[features]
bin = ["fimg/save"]
diff --git a/mindus/src/block/logic.rs b/mindus/src/block/logic.rs
index 7c3e9e0..2b03326 100644
--- a/mindus/src/block/logic.rs
+++ b/mindus/src/block/logic.rs
@@ -56,11 +56,11 @@ impl CanvasBlock {
}
}
- state_impl!(pub Image<Vec<u8>, 1>);
+ state_impl!(pub Image<Box<[u8]>, 1>);
}
-fn deser_canvas_image(b: &[u8], size: usize) -> Image<Vec<u8>, 1> {
- let mut p = Image::alloc(size as u32, size as u32);
+fn deser_canvas_image(b: &[u8], size: usize) -> Image<Box<[u8]>, 1> {
+ let mut p = Image::alloc(size as u32, size as u32).boxed();
for i in 0..(size * size) {
let offset = i * 3;
let mut n = 0;
@@ -144,13 +144,15 @@ impl BlockLogic for CanvasBlock {
(s * self.size as u32) - offset * 2,
(s * self.size as u32) - offset * 2,
)
+ .boxed()
};
let mut borders = load!("canvas", s);
unsafe { borders.overlay_at(&ImageHolder::from(img), offset, offset) };
return borders;
}
- let mut def = Image::alloc(s * self.size as u32, s * self.size as u32);
+ // FIXME: make const
+ let mut def = Image::alloc(s * self.size as u32, s * self.size as u32).boxed();
for [r, g, b, a] in def.chunked_mut() {
(*r, *g, *b) = PALETTE[0];
*a = 255;
diff --git a/mindus/src/block/mod.rs b/mindus/src/block/mod.rs
index c314175..7c1cac2 100644
--- a/mindus/src/block/mod.rs
+++ b/mindus/src/block/mod.rs
@@ -149,7 +149,7 @@ stater! {
String(String),
Item(Option<crate::item::Type>),
Fluid(Option<crate::fluid::Type>),
- Image(Image<Vec<u8>, 1>),
+ Image(Image<Box<[u8]>, 1>),
Point(Option<(i32, i32)>),
Bool(bool),
Processor(logic::ProcessorState),
diff --git a/mindus/src/utils/image/holder.rs b/mindus/src/utils/image/holder.rs
index 24bcdb1..2a8d03b 100644
--- a/mindus/src/utils/image/holder.rs
+++ b/mindus/src/utils/image/holder.rs
@@ -2,15 +2,15 @@ use super::{ClonerOverlay, ClonerOverlayAt, Image, ImageUtils, Overlay, OverlayA
#[derive(Clone, Debug)]
pub enum ImageHolder<const CHANNELS: usize> {
Borrow(Image<&'static [u8], CHANNELS>),
- Own(Image<Vec<u8>, CHANNELS>),
+ Own(Image<Box<[u8]>, CHANNELS>),
}
impl<const CHANNELS: usize> ImageHolder<CHANNELS> {
#[must_use]
- pub fn own(self) -> Image<Vec<u8>, CHANNELS> {
+ pub fn own(self) -> Image<Box<[u8]>, CHANNELS> {
match self {
Self::Own(x) => x,
- Self::Borrow(x) => x.to_owned(),
+ Self::Borrow(x) => x.boxed(),
}
}
}
@@ -31,7 +31,7 @@ impl<const CHANNELS: usize> ImageHolder<CHANNELS> {
match self {
Self::Own(x) => x.as_mut(),
Self::Borrow(x) => {
- *self = Self::from(x.to_owned());
+ *self = Self::from(x.boxed());
self.borrow_mut()
}
}
@@ -48,7 +48,7 @@ macro_rules! make {
}
Self::Borrow(v) => {
#[allow(unused_unsafe)]
- { *$me = Self::from(unsafe { v.cloner().$fn($($argv,)*) }) };
+ { *$me = Self::from(unsafe { v.cloner().$fn($($argv,)*).boxed() }) };
$me
}
}
@@ -100,8 +100,8 @@ impl<const CHANNELS: usize> From<Image<&'static [u8], CHANNELS>> for ImageHolder
}
}
-impl<const CHANNELS: usize> From<Image<Vec<u8>, CHANNELS>> for ImageHolder<CHANNELS> {
- fn from(value: Image<Vec<u8>, CHANNELS>) -> Self {
+impl<const CHANNELS: usize> From<Image<Box<[u8]>, CHANNELS>> for ImageHolder<CHANNELS> {
+ fn from(value: Image<Box<[u8]>, CHANNELS>) -> Self {
Self::Own(value)
}
}