mindustry logic execution, map- and schematic- parsing and rendering
use push() instead of indexing during map deserialization
bendn 2023-09-04
parent e73db46 · commit 1dbfad5
-rw-r--r--Cargo.toml2
-rw-r--r--src/data/map.rs32
-rw-r--r--src/utils/image/overlay.rs1
3 files changed, 9 insertions, 26 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 0084712..cc089fe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mindus"
-version = "4.0.14"
+version = "4.0.15"
edition = "2021"
description = "A library for working with mindustry data formats (eg schematics and maps) (fork of plandustry)"
authors = [
diff --git a/src/data/map.rs b/src/data/map.rs
index 31a0003..c58fbbc 100644
--- a/src/data/map.rs
+++ b/src/data/map.rs
@@ -445,26 +445,6 @@ macro_rules! cond {
}
impl<'l> Crossable for Map<'l> {
- // N
- // cond!(pos.position.1 >= (pos.height - 1) as u16, get(j + 1)),
- // // E
- // cond!(
- // pos.position.0 >= (pos.height - 1) as u16,
- // get(j + pos.height)
- // ),
- // // S
- // cond!(
- // pos.position.1 == 0 || pos.position.1 >= pos.height as u16,
- // cond!(pos.position.1 >= (pos.height - 1), get(j + 1)),
- // // E
- // cond!(pos.position.0 >= (pos.height - 1), get(j + pos.height)),
- // // S
- // cond!(
- // pos.position.1 == 0 || pos.position.1 >= pos.height,
- // get(j - 1)
- // ),
- // // W
- // cond!(j < pos.height, get(j - pos.height)),
fn cross(&self, j: usize, c: &PositionContext) -> Cross {
let get = |i| {
let b = &self[i];
@@ -486,13 +466,17 @@ impl<'l> Map<'l> {
#[must_use]
pub fn new(width: usize, height: usize, tags: HashMap<String, String>) -> Self {
Self {
- tiles: vec![Tile::new(BlockEnum::Air, BlockEnum::Air); width * height],
+ tiles: Vec::with_capacity(width * height),
height,
width,
tags,
entities: vec![],
}
}
+
+ fn push(&mut self, t: Tile<'l>) {
+ self.tiles.push(t);
+ }
}
impl<'l> Index<usize> for Map<'l> {
@@ -576,11 +560,11 @@ impl<'l> Serializable for Map<'l> {
let overlay_id = buff.read_u16()?;
let floor = BlockEnum::try_from(floor_id).unwrap_or(BlockEnum::Stone);
let ore = BlockEnum::try_from(overlay_id).unwrap_or(BlockEnum::Air);
- map[i] = Tile::new(floor, ore);
+ map.push(Tile::new(floor, ore));
let consecutives = buff.read_u8()? as usize;
if consecutives > 0 {
- for i in (i + 1)..(i + 1 + consecutives) {
- map[i] = Tile::new(floor, ore);
+ for _ in 0..consecutives {
+ map.push(Tile::new(floor, ore));
}
i += consecutives;
}
diff --git a/src/utils/image/overlay.rs b/src/utils/image/overlay.rs
index f357f83..f4654ee 100644
--- a/src/utils/image/overlay.rs
+++ b/src/utils/image/overlay.rs
@@ -58,7 +58,6 @@ pub unsafe fn blit(rgb: &mut [u8], rgba: &[u8]) {
}
}
-
impl Overlay<Image<&[u8], 4>> for Image<&mut [u8], 4> {
#[inline]
unsafe fn overlay(&mut self, with: &Image<&[u8], 4>) -> &mut Self {