Implements procedural ground tile generation
Adds procedural ground tile generation with chunking for improved performance. Includes: - Ground tile entity with debug text and cell information - Grass and tree placement based on cell data - Ground shader for visual representation - Chunk loading and unloading system based on player position
This commit is contained in:
parent
95665f54eb
commit
b5bf7619e6
21 changed files with 532 additions and 149 deletions
50
Entities/GroundTile/scripts/grass.gd
Normal file
50
Entities/GroundTile/scripts/grass.gd
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# GrassController.gd
|
||||
extends Node3D
|
||||
class_name GrassController
|
||||
|
||||
# 229379
|
||||
|
||||
var parent_node: GroundTile = null
|
||||
var grass_density: float = 0.5
|
||||
var grass_instance_range: int = 10
|
||||
|
||||
signal grass_data_ready()
|
||||
|
||||
func _ready() -> void:
|
||||
# Use call_deferred to ensure parent is fully ready
|
||||
call_deferred("_setup_connections")
|
||||
|
||||
func _setup_connections() -> void:
|
||||
parent_node = get_parent() as GroundTile
|
||||
if parent_node == null:
|
||||
Log.pr("Error: Parent node is not a GroundTile!")
|
||||
return
|
||||
|
||||
parent_node.cell_info_updated.connect(_on_parent_data_changed)
|
||||
|
||||
# Check if cell_info already exists and process it
|
||||
if parent_node.cell_info != null:
|
||||
_on_parent_data_changed(parent_node.cell_info)
|
||||
|
||||
func _on_parent_data_changed(value):
|
||||
if value == null:
|
||||
return
|
||||
|
||||
grass_density = value.vegetation_density
|
||||
|
||||
update_grass_density()
|
||||
|
||||
grass_data_ready.emit()
|
||||
|
||||
func update_grass_density() -> void:
|
||||
if parent_node == null or parent_node.rng == null:
|
||||
return
|
||||
|
||||
if grass_density > 0.8:
|
||||
grass_instance_range = parent_node.rng.randi_range(100, 500)
|
||||
elif grass_density > 0.6:
|
||||
grass_instance_range = parent_node.rng.randi_range(30, 50)
|
||||
elif grass_density > 0.3:
|
||||
grass_instance_range = parent_node.rng.randi_range(5, 20)
|
||||
else:
|
||||
grass_instance_range = parent_node.rng.randi_range(0, 1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue