Prep for trail prepass and deepen cabin-to-trail search

This commit is contained in:
chelsea
2025-12-02 22:08:52 -06:00
parent 39a44adcfa
commit 317a3f0dcc
2 changed files with 31 additions and 0 deletions

View File

@@ -72,9 +72,12 @@ typedef struct {
struct trail_segment *trail_segments;
size_t trail_segment_count;
size_t trail_segment_cap;
int prepass_done;
int prepass_min_x, prepass_max_x, prepass_min_z, prepass_max_z;
} worldgen_ctx;
void worldgen_init(worldgen_ctx *ctx, int world_seed, int sea_level, int snow_line);
void worldgen_generate_chunk(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *out);
void worldgen_prepass(worldgen_ctx *ctx, int min_x, int max_x, int min_z, int max_z);
#endif

View File

@@ -130,6 +130,7 @@ static void generate_chunk_trails(worldgen_ctx *ctx, int chunk_x, int chunk_z, c
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 ensure_trail_prepass(worldgen_ctx *ctx, int chunk_x, int chunk_z);
static void trail_node_position(worldgen_ctx *ctx, int node_x, int node_z, double spacing, double *out_x, double *out_z);
static void carve_trail_pad(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *out, column_data columns[CHUNK_SIZE][CHUNK_SIZE], int center_x, int center_z, int radius, int target_height);
static void carve_trail_span(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *out, column_data columns[CHUNK_SIZE][CHUNK_SIZE], int x0, int z0, int x1, int z1, int width);
@@ -154,6 +155,30 @@ static uint32_t hash_coords3(int x, int y, int z, uint32_t seed) {
return h ^ (h >> 16);
}
static double land_value(worldgen_ctx *ctx, int x, int z) {
column_data col = get_column_data(ctx, x, z);
double value = 0.0;
double ore_bonus = 0.0;
for (int y = 1; y < col.height - 3; y += 6) {
if (generate_coal(ctx, x, y, z, col.height, col.biome)) {
ore_bonus += 0.08;
}
uint16_t ore = generate_normal_ores(ctx, x, y, z, &col);
if (ore != BLOCK_STONE) ore_bonus += 0.05;
}
value += ore_bonus;
if (col.biome == BIOME_OLD_GROWTH_PLAINS) value += 0.2;
if (col.biome == BIOME_WEST_KY_COALFIELDS) value += 0.1;
if (col.has_water && col.height >= col.water_surface - 2 && col.height <= col.water_surface + 2) {
value += 0.12;
}
int slope = ground_slope(ctx, x, z);
value -= clamp01((double)slope / 6.0) * 0.15;
double noise = simplex_noise2(&ctx->noise, x * 0.0015, z * 0.0015) * 0.5 + 0.5;
value += (noise - 0.5) * 0.08;
return value;
}
static void set_block_with_height(chunk_data *chunk, int local_x, int local_z, int y, uint16_t id) {
if (local_x < 0 || local_x >= CHUNK_SIZE || local_z < 0 || local_z >= CHUNK_SIZE) return;
if (y < 0 || y >= CHUNK_HEIGHT) return;
@@ -2659,6 +2684,9 @@ void worldgen_init(worldgen_ctx *ctx, int world_seed, int sea_level, int snow_li
ctx->trail_segments = NULL;
ctx->trail_segment_count = 0;
ctx->trail_segment_cap = 0;
ctx->prepass_done = 0;
ctx->prepass_min_x = ctx->prepass_max_x = 0;
ctx->prepass_min_z = ctx->prepass_max_z = 0;
simplex_init(&ctx->noise, (uint32_t)world_seed);
}