Skip to content

Commit

Permalink
changed file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Aug 3, 2023
1 parent 38229d0 commit 4bd63c0
Show file tree
Hide file tree
Showing 41 changed files with 428 additions and 287 deletions.
2 changes: 1 addition & 1 deletion dev_debug_draw_3d_Library.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33110.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "debug_draw_3d_Library", "dev_debug_draw_3d_Library.vcxproj", "{A265372D-FCD7-4FBD-9F8C-0D31F6D0F557}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "debug_draw_3d_Library", "src/dev_debug_draw_3d_Library.vcxproj", "{A265372D-FCD7-4FBD-9F8C-0D31F6D0F557}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
36 changes: 18 additions & 18 deletions examples_dd3d/DebugDrawDemoScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,28 @@ func _process(delta: float) -> void:
$LagTest.visible = true

# Testing the rendering layers by showing the image from the second camera inside the 2D panel
#DebugDraw3D.config_3d.geometry_render_layers = 1 if !Input.is_key_pressed(KEY_SHIFT) else 0b10010
#DebugDraw3D.config.geometry_render_layers = 1 if !Input.is_key_pressed(KEY_SHIFT) else 0b10010
$Panel.visible = Input.is_key_pressed(KEY_SHIFT)
DebugDraw2D.custom_canvas = $CustomCanvas if Input.is_key_pressed(KEY_SHIFT) else null

# More property toggles
DebugDraw3D.config_3d.freeze_3d_render = Input.is_key_pressed(KEY_ENTER)
DebugDraw3D.config.freeze_3d_render = Input.is_key_pressed(KEY_ENTER)
DebugDraw3D.debug_enabled = !Input.is_key_pressed(KEY_DOWN)
DebugDraw2D.debug_enabled = !Input.is_key_pressed(KEY_DOWN)
DebugDraw3D.config_3d.visible_instance_bounds = Input.is_key_pressed(KEY_RIGHT)
DebugDraw3D.config.visible_instance_bounds = Input.is_key_pressed(KEY_RIGHT)

# Some property toggles
if _is_key_just_pressed(KEY_F1):
zylann_example = !zylann_example
if _is_key_just_pressed(KEY_LEFT):
DebugDraw3D.config_3d.use_frustum_culling = !DebugDraw3D.config_3d.use_frustum_culling
DebugDraw3D.config.use_frustum_culling = !DebugDraw3D.config.use_frustum_culling
if _is_key_just_pressed(KEY_UP):
DebugDraw3D.config_3d.force_use_camera_from_scene = !DebugDraw3D.config_3d.force_use_camera_from_scene
DebugDraw3D.config.force_use_camera_from_scene = !DebugDraw3D.config.force_use_camera_from_scene

if Engine.is_editor_hint():
DebugDraw3D.config_3d.cull_by_distance = start_culling_distance if DebugDraw3D.config_3d.force_use_camera_from_scene else 0.0
DebugDraw3D.config.cull_by_distance = start_culling_distance if DebugDraw3D.config.force_use_camera_from_scene else 0.0
else:
DebugDraw3D.config_3d.cull_by_distance = start_culling_distance
DebugDraw3D.config.cull_by_distance = start_culling_distance
_update_keys_just_press()

# Zones with black borders
Expand Down Expand Up @@ -196,12 +196,12 @@ func _process(delta: float) -> void:
DebugDraw3D.draw_grid_xf($Misc/Grids/GridCentered.global_transform, Vector2i(tn1.x*10, tn1.z*10))

# 2D
DebugDraw2D.config_2d.text_default_size = text_groups_default_font_size
DebugDraw2D.config_2d.text_block_offset = text_groups_offset
DebugDraw2D.config_2d.text_block_position = text_groups_position
DebugDraw2D.config_2d.text_padding = text_groups_padding
DebugDraw2D.config.text_default_size = text_groups_default_font_size
DebugDraw2D.config.text_block_offset = text_groups_offset
DebugDraw2D.config.text_block_position = text_groups_position
DebugDraw2D.config.text_padding = text_groups_padding

DebugDraw2D.config_2d.text_custom_font = custom_font
DebugDraw2D.config.text_custom_font = custom_font

if test_text:
_text_tests()
Expand Down Expand Up @@ -272,12 +272,12 @@ func _text_tests():

