Android: Fixed a race condition in OGLESContext which sometimes called initialize() more than once, added screen resolution setting and invert mouse x to harness

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7850 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
kim..ng 14 years ago
parent 026abb5a74
commit 2f8ae09033
  1. 27
      engine/src/android/com/jme3/app/AndroidHarness.java
  2. 14
      engine/src/android/com/jme3/input/android/AndroidInput.java
  3. 52
      engine/src/android/com/jme3/system/android/OGLESContext.java

@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Bundle; import android.os.Bundle;
import android.view.Display;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
@ -56,7 +57,17 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
*/ */
protected boolean eglConfigVerboseLogging = false; protected boolean eglConfigVerboseLogging = false;
/**
* If true MouseEvents are generated from TouchEvents
*/
protected boolean mouseEventsEnabled = true; protected boolean mouseEventsEnabled = true;
/**
* Flip X axis
*/
protected boolean mouseEventsInvertX = true;
/**
* Flip Y axis
*/
protected boolean mouseEventsInvertY = true; protected boolean mouseEventsInvertY = true;
/** /**
@ -102,9 +113,12 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
setRequestedOrientation(screenOrientation); setRequestedOrientation(screenOrientation);
// Create Settings
AppSettings settings = new AppSettings(true); AppSettings settings = new AppSettings(true);
AndroidInput input = new AndroidInput(this);
// Create the input class
AndroidInput input = new AndroidInput(this);
input.setMouseEventsInvertX(mouseEventsInvertX);
input.setMouseEventsInvertY(mouseEventsInvertY); input.setMouseEventsInvertY(mouseEventsInvertY);
input.setMouseEventsEnabled(mouseEventsEnabled); input.setMouseEventsEnabled(mouseEventsEnabled);
@ -123,12 +137,23 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
ctx = (OGLESContext) app.getContext(); ctx = (OGLESContext) app.getContext();
view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging); view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);
setContentView(view); setContentView(view);
// Set the screen reolution
WindowManager wind = this.getWindowManager();
Display disp = wind.getDefaultDisplay();
ctx.getSettings().setResolution(disp.getWidth(), disp.getHeight());
AppSettings s = ctx.getSettings();
logger.info("Settings: Width " + s.getWidth() + " Height " + s.getHeight());
} }
catch (Exception ex) catch (Exception ex)
{ {
handleError("Class " + appClass + " init failed", ex); handleError("Class " + appClass + " init failed", ex);
setContentView(new TextView(this)); setContentView(new TextView(this));
} }
} }

@ -32,6 +32,7 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
// Custom settings // Custom settings
public boolean mouseEventsEnabled = true; public boolean mouseEventsEnabled = true;
public boolean mouseEventsInvertX = false;
public boolean mouseEventsInvertY = false; public boolean mouseEventsInvertY = false;
public boolean keyboardEventsEnabled = false; public boolean keyboardEventsEnabled = false;
@ -521,7 +522,11 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
if (mouseEventsEnabled) if (mouseEventsEnabled)
{ {
if (mouseEventsInvertX)
newX = this.getWidth() - (int) event.getX(); newX = this.getWidth() - (int) event.getX();
else
newX = (int) event.getX();
if (mouseEventsInvertY) if (mouseEventsInvertY)
newY = this.getHeight() - (int) event.getY(); newY = this.getHeight() - (int) event.getY();
else else
@ -566,6 +571,8 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
lastY = newY; lastY = newY;
break; break;
} }
} }
} }
@ -737,5 +744,12 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
this.mouseEventsInvertY = mouseEventsInvertY; this.mouseEventsInvertY = mouseEventsInvertY;
} }
public boolean isMouseEventsInvertX() {
return mouseEventsInvertX;
}
public void setMouseEventsInvertX(boolean mouseEventsInvertX) {
this.mouseEventsInvertX = mouseEventsInvertX;
}
} }

@ -179,9 +179,33 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
return view; return view;
} }
// renderer:initialize
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig cfg)
{
if (created.get() && renderer != null)
{
renderer.resetGLObjects();
}
else
{
if (!created.get())
{
logger.info("GL Surface created");
initInThread();
}
else
{
logger.warning("GL Surface already created");
}
}
}
protected void initInThread() protected void initInThread()
{ {
created.set(true);
logger.info("OGLESContext create"); logger.info("OGLESContext create");
logger.info("Running on thread: "+Thread.currentThread().getName()); logger.info("Running on thread: "+Thread.currentThread().getName());
@ -231,8 +255,8 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
} }
} }
created.set(true);
needClose.set(false); needClose.set(false);
renderable.set(true);
} }
/** /**
@ -242,7 +266,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
{ {
if (renderable.get()) if (renderable.get())
{ {
renderable.set(false); created.set(false);
if (renderer != null) if (renderer != null)
renderer.cleanup(); renderer.cleanup();
@ -255,7 +279,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
// do android specific cleaning here // do android specific cleaning here
logger.info("Display destroyed."); logger.info("Display destroyed.");
created.set(false); renderable.set(false);
} }
} }
@ -267,10 +291,11 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
renderer.setVerboseLogging(settings.getBoolean("VERBOSE_LOGGING")); renderer.setVerboseLogging(settings.getBoolean("VERBOSE_LOGGING"));
} }
protected void applySettings(AppSettings setting) protected void applySettings(AppSettings settings)
{ {
setSettings(settings);
if (renderer != null) if (renderer != null)
applySettingsToRenderer(renderer, settings); applySettingsToRenderer(renderer, this.settings);
} }
@Override @Override
@ -336,22 +361,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
this.autoFlush = enabled; this.autoFlush = enabled;
} }
// renderer:initialize
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig cfg)
{
if (created.get() && renderer != null)
{
renderer.resetGLObjects();
}
else
{
logger.info("GL Surface created");
initInThread();
renderable.set(true);
}
}
// SystemListener:reshape // SystemListener:reshape
@Override @Override
@ -447,7 +457,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
protected void waitFor(boolean createdVal) protected void waitFor(boolean createdVal)
{ {
while (created.get() != createdVal){ while (renderable.get() != createdVal){
try { try {
Thread.sleep(10); Thread.sleep(10);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {

Loading…
Cancel
Save