GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
InputManager.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_EVENTS_INPUT_MANAGER_HPP
5#define GREM_EVENTS_INPUT_MANAGER_HPP
6
8
25#include <GREM/core/math.hpp>
29#include <GREM/events/Event.hpp>
30#include <GREM/events/Input.hpp>
31
32#include <memory> // std::allocator
33#include <type_traits> // std::underlying_type_t
34#include <utility> // std::move
35
36namespace grem::json {
37struct Reader; // Forward declaration, to avoid including json.hpp.
38template <template <typename> typename Allocator>
39class VariantBase; // Forward declaration, to avoid including json.hpp.
40using Variant = json::VariantBase<std::allocator>; // Forward declaration, to avoid including json.hpp.
41} // namespace grem::json
42
43namespace grem::events {
44
45class InputManager; // Forward declaration.
46
47namespace detail {
48
49template <typename Action>
50[[nodiscard]] inline const HashMap<String, uint8_t>& getActionMap() {
51 static const HashMap<String, uint8_t> actionMap = []() -> HashMap<String, uint8_t> {
52 HashMap<String, uint8_t> result{};
53 meta::forEachNamedEnumerand<Action>([&](StringView name, auto action) -> void {
54 result[ascii::convertToUppercaseString(name)] = static_cast<uint8_t>(static_cast<std::underlying_type_t<Action>>(action()));
55 });
56 return result;
57 }();
58 return actionMap;
59}
60
61template <typename Action>
64 meta::forEachIndexedNamedEnumerand<Action>([&](auto index, StringView name, auto) -> void { result[index] = name; });
65 return result;
66}();
67
68} // namespace detail
69
245
265
337public:
343 float value;
344 };
345
354
363
369 int32_t addedPresses;
370 float motion;
371 };
372
381
390
394 using OutputIndex = uint8_t;
395
400 static constexpr OutputIndex OUTPUT_COUNT = 64;
401
405 class OutputEventBase {
406 public:
412 [[nodiscard]] GREM_ALWAYS_INLINE TimePoint getTimestamp() const noexcept {
413 return timestamp;
414 }
415
423 [[nodiscard]] GREM_ALWAYS_INLINE OutputIndex getOutputIndex() const noexcept {
424 return outputIndex;
425 }
426
436 template <enumeration Action>
437 [[nodiscard]] GREM_ALWAYS_INLINE bool isAction(Action action) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
438 return outputIndex == getOutputIndex(action);
439 }
440
447 [[nodiscard]] GREM_ALWAYS_INLINE ControlState getState() const noexcept {
448 return state;
449 }
450
457 [[nodiscard]] GREM_ALWAYS_INLINE ControlDelta getDelta() const noexcept {
458 return delta;
459 }
460
461 private:
462 friend InputManager;
463
464 constexpr OutputEventBase(TimePoint timestamp, OutputIndex outputIndex, ControlState state, ControlDelta delta) noexcept
465 : timestamp(timestamp)
466 , outputIndex(outputIndex)
467 , state(state)
468 , delta(delta) {}
469
470 TimePoint timestamp;
471 OutputIndex outputIndex;
472 ControlState state;
473 ControlDelta delta;
474 };
475
477 struct OutputMoved : OutputEventBase {};
478
480 struct OutputPressed : OutputEventBase {};
481
483 struct OutputReleased : OutputEventBase {};
484
488 struct OutputEvent : Variant<OutputMoved, OutputPressed, OutputReleased> {};
489
498
504
511 GREM_API(events) explicit InputManager(const InputManagerOptions& options);
512
540 GREM_API(events)
542 String fileContents, CStringView filepath, FunctionView<Optional<OutputIndex>(StringView actionName)> getOutputIndex,
543 FunctionView<void(StringView key, json::Reader& reader)> readExtraProperty = [](StringView, json::Reader&) -> void {});
544
571 String fileContents, FunctionView<Optional<OutputIndex>(StringView actionName)> getOutputIndex,
572 FunctionView<void(StringView key, json::Reader& reader)> readExtraProperty = [](StringView, json::Reader&) -> void {}) {
573 loadConfiguration(std::move(fileContents), {}, getOutputIndex, readExtraProperty);
574 }
575
606 template <enumeration Action>
608 String fileContents, CStringView filepath = {}, FunctionView<void(StringView key, json::Reader& reader)> readExtraProperty = [](StringView, json::Reader&) -> void {}) {
610 std::move(fileContents), filepath,
611 [](StringView actionName) -> Optional<OutputIndex> {
612 const HashMap<String, uint8_t>& actionMap = detail::getActionMap<Action>();
613 if (const auto it = actionMap.find(ascii::convertToUppercaseString(actionName)); it != actionMap.end()) {
614 return it->second;
615 }
616 return {};
617 },
618 readExtraProperty);
619 }
620
648 const Filesystem& filesystem, CStringView filepath, FunctionView<Optional<OutputIndex>(StringView actionName)> getOutputIndex,
649 FunctionView<void(StringView key, json::Reader& reader)> readExtraProperty = [](StringView, json::Reader&) -> void {}) {
650 loadConfiguration(filesystem.readInputFileString(filepath), filepath, getOutputIndex, readExtraProperty);
651 }
652
682 template <enumeration Action>
684 const Filesystem& filesystem, CStringView filepath, FunctionView<void(StringView key, json::Reader& reader)> readExtraProperty = [](StringView, json::Reader&) -> void {}) {
685 loadConfiguration<Action>(filesystem.readInputFileString(filepath), filepath, readExtraProperty);
686 }
687
709 [[nodiscard]] GREM_API(events) String
710 saveConfiguration(FunctionView<Optional<String>(OutputIndex outputIndex)> getActionName, Span<const Pair<StringView, json::Variant>> extraProperties = {}) const;
711
735 template <enumeration Action>
736 [[nodiscard]] String saveConfiguration(Span<const Pair<StringView, json::Variant>> extraProperties = {}) const {
737 return saveConfiguration(
738 [](OutputIndex outputIndex) -> Optional<String> {
739 const Span<const StringView> actionNames = detail::ACTION_NAMES<Action>;
740 if (outputIndex < actionNames.size()) {
741 return ascii::convertToLowercaseString(actionNames[outputIndex]);
742 }
743 return {};
744 },
745 extraProperties);
746 }
747
775 void saveConfiguration(Filesystem& filesystem, CStringView filepath, FunctionView<Optional<String>(OutputIndex outputIndex)> getActionName,
776 Span<const Pair<StringView, json::Variant>> extraProperties = {}) const {
777 filesystem.createParentOutputDirectories(filepath);
778 filesystem.openEmptyOutputFile(filepath).write(saveConfiguration(getActionName, extraProperties));
779 }
780
810 template <enumeration Action>
811 void saveConfiguration(Filesystem& filesystem, CStringView filepath, Span<const Pair<StringView, json::Variant>> extraProperties = {}) const {
812 filesystem.createParentOutputDirectories(filepath);
813 filesystem.openEmptyOutputFile(filepath).write(saveConfiguration<Action>(extraProperties));
814 }
815
829 void update() {
830 previousState = currentState;
831 relativeState = {};
832 }
833
846 GREM_API(events) void handleEvent(const Event& event);
847
869 polledOutputEvents.clear();
870 polledOutputEvents.swap(pendingOutputEvents);
871 return polledOutputEvents;
872 }
873
887 return polledOutputEvents;
888 }
889
908 GREM_API(events) void bind(Input input, ArrayList<OutputIndex> outputIndices);
909
927 GREM_API(events) void addBindings(Input input, Span<const OutputIndex> outputIndices);
928
946 addBindings(input, Span{&outputIndex, 1});
947 }
948
962 GREM_API(events) void unbind(Input input) noexcept;
963
972 GREM_API(events) void unbindAll() noexcept;
973
983 void resetAllStates() noexcept {
984 currentState = {};
985 previousState = {};
986 relativeState = {};
987 polledOutputEvents.clear();
988 pendingOutputEvents.clear();
989 }
990
1004 GREM_API(events) void setCurrentState(TimePoint timestamp, Input input, ControlState newState);
1005
1020 GREM_API(events) void setCurrentState(TimePoint timestamp, OutputIndex outputIndex, ControlState newState);
1021
1029 template <enumeration Action>
1030 GREM_ALWAYS_INLINE void setCurrentState(TimePoint timestamp, Action action, ControlState newState = {.activePresses = 1, .value = 1.0f})
1032 setCurrentState(timestamp, getOutputIndex(action), newState);
1033 }
1034
1050 GREM_API(events) void addRelativeState(TimePoint timestamp, Input input, ControlDelta delta);
1051
1067 GREM_API(events) void addRelativeState(TimePoint timestamp, OutputIndex outputIndex, ControlDelta delta);
1068
1076 template <enumeration Action>
1078 addRelativeState(timestamp, getOutputIndex(action), delta);
1079 }
1080
1092 GREM_API(events) void releaseAll(TimePoint timestamp);
1093
1103 options.preferences = preferences;
1104 }
1105
1120 GREM_ALWAYS_INLINE void setEmitOutputEvents(bool emitOutputEvents) noexcept {
1121 options.emitOutputEvents = emitOutputEvents;
1122 }
1123
1134 [[nodiscard]] GREM_ALWAYS_INLINE const InputManagerPreferences& getPreferences() const noexcept {
1135 return options.preferences;
1136 }
1137
1147 return initialPreferences;
1148 }
1149
1158 [[nodiscard]] GREM_ALWAYS_INLINE const InputManagerOptions& getOptions() const noexcept {
1159 return options;
1160 }
1161
1168 [[nodiscard]] GREM_ALWAYS_INLINE bool hasAnyBindings() const noexcept {
1169 return !bindings.empty();
1170 }
1171
1186 [[nodiscard]] Allocation<Binding> getBindings() const {
1187 Allocation<Binding> result(bindings.size());
1188 auto it = result.begin();
1189 for (const auto& [input, outputIndices] : bindings) {
1190 *it++ = Binding{.input = input, .outputIndices = outputIndices};
1191 }
1192 return result;
1193 }
1194
1206 [[nodiscard]] Span<const OutputIndex> getBoundOutputs(Input input) const noexcept {
1207 if (const auto it = bindings.find(input); it != bindings.end()) {
1208 return it->second;
1209 }
1210 return {};
1211 }
1212
1225 [[nodiscard]] Span<const Input> getBoundInputs(OutputIndex outputIndex) const noexcept {
1226 if (const auto it = boundInputs.find(outputIndex); it != boundInputs.end()) {
1227 return it->second;
1228 }
1229 return {};
1230 }
1231
1239 template <enumeration Action>
1241 return getBoundInputs(getOutputIndex(action));
1242 }
1243
1262 return currentState.mousePosition;
1263 }
1264
1283 return previousState.mousePosition;
1284 }
1285
1307 if (currentState.mousePosition && previousState.mousePosition) {
1308 return *currentState.mousePosition - *previousState.mousePosition;
1309 }
1310 return {};
1311 }
1312
1329 [[nodiscard]] GREM_ALWAYS_INLINE bool mouseJustMoved() const noexcept {
1330 return relativeState.transientInputPresses[getInputIndex(Input::MOUSE_MOTION_UP)] || //
1331 relativeState.transientInputPresses[getInputIndex(Input::MOUSE_MOTION_DOWN)] || //
1332 relativeState.transientInputPresses[getInputIndex(Input::MOUSE_MOTION_LEFT)] || //
1333 relativeState.transientInputPresses[getInputIndex(Input::MOUSE_MOTION_RIGHT)];
1334 }
1335
1352 [[nodiscard]] GREM_ALWAYS_INLINE vec2 getRelativeMouseWheelScroll() const noexcept {
1353 return relativeState.transientMouseWheelScroll;
1354 }
1355
1372 [[nodiscard]] GREM_ALWAYS_INLINE bool mouseWheelJustScrolledHorizontally() const noexcept {
1373 return relativeState.transientInputPresses[getInputIndex(Input::MOUSE_SCROLL_LEFT)] || //
1374 relativeState.transientInputPresses[getInputIndex(Input::MOUSE_SCROLL_RIGHT)];
1375 }
1376
1393 [[nodiscard]] GREM_ALWAYS_INLINE bool mouseWheelJustScrolledVertically() const noexcept {
1394 return relativeState.transientInputPresses[getInputIndex(Input::MOUSE_SCROLL_UP)] || //
1395 relativeState.transientInputPresses[getInputIndex(Input::MOUSE_SCROLL_DOWN)];
1396 }
1397
1419 return currentState.touchPosition;
1420 }
1421
1442 return previousState.touchPosition;
1443 }
1444
1467 if (currentState.touchPosition && previousState.touchPosition) {
1468 return *currentState.touchPosition - *previousState.touchPosition;
1469 }
1470 return {};
1471 }
1472
1489 [[nodiscard]] GREM_ALWAYS_INLINE bool touchJustMoved() const noexcept {
1490 return relativeState.transientInputPresses[getInputIndex(Input::TOUCH_FINGER_MOTION_UP)] || //
1491 relativeState.transientInputPresses[getInputIndex(Input::TOUCH_FINGER_MOTION_DOWN)] || //
1492 relativeState.transientInputPresses[getInputIndex(Input::TOUCH_FINGER_MOTION_LEFT)] || //
1493 relativeState.transientInputPresses[getInputIndex(Input::TOUCH_FINGER_MOTION_RIGHT)] || //
1494 relativeState.transientInputReleases[getInputIndex(Input::TOUCH_FINGER_MOTION_UP)] || //
1495 relativeState.transientInputReleases[getInputIndex(Input::TOUCH_FINGER_MOTION_DOWN)] || //
1496 relativeState.transientInputReleases[getInputIndex(Input::TOUCH_FINGER_MOTION_LEFT)] || //
1497 relativeState.transientInputReleases[getInputIndex(Input::TOUCH_FINGER_MOTION_RIGHT)];
1498 }
1499
1520 return currentState.touchPressure;
1521 }
1522
1543 return previousState.touchPressure;
1544 }
1545
1568 if (currentState.touchPressure && previousState.touchPressure) {
1569 return *currentState.touchPressure - *previousState.touchPressure;
1570 }
1571 return {};
1572 }
1573
1590 [[nodiscard]] GREM_ALWAYS_INLINE bool touchJustChangedPressure() const noexcept {
1591 return relativeState.transientInputPresses[getInputIndex(Input::TOUCH_FINGER_PRESSURE)] || //
1592 relativeState.transientInputReleases[getInputIndex(Input::TOUCH_FINGER_PRESSURE)];
1593 }
1594
1610 [[nodiscard]] GREM_ALWAYS_INLINE float getRelativePinchScale() const noexcept {
1611 return relativeState.transientPinchScale;
1612 }
1613
1628 [[nodiscard]] GREM_ALWAYS_INLINE bool pinchJustScaled() const noexcept {
1629 return relativeState.transientInputPresses[getInputIndex(Input::PINCH_FINGERS_MOTION_TOGETHER)] || //
1630 relativeState.transientInputPresses[getInputIndex(Input::PINCH_FINGERS_MOTION_TOGETHER)];
1631 }
1632
1653 return currentState.controllerLeftStickPosition;
1654 }
1655
1676 return previousState.controllerLeftStickPosition;
1677 }
1678
1701 if (currentState.controllerLeftStickPosition && previousState.controllerLeftStickPosition) {
1702 return i32vec2{*currentState.controllerLeftStickPosition} - i32vec2{*previousState.controllerLeftStickPosition};
1703 }
1704 return {};
1705 }
1706
1725 [[nodiscard]] GREM_ALWAYS_INLINE bool controllerLeftStickJustMoved() const noexcept {
1726 return relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_LEFT_STICK_UP)] || //
1727 relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_LEFT_STICK_DOWN)] || //
1728 relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_LEFT_STICK_LEFT)] || //
1729 relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_LEFT_STICK_RIGHT)] || //
1730 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_LEFT_STICK_UP)] || //
1731 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_LEFT_STICK_DOWN)] || //
1732 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_LEFT_STICK_LEFT)] || //
1733 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_LEFT_STICK_RIGHT)];
1734 }
1735
1756 return currentState.controllerRightStickPosition;
1757 }
1758
1779 return previousState.controllerRightStickPosition;
1780 }
1781
1804 if (currentState.controllerRightStickPosition && previousState.controllerRightStickPosition) {
1805 return i32vec2{*currentState.controllerRightStickPosition} - i32vec2{*previousState.controllerRightStickPosition};
1806 }
1807 return {};
1808 }
1809
1828 [[nodiscard]] GREM_ALWAYS_INLINE bool controllerRightStickJustMoved() const noexcept {
1829 return relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_STICK_UP)] || //
1830 relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_STICK_DOWN)] || //
1831 relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_STICK_LEFT)] || //
1832 relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_STICK_RIGHT)] || //
1833 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_STICK_UP)] || //
1834 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_STICK_DOWN)] || //
1835 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_STICK_LEFT)] || //
1836 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_STICK_RIGHT)];
1837 }
1838
1858 return currentState.controllerLeftTriggerPosition;
1859 }
1860
1880 return previousState.controllerLeftTriggerPosition;
1881 }
1882
1904 if (currentState.controllerLeftTriggerPosition && previousState.controllerLeftTriggerPosition) {
1905 return static_cast<int32_t>(*currentState.controllerLeftTriggerPosition) - static_cast<int32_t>(*previousState.controllerLeftTriggerPosition);
1906 }
1907 return {};
1908 }
1909
1927 [[nodiscard]] GREM_ALWAYS_INLINE bool controllerLeftTriggerJustMoved() const noexcept {
1928 return relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_LEFT_TRIGGER)] || //
1929 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_LEFT_TRIGGER)];
1930 }
1931
1951 return currentState.controllerRightTriggerPosition;
1952 }
1953
1973 return previousState.controllerRightTriggerPosition;
1974 }
1975
1997 if (currentState.controllerRightTriggerPosition && previousState.controllerRightTriggerPosition) {
1998 return static_cast<int32_t>(*currentState.controllerRightTriggerPosition) - static_cast<int32_t>(*previousState.controllerRightTriggerPosition);
1999 }
2000 return {};
2001 }
2002
2020 [[nodiscard]] GREM_ALWAYS_INLINE bool controllerRightTriggerJustMoved() const noexcept {
2021 return relativeState.transientInputPresses[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_TRIGGER)] || //
2022 relativeState.transientInputReleases[getInputIndex(Input::CONTROLLER_AXIS_RIGHT_TRIGGER)];
2023 }
2024
2040 [[nodiscard]] GREM_ALWAYS_INLINE bool isPressed(OutputIndex outputIndex) const noexcept {
2041 return getCurrentState(outputIndex).activePresses > 0;
2042 }
2043
2059 [[nodiscard]] GREM_ALWAYS_INLINE bool wasPreviouslyPressed(OutputIndex outputIndex) const noexcept {
2060 return getPreviousState(outputIndex).activePresses > 0;
2061 }
2062
2076 [[nodiscard]] GREM_ALWAYS_INLINE bool justPressed(OutputIndex outputIndex) const noexcept {
2077 return outputIndex < OUTPUT_COUNT && relativeState.transientOutputPresses[outputIndex];
2078 }
2079
2093 [[nodiscard]] GREM_ALWAYS_INLINE bool justReleased(OutputIndex outputIndex) const noexcept {
2094 return outputIndex < OUTPUT_COUNT && relativeState.transientOutputReleases[outputIndex];
2095 }
2096
2109 [[nodiscard]] ControlState getCurrentState(OutputIndex outputIndex) const noexcept {
2110 if (outputIndex >= OUTPUT_COUNT) {
2111 [[unlikely]];
2112 return {.activePresses = 0, .value = 0.0f};
2113 }
2114
2115 ControlState result = currentState.outputExternalStates[outputIndex];
2116 if (const auto it = boundInputs.find(outputIndex); it != boundInputs.end()) {
2117 for (const Input input : it->second) {
2118 const ControlState inputState = currentState.inputStates[getInputIndex(input)];
2119 result.activePresses += inputState.activePresses;
2120 result.value += inputState.value;
2121 }
2122 }
2123 return result;
2124 }
2125
2139 [[nodiscard]] ControlState getPreviousState(OutputIndex outputIndex) const noexcept {
2140 if (outputIndex >= OUTPUT_COUNT) {
2141 [[unlikely]];
2142 return {.activePresses = 0, .value = 0.0f};
2143 }
2144
2145 ControlState result = previousState.outputExternalStates[outputIndex];
2146 if (const auto it = boundInputs.find(outputIndex); it != boundInputs.end()) {
2147 for (const Input input : it->second) {
2148 const ControlState inputState = currentState.inputStates[getInputIndex(input)];
2149 result.activePresses += inputState.activePresses;
2150 result.value += inputState.value;
2151 }
2152 }
2153 return result;
2154 }
2155
2169 [[nodiscard]] ControlDelta getRelativeState(OutputIndex outputIndex) const noexcept {
2170 if (outputIndex >= OUTPUT_COUNT) {
2171 [[unlikely]];
2172 return {.addedPresses = 0, .motion = 0.0f};
2173 }
2174
2175 ControlDelta result = relativeState.outputExternalDeltas[outputIndex];
2176 if (const auto it = boundInputs.find(outputIndex); it != boundInputs.end()) {
2177 for (const Input input : it->second) {
2178 const ControlDelta inputDelta = relativeState.inputDeltas[getInputIndex(input)];
2179 result.addedPresses += inputDelta.addedPresses;
2180 result.motion += inputDelta.motion;
2181 }
2182 }
2183 return result;
2184 }
2185
2203 [[nodiscard]] ControlState getCurrentState1D(OutputIndex outputNegative, OutputIndex outputPositive) const noexcept {
2204 const ControlState stateNegative = getCurrentState(outputNegative);
2205 const ControlState statePositive = getCurrentState(outputPositive);
2206 return {
2207 .activePresses = max(statePositive.activePresses, int32_t{0}) - max(stateNegative.activePresses, int32_t{0}),
2208 .value = max(statePositive.value, 0.0f) - max(stateNegative.value, 0.0f),
2209 };
2210 }
2211
2230 [[nodiscard]] ControlState getPreviousState1D(OutputIndex outputNegative, OutputIndex outputPositive) const noexcept {
2231 const ControlState stateNegative = getPreviousState(outputNegative);
2232 const ControlState statePositive = getPreviousState(outputPositive);
2233 return {
2234 .activePresses = max(statePositive.activePresses, int32_t{0}) - max(stateNegative.activePresses, int32_t{0}),
2235 .value = max(statePositive.value, 0.0f) - max(stateNegative.value, 0.0f),
2236 };
2237 }
2238
2257 [[nodiscard]] ControlDelta getRelativeState1D(OutputIndex outputNegative, OutputIndex outputPositive) const noexcept {
2258 const ControlDelta deltaNegative = getRelativeState(outputNegative);
2259 const ControlDelta deltaPositive = getRelativeState(outputPositive);
2260 return {
2261 .addedPresses = max(deltaPositive.addedPresses, int32_t{0}) - max(deltaNegative.addedPresses, int32_t{0}),
2262 .motion = max(deltaPositive.motion, 0.0f) - max(deltaNegative.motion, 0.0f),
2263 };
2264 }
2265
2297 [[nodiscard]] ControlState2D getCurrentState2D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY,
2298 OutputIndex outputPositiveY) const noexcept {
2299 const ControlState stateX = getCurrentState1D(outputNegativeX, outputPositiveX);
2300 const ControlState stateY = getCurrentState1D(outputNegativeY, outputPositiveY);
2301 return {
2302 .activePresses{stateX.activePresses, stateY.activePresses},
2303 .value{stateX.value, stateY.value},
2304 };
2305 }
2306
2331 [[nodiscard]] ControlState2D getPreviousState2D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY,
2332 OutputIndex outputPositiveY) const noexcept {
2333 const ControlState stateX = getPreviousState1D(outputNegativeX, outputPositiveX);
2334 const ControlState stateY = getPreviousState1D(outputNegativeY, outputPositiveY);
2335 return {
2336 .activePresses{stateX.activePresses, stateY.activePresses},
2337 .value{stateX.value, stateY.value},
2338 };
2339 }
2340
2365 [[nodiscard]] ControlDelta2D getRelativeState2D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY,
2366 OutputIndex outputPositiveY) const noexcept {
2367 const ControlDelta deltaX = getRelativeState1D(outputNegativeX, outputPositiveX);
2368 const ControlDelta deltaY = getRelativeState1D(outputNegativeY, outputPositiveY);
2369 return {
2370 .addedPresses{deltaX.addedPresses, deltaY.addedPresses},
2371 .motion{deltaX.motion, deltaY.motion},
2372 };
2373 }
2374
2413 [[nodiscard]] ControlState3D getCurrentState3D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY,
2414 OutputIndex outputNegativeZ, OutputIndex outputPositiveZ) const noexcept {
2415 const ControlState stateX = getCurrentState1D(outputNegativeX, outputPositiveX);
2416 const ControlState stateY = getCurrentState1D(outputNegativeY, outputPositiveY);
2417 const ControlState stateZ = getCurrentState1D(outputNegativeZ, outputPositiveZ);
2418 return {
2419 .activePresses{stateX.activePresses, stateY.activePresses, stateZ.activePresses},
2420 .value{stateX.value, stateY.value, stateZ.value},
2421 };
2422 }
2423
2454 [[nodiscard]] ControlState3D getPreviousState3D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY,
2455 OutputIndex outputNegativeZ, OutputIndex outputPositiveZ) const noexcept {
2456 const ControlState stateX = getPreviousState1D(outputNegativeX, outputPositiveX);
2457 const ControlState stateY = getPreviousState1D(outputNegativeY, outputPositiveY);
2458 const ControlState stateZ = getPreviousState1D(outputNegativeZ, outputPositiveZ);
2459 return {
2460 .activePresses{stateX.activePresses, stateY.activePresses, stateZ.activePresses},
2461 .value{stateX.value, stateY.value, stateZ.value},
2462 };
2463 }
2464
2495 [[nodiscard]] ControlDelta3D getRelativeState3D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY,
2496 OutputIndex outputNegativeZ, OutputIndex outputPositiveZ) const noexcept {
2497 const ControlDelta deltaX = getRelativeState1D(outputNegativeX, outputPositiveX);
2498 const ControlDelta deltaY = getRelativeState1D(outputNegativeY, outputPositiveY);
2499 const ControlDelta deltaZ = getRelativeState1D(outputNegativeZ, outputPositiveZ);
2500 return {
2501 .addedPresses{deltaX.addedPresses, deltaY.addedPresses, deltaZ.addedPresses},
2502 .motion{deltaX.motion, deltaY.motion, deltaZ.motion},
2503 };
2504 }
2505
2523 [[nodiscard]] GREM_ALWAYS_INLINE bool isPressed(Input input) const noexcept {
2524 return getCurrentState(input).activePresses > 0;
2525 }
2526
2545 [[nodiscard]] GREM_ALWAYS_INLINE bool wasPreviouslyPressed(Input input) const noexcept {
2546 return getPreviousState(input).activePresses > 0;
2547 }
2548
2567 [[nodiscard]] GREM_ALWAYS_INLINE bool justPressed(Input input) const noexcept {
2568 const size_t inputIndex = getInputIndex(input);
2569 return inputIndex < INPUT_COUNT && relativeState.transientInputPresses[inputIndex];
2570 }
2571
2590 [[nodiscard]] GREM_ALWAYS_INLINE bool justReleased(Input input) const noexcept {
2591 const size_t inputIndex = getInputIndex(input);
2592 return inputIndex < INPUT_COUNT && relativeState.transientInputReleases[inputIndex];
2593 }
2594
2611 [[nodiscard]] GREM_ALWAYS_INLINE ControlState getCurrentState(Input input) const noexcept {
2612 const size_t inputIndex = getInputIndex(input);
2613 return (inputIndex < INPUT_COUNT) ? currentState.inputStates[inputIndex] : ControlState{.activePresses = 0, .value = 0.0f};
2614 }
2615
2632 [[nodiscard]] GREM_ALWAYS_INLINE ControlState getPreviousState(Input input) const noexcept {
2633 const size_t inputIndex = getInputIndex(input);
2634 return (inputIndex < INPUT_COUNT) ? previousState.inputStates[inputIndex] : ControlState{.activePresses = 0, .value = 0.0f};
2635 }
2636
2653 [[nodiscard]] GREM_ALWAYS_INLINE ControlDelta getRelativeState(Input input) const noexcept {
2654 const size_t inputIndex = getInputIndex(input);
2655 return (inputIndex < INPUT_COUNT) ? relativeState.inputDeltas[inputIndex] : ControlDelta{.addedPresses = 0, .motion = 0.0f};
2656 }
2657
2678 [[nodiscard]] GREM_ALWAYS_INLINE ControlState getCurrentState1D(Input inputNegative, Input inputPositive) const noexcept {
2679 const ControlState stateNegative = getCurrentState(inputNegative);
2680 const ControlState statePositive = getCurrentState(inputPositive);
2681 return {
2682 .activePresses = max(statePositive.activePresses, int32_t{0}) - max(stateNegative.activePresses, int32_t{0}),
2683 .value = max(statePositive.value, 0.0f) - max(stateNegative.value, 0.0f),
2684 };
2685 }
2686
2707 [[nodiscard]] GREM_ALWAYS_INLINE ControlState getPreviousState1D(Input inputNegative, Input inputPositive) const noexcept {
2708 const ControlState stateNegative = getPreviousState(inputNegative);
2709 const ControlState statePositive = getPreviousState(inputPositive);
2710 return {
2711 .activePresses = max(statePositive.activePresses, int32_t{0}) - max(stateNegative.activePresses, int32_t{0}),
2712 .value = max(statePositive.value, 0.0f) - max(stateNegative.value, 0.0f),
2713 };
2714 }
2715
2735 [[nodiscard]] GREM_ALWAYS_INLINE ControlDelta getRelativeState1D(Input inputNegative, Input inputPositive) const noexcept {
2736 const ControlDelta deltaNegative = getRelativeState(inputNegative);
2737 const ControlDelta deltaPositive = getRelativeState(inputPositive);
2738 return {
2739 .addedPresses = max(deltaPositive.addedPresses, int32_t{0}) - max(deltaNegative.addedPresses, int32_t{0}),
2740 .motion = max(deltaPositive.motion, 0.0f) - max(deltaNegative.motion, 0.0f),
2741 };
2742 }
2743
2768 [[nodiscard]] ControlState2D getCurrentState2D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY) const noexcept {
2769 const ControlState stateX = getCurrentState1D(inputNegativeX, inputPositiveX);
2770 const ControlState stateY = getCurrentState1D(inputNegativeY, inputPositiveY);
2771 return {
2772 .activePresses{stateX.activePresses, stateY.activePresses},
2773 .value{stateX.value, stateY.value},
2774 };
2775 }
2776
2801 [[nodiscard]] ControlState2D getPreviousState2D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY) const noexcept {
2802 const ControlState stateX = getPreviousState1D(inputNegativeX, inputPositiveX);
2803 const ControlState stateY = getPreviousState1D(inputNegativeY, inputPositiveY);
2804 return {
2805 .activePresses{stateX.activePresses, stateY.activePresses},
2806 .value{stateX.value, stateY.value},
2807 };
2808 }
2809
2835 [[nodiscard]] ControlDelta2D getRelativeState2D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY) const noexcept {
2836 const ControlDelta deltaX = getRelativeState1D(inputNegativeX, inputPositiveX);
2837 const ControlDelta deltaY = getRelativeState1D(inputNegativeY, inputPositiveY);
2838 return {
2839 .addedPresses{deltaX.addedPresses, deltaY.addedPresses},
2840 .motion{deltaX.motion, deltaY.motion},
2841 };
2842 }
2843
2872 [[nodiscard]] ControlState3D getCurrentState3D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY, Input inputNegativeZ,
2873 Input inputPositiveZ) const noexcept {
2874 const ControlState stateX = getCurrentState1D(inputNegativeX, inputPositiveX);
2875 const ControlState stateY = getCurrentState1D(inputNegativeY, inputPositiveY);
2876 const ControlState stateZ = getCurrentState1D(inputNegativeZ, inputPositiveZ);
2877 return {
2878 .activePresses{stateX.activePresses, stateY.activePresses, stateZ.activePresses},
2879 .value{stateX.value, stateY.value, stateZ.value},
2880 };
2881 }
2882
2911 [[nodiscard]] ControlState3D getPreviousState3D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY, Input inputNegativeZ,
2912 Input inputPositiveZ) const noexcept {
2913 const ControlState stateX = getPreviousState1D(inputNegativeX, inputPositiveX);
2914 const ControlState stateY = getPreviousState1D(inputNegativeY, inputPositiveY);
2915 const ControlState stateZ = getPreviousState1D(inputNegativeZ, inputPositiveZ);
2916 return {
2917 .activePresses{stateX.activePresses, stateY.activePresses, stateZ.activePresses},
2918 .value{stateX.value, stateY.value, stateZ.value},
2919 };
2920 }
2921
2950 [[nodiscard]] ControlDelta3D getRelativeState3D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY, Input inputNegativeZ,
2951 Input inputPositiveZ) const noexcept {
2952 const ControlDelta deltaX = getRelativeState1D(inputNegativeX, inputPositiveX);
2953 const ControlDelta deltaY = getRelativeState1D(inputNegativeY, inputPositiveY);
2954 const ControlDelta deltaZ = getRelativeState1D(inputNegativeZ, inputPositiveZ);
2955 return {
2956 .addedPresses{deltaX.addedPresses, deltaY.addedPresses, deltaZ.addedPresses},
2957 .motion{deltaX.motion, deltaY.motion, deltaZ.motion},
2958 };
2959 }
2960
2968 template <enumeration... Actions>
2969 GREM_ALWAYS_INLINE void bind(Input input, Actions... actions) requires((!same_as<Actions, Input> && !same_as<Actions, OutputIndex>) && ...) {
2970 bind(input, {getOutputIndex(actions)...});
2971 }
2972
2980 template <enumeration Action>
2982 addBinding(input, getOutputIndex(action));
2983 }
2984
2992 template <enumeration... Actions>
2993 GREM_ALWAYS_INLINE void addBindings(Input input, Actions... actions) requires((!same_as<Actions, Input> && !same_as<Actions, OutputIndex>) && ...) {
2994 addBindings(input, {getOutputIndex(actions)...});
2995 }
2996
3004 template <enumeration Action>
3005 [[nodiscard]] GREM_ALWAYS_INLINE bool isPressed(Action action) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3006 return isPressed(getOutputIndex(action));
3007 }
3008
3016 template <enumeration Action>
3017 [[nodiscard]] GREM_ALWAYS_INLINE bool wasPreviouslyPressed(Action action) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3018 return wasPreviouslyPressed(getOutputIndex(action));
3019 }
3020
3028 template <enumeration Action>
3029 [[nodiscard]] GREM_ALWAYS_INLINE bool justPressed(Action action) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3030 return justPressed(getOutputIndex(action));
3031 }
3032
3040 template <enumeration Action>
3041 [[nodiscard]] GREM_ALWAYS_INLINE bool justReleased(Action action) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3042 return justReleased(getOutputIndex(action));
3043 }
3044
3052 template <enumeration Action>
3054 return getCurrentState(getOutputIndex(action));
3055 }
3056
3064 template <enumeration Action>
3066 return getPreviousState(getOutputIndex(action));
3067 }
3068
3076 template <enumeration Action>
3078 return getRelativeState(getOutputIndex(action));
3079 }
3080
3088 template <enumeration Action>
3089 [[nodiscard]] GREM_ALWAYS_INLINE ControlState getCurrentState1D(Action actionNegative, Action actionPositive) const noexcept
3091 return getCurrentState1D( //
3092 getOutputIndex(actionNegative), //
3093 getOutputIndex(actionPositive));
3094 }
3095
3103 template <enumeration Action>
3104 [[nodiscard]] GREM_ALWAYS_INLINE ControlState getPreviousState1D(Action actionNegative, Action actionPositive) const noexcept
3106 return getPreviousState1D( //
3107 getOutputIndex(actionNegative), //
3108 getOutputIndex(actionPositive));
3109 }
3110
3118 template <enumeration Action>
3119 [[nodiscard]] GREM_ALWAYS_INLINE ControlDelta getRelativeState1D(Action actionNegative, Action actionPositive) const noexcept
3121 return getRelativeState1D( //
3122 getOutputIndex(actionNegative), //
3123 getOutputIndex(actionPositive));
3124 }
3125
3133 template <enumeration Action>
3134 [[nodiscard]] GREM_ALWAYS_INLINE ControlState2D getCurrentState2D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY) const noexcept
3136 return getCurrentState2D( //
3137 getOutputIndex(actionNegativeX), //
3138 getOutputIndex(actionPositiveX), //
3139 getOutputIndex(actionNegativeY), //
3140 getOutputIndex(actionPositiveY));
3141 }
3142
3150 template <enumeration Action>
3151 [[nodiscard]] GREM_ALWAYS_INLINE ControlState2D getPreviousState2D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY,
3152 Action actionPositiveY) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3153 return getPreviousState2D( //
3154 getOutputIndex(actionNegativeX), //
3155 getOutputIndex(actionPositiveX), //
3156 getOutputIndex(actionNegativeY), //
3157 getOutputIndex(actionPositiveY));
3158 }
3159
3167 template <enumeration Action>
3168 [[nodiscard]] GREM_ALWAYS_INLINE ControlDelta2D getRelativeState2D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY,
3169 Action actionPositiveY) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3170 return getRelativeState2D( //
3171 getOutputIndex(actionNegativeX), //
3172 getOutputIndex(actionPositiveX), //
3173 getOutputIndex(actionNegativeY), //
3174 getOutputIndex(actionPositiveY));
3175 }
3176
3184 template <enumeration Action>
3185 [[nodiscard]] GREM_ALWAYS_INLINE ControlState3D getCurrentState3D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY,
3186 Action actionNegativeZ, Action actionPositiveZ) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3187 return getCurrentState3D( //
3188 getOutputIndex(actionNegativeX), //
3189 getOutputIndex(actionPositiveX), //
3190 getOutputIndex(actionNegativeY), //
3191 getOutputIndex(actionPositiveY), //
3192 getOutputIndex(actionNegativeZ), //
3193 getOutputIndex(actionPositiveZ));
3194 }
3195
3203 template <enumeration Action>
3204 [[nodiscard]] GREM_ALWAYS_INLINE ControlState3D getPreviousState3D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY,
3205 Action actionNegativeZ, Action actionPositiveZ) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3206 return getPreviousState3D( //
3207 getOutputIndex(actionNegativeX), //
3208 getOutputIndex(actionPositiveX), //
3209 getOutputIndex(actionNegativeY), //
3210 getOutputIndex(actionPositiveY), //
3211 getOutputIndex(actionNegativeZ), //
3212 getOutputIndex(actionPositiveZ));
3213 }
3214
3222 template <enumeration Action>
3223 [[nodiscard]] GREM_ALWAYS_INLINE ControlDelta3D getRelativeState3D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY,
3224 Action actionNegativeZ, Action actionPositiveZ) const noexcept requires(!same_as<Action, Input> && !same_as<Action, OutputIndex>) {
3225 return getRelativeState3D( //
3226 getOutputIndex(actionNegativeX), //
3227 getOutputIndex(actionPositiveX), //
3228 getOutputIndex(actionNegativeY), //
3229 getOutputIndex(actionPositiveY), //
3230 getOutputIndex(actionNegativeZ), //
3231 getOutputIndex(actionPositiveZ));
3232 }
3233
3234private:
3235 struct AbsoluteState {
3236 Optional<vec2> mousePosition{};
3237 Optional<vec2> touchPosition{};
3238 Optional<float> touchPressure{};
3239 Optional<i16vec2> controllerLeftStickPosition{};
3240 Optional<i16vec2> controllerRightStickPosition{};
3241 Optional<int16_t> controllerLeftTriggerPosition{};
3242 Optional<int16_t> controllerRightTriggerPosition{};
3244 Array<ControlState, OUTPUT_COUNT> outputExternalStates{};
3245 };
3246
3247 struct RelativeState {
3248 vec2 transientMouseWheelScroll{};
3249 float transientPinchScale = 1.0f;
3251 Array<ControlDelta, OUTPUT_COUNT> outputExternalDeltas{};
3252 BitArray<INPUT_COUNT> transientInputPresses{};
3253 BitArray<INPUT_COUNT> transientInputReleases{};
3254 BitArray<OUTPUT_COUNT> transientOutputPresses{};
3255 BitArray<OUTPUT_COUNT> transientOutputReleases{};
3256 };
3257
3258 template <typename Action>
3259 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr OutputIndex getOutputIndex(Action action) noexcept {
3260 return static_cast<OutputIndex>(static_cast<std::underlying_type_t<Action>>(action));
3261 }
3262
3263 GREM_API(events)
3264 void setCursorPosition(TimePoint timestamp, Optional<vec2>& position, vec2 newPosition, vec2 relativeMotion, vec2 sensitivity, Input inputLeft, Input inputRight, Input inputUp,
3265 Input inputDown);
3266
3267 void setMousePosition(TimePoint timestamp, vec2 newPosition, vec2 relativeMotion) {
3268 setCursorPosition(timestamp, currentState.mousePosition, newPosition, relativeMotion, options.preferences.mouseSensitivity, Input::MOUSE_MOTION_LEFT,
3270 }
3271
3272 GREM_API(events) void scrollMouseWheel(TimePoint timestamp, vec2 scrollAmount);
3273
3274 void setTouchPosition(TimePoint timestamp, vec2 newPosition, vec2 relativeMotion) {
3275 setCursorPosition(timestamp, currentState.touchPosition, newPosition, relativeMotion, options.preferences.touchMotionSensitivity, Input::TOUCH_FINGER_MOTION_LEFT,
3277 }
3278
3279 GREM_API(events) void setTouchPressure(TimePoint timestamp, float newPressure);
3280
3281 GREM_API(events) void pinchFingers(TimePoint timestamp, float scale);
3282
3283 GREM_API(events)
3284 void setControllerStickPosition(TimePoint timestamp, Optional<i16vec2>& position, i16vec2 newPosition, vec2 sensitivity, float curveExponent, float innerDeadzone,
3285 float outerDeadzone, Input inputLeft, Input inputRight, Input inputUp, Input inputDown);
3286
3287 void setControllerLeftStickPosition(TimePoint timestamp, i16vec2 newPosition) {
3288 setControllerStickPosition(timestamp, currentState.controllerLeftStickPosition, newPosition, options.preferences.controllerLeftStickSensitivity,
3289 options.preferences.controllerLeftStickCurveExponent, options.preferences.controllerLeftStickInnerDeadzone, options.preferences.controllerLeftStickOuterDeadzone,
3291 }
3292
3293 void setControllerRightStickPosition(TimePoint timestamp, i16vec2 newPosition) {
3294 setControllerStickPosition(timestamp, currentState.controllerRightStickPosition, newPosition, options.preferences.controllerRightStickSensitivity,
3295 options.preferences.controllerRightStickCurveExponent, options.preferences.controllerRightStickInnerDeadzone, options.preferences.controllerRightStickOuterDeadzone,
3297 }
3298
3299 GREM_API(events)
3300 void setControllerTriggerPosition(TimePoint timestamp, Optional<int16_t>& position, int16_t newPosition, float lowerDeadzone, float upperDeadzone, Input inputAxis);
3301
3302 void setControllerLeftTriggerPosition(TimePoint timestamp, int16_t newPosition) {
3303 setControllerTriggerPosition(timestamp, currentState.controllerLeftTriggerPosition, newPosition, options.preferences.controllerLeftTriggerLowerDeadzone,
3304 options.preferences.controllerLeftTriggerUpperDeadzone, Input::CONTROLLER_AXIS_LEFT_TRIGGER);
3305 }
3306
3307 void setControllerRightTriggerPosition(TimePoint timestamp, int16_t newPosition) {
3308 setControllerTriggerPosition(timestamp, currentState.controllerRightTriggerPosition, newPosition, options.preferences.controllerRightTriggerLowerDeadzone,
3309 options.preferences.controllerRightTriggerUpperDeadzone, Input::CONTROLLER_AXIS_RIGHT_TRIGGER);
3310 }
3311
3312 InputManagerPreferences initialPreferences;
3313 InputManagerOptions options;
3314 HashMap<Input, ArrayList<OutputIndex>> bindings{};
3315 HashMap<OutputIndex, ArrayList<Input>> boundInputs{};
3316 AbsoluteState currentState{};
3317 AbsoluteState previousState{};
3318 RelativeState relativeState{};
3319 ArrayList<OutputEvent> polledOutputEvents{};
3320 ArrayList<OutputEvent> pendingOutputEvents{};
3321};
3322
3323} // namespace grem::events
3324
3325#endif
#define GREM_ALWAYS_INLINE
Definition attributes.hpp:10
Definition Allocation.hpp:25
constexpr iterator begin() noexcept
Definition Allocation.hpp:433
Definition ArrayList.hpp:27
Base interface for a filesystem.
Definition Filesystem.hpp:25
String readInputFileString(CStringView filepath) const
Open an input file in the virtual filesystem for reading and read its full contents into a string of ...
Definition Filesystem.hpp:382
virtual void createParentOutputDirectories(CStringView filepath)=0
Create any missing parent directories above a host directory relative to the current output directory...
virtual OutputFileHandle openEmptyOutputFile(CStringView filepath)=0
Create a file relative to the current output directory and open it for writing, overwriting any exist...
Definition FunctionView.hpp:29
Definition HashMap.hpp:30
constexpr iterator end() noexcept
Definition HashMap.hpp:712
constexpr iterator find(const Key &key)
Definition HashMap.hpp:626
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
GREM_ALWAYS_INLINE void write(Span< const byte > data)
Write data to the end of an open file.
Definition File.hpp:809
Definition Reader.hpp:658
Definition Span.hpp:146
constexpr size_type size() const noexcept
Definition Span.hpp:207
friend class Variant
Definition Variant.hpp:1402
Output event base.
Definition InputManager.hpp:405
GREM_ALWAYS_INLINE ControlState getState() const noexcept
Get the raw total absolute value of the output after the event took place.
Definition InputManager.hpp:447
GREM_ALWAYS_INLINE ControlDelta getDelta() const noexcept
Get the raw total relative value that was applied to the output by the event.
Definition InputManager.hpp:457
GREM_ALWAYS_INLINE TimePoint getTimestamp() const noexcept
Get the timestamp of the event.
Definition InputManager.hpp:412
GREM_ALWAYS_INLINE OutputIndex getOutputIndex() const noexcept
Get the affected output number.
Definition InputManager.hpp:423
GREM_ALWAYS_INLINE bool isAction(Action action) const noexcept
Check if the affected output is a certain "action" of any enum type, which is interpreted as correspo...
Definition InputManager.hpp:437
System for mapping physical Input controls to abstract output numbers and processing input events tha...
Definition InputManager.hpp:336
GREM_ALWAYS_INLINE Optional< i32vec2 > getRelativeControllerLeftStickMotion() const noexcept
Get the relative motion between the last two known positions of the left analog stick of the connecte...
Definition InputManager.hpp:1700
Allocation< Binding > getBindings() const
Get all active bindings of this input manager.
Definition InputManager.hpp:1186
GREM_ALWAYS_INLINE Optional< float > getPreviousTouchPressure() const noexcept
Get the second last known touch finger pressure processed by the input manager.
Definition InputManager.hpp:1542
void loadConfiguration(String fileContents, CStringView filepath={}, FunctionView< void(StringView key, json::Reader &reader)> readExtraProperty=[](StringView, json::Reader &) -> void {})
Apply the configuration specified in a JSON configuration file, assuming a set of abstract output num...
Definition InputManager.hpp:607
ControlDelta2D getRelativeState2D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY) const noexcept
Get the combined relative delta of four specific inputs along two orthogonal axes.
Definition InputManager.hpp:2835
GREM_ALWAYS_INLINE Optional< vec2 > getRelativeTouchMotion() const noexcept
Get the relative motion between the last two known touch finger positions processed by the input mana...
Definition InputManager.hpp:1466
GREM_ALWAYS_INLINE void setPreferences(const InputManagerPreferences &preferences) noexcept
Set the user preferences of the input manager.
Definition InputManager.hpp:1102
ControlState2D getPreviousState2D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY) const noexcept
Get the previous combined absolute state of four specific inputs along two orthogonal axes.
Definition InputManager.hpp:2801
ControlDelta2D getRelativeState2D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY) const noexcept
Get the combined relative delta of four specific outputs along two orthogonal axes,...
Definition InputManager.hpp:2365
GREM_ALWAYS_INLINE ControlDelta getRelativeState1D(Action actionNegative, Action actionPositive) const noexcept
Like getRelativeState1D(OutputIndex, OutputIndex) const, but accepts "actions" of any enum type,...
Definition InputManager.hpp:3119
GREM_ALWAYS_INLINE bool justReleased(Action action) const noexcept
Like justReleased(OutputIndex) const, but accepts an "action" of any enum type, which is interpreted ...
Definition InputManager.hpp:3041
GREM_ALWAYS_INLINE bool controllerRightTriggerJustMoved() const noexcept
Check if the controller right trigger just moved on the current frame.
Definition InputManager.hpp:2020
void unbindAll() noexcept
Remove all bindings from all inputs.
GREM_ALWAYS_INLINE ControlDelta getRelativeState1D(Input inputNegative, Input inputPositive) const noexcept
Get the combined relative delta of two specific inputs along one axis.
Definition InputManager.hpp:2735
ControlState getCurrentState(OutputIndex outputIndex) const noexcept
Get the current total absolute state of a specific output, which consists of the accumulated contribu...
Definition InputManager.hpp:2109
GREM_ALWAYS_INLINE void bind(Input input, Actions... actions)
Like bind(Input, ArrayList<OutputIndex>), but accepts a pack of "actions" of any enum type,...
Definition InputManager.hpp:2969
GREM_ALWAYS_INLINE const InputManagerPreferences & getInitialPreferences() const noexcept
Get the initial user preferences of the input manager.
Definition InputManager.hpp:1146
void handleEvent(const Event &event)
Handle an event from an EventPump, which may cause updates to the internal input/output state of the ...
GREM_ALWAYS_INLINE bool touchJustMoved() const noexcept
Check if the touch finger just moved on the current frame.
Definition InputManager.hpp:1489
GREM_ALWAYS_INLINE bool controllerRightStickJustMoved() const noexcept
Check if the controller right analog stick just moved on the current frame.
Definition InputManager.hpp:1828
GREM_ALWAYS_INLINE bool isPressed(Action action) const noexcept
Like isPressed(OutputIndex) const, but accepts an "action" of any enum type, which is interpreted as ...
Definition InputManager.hpp:3005
ControlState getCurrentState1D(OutputIndex outputNegative, OutputIndex outputPositive) const noexcept
Get the current combined absolute state of two specific outputs along one axis, which consists of the...
Definition InputManager.hpp:2203
GREM_ALWAYS_INLINE bool touchJustChangedPressure() const noexcept
Check if the touch finger just changed pressure on the current frame.
Definition InputManager.hpp:1590
GREM_ALWAYS_INLINE bool justReleased(Input input) const noexcept
Check if a specific input had a release triggered on the current frame.
Definition InputManager.hpp:2590
GREM_ALWAYS_INLINE Optional< int32_t > getRelativeControllerLeftTriggerMotion() const noexcept
Get the relative motion between the last two known positions of the left trigger of the connected con...
Definition InputManager.hpp:1903
void loadConfiguration(const Filesystem &filesystem, CStringView filepath, FunctionView< void(StringView key, json::Reader &reader)> readExtraProperty=[](StringView, json::Reader &) -> void {})
Apply the configuration specified in a JSON configuration file, assuming a set of abstract output num...
Definition InputManager.hpp:683
GREM_ALWAYS_INLINE bool hasAnyBindings() const noexcept
Check if this input manager has any active bindings for any input.
Definition InputManager.hpp:1168
GREM_ALWAYS_INLINE Optional< vec2 > getCurrentMousePosition() const noexcept
Get the latest known mouse position processed by the input manager.
Definition InputManager.hpp:1261
GREM_ALWAYS_INLINE bool pinchJustScaled() const noexcept
Check if finger pinch was just performed on the current frame.
Definition InputManager.hpp:1628
GREM_ALWAYS_INLINE ControlState2D getPreviousState2D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY) const noexcept
Like getPreviousState2D(OutputIndex, OutputIndex, OutputIndex, OutputIndex) const,...
Definition InputManager.hpp:3151
GREM_ALWAYS_INLINE void setEmitOutputEvents(bool emitOutputEvents) noexcept
Set whether output events should be emitted or not.
Definition InputManager.hpp:1120
GREM_ALWAYS_INLINE bool justReleased(OutputIndex outputIndex) const noexcept
Check if a specific output had a release triggered on the current frame.
Definition InputManager.hpp:2093
ControlState3D getCurrentState3D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY, OutputIndex outputNegativeZ, OutputIndex outputPositiveZ) const noexcept
Get the current combined absolute state of six specific outputs along three orthogonal axes,...
Definition InputManager.hpp:2413
GREM_ALWAYS_INLINE ControlState getCurrentState(Action action) const noexcept
Like getCurrentState(OutputIndex) const, but accepts an "action" of any enum type,...
Definition InputManager.hpp:3053
InputManager(const InputManagerOptions &options)
Construct an input manager.
void setCurrentState(TimePoint timestamp, OutputIndex outputIndex, ControlState newState)
Set the external contribution to an output to a new state.
void resetAllStates() noexcept
Reset the states of all inputs and outputs for the current and previous frames, and clear all polled ...
Definition InputManager.hpp:983
GREM_ALWAYS_INLINE ControlState3D getPreviousState3D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY, Action actionNegativeZ, Action actionPositiveZ) const noexcept
Like getPreviousState3D(OutputIndex, OutputIndex, OutputIndex, OutputIndex, OutputIndex,...
Definition InputManager.hpp:3204
static constexpr OutputIndex OUTPUT_COUNT
The maximum supported number of separate outputs that the input manager can keep track of.
Definition InputManager.hpp:400
GREM_ALWAYS_INLINE float getRelativePinchScale() const noexcept
Get the relative scale performed by finger pinch in the last frame processed by the input manager.
Definition InputManager.hpp:1610
ControlDelta getRelativeState(OutputIndex outputIndex) const noexcept
Get the total relative delta of a specific output, which consists of the accumulated contributions fr...
Definition InputManager.hpp:2169
GREM_ALWAYS_INLINE vec2 getRelativeMouseWheelScroll() const noexcept
Get the relative distance scrolled horizontally by the mouse wheel in the last frame processed by the...
Definition InputManager.hpp:1352
ControlState getPreviousState(OutputIndex outputIndex) const noexcept
Get the previous total absolute value of a specific output, which consists of the accumulated contrib...
Definition InputManager.hpp:2139
void loadConfiguration(const Filesystem &filesystem, CStringView filepath, FunctionView< Optional< OutputIndex >(StringView actionName)> getOutputIndex, FunctionView< void(StringView key, json::Reader &reader)> readExtraProperty=[](StringView, json::Reader &) -> void {})
Apply the configuration specified in a JSON configuration file, adding to the previous bindings if an...
Definition InputManager.hpp:647
GREM_ALWAYS_INLINE bool wasPreviouslyPressed(OutputIndex outputIndex) const noexcept
Check if a specific output was pressed on the previous frame, i.e. if its contributions from all of i...
Definition InputManager.hpp:2059
GREM_ALWAYS_INLINE bool justPressed(Action action) const noexcept
Like justPressed(OutputIndex) const, but accepts an "action" of any enum type, which is interpreted a...
Definition InputManager.hpp:3029
void unbind(Input input) noexcept
Remove all bindings from a specific input.
InputManager()
Construct an input manager with the default options.
Definition InputManager.hpp:502
GREM_ALWAYS_INLINE ControlState getPreviousState1D(Action actionNegative, Action actionPositive) const noexcept
Like getPreviousState1D(OutputIndex, OutputIndex) const, but accepts "actions" of any enum type,...
Definition InputManager.hpp:3104
GREM_ALWAYS_INLINE void addBindings(Input input, Actions... actions)
Like addBindings(Input, Span<const OutputIndex>), but accepts a pack of "actions" of any enum type,...
Definition InputManager.hpp:2993
GREM_ALWAYS_INLINE Optional< vec2 > getPreviousMousePosition() const noexcept
Get the second last known mouse position processed by the input manager.
Definition InputManager.hpp:1282
GREM_ALWAYS_INLINE bool controllerLeftTriggerJustMoved() const noexcept
Check if the controller left trigger just moved on the current frame.
Definition InputManager.hpp:1927
ControlState getPreviousState1D(OutputIndex outputNegative, OutputIndex outputPositive) const noexcept
Get the previous combined absolute state of two specific outputs along one axis, which consists of th...
Definition InputManager.hpp:2230
GREM_ALWAYS_INLINE Optional< int16_t > getCurrentControllerLeftTriggerPosition() const noexcept
Get the latest known position of the left trigger of the connected controller, if there is one.
Definition InputManager.hpp:1857
ControlState3D getPreviousState3D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY, OutputIndex outputNegativeZ, OutputIndex outputPositiveZ) const noexcept
Get the previous combined absolute state of six specific outputs along three orthogonal axes,...
Definition InputManager.hpp:2454
GREM_ALWAYS_INLINE void addRelativeState(TimePoint timestamp, Action action, ControlDelta delta)
Like addRelativeState(TimePoint, OutputIndex, ControlDelta), but accepts an "action" of any enum type...
Definition InputManager.hpp:1077
GREM_ALWAYS_INLINE bool justPressed(Input input) const noexcept
Check if a specific input had a press triggered on the current frame.
Definition InputManager.hpp:2567
GREM_ALWAYS_INLINE ControlState getPreviousState(Action action) const noexcept
Like getPreviousState(OutputIndex) const, but accepts an "action" of any enum type,...
Definition InputManager.hpp:3065
GREM_ALWAYS_INLINE ControlState2D getCurrentState2D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY) const noexcept
Like getCurrentState2D(OutputIndex, OutputIndex, OutputIndex, OutputIndex) const, but accepts "action...
Definition InputManager.hpp:3134
GREM_ALWAYS_INLINE Optional< vec2 > getPreviousTouchPosition() const noexcept
Get the second last known touch finger position processed by the input manager.
Definition InputManager.hpp:1441
ControlState3D getPreviousState3D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY, Input inputNegativeZ, Input inputPositiveZ) const noexcept
Get the previous combined scaled absolute value of six specific inputs along three orthogonal axes.
Definition InputManager.hpp:2911
ControlState2D getPreviousState2D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY) const noexcept
Get the previous combined absolute state of four specific outputs along two orthogonal axes,...
Definition InputManager.hpp:2331
void addRelativeState(TimePoint timestamp, OutputIndex outputIndex, ControlDelta delta)
Apply a relative offset to the external contribution to an output for this frame only.
GREM_ALWAYS_INLINE Span< const Input > getBoundInputs(Action action) const noexcept
Like getBoundInputs(OutputIndex) const noexcept, but accepts an "action" of any enum type,...
Definition InputManager.hpp:1240
GREM_ALWAYS_INLINE ControlDelta getRelativeState(Input input) const noexcept
Get the relative delta of a specific input.
Definition InputManager.hpp:2653
uint8_t OutputIndex
Abstract output number.
Definition InputManager.hpp:394
void setCurrentState(TimePoint timestamp, Input input, ControlState newState)
Set the contribution of an input to its bound outputs to a new state.
GREM_ALWAYS_INLINE Optional< int16_t > getCurrentControllerRightTriggerPosition() const noexcept
Get the latest known position of the right trigger of the connected controller, if there is one.
Definition InputManager.hpp:1950
GREM_ALWAYS_INLINE ControlState getCurrentState1D(Input inputNegative, Input inputPositive) const noexcept
Get the current combined absolute state of two specific inputs along one axis.
Definition InputManager.hpp:2678
GREM_ALWAYS_INLINE void addBinding(Input input, Action action)
Like addBinding(Input, OutputIndex), but accepts a pack of "actions" of any enum type,...
Definition InputManager.hpp:2981
GREM_ALWAYS_INLINE ControlState getCurrentState1D(Action actionNegative, Action actionPositive) const noexcept
Like getCurrentState1D(OutputIndex, OutputIndex) const, but accepts "actions" of any enum type,...
Definition InputManager.hpp:3089
GREM_ALWAYS_INLINE Optional< i16vec2 > getPreviousControllerRightStickPosition() const noexcept
Get the second last known position of the right analog stick of the connected controller,...
Definition InputManager.hpp:1778
GREM_ALWAYS_INLINE void addBinding(Input input, OutputIndex outputIndex)
Bind a physical input to an abstract output number, adding to the previous binding if one already exi...
Definition InputManager.hpp:945
GREM_ALWAYS_INLINE bool wasPreviouslyPressed(Action action) const noexcept
Like wasPreviouslyPressed(OutputIndex) const, but accepts an "action" of any enum type,...
Definition InputManager.hpp:3017
GREM_ALWAYS_INLINE bool mouseWheelJustScrolledVertically() const noexcept
Check if the mouse wheel was just scrolled vertically on the current frame.
Definition InputManager.hpp:1393
void releaseAll(TimePoint timestamp)
Release all currently held inputs and outputs for the current frame, reset the positions of all input...
GREM_ALWAYS_INLINE Optional< i32vec2 > getRelativeControllerRightStickMotion() const noexcept
Get the relative motion between the last two known positions of the right analog stick of the connect...
Definition InputManager.hpp:1803
GREM_ALWAYS_INLINE Span< const OutputEvent > getLatestPolledOutputEvents() const noexcept
Get the latest output events in the internal event buffer that occured since the last call to pollOut...
Definition InputManager.hpp:886
GREM_ALWAYS_INLINE bool controllerLeftStickJustMoved() const noexcept
Check if the controller left analog stick just moved on the current frame.
Definition InputManager.hpp:1725
GREM_ALWAYS_INLINE Optional< i16vec2 > getCurrentControllerRightStickPosition() const noexcept
Get the latest known position of the right analog stick of the connected controller,...
Definition InputManager.hpp:1755
GREM_ALWAYS_INLINE bool wasPreviouslyPressed(Input input) const noexcept
Check if a specific input was in a pressed state on the previous frame.
Definition InputManager.hpp:2545
GREM_ALWAYS_INLINE Optional< int32_t > getRelativeControllerRightTriggerMotion() const noexcept
Get the relative motion between the last two known positions of the right trigger of the connected co...
Definition InputManager.hpp:1996
ControlDelta getRelativeState1D(OutputIndex outputNegative, OutputIndex outputPositive) const noexcept
Get the combined relative delta of two specific outputs along one axis, which consists of the accumul...
Definition InputManager.hpp:2257
GREM_ALWAYS_INLINE bool mouseWheelJustScrolledHorizontally() const noexcept
Check if the mouse wheel was just scrolled horizontally on the current frame.
Definition InputManager.hpp:1372
Span< const OutputEvent > pollOutputEvents()
Poll events from the input manager and update the internal event buffer.
Definition InputManager.hpp:868
GREM_ALWAYS_INLINE Optional< float > getCurrentTouchPressure() const noexcept
Get the latest known touch finger pressure processed by the input manager.
Definition InputManager.hpp:1519
String saveConfiguration(Span< const Pair< StringView, json::Variant > > extraProperties={}) const
Save the current preferences and bindings to a JSON configuration string for a set of abstract output...
Definition InputManager.hpp:736
GREM_ALWAYS_INLINE ControlState3D getCurrentState3D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY, Action actionNegativeZ, Action actionPositiveZ) const noexcept
Like getCurrentState3D(OutputIndex, OutputIndex, OutputIndex, OutputIndex, OutputIndex,...
Definition InputManager.hpp:3185
void addRelativeState(TimePoint timestamp, Input input, ControlDelta delta)
Apply a relative offset to the contribution of an input to its bound outputs for this frame only.
void saveConfiguration(Filesystem &filesystem, CStringView filepath, Span< const Pair< StringView, json::Variant > > extraProperties={}) const
Save the current preferences and bindings to a JSON configuration file for a set of abstract output n...
Definition InputManager.hpp:811
GREM_ALWAYS_INLINE Optional< i16vec2 > getPreviousControllerLeftStickPosition() const noexcept
Get the second last known position of the left analog stick of the connected controller,...
Definition InputManager.hpp:1675
GREM_ALWAYS_INLINE Optional< int16_t > getPreviousControllerRightTriggerPosition() const noexcept
Get the second last known position of the right trigger of the connected controller,...
Definition InputManager.hpp:1972
void saveConfiguration(Filesystem &filesystem, CStringView filepath, FunctionView< Optional< String >(OutputIndex outputIndex)> getActionName, Span< const Pair< StringView, json::Variant > > extraProperties={}) const
Save the current preferences and bindings to a JSON configuration file.
Definition InputManager.hpp:775
GREM_ALWAYS_INLINE Optional< int16_t > getPreviousControllerLeftTriggerPosition() const noexcept
Get the second last known position of the left trigger of the connected controller,...
Definition InputManager.hpp:1879
void loadConfiguration(String fileContents, FunctionView< Optional< OutputIndex >(StringView actionName)> getOutputIndex, FunctionView< void(StringView key, json::Reader &reader)> readExtraProperty=[](StringView, json::Reader &) -> void {})
Apply the configuration specified in a JSON configuration file, adding to the previous bindings if an...
Definition InputManager.hpp:570
GREM_ALWAYS_INLINE ControlDelta3D getRelativeState3D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY, Action actionNegativeZ, Action actionPositiveZ) const noexcept
Like getRelativeState3D(OutputIndex, OutputIndex, OutputIndex, OutputIndex, OutputIndex,...
Definition InputManager.hpp:3223
GREM_ALWAYS_INLINE const InputManagerPreferences & getPreferences() const noexcept
Get the current user preferences of the input manager.
Definition InputManager.hpp:1134
GREM_ALWAYS_INLINE ControlDelta getRelativeState(Action action) const noexcept
Like getRelativeState(OutputIndex) const, but accepts an "action" of any enum type,...
Definition InputManager.hpp:3077
GREM_ALWAYS_INLINE ControlState getPreviousState(Input input) const noexcept
Get the previous absolute value of a specific input.
Definition InputManager.hpp:2632
GREM_ALWAYS_INLINE Optional< i16vec2 > getCurrentControllerLeftStickPosition() const noexcept
Get the latest known position of the left analog stick of the connected controller,...
Definition InputManager.hpp:1652
void bind(Input input, ArrayList< OutputIndex > outputIndices)
Bind a physical input to a set of abstract output numbers, overriding the previous binding if one alr...
GREM_ALWAYS_INLINE ControlDelta2D getRelativeState2D(Action actionNegativeX, Action actionPositiveX, Action actionNegativeY, Action actionPositiveY) const noexcept
Like getRelativeState2D(OutputIndex, OutputIndex, OutputIndex, OutputIndex) const,...
Definition InputManager.hpp:3168
GREM_ALWAYS_INLINE Optional< vec2 > getCurrentTouchPosition() const noexcept
Get the latest known touch finger position processed by the input manager.
Definition InputManager.hpp:1418
ControlDelta3D getRelativeState3D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY, OutputIndex outputNegativeZ, OutputIndex outputPositiveZ) const noexcept
Get the combined relative delta of six specific outputs along three orthogonal axes,...
Definition InputManager.hpp:2495
GREM_ALWAYS_INLINE ControlState getPreviousState1D(Input inputNegative, Input inputPositive) const noexcept
Get the previous combined absolute state of two specific inputs along one axis.
Definition InputManager.hpp:2707
GREM_ALWAYS_INLINE bool isPressed(Input input) const noexcept
Check if a specific input is currently in a pressed state.
Definition InputManager.hpp:2523
GREM_ALWAYS_INLINE void setCurrentState(TimePoint timestamp, Action action, ControlState newState={.activePresses=1,.value=1.0f})
Like setCurrentState(TimePoint, OutputIndex, ControlState), but accepts an "action" of any enum type,...
Definition InputManager.hpp:1030
ControlState2D getCurrentState2D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY) const noexcept
Get the current combined absolute state of four specific inputs along two orthogonal axes.
Definition InputManager.hpp:2768
GREM_ALWAYS_INLINE ControlState getCurrentState(Input input) const noexcept
Get the current absolute value of a specific input.
Definition InputManager.hpp:2611
GREM_ALWAYS_INLINE Optional< vec2 > getRelativeMouseMotion() const noexcept
Get the relative motion between the last two known mouse positions processed by the input manager.
Definition InputManager.hpp:1306
void update()
Advance the internal state to the next frame of inputs.
Definition InputManager.hpp:829
String saveConfiguration(FunctionView< Optional< String >(OutputIndex outputIndex)> getActionName, Span< const Pair< StringView, json::Variant > > extraProperties={}) const
Save the current preferences and bindings to a JSON configuration string.
ControlState2D getCurrentState2D(OutputIndex outputNegativeX, OutputIndex outputPositiveX, OutputIndex outputNegativeY, OutputIndex outputPositiveY) const noexcept
Get the current combined absolute state of four specific outputs along two orthogonal axes,...
Definition InputManager.hpp:2297
Span< const OutputIndex > getBoundOutputs(Input input) const noexcept
Get the set of outputs that a specific input is currently bound to.
Definition InputManager.hpp:1206
GREM_ALWAYS_INLINE Optional< float > getRelativeTouchPressure() const noexcept
Get the relative pressure between the last two known touch finger pressures processed by the input ma...
Definition InputManager.hpp:1567
Span< const Input > getBoundInputs(OutputIndex outputIndex) const noexcept
Get the set of inputs that are bound to a specific output.
Definition InputManager.hpp:1225
GREM_ALWAYS_INLINE const InputManagerOptions & getOptions() const noexcept
Get the current configuration options of the input manager.
Definition InputManager.hpp:1158
GREM_ALWAYS_INLINE bool isPressed(OutputIndex outputIndex) const noexcept
Check if a specific output is currently pressed, i.e. if its contributions from all of its bound inpu...
Definition InputManager.hpp:2040
ControlState3D getCurrentState3D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY, Input inputNegativeZ, Input inputPositiveZ) const noexcept
Get the current combined scaled absolute value of six specific inputs along three orthogonal axes.
Definition InputManager.hpp:2872
GREM_ALWAYS_INLINE bool mouseJustMoved() const noexcept
Check if the mouse just moved on the current frame.
Definition InputManager.hpp:1329
void loadConfiguration(String fileContents, CStringView filepath, FunctionView< Optional< OutputIndex >(StringView actionName)> getOutputIndex, FunctionView< void(StringView key, json::Reader &reader)> readExtraProperty=[](StringView, json::Reader &) -> void {})
Apply the configuration specified in a JSON configuration file, adding to the previous bindings if an...
void addBindings(Input input, Span< const OutputIndex > outputIndices)
Bind a physical input to a set of abstract output numbers, adding to the previous binding if one alre...
GREM_ALWAYS_INLINE bool justPressed(OutputIndex outputIndex) const noexcept
Check if a specific output had a press triggered on the current frame.
Definition InputManager.hpp:2076
ControlDelta3D getRelativeState3D(Input inputNegativeX, Input inputPositiveX, Input inputNegativeY, Input inputPositiveY, Input inputNegativeZ, Input inputPositiveZ) const noexcept
Get the current combined scaled relative value of six specific outputs along three orthogonal axes.
Definition InputManager.hpp:2950
JSON value type.
Definition json.hpp:538
Definition concepts.hpp:94
Definition concepts.hpp:35
constexpr String convertToLowercaseString(StringView string)
Convert each character in a string to its corresponding lowercase ASCII letter (a-z) if it has one.
Definition ascii.hpp:210
constexpr String convertToUppercaseString(StringView string)
Convert each character in a string to its corresponding uppercase ASCII letter (A-Z) if it has one.
Definition ascii.hpp:250
Definition controller.hpp:11
constexpr size_t getInputIndex(Input input) noexcept
Get the 0-based index of an Input.
Definition Input.hpp:207
Input
General identifier for a specific control on a physical input device, such as a certain keyboard key,...
Definition Input.hpp:182
@ CONTROLLER_AXIS_RIGHT_TRIGGER
Controller right trigger (R Trigger/R2).
Definition Input.hpp:184
@ TOUCH_FINGER_PRESSURE
Finger pressure.
Definition Input.hpp:184
@ TOUCH_FINGER_MOTION_RIGHT
Finger right movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_LEFT_STICK_RIGHT
Controller left analog stick rightward movement.
Definition Input.hpp:184
@ MOUSE_MOTION_LEFT
Mouse left movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_RIGHT_STICK_RIGHT
Controller right analog stick rightward movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_LEFT_STICK_UP
Controller left analog stick upward movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_RIGHT_STICK_UP
Controller right analog stick upward movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_LEFT_STICK_DOWN
Controller left analog stick downward movement.
Definition Input.hpp:184
@ MOUSE_SCROLL_LEFT
Mouse scroll wheel leftward movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_LEFT_TRIGGER
Controller left trigger (L Trigger/L2).
Definition Input.hpp:184
@ MOUSE_SCROLL_DOWN
Mouse scroll wheel downward movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_LEFT_STICK_LEFT
Controller left analog stick leftward movement.
Definition Input.hpp:184
@ MOUSE_MOTION_RIGHT
Mouse right movement.
Definition Input.hpp:184
@ TOUCH_FINGER_MOTION_UP
Finger up movement.
Definition Input.hpp:184
@ TOUCH_FINGER_MOTION_DOWN
Finger down movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_RIGHT_STICK_DOWN
Controller right analog stick downward movement.
Definition Input.hpp:184
@ MOUSE_SCROLL_RIGHT
Mouse scroll wheel rightward movement.
Definition Input.hpp:184
@ PINCH_FINGERS_MOTION_TOGETHER
Finger pinch "zoom out" movement.
Definition Input.hpp:184
@ MOUSE_SCROLL_UP
Mouse scroll wheel upward movement.
Definition Input.hpp:184
@ TOUCH_FINGER_MOTION_LEFT
Finger left movement.
Definition Input.hpp:184
@ MOUSE_MOTION_UP
Mouse up movement.
Definition Input.hpp:184
@ MOUSE_MOTION_DOWN
Mouse down movement.
Definition Input.hpp:184
@ CONTROLLER_AXIS_RIGHT_STICK_LEFT
Controller right analog stick leftward movement.
Definition Input.hpp:184
constexpr size_t INPUT_COUNT
Total number of inputs that exist in the Input enumeration.
Definition Input.hpp:197
Definition aliases.hpp:15
json::VariantBase< std::allocator > Variant
JSON value type using the default allocator.
Definition json.hpp:1094
constexpr void forEachIndexedNamedEnumerand(auto fn)
Execute a function for each consecutive valid enumerand starting at value 0 in a given enum type,...
Definition metaprogramming.hpp:1901
constexpr void forEachNamedEnumerand(auto fn)
Execute a function for each consecutive valid enumerand starting at value 0 in a given enum type,...
Definition metaprogramming.hpp:1878
constexpr std::size_t enum_size_v
The number of consecutive valid enumerands starting at value 0 in a given enum type.
Definition metaprogramming.hpp:1792
Array(T, Us...) -> Array< T, 1+sizeof...(Us)>
vec< 2, float > vec2
Definition math.hpp:438
Clock::time_point TimePoint
Definition Clock.hpp:26
vec< 3, int32_t > i32vec3
Definition math.hpp:415
vec< 3, float > vec3
Definition math.hpp:439
StringBase< char, std::char_traits< char >, std::allocator< char > > String
Definition String.hpp:17
GREM_ALWAYS_INLINE constexpr decltype(auto) max(A &&a, B &&b)
Get the greater of two values, or the first value if they are equivalent.
Definition fundamentals.hpp:598
vec< 2, int32_t > i32vec2
Definition math.hpp:414
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL convertDegreesToRadians(T angleInDegrees)
Definition math.hpp:3390
GREM_ALWAYS_INLINE constexpr mat< 3, 3, T > GREM_VECTORCALL scale(vec< 2, T > scale)
Create a scale matrix describing a 2D scale.
Definition math.hpp:2665
vec< 2, int16_t > i16vec2
Definition math.hpp:406
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635
Definition Pair.hpp:53
Data structure containing information about an event.
Definition Event.hpp:370
Configuration options for an InputManager.
Definition InputManager.hpp:249
bool emitOutputEvents
Whether the input manager should emit output events or not.
Definition InputManager.hpp:263
InputManagerPreferences preferences
User preferences configuration, see InputManagerPreferences.
Definition InputManager.hpp:253
User preferences for an InputManager.
Definition InputManager.hpp:73
vec2 mouseWheelScrollSensitivity
Mouse wheel scroll sensitivity coefficient.
Definition InputManager.hpp:90
float controllerRightTriggerLowerDeadzone
Controller right trigger lower deadzone fraction.
Definition InputManager.hpp:234
float controllerRightStickOuterDeadzone
Controller right analog stick outer deadzone fraction.
Definition InputManager.hpp:205
vec2 touchMotionSensitivity
Touch finger motion sensitivity coefficient.
Definition InputManager.hpp:98
float controllerLeftStickCurveExponent
Controller left analog stick curve exponent.
Definition InputManager.hpp:130
vec2 controllerRightStickSensitivity
Controller right analog stick sensitivity coefficient.
Definition InputManager.hpp:118
float controllerRightStickCurveExponent
Controller right analog stick curve exponent.
Definition InputManager.hpp:142
vec2 controllerLeftStickSensitivity
Controller left analog stick sensitivity coefficient.
Definition InputManager.hpp:108
float controllerLeftStickOuterDeadzone
Controller left analog stick outer deadzone fraction.
Definition InputManager.hpp:186
float controllerRightStickInnerDeadzone
Controller right analog stick inner deadzone fraction.
Definition InputManager.hpp:196
float pinchSensitivity
Pinch fingers sensitivity coefficient.
Definition InputManager.hpp:167
float controllerRightTriggerUpperDeadzone
Controller right trigger upper deadzone fraction.
Definition InputManager.hpp:243
float controllerLeftTriggerUpperDeadzone
Controller left trigger upper deadzone fraction.
Definition InputManager.hpp:224
float controllerLeftTriggerLowerDeadzone
Controller left trigger lower deadzone fraction.
Definition InputManager.hpp:215
float touchPressureLowerDeadzone
Touch finger pressure lower deadzone fraction.
Definition InputManager.hpp:151
float controllerLeftStickInnerDeadzone
Controller left analog stick inner deadzone fraction.
Definition InputManager.hpp:177
vec2 mouseSensitivity
Mouse sensitivity coefficient.
Definition InputManager.hpp:82
float touchPressureUpperDeadzone
Touch finger pressure upper deadzone fraction.
Definition InputManager.hpp:159
A single configured binding from a physical input to a set of abstract output numbers.
Definition InputManager.hpp:494
Input input
Input that is bound.
Definition InputManager.hpp:495
ArrayList< OutputIndex > outputIndices
Set of abstract output numbers that the input is bound to.
Definition InputManager.hpp:496
Relative change of the state value between frames of a 2-dimensional control associated with some inp...
Definition InputManager.hpp:377
i32vec2 addedPresses
Number of presses added to the control.
Definition InputManager.hpp:378
vec2 motion
Floating-point value added to the control, affected by sensitivity and deadzone on applicable inputs.
Definition InputManager.hpp:379
Relative change of the state value between frames of a 3-dimensional control associated with some inp...
Definition InputManager.hpp:386
vec3 motion
Floating-point value added to the control, affected by sensitivity and deadzone on applicable inputs.
Definition InputManager.hpp:388
i32vec3 addedPresses
Number of presses added to the control.
Definition InputManager.hpp:387
Relative change of the state value between frames of a control associated with some input(s) and/or o...
Definition InputManager.hpp:368
int32_t addedPresses
Number of presses added to the control.
Definition InputManager.hpp:369
float motion
Floating-point value added to the control, affected by sensitivity and deadzone on applicable inputs.
Definition InputManager.hpp:370
State value of a 2-dimensional control associated with some input(s) and/or output(s).
Definition InputManager.hpp:350
vec2 value
Current floating-point value of the control, affected by sensitivity and deadzone on applicable input...
Definition InputManager.hpp:352
i32vec2 activePresses
Current number of presses of the control.
Definition InputManager.hpp:351
State value of a 3-dimensional control associated with some input(s) and/or output(s).
Definition InputManager.hpp:359
vec3 value
Current floating-point value of the control, affected by sensitivity and deadzone on applicable input...
Definition InputManager.hpp:361
i32vec3 activePresses
Current number of presses of the control.
Definition InputManager.hpp:360
State value of a control associated with some input(s) and/or output(s).
Definition InputManager.hpp:341
int32_t activePresses
Current number of presses of the control.
Definition InputManager.hpp:342
float value
Current floating-point value of the control, affected by sensitivity and deadzone on applicable input...
Definition InputManager.hpp:343
Data structure containing information about an output event.
Definition InputManager.hpp:488
Output value changed.
Definition InputManager.hpp:477
Output was pressed.
Definition InputManager.hpp:480
Output was released.
Definition InputManager.hpp:483
Stateful wrapper object of an input stream for JSON deserialization.
Definition json.hpp:5525