From 85a1bbfcabc6e64bdc20b0e5c21344aa0eb6ac1f Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 21 Sep 2025 15:34:08 +0330 Subject: [PATCH] refactor: fix all clang-tidy diagnosis --- modules/CMakeLists.txt | 4 +- modules/ecs/private/registry.test.cpp | 6 +-- modules/ecs/public/registry.hpp | 2 + modules/ecs/public/sparse_set.hpp | 5 ++ modules/logger/public/logger.hpp | 16 +++--- modules/mirror/private/entrypoint/mirror.cpp | 2 +- modules/surface/private/linux/system.cpp | 57 ++++++++------------ modules/surface/private/system.fuzz.cpp | 26 ++++----- 8 files changed, 56 insertions(+), 62 deletions(-) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 7e4d5c5..25bdc19 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -5,8 +5,8 @@ add_subdirectory(./logger) add_subdirectory(./debug) add_subdirectory(./math) # -add_subdirectory(./asset_baker) -add_subdirectory(./asset_parser) +# add_subdirectory(./asset_baker) +# add_subdirectory(./asset_parser) # add_subdirectory(./asset_manager) # add_subdirectory(./camera) diff --git a/modules/ecs/private/registry.test.cpp b/modules/ecs/private/registry.test.cpp index 096ec68..e6d2a82 100644 --- a/modules/ecs/private/registry.test.cpp +++ b/modules/ecs/private/registry.test.cpp @@ -8,8 +8,6 @@ using lt::test::expect_unreachable; using lt::test::Suite; using lt::test::expect_eq; -using lt::test::expect_ne; -using lt::test::expect_throw; using lt::test::expect_false; using lt::test::expect_true; @@ -19,7 +17,7 @@ using lt::ecs::Registry; struct Component { - int m_int; + int m_int {}; std::string m_string; [[nodiscard]] friend auto operator==(const Component &lhs, const Component &rhs) -> bool @@ -43,7 +41,7 @@ struct std::formatter struct Component_B { - float m_float; + float m_float {}; [[nodiscard]] friend auto operator==(const Component_B lhs, const Component_B &rhs) -> bool { diff --git a/modules/ecs/public/registry.hpp b/modules/ecs/public/registry.hpp index 367e3bc..c6c10af 100644 --- a/modules/ecs/public/registry.hpp +++ b/modules/ecs/public/registry.hpp @@ -6,6 +6,8 @@ namespace lt::ecs { using Entity = uint32_t; +constexpr auto null_entity = std::numeric_limits::max(); + /** A registry of components, the heart of an ECS architecture. * * @todo(Light): Implement grouping diff --git a/modules/ecs/public/sparse_set.hpp b/modules/ecs/public/sparse_set.hpp index 6ac4cb0..833b89b 100644 --- a/modules/ecs/public/sparse_set.hpp +++ b/modules/ecs/public/sparse_set.hpp @@ -150,6 +150,11 @@ public: return m_sparse.capacity(); } + [[nodiscard]] auto is_empty() const noexcept -> bool + { + return m_dense.empty(); + } + private: std::vector m_dense; diff --git a/modules/logger/public/logger.hpp b/modules/logger/public/logger.hpp index 4dc5595..8625f19 100644 --- a/modules/logger/public/logger.hpp +++ b/modules/logger/public/logger.hpp @@ -35,13 +35,13 @@ public: void static show_imgui_window(); template - void static log(LogLvl lvl, std::format_string fmt, Args &&...args) + void static log(LogLvl lvl, std::format_string fmt, Args &&...args) noexcept { std::ignore = lvl; std::println(fmt, std::forward(args)...); } - void static log(LogLvl lvl, const char *message) + void static log(LogLvl lvl, const char *message) noexcept { std::ignore = lvl; std::println("{}", message); @@ -53,37 +53,37 @@ private: }; template -void log_trc(std::format_string fmt, Args &&...args) +void log_trc(std::format_string fmt, Args &&...args) noexcept { Logger::log(LogLvl::trace, fmt, std::forward(args)...); } template -void log_dbg(std::format_string fmt, Args &&...args) +void log_dbg(std::format_string fmt, Args &&...args) noexcept { Logger::log(LogLvl::debug, fmt, std::forward(args)...); } template -void log_inf(std::format_string fmt, Args &&...args) +void log_inf(std::format_string fmt, Args &&...args) noexcept { Logger::log(LogLvl::info, fmt, std::forward(args)...); } template -void log_wrn(std::format_string fmt, Args &&...args) +void log_wrn(std::format_string fmt, Args &&...args) noexcept { Logger::log(LogLvl::warn, fmt, std::forward(args)...); } template -void log_err(std::format_string fmt, Args &&...args) +void log_err(std::format_string fmt, Args &&...args) noexcept { Logger::log(LogLvl::error, fmt, std::forward(args)...); } template -void log_crt(std::format_string fmt, Args &&...args) +void log_crt(std::format_string fmt, Args &&...args) noexcept { Logger::log(LogLvl::critical, fmt, std::forward(args)...); } diff --git a/modules/mirror/private/entrypoint/mirror.cpp b/modules/mirror/private/entrypoint/mirror.cpp index 56cebce..d85a472 100644 --- a/modules/mirror/private/entrypoint/mirror.cpp +++ b/modules/mirror/private/entrypoint/mirror.cpp @@ -201,7 +201,7 @@ private: Ref m_mirror_system; - lt::ecs::Entity m_window; + lt::ecs::Entity m_window = lt::ecs::null_entity; }; auto app::create_application() -> Scope diff --git a/modules/surface/private/linux/system.cpp b/modules/surface/private/linux/system.cpp index b90a134..419c609 100644 --- a/modules/surface/private/linux/system.cpp +++ b/modules/surface/private/linux/system.cpp @@ -58,20 +58,28 @@ System::System(Ref registry): m_registry(std::move(registry)) System::~System() { - // TODO(Light): make registry.remove not validate iterators - auto entities_to_remove = std::vector {}; - for (auto &[entity, surface] : m_registry->view()) + try { - entities_to_remove.emplace_back(entity); - } + // TODO(Light): make registry.remove not validate iterators + auto entities_to_remove = std::vector {}; + for (auto &[entity, surface] : m_registry->view()) + { + entities_to_remove.emplace_back(entity); + } - for (auto entity : entities_to_remove) + for (auto entity : entities_to_remove) + { + m_registry->remove(entity); + } + + m_registry->disconnect_on_construct(); + m_registry->disconnect_on_destruct(); + } + catch (const std::exception &exp) { - m_registry->remove(entity); + log_err("Uncaught exception in surface::~System:"); + log_err("\twhat: {}", exp.what()); } - - m_registry->disconnect_on_construct(); - m_registry->disconnect_on_destruct(); } void System::on_register() @@ -141,8 +149,8 @@ void System::on_surface_construct(ecs::Registry ®istry, ecs::Entity entity) XSetWMProtocols(display, main_window, &surface.m_native_data.wm_delete_message, 1); // code to remove decoration - long hints[5] = { 2, 0, 0, 0, 0 }; - Atom motif_hints = XInternAtom(display, "_MOTIF_WM_HINTS", False); + auto hints = std::array { 2, 0, 0, 0, 0 }; + const auto motif_hints = XInternAtom(display, "_MOTIF_WM_HINTS", False); XChangeProperty( display, @@ -151,7 +159,7 @@ void System::on_surface_construct(ecs::Registry ®istry, ecs::Entity entity) motif_hints, 32, PropModeReplace, - (unsigned char *)&hints, + hints.data(), 5 ); @@ -283,28 +291,7 @@ void System::handle_events(SurfaceComponent &surface) break; } - case Expose: break; - case GraphicsExpose: break; - case NoExpose: break; - case CirculateRequest: break; - case ConfigureRequest: break; - case MapRequest: break; - case ResizeRequest: break; - case CirculateNotify: break; - case CreateNotify: break; - case DestroyNotify: break; - case GravityNotify: break; - case MapNotify: break; - case MappingNotify: break; - case ReparentNotify: break; - case UnmapNotify: break; - case VisibilityNotify: break; - case ColormapNotify: break; - case PropertyNotify: break; - case SelectionClear: break; - case SelectionNotify: break; - case SelectionRequest: break; - default: log_inf("Unknown X Event"); + default: break; /* pass */ } } } diff --git a/modules/surface/private/system.fuzz.cpp b/modules/surface/private/system.fuzz.cpp index d31fcbc..e277bc0 100644 --- a/modules/surface/private/system.fuzz.cpp +++ b/modules/surface/private/system.fuzz.cpp @@ -47,7 +47,9 @@ void create_surface_component(test::FuzzDataProvider &provider, ecs::Registry &r try { - registry.create_entity("").add_component( + auto entity = registry.create_entity(); + registry.add( + entity, surface::SurfaceComponent::CreateInfo { .title = std::move(title), .resolution = resolution, @@ -64,11 +66,11 @@ void create_surface_component(test::FuzzDataProvider &provider, ecs::Registry &r void remove_surface_component(ecs::Registry ®istry) { - const auto view = registry.get_entt_registry().view(); + const auto view = registry.view(); - if (!view->empty()) + if (!view.is_empty()) { - registry.get_entt_registry().remove(*view.begin()); + registry.remove(view[0].first); } } @@ -102,8 +104,7 @@ test::FuzzHarness harness = [](const uint8_t *data, size_t size) { case FuzzAction::create_entity: { const auto length = std::min(provider.consume().value_or(16), 255u); - const auto tag = provider.consume_string(length).value_or(""); - registry->create_entity(tag); + registry->create_entity(); break; } @@ -119,15 +120,15 @@ test::FuzzHarness harness = [](const uint8_t *data, size_t size) { } case FuzzAction::push_event: { - const auto view = registry->get_entt_registry().view(); + auto view = registry->view(); - if (!view->empty()) + if (!view.is_empty()) { - view.each([&](auto entity, SurfaceComponent &surface) { + for (auto &[entity, component] : view) + { provider.consume().value_or(0); - }); - - registry->get_entt_registry().remove(*view.begin()); + // @TODO(Light): push some event + } } break; @@ -136,6 +137,7 @@ test::FuzzHarness harness = [](const uint8_t *data, size_t size) { { break; } + case FuzzAction::count: case FuzzAction::tick_system: { system.tick();