Revamp Chunk Rotaie - test risaie
This commit is contained in:
@@ -3,10 +3,8 @@ extends Node3D
|
||||
@export_group("Riferimenti Base")
|
||||
@export var path_treno: Path3D
|
||||
|
||||
@export_group("I 3 Biomi Principali")
|
||||
@export var bioma_campagna: Array[PackedScene]
|
||||
@export var bioma_foresta: Array[PackedScene]
|
||||
@export var bioma_altro: Array[PackedScene]
|
||||
@export_group("I Tuoi Biomi")
|
||||
@export var lista_biomi: Array[DatiBioma]
|
||||
|
||||
@export_group("Impostazioni Griglia e Aree")
|
||||
@export var dimensione_chunk: float = 20.0
|
||||
@@ -16,30 +14,30 @@ extends Node3D
|
||||
var scacchiera: Dictionary = {}
|
||||
var ultima_pos_griglia_treno: Vector2i = Vector2i(999999, 999999)
|
||||
var generatore_rumore: FastNoiseLite
|
||||
var generatore_altitudine: FastNoiseLite
|
||||
|
||||
var usa_terzo_bioma: bool = true
|
||||
|
||||
# --- VARIABILI PER L'INTERFACCIA A SCHERMO ---
|
||||
var bioma_manuale_attivo: DatiBioma = null
|
||||
var dropdown_biomi: OptionButton
|
||||
var lbl_bioma: Label
|
||||
var lbl_distanza: Label
|
||||
|
||||
func _ready() -> void:
|
||||
if bioma_campagna.is_empty() or path_treno == null:
|
||||
print("❌ ERRORE: Assegna almeno il 'Bioma Campagna' e il 'Path Treno' nell'Inspector!")
|
||||
return
|
||||
if lista_biomi.is_empty() or path_treno == null: return
|
||||
|
||||
generatore_rumore = FastNoiseLite.new()
|
||||
generatore_rumore.noise_type = FastNoiseLite.TYPE_PERLIN
|
||||
generatore_rumore.seed = randi()
|
||||
generatore_rumore.frequency = scala_distretti
|
||||
|
||||
# Creiamo l'interfaccia a schermo!
|
||||
_crea_ui_gps()
|
||||
generatore_altitudine = FastNoiseLite.new()
|
||||
generatore_altitudine.noise_type = FastNoiseLite.TYPE_PERLIN
|
||||
generatore_altitudine.seed = randi()
|
||||
generatore_altitudine.frequency = scala_distretti * 0.5
|
||||
|
||||
print("✅ Generatore a Distretti Dinamici Pronto (Versione Ottimizzata).")
|
||||
print("Premere il tasto 'B' per abilitare/disabilitare il terzo bioma.")
|
||||
_crea_ui_gps()
|
||||
_aggiorna_set_pieces() # Accende/Spegne i mega-templi all'avvio
|
||||
print("✅ Generatore a Distretti Dinamici Pronto.")
|
||||
|
||||
# --- CREA LE SCRITTE A SCHERMO ---
|
||||
func _crea_ui_gps() -> void:
|
||||
var canvas = CanvasLayer.new()
|
||||
canvas.layer = 10
|
||||
@@ -55,7 +53,6 @@ func _crea_ui_gps() -> void:
|
||||
vbox.size_flags_horizontal = Control.SIZE_SHRINK_END
|
||||
margin.add_child(vbox)
|
||||
|
||||
# --- SCRITTA BIOMA ATTUALE (Titolo) ---
|
||||
lbl_bioma = Label.new()
|
||||
lbl_bioma.add_theme_font_size_override("font_size", 10)
|
||||
lbl_bioma.add_theme_color_override("font_color", Color(1, 0.9, 0.4))
|
||||
@@ -64,7 +61,6 @@ func _crea_ui_gps() -> void:
|
||||
lbl_bioma.text = "📍 Avvio GPS..."
|
||||
vbox.add_child(lbl_bioma)
|
||||
|
||||
# --- SCRITTA METRI MANCANTI (Sottotitolo) ---
|
||||
lbl_distanza = Label.new()
|
||||
lbl_distanza.add_theme_font_size_override("font_size", 8)
|
||||
lbl_distanza.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
@@ -72,14 +68,77 @@ func _crea_ui_gps() -> void:
|
||||
lbl_distanza.text = "Calcolo tragitto..."
|
||||
vbox.add_child(lbl_distanza)
|
||||
|
||||
var hbox = HBoxContainer.new()
|
||||
vbox.add_child(hbox)
|
||||
|
||||
dropdown_biomi = OptionButton.new()
|
||||
dropdown_biomi.add_item("Dinamico (Procedurale)")
|
||||
for bioma in lista_biomi:
|
||||
dropdown_biomi.add_item(bioma.nome_bioma)
|
||||
|
||||
dropdown_biomi.item_selected.connect(_on_dropdown_biomi_item_selected)
|
||||
hbox.add_child(dropdown_biomi)
|
||||
|
||||
_radar_bioma_treno()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and event.pressed and not event.echo:
|
||||
if event.keycode == KEY_B:
|
||||
usa_terzo_bioma = !usa_terzo_bioma
|
||||
# E forziamo un aggiornamento del radar per aggiornare le scritte subito
|
||||
_radar_bioma_treno()
|
||||
# --- GESTIONE DEI MEGA-PEZZI (SET PIECES) ---
|
||||
# --- GESTIONE DEI MEGA-PEZZI (SET PIECES) ---
|
||||
func _aggiorna_set_pieces() -> void:
|
||||
var set_pieces = get_tree().get_nodes_in_group("set_pieces")
|
||||
|
||||
print("\n--- CONTROLLO SET PIECES ---")
|
||||
print("🔍 Trovati ", set_pieces.size(), " Set Pieces nel gruppo 'set_pieces'.")
|
||||
|
||||
for sp in set_pieces:
|
||||
if not "bioma_esclusivo" in sp or sp.bioma_esclusivo == "":
|
||||
print("⚠️ Il Set Piece '", sp.name, "' non ha un bioma_esclusivo impostato. Rimarrà sempre visibile.")
|
||||
continue
|
||||
|
||||
var bioma_locale = ""
|
||||
if bioma_manuale_attivo != null:
|
||||
bioma_locale = bioma_manuale_attivo.nome_bioma
|
||||
else:
|
||||
var grid_x = roundi(sp.global_position.x / dimensione_chunk)
|
||||
var grid_z = roundi(sp.global_position.z / dimensione_chunk)
|
||||
bioma_locale = _get_nome_bioma_procedurale(generatore_rumore.get_noise_2d(grid_x, grid_z))
|
||||
|
||||
print("👉 Analizzo: '", sp.name, "' | Vuole il bioma: [", sp.bioma_esclusivo, "] | Il bioma attuale qui è: [", bioma_locale, "]")
|
||||
|
||||
if bioma_locale == sp.bioma_esclusivo:
|
||||
sp.show()
|
||||
sp.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
print(" ✅ CORRISPONDENZA! Il tempio è ORA VISIBILE E SOLIDO.")
|
||||
else:
|
||||
sp.hide()
|
||||
sp.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
print(" ❌ NIENTE CORRISPONDENZA! Il tempio è ORA UN FANTASMA INVISIBILE.")
|
||||
print("----------------------------\n")
|
||||
|
||||
func _on_dropdown_biomi_item_selected(indice: int) -> void:
|
||||
if indice == 0: bioma_manuale_attivo = null
|
||||
else: bioma_manuale_attivo = lista_biomi[indice - 1]
|
||||
|
||||
_distruggi_e_rigenera_mondo()
|
||||
|
||||
func _distruggi_e_rigenera_mondo() -> void:
|
||||
# 1. Spegne i templi vecchi e accende quelli nuovi PRIMA di pulire la memoria
|
||||
_aggiorna_set_pieces()
|
||||
|
||||
# 2. Distrugge fisicamente tutti i modelli 3D dei biomi procedurali
|
||||
for pos in scacchiera.keys():
|
||||
var cella = scacchiera[pos]
|
||||
if cella["tipo"] == "bioma":
|
||||
if cella.has("nodo") and is_instance_valid(cella["nodo"]):
|
||||
cella["nodo"].queue_free()
|
||||
|
||||
# 3. AMNESIA TOTALE: Svuotiamo l'intero dizionario (sia biomi che ostacoli vecchi)
|
||||
scacchiera.clear()
|
||||
|
||||
# 4. Forziamo il treno a sparare i laser e ricreare la mappa al prossimo frame
|
||||
ultima_pos_griglia_treno = Vector2i(999999, 999999)
|
||||
_radar_bioma_treno()
|
||||
ultima_pos_griglia_treno = Vector2i(999999, 999999)
|
||||
_radar_bioma_treno()
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if path_treno == null or path_treno.treno_istanziato == null: return
|
||||
@@ -91,14 +150,8 @@ func _physics_process(_delta: float) -> void:
|
||||
|
||||
if pos_attuale != ultima_pos_griglia_treno:
|
||||
ultima_pos_griglia_treno = pos_attuale
|
||||
|
||||
# 1. Genera i nuovi chunk davanti al treno
|
||||
_genera_attorno_al_treno(pos_attuale)
|
||||
|
||||
# 2. Pulisce i chunk vecchi dietro al treno (OTTIMIZZAZIONE)
|
||||
_pulisci_chunk_lontani(pos_attuale)
|
||||
|
||||
# 3. Aggiorna il GPS a schermo
|
||||
_radar_bioma_treno()
|
||||
|
||||
func _genera_attorno_al_treno(centro: Vector2i) -> void:
|
||||
@@ -112,21 +165,21 @@ func _genera_attorno_al_treno(centro: Vector2i) -> void:
|
||||
_piazza_bioma_compatibile(pos_griglia)
|
||||
|
||||
func _scegli_catalogo_per_cella(pos_griglia: Vector2i) -> Array[PackedScene]:
|
||||
if bioma_manuale_attivo != null:
|
||||
return bioma_manuale_attivo.chunk_disponibili
|
||||
|
||||
var valore = generatore_rumore.get_noise_2d(pos_griglia.x, pos_griglia.y)
|
||||
var nome_bioma_scelto = _get_nome_bioma(valore)
|
||||
|
||||
var catalogo_scelto: Array[PackedScene] = []
|
||||
|
||||
if nome_bioma_scelto == "Campagna": catalogo_scelto = bioma_campagna
|
||||
elif nome_bioma_scelto == "Campagna-Foresta": catalogo_scelto = bioma_campagna if randf() > 0.5 else bioma_foresta
|
||||
elif nome_bioma_scelto == "Foresta": catalogo_scelto = bioma_foresta
|
||||
elif nome_bioma_scelto == "Foresta-Altro": catalogo_scelto = bioma_foresta if randf() > 0.5 else bioma_altro
|
||||
else: catalogo_scelto = bioma_altro
|
||||
var valore_normalizzato = (valore + 1.0) / 2.0
|
||||
var indice = clamp(int(valore_normalizzato * lista_biomi.size()), 0, lista_biomi.size() - 1)
|
||||
return lista_biomi[indice].chunk_disponibili
|
||||
|
||||
func _get_nome_bioma_procedurale(valore: float) -> String:
|
||||
if bioma_manuale_attivo != null:
|
||||
return bioma_manuale_attivo.nome_bioma
|
||||
|
||||
if catalogo_scelto.is_empty():
|
||||
catalogo_scelto = bioma_campagna
|
||||
|
||||
return catalogo_scelto
|
||||
var valore_normalizzato = (valore + 1.0) / 2.0
|
||||
var indice = clamp(int(valore_normalizzato * lista_biomi.size()), 0, lista_biomi.size() - 1)
|
||||
return lista_biomi[indice].nome_bioma
|
||||
|
||||
func _registra_cella_con_laser(pos_griglia: Vector2i) -> bool:
|
||||
if scacchiera.has(pos_griglia): return true
|
||||
@@ -143,88 +196,136 @@ func _registra_cella_con_laser(pos_griglia: Vector2i) -> bool:
|
||||
var collider = result["collider"]
|
||||
var nodo_corrente = collider
|
||||
var uscite_trovate = {"nord": false, "est": false, "sud": false, "ovest": false}
|
||||
var altezze_trovate = {"nord": 0, "est": 0, "sud": 0, "ovest": 0}
|
||||
|
||||
while nodo_corrente != null and nodo_corrente != get_tree().root:
|
||||
if nodo_corrente.has_method("get_uscite_ruotate"):
|
||||
if nodo_corrente.has_method("get_dati_ruotati"):
|
||||
var scatti_rotazione = roundi(rad_to_deg(nodo_corrente.global_rotation.y) / -90.0)
|
||||
uscite_trovate = nodo_corrente.get_uscite_ruotate(scatti_rotazione)
|
||||
var dati = nodo_corrente.get_dati_ruotati(scatti_rotazione)
|
||||
uscite_trovate = dati["connessioni"]
|
||||
altezze_trovate = dati["altezze"]
|
||||
break
|
||||
nodo_corrente = nodo_corrente.get_parent()
|
||||
|
||||
scacchiera[pos_griglia] = {"tipo": "ostacolo", "uscite": uscite_trovate}
|
||||
scacchiera[pos_griglia] = {"tipo": "ostacolo", "uscite": uscite_trovate, "altezze": altezze_trovate}
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func _piazza_bioma_compatibile(pos_griglia: Vector2i) -> void:
|
||||
var req_nord = _richiede_connessione(pos_griglia + Vector2i(0, -1), "sud")
|
||||
var req_est = _richiede_connessione(pos_griglia + Vector2i(1, 0), "ovest")
|
||||
var req_sud = _richiede_connessione(pos_griglia + Vector2i(0, 1), "nord")
|
||||
var req_ovest = _richiede_connessione(pos_griglia + Vector2i(-1, 0), "est")
|
||||
var req_conn_nord = _richiede_connessione(pos_griglia + Vector2i(0, -1), "sud")
|
||||
var req_conn_est = _richiede_connessione(pos_griglia + Vector2i(1, 0), "ovest")
|
||||
var req_conn_sud = _richiede_connessione(pos_griglia + Vector2i(0, 1), "nord")
|
||||
var req_conn_ovest = _richiede_connessione(pos_griglia + Vector2i(-1, 0), "est")
|
||||
|
||||
var req_alt_nord = _richiede_altezza(pos_griglia + Vector2i(0, -1), "sud")
|
||||
var req_alt_est = _richiede_altezza(pos_griglia + Vector2i(1, 0), "ovest")
|
||||
var req_alt_sud = _richiede_altezza(pos_griglia + Vector2i(0, 1), "nord")
|
||||
var req_alt_ovest = _richiede_altezza(pos_griglia + Vector2i(-1, 0), "est")
|
||||
|
||||
var rumore_alt = generatore_altitudine.get_noise_2d(pos_griglia.x, pos_griglia.y)
|
||||
var altitudine_target = clamp(roundi((rumore_alt + 1.0) / 2.0), 0, 1)
|
||||
|
||||
var catalogo_zona = _scegli_catalogo_per_cella(pos_griglia)
|
||||
var candidati = []
|
||||
var candidati_validi = []
|
||||
|
||||
for scena in catalogo_zona:
|
||||
var test_chunk = scena.instantiate()
|
||||
|
||||
if test_chunk.has_method("get_uscite_ruotate"):
|
||||
if test_chunk.has_method("get_dati_ruotati"):
|
||||
for rot in range(4):
|
||||
var u = test_chunk.get_uscite_ruotate(rot)
|
||||
var dati = test_chunk.get_dati_ruotati(rot)
|
||||
var u_conn = dati["connessioni"]
|
||||
var u_alt = dati["altezze"]
|
||||
|
||||
var match_n = (req_nord == -1) or ((req_nord == 1) == u["nord"])
|
||||
var match_e = (req_est == -1) or ((req_est == 1) == u["est"])
|
||||
var match_s = (req_sud == -1) or ((req_sud == 1) == u["sud"])
|
||||
var match_o = (req_ovest == -1) or ((req_ovest == 1) == u["ovest"])
|
||||
var match_conn_n = (req_conn_nord == -1) or ((req_conn_nord == 1) == u_conn["nord"])
|
||||
var match_conn_e = (req_conn_est == -1) or ((req_conn_est == 1) == u_conn["est"])
|
||||
var match_conn_s = (req_conn_sud == -1) or ((req_conn_sud == 1) == u_conn["sud"])
|
||||
var match_conn_o = (req_conn_ovest == -1) or ((req_conn_ovest == 1) == u_conn["ovest"])
|
||||
|
||||
if match_n and match_e and match_s and match_o:
|
||||
candidati.append({"scena": scena, "rotazione": rot, "uscite": u})
|
||||
var match_alt_n = (req_alt_nord == -1) or (req_alt_nord == u_alt["nord"])
|
||||
var match_alt_e = (req_alt_est == -1) or (req_alt_est == u_alt["est"])
|
||||
var match_alt_s = (req_alt_sud == -1) or (req_alt_sud == u_alt["sud"])
|
||||
var match_alt_o = (req_alt_ovest == -1) or (req_alt_ovest == u_alt["ovest"])
|
||||
|
||||
var diff_n = abs(u_alt["nord"] - altitudine_target) if req_alt_nord == -1 else 0
|
||||
var diff_e = abs(u_alt["est"] - altitudine_target) if req_alt_est == -1 else 0
|
||||
var diff_s = abs(u_alt["sud"] - altitudine_target) if req_alt_sud == -1 else 0
|
||||
var diff_o = abs(u_alt["ovest"] - altitudine_target) if req_alt_ovest == -1 else 0
|
||||
var salti_eccessivi = diff_n > 1 or diff_e > 1 or diff_s > 1 or diff_o > 1
|
||||
|
||||
if match_conn_n and match_conn_e and match_conn_s and match_conn_o and match_alt_n and match_alt_e and match_alt_s and match_alt_o and not salti_eccessivi:
|
||||
var score = 0
|
||||
if req_alt_nord == -1 and u_alt["nord"] == altitudine_target: score += 1
|
||||
if req_alt_est == -1 and u_alt["est"] == altitudine_target: score += 1
|
||||
if req_alt_sud == -1 and u_alt["sud"] == altitudine_target: score += 1
|
||||
if req_alt_ovest == -1 and u_alt["ovest"] == altitudine_target: score += 1
|
||||
|
||||
candidati_validi.append({"scena": scena, "rotazione": rot, "dati": dati, "score": score})
|
||||
|
||||
test_chunk.queue_free()
|
||||
|
||||
if candidati.size() > 0:
|
||||
var scelto = candidati.pick_random()
|
||||
if candidati_validi.size() > 0:
|
||||
var max_score = -1
|
||||
for c in candidati_validi:
|
||||
if c.score > max_score: max_score = c.score
|
||||
|
||||
var candidati_migliori = []
|
||||
for c in candidati_validi:
|
||||
if c.score == max_score: candidati_migliori.append(c)
|
||||
|
||||
var scelto = candidati_migliori.pick_random()
|
||||
var nuovo_chunk = scelto.scena.instantiate()
|
||||
add_child(nuovo_chunk)
|
||||
nuovo_chunk.position = Vector3(pos_griglia.x * dimensione_chunk, 0, pos_griglia.y * dimensione_chunk)
|
||||
nuovo_chunk.rotation.y = scelto.rotazione * (-PI / 2.0)
|
||||
|
||||
# MODIFICA: Salviamo il riferimento al nodo per poterlo eliminare in futuro
|
||||
scacchiera[pos_griglia] = {"tipo": "bioma", "uscite": scelto.uscite, "nodo": nuovo_chunk}
|
||||
scacchiera[pos_griglia] = {"tipo": "bioma", "uscite": scelto.dati["connessioni"], "altezze": scelto.dati["altezze"], "nodo": nuovo_chunk}
|
||||
else:
|
||||
push_warning("⚠️ MANCA UN PEZZO IN CATALOGO PER LA POSIZIONE " + str(pos_griglia) + "!")
|
||||
|
||||
var fmt_alt = func(req): return str(req) if req != -1 else "Libero"
|
||||
var fmt_conn = func(req): return "Sì" if req == 1 else ("No" if req == 0 else "Libero")
|
||||
|
||||
print("--- IDENTIKIT DEL PEZZO CHE TI MANCA ---")
|
||||
print("Altezze richieste -> Nord: ", fmt_alt.call(req_alt_nord), " | Est: ", fmt_alt.call(req_alt_est), " | Sud: ", fmt_alt.call(req_alt_sud), " | Ovest: ", fmt_alt.call(req_alt_ovest))
|
||||
print("----------------------------------------\n")
|
||||
|
||||
var backup = catalogo_zona[0].instantiate()
|
||||
add_child(backup)
|
||||
backup.position = Vector3(pos_griglia.x * dimensione_chunk, 0, pos_griglia.y * dimensione_chunk)
|
||||
|
||||
# MODIFICA: Salviamo il riferimento al nodo
|
||||
scacchiera[pos_griglia] = {"tipo": "bioma", "uscite": {"nord":false, "est":false, "sud":false, "ovest":false}, "nodo": backup}
|
||||
var altezze_sicure = {
|
||||
"nord": req_alt_nord if req_alt_nord != -1 else altitudine_target,
|
||||
"est": req_alt_est if req_alt_est != -1 else altitudine_target,
|
||||
"sud": req_alt_sud if req_alt_sud != -1 else altitudine_target,
|
||||
"ovest": req_alt_ovest if req_alt_ovest != -1 else altitudine_target
|
||||
}
|
||||
scacchiera[pos_griglia] = {"tipo": "bioma", "uscite": {"nord":false, "est":false, "sud":false, "ovest":false}, "altezze": altezze_sicure, "nodo": backup}
|
||||
|
||||
func _richiede_connessione(pos_vicino: Vector2i, lato_richiesto: String) -> int:
|
||||
if not scacchiera.has(pos_vicino): _registra_cella_con_laser(pos_vicino)
|
||||
if scacchiera.has(pos_vicino):
|
||||
if not scacchiera.has(pos_vicino):
|
||||
_registra_cella_con_laser(pos_vicino)
|
||||
if scacchiera.has(pos_vicino) and scacchiera[pos_vicino].has("uscite"):
|
||||
return 1 if scacchiera[pos_vicino]["uscite"][lato_richiesto] else 0
|
||||
return -1
|
||||
|
||||
func _get_nome_bioma(valore: float) -> String:
|
||||
if valore < -0.4: return "Campagna"
|
||||
elif valore < -0.15: return "Campagna-Foresta"
|
||||
|
||||
if not usa_terzo_bioma: return "Foresta"
|
||||
|
||||
if valore < 0.15: return "Foresta"
|
||||
elif valore < 0.4: return "Foresta-Altro"
|
||||
else: return "Altro (Deserto/Neve)"
|
||||
func _richiede_altezza(pos_vicino: Vector2i, lato_richiesto: String) -> int:
|
||||
if scacchiera.has(pos_vicino) and scacchiera[pos_vicino].has("altezze"):
|
||||
return scacchiera[pos_vicino]["altezze"][lato_richiesto]
|
||||
return -1
|
||||
|
||||
# --- AGGIORNAMENTO GPS A SCHERMO ---
|
||||
func _radar_bioma_treno() -> void:
|
||||
if path_treno == null or path_treno.curve == null or path_treno.treno_istanziato == null:
|
||||
if path_treno == null or path_treno.curve == null or path_treno.treno_istanziato == null: return
|
||||
|
||||
if bioma_manuale_attivo != null:
|
||||
if lbl_bioma: lbl_bioma.text = bioma_manuale_attivo.nome_bioma
|
||||
if lbl_distanza: lbl_distanza.text = "Override manuale (Infinita)"
|
||||
return
|
||||
|
||||
var pos_treno = path_treno.treno_istanziato.global_position
|
||||
var grid_x = roundi(pos_treno.x / dimensione_chunk)
|
||||
var grid_z = roundi(pos_treno.z / dimensione_chunk)
|
||||
var valore_attuale = generatore_rumore.get_noise_2d(grid_x, grid_z)
|
||||
var bioma_attuale = _get_nome_bioma(valore_attuale)
|
||||
var bioma_attuale = _get_nome_bioma_procedurale(generatore_rumore.get_noise_2d(grid_x, grid_z))
|
||||
|
||||
var progresso_attuale = path_treno.progresso_treno
|
||||
var lunghezza_totale = path_treno.curve.get_baked_length()
|
||||
@@ -238,8 +339,7 @@ func _radar_bioma_treno() -> void:
|
||||
|
||||
var f_x = roundi(pos_futura_globale.x / dimensione_chunk)
|
||||
var f_z = roundi(pos_futura_globale.z / dimensione_chunk)
|
||||
var valore_futuro = generatore_rumore.get_noise_2d(f_x, f_z)
|
||||
var bioma_futuro = _get_nome_bioma(valore_futuro)
|
||||
var bioma_futuro = _get_nome_bioma_procedurale(generatore_rumore.get_noise_2d(f_x, f_z))
|
||||
|
||||
if bioma_futuro != bioma_attuale:
|
||||
distanza_cambio = step * dimensione_chunk
|
||||
@@ -253,30 +353,21 @@ func _radar_bioma_treno() -> void:
|
||||
else:
|
||||
lbl_distanza.text = "Nessun cambio nei prossimi 600m"
|
||||
|
||||
# --- NUOVA FUNZIONE: SPAZZINO DEI CHUNK LONTANI ---
|
||||
func _pulisci_chunk_lontani(centro_attuale: Vector2i) -> void:
|
||||
var celle_da_rimuovere = []
|
||||
var margine_sicurezza = 2 # Eliminiamo solo i chunk fuori dal raggio visivo + 2
|
||||
var margine_sicurezza = 2
|
||||
|
||||
for pos_griglia in scacchiera.keys():
|
||||
var cella = scacchiera[pos_griglia]
|
||||
|
||||
if cella["tipo"] == "ostacolo":
|
||||
continue
|
||||
if cella["tipo"] == "ostacolo": continue
|
||||
|
||||
var dist_x = abs(pos_griglia.x - centro_attuale.x)
|
||||
var dist_z = abs(pos_griglia.y - centro_attuale.y)
|
||||
|
||||
# Se il chunk è troppo lontano dalla telecamera...
|
||||
if dist_x > raggio_visivo + margine_sicurezza or dist_z > raggio_visivo + margine_sicurezza:
|
||||
|
||||
# 1. Distruggiamo il modello 3D per liberare memoria video
|
||||
if cella.has("nodo") and is_instance_valid(cella["nodo"]):
|
||||
cella["nodo"].queue_free()
|
||||
|
||||
# 2. Ci segniamo questa posizione per rimuoverla dalla logica
|
||||
celle_da_rimuovere.append(pos_griglia)
|
||||
|
||||
# 3. Puliamo la scacchiera (liberando memoria RAM)
|
||||
for pos in celle_da_rimuovere:
|
||||
scacchiera.erase(pos)
|
||||
|
||||
Reference in New Issue
Block a user