THIS REVISION WILL NOT RUN! Added an own implementation of GLSurfaceView to launch native main() code from it.
This commit is contained in:
@@ -61,9 +61,16 @@ cat project/AndroidManifest.xml | \
|
|||||||
project/AndroidManifest.xml.1
|
project/AndroidManifest.xml.1
|
||||||
mv -f project/AndroidManifest.xml.1 project/AndroidManifest.xml
|
mv -f project/AndroidManifest.xml.1 project/AndroidManifest.xml
|
||||||
|
|
||||||
|
for F in project/src/*.java; do
|
||||||
|
echo Patching $F
|
||||||
|
cat $F | \
|
||||||
|
sed "s/package .*;/package $AppFullName;/" > \
|
||||||
|
$F.1
|
||||||
|
mv -f $F.1 $F
|
||||||
|
done
|
||||||
|
|
||||||
echo Patching project/src/DemoActivity.java
|
echo Patching project/src/DemoActivity.java
|
||||||
cat project/src/DemoActivity.java | \
|
cat project/src/DemoActivity.java | \
|
||||||
sed "s/package .*;/package $AppFullName;/" | \
|
|
||||||
sed "s/public static String ApplicationName = .*;/public static String ApplicationName = \"$AppShortName\";/" | \
|
sed "s/public static String ApplicationName = .*;/public static String ApplicationName = \"$AppShortName\";/" | \
|
||||||
sed "s^public static String DataDownloadUrl = \".*\";^public static String DataDownloadUrl = \"$AppDataDownloadUrl1\";^" | \
|
sed "s^public static String DataDownloadUrl = \".*\";^public static String DataDownloadUrl = \"$AppDataDownloadUrl1\";^" | \
|
||||||
sed "s/public static boolean DownloadToSdcard = .*;/public static boolean DownloadToSdcard = $DownloadToSdcard1;/" > \
|
sed "s/public static boolean DownloadToSdcard = .*;/public static boolean DownloadToSdcard = $DownloadToSdcard1;/" > \
|
||||||
|
|||||||
@@ -125,20 +125,20 @@ static void * memBuffer1 = NULL;
|
|||||||
static void * memBuffer2 = NULL;
|
static void * memBuffer2 = NULL;
|
||||||
static void * memBuffer = NULL;
|
static void * memBuffer = NULL;
|
||||||
static int sdl_opengl = 0;
|
static int sdl_opengl = 0;
|
||||||
// We have one Java thread drawing on GL surface, and another native C thread (typically main()) feeding it with video data
|
|
||||||
extern SDL_Thread * SDL_mainThread;
|
|
||||||
SDL_Thread * SDL_mainThread = NULL;
|
|
||||||
// Some wicked multithreading
|
|
||||||
static SDL_mutex * WaitForNativeRender = NULL;
|
|
||||||
static SDL_cond * WaitForNativeRender1 = NULL;
|
|
||||||
static enum { Render_State_Started, Render_State_Processing, Render_State_Finished }
|
|
||||||
WaitForNativeRenderState = Render_State_Finished;
|
|
||||||
// Some wicked GLES stuff
|
// Some wicked GLES stuff
|
||||||
static enum { GL_State_Init, GL_State_Ready, GL_State_Uninit, GL_State_Uninit2 } openglInitialized = GL_State_Uninit2;
|
|
||||||
static GLuint texture = 0;
|
static GLuint texture = 0;
|
||||||
|
|
||||||
|
// Extremely wicked JNI environment to call Java functions from C code
|
||||||
|
static JNIEnv* JavaEnv = NULL;
|
||||||
|
static jclass JavaRendererClass = NULL;
|
||||||
|
static jobject JavaRenderer = NULL;
|
||||||
|
static jmethodID JavaSwapBuffers = NULL;
|
||||||
|
|
||||||
|
|
||||||
static SDLKey keymap[KEYCODE_LAST+1];
|
static SDLKey keymap[KEYCODE_LAST+1];
|
||||||
|
|
||||||
|
static int CallJavaSwapBuffers();
|
||||||
|
static void SdlGlRenderInit();
|
||||||
static int processAndroidTrackballKeyDelays( int key, int action );
|
static int processAndroidTrackballKeyDelays( int key, int action );
|
||||||
|
|
||||||
/* ANDROID driver bootstrap functions */
|
/* ANDROID driver bootstrap functions */
|
||||||
@@ -272,7 +272,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
|
|||||||
memX = width;
|
memX = width;
|
||||||
memY = height;
|
memY = height;
|
||||||
|
|
||||||
//if( ! sdl_opengl )
|
if( ! sdl_opengl )
|
||||||
{
|
{
|
||||||
memBuffer1 = SDL_malloc(memX * memY * (bpp / 8));
|
memBuffer1 = SDL_malloc(memX * memY * (bpp / 8));
|
||||||
if ( ! memBuffer1 ) {
|
if ( ! memBuffer1 ) {
|
||||||
@@ -295,8 +295,6 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
|
|||||||
memBuffer = memBuffer1;
|
memBuffer = memBuffer1;
|
||||||
}
|
}
|
||||||
|
|
||||||
openglInitialized = GL_State_Init;
|
|
||||||
|
|
||||||
/* Allocate the new pixel format for the screen */
|
/* Allocate the new pixel format for the screen */
|
||||||
if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
|
if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
|
||||||
if(memBuffer)
|
if(memBuffer)
|
||||||
@@ -313,15 +311,9 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
|
|||||||
current->h = height;
|
current->h = height;
|
||||||
current->pitch = memX * (bpp / 8);
|
current->pitch = memX * (bpp / 8);
|
||||||
current->pixels = memBuffer;
|
current->pixels = memBuffer;
|
||||||
|
|
||||||
if( ! WaitForNativeRender )
|
|
||||||
{
|
|
||||||
WaitForNativeRender = SDL_CreateMutex();
|
|
||||||
WaitForNativeRender1 = SDL_CreateCond();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait 'till we can draw */
|
SdlGlRenderInit();
|
||||||
ANDROID_FlipHWSurface(this, current);
|
|
||||||
/* We're done */
|
/* We're done */
|
||||||
return(current);
|
return(current);
|
||||||
}
|
}
|
||||||
@@ -331,9 +323,12 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
|
|||||||
*/
|
*/
|
||||||
void ANDROID_VideoQuit(_THIS)
|
void ANDROID_VideoQuit(_THIS)
|
||||||
{
|
{
|
||||||
openglInitialized = GL_State_Uninit;
|
if( ! sdl_opengl )
|
||||||
while( openglInitialized != GL_State_Uninit2 )
|
{
|
||||||
SDL_Delay(50);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glDeleteTextures(1, &texture);
|
||||||
|
}
|
||||||
|
|
||||||
memX = 0;
|
memX = 0;
|
||||||
memY = 0;
|
memY = 0;
|
||||||
@@ -343,10 +338,6 @@ void ANDROID_VideoQuit(_THIS)
|
|||||||
if( memBuffer2 )
|
if( memBuffer2 )
|
||||||
SDL_free( memBuffer2 );
|
SDL_free( memBuffer2 );
|
||||||
memBuffer2 = NULL;
|
memBuffer2 = NULL;
|
||||||
SDL_DestroyMutex( WaitForNativeRender );
|
|
||||||
WaitForNativeRender = NULL;
|
|
||||||
SDL_DestroyCond( WaitForNativeRender1 );
|
|
||||||
WaitForNativeRender1 = NULL;
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -397,37 +388,15 @@ static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
|
|||||||
|
|
||||||
static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface)
|
static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
if( ! WaitForNativeRender )
|
if( ! sdl_opengl )
|
||||||
{
|
{
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "libSDL", "FlipHWSurface: called before SetVideoMode");
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, memX, memY, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBuffer);
|
||||||
return 0;
|
if( sWindowHeight < memY || sWindowWidth < memX )
|
||||||
}
|
glDrawTexiOES(0, 0, 1, sWindowWidth, sWindowHeight); // Larger than screen - shrink to fit
|
||||||
SDL_mutexP(WaitForNativeRender);
|
else
|
||||||
while( WaitForNativeRenderState != Render_State_Finished )
|
glDrawTexiOES(0, sWindowHeight-memY, 1, memX, memY); // Smaller than screen - do not scale, it's faster that way
|
||||||
{
|
|
||||||
if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 5000 ) != 0 )
|
|
||||||
{
|
|
||||||
__android_log_print(ANDROID_LOG_INFO, "libSDL", "FlipHWSurface: Frame failed to render");
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WaitForNativeRenderState = Render_State_Started;
|
if( surface->flags & SDL_DOUBLEBUF )
|
||||||
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
|
||||||
SDL_CondSignal(WaitForNativeRender1);
|
|
||||||
SDL_mutexP(WaitForNativeRender);
|
|
||||||
|
|
||||||
if( WaitForNativeRenderState == Render_State_Started )
|
|
||||||
if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 5000 ) != 0 )
|
|
||||||
{
|
|
||||||
__android_log_print(ANDROID_LOG_INFO, "libSDL", "FlipHWSurface: Frame rendering timed out");
|
|
||||||
}
|
|
||||||
|
|
||||||
if( WaitForNativeRenderState != Render_State_Started )
|
|
||||||
{
|
|
||||||
if( ! sdl_opengl && surface && surface->flags & SDL_DOUBLEBUF )
|
|
||||||
{
|
{
|
||||||
if( memBuffer == memBuffer1 )
|
if( memBuffer == memBuffer1 )
|
||||||
memBuffer = memBuffer2;
|
memBuffer = memBuffer2;
|
||||||
@@ -437,9 +406,11 @@ static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
CallJavaSwapBuffers();
|
||||||
|
|
||||||
processAndroidTrackballKeyDelays( -1, 0 );
|
processAndroidTrackballKeyDelays( -1, 0 );
|
||||||
|
|
||||||
|
SDL_Delay(10);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
};
|
};
|
||||||
@@ -447,7 +418,6 @@ static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface)
|
|||||||
void ANDROID_GL_SwapBuffers(_THIS)
|
void ANDROID_GL_SwapBuffers(_THIS)
|
||||||
{
|
{
|
||||||
ANDROID_FlipHWSurface(this, NULL);
|
ANDROID_FlipHWSurface(this, NULL);
|
||||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "GL_SwapBuffers: Frame rendered");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int ANDROID_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
|
int ANDROID_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
|
||||||
@@ -476,14 +446,15 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeResize) ( JNIEnv* env, jobject thiz, jint
|
|||||||
extern void
|
extern void
|
||||||
JAVA_EXPORT_NAME(DemoRenderer_nativeDone) ( JNIEnv* env, jobject thiz )
|
JAVA_EXPORT_NAME(DemoRenderer_nativeDone) ( JNIEnv* env, jobject thiz )
|
||||||
{
|
{
|
||||||
if( SDL_mainThread )
|
__android_log_print(ANDROID_LOG_INFO, "libSDL", "quitting...");
|
||||||
{
|
SDL_PrivateQuit();
|
||||||
__android_log_print(ANDROID_LOG_INFO, "libSDL", "quitting...");
|
__android_log_print(ANDROID_LOG_INFO, "libSDL", "quit OK");
|
||||||
SDL_PrivateQuit();
|
}
|
||||||
SDL_WaitThread(SDL_mainThread, NULL);
|
|
||||||
SDL_mainThread = NULL;
|
extern void
|
||||||
__android_log_print(ANDROID_LOG_INFO, "libSDL", "quit OK");
|
JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobject thiz, jfloat accX, jfloat accY, jfloat accZ )
|
||||||
}
|
{
|
||||||
|
// TODO: use accelerometer as joystick
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 };
|
enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 };
|
||||||
@@ -518,78 +489,9 @@ static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
|
|||||||
return(keysym);
|
return(keysym);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AndroidTrackballKeyDelays[4] = {0,0,0,0};
|
|
||||||
|
|
||||||
// Key = -1 if we want to send KeyUp events from main loop
|
|
||||||
static int processAndroidTrackballKeyDelays( int key, int action )
|
|
||||||
{
|
|
||||||
#if ! defined(SDL_TRACKBALL_KEYUP_DELAY) || (SDL_TRACKBALL_KEYUP_DELAY == 0)
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
// Send Directional Pad Up events with a delay, so app wil lthink we're holding the key a bit
|
|
||||||
static const int KeysMapping[4] = {KEYCODE_DPAD_UP, KEYCODE_DPAD_DOWN, KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT};
|
|
||||||
int idx, idx2;
|
|
||||||
SDL_keysym keysym;
|
|
||||||
|
|
||||||
if( key < 0 )
|
|
||||||
{
|
|
||||||
for( idx = 0; idx < 4; idx ++ )
|
|
||||||
{
|
|
||||||
if( AndroidTrackballKeyDelays[idx] > 0 )
|
|
||||||
{
|
|
||||||
AndroidTrackballKeyDelays[idx] --;
|
|
||||||
if( AndroidTrackballKeyDelays[idx] == 0 )
|
|
||||||
SDL_PrivateKeyboard( SDL_RELEASED, TranslateKey(KeysMapping[idx], &keysym) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
idx = -1;
|
|
||||||
// Too lazy to do switch or function
|
|
||||||
if( key == KEYCODE_DPAD_UP )
|
|
||||||
idx = 0;
|
|
||||||
else if( key == KEYCODE_DPAD_DOWN )
|
|
||||||
idx = 1;
|
|
||||||
else if( key == KEYCODE_DPAD_LEFT )
|
|
||||||
idx = 2;
|
|
||||||
else if( key == KEYCODE_DPAD_RIGHT )
|
|
||||||
idx = 3;
|
|
||||||
if( idx >= 0 )
|
|
||||||
{
|
|
||||||
if( action && AndroidTrackballKeyDelays[idx] == 0 )
|
|
||||||
{
|
|
||||||
// User pressed key for the first time
|
|
||||||
idx2 = (idx + 2) % 4; // Opposite key for current key - if it's still pressing, release it
|
|
||||||
if( AndroidTrackballKeyDelays[idx2] > 0 )
|
|
||||||
{
|
|
||||||
AndroidTrackballKeyDelays[idx2] = 0;
|
|
||||||
SDL_PrivateKeyboard( SDL_RELEASED, TranslateKey(KeysMapping[idx2], &keysym) );
|
|
||||||
}
|
|
||||||
SDL_PrivateKeyboard( SDL_PRESSED, TranslateKey(key, &keysym) );
|
|
||||||
}
|
|
||||||
else if( !action && AndroidTrackballKeyDelays[idx] == 0 )
|
|
||||||
{
|
|
||||||
// User released key - make a delay, do not send release event
|
|
||||||
AndroidTrackballKeyDelays[idx] = SDL_TRACKBALL_KEYUP_DELAY;
|
|
||||||
}
|
|
||||||
else if( action && AndroidTrackballKeyDelays[idx] > 0 )
|
|
||||||
{
|
|
||||||
// User pressed key another time - add some more time for key to be pressed
|
|
||||||
AndroidTrackballKeyDelays[idx] += SDL_TRACKBALL_KEYUP_DELAY;
|
|
||||||
if( AndroidTrackballKeyDelays[idx] < SDL_TRACKBALL_KEYUP_DELAY * 4 )
|
|
||||||
AndroidTrackballKeyDelays[idx] = SDL_TRACKBALL_KEYUP_DELAY * 4;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint key, jint action )
|
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint key, jint action )
|
||||||
{
|
{
|
||||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "key event %i %s", key, action ? "down" : "up");
|
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "key event %i %s", key, action ? "down" : "up");
|
||||||
SDL_keysym keysym;
|
SDL_keysym keysym;
|
||||||
@@ -597,9 +499,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jin
|
|||||||
SDL_PrivateKeyboard( action ? SDL_PRESSED : SDL_RELEASED, TranslateKey(key, &keysym) );
|
SDL_PrivateKeyboard( action ? SDL_PRESSED : SDL_RELEASED, TranslateKey(key, &keysym) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// The most wicked routine out there, all wicked multithreading and GL-ES stuff here
|
void SdlGlRenderInit()
|
||||||
extern void
|
|
||||||
JAVA_EXPORT_NAME(DemoRenderer_nativeRender) ( JNIEnv* env, jobject thiz, jfloat accX, jfloat accY, jfloat accZ )
|
|
||||||
{
|
{
|
||||||
// Set up an array of values to use as the sprite vertices.
|
// Set up an array of values to use as the sprite vertices.
|
||||||
static GLfloat vertices[] =
|
static GLfloat vertices[] =
|
||||||
@@ -629,12 +529,8 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeRender) ( JNIEnv* env, jobject thiz, jfloa
|
|||||||
int textX, textY;
|
int textX, textY;
|
||||||
void * memBufferTemp;
|
void * memBufferTemp;
|
||||||
|
|
||||||
if( !sdl_opengl && memBuffer && openglInitialized != GL_State_Uninit2 )
|
if( !sdl_opengl && memBuffer )
|
||||||
{
|
{
|
||||||
if( openglInitialized == GL_State_Init )
|
|
||||||
{
|
|
||||||
openglInitialized = GL_State_Ready;
|
|
||||||
|
|
||||||
// Texture sizes should be 2^n
|
// Texture sizes should be 2^n
|
||||||
textX = memX;
|
textX = memX;
|
||||||
textY = memY;
|
textY = memY;
|
||||||
@@ -714,122 +610,24 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeRender) ( JNIEnv* env, jobject thiz, jfloa
|
|||||||
glFinish();
|
glFinish();
|
||||||
|
|
||||||
SDL_free( textBuffer );
|
SDL_free( textBuffer );
|
||||||
|
|
||||||
}
|
|
||||||
else if( openglInitialized == GL_State_Uninit )
|
|
||||||
{
|
|
||||||
openglInitialized = GL_State_Uninit2;
|
|
||||||
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
|
||||||
|
|
||||||
glDeleteTextures(1, &texture);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( WaitForNativeRender )
|
|
||||||
{
|
|
||||||
SDL_mutexP(WaitForNativeRender);
|
|
||||||
|
|
||||||
WaitForNativeRenderState = Render_State_Finished;
|
|
||||||
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
|
||||||
SDL_CondSignal(WaitForNativeRender1);
|
|
||||||
SDL_mutexP(WaitForNativeRender);
|
|
||||||
|
|
||||||
while( WaitForNativeRenderState != Render_State_Started )
|
|
||||||
{
|
|
||||||
if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 5000 ) != 0 )
|
|
||||||
{
|
|
||||||
__android_log_print(ANDROID_LOG_INFO, "libSDL", "nativeRender: Frame failed to render");
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memBufferTemp = memBuffer;
|
|
||||||
|
|
||||||
WaitForNativeRenderState = Render_State_Processing;
|
|
||||||
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
|
||||||
|
|
||||||
SDL_CondSignal(WaitForNativeRender1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
memBufferTemp = memBuffer;
|
|
||||||
|
|
||||||
// TODO: use accelerometer as joystick
|
|
||||||
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, memX, memY, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBufferTemp);
|
|
||||||
if( sWindowHeight < memY || sWindowWidth < memX )
|
|
||||||
glDrawTexiOES(0, 0, 1, sWindowWidth, sWindowHeight); // Larger than screen - shrink to fit
|
|
||||||
else
|
|
||||||
glDrawTexiOES(0, sWindowHeight-memY, 1, memX, memY); // Smaller than screen - do not scale, it's faster that way
|
|
||||||
|
|
||||||
//glFinish(); //glFlush();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if( sdl_opengl && openglInitialized != GL_State_Uninit2 )
|
}
|
||||||
{
|
|
||||||
if( openglInitialized == GL_State_Init )
|
|
||||||
{
|
|
||||||
openglInitialized = GL_State_Ready;
|
|
||||||
|
|
||||||
glViewport(0, 0, memX, memY);
|
|
||||||
|
|
||||||
glClearColor(0,0,0,0);
|
void
|
||||||
}
|
JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject thiz )
|
||||||
else if( openglInitialized == GL_State_Uninit )
|
{
|
||||||
{
|
char classPath[1024];
|
||||||
openglInitialized = GL_State_Uninit2;
|
JavaEnv = env;
|
||||||
return;
|
JavaRenderer = thiz;
|
||||||
}
|
|
||||||
|
JavaRendererClass = (*JavaEnv)->GetObjectClass(JavaEnv, thiz);
|
||||||
if( WaitForNativeRender )
|
JavaSwapBuffers = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "swapBuffers", "()I");
|
||||||
{
|
}
|
||||||
SDL_mutexP(WaitForNativeRender);
|
|
||||||
|
|
||||||
WaitForNativeRenderState = Render_State_Finished;
|
|
||||||
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
int CallJavaSwapBuffers()
|
||||||
SDL_CondSignal(WaitForNativeRender1);
|
{
|
||||||
SDL_mutexP(WaitForNativeRender);
|
return (*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaSwapBuffers );
|
||||||
|
|
||||||
while( WaitForNativeRenderState != Render_State_Started )
|
|
||||||
{
|
|
||||||
if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 5000 ) != 0 )
|
|
||||||
{
|
|
||||||
__android_log_print(ANDROID_LOG_INFO, "libSDL", "nativeRender: Frame failed to render");
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "nativeRender: Frame rendered");
|
|
||||||
|
|
||||||
WaitForNativeRenderState = Render_State_Processing;
|
|
||||||
|
|
||||||
SDL_mutexV(WaitForNativeRender);
|
|
||||||
|
|
||||||
SDL_CondSignal(WaitForNativeRender1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
// Flash the screen
|
|
||||||
if( clearColor >= 1.0f )
|
|
||||||
clearColorDir = -1;
|
|
||||||
else if( clearColor <= 0.0f )
|
|
||||||
clearColorDir = 1;
|
|
||||||
|
|
||||||
clearColor += (float)clearColorDir * 0.01f;
|
|
||||||
glClearColor(clearColor,clearColor,clearColor,0);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
SDL_Delay(50);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANDROID_InitOSKeymap(_THIS)
|
void ANDROID_InitOSKeymap(_THIS)
|
||||||
@@ -953,3 +751,72 @@ void ANDROID_InitOSKeymap(_THIS)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int AndroidTrackballKeyDelays[4] = {0,0,0,0};
|
||||||
|
|
||||||
|
// Key = -1 if we want to send KeyUp events from main loop
|
||||||
|
int processAndroidTrackballKeyDelays( int key, int action )
|
||||||
|
{
|
||||||
|
#if ! defined(SDL_TRACKBALL_KEYUP_DELAY) || (SDL_TRACKBALL_KEYUP_DELAY == 0)
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
// Send Directional Pad Up events with a delay, so app wil lthink we're holding the key a bit
|
||||||
|
static const int KeysMapping[4] = {KEYCODE_DPAD_UP, KEYCODE_DPAD_DOWN, KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT};
|
||||||
|
int idx, idx2;
|
||||||
|
SDL_keysym keysym;
|
||||||
|
|
||||||
|
if( key < 0 )
|
||||||
|
{
|
||||||
|
for( idx = 0; idx < 4; idx ++ )
|
||||||
|
{
|
||||||
|
if( AndroidTrackballKeyDelays[idx] > 0 )
|
||||||
|
{
|
||||||
|
AndroidTrackballKeyDelays[idx] --;
|
||||||
|
if( AndroidTrackballKeyDelays[idx] == 0 )
|
||||||
|
SDL_PrivateKeyboard( SDL_RELEASED, TranslateKey(KeysMapping[idx], &keysym) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
idx = -1;
|
||||||
|
// Too lazy to do switch or function
|
||||||
|
if( key == KEYCODE_DPAD_UP )
|
||||||
|
idx = 0;
|
||||||
|
else if( key == KEYCODE_DPAD_DOWN )
|
||||||
|
idx = 1;
|
||||||
|
else if( key == KEYCODE_DPAD_LEFT )
|
||||||
|
idx = 2;
|
||||||
|
else if( key == KEYCODE_DPAD_RIGHT )
|
||||||
|
idx = 3;
|
||||||
|
if( idx >= 0 )
|
||||||
|
{
|
||||||
|
if( action && AndroidTrackballKeyDelays[idx] == 0 )
|
||||||
|
{
|
||||||
|
// User pressed key for the first time
|
||||||
|
idx2 = (idx + 2) % 4; // Opposite key for current key - if it's still pressing, release it
|
||||||
|
if( AndroidTrackballKeyDelays[idx2] > 0 )
|
||||||
|
{
|
||||||
|
AndroidTrackballKeyDelays[idx2] = 0;
|
||||||
|
SDL_PrivateKeyboard( SDL_RELEASED, TranslateKey(KeysMapping[idx2], &keysym) );
|
||||||
|
}
|
||||||
|
SDL_PrivateKeyboard( SDL_PRESSED, TranslateKey(key, &keysym) );
|
||||||
|
}
|
||||||
|
else if( !action && AndroidTrackballKeyDelays[idx] == 0 )
|
||||||
|
{
|
||||||
|
// User released key - make a delay, do not send release event
|
||||||
|
AndroidTrackballKeyDelays[idx] = SDL_TRACKBALL_KEYUP_DELAY;
|
||||||
|
}
|
||||||
|
else if( action && AndroidTrackballKeyDelays[idx] > 0 )
|
||||||
|
{
|
||||||
|
// User pressed key another time - add some more time for key to be pressed
|
||||||
|
AndroidTrackballKeyDelays[idx] += SDL_TRACKBALL_KEYUP_DELAY;
|
||||||
|
if( AndroidTrackballKeyDelays[idx] < SDL_TRACKBALL_KEYUP_DELAY * 4 )
|
||||||
|
AndroidTrackballKeyDelays[idx] = SDL_TRACKBALL_KEYUP_DELAY * 4;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,15 +15,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
extern C_LINKAGE int main( int argc, char ** argv );
|
|
||||||
static int SDLCALL MainThreadWrapper(void * dummy)
|
|
||||||
{
|
|
||||||
int argc = 1;
|
|
||||||
char * argv[] = { "sdl" };
|
|
||||||
chdir(SDL_CURDIR_PATH);
|
|
||||||
return main( argc, argv );
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef SDL_JAVA_PACKAGE_PATH
|
#ifndef SDL_JAVA_PACKAGE_PATH
|
||||||
#error You have to define SDL_JAVA_PACKAGE_PATH to your package path with dots replaced with underscores, for example "com_example_SanAngeles"
|
#error You have to define SDL_JAVA_PACKAGE_PATH to your package path with dots replaced with underscores, for example "com_example_SanAngeles"
|
||||||
#endif
|
#endif
|
||||||
@@ -31,13 +22,14 @@ static int SDLCALL MainThreadWrapper(void * dummy)
|
|||||||
#define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package)
|
#define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package)
|
||||||
#define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH)
|
#define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH)
|
||||||
|
|
||||||
extern C_LINKAGE SDL_Thread * SDL_mainThread;
|
|
||||||
|
|
||||||
extern C_LINKAGE void
|
extern C_LINKAGE void
|
||||||
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz )
|
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz )
|
||||||
{
|
{
|
||||||
SDL_mainThread = SDL_CreateThread( MainThreadWrapper, NULL );
|
int argc = 1;
|
||||||
}
|
char * argv[] = { "sdl" };
|
||||||
|
chdir(SDL_CURDIR_PATH);
|
||||||
|
main( argc, argv );
|
||||||
|
};
|
||||||
|
|
||||||
#undef JAVA_EXPORT_NAME
|
#undef JAVA_EXPORT_NAME
|
||||||
#undef JAVA_EXPORT_NAME1
|
#undef JAVA_EXPORT_NAME1
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
|
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
|
||||||
package de.schwardtnet.alienblaster;
|
package de.schwardtnet.alienblaster;
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
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.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
@@ -65,22 +71,31 @@ class AccelerometerReader implements SensorListener {
|
|||||||
private long timekeeper;
|
private long timekeeper;
|
||||||
|
|
||||||
private float [] v;
|
private float [] v;
|
||||||
|
|
||||||
|
private SensorManager _manager = null;
|
||||||
|
|
||||||
public AccelerometerReader(Activity context) {
|
public AccelerometerReader(Activity context) {
|
||||||
v = new float[3];
|
v = new float[3];
|
||||||
SensorManager sma = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
_manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||||
if( sma != null )
|
if( _manager != null )
|
||||||
{
|
{
|
||||||
timekeeper = android.os.SystemClock.uptimeMillis();
|
timekeeper = android.os.SystemClock.uptimeMillis();
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
mask |= SensorManager.SENSOR_ORIENTATION;
|
//mask |= SensorManager.SENSOR_ORIENTATION;
|
||||||
mask |= SensorManager.SENSOR_ACCELEROMETER;
|
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) {
|
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();
|
timekeeper = android.os.SystemClock.uptimeMillis();
|
||||||
|
|
||||||
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
|
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
|
||||||
@@ -90,8 +105,9 @@ class AccelerometerReader implements SensorListener {
|
|||||||
v[1] = values[1];
|
v[1] = values[1];
|
||||||
if( values.length >= 3 )
|
if( values.length >= 3 )
|
||||||
v[2] = values[2];
|
v[2] = values[2];
|
||||||
|
nativeAccelerometer(v[0], v[1], v[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void onAccuracyChanged(int i, int i1) {
|
public synchronized void onAccuracyChanged(int i, int i1) {
|
||||||
@@ -106,15 +122,16 @@ class AccelerometerReader implements SensorListener {
|
|||||||
ret[2] = v[2];
|
ret[2] = v[2];
|
||||||
return ret;
|
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)
|
public DemoRenderer(Activity _context)
|
||||||
{
|
{
|
||||||
super();
|
|
||||||
context = _context;
|
context = _context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,30 +145,43 @@ class DemoRenderer implements GLSurfaceView.Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onDrawFrame(GL10 gl) {
|
public void onDrawFrame(GL10 gl) {
|
||||||
if( accelerometer == null) {
|
|
||||||
accelerometer = new AccelerometerReader(context);
|
nativeInitJavaCallbacks();
|
||||||
nativeInit();
|
|
||||||
}
|
nativeInit(); // Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code
|
||||||
float [] f = accelerometer.readAccelerometer();
|
|
||||||
nativeRender(f[0], f[1], f[2]);
|
}
|
||||||
|
|
||||||
|
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() {
|
public void exitApp() {
|
||||||
nativeDone();
|
nativeDone();
|
||||||
};
|
};
|
||||||
|
|
||||||
private static native void nativeInit();
|
private native void nativeInitJavaCallbacks();
|
||||||
private static native void nativeResize(int w, int h);
|
private native void nativeInit();
|
||||||
private static native void nativeRender(float accX, float accY, float accZ);
|
private native void nativeResize(int w, int h);
|
||||||
private static native void nativeDone();
|
private native void nativeDone();
|
||||||
private AccelerometerReader accelerometer = null;
|
|
||||||
private Activity context = null;
|
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) {
|
public DemoGLSurfaceView(Activity context) {
|
||||||
super(context);
|
super(context);
|
||||||
mParent = context;
|
mParent = context;
|
||||||
|
accelerometer = new AccelerometerReader(context);
|
||||||
mRenderer = new DemoRenderer(context);
|
mRenderer = new DemoRenderer(context);
|
||||||
setRenderer(mRenderer);
|
setRenderer(mRenderer);
|
||||||
}
|
}
|
||||||
@@ -175,6 +205,8 @@ class DemoGLSurfaceView extends GLSurfaceView {
|
|||||||
|
|
||||||
public void exitApp() {
|
public void exitApp() {
|
||||||
mRenderer.exitApp();
|
mRenderer.exitApp();
|
||||||
|
accelerometer.stop();
|
||||||
|
accelerometer = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -191,9 +223,10 @@ class DemoGLSurfaceView extends GLSurfaceView {
|
|||||||
|
|
||||||
DemoRenderer mRenderer;
|
DemoRenderer mRenderer;
|
||||||
Activity mParent;
|
Activity mParent;
|
||||||
|
AccelerometerReader accelerometer = null;
|
||||||
|
|
||||||
public static native void nativeMouse( int x, int y, int action );
|
public native void nativeMouse( int x, int y, int action );
|
||||||
public static native void nativeKey( int keyCode, int down );
|
public native void nativeKey( int keyCode, int down );
|
||||||
}
|
}
|
||||||
|
|
||||||
class AudioThread extends Thread {
|
class AudioThread extends Thread {
|
||||||
@@ -267,10 +300,10 @@ class AudioThread extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native int[] nativeAudioInit();
|
private native int[] nativeAudioInit();
|
||||||
private static native int nativeAudioInit2(byte[] buf);
|
private native int nativeAudioInit2(byte[] buf);
|
||||||
private static native int nativeAudioBufferLock();
|
private native int nativeAudioBufferLock();
|
||||||
private static native int nativeAudioBufferUnlock();
|
private native int nativeAudioBufferUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1355
alienblaster/project/src/GLSurfaceView_SDL.java
Normal file
1355
alienblaster/project/src/GLSurfaceView_SDL.java
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user