diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 502fc10..70399c7 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -46,6 +46,8 @@ add_module( vec3.cppm vec4.cppm components.cppm + DEPENDENCIES + lt_debug ) add_module( diff --git a/modules/asset_baker/bakers.cppm b/modules/asset_baker/bakers.cppm index 522ce59..e6912b5 100644 --- a/modules/asset_baker/bakers.cppm +++ b/modules/asset_baker/bakers.cppm @@ -26,13 +26,15 @@ export void bake_shader( // Don't bother linking to shaderc, just invoke the command with a system call. // NOLINTNEXTLINE(concurrency-mt-unsafe) - std::system(std::format( - "glslc --target-env=vulkan1.4 -std=450core -fshader-stage={} {} -o {}", - type == vertex ? "vert" : "frag", - glsl_path, - spv_path - ) - .c_str()); + std::system( + std::format( + "glslc --target-env=vulkan1.4 -std=450core -fshader-stage={} {} -o {}", + type == vertex ? "vert" : "frag", + glsl_path, + spv_path + ) + .c_str() + ); auto stream = std::ifstream(spv_path, std::ios::binary); lt::debug::ensure( @@ -48,7 +50,6 @@ export void bake_shader( auto bytes = std::vector(size); stream.seekg(0, std::ios::beg); stream.read((char *)bytes.data(), size); // NOLINT - lt::log::debug("BYTES: {}", bytes.size()); stream.close(); std::filesystem::remove(spv_path); diff --git a/modules/assets/shader.cppm b/modules/assets/shader.cppm index 48c4a0b..877f244 100644 --- a/modules/assets/shader.cppm +++ b/modules/assets/shader.cppm @@ -1,5 +1,6 @@ export module assets.shader; import assets.metadata; +import logger; import debug.assertions; import std; @@ -109,6 +110,7 @@ ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) read(m_asset_metadata.type); read(m_asset_metadata.version); read(m_metadata.type); + read(m_code_blob_metadata.tag); read(m_code_blob_metadata.offset); read(m_code_blob_metadata.compression_type); diff --git a/modules/assets/shader.test.cpp b/modules/assets/shader.test.cpp index 074572b..96bc856 100644 --- a/modules/assets/shader.test.cpp +++ b/modules/assets/shader.test.cpp @@ -1,5 +1,6 @@ import assets.metadata; import assets.shader; +import logger; import test.test; import test.expects; import std; @@ -38,7 +39,7 @@ Suite packing = "shader_pack"_suite = [] { Case { "" } = [] { const auto out_path = tmp_path / "shader_packing"; auto dummy_blob = lt::assets::Blob {}; - for (auto idx : std::views::iota(0, 255)) + for (auto idx : std::views::iota(0u, 255u)) { dummy_blob.emplace_back(static_cast(idx)); } @@ -72,7 +73,7 @@ Suite packing = "shader_pack"_suite = [] { }; expect_true(stream.is_open()); - stream.seekg(0, std::ios::end); + stream.seekg(0u, std::ios::end); const auto file_size = static_cast(stream.tellg()); expect_eq(file_size, expected_size); stream.close(); @@ -87,9 +88,9 @@ Suite packing = "shader_pack"_suite = [] { expect_eq(metadata.type, ShaderAsset::Type::vertex); auto blob = shader_asset.unpack(ShaderAsset::BlobTag::code); - expect_eq(blob.size(), 255); + expect_eq(blob.size(), 255u); - for (auto idx : std::views::iota(0, 255)) + for (auto idx : std::views::iota(0u, 255u)) { expect_eq(blob[idx], static_cast(idx)); } diff --git a/modules/ecs/registry.test.cpp b/modules/ecs/registry.test.cpp index 631fed9..f71f02c 100644 --- a/modules/ecs/registry.test.cpp +++ b/modules/ecs/registry.test.cpp @@ -68,6 +68,7 @@ Suite raii = "raii"_suite = [] { Case { "many won't freeze/throw" } = [] { for (auto idx : std::views::iota(0, 100'000)) { + std::ignore = idx; std::ignore = Registry {}; } }; @@ -158,6 +159,7 @@ Suite callbacks = "callbacks"_suite = [] { Case { "on_construct/on_destruct won't get called on unrelated component" } = [] { auto registry = Registry {}; + registry.connect_on_construct([&](Registry &, EntityId) { expect_unreachable(); }); @@ -167,6 +169,7 @@ Suite callbacks = "callbacks"_suite = [] { for (auto idx : std::views::iota(0, 100'000)) { + std::ignore = idx; registry.add(registry.create_entity(), {}); } }; @@ -188,6 +191,8 @@ Suite callbacks = "callbacks"_suite = [] { expect_true(on_destruct_called.empty()); for (auto idx : std::views::iota(0, 100'000)) { + std::ignore = idx; + auto entity = all_entities.emplace_back(registry.create_entity()); registry.add(entity, {}); } diff --git a/modules/ecs/sparse_set.cppm b/modules/ecs/sparse_set.cppm index 340a760..6e69b2f 100644 --- a/modules/ecs/sparse_set.cppm +++ b/modules/ecs/sparse_set.cppm @@ -59,16 +59,11 @@ public: ); new_capacity = std::min(new_capacity, max_capacity); - // log::debug("Increasing sparse vector size:", m_dead_count); - // log::debug("\tdead_count: {}", m_dead_count); - // log::debug("\talive_count: {}", m_alive_count); - // log::debug("\tsparse.size: {} -> {}", m_sparse.size(), new_capacity); - m_sparse.resize(new_capacity, null_identifier); } ++m_alive_count; - m_sparse[identifier] = m_dense.size(); + m_sparse[identifier] = static_cast(m_dense.size()); return m_dense.emplace_back(identifier, std::move(value)); } diff --git a/modules/ecs/sparse_set.test.cpp b/modules/ecs/sparse_set.test.cpp index baf9fec..e1b2659 100644 --- a/modules/ecs/sparse_set.test.cpp +++ b/modules/ecs/sparse_set.test.cpp @@ -12,7 +12,8 @@ using ::lt::test::expect_true; using ::lt::test::Suite; using ::lt::test::operator""_suite; -using Set = lt::ecs::SparseSet; +using Value_T = int; +using Set = lt::ecs::SparseSet; constexpr auto capacity = 100; Suite raii = "raii"_suite = [] { @@ -97,7 +98,7 @@ Suite element_raii = "element_raii"_suite = [] { for (auto &[identifier, value] : set) { - expect_eq(identifier, value); + expect_eq(static_cast(identifier), value); expect_ne(value, 0); expect_ne(value, 32); expect_ne(value, 69); @@ -129,7 +130,7 @@ Suite getters = "getters"_suite = [] { expect_eq(set.get_capacity(), 10'000); - set.insert(set.get_size(), {}); + set.insert(static_cast(set.get_size()), {}); expect_ne(set.get_capacity(), 10'000); }; diff --git a/modules/input/system.cppm b/modules/input/system.cppm index 66f8f2c..8e2cbda 100644 --- a/modules/input/system.cppm +++ b/modules/input/system.cppm @@ -158,8 +158,10 @@ void System::on_key_press(const lt::surface::KeyPressedEvent &event) { if (std::to_underlying(event.get_key()) > m_keys.size()) { - log::debug("Key code larger than key container size, implement platform-dependant " - "key-code-mapping!"); + log::warn( + "Key code larger than key container size, implement platform-dependant " + "key-code-mapping!" + ); return; } @@ -171,8 +173,10 @@ void System::on_key_release(const lt::surface::KeyReleasedEvent &event) { if (std::to_underlying(event.get_key()) > m_keys.size()) { - log::debug("Key code larger than key container size, implement platform-dependant " - "key-code-mapping!"); + log::warn( + "Key code larger than key container size, implement platform-dependant " + "key-code-mapping!" + ); return; } diff --git a/modules/input/system.test.cpp b/modules/input/system.test.cpp index 3b5b53e..f6d28ad 100644 --- a/modules/input/system.test.cpp +++ b/modules/input/system.test.cpp @@ -79,6 +79,7 @@ Suite raii = "raii"_suite = "raii"_suite = [] { auto fixture = Fixture {}; for (auto idx : std::views::iota(0, 10'000)) { + std::ignore = idx; ignore = System { fixture.registry() }; } }; @@ -115,7 +116,7 @@ Suite registry_events = "registry_events"_suite = [] { auto registry = fixture.registry(); auto system = System { registry }; - const auto &entity = fixture.add_input_component(); + fixture.add_input_component(); expect_eq(registry->view().get_size(), 1); }; @@ -162,7 +163,7 @@ Suite tick = "tick"_suite = [] { auto action_key = input.add_action( { .name { "test" }, - .trigger = { .mapped_keycode = Key::A }, + .trigger = { .mapped_keycode = Key::a }, } ); @@ -170,7 +171,7 @@ Suite tick = "tick"_suite = [] { system.tick(tick_info()); expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive); - surface.push_event(surface::KeyPressedEvent(Key::A)); + surface.push_event(surface::KeyPressedEvent(Key::a)); system.tick(tick_info()); expect_eq(input.get_action(action_key).state, input::InputAction::State::triggered); @@ -182,28 +183,8 @@ Suite tick = "tick"_suite = [] { system.tick(tick_info()); expect_eq(input.get_action(action_key).state, input::InputAction::State::active); - surface.push_event(surface::KeyReleasedEvent(Key::A)); + surface.push_event(surface::KeyReleasedEvent(Key::a)); system.tick(tick_info()); expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive); }; - - Case { "Tick triggers" } = [] { - auto fixture = Fixture {}; - auto registry = fixture.registry(); - auto system = System { fixture.registry() }; - - auto surface_entity = fixture.add_surface_component(); - auto &surface = registry->get(surface_entity); - - auto input_entity = fixture.add_input_component(); - auto &input = registry->get(input_entity); - - - auto action_key = input.add_action( - { - .name { "test" }, - .trigger = { .mapped_keycode = Key::A }, - } - ); - }; }; diff --git a/modules/input_codes/input_codes.cppm b/modules/input_codes/input_codes.cppm index 495306e..6e1dc7e 100644 --- a/modules/input_codes/input_codes.cppm +++ b/modules/input_codes/input_codes.cppm @@ -4,17 +4,18 @@ import std; export enum class Key: std::uint16_t { none = 0, - left_mouse_button, - right_mouse_button, - middle_mouse_button, + left_button, + l_button = left_button, - left_mouse = left_mouse_button, - right_mouse = right_mouse_button, - middle_mouse = middle_mouse_button, + right_button, + r_button = right_button, - l_mouse = left_mouse_button, - r_mouse = right_mouse_button, - m_mouse = middle_mouse_button, + middle_button, + m_button = middle_button, + + // the buttons on the sidse of some mouses + x_button_1, + x_button_2, backspace, tab, @@ -87,7 +88,6 @@ export enum class Key: std::uint16_t { digit_8, digit_9, - /* letters */ a, b, c, @@ -140,7 +140,6 @@ export enum class Key: std::uint16_t { kp_enter, kp_equal, - /* function */ f1, f2, f3, @@ -164,12 +163,13 @@ export [[nodiscard]] constexpr auto to_string(Key key) -> std::string { case none: return ""; - /* mouse */ - case left_mouse_button: return "left_mouse_button"; - case right_mouse_button: return "right_mouse_button"; - case middle_mouse_button: return "middle_mouse_button"; + case left_button: return "left_button"; + case right_button: return "right_button"; + case middle_button: return "middle_button"; + + case x_button_1: return "x_button_1"; + case x_button_2: return "x_button_2"; - /* editing / control */ case backspace: return "backspace"; case tab: return "tab"; case capslock: return "capslock"; @@ -177,14 +177,12 @@ export [[nodiscard]] constexpr auto to_string(Key key) -> std::string case space: return "space"; case delete_: return "delete"; - /* modifiers */ case shift: return "shift"; case control: return "control"; case right_control: return "right_control"; case alt: return "alt"; case right_alt: return "right_alt"; - /* navigation */ case pageup: return "pageup"; case pagedown: return "pagedown"; case home: return "home"; @@ -195,7 +193,6 @@ export [[nodiscard]] constexpr auto to_string(Key key) -> std::string case right_arrow: return "right_arrow"; case down_arrow: return "down_arrow"; - /* system */ case cancel: return "cancel"; case pause: return "pause"; case select: return "select"; @@ -205,7 +202,6 @@ export [[nodiscard]] constexpr auto to_string(Key key) -> std::string case help: return "help"; case sleep: return "sleep"; - /* digits */ case digit_0: return "0"; case digit_1: return "1"; case digit_2: return "2"; @@ -217,7 +213,6 @@ export [[nodiscard]] constexpr auto to_string(Key key) -> std::string case digit_8: return "8"; case digit_9: return "9"; - /* letters */ case a: return "a"; case b: return "b"; case c: return "c"; @@ -245,11 +240,9 @@ export [[nodiscard]] constexpr auto to_string(Key key) -> std::string case y: return "y"; case z: return "z"; - /* super / meta */ case super: return "super"; case right_super: return "right_super"; - /* keypad */ case kp_0: return "kp_0"; case kp_1: return "kp_1"; case kp_2: return "kp_2"; @@ -268,7 +261,6 @@ export [[nodiscard]] constexpr auto to_string(Key key) -> std::string case kp_enter: return "kp_enter"; case kp_equal: return "kp_equal"; - /* function keys */ case f1: return "f1"; case f2: return "f2"; case f3: return "f3"; diff --git a/modules/logger/logger.cppm b/modules/logger/logger.cppm index 4e39d8c..7e6aaa5 100644 --- a/modules/logger/logger.cppm +++ b/modules/logger/logger.cppm @@ -48,7 +48,7 @@ struct [[maybe_unused]] print Args &&...arguments ) noexcept { - constexpr auto to_string = [](Level level, auto location) { + constexpr auto to_string = [](Level level) { // clang-format off switch (level) { @@ -70,7 +70,7 @@ struct [[maybe_unused]] print std::println( "{} {} ==> {}", - to_string(level, location), + to_string(level), std::format("{}:{}", path.filename().string(), location.line()), std::format(format, std::forward(arguments)...) ); diff --git a/modules/math/mat4.cppm b/modules/math/mat4.cppm index 3e0544b..9c67dea 100644 --- a/modules/math/mat4.cppm +++ b/modules/math/mat4.cppm @@ -74,7 +74,7 @@ struct mat4_impl return vec4_impl {}; } - std::array values; // NOLINT + std::array values; }; export template diff --git a/modules/math/vec4.cppm b/modules/math/vec4.cppm index d96ab81..d9f4150 100644 --- a/modules/math/vec4.cppm +++ b/modules/math/vec4.cppm @@ -1,5 +1,6 @@ export module math.vec4; import math.vec2; +import debug.assertions; import math.vec3; import std; @@ -8,6 +9,8 @@ namespace lt::math { export template struct vec4_impl { + static constexpr auto num_elements = 4u; + constexpr vec4_impl(): x(), y(), z(), w() { } @@ -40,14 +43,18 @@ struct vec4_impl }; } - [[nodiscard]] constexpr auto operator[](std::size_t idx) -> T & + [[nodiscard]] constexpr auto operator[](std::uint8_t idx) -> T & { - return values[idx]; + // TODO(Light): Use contract + debug::ensure(idx <= num_elements, "vec4 out of bound: {}", idx); + return ((T *)this)[idx]; } - [[nodiscard]] constexpr auto operator[](std::size_t idx) const -> const T & + [[nodiscard]] constexpr auto operator[](std::uint8_t idx) const -> const T & { - return values[idx]; + // TODO(Light): Use contract + debug::ensure(idx < num_elements, "vec4 out of bound: {}", idx); + return ((T *)this)[idx]; } friend auto operator<<(std::ostream &stream, vec4_impl value) -> std::ostream & @@ -56,34 +63,13 @@ struct vec4_impl return stream; } - // NOLINTNEXTLINE - union - { - struct - { - T x; + T x; - T y; + T y; - T z; + T z; - T w; - }; - struct - { - T r; - - T g; - - T b; - - T a; - }; - struct - { - std::array values; - }; - }; + T w; }; export using vec4 = vec4_impl; diff --git a/modules/mirror/system.cppm b/modules/mirror/system.cppm index 71b5321..2773d7f 100644 --- a/modules/mirror/system.cppm +++ b/modules/mirror/system.cppm @@ -37,7 +37,7 @@ void renderer_callback( std::ignore = message_type; std::ignore = user_data; - log::debug("RENDERER CALLBACK: {}", std::string { data.message }); + log::trace("< Renderer > ==> {}", std::string { data.message }); } class MirrorSystem: public lt::app::ISystem diff --git a/modules/renderer/_tests/utils.cppm b/modules/renderer/_tests/utils.cppm index e4a8c3a..d0e07f3 100644 --- a/modules/renderer/_tests/utils.cppm +++ b/modules/renderer/_tests/utils.cppm @@ -35,10 +35,10 @@ constexpr auto frames_in_flight = std::uint32_t { 3u }; void noop_messenger_callback( - lt::renderer::IDebugger::MessageSeverity severity, - lt::renderer::IDebugger::MessageType type, - const lt::renderer::IDebugger::MessageData &data, - std::any &user_data + lt::renderer::IDebugger::MessageSeverity, + lt::renderer::IDebugger::MessageType, + const lt::renderer::IDebugger::MessageData &, + std::any & ) { } diff --git a/modules/renderer/vk/api_wrapper.cppm b/modules/renderer/vk/api_wrapper.cppm index 896e1f2..e78b710 100644 --- a/modules/renderer/vk/api_wrapper.cppm +++ b/modules/renderer/vk/api_wrapper.cppm @@ -2944,11 +2944,11 @@ void load_library() "Failed to load vulkan function: vkGetInstanceProcAddr" ); #elif defined(LIGHT_PLATFORM_WINDOWS) - auto library = LoadLibraryA("vulkan-1.dll"); + library = LoadLibraryA("vulkan-1.dll"); lt::debug::ensure(library, "Failed to LoadLibraryA the vulkan-1.dll"); api::get_instance_proc_address = std::bit_cast( - GetProcAddress(library, "vkGetInstanceProcAddr") + GetProcAddress(std::bit_cast(library), "vkGetInstanceProcAddr") ); lt::debug::ensure( api::get_instance_proc_address, @@ -3883,7 +3883,7 @@ void Device::reset_fence(VkFence fence) const void Device::reset_fences(std::span fences) const { - vkc(api::reset_fences(m_device, fences.size(), fences.data())); + vkc(api::reset_fences(m_device, static_cast(fences.size()), fences.data())); } auto Device::acquire_image(VkSwapchainKHR swapchain, VkSemaphore semaphore, uint64_t timeout) @@ -3917,7 +3917,7 @@ void Device::wait_for_fences(std::span fences) const { vkc(api::wait_for_fences( m_device, - fences.size(), + static_cast(fences.size()), fences.data(), true, std::numeric_limits::max() @@ -4274,6 +4274,9 @@ void Queue::present(PresentInfo info) const Image::Image(Device &device, CreateInfo info): m_device(device.get_vk_handle()), m_image() { + // WIP(Light): use image create info's info + + std::ignore = info; auto vk_info = VkImageCreateInfo {}; vkc(api::create_image(m_device, &vk_info, nullptr, &m_image)); } @@ -4337,6 +4340,9 @@ CommandBuffer::CommandBuffer(VkCommandBuffer buffer): m_buffer(buffer) void CommandBuffer::begin(BeginInfo info /* = {} */) { + // WIP(Light): Use info + std::ignore = info; + auto vk_info = VkCommandBufferBeginInfo { .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, .pNext = {}, @@ -4937,11 +4943,12 @@ Pipeline::Pipeline(Device &device, PipelineLayout &layout, CreateInfo info) auto color_attachment_formats = std::vector {}; + // WIP(Light): use color attachments for (auto &color_attachment : info.attachment_state.color_attachments) { + std::ignore = color_attachment; } - auto rendering_info = VkPipelineRenderingCreateInfoKHR { .sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO, .colorAttachmentCount = static_cast(color_attachment_formats.size()), diff --git a/modules/renderer/vk/renderer.cppm b/modules/renderer/vk/renderer.cppm index 3e40d40..b1c276d 100644 --- a/modules/renderer/vk/renderer.cppm +++ b/modules/renderer/vk/renderer.cppm @@ -35,9 +35,10 @@ public: { m_device->vk().wait_idle(); } - catch (std::exception &exp) + catch (const std::exception &exp) { - log::error("Failed to wait idle on device in renderer destructor"); + log::error("Failed to wait idle on device in renderer destructor:"); + log::error("\twhat: {}", exp.what()); } } @@ -193,6 +194,9 @@ Renderer::Renderer( frame_fence.reset(); map_buffers(frame_idx); + + // WIP(Light): submit the scene! + std::ignore = submit_scene; // submit_scene(); record_cmd(cmd, image_idx); diff --git a/modules/renderer/vk/swapchain.cppm b/modules/renderer/vk/swapchain.cppm index 1200907..bf1bb7b 100644 --- a/modules/renderer/vk/swapchain.cppm +++ b/modules/renderer/vk/swapchain.cppm @@ -81,8 +81,6 @@ Swapchain::Swapchain(ISurface *surface, IGpu *gpu, IDevice *device) , m_gpu(static_cast(gpu)) , m_device(static_cast(device)) { - static auto idx = 0u; - auto capabilities = m_gpu->vk().get_surface_capabilities(m_surface->vk()); const auto formats = m_gpu->vk().get_surface_formats(m_surface->vk()); @@ -104,6 +102,7 @@ Swapchain::Swapchain(ISurface *surface, IGpu *gpu, IDevice *device) capabilities.current_extent.y = 600u; } + static auto swapchain_idx = 0u; m_swapchain = vk::Swapchain( m_device->vk(), m_surface->vk(), @@ -116,7 +115,7 @@ Swapchain::Swapchain(ISurface *surface, IGpu *gpu, IDevice *device) .queue_family_indices = m_device->get_family_indices(), .present_mode = vk::Swapchain::PresentMode::mailbox, .pre_transform = capabilities.current_transform, - .name = std::format("swapchain {}", idx++), + .name = std::format("swapchain {}", swapchain_idx++), } ); m_resolution = capabilities.current_extent; diff --git a/modules/sandbox/sandbox.cpp b/modules/sandbox/sandbox.cpp index 3cd9027..3171fb6 100644 --- a/modules/sandbox/sandbox.cpp +++ b/modules/sandbox/sandbox.cpp @@ -37,7 +37,7 @@ int main() auto timer = lt::time::Timer {}; lt::log::trace("Ticking for 3 seconds..."); - while (timer.elapsed_time() < std::chrono::seconds { 3 }) + while (timer.elapsed_time() < std::chrono::seconds { 30 }) { system.tick({}); } diff --git a/modules/surface/system.cppm b/modules/surface/system.cppm index 7fb8ff8..e35bd3b 100644 --- a/modules/surface/system.cppm +++ b/modules/surface/system.cppm @@ -527,6 +527,125 @@ void System::tick(app::TickInfo tick) #ifdef LIGHT_PLATFORM_WINDOWS +constexpr auto translate_key(auto code) -> Key +{ + using enum Key; + + switch (code) + { + case VK_LBUTTON: return left_button; + case VK_RBUTTON: return right_button; + case VK_MBUTTON: return middle_button; + + case VK_BACK: return backspace; + case VK_TAB: return tab; + case VK_CAPITAL: return capslock; + case VK_RETURN: return enter; + case VK_SPACE: return space; + case VK_DELETE: return delete_; + + case VK_SHIFT: return shift; + case VK_RSHIFT: return right_shift; + + case VK_CONTROL: return control; + case VK_RCONTROL: return right_control; + + case VK_MENU: return alt; + case VK_RMENU: return right_alt; + + case VK_PRIOR: return pageup; + case VK_NEXT: return pagedown; + case VK_END: return end; + case VK_HOME: return home; + + case VK_LEFT: return left_arrow; + case VK_RIGHT: return right_arrow; + case VK_DOWN: return down_arrow; + case VK_UP: return up_arrow; + + case VK_CANCEL: return cancel; + case VK_PAUSE: return pause; + case VK_SELECT: return select; + case VK_PRINT: return print; + case VK_SNAPSHOT: return snapshot; + case VK_INSERT: return insert; + case VK_HELP: return help; + case VK_SLEEP: return sleep; + + case '0': return digit_0; + case '1': return digit_1; + case '2': return digit_2; + case '3': return digit_3; + case '4': return digit_4; + case '5': return digit_5; + case '6': return digit_6; + case '7': return digit_7; + case '8': return digit_8; + case '9': return digit_9; + + case 'A': return a; + case 'B': return b; + case 'C': return c; + case 'D': return d; + case 'E': return e; + case 'F': return f; + case 'G': return g; + case 'H': return h; + case 'I': return i; + case 'J': return j; + case 'K': return k; + case 'L': return l; + case 'M': return m; + case 'N': return n; + case 'O': return o; + case 'P': return p; + case 'Q': return q; + case 'R': return r; + case 'S': return s; + case 'T': return t; + case 'U': return u; + case 'V': return v; + case 'W': return w; + case 'X': return x; + case 'Y': return y; + case 'Z': return z; + + case VK_LWIN: return super; + case VK_RWIN: return right_super; + + case VK_NUMPAD0: return kp_0; + case VK_NUMPAD1: return kp_1; + case VK_NUMPAD2: return kp_2; + case VK_NUMPAD3: return kp_3; + case VK_NUMPAD4: return kp_4; + case VK_NUMPAD5: return kp_5; + case VK_NUMPAD6: return kp_6; + case VK_NUMPAD7: return kp_7; + case VK_NUMPAD8: return kp_8; + case VK_NUMPAD9: return kp_9; + + case VK_MULTIPLY: return kp_multiply; + case VK_ADD: return kp_add; + case VK_SUBTRACT: return kp_subtract; + case VK_DECIMAL: return kp_decimal; + + case VK_F1: return f1; + case VK_F2: return f2; + case VK_F3: return f3; + case VK_F4: return f4; + case VK_F5: return f5; + case VK_F6: return f6; + case VK_F7: return f7; + case VK_F8: return f8; + case VK_F9: return f9; + case VK_F10: return f10; + case VK_F11: return f11; + case VK_F12: return f12; + + default: return unknown; + } +}; + template struct overloads: Ts... { @@ -535,7 +654,7 @@ struct overloads: Ts... void ensure_component_sanity(const SurfaceComponent &component); -auto CALLBACK native_window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -> LRESULT; +auto CALLBACK window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -> LRESULT; System::System(memory::Ref registry): m_registry(std::move(registry)) { @@ -553,7 +672,7 @@ System::System(memory::Ref registry): m_registry(std::move(regist ); auto window_class = WNDCLASS { - .lpfnWndProc = native_window_proc, + .lpfnWndProc = window_proc, .hInstance = GetModuleHandle(nullptr), .lpszClassName = constants::class_name, }; @@ -602,11 +721,17 @@ void System::on_unregister() void System::create_surface_component(ecs::EntityId entity, SurfaceComponent::CreateInfo info) try { + // WIP(Light): use ignored local variables... auto &component = m_registry->add(entity, info); + std::ignore = component; + auto &surface = m_registry->get(entity); + ensure_component_sanity(surface); + const auto &resolution = surface.get_resolution(); const auto &position = surface.get_position(); - ensure_component_sanity(surface); + std::ignore = resolution; + std::ignore = position; surface.m_native_data.window = CreateWindowEx( 0, @@ -625,6 +750,9 @@ try debug::ensure(surface.m_native_data.window, "Failed to create Windows surface component"); ShowWindow(surface.m_native_data.window, SW_NORMAL); + // SetWindowLongPtrA(surface.m_native_data.window, 0, this); + // SetWindowLongPtrA(surface.m_native_data.window, 1, entity); + // TODO(Light): refactor "environment" into standalone module // NOLINTNEXTLINE(concurrency-mt-unsafe) @@ -726,15 +854,65 @@ void System::handle_events(SurfaceComponent &surface) queue.clear(); auto message = MSG {}; - while (PeekMessage(&message, surface.m_native_data.window, {}, {}, PM_REMOVE)) + while (PeekMessage(&message, {}, {}, {}, PM_REMOVE)) { + TranslateMessage(&message); + + const auto wParam = message.wParam; switch (message.message) { + case WM_SETFOCUS: log::debug("Window setfocus"); break; + case WM_KILLFOCUS: log::debug("Window killfocus"); break; + case WM_ACTIVATE: + log::debug("Window activate: {}", static_cast(LOWORD(wParam))); + break; + case WM_MOUSEWHEEL: + { + const auto delta = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA; + log::debug("wheel delta: {}", static_cast(delta)); + break; + } + + case WM_LBUTTONDOWN: + log::debug("Left button down: {}", to_string(translate_key(wParam))); + break; + case WM_LBUTTONUP: log::debug("Left button up {}", to_string(translate_key(wParam))); break; + + case WM_RBUTTONDOWN: + log::debug("Right button down {}", to_string(translate_key(wParam))); + break; + case WM_RBUTTONUP: + log::debug("Right button up {}", to_string(translate_key(wParam))); + break; + + case WM_MBUTTONDOWN: + log::debug("Middle button down {}", to_string(translate_key(wParam))); + break; + case WM_MBUTTONUP: + log::debug("Middle button up {}", to_string(translate_key(wParam))); + break; + + case WM_XBUTTONDOWN: + { + const auto key = static_cast( + std::to_underlying(Key::x_button_1) + GET_XBUTTON_WPARAM(wParam) - 1 + ); + log::debug("xbutn: {}", std::to_underlying(key)); + break; + } + case WM_XBUTTONUP: + { + const auto key = static_cast( + std::to_underlying(Key::x_button_1) + GET_XBUTTON_WPARAM(wParam) - 1 + ); + log::debug("xbutn: {}", std::to_underlying(key)); + break; + } + case WM_KEYDOWN: log::debug("Keydown: {}", to_string(translate_key(wParam))); break; + case WM_KEYUP: log::debug("Keyup__: {}", to_string(translate_key(wParam))); break; } - TranslateMessage(&message); DispatchMessage(&message); - // log::debug("Window message type: {}", std::uint32_t { message.message }); } // auto event = XEvent {}; @@ -852,6 +1030,10 @@ void System::handle_requests(SurfaceComponent &surface) void System::modify_title(SurfaceComponent &surface, const ModifyTitleRequest &request) { + // WIP(Light): + std::ignore = surface; + std::ignore = request; + surface.m_title = request.title; // const auto &[display, window, _] = surface.get_native_data(); @@ -860,6 +1042,10 @@ void System::modify_title(SurfaceComponent &surface, const ModifyTitleRequest &r void System::modify_resolution(SurfaceComponent &surface, const ModifyResolutionRequest &request) { + // WIP(Light): + std::ignore = surface; + std::ignore = request; + // surface.m_resolution = request.resolution; // auto &[display, window, _] = surface.m_native_data; @@ -922,6 +1108,10 @@ void System::modify_resolution(SurfaceComponent &surface, const ModifyResolution void System::modify_position(SurfaceComponent &surface, const ModifyPositionRequest &request) { + // WIP(Light): Use ignored local-variables + std::ignore = surface; + std::ignore = request; + // surface.m_position = request.position; // auto &[display, window, _] = surface.m_native_data; @@ -961,6 +1151,10 @@ void System::modify_position(SurfaceComponent &surface, const ModifyPositionRequ void System::modify_visiblity(SurfaceComponent &surface, const ModifyVisibilityRequest &request) { + // WIP(Light): Use ignored local-variables + std::ignore = surface; + std::ignore = request; + // const auto &[display, window, _] = surface.get_native_data(); // surface.m_visible = request.visible; @@ -1024,139 +1218,27 @@ void ensure_component_sanity(const SurfaceComponent &component) ); } -auto CALLBACK native_window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -> LRESULT +auto CALLBACK window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -> LRESULT { - constexpr auto translate_key = [](auto code) -> Key { - switch (code) - { - using enum Key; - case VK_LBUTTON: return left_mouse_button; - case VK_RBUTTON: return right_mouse_button; - case VK_MBUTTON: return middle_mouse_button; - - case VK_BACK: return backspace; - case VK_TAB: return tab; - case VK_CAPITAL: return capslock; - case VK_RETURN: enter; - case VK_SPACE: space; - case VK_DELETE: return delete_; - - case VK_SHIFT: shift; - case VK_RSHIFT: right_shift; - - case VK_CONTROL: control; - case VK_RCONTROL: right_control; - - case VK_MENU: alt; - case VK_RMENU: right_alt; - - case VK_PRIOR: return pageup; - case VK_NEXT: return pagedown; - case VK_END: return end; - case VK_HOME: return home; - - case VK_LEFT: return left_arrow; - case VK_RIGHT: return right_arrow; - case VK_DOWN: return down_arrow; - case VK_UP: return up_arrow; - - case VK_CANCEL: return cancel; - case VK_PAUSE: return pause; - case VK_SELECT: return select; - case VK_PRINT: return print; - case VK_SNAPSHOT: return snapshot; - case VK_INSERT: return insert; - case VK_HELP: return help; - case VK_SLEEP: return sleep; - - case '0': return digit_0; - case '1': return digit_1; - case '2': return digit_2; - case '3': return digit_3; - case '4': return digit_4; - case '5': return digit_5; - case '6': return digit_6; - case '7': return digit_7; - case '8': return digit_8; - case '9': return digit_9; - - case 'A': return a; - case 'B': return b; - case 'C': return c; - case 'D': return d; - case 'E': return e; - case 'F': return f; - case 'G': return g; - case 'H': return h; - case 'I': return i; - case 'J': return j; - case 'K': return k; - case 'L': return l; - case 'M': return m; - case 'N': return n; - case 'O': return o; - case 'P': return p; - case 'Q': return q; - case 'R': return r; - case 'S': return s; - case 'T': return t; - case 'U': return u; - case 'V': return v; - case 'W': return w; - case 'X': return x; - case 'Y': return y; - case 'Z': return z; - - case VK_LWIN: return super; - case VK_RWIN: return right_super; - - case VK_NUMPAD0: return kp_0; - case VK_NUMPAD1: return kp_1; - case VK_NUMPAD2: return kp_2; - case VK_NUMPAD3: return kp_3; - case VK_NUMPAD4: return kp_4; - case VK_NUMPAD5: return kp_5; - case VK_NUMPAD6: return kp_6; - case VK_NUMPAD7: return kp_7; - case VK_NUMPAD8: return kp_8; - case VK_NUMPAD9: return kp_9; - - case VK_MULTIPLY: return kp_multiply; - case VK_ADD: return kp_add; - case VK_SUBTRACT: return kp_subtract; - case VK_DECIMAL: return kp_decimal; - - case VK_F1: return f1; - case VK_F2: return f2; - case VK_F3: return f3; - case VK_F4: return f4; - case VK_F5: return f5; - case VK_F6: return f6; - case VK_F7: return f7; - case VK_F8: return f8; - case VK_F9: return f9; - case VK_F10: return f10; - case VK_F11: return f11; - case VK_F12: return f12; - - default: return unknown; - } - }; - switch (uMsg) { - case WM_KEYDOWN: log::debug("Keydown: {}", to_string(translate_key(wParam))); - case WM_KEYUP: log::debug("Keyup__: {}", to_string(translate_key(wParam))); - case WM_DESTROY: - { - PostQuitMessage(0); - return 0; - } + case WM_KILLFOCUS: + case WM_SETFOCUS: log::debug("GOT FOCUS IN WIN PROC"); + case WM_ACTIVATE: + case WM_MOUSEWHEEL: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_XBUTTONDOWN: + case WM_XBUTTONUP: + case WM_KEYDOWN: + case WM_KEYUP: return 0; + case WM_DESTROY: PostQuitMessage(0); return 0; } - - // log::debug("Window message type (window proc): {}", std::uint32_t { uMsg - // }); return DefWindowProcA(hwnd, uMsg, wParam, lParam); } diff --git a/modules/test/expects.cppm b/modules/test/expects.cppm index 579b4fc..b084500 100644 --- a/modules/test/expects.cppm +++ b/modules/test/expects.cppm @@ -31,6 +31,7 @@ export void expect_unreachable( }; }; +/** @todo(Light7734): Check exception type. */ export constexpr void expect_throw( std::invocable auto invocable, std::source_location source_location = std::source_location::current() @@ -40,7 +41,7 @@ export constexpr void expect_throw( { invocable(); } - catch (const std::exception &exp) + catch (const std::exception &) { return; } diff --git a/modules/test/test.cppm b/modules/test/test.cppm index 6d0c96b..aa8ccf1 100644 --- a/modules/test/test.cppm +++ b/modules/test/test.cppm @@ -108,6 +108,9 @@ constexpr TestFuzzHarness::TestFuzzHarness(auto body) auto operator""_suite(const char *name, std::size_t size) -> TestSuite { + // TODO(Light): do we need the size parameter? + std::ignore = size; + Registry::set_last_suite_name(name); return {}; } diff --git a/modules/test/test.test.cpp b/modules/test/test.test.cpp index f37e32a..8fdb49b 100644 --- a/modules/test/test.test.cpp +++ b/modules/test/test.test.cpp @@ -24,7 +24,7 @@ Suite expects = "expects"_suite = []() { // clang-format off try { expect_unreachable(); } - catch (const std::exception &exp) { unhappy = true; } + catch (const std::exception &) { unhappy = true; } // clang-format on if (!unhappy) @@ -48,16 +48,16 @@ Suite expects = "expects"_suite = []() { // clang-format off try { expect_true(where_oongaboonga_ptr); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } try { expect_true(!true); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } try { expect_true(false); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } try { expect_true(0); } // NOLINT - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } // clang-format on }; @@ -66,27 +66,30 @@ Suite expects = "expects"_suite = []() { expect_false(oongaboonga_is_slacking); expect_false(false); - expect_false(0); // NOLINT }; Case { "expect_false - unhappy" } = [] { - auto oongaboonga = int {}; auto *oonga_oonga_can_rest_now = (int *)nullptr; auto unhappy_counter = 0u; // clang-format off try { expect_false(oonga_oonga_can_rest_now); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } try { expect_false(true); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } try { expect_false(!false); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } - try { expect_false(1); } // NOLINT - catch (const std::exception& exp) { ++unhappy_counter; } + try { expect_false(!!1); } + catch (const std::exception&) { ++unhappy_counter; } // clang-format on + + if (unhappy_counter != 4) + { + throw std::runtime_error { "expect_false - unhappy" }; + } }; Case { "expect_true - unhappy" } = [] { @@ -95,23 +98,28 @@ Suite expects = "expects"_suite = []() { // clang-format off try { expect_true(where_oongaboonga_ptr); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } try { expect_true(!true); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } try { expect_true(false); } - catch (const std::exception& exp) { ++unhappy_counter; } + catch (const std::exception&) { ++unhappy_counter; } - try { expect_true(0); } // NOLINT - catch (const std::exception& exp) { ++unhappy_counter; } + try { expect_true(!!0); } + catch (const std::exception&) { ++unhappy_counter; } // clang-format on + + if (unhappy_counter != 4) + { + throw std::runtime_error { "expect_true - unhappy" }; + } }; Case { "expect_eq - happy" } = [] { expect_eq(5, 5); expect_eq(20.0, 20.0); - expect_eq(true, 1); + expect_eq(true, true); }; Case { "expect_eq - unhappy" } = [] { @@ -119,7 +127,7 @@ Suite expects = "expects"_suite = []() { // clang-format off try { expect_eq(true, false); } - catch (const std::exception &exp) { unhappy = true; } + catch (const std::exception &) { unhappy = true; } // clang-format on if (!unhappy) @@ -131,7 +139,8 @@ Suite expects = "expects"_suite = []() { Case { "expect_ne - happy " } = [] { expect_ne(5, 5.0000001); expect_ne(20.0, 69.0); - expect_ne(true, 0); + expect_ne(true, true); + expect_ne(false, false); }; Case { "expect_ne - unhappy" } = [] { @@ -139,16 +148,19 @@ Suite expects = "expects"_suite = []() { // clang-format off try { expect_ne(5, 5); } - catch (const std::exception &exp) { ++unhappy_counter; } + catch (const std::exception &) { ++unhappy_counter; } try { expect_ne(20.0, 20.0); } - catch (const std::exception &exp) { ++unhappy_counter; } + catch (const std::exception &) { ++unhappy_counter; } - try { expect_ne(true, 1); } - catch (const std::exception &exp) { ++unhappy_counter; } + try { expect_ne(true, true); } + catch (const std::exception &) { ++unhappy_counter; } + + try { expect_ne(false, false); } + catch (const std::exception &) { ++unhappy_counter; } // clang-format on - if (unhappy_counter != 3) + if (unhappy_counter != 4) { throw std::runtime_error { "expect_ne unhappy" }; } @@ -163,7 +175,7 @@ Suite expects = "expects"_suite = []() { // clang-format off try { expect_throw([] {}); } - catch (const std::exception &exp) { unhappy = true; } + catch (const std::exception &) { unhappy = true; } // clang-format on if (!unhappy) @@ -175,7 +187,7 @@ Suite expects = "expects"_suite = []() { Case { "expect_le - happy" } = [] { expect_le(69, 420); expect_le(19.694206942069420, 20.0); - expect_le(false, 1); + expect_le(false, !!1); }; Case { "expect_le - unhappy" } = [] { @@ -183,16 +195,16 @@ Suite expects = "expects"_suite = []() { // clang-format off try { expect_le(20020619 + 23, 20020619 ); } - catch (const std::exception &exp) { ++unhappy_counter; } + catch (const std::exception &) { ++unhappy_counter; } try { expect_le(420, 69); } - catch (const std::exception &exp) { ++unhappy_counter; } + catch (const std::exception &) { ++unhappy_counter; } try { expect_le(20.0, 19.694206942069420); } - catch (const std::exception &exp) { ++unhappy_counter; } + catch (const std::exception &) { ++unhappy_counter; } - try { expect_le(1, false); } - catch (const std::exception &exp) { ++unhappy_counter; } + try { expect_le(true, false); } + catch (const std::exception &) { ++unhappy_counter; } // clang-format on if (unhappy_counter != 4) diff --git a/modules/time/timer.test.cpp b/modules/time/timer.test.cpp index d911829..3fad4d3 100644 --- a/modules/time/timer.test.cpp +++ b/modules/time/timer.test.cpp @@ -28,6 +28,7 @@ Suite raii = "raii"_suite = [] { Case { "plenty" } = [] { for (auto idx : std::views::iota(0, 100'001)) { + std::ignore = idx; Timer {}; } };