Loads of crap

This commit is contained in:
Dan Baker 2025-06-26 14:46:23 +01:00
parent b5bf7619e6
commit 1dc768ad27
725 changed files with 15096 additions and 191 deletions

91
stages/UI/debug_ui.gd Normal file
View file

@ -0,0 +1,91 @@
extends Control
@onready var map_size_label = $PanelContainer/VBoxContainer/MapSizeLabel
@onready var cell_count_label = $PanelContainer/VBoxContainer/CellCountLabel
@onready var loaded_cells_label = $PanelContainer/VBoxContainer/LoadedCellsLabel
@onready var loaded_ojects_label = $PanelContainer/VBoxContainer/LoadedTreesLabel
func _ready() -> void:
update_map_size()
update_cell_count()
func _process(delta: float) -> void:
update_loaded_cells_count()
update_loaded_objects()
func update_map_size() -> void:
map_size_label.text = 'Map Dimensions: ' + str(Global.map_height) + 'x' + str(Global.map_width)
func update_cell_count() -> void:
cell_count_label.text = 'Cell Count: ' + str(Global.map_height * Global.map_width)
func update_loaded_cells_count() -> void:
var actual_tiles = count_actual_tiles_in_scene()
loaded_cells_label.text = 'Loaded chunks: ' + str(%TileGround.loaded_chunks.size()) + '\nActual tiles: ' + str(actual_tiles)
func update_loaded_objects() -> void:
var debug_text = get_object_debug_text()
loaded_ojects_label.text = debug_text
func count_actual_tiles_in_scene() -> int:
var count = 0
var tile_ground = %TileGround
for child in tile_ground.get_children():
if child.name.begins_with("Chunk_"):
count += child.get_child_count()
return count
func get_object_debug_text() -> String:
var text = ""
var total_objects = Performance.get_monitor(Performance.OBJECT_COUNT)
var node_count = Performance.get_monitor(Performance.OBJECT_NODE_COUNT)
var resource_count = Performance.get_monitor(Performance.OBJECT_RESOURCE_COUNT)
var orphan_count = Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT)
text += "Total Objects: " + str(total_objects) + "\n"
text += "Nodes: " + str(node_count) + "\n"
text += "Resources: " + str(resource_count) + "\n"
text += "Orphans: " + str(orphan_count) + "\n"
var scene_nodes = _count_all_nodes(get_tree().root)
var leaked_nodes = node_count - scene_nodes # Better calculation
var other_objects = total_objects - node_count - resource_count
text += "Scene Tree: " + str(scene_nodes) + "\n"
text += "Leaked Nodes: " + str(leaked_nodes) + "\n" # More accurate
text += "Other Objects: " + str(other_objects) + "\n" # Show what else exists
# Memory usage
var static_mem = Performance.get_monitor(Performance.MEMORY_STATIC)
var static_max = Performance.get_monitor(Performance.MEMORY_STATIC_MAX)
text += "Static Mem: " + format_bytes(static_mem) + "\n"
text += "Peak Mem: " + format_bytes(static_max)
return text
func _count_all_nodes(node: Node) -> int:
var count = 1
for child in node.get_children():
count += _count_all_nodes(child)
return count
func format_bytes(bytes: float) -> String:
if bytes < 1024:
return str(int(bytes)) + "B"
elif bytes < 1024 * 1024:
return str(int(bytes / 1024)) + "KB"
else:
return str(int(bytes / (1024 * 1024))) + "MB"
# Add to your debug script
func track_orphan_creation():
# Hook into the scene tree to catch orphan creation
get_tree().node_removed.connect(_on_node_orphaned)
func _on_node_orphaned(node: Node):
print("Orphan created: ", node.name, " (", node.get_class(), ")")
if node.get_script():
print(" Script: ", node.get_script().resource_path)

View file

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