Fix generated map integrity and wall access

This commit is contained in:
chelsea
2026-05-02 23:48:35 -05:00
parent 127e706bcb
commit 95bd106a3b
3 changed files with 18 additions and 11 deletions

Binary file not shown.

View File

@@ -320,18 +320,18 @@ static int64_t to_signed64(uint64_t v) {
static void pack_bits(const uint16_t *indices, size_t count, int bits_per_value, int64_t *out_longs, size_t out_count) {
memset(out_longs, 0, out_count * sizeof(int64_t));
int values_per_long = 64 / bits_per_value;
if (values_per_long < 1) values_per_long = 1;
for (size_t idx = 0; idx < count; ++idx) {
uint64_t value = indices[idx];
size_t bit_index = idx * (size_t)bits_per_value;
size_t long_id = bit_index / 64;
size_t offset = bit_index % 64;
size_t long_id = idx / (size_t)values_per_long;
size_t offset = (idx % (size_t)values_per_long) * (size_t)bits_per_value;
if (long_id >= out_count) continue;
uint64_t *target = (uint64_t *)&out_longs[long_id];
*target |= value << offset;
int spill = (int)(offset + bits_per_value - 64);
if (spill > 0 && long_id + 1 < out_count) {
uint64_t *next = (uint64_t *)&out_longs[long_id + 1];
*next |= value >> (bits_per_value - spill);
}
}
for (size_t i = 0; i < out_count; ++i) {
out_longs[i] = to_signed64((uint64_t)out_longs[i]);
}
}
@@ -425,7 +425,9 @@ static void write_section(buf *b, const chunk_data *chunk, int section_y) {
int needed = (int)ceil(log2((double)palette_len));
if (needed > bits) bits = needed;
}
size_t packed_count = ((size_t)idx * (size_t)bits + 63) / 64;
size_t values_per_long = (size_t)(64 / bits);
if (values_per_long < 1) values_per_long = 1;
size_t packed_count = ((size_t)idx + values_per_long - 1) / values_per_long;
int64_t *packed = (int64_t *)calloc(packed_count, sizeof(int64_t));
if (!packed) return;
pack_bits(block_indices, idx, bits, packed, packed_count);

View File

@@ -1068,6 +1068,7 @@ static void place_leaf_circle(int cx, int cy, int cz, int radius, int leaf_block
int r2 = radius * radius;
for (int dx = -radius; dx <= radius; ++dx) {
for (int dz = -radius; dz <= radius; ++dz) {
if (dx == 0 && dz == 0) continue;
if (dx * dx + dz * dz > r2) continue;
if (hole_prob > 0.0 && rng_next_f64(rng) < hole_prob) continue;
block_list_push(out, cx + dx, cy, cz + dz, (uint16_t)leaf_block);
@@ -3779,7 +3780,10 @@ static void generate_chunk_border_wall(worldgen_ctx *ctx, int chunk_x, int chunk
uint16_t block = BLOCK_SMOOTH_STONE;
int in_center_corridor = side_dist >= wall_center - 1 && side_dist <= wall_center + 1 &&
rel_y >= 2 && rel_y <= 4;
if (in_center_corridor) {
int in_walltop_tower_passage = in_tower &&
side_dist >= wall_center - 1 && side_dist <= wall_center + 1 &&
rel_y >= wall_height + 1 && rel_y <= wall_height + 3;
if (in_center_corridor || in_walltop_tower_passage) {
continue;
}
if (rel_y < 0) {
@@ -3810,7 +3814,8 @@ static void generate_chunk_border_wall(worldgen_ctx *ctx, int chunk_x, int chunk
set_block_with_height(out, dx, dz, y, block);
}
if (top + 1 < CHUNK_HEIGHT) {
if (!in_tower && (side_dist == wall_start || side_dist == wall_end)) {
int rail_opening = ladder_module && side_dist == wall_end && ladder_offset <= 1;
if (!in_tower && !rail_opening && (side_dist == wall_start || side_dist == wall_end)) {
uint16_t rail_block = (side < 2) ? BLOCK_IRON_BARS_NS : BLOCK_IRON_BARS_EW;
set_block_with_height(out, dx, dz, top + 1, rail_block);
} else if (in_tower && phase % 4 < 2) {