THIS REVISION WILL NOT RUN! Added an own implementation of GLSurfaceView to launch native main() code from it.

This commit is contained in:
pelya
2010-05-17 18:39:02 +03:00
parent cac11c5812
commit 4059cb46f1
5 changed files with 1552 additions and 298 deletions

View File

@@ -1,9 +1,15 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
package de.schwardtnet.alienblaster;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGL11;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
@@ -65,22 +71,31 @@ class AccelerometerReader implements SensorListener {
private long timekeeper;
private float [] v;
private SensorManager _manager = null;
public AccelerometerReader(Activity context) {
v = new float[3];
SensorManager sma = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
if( sma != null )
_manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
if( _manager != null )
{
timekeeper = android.os.SystemClock.uptimeMillis();
int mask = 0;
mask |= SensorManager.SENSOR_ORIENTATION;
//mask |= SensorManager.SENSOR_ORIENTATION;
mask |= SensorManager.SENSOR_ACCELEROMETER;
sma.registerListener(this, mask, SensorManager.SENSOR_DELAY_GAME);
_manager.registerListener(this, mask, SensorManager.SENSOR_DELAY_GAME);
}
}
public synchronized void stop() {
if( _manager != null )
{
_manager.unregisterListener(this);
}
}
public synchronized void onSensorChanged(int sensor, float[] values) {
if (android.os.SystemClock.uptimeMillis() < timekeeper + 20) return;
//if (android.os.SystemClock.uptimeMillis() < timekeeper + 20) return;
timekeeper = android.os.SystemClock.uptimeMillis();
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
@@ -90,8 +105,9 @@ class AccelerometerReader implements SensorListener {
v[1] = values[1];
if( values.length >= 3 )
v[2] = values[2];
nativeAccelerometer(v[0], v[1], v[2]);
}
}
public synchronized void onAccuracyChanged(int i, int i1) {
@@ -106,15 +122,16 @@ class AccelerometerReader implements SensorListener {
ret[2] = v[2];
return ret;
};
private native void nativeAccelerometer(float accX, float accY, float accZ);
}
class DemoRenderer implements GLSurfaceView.Renderer {
class DemoRenderer extends GLSurfaceView_SDL.Renderer {
public DemoRenderer(Activity _context)
{
super();
context = _context;
}
@@ -128,30 +145,43 @@ class DemoRenderer implements GLSurfaceView.Renderer {
}
public void onDrawFrame(GL10 gl) {
if( accelerometer == null) {
accelerometer = new AccelerometerReader(context);
nativeInit();
}
float [] f = accelerometer.readAccelerometer();
nativeRender(f[0], f[1], f[2]);
nativeInitJavaCallbacks();
nativeInit(); // Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code
}
public int swapBuffers() // Called from native code, returns 1 on success, 0 when GL context lost (user put app to background)
{
System.out.println("Java: swapBuffers() called");
return super.SwapBuffers() ? 1 : 0;
}
public void exitApp() {
nativeDone();
};
private static native void nativeInit();
private static native void nativeResize(int w, int h);
private static native void nativeRender(float accX, float accY, float accZ);
private static native void nativeDone();
private AccelerometerReader accelerometer = null;
private native void nativeInitJavaCallbacks();
private native void nativeInit();
private native void nativeResize(int w, int h);
private native void nativeDone();
private Activity context = null;
private EGL10 mEgl = null;
private EGLDisplay mEglDisplay = null;
private EGLSurface mEglSurface = null;
private EGLContext mEglContext = null;
private int skipFrames = 0;
}
class DemoGLSurfaceView extends GLSurfaceView {
class DemoGLSurfaceView extends GLSurfaceView_SDL {
public DemoGLSurfaceView(Activity context) {
super(context);
mParent = context;
accelerometer = new AccelerometerReader(context);
mRenderer = new DemoRenderer(context);
setRenderer(mRenderer);
}
@@ -175,6 +205,8 @@ class DemoGLSurfaceView extends GLSurfaceView {
public void exitApp() {
mRenderer.exitApp();
accelerometer.stop();
accelerometer = null;
};
@Override
@@ -191,9 +223,10 @@ class DemoGLSurfaceView extends GLSurfaceView {
DemoRenderer mRenderer;
Activity mParent;
AccelerometerReader accelerometer = null;
public static native void nativeMouse( int x, int y, int action );
public static native void nativeKey( int keyCode, int down );
public native void nativeMouse( int x, int y, int action );
public native void nativeKey( int keyCode, int down );
}
class AudioThread extends Thread {
@@ -267,10 +300,10 @@ class AudioThread extends Thread {
}
}
private static native int[] nativeAudioInit();
private static native int nativeAudioInit2(byte[] buf);
private static native int nativeAudioBufferLock();
private static native int nativeAudioBufferUnlock();
private native int[] nativeAudioInit();
private native int nativeAudioInit2(byte[] buf);
private native int nativeAudioBufferLock();
private native int nativeAudioBufferUnlock();
}

File diff suppressed because it is too large Load Diff