diff --git a/src/java/org/lwjgl/input/Keyboard.java b/src/java/org/lwjgl/input/Keyboard.java
index 71a440ee..fab9ecdf 100644
--- a/src/java/org/lwjgl/input/Keyboard.java
+++ b/src/java/org/lwjgl/input/Keyboard.java
@@ -40,6 +40,7 @@ import java.util.HashMap;
import java.util.Map;
import org.lwjgl.Sys;
+import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.Window;
/**
@@ -191,11 +192,14 @@ public class Keyboard {
public static final int KEY_APPS = 0xDD; /* AppMenu key */
public static final int KEY_POWER = 0xDE;
public static final int KEY_SLEEP = 0xDF;
-
- public static final int STATE_ON = 0;
- public static final int STATE_OFF = 1;
- public static final int STATE_UNKNOWN = 2;
-
+
+ public static final int STATE_ON = 0;
+ public static final int STATE_OFF = 1;
+ public static final int STATE_UNKNOWN = 2;
+
+ /** Buffer size in events */
+ private final static int BUFFER_SIZE = 50;
+
/** Key names */
private static final String[] keyName = new String[255];
private static final Map keyMap = new HashMap(253);
@@ -243,9 +247,6 @@ public class Keyboard {
/** True if translation is enabled */
private static boolean translationEnabled;
- /** The number of events read in the last read() */
- private static int numEvents;
-
/** The current keyboard character being examined */
private static char eventCharacter;
@@ -285,7 +286,7 @@ public class Keyboard {
* @throws Exception if the keyboard could not be created for any reason
*/
public static void create() throws Exception {
- assert Window.isCreated() : "Window must be created prior to creating keyboard";
+ assert Window.isCreated() : "Window must be created prior to creating keyboard";
if (!initialized)
initialize();
if (created)
@@ -322,16 +323,16 @@ public class Keyboard {
private static native void nDestroy();
/**
- * Polls the keyboard for its current state. Access the polled values using the
- * isKeyDown method.
- * By using this method, it is possible to "miss" keyboard keys if you don't
- * poll fast enough. To receive all events, enable buffering by calling
- * enableBuffer, and read those events by calling read
- *
- * @see org.lwjgl.input.Keyboard#isKeyDown(int key)
- * @see org.lwjgl.input.Keyboard#isStateKeySet(int key)
- * @see org.lwjgl.input.Keyboard#enableBuffer()
- * @see org.lwjgl.input.Keyboard#read()
+ * Polls the keyboard for its current state. Access the polled values using the
+ * isKeyDown method.
+ * By using this method, it is possible to "miss" keyboard keys if you don't
+ * poll fast enough. To receive all events, enable buffering by calling
+ * enableBuffer, and read those events by calling read
+ *
+ * @see org.lwjgl.input.Keyboard#isKeyDown(int key)
+ * @see org.lwjgl.input.Keyboard#isStateKeySet(int key)
+ * @see org.lwjgl.input.Keyboard#enableBuffer()
+ * @see org.lwjgl.input.Keyboard#read()
*/
public static void poll() {
assert created : "The keyboard has not been created.";
@@ -347,35 +348,36 @@ public class Keyboard {
private static native void nPoll(ByteBuffer keyDownBuffer);
/**
- * Reads all keyboard events since last read.
- * To use these values, you have to call next for each event you
- * want to read. You can query which key caused the event by using
- * getEventKey. To get the state of that key, for that event, use
- * getEventKeyState - finally use getEventCharacter to get the
- * character for that event.
- *
- * @see org.lwjgl.input.Keyboard#next()
- * @see org.lwjgl.input.Keyboard#enableBuffer()
- * @see org.lwjgl.input.Keyboard#getEventKey()
- * @see org.lwjgl.input.Keyboard#getEventKeyState()
- * @see org.lwjgl.input.Keyboard#getEventCharacter()
+ * Reads all keyboard events since last read.
+ * To use these values, you have to call next for each event you
+ * want to read. You can query which key caused the event by using
+ * getEventKey. To get the state of that key, for that event, use
+ * getEventKeyState - finally use getEventCharacter to get the
+ * character for that event.
+ *
+ * @see org.lwjgl.input.Keyboard#next()
+ * @see org.lwjgl.input.Keyboard#enableBuffer()
+ * @see org.lwjgl.input.Keyboard#getEventKey()
+ * @see org.lwjgl.input.Keyboard#getEventKeyState()
+ * @see org.lwjgl.input.Keyboard#getEventCharacter()
*/
public static void read() {
assert created : "The keyboard has not been created.";
assert readBuffer != null : "Keyboard buffering has not been enabled.";
- numEvents = nRead();
- readBuffer.clear();
+ readBuffer.compact();
+ int numEvents = nRead(readBuffer, readBuffer.position());
if (translationEnabled)
- readBuffer.limit(numEvents << 2);
+ readBuffer.position(readBuffer.position() + numEvents*4);
else
- readBuffer.limit(numEvents << 1);
+ readBuffer.position(readBuffer.position() + numEvents*2);
+ readBuffer.flip();
}
/**
* Native method to read the keyboard buffer
* @return the total number of events read.
*/
- private static native int nRead();
+ private static native int nRead(ByteBuffer buffer, int buffer_position);
/**
* Enable keyboard translation. Must be called after the keyboard is created,
@@ -384,7 +386,6 @@ public class Keyboard {
public static void enableTranslation() throws Exception {
assert created : "The keyboard has not been created.";
assert readBuffer != null : "Keyboard buffering has not been enabled.";
-
nEnableTranslation();
translationEnabled = true;
}
@@ -396,14 +397,12 @@ public class Keyboard {
/**
* Enable keyboard buffering. Must be called after the keyboard is created.
- * @return the size of the keyboard buffer in events, or 0 if no buffering
- * can be enabled for any reason
*/
- public static int enableBuffer() throws Exception {
+ public static void enableBuffer() throws Exception {
assert created : "The keyboard has not been created.";
- readBuffer = nEnableBuffer();
- readBuffer.order(ByteOrder.nativeOrder());
- return readBuffer.capacity()/2;
+ readBuffer = BufferUtils.createByteBuffer(4*BUFFER_SIZE);
+ readBuffer.limit(0);
+ nEnableBuffer();
}
/**
@@ -411,7 +410,7 @@ public class Keyboard {
* @return the event buffer,
* or null if no buffer can be allocated
*/
- private static native ByteBuffer nEnableBuffer() throws Exception;
+ private static native void nEnableBuffer() throws Exception;
/**
* Checks to see if a key is down.
@@ -436,18 +435,18 @@ public class Keyboard {
public static boolean isTranslationEnabled() {
return translationEnabled;
}
-
- /**
- * Checks whether one of the state keys are "active"
- *
- * @param key State key to test (KEY_CAPITAL | KEY_NUMLOCK | KEY_SYSRQ)
- * @return STATE_ON if on, STATE_OFF if off and STATE_UNKNOWN if the state is unknown
- */
- public static int isStateKeySet(int key) {
- assert created : "The keyboard has not been created.";
- return nisStateKeySet(key);
- }
- private static native int nisStateKeySet(int key);
+
+ /**
+ * Checks whether one of the state keys are "active"
+ *
+ * @param key State key to test (KEY_CAPITAL | KEY_NUMLOCK | KEY_SYSRQ)
+ * @return STATE_ON if on, STATE_OFF if off and STATE_UNKNOWN if the state is unknown
+ */
+ public static int isStateKeySet(int key) {
+ assert created : "The keyboard has not been created.";
+ return nisStateKeySet(key);
+ }
+ private static native int nisStateKeySet(int key);
/**
* Gets a key's name
@@ -463,7 +462,7 @@ public class Keyboard {
* @param keyName The key name
*/
public static int getKeyIndex(String keyName) {
- Integer ret = (Integer) keyMap.get(keyName);
+ Integer ret = (Integer) keyMap.get(keyName);
if (ret == null)
return KEY_NONE;
else
@@ -476,19 +475,22 @@ public class Keyboard {
*/
public static int getNumKeyboardEvents() {
assert created : "The keyboard has not been created.";
- return numEvents;
+ if (translationEnabled)
+ return readBuffer.remaining()/4;
+ else
+ return readBuffer.remaining()/2;
}
/**
- * Gets the next keyboard event. You can query which key caused the event by using
- * getEventKey. To get the state of that key, for that event, use
- * getEventKeyState - finally use getEventCharacter to get the
- * character for that event.
- *
- * @see org.lwjgl.input.Keyboard#getEventKey()
- * @see org.lwjgl.input.Keyboard#getEventKeyState()
- * @see org.lwjgl.input.Keyboard#getEventCharacter()
- * @return true if a keyboard event was read, false otherwise
+ * Gets the next keyboard event. You can query which key caused the event by using
+ * getEventKey. To get the state of that key, for that event, use
+ * getEventKeyState - finally use getEventCharacter to get the
+ * character for that event.
+ *
+ * @see org.lwjgl.input.Keyboard#getEventKey()
+ * @see org.lwjgl.input.Keyboard#getEventKeyState()
+ * @see org.lwjgl.input.Keyboard#getEventCharacter()
+ * @return true if a keyboard event was read, false otherwise
*/
public static boolean next() {
assert created : "The keyboard has not been created.";
@@ -499,41 +501,41 @@ public class Keyboard {
eventState = readBuffer.get() != 0;
if (translationEnabled) {
eventCharacter = readBuffer.getChar();
- }
+ }
return true;
} else {
return false;
- }
+ }
}
/**
* @return Number of keys on this keyboard
*/
- public static int getKeyCount() {
- return keyCount;
- }
+ public static int getKeyCount() {
+ return keyCount;
+ }
- /**
- * @return The character from the current event
- */
- public static char getEventCharacter() {
- return eventCharacter;
- }
+ /**
+ * @return The character from the current event
+ */
+ public static char getEventCharacter() {
+ return eventCharacter;
+ }
- /**
- * @return The key from the current event
- */
- public static int getEventKey() {
- return eventKey;
- }
+ /**
+ * @return The key from the current event
+ */
+ public static int getEventKey() {
+ return eventKey;
+ }
- /**
- * Gets the state of the tkey that generated the
- * current event
- *
- * @return True if key was down, or false if released
- */
- public static boolean getEventKeyState() {
- return eventState;
- }
-}
\ No newline at end of file
+ /**
+ * Gets the state of the tkey that generated the
+ * current event
+ *
+ * @return True if key was down, or false if released
+ */
+ public static boolean getEventKeyState() {
+ return eventState;
+ }
+}
diff --git a/src/java/org/lwjgl/input/Mouse.java b/src/java/org/lwjgl/input/Mouse.java
index 7c13733c..931be48f 100644
--- a/src/java/org/lwjgl/input/Mouse.java
+++ b/src/java/org/lwjgl/input/Mouse.java
@@ -38,6 +38,7 @@ import java.util.HashMap;
import java.util.Map;
import org.lwjgl.Sys;
+import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.Window;
/**
@@ -57,15 +58,15 @@ import org.lwjgl.opengl.Window;
* @version $Revision$
*/
public class Mouse {
-
- /** 1 bit transparency for native cursor */
+
+ /** 1 bit transparency for native cursor */
public final static int CURSOR_ONE_BIT_TRANSPARENCY = 1;
-
- /** 8 bit alhpa native cursor */
+
+ /** 8 bit alhpa native cursor */
public final static int CURSOR_8_BIT_ALPHA = 2;
-
- /** animation native cursor */
- public final static int CURSOR_ANIMATION = 4;
+
+ /** animation native cursor */
+ public final static int CURSOR_ANIMATION = 4;
/** Has the mouse been created? */
private static boolean created;
@@ -73,12 +74,12 @@ public class Mouse {
/** The mouse buttons status from the last poll */
private static byte[] buttons;
- /** X */
- private static int x;
+ /** X */
+ private static int x;
- /** Y */
- private static int y;
-
+ /** Y */
+ private static int y;
+
/** Delta X */
private static int dx;
@@ -99,8 +100,8 @@ public class Mouse {
/** Button names. These are set upon create(), to names like BUTTON0, BUTTON1, etc. */
private static String[] buttonName;
-
- /** hashmap of button names, for fast lookup */
+
+ /** hashmap of button names, for fast lookup */
private static final Map buttonMap = new HashMap(16);
/** Lazy initialization */
@@ -113,7 +114,10 @@ public class Mouse {
private static int eventButton;
/** The current state of the button being examined in the event queue */
- private static boolean eventState;
+ private static boolean eventState;
+
+ /** Buffer size in events */
+ private final static int BUFFER_SIZE = 50;
/**
* Mouse cannot be constructed.
@@ -161,7 +165,7 @@ public class Mouse {
*
* @param cursor the native cursor object to bind. May be null.
* @return The previous Cursor object set, or null.
- * @throws Exception if the cursor could not be set for any reason
+ * @throws Exception if the cursor could not be set for any reason
*/
public static Cursor setNativeCursor(Cursor cursor) throws Exception {
assert created && ((getNativeCursorCaps() | CURSOR_ONE_BIT_TRANSPARENCY) != 0);
@@ -169,7 +173,7 @@ public class Mouse {
currentCursor = cursor;
if (currentCursor != null) {
nSetNativeCursor(currentCursor.getHandle());
- currentCursor.setTimeout();
+ currentCursor.setTimeout();
} else {
nSetNativeCursor(0);
}
@@ -235,9 +239,9 @@ public class Mouse {
* @throws Exception if the mouse could not be created for any reason
*/
public static void create() throws Exception {
-
+
assert Window.isCreated() : "Window must be created prior to creating mouse";
-
+
if (!initialized) {
initialize();
}
@@ -254,10 +258,10 @@ public class Mouse {
buttons = new byte[buttonCount];
}
- /** Native query of wheel support */
+ /** Native query of wheel support */
private static native boolean nHasWheel();
- /** Native query of button count */
+ /** Native query of button count */
private static native int nGetButtonCount();
/**
@@ -309,43 +313,43 @@ public class Mouse {
/**
* Polls the mouse for its current state. Access the polled values using the
- * get methods.
- * By using this method, it is possible to "miss" mouse click events if you don't
- * poll fast enough. To receive all button events, enable buffering by calling
- * enableBuffer, and read those events by calling read
- *
- * @see org.lwjgl.input.Mouse#isButtonDown(int button)
- * @see org.lwjgl.input.Mouse#getX()
- * @see org.lwjgl.input.Mouse#getY()
- * @see org.lwjgl.input.Mouse#getDX()
- * @see org.lwjgl.input.Mouse#getDY()
- * @see org.lwjgl.input.Mouse#getDWheel()
- * @see org.lwjgl.input.Mouse#enableBuffer()
- * @see org.lwjgl.input.Mouse#read()
+ * get methods.
+ * By using this method, it is possible to "miss" mouse click events if you don't
+ * poll fast enough. To receive all button events, enable buffering by calling
+ * enableBuffer, and read those events by calling read
+ *
+ * @see org.lwjgl.input.Mouse#isButtonDown(int button)
+ * @see org.lwjgl.input.Mouse#getX()
+ * @see org.lwjgl.input.Mouse#getY()
+ * @see org.lwjgl.input.Mouse#getDX()
+ * @see org.lwjgl.input.Mouse#getDY()
+ * @see org.lwjgl.input.Mouse#getDWheel()
+ * @see org.lwjgl.input.Mouse#enableBuffer()
+ * @see org.lwjgl.input.Mouse#read()
*/
public static void poll() {
assert created : "The mouse has not been created.";
nPoll();
-
- // set absolute position
- x += dx;
- y += dy;
+
+ // set absolute position
+ x += dx;
+ y += dy;
- // if window has been created, clamp to edges
- if(Window.isCreated()) {
- // clamp x, y
- if (x < 0) {
- x = 0;
- } else if (x > Window.getWidth()) {
- x = Window.getWidth();
- }
-
- if (y < 0) {
- y = 0;
- } else if (y > Window.getHeight()) {
- y = Window.getHeight();
- }
- }
+ // if window has been created, clamp to edges
+ if(Window.isCreated()) {
+ // clamp x, y
+ if (x < 0) {
+ x = 0;
+ } else if (x > Window.getWidth()) {
+ x = Window.getWidth();
+ }
+
+ if (y < 0) {
+ y = 0;
+ } else if (y > Window.getHeight()) {
+ y = Window.getHeight();
+ }
+ }
}
/**
@@ -362,9 +366,9 @@ public class Mouse {
public static boolean isButtonDown(int button) {
assert created : "The mouse has not been created.";
if (button >= buttonCount || button < 0)
- return false;
+ return false;
else
- return buttons[button] == 1;
+ return buttons[button] == 1;
}
/**
@@ -384,7 +388,7 @@ public class Mouse {
* @param buttonName The button name
*/
public static int getButtonIndex(String buttonName) {
- Integer ret = (Integer) buttonMap.get(buttonName);
+ Integer ret = (Integer) buttonMap.get(buttonName);
if (ret == null)
return -1;
else
@@ -393,15 +397,12 @@ public class Mouse {
/**
* Enable mouse button buffering. Must be called after the mouse is created.
- * @return the size of the mouse buffer in events, or 0 if no buffering
- * can be enabled for any reason
*/
- public static int enableBuffer() throws Exception {
+ public static void enableBuffer() throws Exception {
assert created : "The mouse has not been created.";
- readBuffer = nEnableBuffer();
- if (readBuffer != null)
- readBuffer.order(ByteOrder.nativeOrder());
- return readBuffer.capacity()/2;
+ readBuffer = BufferUtils.createByteBuffer(2*BUFFER_SIZE);
+ readBuffer.limit(0);
+ nEnableBuffer();
}
/**
@@ -409,40 +410,41 @@ public class Mouse {
* @return the event buffer,
* or null if no buffer can be allocated
*/
- private static native ByteBuffer nEnableBuffer() throws Exception;
+ private static native void nEnableBuffer() throws Exception;
/**
* Reads all button events since last read.
- * To use these values, you have to call next for each event you
- * want to read. You can query which button caused the event by using
- * getEventButton. To get the state of that button, for that event, use
- * getEventButtonState.
- *
- * @see org.lwjgl.input.Mouse#next()
- * @see org.lwjgl.input.Mouse#enableBuffer()
- * @see org.lwjgl.input.Mouse#getEventButton()
- * @see org.lwjgl.input.Mouse#getEventButtonState()
+ * To use these values, you have to call next for each event you
+ * want to read. You can query which button caused the event by using
+ * getEventButton. To get the state of that button, for that event, use
+ * getEventButtonState.
+ *
+ * @see org.lwjgl.input.Mouse#next()
+ * @see org.lwjgl.input.Mouse#enableBuffer()
+ * @see org.lwjgl.input.Mouse#getEventButton()
+ * @see org.lwjgl.input.Mouse#getEventButtonState()
*/
public static void read() {
assert created : "The mouse has not been created.";
assert readBuffer != null : "Mouse buffering has not been enabled.";
- int numEvents = nRead();
- readBuffer.clear();
- readBuffer.limit(numEvents << 1);
+ readBuffer.compact();
+ int numEvents = nRead(readBuffer, readBuffer.position());
+ readBuffer.position(readBuffer.position() + numEvents*2);
+ readBuffer.flip();
}
/**
* Native method to read the keyboard buffer
* @return the total number of events read.
*/
- private static native int nRead();
+ private static native int nRead(ByteBuffer buffer, int buffer_position);
/**
* Gets the next mouse event. You can query which button caused the event by using
- * getEventButton(). To get the state of that key, for that event, use
- * getEventButtonState.
- * @see org.lwjgl.input.Mouse#getEventButton()
- * @see org.lwjgl.input.Mouse#getEventButtonState()
+ * getEventButton(). To get the state of that key, for that event, use
+ * getEventButtonState.
+ * @see org.lwjgl.input.Mouse#getEventButton()
+ * @see org.lwjgl.input.Mouse#getEventButtonState()
* @return true if a mouse event was read, false otherwise
*/
public static boolean next() {
@@ -456,79 +458,79 @@ public class Mouse {
} else
return false;
}
-
- /**
- * @return Current events button
- */
- public static int getEventButton() {
- return eventButton;
- }
-
- /**
- * @return Current events button state
- */
- public static boolean getEventButtonState() {
- return eventState;
- }
+
+ /**
+ * @return Current events button
+ */
+ public static int getEventButton() {
+ return eventButton;
+ }
+
+ /**
+ * @return Current events button state
+ */
+ public static boolean getEventButtonState() {
+ return eventState;
+ }
- /**
- * Retrieves the absolute position. If the Window has been created
- * x will be clamped to 0 - Window.getWidth().
- *
- * @return Absolute x axis position of mouse
- */
- public static int getX() {
- return x;
- }
+ /**
+ * Retrieves the absolute position. If the Window has been created
+ * x will be clamped to 0 - Window.getWidth().
+ *
+ * @return Absolute x axis position of mouse
+ */
+ public static int getX() {
+ return x;
+ }
- /**
- * Retrieves the absolute position. If the Window has been created
- * y will be clamped to 0 - Window.getHeight().
- *
- * @return Absolute y axis position of mouse
- */
- public static int getY() {
- return y;
- }
-
- /**
- * @return Movement on the x axis since last poll
- */
- public static int getDX() {
- return dx;
- }
+ /**
+ * Retrieves the absolute position. If the Window has been created
+ * y will be clamped to 0 - Window.getHeight().
+ *
+ * @return Absolute y axis position of mouse
+ */
+ public static int getY() {
+ return y;
+ }
+
+ /**
+ * @return Movement on the x axis since last poll
+ */
+ public static int getDX() {
+ return dx;
+ }
- /**
- * @return Movement on the y axis since last poll
- */
- public static int getDY() {
- return dy;
- }
+ /**
+ * @return Movement on the y axis since last poll
+ */
+ public static int getDY() {
+ return dy;
+ }
- /**
- * @return Movement of the wheel since last poll
- */
- public static int getDWheel() {
- return dwheel;
- }
+ /**
+ * @return Movement of the wheel since last poll
+ */
+ public static int getDWheel() {
+ return dwheel;
+ }
- /**
- * @return Number of buttons on this mouse
- */
- public static int getButtonCount() {
- return buttonCount;
- }
+ /**
+ * @return Number of buttons on this mouse
+ */
+ public static int getButtonCount() {
+ return buttonCount;
+ }
- /**
- * @return Whether or not this mouse has wheel support
- */
- public static boolean hasWheel() {
- return hasWheel;
- }
+ /**
+ * @return Whether or not this mouse has wheel support
+ */
+ public static boolean hasWheel() {
+ return hasWheel;
+ }
/**
* Updates the cursor, so that animation can be changed if needed.
- * This method is called automatically by the window on its update.
+ * This method is called automatically by the window on its update.
*/
public static void updateCursor() {
if(currentCursor != null && currentCursor.hasTimedOut()) {
diff --git a/src/native/common/common_tools.cpp b/src/native/common/common_tools.cpp
index a8ced735..794dd4d7 100644
--- a/src/native/common/common_tools.cpp
+++ b/src/native/common/common_tools.cpp
@@ -77,32 +77,29 @@ static bool hasMoreEvents(event_queue_t *queue) {
return queue->list_start != queue->list_end;
}
-static void copyEvent(event_queue_t *queue, int event_size, int event_index) {
- int output_index = event_index*event_size;
+static void copyEvent(event_queue_t *queue, unsigned char *output_event_buffer, int output_index, int event_size) {
for (int i = 0; i < event_size; i++) {
- queue->output_event_buffer[output_index] = queue->input_event_buffer[queue->list_start];
+ output_event_buffer[output_index] = queue->input_event_buffer[queue->list_start];
incListStart(queue);
output_index++;
}
}
-int copyEvents(event_queue_t *event_queue, int event_size) {
+int copyEvents(event_queue_t *event_queue, unsigned char *output_event_buffer, int buffer_size, int event_size) {
int num_events = 0;
- while (hasMoreEvents(event_queue)) {
- copyEvent(event_queue, event_size, num_events);
+ int index = 0;
+ while (index + event_size <= buffer_size && hasMoreEvents(event_queue)) {
+ copyEvent(event_queue, output_event_buffer, index, event_size);
num_events++;
+ index += event_size;
}
return num_events;
}
-unsigned char *getOutputList(event_queue_t *queue) {
- return queue->output_event_buffer;
-}
-
-int getEventBufferSize(event_queue_t *event_queue) {
+/*int getEventBufferSize(event_queue_t *event_queue) {
return EVENT_BUFFER_SIZE;
}
-
+*/
static void throwGeneralException(JNIEnv * env, const char *exception_name, const char * err) {
jclass cls = env->FindClass(exception_name);
env->ThrowNew(cls, err);
diff --git a/src/native/common/common_tools.h b/src/native/common/common_tools.h
index fb5cab22..5b103cad 100644
--- a/src/native/common/common_tools.h
+++ b/src/native/common/common_tools.h
@@ -51,17 +51,16 @@ extern bool debug;
typedef struct {
unsigned char input_event_buffer[EVENT_BUFFER_SIZE];
- unsigned char output_event_buffer[EVENT_BUFFER_SIZE];
int list_start;
int list_end;
} event_queue_t;
extern void initEventQueue(event_queue_t *event_queue);
-extern int copyEvents(event_queue_t *event_queue, int event_size);
+extern int copyEvents(event_queue_t *event_queue, unsigned char *output_event_buffer, int buffer_size, int event_size);
extern void putEventElement(event_queue_t *queue, unsigned char byte);
extern unsigned char *getOutputList(event_queue_t *queue);
-extern int getEventBufferSize(event_queue_t *event_queue);
+//extern int getEventBufferSize(event_queue_t *event_queue);
extern void throwException(JNIEnv *env, const char *msg);
extern void throwOpenALException(JNIEnv * env, const char * err);
extern void setDebugEnabled(bool enable);
diff --git a/src/native/common/org_lwjgl_input_Keyboard.h b/src/native/common/org_lwjgl_input_Keyboard.h
index 4348d802..0243d76e 100644
--- a/src/native/common/org_lwjgl_input_Keyboard.h
+++ b/src/native/common/org_lwjgl_input_Keyboard.h
@@ -264,6 +264,8 @@ extern "C" {
#define org_lwjgl_input_Keyboard_STATE_OFF 1L
#undef org_lwjgl_input_Keyboard_STATE_UNKNOWN
#define org_lwjgl_input_Keyboard_STATE_UNKNOWN 2L
+#undef org_lwjgl_input_Keyboard_BUFFER_SIZE
+#define org_lwjgl_input_Keyboard_BUFFER_SIZE 50L
/* Inaccessible static: keyName */
/* Inaccessible static: keyMap */
/* Inaccessible static: counter */
@@ -272,13 +274,11 @@ extern "C" {
/* Inaccessible static: keyDownBuffer */
/* Inaccessible static: readBuffer */
/* Inaccessible static: translationEnabled */
-/* Inaccessible static: numEvents */
/* Inaccessible static: eventCharacter */
/* Inaccessible static: eventKey */
/* Inaccessible static: eventState */
/* Inaccessible static: initialized */
-/* Inaccessible static: class_000240 */
-/* Inaccessible static: class_000241 */
+/* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Keyboard */
/*
* Class: org_lwjgl_input_Keyboard
* Method: initIDs
@@ -314,10 +314,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll
/*
* Class: org_lwjgl_input_Keyboard
* Method: nRead
- * Signature: ()I
+ * Signature: (Ljava/nio/ByteBuffer;I)I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead
- (JNIEnv *, jclass);
+ (JNIEnv *, jclass, jobject, jint);
/*
* Class: org_lwjgl_input_Keyboard
@@ -330,9 +330,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation
/*
* Class: org_lwjgl_input_Keyboard
* Method: nEnableBuffer
- * Signature: ()Ljava/nio/ByteBuffer;
+ * Signature: ()V
*/
-JNIEXPORT jobject JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer
+JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer
(JNIEnv *, jclass);
/*
diff --git a/src/native/common/org_lwjgl_input_Mouse.h b/src/native/common/org_lwjgl_input_Mouse.h
index 26650b14..d5fcf849 100644
--- a/src/native/common/org_lwjgl_input_Mouse.h
+++ b/src/native/common/org_lwjgl_input_Mouse.h
@@ -30,7 +30,9 @@ extern "C" {
/* Inaccessible static: readBuffer */
/* Inaccessible static: eventButton */
/* Inaccessible static: eventState */
-/* Inaccessible static: class_000240 */
+#undef org_lwjgl_input_Mouse_BUFFER_SIZE
+#define org_lwjgl_input_Mouse_BUFFER_SIZE 50L
+/* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Mouse */
/*
* Class: org_lwjgl_input_Mouse
* Method: nGetNativeCursorCaps
@@ -114,18 +116,18 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll
/*
* Class: org_lwjgl_input_Mouse
* Method: nEnableBuffer
- * Signature: ()Ljava/nio/ByteBuffer;
+ * Signature: ()V
*/
-JNIEXPORT jobject JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer
+JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_input_Mouse
* Method: nRead
- * Signature: ()I
+ * Signature: (Ljava/nio/ByteBuffer;I)I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead
- (JNIEnv *, jclass);
+ (JNIEnv *, jclass, jobject, jint);
#ifdef __cplusplus
}
diff --git a/src/native/linux/org_lwjgl_input_Keyboard.cpp b/src/native/linux/org_lwjgl_input_Keyboard.cpp
index af416e1b..4b72acaf 100644
--- a/src/native/linux/org_lwjgl_input_Keyboard.cpp
+++ b/src/native/linux/org_lwjgl_input_Keyboard.cpp
@@ -249,25 +249,25 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll(JNIEnv * env, jclass
memcpy(new_keyboard_buffer, key_buf, KEYBOARD_SIZE*sizeof(unsigned char));
}
-JNIEXPORT int JNICALL Java_org_lwjgl_input_Keyboard_nRead(JNIEnv * env, jclass clazz) {
+JNIEXPORT int JNICALL Java_org_lwjgl_input_Keyboard_nRead(JNIEnv * env, jclass clazz, jobject buffer, jint buffer_position) {
int event_size;
if (translation_enabled)
event_size = 4;
else
event_size = 2;
- return copyEvents(&event_queue, event_size);
+ unsigned char* buffer_ptr = (unsigned char *)env->GetDirectBufferAddress(buffer);
+ int buffer_size = env->GetDirectBufferCapacity(buffer) - buffer_position;
+ return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size, event_size);
}
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation(JNIEnv *env, jclass clazz) {
translation_enabled = true;
}
-JNIEXPORT jobject JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer(JNIEnv * env, jclass clazz) {
- jobject newBuffer = env->NewDirectByteBuffer(getOutputList(&event_queue), getEventBufferSize(&event_queue));
+JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer(JNIEnv * env, jclass clazz) {
buffer_enabled = true;
- return newBuffer;
}
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key) {
- return org_lwjgl_input_Keyboard_STATE_UNKNOWN;
+ return org_lwjgl_input_Keyboard_STATE_UNKNOWN;
}
diff --git a/src/native/linux/org_lwjgl_input_Mouse.cpp b/src/native/linux/org_lwjgl_input_Mouse.cpp
index 230e5c2a..9307f0a9 100644
--- a/src/native/linux/org_lwjgl_input_Mouse.cpp
+++ b/src/native/linux/org_lwjgl_input_Mouse.cpp
@@ -393,12 +393,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass cla
warpPointer();
}
-JNIEXPORT jobject JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer(JNIEnv *env, jclass clazz) {
- jobject newBuffer = env->NewDirectByteBuffer(getOutputList(&event_queue), getEventBufferSize(&event_queue));
+JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer(JNIEnv *env, jclass clazz) {
buffer_enabled = true;
- return newBuffer;
}
-JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead(JNIEnv *env, jclass clazz) {
- return copyEvents(&event_queue, 2);
+JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead(JNIEnv *env, jclass clazz, jobject buffer, jint buffer_position) {
+ unsigned char* buffer_ptr = (unsigned char *)env->GetDirectBufferAddress(buffer);
+ int buffer_size = env->GetDirectBufferCapacity(buffer) - buffer_position;
+ return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size, 2);
}
diff --git a/src/native/macosx/org_lwjgl_input_Keyboard.cpp b/src/native/macosx/org_lwjgl_input_Keyboard.cpp
index b92b3a6e..5e348155 100644
--- a/src/native/macosx/org_lwjgl_input_Keyboard.cpp
+++ b/src/native/macosx/org_lwjgl_input_Keyboard.cpp
@@ -365,25 +365,23 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll(JNIEnv * env, jclass
memcpy(new_keyboard_buffer, key_buf, KEYBOARD_SIZE*sizeof(unsigned char));
}
-JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead(JNIEnv * env, jclass clazz) {
- int num_events = 0;
+JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead(JNIEnv * env, jclass clazz, jobject buffer, jint buffer_position) {
int event_size;
if (translation_enabled)
event_size = 4;
else
event_size = 2;
- num_events = copyEvents(&event_queue, event_size);
- return num_events;
+ unsigned char* buffer_ptr = (unsigned char *)env->GetDirectBufferAddress(buffer);
+ int buffer_size = env->GetDirectBufferCapacity(buffer) - buffer_position;
+ return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size, event_size);
}
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation(JNIEnv *env, jclass clazz) {
translation_enabled = true;
}
-JNIEXPORT jobject JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer(JNIEnv * env, jclass clazz) {
- jobject new_buffer = env->NewDirectByteBuffer(getOutputList(&event_queue), getEventBufferSize(&event_queue));
+JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer(JNIEnv * env, jclass clazz) {
buffer_enabled = true;
- return new_buffer;
}
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key) {
diff --git a/src/native/macosx/org_lwjgl_input_Mouse.cpp b/src/native/macosx/org_lwjgl_input_Mouse.cpp
index 8b3f99f8..b8842058 100644
--- a/src/native/macosx/org_lwjgl_input_Mouse.cpp
+++ b/src/native/macosx/org_lwjgl_input_Mouse.cpp
@@ -249,12 +249,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass cla
resetDeltas();
}
-JNIEXPORT jobject JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer(JNIEnv *env, jclass clazz) {
- jobject newBuffer = env->NewDirectByteBuffer(getOutputList(&event_queue), getEventBufferSize(&event_queue));
+JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer(JNIEnv *env, jclass clazz) {
buffer_enabled = true;
- return newBuffer;
}
-JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead(JNIEnv *env, jclass clazz) {
- return copyEvents(&event_queue, 2);
+JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead(JNIEnv *env, jclass clazz, jobject buffer, jint buffer_position) {
+ unsigned char* buffer_ptr = (unsigned char *)env->GetDirectBufferAddress(buffer);
+ int buffer_size = env->GetDirectBufferCapacity(buffer) - buffer_position;
+ return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size, 2);
}