From aa516aa45f2ea6c3e1c689edaa08ad1f208676c3 Mon Sep 17 00:00:00 2001 From: DmitriySalnikov Date: Mon, 4 Dec 2023 16:03:34 +0300 Subject: [PATCH] updated C# generator --- examples_dd3d/DebugDrawDemoScene.gd | 13 ++- examples_dd3d/DebugDrawDemoScene.tscn | 4 +- examples_dd3d/DebugDrawDemoSceneCS.cs | 106 ++++++++++++++++-------- examples_dd3d/DebugDrawDemoSceneCS.tscn | 5 +- src/3d/config_scoped_3d.cpp | 13 ++- src/3d/config_scoped_3d.h | 2 + src/dev_debug_draw_3d_Library.vcxproj | 4 - src/editor/generate_csharp_bindings.cpp | 63 ++++++++++++-- src/editor/generate_csharp_bindings.h | 8 ++ 9 files changed, 158 insertions(+), 60 deletions(-) diff --git a/examples_dd3d/DebugDrawDemoScene.gd b/examples_dd3d/DebugDrawDemoScene.gd index ee1d702b..94c0b6ba 100644 --- a/examples_dd3d/DebugDrawDemoScene.gd +++ b/examples_dd3d/DebugDrawDemoScene.gd @@ -73,12 +73,11 @@ func _process(delta: float) -> void: DebugDraw3D.scoped_config().set_thickness(debug_thickness) if false: #test - var s11 = DebugDraw3D.new_scoped_config() - s11.set_thickness(1) + var _s11 = DebugDraw3D.new_scoped_config().set_thickness(1) if true: pass - var s13 = DebugDraw3D.new_scoped_config() - s13.set_thickness(3) + var _s13 = DebugDraw3D.new_scoped_config() + _s13.set_thickness(3) _update_keys_just_press() @@ -216,7 +215,7 @@ func _process(delta: float) -> void: # Misc if true: #for i in 1000: - var a11 = DebugDraw3D.new_scoped_config().set_thickness(0) + var _a11 = DebugDraw3D.new_scoped_config().set_thickness(0) DebugDraw3D.draw_camera_frustum($Camera, Color.DARK_ORANGE) DebugDraw3D.draw_arrow($Misc/Arrow.global_transform, Color.YELLOW_GREEN) @@ -349,12 +348,12 @@ func _more_tests(): # Delayed line render if true: - var a12 = DebugDraw3D.new_scoped_config().set_thickness(0.035) + var _a12 = DebugDraw3D.new_scoped_config().set_thickness(0.035) DebugDraw3D.draw_line($LagTest.global_transform.origin + Vector3.UP, $LagTest.global_transform.origin + Vector3(0,3,sin(Time.get_ticks_msec() / 50.0)), DebugDraw3D.empty_color, 0.5) func _draw_array_of_boxes(): - # Lots of boxes to check performance.. I guess.. + # Lots of boxes to check performance.. if time2 <= 0: for x in 50: for y in 50: diff --git a/examples_dd3d/DebugDrawDemoScene.tscn b/examples_dd3d/DebugDrawDemoScene.tscn index ccb72388..0b2ebce7 100644 --- a/examples_dd3d/DebugDrawDemoScene.tscn +++ b/examples_dd3d/DebugDrawDemoScene.tscn @@ -277,10 +277,10 @@ transform = Transform3D(10.7186, 0, 0, 0, 3.9777, 0, 0, 0, 7.05487, 10.6302, 1.9 [node name="LinePathAnim" type="AnimationPlayer" parent="."] root_node = NodePath("../LinePath") -autoplay = "New Anim" libraries = { "": SubResource("AnimationLibrary_nj4nv") } +autoplay = "New Anim" [node name="Label3D" type="Label3D" parent="."] transform = Transform3D(1, -1.93359e-07, -8.48396e-08, -1.17881e-07, 1, 5.96046e-08, 6.22839e-09, 0, 1, 0, 0, 0) @@ -480,10 +480,10 @@ transform = Transform3D(0.935992, 0.352021, 0, -0.352021, 0.935992, 0, 0, 0, 1, target_position = Vector3(0, -3.464, 0) [node name="AnimationPlayer" type="AnimationPlayer" parent="HitTest"] -autoplay = "New Anim" libraries = { "": SubResource("AnimationLibrary_vh8ml") } +autoplay = "New Anim" [node name="LagTest" type="CSGBox3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10.4482, -1.49353, -0.450473) diff --git a/examples_dd3d/DebugDrawDemoSceneCS.cs b/examples_dd3d/DebugDrawDemoSceneCS.cs index 65e32a32..58464ad6 100644 --- a/examples_dd3d/DebugDrawDemoSceneCS.cs +++ b/examples_dd3d/DebugDrawDemoSceneCS.cs @@ -14,7 +14,8 @@ public partial class DebugDrawDemoSceneCS : Node3D [Export] bool test_graphs = false; [Export] bool more_test_cases = true; [Export] bool draw_array_of_boxes = false; - [Export(PropertyHint.Range, "0, 1024")] float start_culling_distance = 0.0f; + [Export(PropertyHint.Range, "0, 5, 0.001")] float debug_thickness = 0.05f; + [Export(PropertyHint.Range, "0, 1024")] float start_culling_distance = 55.0f; [ExportGroup("Text groups", "text_groups")] [Export] bool text_groups_show_hints = true; @@ -23,16 +24,16 @@ public partial class DebugDrawDemoSceneCS : Node3D [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; + [Export(PropertyHint.Range, "1, 100")] int text_groups_default_font_size = 15; + [Export(PropertyHint.Range, "1, 100")] int text_groups_title_font_size = 20; + [Export(PropertyHint.Range, "1, 100")] int text_groups_text_font_size = 17; [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; [Export(PropertyHint.Range, "1, 100")] int graph_text_font_size = 12; - [Export(PropertyHint.Range, "0, 64")] int graph_text_precision = 2; + [Export(PropertyHint.Range, "0, 64")] int graph_text_precision = 1; [Export(PropertyHint.Range, "1, 32")] float graph_line_width = 1.0f; [Export(PropertyHint.Range, "1, 512")] int graph_buffer_size = 128; [Export] bool graph_frame_time_mode = true; @@ -41,6 +42,7 @@ public partial class DebugDrawDemoSceneCS : Node3D Dictionary button_presses = new Dictionary() { { Key.Left, 0 }, { Key.Up, 0 }, + { Key.Ctrl, 0 }, { Key.F1, 0 }, { Key.Key1, 0 }, { Key.Key2, 0 }, @@ -56,25 +58,28 @@ public partial class DebugDrawDemoSceneCS : Node3D CsgBox3D dLagTest; PanelContainer dPanel; Node3D dZones; - Node3D dAABB; - Node3D dAABB_fixed; Node3D dSpherePosition; Node3D dSphereTransform; Node3D dSphereHDTransform; + Node3D dAABB; + Node3D dAABB_fixed; Node3D dBox1; Node3D dBox2; Node3D dBox3; Node3D dBoxOutOfDistanceCulling; Node3D dLines_1; - Node3D dLines_3; - Node3D dLines_6; Node3D dLines_2; + Node3D dLines_3; Node3D dLines_4; Node3D dLines_5; + Node3D dLines_6; + Node3D dLines_7; Node3D dLines_Target; Node3D dLinePath; Node3D dCylinder1; Node3D dCylinder2; + Node3D dCylinder3a; + Node3D dCylinder3b; Control dCustomCanvas; Node3D dMisc_Arrow; @@ -98,25 +103,28 @@ public override async void _Ready() dLagTest = GetNode("LagTest"); dPanel = GetNode("Panel"); dZones = GetNode("Zones"); - dAABB = GetNode("AABB"); - dAABB_fixed = GetNode("AABB_fixed"); - dSpherePosition = GetNode("SpherePosition"); - dSphereTransform = GetNode("SphereTransform"); - dSphereHDTransform = GetNode("SphereHDTransform"); - dBox1 = GetNode("Box1"); - dBox2 = GetNode("Box2"); - dBox3 = GetNode("Box3"); - dBoxOutOfDistanceCulling = GetNode("BoxOutOfDistanceCulling"); + dSpherePosition = GetNode("Spheres/SpherePosition"); + dSphereTransform = GetNode("Spheres/SphereTransform"); + dSphereHDTransform = GetNode("Spheres/SphereHDTransform"); + dAABB = GetNode("Boxes/AABB"); + dAABB_fixed = GetNode("Boxes/AABB_fixed"); + dBox1 = GetNode("Boxes/Box1"); + dBox2 = GetNode("Boxes/Box2"); + dBox3 = GetNode("Boxes/Box3"); + dBoxOutOfDistanceCulling = GetNode("Boxes/BoxOutOfDistanceCulling"); dLines_1 = GetNode("Lines/1"); - dLines_3 = GetNode("Lines/3"); - dLines_6 = GetNode("Lines/6"); dLines_2 = GetNode("Lines/2"); + dLines_3 = GetNode("Lines/3"); dLines_4 = GetNode("Lines/4"); dLines_5 = GetNode("Lines/5"); + dLines_6 = GetNode("Lines/6"); + dLines_7 = GetNode("Lines/7"); dLines_Target = GetNode("Lines/Target"); dLinePath = GetNode("LinePath"); - dCylinder1 = GetNode("Cylinder1"); - dCylinder2 = GetNode("Cylinder2"); + dCylinder1 = GetNode("Cylinders/Cylinder1"); + dCylinder2 = GetNode("Cylinders/Cylinder2"); + dCylinder3a = GetNode("Cylinders/Cylinder3/1"); + dCylinder3b = GetNode("Cylinders/Cylinder3/2"); dCustomCanvas = GetNode("CustomCanvas"); dMisc_Arrow = GetNode("Misc/Arrow"); @@ -168,6 +176,19 @@ void _update_keys_just_press() public override void _Process(double delta) { + if (Input.IsActionJustPressed("ui_end")) + DebugDraw3D.RegenerateGeometryMeshes(); + + DebugDraw3D.ScopedConfig().SetThickness(debug_thickness); +#pragma warning disable CS0162 // Unreachable code detected + if (false) // #test + { + using var s11 = DebugDraw3D.NewScopedConfig().SetThickness(1); + using var s13 = DebugDraw3D.NewScopedConfig(); + s13.SetThickness(3); + } +#pragma warning restore CS0162 // Unreachable code detected + _update_keys_just_press(); if (_is_key_just_pressed(Key.F1)) @@ -215,12 +236,15 @@ public override void _Process(double delta) if (!Engine.IsEditorHint()) GetViewport().Msaa3D = GetViewport().Msaa3D == Viewport.Msaa.Msaa4X ? Viewport.Msaa.Disabled : Viewport.Msaa.Msaa4X; - if (_is_key_just_pressed(Key.Key1)) - DebugDraw3D.DebugEnabled = !DebugDraw3D.DebugEnabled; - if (_is_key_just_pressed(Key.Key2)) - DebugDraw2D.DebugEnabled = !DebugDraw2D.DebugEnabled; - if (_is_key_just_pressed(Key.Key3)) - DebugDrawManager.DebugEnabled = !DebugDrawManager.DebugEnabled; + if (!Engine.IsEditorHint()) + { + if (_is_key_just_pressed(Key.Key1)) + DebugDraw3D.DebugEnabled = !DebugDraw3D.DebugEnabled; + if (_is_key_just_pressed(Key.Key2)) + DebugDraw2D.DebugEnabled = !DebugDraw2D.DebugEnabled; + if (_is_key_just_pressed(Key.Key3)) + DebugDrawManager.DebugEnabled = !DebugDrawManager.DebugEnabled; + } if (Engine.IsEditorHint()) @@ -257,7 +281,8 @@ public override void _Process(double delta) // Cylinders DebugDraw3D.DrawCylinder(dCylinder1.GlobalTransform, Colors.Crimson); - DebugDraw3D.DrawCylinder(new Transform3D(Basis.Identity, dCylinder2.GlobalTransform.Origin).Scaled(new Vector3(1, 2, 1)), Colors.Red); + DebugDraw3D.DrawCylinder(new Transform3D(Basis.Identity.Scaled(new Vector3(1, 2, 1)), dCylinder2.GlobalTransform.Origin), Colors.Red); + DebugDraw3D.DrawCylinderAb(dCylinder3a.GlobalTransform.Origin, dCylinder3b.GlobalTransform.Origin, 0.35f); // Boxes DebugDraw3D.DrawBoxXf(dBox1.GlobalTransform, Colors.MediumPurple); @@ -285,6 +310,9 @@ public override void _Process(double delta) time3 -= delta; + // Test UP vector + DebugDraw3D.DrawLine(dLines_7.GlobalTransform.Origin, target.GlobalTransform.Origin, Colors.Red); + // Lines with Arrow DebugDraw3D.DrawArrowLine(dLines_2.GlobalTransform.Origin, target.GlobalTransform.Origin, Colors.Blue, 0.5f, true); DebugDraw3D.DrawArrowRay(dLines_4.GlobalTransform.Origin, (target.GlobalTransform.Origin - dLines_4.GlobalTransform.Origin).Normalized(), 8.0f, Colors.Lavender, 0.5f, true); @@ -325,7 +353,10 @@ public override void _Process(double delta) DebugDraw3D.DrawPointPath(points_below3.ToArray(), 0.25f, Colors.Blue, Colors.Tomato); // Misc - DebugDraw3D.DrawCameraFrustum(dCamera, Colors.DarkOrange); + using (var s = DebugDraw3D.NewScopedConfig().SetThickness(0)) + { + DebugDraw3D.DrawCameraFrustum(dCamera, Colors.DarkOrange); + } DebugDraw3D.DrawArrow(dMisc_Arrow.GlobalTransform, Colors.YellowGreen); @@ -342,7 +373,7 @@ public override void _Process(double delta) DebugDraw3D.DrawGrid(tg.Origin, tg.Basis.X, tg.Basis.Z, new Vector2I((int)tn.X * 10, (int)tn.Z * 10), Colors.LightCoral, false); var tn1 = dMisc_Grids_GridCentered_Subdivision.Transform.Origin; - DebugDraw3D.DrawGridXf(dMisc_Grids_GridCentered.GlobalTransform, new Vector2I((int)tn1.X * 10, (int)tn1.Z * 10)); + DebugDraw3D.DrawGridXf(dMisc_Grids_GridCentered.GlobalTransform, new Vector2I((int)(tn1.X * 10), (int)(tn1.Z * 10))); // 2D DebugDraw2D.Config.TextDefaultSize = text_groups_default_font_size; @@ -450,6 +481,10 @@ void _text_tests() DebugDraw2D.SetText("Filling lines buffer", $"{(render_stats.TimeFillingBuffersLinesUsec / 1000.0):F2} ms", 9); DebugDraw2D.SetText("Filling time", $"{(render_stats.TotalTimeFillingBuffersUsec / 1000.0):F2} ms", 10); DebugDraw2D.SetText("Total time", $"{(render_stats.TotalTimeSpentUsec / 1000.0):F2} ms", 11); + + DebugDraw2D.SetText("---", null, 14); + + DebugDraw2D.SetText("Created scoped configs", $"{render_stats.CreatedScopedConfigs}", 15); } if (text_groups_show_stats && text_groups_show_stats_2d) @@ -472,7 +507,7 @@ void _text_tests() { DebugDraw2D.BeginTextGroup("controls", 1024, Colors.White, false); DebugDraw2D.SetText("Shift: change render layers", DebugDraw3D.Config.GeometryRenderLayers, 1); - DebugDraw2D.SetText("Ctrl: change render layers", GetViewport().Msaa3D == Viewport.Msaa.Msaa4X ? "MSAA 4x" : "Disabled", 2); + DebugDraw2D.SetText("Ctrl: toggle anti-aliasing", GetViewport().Msaa3D == Viewport.Msaa.Msaa4X ? "MSAA 4x" : "Disabled", 2); DebugDraw2D.SetText("Down: freeze render", DebugDraw3D.Config.Freeze3dRender, 3); DebugDraw2D.SetText("Up: use scene camera", DebugDraw3D.Config.ForceUseCameraFromScene, 4); DebugDraw2D.SetText("1,2,3: toggle debug", $"{DebugDraw3D.DebugEnabled}, {DebugDraw2D.DebugEnabled} 😐, {DebugDrawManager.DebugEnabled} 😏", 5); @@ -493,12 +528,15 @@ void _more_tests() } // Delayed line render - DebugDraw3D.DrawLine(dLagTest.GlobalTransform.Origin + Vector3.Up, dLagTest.GlobalTransform.Origin + new Vector3(0, 3, Mathf.Sin(Time.GetTicksMsec() / 50.0f)), null, 0.5f); + using (var s = DebugDraw3D.NewScopedConfig().SetThickness(0.035f)) + { + DebugDraw3D.DrawLine(dLagTest.GlobalTransform.Origin + Vector3.Up, dLagTest.GlobalTransform.Origin + new Vector3(0, 3, Mathf.Sin(Time.GetTicksMsec() / 50.0f)), null, 0.5f); + } } void _draw_array_of_boxes() { - // Lots of boxes to check performance.. I guess.. + // Lots of boxes to check performance.. if (time2 <= 0) { for (int x = 0; x < 50; x++) diff --git a/examples_dd3d/DebugDrawDemoSceneCS.tscn b/examples_dd3d/DebugDrawDemoSceneCS.tscn index 2b919a74..7f54ba11 100644 --- a/examples_dd3d/DebugDrawDemoSceneCS.tscn +++ b/examples_dd3d/DebugDrawDemoSceneCS.tscn @@ -6,10 +6,7 @@ [node name="DebugDrawDemoSceneCS" instance=ExtResource("2")] script = ExtResource("2_ipqea") -[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) - -[node name="Settings" parent="." index="21"] +[node name="Settings" parent="." index="14"] switch_to_scene = "res://examples_dd3d/DebugDrawDemoScene.tscn" [node name="Label" parent="Settings/GC" index="0"] diff --git a/src/3d/config_scoped_3d.cpp b/src/3d/config_scoped_3d.cpp index 662c601d..c0430311 100644 --- a/src/3d/config_scoped_3d.cpp +++ b/src/3d/config_scoped_3d.cpp @@ -4,11 +4,20 @@ void DDScopedConfig3D::_bind_methods() { #define REG_CLASS_NAME DDScopedConfig3D + REG_METHOD(_manual_unregister); + REG_METHOD(set_thickness, "value"); REG_METHOD(get_thickness); #undef REG_CLASS_NAME } +void DDScopedConfig3D::_manual_unregister() { + if (unregister_action) { + unregister_action(thread_id, guard_id); + } + unregister_action = nullptr; +} + Ref DDScopedConfig3D::set_thickness(real_t value) { thickness = Math::clamp(value, (real_t)0, (real_t)100); return Ref(this); @@ -36,7 +45,5 @@ DDScopedConfig3D::DDScopedConfig3D(const uint64_t &p_thread_id, const uint64_t & } DDScopedConfig3D::~DDScopedConfig3D() { - if (unregister_action) { - unregister_action(thread_id, guard_id); - } + _manual_unregister(); } diff --git a/src/3d/config_scoped_3d.h b/src/3d/config_scoped_3d.h index 97ecef53..524d1307 100644 --- a/src/3d/config_scoped_3d.h +++ b/src/3d/config_scoped_3d.h @@ -22,6 +22,8 @@ class DDScopedConfig3D : public RefCounted { real_t thickness; public: + void _manual_unregister(); + Ref set_thickness(real_t value); real_t get_thickness(); diff --git a/src/dev_debug_draw_3d_Library.vcxproj b/src/dev_debug_draw_3d_Library.vcxproj index c55629dc..5713a1e2 100644 --- a/src/dev_debug_draw_3d_Library.vcxproj +++ b/src/dev_debug_draw_3d_Library.vcxproj @@ -132,7 +132,6 @@ libgodot-cpp.windows.$(Configuration).$(LlvmPlatformName).lib $(OutDir)$(TargetName)$(TargetExt) true - %(IgnoreSpecificDefaultLibraries) $(OutDir)$(TargetName)_vs.pdb @@ -161,7 +160,6 @@ $(OutDir)$(TargetName)$(TargetExt) Default true - %(IgnoreSpecificDefaultLibraries) $(OutDir)$(TargetName)_vs.pdb @@ -188,7 +186,6 @@ false libgodot-cpp.windows.$(Configuration).$(LlvmPlatformName).lib $(OutDir)$(TargetName)$(TargetExt) - %(IgnoreSpecificDefaultLibraries) UseLinkTimeCodeGeneration $(OutDir)$(TargetName)_vs.pdb @@ -216,7 +213,6 @@ false libgodot-cpp.windows.template_release.$(LlvmPlatformName).lib $(OutDir)$(TargetName)$(TargetExt) - %(IgnoreSpecificDefaultLibraries) UseLinkTimeCodeGeneration $(OutDir)$(TargetName)_vs.pdb diff --git a/src/editor/generate_csharp_bindings.cpp b/src/editor/generate_csharp_bindings.cpp index 27d01ed2..ffb43703 100644 --- a/src/editor/generate_csharp_bindings.cpp +++ b/src/editor/generate_csharp_bindings.cpp @@ -73,6 +73,11 @@ void GenerateCSharpBindingsPlugin::generate() { opened_log_file = FileAccess::open(out_log_path, FileAccess::ModeFlags::WRITE); ERR_FAIL_COND(FileAccess::get_open_error() != Error::OK); + property_method_prefix = TypedArray(Array::make( + "set", + "get", + "is")); + generate_for_classes = TypedArray(Array::make( "DebugDraw2D", "DebugDrawStats2D", @@ -82,7 +87,20 @@ void GenerateCSharpBindingsPlugin::generate() { "DebugDraw3D", "DebugDrawStats3D", "DebugDrawConfig3D", + "DDScopedConfig3D", "DebugDrawManager")); + + avoid_caching_for_classes = TypedArray(Array::make( + "DDScopedConfig3D")); + + additional_statics_for_classes = extend_class_strings{ + { "DDScopedConfig3D", { "private static readonly StringName ___manual_unregister = \"_manual_unregister\";" } } + }; + + override_disposable_for_classes = extend_class_strings{ + { "DDScopedConfig3D", { "Instance?.Call(___manual_unregister);" } } + }; + singletons = Engine::get_singleton()->get_singleton_list(); generate_header(); @@ -139,10 +157,16 @@ void GenerateCSharpBindingsPlugin::generate_class(const StringName &cls, remap_d line(); // class DebugDrawFPSGraph : DebugDrawGraph String static_modifier_str = is_singleton ? "static " : ""; + String additional_inheritance = ""; + + if (override_disposable_for_classes.find(cls) != override_disposable_for_classes.end()) { + additional_inheritance += ", IDisposable"; + } + if (is_preserved_inheritance) { - line(FMT_STR("internal class {0} : {1}", cls, parent_name)); + line(FMT_STR("internal class {0} : {1}{2}", cls, parent_name, additional_inheritance)); } else { - line(FMT_STR("{0}internal class {1}{2}", static_modifier_str, cls, is_singleton ? "" : " : _DebugDrawInstanceWrapper_")); + line(FMT_STR("{0}internal class {1}{2}{3}", static_modifier_str, cls, is_singleton ? "" : " : _DebugDrawInstanceWrapper_", additional_inheritance)); } { @@ -176,11 +200,14 @@ void GenerateCSharpBindingsPlugin::generate_class(const StringName &cls, remap_d for (int i = 0; i < methods.size(); i++) { String name = ((Dictionary)methods[i])["name"]; + auto split = name.split("_", true, 1); for (int j = 0; j < properties.size(); j++) { String prop_name = ((Dictionary)properties[j])["name"]; - auto split = name.split("_", true, 1); - if (split.size() == 2 && split[1] == prop_name) { + + // check for prefix (set, get, is) and name of property + // to avoid confusion between `config` and `scoped_config` + if (split.size() == 2 && split[1] == prop_name && (property_method_prefix.has(split[0].to_lower()))) { is_property.append(name); std::map::iterator it = properties_map.find(prop_name); @@ -208,9 +235,31 @@ void GenerateCSharpBindingsPlugin::generate_class(const StringName &cls, remap_d } } + const auto &it_add = additional_statics_for_classes.find(cls); + if (it_add != additional_statics_for_classes.end()) { + line("// Additional custom statics"); + for (const auto &i : it_add->second) { + added++; + line(i); + } + } + if (added) line(); + const auto &it_over = override_disposable_for_classes.find(cls); + if (it_over != override_disposable_for_classes.end()) { + line("// Custom Disposable"); + line("public new void Dispose()"); + { + TAB(); + for (const auto &i : it_over->second) { + line(i); + } + } + line(); + } + for (int i = 0; i < methods.size(); i++) { String name = ((Dictionary)methods[i])["name"]; @@ -281,7 +330,7 @@ void GenerateCSharpBindingsPlugin::generate_class_utilities(const remap_data &re line("public void Dispose()"); { TAB(); - line("Instance.Dispose();"); + line("Instance?.Dispose();"); line("Instance = null;"); } line(); @@ -389,7 +438,9 @@ void GenerateCSharpBindingsPlugin::generate_class_utilities(const remap_data &re { TAB(); line(FMT_STR("_DebugDrawInstanceWrapper_ new_instance = new {0}(_instance);", cls)); - line("cached_instances[id] = new_instance;"); + if (!avoid_caching_for_classes.has(cls)) { + line("cached_instances[id] = new_instance;"); + } line("return new_instance;"); } } diff --git a/src/editor/generate_csharp_bindings.h b/src/editor/generate_csharp_bindings.h index c243017d..5c9e09d6 100644 --- a/src/editor/generate_csharp_bindings.h +++ b/src/editor/generate_csharp_bindings.h @@ -85,7 +85,15 @@ class GenerateCSharpBindingsPlugin { String indent; Ref opened_file; Ref opened_log_file; + TypedArray property_method_prefix; + TypedArray generate_for_classes; + TypedArray avoid_caching_for_classes; + + typedef std::map > extend_class_strings; + extend_class_strings additional_statics_for_classes; + extend_class_strings override_disposable_for_classes; + PackedStringArray singletons; bool is_shift_pressed = false; bool is_generate_unload_event = false;