77 lines
2.7 KiB
C++
77 lines
2.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 { return GetAxis(&action); }
|
|
[[nodiscard]] float GetAxis(const InputAction* action) const;
|
|
[[nodiscard]] float GetAxis(InputKey key) const;
|
|
|
|
[[nodiscard]] Math::Vector2f GetAxis2d(const InputAction& actionX, const InputAction& actionY) const { return GetAxis2d(&actionX, &actionY); }
|
|
[[nodiscard]] Math::Vector2f GetAxis2d(const InputAction* actionX, const InputAction* actionY) const { return { GetAxis(actionX), GetAxis(actionY) }; }
|
|
[[nodiscard]] Math::Vector2f GetAxis2d(InputKey keyX, InputKey keyY) const { return { GetAxis(keyX), GetAxis(keyY) }; }
|
|
|
|
[[nodiscard]] bool GetButton(const InputAction& action) const { return GetButton(&action); }
|
|
[[nodiscard]] bool GetButton(const InputAction* action) const;
|
|
[[nodiscard]] bool GetButton(InputKey key) const;
|
|
|
|
[[nodiscard]] bool GetButtonUp(const InputAction& action) const { return GetButtonUp(&action); }
|
|
[[nodiscard]] bool GetButtonUp(const InputAction* action) const;
|
|
[[nodiscard]] bool GetButtonUp(InputKey key) const;
|
|
|
|
[[nodiscard]] bool GetButtonDown(const InputAction& action) const { return GetButtonDown(&action); }
|
|
[[nodiscard]] bool GetButtonDown(const InputAction* action) const;
|
|
[[nodiscard]] bool GetButtonDown(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;
|
|
};
|
|
}
|