From d506d6a6a7d0e1514725091fd7d10a3224f82901 Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 5 Oct 2025 10:07:36 +0330 Subject: [PATCH] refactor: split base module into std, bitwise, memory & env --- modules/CMakeLists.txt | 4 +- modules/app/CMakeLists.txt | 2 +- modules/app/private/application.cpp | 5 +- modules/app/public/application.hpp | 15 +- modules/app/public/entrypoint.hpp | 4 +- modules/assets/private/shader.cpp | 3 +- modules/base/CMakeLists.txt | 2 - modules/base/private/pch.hpp | 37 ----- modules/base/public/base.hpp | 91 ---------- modules/bitwise/CMakeLists.txt | 1 + modules/bitwise/public/operations.hpp | 13 ++ modules/ecs/CMakeLists.txt | 2 +- modules/ecs/public/entity.hpp | 10 +- modules/ecs/public/registry.hpp | 5 +- modules/env/CMakeLists.txt | 1 + modules/env/public/constants.hpp | 68 ++++++++ modules/input/private/system.cpp | 3 +- modules/input/private/system.test.cpp | 8 +- modules/input/public/system.hpp | 5 +- modules/math/public/vec3.hpp | 1 + modules/math/public/vec4.hpp | 1 + .../public/pointer_types/null_on_move.hpp | 16 ++ .../public/{pointer_types => }/reference.hpp | 7 +- .../{pointer_types/scoped.hpp => scope.hpp} | 7 +- modules/mirror/private/entrypoint/mirror.cpp | 53 ++++-- .../mirror/private/layers/editor_layer.cpp | 9 +- .../mirror/private/panels/asset_browser.cpp | 3 +- .../mirror/private/panels/scene_hierarchy.cpp | 11 +- modules/mirror/public/layers/editor_layer.hpp | 11 +- .../mirror/public/panels/asset_browser.hpp | 13 +- .../mirror/public/panels/scene_hierarchy.hpp | 15 +- modules/renderer/.clangd | 3 - modules/renderer/CMakeLists.txt | 1 + .../private/backend/vk/context/context.cpp | 9 +- .../private/backend/vk/context/context.hpp | 11 +- .../private/backend/vk/renderer/renderer.cpp | 3 +- .../private/backend/vk/renderer/renderer.hpp | 3 +- .../private/backend/vk/test_utils.hpp | 3 +- .../private/frontend/context/context.cpp | 6 +- .../private/frontend/context/context.hpp | 4 +- .../private/frontend/context/context.test.cpp | 10 +- .../private/frontend/context/device.test.cpp | 11 +- .../private/frontend/context/surface.test.cpp | 5 +- .../renderer/private/frontend/messenger.cpp | 5 +- .../renderer/private/frontend/messenger.hpp | 3 +- .../private/frontend/renderer/renderer.cpp | 5 +- .../private/frontend/renderer/renderer.hpp | 3 +- .../frontend/renderer/renderer.test.cpp | 7 +- modules/renderer/private/system.cpp | 4 +- modules/renderer/private/system.test.cpp | 24 +-- .../renderer/public/components/messenger.hpp | 15 +- modules/renderer/public/system.hpp | 12 +- modules/std/CMakeLists.txt | 2 + modules/std/public/pch.hpp | 155 ++++++++++++++++++ modules/surface/private/linux/system.cpp | 3 +- modules/surface/private/system.fuzz.cpp | 3 +- modules/surface/private/system.test.cpp | 10 +- modules/surface/private/windows/system.cpp | 6 +- modules/surface/public/system.hpp | 5 +- modules/test.sh | 38 +++++ modules/ui/private/ui.cpp | 14 +- modules/ui/public/ui.hpp | 10 +- 62 files changed, 544 insertions(+), 275 deletions(-) delete mode 100644 modules/base/CMakeLists.txt delete mode 100644 modules/base/private/pch.hpp delete mode 100644 modules/base/public/base.hpp create mode 100644 modules/bitwise/CMakeLists.txt create mode 100644 modules/bitwise/public/operations.hpp create mode 100644 modules/env/CMakeLists.txt create mode 100644 modules/env/public/constants.hpp rename modules/memory/public/{pointer_types => }/reference.hpp (75%) rename modules/memory/public/{pointer_types/scoped.hpp => scope.hpp} (76%) delete mode 100644 modules/renderer/.clangd create mode 100644 modules/std/CMakeLists.txt create mode 100644 modules/std/public/pch.hpp create mode 100755 modules/test.sh diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 9fa9d27..f176071 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,5 +1,7 @@ # engine -add_subdirectory(./base) +add_subdirectory(./std) +add_subdirectory(./bitwise) +add_subdirectory(./env) add_subdirectory(./memory) add_subdirectory(./time) add_subdirectory(./logger) diff --git a/modules/app/CMakeLists.txt b/modules/app/CMakeLists.txt index 0a16270..2f87a4b 100644 --- a/modules/app/CMakeLists.txt +++ b/modules/app/CMakeLists.txt @@ -1,2 +1,2 @@ add_library_module(app application.cpp) -target_link_libraries(app PRIVATE lt_debug) +target_link_libraries(app PUBLIC memory PRIVATE lt_debug) diff --git a/modules/app/private/application.cpp b/modules/app/private/application.cpp index 194bfcf..32d8fdb 100644 --- a/modules/app/private/application.cpp +++ b/modules/app/private/application.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace lt::app { @@ -41,12 +42,12 @@ void Application::game_loop() } } -void Application::register_system(Ref system) +void Application::register_system(memory::Ref system) { m_systems.emplace_back(std::move(system)); } -void Application::unregister_system(Ref system) +void Application::unregister_system(memory::Ref system) { m_systems_to_be_unregistered.emplace_back(std::move(system)); } diff --git a/modules/app/public/application.hpp b/modules/app/public/application.hpp index fa4ba7d..c67297b 100644 --- a/modules/app/public/application.hpp +++ b/modules/app/public/application.hpp @@ -1,10 +1,13 @@ #pragma once +#include +#include + namespace lt::app { class ISystem; -extern Scope create_application(); +extern memory::Scope create_application(); /** The main application class. * Think of this like an aggregate of systems, you register systems through this interface. @@ -25,19 +28,19 @@ public: void game_loop(); - void register_system(Ref system); + void register_system(memory::Ref system); - void unregister_system(Ref system); + void unregister_system(memory::Ref system); protected: Application() = default; private: - std::vector> m_systems; + std::vector> m_systems; - std::vector> m_systems_to_be_unregistered; + std::vector> m_systems_to_be_unregistered; - std::vector> m_systems_to_be_registered; + std::vector> m_systems_to_be_registered; }; diff --git a/modules/app/public/entrypoint.hpp b/modules/app/public/entrypoint.hpp index fc04cea..8708c92 100644 --- a/modules/app/public/entrypoint.hpp +++ b/modules/app/public/entrypoint.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include auto main(int argc, char *argv[]) -> int32_t try @@ -8,8 +9,7 @@ try std::ignore = argc; std::ignore = argv; - auto application = lt::Scope {}; - + auto application = lt::memory::Scope {}; application = lt::app::create_application(); if (!application) { diff --git a/modules/assets/private/shader.cpp b/modules/assets/private/shader.cpp index 2be2e09..53c3b1a 100644 --- a/modules/assets/private/shader.cpp +++ b/modules/assets/private/shader.cpp @@ -2,8 +2,7 @@ namespace lt::assets { -ShaderAsset::ShaderAsset(const std::filesystem::path &path) - : m_stream(path, std::ios::binary | std::ios::beg) +ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) { constexpr auto total_metadata_size = // sizeof(AssetMetadata) // diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt deleted file mode 100644 index 5d975bb..0000000 --- a/modules/base/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_library_module(base) -target_precompile_headers(base INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/private/pch.hpp) diff --git a/modules/base/private/pch.hpp b/modules/base/private/pch.hpp deleted file mode 100644 index d932553..0000000 --- a/modules/base/private/pch.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include - -/* windows */ -#ifdef _WIN32 - #define NOMINMAX - #include - #undef NOMINMAX -#endif - -/** Stdlib */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/modules/base/public/base.hpp b/modules/base/public/base.hpp deleted file mode 100644 index 57eaff1..0000000 --- a/modules/base/public/base.hpp +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once - -#include - -namespace lt { - -// Ref (Ref) -template -using Ref = std::shared_ptr; - -template -constexpr Ref create_ref(Args &&...args) -{ - return std::make_shared(std::forward(args)...); -} - -template -constexpr Ref make_ref(t *rawPointer) -{ - return std::shared_ptr(rawPointer); -} - -// Scope (std::unique_ptr) -template -using Scope = std::unique_ptr; - -template -constexpr std::unique_ptr create_scope(Args &&...args) -{ - return std::make_unique(std::forward(args)...); -} - -template -constexpr std::unique_ptr make_scope(t *rawPointer) -{ - return std::unique_ptr(rawPointer); -} - -} // namespace lt - -#define lt_win(x) // windows -#define lt_lin(x) // linux -#define lt_mac(x) // mac - -enum class Platform : uint8_t -{ - windows, - - /** Named like so because "linux" is a built-in identifier. */ - gnu, - - mac, -}; - -namespace constants { - -#if defined(LIGHT_PLATFORM_WINDOWS) - #define lt_win(x) -constexpr auto platform = Platform::windows; -constexpr auto platform_name = "windows"; - - #undef LIGHT_PLATFORM_WINDOWS - -#elif defined(LIGHT_PLATFORM_LINUX) - #define lt_lin(x) x -constexpr auto platform = Platform::gnu; -constexpr auto platform_name = "linux"; - -#elif defined(LIGHT_PLATFORM_MAC) - #define lt_mac(x) x -constexpr auto platform = Platform::mac; -constexpr auto platform_name = "mac"; - -#else - #error "Unsupported platform: Unknown" - -#endif - - -} // namespace constants - -/* bit-wise */ -constexpr auto bit(auto x) -{ - return 1 << x; -} - -/* token */ -#define lt_pair_token_value_to_name(token) { token, #token } -#define lt_pair_token_name_to_value(token) { #token, token } -#define lt_token_name(token) #token diff --git a/modules/bitwise/CMakeLists.txt b/modules/bitwise/CMakeLists.txt new file mode 100644 index 0000000..7e9981a --- /dev/null +++ b/modules/bitwise/CMakeLists.txt @@ -0,0 +1 @@ +add_library_module(bitwise) diff --git a/modules/bitwise/public/operations.hpp b/modules/bitwise/public/operations.hpp new file mode 100644 index 0000000..c2c4289 --- /dev/null +++ b/modules/bitwise/public/operations.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace lt::bitwise { + +/* bit-wise */ +constexpr auto bit(uint32_t x) -> uint32_t +{ + return 1u << x; +} + +} // namespace lt::bitwise diff --git a/modules/ecs/CMakeLists.txt b/modules/ecs/CMakeLists.txt index 5495f37..312dd4b 100644 --- a/modules/ecs/CMakeLists.txt +++ b/modules/ecs/CMakeLists.txt @@ -1,4 +1,4 @@ add_library_module(ecs sparse_set.cpp) -target_link_libraries(ecs PUBLIC logger lt_debug) +target_link_libraries(ecs PUBLIC logger lt_debug memory) add_test_module(ecs sparse_set.test.cpp registry.test.cpp) diff --git a/modules/ecs/public/entity.hpp b/modules/ecs/public/entity.hpp index 5968b8f..ba24a4c 100644 --- a/modules/ecs/public/entity.hpp +++ b/modules/ecs/public/entity.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace lt::ecs { @@ -8,7 +9,7 @@ namespace lt::ecs { class Entity { public: - Entity(Ref registry, EntityId identifier) + Entity(memory::Ref registry, EntityId identifier) : m_registry(std::move(registry)) , m_identifier(identifier) { @@ -18,7 +19,7 @@ public: template auto add(Component_T component) -> Component_T & { - return m_registry->add(m_identifier, component); + m_registry->add(m_identifier, component); } template @@ -33,13 +34,14 @@ public: return m_registry->get(m_identifier); } - auto get_registry() -> Ref + auto get_registry() -> memory::Ref { return m_registry; } private: - Ref m_registry; + memory::Ref m_registry; + EntityId m_identifier; }; diff --git a/modules/ecs/public/registry.hpp b/modules/ecs/public/registry.hpp index 75b3265..7d7ca4b 100644 --- a/modules/ecs/public/registry.hpp +++ b/modules/ecs/public/registry.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace lt::ecs { @@ -235,7 +236,7 @@ private: constexpr auto type_id = get_type_id(); if (!m_sparsed_sets.contains(type_id)) { - m_sparsed_sets[type_id] = create_scope>(); + m_sparsed_sets[type_id] = memory::create_scope>(); } auto *base_set = m_sparsed_sets[type_id].get(); @@ -249,7 +250,7 @@ private: TypeId m_entity_count; - std::flat_map> m_sparsed_sets; + std::flat_map> m_sparsed_sets; std::flat_map m_on_construct_hooks; diff --git a/modules/env/CMakeLists.txt b/modules/env/CMakeLists.txt new file mode 100644 index 0000000..a29a773 --- /dev/null +++ b/modules/env/CMakeLists.txt @@ -0,0 +1 @@ +add_library_module(env) diff --git a/modules/env/public/constants.hpp b/modules/env/public/constants.hpp new file mode 100644 index 0000000..22dc134 --- /dev/null +++ b/modules/env/public/constants.hpp @@ -0,0 +1,68 @@ +#pragma once + +namespace lt { + +enum class Platform : uint8_t +{ + /** The GNU/Linux platform. + * Tested on the following distros: arch-x86_64 + * @note: Named like so because `linux` is a built-in identifier. + * */ + gnu_linux, + + /** + * The Microsoft Windows(tm) platform. + * Tested on the following architectures: x86_64 + */ + windows, + + /** + * The apple's macOS platform. + * Currently not supported. + */ + mac, +}; + +/** The compiler that was used for compiling the project. */ +enum class Compiler : uint8_t +{ + clang, + gcc, + msvc, + apple_clang, +}; + +namespace constants { + +#if defined(LIGHT_PLATFORM_WINDOWS) + #define lt_win(x) +constexpr auto platform = Platform::windows; +constexpr auto platform_name = "windows"; + + #undef LIGHT_PLATFORM_WINDOWS + +#elif defined(LIGHT_PLATFORM_LINUX) +constexpr auto platform = Platform::gnu_linux; +constexpr auto platform_name = "gnu_linux"; + +#elif defined(LIGHT_PLATFORM_MAC) + #define lt_mac(x) x +constexpr auto platform = Platform::mac; +constexpr auto platform_name = "mac"; + +#else + #error "Unsupported platform: Unknown" + +#endif + +#ifdef __clang__ +constexpr auto compiler = Compiler::clang; +constexpr auto compiler_name = "clang"; + +/** @todo(Light): insert the full identifier, including version information and such */ +constexpr auto full_compiler_identifier = "clang"; +#endif + +} // namespace constants + +} // namespace lt diff --git a/modules/input/private/system.cpp b/modules/input/private/system.cpp index 829d366..22c4319 100644 --- a/modules/input/private/system.cpp +++ b/modules/input/private/system.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace lt::input { @@ -9,7 +10,7 @@ struct overloads: Ts... using Ts::operator()...; }; -System::System(Ref registry): m_registry(std::move(registry)) +System::System(memory::Ref registry): m_registry(std::move(registry)) { ensure(m_registry, "Failed to initialize input system: null registry"); } diff --git a/modules/input/private/system.test.cpp b/modules/input/private/system.test.cpp index 465d468..3e450fa 100644 --- a/modules/input/private/system.test.cpp +++ b/modules/input/private/system.test.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include @@ -30,7 +32,7 @@ using test::Suite; class Fixture { public: - [[nodiscard]] auto registry() -> Ref + [[nodiscard]] auto registry() -> memory::Ref { return m_registry; } @@ -55,7 +57,7 @@ public: } private: - Ref m_registry = create_ref(); + memory::Ref m_registry = memory::create_ref(); }; Suite raii = "raii"_suite = "raii"_suite = [] { @@ -110,7 +112,7 @@ Suite registry_events = "registry_events"_suite = [] { Case { "on_destrroy" } = [] { auto fixture = Fixture {}; auto registry = fixture.registry(); - auto system = create_scope(registry); + auto system = memory::create_scope(registry); auto entity_a = fixture.add_input_component(); auto entity_b = fixture.add_input_component(); diff --git a/modules/input/public/system.hpp b/modules/input/public/system.hpp index d0eecf6..61b77d7 100644 --- a/modules/input/public/system.hpp +++ b/modules/input/public/system.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -11,7 +12,7 @@ namespace lt::input { class System: public app::ISystem { public: - System(Ref registry); + System(memory::Ref registry); void tick(app::TickInfo tick) override; @@ -39,7 +40,7 @@ private: void on_button_release(const lt::surface::ButtonReleasedEvent &event); - Ref m_registry; + memory::Ref m_registry; std::array m_keys {}; diff --git a/modules/math/public/vec3.hpp b/modules/math/public/vec3.hpp index c01c901..8173899 100644 --- a/modules/math/public/vec3.hpp +++ b/modules/math/public/vec3.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include namespace lt::math { diff --git a/modules/math/public/vec4.hpp b/modules/math/public/vec4.hpp index 917cfb0..f4b27b6 100644 --- a/modules/math/public/vec4.hpp +++ b/modules/math/public/vec4.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace lt::math { diff --git a/modules/memory/public/pointer_types/null_on_move.hpp b/modules/memory/public/pointer_types/null_on_move.hpp index aeea689..5d6e227 100644 --- a/modules/memory/public/pointer_types/null_on_move.hpp +++ b/modules/memory/public/pointer_types/null_on_move.hpp @@ -41,6 +41,17 @@ public: return *this; } + auto operator->() -> Underlying_T + { + return m_value; + } + + // NOLINTNEXTLINE + auto operator->() const -> const Underlying_T + { + return m_value; + } + auto operator&() const -> const Underlying_T * { return &m_value; @@ -66,6 +77,11 @@ public: return m_value; } + operator uint64_t() const + { + return (uint64_t)m_value; + } + [[nodiscard]] auto get() -> Underlying_T { return m_value; diff --git a/modules/memory/public/pointer_types/reference.hpp b/modules/memory/public/reference.hpp similarity index 75% rename from modules/memory/public/pointer_types/reference.hpp rename to modules/memory/public/reference.hpp index 6c1665a..00f5e0b 100644 --- a/modules/memory/public/pointer_types/reference.hpp +++ b/modules/memory/public/reference.hpp @@ -1,10 +1,15 @@ #pragma once +#include #include namespace lt::memory { -/** Wrapper around std::shared_ptr. */ +/** Wrapper around std::shared_ptr. + * + * @note Currently just an alias, might turn into an implementation later. + * @ref https://en.cppreference.com/w/cpp/memory/shared_ptr.html + */ template using Ref = std::shared_ptr; diff --git a/modules/memory/public/pointer_types/scoped.hpp b/modules/memory/public/scope.hpp similarity index 76% rename from modules/memory/public/pointer_types/scoped.hpp rename to modules/memory/public/scope.hpp index 8a0eb5a..9ed8048 100644 --- a/modules/memory/public/pointer_types/scoped.hpp +++ b/modules/memory/public/scope.hpp @@ -1,10 +1,15 @@ #pragma once +#include #include namespace lt::memory { -/** Wrapper around std::unique_ptr. */ +/** Wrapper around std::unique_ptr. + * + * @note Currently just an alias, might turn into an implementation later. + * @ref https://en.cppreference.com/w/cpp/memory/unique_ptr.html + */ template using Scope = std::unique_ptr; diff --git a/modules/mirror/private/entrypoint/mirror.cpp b/modules/mirror/private/entrypoint/mirror.cpp index 8be091a..bafbd23 100644 --- a/modules/mirror/private/entrypoint/mirror.cpp +++ b/modules/mirror/private/entrypoint/mirror.cpp @@ -6,6 +6,9 @@ #include +#include +#include +#include +#include + +//============================================================ +// Algorithms and Iterators +//============================================================ +#include +#include +#include +#include + +//============================================================ +// Strings and Localization +//============================================================ +#include +#include +#include +#include +#include + +//============================================================ +// Memory Management and Smart Pointers +//============================================================ +#include +#include +#include +#include + +//============================================================ +// Utility and Miscellaneous +//============================================================ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//============================================================ +// Concurrency and Multithreading +//============================================================ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//============================================================ +// Random Numbers and Numeric Limits +//============================================================ +#include +#include +#include +#include +#include + +//============================================================ +// Regular Expressions +//============================================================ +#include + +//============================================================ +// Error Handling and Diagnostics +//============================================================ +#include +#include +#include +#include +#include +#include + +//============================================================ +// C++20/23 Additions +//============================================================ +#include // C++20 bit operations +#include // C++20 three-way comparison +#include // C++23 std::expected (if supported) +#include // C++20 formatting +#include // C++23 print functions +#include // C++20 ranges library +#include // C++20 span (repeated intentionally for clarity) +// #include // C++23 stack tracing utilities // Not supported yet +#include // C++20 synchronized output streams +// NOLINTEND diff --git a/modules/surface/private/linux/system.cpp b/modules/surface/private/linux/system.cpp index 98c48e3..870ae27 100644 --- a/modules/surface/private/linux/system.cpp +++ b/modules/surface/private/linux/system.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -44,7 +45,7 @@ constexpr auto all_events_mask = KeyPressMask | // ColormapChangeMask | // OwnerGrabButtonMask; -System::System(Ref registry): m_registry(std::move(registry)) +System::System(memory::Ref registry): m_registry(std::move(registry)) { ensure(m_registry, "Failed to initialize surface system: null registry"); diff --git a/modules/surface/private/system.fuzz.cpp b/modules/surface/private/system.fuzz.cpp index e277bc0..2f21912 100644 --- a/modules/surface/private/system.fuzz.cpp +++ b/modules/surface/private/system.fuzz.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -89,7 +90,7 @@ void check_invariants() test::FuzzHarness harness = [](const uint8_t *data, size_t size) { auto provider = test::FuzzDataProvider { data, size }; - auto registry = create_ref(); + auto registry = memory::create_ref(); auto system = surface::System { registry }; while (auto action = provider.consume()) diff --git a/modules/surface/private/system.test.cpp b/modules/surface/private/system.test.cpp index 35d1fae..47d95e7 100644 --- a/modules/surface/private/system.test.cpp +++ b/modules/surface/private/system.test.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include #include #include @@ -41,7 +43,7 @@ struct overloads: Ts... class Fixture { public: - [[nodiscard]] auto registry() -> Ref + [[nodiscard]] auto registry() -> memory::Ref { return m_registry; } @@ -74,7 +76,7 @@ public: } private: - Ref m_registry = create_ref(); + memory::Ref m_registry = memory::create_ref(); }; @@ -108,7 +110,7 @@ Suite raii = "raii"_suite = [] { Case { "post destruct has correct state" } = [] { auto fixture = Fixture {}; - auto system = create_scope(fixture.registry()); + auto system = memory::create_scope(fixture.registry()); fixture.add_surface_component(); expect_eq(fixture.registry()->view().get_size(), 1); @@ -184,7 +186,7 @@ Suite registry_events = "registry_events"_suite = [] { Case { "on_destrroy cleans up component" } = [] { auto fixture = Fixture {}; - auto system = create_scope(fixture.registry()); + auto system = memory::create_scope(fixture.registry()); const auto &component = fixture.add_surface_component(); expect_eq(fixture.registry()->view().get_size(), 1); diff --git a/modules/surface/private/windows/system.cpp b/modules/surface/private/windows/system.cpp index 053f8aa..3b48c72 100644 --- a/modules/surface/private/windows/system.cpp +++ b/modules/surface/private/windows/system.cpp @@ -1,9 +1,13 @@ +#include #include #include namespace lt::surface { -System::System(Ref registry, Ref event_mediator) +System::System( + memory::Ref registry, + memory::Ref event_mediator +) : m_registry(std::move(registry)) , m_event_mediator(std::move(event_mediator)) { diff --git a/modules/surface/public/system.hpp b/modules/surface/public/system.hpp index 0d8f08d..ad448c8 100644 --- a/modules/surface/public/system.hpp +++ b/modules/surface/public/system.hpp @@ -3,13 +3,14 @@ #include #include #include +#include namespace lt::surface { class System: public app::ISystem { public: - [[nodiscard]] System(Ref registry); + [[nodiscard]] System(memory::Ref registry); ~System() override; @@ -64,7 +65,7 @@ private: void set_visibility(ecs::EntityId surface_entity, bool visible); - Ref m_registry; + memory::Ref m_registry; app::TickResult m_last_tick_result; }; diff --git a/modules/test.sh b/modules/test.sh new file mode 100755 index 0000000..cad7ba6 --- /dev/null +++ b/modules/test.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +find . -type f \( -name "*.cpp" -o -name "*.hpp" \) -print0 | while IFS= read -r -d '' file; do + scope=false + ref=false + if grep -Eq "Scope\s*<" "$file"; then + scope=true + sed -i -E 's/(Scope)(\s*<)/memory::\1\2/g' "$file" + fi + if grep -Eq "Ref\s*<" "$file"; then + ref=true + sed -i -E 's/(Ref)(\s*<)/memory::\1\2/g' "$file" + fi + if grep -Eq "\bcreate_scope\b" "$file"; then + scope=true + sed -i -E 's/\b(create_scope)\b/memory::\1/g' "$file" + fi + if grep -Eq "\bcreate_ref\b" "$file"; then + ref=true + sed -i -E 's/\b(create_ref)\b/memory::\1/g' "$file" + fi + if $scope || $ref; then + includes="" + $scope && includes+="#include \n" + $ref && includes+="#include \n" + tmp=$(mktemp) + if [[ "$file" =~ \.hpp$ ]] && pragma_line=$(grep -En -m1 '^#pragma once' "$file" | cut -d: -f1); then + insert_line=$((pragma_line + 2)) + else + insert_line=1 + fi + head -n $((insert_line - 1)) "$file" > "$tmp" + echo -e "$includes" >> "$tmp" + tail -n +$insert_line "$file" >> "$tmp" + mv "$tmp" "$file" + clang-format -i "$file" + fi +done diff --git a/modules/ui/private/ui.cpp b/modules/ui/private/ui.cpp index 0c5acd8..1118302 100644 --- a/modules/ui/private/ui.cpp +++ b/modules/ui/private/ui.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include @@ -25,15 +27,17 @@ namespace lt { UserInterface *UserInterface::s_context = nullptr; -auto UserInterface::create(Ref sharedContext) -> Scope +auto UserInterface::create(memory::Ref sharedContext) + -> memory::Scope { - auto scopeUserInterface = Scope { nullptr }; + auto scopeUserInterface = memory::Scope { nullptr }; switch (GraphicsContext::get_graphics_api()) { - case GraphicsAPI::OpenGL: scopeUserInterface = create_scope(); break; + case GraphicsAPI::OpenGL: scopeUserInterface = memory::create_scope(); break; - case GraphicsAPI::DirectX: lt_win(scopeUserInterface = create_scope();) break; + case GraphicsAPI::DirectX: + lt_win(scopeUserInterface = memory::create_scope();) break; default: ensure( @@ -65,7 +69,7 @@ UserInterface::UserInterface() s_context = this; } -void UserInterface::init(Ref sharedContext) +void UserInterface::init(memory::Ref sharedContext) { // create context IMGUI_CHECKVERSION(); diff --git a/modules/ui/public/ui.hpp b/modules/ui/public/ui.hpp index 24ef075..1402a4e 100644 --- a/modules/ui/public/ui.hpp +++ b/modules/ui/public/ui.hpp @@ -1,5 +1,8 @@ #pragma once +#include +#include + namespace lt { class Event; @@ -8,7 +11,8 @@ class SharedContext; class UserInterface { public: - static auto create(Ref sharedContext) -> Scope; + static auto create(memory::Ref sharedContext) + -> memory::Scope; static void dockspace_begin(); @@ -20,9 +24,9 @@ public: virtual ~UserInterface() = default; - void init(Ref sharedContext); + void init(memory::Ref sharedContext); - virtual void platform_implementation(Ref sharedContext) = 0; + virtual void platform_implementation(memory::Ref sharedContext) = 0; virtual void begin() = 0;