W3: Chunked terrain mesh, collision and LOD
TerrainView draws the island as 16 x 16 chunks of 64 m, each at one of four detail levels (2, 4, 8 and 16 m spacing) chosen by distance to the camera. TerrainChunkBuilder builds chunk geometry on WorkerThreadPool threads; the main thread only uploads finished meshes, within a 2 ms per-frame budget, nearest chunks first. - Seams: every chunk hangs skirts deeper than twice the most any level strays from the full-resolution edge, so neighbours at any two levels meet without a crack. Normals come from the full-resolution heightfield at every level, and back faces light like the ground above them. - Splat material: a procedural shader blends sand, marsh, grass and rock with weights from the island's bands, averaged over 4 m so borders blend. Steep ground turns to rock and summits weather pale. - Collision stays SimGround's heightfield, with no renderer involved. - Capture scenarios terrain, terrain_lod (tinted by level) and terrain_cracks (magenta sky). tools/crack_check.gd counts sky pixels seen through the ground; make terrain-capture requires cracks in a skirtless control and none in the real terrain. Tests: chunk vertices sit on the heightfield; skirts cover every pairing of levels on sampled shared edges; detail falls with distance; flying across the island at 30 m/s for 2,037 frames streams 661 chunk rebuilds with the worst main-thread frame at 0.8 to 1.4 ms (headless, CPU only); 24 players over 900 ticks on two generated islands never sink into the ground, and a player sprints up towards a summit unharmed. make terrain-capture: control 437 crack pixels, terrain 0. Closes #10 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
extends TestCase
|
||||
|
||||
## Character movement on generated islands, in the headless simulation with no renderer:
|
||||
## the server's collision is SimGround's heightfield, never a render mesh.
|
||||
|
||||
const TICKS: int = 900
|
||||
|
||||
|
||||
func test_players_never_sink_into_generated_terrain() -> void:
|
||||
for seed_value: int in [11, 12]:
|
||||
var sim: Simulation = Simulation.new(seed_value)
|
||||
var random: RandomNumberGenerator = RandomNumberGenerator.new()
|
||||
random.seed = seed_value
|
||||
var ids: Array[int] = []
|
||||
for _index: int in 12:
|
||||
ids.append(sim.add_player())
|
||||
var grounded: int = 0
|
||||
var samples: int = 0
|
||||
for _tick: int in TICKS:
|
||||
for id: int in ids:
|
||||
var move: Vector2 = Vector2(random.randf_range(-1.0, 1.0), random.randf_range(-1.0, 1.0))
|
||||
var buttons: int = PlayerCommand.BUTTON_SPRINT if random.randf() < 0.5 else 0
|
||||
if random.randf() < 0.004:
|
||||
buttons |= PlayerCommand.BUTTON_JUMP
|
||||
sim.submit_command(id, PlayerCommand.from_input(sim.tick, move, random.randf() * TAU, 0.0, buttons))
|
||||
sim.step()
|
||||
for id: int in ids:
|
||||
var player: SimEntity = sim.entities.find(id)
|
||||
var floor_height: float = sim.ground.terrain_height(player.position.x, player.position.z)
|
||||
assert_true(player.position.y >= floor_height - 0.01,
|
||||
"seed %d player %d sank to %.2f below ground at %s" % [seed_value, id, floor_height - player.position.y, player.position])
|
||||
assert_false(is_nan(player.position.length()), "position became NaN")
|
||||
samples += 1
|
||||
if player.on_ground:
|
||||
grounded += 1
|
||||
assert_true(grounded > samples * 0.7, "seed %d: players grounded only %d of %d ticks" % [seed_value, grounded, samples])
|
||||
|
||||
|
||||
func test_walking_up_to_a_summit_and_back_down() -> void:
|
||||
# Head straight for the tallest summit from the plateau below it, then walk away.
|
||||
var sim: Simulation = Simulation.new(21)
|
||||
var id: int = sim.add_player()
|
||||
var player: SimEntity = sim.entities.find(id)
|
||||
var summit: Vector3 = sim.island.summits[0]
|
||||
var start: Vector2 = Vector2(summit.x, summit.z) + Vector2(150.0, 0.0)
|
||||
player.position = Vector3(start.x, sim.ground.terrain_height(start.x, start.y), start.y)
|
||||
var lowest_start: float = player.position.y
|
||||
var highest: float = player.position.y
|
||||
for _tick: int in 60 * Tuning.TICK_RATE_HZ:
|
||||
var towards: Vector2 = Vector2(summit.x - player.position.x, summit.z - player.position.z)
|
||||
if towards.length() < 3.0:
|
||||
break
|
||||
var yaw: float = atan2(towards.x, towards.y)
|
||||
sim.submit_command(id, PlayerCommand.from_input(sim.tick, Vector2(0.0, 1.0), yaw, 0.0, PlayerCommand.BUTTON_SPRINT))
|
||||
sim.step()
|
||||
highest = maxf(highest, player.position.y)
|
||||
assert_true(highest > lowest_start + 15.0,
|
||||
"climbed only from %.1f to %.1f m towards a %.1f m summit" % [lowest_start, highest, summit.y])
|
||||
assert_true(highest <= sim.island.max_height() + 0.01, "rose above the highest ground without jumping")
|
||||
assert_eq(player.health, Tuning.PLAYER_MAX_HEALTH, "walking the hills must not hurt")
|
||||
Reference in New Issue
Block a user