Remove Gamepad from limelight-pc

This commit is contained in:
Iwan Timmer
2014-01-08 21:48:44 +01:00
parent 60d45af884
commit 392da3cc59
21 changed files with 0 additions and 1001 deletions

View File

@@ -1,125 +0,0 @@
/*
Copyright (c) 2013 Alex Diener
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Alex Diener adiener@sacredsoftware.net
*/
#ifndef __GAMEPAD_H__
#define __GAMEPAD_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
struct Gamepad_device {
// Unique device identifier for application session, starting at 0 for the first device attached and
// incrementing by 1 for each additional device. If a device is removed and subsequently reattached
// during the same application session, it will have a new deviceID.
unsigned int deviceID;
// Human-readable device name
const char * description;
// USB vendor/product IDs as returned by the driver. Can be used to determine the particular model of device represented.
int vendorID;
int productID;
// Number of axis elements belonging to the device
unsigned int numAxes;
// Number of button elements belonging to the device
unsigned int numButtons;
// Array[numAxes] of values representing the current state of each axis, in the range [-1..1]
float * axisStates;
// Array[numButtons] of values representing the current state of each button
bool * buttonStates;
// Platform-specific device data storage. Don't touch unless you know what you're doing and don't
// mind your code breaking in future versions of this library.
void * privateData;
};
/* Initializes gamepad library and detects initial devices. Call this before any other Gamepad_*()
function, other than callback registration functions. If you want to receive deviceAttachFunc
callbacks from devices detected in Gamepad_init(), you must call Gamepad_deviceAttachFunc()
before calling Gamepad_init(). */
void Gamepad_init();
/* Tears down all data structures created by the gamepad library and releases any memory that was
allocated. It is not necessary to call this function at application termination, but it's
provided in case you want to free memory associated with gamepads at some earlier time. */
void Gamepad_shutdown();
/* Returns the number of currently attached gamepad devices. */
unsigned int Gamepad_numDevices();
/* Returns the specified Gamepad_device struct, or NULL if deviceIndex is out of bounds. */
struct Gamepad_device * Gamepad_deviceAtIndex(unsigned int deviceIndex);
/* Polls for any devices that have been attached since the last call to Gamepad_detectDevices() or
Gamepad_init(). If any new devices are found, the callback registered with
Gamepad_deviceAttachFunc() (if any) will be called once per newly detected device.
Note that depending on implementation, you may receive button and axis event callbacks for
devices that have not yet been detected with Gamepad_detectDevices(). You can safely ignore
these events, but be aware that your callbacks might receive a device ID that hasn't been seen
by your deviceAttachFunc. */
void Gamepad_detectDevices();
/* Reads pending input from all attached devices and calls the appropriate input callbacks, if any
have been registered. */
void Gamepad_processEvents();
/* Registers a function to be called whenever a device is attached. The specified function will be
called only during calls to Gamepad_init() and Gamepad_detectDevices(), in the thread from
which those functions were called. Calling this function with a NULL argument will stop any
previously registered callback from being called subsequently. */
void Gamepad_deviceAttachFunc(void (* callback)(struct Gamepad_device * device, void * context), void * context);
/* Registers a function to be called whenever a device is detached. The specified function can be
called at any time, and will not necessarily be called from the main thread. Calling this
function with a NULL argument will stop any previously registered callback from being called
subsequently. */
void Gamepad_deviceRemoveFunc(void (* callback)(struct Gamepad_device * device, void * context), void * context);
/* Registers a function to be called whenever a button on any attached device is pressed. The
specified function will be called only during calls to Gamepad_processEvents(), in the
thread from which Gamepad_processEvents() was called. Calling this function with a NULL
argument will stop any previously registered callback from being called subsequently. */
void Gamepad_buttonDownFunc(void (* callback)(struct Gamepad_device * device, unsigned int buttonID, double timestamp, void * context), void * context);
/* Registers a function to be called whenever a button on any attached device is released. The
specified function will be called only during calls to Gamepad_processEvents(), in the
thread from which Gamepad_processEvents() was called. Calling this function with a NULL
argument will stop any previously registered callback from being called subsequently. */
void Gamepad_buttonUpFunc(void (* callback)(struct Gamepad_device * device, unsigned int buttonID, double timestamp, void * context), void * context);
/* Registers a function to be called whenever an axis on any attached device is moved. The
specified function will be called only during calls to Gamepad_processEvents(), in the
thread from which Gamepad_processEvents() was called. Calling this function with a NULL
argument will stop any previously registered callback from being called subsequently. */
void Gamepad_axisMoveFunc(void (* callback)(struct Gamepad_device * device, unsigned int axisID, float value, float lastValue, double timestamp, void * context), void * context);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,5 +0,0 @@
rm *.o libgamepad_jni.so
gcc -I /usr/lib/jvm/java-7-openjdk-amd64/include/ -fPIC -c *.c
gcc -shared -Wl,-soname,libgamepad_jni.so -Wl,--no-undefined -o libgamepad_jni.so *.o -L./lin64 -lstem_gamepad -lpthread
rm *.o

View File

@@ -1,5 +0,0 @@
rm *.o libgamepad_jni.dylib
gcc -I /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/include/ -I /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/include/darwin -fPIC -c *.c
gcc -shared -o libgamepad_jni.dylib *.o -L./osx -lstem_gamepad -lpthread -framework IOKit -framework CoreFoundation
rm *.o

