Fix generated map integrity and wall access
This commit is contained in:
Binary file not shown.
@@ -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) {
|
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));
|
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) {
|
for (size_t idx = 0; idx < count; ++idx) {
|
||||||
uint64_t value = indices[idx];
|
uint64_t value = indices[idx];
|
||||||
size_t bit_index = idx * (size_t)bits_per_value;
|
size_t long_id = idx / (size_t)values_per_long;
|
||||||
size_t long_id = bit_index / 64;
|
size_t offset = (idx % (size_t)values_per_long) * (size_t)bits_per_value;
|
||||||
size_t offset = bit_index % 64;
|
if (long_id >= out_count) continue;
|
||||||
uint64_t *target = (uint64_t *)&out_longs[long_id];
|
uint64_t *target = (uint64_t *)&out_longs[long_id];
|
||||||
*target |= value << offset;
|
*target |= value << offset;
|
||||||
int spill = (int)(offset + bits_per_value - 64);
|
}
|
||||||
if (spill > 0 && long_id + 1 < out_count) {
|
for (size_t i = 0; i < out_count; ++i) {
|
||||||
uint64_t *next = (uint64_t *)&out_longs[long_id + 1];
|
out_longs[i] = to_signed64((uint64_t)out_longs[i]);
|
||||||
*next |= value >> (bits_per_value - spill);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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));
|
int needed = (int)ceil(log2((double)palette_len));
|
||||||
if (needed > bits) bits = needed;
|
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));
|
int64_t *packed = (int64_t *)calloc(packed_count, sizeof(int64_t));
|
||||||
if (!packed) return;
|
if (!packed) return;
|
||||||
pack_bits(block_indices, idx, bits, packed, packed_count);
|
pack_bits(block_indices, idx, bits, packed, packed_count);
|
||||||
|
|||||||
@@ -1068,6 +1068,7 @@ static void place_leaf_circle(int cx, int cy, int cz, int radius, int leaf_block
|
|||||||
int r2 = radius * radius;
|
int r2 = radius * radius;
|
||||||
for (int dx = -radius; dx <= radius; ++dx) {
|
for (int dx = -radius; dx <= radius; ++dx) {
|
||||||
for (int dz = -radius; dz <= radius; ++dz) {
|
for (int dz = -radius; dz <= radius; ++dz) {
|
||||||
|
if (dx == 0 && dz == 0) continue;
|
||||||
if (dx * dx + dz * dz > r2) continue;
|
if (dx * dx + dz * dz > r2) continue;
|
||||||
if (hole_prob > 0.0 && rng_next_f64(rng) < hole_prob) 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);
|
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;
|
uint16_t block = BLOCK_SMOOTH_STONE;
|
||||||
int in_center_corridor = side_dist >= wall_center - 1 && side_dist <= wall_center + 1 &&
|
int in_center_corridor = side_dist >= wall_center - 1 && side_dist <= wall_center + 1 &&
|
||||||
rel_y >= 2 && rel_y <= 4;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (rel_y < 0) {
|
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);
|
set_block_with_height(out, dx, dz, y, block);
|
||||||
}
|
}
|
||||||
if (top + 1 < CHUNK_HEIGHT) {
|
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;
|
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);
|
set_block_with_height(out, dx, dz, top + 1, rail_block);
|
||||||
} else if (in_tower && phase % 4 < 2) {
|
} else if (in_tower && phase % 4 < 2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user