From 0cc399837905a834a17f554ee87aaf3084f9bbf8 Mon Sep 17 00:00:00 2001 From: DmitriySalnikov Date: Fri, 26 Jul 2024 17:04:25 +0300 Subject: [PATCH] Small fixes and renaming --- src/3d/config_scope_3d.cpp | 14 ++-- src/3d/config_scope_3d.h | 2 +- src/3d/debug_draw_3d.cpp | 23 ++---- src/3d/debug_geometry_container.cpp | 44 +++++----- src/3d/debug_geometry_container.h | 2 +- src/3d/geometry_generators.cpp | 124 ++++++++++------------------ src/3d/geometry_generators.h | 2 +- src/3d/render_instances.cpp | 8 +- 8 files changed, 89 insertions(+), 130 deletions(-) diff --git a/src/3d/config_scope_3d.cpp b/src/3d/config_scope_3d.cpp index 451ca346..3be00ba1 100644 --- a/src/3d/config_scope_3d.cpp +++ b/src/3d/config_scope_3d.cpp @@ -70,21 +70,21 @@ real_t DebugDraw3DScopeConfig::get_plane_size() const { } Ref DebugDraw3DScopeConfig::set_viewport(Viewport *_value) const { - data->dgcd.viewport = _value; + data->dcd.viewport = _value; return Ref(this); } Viewport *DebugDraw3DScopeConfig::get_viewport() const { - return data->dgcd.viewport; + return data->dcd.viewport; } Ref DebugDraw3DScopeConfig::set_no_depth_test(bool _value) const { - data->dgcd.no_depth_test = _value; + data->dcd.no_depth_test = _value; return Ref(this); } bool DebugDraw3DScopeConfig::is_no_depth_test() const { - return data->dgcd.no_depth_test; + return data->dcd.no_depth_test; } DebugDraw3DScopeConfig::DebugDraw3DScopeConfig() { @@ -113,7 +113,7 @@ DebugDraw3DScopeConfig::Data::Data() { center_brightness = 0; hd_sphere = false; plane_size = INFINITY; - dgcd = {}; + dcd = {}; } DebugDraw3DScopeConfig::Data::Data(const std::shared_ptr &p_parent) { @@ -122,6 +122,6 @@ DebugDraw3DScopeConfig::Data::Data(const std::shared_ptr &p_parent) { hd_sphere = p_parent->hd_sphere; plane_size = p_parent->plane_size; - dgcd.viewport = p_parent->dgcd.viewport; - dgcd.no_depth_test = p_parent->dgcd.no_depth_test; + dcd.viewport = p_parent->dcd.viewport; + dcd.no_depth_test = p_parent->dcd.no_depth_test; } diff --git a/src/3d/config_scope_3d.h b/src/3d/config_scope_3d.h index e8e41182..7e80ed73 100644 --- a/src/3d/config_scope_3d.h +++ b/src/3d/config_scope_3d.h @@ -94,7 +94,7 @@ class DebugDraw3DScopeConfig : public RefCounted { real_t center_brightness; bool hd_sphere; real_t plane_size; - DebugContainerDependent dgcd; + DebugContainerDependent dcd; Data(); Data(const std::shared_ptr &parent); diff --git a/src/3d/debug_draw_3d.cpp b/src/3d/debug_draw_3d.cpp index d206d47c..8d78267b 100644 --- a/src/3d/debug_draw_3d.cpp +++ b/src/3d/debug_draw_3d.cpp @@ -685,28 +685,21 @@ void DebugDraw3D::clear_all() { if (NEED_LEAVE || config->is_freeze_3d_render()) return; #endif -#define GET_SCOPED_CFG_AND_DGC() \ - auto scfg = scoped_config_for_current_thread(); \ - auto dgc = get_debug_container(scfg->dgcd, true); \ +#define GET_SCOPED_CFG_AND_DGC() \ + auto scfg = scoped_config_for_current_thread(); \ + auto dgc = get_debug_container(scfg->dcd, true); \ if (!dgc) return #ifndef DISABLE_DEBUG_RENDERING Vector3 DebugDraw3D::get_up_vector(const Vector3 &p_dir) { - bool ex = Math::is_equal_approx(p_dir.x, 0); - bool ey = Math::is_equal_approx(p_dir.y, 0); - bool ez = Math::is_equal_approx(p_dir.z, 0); - - if (ex) { - if (ey) { - return Vector3_UP; - } else if (ez) { + if (Math::is_equal_approx(p_dir.x, 0)) { + if (Math::is_equal_approx(p_dir.z, 0)) return Vector3_FORWARD; - } return Vector3_UP; - } else if (ey) { + } else if (Math::is_equal_approx(p_dir.y, 0)) { return p_dir.normalized().cross(Vector3_UP); - } else if (ez) { + } else if (Math::is_equal_approx(p_dir.z, 0)) { return Vector3_UP; } @@ -1138,7 +1131,7 @@ void DebugDraw3D::draw_plane(const Plane &plane, const Color &color, const Vecto LOCK_GUARD(datalock); GET_SCOPED_CFG_AND_DGC(); - Camera3D *cam = scfg->dgcd.viewport ? scfg->dgcd.viewport->get_camera_3d() : nullptr; + Camera3D *cam = scfg->dcd.viewport ? scfg->dcd.viewport->get_camera_3d() : nullptr; Vector3 center_pos = plane.project(anchor_point == Vector3_INF ? (cam ? cam->get_global_position() : Vector3()) : anchor_point); real_t plane_size = scfg->plane_size != INFINITY ? scfg->plane_size : (cam ? (real_t)cam->get_far() : 1000); diff --git a/src/3d/debug_geometry_container.cpp b/src/3d/debug_geometry_container.cpp index 15aa578f..502cae11 100644 --- a/src/3d/debug_geometry_container.cpp +++ b/src/3d/debug_geometry_container.cpp @@ -48,31 +48,31 @@ DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *p_root, bool p auto *meshes = owner->get_shared_meshes(); int mat_variant = !!no_depth_test; - CreateMMI(InstanceType::CUBE, NAMEOF(mmi_cubes), meshes[(int)InstanceType::CUBE][mat_variant]); - CreateMMI(InstanceType::CUBE_CENTERED, NAMEOF(mmi_cubes_centered), meshes[(int)InstanceType::CUBE_CENTERED][mat_variant]); - CreateMMI(InstanceType::ARROWHEAD, NAMEOF(mmi_arrowheads), meshes[(int)InstanceType::ARROWHEAD][mat_variant]); - CreateMMI(InstanceType::POSITION, NAMEOF(mmi_positions), meshes[(int)InstanceType::POSITION][mat_variant]); - CreateMMI(InstanceType::SPHERE, NAMEOF(mmi_spheres), meshes[(int)InstanceType::SPHERE][mat_variant]); - CreateMMI(InstanceType::SPHERE_HD, NAMEOF(mmi_spheres_hd), meshes[(int)InstanceType::SPHERE_HD][mat_variant]); - CreateMMI(InstanceType::CYLINDER, NAMEOF(mmi_cylinders), meshes[(int)InstanceType::CYLINDER][mat_variant]); - CreateMMI(InstanceType::CYLINDER_AB, NAMEOF(mmi_cylinders), meshes[(int)InstanceType::CYLINDER_AB][mat_variant]); + CreateMMI(InstanceType::CUBE, meshes[(int)InstanceType::CUBE][mat_variant]); + CreateMMI(InstanceType::CUBE_CENTERED, meshes[(int)InstanceType::CUBE_CENTERED][mat_variant]); + CreateMMI(InstanceType::ARROWHEAD, meshes[(int)InstanceType::ARROWHEAD][mat_variant]); + CreateMMI(InstanceType::POSITION, meshes[(int)InstanceType::POSITION][mat_variant]); + CreateMMI(InstanceType::SPHERE, meshes[(int)InstanceType::SPHERE][mat_variant]); + CreateMMI(InstanceType::SPHERE_HD, meshes[(int)InstanceType::SPHERE_HD][mat_variant]); + CreateMMI(InstanceType::CYLINDER, meshes[(int)InstanceType::CYLINDER][mat_variant]); + CreateMMI(InstanceType::CYLINDER_AB, meshes[(int)InstanceType::CYLINDER_AB][mat_variant]); // VOLUMETRIC - CreateMMI(InstanceType::LINE_VOLUMETRIC, NAMEOF(mmi_cubes_volumetric), meshes[(int)InstanceType::LINE_VOLUMETRIC][mat_variant]); - CreateMMI(InstanceType::CUBE_VOLUMETRIC, NAMEOF(mmi_cubes_volumetric), meshes[(int)InstanceType::CUBE_VOLUMETRIC][mat_variant]); - CreateMMI(InstanceType::CUBE_CENTERED_VOLUMETRIC, NAMEOF(mmi_cubes_centered_volumetric), meshes[(int)InstanceType::CUBE_CENTERED_VOLUMETRIC][mat_variant]); - CreateMMI(InstanceType::ARROWHEAD_VOLUMETRIC, NAMEOF(mmi_arrowheads_volumetric), meshes[(int)InstanceType::ARROWHEAD_VOLUMETRIC][mat_variant]); - CreateMMI(InstanceType::POSITION_VOLUMETRIC, NAMEOF(mmi_positions_volumetric), meshes[(int)InstanceType::POSITION_VOLUMETRIC][mat_variant]); - CreateMMI(InstanceType::SPHERE_VOLUMETRIC, NAMEOF(mmi_spheres_volumetric), meshes[(int)InstanceType::SPHERE_VOLUMETRIC][mat_variant]); - CreateMMI(InstanceType::SPHERE_HD_VOLUMETRIC, NAMEOF(mmi_spheres_hd_volumetric), meshes[(int)InstanceType::SPHERE_HD_VOLUMETRIC][mat_variant]); - CreateMMI(InstanceType::CYLINDER_VOLUMETRIC, NAMEOF(mmi_cylinders_volumetric), meshes[(int)InstanceType::CYLINDER_VOLUMETRIC][mat_variant]); - CreateMMI(InstanceType::CYLINDER_AB_VOLUMETRIC, NAMEOF(mmi_cylinders_volumetric), meshes[(int)InstanceType::CYLINDER_AB_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::LINE_VOLUMETRIC, meshes[(int)InstanceType::LINE_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::CUBE_VOLUMETRIC, meshes[(int)InstanceType::CUBE_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::CUBE_CENTERED_VOLUMETRIC, meshes[(int)InstanceType::CUBE_CENTERED_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::ARROWHEAD_VOLUMETRIC, meshes[(int)InstanceType::ARROWHEAD_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::POSITION_VOLUMETRIC, meshes[(int)InstanceType::POSITION_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::SPHERE_VOLUMETRIC, meshes[(int)InstanceType::SPHERE_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::SPHERE_HD_VOLUMETRIC, meshes[(int)InstanceType::SPHERE_HD_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::CYLINDER_VOLUMETRIC, meshes[(int)InstanceType::CYLINDER_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::CYLINDER_AB_VOLUMETRIC, meshes[(int)InstanceType::CYLINDER_AB_VOLUMETRIC][mat_variant]); // SOLID - CreateMMI(InstanceType::BILLBOARD_SQUARE, NAMEOF(mmi_billboard_squares), meshes[(int)InstanceType::BILLBOARD_SQUARE][mat_variant]); - CreateMMI(InstanceType::PLANE, NAMEOF(mmi_planes), meshes[(int)InstanceType::PLANE][mat_variant]); + CreateMMI(InstanceType::BILLBOARD_SQUARE, meshes[(int)InstanceType::BILLBOARD_SQUARE][mat_variant]); + CreateMMI(InstanceType::PLANE, meshes[(int)InstanceType::PLANE][mat_variant]); set_render_layer_mask(1); } @@ -90,7 +90,7 @@ bool DebugGeometryContainer::is_no_depth_test() const { return no_depth_test; } -void DebugGeometryContainer::CreateMMI(InstanceType p_type, const String &p_name, Ref p_mesh) { +void DebugGeometryContainer::CreateMMI(InstanceType p_type, Ref p_mesh) { ZoneScoped; RenderingServer *rs = RenderingServer::get_singleton(); @@ -277,7 +277,7 @@ void DebugGeometryContainer::update_geometry(double p_delta) { // Draw custom sphere for 1 frame for (auto &i : new_instances) { - cfg->dgcd.viewport = vp; + cfg->dcd.viewport = vp; Vector3 diag = i.max - i.min; Vector3 center = i.center; real_t radius = i.radius; @@ -309,7 +309,7 @@ void DebugGeometryContainer::update_geometry(double p_delta) { Vector3 center = o->bounds.center; real_t radius = o->bounds.radius; - cfg->dgcd.viewport = vp; + cfg->dcd.viewport = vp; geometry_pool.add_or_update_instance( cfg, InstanceType::CUBE_CENTERED, diff --git a/src/3d/debug_geometry_container.h b/src/3d/debug_geometry_container.h index c613e9b7..aa8cdd9b 100644 --- a/src/3d/debug_geometry_container.h +++ b/src/3d/debug_geometry_container.h @@ -48,7 +48,7 @@ class DebugGeometryContainer { bool is_frame_rendered = false; bool no_depth_test = false; - void CreateMMI(InstanceType p_type, const String &p_name, Ref p_mesh); + void CreateMMI(InstanceType p_type, Ref p_mesh); public: DebugGeometryContainer(class DebugDraw3D *p_root, bool p_no_depth_test); diff --git a/src/3d/geometry_generators.cpp b/src/3d/geometry_generators.cpp index b7545d8f..26cad5d9 100644 --- a/src/3d/geometry_generators.cpp +++ b/src/3d/geometry_generators.cpp @@ -20,43 +20,31 @@ const std::array GeometryGenerator::CenteredCubeVertexes{ }; const std::array GeometryGenerator::CubeVertexes{ - Vector3(0, 0, 0), - Vector3(1, 0, 0), - Vector3(1, 0, 1), - Vector3(0, 0, 1), - Vector3(0, 1, 0), - Vector3(1, 1, 0), - Vector3(1, 1, 1), - Vector3(0, 1, 1) + Vector3(0, 0, 0), // 0 + Vector3(1, 0, 0), // 1 + Vector3(1, 0, 1), // 2 + Vector3(0, 0, 1), // 3 + Vector3(0, 1, 0), // 4 + Vector3(1, 1, 0), // 5 + Vector3(1, 1, 1), // 6 + Vector3(0, 1, 1) // 7 }; const std::array GeometryGenerator::CubeIndexes{ - 0, - 1, - 1, - 2, - 2, - 3, - 3, - 0, - - 4, - 5, - 5, - 6, - 6, - 7, - 7, - 4, - - 0, - 4, - 1, - 5, - 2, - 6, - 3, - 7, + 0, 1, + 1, 2, + 2, 3, + 3, 0, + + 4, 5, + 5, 6, + 6, 7, + 7, 4, + + 0, 4, + 1, 5, + 2, 6, + 3, 7 }; const std::array GeometryGenerator::CubeWithDiagonalsIndexes{ @@ -112,40 +100,27 @@ const std::array GeometryGenerator::ArrowheadVertexes{ }; const std::array GeometryGenerator::ArrowheadIndexes{ - 0, - 1, - 0, - 2, - 0, - 3, - 0, - 4, + 0, 1, + 0, 2, + 0, 3, + 0, 4, // Center line - 5, - 0, + 5, 0, // Cross // 1, 2, // 3, 4, // Or Cross to center - 5, - 1, - 5, - 2, - 5, - 3, - 5, - 4, + 5, 1, + 5, 2, + 5, 3, + 5, 4 }; -const std::array GeometryGenerator::ArrowheadIndexesSimplified{ - 0, - 1, - 0, - 2, - 0, - 3, - 0, - 4, +const std::array GeometryGenerator::ArrowheadIndexesSimplified{ + 0, 1, + 0, 2, + 0, 3, + 0, 4 }; const std::array GeometryGenerator::CenteredSquareVertexes{ @@ -156,21 +131,15 @@ const std::array GeometryGenerator::CenteredSquareVertexes{ }; const std::array GeometryGenerator::SquareBackwardsIndexes{ - 0, - 1, - 2, - 2, - 3, - 0, + 0, 1, + 2, 2, + 3, 0 }; const std::array GeometryGenerator::SquareIndexes{ - 0, - 2, - 1, - 2, - 0, - 3, + 0, 2, + 1, 2, + 0, 3 }; const std::array GeometryGenerator::PositionVertexes{ @@ -183,12 +152,9 @@ const std::array GeometryGenerator::PositionVertexes{ }; const std::array GeometryGenerator::PositionIndexes{ - 0, - 1, - 2, - 3, - 4, - 5, + 0, 1, + 2, 3, + 4, 5 }; #pragma endregion diff --git a/src/3d/geometry_generators.h b/src/3d/geometry_generators.h index 779dc710..2e06cb0e 100644 --- a/src/3d/geometry_generators.h +++ b/src/3d/geometry_generators.h @@ -34,7 +34,7 @@ class GeometryGenerator { const static std::array ArrowheadVertexes; const static std::array ArrowheadIndexes; - const static std::array ArrowheadIndexesSimplified; + const static std::array ArrowheadIndexesSimplified; const static std::array CenteredSquareVertexes; const static std::array SquareBackwardsIndexes; diff --git a/src/3d/render_instances.cpp b/src/3d/render_instances.cpp index 0ea127dc..5df2517c 100644 --- a/src/3d/render_instances.cpp +++ b/src/3d/render_instances.cpp @@ -469,9 +469,9 @@ void GeometryPool::add_or_update_instance(const std::shared_ptr &p_cfg, InstanceType p_type, const real_t &p_exp_time, const ProcessType &p_proc, const Transform3D &p_transform, const Color &p_col, const SphereBounds &p_bounds, const Color *p_custom_col) { ZoneScoped; - auto &proc = pools[p_cfg->dgcd.viewport][(int)p_proc]; + auto &proc = pools[p_cfg->dcd.viewport][(int)p_proc]; DelayedRendererInstance *inst = proc.instances[(int)p_type].get(p_exp_time > 0); - viewport_ids[p_cfg->dgcd.viewport] = p_cfg->dgcd.viewport->get_instance_id(); + viewport_ids[p_cfg->dcd.viewport] = p_cfg->dcd.viewport->get_instance_id(); SphereBounds thick_sphere = p_bounds; thick_sphere.radius += p_cfg->thickness * 0.5f; @@ -485,9 +485,9 @@ void GeometryPool::add_or_update_instance(const std::shared_ptr &p_cfg, const real_t &p_exp_time, const ProcessType &p_proc, std::unique_ptr p_lines, const size_t p_line_count, const Color &p_col) { ZoneScoped; - auto &proc = pools[p_cfg->dgcd.viewport][(int)p_proc]; + auto &proc = pools[p_cfg->dcd.viewport][(int)p_proc]; DelayedRendererLine *inst = proc.lines.get(p_exp_time > 0); - viewport_ids[p_cfg->dgcd.viewport] = p_cfg->dgcd.viewport->get_instance_id(); + viewport_ids[p_cfg->dcd.viewport] = p_cfg->dcd.viewport->get_instance_id(); inst->lines = std::move(p_lines); inst->lines_count = p_line_count;