fixed some crap to work with stupid lwjgl display-mouse-keyboard combo
This commit is contained in:
+10
-2
@@ -6,8 +6,16 @@
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/MightyUtils"/>
|
||||
<classpathentry kind="lib" path="lib/jogg-0.0.7.jar" sourcepath="lib/lwjgl-source-2.8.4.zip"/>
|
||||
<classpathentry kind="lib" path="lib/jorbis-0.0.15.jar" sourcepath="lib/lwjgl-source-2.8.4.zip"/>
|
||||
<classpathentry kind="lib" path="lib/lwjgl_util.jar" sourcepath="lib/lwjgl-source-2.8.4.zip"/>
|
||||
<classpathentry kind="lib" path="lib/lwjgl.jar" sourcepath="lib/lwjgl-source-2.8.4.zip"/>
|
||||
<classpathentry kind="lib" path="lib/lwjgl_util.jar" sourcepath="lib/lwjgl-source-2.8.4.zip">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="GameCore-LWJGL/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="lib/lwjgl.jar" sourcepath="lib/lwjgl-source-2.8.4.zip">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="GameCore-LWJGL/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="lib/slick-util.jar" sourcepath="lib/slick-util-src.zip"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -9,6 +9,7 @@ import mightypork.gamecore.input.events.KeyEvent;
|
||||
import mightypork.gamecore.input.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.input.events.MouseMotionEvent;
|
||||
import mightypork.utils.interfaces.Updateable;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.math.constraints.vect.var.VectVar;
|
||||
|
||||
@@ -24,19 +25,19 @@ import org.lwjgl.opengl.Display;
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
public class LwjglInputModule extends InputModule implements Updateable {
|
||||
|
||||
|
||||
/** Current mouse position */
|
||||
private static final Vect mousePos = new Vect() {
|
||||
|
||||
|
||||
@Override
|
||||
public double x()
|
||||
{
|
||||
if (!Mouse.isInsideWindow()) return Integer.MIN_VALUE;
|
||||
|
||||
|
||||
return Mouse.getX();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public double y()
|
||||
{
|
||||
@@ -45,26 +46,36 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
return Display.getHeight() - Mouse.getY();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void initDevices()
|
||||
{
|
||||
try {
|
||||
Mouse.create();
|
||||
Keyboard.create();
|
||||
tryCreate();
|
||||
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
|
||||
} catch (final LWJGLException e) {
|
||||
throw new RuntimeException("Failed to initialize input devices.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void tryCreate() throws LWJGLException
|
||||
{
|
||||
if (Display.isCreated()) {
|
||||
Mouse.create();
|
||||
Keyboard.create();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initKeyCodes()
|
||||
{
|
||||
Keys.NONE.setCode(Keyboard.KEY_NONE);
|
||||
|
||||
|
||||
Keys.NUM_1.setCode(Keyboard.KEY_1);
|
||||
Keys.NUM_2.setCode(Keyboard.KEY_2);
|
||||
Keys.NUM_3.setCode(Keyboard.KEY_3);
|
||||
@@ -75,7 +86,7 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.NUM_8.setCode(Keyboard.KEY_8);
|
||||
Keys.NUM_9.setCode(Keyboard.KEY_9);
|
||||
Keys.NUM_0.setCode(Keyboard.KEY_0);
|
||||
|
||||
|
||||
Keys.Q.setCode(Keyboard.KEY_Q);
|
||||
Keys.W.setCode(Keyboard.KEY_W);
|
||||
Keys.E.setCode(Keyboard.KEY_E);
|
||||
@@ -102,7 +113,7 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.B.setCode(Keyboard.KEY_B);
|
||||
Keys.N.setCode(Keyboard.KEY_N);
|
||||
Keys.M.setCode(Keyboard.KEY_M);
|
||||
|
||||
|
||||
Keys.MINUS.setCode(Keyboard.KEY_MINUS);
|
||||
Keys.EQUALS.setCode(Keyboard.KEY_EQUALS);
|
||||
Keys.SLASH.setCode(Keyboard.KEY_SLASH);
|
||||
@@ -114,17 +125,17 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.GRAVE.setCode(Keyboard.KEY_GRAVE);
|
||||
Keys.COMMA.setCode(Keyboard.KEY_COMMA);
|
||||
Keys.PERIOD.setCode(Keyboard.KEY_PERIOD);
|
||||
|
||||
|
||||
Keys.SPACE.setCode(Keyboard.KEY_SPACE);
|
||||
Keys.BACKSPACE.setCode(Keyboard.KEY_BACK);
|
||||
Keys.TAB.setCode(Keyboard.KEY_TAB);
|
||||
Keys.ESCAPE.setCode(Keyboard.KEY_ESCAPE);
|
||||
|
||||
|
||||
Keys.APPS.setCode(Keyboard.KEY_APPS);
|
||||
Keys.POWER.setCode(Keyboard.KEY_POWER);
|
||||
Keys.SLEEP.setCode(Keyboard.KEY_SLEEP);
|
||||
//Keys.MENU.setCode(Keyboard.KEY_MENU); // not defined
|
||||
|
||||
|
||||
Keys.F1.setCode(Keyboard.KEY_F1);
|
||||
Keys.F2.setCode(Keyboard.KEY_F2);
|
||||
Keys.F3.setCode(Keyboard.KEY_F3);
|
||||
@@ -140,11 +151,11 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.F13.setCode(Keyboard.KEY_F13);
|
||||
Keys.F14.setCode(Keyboard.KEY_F14);
|
||||
Keys.F15.setCode(Keyboard.KEY_F15);
|
||||
|
||||
|
||||
Keys.CAPS_LOCK.setCode(Keyboard.KEY_CAPITAL);
|
||||
Keys.SCROLL_LOCK.setCode(Keyboard.KEY_SCROLL);
|
||||
Keys.NUM_LOCK.setCode(Keyboard.KEY_NUMLOCK);
|
||||
|
||||
|
||||
Keys.NUMPAD_MINUS.setCode(Keyboard.KEY_SUBTRACT);
|
||||
Keys.NUMPAD_PLUSS.setCode(Keyboard.KEY_ADD);
|
||||
Keys.NUMPAD_0.setCode(Keyboard.KEY_NUMPAD0);
|
||||
@@ -161,7 +172,7 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.NUMPAD_ENTER.setCode(Keyboard.KEY_NUMPADENTER);
|
||||
Keys.NUMPAD_DIVIDE.setCode(Keyboard.KEY_DIVIDE);
|
||||
Keys.NUMPAD_MULTIPLY.setCode(Keyboard.KEY_MULTIPLY);
|
||||
|
||||
|
||||
Keys.CONTROL_LEFT.setCode(Keyboard.KEY_LCONTROL);
|
||||
Keys.CONTROL_RIGHT.setCode(Keyboard.KEY_RCONTROL);
|
||||
Keys.ALT_LEFT.setCode(Keyboard.KEY_LMENU);
|
||||
@@ -170,47 +181,55 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.SHIFT_RIGHT.setCode(Keyboard.KEY_RSHIFT);
|
||||
Keys.META_LEFT.setCode(Keyboard.KEY_LMETA);
|
||||
Keys.META_RIGHT.setCode(Keyboard.KEY_RMETA);
|
||||
|
||||
|
||||
Keys.UP.setCode(Keyboard.KEY_UP);
|
||||
Keys.DOWN.setCode(Keyboard.KEY_DOWN);
|
||||
Keys.LEFT.setCode(Keyboard.KEY_LEFT);
|
||||
Keys.RIGHT.setCode(Keyboard.KEY_RIGHT);
|
||||
|
||||
|
||||
Keys.HOME.setCode(Keyboard.KEY_HOME);
|
||||
Keys.END.setCode(Keyboard.KEY_END);
|
||||
|
||||
|
||||
Keys.PAGE_UP.setCode(Keyboard.KEY_PRIOR);
|
||||
Keys.PAGE_DOWN.setCode(Keyboard.KEY_NEXT);
|
||||
|
||||
|
||||
Keys.RETURN.setCode(Keyboard.KEY_RETURN);
|
||||
Keys.PAUSE.setCode(Keyboard.KEY_PAUSE);
|
||||
Keys.INSERT.setCode(Keyboard.KEY_INSERT);
|
||||
Keys.DELETE.setCode(Keyboard.KEY_DELETE);
|
||||
Keys.SYSRQ.setCode(Keyboard.KEY_SYSRQ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
Mouse.destroy();
|
||||
Keyboard.destroy();
|
||||
}
|
||||
|
||||
|
||||
private final VectVar mouseMove = Vect.makeVar();
|
||||
private final VectVar mouseLastPos = Vect.makeVar();
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void update(double delta)
|
||||
{
|
||||
// was destroyed or not initialized
|
||||
if (!Display.isCreated()) return;
|
||||
if (!Mouse.isCreated()) return;
|
||||
if (!Keyboard.isCreated()) return;
|
||||
|
||||
if (!Mouse.isCreated() || !Keyboard.isCreated()) {
|
||||
try {
|
||||
tryCreate();
|
||||
} catch (final LWJGLException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Mouse.isCreated() || !Keyboard.isCreated()) return;
|
||||
|
||||
Display.processMessages();
|
||||
|
||||
|
||||
// sum the moves
|
||||
mouseMove.reset();
|
||||
mouseLastPos.reset();
|
||||
@@ -219,81 +238,81 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
onMouseEvent(mouseMove, mouseLastPos);
|
||||
wasMouse = true;
|
||||
}
|
||||
|
||||
|
||||
if (wasMouse && !mouseMove.isZero()) {
|
||||
App.bus().send(new MouseMotionEvent(mouseLastPos, mouseMove));
|
||||
}
|
||||
|
||||
|
||||
while (Keyboard.next()) {
|
||||
onKeyEvent();
|
||||
}
|
||||
|
||||
|
||||
if (Display.isCloseRequested()) {
|
||||
App.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void onMouseEvent(VectVar moveSum, VectVar lastPos)
|
||||
{
|
||||
final int button = Mouse.getEventButton();
|
||||
final boolean down = Mouse.getEventButtonState();
|
||||
|
||||
|
||||
final VectVar pos = Vect.makeVar(Mouse.getEventX(), Mouse.getEventY());
|
||||
final VectVar move = Vect.makeVar(Mouse.getEventDX(), Mouse.getEventDY());
|
||||
|
||||
|
||||
final int wheeld = Mouse.getEventDWheel();
|
||||
|
||||
|
||||
// flip Y axis
|
||||
pos.setY(Display.getHeight() - pos.y());
|
||||
|
||||
|
||||
if (button != -1 || wheeld != 0) {
|
||||
App.bus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld));
|
||||
}
|
||||
|
||||
|
||||
moveSum.setTo(moveSum.add(move));
|
||||
lastPos.setTo(pos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void onKeyEvent()
|
||||
{
|
||||
final int key = Keyboard.getEventKey();
|
||||
final boolean down = Keyboard.getEventKeyState();
|
||||
final char c = Keyboard.getEventCharacter();
|
||||
|
||||
|
||||
App.bus().send(new KeyEvent(key, c, down));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vect getMousePos()
|
||||
{
|
||||
return mousePos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isMouseInside()
|
||||
{
|
||||
return Mouse.isInsideWindow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void grabMouse(boolean grab)
|
||||
{
|
||||
Mouse.setGrabbed(grab);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isKeyDown(Key key)
|
||||
{
|
||||
return key.isDefined() && Keyboard.isKeyDown(key.getCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isMouseButtonDown(int button)
|
||||
{
|
||||
|
||||
@@ -47,6 +47,8 @@ public class SlickAudio extends DeferredAudio {
|
||||
final String ext = FileUtil.getExtension(resource);
|
||||
|
||||
try(final InputStream stream = FileUtil.getResource(resource)) {
|
||||
|
||||
if (stream == null) throw new IOException("Not found: " + resource);
|
||||
|
||||
if (ext.equalsIgnoreCase("ogg")) {
|
||||
backingAudio = SoundStore.get().getOgg(resource, stream);
|
||||
|
||||
@@ -83,9 +83,16 @@ public class LwjglGraphicsModule extends GraphicsModule {
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createDisplay()
|
||||
{
|
||||
try {
|
||||
Display.create();
|
||||
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException("Could not initialize display.", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user