1 #ifndef DONUT_EVENTS_INPUT_MANAGER_HPP
2 #define DONUT_EVENTS_INPUT_MANAGER_HPP
13 #include <type_traits>
14 #include <unordered_map>
831 [[nodiscard]]
bool isPressed(std::
size_t output) const noexcept;
850 [[nodiscard]]
bool justPressed(std::
size_t output) const noexcept;
977 [[nodiscard]]
float getAbsoluteValue(std::
size_t outputNegative, std::
size_t outputPositive) const noexcept;
1000 [[nodiscard]]
float getRelativeValue(std::
size_t outputNegative, std::
size_t outputPositive) const noexcept;
1037 [[nodiscard]] vec2
getAbsoluteValue(std::
size_t outputNegativeX, std::
size_t outputPositiveX, std::
size_t outputNegativeY, std::
size_t outputPositiveY) const noexcept;
1066 [[nodiscard]] vec2
getRelativeValue(std::
size_t outputNegativeX, std::
size_t outputPositiveX, std::
size_t outputNegativeY, std::
size_t outputPositiveY) const noexcept;
1110 [[nodiscard]] vec3
getAbsoluteValue(std::
size_t outputNegativeX, std::
size_t outputPositiveX, std::
size_t outputNegativeY, std::
size_t outputPositiveY,
1111 std::
size_t outputNegativeZ, std::
size_t outputPositiveZ) const noexcept;
1146 [[nodiscard]] vec3
getRelativeValue(std::
size_t outputNegativeX, std::
size_t outputPositiveX, std::
size_t outputNegativeY, std::
size_t outputPositiveY,
1147 std::
size_t outputNegativeZ, std::
size_t outputPositiveZ) const noexcept;
1217 template <typename... Actions>
1218 void bind(
Input input, Actions... actions) requires((std::is_enum_v<Actions> && !std::is_same_v<Actions,
Input>) && ...) {
1220 (outputs.set(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Actions>
>(actions))), ...);
1221 bind(input, outputs);
1231 template <
typename... Actions>
1232 void addBinding(
Input input, Actions... actions) requires((std::is_enum_v<Actions> && !std::is_same_v<Actions, Input>) && ...) {
1234 (outputs.set(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Actions>
>(actions))), ...);
1245 template <
typename Action>
1246 [[nodiscard]]
bool isPressed(Action action)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1247 return isPressed(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(action)));
1257 template <
typename Action>
1258 [[nodiscard]]
bool justPressed(Action action)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1259 return justPressed(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(action)));
1269 template <
typename Action>
1270 [[nodiscard]]
bool justReleased(Action action)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1271 return justReleased(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(action)));
1281 template <
typename Action>
1282 [[nodiscard]] i32
getAbsoluteState(Action action)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1283 return getAbsoluteState(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(action)));
1293 template <
typename Action>
1294 [[nodiscard]] i32
getRelativeState(Action action)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1295 return getRelativeState(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(action)));
1305 template <
typename Action>
1306 [[nodiscard]]
float getAbsoluteValue(Action actionPositive)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1307 return getAbsoluteValue(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositive)));
1317 template <
typename Action>
1318 [[nodiscard]]
float getRelativeValue(Action actionPositive)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1319 return getRelativeValue(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositive)));
1329 template <
typename Action>
1330 [[nodiscard]]
float getAbsoluteValue(Action actionNegative, Action actionPositive)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1331 return getAbsoluteValue(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegative)),
1332 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositive)));
1342 template <
typename Action>
1343 [[nodiscard]]
float getRelativeValue(Action actionNegative, Action actionPositive)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1344 return getRelativeValue(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegative)),
1345 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositive)));
1357 template <
typename Action>
1358 [[nodiscard]] vec2
getAbsoluteValue(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY)
const noexcept
1359 requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1360 return getAbsoluteValue(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeX)),
1361 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveX)),
1362 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeY)),
1363 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveY)));
1375 template <
typename Action>
1376 [[nodiscard]] vec2
getRelativeValue(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY)
const noexcept
1377 requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1378 return getRelativeValue(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeX)),
1379 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveX)),
1380 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeY)),
1381 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveY)));
1393 template <
typename Action>
1394 [[nodiscard]] vec3
getAbsoluteValue(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY, Action actionNegativeZ,
1395 Action actionPositiveZ)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1396 return getAbsoluteValue(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeX)),
1397 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveX)),
1398 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeY)),
1399 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveY)),
1400 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeZ)),
1401 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveZ)));
1413 template <
typename Action>
1414 [[nodiscard]] vec3
getRelativeValue(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY, Action actionNegativeZ,
1415 Action actionPositiveZ)
const noexcept requires(std::is_enum_v<Action> && !std::is_same_v<Action, Input>) {
1416 return getRelativeValue(
static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeX)),
1417 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveX)),
1418 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeY)),
1419 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveY)),
1420 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionNegativeZ)),
1421 static_cast<std::size_t
>(
static_cast<std::underlying_type_t<Action>
>(actionPositiveZ)));
1425 struct ControllerDeleter {
1426 void operator()(
void* handle)
const noexcept;
1431 void setMousePosition(vec2 position, vec2 relativeMotion) noexcept;
1432 void scrollMouseWheelHorizontally(
float offset) noexcept;
1433 void scrollMouseWheelVertically(
float offset) noexcept;
1435 void setControllerLeftStickPosition(vec2 position) noexcept;
1436 void setControllerRightStickPosition(vec2 position) noexcept;
1437 void setControllerLeftTriggerPosition(
float position) noexcept;
1438 void setControllerRightTriggerPosition(
float position) noexcept;
1440 void setTouchPosition(vec2 position) noexcept;
1441 void setTouchPressure(
float pressure) noexcept;
1443 InputManagerOptions options;
1444 std::unordered_map<Input, Outputs> bindings{};
1445 std::optional<vec2> mousePosition{};
1446 Controller controller{};
1447 std::optional<vec2> controllerLeftStickPosition{};
1448 std::optional<vec2> controllerRightStickPosition{};
1449 std::optional<float> controllerLeftTriggerPosition{};
1450 std::optional<float> controllerRightTriggerPosition{};
1451 std::optional<vec2> touchPosition{};
1452 std::optional<float> touchPressure{};
1453 Outputs currentPersistentOutputs{};
1454 Outputs previousPersistentOutputs{};
1455 Outputs transientOutputPresses{};
1456 Outputs transientOutputReleases{};
1457 std::array<i32, OUTPUT_COUNT> outputAbsoluteStates{};
1458 std::array<i32, OUTPUT_COUNT> outputRelativeStates{};
1459 std::array<u8, OUTPUT_COUNT> outputPersistentPresses{};
1460 std::bitset<INPUT_COUNT> currentPersistentInputs{};
1461 std::bitset<INPUT_COUNT> previousPersistentInputs{};
1462 std::bitset<INPUT_COUNT> transientInputPresses{};
1463 std::bitset<INPUT_COUNT> transientInputReleases{};
1464 bool mouseTransientMotion =
false;
1465 bool mouseWheelHorizontalTransientMotion =
false;
1466 bool mouseWheelVerticalTransientMotion =
false;
1467 bool controllerLeftStickTransientMotion =
false;
1468 bool controllerRightStickTransientMotion =
false;
1469 bool controllerLeftTriggerTransientMotion =
false;
1470 bool controllerRightTriggerTransientMotion =
false;
1471 bool touchTransientMotion =
false;
1472 bool touchTransientPressure =
false;
Input
Unique identifier for a specific control on a physical input device, such as a certain keyboard key,...
Definition: Input.hpp:323
Data structure containing information about an event.
Definition: Event.hpp:339