Skip to content

Commit

Permalink
Merge pull request #2031 from bob0bob/master
Browse files Browse the repository at this point in the history
 Add support for Multiple Monitors in jme-LWJGL3 #2030
  • Loading branch information
yaRnMcDonuts authored Jan 4, 2025
2 parents 9da1079 + b2bf1b4 commit 80623a1
Show file tree
Hide file tree
Showing 18 changed files with 2,367 additions and 1,582 deletions.
230 changes: 139 additions & 91 deletions jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import com.jme3.system.*;
import com.jme3.util.BufferAllocatorFactory;
import com.jme3.util.PrimitiveAllocator;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -79,7 +78,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
protected SystemListener listener;
protected boolean autoFlush = true;
protected AndroidInputHandler androidInput;
protected long minFrameDuration = 0; // No FPS cap
protected long minFrameDuration = 0; // No FPS cap
protected long lastUpdateTime = 0;

static {
Expand All @@ -90,8 +89,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
}
}

public OGLESContext() {
}
public OGLESContext() {}

@Override
public Type getType() {
Expand All @@ -115,9 +113,11 @@ public GLSurfaceView createView(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// below 4.0, check OpenGL ES 2.0 support.
if (info.reqGlEsVersion < 0x20000) {
throw new UnsupportedOperationException("OpenGL ES 2.0 or better is not supported on this device");
throw new UnsupportedOperationException(
"OpenGL ES 2.0 or better is not supported on this device"
);
}
} else if (Build.VERSION.SDK_INT < 9){
} else if (Build.VERSION.SDK_INT < 9) {
throw new UnsupportedOperationException("jME3 requires Android 2.3 or later");
}

Expand All @@ -127,7 +127,7 @@ public GLSurfaceView createView(Context context) {
if (androidInput == null) {
if (Build.VERSION.SDK_INT >= 14) {
androidInput = new AndroidInputHandler14();
} else if (Build.VERSION.SDK_INT >= 9){
} else if (Build.VERSION.SDK_INT >= 9) {
androidInput = new AndroidInputHandler();
}
}
Expand All @@ -137,7 +137,7 @@ public GLSurfaceView createView(Context context) {
// setEGLContextClientVersion must be set before calling setRenderer
// this means it cannot be set in AndroidConfigChooser (too late)
// use proper openGL ES version
view.setEGLContextClientVersion(info.reqGlEsVersion>>16);
view.setEGLContextClientVersion(info.reqGlEsVersion >> 16);

view.setFocusableInTouchMode(true);
view.setFocusable(true);
Expand Down Expand Up @@ -200,22 +200,35 @@ protected void initInThread() {
logger.log(Level.FINE, "Running on thread: {0}", Thread.currentThread().getName());

// Setup unhandled Exception Handler
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable thrown) {
listener.handleError("Exception thrown in " + thread.toString(), thrown);
}
});
Thread
.currentThread()
.setUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable thrown) {
listener.handleError("Exception thrown in " + thread.toString(), thrown);
}
}
);

timer = new NanoTimer();
GL gl = new AndroidGL();
if (settings.getBoolean("GraphicsDebug")) {
gl = (GL) GLDebug.createProxy(gl, gl, GL.class, GL2.class, GLES_30.class, GLFbo.class, GLExt.class);
gl =
(GL) GLDebug.createProxy(
gl,
gl,
GL.class,
GL2.class,
GLES_30.class,
GLFbo.class,
GLExt.class
);
}
if (settings.getBoolean("GraphicsTrace")) {
gl = (GL)GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
gl = (GL) GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
}
renderer = new GLRenderer(gl, (GLExt)gl, (GLFbo)gl);
renderer = new GLRenderer(gl, (GLExt) gl, (GLFbo) gl);
renderer.initialize();

JmeSystem.setSoftTextDialogInput(this);
Expand Down Expand Up @@ -254,7 +267,7 @@ public void setSettings(AppSettings settings) {
}

if (settings.getFrameRate() > 0) {
minFrameDuration = (long)(1000d / settings.getFrameRate()); // ms
minFrameDuration = (long) (1000d / settings.getFrameRate()); // ms
logger.log(Level.FINE, "Setting min tpf: {0}ms", minFrameDuration);
} else {
minFrameDuration = 0;
Expand Down Expand Up @@ -312,8 +325,7 @@ public Timer getTimer() {
}

@Override
public void setTitle(String title) {
}
public void setTitle(String title) {}

@Override
public boolean isCreated() {
Expand All @@ -329,7 +341,11 @@ public void setAutoFlushFrames(boolean enabled) {
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "GL Surface changed, width: {0} height: {1}", new Object[]{width, height});
logger.log(
Level.FINE,
"GL Surface changed, width: {0} height: {1}",
new Object[] { width, height }
);
}
// update the application settings with the new resolution
settings.setResolution(width, height);
Expand Down Expand Up @@ -372,16 +388,14 @@ public void onDrawFrame(GL10 gl) {

// Enforce a FPS cap
if (updateDelta < minFrameDuration) {
// logger.log(Level.INFO, "lastUpdateTime: {0}, updateDelta: {1}, minTimePerFrame: {2}",
// new Object[]{lastUpdateTime, updateDelta, minTimePerFrame});
// logger.log(Level.INFO, "lastUpdateTime: {0}, updateDelta: {1}, minTimePerFrame: {2}",
// new Object[]{lastUpdateTime, updateDelta, minTimePerFrame});
try {
Thread.sleep(minFrameDuration - updateDelta);
} catch (InterruptedException e) {
}
} catch (InterruptedException e) {}
}

lastUpdateTime = System.currentTimeMillis();

}
}

