Skip to content

Commit

Permalink
Make using SDL 2.0.14 RawInput configurable on instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed Jan 13, 2021
1 parent 04c10dc commit 237d630
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/studiohartman/jamepad/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.studiohartman.jamepad;

/**
* Class defining the configuration of a {@link ControllerManager}.
*
* @author Benjamin Schulte
*/
public class Configuration {
/**
* The max number of controllers the ControllerManager should deal with
*/
public int maxNumControllers = 4;

/**
* Use RawInput implementation instead of XInput on Windows, if applicable. Enable this if you
* need to use more than four XInput controllers at once. Comes with drawbacks.
*/
public boolean useRawInput = false;
}
24 changes: 14 additions & 10 deletions src/main/java/com/studiohartman/jamepad/ControllerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ControllerManager {
SDL_Event event;
*/

private final Configuration configuration;
private String mappingsPath;
private boolean isInitialized;
private ControllerIndex[] controllers;
Expand All @@ -38,28 +39,29 @@ public class ControllerManager {
* https://github.com/gabomdq/SDL_GameControllerDB
*/
public ControllerManager() {
this(4, "/gamecontrollerdb.txt");
this(new Configuration(), "/gamecontrollerdb.txt");
}

/**
* Constructor. Uses built-in mappings from here: https://github.com/gabomdq/SDL_GameControllerDB
*
* @param maxNumControllers The number of controllers this ControllerManager can deal with
* @param configuration see {@link Configuration and its fields}
*/
public ControllerManager(int maxNumControllers) {
this(maxNumControllers, "/gamecontrollerdb.txt");
public ControllerManager(Configuration configuration) {
this(configuration, "/gamecontrollerdb.txt");
}

/**
* Constructor.
*
* @param mappingsPath The path to a file containing SDL controller mappings.
* @param maxNumControllers The number of controller this ControllerManager can deal with
* @param configuration see {@link Configuration and its fields}
*/
public ControllerManager(int maxNumControllers, String mappingsPath) {
public ControllerManager(Configuration configuration, String mappingsPath) {
this.configuration = configuration;
this.mappingsPath = mappingsPath;
isInitialized = false;
controllers = new ControllerIndex[maxNumControllers];
controllers = new ControllerIndex[configuration.maxNumControllers];

new SharedLibraryLoader().load("jamepad");
}
Expand All @@ -76,7 +78,7 @@ public void initSDLGamepad() throws IllegalStateException {
}

//Initialize SDL
if (!nativeInitSDLGamepad()) {
if (!nativeInitSDLGamepad(!configuration.useRawInput)) {
throw new IllegalStateException("Failed to initialize SDL in native method!");
} else {
isInitialized = true;
Expand All @@ -97,8 +99,10 @@ public void initSDLGamepad() throws IllegalStateException {
controllers[i] = new ControllerIndex(i);
}
}
private native boolean nativeInitSDLGamepad(); /*
SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
private native boolean nativeInitSDLGamepad(boolean disableRawInput); /*
if (disableRawInput) {
SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
}
if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) != 0) {
printf("NATIVE METHOD: SDL_Init failed: %s\n", SDL_GetError());
Expand Down

0 comments on commit 237d630

Please sign in to comment.