Skip to content

Extend PlayerIndex Enum To Support 8 Players On Compatible Platforms #8809

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

AristurtleDev
Copy link
Contributor

Summary

This PR extends the PlayerIndex enum to support up to 8 players on platforms that can handle more than 4 controllers simultaneously. The change uses preprocessor directives to maintain platform-specific limitations.

Changes

  • Added PlayerIndex.Five through PlayerIndex.Eight (values 4-7).
  • Implemented preprocessor directives #if !PLAYSTATION4 && !PLAYSTATION5 to exclude additional values on Playstation platforms as they only support a maximum of four controllers.

Extends the `PlayerIndex` enum support up to 8 players on compatible platforms:

- Added `PlayerIndex.Five` through `PlayerIndex.Eight`
- Use preprocessor directives to exclude `PlayerIndex.Five` through`PlayerIndex.Eight` on Playstation platforms since they are limited to four controllers
@SimonDarksideJ SimonDarksideJ added this to the 3.8.5 milestone Jun 2, 2025
@squarebananas
Copy link
Contributor

I remember @KelsamGames saying DesktopGL can have up to 16 controllers:
https://community.monogame.net/t/does-monogame-support-more-than-4-controllers/18575/3
https://muffed.kelsam.net/docs/game/engine/input/devices/#device-connection-limits
image

@AristurtleDev
Copy link
Contributor Author

I remember @KelsamGames saying DesktopGL can have up to 16 controllers: https://community.monogame.net/t/does-monogame-support-more-than-4-controllers/18575/3 https://muffed.kelsam.net/docs/game/engine/input/devices/#device-connection-limits

This is because of the differences in DirectInput vs XInput. XInput API documentation states that the ID is in range 0 - 3. When using an ID outside this range with additional XInput devices they won't return back (from my understanding).

Steam has the "Extended Xbox Feature Support" in the settings which bypasses the four gamepad limit.

However i believe the new Microsoft GDK supports up to eight, which would go with with the DirectX 12 implementation from PR #8646

@tomspilman may be able to answer if this is the case, if so, then the only four gamepad limitation at that point is the Playstation platforms.

@squarebananas
Copy link
Contributor

@AristurtleDev I actually meant if MonoGame.DesktopGL can have 16 controllers, then maybe increase it to PlayerIndex.Sixteen. I would think that will be the case for DesktopVK as well.

As for WindowsDX though (the current one without GDK), that is hardcoded to 4 controllers in multiple places:

private static readonly SharpDX.XInput.Controller[] _controllers = new[]

@KelsamGames
Copy link

Should update this as a part of this change too, and probably take a look at other platforms:

@AristurtleDev
Copy link
Contributor Author

Should update this as a part of this change too, and probably take a look at other platforms:

XInput is still limited to 4 controllers. I mentioned earlier that the GDK support would increase that amount for DX platforms which is worked on in #8646, but I'd need @tomspilman to verify for me since he's the one working on that PR

@@ -24,6 +24,24 @@ public enum PlayerIndex
/// <summary>
/// The fourth player index.
/// </summary>
Four = 3
Four = 3,
#if !PLAYSTATION4 && !PLAYSTATION5
Copy link
Member

Choose a reason for hiding this comment

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

Don't add a platform define for common API, even if the platform does not support it, there is no need for the define to hide the enum values / properties as its much easier to have your own game code without a bunch of defines for random MG props.

We have some of it in GameWindow right now and it just causes issues for no good reason 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the directives.

Should the XML documentation be updated with a <remark> to state that users can use GamePads.MaximumGamePadCount to find the limit for the current system? Something like

/// <summary>
/// Defines the index of player for various MonoGame components.
/// </summary>
/// <remark>
/// Use <see cref="GamePad.GetMaximumGamePadCount" /> to determine the number of supported
/// gamespads to ensure that a valid<see cref="PlayerIndex" /> is used when accessing gamepad input.
/// </remark>
public enum PlayerIndex

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.

5 participants