Drive planets from definitions

This commit is contained in:
Loïc Wisniewski 2026-08-14 16:13:24 +02:00
commit 02643c76c4
22 changed files with 183 additions and 82 deletions

View file

@ -1,6 +1,8 @@
class_name WorldGen
extends RefCounted
const PLANET_DEFINITIONS = preload("res://PlanetDefinitions.gd")
# Deterministic procedural world generation: the world is divided into
# square chunks, and each chunk's biome is derived from a seeded
# low-frequency noise field sampled at the chunk's own coordinates - so
@ -22,13 +24,6 @@ const GAS_GIANT_THRESHOLD: float = 0.55
const NEARBY_GAS_GIANT_CHUNK: Vector2i = Vector2i.ZERO
const NEARBY_GAS_GIANT_LOCAL_POS: Vector2 = Vector2(900.0, 600.0)
const PLANET_NAMES: Array = [
"Kepler's Rest", "Ceres Minor", "Vesta's Shadow", "Ironhold",
"Drift Anchor", "Stonefall", "Grey Watch", "Silent Quarry",
"Baros Rock", "Umbra Point",
]
const GAS_GIANT_NAMES: Array = ["Aurelia", "Boreas", "Cerulean Deep", "Helios Major", "Vesper"]
static var _noise: FastNoiseLite
static var _planet_noise: FastNoiseLite
@ -88,16 +83,16 @@ static func planet_data_at_chunk(chunk: Vector2i) -> Dictionary:
var guaranteed_nearby_giant: bool = chunk == NEARBY_GAS_GIANT_CHUNK
var local_pos: Vector2 = NEARBY_GAS_GIANT_LOCAL_POS if guaranteed_nearby_giant \
else Vector2(rng.randf() * CHUNK_SIZE, rng.randf() * CHUNK_SIZE)
var planet_name: String = PLANET_NAMES[rng.randi() % PLANET_NAMES.size()]
var shape_seed: int = rng.randi()
# A stable per-chunk roll makes gas giants persistent landmarks rather
# than a different resource whenever the scene reloads.
var gas_giant: bool = guaranteed_nearby_giant or biome_at_chunk(chunk) == Biome.SPACE
if gas_giant:
planet_name = GAS_GIANT_NAMES[rng.randi() % GAS_GIANT_NAMES.size()]
var definition_id: String = PLANET_DEFINITIONS.GAS_GIANT_ID if gas_giant else PLANET_DEFINITIONS.ROCKY_ID
var definition: Resource = PLANET_DEFINITIONS.get_definition(definition_id)
var names: PackedStringArray = definition.names
var planet_name: String = names[rng.randi() % names.size()]
return {"local_pos": local_pos, "name": planet_name, "shape_seed": shape_seed,
"planet_type": "gas_giant" if gas_giant else "rocky", "resource_type": "gas" if gas_giant else "ore",
"surface_profile_id": "gas" if gas_giant else "rocky"}
"definition_id": definition_id}
static func biome_color(biome: int) -> Color: