Skip to content

Commit

Permalink
Merge pull request #83 from scd31/world_format_bugfix
Browse files Browse the repository at this point in the history
revert a small world change
  • Loading branch information
louis-e authored Nov 2, 2024
2 parents 7decd37 + 2068c1a commit 25e4b17
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions src/world_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,37 @@ impl SectionToModify {
palette.sort();
palette.dedup();

let data = if palette.len() == 1 {
vec![]
} else {
let palette_lookup: FnvHashMap<_, _> = palette
.iter()
.enumerate()
.map(|(k, v)| (v, i64::try_from(k).unwrap()))
.collect();

let mut bits_per_block = 4; // minimum allowed
while (1 << bits_per_block) < palette.len() {
bits_per_block += 1;
}

let mut data = vec![];
let palette_lookup: FnvHashMap<_, _> = palette
.iter()
.enumerate()
.map(|(k, v)| (v, i64::try_from(k).unwrap()))
.collect();

let mut cur = 0;
let mut cur_idx = 0;
for block in &self.blocks {
let p = palette_lookup[block];
let mut bits_per_block = 4; // minimum allowed
while (1 << bits_per_block) < palette.len() {
bits_per_block += 1;
}

if cur_idx + bits_per_block > 64 {
data.push(cur);
cur = 0;
cur_idx = 0;
}
let mut data = vec![];

cur |= p << cur_idx;
cur_idx += bits_per_block;
}
let mut cur = 0;
let mut cur_idx = 0;
for block in &self.blocks {
let p = palette_lookup[block];

if cur_idx > 0 {
if cur_idx + bits_per_block > 64 {
data.push(cur);
cur = 0;
cur_idx = 0;
}

data
};
cur |= p << cur_idx;
cur_idx += bits_per_block;
}

if cur_idx > 0 {
data.push(cur);
}

let palette = palette
.iter()
Expand Down

0 comments on commit 25e4b17

Please sign in to comment.