Skip to content

Commit

Permalink
updated C# generator
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Dec 4, 2023
1 parent 03d4062 commit aa516aa
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 60 deletions.
13 changes: 6 additions & 7 deletions examples_dd3d/DebugDrawDemoScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions examples_dd3d/DebugDrawDemoScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
106 changes: 72 additions & 34 deletions examples_dd3d/DebugDrawDemoSceneCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -41,6 +42,7 @@ public partial class DebugDrawDemoSceneCS : Node3D
Dictionary<Key, int> button_presses = new Dictionary<Key, int>() {
{ Key.Left, 0 },
{ Key.Up, 0 },
{ Key.Ctrl, 0 },
{ Key.F1, 0 },
{ Key.Key1, 0 },
{ Key.Key2, 0 },
Expand All @@ -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;
Expand All @@ -98,25 +103,28 @@ public override async void _Ready()
dLagTest = GetNode<CsgBox3D>("LagTest");
dPanel = GetNode<PanelContainer>("Panel");
dZones = GetNode<Node3D>("Zones");
dAABB = GetNode<Node3D>("AABB");
dAABB_fixed = GetNode<Node3D>("AABB_fixed");
dSpherePosition = GetNode<Node3D>("SpherePosition");
dSphereTransform = GetNode<Node3D>("SphereTransform");
dSphereHDTransform = GetNode<Node3D>("SphereHDTransform");
dBox1 = GetNode<Node3D>("Box1");
dBox2 = GetNode<Node3D>("Box2");
dBox3 = GetNode<Node3D>("Box3");
dBoxOutOfDistanceCulling = GetNode<Node3D>("BoxOutOfDistanceCulling");
dSpherePosition = GetNode<Node3D>("Spheres/SpherePosition");
dSphereTransform = GetNode<Node3D>("Spheres/SphereTransform");
dSphereHDTransform = GetNode<Node3D>("Spheres/SphereHDTransform");
dAABB = GetNode<Node3D>("Boxes/AABB");
dAABB_fixed = GetNode<Node3D>("Boxes/AABB_fixed");
dBox1 = GetNode<Node3D>("Boxes/Box1");
dBox2 = GetNode<Node3D>("Boxes/Box2");
dBox3 = GetNode<Node3D>("Boxes/Box3");
dBoxOutOfDistanceCulling = GetNode<Node3D>("Boxes/BoxOutOfDistanceCulling");
dLines_1 = GetNode<Node3D>("Lines/1");
dLines_3 = GetNode<Node3D>("Lines/3");
dLines_6 = GetNode<Node3D>("Lines/6");
dLines_2 = GetNode<Node3D>("Lines/2");
dLines_3 = GetNode<Node3D>("Lines/3");
dLines_4 = GetNode<Node3D>("Lines/4");
dLines_5 = GetNode<Node3D>("Lines/5");
dLines_6 = GetNode<Node3D>("Lines/6");
dLines_7 = GetNode<Node3D>("Lines/7");
dLines_Target = GetNode<Node3D>("Lines/Target");
dLinePath = GetNode<Node3D>("LinePath");
dCylinder1 = GetNode<Node3D>("Cylinder1");
dCylinder2 = GetNode<Node3D>("Cylinder2");
dCylinder1 = GetNode<Node3D>("Cylinders/Cylinder1");
dCylinder2 = GetNode<Node3D>("Cylinders/Cylinder2");
dCylinder3a = GetNode<Node3D>("Cylinders/Cylinder3/1");
dCylinder3b = GetNode<Node3D>("Cylinders/Cylinder3/2");

dCustomCanvas = GetNode<Control>("CustomCanvas");
dMisc_Arrow = GetNode<Node3D>("Misc/Arrow");
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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++)
Expand Down
5 changes: 1 addition & 4 deletions examples_dd3d/DebugDrawDemoSceneCS.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 10 additions & 3 deletions src/3d/config_scoped_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> DDScopedConfig3D::set_thickness(real_t value) {
thickness = Math::clamp(value, (real_t)0, (real_t)100);
return Ref<DDScopedConfig3D>(this);
Expand Down Expand Up @@ -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();
}
2 changes: 2 additions & 0 deletions src/3d/config_scoped_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class DDScopedConfig3D : public RefCounted {
real_t thickness;

public:
void _manual_unregister();

Ref<DDScopedConfig3D> set_thickness(real_t value);
real_t get_thickness();

Expand Down
4 changes: 0 additions & 4 deletions src/dev_debug_draw_3d_Library.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
<AdditionalDependencies>libgodot-cpp.windows.$(Configuration).$(LlvmPlatformName).lib</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<ProgramDatabaseFile>$(OutDir)$(TargetName)_vs.pdb</ProgramDatabaseFile>
</Link>
</ItemDefinitionGroup>
Expand Down Expand Up @@ -161,7 +160,6 @@
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
<SuppressStartupBanner>true</SuppressStartupBanner>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<ProgramDatabaseFile>$(OutDir)$(TargetName)_vs.pdb</ProgramDatabaseFile>
</Link>
</ItemDefinitionGroup>
Expand All @@ -188,7 +186,6 @@
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>libgodot-cpp.windows.$(Configuration).$(LlvmPlatformName).lib</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<ProgramDatabaseFile>$(OutDir)$(TargetName)_vs.pdb</ProgramDatabaseFile>
</Link>
Expand Down Expand Up @@ -216,7 +213,6 @@
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>libgodot-cpp.windows.template_release.$(LlvmPlatformName).lib</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<ProgramDatabaseFile>$(OutDir)$(TargetName)_vs.pdb</ProgramDatabaseFile>
</Link>
Expand Down
Loading

0 comments on commit aa516aa

Please sign in to comment.