🐛 static Input handling

export inline to have a single instance of it
This commit is contained in:
Maurice Grönwoldt 2025-05-29 17:48:42 +02:00
commit 571c1eb35e
3 changed files with 14 additions and 13 deletions

View file

@ -3,8 +3,6 @@ module;
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include "../PlatformDetection.h"
export module VUI:Window; export module VUI:Window;
import :Ref; import :Ref;
@ -13,7 +11,7 @@ import :Input;
namespace VUI { namespace VUI {
struct WindowManager; struct WindowManager;
std::uint64_t s_Handle = 0; export inline std::uint64_t s_Handle = 0;
export struct WindowSpecification { export struct WindowSpecification {
uint32_t width{1280}; uint32_t width{1280};

View file

@ -2,6 +2,7 @@ module;
#include <array> #include <array>
#include <cassert> #include <cassert>
#include <iostream>
#include <utility> #include <utility>
export module VUI:Input; export module VUI:Input;
@ -15,9 +16,9 @@ struct Window;
constexpr uint32_t DownMask = 1; constexpr uint32_t DownMask = 1;
constexpr uint32_t RepeatMask = 1 << 2; constexpr uint32_t RepeatMask = 1 << 2;
static std::array<uint8_t, std::to_underlying(KeyCodes::KEYLAST)> s_Keys{}; export inline std::array<uint8_t, std::to_underlying(KeyCodes::KEYLAST)> s_Keys{};
static constexpr std::array<KeyCodes, Keys> InputKeys = InitKeys(); export inline constexpr std::array<KeyCodes, Keys> InputKeys = InitKeys();
export struct Input { export struct Input {
static bool IsKeyDown(const KeyCodes key) { static bool IsKeyDown(const KeyCodes key) {
@ -54,6 +55,6 @@ void Input::UpdateKey(const uint32_t key, const bool isDown) {
void Input::PostFrameUpdate() { void Input::PostFrameUpdate() {
for (uint8_t &s_key : s_Keys) for (uint8_t &s_key : s_Keys)
s_key |= s_key & DownMask ? RepeatMask : 0; s_key |= (s_key & DownMask) ? RepeatMask : 0;
} }
} // namespace VUI } // namespace VUI

View file

@ -1,16 +1,18 @@
import VUI; import VUI;
#include <chrono>
#include <iostream> #include <thread>
#include <ostream>
struct Me final : VUI::RefCounted {
};
int main() { int main() {
VUI::WindowManager::Create(1280, 720, "VUI"); VUI::WindowManager::Create(1280, 720, "VUI");
while (VUI::WindowManager::HasOpenWindows()) { while (VUI::WindowManager::HasOpenWindows()) {
VUI::WindowManager::Update(); 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; return 0;
} }