Skip to content

Commit

Permalink
Add a built-in debug menu that displays current performance
Browse files Browse the repository at this point in the history
This can be used to diagnose performance issues, both for developers
and players (since this is also available in exported projects).

Press F3 to cycle between 3 modes: hidden, compact (FPS/frametime display only),
detailed.
  • Loading branch information
Calinou committed Nov 19, 2024
1 parent fd4c29a commit 5699876
Show file tree
Hide file tree
Showing 14 changed files with 1,111 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/input/input_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
{ "ui_filedialog_show_hidden", TTRC("Show Hidden") },
{ "ui_swap_input_direction ", TTRC("Swap Input Direction") },
{ "ui_unicode_start", TTRC("Start Unicode Character Input") },
{ "ui_cycle_debug_menu_display_mode", TTRC("Cycle Debug Menu") },
{ "", ""}
/* clang-format on */
};
Expand Down Expand Up @@ -785,6 +786,12 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() {
inputs.push_back(InputEventKey::create_reference(Key::QUOTELEFT | KeyModifierMask::CMD_OR_CTRL));
default_builtin_cache.insert("ui_swap_input_direction", inputs);

// ///// UI Misc Shortcuts /////

inputs = List<Ref<InputEvent>>();
inputs.push_back(InputEventKey::create_reference(Key::F3));
default_builtin_cache.insert("ui_cycle_debug_menu_display_mode", inputs);

return default_builtin_cache;
}

Expand Down
4 changes: 4 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,10 @@
Default [InputEventAction] to cut a selection to the clipboard.
[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
</member>
<member name="input/ui_cycle_debug_menu_display_mode" type="Dictionary" setter="" getter="">
Default [InputEventAction] to cycle between display modes in the built-in debug menu (hidden, compact, detailed). See also [member SceneTree.debug_menu_display_mode].
[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of the debug menu. The events assigned to the action can however be modified.
</member>
<member name="input/ui_down" type="Dictionary" setter="" getter="">
Default [InputEventAction] to move down in the UI.
[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
Expand Down
15 changes: 15 additions & 0 deletions doc/classes/SceneTree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@
If [code]true[/code], collision shapes will be visible when running the game from the editor for debugging purposes.
[b]Note:[/b] This property is not designed to be changed at run-time. Changing the value of [member debug_collisions_hint] while the project is running will not have the desired effect.
</member>
<member name="debug_menu_display_mode" type="int" setter="set_debug_menu_display_mode" getter="get_debug_menu_display_mode" enum="SceneTree.DebugMenuDisplayMode" default="0">
The current display mode of the built-in debug menu. See also [member ProjectSettings.input/ui_cycle_debug_menu_display_mode].
</member>
<member name="debug_navigation_hint" type="bool" setter="set_debug_navigation_hint" getter="is_debugging_navigation_hint" default="false">
If [code]true[/code], navigation polygons will be visible when running the game from the editor for debugging purposes.
[b]Note:[/b] This property is not designed to be changed at run-time. Changing the value of [member debug_navigation_hint] while the project is running will not have the desired effect.
Expand Down Expand Up @@ -337,5 +340,17 @@
Call nodes within a group only once, even if the call is executed many times in the same frame. Must be combined with [constant GROUP_CALL_DEFERRED] to work.
[b]Note:[/b] Different arguments are not taken into account. Therefore, when the same call is executed with different arguments, only the first call will be performed.
</constant>
<constant name="DEBUG_MENU_DISPLAY_MODE_HIDDEN" value="0" enum="DebugMenuDisplayMode">
Built-in debug menu is hidden.
</constant>
<constant name="DEBUG_MENU_DISPLAY_MODE_COMPACT" value="1" enum="DebugMenuDisplayMode">
Built-in debug menu is visible in compact mode (only FPS, frametime, V-Sync mode and framerate cap displayed).
</constant>
<constant name="DEBUG_MENU_DISPLAY_MODE_DETAILED" value="2" enum="DebugMenuDisplayMode">
Built-in debug menu is visible in detailed mode, with all information visible.
</constant>
<constant name="DEBUG_MENU_DISPLAY_MODE_MAX" value="3" enum="DebugMenuDisplayMode">
Represents the size of the [enum DebugMenuDisplayMode] enum.
</constant>
</constants>
</class>
1 change: 1 addition & 0 deletions editor/icons/DebugMenu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5699876

Please sign in to comment.