refactor: split base module into std, bitwise, memory & env

This commit is contained in:
light7734 2025-10-05 10:07:36 +03:30
parent 16f3a80fd3
commit d506d6a6a7
Signed by: light7734
GPG key ID: 8C30176798F1A6BA
62 changed files with 544 additions and 275 deletions

View file

@ -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)

View file

@ -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)

View file

@ -1,5 +1,6 @@
#include <app/application.hpp>
#include <app/system.hpp>
#include <memory/reference.hpp>
namespace lt::app {
@ -41,12 +42,12 @@ void Application::game_loop()
}
}
void Application::register_system(Ref<app::ISystem> system)
void Application::register_system(memory::Ref<app::ISystem> system)
{
m_systems.emplace_back(std::move(system));
}
void Application::unregister_system(Ref<app::ISystem> system)
void Application::unregister_system(memory::Ref<app::ISystem> system)
{
m_systems_to_be_unregistered.emplace_back(std::move(system));
}

View file

@ -1,10 +1,13 @@
#pragma once
#include <memory/reference.hpp>
#include <memory/scope.hpp>
namespace lt::app {
class ISystem;
extern Scope<class Application> create_application();
extern memory::Scope<class Application> 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<app::ISystem> system);
void register_system(memory::Ref<app::ISystem> system);
void unregister_system(Ref<app::ISystem> system);
void unregister_system(memory::Ref<app::ISystem> system);
protected:
Application() = default;
private:
std::vector<Ref<app::ISystem>> m_systems;
std::vector<memory::Ref<app::ISystem>> m_systems;
std::vector<Ref<app::ISystem>> m_systems_to_be_unregistered;
std::vector<memory::Ref<app::ISystem>> m_systems_to_be_unregistered;
std::vector<Ref<app::ISystem>> m_systems_to_be_registered;
std::vector<memory::Ref<app::ISystem>> m_systems_to_be_registered;
};

View file

@ -1,6 +1,7 @@
#pragma once
#include <app/application.hpp>
#include <memory/scope.hpp>
auto main(int argc, char *argv[]) -> int32_t
try
@ -8,8 +9,7 @@ try
std::ignore = argc;
std::ignore = argv;
auto application = lt::Scope<lt::app::Application> {};
auto application = lt::memory::Scope<lt::app::Application> {};
application = lt::app::create_application();
if (!application)
{

View file

@ -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) //

View file

@ -1,2 +0,0 @@
add_library_module(base)
target_precompile_headers(base INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/private/pch.hpp)

View file

@ -1,37 +0,0 @@
#pragma once
#include <base/base.hpp>
/* windows */
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#undef NOMINMAX
#endif
/** Stdlib */
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <filesystem>
#include <flat_map>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <set>
#include <span>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

View file

