Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor Input handling #1891

Merged
merged 14 commits into from
Aug 27, 2024
Merged

fix: refactor Input handling #1891

merged 14 commits into from
Aug 27, 2024

Conversation

fcolarich
Copy link
Collaborator

@fcolarich fcolarich commented Aug 26, 2024

What does this PR change?

What does this NOT do?! well for starters, it wont cuddle you in the middle of the night when you are feeling lonely.

What does DO do? Given the growing number of windows and menus and whatnot that we are adding, the input handling was getting out of control, particularly blocking and unblocking input. It would happen that a window would block input until closed and then another window would open blocking the same input, but when the previous window finishes closing after the second one loads, it blocks the input again. And all sorts of similar things. Making it REALLY difficult to ascertain which inputs should be enabled and when.
To avoid this, I piggybacked into a couple of existing systems that already handled input changes, but improved them so we can properly track how many times each input was requested to be blocked or unblocked.
So, I expanded the InputBlock class so it can be used as intermediary between the already existing InputMapComponent and every Controller. Also I expanded the InputMapComponent so it has inside a dictionary tracking each input kind along with the number of block requests for it.
The InputBlock class can block several inputs at the same time, making use of the InputMapComponent.Kind Flag enum, but can be overriden to only block one input to save a bit of processing.
The InputMapComponent will only update its Active property when the block counter reaches either 1 or 0 (for disabling or enabling the inputs), in other cases it will just increase or decrease the appropriate counters.
Other than that, it was a matter of updating all places where input blocking/unblocking was done and make sure the number of blocks and unblocks was paired in all cases. This was time consuming for some parts of the game, but overall ended up improving some exit flows as well.
Also, added finally, the input blocking while the loading screen is showing, this way no input will be sent while displaying it.

Now, go find something to cuddle you in the middle of the night you brave soul!

How to test the changes?

To test it just try to go through the normal flow of the game, chat messages, menus, jumping through worlds, etc. The input should behave as before and even better :) Now it should be impossible to move while teleporting and the loading screen is showing for example.
This fixes this issue as well: [https://github.com//issues/1793] As it was caused exactly by this kind of Input woes.
Also fixes an issue happening when opening the emote wheel and closing it quickly which sometimes would leave some inputs blocked

Copy link

github-actions bot commented Aug 26, 2024

badge

New build in progress, come back later!

@anicalbano anicalbano requested review from anicalbano and removed request for Ludmilafantaniella August 27, 2024 12:19
Copy link
Contributor

@anicalbano anicalbano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tested thoroughly, everything appears to be working as expected

Copy link
Member

@davidejensen davidejensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niceeeee

Copy link
Collaborator

@popuz popuz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring 💪
However, I would suggest some changes here and there :) While most of them are small and rather cosmetical, changing BlockInput/UnblockInput from UnblockInputs(InputMapComponent.Kind kinds, bool singleValue = false) to UnblockInputs(params InputMapComponent.Kind[] kinds) could be a nice improvement

@fcolarich
Copy link
Collaborator Author

Will think of more optimizations for the block/unblock methods after merging :)

@fcolarich fcolarich enabled auto-merge (squash) August 27, 2024 14:57
@fcolarich fcolarich merged commit 6237f7e into main Aug 27, 2024
5 checks passed
@fcolarich fcolarich deleted the fix/input_fixes branch August 27, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants