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

Improve gamepad support #17

Merged
merged 17 commits into from Mar 21, 2016
Merged

Conversation

lluchs
Copy link
Member

@lluchs lluchs commented Feb 21, 2016

See the corresponding topic in the forums.

I don't have Windows, so somebody should probably try to compile this there before merging.

With the SDL_GameController interface, buttons and axes have actual
names we can refer to. This also allows for advanced mappings using both
sticks (this probably needs script changes) as well as the triggers.
Analog moved events are only sent once per control frame.
SDL usage is masked with HAVE_SDL checks so it should work without SDL,
but SDL has to be linked when it's available.
To keep compatibility with scripts which expect only binary buttons,
this adds a third parameter to the function which enables the new
functionality.

Bonus /script to test the controller stick x axis:

    Schedule(GetCursor(), "Message(\"%d / %d\", GetPlayerControlState(0, CON_Left, true), GetPlayerControlState(0, CON_Right, true))", 10, 100000000)

Note that the values will be inconsistent if multiple analog sticks are
bound to the same control, as values from one stick will overwrite those
from the other one. This can happen even if you move only one stick.
It is now possible to control all GUI menus using the left stick or the
dpad, along with the A and B buttons on the controller.

This also doubles the button emulation dead zone to make navigating the
menus with the stick easier.
This also removes the controller id from the control definitions,
instead defaulting to 0. This doesn't change anything for now as we only
had definitions for controller 0 anyways.
 - GamePadControl::AnyButtonDown
 - GamePadOpener::SetGamePad
New script functions:
 - PlayRumble(int plr, int strength, int length)
 - StopRumble(int plr)
The icons currently only show Xbox 360 controller labeling. The icon set
also includes icons for PlayStation controllers, so we could extend this
in the future.
We want one gamepad key mapping to work with multiple gamepads, so
including the id there doesn't make sense.

Additionally, the gamepad id may change during the game (controller
hot-plugging).
The available gamepads are distributed automatically among players.

This also implements controller hot-plugging: It is possible to start a
game without a controller and plug it in later, and to reconnect a
controller after plugging it out.
@lluchs
Copy link
Member Author

lluchs commented Mar 7, 2016

I don't have Windows, so somebody should probably try to compile this there before merging.

@ckanibal made building on Windows work now, so this is ready for merging now.

@openclonk-mirror openclonk-mirror merged commit 8f31ae2 into openclonk:master Mar 21, 2016
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.

None yet

2 participants