View File

@@ -1,3 +0,0 @@
rm gamepad_jni.dll gamepad_jni64.dll
/C/MinGW/bin/gcc -m32 -shared -Wall -I"/C/Program Files (x86)/Java/jdk1.7.0_45/include" -I"/C/Program Files (x86)/Java/jdk1.7.0_45/include/win32" *.c -L./win32 -lstem_gamepad -lxinput9_1_0 -Wl,--no-undefined -Wl,--kill-at -o gamepad_jni.dll
/C/MinGW-w64/bin/gcc -m64 -shared -Wall -I"/C/Program Files (x86)/Java/jdk1.7.0_45/include" -I"/C/Program Files (x86)/Java/jdk1.7.0_45/include/win32" *.c -L./win64 -lstem_gamepad -lxinput9_1_0 -Wl,--no-undefined -Wl,--kill-at -o gamepad_jni64.dll

View File

@@ -1,108 +0,0 @@
#include <stdlib.h>
#include <jni.h>
#include "Gamepad.h"
static JavaVM *jvm;
static jclass nativeGamepadClass;
static jmethodID jdeviceAttached;
static jmethodID jdeviceRemoved;
static jmethodID jbuttonDown;
static jmethodID jbuttonUp;
static jmethodID jaxisMove;
static JNIEnv *getThreadEnv(void) {
JNIEnv *env;
(*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6);
return env;
}
static void invokeJavaCallback(jmethodID method, ...) {
JNIEnv *env = getThreadEnv();
va_list args;
va_start(args, method);
(*env)->CallStaticVoidMethodV(env, nativeGamepadClass, method, args);
va_end(args);
}
static void deviceAttachCallback(struct Gamepad_device * device, void * context) {
invokeJavaCallback(jdeviceAttached, device->deviceID, device->numButtons, device->numAxes);
}
static void deviceRemoveCallback(struct Gamepad_device * device, void * context) {
invokeJavaCallback(jdeviceRemoved, device->deviceID);
}
static void buttonDownCallback(struct Gamepad_device * device, unsigned int buttonID, double timestamp, void * context) {
invokeJavaCallback(jbuttonDown, device->deviceID, buttonID);
}
static void buttonUpCallback(struct Gamepad_device * device, unsigned int buttonID, double timestamp, void * context) {
invokeJavaCallback(jbuttonUp, device->deviceID, buttonID);
}
static void axisMoveCallback(struct Gamepad_device * device, unsigned int axisID, float value, float lastValue, double timestamp, void * context) {
invokeJavaCallback(jaxisMove, device->deviceID, axisID, value, lastValue);
}
// This function must be called first
JNIEXPORT void JNICALL
Java_com_limelight_input_gamepad_NativeGamepad_init(JNIEnv *env, jobject this) {
Gamepad_deviceAttachFunc(deviceAttachCallback, NULL);
Gamepad_deviceRemoveFunc(deviceRemoveCallback, NULL);
Gamepad_buttonDownFunc(buttonDownCallback, NULL);
Gamepad_buttonUpFunc(buttonUpCallback, NULL);
Gamepad_axisMoveFunc(axisMoveCallback, NULL);
Gamepad_init();
}
// This function must be called last
JNIEXPORT void JNICALL
Java_com_limelight_input_gamepad_NativeGamepad_shutdown(JNIEnv *env, jobject this) {
Gamepad_shutdown();
// Remove the class reference
(*env)->DeleteGlobalRef(env, nativeGamepadClass);
}
// This returns the number of connected devices
JNIEXPORT jint JNICALL
Java_com_limelight_input_gamepad_NativeGamepad_numDevices(JNIEnv *env, jobject this) {
return Gamepad_numDevices();
}
// This triggers device detection
JNIEXPORT void JNICALL
Java_com_limelight_input_gamepad_NativeGamepad_detectDevices(JNIEnv *env, jobject this) {
Gamepad_detectDevices();
}
// This polls for events and calls the appropriate callbacks
JNIEXPORT void JNICALL
Java_com_limelight_input_gamepad_NativeGamepad_processEvents(JNIEnv *env, jobject this) {
Gamepad_processEvents();
}
// This is called when the library is first loaded
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *pjvm, void *reserved) {
JNIEnv *env;
// This has to be saved before getThreadEnv() can be called
jvm = pjvm;
env = getThreadEnv();
// We use a global reference to keep the class loaded
nativeGamepadClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/limelight/input/gamepad/NativeGamepad"));
// These method IDs are only valid as long as the NativeGamepad class is loaded
jdeviceAttached = (*env)->GetStaticMethodID(env, nativeGamepadClass, "deviceAttachCallback", "(III)V");
jdeviceRemoved = (*env)->GetStaticMethodID(env, nativeGamepadClass, "deviceRemoveCallback", "(I)V");
jbuttonDown = (*env)->GetStaticMethodID(env, nativeGamepadClass, "buttonDownCallback", "(II)V");
jbuttonUp = (*env)->GetStaticMethodID(env, nativeGamepadClass, "buttonUpCallback", "(II)V");
jaxisMove = (*env)->GetStaticMethodID(env, nativeGamepadClass, "axisMovedCallback", "(IIFF)V");
return JNI_VERSION_1_6;
}