Skip to content

Commit

Permalink
added "Open Site" tool menu
Browse files Browse the repository at this point in the history
fixed clear_2d method
fixed nullable Variant
  • Loading branch information
DmitriySalnikov committed Sep 16, 2023
1 parent 3da6b63 commit 73ea070
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 37 deletions.
3 changes: 0 additions & 3 deletions examples_dd3d/DebugDrawDemoScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func _on_HSlider2_value_changed(value: float) -> void:
get_parent().graph_buffer_size = int(value)

func _on_Button_pressed() -> void:
DebugDraw2D.clear_2d_objects()
get_tree().call_deferred(\"change_scene_to_file\", switch_to_scene)
"
Expand All @@ -223,8 +222,6 @@ process_priority = 1
script = ExtResource("1")
custom_font = ExtResource("2_aedbq")
start_culling_distance = 55.0
text_groups_show_stats = true
text_groups_show_stats_2d = true
text_groups_position = 2
text_groups_default_font_size = 15
text_groups_title_font_size = 20
Expand Down
19 changes: 17 additions & 2 deletions examples_dd3d/DebugDrawDemoSceneCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ public partial class DebugDrawDemoSceneCS : Node3D
[ExportGroup("Text groups", "text_groups")]
[Export] bool text_groups_show_hints = true;
[Export] bool text_groups_show_stats = true;
[Export] bool text_groups_show_stats_2d = true;
[Export] DebugDrawConfig2D.BlockPosition text_groups_position = DebugDrawConfig2D.BlockPosition.LeftTop;
[Export] Vector2I text_groups_offset = new Vector2I(8, 8);
[Export] Vector2I text_groups_padding = new Vector2I(3, 1);
[Export(PropertyHint.Range, "1, 100")] int text_groups_default_font_size = 12;
[Export(PropertyHint.Range, "1, 100")] int text_groups_title_font_size = 14;
[Export(PropertyHint.Range, "1, 100")] int text_groups_text_font_size = 12;

[ExportGroup("Graphs")]
[ExportGroup("Graphs", "graph")]
[Export] Vector2I graph_offset = new Vector2I(8, 8);
[Export] Vector2I graph_size = new Vector2I(200, 80);
[Export(PropertyHint.Range, "1, 100")] int graph_title_font_size = 14;
Expand Down Expand Up @@ -417,7 +418,7 @@ void _text_tests()
DebugDraw2D.BeginTextGroup("-- Stats --", 3, Colors.Wheat);
var render_stats = DebugDraw3D.GetRenderStats();

if (render_stats != null)
if (render_stats != null && text_groups_show_stats)
{
DebugDraw2D.SetText("Total", render_stats.TotalGeometry);
DebugDraw2D.SetText("Instances", render_stats.Instances, 1);
Expand All @@ -434,6 +435,20 @@ void _text_tests()
DebugDraw2D.SetText("Filling time", $"{(render_stats.TotalTimeFillingBuffersUsec / 1000.0):F2} ms", 10);
DebugDraw2D.SetText("Total time", $"{(render_stats.TotalTimeSpentUsec / 1000.0):F2} ms", 11);
}

if (text_groups_show_stats && text_groups_show_stats_2d)
{
DebugDraw2D.SetText("----", null, 19);
}

var render_stats_2d = DebugDraw2D.GetRenderStats();
if (render_stats_2d != null && text_groups_show_stats_2d)
{
DebugDraw2D.SetText("Text groups", render_stats_2d.OverlayTextGroups, 20);
DebugDraw2D.SetText("Text lines", render_stats_2d.OverlayTextLines, 21);
DebugDraw2D.SetText("Graphs total", render_stats_2d.OverlayGraphsTotal, 22);
DebugDraw2D.SetText("Graphs enabled", render_stats_2d.OverlayGraphsEnabled, 23);
}
DebugDraw2D.EndTextGroup();
}

Expand Down
3 changes: 3 additions & 0 deletions examples_dd3d/DebugDrawDemoSceneCS.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
[node name="DebugDrawDemoSceneCS" instance=ExtResource("2")]
script = ExtResource("2_ipqea")

[node name="Viewport" parent="Panel/ViewportContainer" index="0"]
size = Vector2i(2, 2)

[node name="a" parent="AABB" index="0"]
transform = Transform3D(1, -1.53668e-08, 2.23517e-08, 1.74623e-08, 1, 1.11759e-08, -1.11759e-08, 0, 1, -0.5468, -2.45083, -0.991707)

Expand Down
1 change: 0 additions & 1 deletion src/2d/config_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void DebugDrawConfig2D::_bind_methods() {
}

