Files
OpenVulkano/openVulkanoCpp/Input/InputManager.hpp
2024-11-07 16:45:42 +02:00

62 lines
1.5 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 <memory>
#include <unordered_map>
#include <vector>
namespace OpenVulkano::Input
{
class InputManager final
{
InputManager() = default;
public:
static InputManager* GetInstance();
void Tick();
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;
}
private:
std::unordered_map<std::string, std::unique_ptr<InputAction>> actionNameMapping;
std::vector<InputDevice*> devices;
InputDevice* lastActiveDevice = nullptr;
};
}