@ -1,91 +0,0 @@
#pragma once
#include <memory>
namespace lt {
// Ref (Ref)
template<typename t>
using Ref = std::shared_ptr<t>;
template<typename t, typename... Args>
constexpr Ref<t> create_ref(Args &&...args)
{
return std::make_shared<t>(std::forward<Args>(args)...);
}
template<typename t>
constexpr Ref<t> make_ref(t *rawPointer)
{
return std::shared_ptr<t>(rawPointer);
}
// Scope (std::unique_ptr)
template<typename t>
using Scope = std::unique_ptr<t>;
template<typename t, typename... Args>
constexpr std::unique_ptr<t> create_scope(Args &&...args)
{
return std::make_unique<t>(std::forward<Args>(args)...);
}
template<typename t>
constexpr std::unique_ptr<t> make_scope(t *rawPointer)
{
return std::unique_ptr<t>(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

View file

@ -0,0 +1 @@
add_library_module(bitwise)

View file

@ -0,0 +1,13 @@
#pragma once
#include <cstdint>
namespace lt::bitwise {
/* bit-wise */
constexpr auto bit(uint32_t x) -> uint32_t
{
return 1u << x;
}
} // namespace lt::bitwise

View file

@ -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)

View file

@ -1,6 +1,7 @@
#pragma once
#include <ecs/registry.hpp>
#include <memory/reference.hpp>
namespace lt::ecs {
@ -8,7 +9,7 @@ namespace lt::ecs {
class Entity
{
public:
Entity(Ref<Registry> registry, EntityId identifier)
Entity(memory::Ref<Registry> registry, EntityId identifier)
: m_registry(std::move(registry))
, m_identifier(identifier)
{
@ -18,7 +19,7 @@ public:
template<typename Component_T>
auto add(Component_T component) -> Component_T &
{
return m_registry->add(m_identifier, component);
m_registry->add(m_identifier, component);
}
template<typename Component_T>
@ -33,13 +34,14 @@ public:
return m_registry->get<Component_T>(m_identifier);
}
auto get_registry() -> Ref<Registry>
auto get_registry() -> memory::Ref<Registry>
{
return m_registry;
}
private:
Ref<Registry> m_registry;
memory::Ref<Registry> m_registry;
EntityId m_identifier;
};

View file

@ -1,6 +1,7 @@
#pragma once
#include <ecs/sparse_set.hpp>
#include <memory/scope.hpp>
namespace lt::ecs {
@ -235,7 +236,7 @@ private:
constexpr auto type_id = get_type_id<T>();
if (!m_sparsed_sets.contains(type_id))
{
m_sparsed_sets[type_id] = create_scope<SparseSet<T, EntityId>>();
m_sparsed_sets[type_id] = memory::create_scope<SparseSet<T, EntityId>>();
}
auto *base_set = m_sparsed_sets[type_id].get();
@ -249,7 +250,7 @@ private:
TypeId m_entity_count;
std::flat_map<TypeId, Scope<UnderlyingSparseSet_T>> m_sparsed_sets;
std::flat_map<TypeId, memory::Scope<UnderlyingSparseSet_T>> m_sparsed_sets;
std::flat_map<TypeId, Callback_T> m_on_construct_hooks;

1
modules/env/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1 @@
add_library_module(env)

68
modules/env/public/constants.hpp vendored Normal file
View file

@ -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

View file

@ -1,5 +1,6 @@
#include <input/components.hpp>
#include <input/system.hpp>
#include <memory/reference.hpp>
namespace lt::input {
@ -9,7 +10,7 @@ struct overloads: Ts...
using Ts::operator()...;
};
System::System(Ref<ecs::Registry> registry): m_registry(std::move(registry))
System::System(memory::Ref<ecs::Registry> registry): m_registry(std::move(registry))
{
ensure(m_registry, "Failed to initialize input system: null registry");
}

View file

@ -1,6 +1,8 @@
#include <ecs/entity.hpp>
#include <input/components.hpp>
#include <input/system.hpp>
#include <memory/reference.hpp>
#include <memory/scope.hpp>
#include <ranges>
#include <test/test.hpp>
@ -30,7 +32,7 @@ using test::Suite;
class Fixture
{
public:
[[nodiscard]] auto registry() -> Ref<ecs::Registry>
[[nodiscard]] auto registry() -> memory::Ref<ecs::Registry>
{
return m_registry;
}
@ -55,7 +57,7 @@ public:
}
private:
Ref<ecs::Registry> m_registry = create_ref<ecs::Registry>();
memory::Ref<ecs::Registry> m_registry = memory::create_ref<ecs::Registry>();
};
Suite raii = "raii"_suite = "raii"_suite = [] {
@ -110,7 +112,7 @@ Suite registry_events = "registry_events"_suite = [] {
Case { "on_destrroy<InputComponent>" } = [] {
auto fixture = Fixture {};
auto registry = fixture.registry();
auto system = create_scope<System>(registry);
auto system = memory::create_scope<System>(registry);
auto entity_a = fixture.add_input_component();
auto entity_b = fixture.add_input_component();

View file

@ -2,6 +2,7 @@
#include <app/system.hpp>
#include <ecs/registry.hpp>
#include <memory/reference.hpp>
#include <surface/components.hpp>
#include <surface/events/keyboard.hpp>
#include <surface/events/mouse.hpp>
@ -11,7 +12,7 @@ namespace lt::input {
class System: public app::ISystem
{
public:
System(Ref<ecs::Registry> registry);
System(memory::Ref<ecs::Registry> registry);
void tick(app::TickInfo tick) override;
@ -39,7 +40,7 @@ private:
void on_button_release(const lt::surface::ButtonReleasedEvent &event);
Ref<ecs::Registry> m_registry;
memory::Ref<ecs::Registry> m_registry;
std::array<bool, 512> m_keys {};

View file

@ -1,5 +1,6 @@
#pragma once
#include <cstdint>
#include <math/vec2.hpp>
namespace lt::math {

View file

@ -1,6 +1,7 @@
#pragma once
#include <array>
#include <cstdint>
namespace lt::math {

View file

@ -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;

View file

@ -1,10 +1,15 @@
#pragma once
#include <memory/reference.hpp>
#include <memory>
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<typename t>
using Ref = std::shared_ptr<t>;

View file

@ -1,10 +1,15 @@
#pragma once
#include <memory/scope.hpp>
#include <memory>
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<typename t>
using Scope = std::unique_ptr<t>;

View file

@ -6,6 +6,9 @@
#include <input/components.hpp>
#include <input/system.hpp>
#include <math/vec2.hpp>
#include <memory/reference.hpp>
#include <memory/scope.hpp>
#include <renderer/components/messenger.hpp>
#include <renderer/system.hpp>
#include <surface/events/keyboard.hpp>
#include <surface/events/surface.hpp>
@ -14,11 +17,21 @@
namespace lt {
void renderer_callback(
renderer::MessageSeverity message_severity,
renderer::MessageType message_type,
renderer::MessengerCallbackData data,
std::any user_data
)
{
log_dbg("RENDERER CALLBACK: {}", data.message);
}
class MirrorSystem: public lt::app::ISystem
{
public:
MirrorSystem(
Ref<ecs::Registry> registry,
memory::Ref<ecs::Registry> registry,
lt::input::InputAction::Key quit_action_key,
std::array<lt::input::InputAction::Key, 4> debug_action_keys
)
@ -27,6 +40,8 @@ public:
, m_debug_action_keys(debug_action_keys)
{
using Surface = lt::surface::SurfaceComponent;
using Input = lt::input::InputComponent;
for (auto &[entity, surface, input] : m_registry->view<Surface, Input>())
@ -99,7 +114,8 @@ public:
}
private:
Ref<ecs::Registry> m_registry;
memory::Ref<ecs::Registry> m_registry;
lt::input::InputAction::Key m_quit_action_key;
@ -113,7 +129,7 @@ class Mirror: public app::Application
public:
Mirror()
{
m_editor_registry = create_ref<ecs::Registry>();
m_editor_registry = memory::create_ref<ecs::Registry>();
setup_window_system();
setup_input_system();
@ -135,7 +151,7 @@ public:
{
using lt::input::InputComponent;
using lt::surface::SurfaceComponent;
m_surface_system = create_ref<lt::surface::System>(m_editor_registry);
m_surface_system = memory::create_ref<lt::surface::System>(m_editor_registry);
m_window = m_editor_registry->create_entity();
m_editor_registry->add<SurfaceComponent>(
@ -185,21 +201,28 @@ public:
}
);
m_input_system = create_ref<input::System>(m_editor_registry);
m_mirror_system = create_ref<MirrorSystem>(
m_input_system = memory::create_ref<input::System>(m_editor_registry);
m_mirror_system = memory::create_ref<MirrorSystem>(
m_editor_registry,
quit_action_key,
debug_action_keys
);
auto entity = ecs::Entity { m_editor_registry, m_window };
Ref<app::SystemStats> system_stats = nullptr;
memory::Ref<app::SystemStats> system_stats = nullptr;
m_renderer_system = std::make_shared<renderer::System>(renderer::System::CreateInfo {
.config = { .target_api = renderer::API::Vulkan, .max_frames_in_flight = 3u },
.registry = m_editor_registry,
.surface_entity = entity,
.system_stats = system_stats,
});
// entity.add<renderer::MessengerComponent>({
// .severities = renderer::MessageSeverity::all,
// .types = renderer::MessageType::all,
// .callback = &renderer_callback,
// .user_data = this,
// });
}
void setup_input_system()
@ -215,22 +238,22 @@ public:
}
private:
Ref<ecs::Registry> m_editor_registry;
memory::Ref<ecs::Registry> m_editor_registry;
Ref<lt::surface::System> m_surface_system;
memory::Ref<lt::surface::System> m_surface_system;
Ref<lt::input::System> m_input_system;
memory::Ref<lt::input::System> m_input_system;
Ref<lt::renderer::System> m_renderer_system;
memory::Ref<lt::renderer::System> m_renderer_system;
Ref<MirrorSystem> m_mirror_system;
memory::Ref<MirrorSystem> m_mirror_system;
lt::ecs::EntityId m_window = lt::ecs::null_entity;
};
auto app::create_application() -> Scope<app::Application>
auto app::create_application() -> memory::Scope<app::Application>
{
return create_scope<Mirror>();
return memory::create_scope<Mirror>();
}
} // namespace lt

View file

@ -7,6 +7,7 @@
#include <input/input.hpp>
#include <input/key_codes.hpp>
#include <math/vec4.hpp>
#include <memory/reference.hpp>
#include <mirror/layers/editor_layer.hpp>
#include <renderer/framebuffer.hpp>
#include <renderer/graphics_context.hpp>
@ -20,11 +21,11 @@ EditorLayer::EditorLayer(const std::string &name)
, m_scene_dir("")
, m_direction { 0.0, 0.0 }
{
m_scene = create_ref<Scene>();
m_scene = memory::create_ref<Scene>();
m_properties_panel = create_ref<PropertiesPanel>();
m_sceneHierarchyPanel = create_ref<SceneHierarchyPanel>(m_scene, m_properties_panel);
m_content_browser_panel = create_ref<AssetBrowserPanel>(m_scene);
m_properties_panel = memory::create_ref<PropertiesPanel>();
m_sceneHierarchyPanel = memory::create_ref<SceneHierarchyPanel>(m_scene, m_properties_panel);
m_content_browser_panel = memory::create_ref<AssetBrowserPanel>(m_scene);
m_framebuffer = Framebuffer::create(
{

View file

@ -2,12 +2,13 @@
#include <ecs/registry.hpp>
#include <ecs/serializer.hpp>
#include <imgui.h>
#include <memory/reference.hpp>
#include <mirror/panels/asset_browser.hpp>
#include <renderer/texture.hpp>
namespace lt {
AssetBrowserPanel::AssetBrowserPanel(Ref<Scene> active_scene)
AssetBrowserPanel::AssetBrowserPanel(memory::Ref<Scene> active_scene)
: m_current_directory("./data/assets")
, m_assets_path("./data/assets")
, m_active_scene(std::move(active_scene))

View file

@ -1,5 +1,6 @@
#include <ecs/components.hpp>
#include <imgui.h>
#include <memory/reference.hpp>
#include <mirror/panels/properties.hpp>
#include <mirror/panels/scene_hierarchy.hpp>
@ -9,7 +10,10 @@ SceneHierarchyPanel::SceneHierarchyPanel(): m_context(nullptr), m_properties_pan
{
}
SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> properties_panel)
SceneHierarchyPanel::SceneHierarchyPanel(
memory::Ref<Scene> context,
memory::Ref<PropertiesPanel> properties_panel
)
: m_context(std::move(context))
, m_properties_panel_context(std::move(properties_panel))
{
@ -36,7 +40,10 @@ void SceneHierarchyPanel::on_user_interface_update()
ImGui::End();
}
void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> properties_panel)
void SceneHierarchyPanel::set_context(
memory::Ref<Scene> context,
memory::Ref<PropertiesPanel> properties_panel
)
{
if (properties_panel)
{

View file

@ -3,6 +3,7 @@
#include <app/layer.hpp>
#include <imgui.h>
#include <math/vec2.hpp>
#include <memory/reference.hpp>
#include <mirror/panels/asset_browser.hpp>
#include <mirror/panels/properties.hpp>
#include <mirror/panels/scene_hierarchy.hpp>
@ -40,15 +41,15 @@ private:
float m_speed = 1000.0f;
Ref<Scene> m_scene;
memory::Ref<Scene> m_scene;
Ref<SceneHierarchyPanel> m_sceneHierarchyPanel;
memory::Ref<SceneHierarchyPanel> m_sceneHierarchyPanel;
Ref<PropertiesPanel> m_properties_panel;
memory::Ref<PropertiesPanel> m_properties_panel;
Ref<AssetBrowserPanel> m_content_browser_panel;
memory::Ref<AssetBrowserPanel> m_content_browser_panel;
Ref<Framebuffer> m_framebuffer;
memory::Ref<Framebuffer> m_framebuffer;
Entity m_camera_entity;

View file

@ -1,6 +1,7 @@
#pragma once
#include <filesystem>
#include <memory/reference.hpp>
#include <mirror/panels/panel.hpp>
#include <renderer/texture.hpp>
@ -11,7 +12,7 @@ class Scene;
class AssetBrowserPanel: public Panel
{
public:
AssetBrowserPanel(Ref<Scene> active_scene);
AssetBrowserPanel(memory::Ref<Scene> active_scene);
void on_user_interface_update();
@ -33,15 +34,15 @@ private:
float m_file_padding = 8.0f;
Ref<Scene> m_active_scene;
memory::Ref<Scene> m_active_scene;
Ref<Texture> m_directory_texture;
memory::Ref<Texture> m_directory_texture;
Ref<Texture> m_scene_texture;
memory::Ref<Texture> m_scene_texture;
Ref<Texture> m_image_texture;
memory::Ref<Texture> m_image_texture;
Ref<Texture> m_text_texture;
memory::Ref<Texture> m_text_texture;
};
} // namespace lt

View file

@ -2,6 +2,7 @@
#include <ecs/entity.hpp>
#include <ecs/registry.hpp>
#include <memory/reference.hpp>
#include <mirror/panels/panel.hpp>
namespace lt {
@ -13,18 +14,24 @@ class SceneHierarchyPanel: public Panel
public:
SceneHierarchyPanel();
SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> properties_panel = nullptr);
SceneHierarchyPanel(
memory::Ref<Scene> context,
memory::Ref<PropertiesPanel> properties_panel = nullptr
);
void on_user_interface_update();
void set_context(Ref<Scene> context, Ref<PropertiesPanel> properties_panel = nullptr);
void set_context(
memory::Ref<Scene> context,
memory::Ref<PropertiesPanel> properties_panel = nullptr
);
private:
void draw_node(Entity entity, const std::string &label);
Ref<Scene> m_context;
memory::Ref<Scene> m_context;
Ref<PropertiesPanel> m_properties_panel_context;
memory::Ref<PropertiesPanel> m_properties_panel_context;
Entity m_selection_context;
};

View file

@ -1,3 +0,0 @@
Diagnostics:
UnusedIncludes: None
MissingIncludes: None

View file

@ -25,6 +25,7 @@ PUBLIC
memory
assets
time
bitwise
PRIVATE
surface
pthread

View file

@ -1,3 +1,4 @@
#include <memory/scope.hpp>
#include <renderer/backend/vk/context/context.hpp>
#include <renderer/backend/vk/context/device.hpp>
#include <renderer/backend/vk/context/gpu.hpp>
@ -9,10 +10,10 @@ namespace lt::renderer::vk {
Context::Context(const ecs::Entity &surface_entity)
: m_instance(Instance::get())
, m_surface(create_scope<Surface>(m_instance, surface_entity))
, m_gpu(create_scope<Gpu>(m_instance))
, m_device(create_scope<Device>(m_gpu.get(), m_surface.get()))
, m_swapchain(create_scope<Swapchain>(m_surface.get(), m_gpu.get(), m_device.get()))
, m_surface(memory::create_scope<Surface>(m_instance, surface_entity))
, m_gpu(memory::create_scope<Gpu>(m_instance))
, m_device(memory::create_scope<Device>(m_gpu.get(), m_surface.get()))
, m_swapchain(memory::create_scope<Swapchain>(m_surface.get(), m_gpu.get(), m_device.get()))
{
ensure(
static_cast<Instance *>(m_instance)->vk(),

View file

@ -2,6 +2,7 @@
#include <ecs/entity.hpp>
#include <memory/pointer_types/null_on_move.hpp>
#include <memory/scope.hpp>
#include <renderer/frontend/context/context.hpp>
namespace lt::renderer::vk {
@ -42,19 +43,19 @@ public:
void recreate_swapchain() override
{
m_swapchain.reset();
// m_swapchain = create_scope<vk::Swapchain>(m_device, m_surface);
// m_swapchain = memory::create_scope<vk::Swapchain>(m_device, m_surface);
}
private:
IInstance *m_instance;
Scope<ISurface> m_surface;
memory::Scope<ISurface> m_surface;
Scope<IGpu> m_gpu;
memory::Scope<IGpu> m_gpu;
Scope<IDevice> m_device;
memory::Scope<IDevice> m_device;
Scope<ISwapchain> m_swapchain;
memory::Scope<ISwapchain> m_swapchain;
};
} // namespace lt::renderer::vk

View file

@ -1,3 +1,4 @@
#include <memory/reference.hpp>
#include <renderer/backend/vk/context/swapchain.hpp>
#include <renderer/backend/vk/renderer/renderer.hpp>
@ -13,7 +14,7 @@ Renderer::Renderer(IContext &context, uint32_t max_frames_in_flight)
ensure(m_swapchain, "Failed to initialize renderer: null swapchain");
// TODO(Light): HARDCODED PASS!!!
m_pass = create_ref<vk::Pass>(
m_pass = memory::create_ref<vk::Pass>(
context,
assets::ShaderAsset { "./data/test_assets/triangle.vert.asset" },
assets::ShaderAsset { "./data/test_assets/triangle.frag.asset" }

View file

@ -1,5 +1,6 @@
#pragma once
#include <memory/reference.hpp>
#include <ranges>
#include <renderer/backend/vk/context/context.hpp>
#include <renderer/backend/vk/context/device.hpp>
@ -37,7 +38,7 @@ private:
class Swapchain *m_swapchain {};
Ref<class Pass> m_pass;
memory::Ref<class Pass> m_pass;
VkCommandPool m_pool = VK_NULL_HANDLE;

View file

@ -1,5 +1,6 @@
#pragma once
#include <memory/reference.hpp>
#include <ranges>
#include <renderer/backend/vk/context/context.hpp>
#include <renderer/backend/vk/context/surface.hpp>
@ -83,7 +84,7 @@ private:
{
using lt::surface::SurfaceComponent;
auto registry = lt::create_ref<lt::ecs::Registry>();
auto registry = lt::memory::create_ref<lt::ecs::Registry>();
auto entity = lt::ecs::Entity { registry, registry->create_entity() };
auto surface_system = lt::surface::System(registry);
entity.add<SurfaceComponent>(SurfaceComponent::CreateInfo {

View file

@ -1,14 +1,16 @@
#include <memory/scope.hpp>
#include <renderer/api.hpp>
#include <renderer/backend/vk/context/context.hpp>
#include <renderer/frontend/context/context.hpp>
namespace lt::renderer {
auto IContext::create(API target_api, const ecs::Entity &surface_entity) -> Scope<IContext>
auto IContext::create(API target_api, const ecs::Entity &surface_entity)
-> memory::Scope<IContext>
{
switch (target_api)
{
case API::Vulkan: return create_scope<vk::Context>(surface_entity);
case API::Vulkan: return memory::create_scope<vk::Context>(surface_entity);
default: throw std::runtime_error { "Invalid API" };
}
}

View file

@ -1,6 +1,7 @@
#pragma once
#include <ecs/entity.hpp>
#include <memory/scope.hpp>
#include <renderer/api.hpp>
#include <renderer/frontend/context/device.hpp>
#include <renderer/frontend/context/gpu.hpp>
@ -14,7 +15,8 @@ namespace lt::renderer {
class IContext
{
public:
static auto create(API target_api, const ecs::Entity &surface_entity) -> Scope<IContext>;
static auto create(API target_api, const ecs::Entity &surface_entity)
-> memory::Scope<IContext>;
IContext() = default;
virtual ~IContext() = default;

View file

@ -1,3 +1,5 @@
#include <memory/reference.hpp>
#include <memory/scope.hpp>
#include <ranges>
#include <renderer/interface/context.hpp>
#include <renderer/vk/context/context.hpp>
@ -29,8 +31,8 @@ class Fixture
{
public:
Fixture()
: m_registry(lt::create_ref<lt::ecs::Registry>())
, m_surface_system(lt::create_scope<lt::surface::System>(m_registry))
: m_registry(lt::memory::create_ref<lt::ecs::Registry>())
, m_surface_system(lt::memory::create_scope<lt::surface::System>(m_registry))
, m_surface_entity(m_registry, m_registry->create_entity())
{
}
@ -41,8 +43,8 @@ public:
}
private:
lt::Ref<lt::ecs::Registry> m_registry;
lt::Scope<lt::surface::System> m_surface_system;
lt::memory::Ref<lt::ecs::Registry> m_registry;
lt::memory::Scope<lt::surface::System> m_surface_system;
lt::ecs::Entity m_surface_entity;
};

View file

@ -1,3 +1,4 @@
#include <memory/reference.hpp>
#include <ranges>
#include <renderer/vk/context/device.hpp>
#include <renderer/vk/context/surface.hpp>
@ -17,7 +18,7 @@ constexpr auto resolution = math::uvec2 { 800u, 600u };
Suite raii = "device_raii"_suite = [] {
Case { "happy path won't throw" } = [] {
auto registry = create_ref<ecs::Registry>();
auto registry = memory::create_ref<ecs::Registry>();
auto surface_system = surface::System { registry };
auto entity = ecs::Entity { registry, registry->create_entity() };
entity.add<surface::SurfaceComponent>(surface::SurfaceComponent::CreateInfo {
@ -30,7 +31,7 @@ Suite raii = "device_raii"_suite = [] {
};
Case { "many won't freeze/throw" } = [] {
auto registry = create_ref<ecs::Registry>();
auto registry = memory::create_ref<ecs::Registry>();
auto surface_system = surface::System { registry };
auto entity = ecs::Entity { registry, registry->create_entity() };
entity.add<surface::SurfaceComponent>(surface::SurfaceComponent::CreateInfo {
@ -47,7 +48,7 @@ Suite raii = "device_raii"_suite = [] {
};
Case { "unhappy path throws" } = [] {
auto registry = create_ref<ecs::Registry>();
auto registry = memory::create_ref<ecs::Registry>();
auto surface_system = surface::System { registry };
auto entity = ecs::Entity { registry, registry->create_entity() };
entity.add<surface::SurfaceComponent>(surface::SurfaceComponent::CreateInfo {
@ -62,7 +63,7 @@ Suite raii = "device_raii"_suite = [] {
};
Case { "post construct has correct state" } = [] {
auto registry = create_ref<ecs::Registry>();
auto registry = memory::create_ref<ecs::Registry>();
auto surface_system = surface::System { registry };
auto entity = ecs::Entity { registry, registry->create_entity() };
entity.add<surface::SurfaceComponent>(surface::SurfaceComponent::CreateInfo {
@ -82,7 +83,7 @@ Suite raii = "device_raii"_suite = [] {
};
Case { "post destruct has correct state" } = [] {
auto registry = create_ref<ecs::Registry>();
auto registry = memory::create_ref<ecs::Registry>();
auto surface_system = surface::System { registry };
auto entity = ecs::Entity { registry, registry->create_entity() };
entity.add<surface::SurfaceComponent>(surface::SurfaceComponent::CreateInfo {

View file

@ -1,3 +1,4 @@
#include <memory/reference.hpp>
#include <renderer/vk/context/surface.hpp>
#include <renderer/vk/debug/messenger.hpp>
#include <renderer/vk/test_utils.hpp>
@ -15,7 +16,7 @@ Suite raii = "surface"_suite = [] {
Case { "happy path won't throw" } = [&] {
auto observer = ValidationObserver {};
auto registry = lt::create_ref<Registry>();
auto registry = lt::memory::create_ref<Registry>();
auto entity = Entity { registry, registry->create_entity() };
auto surface_system = System(registry);
@ -36,7 +37,7 @@ Suite raii = "surface"_suite = [] {
Case { "unhappy path throws" } = [&] {
auto observer = ValidationObserver {};
auto registry = lt::create_ref<Registry>();
auto registry = lt::memory::create_ref<Registry>();
auto entity = Entity { registry, registry->create_entity() };
entity.add<SurfaceComponent>(SurfaceComponent::CreateInfo {

View file

@ -1,3 +1,4 @@
#include <memory/scope.hpp>
#include <renderer/backend/vk/messenger.hpp>
#include <renderer/frontend/messenger.hpp>
@ -7,11 +8,11 @@ namespace lt::renderer {
API target_api,
IInstance *instance,
ecs::Entity entity
) -> Scope<IMessenger>
) -> memory::Scope<IMessenger>
{
switch (target_api)
{
case API::Vulkan: return create_scope<vk::Messenger>(instance, std::move(entity));
case API::Vulkan: return memory::create_scope<vk::Messenger>(instance, std::move(entity));
case API::Metal:
case API::DirectX: throw std::runtime_error { "Invalid API" };

View file

@ -1,6 +1,7 @@
#pragma once
#include <ecs/entity.hpp>
#include <memory/scope.hpp>
#include <renderer/api.hpp>
namespace lt::renderer {
@ -9,7 +10,7 @@ class IMessenger
{
public:
[[nodiscard]] static auto create(API target_api, class IInstance *instance, ecs::Entity entity)
-> Scope<IMessenger>;
-> memory::Scope<IMessenger>;
IMessenger() = default;

View file

@ -1,3 +1,4 @@
#include <memory/scope.hpp>
#include <renderer/api.hpp>
#include <renderer/backend/vk/renderer/renderer.hpp>
#include <renderer/frontend/renderer/renderer.hpp>
@ -5,11 +6,11 @@
namespace lt::renderer {
auto IRenderer::create(API target_api, IContext &context, uint32_t max_frames_in_flight)
-> Scope<IRenderer>
-> memory::Scope<IRenderer>
{
switch (target_api)
{
case API::Vulkan: return create_scope<vk::Renderer>(context, max_frames_in_flight);
case API::Vulkan: return memory::create_scope<vk::Renderer>(context, max_frames_in_flight);
default: throw std::runtime_error { "Invalid API" };
}
}

View file

@ -1,5 +1,6 @@
#pragma once
#include <memory/scope.hpp>
#include <renderer/api.hpp>
namespace lt::renderer {
@ -15,7 +16,7 @@ public:
};
static auto create(API target_api, class IContext &context, uint32_t max_frames_in_flight)
-> Scope<IRenderer>;
-> memory::Scope<IRenderer>;
IRenderer() = default;

View file

@ -1,3 +1,4 @@
#include <memory/reference.hpp>
#include <renderer/vk/renderer/renderer.hpp>
#include <renderer/vk/test_utils.hpp>
@ -12,7 +13,7 @@ Suite raii = "renderer_raii"_suite = [] {
std::ignore = Renderer(
context,
lt::create_ref<Pass>(
lt::memory::create_ref<Pass>(
context,
ShaderAsset { "./data/test_assets/triangle.vert.asset" },
ShaderAsset { "./data/test_assets/triangle.frag.asset" }
@ -30,7 +31,7 @@ Suite draw = "renderer_draw"_suite = [] {
auto renderer = Renderer(
context,
lt::create_ref<Pass>(
lt::memory::create_ref<Pass>(
context,
ShaderAsset { "./data/test_assets/triangle.vert.asset" },
ShaderAsset { "./data/test_assets/triangle.frag.asset" }
@ -47,7 +48,7 @@ Suite draw = "renderer_draw"_suite = [] {
Case { "post swapchain replacement renderer draw" } = [] {
auto observer = ValidationObserver {};
auto [context, _] = create_context();
auto pass = lt::create_ref<Pass>(
auto pass = lt::memory::create_ref<Pass>(
context,
ShaderAsset { "./data/test_assets/triangle.vert.asset" },
ShaderAsset { "./data/test_assets/triangle.frag.asset" }

View file

@ -21,8 +21,8 @@ System::System(CreateInfo info)
m_renderer = IRenderer::create(m_api, *m_context, info.config.max_frames_in_flight);
// WIP(Light): attach debug messenger on messenger component construction
m_registry->connect_on_construct<renderer::MessengerComponent>([](ecs::Registry &registry,
ecs::EntityId entity) {});
// m_registry->connect_on_construct<renderer::MessengerComponent>([](ecs::Registry &registry,
// ecs::EntityId entity) {});
}
System::~System()

View file

@ -1,3 +1,5 @@
#include <memory/reference.hpp>
#include <memory/scope.hpp>
#include <ranges>
#include <renderer/system.hpp>
#include <renderer/vk/context/context.hpp>
@ -25,7 +27,7 @@ struct SurfaceContext
struct RendererContext
{
Ref<ecs::Registry> registry;
memory::Ref<ecs::Registry> registry;
System system;
};
@ -33,7 +35,7 @@ struct RendererContext
{
using surface::SurfaceComponent;
auto surface_registry = create_ref<ecs::Registry>();
auto surface_registry = memory::create_ref<ecs::Registry>();
auto surface_entity = surface_registry->create_entity();
auto surface_system = surface::System(surface_registry);
surface_registry->add<SurfaceComponent>(
@ -54,8 +56,8 @@ struct RendererContext
{
auto surface_context = create_surface();
auto &[surface_system, surface_entity] = surface_context;
auto registry = create_ref<ecs::Registry>();
auto stats = create_ref<app::SystemStats>();
auto registry = memory::create_ref<ecs::Registry>();
auto stats = memory::create_ref<app::SystemStats>();
return {
std::move(surface_context),
@ -83,7 +85,7 @@ public:
});
}
[[nodiscard]] auto registry() const -> Ref<ecs::Registry>
[[nodiscard]] auto registry() const -> memory::Ref<ecs::Registry>
{
return m_registry;
}
@ -93,19 +95,21 @@ public:
return *m_surface_entity;
}
[[nodiscard]] auto stats() const -> Ref<app::SystemStats>
[[nodiscard]] auto stats() const -> memory::Ref<app::SystemStats>
{
return m_stats;
}
private:
Ref<app::SystemStats> m_stats = create_ref<app::SystemStats>();
memory::Ref<app::SystemStats> m_stats = memory::create_ref<app::SystemStats>();
Ref<ecs::Registry> m_registry = create_ref<ecs::Registry>();
memory::Ref<ecs::Registry> m_registry = memory::create_ref<ecs::Registry>();
Ref<surface::System> m_surface_system = create_ref<surface::System>(m_registry);
memory::Ref<surface::System> m_surface_system = memory::create_ref<surface::System>(
m_registry
);
Scope<ecs::Entity> m_surface_entity = create_scope<ecs::Entity>(
memory::Scope<ecs::Entity> m_surface_entity = memory::create_scope<ecs::Entity>(
m_registry,
m_registry->create_entity()
);

View file

@ -1,5 +1,6 @@
#pragma once
#include <bitwise/operations.hpp>
#include <any>
namespace lt::renderer {
@ -8,10 +9,10 @@ enum class MessageSeverity : uint8_t
{
none = 0u,
verbose = bit(0u),
info = bit(1u),
warning = bit(2u),
error = bit(3u),
verbose = bitwise::bit(0u),
info = bitwise::bit(1u),
warning = bitwise::bit(2u),
error = bitwise::bit(3u),
all = verbose | info | warning | error,
};
@ -19,9 +20,9 @@ enum class MessageSeverity : uint8_t
enum class MessageType : uint8_t
{
none = 0u,
general = bit(0u),
validation = bit(1u),
performance = bit(2u),
general = bitwise::bit(0u),
validation = bitwise::bit(1u),
performance = bitwise::bit(2u),
all = general | validation | performance,
};

View file

@ -3,6 +3,8 @@
#include <app/system.hpp>
#include <ecs/entity.hpp>
#include <ecs/registry.hpp>
#include <memory/reference.hpp>
#include <memory/scope.hpp>
#include <renderer/api.hpp>
namespace lt::renderer {
@ -21,7 +23,7 @@ public:
{
Configuration config;
Ref<ecs::Registry> registry;
memory::Ref<ecs::Registry> registry;
ecs::Entity surface_entity;
};
@ -52,15 +54,15 @@ public:
private:
API m_api;
Ref<ecs::Registry> m_registry;
memory::Ref<ecs::Registry> m_registry;
ecs::Entity m_surface_entity;
Scope<class IContext> m_context;
memory::Scope<class IContext> m_context;
Scope<class IRenderer> m_renderer;
memory::Scope<class IRenderer> m_renderer;
std::vector<Scope<class IMessenger>> m_messengers;
std::vector<memory::Scope<class IMessenger>> m_messengers;
app::TickResult m_last_tick_result {};

View file

@ -0,0 +1,2 @@
add_library(std INTERFACE)
target_precompile_headers(std INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/public/pch.hpp)

155
modules/std/public/pch.hpp Normal file
View file

@ -0,0 +1,155 @@
/** @file pch.hpp
*
* @brief Provides the entire standard library as a precompiled header
*/
#pragma once // NOLINTBEGIN
//============================================================
// C Standard Library Headers (from <c...> family)
//============================================================
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
//============================================================
// Input/Output and Formatting
//============================================================
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>
//============================================================
// Containers
//============================================================
#include <array>
#include <deque>
#include <flat_map>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <span>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//============================================================
// Algorithms and Iterators
//============================================================
#include <algorithm>
#include <execution>
#include <iterator>
#include <numeric>
//============================================================
// Strings and Localization
//============================================================
#include <charconv>
#include <codecvt>
#include <locale>
#include <string>
#include <string_view>
//============================================================
// Memory Management and Smart Pointers
//============================================================
#include <memory>
#include <memory_resource>
#include <new>
#include <scoped_allocator>
//============================================================
// Utility and Miscellaneous
//============================================================
#include <any>
#include <bitset>
#include <chrono>
#include <functional>
#include <optional>
#include <ratio>
#include <source_location>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <utility>
#include <variant>
#include <version>
//============================================================
// Concurrency and Multithreading
//============================================================
#include <atomic>
#include <barrier>
#include <condition_variable>
#include <future>
#include <latch>
#include <mutex>
#include <semaphore>
#include <shared_mutex>
#include <stop_token>
#include <thread>
//============================================================
// Random Numbers and Numeric Limits
//============================================================
#include <complex>
#include <limits>
#include <numbers>
#include <random>
#include <valarray>
//============================================================
// Regular Expressions
//============================================================
#include <regex>
//============================================================
// Error Handling and Diagnostics
//============================================================
#include <cassert>
#include <cerrno>
#include <exception>
#include <source_location>
#include <stdexcept>
#include <system_error>
//============================================================
// C++20/23 Additions
//============================================================
#include <bit> // C++20 bit operations
#include <compare> // C++20 three-way comparison
#include <expected> // C++23 std::expected (if supported)
#include <format> // C++20 formatting
#include <print> // C++23 print functions
#include <ranges> // C++20 ranges library
#include <span> // C++20 span (repeated intentionally for clarity)
// #include <stacktrace> // C++23 stack tracing utilities // Not supported yet
#include <syncstream> // C++20 synchronized output streams
// NOLINTEND

View file

@ -1,3 +1,4 @@
#include <memory/reference.hpp>
#include <surface/components.hpp>
#include <surface/events/mouse.hpp>
#include <surface/requests/surface.hpp>
@ -44,7 +45,7 @@ constexpr auto all_events_mask = KeyPressMask | //
ColormapChangeMask | //
OwnerGrabButtonMask;
System::System(Ref<ecs::Registry> registry): m_registry(std::move(registry))
System::System(memory::Ref<ecs::Registry> registry): m_registry(std::move(registry))
{
ensure(m_registry, "Failed to initialize surface system: null registry");

View file

@ -1,5 +1,6 @@
#include <ecs/entity.hpp>
#include <ecs/registry.hpp>
#include <memory/reference.hpp>
#include <surface/components.hpp>
#include <surface/system.hpp>
#include <test/fuzz.hpp>
@ -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<ecs::Registry>();
auto registry = memory::create_ref<ecs::Registry>();
auto system = surface::System { registry };
while (auto action = provider.consume<uint8_t>())

View file

@ -1,4 +1,6 @@
#include <ecs/entity.hpp>
#include <memory/reference.hpp>
#include <memory/scope.hpp>
#include <ranges>
#include <surface/components.hpp>
#include <surface/requests/surface.hpp>
@ -41,7 +43,7 @@ struct overloads: Ts...
class Fixture
{
public:
[[nodiscard]] auto registry() -> Ref<ecs::Registry>
[[nodiscard]] auto registry() -> memory::Ref<ecs::Registry>
{
return m_registry;
}
@ -74,7 +76,7 @@ public:
}
private:
Ref<ecs::Registry> m_registry = create_ref<ecs::Registry>();
memory::Ref<ecs::Registry> m_registry = memory::create_ref<ecs::Registry>();
};
@ -108,7 +110,7 @@ Suite raii = "raii"_suite = [] {
Case { "post destruct has correct state" } = [] {
auto fixture = Fixture {};
auto system = create_scope<System>(fixture.registry());
auto system = memory::create_scope<System>(fixture.registry());
fixture.add_surface_component();
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 1);
@ -184,7 +186,7 @@ Suite registry_events = "registry_events"_suite = [] {
Case { "on_destrroy<SurfaceComponent> cleans up component" } = [] {
auto fixture = Fixture {};
auto system = create_scope<System>(fixture.registry());
auto system = memory::create_scope<System>(fixture.registry());
const auto &component = fixture.add_surface_component();
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 1);

View file

@ -1,9 +1,13 @@
#include <memory/reference.hpp>
#include <surface/system.hpp>
#include <utility>
namespace lt::surface {
System::System(Ref<ecs::Registry> registry, Ref<app::EventMediator> event_mediator)
System::System(
memory::Ref<ecs::Registry> registry,
memory::Ref<app::EventMediator> event_mediator
)
: m_registry(std::move(registry))
, m_event_mediator(std::move(event_mediator))
{

View file

@ -3,13 +3,14 @@
#include <app/system.hpp>
#include <ecs/registry.hpp>
#include <math/vec2.hpp>
#include <memory/reference.hpp>
namespace lt::surface {
class System: public app::ISystem
{
public:
[[nodiscard]] System(Ref<ecs::Registry> registry);
[[nodiscard]] System(memory::Ref<ecs::Registry> registry);
~System() override;
@ -64,7 +65,7 @@ private:
void set_visibility(ecs::EntityId surface_entity, bool visible);
Ref<ecs::Registry> m_registry;
memory::Ref<ecs::Registry> m_registry;
app::TickResult m_last_tick_result;
};

38
modules/test.sh Executable file
View file

@ -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 <memory/scope.hpp>\n"
$ref && includes+="#include <memory/reference.hpp>\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

View file

@ -1,3 +1,5 @@
#include <memory/reference.hpp>
#include <memory/scope.hpp>
#include <ui/gl/ui.hpp>
#include <ui/ui.hpp>
@ -25,15 +27,17 @@ namespace lt {
UserInterface *UserInterface::s_context = nullptr;
auto UserInterface::create(Ref<SharedContext> sharedContext) -> Scope<UserInterface>
auto UserInterface::create(memory::Ref<SharedContext> sharedContext)
-> memory::Scope<UserInterface>
{
auto scopeUserInterface = Scope<UserInterface> { nullptr };
auto scopeUserInterface = memory::Scope<UserInterface> { nullptr };
switch (GraphicsContext::get_graphics_api())
{
case GraphicsAPI::OpenGL: scopeUserInterface = create_scope<glUserInterface>(); break;
case GraphicsAPI::OpenGL: scopeUserInterface = memory::create_scope<glUserInterface>(); break;
case GraphicsAPI::DirectX: lt_win(scopeUserInterface = create_scope<dxUserInterface>();) break;
case GraphicsAPI::DirectX:
lt_win(scopeUserInterface = memory::create_scope<dxUserInterface>();) break;
default:
ensure(
@ -65,7 +69,7 @@ UserInterface::UserInterface()
s_context = this;
}
void UserInterface::init(Ref<SharedContext> sharedContext)
void UserInterface::init(memory::Ref<SharedContext> sharedContext)
{
// create context
IMGUI_CHECKVERSION();

View file

@ -1,5 +1,8 @@
#pragma once
#include <memory/reference.hpp>
#include <memory/scope.hpp>
namespace lt {
class Event;
@ -8,7 +11,8 @@ class SharedContext;
class UserInterface
{
public:
static auto create(Ref<SharedContext> sharedContext) -> Scope<UserInterface>;
static auto create(memory::Ref<SharedContext> sharedContext)
-> memory::Scope<UserInterface>;
static void dockspace_begin();
@ -20,9 +24,9 @@ public:
virtual ~UserInterface() = default;
void init(Ref<SharedContext> sharedContext);
void init(memory::Ref<SharedContext> sharedContext);
virtual void platform_implementation(Ref<SharedContext> sharedContext) = 0;
virtual void platform_implementation(memory::Ref<SharedContext> sharedContext) = 0;
virtual void begin() = 0;