Add generated area border wall option

This commit is contained in:
chelsea
2026-05-02 19:26:44 -05:00
parent 1addbada63
commit f423c046ac
3 changed files with 70 additions and 1 deletions

View File

@@ -138,6 +138,7 @@ static void generate_chunk_redwood_floor(worldgen_ctx *ctx, int chunk_x, int chu
static void generate_chunk_grass(worldgen_ctx *ctx, int chunk_x, int chunk_z, column_data columns[CHUNK_SIZE][CHUNK_SIZE], chunk_data *out);
static void generate_chunk_flowers(worldgen_ctx *ctx, int chunk_x, int chunk_z, column_data columns[CHUNK_SIZE][CHUNK_SIZE], chunk_data *out);
static void generate_chunk_cabins(worldgen_ctx *ctx, int chunk_x, int chunk_z, column_data columns[CHUNK_SIZE][CHUNK_SIZE], chunk_data *out);
static void generate_chunk_border_wall(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *out);
static void ensure_trail_prepass(worldgen_ctx *ctx, int chunk_x, int chunk_z);
static void append_trail_segment(worldgen_ctx *ctx, int ax, int az, int bx, int bz, int *points, int count);
static int *smooth_trail_polyline(worldgen_ctx *ctx, int *points, int count, int *out_count);
@@ -3553,6 +3554,47 @@ static void generate_chunk_trails(worldgen_ctx *ctx, int chunk_x, int chunk_z, c
}
}
static void generate_chunk_border_wall(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *out) {
if (!ctx->enable_wall) return;
if (ctx->wall_min_x > ctx->wall_max_x || ctx->wall_min_z > ctx->wall_max_z) return;
const int wall_height = 9;
for (int dx = 0; dx < CHUNK_SIZE; ++dx) {
for (int dz = 0; dz < CHUNK_SIZE; ++dz) {
int world_x = chunk_x * CHUNK_SIZE + dx;
int world_z = chunk_z * CHUNK_SIZE + dz;
if (world_x < ctx->wall_min_x || world_x > ctx->wall_max_x) continue;
if (world_z < ctx->wall_min_z || world_z > ctx->wall_max_z) continue;
int on_border = world_x == ctx->wall_min_x || world_x == ctx->wall_max_x ||
world_z == ctx->wall_min_z || world_z == ctx->wall_max_z;
if (!on_border) continue;
column_data data = get_column_data(ctx, world_x, world_z);
int visible_base = data.height;
if (data.has_water && data.water_surface > visible_base) {
visible_base = data.water_surface;
}
if (visible_base >= CHUNK_HEIGHT - 1) continue;
int top = visible_base + wall_height;
if (top >= CHUNK_HEIGHT) top = CHUNK_HEIGHT - 1;
for (int y = data.height + 1; y < CHUNK_HEIGHT; ++y) {
out->blocks[y][dx][dz] = BLOCK_AIR;
}
out->heightmap[dx][dz] = (uint16_t)data.height;
int start = data.height + 1;
if (start < 1) start = 1;
for (int y = start; y <= top; ++y) {
uint16_t block = (y == top) ? BLOCK_OAK_PLANKS : BLOCK_STONE;
set_block_with_height(out, dx, dz, y, block);
}
}
}
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
@@ -3561,6 +3603,9 @@ void worldgen_init(worldgen_ctx *ctx, int world_seed, int sea_level, int snow_li
ctx->sea_level = sea_level;
ctx->snow_line = snow_line;
ctx->enable_trails = 0;
ctx->enable_wall = 0;
ctx->wall_min_x = ctx->wall_max_x = 0;
ctx->wall_min_z = ctx->wall_max_z = 0;
ctx->trail_segments = NULL;
ctx->trail_segment_count = 0;
ctx->trail_segment_cap = 0;
@@ -3650,4 +3695,6 @@ void worldgen_generate_chunk(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_
}
}
block_list_free(&trees);
generate_chunk_border_wall(ctx, chunk_x, chunk_z, out);
}