Simplify trail prepass network and raise slope cost

This commit is contained in:
chelsea
2025-12-02 22:44:26 -06:00
parent e0151c626b
commit 8edafec024
2 changed files with 16 additions and 18 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 = 48; const int step = 96;
const int max_points = 128; const int max_points = 32;
const double min_spacing = 64.0; const double min_spacing = 160.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));
@@ -271,8 +271,8 @@ void worldgen_prepass(worldgen_ctx *ctx, int min_x, int max_x, int min_z, int ma
} }
/* Select hubs: pick top valued, then farthest from existing hubs */ /* Select hubs: pick top valued, then farthest from existing hubs */
const int max_hubs = 3; const int max_hubs = 2;
int hub_indices[3] = {0, 0, 0}; int hub_indices[2] = {0, 0};
int hub_count = 0; int hub_count = 0;
int first = 0; int first = 0;
for (int i = 1; i < count; ++i) { for (int i = 1; i < count; ++i) {
@@ -303,17 +303,15 @@ void worldgen_prepass(worldgen_ctx *ctx, int min_x, int max_x, int min_z, int ma
} }
} }
/* Connect hubs together */ /* Connect hubs together (if two hubs exist) */
for (int i = 0; i < hub_count; ++i) { if (hub_count == 2) {
for (int j = i + 1; j < hub_count; ++j) { int *pts = NULL;
int *pts = NULL; int path_count = 0;
int path_count = 0; if (build_trail_path(ctx, (double)px[hub_indices[0]], (double)pz[hub_indices[0]],
if (build_trail_path(ctx, (double)px[hub_indices[i]], (double)pz[hub_indices[i]], (double)px[hub_indices[1]], (double)pz[hub_indices[1]], &pts, &path_count) && pts && path_count >= 2) {
(double)px[hub_indices[j]], (double)pz[hub_indices[j]], &pts, &path_count) && pts && path_count >= 2) { append_trail_segment(ctx, px[hub_indices[0]], pz[hub_indices[0]], px[hub_indices[1]], pz[hub_indices[1]], pts, path_count);
append_trail_segment(ctx, px[hub_indices[i]], pz[hub_indices[i]], px[hub_indices[j]], pz[hub_indices[j]], pts, path_count); } else {
} else { free(pts);
free(pts);
}
} }
} }
@@ -2622,9 +2620,9 @@ static int build_trail_path(worldgen_ctx *ctx, double ax, double az, double bx,
if (used[ni]) continue; if (used[ni]) continue;
double next_height = heights[ni]; double next_height = heights[ni];
double slope = fabs(next_height - current_height); double slope = fabs(next_height - current_height);
if (slope > 3.5) continue; if (slope > 3.0) continue;
double base_cost = (neighbors[n][0] == 0 || neighbors[n][1] == 0) ? 1.0 : 1.41421356237; double base_cost = (neighbors[n][0] == 0 || neighbors[n][1] == 0) ? 1.0 : 1.41421356237;
double cost = base_cost * (1.0 + slope * 4.0); double cost = base_cost * (1.0 + slope * 6.0);
if (dist[current] + cost < dist[ni]) { if (dist[current] + cost < dist[ni]) {
dist[ni] = dist[current] + cost; dist[ni] = dist[current] + cost;
prev[ni] = current; prev[ni] = current;