DebugDrawConfig2D::~DebugDrawConfig2D() {
text_custom_font.unref();
}

DebugDrawConfig2D::DebugDrawConfig2D() {
Expand Down
8 changes: 4 additions & 4 deletions src/2d/debug_draw_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void DebugDraw2D::_bind_methods() {
#undef REG_CLASS_NAME

#pragma region Draw Functions
ClassDB::bind_method(D_METHOD(NAMEOF(clear_2d_objects)), &DebugDraw2D::clear_2d_objects);
ClassDB::bind_method(D_METHOD(NAMEOF(clear_objects)), &DebugDraw2D::clear_objects);

ClassDB::bind_method(D_METHOD(NAMEOF(begin_text_group), "group_title", "group_priority", "group_color", "show_title", "title_size", "text_size"), &DebugDraw2D::begin_text_group, 0, Colors::empty_color, true, -1, -1);
ClassDB::bind_method(D_METHOD(NAMEOF(end_text_group)), &DebugDraw2D::end_text_group);
Expand Down Expand Up @@ -157,7 +157,7 @@ void DebugDraw2D::set_debug_enabled(const bool &_state) {
debug_enabled = _state;

if (!_state) {
clear_2d_objects();
clear_objects();
}
}

Expand Down Expand Up @@ -228,9 +228,9 @@ Ref<DebugDrawStats2D> DebugDraw2D::get_render_stats() {
#endif
}

void DebugDraw2D::clear_2d_objects() {
void DebugDraw2D::clear_objects() {
#ifndef DISABLE_DEBUG_RENDERING
if (!grouped_text || !data_graphs || !is_ready) return;
if (!grouped_text || !data_graphs) return;
grouped_text->clear_text();
data_graphs->clear_graphs();
mark_canvas_dirty();
Expand Down
4 changes: 1 addition & 3 deletions src/2d/debug_draw_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class DebugDraw2D : public Object {
std::unique_ptr<DataGraphManager> data_graphs;
#endif

bool is_ready = false;

void _on_canvas_marked_dirty();
void _on_canvas_item_draw(Control *ci);

Expand Down Expand Up @@ -103,7 +101,7 @@ class DebugDraw2D : public Object {
Ref<DebugDrawStats2D> get_render_stats();

/// Clear all 2D objects
void clear_2d_objects();
void clear_objects();

#pragma region Text

Expand Down
6 changes: 3 additions & 3 deletions src/3d/debug_draw_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void DebugDraw3D::_bind_methods() {
#undef REG_CLASS_NAME

#pragma region Draw Functions
ClassDB::bind_method(D_METHOD(NAMEOF(clear_3d_objects)), &DebugDraw3D::clear_3d_objects);
ClassDB::bind_method(D_METHOD(NAMEOF(clear_objects)), &DebugDraw3D::clear_objects);

ClassDB::bind_method(D_METHOD(NAMEOF(draw_sphere), "position", "radius", "color", "duration"), &DebugDraw3D::draw_sphere, 0.5f, Colors::empty_color, 0);
ClassDB::bind_method(D_METHOD(NAMEOF(draw_sphere_xf), "transform", "color", "duration"), &DebugDraw3D::draw_sphere_xf, Colors::empty_color, 0);
Expand Down Expand Up @@ -147,7 +147,7 @@ void DebugDraw3D::set_debug_enabled(const bool &_state) {
debug_enabled = _state;

if (!_state) {
clear_3d_objects();
clear_objects();
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ Ref<DebugDrawStats3D> DebugDraw3D::get_render_stats() {
#endif
}

void DebugDraw3D::clear_3d_objects() {
void DebugDraw3D::clear_objects() {
#ifndef DISABLE_DEBUG_RENDERING
if (!dgc) return;
dgc->clear_3d_objects();
Expand Down
2 changes: 1 addition & 1 deletion src/3d/debug_draw_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DebugDraw3D : public Object {
#endif

/// Clear all 3D objects
void clear_3d_objects();
void clear_objects();

#pragma region Spheres

Expand Down
4 changes: 2 additions & 2 deletions src/debug_draw_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void DebugDrawManager::_on_scene_changed(bool _is_scene_null) {
#ifndef DISABLE_DEBUG_RENDERING
if (!is_current_scene_is_null || is_current_scene_is_null != _is_scene_null) {
DEV_PRINT("Scene changed! clear_all()");
debug_draw_3d_singleton->clear_3d_objects();
debug_draw_2d_singleton->clear_2d_objects();
debug_draw_3d_singleton->clear_objects();
debug_draw_2d_singleton->clear_objects();
}

is_current_scene_is_null = _is_scene_null;
Expand Down
17 changes: 8 additions & 9 deletions src/editor/editor_menu_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

GODOT_WARNING_DISABLE()
#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/os.hpp>
GODOT_WARNING_RESTORE()

void DebugDrawMenuExtensionPlugin::_bind_methods() {
Expand All @@ -23,6 +24,7 @@ void DebugDrawMenuExtensionPlugin::_enter_tree() {

PopupMenu *menu = memnew(PopupMenu);
menu->connect("id_pressed", Callable(this, NAMEOF(_on_id_pressed)));
menu->add_item("Open project site", OPEN_LIBRARY_SITE);
menu->add_item("Generate C# bindings", GENERATE_CSHARP_BINDING);

add_tool_submenu_item(menu_item_name, menu);
Expand All @@ -35,19 +37,16 @@ void DebugDrawMenuExtensionPlugin::_exit_tree() {
remove_tool_menu_item(menu_item_name);
}

void DebugDrawMenuExtensionPlugin::_enable_plugin() {
DEV_PRINT(NAMEOF(DebugDrawMenuExtensionPlugin) " _enable_plugin");
}

void DebugDrawMenuExtensionPlugin::_disable_plugin() {
DEV_PRINT(NAMEOF(DebugDrawMenuExtensionPlugin) " _disable_plugin");
}

void DebugDrawMenuExtensionPlugin::_on_id_pressed(MenuItemId id) {
switch (id) {
case DebugDrawMenuExtensionPlugin::GENERATE_CSHARP_BINDING:
case DebugDrawMenuExtensionPlugin::OPEN_LIBRARY_SITE: {
OS::get_singleton()->shell_open("https://github.com/DmitriySalnikov/godot_debug_draw_3d");
break;
}
case DebugDrawMenuExtensionPlugin::GENERATE_CSHARP_BINDING: {
GenerateCSharpBindingsPlugin().generate();
break;
}
default:
PRINT_ERROR("Menu item " + String::num_int64(id) + " not implemented.");
break;
Expand Down
5 changes: 2 additions & 3 deletions src/editor/editor_menu_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class DebugDrawMenuExtensionPlugin : public EditorPlugin {
GDCLASS(DebugDrawMenuExtensionPlugin, EditorPlugin)

enum MenuItemId {
GENERATE_CSHARP_BINDING = 1,
OPEN_LIBRARY_SITE = 1,
GENERATE_CSHARP_BINDING = 2,
};

String menu_item_name;
Expand All @@ -26,8 +27,6 @@ class DebugDrawMenuExtensionPlugin : public EditorPlugin {
// Ref<Texture2D> _get_plugin_icon() const override;
void _enter_tree() override;
void _exit_tree() override;
void _enable_plugin() override;
void _disable_plugin() override;

void _on_id_pressed(MenuItemId id);

Expand Down
9 changes: 5 additions & 4 deletions src/editor/generate_csharp_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,11 @@ GenerateCSharpBindingsPlugin::ArgumentData GenerateCSharpBindingsPlugin::argumen
return ArgumentData(name, var_type, types_map[var_type]);
}

if (is_return)
if (is_return) {
return ArgumentData(name, var_type, "void");
else
} else {
return ArgumentData(name, var_type, "Variant");
}
}

GenerateCSharpBindingsPlugin::ArgumentData GenerateCSharpBindingsPlugin::argument_parse(const StringName &class_name, const String &name, const Variant::Type type) {
Expand Down Expand Up @@ -593,7 +594,7 @@ GenerateCSharpBindingsPlugin::DefaultData GenerateCSharpBindingsPlugin::argument
switch (arg_data.type) {
case godot::Variant::NIL: // aka Variant
if (def_val.get_type() == 0) {
return DefaultData(arg_data, false, "default");
return DefaultData(arg_data, true, "default");
} else {
ArgumentData tmp_arg = arg_data;
tmp_arg.type = def_val.get_type();
Expand Down Expand Up @@ -801,12 +802,12 @@ String GenerateCSharpBindingsPlugin::arguments_string_decl(const TypedArray<Dict
PackedStringArray arg_strs;
for (int i = 0; i < args.size(); i++) {
ArgumentData arg_data = argument_parse(args[i]);
arg_data = argument_parse(args[i]);

DefaultData *def_data = nullptr;
for (auto &it : def_args_data) {
if (it.name == arg_data.name) {
def_data = &it;
break;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ Ref<AssetLibraryUpdateChecker> upd_checker;
#endif
#endif

// TODO: test android debug symbols

/** GDExtension Initialize **/
void initialize_debug_draw_3d_module(ModuleInitializationLevel p_level) {
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
Expand Down

0 comments on commit 73ea070

Please sign in to comment.