This commit is contained in:
2026-05-13 17:05:29 +02:00
parent c25e3bb4f6
commit 4658250206
4 changed files with 68 additions and 17 deletions

View File

@@ -25,32 +25,32 @@ const RIVER_NEIGHBOUR_OFFSETS: Dictionary = {
}
@export_group("Rails")
@export var rail_path: Path3D
@export var rail_path: Path3D #rail path
@export_group("Biomes")
@export var biome_list: Array[Biome]
@export var biome_list: Array[Biome] #list of scenes for the biome
@export_group("Grid and Area")
@export var chunk_size: float = 20.0
@export var eye_line: int = 3
@export var district_scale: float = 0.05
@export var chunk_size: float = 20.0 #size of a cell; default 20 (global position is defined dividing x and z for this value)
@export var eye_line: int = 3 #cells to be considerated around the train (e.g. 3 => a square of cells from -3 to 3 around train cell)
@export var district_scale: float = 0.05 #noise value to distribuite biome; low values create large area, high values create biome with more variants
@export_group("Lamppost")
@export var lamppost_wire_material: ShaderMaterial
@export_range(0.01, 1.0) var wire_thickness: float = 0.05
@export var lamppost_dist_factor: int = 10
@export var lamppost_dist_factor: int = 10 #max distance of connections
var board: Dictionary = {}
var last_pos_train: Vector2i = Vector2i(999999, 999999)
var noise_generator: FastNoiseLite
var altitude_generator: FastNoiseLite
var wire_connections: Dictionary = {}
var chunk_candidate_cache: Dictionary = {}
var chunk_candidate_cache: Dictionary = {} #node cache (metadata)
var pending_generation_cells: Array[Vector2i] = []
var pending_cleanup_cells: Array[Vector2i] = []
var pending_wire_cells: Array[Vector2i] = []
var pending_wire_lookup: Dictionary = {}
var rail_chunk_catalogue: Dictionary = {}
var rail_chunk_catalogue: Dictionary = {} #rails chunk list
var manual_biome: Biome = null
@@ -60,6 +60,7 @@ func _ready() -> void:
#connect events
UIEvents.update_rail_chunks.connect(_update_rail_chunks)
#noise generator for biome and altitute
noise_generator = FastNoiseLite.new()
noise_generator.noise_type = FastNoiseLite.TYPE_PERLIN
noise_generator.seed = randi()
@@ -70,8 +71,10 @@ func _ready() -> void:
altitude_generator.seed = randi()
altitude_generator.frequency = district_scale * 0.5
#fill cache with available chunk
_warm_chunk_candidate_cache()
_warm_rail_chunk_catalogue()
#set unique pieces
_update_set_pieces()
func _update_set_pieces() -> void:
@@ -128,6 +131,7 @@ func _destroy_and_regenrate_world() -> void:
_refresh_world(current_pos)
func _process(_delta: float) -> void:
#based on constant values the queue are evalutated by frame and not all together
_drain_cleanup_queue()
_drain_generation_queue()
_drain_wire_queue()
@@ -153,6 +157,15 @@ func collect_all_chunkinfo(root: Node, list: Array[Node]) -> void:
for child in root.get_children():
collect_all_chunkinfo(child, list)
func collect_all_propinfo(root: Node, list: Array[Node]) -> void:
if root == null: return
if "available_props" in root:
list.append(root)
for child in root.get_children():
collect_all_propinfo(child, list)
func _warm_chunk_candidate_cache() -> void:
var unique_scenes: Dictionary = {}
@@ -514,6 +527,30 @@ func _pick_backup_scene(zone_catalogue: Array[PackedScene], grid_pos: Vector2i)
return scene
return zone_catalogue[0]
func _spawn_props_for_chunk(root: Node) -> void:
var prop_markers: Array[Node] = []
collect_all_propinfo(root, prop_markers)
for marker in prop_markers:
_spawn_prop_for_marker(marker)
func _spawn_prop_for_marker(marker: Node) -> void:
if marker.available_props.is_empty():
return
var prop_scene = marker.available_props.pick_random()
if prop_scene == null:
return
var prop_instance = prop_scene.instantiate()
var prop_node = prop_instance as Node3D
if prop_node == null:
prop_instance.queue_free()
return
marker.add_child(prop_node)
prop_node.transform = Transform3D.IDENTITY
func _register_cell_with_ray(grid_pos: Vector2i) -> bool:
if board.has(grid_pos): return true
@@ -681,6 +718,7 @@ func _add_compatible_biome(grid_pos: Vector2i) -> void:
new_chunk.position = Vector3(grid_pos.x * chunk_size, 0, grid_pos.y * chunk_size)
new_chunk.rotation.y = choise.rotation * (-PI / 2.0)
add_child(new_chunk)
_spawn_props_for_chunk(new_chunk)
var info_new = _get_cached_chunk_info(new_chunk, choise.scene)
@@ -711,6 +749,7 @@ func _add_compatible_biome(grid_pos: Vector2i) -> void:
var backup = backup_scene.instantiate()
backup.position = Vector3(grid_pos.x * chunk_size, 0, grid_pos.y * chunk_size)
add_child(backup)
_spawn_props_for_chunk(backup)
var info_backup = _get_cached_chunk_info(backup, backup_scene)
var backup_uniqueness = _get_chunk_uniqueness_from_info(info_backup)

