Loosen trail prepass sampling to guarantee roads

This commit is contained in:
chelsea
2025-12-02 22:31:44 -06:00
parent f1d6bf6434
commit f766a342c2
2 changed files with 12 additions and 9 deletions

Binary file not shown.

View File

@@ -217,9 +217,9 @@ void worldgen_prepass(worldgen_ctx *ctx, int min_x, int max_x, int min_z, int ma
ctx->trail_segment_count = 0; ctx->trail_segment_count = 0;
ctx->trail_segment_cap = 0; ctx->trail_segment_cap = 0;
const int step = 64; const int step = 48;
const int max_points = 64; const int max_points = 128;
const double min_spacing = 96.0; const double min_spacing = 64.0;
int cap = max_points; int cap = max_points;
int count = 0; int count = 0;
int *px = (int *)malloc((size_t)cap * sizeof(int)); int *px = (int *)malloc((size_t)cap * sizeof(int));
@@ -232,7 +232,7 @@ void worldgen_prepass(worldgen_ctx *ctx, int min_x, int max_x, int min_z, int ma
for (int z = min_z; z <= max_z; z += step) { for (int z = min_z; z <= max_z; z += step) {
for (int x = min_x; x <= max_x; x += step) { for (int x = min_x; x <= max_x; x += step) {
double val = land_value(ctx, x, z); double val = land_value(ctx, x, z);
if (val < 0.05) continue; if (val < -0.05) continue;
int spaced = 1; int spaced = 1;
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
double dx = (double)(x - px[i]); double dx = (double)(x - px[i]);
@@ -253,10 +253,10 @@ void worldgen_prepass(worldgen_ctx *ctx, int min_x, int max_x, int min_z, int ma
} }
if (count >= max_points) break; if (count >= max_points) break;
} }
if (count == 0) { if (count < 2) {
px = (int *)realloc(px, sizeof(int)); px = (int *)realloc(px, 2 * sizeof(int));
pz = (int *)realloc(pz, sizeof(int)); pz = (int *)realloc(pz, 2 * sizeof(int));
pv = (double *)realloc(pv, sizeof(double)); pv = (double *)realloc(pv, 2 * sizeof(double));
if (!px || !pz || !pv) { if (!px || !pz || !pv) {
free(px); free(pz); free(pv); free(px); free(pz); free(pv);
return; return;
@@ -264,7 +264,10 @@ void worldgen_prepass(worldgen_ctx *ctx, int min_x, int max_x, int min_z, int ma
px[0] = (min_x + max_x) / 2; px[0] = (min_x + max_x) / 2;
pz[0] = (min_z + max_z) / 2; pz[0] = (min_z + max_z) / 2;
pv[0] = 1.0; pv[0] = 1.0;
count = 1; px[1] = max_x - 16;
pz[1] = max_z - 16;
pv[1] = 0.8;
count = 2;
} }
/* Select hubs: pick top valued, then farthest from existing hubs */ /* Select hubs: pick top valued, then farthest from existing hubs */