From 988f11521829d2c0534d7e9331e91259d22725cc Mon Sep 17 00:00:00 2001 From: Brian Matzon Date: Fri, 3 Jan 2003 18:47:42 +0000 Subject: [PATCH] Joystick replaced by Controller GamePad no modelled as a controller --- .../input/{Joystick.java => Controller.java} | 46 ++-- src/java/org/lwjgl/input/GamePad.java | 256 ------------------ .../org/lwjgl/test/input/ControllerTest.java | 151 +++++++++++ .../org/lwjgl/test/input/JoystickTest.java | 151 ----------- .../common/org_lwjgl_input_Controller.h | 66 +++++ src/native/common/org_lwjgl_input_GamePad.h | 91 ------- src/native/common/org_lwjgl_input_Joystick.h | 66 ----- ...ick.cpp => org_lwjgl_input_Controller.cpp} | 140 +++++----- src/native/win32/org_lwjgl_input_GamePad.cpp | 126 --------- 9 files changed, 310 insertions(+), 783 deletions(-) rename src/java/org/lwjgl/input/{Joystick.java => Controller.java} (78%) delete mode 100644 src/java/org/lwjgl/input/GamePad.java create mode 100644 src/java/org/lwjgl/test/input/ControllerTest.java delete mode 100644 src/java/org/lwjgl/test/input/JoystickTest.java create mode 100644 src/native/common/org_lwjgl_input_Controller.h delete mode 100644 src/native/common/org_lwjgl_input_GamePad.h delete mode 100644 src/native/common/org_lwjgl_input_Joystick.h rename src/native/win32/{org_lwjgl_input_Joystick.cpp => org_lwjgl_input_Controller.cpp} (64%) delete mode 100644 src/native/win32/org_lwjgl_input_GamePad.cpp diff --git a/src/java/org/lwjgl/input/Joystick.java b/src/java/org/lwjgl/input/Controller.java similarity index 78% rename from src/java/org/lwjgl/input/Joystick.java rename to src/java/org/lwjgl/input/Controller.java index 3feb76a1..200bd895 100644 --- a/src/java/org/lwjgl/input/Joystick.java +++ b/src/java/org/lwjgl/input/Controller.java @@ -37,32 +37,32 @@ import org.lwjgl.Sys; /** * $Id$ *
- * A raw Joystick interface. This can be used to poll the current state of the - * joystick buttons, and determine the joystick position. The joystick position - * is returned as ints in the range -1000 to 1000. + * A raw Controller interface. This can be used to poll the current state of a + * controllers buttons, and axis positions. The axis positions + * are returned as ints in the range -1000 to 1000. * * No buffering is available. * * Currently n (native limits, currently 128 - might change) buttons, the x, y, * z axis is supported along with a POV (or HAT) and a slider, where the z axis - * represents a throttle. In the future the joystick may support more buttons + * represents a throttle. In the future the controller may support more buttons * and axises and other features. but this is a platform issue. * - * The joystick implementation currently only supports the first attached joystick. + * The Controller implementation currently only supports the first attached device. * * @author Brian Matzon * @version $Revision$ */ -public class Joystick { +public class Controller { static { initialize(); } - /** Has the joystick been created? */ + /** Has the controller been created? */ private static boolean created; - /** The joystick buttons status */ + /** The controller buttons status */ private static boolean[] buttons; /** X position, range -1000 to 1000 */ @@ -95,7 +95,7 @@ public class Joystick { /** Constant specifying westward POV */ public static final int POV_WEST = 9000; - /* Joystick capabilities */ + /* Controller capabilities */ public static int buttonCount = -1; public static boolean hasXAxis = false; public static boolean hasYAxis = false; @@ -104,9 +104,9 @@ public class Joystick { public static boolean hasSlider = false; /** - * Joystick cannot be constructed. + * Controller cannot be constructed. */ - private Joystick() { + private Controller() { } /** @@ -118,8 +118,8 @@ public class Joystick { } /** - * "Create" the joystick. The display must first have been created. - * @throws Exception if the joystick could not be created for any reason + * "Create" the controller. The display must first have been created. + * @throws Exception if the controller could not be created for any reason */ public static void create() throws Exception { if (created) { @@ -127,13 +127,13 @@ public class Joystick { } if (!nCreate()) { - throw new Exception("The joystick could not be created."); + throw new Exception("The controller could not be created."); } created = true; } /** - * "Destroy" the joystick + * "Destroy" the controller */ public static void destroy() { if (!created) { @@ -145,39 +145,39 @@ public class Joystick { } /** - * Polls the joystick. + * Polls the controller. */ public static void poll() { - assert created : "The joystick has not been created."; + assert created : "The controller has not been created."; nPoll(); } /** - * See if a particular mouse button is down. + * See if a particular button is down. * * @param button The index of the button you wish to test (0..buttonCount) * @return true if the specified button is down * @see #buttonCount */ public static boolean isButtonDown(int button) { - assert created : "The joystick has not been created."; + assert created : "The controller has not been created."; return buttons[button]; } /** - * Native method to poll the joystick + * Native method to poll the controller */ private static native void nPoll(); /** - * Native method to create the joystick + * Native method to create the controller * - * @return true if the joystick was created + * @return true if the controller was created */ private static native boolean nCreate(); /** - * Native method the destroy the joystick + * Native method the destroy the controller */ private static native void nDestroy(); diff --git a/src/java/org/lwjgl/input/GamePad.java b/src/java/org/lwjgl/input/GamePad.java deleted file mode 100644 index 4423cc69..00000000 --- a/src/java/org/lwjgl/input/GamePad.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2002 Lightweight Java Game Library Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'Light Weight Java Game Library' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.lwjgl.input; - -import java.nio.ByteBuffer; - -import org.lwjgl.Display; -import org.lwjgl.Sys; - -/** - * $Id$ - * - * A raw GamePad interface. This can be used to poll the current state of the - * buttons, or read all the gamepad presses / releases since the last read. - * Buffering must be explicitly enabled; the size of the buffer is determined - * by the native implementation at its discretion. - * - * @author cix_foo - * @version $Revision$ - */ -public class GamePad { - - // Button codes - public static int PAD_UP = 1; - public static int PAD_DOWN = 2; - public static int PAD_LEFT = 3; - public static int PAD_RIGHT = 4; - public static int PAD_BUTTON0 = 5; - public static int PAD_BUTTON1 = 6; - public static int PAD_BUTTON2 = 7; - public static int PAD_BUTTON3 = 8; - public static int PAD_BUTTON4 = 9; - public static int PAD_BUTTON5 = 10; - public static int PAD_BUTTON6 = 11; - public static int PAD_BUTTON7 = 12; - public static int PAD_BUTTON8 = 13; - - static { - initialize(); - } - - /** Has the gamepad been created? */ - private static boolean created; - - /** The buttons status from the last poll */ - private static final ByteBuffer buttonDownBuffer = ByteBuffer.allocateDirect(256); - - /** Address of the buttonDown buffer */ - private static final int buttonDownAddress = Sys.getDirectBufferAddress(buttonDownBuffer); - - /** - * The button events from the last read: a sequence of pairs of button number, - * followed by state. - */ - private static ByteBuffer readBuffer; - - /** Address of the read buffer */ - private static int readBufferAddress; - - /** The current gamepad event button being examined */ - public static int button; - - /** The current state of the button being examined in the event queue */ - public static boolean state; - - /** - * GamePad cannot be constructed. - */ - private GamePad() { - } - - /** - * Static initialization - */ - private static void initialize() { - System.loadLibrary(Sys.getLibraryName()); - initIDs(); - } - - /** - * Register fields with the native library - */ - private static native void initIDs(); - - /** - * "Create" the gamepad. The display must first have been created. The - * reason for this is so the gamepad has a window to "focus" in. - * - * @throws Exception if the gamepad could not be created for any reason - */ - public static void create() throws Exception { - if (created) - return; - if (!Display.isCreated()) - throw new Exception("The display has not yet been created."); - if (!nCreate()) - throw new Exception("The gamepad could not be created."); - created = true; - } - - /** - * Native method to create the gamepad - * - * @return true if the gamepad was created - */ - private static native boolean nCreate(); - - /** - * "Destroy" the gamepad - */ - public static void destroy() { - if (!created) - return; - created = false; - nDestroy(); - } - - /** - * Native method the destroy the gamepad - */ - private static native void nDestroy(); - - /** - * Polls the gamepad. - */ - public static void poll() { - assert created : "The gamepad has not been created."; - nPoll(buttonDownAddress); - } - - /** - * Native method to poll the gamepad. - * - * @param keyDownBufferAddress the address of a 256-byte buffer to place - * key states in. - */ - private static native void nPoll(int keyDownBufferAddress); - - /** - * Reads the gamepad buffer. Call next() to read the events one by one. - * @see #next() - */ - public static void read() { - assert created : "The gamepad has not been created."; - assert readBuffer != null : "GamePad buffering has not been enabled."; - readBuffer.clear(); - readBuffer.limit(nRead(readBufferAddress) << 1); - } - - /** - * Native method to read the gamepad buffer - * - * @param readBufferAddress the address of the gamepad buffer - * @return the number of gamepad events read - */ - private static native int nRead(int readBufferAddress); - - /** - * Enable gamepad buffering. Must be called after the gamepad is created. - * @return the size of the gamepad buffer in events, or 0 if no buffering - * can be enabled for any reason - */ - public static int enableBuffer() { - assert created : "The gamepad has not been created."; - return nEnableBuffer(); - } - - /** - * Native method to enable the buffer - * @return the size of the buffer allocated, in events (1 event is 2 bytes), - * or 0 if no buffer can be allocated - */ - private static native int nEnableBuffer(); - - /** - * Checks to see if a button is down. - * @param button The button code to check - * @return true if the button is down according to the last poll() - */ - public static boolean isButtonDown(int button) { - assert created : "The gamepad has not been created."; - return buttonDownBuffer.get(button) != 0; - } - - /** - * Gets the number of gamepad events waiting after doing a read(). - * @return the number of gamepad events - */ - public static int getNumGamePadEvents() { - return readBuffer.limit() >> 1; - } - - /** - * Gets the next gamepad event. This is stored in the publicly accessible - * static fields button and state. - * @return true if a gamepad event was read, false otherwise - */ - public static boolean next() { - assert created : "The gamepad has not been created."; - assert readBuffer != null : "GamePad buffering has not been enabled."; - - if (readBuffer.hasRemaining()) { - button = readBuffer.get(); - state = readBuffer.get() != 0; - return true; - } else - return false; - - } - - /** - * Queries the number of buttons the gamepad has (excluding up, down, left, right) - * @return the number of buttons the gamepad has - */ - public static int getNumButtons() { - assert created : "The gamepad has not been created."; - return nGetNumButtons(); - } - - /** - * Native implementation of getNumButtons() - */ - private static native int nGetNumButtons(); - - -} diff --git a/src/java/org/lwjgl/test/input/ControllerTest.java b/src/java/org/lwjgl/test/input/ControllerTest.java new file mode 100644 index 00000000..86aadbf5 --- /dev/null +++ b/src/java/org/lwjgl/test/input/ControllerTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2002 Lightweight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.test.input; + +import java.awt.*; +import java.awt.event.*; +import org.lwjgl.input.Controller; + +/** + * $Id$ + *
+ * Controller test, hwich shows a awt window, printing Controller state + * + * @author Brian Matzon + * @version $Revision$ + */ +public class ControllerTest extends Panel { + + private int counter = 0; + + public Thread animationThread; + + /** Creates a new instance of ControllerTest */ + public ControllerTest() { + try { + Controller.create(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + + animationThread = new Thread() { + public void run() { + while (true) { + paint(getGraphics()); + + try { + Thread.sleep(250); + } catch (InterruptedException inte) { + inte.printStackTrace(); + } + } + } + }; + animationThread.setDaemon(true); + } + + public void paint(Graphics g) { + if (g == null) { + return; + } + + g.setColor(Color.white); + g.fillRect(0, 0, 640, 480); + + int y = 100; + int x = 100; + Controller.poll(); + + g.setColor(Color.blue); + g.drawString("Buttoncount: " + Controller.buttonCount, x, y); + y += 20; + g.drawString("-----------------------------------------------", x, y); + y += 20; + g.drawString("x : " + Controller.x, x, y); + y += 20; + g.drawString("y : " + Controller.y, x, y); + y += 20; + if (Controller.hasZAxis) { + g.drawString("z : " + Controller.z, x, y); + y += 20; + } + if (Controller.hasPOV) { + g.drawString("pov: " + Controller.pov, x, y); + y += 20; + } + + //paint buttons + g.drawString("btn: ", x, y); + x += g.getFontMetrics().stringWidth("btn: "); + for (int i = 0; i < Controller.buttonCount; i++) { + if (Controller.isButtonDown(i)) { + g.drawString(i + ", ", x, y); + x += 15; + } + } + } + + public void update(Graphics g) { + paint(g); + } + + public void disposing() { + Controller.destroy(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + final ControllerTest p = new ControllerTest(); + final Frame f = new Frame(); + f.setLayout(null); + f.setSize(640, 480); + f.setLocation(100, 100); + f.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent we) { + f.hide(); + p.disposing(); + f.dispose(); + } + }); + + p.setSize(640, 480); + p.setLocation(0, 0); + p.setBackground(Color.RED); + + f.add(p); + f.show(); + p.animationThread.start(); + } +} \ No newline at end of file diff --git a/src/java/org/lwjgl/test/input/JoystickTest.java b/src/java/org/lwjgl/test/input/JoystickTest.java deleted file mode 100644 index d1433372..00000000 --- a/src/java/org/lwjgl/test/input/JoystickTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2002 Lightweight Java Game Library Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'Light Weight Java Game Library' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.lwjgl.test.input; - -import java.awt.*; -import java.awt.event.*; -import org.lwjgl.input.Joystick; - -/** - * $Id$ - *
- * Joystick test, hwich shows a awt window, printing joystick state - * - * @author Brian Matzon - * @version $Revision$ - */ -public class JoystickTest extends Panel { - - private int counter = 0; - - public Thread animationThread; - - /** Creates a new instance of JoystickTest */ - public JoystickTest() { - try { - Joystick.create(); - } catch (Exception e) { - e.printStackTrace(); - return; - } - - animationThread = new Thread() { - public void run() { - while (true) { - paint(getGraphics()); - - try { - Thread.sleep(250); - } catch (InterruptedException inte) { - inte.printStackTrace(); - } - } - } - }; - animationThread.setDaemon(true); - } - - public void paint(Graphics g) { - if (g == null) { - return; - } - - g.setColor(Color.white); - g.fillRect(0, 0, 640, 480); - - int y = 100; - int x = 100; - Joystick.poll(); - - g.setColor(Color.blue); - g.drawString("Buttoncount: " + Joystick.buttonCount, x, y); - y += 20; - g.drawString("-----------------------------------------------", x, y); - y += 20; - g.drawString("x : " + Joystick.x, x, y); - y += 20; - g.drawString("y : " + Joystick.y, x, y); - y += 20; - if(Joystick.hasZAxis) { - g.drawString("z : " + Joystick.z, x, y); - y += 20; - } - if(Joystick.hasPOV) { - g.drawString("pov: " + Joystick.pov, x, y); - y += 20; - } - - //paint buttons - g.drawString("btn: ", x, y); - x += g.getFontMetrics().stringWidth("btn: "); - for(int i=0; i +/* Header for class org_lwjgl_input_Controller */ + +#ifndef _Included_org_lwjgl_input_Controller +#define _Included_org_lwjgl_input_Controller +#ifdef __cplusplus +extern "C" { +#endif +/* Inaccessible static: _00024assertionsDisabled */ +/* Inaccessible static: created */ +/* Inaccessible static: buttons */ +/* Inaccessible static: x */ +/* Inaccessible static: y */ +/* Inaccessible static: z */ +/* Inaccessible static: pov */ +#undef org_lwjgl_input_Controller_POV_CENTER +#define org_lwjgl_input_Controller_POV_CENTER -1L +#undef org_lwjgl_input_Controller_POV_NORTH +#define org_lwjgl_input_Controller_POV_NORTH 0L +#undef org_lwjgl_input_Controller_POV_SOUTH +#define org_lwjgl_input_Controller_POV_SOUTH 18000L +#undef org_lwjgl_input_Controller_POV_EAST +#define org_lwjgl_input_Controller_POV_EAST 27000L +#undef org_lwjgl_input_Controller_POV_WEST +#define org_lwjgl_input_Controller_POV_WEST 9000L +/* Inaccessible static: buttonCount */ +/* Inaccessible static: hasZAxis */ +/* Inaccessible static: hasPOV */ +/* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Controller */ +/* + * Class: org_lwjgl_input_Controller + * Method: nPoll + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll + (JNIEnv *, jclass); + +/* + * Class: org_lwjgl_input_Controller + * Method: nCreate + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Controller_nCreate + (JNIEnv *, jclass); + +/* + * Class: org_lwjgl_input_Controller + * Method: nDestroy + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nDestroy + (JNIEnv *, jclass); + +/* + * Class: org_lwjgl_input_Controller + * Method: initIDs + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_initIDs + (JNIEnv *, jclass); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/native/common/org_lwjgl_input_GamePad.h b/src/native/common/org_lwjgl_input_GamePad.h deleted file mode 100644 index 9200271b..00000000 --- a/src/native/common/org_lwjgl_input_GamePad.h +++ /dev/null @@ -1,91 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class org_lwjgl_input_GamePad */ - -#ifndef _Included_org_lwjgl_input_GamePad -#define _Included_org_lwjgl_input_GamePad -#ifdef __cplusplus -extern "C" { -#endif -/* Inaccessible static: _00024assertionsDisabled */ -/* Inaccessible static: PAD_UP */ -/* Inaccessible static: PAD_DOWN */ -/* Inaccessible static: PAD_LEFT */ -/* Inaccessible static: PAD_RIGHT */ -/* Inaccessible static: PAD_BUTTON0 */ -/* Inaccessible static: PAD_BUTTON1 */ -/* Inaccessible static: PAD_BUTTON2 */ -/* Inaccessible static: PAD_BUTTON3 */ -/* Inaccessible static: PAD_BUTTON4 */ -/* Inaccessible static: PAD_BUTTON5 */ -/* Inaccessible static: PAD_BUTTON6 */ -/* Inaccessible static: PAD_BUTTON7 */ -/* Inaccessible static: PAD_BUTTON8 */ -/* Inaccessible static: created */ -/* Inaccessible static: buttonDownBuffer */ -/* Inaccessible static: buttonDownAddress */ -/* Inaccessible static: readBuffer */ -/* Inaccessible static: readBufferAddress */ -/* Inaccessible static: button */ -/* Inaccessible static: state */ -/* Inaccessible static: class_000240 */ -/* - * Class: org_lwjgl_input_GamePad - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_GamePad_initIDs - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_input_GamePad - * Method: nCreate - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_GamePad_nCreate - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_input_GamePad - * Method: nDestroy - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_GamePad_nDestroy - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_input_GamePad - * Method: nPoll - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_GamePad_nPoll - (JNIEnv *, jclass, jint); - -/* - * Class: org_lwjgl_input_GamePad - * Method: nRead - * Signature: (I)I - */ -JNIEXPORT jint JNICALL Java_org_lwjgl_input_GamePad_nRead - (JNIEnv *, jclass, jint); - -/* - * Class: org_lwjgl_input_GamePad - * Method: nEnableBuffer - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_org_lwjgl_input_GamePad_nEnableBuffer - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_input_GamePad - * Method: nGetNumButtons - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_org_lwjgl_input_GamePad_nGetNumButtons - (JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/native/common/org_lwjgl_input_Joystick.h b/src/native/common/org_lwjgl_input_Joystick.h deleted file mode 100644 index ac60319c..00000000 --- a/src/native/common/org_lwjgl_input_Joystick.h +++ /dev/null @@ -1,66 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class org_lwjgl_input_Joystick */ - -#ifndef _Included_org_lwjgl_input_Joystick -#define _Included_org_lwjgl_input_Joystick -#ifdef __cplusplus -extern "C" { -#endif -/* Inaccessible static: _00024assertionsDisabled */ -/* Inaccessible static: created */ -/* Inaccessible static: buttons */ -/* Inaccessible static: x */ -/* Inaccessible static: y */ -/* Inaccessible static: z */ -/* Inaccessible static: pov */ -#undef org_lwjgl_input_Joystick_POV_CENTER -#define org_lwjgl_input_Joystick_POV_CENTER -1L -#undef org_lwjgl_input_Joystick_POV_NORTH -#define org_lwjgl_input_Joystick_POV_NORTH 0L -#undef org_lwjgl_input_Joystick_POV_SOUTH -#define org_lwjgl_input_Joystick_POV_SOUTH 18000L -#undef org_lwjgl_input_Joystick_POV_EAST -#define org_lwjgl_input_Joystick_POV_EAST 27000L -#undef org_lwjgl_input_Joystick_POV_WEST -#define org_lwjgl_input_Joystick_POV_WEST 9000L -/* Inaccessible static: buttonCount */ -/* Inaccessible static: hasZAxis */ -/* Inaccessible static: hasPOV */ -/* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Joystick */ -/* - * Class: org_lwjgl_input_Joystick - * Method: nPoll - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_Joystick_nPoll - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_input_Joystick - * Method: nCreate - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Joystick_nCreate - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_input_Joystick - * Method: nDestroy - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_Joystick_nDestroy - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_input_Joystick - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_Joystick_initIDs - (JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/native/win32/org_lwjgl_input_Joystick.cpp b/src/native/win32/org_lwjgl_input_Controller.cpp similarity index 64% rename from src/native/win32/org_lwjgl_input_Joystick.cpp rename to src/native/win32/org_lwjgl_input_Controller.cpp index 3b21678d..7c1db5ad 100644 --- a/src/native/win32/org_lwjgl_input_Joystick.cpp +++ b/src/native/win32/org_lwjgl_input_Controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 Light Weight Java Game Library Project + * Copyright (c) 2002 Lightweight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,27 +32,27 @@ /** * $Id$ * - * Win32 analogue joystick handling. + * Win32 controller handling. * * @author Brian Matzon * @version $Revision$ */ #define WIN32_LEAN_AND_MEAN -#include "org_lwjgl_input_Joystick.h" +#include "org_lwjgl_input_Controller.h" #include #undef DIRECTINPUT_VERSION #define DIRECTINPUT_VERSION 0x0500 #include -#define JOYMAX 1000 // Maxmimum range to which we'll gauge the swing -#define JOYMIN -1000 // Minimum range to which we'll gauge the swing +#define AXISMAX 1000 // Maxmimum range to which we'll gauge the swing +#define AXISMIN -1000 // Minimum range to which we'll gauge the swing extern HWND hwnd; // Handle to window IDirectInput* lpDI; // DI instance IDirectInputDevice2* lpDIDevice; // DI Device instance -DIJOYSTATE2 js; // State of joystick +DIJOYSTATE2 js; // State of Controller int buttoncount = 0; // Temporary buttoncount bool hasz; // Temporary zaxis check @@ -62,8 +62,8 @@ JNIEnv* environment; // JNIEnvironment copy bool create_success; // bool used to determine successfull creation -// Cached fields of Joystick.java -jclass clsJoystick; +// Cached fields of Controller.java +jclass clsController; jfieldID fidButtonCount; jfieldID fidHasZAxis; jfieldID fidHasPOV; @@ -75,12 +75,12 @@ jfieldID fidPOV; // Function prototypes (defined in the cpp file, since header file is generic across platforms void EnumerateCapabilities(); -void EnumerateJoysticks(); -BOOL CALLBACK EnumJoystickCallback(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef); -BOOL CALLBACK EnumJoystickObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef); +void EnumerateControllers(); +BOOL CALLBACK EnumControllerCallback(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef); +BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef); void Shutdown(); -void CreateJoystick(LPCDIDEVICEINSTANCE lpddi); -void SetupJoystick(); +void CreateController(LPCDIDEVICEINSTANCE lpddi); +void SetupController(); void InitializeFields(); void CacheFields(); void UpdateFields(); @@ -90,18 +90,18 @@ void PrintError(HRESULT error); /** * Initializes any field ids */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_Joystick_initIDs(JNIEnv * env, jclass clazz) { +JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_initIDs(JNIEnv * env, jclass clazz) { environment = env; - clsJoystick = clazz; + clsController = clazz; - /* Cache fields in Joystick */ + /* Cache fields in Controller */ CacheFields(); } /** - * Called when the Joystick instance is to be created + * Called when the Controller instance is to be created */ -JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Joystick_nCreate(JNIEnv *env, jclass clazz) { +JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jclass clazz) { // Create the DirectInput object. HRESULT hr; hr = DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &lpDI, NULL); @@ -110,27 +110,27 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Joystick_nCreate(JNIEnv *env, jc return JNI_FALSE; } - /* Find all joysticks */ - EnumerateJoysticks(); + /* Find all Controllers */ + EnumerateControllers(); if (!create_success) { Shutdown(); return JNI_FALSE; } - /* Enumerate capabilities of joystick */ + /* Enumerate capabilities of Controller */ EnumerateCapabilities(); if (!create_success) { Shutdown(); return JNI_FALSE; } - /* Initialize any fields on the Joystick */ + /* Initialize any fields on the Controller */ InitializeFields(); /* Set capabilities */ SetCapabilities(); - /* Aquire the joystick */ + /* Aquire the Controller */ hr = lpDIDevice->Acquire(); if(FAILED(hr)) { Shutdown(); @@ -141,23 +141,23 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Joystick_nCreate(JNIEnv *env, jc } /* - * Class: org_lwjgl_input_Joystick + * Class: org_lwjgl_input_Controller * Method: nDestroy * Signature: ()V */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_Joystick_nDestroy(JNIEnv *env, jclass clazz) { +JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nDestroy(JNIEnv *env, jclass clazz) { Shutdown(); } /* - * Class: org_lwjgl_input_Joystick + * Class: org_lwjgl_input_Controller * Method: nPoll * Signature: ()V */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_Joystick_nPoll(JNIEnv * env, jclass clazz) { +JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll(JNIEnv * env, jclass clazz) { HRESULT hRes; - // poll the joystick to read the current state + // poll the Controller to read the current state hRes = lpDIDevice->Poll(); if (FAILED(hRes)) { #if _DEBUG @@ -187,11 +187,11 @@ void Shutdown() { } /** - * Enumerates the capabilities of the joystick attached to the system + * Enumerates the capabilities of the Controller attached to the system */ void EnumerateCapabilities() { HRESULT hr; - hr = lpDIDevice->EnumObjects(EnumJoystickObjectsCallback, NULL, DIDFT_ALL); + hr = lpDIDevice->EnumObjects(EnumControllerObjectsCallback, NULL, DIDFT_ALL); if FAILED(hr) { create_success = false; return; @@ -200,11 +200,11 @@ void EnumerateCapabilities() { } /** - * Enumerates the joysticks attached to the system + * Enumerates the Controllers attached to the system */ -void EnumerateJoysticks() { +void EnumerateControllers() { HRESULT hr; - hr = lpDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumJoystickCallback, 0, DIEDFL_ATTACHEDONLY); + hr = lpDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY); if FAILED(hr) { create_success = false; return; @@ -213,24 +213,24 @@ void EnumerateJoysticks() { } /** - * Callback from EnumDevices. Called for each joystick attached to the system + * Callback from EnumDevices. Called for each Controller attached to the system */ -BOOL CALLBACK EnumJoystickCallback(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef) { - /* Add the joystick */ - CreateJoystick(pdinst); +BOOL CALLBACK EnumControllerCallback(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef) { + /* Add the Controller */ + CreateController(pdinst); if(create_success) { - /* Do setup of joystick */ - SetupJoystick(); + /* Do setup of Controller */ + SetupController(); } - /* just stop after 1st joystick */ + /* just stop after 1st Controller */ return DIENUM_STOP; } /** - * Callback from EnumObjects. Called for each "object" on the joystick. + * Callback from EnumObjects. Called for each "object" on the Controller. */ -BOOL CALLBACK EnumJoystickObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { +BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { if(lpddoi->guidType == GUID_Button) { buttoncount++; } else if(lpddoi->guidType == GUID_XAxis || lpddoi->guidType == GUID_YAxis) { @@ -248,9 +248,9 @@ BOOL CALLBACK EnumJoystickObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVO } /** - * Creates the specified device as a joystick + * Creates the specified device as a Controller */ -void CreateJoystick(LPCDIDEVICEINSTANCE lpddi) { +void CreateController(LPCDIDEVICEINSTANCE lpddi) { HRESULT hr; hr = lpDI->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &lpDIDevice, NULL); if FAILED(hr) { @@ -261,10 +261,10 @@ void CreateJoystick(LPCDIDEVICEINSTANCE lpddi) { } /** - * Sets up the joystick properties + * Sets up the Controller properties */ -void SetupJoystick() { - // set joystick data format +void SetupController() { + // set Controller data format if(lpDIDevice->SetDataFormat(&c_dfDIJoystick2) != DI_OK) { create_success = false; return; @@ -283,8 +283,8 @@ void SetupJoystick() { diprg.diph.dwHeaderSize = sizeof(diprg.diph); diprg.diph.dwObj = DIJOFS_X; diprg.diph.dwHow = DIPH_BYOFFSET; - diprg.lMin = JOYMIN; - diprg.lMax = JOYMAX; + diprg.lMin = AXISMIN; + diprg.lMax = AXISMAX; if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) { create_success = false; @@ -315,21 +315,21 @@ void SetupJoystick() { } /** - * Sets the fields on the Joystick + * Sets the fields on the Controller */ void InitializeFields() { //set buttons array jbooleanArray buttonsArray = environment->NewBooleanArray(buttoncount); - environment->SetStaticObjectField(clsJoystick, fidButtons, buttonsArray); + environment->SetStaticObjectField(clsController, fidButtons, buttonsArray); } /** - * Updates the fields on the Joystick + * Updates the fields on the Controller */ void UpdateFields() { HRESULT hRes; - // get data from the joystick + // get data from the Controller hRes = lpDIDevice->GetDeviceState(sizeof(DIJOYSTATE2), &js); if (hRes != DI_OK) { @@ -345,48 +345,48 @@ void UpdateFields() { } //axis's - environment->SetStaticIntField(clsJoystick, fidX, js.lX); - environment->SetStaticIntField(clsJoystick, fidY, js.lY); + environment->SetStaticIntField(clsController, fidX, js.lX); + environment->SetStaticIntField(clsController, fidY, js.lY); if(hasz) { - environment->SetStaticIntField(clsJoystick, fidZ, js.lZ); + environment->SetStaticIntField(clsController, fidZ, js.lZ); } //buttons - jbooleanArray buttonsArray = (jbooleanArray) environment->GetStaticObjectField(clsJoystick, fidButtons); + jbooleanArray buttonsArray = (jbooleanArray) environment->GetStaticObjectField(clsController, fidButtons); BYTE * buttons = (BYTE *) environment->GetPrimitiveArrayCritical(buttonsArray, NULL); memcpy(buttons, js.rgbButtons, buttoncount); environment->ReleasePrimitiveArrayCritical(buttonsArray, buttons, 0); //pov if(haspov) { - environment->SetStaticIntField(clsJoystick, fidPOV, js.rgdwPOV[0]); + environment->SetStaticIntField(clsController, fidPOV, js.rgdwPOV[0]); } } /** - * Sets the capabilities of the joystick + * Sets the capabilities of the Controller */ void SetCapabilities() { //set buttoncount - environment->SetStaticIntField(clsJoystick, fidButtonCount, buttoncount); + environment->SetStaticIntField(clsController, fidButtonCount, buttoncount); //set z axis - environment->SetStaticIntField(clsJoystick, fidHasZAxis, hasz); + environment->SetStaticIntField(clsController, fidHasZAxis, hasz); //set pov - environment->SetStaticIntField(clsJoystick, fidHasPOV, haspov); + environment->SetStaticIntField(clsController, fidHasPOV, haspov); } /** * Caches the field ids for quicker access */ void CacheFields() { - fidButtonCount = environment->GetStaticFieldID(clsJoystick, "buttonCount", "I"); - fidHasZAxis = environment->GetStaticFieldID(clsJoystick, "hasZAxis", "Z"); - fidHasPOV = environment->GetStaticFieldID(clsJoystick, "hasPOV", "Z"); - fidButtons = environment->GetStaticFieldID(clsJoystick, "buttons", "[Z"); - fidX = environment->GetStaticFieldID(clsJoystick, "x", "I"); - fidY = environment->GetStaticFieldID(clsJoystick, "y", "I"); - fidZ = environment->GetStaticFieldID(clsJoystick, "z", "I"); - fidPOV = environment->GetStaticFieldID(clsJoystick, "pov", "I"); + fidButtonCount = environment->GetStaticFieldID(clsController, "buttonCount", "I"); + fidHasZAxis = environment->GetStaticFieldID(clsController, "hasZAxis", "Z"); + fidHasPOV = environment->GetStaticFieldID(clsController, "hasPOV", "Z"); + fidButtons = environment->GetStaticFieldID(clsController, "buttons", "[Z"); + fidX = environment->GetStaticFieldID(clsController, "x", "I"); + fidY = environment->GetStaticFieldID(clsController, "y", "I"); + fidZ = environment->GetStaticFieldID(clsController, "z", "I"); + fidPOV = environment->GetStaticFieldID(clsController, "pov", "I"); } \ No newline at end of file diff --git a/src/native/win32/org_lwjgl_input_GamePad.cpp b/src/native/win32/org_lwjgl_input_GamePad.cpp deleted file mode 100644 index 6ec2c6af..00000000 --- a/src/native/win32/org_lwjgl_input_GamePad.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2002 Light Weight Java Game Library Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'Light Weight Java Game Library' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * $Id$ - * - * Win32 digital (Atari) joystick handling. These days it's a gamepad. - * - * @author cix_foo - * @version $Revision$ - */ - - -#define WIN32_LEAN_AND_MEAN - -#include -#include "org_lwjgl_input_GamePad.h" -#undef DIRECTINPUT_VERSION -#define DIRECTINPUT_VERSION 0x0300 -#include - -extern LPDIRECTINPUT lpdi; -LPDIRECTINPUTDEVICE lpdiGamePad; -extern HWND hwnd; // The display, which must have been created -/* - * Class: org_lwjgl_input_GamePad - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_GamePad_initIDs - (JNIEnv * env, jclass clazz) {} - -/* - * Class: org_lwjgl_input_GamePad - * Method: nCreate - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_GamePad_nCreate - (JNIEnv * env, jclass clazz) -{ - printf("GamePad not implemented yet!\n"); - return JNI_FALSE; -} - -/* - * Class: org_lwjgl_input_GamePad - * Method: nDestroy - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_GamePad_nDestroy - (JNIEnv * env, jclass clazz) -{ -} - -/* - * Class: org_lwjgl_input_GamePad - * Method: nPoll - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_input_GamePad_nPoll - (JNIEnv * env, jclass clazz, jint buf) -{ -} - -/* - * Class: org_lwjgl_input_GamePad - * Method: nRead - * Signature: (I)I - */ -JNIEXPORT jint JNICALL Java_org_lwjgl_input_GamePad_nRead - (JNIEnv * env, jclass clazz, jint buf) -{ - return 0; -} - -/* - * Class: org_lwjgl_input_GamePad - * Method: nEnableBuffer - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_org_lwjgl_input_GamePad_nEnableBuffer - (JNIEnv * env, jclass clazz) -{ - return 0; -} - -/* - * Class: org_lwjgl_input_GamePad - * Method: nGetNumButtons - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_org_lwjgl_input_GamePad_nGetNumButtons - (JNIEnv * env, jclass clazz) -{ - return 0; -} -