From c6c4cf53a08f0d766923141a0466493c4bdb1a62 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sun, 20 Nov 2011 00:18:02 +0000 Subject: [PATCH] * Some minor optimizations * Disable dead zone check for mouse axes git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8732 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/core/com/jme3/input/InputManager.java | 19 ++++++++++++------- .../src/core/com/jme3/material/Material.java | 6 ++++-- .../com/jme3/system/lwjgl/LwjglCanvas.java | 2 ++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/engine/src/core/com/jme3/input/InputManager.java b/engine/src/core/com/jme3/input/InputManager.java index 6c9a9370d..baa3f1b5b 100644 --- a/engine/src/core/com/jme3/input/InputManager.java +++ b/engine/src/core/com/jme3/input/InputManager.java @@ -262,8 +262,8 @@ public class InputManager implements RawInputListener { } } - private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) { - if (value < axisDeadZone) { + private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf, float deadZone) { + if (value < deadZone) { invokeAnalogs(hash, value, !applyTpf); return; } @@ -276,6 +276,10 @@ public class InputManager implements RawInputListener { boolean valueChanged = !axisValues.containsKey(hash); if (applyTpf) { value *= frameTPF; + }else{ + if (value != 0){ + axisValues.put(hash, value); + } } int size = maps.size(); @@ -338,13 +342,13 @@ public class InputManager implements RawInputListener { } else if (value < 0) { int hash = JoyAxisTrigger.joyAxisHash(joyId, axis, true); int otherHash = JoyAxisTrigger.joyAxisHash(joyId, axis, false); - invokeAnalogsAndActions(hash, -value, true); + invokeAnalogsAndActions(hash, -value, true, axisDeadZone); axisValues.put(hash, -value); axisValues.remove(otherHash); } else { int hash = JoyAxisTrigger.joyAxisHash(joyId, axis, false); int otherHash = JoyAxisTrigger.joyAxisHash(joyId, axis, true); - invokeAnalogsAndActions(hash, value, true); + invokeAnalogsAndActions(hash, value, true, axisDeadZone); axisValues.put(hash, value); axisValues.remove(otherHash); } @@ -387,17 +391,18 @@ public class InputManager implements RawInputListener { // rawListeners.get(i).onMouseMotionEvent(evt); // } + // Do not use dead zone for mouse motion events if (evt.getDX() != 0) { float val = Math.abs(evt.getDX()) / 1024f; - invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, false); + invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, false, 0); } if (evt.getDY() != 0) { float val = Math.abs(evt.getDY()) / 1024f; - invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, false); + invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, false, 0); } if (evt.getDeltaWheel() != 0) { float val = Math.abs(evt.getDeltaWheel()) / 100f; - invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0), val, false); + invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0), val, false, 0); } } diff --git a/engine/src/core/com/jme3/material/Material.java b/engine/src/core/com/jme3/material/Material.java index fa488b8d9..a018a31bb 100644 --- a/engine/src/core/com/jme3/material/Material.java +++ b/engine/src/core/com/jme3/material/Material.java @@ -942,7 +942,8 @@ public class Material implements Asset, Cloneable, Savable, Comparable private void clearUniformsSetByCurrent(Shader shader) { ListMap uniforms = shader.getUniformMap(); - for (int i = 0; i < uniforms.size(); i++) { + int size = uniforms.size(); + for (int i = 0; i < size; i++) { Uniform u = uniforms.getValue(i); u.clearSetByCurrentMaterial(); } @@ -950,7 +951,8 @@ public class Material implements Asset, Cloneable, Savable, Comparable private void resetUniformsNotSetByCurrent(Shader shader) { ListMap uniforms = shader.getUniformMap(); - for (int i = 0; i < uniforms.size(); i++) { + int size = uniforms.size(); + for (int i = 0; i < size; i++) { Uniform u = uniforms.getValue(i); if (!u.isSetByCurrentMaterial()) { u.clearValue(); diff --git a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglCanvas.java b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglCanvas.java index 6e6d9dc83..f597f3a8d 100644 --- a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglCanvas.java +++ b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglCanvas.java @@ -295,6 +295,8 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex */ protected PixelFormat acquirePixelFormat(boolean forPbuffer){ if (forPbuffer){ + // Use 0 samples for pbuffer format, prevents + // crashes on bad drivers if (pbufferFormat == null){ pbufferFormat = new PixelFormat(settings.getBitsPerPixel(), 0,