refactor(autoloads): ♻️ Optimize ecology data loading performance by decoupling redundancy and improving resource loading sequences

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-04-16 23:14:46 -07:00
parent 53135542b5
commit 11426744df
2 changed files with 23 additions and 4 deletions

View file

@ -440,6 +440,7 @@ func get_social_policies() -> Dictionary:
# -- Ecology: delegated to _ecology (data_loader_ecology.gd) --
func get_biome(id: String) -> Variant: return _ecology.get_biome(id)
func get_biome_collectibles(id: String) -> Array: return _ecology.get_biome_collectibles(id)
func get_all_biomes() -> Array: return _ecology.get_all_biomes()
func get_flora_profile(biome_id: String) -> Variant: return _ecology.get_flora_profile(biome_id)
func get_substrate(id: String) -> Variant: return _ecology.get_substrate(id)

View file

@ -18,8 +18,9 @@ const AirFaunaScript = preload("res://engine/src/models/world/air_fauna.gd")
## Back-reference to _raw on the parent DataLoader (set by DataLoader after construction).
var _raw: Dictionary = {}
var _biomes: Dictionary = {} # id -> BiomeModel
var _flora_profiles: Dictionary = {} # biome_id -> FloraProfile
var _biomes: Dictionary = {} # id -> BiomeModel
var _biome_collectibles: Dictionary = {} # id -> Array of collectible entry Dictionaries
var _flora_profiles: Dictionary = {} # biome_id -> FloraProfile
var _substrates: Dictionary = {} # id -> SubstrateType
var _marine_fauna: Variant = null # MarineFaunaModel
var _land_fauna: Variant = null # LandFaunaModel
@ -28,6 +29,7 @@ var _air_fauna: Variant = null # AirFaunaModel
func clear() -> void:
_biomes.clear()
_biome_collectibles.clear()
_flora_profiles.clear()
_substrates.clear()
_marine_fauna = null
@ -58,6 +60,11 @@ func get_all_biomes() -> Array:
return _biomes.values()
func get_biome_collectibles(id: String) -> Array:
## Returns the raw collectibles Array for a biome, or empty if none.
return _biome_collectibles.get(id, [])
func get_flora_profile(biome_id: String) -> Variant:
## Returns a FloraProfile for the given biome or null if not found.
return _flora_profiles.get(biome_id)
@ -174,6 +181,7 @@ func register_collection_biome(biome_data: Dictionary) -> void:
if _biomes.has(biome_id):
return # game-pack biome takes precedence over collection
_biomes[biome_id] = BiomeModelScript.from_dict(biome_data)
_store_collectibles(biome_id, biome_data)
# Build flora profile if this biome has vegetation
var climax: Dictionary = biome_data.get("flora_climax", {})
if climax.get("canopy", 0.0) > 0.0 or climax.get("undergrowth", 0.0) > 0.0:
@ -208,15 +216,25 @@ func _deserialize_biomes() -> void:
if entry is Dictionary:
if not entry.has("id"):
entry["id"] = key
_biomes[entry.get("id", key)] = BiomeModelScript.from_dict(entry)
var bid: String = entry.get("id", key)
_biomes[bid] = BiomeModelScript.from_dict(entry)
_store_collectibles(bid, entry)
elif biomes_data is Array:
for entry: Variant in biomes_data:
if entry is Dictionary and entry.has("id"):
_biomes[entry["id"]] = BiomeModelScript.from_dict(entry)
var bid: String = entry["id"]
_biomes[bid] = BiomeModelScript.from_dict(entry)
_store_collectibles(bid, entry)
if _biomes.size() > 0:
print("DataLoader: Deserialized %d biome models" % _biomes.size())
func _store_collectibles(biome_id: String, entry: Dictionary) -> void:
var raw: Array = entry.get("collectibles", [])
if not raw.is_empty():
_biome_collectibles[biome_id] = raw
func _deserialize_flora_profiles() -> void:
var raw_flora: Dictionary = _raw.get("world_flora", {})
for biome_id: String in _biomes: