Files
letnik3koncni-prap/include/game/input.hpp
2026-05-19 22:35:10 +02:00

42 lines
1.5 KiB
C++

#pragma once
#include <SDL3/SDL.h>
#include <vector>
#include <queue>
#include <mutex>
#include <string>
namespace Game {
class Input {
public:
Input() = delete;
static void update();
static bool isKeyPressed(SDL_Scancode key);
static bool isKeyJustPressed(SDL_Scancode key);
static bool isKeyJustReleased(SDL_Scancode key);
static bool isMouseButtonPressed(Uint8 button);
static bool isMouseButtonJustPressed(Uint8 button);
static bool isMouseButtonJustReleased(Uint8 button);
static float getMouseX();
static float getMouseY();
// Text input from SDL text-input events (pushed by window thread, consumed by game thread)
static void pushText(const std::string& utf8);
static void consumeText(std::vector<std::string>& out);
private:
static const bool* mCurrentKeyStates;
static std::vector<Uint8> mPreviousKeyStates;
static int mNumKeys;
static int mPrevNumKeys;
static SDL_MouseButtonFlags mCurrentMouseButtonStates;
static SDL_MouseButtonFlags mPreviousMouseButtonStates;
static float mMouseX;
static float mMouseY;
// Text input queue and mutex (window thread writes via pushText, game thread reads via consumeText)
static std::mutex mTextMutex;
static std::vector<std::string> mPendingText;
};
}