54 lines
1.2 KiB
C++
54 lines
1.2 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 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 GetButton(InputKey key) 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;
|
|
};
|
|
}
|