/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include "InputDevice.hpp" #include "InputAction.hpp" #include "InputShortcut.hpp" #include "Math/Range.hpp" #include #include #include namespace OpenVulkano::Input { class InputManager final { InputManager() = default; public: static InputManager* GetInstance(); void Tick(double time); void RegisterInputDevice(InputDevice* device) { devices.push_back(device); if (!lastActiveDevice) lastActiveDevice = device; } void UnregisterInputDevice(InputDevice* device); [[nodiscard]] InputAction* GetAction(const std::string& actionName); [[nodiscard]] float GetAxis(const InputAction* action) const; [[nodiscard]] float GetAxis(InputKey key) const; [[nodiscard]] bool GetButton(InputAction* action) const; [[nodiscard]] bool GetButtonDown(InputAction* action) const; [[nodiscard]] bool GetButton(InputKey key) const; [[nodiscard]] InputDevice* GetDevice(InputDeviceType type) const; [[nodiscard]] std::vector GetDevices(InputDeviceType type) const; [[nodiscard]] InputDevice* GetLastActiveDevice() const { return lastActiveDevice; } [[nodiscard]] float GetTimeScale() const { return timescale; } private: std::unordered_map> actionNameMapping; std::vector devices; InputDevice* lastActiveDevice = nullptr; const Math::Range inputTimeRange = { 1.0f / 10000, 1.0f / 30 }; // Limit input time range from 1/10k FPS to 1/30fps float timescale = 1.0f / 60; }; }