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

Keyboard gamepad fixes #2253

Merged
merged 5 commits into from
Apr 14, 2020
Merged

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Apr 14, 2020

Was made to close #2249 but it unveiled some other, related inconsistencies. I can split this up into multiple PRs if needed.

  • Made FlxG.keys.anyPressed([ANY]) return true if any key is pressed, previously it would always return false.
  • Make myGamePad.pressed.A true when A is either PRESSED or JUST_PRESSED. Previously, it would be false if just pressed.
  • Added FlxKey.NONE to FlxKeyList, since game pads have this feature.
  • Added FlxG.keys.released since game pads had that too.

@@ -135,25 +141,37 @@ class FlxKeyManager<Key:Int, KeyList:FlxBaseKeyList> implements IFlxInputManager
* @param Status The key state to check for.
* @return Whether the provided key has the specified status.
*/
public function checkStatus(KeyCode:Key, Status:FlxInputState):Bool
public inline function checkStatus(KeyCode:Key, Status:FlxInputState):Bool
Copy link
Member

Choose a reason for hiding this comment

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

This function is too complex to be inline.

Copy link
Member Author

@Geokureli Geokureli Apr 14, 2020

Choose a reason for hiding this comment

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

I mostly did this to match FlxGamepad.checkStatus but it should work because checkStatus should always be called with a literal key value through inlined getters like FlxG.keys.pressed.A which is inlined and assumedly optimized all the way down the call stack to become:

var key = getKey(KeyCode);
var tmp:Bool
if (key == null)
    tmp = false;
else
    tmp = key.hasState(Status);

otherwise only checkKeyArrayState should get the full inline. of course, people can call this method, as it's public and that can cause problems. I thought about making it private and adding @:allow(flixel.input.FlxBaseKeyList) to it. but that might screw up someone's project.

@Gama11
Copy link
Member

Gama11 commented Apr 14, 2020

Thanks, these changes all make sense to me. 👍

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.

FlxG.keys.anyJustPressed([ANY]) returns false when FlxG.keys.justPressed.ANY return true
2 participants