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

SDL: Initial implementation of joystick events #1681

Merged
merged 4 commits into from Jul 7, 2019

Conversation

Projects
None yet
3 participants
@ccawley2011
Copy link
Member

commented Jun 17, 2019

This PR provides the option for engines to receive joystick events from the backend. It's based ResidualVM's joystick handling.

Currently this implements joystick support for The Journeyman Project: Pegasus Prime. The joystick mapping is based on the on the PlayStation and Pippin versions, with some changes.

All games with joystick support will open the main menu when the start button is pressed.

This PR is not 100% complete. The most notable thing missing is proper handling for analog sticks. Since Pegasus Prime simply uses the analog stick to simulate mouse input, I simply opted to disable passing axis events and let the backend handle it. In the long term though, the joystick to mouse code should be moved into Common, so that it can be used by engines that need it, and the analog stick can still be used for games that need it for other purposes, such as movement in RPGs, or if it's used by the game's scripts, like it is with GrimE. (Plus it means the joystick to mouse code can be shared between backends).

I haven't implemented joystick support for games like Lands of Lore, Eye of the Beholder or Worlds of Xeen since I don't have any of them, however I've decided to open this PR anyway in case any engine authors wanted to take a look.

@rsn8887

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2019

The way I understand it this could be merged. It would allow us to implement engine-specific controller support where needed (lol, eotb, xeen) , while keeping the existing functionality for all other engines automatically.

EDIT: It would be great to keep R shoulder on game controllers as the "slow mouse" modifier for now in all cases.

@@ -1071,6 +1153,15 @@ bool SdlEventSource::handleControllerButton(const SDL_Event &ev, Common::Event &
{ EVENT_KEYDOWN, KeyState(KEYCODE_KP6, 0), EVENT_KEYDOWN, KeyState(KEYCODE_KP3, 0) }
};

if (!shouldGenerateMouseEvents()) {
event.type = buttonUp ? Common::EVENT_JOYBUTTON_UP : Common::EVENT_JOYBUTTON_DOWN;

This comment has been minimized.

Copy link
@rsn8887

rsn8887 Jun 18, 2019

Contributor

What about (for the moment) still allow holding R to slow slow down mouse here

if (!shouldGenerateMouseEvents()) {
	if (ev.cbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) {
		// Right shoulder is the modifier button that makes the mouse go slower
		_km.modifier = !buttonUp;
	}
(...)

This comment has been minimized.

Copy link
@ccawley2011

ccawley2011 Jun 18, 2019

Author Member

Pegasus Prime already uses the R button to open the Biochip panel, so this will need to be mapped to another button.

This comment has been minimized.

Copy link
@rsn8887

rsn8887 Jun 18, 2019

Contributor

Maybe just leave the code as is then. I guess if an engine with joystick support wants slow mouse hotkey it can implement it by itself...

This comment has been minimized.

Copy link
@rsn8887

rsn8887 Jun 20, 2019

Contributor

As per discord discussion, we could use holding down X to slow down mouse here.

So:

if (!shouldGenerateMouseEvents()) {
	if (ev.cbutton.button == SDL_CONTROLLER_BUTTON_X) {
		// When the engine supports joysticks, we use the 
		// X button as the modifier button that makes the mouse go slower
		// If needed, X can also be used as a modifier for extended button 
		// mappings in the engine.
		_km.modifier = !buttonUp;
	}
(...)

This comment has been minimized.

Copy link
@bluegr

bluegr Jul 7, 2019

Member

Why would you want to keep a specific key pressed down in order to slow down the mouse movement? It's bad practice to reserve a specific key for this kind of functionality, as that key can be used in specific games, and slowing down mouse movement may not be needed in all games.

This comment has been minimized.

Copy link
@rsn8887

rsn8887 Jul 8, 2019

Contributor

I agree

@bluegr

This comment has been minimized.

Copy link
Member

commented Jul 7, 2019

Any news on this?

@bluegr

This comment has been minimized.

Copy link
Member

commented Jul 7, 2019

Many thanks for your work! This looks good to be merged, and can be used as a basis for joystick events in games where a joystick controller can be used. Three weeks have passed since this PR was created, and no negative feedback was given.

Thus, this can be merged now, and further development on this feature can be continued in-tree.

@bluegr bluegr merged commit 52e7ba5 into scummvm:master Jul 7, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@ccawley2011 ccawley2011 deleted the ccawley2011:joystick branch Jul 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.