🐛 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 <string>
#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};

View file

@ -2,6 +2,7 @@ module;
#include <array>
#include <cassert>
#include <iostream>
#include <utility>
export module VUI:Input;
@ -15,9 +16,9 @@ struct Window;
constexpr uint32_t DownMask = 1;
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 {
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

View file

@ -1,16 +1,18 @@
import VUI;
#include <iostream>
#include <ostream>
struct Me final : VUI::RefCounted {
};
#include <chrono>
#include <thread>
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;
}