Commit graph

183 commits

Author SHA1 Message Date
puzzud
140440ee82 [3.x] Prevent double input events on gamepad when running through steam input #79706
Co-authored-by: Eoin O'Neill <eoinoneill1991@gmail.com>
2023-07-20 16:35:44 -04:00
lawnjelly
63d208d1b0 Input - fix just pressed and released with short presses
Previously if an action was both pressed and released on the same tick or frame, `is_action_just_pressed()` would return false, resulting in missed input.

This PR separately the timestamp for pressing and releasing so each can be tested independently.
2023-06-12 16:33:48 +01:00
Fredia Huya-Kouadio
94d6c3dcc6 Augment the InputEvent class with a CANCELED state
The `InputEvent` class currently supports the `pressed` and `released` states, which given the binary nature, is represented by a `bool` field.
This commit introduced the `CANCELED` state, which signals that an ongoing input event has been canceled.
To represent all the states, the `InputEventState` enum is added and the `InputEvent` logic is refactored accordingly.
2023-05-12 15:22:54 -07:00
Fredia Huya-Kouadio
2509c1691d Follow up to https://github.com/godotengine/godot/pull/76400 to fix input ANR in the Godot Android editor 2023-05-11 19:10:31 -07:00
Pedro J. Estébanez
e5b399be65 Allow concurrent buffering and dispatch of input events 2023-05-08 09:15:48 +02:00
Ricardo Subtil
e814861950
Change message of unknown joypad property from error to warning
(cherry picked from commit e841f13cdc)
2023-03-06 13:48:17 +01:00
Pedro J. Estébanez
9cd84224bd Warn users about unsafe usage of InputEvent 2023-01-31 14:41:27 +01:00
Rémi Verschelde
1426cd3b3a
One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".

Backported from #70885.
2023-01-10 15:26:54 +01:00
Fredia Huya-Kouadio
be4b07c3e4 Add double_tap attribute to InputEventScreenTouch
This provides parity with the `InputEventMouseButton` allowing for proper conversion between the two events.
2022-10-20 11:56:11 -07:00
Michael Alexsander
6f0c852c9b Port Input.action_press/release() changes 2022-09-26 22:25:10 -03:00
Marcel Admiraal
cdd60416ed Fix axis mapped to DPad buttons not releasing opposite button 2022-08-17 09:10:36 +01:00
Rémi Verschelde
daa5b542b4
Merge pull request #56765 from madmiraal/fix-45592-2-3.x
[3.x] Fix mouse speed not changing fast enough
2022-08-05 22:37:44 +02:00
Fabio Alessandrelli
fbc7fc44ae Fix some array size function definition mismatch.
(cherry picked from commit 55845bac26)
2022-08-04 15:18:43 +02:00
Rémi Verschelde
d6bcdd18c3 Input: Re-enable input accumulation disabled by error in 3.4
Input accumulation was implemented and enabled by default in 3.1, and
I don't recall major complaints around it (or bugs were fixed).

In 3.4, #42220 added input buffering and apparently toggled input
accumulation off by mistake.

