Folded read into poll to simplify interface
This commit is contained in:
parent
8065870592
commit
4974a66398
|
@ -228,14 +228,6 @@ public class Controller {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Read the controller's input buffer. This is not yet implemented in LWJGL so
|
|
||||||
* it always throws a RuntimeException.
|
|
||||||
*/
|
|
||||||
public static void read() {
|
|
||||||
throw new UnsupportedOperationException("Buffering is not implemented for Controllers.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a button's name
|
* Gets a button's name
|
||||||
* @param button The button
|
* @param button The button
|
||||||
|
|
|
@ -326,15 +326,37 @@ public class Keyboard {
|
||||||
* poll fast enough. To receive all events, enable buffering by calling
|
* poll fast enough. To receive all events, enable buffering by calling
|
||||||
* <code>enableBuffer</code>, and read those events by calling <code>read</code>
|
* <code>enableBuffer</code>, and read those events by calling <code>read</code>
|
||||||
*
|
*
|
||||||
|
* This method also reads all keyboard events since last read if keyboard buffering is enabled.
|
||||||
|
* To use these values, you have to call <code>next</code> for each event you
|
||||||
|
* want to read. You can query which key caused the event by using
|
||||||
|
* <code>getEventKey</code>. To get the state of that key, for that event, use
|
||||||
|
* <code>getEventKeyState</code> - finally use <code>getEventCharacter</code> to get the
|
||||||
|
* character for that event.
|
||||||
|
*
|
||||||
* @see org.lwjgl.input.Keyboard#isKeyDown(int key)
|
* @see org.lwjgl.input.Keyboard#isKeyDown(int key)
|
||||||
* @see org.lwjgl.input.Keyboard#isStateKeySet(int key)
|
* @see org.lwjgl.input.Keyboard#isStateKeySet(int key)
|
||||||
|
* @see org.lwjgl.input.Keyboard#next()
|
||||||
* @see org.lwjgl.input.Keyboard#enableBuffer()
|
* @see org.lwjgl.input.Keyboard#enableBuffer()
|
||||||
* @see org.lwjgl.input.Keyboard#read()
|
* @see org.lwjgl.input.Keyboard#getEventKey()
|
||||||
|
* @see org.lwjgl.input.Keyboard#getEventKeyState()
|
||||||
|
* @see org.lwjgl.input.Keyboard#getEventCharacter()
|
||||||
*/
|
*/
|
||||||
public static void poll() {
|
public static void poll() {
|
||||||
if (!created)
|
if (!created)
|
||||||
throw new IllegalStateException("Keyboard must be created before you can poll the device");
|
throw new IllegalStateException("Keyboard must be created before you can poll the device");
|
||||||
nPoll(keyDownBuffer);
|
nPoll(keyDownBuffer);
|
||||||
|
if (readBuffer != null)
|
||||||
|
read();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void read() {
|
||||||
|
readBuffer.compact();
|
||||||
|
int numEvents = nRead(readBuffer, readBuffer.position());
|
||||||
|
if (translationEnabled)
|
||||||
|
readBuffer.position(readBuffer.position() + numEvents*4);
|
||||||
|
else
|
||||||
|
readBuffer.position(readBuffer.position() + numEvents*2);
|
||||||
|
readBuffer.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -345,34 +367,6 @@ public class Keyboard {
|
||||||
*/
|
*/
|
||||||
private static native void nPoll(ByteBuffer keyDownBuffer);
|
private static native void nPoll(ByteBuffer keyDownBuffer);
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads all keyboard events since last read.
|
|
||||||
* To use these values, you have to call <code>next</code> for each event you
|
|
||||||
* want to read. You can query which key caused the event by using
|
|
||||||
* <code>getEventKey</code>. To get the state of that key, for that event, use
|
|
||||||
* <code>getEventKeyState</code> - finally use <code>getEventCharacter</code> 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() {
|
|
||||||
if (!created)
|
|
||||||
throw new IllegalStateException("Keyboard must be created before you can read events");
|
|
||||||
if (readBuffer == null)
|
|
||||||
throw new IllegalStateException("Event buffering must be enabled before you can read events");
|
|
||||||
readBuffer.compact();
|
|
||||||
int numEvents = nRead(readBuffer, readBuffer.position());
|
|
||||||
if (translationEnabled)
|
|
||||||
readBuffer.position(readBuffer.position() + numEvents*4);
|
|
||||||
else
|
|
||||||
readBuffer.position(readBuffer.position() + numEvents*2);
|
|
||||||
readBuffer.flip();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Native method to read the keyboard buffer
|
* Native method to read the keyboard buffer
|
||||||
* @return the total number of events read.
|
* @return the total number of events read.
|
||||||
|
|
|
@ -323,6 +323,15 @@ public class Mouse {
|
||||||
* poll fast enough. To receive all button events, enable buffering by calling
|
* poll fast enough. To receive all button events, enable buffering by calling
|
||||||
* <code>enableBuffer</code>, and read those events by calling <code>read</code>
|
* <code>enableBuffer</code>, and read those events by calling <code>read</code>
|
||||||
*
|
*
|
||||||
|
* If buffering is enabled, this method also reads all button events since last read.
|
||||||
|
* To use these values, you have to call <code>next</code> for each event you
|
||||||
|
* want to read. You can query which button caused the event by using
|
||||||
|
* <code>getEventButton</code>. To get the state of that button, for that event, use
|
||||||
|
* <code>getEventButtonState</code>.
|
||||||
|
*
|
||||||
|
* @see org.lwjgl.input.Mouse#next()
|
||||||
|
* @see org.lwjgl.input.Mouse#getEventButton()
|
||||||
|
* @see org.lwjgl.input.Mouse#getEventButtonState()
|
||||||
* @see org.lwjgl.input.Mouse#isButtonDown(int button)
|
* @see org.lwjgl.input.Mouse#isButtonDown(int button)
|
||||||
* @see org.lwjgl.input.Mouse#getX()
|
* @see org.lwjgl.input.Mouse#getX()
|
||||||
* @see org.lwjgl.input.Mouse#getY()
|
* @see org.lwjgl.input.Mouse#getY()
|
||||||
|
@ -330,7 +339,6 @@ public class Mouse {
|
||||||
* @see org.lwjgl.input.Mouse#getDY()
|
* @see org.lwjgl.input.Mouse#getDY()
|
||||||
* @see org.lwjgl.input.Mouse#getDWheel()
|
* @see org.lwjgl.input.Mouse#getDWheel()
|
||||||
* @see org.lwjgl.input.Mouse#enableBuffer()
|
* @see org.lwjgl.input.Mouse#enableBuffer()
|
||||||
* @see org.lwjgl.input.Mouse#read()
|
|
||||||
*/
|
*/
|
||||||
public static void poll() {
|
public static void poll() {
|
||||||
if (!created)
|
if (!created)
|
||||||
|
@ -362,6 +370,15 @@ public class Mouse {
|
||||||
y = Window.getHeight();
|
y = Window.getHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (readBuffer != null)
|
||||||
|
read();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void read() {
|
||||||
|
readBuffer.compact();
|
||||||
|
int numEvents = nRead(readBuffer, readBuffer.position());
|
||||||
|
readBuffer.position(readBuffer.position() + numEvents*2);
|
||||||
|
readBuffer.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -426,29 +443,6 @@ public class Mouse {
|
||||||
*/
|
*/
|
||||||
private static native void nEnableBuffer() throws LWJGLException;
|
private static native void nEnableBuffer() throws LWJGLException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads all button events since last read.
|
|
||||||
* To use these values, you have to call <code>next</code> for each event you
|
|
||||||
* want to read. You can query which button caused the event by using
|
|
||||||
* <code>getEventButton</code>. To get the state of that button, for that event, use
|
|
||||||
* <code>getEventButtonState</code>.
|
|
||||||
*
|
|
||||||
* @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() {
|
|
||||||
if (!created)
|
|
||||||
throw new IllegalStateException("Mouse must be created before you can read events");
|
|
||||||
if (readBuffer == null)
|
|
||||||
throw new IllegalStateException("Event buffering must be enabled before you can read events");
|
|
||||||
readBuffer.compact();
|
|
||||||
int numEvents = nRead(readBuffer, readBuffer.position());
|
|
||||||
readBuffer.position(readBuffer.position() + numEvents*2);
|
|
||||||
readBuffer.flip();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Native method to read the keyboard buffer
|
* Native method to read the keyboard buffer
|
||||||
* @return the total number of events read.
|
* @return the total number of events read.
|
||||||
|
|
|
@ -241,22 +241,13 @@ public final class Window {
|
||||||
// Poll the input devices while we're here
|
// Poll the input devices while we're here
|
||||||
if (Mouse.isCreated()) {
|
if (Mouse.isCreated()) {
|
||||||
Mouse.poll();
|
Mouse.poll();
|
||||||
if (Mouse.isBuffered()) {
|
|
||||||
Mouse.read();
|
|
||||||
}
|
|
||||||
Mouse.updateCursor();
|
Mouse.updateCursor();
|
||||||
}
|
}
|
||||||
if (Keyboard.isCreated()) {
|
if (Keyboard.isCreated()) {
|
||||||
Keyboard.poll();
|
Keyboard.poll();
|
||||||
if (Keyboard.isBuffered()) {
|
|
||||||
Keyboard.read();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (Controller.isCreated()) {
|
if (Controller.isCreated()) {
|
||||||
Controller.poll();
|
Controller.poll();
|
||||||
if (Controller.isBuffered()) {
|
|
||||||
Controller.read();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,6 @@ public class KeyboardTest {
|
||||||
|
|
||||||
//check keys, buffered
|
//check keys, buffered
|
||||||
Keyboard.poll();
|
Keyboard.poll();
|
||||||
Keyboard.read();
|
|
||||||
|
|
||||||
int count = Keyboard.getNumKeyboardEvents();
|
int count = Keyboard.getNumKeyboardEvents();
|
||||||
while (Keyboard.next()) {
|
while (Keyboard.next()) {
|
||||||
|
|
Loading…
Reference in New Issue