4.7 KiB
4.7 KiB
MapGenerator.cs - Architecture & Historical Decisions
Date: March 2026 Purpose: Generates a 4096x4096 2D topographical blueprint (Topography, Biomes, Cities, and Road Networks) to be parsed and translated into a 3D Voxel World.
1. Topography & The Impact Crater
- Base Generation: Uses
FastNoiseLiteto generate standard heightmaps and temperature maps, which drive dynamic biomes. - Dynamic Sea Level: Sea level is calculated based on the temperature map (simulating ice caps/equatorial swelling).
- The Crater: A massive (radius 400) blast zone is forced along the northern coast. Surrounding it is a
Biome.Wastelandwith a noise-driven "fray" on its borders. - Design Choice: We allowed the crater to occasionally spawn slightly inland rather than strictly on the beach. This creates natural topographical "pinch points" that will result in highly memorable, claustrophobic 3D driving mechanics.
2. City Placement & The Capitol Tether
- The Challenge: The Capitol City must spawn inside the radioactive Wasteland, but it MUST be connected to the contiguous mainland for the A* highway to reach it. Early iterations spawned the Capitol underwater or stranded it on offshore islands caused by the Wasteland noise bleeding over the ocean.
- The Solution (Smart Tiered Spawner): We abandoned a rigid
whileloop in favor of a tiered attempt system.- Tier 1: Searches for ideal (Wasteland + Coastal + Mainland).
- Tier 2: Relaxes the coastal requirement.
- Tier 3: Scans the entire array for the closest valid pixel to the impact center.
- Tier 4 (Doomsday): Walks strictly south until it hits the mainland.
3. The Pathfinding Wars (A* Road Optimization)
The road network generation was the hardest logistical hurdle. Standard grid-based AStarGrid2D math does not scale cleanly to a 4096 map.
Phase 1: The 16-Minute Bottleneck
- The Flaw: To force the highway to create a large loop connecting our 3 Hubs, we used an
ApplyRepulsionfunction that penalized pixels in a 400px radius around the first drawn road. - The Math: Repelling a 2,000-point path with a 400px radius resulted in over 1.3 Billion nested loop iterations. The CPU choked, and generation took 11–16 minutes.
- The Result: Unusable generation times, extreme stair-stepping (zig-zagging), and roads cutting straight over mountains.
Phase 2: The Speedrun & The Double-Back
- The Flaw: We ripped out the repulsion completely to save CPU time, dropping the render to 1 minute.
- The Result: Because A* is deterministic, the pathfinder just used the exact same pixels to return to the start, completely breaking the 3-point loop and causing the highway to double back on itself.
Phase 3: The Over-Engineered Spaghetti (The LLM Trap)
- The Flaw: We brought in an external LLM to fix the pathing. It introduced a "Midland Sweet Spot" to force roads off the coast, and a "Daisy-Chain" mechanic for branch roads.
- The Result: The highway started tracing narrow elevation contour lines like a drunk driver. The branch roads turned into a game of "Snake," meandering wildly to connect to each other instead of taking logical paths to the highway. Furthermore, adding a soft weight to the crater combined with our loop repulsion created a "Wasteland Phobia" where the A* algorithm mathematically folded and refused to complete the loop.
Phase 4: The Tactical Revert (Our Final State)
We executed a deliberate tactical revert, stripping out the over-engineered LLM spaghetti and keeping only robust, simple math:
- Direct Branches: Black roads path directly to the closest highway pixel. No daisy-chaining.
- The Iron Curtain Repulsion: We restored a
+10000fpenalty to old highway segments with a radius of 120px to physically force the 3-point loop. We optimized it by only applying the penalty to everystep(half the radius) pixel. Render time remains at ~1 minute. - Simple Elevation Weights: Instead of a complex U-curve, we use
Mathf.Pow(normalizedElevation, 3.0f) * 400.0fto aggressively punish mountains, and a flat+15.0fpenalty to gently push roads off the beach sand.
4. The AAA Smoothing Pipeline
Standard A* creates jagged, octagonal stair-steps that look terrible in a 3D voxel world. We completely eradicated this using a 2-step geometric smoothing pipeline:
- Ramer-Douglas-Peucker (RDP): Decimates the raw A* path, removing thousands of useless straight-line grid points and leaving only the major turns.
- Chaikin's Algorithm: Performs 4 passes of corner-cutting on the decimated points, resulting in buttery-smooth, sweeping, AAA-style highway curves ready for 3D mesh generation.