From 721b2f4543c4bb656c053e0de162221ceb5d539f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 27 Sep 2025 21:04:30 +0200 Subject: Add debug pie for node counts --- client/gui/overlays/debug.gd | 39 ----------- client/gui/overlays/debug.gd.uid | 1 - client/gui/overlays/debug.tscn | 26 ------- client/gui/overlays/debug/debug.gd | 39 +++++++++++ client/gui/overlays/debug/debug.gd.uid | 1 + client/gui/overlays/debug/debug.tscn | 43 ++++++++++++ client/gui/overlays/debug/debug_pie.gd | 108 +++++++++++++++++++++++++++++ client/gui/overlays/debug/debug_pie.gd.uid | 1 + client/gui/overlays/debug/pie.tscn | 9 +++ client/gui/overlays/overlays.tscn | 2 +- 10 files changed, 202 insertions(+), 67 deletions(-) delete mode 100644 client/gui/overlays/debug.gd delete mode 100644 client/gui/overlays/debug.gd.uid delete mode 100644 client/gui/overlays/debug.tscn create mode 100644 client/gui/overlays/debug/debug.gd create mode 100644 client/gui/overlays/debug/debug.gd.uid create mode 100644 client/gui/overlays/debug/debug.tscn create mode 100644 client/gui/overlays/debug/debug_pie.gd create mode 100644 client/gui/overlays/debug/debug_pie.gd.uid create mode 100644 client/gui/overlays/debug/pie.tscn (limited to 'client/gui') diff --git a/client/gui/overlays/debug.gd b/client/gui/overlays/debug.gd deleted file mode 100644 index 3a37a1b7..00000000 --- a/client/gui/overlays/debug.gd +++ /dev/null @@ -1,39 +0,0 @@ -# Hurry Curry! - a game about cooking -# Copyright (C) 2025 Hurry Curry! contributors -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, version 3 of the License only. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -extends RichTextLabel - -func _ready(): - Settings.hook_changed_init("graphics.debug_info", "main", func (v): - visible = v - RenderingServer.viewport_set_measure_render_time(get_viewport().get_viewport_rid(), visible) - ) - -func _process(_delta): - if not visible: return - var t = "" - t += " Renderer: %s (%s)\n" % [RenderingServer.get_current_rendering_driver_name(), RenderingServer.get_video_adapter_name()] - t += " Timing: %.01fms CPU; %.01fms GPU\n" % [ - RenderingServer.viewport_get_measured_render_time_cpu(get_viewport().get_viewport_rid()), - RenderingServer.viewport_get_measured_render_time_gpu(get_viewport().get_viewport_rid()) - ] - t += " Resolution: %dx%d\n" % [get_tree().root.size.x, get_tree().root.size.y] - t += " FPS: %d\n" % Engine.get_frames_per_second() - t += " Node count: %d\n" % get_tree().get_node_count() - text = t - -func _input(_event): - if Input.is_action_just_pressed("toggle_debug"): - Settings.write("graphics.debug_info", not Settings.read("graphics.debug_info")) diff --git a/client/gui/overlays/debug.gd.uid b/client/gui/overlays/debug.gd.uid deleted file mode 100644 index 318ab745..00000000 --- a/client/gui/overlays/debug.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bpmdfuqjtwf5v diff --git a/client/gui/overlays/debug.tscn b/client/gui/overlays/debug.tscn deleted file mode 100644 index 5a954189..00000000 --- a/client/gui/overlays/debug.tscn +++ /dev/null @@ -1,26 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://3lytexnfrub6"] - -[ext_resource type="Script" uid="uid://bpmdfuqjtwf5v" path="res://gui/overlays/debug.gd" id="1_62otr"] -[ext_resource type="Script" uid="uid://byshs20og68tn" path="res://gui/components/smart_margin_container.gd" id="1_c21gy"] - -[node name="SmartMarginContainer" type="MarginContainer"] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -mouse_filter = 2 -theme_override_constants/margin_left = 10 -theme_override_constants/margin_top = 10 -theme_override_constants/margin_right = 10 -theme_override_constants/margin_bottom = 10 -script = ExtResource("1_c21gy") -metadata/_custom_type_script = "uid://byshs20og68tn" - -[node name="Debug" type="RichTextLabel" parent="."] -visible = false -layout_mode = 2 -mouse_filter = 2 -theme_override_colors/font_outline_color = Color(0, 0, 0, 1) -theme_override_constants/outline_size = 10 -script = ExtResource("1_62otr") diff --git a/client/gui/overlays/debug/debug.gd b/client/gui/overlays/debug/debug.gd new file mode 100644 index 00000000..3a37a1b7 --- /dev/null +++ b/client/gui/overlays/debug/debug.gd @@ -0,0 +1,39 @@ +# Hurry Curry! - a game about cooking +# Copyright (C) 2025 Hurry Curry! contributors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +extends RichTextLabel + +func _ready(): + Settings.hook_changed_init("graphics.debug_info", "main", func (v): + visible = v + RenderingServer.viewport_set_measure_render_time(get_viewport().get_viewport_rid(), visible) + ) + +func _process(_delta): + if not visible: return + var t = "" + t += " Renderer: %s (%s)\n" % [RenderingServer.get_current_rendering_driver_name(), RenderingServer.get_video_adapter_name()] + t += " Timing: %.01fms CPU; %.01fms GPU\n" % [ + RenderingServer.viewport_get_measured_render_time_cpu(get_viewport().get_viewport_rid()), + RenderingServer.viewport_get_measured_render_time_gpu(get_viewport().get_viewport_rid()) + ] + t += " Resolution: %dx%d\n" % [get_tree().root.size.x, get_tree().root.size.y] + t += " FPS: %d\n" % Engine.get_frames_per_second() + t += " Node count: %d\n" % get_tree().get_node_count() + text = t + +func _input(_event): + if Input.is_action_just_pressed("toggle_debug"): + Settings.write("graphics.debug_info", not Settings.read("graphics.debug_info")) diff --git a/client/gui/overlays/debug/debug.gd.uid b/client/gui/overlays/debug/debug.gd.uid new file mode 100644 index 00000000..318ab745 --- /dev/null +++ b/client/gui/overlays/debug/debug.gd.uid @@ -0,0 +1 @@ +uid://bpmdfuqjtwf5v diff --git a/client/gui/overlays/debug/debug.tscn b/client/gui/overlays/debug/debug.tscn new file mode 100644 index 00000000..c794c161 --- /dev/null +++ b/client/gui/overlays/debug/debug.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=6 format=3 uid="uid://3lytexnfrub6"] + +[ext_resource type="Script" uid="uid://bpmdfuqjtwf5v" path="res://gui/overlays/debug/debug.gd" id="1_62otr"] +[ext_resource type="Script" uid="uid://byshs20og68tn" path="res://gui/components/smart_margin_container.gd" id="1_c21gy"] +[ext_resource type="Script" uid="uid://c40pm2fx0t5t8" path="res://gui/overlays/debug/debug_pie.gd" id="3_weeal"] +[ext_resource type="FontFile" uid="uid://bk704sc5gkrb3" path="res://gui/resources/fonts/font-azaret-mono.woff2" id="4_fa78f"] + +[sub_resource type="FontVariation" id="FontVariation_42mmf"] +base_font = ExtResource("4_fa78f") +variation_opentype = { +2003265652: 700 +} + +[node name="SmartMarginContainer" type="MarginContainer"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 +script = ExtResource("1_c21gy") +metadata/_custom_type_script = "uid://byshs20og68tn" + +[node name="Debug" type="RichTextLabel" parent="."] +visible = false +layout_mode = 2 +mouse_filter = 2 +theme_override_colors/font_outline_color = Color(0, 0, 0, 1) +theme_override_constants/outline_size = 10 +script = ExtResource("1_62otr") + +[node name="DebugPie" type="Control" parent="."] +visible = false +layout_mode = 2 +size_flags_horizontal = 8 +size_flags_vertical = 8 +mouse_filter = 2 +script = ExtResource("3_weeal") +font = SubResource("FontVariation_42mmf") diff --git a/client/gui/overlays/debug/debug_pie.gd b/client/gui/overlays/debug/debug_pie.gd new file mode 100644 index 00000000..c1140683 --- /dev/null +++ b/client/gui/overlays/debug/debug_pie.gd @@ -0,0 +1,108 @@ +extends Control + +@export var radius: float = 150 +@export var pie_squish: float = 0.6 +@export var font: Font +const circle_res := 128. + +var current_class := "Node" +var data = {} +var class_lookup = {} + +var offset = 0. +var font_size = radius / 10 + +var sorted := [] +var total = 0 + +func _ready(): + custom_minimum_size = get_draw_size() + +func _process(_dt): + setup_counters() + traverse(get_tree().root) + sort_counters() + queue_redraw() + +func _input(event: InputEvent): + if event is InputEventKey and event.is_pressed(): + if Input.is_action_pressed("toggle_debug"): + visible = event.as_text_key_label() == "1" + current_class = "Node" + return + if not visible: return + var text = event.as_text() + if not text.is_valid_int(): return + var num = int(text) + if num > sorted.size(): return + if num == 0: + if current_class == "Node": return + current_class = ClassDB.get_parent_class(current_class) + else: current_class = sorted[num - 1][0] + +func setup_counters(): + class_lookup.clear() + data.clear() + for c in ClassDB.get_inheriters_from_class(current_class): + if ClassDB.get_parent_class(c) == current_class: + class_lookup[c] = c + data[c] = 0 + for c2 in ClassDB.get_inheriters_from_class(c): + class_lookup[c2] = c + +func traverse(node: Node): + var cls = node.get_class() + if class_lookup.has(cls): data[class_lookup[cls]] += 1 + for c in node.get_children(): traverse(c) + +func sort_counters(): + total = 0 + sorted.clear() + for key in data: + if data[key] == 0: continue + sorted.append([key, data[key]]) + total += data[key] + sorted.sort_custom(func(a,b): return a[1] > b[1]) + +func draw_slice(start: float, end: float, color: Color): + var a = PackedVector2Array() + a.append(Vector2.ZERO) + var res = ceil((end - start) * 128) + for i in range(res + 1): + var ang = lerpf(start, end, float(i) / res) + a.append(Vector2(sin(ang), -cos(ang) * pie_squish) * radius) + draw_colored_polygon(a, color) + +func get_draw_size(): + return Vector2(1, 1.5) * radius * 2. + +func _draw(): + draw_rect(Rect2(Vector2.ZERO, get_draw_size()), Color(.1,.1,.1,0.8)) + offset = 0. + draw_row(0, current_class, total) + draw_pie() + for i in range(sorted.size()): + var label = sorted[i][0]; var value = sorted[i][1] + draw_row(i + 1, label, value) + +func draw_pie(): + draw_set_transform(Vector2(radius, offset + radius * pie_squish)) + var angle = 0. + for i in range(sorted.size()): + var label = sorted[i][0]; var value = sorted[i][1] + var inc = float(value) / float(total) * PI * 2. + draw_slice(angle, angle + inc, label_color(i+1, label)) + angle += inc + offset += radius * 2 * pie_squish + draw_set_transform(Vector2.ZERO) + +func draw_row(index: int, label: String, value: int): + offset += font_size + var color = label_color(index, label) + var text_left = "[%d] %s" % [index, label] + var text_right = "%3d" % value + draw_string(font, Vector2(0., offset), text_left, HORIZONTAL_ALIGNMENT_LEFT, radius * 1.5, font_size, color) + draw_string(font, Vector2(radius * 1.5, offset), text_right, HORIZONTAL_ALIGNMENT_LEFT, radius * 0.5, font_size, color) + +func label_color(i: int, _label: String) -> Color: + return Color.from_hsv(fmod(float(i + current_class.hash() & 0xffff) / 3.5, 1.), 0.5, 1.) diff --git a/client/gui/overlays/debug/debug_pie.gd.uid b/client/gui/overlays/debug/debug_pie.gd.uid new file mode 100644 index 00000000..24590101 --- /dev/null +++ b/client/gui/overlays/debug/debug_pie.gd.uid @@ -0,0 +1 @@ +uid://c40pm2fx0t5t8 diff --git a/client/gui/overlays/debug/pie.tscn b/client/gui/overlays/debug/pie.tscn new file mode 100644 index 00000000..69872d72 --- /dev/null +++ b/client/gui/overlays/debug/pie.tscn @@ -0,0 +1,9 @@ +[gd_scene format=3 uid="uid://27qwbrf7mh7i"] + +[node name="DebugPie" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/client/gui/overlays/overlays.tscn b/client/gui/overlays/overlays.tscn index f272fd6b..93717736 100644 --- a/client/gui/overlays/overlays.tscn +++ b/client/gui/overlays/overlays.tscn @@ -7,7 +7,7 @@ [ext_resource type="PackedScene" uid="uid://bc50la65ntifb" path="res://gui/overlays/lobby/lobby.tscn" id="4_jwd7s"] [ext_resource type="PackedScene" uid="uid://c7pykhpdhgs64" path="res://gui/overlays/announce_title.tscn" id="5_whygm"] [ext_resource type="PackedScene" uid="uid://b21nrnkygiyjt" path="res://gui/overlays/popup_message/popup_message.tscn" id="7_jwd7s"] -[ext_resource type="PackedScene" uid="uid://3lytexnfrub6" path="res://gui/overlays/debug.tscn" id="8_8ouu3"] +[ext_resource type="PackedScene" uid="uid://3lytexnfrub6" path="res://gui/overlays/debug/debug.tscn" id="8_8ouu3"] [node name="Overlays" type="Control"] layout_mode = 3 -- cgit v1.2.3-70-g09d2