From 571c1eb35ec32d3c74ab2affa07ab92bbcad6c5f Mon Sep 17 00:00:00 2001 From: versustunez Date: Thu, 29 May 2025 17:48:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20static=20Input=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit export inline to have a single instance of it --- Source/Core/Window.cppm | 4 +--- Source/Input/Input.cppm | 7 ++++--- main.cppm | 16 +++++++++------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Source/Core/Window.cppm b/Source/Core/Window.cppm index 8896409..fb590f0 100644 --- a/Source/Core/Window.cppm +++ b/Source/Core/Window.cppm @@ -3,8 +3,6 @@ module; #include #include -#include "../PlatformDetection.h" - export module VUI:Window; import :Ref; @@ -13,7 +11,7 @@ import :Input; namespace VUI { struct WindowManager; -std::uint64_t s_Handle = 0; +export inline std::uint64_t s_Handle = 0; export struct WindowSpecification { uint32_t width{1280}; diff --git a/Source/Input/Input.cppm b/Source/Input/Input.cppm index 555bdb0..3805038 100644 --- a/Source/Input/Input.cppm +++ b/Source/Input/Input.cppm @@ -2,6 +2,7 @@ module; #include #include +#include #include export module VUI:Input; @@ -15,9 +16,9 @@ struct Window; constexpr uint32_t DownMask = 1; constexpr uint32_t RepeatMask = 1 << 2; -static std::array s_Keys{}; +export inline std::array s_Keys{}; -static constexpr std::array InputKeys = InitKeys(); +export inline constexpr std::array InputKeys = InitKeys(); export struct Input { static bool IsKeyDown(const KeyCodes key) { @@ -54,6 +55,6 @@ void Input::UpdateKey(const uint32_t key, const bool isDown) { void Input::PostFrameUpdate() { for (uint8_t &s_key : s_Keys) - s_key |= s_key & DownMask ? RepeatMask : 0; + s_key |= (s_key & DownMask) ? RepeatMask : 0; } } // namespace VUI \ No newline at end of file diff --git a/main.cppm b/main.cppm index 5ec8162..661ae1b 100644 --- a/main.cppm +++ b/main.cppm @@ -1,16 +1,18 @@ import VUI; - -#include -#include - -struct Me final : VUI::RefCounted { - -}; +#include +#include int main() { VUI::WindowManager::Create(1280, 720, "VUI"); while (VUI::WindowManager::HasOpenWindows()) { VUI::WindowManager::Update(); + if (VUI::Input::IsKeyPressed(VUI::KeyCodes::F3)) { + VUI::WindowManager::Create(1280, 720, "Second Window"); + } + if (VUI::Input::IsKeyPressed(VUI::KeyCodes::F4)) { + VUI::WindowManager::CloseByTitle("Second Window"); + } + std::this_thread::sleep_for(std::chrono::milliseconds(30)); } return 0; } \ No newline at end of file