View File

@@ -0,0 +1,4 @@
extends Marker3D
class_name PropInfo
@export var available_props: Array[PackedScene]

View File

@@ -0,0 +1 @@
uid://dg6ngy4pmtsyc

View File

@@ -4,8 +4,10 @@
[ext_resource type="Script" uid="uid://dg2h4kbqe8j3m" path="res://core/biome_generator/chunk_info.gd" id="2_4d433"]
[ext_resource type="Material" uid="uid://blqelpjvdv23j" path="res://tgcc/chunk/material/grassflat_chunk.tres" id="2_ewqv4"]
[ext_resource type="Material" uid="uid://4xhpd6lust7w" path="res://tgcc/chunk/material/path_chunk.tres" id="3_4d433"]
[ext_resource type="Script" uid="uid://dg6ngy4pmtsyc" path="res://core/biome_generator/prop_info.gd" id="3_ckjyx"]
[ext_resource type="Material" uid="uid://ce0bdk3mx2xao" path="res://tgcc/chunk/material/water_chunk.tres" id="4_r06ll"]
[ext_resource type="Material" uid="uid://fnjxocmx16b7" path="res://tgcc/chunk/prop/grass/grass_chunk.tres" id="5_sddh0"]
[ext_resource type="PackedScene" uid="uid://d12t04rs47jq3" path="res://tgcc/chunk/prop/tree/tree_01.tscn" id="5_y2fk3"]
[ext_resource type="Material" uid="uid://jygb1hcokks5" path="res://tgcc/chunk/prop/grass/grass_bank.tres" id="6_ckjyx"]
[ext_resource type="Material" uid="uid://bjrb33qwp1p43" path="res://tgcc/chunk/prop/grass/grass_chunk_weeds.tres" id="7_y2fk3"]
[ext_resource type="Material" uid="uid://0x17mj2v807r" path="res://tgcc/chunk/prop/grass/grass_chunk_weeds2.tres" id="8_vtfy7"]
@@ -52,22 +54,27 @@ have_lamppost = true
connection_left = [NodePath("PaloLuce/sx")]
connection_right = [NodePath("PaloLuce/dx")]
[node name="Argini_001" parent="." index="0" unique_id=439223507]
[node name="Prop1" type="Marker3D" parent="." index="0" unique_id=1846012620]
transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 2.1078086, 4.588761, 4.5396976)
script = ExtResource("3_ckjyx")
available_props = Array[PackedScene]([ExtResource("10_r06ll"), ExtResource("5_y2fk3")])
[node name="Argini_001" parent="." index="1" unique_id=1474838784]
surface_material_override/0 = ExtResource("2_ewqv4")
[node name="Chunk_005" parent="." index="1" unique_id=1955568282]
[node name="Chunk_005" parent="." index="2" unique_id=844192036]
surface_material_override/0 = ExtResource("2_ewqv4")
[node name="Chunk_036" parent="." index="2" unique_id=1808067169 groups=["weather_node"]]
[node name="Chunk_036" parent="." index="3" unique_id=1584066508 groups=["weather_node"]]
surface_material_override/0 = ExtResource("3_4d433")
[node name="Chunk_037" parent="." index="3" unique_id=1338393481 groups=["weather_node"]]
[node name="Chunk_037" parent="." index="4" unique_id=1100757609 groups=["weather_node"]]
surface_material_override/0 = ExtResource("3_4d433")
[node name="Water_003" parent="." index="4" unique_id=1175879696]
[node name="Water_003" parent="." index="5" unique_id=1047599796]
surface_material_override/0 = ExtResource("4_r06ll")
[node name="grass" type="Node3D" parent="." index="5" unique_id=924191951 groups=["weather_vegetables_node", "wind_node"]]
[node name="grass" type="Node3D" parent="." index="6" unique_id=924191951 groups=["weather_vegetables_node", "wind_node"]]
[node name="grass_plane" type="MeshInstance3D" parent="grass" index="0" unique_id=1701437548]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0)
@@ -98,7 +105,7 @@ material_override = ExtResource("8_vtfy7")
cast_shadow = 0
multimesh = SubResource("MultiMesh_sddh0")
[node name="rice" type="Node3D" parent="." index="6" unique_id=318026795 groups=["weather_vegetables_node", "wind_node"]]
[node name="rice" type="Node3D" parent="." index="7" unique_id=318026795 groups=["weather_vegetables_node", "wind_node"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -86.08408, 0, 0)
[node name="rice_plane61" type="MeshInstance3D" parent="rice" index="0" unique_id=1796062490]
@@ -911,7 +918,7 @@ cast_shadow = 0
mesh = SubResource("PlaneMesh_oviqx")
surface_material_override/0 = ExtResource("7_y2fk3")
[node name="PaloLuce" parent="." index="7" unique_id=1607500596 instance=ExtResource("10_r06ll")]
[node name="PaloLuce" parent="." index="8" unique_id=1607500596 instance=ExtResource("10_r06ll")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.4629593, 0, -1.4456635)
[editable path="PaloLuce"]