Android: Fixed race-condition on GLSurfaceView destroy, fixed MouseEvents for flyCam rotation bug

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7536 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
kim..ng 14 years ago
parent e5478faae0
commit 8cefea550e
  1. 2
      engine/src/android/com/jme3/app/AndroidHarness.java
  2. 5
      engine/src/android/com/jme3/app/android/AndroidApplication.java
  3. 42
      engine/src/android/com/jme3/input/android/AndroidInput.java
  4. 8
      engine/src/android/com/jme3/system/android/OGLESContext.java

@ -110,7 +110,7 @@ public class AndroidHarness extends Activity implements DialogInterface.OnClickL
@Override
protected void onDestroy(){
super.onDestroy();
super.onDestroy();
app.stop();
logger.info("onDestroy");
}

@ -33,6 +33,7 @@ package com.jme3.app.android;
import java.nio.CharBuffer;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import android.app.Activity;
import android.app.AlertDialog;
@ -62,6 +63,7 @@ import com.jme3.app.AndroidHarness;
@Deprecated
public abstract class AndroidApplication extends Application implements DialogInterface.OnClickListener
{
protected final static Logger logger = Logger.getLogger(AndroidApplication.class.getName());
protected Node rootNode = new Node("Root Node");
protected Node guiNode = new Node("Gui Node");
@ -258,6 +260,9 @@ public abstract class AndroidApplication extends Application implements DialogIn
}
}
final String sTrace = s;
logger.severe(t != null ? t.toString() : "Failed");
logger.severe((errorMsg != null ? errorMsg + ": " : "") + sTrace);
activity.runOnUiThread(new Runnable() {
@Override
public void run()

@ -30,7 +30,8 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
private AndroidTouchInputListener listenerTouch = null;
private ScaleGestureDetector scaledetector;
private GestureDetector detector;
private Vector2f lastPos = new Vector2f();
private int lastX;
private int lastY;
private boolean dragging = false;
private List<Object> currentEvents = new ArrayList<Object>();
@ -175,22 +176,24 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
this.detector.onTouchEvent(event);
this.scaledetector.onTouchEvent(event);
int newX = getWidth() - (int) event.getX();
int newY = (int) event.getY();
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
// Store current pos
lastPos.set(event.getX(),event.getY());
if (FIRE_MOUSE_EVENTS)
{
// Handle mouse events
btn = new MouseButtonEvent(0, true, (int)lastPos.getX(), (int)lastPos.getY());
btn = new MouseButtonEvent(0, true, newX, newY);
btn.setTime(event.getEventTime());
processEvent(btn);
}
// Store current pos
lastX = -1;
lastY = -1;
// Handle gesture events
touch = new TouchEvent(TouchEvent.Type.GRABBED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null);
processEvent(touch);
@ -203,14 +206,18 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
if (FIRE_MOUSE_EVENTS)
{
// Handle mouse events
btn = new MouseButtonEvent(0, false, (int)event.getX(), (int)event.getY());
btn = new MouseButtonEvent(0, false, newX, newY);
btn.setTime(event.getEventTime());
processEvent(btn);
}
}
// Store current pos
lastX = -1;
lastY = -1;
// Handle gesture events
if(dragging)
{
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STOPPED,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null);
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STOPPED,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null);
processEvent(touch);
}
touch = new TouchEvent(TouchEvent.Type.RELEASED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null);
@ -222,22 +229,21 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
if(!scaledetector.isInProgress())
{
if(!dragging)
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STARTED,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null);
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STARTED,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null);
else
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.RUNNING,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null);
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.RUNNING,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null);
processEvent(touch);
dragging=true;
}
if (FIRE_MOUSE_EVENTS)
{
int newX = getWidth() - (int) event.getX();
int newY = (int) event.getY();
int dx;
int dy;
if (lastPos.getX() != -1){
dx = newX - (int)lastPos.getX();
dy = newY - (int)lastPos.getY();
if (lastX != -1){
dx = newX - lastX;
dy = newY - lastY;
}else{
dx = 0;
dy = 0;
@ -246,6 +252,8 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
mot.setTime(event.getEventTime());
processEvent(mot);
}
lastX = newX;
lastY = newY;
bWasHandled = true;
break;

@ -295,8 +295,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
public void onDrawFrame(GL10 gl)
{
if (!created.get())
throw new IllegalStateException("onDrawFrame without create");
if (needClose.get())
{
@ -306,6 +304,10 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
if (renderable.get())
{
if (!created.get())
throw new IllegalStateException("onDrawFrame without create");
milliStart = System.currentTimeMillis();
@ -369,7 +371,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
public void destroy()
{
destroy(false);
destroy(true);
}
protected void waitFor(boolean createdVal)

Loading…
Cancel
Save