if text_groups_show_hints:
DebugDraw2D.begin_text_group("controls", 1024, Color.WHITE, false)
DebugDraw2D.set_text("Shift: change render layers", DebugDraw3D.config_3d.geometry_render_layers, 1)
DebugDraw2D.set_text("Enter: freeze render", DebugDraw3D.config_3d.freeze_3d_render, 2)
DebugDraw2D.set_text("Up: use scene camera", DebugDraw3D.config_3d.force_use_camera_from_scene, 3)
DebugDraw2D.set_text("Shift: change render layers", DebugDraw3D.config.geometry_render_layers, 1)
DebugDraw2D.set_text("Enter: freeze render", DebugDraw3D.config.freeze_3d_render, 2)
DebugDraw2D.set_text("Up: use scene camera", DebugDraw3D.config.force_use_camera_from_scene, 3)
DebugDraw2D.set_text("Down: toggle debug", DebugDraw2D.debug_enabled, 4)
DebugDraw2D.set_text("Left: toggle frustum culling", DebugDraw3D.config_3d.use_frustum_culling, 5)
DebugDraw2D.set_text("Right: draw bounds for culling", DebugDraw3D.config_3d.visible_instance_bounds, 6)
DebugDraw2D.set_text("Left: toggle frustum culling", DebugDraw3D.config.use_frustum_culling, 5)
DebugDraw2D.set_text("Right: draw bounds for culling", DebugDraw3D.config.visible_instance_bounds, 6)


func _more_tests():
Expand Down Expand Up @@ -350,7 +350,7 @@ func _graph_test():


func _upd_graph_params():
DebugDraw2D.config_2d.graphs_base_offset = graph_offset
DebugDraw2D.config.graphs_base_offset = graph_offset
for g in [&"FPS", &"fps5", &"fps8"]:
var graph := DebugDraw2D.get_graph(g) as DebugDrawFPSGraph
if graph:
Expand Down
7 changes: 3 additions & 4 deletions src/debug_draw_config_2d.cpp → src/2d/config_2d.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "debug_draw_config_2d.h"
#include "utils.h"
#include "config_2d.h"
#include "utils/utils.h"

#include "data_graphs.h"
#include "debug_geometry_container.h"
#include "graphs.h"
#include "grouped_text.h"

#include <limits.h>
Expand Down
3 changes: 2 additions & 1 deletion src/debug_draw_config_2d.h → src/2d/config_2d.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "colors.h"
#include "common/colors.h"
#include "utils/compiler.h"

GODOT_WARNING_DISABLE()
#include <godot_cpp/classes/font.hpp>
Expand Down
36 changes: 17 additions & 19 deletions src/debug_draw_2d.cpp → src/2d/debug_draw_2d.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include "debug_draw_2d.h"

#include "data_graphs.h"
#include "debug_draw_config_2d.h"
#include "debug_draw_config_3d.h"
#include "config_2d.h"
#include "debug_draw_manager.h"
#include "debug_geometry_container.h"
#include "draw_stats.h"
#include "graphs.h"
#include "grouped_text.h"
#include "utils.h"
#include "stats_2d.h"
#include "utils/utils.h"

