From 2b81b4376cac14a6935cb70508362d2c73a009d8 Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 30 Nov 2025 09:46:48 +0330 Subject: [PATCH] revert: feat: lsd It was a horrible idea... --- modules/CMakeLists.txt | 97 ++++++------ modules/app/application.cppm | 28 ++-- modules/app/system.cppm | 22 +-- modules/asset_baker/bakers.cppm | 49 +++--- modules/assets/shader.cppm | 48 +++--- modules/bitwise/operations.cppm | 12 ++ modules/camera/components.cppm | 16 +- modules/debug/assertions.cppm | 29 ++-- modules/debug/instrumentor.cppm | 146 ++++++++++++++++++ modules/ecs/sparse_set.cppm | 37 +++-- modules/env/constants.cppm | 23 ++- modules/logger/logger.cppm | 125 +++++++-------- modules/lsd/algorithm.cppm | 9 -- modules/lsd/arr.cppm | 10 -- modules/lsd/bitwise.cppm | 11 -- modules/lsd/chrono.cppm | 13 -- modules/lsd/concepts.cppm | 9 -- modules/lsd/exceptions.cppm | 10 -- modules/lsd/filesystem.cppm | 16 -- modules/lsd/hash.cppm | 8 - modules/lsd/literals.cppm | 12 -- modules/lsd/lsd.cppm | 27 ---- modules/lsd/map.cppm | 9 -- modules/lsd/math/vec4.cppm | 104 ------------- modules/lsd/numeric_limits.cppm | 8 - modules/lsd/primitives.cppm | 34 ---- modules/lsd/set.cppm | 9 -- modules/lsd/span.cppm | 6 - modules/lsd/src_location.cppm | 8 - modules/lsd/str.cppm | 20 --- modules/lsd/thread.cppm | 13 -- modules/lsd/utils.cppm | 30 ---- modules/lsd/vec.cppm | 9 -- modules/{lsd => }/math/algebra.cppm | 18 +-- modules/{lsd => }/math/components.cppm | 0 modules/{lsd => }/math/mat4.cppm | 55 ++++--- modules/{lsd => }/math/trig.cppm | 11 +- modules/{lsd => }/math/vec2.cppm | 35 ++--- modules/{lsd => }/math/vec3.cppm | 44 +++--- modules/math/vec4.cppm | 109 +++++++++++++ modules/memory/null_on_move.cppm | 101 ++++++++++++ .../{lsd/ref.cppm => memory/reference.cppm} | 20 +-- modules/{lsd => memory}/scope.cppm | 23 +-- modules/renderer/vk/api_wrapper.cppm | 116 ++------------ modules/test/entrypoint.cpp | 37 +++-- modules/test/test.cppm | 33 ++-- modules/time/timer.cppm | 10 +- tools/cmake/functions.cmake | 32 ++-- 48 files changed, 763 insertions(+), 888 deletions(-) create mode 100644 modules/bitwise/operations.cppm create mode 100644 modules/debug/instrumentor.cppm delete mode 100644 modules/lsd/algorithm.cppm delete mode 100644 modules/lsd/arr.cppm delete mode 100644 modules/lsd/bitwise.cppm delete mode 100644 modules/lsd/chrono.cppm delete mode 100644 modules/lsd/concepts.cppm delete mode 100644 modules/lsd/exceptions.cppm delete mode 100644 modules/lsd/filesystem.cppm delete mode 100644 modules/lsd/hash.cppm delete mode 100644 modules/lsd/literals.cppm delete mode 100644 modules/lsd/lsd.cppm delete mode 100644 modules/lsd/map.cppm delete mode 100644 modules/lsd/math/vec4.cppm delete mode 100644 modules/lsd/numeric_limits.cppm delete mode 100644 modules/lsd/primitives.cppm delete mode 100644 modules/lsd/set.cppm delete mode 100644 modules/lsd/span.cppm delete mode 100644 modules/lsd/src_location.cppm delete mode 100644 modules/lsd/str.cppm delete mode 100644 modules/lsd/thread.cppm delete mode 100644 modules/lsd/utils.cppm delete mode 100644 modules/lsd/vec.cppm rename modules/{lsd => }/math/algebra.cppm (80%) rename modules/{lsd => }/math/components.cppm (100%) rename modules/{lsd => }/math/mat4.cppm (65%) rename modules/{lsd => }/math/trig.cppm (76%) rename modules/{lsd => }/math/vec2.cppm (56%) rename modules/{lsd => }/math/vec3.cppm (52%) create mode 100644 modules/math/vec4.cppm create mode 100644 modules/memory/null_on_move.cppm rename modules/{lsd/ref.cppm => memory/reference.cppm} (55%) rename modules/{lsd => memory}/scope.cppm (51%) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index d38d3f7..9ece596 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,35 +1,12 @@ add_module( - NAME - lsd - INTERFACES - lsd.cppm - ref.cppm - vec.cppm - arr.cppm - str.cppm - set.cppm - span.cppm - hash.cppm - utils.cppm - scope.cppm - chrono.cppm - thread.cppm - bitwise.cppm - concepts.cppm - algorithm.cppm - filesystem.cppm - primitives.cppm - exceptions.cppm - src_location.cppm - math/algebra.cppm - math/trig.cppm - math/vec2.cppm - math/vec3.cppm - math/vec4.cppm - math/mat4.cppm + NAME logger INTERFACES logger.cppm TESTS logger.test.cpp ) - -add_module(NAME logger INTERFACES logger.cppm DEPENDENCIES lsd) +add_module(NAME bitwise INTERFACES operations.cppm) +add_module(NAME env INTERFACES constants.cppm) +add_module( + NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm +) +add_module(NAME time INTERFACES timer.cppm) add_module( NAME @@ -41,12 +18,8 @@ add_module( SOURCES entrypoint.cpp DEPENDENCIES - lsd logger ) -add_module(NAME env INTERFACES constants.cppm DEPENDENCIES lsd) -# add_module(NAME memory INTERFACES reference.cppm scope.cppm) -add_module(NAME time INTERFACES timer.cppm DEPENDENCIES lsd) add_module( NAME @@ -54,10 +27,23 @@ add_module( ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/debug INTERFACES + instrumentor.cppm assertions.cppm DEPENDENCIES logger - lsd +) + +add_module( + NAME + math + INTERFACES + algebra.cppm + mat4.cppm + trig.cppm + vec2.cppm + vec3.cppm + vec4.cppm + components.cppm ) add_module( @@ -79,7 +65,6 @@ add_module( INTERFACES bakers.cppm DEPENDENCIES - lsd assets logger lt_debug @@ -88,15 +73,7 @@ add_module( # add_executable(asset_baker entrypoint.cpp) target_link_libraries(asset_baker # PRIVATE libasset_baker) -add_module( - NAME - camera - INTERFACES - components.cppm - DEPENDENCIES - math - lsd -) +add_module(NAME camera INTERFACES components.cppm DEPENDENCIES math) add_module( NAME @@ -104,9 +81,10 @@ add_module( INTERFACES application.cppm system.cppm + DEPENDENCIES + memory PRIVATE_DEPENDENCIES lt_debug - lsd ) add_module( @@ -119,11 +97,9 @@ add_module( DEPENDENCIES logger lt_debug - lsd + memory ) -return() - if(WIN32) add_module( NAME @@ -230,8 +206,6 @@ add_module( mirror ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/mirror - ENTRYPOINT - entrypoint.cpp INTERFACES system.cppm DEPENDENCIES @@ -242,6 +216,23 @@ add_module( surface renderer camera - TESTS - system.test.cpp + # TESTS + # system.test.cpp ) + +add_executable(exectest ${CMAKE_CURRENT_SOURCE_DIR}/mirror/entrypoint.cpp +) + +target_link_libraries(exectest PRIVATE + + mirror + app + time + input + surface + renderer + camera +) + +# add_executable_module(mirror entrypoint/mirror.cpp) +# target_link_libraries(mirror PRIVATE libmirror input) diff --git a/modules/app/application.cppm b/modules/app/application.cppm index 3308635..5c3cfaa 100644 --- a/modules/app/application.cppm +++ b/modules/app/application.cppm @@ -1,6 +1,8 @@ export module app; import app.system; -import lsd; +import memory.reference; +import memory.scope; +import std; namespace lt::app { @@ -23,19 +25,19 @@ public: void game_loop(); - void register_system(lsd::ref system); + void register_system(memory::Ref system); - void unregister_system(lsd::ref system); + void unregister_system(memory::Ref system); protected: Application() = default; private: - lsd::vec> m_systems; + std::vector> m_systems; - lsd::vec> m_systems_to_be_unregistered; + std::vector> m_systems_to_be_unregistered; - lsd::vec> m_systems_to_be_registered; + std::vector> m_systems_to_be_registered; }; } // namespace lt::app @@ -50,11 +52,11 @@ void Application::game_loop() for (auto &system : m_systems) { const auto &last_tick = system->get_last_tick_result(); - const auto now = lsd::chrono::steady_clock::now(); + const auto now = std::chrono::steady_clock::now(); system->tick(TickInfo { .delta_time = now - last_tick.end_time, - .budget = lsd::chrono::milliseconds { 10 }, + .budget = std::chrono::milliseconds { 10 }, .start_time = now, }); } @@ -67,7 +69,7 @@ void Application::game_loop() for (auto &system : m_systems_to_be_unregistered) { m_systems.erase( - lsd::remove(m_systems.begin(), m_systems.end(), system), + std::remove(m_systems.begin(), m_systems.end(), system), m_systems.end() ); } @@ -79,14 +81,14 @@ void Application::game_loop() } } -void Application::register_system(lsd::ref system) +void Application::register_system(memory::Ref system) { - m_systems.emplace_back(lsd::move(system)); + m_systems.emplace_back(std::move(system)); } -void Application::unregister_system(lsd::ref system) +void Application::unregister_system(memory::Ref system) { - m_systems_to_be_unregistered.emplace_back(lsd::move(system)); + m_systems_to_be_unregistered.emplace_back(std::move(system)); } } // namespace lt::app diff --git a/modules/app/system.cppm b/modules/app/system.cppm index d066f9c..f0a731e 100644 --- a/modules/app/system.cppm +++ b/modules/app/system.cppm @@ -1,6 +1,6 @@ export module app.system; import logger; -import lsd; +import std; namespace lt::app { @@ -9,9 +9,9 @@ namespace lt::app { */ export struct TickInfo { - using Timepoint_T = lsd::chrono::time_point; + using Timepoint_T = std::chrono::time_point; - using Duration_T = lsd::chrono::duration; + using Duration_T = std::chrono::duration; /** Duration since previous tick's end_time to current tick's start_time. */ Duration_T delta_time {}; @@ -32,9 +32,9 @@ export struct TickInfo /** Information about how a system's tick performed */ export struct TickResult { - using Timepoint_T = lsd::chrono::time_point; + using Timepoint_T = std::chrono::time_point; - using Duration_T = lsd::chrono::duration; + using Duration_T = std::chrono::duration; /** The info supplied to the system for ticking. */ TickInfo info; @@ -48,7 +48,7 @@ export struct TickResult export struct SystemDiagnosis { - enum class Severity : u8 + enum class Severity : std::uint8_t { verbose, info, @@ -57,9 +57,9 @@ export struct SystemDiagnosis fatal, }; - lsd::str message; + std::string message; - lsd::str code; + std::string code; Severity severity; }; @@ -69,9 +69,9 @@ export class SystemStats public: void push_diagnosis(SystemDiagnosis &&diagnosis) { - auto &diag = m_diagnosis.emplace_back(lsd::move(diagnosis)); + auto &diag = m_diagnosis.emplace_back(std::move(diagnosis)); - log::info("message: {}", lsd::str { diag.message }); + log::info("message: {}", std::string { diag.message }); } [[nodiscard]] auto empty_diagnosis() const -> bool @@ -80,7 +80,7 @@ public: } private: - lsd::vec m_diagnosis; + std::vector m_diagnosis; }; export class ISystem diff --git a/modules/asset_baker/bakers.cppm b/modules/asset_baker/bakers.cppm index 0bfc7d3..522ce59 100644 --- a/modules/asset_baker/bakers.cppm +++ b/modules/asset_baker/bakers.cppm @@ -1,33 +1,32 @@ export module bakers; + import debug.assertions; import assets.metadata; import assets.shader; import logger; -import lsd; - -namespace lt { +import std; export void bake_shader( - const lsd::file::path &in_path, - const lsd::file::path &out_path, - assets::ShaderAsset::Type type + const std::filesystem::path &in_path, + const std::filesystem::path &out_path, + lt::assets::ShaderAsset::Type type ) { - using assets::ShaderAsset; - using enum assets::ShaderAsset::Type; + using lt::assets::ShaderAsset; + using enum lt::assets::ShaderAsset::Type; - auto glsl_path = lsd::str { in_path.string() }; - auto spv_path = lsd::format("{}.spv", glsl_path); - log::trace( + auto glsl_path = std::string { in_path.string() }; + auto spv_path = std::format("{}.spv", glsl_path); + lt::log::trace( "Compiling {} shader {} -> {}", type == vertex ? "vertex" : "fragment", - lsd::str { glsl_path }, - lsd::str { spv_path } + std::string { glsl_path }, + std::string { spv_path } ); // Don't bother linking to shaderc, just invoke the command with a system call. // NOLINTNEXTLINE(concurrency-mt-unsafe) - lsd::system(lsd::format( + std::system(std::format( "glslc --target-env=vulkan1.4 -std=450core -fshader-stage={} {} -o {}", type == vertex ? "vert" : "frag", glsl_path, @@ -35,35 +34,33 @@ export void bake_shader( ) .c_str()); - auto stream = lsd::file::in_stream(spv_path, lsd::file::ios_binary); - debug::ensure( + auto stream = std::ifstream(spv_path, std::ios::binary); + lt::debug::ensure( stream.is_open(), "Failed to open compiled {} shader at: {}", type == vertex ? "vert" : "frag", spv_path ); - stream.seekg(0, lsd::file::ios_end); + stream.seekg(0, std::ios::end); const auto size = stream.tellg(); - auto bytes = lsd::vec(size); - stream.seekg(0, lsd::file::ios_beg); + auto bytes = std::vector(size); + stream.seekg(0, std::ios::beg); stream.read((char *)bytes.data(), size); // NOLINT - log::debug("BYTES: {}", bytes.size()); + lt::log::debug("BYTES: {}", bytes.size()); stream.close(); - lsd::file::remove(spv_path); + std::filesystem::remove(spv_path); ShaderAsset::pack( out_path, - assets::AssetMetadata { - .version = assets::current_version, + lt::assets::AssetMetadata { + .version = lt::assets::current_version, .type = ShaderAsset::asset_type_identifier, }, ShaderAsset::Metadata { .type = type, }, - lsd::move(bytes) + std::move(bytes) ); } - -} // namespace lt diff --git a/modules/assets/shader.cppm b/modules/assets/shader.cppm index 5cd038f..48c4a0b 100644 --- a/modules/assets/shader.cppm +++ b/modules/assets/shader.cppm @@ -2,7 +2,7 @@ export module assets.shader; import assets.metadata; import debug.assertions; -import lsd; +import std; export namespace lt::assets { @@ -16,7 +16,7 @@ public: code, }; - enum class Type : u8 + enum class Type : std::uint8_t { vertex, fragment, @@ -30,15 +30,15 @@ public: }; static void pack( - const lsd::file::path &destination, + const std::filesystem::path &destination, AssetMetadata asset_metadata, Metadata metadata, Blob code_blob ); - ShaderAsset(const lsd::file::path &path); + ShaderAsset(const std::filesystem::path &path); - void unpack_to(BlobTag tag, lsd::span destination) const; + void unpack_to(BlobTag tag, std::span destination) const; [[nodiscard]] auto unpack(BlobTag tag) const -> Blob; @@ -57,7 +57,7 @@ public: debug::ensure( tag == BlobTag::code, "Invalid blob tag for shader asset: {}", - lsd::to_underlying(tag) + std::to_underlying(tag) ); return m_code_blob_metadata; @@ -88,15 +88,15 @@ constexpr auto total_metadata_size = // + sizeof(BlobMetadata::compressed_size) // + sizeof(BlobMetadata::uncompressed_size); -ShaderAsset::ShaderAsset(const lsd::file::path &path): m_stream(path) +ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) { debug::ensure(m_stream.is_open(), "Failed to open shader asset at: {}", path.string()); const auto read = [this](auto &field) { - m_stream.read(bit_cast(&field), sizeof(field)); + m_stream.read(std::bit_cast(&field), sizeof(field)); }; m_stream.seekg(0, std::ifstream::end); - const auto file_size = static_cast(m_stream.tellg()); + const auto file_size = static_cast(m_stream.tellg()); debug::ensure( file_size > total_metadata_size, "Failed to open shader asset at: {}, file smaller than metadata: {} < {}", @@ -132,14 +132,14 @@ ShaderAsset::ShaderAsset(const lsd::file::path &path): m_stream(path) ); debug::ensure( - lsd::to_underlying(m_metadata.type) <= std::to_underlying(Type::compute), + std::to_underlying(m_metadata.type) <= std::to_underlying(Type::compute), "Failed to open shader asset at: {}, invalid shader type: {}", path.string(), - lsd::to_underlying(m_metadata.type) + std::to_underlying(m_metadata.type) ); debug::ensure( - m_code_blob_metadata.tag == lsd::to_underlying(BlobTag::code), + m_code_blob_metadata.tag == std::to_underlying(BlobTag::code), "Failed to open shader asset at: {}, invalid blob tag: {}", path.string(), m_code_blob_metadata.tag @@ -156,7 +156,7 @@ ShaderAsset::ShaderAsset(const lsd::file::path &path): m_stream(path) } /* static */ void ShaderAsset::pack( - const lsd::file::path &destination, + const std::filesystem::path &destination, AssetMetadata asset_metadata, Metadata metadata, Blob code_blob @@ -168,7 +168,7 @@ ShaderAsset::ShaderAsset(const lsd::file::path &path): m_stream(path) }; const auto code_blob_metadata = BlobMetadata { - .tag = lsd::to_underlying(BlobTag::code), + .tag = std::to_underlying(BlobTag::code), .offset = total_metadata_size, .compression_type = CompressionType::none, .compressed_size = code_blob.size(), @@ -177,7 +177,7 @@ ShaderAsset::ShaderAsset(const lsd::file::path &path): m_stream(path) debug::ensure(stream.is_open(), "Failed to pack shader asset to {}", destination.string()); const auto write = [&stream](auto &field) { - stream.write(bit_cast(&field), sizeof(field)); + stream.write(std::bit_cast(&field), sizeof(field)); }; write(asset_metadata.type); write(asset_metadata.version); @@ -187,31 +187,31 @@ ShaderAsset::ShaderAsset(const lsd::file::path &path): m_stream(path) write(code_blob_metadata.compression_type); write(code_blob_metadata.compressed_size); write(code_blob_metadata.uncompressed_size); - stream.write(bit_cast(code_blob.data()), static_cast(code_blob.size())); + stream.write(std::bit_cast(code_blob.data()), static_cast(code_blob.size())); } -void ShaderAsset::unpack_to(BlobTag tag, lsd::span destination) const +void ShaderAsset::unpack_to(BlobTag tag, std::span destination) const { debug::ensure( tag == BlobTag::code, "Invalid blob tag for shader asset: {}", - lsd::to_underlying(tag) + std::to_underlying(tag) ); debug::ensure( destination.size() >= m_code_blob_metadata.uncompressed_size, "Failed to unpack shader blob {} to destination ({}) of size {} since it's smaller " "than the blobl's uncompressed size: {}", - lsd::to_underlying(tag), - bit_cast(destination.data()), + std::to_underlying(tag), + std::bit_cast(destination.data()), destination.size(), m_code_blob_metadata.uncompressed_size ); - m_stream.seekg(static_cast(m_code_blob_metadata.offset)); + m_stream.seekg(static_cast(m_code_blob_metadata.offset)); m_stream.read( - bit_cast(destination.data()), - static_cast(m_code_blob_metadata.uncompressed_size) + std::bit_cast(destination.data()), + static_cast(m_code_blob_metadata.uncompressed_size) ); } @@ -220,7 +220,7 @@ void ShaderAsset::unpack_to(BlobTag tag, lsd::span destination) const debug::ensure( tag == BlobTag::code, "Invalid blob tag for shader asset: {}", - lsd::to_underlying(tag) + std::to_underlying(tag) ); auto blob = Blob(m_code_blob_metadata.uncompressed_size); diff --git a/modules/bitwise/operations.cppm b/modules/bitwise/operations.cppm new file mode 100644 index 0000000..dd66a76 --- /dev/null +++ b/modules/bitwise/operations.cppm @@ -0,0 +1,12 @@ +export module bitwise; +import std; + +namespace lt::bitwise { + +/* bit-wise */ +export constexpr auto bit(std::uint32_t x) -> std::uint32_t +{ + return 1u << x; +} + +} // namespace lt::bitwise diff --git a/modules/camera/components.cppm b/modules/camera/components.cppm index fab5dbb..883813b 100644 --- a/modules/camera/components.cppm +++ b/modules/camera/components.cppm @@ -1,19 +1,19 @@ export module camera.components; -import lsd; +import math.vec4; -export namespace lt::camera::components { +namespace lt::camera::components { -struct PerspectiveCamera +export struct PerspectiveCamera { - f32 vertical_fov {}; + float vertical_fov {}; - f32 near_plane {}; + float near_plane {}; - f32 far_plane {}; + float far_plane {}; - f32 aspect_ratio {}; + float aspect_ratio {}; - lsd::vec4 background_color; + math::vec4 background_color; bool is_primary {}; }; diff --git a/modules/debug/assertions.cppm b/modules/debug/assertions.cppm index f3d4bb6..1666d10 100644 --- a/modules/debug/assertions.cppm +++ b/modules/debug/assertions.cppm @@ -1,36 +1,43 @@ export module debug.assertions; -import lsd; +import std; -export namespace lt::debug { +namespace lt::debug { -template +/////////////////////////////////////// +// ----------* INTERFACE *--------- // +///////////////////////////////////// +export template struct ensure { ensure( const Expression_T &expression, - lsd::format_str fmt, + std::format_string fmt, Args_T &&...args, - const lsd::src_location &location = lsd::src_location::current() + const std::source_location &location = std::source_location::current() ); }; -template -ensure(Expression_T, lsd::format_str, Args_T &&...) -> ensure; +export template +ensure(Expression_T, std::format_string, Args_T &&...) + -> ensure; +/////////////////////////////////////// +// * IMPLEMENTATION -- TEMPLATES * // +///////////////////////////////////// template ensure::ensure( const Expression_T &expression, - lsd::format_str fmt, + std::format_string fmt, Args_T &&...args, - const lsd::src_location &location + const std::source_location &location ) { if (!static_cast(expression)) { - throw lsd::runtime_error { lsd::format( + throw std::runtime_error { std::format( "exception: {}\nlocation: {}:{}", - lsd::format(fmt, lsd::forward(args)...), + std::format(fmt, std::forward(args)...), location.file_name(), location.line() ) }; diff --git a/modules/debug/instrumentor.cppm b/modules/debug/instrumentor.cppm new file mode 100644 index 0000000..8978a58 --- /dev/null +++ b/modules/debug/instrumentor.cppm @@ -0,0 +1,146 @@ +export module debug.instrumentor; + +import std; +import logger; + +namespace lt::debug { + +struct ScopeProfileResult +{ + std::string name; + long long start, duration; + std::uint32_t threadID; +}; + +class Instrumentor +{ +public: + static auto instance() -> Instrumentor & + { + static auto instance = Instrumentor {}; + return instance; + } + + static void begin_session(const std::string &outputPath) + { + instance().begin_session_impl(outputPath); + } + static void end_session() + { + instance().end_session_impl(); + } + + static void submit_scope_profile(const ScopeProfileResult &profileResult) + { + instance().submit_scope_profile_impl(profileResult); + } + +private: + std::ofstream m_output_file_stream; + + unsigned int m_current_session_count { 0u }; + + Instrumentor() = default; + + void begin_session_impl(const std::string &outputPath); + + void end_session_impl(); + + void submit_scope_profile_impl(const ScopeProfileResult &profileResult); +}; + +class InstrumentorTimer +{ +public: + InstrumentorTimer(const std::string &scopeName); + + ~InstrumentorTimer(); + +private: + ScopeProfileResult m_result; + + std::chrono::time_point m_start; +}; + +} // namespace lt::debug + +/* scope */ +#define lt_profile_scope(name) lt_profile_scope_no_redifinition(name, __LINE__) +#define lt_profile_scope_no_redifinition(name, line) lt_profile_scope_no_redifinition2(name, line) +#define lt_profile_scope_no_redifinition2(name, line) InstrumentorTimer timer##line(name) + +/* function */ +#define LT_PROFILE_FUNCTION lt_profile_scope(__FUNCSIG__) + +/* session */ +#define lt_profile_begin_session(outputPath) ::lt::Instrumentor::begin_session(outputPath) +#define lt_profile_end_session() ::lt::Instrumentor::end_session() + +module :private; +namespace lt::debug { + +void Instrumentor::begin_session_impl(const std::string &outputPath) +{ + std::filesystem::create_directory(outputPath.substr(0, outputPath.find_last_of('/') + 1)); + + m_output_file_stream.open(outputPath); + m_output_file_stream << "{\"traceEvents\":["; +} + +void Instrumentor::end_session_impl() +{ + if (m_current_session_count == 0u) + { + log::warn("0 profiling for the ended session"); + } + + m_current_session_count = 0u; + + m_output_file_stream << "]}"; + m_output_file_stream.flush(); + m_output_file_stream.close(); +} + +void Instrumentor::submit_scope_profile_impl(const ScopeProfileResult &profileResult) +{ + if (m_current_session_count++ == 0u) + { + m_output_file_stream << "{"; + } + else + { + m_output_file_stream << ",{"; + } + + m_output_file_stream << R"("name":")" << profileResult.name << "\","; + m_output_file_stream << R"("cat": "scope",)"; + m_output_file_stream << R"("ph": "X",)"; + m_output_file_stream << "\"ts\":" << profileResult.start << ","; + m_output_file_stream << "\"dur\":" << profileResult.duration << ","; + m_output_file_stream << "\"pid\":0,"; + m_output_file_stream << "\"tid\":" << profileResult.threadID << ""; + m_output_file_stream << "}"; +} + +InstrumentorTimer::InstrumentorTimer(const std::string &scopeName) + : m_result({ .name = scopeName, .start = 0, .duration = 0, .threadID = 0 }) + , m_start(std::chrono::steady_clock::now()) +{ +} + +InstrumentorTimer::~InstrumentorTimer() +{ + auto end = std::chrono::steady_clock::now(); + + m_result.start = std::chrono::time_point_cast(m_start) + .time_since_epoch() + .count(); + + m_result.duration = std::chrono::time_point_cast(end) + .time_since_epoch() + .count() + - m_result.start; + + Instrumentor::submit_scope_profile(m_result); +} +} // namespace lt::debug diff --git a/modules/ecs/sparse_set.cppm b/modules/ecs/sparse_set.cppm index 511b85a..340a760 100644 --- a/modules/ecs/sparse_set.cppm +++ b/modules/ecs/sparse_set.cppm @@ -1,13 +1,13 @@ export module ecs.sparse_set; import debug.assertions; -import lsd; +import std; -export namespace lt::ecs { +namespace lt::ecs { /** * @ref https://programmingpraxis.com/2012/03/09/sparse-sets/ */ -template +export template class TypeErasedSparseSet { public: @@ -26,17 +26,17 @@ public: virtual void remove(Identifier_T identifier) = 0; }; -template +export template class SparseSet: public TypeErasedSparseSet { public: using Dense_T = std::pair; - static constexpr auto max_capacity = size_t { 1'000'000 }; + static constexpr auto max_capacity = std::size_t { 1'000'000 }; - static constexpr auto null_identifier = lsd::numeric_limits().max(); + static constexpr auto null_identifier = std::numeric_limits().max(); - explicit SparseSet(size_t initial_capacity = 1) + explicit SparseSet(std::size_t initial_capacity = 1) { debug::ensure( initial_capacity <= max_capacity, @@ -53,7 +53,10 @@ public: { if (m_sparse.size() < identifier + 1) { - auto new_capacity = std::max(static_cast(identifier + 1), m_sparse.size() * 2); + auto new_capacity = std::max( + static_cast(identifier + 1), + m_sparse.size() * 2 + ); new_capacity = std::min(new_capacity, max_capacity); // log::debug("Increasing sparse vector size:", m_dead_count); @@ -119,12 +122,12 @@ public: && m_dense[m_sparse[identifier]].first == identifier; } - auto begin() -> lsd::vector::iterator + auto begin() -> std::vector::iterator { return m_dense.begin(); } - auto end() -> lsd::vector::iterator + auto end() -> std::vector::iterator { return m_dense.end(); } @@ -143,15 +146,15 @@ public: [[nodiscard]] auto &&operator[](this auto &&self, Identifier_T identifier) { using Self_T = decltype(self); - return lsd::forward(self).m_dense[lsd::forward(self).m_sparse[identifier]]; + return std::forward(self).m_dense[std::forward(self).m_sparse[identifier]]; } - [[nodiscard]] auto get_size() const noexcept -> size_t + [[nodiscard]] auto get_size() const noexcept -> std::size_t { return m_alive_count; } - [[nodiscard]] auto get_capacity() const noexcept -> size_t + [[nodiscard]] auto get_capacity() const noexcept -> std::size_t { return m_sparse.capacity(); } @@ -162,13 +165,13 @@ public: } private: - lsd::vector m_dense; + std::vector m_dense; - lsd::vector m_sparse; + std::vector m_sparse; - size_t m_alive_count {}; + std::size_t m_alive_count {}; - size_t m_dead_count {}; + std::size_t m_dead_count {}; }; } // namespace lt::ecs diff --git a/modules/env/constants.cppm b/modules/env/constants.cppm index a13022d..8c1b40f 100644 --- a/modules/env/constants.cppm +++ b/modules/env/constants.cppm @@ -1,9 +1,10 @@ export module env; -import lsd; -export namespace lt { +import std; -enum class Platform : u8 +namespace lt { + +enum class Platform : std::uint8_t { /** The GNU/Linux platform. * Tested on the following distros: arch-x86_64 @@ -25,7 +26,7 @@ enum class Platform : u8 }; /** The compiler that was used for compiling the project. */ -enum class Compiler : u8 +enum class Compiler : std::uint8_t { clang, gcc, @@ -35,25 +36,19 @@ enum class Compiler : u8 namespace constants { -#define lt_windows_only(x) -#define lt_linux_only(x) -#define lt_mac_only(x) - #if defined(LIGHT_PLATFORM_WINDOWS) - // NOLINTNEXTLINE - #define lt_windows_only(x) x + #define lt_win(x) constexpr auto platform = Platform::windows; constexpr auto platform_name = "windows"; + #undef LIGHT_PLATFORM_WINDOWS + #elif defined(LIGHT_PLATFORM_LINUX) - // NOLINTNEXTLINE - #define lt_linux_only(x) x constexpr auto platform = Platform::gnu_linux; constexpr auto platform_name = "gnu_linux"; #elif defined(LIGHT_PLATFORM_MAC) - // NOLINTNEXTLINE - #define lt_mac_only(x) x + #define lt_mac(x) x constexpr auto platform = Platform::mac; constexpr auto platform_name = "mac"; diff --git a/modules/logger/logger.cppm b/modules/logger/logger.cppm index eb87e30..4e39d8c 100644 --- a/modules/logger/logger.cppm +++ b/modules/logger/logger.cppm @@ -1,49 +1,50 @@ export module logger; -import lsd; + +import std; namespace lt::log { -auto thread_hash_id() noexcept -> u64 -{ - return static_cast(lsd::hash {}(lsd::this_thread_id())); -} - -} // namespace lt::log - -export namespace lt::log { - /** Severity of a log message. */ -enum class Level : u8 +enum class Level : std::uint8_t { /** Lowest and most vebose log level, for tracing execution paths and events */ - trace = 0u, + trace = 0, /** Vebose log level, for enabling temporarily to debug */ - debug = 1u, + debug = 1, /** General information */ - info = 2u, + info = 2, /** Things we should to be aware of and edge cases */ - warn = 3u, + warn = 3, /** Defects, bugs and undesired behaviour */ - error = 4u, + error = 4, /** Unrecoverable errors */ - critical = 5u, + critical = 5, /** No logging */ - off = 6u, + off = 6, }; +namespace details { + +inline auto thread_hash_id() noexcept -> std::uint64_t +{ + return static_cast(std::hash {}(std::this_thread::get_id())); +} + +} // namespace details + template struct [[maybe_unused]] print { [[maybe_unused]] print( Level level, - const lsd::src_location &location, - lsd::format_str format, + const std::source_location &location, + std::format_string format, Args &&...arguments ) noexcept { @@ -62,118 +63,118 @@ struct [[maybe_unused]] print } // clang-format on - lsd::unreachable(); + std::unreachable(); }; - const auto path = lsd::file::path { location.file_name() }; + const auto path = std::filesystem::path { location.file_name() }; - lsd::println( + std::println( "{} {} ==> {}", to_string(level, location), - lsd::format("{}:{}", path.filename().string(), location.line()), - lsd::format(format, lsd::forward(arguments)...) + std::format("{}:{}", path.filename().string(), location.line()), + std::format(format, std::forward(arguments)...) ); } }; template -print(Level, const lsd::src_location &, lsd::format_str, Args &&...) noexcept +print(Level, const std::source_location &, std::format_string, Args &&...) noexcept -> print; -template +export template struct [[maybe_unused]] trace { [[maybe_unused]] trace( - lsd::format_str format, + std::format_string format, Args &&...arguments, - const lsd::src_location &location = lsd::src_location::current() + const std::source_location &location = std::source_location::current() ) noexcept { - print(Level::trace, location, format, lsd::forward(arguments)...); + print(Level::trace, location, format, std::forward(arguments)...); } }; -template -trace(lsd::format_str, Args &&...) noexcept -> trace; +export template +trace(std::format_string, Args &&...) noexcept -> trace; -template +export template struct [[maybe_unused]] debug { [[maybe_unused]] debug( - lsd::format_str format, + std::format_string format, Args &&...arguments, - const lsd::src_location &location = lsd::src_location::current() + const std::source_location &location = std::source_location::current() ) noexcept { - print(Level::debug, location, format, lsd::forward(arguments)...); + print(Level::debug, location, format, std::forward(arguments)...); } }; -template -debug(lsd::format_str, Args &&...) noexcept -> debug; +export template +debug(std::format_string, Args &&...) noexcept -> debug; -template +export template struct [[maybe_unused]] info { [[maybe_unused]] info( - lsd::format_str format, + std::format_string format, Args &&...arguments, - const lsd::src_location &location = lsd::src_location::current() + const std::source_location &location = std::source_location::current() ) noexcept { - print(Level::info, location, format, lsd::forward(arguments)...); + print(Level::info, location, format, std::forward(arguments)...); } }; -template -info(lsd::format_str, Args &&...) noexcept -> info; +export template +info(std::format_string, Args &&...) noexcept -> info; -template +export template struct [[maybe_unused]] warn { [[maybe_unused]] warn( - lsd::format_str format, + std::format_string format, Args &&...arguments, - const lsd::src_location &location = lsd::src_location::current() + const std::source_location &location = std::source_location::current() ) noexcept { - print(Level::warn, location, format, lsd::forward(arguments)...); + print(Level::warn, location, format, std::forward(arguments)...); } }; -template -warn(lsd::format_str, Args &&...) noexcept -> warn; +export template +warn(std::format_string, Args &&...) noexcept -> warn; -template +export template struct [[maybe_unused]] error { [[maybe_unused]] error( - lsd::format_str format, + std::format_string format, Args &&...arguments, - const lsd::src_location &location = lsd::src_location::current() + const std::source_location &location = std::source_location::current() ) noexcept { - print(Level::error, location, format, lsd::forward(arguments)...); + print(Level::error, location, format, std::forward(arguments)...); } }; -template -error(lsd::format_str, Args &&...) noexcept -> error; +export template +error(std::format_string, Args &&...) noexcept -> error; -template +export template struct [[maybe_unused]] critical { [[maybe_unused]] critical( - lsd::format_str format, + std::format_string format, Args &&...arguments, - const lsd::src_location &location = lsd::src_location::current() + const std::source_location &location = std::source_location::current() ) noexcept { - print(Level::critical, location, format, lsd::forward(arguments)...); + print(Level::critical, location, format, std::forward(arguments)...); } }; -template -critical(lsd::format_str, Args &&...) noexcept -> critical; +export template +critical(std::format_string, Args &&...) noexcept -> critical; } // namespace lt::log diff --git a/modules/lsd/algorithm.cppm b/modules/lsd/algorithm.cppm deleted file mode 100644 index a8e6647..0000000 --- a/modules/lsd/algorithm.cppm +++ /dev/null @@ -1,9 +0,0 @@ -export module lsd.algorithm; -import std; - -export namespace lt::lsd { - -using ::std::remove; -using ::std::remove_if; - -} // namespace lt::lsd diff --git a/modules/lsd/arr.cppm b/modules/lsd/arr.cppm deleted file mode 100644 index 2674418..0000000 --- a/modules/lsd/arr.cppm +++ /dev/null @@ -1,10 +0,0 @@ -export module lsd.arr; -import lsd.primitives; -import std; - -export namespace lt::lsd { - -template -using arr = std::array; - -} diff --git a/modules/lsd/bitwise.cppm b/modules/lsd/bitwise.cppm deleted file mode 100644 index 66cf2d7..0000000 --- a/modules/lsd/bitwise.cppm +++ /dev/null @@ -1,11 +0,0 @@ -export module lsd.bitwise; - -export namespace lt::lsd { - -/* bit-wise */ -constexpr auto bit(auto x) -{ - return 1u << x; -} - -} // namespace lt::lsd diff --git a/modules/lsd/chrono.cppm b/modules/lsd/chrono.cppm deleted file mode 100644 index 2d17c8f..0000000 --- a/modules/lsd/chrono.cppm +++ /dev/null @@ -1,13 +0,0 @@ -export module lsd.chrono; -import std; - -export namespace lt::lsd::chrono { - -using std::chrono::duration; -using std::chrono::steady_clock; -using std::chrono::time_point; -using std::chrono::time_point_cast; - -using std::chrono::milliseconds; - -} // namespace lt::lsd::chrono diff --git a/modules/lsd/concepts.cppm b/modules/lsd/concepts.cppm deleted file mode 100644 index ff085f9..0000000 --- a/modules/lsd/concepts.cppm +++ /dev/null @@ -1,9 +0,0 @@ -export module lsd.concepts; - -import std; - -export namespace lt::lsd { - -using std::invocable; - -} diff --git a/modules/lsd/exceptions.cppm b/modules/lsd/exceptions.cppm deleted file mode 100644 index 7be1dba..0000000 --- a/modules/lsd/exceptions.cppm +++ /dev/null @@ -1,10 +0,0 @@ -export module lsd.exceptions; - -import std; - -export namespace lt::lsd { - -using std::exception; -using std::runtime_error; - -} // namespace lt::lsd diff --git a/modules/lsd/filesystem.cppm b/modules/lsd/filesystem.cppm deleted file mode 100644 index 5f688b9..0000000 --- a/modules/lsd/filesystem.cppm +++ /dev/null @@ -1,16 +0,0 @@ -export module lsd.filesystem; -import std; - -export namespace lt::lsd::file { - -using path = ::std::filesystem::path; -using ::std::filesystem::remove; -using in_stream = ::std::ifstream; -using out_stream = ::std::ofstream; - -constexpr auto ios_binary = std::ios::binary; -constexpr auto ios_end = std::ios::end; -constexpr auto ios_beg = std::ios::beg; - - -} // namespace lt::lsd::file diff --git a/modules/lsd/hash.cppm b/modules/lsd/hash.cppm deleted file mode 100644 index 592b4bc..0000000 --- a/modules/lsd/hash.cppm +++ /dev/null @@ -1,8 +0,0 @@ -export module lsd.hash; -import std; - -export namespace lt::lsd { - -template -using hash = std::hash; -} diff --git a/modules/lsd/literals.cppm b/modules/lsd/literals.cppm deleted file mode 100644 index 50c9962..0000000 --- a/modules/lsd/literals.cppm +++ /dev/null @@ -1,12 +0,0 @@ -export module lsd.literals; -import lsd.str; -import std; - -export namespace lt { - -constexpr str_view operator""sv(const char *str, unsigned long len) noexcept -{ - return str_view { str, len }; -} - -} // namespace lt diff --git a/modules/lsd/lsd.cppm b/modules/lsd/lsd.cppm deleted file mode 100644 index f2ec078..0000000 --- a/modules/lsd/lsd.cppm +++ /dev/null @@ -1,27 +0,0 @@ -export module lsd; -export import lsd.set; -export import lsd.vec; -export import lsd.arr; -export import lsd.str; -export import lsd.hash; -export import lsd.span; -export import lsd.utils; -export import lsd.thread; -export import lsd.chrono; -export import lsd.ref_ptr; -export import lsd.bitwise; -export import lsd.concepts; -export import lsd.scope_ptr; -export import lsd.exceptions; -export import lsd.primitives; -export import lsd.filesystem; -export import lsd.src_location; - -export import lsd.math.vec2; -export import lsd.math.vec3; -export import lsd.math.vec4; -export import lsd.math.mat4; -export import lsd.math.algebra; -export import lsd.math.trig; - -export import lsd.algorithm; diff --git a/modules/lsd/map.cppm b/modules/lsd/map.cppm deleted file mode 100644 index 3fd1da6..0000000 --- a/modules/lsd/map.cppm +++ /dev/null @@ -1,9 +0,0 @@ -export module lsd.bitwise; -import std; - -export namespace lt::lsd { - -template -using set = std::set; - -} diff --git a/modules/lsd/math/vec4.cppm b/modules/lsd/math/vec4.cppm deleted file mode 100644 index f6beee7..0000000 --- a/modules/lsd/math/vec4.cppm +++ /dev/null @@ -1,104 +0,0 @@ -export module lsd.math.vec4; -import lsd.math.vec2; -import lsd.math.vec3; -import lsd.primitives; -import lsd.arr; -import lsd.str; - -export namespace lt::lsd { - -template -struct vec4_impl -{ - constexpr vec4_impl() = default; - - constexpr explicit vec4_impl(T scalar): x(scalar), y(scalar), z(scalar), w(scalar) - { - } - - constexpr vec4_impl(T x, T y, T z, T w): x(x), y(y), z(z), w(w) - { - } - - [[nodiscard]] auto operator==(const vec4_impl &other) const -> bool - { - return x == other.x && y == other.y && z == other.z && w == other.w; - } - - [[nodiscard]] auto operator!=(const vec4_impl &other) const -> bool - - { - return !(*this == other); - } - - [[nodiscard]] constexpr auto operator-(const vec4_impl &other) const -> vec4_impl - { - return { - x - other.x, - y - other.y, - z - other.z, - w - other.w, - }; - } - - [[nodiscard]] constexpr auto operator[](size_t idx) -> T & - { - return values[idx]; - } - - [[nodiscard]] constexpr auto operator[](size_t idx) const -> const T & - { - return values[idx]; - } - - // NOLINTNEXTLINE - union - { - struct - { - T x; - - T y; - - T z; - - T w; - }; - struct - { - T r; - - T g; - - T b; - - T a; - }; - struct - { - lsd::arr values; - }; - }; -}; - -using vec4 = vec4_impl; - -using ivec4 = vec4_impl; - -using uvec4 = vec4_impl; - -} // namespace lt::lsd - -export template -struct lt::lsd::formatter> -{ - constexpr auto parse(lt::lsd::format_parse_context &context) - { - return context.begin(); - } - - auto format(const lt::lsd::vec4_impl &val, lt::lsd::format_context &context) const - { - return lt::lsd::format_to(context.out(), "{}, {}, {}, {}", val.x, val.y, val.z, val.w); - } -}; diff --git a/modules/lsd/numeric_limits.cppm b/modules/lsd/numeric_limits.cppm deleted file mode 100644 index e31b9cf..0000000 --- a/modules/lsd/numeric_limits.cppm +++ /dev/null @@ -1,8 +0,0 @@ -export module lsd.numeric_limits; -import std; - -export namespace lt::lsd { - -using ::std::numeric_limits; - -} diff --git a/modules/lsd/primitives.cppm b/modules/lsd/primitives.cppm deleted file mode 100644 index 1effd19..0000000 --- a/modules/lsd/primitives.cppm +++ /dev/null @@ -1,34 +0,0 @@ -export module lsd.primitives; -import std; - -/** THIS IS AND SHALL BE THE ONLY NAMESPACE FROM LT -THAT HAS NO SUB-NAMESPACE IDENTIFIER. */ -export namespace lt { - -using byte = ::std::byte; - -using u8 = ::std::uint8_t; -using u16 = ::std::uint16_t; -using u32 = ::std::uint32_t; -using u64 = ::std::uint64_t; - -using i8 = ::std::int8_t; -using i16 = ::std::int16_t; -using i32 = ::std::int32_t; -using i64 = ::std::int64_t; - -using f32 = float; -using f64 = double; - -using size_t = ::std::size_t; - -using stream_size = ::std::streamsize; - -// The fact that bit_cast is a part of the standard library, -// rather than a builtin like static_cast is language quirk. -// -// From the end-user's perspective, it would be convenient -// for the bit_cast to be a language keyword. -using ::std::bit_cast; - -} // namespace lt diff --git a/modules/lsd/set.cppm b/modules/lsd/set.cppm deleted file mode 100644 index 11a1415..0000000 --- a/modules/lsd/set.cppm +++ /dev/null @@ -1,9 +0,0 @@ -export module lsd.set; -import std; - -namespace lt::lsd { - -template -using set = std::set; - -} diff --git a/modules/lsd/span.cppm b/modules/lsd/span.cppm deleted file mode 100644 index ecaa0f5..0000000 --- a/modules/lsd/span.cppm +++ /dev/null @@ -1,6 +0,0 @@ -export module lsd.span; -import std; - -export namespace lt::lsd { -using ::std::span; -} diff --git a/modules/lsd/src_location.cppm b/modules/lsd/src_location.cppm deleted file mode 100644 index 181e53d..0000000 --- a/modules/lsd/src_location.cppm +++ /dev/null @@ -1,8 +0,0 @@ -export module lsd.src_location; -import std; - -export namespace lt::lsd { - -using src_location = std::source_location; - -} diff --git a/modules/lsd/str.cppm b/modules/lsd/str.cppm deleted file mode 100644 index 5bb066d..0000000 --- a/modules/lsd/str.cppm +++ /dev/null @@ -1,20 +0,0 @@ -export module lsd.str; -import std; - -export namespace lt::lsd { - -using c_str = const char *; - -using str = std::string; - -using str_view = std::string_view; - -template -using format_str = std::format_string; - -using std::format_context; -using std::format_parse_context; -using std::format_to; -using std::formatter; - -} // namespace lt::lsd diff --git a/modules/lsd/thread.cppm b/modules/lsd/thread.cppm deleted file mode 100644 index fb75024..0000000 --- a/modules/lsd/thread.cppm +++ /dev/null @@ -1,13 +0,0 @@ -export module lsd.thread; -import std; - -export namespace lt::lsd { - -using thread_id = std::thread::id; - -[[nodiscard]] auto this_thread_id() -> thread_id -{ - return std::this_thread::get_id(); -} - -} // namespace lt::sd diff --git a/modules/lsd/utils.cppm b/modules/lsd/utils.cppm deleted file mode 100644 index bb3802f..0000000 --- a/modules/lsd/utils.cppm +++ /dev/null @@ -1,30 +0,0 @@ -export module lsd.utils; -import std; - -export namespace lt::lsd { - -[[noreturn]] void unreachable() noexcept -{ -#if defined(__clang__) || defined(__GNUC__) - __builtin_unreachable(); -#elif defined(_MSC_VER) - std::terminate(); - __assume(0); -#else - std::terminate(); -#endif -} - -// NOLINTBEGIN -using ::std::bit_cast; -using ::std::declval; -using ::std::format; -using ::std::forward; -using ::std::move; -using ::std::println; -using ::std::system; -using ::std::to_underlying; - -// NOLINTEND - -} // namespace lt::lsd diff --git a/modules/lsd/vec.cppm b/modules/lsd/vec.cppm deleted file mode 100644 index d38803c..0000000 --- a/modules/lsd/vec.cppm +++ /dev/null @@ -1,9 +0,0 @@ -export module lsd.vec; -import std; - -export namespace lt::lsd { - -template -using vec = std::vector; - -} diff --git a/modules/lsd/math/algebra.cppm b/modules/math/algebra.cppm similarity index 80% rename from modules/lsd/math/algebra.cppm rename to modules/math/algebra.cppm index 36bdf2b..5513e8e 100644 --- a/modules/lsd/math/algebra.cppm +++ b/modules/math/algebra.cppm @@ -1,8 +1,8 @@ -export module lsd.math.algebra; -import lsd.math.mat4; -import lsd.math.trig; +export module math.algebra; +import math.mat4; +import std; -export namespace lt::lsd { +export namespace lt::math { /** * let... @@ -37,19 +37,19 @@ export namespace lt::lsd { template constexpr auto perspective(T field_of_view, T aspect_ratio, T z_near, T z_far) { - const T half_fov_tan = tan(field_of_view / static_cast(2u)); + const T half_fov_tan = std::tan(field_of_view / static_cast(2)); auto result = mat4_impl::identity(); - result[0][0] = T { 1u } / (aspect_ratio * half_fov_tan); + result[0][0] = T { 1 } / (aspect_ratio * half_fov_tan); // - result[1][1] = T { 1u } / (half_fov_tan); + result[1][1] = T { 1 } / (half_fov_tan); // // result[2][2] = -(z_far + z_near) / (z_far - z_near); // result[2][2] = z_far / (z_far - z_near); // - result[2][3] = -T { 1u }; + result[2][3] = -T { 1 }; // // result[3][2] = -(T { 2 } * z_far * z_near) / (z_far - z_near); result[3][2] = -(z_far * z_near) / (z_far - z_near); @@ -57,4 +57,4 @@ constexpr auto perspective(T field_of_view, T aspect_ratio, T z_near, T z_far) return result; } -} // namespace lt::lsd +} // namespace lt::math diff --git a/modules/lsd/math/components.cppm b/modules/math/components.cppm similarity index 100% rename from modules/lsd/math/components.cppm rename to modules/math/components.cppm diff --git a/modules/lsd/math/mat4.cppm b/modules/math/mat4.cppm similarity index 65% rename from modules/lsd/math/mat4.cppm rename to modules/math/mat4.cppm index 690cc53..3e0544b 100644 --- a/modules/lsd/math/mat4.cppm +++ b/modules/math/mat4.cppm @@ -1,27 +1,24 @@ -export module lsd.math.mat4; -import lsd.math.vec2; -import lsd.math.vec3; -import lsd.math.vec4; -import lsd.primitives; -import lsd.arr; -import lsd.str; +export module math.mat4; +import math.vec3; +import math.vec4; +import std; -export namespace lt::lsd { +namespace lt::math { -template +export template struct mat4_impl { using Column_T = vec4_impl; - constexpr mat4_impl() = default; - constexpr explicit mat4_impl(T scalar = 0) - : values({ - Column_T { scalar }, - Column_T { scalar }, - Column_T { scalar }, - Column_T { scalar }, - }) + : values( + { + Column_T { scalar }, + Column_T { scalar }, + Column_T { scalar }, + Column_T { scalar }, + } + ) { } @@ -57,12 +54,12 @@ struct mat4_impl }; } - [[nodiscard]] constexpr auto operator[](size_t idx) -> Column_T & + [[nodiscard]] constexpr auto operator[](std::size_t idx) -> Column_T & { return values[idx]; } - [[nodiscard]] constexpr auto operator[](size_t idx) const -> const Column_T & + [[nodiscard]] constexpr auto operator[](std::size_t idx) const -> const Column_T & { return values[idx]; } @@ -77,37 +74,37 @@ struct mat4_impl return vec4_impl {}; } - lsd::arr values; // NOLINT + std::array values; // NOLINT }; -template +export template [[nodiscard]] auto translate(const vec3_impl &value) -> mat4_impl { return mat4_impl {}; } -template -[[nodiscard]] auto rotate(f32 value, const vec3_impl &xyz) -> mat4_impl +export template +[[nodiscard]] auto rotate(float value, const vec3_impl &xyz) -> mat4_impl { return mat4_impl {}; } -template +export template [[nodiscard]] auto scale(const vec3_impl &value) -> mat4_impl { return mat4_impl {}; } -template +export template [[nodiscard]] auto inverse(const mat4_impl &value) -> mat4_impl { return mat4_impl {}; } -using mat4 = mat4_impl; +export using mat4 = mat4_impl; -using imat4 = mat4_impl; +export using imat4 = mat4_impl; -using umat4 = mat4_impl; +export using umat4 = mat4_impl; -} // namespace lt::lsd +} // namespace lt::math diff --git a/modules/lsd/math/trig.cppm b/modules/math/trig.cppm similarity index 76% rename from modules/lsd/math/trig.cppm rename to modules/math/trig.cppm index 2bd6ee2..acea076 100644 --- a/modules/lsd/math/trig.cppm +++ b/modules/math/trig.cppm @@ -1,11 +1,6 @@ -export module lsd.math.trig; -import std; +export module math.trig; -export namespace lt::lsd { - -using ::std::cos; -using ::std::sin; -using ::std::tan; +export namespace lt::math { [[nodiscard]] constexpr auto radians(float degrees) -> float { @@ -28,4 +23,4 @@ using ::std::tan; } -} // namespace lt::lsd +} // namespace lt::math diff --git a/modules/lsd/math/vec2.cppm b/modules/math/vec2.cppm similarity index 56% rename from modules/lsd/math/vec2.cppm rename to modules/math/vec2.cppm index b7742be..f59a45b 100644 --- a/modules/lsd/math/vec2.cppm +++ b/modules/math/vec2.cppm @@ -1,14 +1,15 @@ -export module lsd.math.vec2; -import lsd.primitives; -import lsd.str; +export module math.vec2; -export namespace lt::lsd { +import std; -template +namespace lt::math { + +export template struct vec2_impl { - constexpr vec2_impl() = default; - + constexpr vec2_impl(): x(), y() + { + } constexpr explicit vec2_impl(T scalar): x(scalar), y(scalar) { @@ -44,7 +45,7 @@ struct vec2_impl }; } - [[nodiscard]] auto operator*(f32 scalar) const -> vec2_impl + [[nodiscard]] auto operator*(float scalar) const -> vec2_impl { return { x * scalar, @@ -58,26 +59,24 @@ struct vec2_impl }; -using vec2 = vec2_impl; +export using vec2 = vec2_impl; -using dvec2 = vec2_impl; +export using ivec2 = vec2_impl; -using ivec2 = vec2_impl; +export using uvec2 = vec2_impl; -using uvec2 = vec2_impl; - -} // namespace lt::lsd +} // namespace lt::math export template -struct lt::lsd::formatter> +struct std::formatter> { - constexpr auto parse(lt::lsd::format_parse_context &context) + constexpr auto parse(std::format_parse_context &context) { return context.begin(); } - auto format(const lt::lsd::vec2_impl &val, lt::lsd::format_context &context) const + auto format(const lt::math::vec2_impl &val, std::format_context &context) const { - return lt::lsd::format_to(context.out(), "{}, {}", val.x, val.y); + return std::format_to(context.out(), "{}, {}", val.x, val.y); } }; diff --git a/modules/lsd/math/vec3.cppm b/modules/math/vec3.cppm similarity index 52% rename from modules/lsd/math/vec3.cppm rename to modules/math/vec3.cppm index a597753..9ee5036 100644 --- a/modules/lsd/math/vec3.cppm +++ b/modules/math/vec3.cppm @@ -1,16 +1,16 @@ -export module lsd.math.vec3; +export module math.vec3; -import lsd.math.vec2; -import lsd.primitives; -import lsd.str; +import math.vec2; +import std; -export namespace lt::lsd { +namespace lt::math { -template +export template struct vec3_impl { - constexpr vec3_impl() = default; - + constexpr vec3_impl(): x(), y(), z() + { + } constexpr explicit vec3_impl(T scalar): x(scalar), y(scalar), z(scalar) { @@ -48,11 +48,11 @@ struct vec3_impl }; } - // friend auto operator<<(std::ostream &stream, vec3_impl value) -> std::ostream & - // { - // stream << value.x << ", " << value.y << ", " << value.z; - // return stream; - // } + friend auto operator<<(std::ostream &stream, vec3_impl value) -> std::ostream & + { + stream << value.x << ", " << value.y << ", " << value.z; + return stream; + } T x; // NOLINT @@ -61,26 +61,24 @@ struct vec3_impl T z; // NOLINT }; -using vec3 = vec3_impl; +export using vec3 = vec3_impl; -using dvec3 = vec3_impl; +export using ivec3 = vec3_impl; -using ivec3 = vec3_impl; +export using uvec3 = vec3_impl; -using uvec3 = vec3_impl; - -} // namespace lt::lsd +} // namespace lt::math template -struct lt::lsd::formatter> +struct std::formatter> { - constexpr auto parse(lt::lsd::format_parse_context &context) + constexpr auto parse(std::format_parse_context &context) { return context.begin(); } - auto format(const lt::lsd::vec3_impl &val, lt::lsd::format_context &context) const + auto format(const lt::math::vec3_impl &val, std::format_context &context) const { - return lt::lsd::format_to(context.out(), "{}, {}, {}", val.x, val.y, val.z); + return std::format_to(context.out(), "{}, {}, {}", val.x, val.y, val.z); } }; diff --git a/modules/math/vec4.cppm b/modules/math/vec4.cppm new file mode 100644 index 0000000..d96ab81 --- /dev/null +++ b/modules/math/vec4.cppm @@ -0,0 +1,109 @@ +export module math.vec4; +import math.vec2; +import math.vec3; +import std; + +namespace lt::math { + +export template +struct vec4_impl +{ + constexpr vec4_impl(): x(), y(), z(), w() + { + } + + constexpr explicit vec4_impl(T scalar): x(scalar), y(scalar), z(scalar), w(scalar) + { + } + + constexpr vec4_impl(T x, T y, T z, T w): x(x), y(y), z(z), w(w) + { + } + + [[nodiscard]] auto operator==(const vec4_impl &other) const -> bool + { + return x == other.x && y == other.y && z == other.z && w == other.w; + } + + [[nodiscard]] auto operator!=(const vec4_impl &other) const -> bool + { + return !(*this == other); + } + + [[nodiscard]] constexpr auto operator-(const vec4_impl &other) const -> vec4_impl + { + return { + x - other.x, + y - other.y, + z - other.z, + w - other.w, + }; + } + + [[nodiscard]] constexpr auto operator[](std::size_t idx) -> T & + { + return values[idx]; + } + + [[nodiscard]] constexpr auto operator[](std::size_t idx) const -> const T & + { + return values[idx]; + } + + friend auto operator<<(std::ostream &stream, vec4_impl value) -> std::ostream & + { + stream << value.x << ", " << value.y << ", " << value.z << ", " << value.w; + return stream; + } + + // NOLINTNEXTLINE + union + { + struct + { + T x; + + T y; + + T z; + + T w; + }; + struct + { + T r; + + T g; + + T b; + + T a; + }; + struct + { + std::array values; + }; + }; +}; + +export using vec4 = vec4_impl; + +export using ivec4 = vec4_impl; + +export using uvec4 = vec4_impl; + +} // namespace lt::math + +export template +struct std::formatter> +{ + constexpr auto parse(std::format_parse_context &context) + { + return context.begin(); + } + + auto format(const lt::math::vec4_impl &val, std::format_context &context) const + { + return std::format_to(context.out(), "{}, {}, {}, {}", val.x, val.y, val.z, val.w); + } +}; diff --git a/modules/memory/null_on_move.cppm b/modules/memory/null_on_move.cppm new file mode 100644 index 0000000..4ba612f --- /dev/null +++ b/modules/memory/null_on_move.cppm @@ -0,0 +1,101 @@ +export module memory.null_on_move; + +import std; + +namespace lt::memory { + +/** Holds an `Underlying_T`, assigns it to `null_value` when this object is moved. + * + * @note For avoiding the need to explicitly implement the move constructor for objects that hold + * Vulkan handles. But may serve other purposes, hence why I kept the implementation generic. + */ +export template +class NullOnMove +{ +public: + NullOnMove() = default; + + NullOnMove(Underlying_T value): m_value(value) + { + } + + ~NullOnMove() = default; + + NullOnMove(const NullOnMove &) = delete; + + auto operator=(const NullOnMove &) -> NullOnMove & = delete; + + NullOnMove(NullOnMove &&other) noexcept + { + *this = std::move(other); + } + + auto operator=(NullOnMove &&other) noexcept -> NullOnMove & + { + if (this == std::addressof(other)) + { + return *this; + } + + m_value = other.m_value; + other.m_value = null_value; + + 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; + } + + auto operator&() -> Underlying_T * + { + return &m_value; + } + + operator bool() const + { + return m_value != null_value; + } + + operator Underlying_T() const + { + return m_value; + } + + operator Underlying_T() + { + return m_value; + } + + operator std::uint64_t() const + { + return (std::uint64_t)m_value; + } + + [[nodiscard]] auto get() -> Underlying_T & + { + return m_value; + } + + [[nodiscard]] auto get() const -> const Underlying_T & + { + return m_value; + } + +private: + Underlying_T m_value; +}; + +} // namespace lt::memory diff --git a/modules/lsd/ref.cppm b/modules/memory/reference.cppm similarity index 55% rename from modules/lsd/ref.cppm rename to modules/memory/reference.cppm index 9545500..2b41e70 100644 --- a/modules/lsd/ref.cppm +++ b/modules/memory/reference.cppm @@ -1,32 +1,32 @@ -export module lsd.ref_ptr; +export module memory.reference; import std; -export namespace lt::lsd { +namespace lt::memory { /** 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; +export template +using Ref = std::shared_ptr; /** Allocates memory for an `Underlying_T` and directly constructs it there. * * @return A Ref to the constructed object. */ -template -constexpr auto create_ref(Args &&...args) -> ref +export template +constexpr Ref create_ref(Args &&...args) { return std::make_shared(std::forward(args)...); } /** Converts c-style pointer of type `Underlying_T` to a `Ref`. */ -template -constexpr auto make_ref(Underlying_T *raw_pointer) -> ref +export template +constexpr Ref make_ref(Underlying_T *raw_pointer) { - return ref(raw_pointer); + return Ref(raw_pointer); } -} // namespace lt::lsd +} // namespace lt::memory diff --git a/modules/lsd/scope.cppm b/modules/memory/scope.cppm similarity index 51% rename from modules/lsd/scope.cppm rename to modules/memory/scope.cppm index 3a1e11f..2a22635 100644 --- a/modules/lsd/scope.cppm +++ b/modules/memory/scope.cppm @@ -1,31 +1,32 @@ -export module lsd.scope_ptr; +export module memory.scope; + import std; -export namespace lt::lsd { +namespace lt::memory { -/** Wrapper around std::unique_ptr. +/** @brief 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; +export template +using Scope = std::unique_ptr; /** Allocates memory for an `Underlying_T` and directly constructs it there. * * @return A Scope to the constructed object. */ -template -constexpr auto create_scope(Args &&...args) -> scope +export template +constexpr Scope create_scope(Args &&...args) { return std::make_unique(std::forward(args)...); } /** Converts c-style pointer of type `Underlying_T` to a `Scope`. */ -template -constexpr auto make_scope(Underlying_T *raw_pointer) -> scope +export template +constexpr Scope make_scope(Underlying_T *raw_pointer) { - return scope(raw_pointer); + return Scope(raw_pointer); } -} // namespace lt::lsd +} // namespace lt::memory diff --git a/modules/renderer/vk/api_wrapper.cppm b/modules/renderer/vk/api_wrapper.cppm index b958263..1e3db76 100644 --- a/modules/renderer/vk/api_wrapper.cppm +++ b/modules/renderer/vk/api_wrapper.cppm @@ -50,96 +50,6 @@ struct overloads: Ts... using Ts::operator()...; }; -template -class NullOnMove -{ -public: - NullOnMove() = default; - - NullOnMove(Underlying_T value): m_value(value) - { - } - - ~NullOnMove() = default; - - NullOnMove(const NullOnMove &) = delete; - - auto operator=(const NullOnMove &) -> NullOnMove & = delete; - - NullOnMove(NullOnMove &&other) noexcept - { - *this = std::move(other); - } - - auto operator=(NullOnMove &&other) noexcept -> NullOnMove & - { - if (this == std::addressof(other)) - { - return *this; - } - - m_value = other.m_value; - other.m_value = null_value; - - 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; - } - - auto operator&() -> Underlying_T * - { - return &m_value; - } - - operator bool() const - { - return m_value != null_value; - } - - operator Underlying_T() const - { - return m_value; - } - - operator Underlying_T() - { - return m_value; - } - - operator std::uint64_t() const - { - return (std::uint64_t)m_value; - } - - [[nodiscard]] auto get() -> Underlying_T & - { - return m_value; - } - - [[nodiscard]] auto get() const -> const Underlying_T & - { - return m_value; - } - -private: - Underlying_T m_value; -}; - - export namespace lt::renderer::vk { using Bool32 = VkBool32; @@ -840,7 +750,7 @@ private: return m_instance; } - NullOnMove m_instance {}; + memory::NullOnMove m_instance {}; }; class Surface @@ -932,7 +842,7 @@ private: return m_surface.get(); } - NullOnMove m_surface {}; + memory::NullOnMove m_surface {}; VkInstance m_instance {}; }; @@ -1419,7 +1329,7 @@ private: return m_device.get(); } - NullOnMove m_device {}; + memory::NullOnMove m_device {}; }; class Semaphore @@ -1456,7 +1366,7 @@ private: return &m_semaphore; } - NullOnMove m_device; + memory::NullOnMove m_device; VkSemaphore m_semaphore; }; @@ -1507,7 +1417,7 @@ private: return &m_fence; } - NullOnMove m_device; + memory::NullOnMove m_device; VkFence m_fence; }; @@ -1586,7 +1496,7 @@ private: return m_buffer; } - NullOnMove m_device {}; + memory::NullOnMove m_device {}; VkBuffer m_buffer {}; }; @@ -1841,7 +1751,7 @@ private: return m_shader_module; } - NullOnMove m_device {}; + memory::NullOnMove m_device {}; VkShaderModule m_shader_module {}; }; @@ -1944,7 +1854,7 @@ public: } private: - NullOnMove m_device; + memory::NullOnMove m_device; VkDescriptorSetLayout m_layout; }; @@ -2074,7 +1984,7 @@ public: ~Pipeline(); private: - NullOnMove m_device {}; + memory::NullOnMove m_device {}; VkPipeline m_pipeline {}; }; @@ -2126,7 +2036,7 @@ private: return m_layout; } - NullOnMove m_device {}; + memory::NullOnMove m_device {}; VkPipelineLayout m_layout {}; }; @@ -2522,7 +2432,7 @@ private: return m_queue; } - NullOnMove m_device; + memory::NullOnMove m_device; VkQueue m_queue; }; @@ -2576,7 +2486,7 @@ private: return m_memory; } - NullOnMove m_device {}; + memory::NullOnMove m_device {}; VkDeviceMemory m_memory {}; }; @@ -2630,7 +2540,7 @@ public: auto operator=(const Messenger &) -> Messenger & = delete; private: - NullOnMove m_instance {}; + memory::NullOnMove m_instance {}; VkDebugUtilsMessengerEXT m_messenger {}; }; diff --git a/modules/test/entrypoint.cpp b/modules/test/entrypoint.cpp index 0b122b5..fa3132b 100644 --- a/modules/test/entrypoint.cpp +++ b/modules/test/entrypoint.cpp @@ -2,15 +2,14 @@ import logger; import test.test; import test.registry; -import lsd; +import std; -using namespace ::lt; using namespace ::lt::test; -void parse_option(lsd::str_view argument, Registry::Options &options) +void parse_option(std::string_view argument, Registry::Options &options) { - constexpr auto case_str = lsd::str_view { "--case=" }; - constexpr auto suite_str = lsd::str_view { "--suite=" }; + constexpr auto case_str = std::string_view { "--case=" }; + constexpr auto suite_str = std::string_view { "--suite=" }; if (argument == "--stop-on-fail") { @@ -27,14 +26,14 @@ void parse_option(lsd::str_view argument, Registry::Options &options) if (argument.starts_with(suite_str) && argument.length() > suite_str.size()) { options.suite_regex = argument.substr(suite_str.length()); - lsd::println("SUITE REGEX: {}", options.suite_regex); + std::println("SUITE REGEX: {}", options.suite_regex); return; } if (argument.starts_with(case_str) && argument.length() > case_str.size()) { options.case_regex = argument.substr(case_str.length()); - lsd::println("CASE REGEX: {}", options.case_regex); + std::println("CASE REGEX: {}", options.case_regex); return; } @@ -43,19 +42,19 @@ void parse_option(lsd::str_view argument, Registry::Options &options) void print_help() { - lsd::println("Options: "); - lsd::println("--stop-on-fail --> Stops executing the remaining tests on first failure"); - lsd::println("--suite --> Regex for running specific suite(s)"); - lsd::println("--case --> Regex for running specific test(s)"); - lsd::println("--mode=stats --> Executes tests with an alternative policy"); - lsd::println("\t---> stats: Print statistics about the tests without running any"); - lsd::println("--help | -h --> ~You just used it! :D"); + std::println("Options: "); + std::println("--stop-on-fail --> Stops executing the remaining tests on first failure"); + std::println("--suite --> Regex for running specific suite(s)"); + std::println("--case --> Regex for running specific test(s)"); + std::println("--mode=stats --> Executes tests with an alternative policy"); + std::println("\t---> stats: Print statistics about the tests without running any"); + std::println("--help | -h --> ~You just used it! :D"); } -auto main(i32 argc, char **argv) -> i32 +auto main(std::int32_t argc, char **argv) -> std::int32_t try { - auto raw_arguments = lsd::span(argv, argc); + auto raw_arguments = std::span(argv, argc); auto options = Registry::Options {}; for (auto idx = 0; auto &raw_argument : raw_arguments) @@ -66,7 +65,7 @@ try continue; } - auto argument = lsd::str_view(raw_argument); + auto argument = std::string_view(raw_argument); if (argument == "-h" || argument == "--help") { @@ -84,9 +83,9 @@ try } } - return static_cast(Registry::run_all(options)); + return static_cast(Registry::run_all(options)); } -catch (const lsd::exception &exp) +catch (const std::exception &exp) { lt::log::critical("Terminated due to uncaught exception:"); lt::log::critical("\twhat: {}", exp.what()); diff --git a/modules/test/test.cppm b/modules/test/test.cppm index 47f9998..6d0c96b 100644 --- a/modules/test/test.cppm +++ b/modules/test/test.cppm @@ -1,9 +1,8 @@ export module test.test; +import std; import test.expects; import test.registry; -import std; -import lsd; /////////////////////////////////////// // ----------* INTERFACE *--------- // @@ -13,16 +12,16 @@ namespace lt::test { class TestCase { public: - TestCase(lsd::str_view name); + TestCase(std::string_view name); // NOLINTNEXTLINE(misc-unconventional-assign-operator) - auto operator=(lsd::invocable auto test) const -> void; + auto operator=(std::invocable auto test) const -> void; private: - void run_normal(lsd::invocable auto test) const; + void run_normal(std::invocable auto test) const; private: - lsd::str_view m_name; + std::string_view m_name; }; struct TestSuite @@ -39,25 +38,25 @@ struct TestFuzzHarness export using Case = const TestCase; export using Suite = const TestSuite; export using FuzzHarness = const TestFuzzHarness; -export auto operator""_suite(const char *name, size_t size) -> TestSuite; +export auto operator""_suite(const char *name, std::size_t size) -> TestSuite; /////////////////////////////////////// // * IMPLEMENTATION -- TEMPLATES * // ///////////////////////////////////// // NOLINTNEXTLINE(misc-unconventional-assign-operator) -auto TestCase::operator=(lsd::invocable auto test) const -> void +auto TestCase::operator=(std::invocable auto test) const -> void { using enum Registry::ExecutionPolicy; switch (Registry::get_options().execution_policy) { - case normal: run_normal(lsd::move(test)); break; + case normal: run_normal(std::move(test)); break; case stats: Registry::increment_total_case_count(); break; } } -void TestCase::run_normal(lsd::invocable auto test) const +void TestCase::run_normal(std::invocable auto test) const { Registry::increment_total_case_count(); @@ -69,16 +68,16 @@ void TestCase::run_normal(lsd::invocable auto test) const } Registry::increment_matched_case_count(); - lsd::println("[Running-----------] --> "); - lsd::println("{}", m_name); + std::println("[Running-----------] --> "); + std::println("{}", m_name); try { test(); } catch (const std::exception &exp) { - lsd::println("{}", exp.what()); - lsd::println("[-----------FAIL !!]"); + std::println("{}", exp.what()); + std::println("[-----------FAIL !!]"); Registry::increment_failed_case_count(); if (Registry::should_return_on_failure()) @@ -90,7 +89,7 @@ void TestCase::run_normal(lsd::invocable auto test) const } Registry::increment_passed_case_count(); - lsd::println("[--------SUCCESS :D]"); + std::println("[--------SUCCESS :D]"); } TestSuite::TestSuite(auto body) @@ -107,7 +106,7 @@ constexpr TestFuzzHarness::TestFuzzHarness(auto body) #endif }; -auto operator""_suite(const char *name, size_t size) -> TestSuite +auto operator""_suite(const char *name, std::size_t size) -> TestSuite { Registry::set_last_suite_name(name); return {}; @@ -121,7 +120,7 @@ auto operator""_suite(const char *name, size_t size) -> TestSuite module :private; namespace lt::test { -TestCase::TestCase(lsd::str_view name): m_name(name) +TestCase::TestCase(std::string_view name): m_name(name) { } diff --git a/modules/time/timer.cppm b/modules/time/timer.cppm index 42dc48b..18d8dd2 100644 --- a/modules/time/timer.cppm +++ b/modules/time/timer.cppm @@ -1,5 +1,5 @@ export module time; -import lsd; +import std; namespace lt::time { @@ -7,11 +7,11 @@ namespace lt::time { export class Timer { public: - using Clock = lsd::chrono::steady_clock; + using Clock = std::chrono::steady_clock; - using Duration = lsd::chrono::duration; + using Duration = std::chrono::duration; - using Timepoint = lsd::chrono::time_point; + using Timepoint = std::chrono::time_point; Timer(Timepoint start = Clock::now()); @@ -39,7 +39,7 @@ void Timer::reset(Timepoint start) [[nodiscard]] auto Timer::elapsed_time() const -> Duration { - return { lsd::chrono::steady_clock::now() - m_start }; + return { std::chrono::steady_clock::now() - m_start }; } } // namespace lt::time diff --git a/tools/cmake/functions.cmake b/tools/cmake/functions.cmake index 3215559..64e4a8c 100644 --- a/tools/cmake/functions.cmake +++ b/tools/cmake/functions.cmake @@ -19,22 +19,14 @@ function(add_module) set(module_directory "${ARGS_ROOT_DIR}") endif() - # In this case, the module is an executable, so we prepend "lib" to the - # target name. And set the "executable_target" name to ARGS_NAME. - # - # The rationale here is to easily be able to write tests for an executable - # modules's interfaces... by splitting it into two targets: - # lib"executable_name" for the interface and "executable_name" for the "int - # main()" defining file (the entrypoint). - - # The lib"executable_name" should not be disruptive since an executable - # module's library will not be dependent upon (except by the tests within - # the same module) + # In this case, the module is an executable, so we prepend "lib" to the target name. + # And set the "executable_target" name to ARGS_NAME. + # The rationale here is to easily be able to write tests for an executable modules's interfaces... + # by splitting it into two targets: lib"executable_name" for the interface and "executable_name" for the "int main()" defining file (the entrypoint). + # the lib"executable_name" should not be disruptive since an executable module's library will not be dependent upon (except by the tests within the same module) if(ARGS_ENTRYPOINT) set(target_library_name "lib_${ARGS_NAME}") - add_executable( - ${target_executable_name} ${module_directory}/${ARGS_ENTRYPOINT} - ) + add_executable(${target_executable_name} ${module_directory}/${ARGS_ENTRYPOINT}) endif() add_library(${target_library_name}) @@ -61,15 +53,13 @@ function(add_module) list(APPEND files "${module_directory}/${file}") endforeach() target_sources( - ${target_library_name} PUBLIC FILE_SET public_cxx_modules TYPE - CXX_MODULES FILES ${files} + ${target_library_name} PUBLIC FILE_SET public_cxx_modules TYPE CXX_MODULES + FILES ${files} ) endif() target_link_libraries(${target_library_name} PUBLIC ${ARGS_DEPENDENCIES}) - target_link_libraries( - ${target_library_name} PRIVATE ${ARGS_PRIVATE_DEPENDENCIES} - ) + target_link_libraries(${target_library_name} PRIVATE ${ARGS_PRIVATE_DEPENDENCIES}) if(ARGS_TESTS) message("ADDING TESTS!!!") @@ -88,9 +78,7 @@ function(add_module) endif() if(ARGS_ENTRYPOINT) - target_link_libraries( - ${target_executable_name} PRIVATE ${target_library_name} - ) + target_link_libraries(${target_executable_name} PRIVATE ${target_library_name}) endif() endfunction()