Files
OpenVulkano/openVulkanoCpp/Input/InputManager.hpp
2025-01-25 22:15:14 +01:00

67 lines
1.7 KiB
C++

/*
* 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 <memory>
#include <unordered_map>
#include <vector>
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<InputDevice*> GetDevices(InputDeviceType type) const;
[[nodiscard]] InputDevice* GetLastActiveDevice() const
{
return lastActiveDevice;
}
[[nodiscard]] float GetTimeScale() const { return timescale; }
private:
std::unordered_map<std::string, std::unique_ptr<InputAction>> actionNameMapping;
std::vector<InputDevice*> devices;
InputDevice* lastActiveDevice = nullptr;
const Math::Range<float> inputTimeRange = { 1.0f / 10000, 1.0f / 30 }; // Limit input time range from 1/10k FPS to 1/30fps
float timescale = 1.0f / 60;
};
}