GODOT_WARNING_DISABLE()
#include <godot_cpp/classes/config_file.hpp>
Expand Down Expand Up @@ -41,7 +39,7 @@ void DebugDraw2D::_bind_methods() {
REG_PROP(empty_color, Variant::COLOR);
REG_PROP_BOOL(debug_enabled);

REG_PROP(config_2d, Variant::OBJECT);
REG_PROP(config, Variant::OBJECT);

REG_PROP(custom_canvas, Variant::OBJECT);

Expand Down Expand Up @@ -74,7 +72,7 @@ DebugDraw2D::DebugDraw2D() {

void DebugDraw2D::init(DebugDrawManager *root) {
root_node = root;
set_config_2d(nullptr);
set_config(nullptr);

#ifndef DISABLE_DEBUG_RENDERING
grouped_text = std::make_unique<GroupedText>();
Expand Down Expand Up @@ -109,7 +107,7 @@ DebugDraw2D::~DebugDraw2D() {
#endif

root_node = nullptr;
config_2d.unref();
config.unref();
}

void DebugDraw2D::process(double delta) {
Expand Down Expand Up @@ -178,26 +176,26 @@ bool DebugDraw2D::is_debug_enabled() const {
return debug_enabled;
}

void DebugDraw2D::set_config_2d(Ref<DebugDrawConfig2D> _cfg) {
void DebugDraw2D::set_config(Ref<DebugDrawConfig2D> _cfg) {
if (_cfg.is_valid()) {
#ifndef DISABLE_DEBUG_RENDERING
Utils::disconnect_safe(config_2d, DebugDrawConfig2D::s_marked_dirty, Callable(this, NAMEOF(_on_canvas_marked_dirty)));
Utils::disconnect_safe(config, DebugDrawConfig2D::s_marked_dirty, Callable(this, NAMEOF(_on_canvas_marked_dirty)));
#endif

config_2d = _cfg;
config = _cfg;
} else {
config_2d = Ref<DebugDrawConfig2D>();
config_2d.instantiate();
config = Ref<DebugDrawConfig2D>();
config.instantiate();
}

#ifndef DISABLE_DEBUG_RENDERING
mark_canvas_dirty();
Utils::connect_safe(config_2d, DebugDrawConfig2D::s_marked_dirty, Callable(this, NAMEOF(_on_canvas_marked_dirty)));
Utils::connect_safe(config, DebugDrawConfig2D::s_marked_dirty, Callable(this, NAMEOF(_on_canvas_marked_dirty)));
#endif
}

Ref<DebugDrawConfig2D> DebugDraw2D::get_config_2d() const {
return config_2d;
Ref<DebugDrawConfig2D> DebugDraw2D::get_config() const {
return config;
}

void DebugDraw2D::set_custom_canvas(Control *_canvas) {
Expand All @@ -224,9 +222,9 @@ Control *DebugDraw2D::get_custom_canvas() const {

#pragma region Draw Functions

Ref<DebugDrawStats> DebugDraw2D::get_render_stats() {
Ref<DebugDrawStats2D> DebugDraw2D::get_render_stats() {
// TODO: add 2d version
return Ref<DebugDrawStats>();
return Ref<DebugDrawStats2D>();
}

void DebugDraw2D::clear_2d_objects() {
Expand Down
14 changes: 7 additions & 7 deletions src/debug_draw_2d.h → src/2d/debug_draw_2d.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "colors.h"
#include "geometry_generators.h"
#include "common/colors.h"
#include "utils/compiler.h"

GODOT_WARNING_DISABLE()
#include <godot_cpp/classes/camera3d.hpp> // TODO: need to be removed with vararg functions in release build.
Expand All @@ -20,7 +20,7 @@ class DataGraphManager;
class DebugDrawManager;
class DebugDrawConfig2D;
class DebugDrawGraph;
class DebugDrawStats;
class DebugDrawStats2D;
class GroupedText;

class DebugDraw2D : public Object {
Expand Down Expand Up @@ -63,7 +63,7 @@ class DebugDraw2D : public Object {
/// Custom 'CanvasItem' to draw on it. Set to 'null' to disable.
Control *custom_canvas = nullptr;

Ref<DebugDrawConfig2D> config_2d;
Ref<DebugDrawConfig2D> config;

#pragma endregion // Exposed Parameter Values

Expand All @@ -90,8 +90,8 @@ class DebugDraw2D : public Object {
void set_debug_enabled(const bool &_state);
bool is_debug_enabled() const;

void set_config_2d(Ref<DebugDrawConfig2D> _cfg);
Ref<DebugDrawConfig2D> get_config_2d() const;
void set_config(Ref<DebugDrawConfig2D> _cfg);
Ref<DebugDrawConfig2D> get_config() const;

void set_custom_canvas(Control *_canvas);
Control *get_custom_canvas() const;
Expand All @@ -101,7 +101,7 @@ class DebugDraw2D : public Object {

/// Returns a dictionary with rendering statistics.
/// Some data can be delayed by 1 frame.
Ref<DebugDrawStats> get_render_stats();
Ref<DebugDrawStats2D> get_render_stats();

/// Clear all 2D objects
void clear_2d_objects();
Expand Down
10 changes: 5 additions & 5 deletions src/data_graphs.cpp → src/2d/graphs.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "data_graphs.h"
#include "graphs.h"
#include "config_2d.h"
#include "debug_draw_2d.h"
#include "debug_draw_config_2d.h"
#include "math_utils.h"
#include "utils.h"
#include "utils/math_utils.h"
#include "utils/utils.h"

#include <limits.h>

Expand Down Expand Up @@ -703,7 +703,7 @@ void DataGraphManager::draw(CanvasItem *_ci, Ref<Font> _font, Vector2 _vp_size,
populate_nodes(&n);
}

Vector2 base_offset = owner->get_config_2d()->get_graphs_base_offset();
Vector2 base_offset = owner->get_config()->get_graphs_base_offset();
Rect2i base_rect[DebugDrawGraph::POSITION_MAX] = {
Rect2i(base_offset, Vector2i()), // left_top
Rect2i(Vector2(_vp_size.x - base_offset.x, base_offset.y), Vector2i()), // right_top
Expand Down
7 changes: 5 additions & 2 deletions src/data_graphs.h → src/2d/graphs.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include "circular_buffer.h"
#include "colors.h"
#include "common/circular_buffer.h"
#include "common/colors.h"
#include "utils/compiler.h"

GODOT_WARNING_DISABLE()
#include <godot_cpp/classes/canvas_item.hpp>
Expand All @@ -10,6 +11,8 @@ GODOT_WARNING_DISABLE()
GODOT_WARNING_RESTORE()

#include <map>
#include <mutex>
#include <vector>

using namespace godot;

Expand Down
Loading

0 comments on commit 4bd63c0

Please sign in to comment.