Skip to content

Commit

Permalink
Merge pull request #9 from electronstudio/master
Browse files Browse the repository at this point in the history
update SDL to 2.0.9
  • Loading branch information
electronstudio authored Nov 27, 2018
2 parents 4458a36 + b992cfa commit 7366bb5
Show file tree
Hide file tree
Showing 343 changed files with 1,047 additions and 159,841 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Java

jni/
*.class
*.war
*.ear
Expand Down
78 changes: 51 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Jamepad

#### A better way to use gamepads in Java

Jamepad is a library for using gamepads in Java. It's based on SDL2 ([here](https://www.libsdl.org/)) and uses jnigen ([more info here](https://github.com/libgdx/libgdx/wiki/jnigen)). We also use [this](https://github.com/gabomdq/SDL_GameControllerDB) really nice database of gamepad mappings.

Other gamepad libraries are missing stuff developers need. For most libraries, Xbox 360 controllers on windows are not properly supported. The libraries that do support Xbox 360 controllers are not cross platform (or are GPL encumbered). On some, hotplugging controllers is not supported.
Other gamepad libraries are missing stuff developers need. For most libraries, Xbox 360 controllers on windows are not properly supported. The libraries that do support Xbox 360 controllers are not cross platform. On some, hotplugging controllers is not supported.

Jamepad has:
- One library that supports all platforms (Windows, OSX, and Linux)
- XInput support on Windows for full Xbox 360 controller support.
- Support for plugging/unplugging controllers at runtime.
- Support for rumble
- Button/Axis mappings for popular controllers.
- A permissive license. You can include this use this library in commercial projects without sharing source.
- A permissive license. You can include this use this library in proprietary projects without sharing source.

#### Stuff You Should Know About Jamepad

