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
This commit is contained in:
parent
026abb5a74
commit
2f8ae09033
@ -8,6 +8,7 @@ import android.content.DialogInterface;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
import android.view.Display;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
@ -56,7 +57,17 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
||||
*/
|
||||
protected boolean eglConfigVerboseLogging = false;
|
||||
|
||||
/**
|
||||
* If true MouseEvents are generated from TouchEvents
|
||||
*/
|
||||
protected boolean mouseEventsEnabled = true;
|
||||
/**
|
||||
* Flip X axis
|
||||
*/
|
||||
protected boolean mouseEventsInvertX = true;
|
||||
/**
|
||||
* Flip Y axis
|
||||
*/
|
||||
protected boolean mouseEventsInvertY = true;
|
||||
|
||||
/**
|
||||
@ -102,9 +113,12 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
||||
|
||||
setRequestedOrientation(screenOrientation);
|
||||
|
||||
// Create Settings
|
||||
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.setMouseEventsEnabled(mouseEventsEnabled);
|
||||
|
||||
@ -123,12 +137,23 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
||||
ctx = (OGLESContext) app.getContext();
|
||||
view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);
|
||||
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)
|
||||
{
|
||||
handleError("Class " + appClass + " init failed", ex);
|
||||
setContentView(new TextView(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,6 +32,7 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
||||
|
||||
// Custom settings
|
||||
public boolean mouseEventsEnabled = true;
|
||||
public boolean mouseEventsInvertX = false;
|
||||
public boolean mouseEventsInvertY = false;
|
||||
|
||||
public boolean keyboardEventsEnabled = false;
|
||||
@ -521,7 +522,11 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
||||
|
||||
if (mouseEventsEnabled)
|
||||
{
|
||||
if (mouseEventsInvertX)
|
||||
newX = this.getWidth() - (int) event.getX();
|
||||
else
|
||||
newX = (int) event.getX();
|
||||
|
||||
if (mouseEventsInvertY)
|
||||
newY = this.getHeight() - (int) event.getY();
|
||||
else
|
||||
@ -566,6 +571,8 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
||||
lastY = newY;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -737,5 +744,12 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
||||
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;
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
created.set(true);
|
||||
|
||||
logger.info("OGLESContext create");
|
||||
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);
|
||||
renderable.set(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,7 +266,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
|
||||
{
|
||||
if (renderable.get())
|
||||
{
|
||||
renderable.set(false);
|
||||
created.set(false);
|
||||
if (renderer != null)
|
||||
renderer.cleanup();
|
||||
|
||||
@ -255,7 +279,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
|
||||
// do android specific cleaning here
|
||||
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"));
|
||||
}
|
||||
|
||||
protected void applySettings(AppSettings setting)
|
||||
protected void applySettings(AppSettings settings)
|
||||
{
|
||||
setSettings(settings);
|
||||
if (renderer != null)
|
||||
applySettingsToRenderer(renderer, settings);
|
||||
applySettingsToRenderer(renderer, this.settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -336,22 +361,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
|
||||
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
|
||||
@Override
|
||||
@ -447,7 +457,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
|
||||
|
||||
protected void waitFor(boolean createdVal)
|
||||
{
|
||||
while (created.get() != createdVal){
|
||||
while (renderable.get() != createdVal){
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException ex) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user