herobank110 / factorygame

Python game engine to have a 2d movable "graph".
https://factorygame.readthedocs.io
MIT License
1 stars 2 forks source link

input axis system #7

Open herobank110 opened 3 years ago

herobank110 commented 3 years ago

Currently only action input events are implemented (press or release a mapping of keys.) Axis input events would continuously send the extent to which a mapping of keys are pressed.

Like an action mapping, an axis mapping can have multiple keys bound to it. But now each key also must say to what degree to exert itself on the axis (its strength.) The magnitude of the strength signifies the axis sensitivity per bound key and a negative strength signifies the axis per bound key is inverted. Typical strengths may include 1 or -1.

The actual recorded extent a key is pressed is its raw value. A key's raw value is multiplied by its mapped strength to give the axis event's extent. For a key in a state where the player isn't affecting it (the start point), its raw value is zero. Negative raw values result from keys which may be affected in opposite directions from their start point (bidirectional keys). Unidirectional keys are those which may only be affected in one direction from the start point. For keys that report a granular level of affect (analogue keys) such as thumbsticks or triggers, the raw values will be normalized to the range [-1, 1] for bidirectional keys and [0, 1] for unidirectional keys. For non analogue keys (such as keyboard keys) the pressed state signifies a raw value of 1 and released signifies 0. For unbounded keys such as mouse acceleration, the raw values values may exceed the range of raw values of other keys. In this case a typical usage range should be mapped to the range [-1, 1] if a bidirectional key is unbounded in both directions, or [0, 1] if a unidirectional key is unbounded in its only direction. If a bidirectional key is unbounded in only one direction, the unbounded direction may use a range mapping independent of the range of the degree of affect of the key in the bounded direction. The bounded direction must be normalized to the range of magnitudes [0, 1].

For an input device's multi dimensional analogue keys, such as thumbsticks, each dimension is considered its own key. Opposite directions from an input device's key's start point are considered a single, bidirectional dimension. The dimension's label is concatenated to the input device's key's name to give each key's unique name. Bidirectional dimensions consisting a set of states where the input device's key is affected towards and away from the human player during conventional use of the input device are labelled 'Y'. Bidirectional dimensions consisting a set of states where the input device's key is affected left and right relative to the human player during conventional use of the input device are labelled 'X'. All other dimensions are labelled 'Axis'. For multidimensional bidirectional keys, the direction of the dimension labelled 'Y' consisting a state entered when the input device's key is closest to or pointing mostly towards the human player in a conventional usage of the input device is considered to yield a negative raw value. For multidimensional bidirectional keys, the direction of the dimension labelled 'X' consisting a state entered when he input device's key is leftmost relative to the human player in a conventional usage of the input device is considered to yield a negative raw value.

When multiple keys bound to the same axis are held simultaneously, only the most recently pressed key (the active key) may exert influence on the axis event's extent. If an active key is released, the next most recently pressed key bound to the previously active key's mapping to still be held becomes the active key. If no more keys bound to the axis mapping are held, the axis event will always be triggered with an extent of 0.

Axis events should be triggered at a constant rate independent of the frame rate. The default rate is 20 events per second, which may be adjusted at game engine initialization.