- Jamepad is based on SDL. Since SDL is a bit overkill for just gamepad stuff, we build a smaller version that only contains the SDL_GameController subsystem and its dependencies.
- On Windows (only 7 and up were tested), no special dependencies are needed.
- On Linux, runtime dependencies are:
- libevdev
Expand All @@ -24,15 +24,20 @@ Jamepad has:
- If you want to use Xbox controllers, you need separate drivers for them. The ones [here](https://github.com/360Controller/360Controller) have been tested with Jamepad and work properly.

#### Current Limitations
- Rumble stuff is iffy.
- It works on Linux and with XInput on windows.
- It seems like it doesn't work on OSX right now. I'm not totally sure though, because the same controllers don't vibrate with straight up SDL either. This could also just be that the controllers I tested (X360, Xbox One, PS3, PS4) don't have driver support for rumble on OS X. It's also possible things are just broken.
- DirectInput on Windows is untested, as I don't have any DirectInput controllers where the vibration works normally.
- There are some (driver-y) problems Jamepad just can't fix. Xbox controller support on Linux is still kind of iffy. The 360 Wireless Adapter is a mess on Linux without the [SteamOS version of xpad](https://launchpad.net/~mdeslaur/+archive/ubuntu/steamos) or the [Xboxdrv](https://github.com/xboxdrv/xboxdrv) userspace drivers. The Xbox One Wireless adapter isn't currently supported at all on Linux and OSX.
- The order of gamepads on Windows is not necessarily the order they were plugged in. XInput controllers will always appear before DirectInput controllers, regardless of when they were plugged in. This means that the player numbers associated with each controller can change unexpectedly if XInput controllers are plugged in or disconnected while DirectInput controllers are present.
- If using getState() in ControllerManager, a new ControllerState is instantiated on each call. For some games, this could pose a problem.
- For now, when we build SDL, the dynamic API stuff is disabled. This seems bad and should probably change. I just don't know how to get it to work through JNI with that stuff enabled.


#### Latest changes in 1.3

* Uses new rumble API and depreciates the old haptics API.
* Based on SDL 2.0.9
* Changes to build system.
* Remove Mac32 and Lin32 builds.
* Creating portable binaries for Linux is a minefield at the best of times so we need to do some testing on different Linux distros to make sure they work.



## Using Jamepad

#### Getting Jamepad
Expand All @@ -48,7 +53,7 @@ Next, add this line to your dependencies section. Update the version number to w
````
dependencies {
...
compile 'com.github.WilliamAHartman:Jamepad:1.1'
compile 'com.github.WilliamAHartman:Jamepad:1.3'
}
````

Expand Down Expand Up @@ -117,35 +122,54 @@ controllers.quitSDLGamepad();
```

## Building Jamepad
1. run `gradle windowsNatives`
2. run `gradle linuxNatives`
3. Clone the repo on a mac. Copy the files you just built (from the `libs` folder) to the mac
4. On the mac, run `gradle OSXNatives`
5. run `gradle dist` to generate a .jar file with all the dependencies bundled
1. Clone the repo on Linux. Run `./gradlew linuxNatives`
2. The binaries for Windows are cross-compiled and so also need to be built on Linux. Run `./gradlew windowsNatives`
3. Clone the repo on a mac. Copy the files you just built (from the `libs` folder) to the mac .
4. On the mac, run `./gradlew OSXNatives`
5. Run `./gradlew dist` to generate a .jar file with all the dependencies bundled.

#### Dependencies for Building Jamepad on Linux
Right now the Windows and Linux binaries, Jamepad needs to be built on Linux. The binaries for Windows are cross-compiled.
#### Linux build dependencies

The following packages (or equivalents) are needed:

```
gradle
ant
build-essential
libc6-i386
libc6-dev-i386
g++-multilib
g++-mingw-w64-i686
g++-mingw-w64-x86-64
build-essential
sdl2-dev
```

If you've built C stuff for different platforms and bitnesses, you probably have all this stuff. If not, use your package manager to get them all. It should be something like this if you're on Ubuntu or Debian or whatever:

```
sudo apt-get install ant gradle build-essential libc6-i386 libc6-dev-i386 g++-multilib g++-mingw-w64-i686 g++-mingw-w64-x86-64
sudo apt-get install ant build-essential sdl2-dev
```

sdl2-config must be in the path.

If your distro doesn't have an up to date version of SDL or you get errors, you can build it yourself from source:

```
./configure CFLAGS=-fPIC CPPFLAGS=-fPIC ; make ; sudo make install
```

If you want to make the binaries smaller you can disable parts of SDL you don't need with configure flags. (We only make use of Joystick, GameController and Events systems). However this is not tested.

#### Windows (cross compiled on Linux) build dependencies

```
sudo apt-get install mingw-w64
```

#### Dependencies for Building Jamepad on OS X
You need to install cross compiled Windows 32 and 64 bit versions of SDL, e.g.

```
./configure --host=i686-w64-mingw32 ; make ; sudo make install
./configure --host=x86_64-w64-mingw32 ; make ; sudo make install
```

sdl2-config is assumed to be in /usr/local/cross-tools/ if it is not found there you will need to edit JamepadNativesBuild.java with the correct path.

#### MacOS build dependencies
The OS X binaries currently must be built on OS X. It is probably possible to build the Windows and Linux binaries here too, but I haven't tried that out.

The dependencies are pretty much the same (gradle, ant, g++). These packages can be installed from homebrew.
The dependencies are pretty much the same (ant, g++). These packages can be installed from homebrew.
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ repositories {
}

dependencies {
compile "com.badlogicgames.gdx:gdx-jnigen:1.9.2"
compile "com.badlogicgames.gdx:gdx-jnigen:1.9.9"
}

task deleteJniFolder(type: Delete) {
delete "jni"
}

clean.dependsOn(deleteJniFolder)

task runTester(dependsOn: classes, type: JavaExec) {
main = 'com.studiohartman.jamepad.tester.ControllerTester'
classpath = sourceSets.main.runtimeClasspath
Expand All @@ -32,21 +38,21 @@ task runTester(dependsOn: classes, type: JavaExec) {

task linuxNatives(dependsOn: classes, type: JavaExec) {
main = 'com.studiohartman.jamepad.JamepadNativesBuild'
args = ['build-linux']
args = ['build-linux', 'system-SDL2']
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
}

task windowsNatives(dependsOn: classes, type: JavaExec) {
main = 'com.studiohartman.jamepad.JamepadNativesBuild'
args = ['build-windows']
args = ['build-windows', 'system-SDL2']
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
}

task OSXNatives(dependsOn: classes, type: JavaExec) {
main = 'com.studiohartman.jamepad.JamepadNativesBuild'
args = ['build-OSX']
args = ['build-OSX', 'system-SDL2']
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
}
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
172 changes: 172 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit 7366bb5

Please sign in to comment.