Allow using Keyboard and SDL controllers as separate joysticks #197
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Having read about M.U.L.E., I wanted to give that a try with a group of 4 players. 3 controllers and 1 keyboard, or so I hoped. But it didn't work out. And it took considerable working with the code and some recorded inputs to figure out that both the keyboard and the first SDL device were controlling the emulated joystick 0, while nothing was controlling the emulated joystick 3. Pity.
So I wrote some code to change that. This pull request introduces a new command line flag
-joy-distinctwhich places the physical SDL devices after the keyboard-emulated devices, based on which keyboard-emulated devices are enabled at the time the config file and command line flags have been processed. This doesn't achieve full control over freely mapping which combinations of physical devices should control which emulated joysticks at which point in time, but it's a start and good enough for my use case. Extended logging output will make the assignments clearer and hopefully help future users who might get surprised by the default behavior the way I was surprised.Reading the existing code I found that a lot of places were making very non-trivial assumptions about which kinds of host devices could be associated with which emulated controller. Different arrays were linked by index in various places. The possibility of having LPT joysticks and an on-screen keyboard (OSK) thrown in didn't make things any simpler. So the first commit of this request is a fairly wide-ranging change to simplify the abstraction of an emulated device without introducing any actual changes in observed behavior. A later commit then performs the changes based on the setting of the flag. One commit is a drive-by improvement by means of bit field arithmetic which is not really related to this PR except that I happened to look at that code and see a potential for simplification. Readers may choose to look at the commits in isolation to separate these aspects. The commit descriptions have more details which I won't repeat here.