mindustry logic execution, map- and schematic- parsing and rendering
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/lib.rs | 6 | ||||
| -rw-r--r-- | src/utils/image/overlay.rs | 29 |
3 files changed, 22 insertions, 15 deletions
@@ -1,6 +1,6 @@ [package] name = "mindus" -version = "4.0.12" +version = "4.0.13" edition = "2021" description = "A library for working with mindustry data formats (eg schematics and maps) (fork of plandustry)" authors = [ @@ -1,11 +1,11 @@ //! crate for dealing with mindustry #![feature( - array_chunks, + slice_swap_unchecked, const_trait_impl, - unchecked_math, slice_as_chunks, - slice_swap_unchecked, + unchecked_math, portable_simd, + array_chunks, trace_macros, let_chains, effects, diff --git a/src/utils/image/overlay.rs b/src/utils/image/overlay.rs index 3dba13b..95c9a0e 100644 --- a/src/utils/image/overlay.rs +++ b/src/utils/image/overlay.rs @@ -81,17 +81,24 @@ impl OverlayAt<Image<&[u8], 4>> for Image<&mut [u8], 3> { impl OverlayAt<Image<&[u8], 3>> for Image<&mut [u8], 3> { unsafe fn overlay_at(&mut self, with: &Image<&[u8], 3>, x: u32, y: u32) -> &mut Self { - for j in 0..with.height() { - let i_x = j as usize * with.width() as usize * 3 - ..(j as usize + 1) * with.width() as usize * 3; - let o_x = ((j as usize + y as usize) * self.width() as usize + x as usize) * 3 - ..((j as usize + y as usize) * self.width() as usize - + x as usize - + with.width() as usize) - * 3; - let a = unsafe { self.buffer.get_unchecked_mut(o_x) }; - let b = unsafe { with.buffer.get_unchecked(i_x) }; - a.copy_from_slice(b); + macro_rules! o3x3 { + ($n:expr) => {{ + for j in 0..($n as usize) { + let i_x = j * ($n as usize) * 3..(j + 1) * ($n as usize) * 3; + let o_x = ((j + y as usize) * self.width() as usize + x as usize) * 3 + ..((j + y as usize) * self.width() as usize + x as usize + ($n as usize)) + * 3; + let a = unsafe { self.buffer.get_unchecked_mut(o_x) }; + let b = unsafe { with.buffer.get_unchecked(i_x) }; + a.copy_from_slice(b); + } + }}; + } + // let it unroll + match with.width() { + 8 => o3x3!(8), + 16 => o3x3!(16), // this branch makes 8x8 0.16 times slower; but 16x16 0.2 times faster. + _ => o3x3!(with.width()), } self } |