This led to multiple bug reports about degraded performance on Windows,
or simply unexpected behavior change (see linked issues in #55037).

Fixes #55037.
2022-07-07 23:04:51 +02:00
FireForge
53c01540d9 Make Input mouse_mode and use_accumulated_input properties
Co-authored-by: Haoyu Qiu <timothyqiu32@gmail.com>
2022-06-10 17:33:12 +08:00
KingCakeTheFruity
198d147f8e Added p_shape check to avoid engine crush
(cherry picked from commit 29a2809d21)
2022-04-14 21:35:32 +02:00
snowapril
c77b710035 Fix crash on get index for non-existing string
As _buttons and _axes have both valid string and nullptr.
When iterating over them, if given key exists it will work correctly.
But if given key does not exist, it will end up with
String::operator=(nullptr). As String constructor from nullptr exists, I
use it.
2022-03-17 17:49:12 +09:00
Rémi Verschelde
ed869729ae
Merge pull request #56755 from madmiraal/fix-45592-3.x 2022-01-24 10:06:24 +01:00
Marcel Admiraal
949ea2b326 Simplify InputDefault::joy_axis code by using float instead of struct JoyAxis 2022-01-14 15:36:35 +00:00
Marcel Admiraal
3d96d7d9fb Fix mouse speed not changing fast enough
- Uses all accumulated movements when calculating speed
- Discards old accumulated movements
- Sets last mouse speed to zero when there is no movement
2022-01-13 18:52:08 +00:00
Rémi Verschelde
a627cdafc5
Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-13 15:54:13 +01:00
Marcel Admiraal
b7545631de Use mouse event relative motion to calculate mouse speed 2022-01-13 10:29:57 +00:00
bruvzg
6eac65d4fe
Add joystick button index boundary check. Increase max. button number to 128 (max. buttons supported by DirectInput).
(cherry picked from commit 61ea8f8337)
2022-01-12 17:28:07 +01:00
Marcel Admiraal
9f250e8370
Revert "[3.x] Fixed event spam when using the Nintendo Switch controller" 2021-12-17 17:20:43 +00:00
Sam Lantinga
e5b0f86260 Fixed event spam when using the Nintendo Switch controller
There is no filtering on the Nintendo Switch Pro controller thumbstick, so there will frequently be events with very slight change. These are turned into "not pressed" events, which cancel "pressed" events from keys and buttons.

This change filters out up to 5% jitter, but it might be worth revisiting whether "not pressed" events should cancel "pressed" events.
2021-12-16 09:09:06 -08:00
bruvzg
2ef2879d7b
Add Input.is_physical_key_pressed method.
(cherry picked from commit 9877d91c4a)
2021-11-25 22:19:33 +01:00
Rémi Verschelde
7afb784269
Sync controller mappings DB with SDL2 community repo
Synced with gabomdq/SDL_GameControllerDB@322aac4bb7.

Also improve parser errors to allow identifying the problematic mappings.

(cherry picked from commit 4b247e7ffa)
2021-11-03 21:32:53 +01:00
Rémi Verschelde
42d385b312
clang-format: Disable alignment of operands, too unreliable
Sets `AlignOperands` to `DontAlign`.

`clang-format` developers seem to mostly care about space-based indentation and
every other version of clang-format breaks the bad mismatch of tabs and spaces
that it seems to use for operand alignment. So it's better without, so that it
respects our two-tabs `ContinuationIndentWidth`.
2021-10-28 13:23:38 +02:00
jmb462
e7dac5da41
Adding InputMap action error suggestion for Input singleton
(cherry picked from commit a3b9842616)
2021-09-21 17:14:58 +02:00
Pedro J. Estébanez
7be9c26e20 Add input buffering framework
Input buffering is implicitly used by event accumulation, but this commit makes it more generic so it can be enabled for other uses.

For desktop OSs it's currently not feasible given main and UI threads are the same).
2021-08-08 12:37:55 +02:00
Pedro J. Estébanez
58a54f534e Improve input event accumulation
- API has been simplified: all events now go through `parse_input_event()`. Whether they are accumulated or not depends on the `use_accumulated_input` flag.
- Event accumulation is now thread-safe (it was not needed so far, but it prepares the ground for the following changes).
- Touch drag events now support accumulation.
2021-08-08 12:37:55 +02:00
EricEzaM
0e5c6e0d55 Allow checking for exact matches with Action events.
Added additional param to action related methods to test for exactness.
If "p_exact_match" is true, then the action will only be "matched" if the provided input event *exactly* matches with the action event.

Before:
* Action Event = KEY_S
* Input Event = KEY_CONTROL + KEY_S
* Is Action Pressed = True

Now:
You can still do the above, however you can optionally check that the input is exactly what the action event is:
* Action Event = KEY_S
* Input Event = KEY_CONTROL + KEY_S
* p_exact_match = True
* Is Action Pressed = False
* If the Input Event was only KEY_S, then the result would be true.

Usage:

```gdscript
Input.is_action_pressed(action_name: String, exact_match: bool)
Input.is_action_pressed("my_action", true)

InputMap.event_is_action(p_event, "my_action", true)

func _input(event: InputEvent):
  event.is_action_pressed("my_action", false, true) # false = "allow_echo", true = "exact_match"
  event.is_action("my_action", true)
```

Co-authored-by: Eric M <itsjusteza@gmail.com>
2021-07-30 15:35:39 +02:00
Aaron Franke
69fb14256b
[3.x] Allow getting Input axis/vector values from multiple actions
For get_vector, use raw values and handle deadzones appropriately
2021-07-23 19:17:55 -04:00
Aaron Franke
afa89c9eea
[3.x] Add raw strength value for internal use 2021-07-23 19:09:53 -04:00
Marcel Admiraal
18825ad4ff Fix game controllers ignoring the last listed button 2021-06-03 15:45:05 +01:00
Rémi Verschelde
140350d767
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
2021-05-05 15:02:01 +02:00
Rémi Verschelde
a828398655
Style: Replaces uses of 0/NULL by nullptr (C++11)
Using clang-tidy's `modernize-use-nullptr`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
2021-05-04 16:30:23 +02:00
Rémi Verschelde
b5e1e05ef2
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks 2021-05-04 14:45:16 +02:00
Rémi Verschelde
8ec14c917f
Merge pull request #47469 from HEAVYPOLY/ios-pen-pressure
Add iOS pen pressure
2021-04-28 17:01:05 +02:00
Marcel Admiraal
9170314434 Avoid creating joy_names map entries when using Map operator[] 2021-04-17 20:41:10 +01:00
Vaughan Ling
f60b90d92e Add iOS Apple Pencil pressure 2021-04-03 10:30:57 -07:00
Pop0p
07fc567d03 Fix a crash when using Input.get_joy_button_index_from_string()
There was a missing comma between two elements in the _buttons array
2021-03-05 11:17:18 +01:00
Liz Haas
8a1f8a68fb Input: Throw error if action doesn't exist
Thow errors if requesting an unexisting InputMap action.
Makes `Input.is_action_*` methods consistents with `Event.is_action_*` which already throw errors.

fixes #33303

(cherry picked from commit 2aee71d52d)
2021-02-25 14:30:25 +01:00
Marcel Admiraal
3dd57a22df Add support for new SDL gamecontroller keywords. 2021-02-07 16:41:23 +00:00
Fabio Alessandrelli
ea89e73a88 Better gamepad axis event injection.
In the core input handling code we have checks to make sure that if axis
rapidly change sign we inject mid-points to release any pending inputmap
action.

The function though, did not correctly insert the mid-point causing
dpads mapped to an axis that behaves like tri-state buttons (-1,0,1) to
not be released correctly.

This commit fixes that by including in the check the case where the axis
swtiches from abs(1) to 0.
2021-01-18 13:07:37 +01:00
Rémi Verschelde
49646383f1
Update copyright statements to 2021
Happy new year to the wonderful Godot community!

2020 has been a tough year for most of us personally, but a good year for
Godot development nonetheless with a huge amount of work done towards Godot
4.0 and great improvements backported to the long-lived 3.2 branch.

We've had close to 400 contributors to engine code this year, authoring near
7,000 commit! (And that's only for the `master` branch and for the engine code,
there's a lot more when counting docs, demos and other first-party repos.)

Here's to a great year 2021 for all Godot users 🎆

(cherry picked from commit b5334d14f7)
2021-01-13 16:17:06 +01:00
Marcel Admiraal
c3150eb783 Ignore hint entries in game controller mapping 2020-12-03 09:07:15 +00:00
Marcel Admiraal
ef2a04bfd7 Remove unneeded filter on joy_axis() 2020-10-31 09:22:52 +00:00
Marcel Admiraal
954b14ecec Provide support for buttons and D-pads mapped to half axes, and
fix axes mapped to buttons and D-pads.
2020-10-26 15:54:30 +00:00
Marcel Admiraal
ebff150680 Support SDL2 half axes and inverted axes mappings. 2020-06-26 06:28:56 +01:00