Expand All @@ -402,8 +416,7 @@ public void create() {
}

@Override
public void restart() {
}
public void restart() {}

@Override
public void destroy(boolean waitFor) {
Expand All @@ -421,76 +434,99 @@ protected void waitFor(boolean createdVal) {
while (renderable.get() != createdVal) {
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
}
} catch (InterruptedException ex) {}
}
}

@Override
public void requestDialog(final int id, final String title, final String initialValue, final SoftTextDialogInputListener listener) {
public void requestDialog(
final int id,
final String title,
final String initialValue,
final SoftTextDialogInputListener listener
) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "requestDialog: title: {0}, initialValue: {1}",
new Object[]{title, initialValue});
logger.log(
Level.FINE,
"requestDialog: title: {0}, initialValue: {1}",
new Object[] { title, initialValue }
);
}

final View view = JmeAndroidSystem.getView();
view.getHandler().post(new Runnable() {
@Override
public void run() {

final FrameLayout layoutTextDialogInput = new FrameLayout(view.getContext());
final EditText editTextDialogInput = new EditText(view.getContext());
editTextDialogInput.setWidth(LayoutParams.FILL_PARENT);
editTextDialogInput.setHeight(LayoutParams.FILL_PARENT);
editTextDialogInput.setPadding(20, 20, 20, 20);
editTextDialogInput.setGravity(Gravity.FILL_HORIZONTAL);
//editTextDialogInput.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

editTextDialogInput.setText(initialValue);

switch (id) {
case SoftTextDialogInput.TEXT_ENTRY_DIALOG:

editTextDialogInput.setInputType(InputType.TYPE_CLASS_TEXT);
break;

case SoftTextDialogInput.NUMERIC_ENTRY_DIALOG:

editTextDialogInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
break;

case SoftTextDialogInput.NUMERIC_KEYPAD_DIALOG:

editTextDialogInput.setInputType(InputType.TYPE_CLASS_PHONE);
break;

default:
break;
view
.getHandler()
.post(
new Runnable() {
@Override
public void run() {
final FrameLayout layoutTextDialogInput = new FrameLayout(view.getContext());
final EditText editTextDialogInput = new EditText(view.getContext());
editTextDialogInput.setWidth(LayoutParams.FILL_PARENT);
editTextDialogInput.setHeight(LayoutParams.FILL_PARENT);
editTextDialogInput.setPadding(20, 20, 20, 20);
editTextDialogInput.setGravity(Gravity.FILL_HORIZONTAL);
//editTextDialogInput.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

editTextDialogInput.setText(initialValue);

switch (id) {
case SoftTextDialogInput.TEXT_ENTRY_DIALOG:
editTextDialogInput.setInputType(InputType.TYPE_CLASS_TEXT);
break;
case SoftTextDialogInput.NUMERIC_ENTRY_DIALOG:
editTextDialogInput.setInputType(
InputType.TYPE_CLASS_NUMBER |
InputType.TYPE_NUMBER_FLAG_DECIMAL |
InputType.TYPE_NUMBER_FLAG_SIGNED
);
break;
case SoftTextDialogInput.NUMERIC_KEYPAD_DIALOG:
editTextDialogInput.setInputType(InputType.TYPE_CLASS_PHONE);
break;
default:
break;
}

layoutTextDialogInput.addView(editTextDialogInput);

AlertDialog dialogTextInput = new AlertDialog.Builder(view.getContext())
.setTitle(title)
.setView(layoutTextDialogInput)
.setPositiveButton(
"OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK, send COMPLETE action
* and text */
listener.onSoftText(
SoftTextDialogInputListener.COMPLETE,
editTextDialogInput.getText().toString()
);
}
}
)
.setNegativeButton(
"Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked CANCEL, send CANCEL action
* and text */
listener.onSoftText(
SoftTextDialogInputListener.CANCEL,
editTextDialogInput.getText().toString()
);
}
}
)
.create();

dialogTextInput.show();
}
}

layoutTextDialogInput.addView(editTextDialogInput);

AlertDialog dialogTextInput = new AlertDialog.Builder(view.getContext()).setTitle(title).setView(layoutTextDialogInput).setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK, send COMPLETE action
* and text */
listener.onSoftText(SoftTextDialogInputListener.COMPLETE, editTextDialogInput.getText().toString());
}
}).setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked CANCEL, send CANCEL action
* and text */
listener.onSoftText(SoftTextDialogInputListener.CANCEL, editTextDialogInput.getText().toString());
}
}).create();

dialogTextInput.show();
}
});
);
}

@Override
Expand Down Expand Up @@ -542,11 +578,11 @@ public int getWindowXPosition() {
public int getWindowYPosition() {
throw new UnsupportedOperationException("not implemented yet");
}

/**
* Retrieves the dimensions of the input surface. Note: do not modify the
* returned object.
*
*
* @return the dimensions (in pixels, left and top are 0)
*/
private Rect getSurfaceFrame() {
Expand All @@ -555,4 +591,16 @@ private Rect getSurfaceFrame() {
Rect result = holder.getSurfaceFrame();
return result;
}

@Override
public Displays getDisplays() {
// TODO Auto-generated method stub
return null;
}

@Override
public int getPrimaryDisplay() {
// TODO Auto-generated method stub
return 0;
}
}
Loading

0 comments on commit 80623a1

Please sign in to comment.