no message

This commit is contained in:
gregorypierce 2003-08-07 21:57:08 +00:00
parent c88f6ab0c6
commit aeea752a6f
3 changed files with 112 additions and 49 deletions

View file

@ -53,21 +53,7 @@ import net.java.games.util.plugins.Plugin;
*/
public class OSXEnvironmentPlugin extends ControllerEnvironment implements Plugin
{
static
{
System.loadLibrary("jinput");
}
public native void hidCreate();
public native void hidDispose();
public native void enumDevices();
/**
* Opens an input device and returns the address of the input queue for that device
*/
public native long openDevice( long lpDevice, int queueDepth );
public native void closeDevice( long lpDevice, long lpInputQueue );
public native void pollDevice( long lpInputQueue );
public static final int HID_DEVICE_MOUSE = 0x02;
public static final int HID_DEVICE_JOYSTICK = 0x04;
@ -125,6 +111,34 @@ public class OSXEnvironmentPlugin extends ControllerEnvironment implements Plugi
public static final int HID_ELEMENTTYPE_COLLECTION = 513;
static
{
System.loadLibrary("jinput");
}
public native void hidCreate();
public native void hidDispose();
public native void enumDevices();
/**
* Opens an input device and returns the address of the input queue for that device
*/
public native long openDevice( long lpDevice, int queueDepth );
public native void closeDevice( long lpDevice, long lpQueue );
/**
* Polls a device and returns the element top most on the input queue. The elements that
* are returned are only those that have had their hidCookies registered with registerDeviceElement.
* @param lpQueue
* @return
*/
public native int pollDevice( long lpQueue );
public native int pollElement( long lpDevice, long hidCookie );
public native void registerDeviceElement( long lpQueue, long hidCookie );
public native void deregisterDeviceElement( long lpQueue, long hidCookie );
private HashMap devices = new HashMap();

View file

@ -181,18 +181,7 @@ public class OSXMouse extends Mouse implements InputController
*/
public float getPollData()
{
/* // Mouse button
byte data = mouseData[index];
if ((data & 0x80) != 0)
{
return 1.0f;
}
else
{
return 0.0f;
}*/
return 0.0f;
return (float) plugin.pollElement( lpDevice, hidCookie );
}
/** Returns <code>true</code> if data returned from <code>poll</code>
@ -237,24 +226,7 @@ public class OSXMouse extends Mouse implements InputController
*/
public float getPollData()
{
/* int data = ((int) mouseData[index] << 12) |
((int) mouseData[index + 1] << 8) |
((int) mouseData[index + 2] << 4) |
((int) mouseData[index + 3]);
if (data == -1)
{
return -1.0f;
}
else if (data >= 1)
{
return 1.0f;
}
else
{
return 0.0f;
}*/
return 0.0f;
return (float) plugin.pollElement( lpDevice, hidCookie );
}
/** Returns <code>true</code> if data returned from <code>poll</code>

View file

@ -677,7 +677,7 @@ JNIEXPORT jlong JNICALL Java_net_java_games_input_OSXEnvironmentPlugin_openDevic
// create a queue and specify how deep they want the input queue to be
//
(*queue)->create( queue, 0, (int)queueDepth );
printf("InputQueue created %lx with depth %d \n", queue, (int)queueDepth );
printf("InputQueue created %lx with depth %d \n", (long) queue, (int)queueDepth );
// todo - add the buttons/keys we want to receive from the queue
@ -729,9 +729,9 @@ JNIEXPORT void JNICALL Java_net_java_games_input_OSXEnvironmentPlugin_closeDevic
/*
* Class: net_java_games_input_OSXEnvironmentPlugin
* Method: pollDevice
* Signature: (J)V
* Signature: (J)I
*/
JNIEXPORT void JNICALL Java_net_java_games_input_OSXEnvironmentPlugin_pollDevice
JNIEXPORT jint JNICALL Java_net_java_games_input_OSXEnvironmentPlugin_pollDevice
(JNIEnv * env, jobject obj, jlong lpQueue)
{
IOHIDEventStruct event;
@ -749,9 +749,86 @@ JNIEXPORT void JNICALL Java_net_java_games_input_OSXEnvironmentPlugin_pollDevice
else
{
printf("Queue event[%lx] %ld\n", (unsigned long) event.elementCookie, event.value );
}
return (jint) event.value;
}
/*
* Class: net_java_games_input_OSXEnvironmentPlugin
* Method: pollDevice
* Signature: (JJ)I
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_OSXEnvironmentPlugin_pollElement
(JNIEnv * env, jobject obj, jlong lpDevice, jlong hidCookie)
{
IOHIDDeviceInterface **hidDeviceInterface = NULL;
hidDeviceInterface = (IOHIDDeviceInterface **) (long)lpDevice;
IOHIDElementCookie cookie = (IOHIDElementCookie)(long)hidCookie;
IOHIDEventStruct event;
HRESULT result = (*hidDeviceInterface)->getElementValue(hidDeviceInterface, cookie, &event);
if ( result )
{
printf("Queue getNextEvent result: %lx\n", result );
}
else
{
printf("Queue event[%lx] %ld\n", (unsigned long) event.elementCookie, event.value );
}
return (jint) event.value;
}
/*
* Class: net_java_games_input_OSXEnvironmentPlugin
* Method: registerDeviceElement
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_OSXEnvironmentPlugin_registerDeviceElement
(JNIEnv * env, jobject obj, jlong lpQueue, jlong hidCookie)
{
IOHIDQueueInterface **queue = NULL;
queue = (IOHIDQueueInterface **)(long)lpQueue;
IOHIDElementCookie cookie = (IOHIDElementCookie)(long)hidCookie;
HRESULT result = (*queue)->addElement(queue, cookie, 0);
if ( result )
{
printf("Added pollElement: %ld\n", (long)cookie );
}
else
{
printf("Failed to add poll element: %ld\n", (long)cookie );
}
}
/*
* Class: net_java_games_input_OSXEnvironmentPlugin
* Method: deregisterDeviceElement
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_net_java_games_input_OSXEnvironmentPlugin_deregisterDeviceElement
(JNIEnv * env, jobject obj, jlong lpQueue, jlong hidCookie)
{
IOHIDQueueInterface **queue = NULL;
queue = (IOHIDQueueInterface **)(long)lpQueue;
IOHIDElementCookie cookie = (IOHIDElementCookie)(long)hidCookie;
HRESULT result = (*queue)->removeElement(queue, cookie );
if ( result )
{
printf("Removed pollElement: %ld\n", (long)cookie );
}
else
{
printf("Failed to remove poll element: %ld\n", (long)cookie );
}
}