Conflicts: jme3-core/src/main/java/com/jme3/material/TechniqueDef.javadefine_list_fix
commit
e1d0e06c59
File diff suppressed because it is too large
Load Diff
@ -1,265 +1,263 @@ |
||||
/* |
||||
* Copyright (c) 2009-2012 jMonkeyEngine |
||||
* 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 'jMonkeyEngine' 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 com.jme3.input.android; |
||||
|
||||
import android.opengl.GLSurfaceView; |
||||
import android.os.Build; |
||||
import android.view.View; |
||||
import com.jme3.input.RawInputListener; |
||||
import com.jme3.input.TouchInput; |
||||
import com.jme3.input.event.InputEvent; |
||||
import com.jme3.input.event.KeyInputEvent; |
||||
import com.jme3.input.event.MouseButtonEvent; |
||||
import com.jme3.input.event.MouseMotionEvent; |
||||
import com.jme3.input.event.TouchEvent; |
||||
import com.jme3.system.AppSettings; |
||||
import java.util.concurrent.ConcurrentLinkedQueue; |
||||
import java.util.logging.Level; |
||||
import java.util.logging.Logger; |
||||
|
||||
/** |
||||
* <code>AndroidInput</code> is the main class that connects the Android system |
||||
* inputs to jME. It serves as the manager that gathers inputs from the various |
||||
* Android input methods and provides them to jME's <code>InputManager</code>. |
||||
* |
||||
* @author iwgeric |
||||
*/ |
||||
public class AndroidInputHandler implements TouchInput { |
||||
private static final Logger logger = Logger.getLogger(AndroidInputHandler.class.getName()); |
||||
|
||||
// Custom settings
|
||||
private boolean mouseEventsEnabled = true; |
||||
private boolean mouseEventsInvertX = false; |
||||
private boolean mouseEventsInvertY = false; |
||||
private boolean keyboardEventsEnabled = false; |
||||
private boolean joystickEventsEnabled = false; |
||||
private boolean dontSendHistory = false; |
||||
|
||||
|
||||
// Internal
|
||||
private GLSurfaceView view; |
||||
private AndroidTouchHandler touchHandler; |
||||
private AndroidKeyHandler keyHandler; |
||||
private AndroidGestureHandler gestureHandler; |
||||
private boolean initialized = false; |
||||
private RawInputListener listener = null; |
||||
private ConcurrentLinkedQueue<InputEvent> inputEventQueue = new ConcurrentLinkedQueue<InputEvent>(); |
||||
private final static int MAX_TOUCH_EVENTS = 1024; |
||||
private final TouchEventPool touchEventPool = new TouchEventPool(MAX_TOUCH_EVENTS); |
||||
private float scaleX = 1f; |
||||
private float scaleY = 1f; |
||||
|
||||
|
||||
public AndroidInputHandler() { |
||||
int buildVersion = Build.VERSION.SDK_INT; |
||||
logger.log(Level.INFO, "Android Build Version: {0}", buildVersion); |
||||
if (buildVersion >= 14) { |
||||
// add support for onHover and GenericMotionEvent (ie. gamepads)
|
||||
gestureHandler = new AndroidGestureHandler(this); |
||||
touchHandler = new AndroidTouchHandler14(this, gestureHandler); |
||||
keyHandler = new AndroidKeyHandler(this); |
||||
} else if (buildVersion >= 8){ |
||||
gestureHandler = new AndroidGestureHandler(this); |
||||
touchHandler = new AndroidTouchHandler(this, gestureHandler); |
||||
keyHandler = new AndroidKeyHandler(this); |
||||
} |
||||
} |
||||
|
||||
public AndroidInputHandler(AndroidTouchHandler touchInput, |
||||
AndroidKeyHandler keyInput, AndroidGestureHandler gestureHandler) { |
||||
this.touchHandler = touchInput; |
||||
this.keyHandler = keyInput; |
||||
this.gestureHandler = gestureHandler; |
||||
} |
||||
|
||||
public void setView(View view) { |
||||
if (touchHandler != null) { |
||||
touchHandler.setView(view); |
||||
} |
||||
if (keyHandler != null) { |
||||
keyHandler.setView(view); |
||||
} |
||||
if (gestureHandler != null) { |
||||
gestureHandler.setView(view); |
||||
} |
||||
this.view = (GLSurfaceView)view; |
||||
} |
||||
|
||||
public View getView() { |
||||
return view; |
||||
} |
||||
|
||||
public float invertX(float origX) { |
||||
return getJmeX(view.getWidth()) - origX; |
||||
} |
||||
|
||||
public float invertY(float origY) { |
||||
return getJmeY(view.getHeight()) - origY; |
||||
} |
||||
|
||||
public float getJmeX(float origX) { |
||||
return origX * scaleX; |
||||
} |
||||
|
||||
public float getJmeY(float origY) { |
||||
return origY * scaleY; |
||||
} |
||||
|
||||
public void loadSettings(AppSettings settings) { |
||||
keyboardEventsEnabled = settings.isEmulateKeyboard(); |
||||
mouseEventsEnabled = settings.isEmulateMouse(); |
||||
mouseEventsInvertX = settings.isEmulateMouseFlipX(); |
||||
mouseEventsInvertY = settings.isEmulateMouseFlipY(); |
||||
joystickEventsEnabled = settings.useJoysticks(); |
||||
|
||||
// view width and height are 0 until the view is displayed on the screen
|
||||
if (view.getWidth() != 0 && view.getHeight() != 0) { |
||||
scaleX = (float)settings.getWidth() / (float)view.getWidth(); |
||||
scaleY = (float)settings.getHeight() / (float)view.getHeight(); |
||||
} |
||||
logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}", |
||||
new Object[]{scaleX, scaleY}); |
||||
|
||||
} |
||||
|
||||
// -----------------------------------------
|
||||
// JME3 Input interface
|
||||
@Override |
||||
public void initialize() { |
||||
touchEventPool.initialize(); |
||||
if (touchHandler != null) { |
||||
touchHandler.initialize(); |
||||
} |
||||
if (keyHandler != null) { |
||||
keyHandler.initialize(); |
||||
} |
||||
if (gestureHandler != null) { |
||||
gestureHandler.initialize(); |
||||
} |
||||
|
||||
initialized = true; |
||||
} |
||||
|
||||
@Override |
||||
public void destroy() { |
||||
initialized = false; |
||||
|
||||
touchEventPool.destroy(); |
||||
if (touchHandler != null) { |
||||
touchHandler.destroy(); |
||||
} |
||||
if (keyHandler != null) { |
||||
keyHandler.destroy(); |
||||
} |
||||
if (gestureHandler != null) { |
||||
gestureHandler.destroy(); |
||||
} |
||||
|
||||
setView(null); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isInitialized() { |
||||
return initialized; |
||||
} |
||||
|
||||
@Override |
||||
public void setInputListener(RawInputListener listener) { |
||||
this.listener = listener; |
||||
} |
||||
|
||||
@Override |
||||
public long getInputTimeNanos() { |
||||
return System.nanoTime(); |
||||
} |
||||
|
||||
public void update() { |
||||
if (listener != null) { |
||||
InputEvent inputEvent; |
||||
|
||||
while ((inputEvent = inputEventQueue.poll()) != null) { |
||||
if (inputEvent instanceof TouchEvent) { |
||||
listener.onTouchEvent((TouchEvent)inputEvent); |
||||
} else if (inputEvent instanceof MouseButtonEvent) { |
||||
listener.onMouseButtonEvent((MouseButtonEvent)inputEvent); |
||||
} else if (inputEvent instanceof MouseMotionEvent) { |
||||
listener.onMouseMotionEvent((MouseMotionEvent)inputEvent); |
||||
} else if (inputEvent instanceof KeyInputEvent) { |
||||
listener.onKeyEvent((KeyInputEvent)inputEvent); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
// -----------------------------------------
|
||||
|
||||
public TouchEvent getFreeTouchEvent() { |
||||
return touchEventPool.getNextFreeEvent(); |
||||
} |
||||
|
||||
public void addEvent(InputEvent event) { |
||||
inputEventQueue.add(event); |
||||
if (event instanceof TouchEvent) { |
||||
touchEventPool.storeEvent((TouchEvent)event); |
||||
} |
||||
} |
||||
|
||||
public void setSimulateMouse(boolean simulate) { |
||||
this.mouseEventsEnabled = simulate; |
||||
} |
||||
|
||||
public boolean isSimulateMouse() { |
||||
return mouseEventsEnabled; |
||||
} |
||||
|
||||
public boolean isMouseEventsInvertX() { |
||||
return mouseEventsInvertX; |
||||
} |
||||
|
||||
public boolean isMouseEventsInvertY() { |
||||
return mouseEventsInvertY; |
||||
} |
||||
|
||||
public void setSimulateKeyboard(boolean simulate) { |
||||
this.keyboardEventsEnabled = simulate; |
||||
} |
||||
|
||||
public boolean isSimulateKeyboard() { |
||||
return keyboardEventsEnabled; |
||||
} |
||||
|
||||
public void setOmitHistoricEvents(boolean dontSendHistory) { |
||||
this.dontSendHistory = dontSendHistory; |
||||
} |
||||
|
||||
} |
||||
/* |
||||
* Copyright (c) 2009-2012 jMonkeyEngine |
||||
* 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 'jMonkeyEngine' 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 com.jme3.input.android; |
||||
|
||||
import android.opengl.GLSurfaceView; |
||||
import android.os.Build; |
||||
import android.view.View; |
||||
import com.jme3.input.RawInputListener; |
||||
import com.jme3.input.TouchInput; |
||||
import com.jme3.input.event.InputEvent; |
||||
import com.jme3.input.event.KeyInputEvent; |
||||
import com.jme3.input.event.MouseButtonEvent; |
||||
import com.jme3.input.event.MouseMotionEvent; |
||||
import com.jme3.input.event.TouchEvent; |
||||
import com.jme3.system.AppSettings; |
||||
import java.util.concurrent.ConcurrentLinkedQueue; |
||||
import java.util.logging.Level; |
||||
import java.util.logging.Logger; |
||||
|
||||
/** |
||||
* <code>AndroidInput</code> is the main class that connects the Android system |
||||
* inputs to jME. It serves as the manager that gathers inputs from the various |
||||
* Android input methods and provides them to jME's <code>InputManager</code>. |
||||
* |
||||
* @author iwgeric |
||||
*/ |
||||
public class AndroidInputHandler implements TouchInput { |
||||
private static final Logger logger = Logger.getLogger(AndroidInputHandler.class.getName()); |
||||
|
||||
// Custom settings
|
||||
private boolean mouseEventsEnabled = true; |
||||
private boolean mouseEventsInvertX = false; |
||||
private boolean mouseEventsInvertY = false; |
||||
private boolean keyboardEventsEnabled = false; |
||||
private boolean dontSendHistory = false; |
||||
|
||||
|
||||
// Internal
|
||||
private GLSurfaceView view; |
||||
private AndroidTouchHandler touchHandler; |
||||
private AndroidKeyHandler keyHandler; |
||||
private AndroidGestureHandler gestureHandler; |
||||
private boolean initialized = false; |
||||
private RawInputListener listener = null; |
||||
private ConcurrentLinkedQueue<InputEvent> inputEventQueue = new ConcurrentLinkedQueue<InputEvent>(); |
||||
private final static int MAX_TOUCH_EVENTS = 1024; |
||||
private final TouchEventPool touchEventPool = new TouchEventPool(MAX_TOUCH_EVENTS); |
||||
private float scaleX = 1f; |
||||
private float scaleY = 1f; |
||||
|
||||
|
||||
public AndroidInputHandler() { |
||||
int buildVersion = Build.VERSION.SDK_INT; |
||||
logger.log(Level.INFO, "Android Build Version: {0}", buildVersion); |
||||
if (buildVersion >= 14) { |
||||
// add support for onHover and GenericMotionEvent (ie. gamepads)
|
||||
gestureHandler = new AndroidGestureHandler(this); |
||||
touchHandler = new AndroidTouchHandler14(this, gestureHandler); |
||||
keyHandler = new AndroidKeyHandler(this); |
||||
} else if (buildVersion >= 8){ |
||||
gestureHandler = new AndroidGestureHandler(this); |
||||
touchHandler = new AndroidTouchHandler(this, gestureHandler); |
||||
keyHandler = new AndroidKeyHandler(this); |
||||
} |
||||
} |
||||
|
||||
public AndroidInputHandler(AndroidTouchHandler touchInput, |
||||
AndroidKeyHandler keyInput, AndroidGestureHandler gestureHandler) { |
||||
this.touchHandler = touchInput; |
||||
this.keyHandler = keyInput; |
||||
this.gestureHandler = gestureHandler; |
||||
} |
||||
|
||||
public void setView(View view) { |
||||
if (touchHandler != null) { |
||||
touchHandler.setView(view); |
||||
} |
||||
if (keyHandler != null) { |
||||
keyHandler.setView(view); |
||||
} |
||||
if (gestureHandler != null) { |
||||
gestureHandler.setView(view); |
||||
} |
||||
this.view = (GLSurfaceView)view; |
||||
} |
||||
|
||||
public View getView() { |
||||
return view; |
||||
} |
||||
|
||||
public float invertX(float origX) { |
||||
return getJmeX(view.getWidth()) - origX; |
||||
} |
||||
|
||||
public float invertY(float origY) { |
||||
return getJmeY(view.getHeight()) - origY; |
||||
} |
||||
|
||||
public float getJmeX(float origX) { |
||||
return origX * scaleX; |
||||
} |
||||
|
||||
public float getJmeY(float origY) { |
||||
return origY * scaleY; |
||||
} |
||||
|
||||
public void loadSettings(AppSettings settings) { |
||||
keyboardEventsEnabled = settings.isEmulateKeyboard(); |
||||
mouseEventsEnabled = settings.isEmulateMouse(); |
||||
mouseEventsInvertX = settings.isEmulateMouseFlipX(); |
||||
mouseEventsInvertY = settings.isEmulateMouseFlipY(); |
||||
|
||||
// view width and height are 0 until the view is displayed on the screen
|
||||
if (view.getWidth() != 0 && view.getHeight() != 0) { |
||||
scaleX = (float)settings.getWidth() / (float)view.getWidth(); |
||||
scaleY = (float)settings.getHeight() / (float)view.getHeight(); |
||||
} |
||||
logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}", |
||||
new Object[]{scaleX, scaleY}); |
||||
|
||||
} |
||||
|
||||
// -----------------------------------------
|
||||
// JME3 Input interface
|
||||
@Override |
||||
public void initialize() { |
||||
touchEventPool.initialize(); |
||||
if (touchHandler != null) { |
||||
touchHandler.initialize(); |
||||
} |
||||
if (keyHandler != null) { |
||||
keyHandler.initialize(); |
||||
} |
||||
if (gestureHandler != null) { |
||||
gestureHandler.initialize(); |
||||
} |
||||
|
||||
initialized = true; |
||||
} |
||||
|
||||
@Override |
||||
public void destroy() { |
||||
initialized = false; |
||||
|
||||
touchEventPool.destroy(); |
||||
if (touchHandler != null) { |
||||
touchHandler.destroy(); |
||||
} |
||||
if (keyHandler != null) { |
||||
keyHandler.destroy(); |
||||
} |
||||
if (gestureHandler != null) { |
||||
gestureHandler.destroy(); |
||||
} |
||||
|
||||
setView(null); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isInitialized() { |
||||
return initialized; |
||||
} |
||||
|
||||
@Override |
||||
public void setInputListener(RawInputListener listener) { |
||||
this.listener = listener; |
||||
} |
||||
|
||||
@Override |
||||
public long getInputTimeNanos() { |
||||
return System.nanoTime(); |
||||
} |
||||
|
||||
public void update() { |
||||
if (listener != null) { |
||||
InputEvent inputEvent; |
||||
|
||||
while ((inputEvent = inputEventQueue.poll()) != null) { |
||||
if (inputEvent instanceof TouchEvent) { |
||||
listener.onTouchEvent((TouchEvent)inputEvent); |
||||
} else if (inputEvent instanceof MouseButtonEvent) { |
||||
listener.onMouseButtonEvent((MouseButtonEvent)inputEvent); |
||||
} else if (inputEvent instanceof MouseMotionEvent) { |
||||
listener.onMouseMotionEvent((MouseMotionEvent)inputEvent); |
||||
} else if (inputEvent instanceof KeyInputEvent) { |
||||
listener.onKeyEvent((KeyInputEvent)inputEvent); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
// -----------------------------------------
|
||||
|
||||
public TouchEvent getFreeTouchEvent() { |
||||
return touchEventPool.getNextFreeEvent(); |
||||
} |
||||
|
||||
public void addEvent(InputEvent event) { |
||||
inputEventQueue.add(event); |
||||
if (event instanceof TouchEvent) { |
||||
touchEventPool.storeEvent((TouchEvent)event); |
||||
} |
||||
} |
||||
|
||||
public void setSimulateMouse(boolean simulate) { |
||||
this.mouseEventsEnabled = simulate; |
||||
} |
||||
|
||||
public boolean isSimulateMouse() { |
||||
return mouseEventsEnabled; |
||||
} |
||||
|
||||
public boolean isMouseEventsInvertX() { |
||||
return mouseEventsInvertX; |
||||
} |
||||
|
||||
public boolean isMouseEventsInvertY() { |
||||
return mouseEventsInvertY; |
||||
} |
||||
|
||||
public void setSimulateKeyboard(boolean simulate) { |
||||
this.keyboardEventsEnabled = simulate; |
||||
} |
||||
|
||||
public boolean isSimulateKeyboard() { |
||||
return keyboardEventsEnabled; |
||||
} |
||||
|
||||
public void setOmitHistoricEvents(boolean dontSendHistory) { |
||||
this.dontSendHistory = dontSendHistory; |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,257 @@ |
||||
/* |
||||
* Copyright (c) 2009-2015 jMonkeyEngine |
||||
* 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 'jMonkeyEngine' 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 com.jme3.input.android; |
||||
|
||||
import android.content.Context; |
||||
import android.opengl.GLSurfaceView; |
||||
import android.os.Build; |
||||
import android.os.Vibrator; |
||||
import android.view.View; |
||||
import com.jme3.input.InputManager; |
||||
import com.jme3.input.JoyInput; |
||||
import com.jme3.input.Joystick; |
||||
import com.jme3.input.RawInputListener; |
||||
import com.jme3.input.event.InputEvent; |
||||
import com.jme3.input.event.JoyAxisEvent; |
||||
import com.jme3.input.event.JoyButtonEvent; |
||||
import com.jme3.system.AppSettings; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.concurrent.ConcurrentLinkedQueue; |
||||
import java.util.logging.Level; |
||||
import java.util.logging.Logger; |
||||
|
||||
/** |
||||
* Main class that manages various joystick devices. Joysticks can be many forms |
||||
* including a simulated joystick to communicate the device orientation as well |
||||
* as physical gamepads. </br> |
||||
* This class manages all the joysticks and feeds the inputs from each back |
||||
* to jME's InputManager. |
||||
* |
||||
* This handler also supports the joystick.rumble(rumbleAmount) method. In this |
||||
* case, when joystick.rumble(rumbleAmount) is called, the Android device will vibrate |
||||
* if the device has a built in vibrate motor. |
||||
* |
||||
* Because Andorid does not allow for the user to define the intensity of the |
||||
* vibration, the rumble amount (ie strength) is converted into vibration pulses |
||||
* The stronger the strength amount, the shorter the delay between pulses. If |
||||
* amount is 1, then the vibration stays on the whole time. If amount is 0.5, |
||||
* the vibration will a pulse of equal parts vibration and delay. |
||||
* To turn off vibration, set rumble amount to 0. |
||||
* |
||||
* MainActivity needs the following line to enable Joysticks on Android platforms |
||||
* joystickEventsEnabled = true; |
||||
* This is done to allow for battery conservation when sensor data or gamepads |
||||
* are not required by the application. |
||||
* |
||||
* To use the joystick rumble feature, the following line needs to be |
||||
* added to the Android Manifest File |
||||
* <uses-permission android:name="android.permission.VIBRATE"/> |
||||
* |
||||
* @author iwgeric |
||||
*/ |
||||
public class AndroidJoyInputHandler implements JoyInput { |
||||
private static final Logger logger = Logger.getLogger(AndroidJoyInputHandler.class.getName()); |
||||
|
||||
private List<Joystick> joystickList = new ArrayList<Joystick>(); |
||||
// private boolean dontSendHistory = false;
|
||||
|
||||
|
||||
// Internal
|
||||
private GLSurfaceView view; |
||||
private boolean initialized = false; |
||||
private RawInputListener listener = null; |
||||
private ConcurrentLinkedQueue<InputEvent> eventQueue = new ConcurrentLinkedQueue<InputEvent>(); |
||||
private AndroidSensorJoyInput sensorJoyInput; |
||||
private Vibrator vibrator = null; |
||||
private boolean vibratorActive = false; |
||||
private long maxRumbleTime = 250; // 250ms
|
||||
|
||||
public AndroidJoyInputHandler() { |
||||
int buildVersion = Build.VERSION.SDK_INT; |
||||
logger.log(Level.INFO, "Android Build Version: {0}", buildVersion); |
||||
// if (buildVersion >= 14) {
|
||||
// touchHandler = new AndroidTouchHandler14(this);
|
||||
// } else if (buildVersion >= 8){
|
||||
// touchHandler = new AndroidTouchHandler(this);
|
||||
// }
|
||||
sensorJoyInput = new AndroidSensorJoyInput(this); |
||||
} |
||||
|
||||
public void setView(GLSurfaceView view) { |
||||
// if (touchHandler != null) {
|
||||
// touchHandler.setView(view);
|
||||
// }
|
||||
if (sensorJoyInput != null) { |
||||
sensorJoyInput.setView(view); |
||||
} |
||||
this.view = (GLSurfaceView)view; |
||||
|
||||
} |
||||
|
||||
public View getView() { |
||||
return view; |
||||
} |
||||
|
||||
public void loadSettings(AppSettings settings) { |
||||
// sensorEventsEnabled = settings.useSensors();
|
||||
} |
||||
|
||||
public void addEvent(InputEvent event) { |
||||
eventQueue.add(event); |
||||
} |
||||
|
||||
/** |
||||
* Pauses the joystick device listeners to save battery life if they are not needed. |
||||
* Used to pause when the activity pauses |
||||
*/ |
||||
public void pauseJoysticks() { |
||||
if (sensorJoyInput != null) { |
||||
sensorJoyInput.pauseSensors(); |
||||
} |
||||
if (vibrator != null && vibratorActive) { |
||||
vibrator.cancel(); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Resumes the joystick device listeners. |
||||
* Used to resume when the activity comes to the top of the stack |
||||
*/ |
||||
public void resumeJoysticks() { |
||||
if (sensorJoyInput != null) { |
||||
sensorJoyInput.resumeSensors(); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override |
||||
public void initialize() { |
||||
// if (sensorJoyInput != null) {
|
||||
// sensorJoyInput.initialize();
|
||||
// }
|
||||
// Get instance of Vibrator from current Context
|
||||
vibrator = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE); |
||||
if (vibrator == null) { |
||||
logger.log(Level.FINE, "Vibrator Service not found."); |
||||
} |
||||
initialized = true; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isInitialized() { |
||||
return initialized; |
||||
} |
||||
|
||||
@Override |
||||
public void destroy() { |
||||
initialized = false; |
||||
|
||||
if (sensorJoyInput != null) { |
||||
sensorJoyInput.destroy(); |
||||
} |
||||
|
||||
setView(null); |
||||
} |
||||
|
||||
@Override |
||||
public void setInputListener(RawInputListener listener) { |
||||
this.listener = listener; |
||||
} |
||||
|
||||
@Override |
||||
public long getInputTimeNanos() { |
||||
return System.nanoTime(); |
||||
} |
||||
|
||||
@Override |
||||
public void setJoyRumble(int joyId, float amount) { |
||||
// convert amount to pulses since Android doesn't allow intensity
|
||||
if (vibrator != null) { |
||||
final long rumbleOnDur = (long)(amount * maxRumbleTime); // ms to pulse vibration on
|
||||
final long rumbleOffDur = maxRumbleTime - rumbleOnDur; // ms to delay between pulses
|
||||
final long[] rumblePattern = { |
||||
0, // start immediately
|
||||
rumbleOnDur, // time to leave vibration on
|
||||
rumbleOffDur // time to delay between vibrations
|
||||
}; |
||||
final int rumbleRepeatFrom = 0; // index into rumble pattern to repeat from
|
||||
|
||||
logger.log(Level.FINE, "Rumble amount: {0}, rumbleOnDur: {1}, rumbleOffDur: {2}", |
||||
new Object[]{amount, rumbleOnDur, rumbleOffDur}); |
||||
|
||||
if (rumbleOnDur > 0) { |
||||
vibrator.vibrate(rumblePattern, rumbleRepeatFrom); |
||||
vibratorActive = true; |
||||
} else { |
||||
vibrator.cancel(); |
||||
vibratorActive = false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Joystick[] loadJoysticks(InputManager inputManager) { |
||||
joystickList.add(sensorJoyInput.loadJoystick(joystickList.size(), inputManager)); |
||||
|
||||
|
||||
return joystickList.toArray( new Joystick[joystickList.size()] ); |
||||
} |
||||
|
||||
@Override |
||||
public void update() { |
||||
if (sensorJoyInput != null) { |
||||
sensorJoyInput.update(); |
||||
} |
||||
|
||||
if (listener != null) { |
||||
InputEvent inputEvent; |
||||
|
||||
while ((inputEvent = eventQueue.poll()) != null) { |
||||
if (inputEvent instanceof JoyAxisEvent) { |
||||
listener.onJoyAxisEvent((JoyAxisEvent)inputEvent); |
||||
} else if (inputEvent instanceof JoyButtonEvent) { |
||||
listener.onJoyButtonEvent((JoyButtonEvent)inputEvent); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue