Skip to content

Commit

Permalink
Add debug menu option to make Marker nodes visible at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
danboo committed Oct 3, 2022
1 parent f2061f1 commit 5e20a56
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/classes/SceneTree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@
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_markers_hint" type="bool" setter="set_debug_markers_hint" getter="is_debugging_markers_hint" default="false">
If [code]true[/code], Marker2D and Marker3D nodes 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_markers_hint] while the project is running will not have the desired effect.
</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
5 changes: 5 additions & 0 deletions editor/editor_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie) {
bool debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisions", false);
bool debug_paths = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_paths", false);
bool debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
bool debug_markers = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_markers", false);
if (debug_collisions) {
args.push_back("--debug-collisions");
}
Expand All @@ -78,6 +79,10 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie) {
args.push_back("--debug-navigation");
}

if (debug_markers) {
args.push_back("--debug-markers");
}

if (p_write_movie != "") {
args.push_back("--write-movie");
args.push_back(p_write_movie);
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_run_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Error EditorRunNative::run_native(int p_idx, int p_platform) {
bool deploy_dumb = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_file_server", false);
bool debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisions", false);
bool debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
bool debug_markers = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_markers", false);

if (deploy_debug_remote) {
flags |= EditorExportPlatform::DEBUG_FLAG_REMOTE_DEBUG;
Expand All @@ -149,6 +150,9 @@ Error EditorRunNative::run_native(int p_idx, int p_platform) {
if (debug_navigation) {
flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_NAVIGATION;
}
if (debug_markers) {
flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_MARKERS;
}

eep->clear_messages();
Error err = eep->run(preset, p_idx, flags);
Expand Down
8 changes: 8 additions & 0 deletions editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags)
if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
r_flags.push_back("--debug-navigation");
}

if (p_flags & DEBUG_FLAG_VIEW_MARKERS) {
r_flags.push_back("--debug-markers");
}
}

Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key) {
Expand Down Expand Up @@ -1616,6 +1620,10 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags
if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
r_flags.push_back("--debug-navigation");
}

if (p_flags & DEBUG_FLAG_VIEW_MARKERS) {
r_flags.push_back("--debug-markers");
}
}

bool EditorExportPlatform::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
Expand Down
1 change: 1 addition & 0 deletions editor/export/editor_export_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class EditorExportPlatform : public RefCounted {
DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST = 4,
DEBUG_FLAG_VIEW_COLLISIONS = 8,
DEBUG_FLAG_VIEW_NAVIGATION = 16,
DEBUG_FLAG_VIEW_MARKERS = 32,
};

virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { return OK; }
Expand Down
13 changes: 13 additions & 0 deletions editor/plugins/debugger_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ DebuggerEditorPlugin::DebuggerEditorPlugin(PopupMenu *p_debug_menu) {
debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_navigation", TTR("Visible Navigation")), RUN_DEBUG_NAVIGATION);
debug_menu->set_item_tooltip(-1,
TTR("When this option is enabled, navigation meshes and polygons will be visible in the running project."));
debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_markers", TTR("Visible Markers")), RUN_DEBUG_MARKERS);
debug_menu->set_item_tooltip(-1,
TTR("When this option is enabled, Marker2D and Marker3D nodes will be visible in the running project."));
debug_menu->add_separator();
debug_menu->add_check_shortcut(ED_SHORTCUT("editor/sync_scene_changes", TTR("Synchronize Scene Changes")), RUN_LIVE_DEBUG);
debug_menu->set_item_tooltip(-1,
Expand Down Expand Up @@ -167,6 +170,12 @@ void DebuggerEditorPlugin::_menu_option(int p_option) {
debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_NAVIGATION), !ischecked);
EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_navigation", !ischecked);

} break;
case RUN_DEBUG_MARKERS: {
bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_MARKERS));
debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_MARKERS), !ischecked);
EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_markers", !ischecked);

} break;
case RUN_RELOAD_SCRIPTS: {
bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_RELOAD_SCRIPTS));
Expand All @@ -193,6 +202,7 @@ void DebuggerEditorPlugin::_update_debug_options() {
bool check_debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisions", false);
bool check_debug_paths = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_paths", false);
bool check_debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
bool check_debug_markers = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_markers", false);
bool check_live_debug = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_live_debug", true);
bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", true);
int instances = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_instances", 1);
Expand All @@ -212,6 +222,9 @@ void DebuggerEditorPlugin::_update_debug_options() {
if (check_debug_navigation) {
_menu_option(RUN_DEBUG_NAVIGATION);
}
if (check_debug_markers) {
_menu_option(RUN_DEBUG_MARKERS);
}
if (check_live_debug) {
_menu_option(RUN_LIVE_DEBUG);
}
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/debugger_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DebuggerEditorPlugin : public EditorPlugin {
RUN_DEBUG_COLLISIONS,
RUN_DEBUG_PATHS,
RUN_DEBUG_NAVIGATION,
RUN_DEBUG_MARKERS,
RUN_DEPLOY_REMOTE_DEBUG,
RUN_RELOAD_SCRIPTS,
};
Expand Down
7 changes: 7 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ static bool use_debug_profiler = false;
static bool debug_collisions = false;
static bool debug_paths = false;
static bool debug_navigation = false;
static bool debug_markers = false;
#endif
static int frame_delay = 0;
static bool disable_render_loop = false;
Expand Down Expand Up @@ -391,6 +392,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --debug-collisions Show collision shapes when running the scene.\n");
OS::get_singleton()->print(" --debug-paths Show path lines when running the scene.\n");
OS::get_singleton()->print(" --debug-navigation Show navigation polygons when running the scene.\n");
OS::get_singleton()->print(" --debug-markers Show Marker2D and Marker3D nodes when running the scene.\n");
OS::get_singleton()->print(" --debug-stringnames Print all StringName allocations to stdout when the engine quits.\n");
#endif
OS::get_singleton()->print(" --frame-delay <ms> Simulate high CPU load (delay each frame by <ms> milliseconds).\n");
Expand Down Expand Up @@ -1194,6 +1196,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
debug_paths = true;
} else if (I->get() == "--debug-navigation") {
debug_navigation = true;
} else if (I->get() == "--debug-markers") {
debug_markers = true;
} else if (I->get() == "--debug-stringnames") {
StringName::set_debug_stringnames(true);
#endif
Expand Down Expand Up @@ -2677,6 +2681,9 @@ bool Main::start() {
NavigationServer3D::get_singleton()->set_active(true);
NavigationServer3D::get_singleton_mut()->set_debug_enabled(true);
}
if (debug_markers) {
sml->set_debug_markers_hint(true);
}
#endif

bool embed_subwindows = GLOBAL_DEF("display/window/subwindows/embed_subwindows", true);
Expand Down
1 change: 1 addition & 0 deletions misc/dist/shell/_godot.zsh-completion
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ _arguments \
'--remote-debug[enable remote debugging]:remote debugger address' \
'--debug-collisions[show collision shapes when running the scene]' \
'--debug-navigation[show navigation polygons when running the scene]' \
'--debug-markers[show Marker2D and Marker3D nodes when running the scene]' \
'--debug-stringnames[print all StringName allocations to stdout when the engine quits]' \
'--frame-delay[simulate high CPU load (delay each frame by the given number of milliseconds)]:number of milliseconds' \
'--time-scale[force time scale (higher values are faster, 1.0 is normal speed)]:time scale' \
Expand Down
1 change: 1 addition & 0 deletions misc/dist/shell/godot.bash-completion
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ _complete_godot_options() {
--remote-debug
--debug-collisions
--debug-navigation
--debug-markers
--debug-stringnames
--frame-delay
--time-scale
Expand Down
1 change: 1 addition & 0 deletions misc/dist/shell/godot.fish
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ complete -c godot -l gpu-abort -d "Abort on graphics API usage errors (usually v
complete -c godot -l remote-debug -d "Enable remote debugging"
complete -c godot -l debug-collisions -d "Show collision shapes when running the scene"
complete -c godot -l debug-navigation -d "Show navigation polygons when running the scene"
complete -c godot -l debug-markers -d "Show Marker2D and Marker3D nodes when running the scene"
complete -c godot -l debug-stringnames -d "Print all StringName allocations to stdout when the engine quits"
complete -c godot -l frame-delay -d "Simulate high CPU load (delay each frame by the given number of milliseconds)" -x
complete -c godot -l time-scale -d "Force time scale (higher values are faster, 1.0 is normal speed)" -x
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/marker_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void Marker2D::_notification(int p_what) {
if (!is_inside_tree()) {
break;
}
if (Engine::get_singleton()->is_editor_hint()) {
if (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_markers_hint()) {
_draw_cross();
}
} break;
Expand Down
11 changes: 11 additions & 0 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ void SceneTree::set_debug_navigation_hint(bool p_enabled) {
bool SceneTree::is_debugging_navigation_hint() const {
return debug_navigation_hint;
}

void SceneTree::set_debug_markers_hint(bool p_enabled) {
debug_markers_hint = p_enabled;
}

bool SceneTree::is_debugging_markers_hint() const {
return debug_markers_hint;
}
#endif

void SceneTree::set_debug_collisions_color(const Color &p_color) {
Expand Down Expand Up @@ -1217,6 +1225,8 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_debugging_paths_hint"), &SceneTree::is_debugging_paths_hint);
ClassDB::bind_method(D_METHOD("set_debug_navigation_hint", "enable"), &SceneTree::set_debug_navigation_hint);
ClassDB::bind_method(D_METHOD("is_debugging_navigation_hint"), &SceneTree::is_debugging_navigation_hint);
ClassDB::bind_method(D_METHOD("set_debug_markers_hint", "enable"), &SceneTree::set_debug_markers_hint);
ClassDB::bind_method(D_METHOD("is_debugging_markers_hint"), &SceneTree::is_debugging_markers_hint);

ClassDB::bind_method(D_METHOD("set_edited_scene_root", "scene"), &SceneTree::set_edited_scene_root);
ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &SceneTree::get_edited_scene_root);
Expand Down Expand Up @@ -1278,6 +1288,7 @@ void SceneTree::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_collisions_hint"), "set_debug_collisions_hint", "is_debugging_collisions_hint");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_paths_hint"), "set_debug_paths_hint", "is_debugging_paths_hint");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_navigation_hint"), "set_debug_navigation_hint", "is_debugging_navigation_hint");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_markers_hint"), "set_debug_markers_hint", "is_debugging_markers_hint");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_pause", "is_paused");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_edited_scene_root", "get_edited_scene_root");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "current_scene", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_current_scene", "get_current_scene");
Expand Down
7 changes: 7 additions & 0 deletions scene/main/scene_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class SceneTree : public MainLoop {
bool debug_collisions_hint = false;
bool debug_paths_hint = false;
bool debug_navigation_hint = false;
bool debug_markers_hint = false;
#endif
bool paused = false;
int root_lock = 0;
Expand Down Expand Up @@ -311,6 +312,9 @@ class SceneTree : public MainLoop {

void set_debug_navigation_hint(bool p_enabled);
bool is_debugging_navigation_hint() const;

void set_debug_markers_hint(bool p_enabled);
bool is_debugging_markers_hint() const;
#else
void set_debug_collisions_hint(bool p_enabled) {}
bool is_debugging_collisions_hint() const { return false; }
Expand All @@ -320,6 +324,9 @@ class SceneTree : public MainLoop {

void set_debug_navigation_hint(bool p_enabled) {}
bool is_debugging_navigation_hint() const { return false; }

void set_debug_markers_hint(bool p_enabled) {}
bool is_debugging_markers_hint() const { return false; }
#endif

void set_debug_collisions_color(const Color &p_color);
Expand Down

0 comments on commit 5e20a56

Please sign in to comment.