From 8fce28ca722d01feab030700d7f7eac4093c5651 Mon Sep 17 00:00:00 2001 From: pelya Date: Mon, 14 Mar 2011 19:09:41 +0200 Subject: [PATCH] Fixed non-blocking SwapBuffers --- project/java/Video.java | 6 +- .../ballfield/AndroidAppSettings.cfg | 2 +- .../jni/application/ballfield/ballfield.cpp | 55 ++++++++++++------- project/jni/application/src | 2 +- readme.txt | 11 ++-- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/project/java/Video.java b/project/java/Video.java index cfbc517bf..853185c84 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -182,8 +182,9 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { } public void onSurfaceCreated(GL10 gl, EGLConfig config) { + System.out.println("libSDL: DemoRenderer.onSurfaceCreated(): paused " + mPaused + " mFirstTimeStart " + mFirstTimeStart ); mGlSurfaceCreated = true; - if( mGlSurfaceCreated && ! mPaused && ! mFirstTimeStart ) + if( ! mPaused && ! mFirstTimeStart ) nativeGlContextRecreated(); mFirstTimeStart = false; } @@ -341,7 +342,8 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { public void onResume() { super.onResume(); mRenderer.mPaused = false; - if( mRenderer.mGlSurfaceCreated && ! mRenderer.mPaused ) + System.out.println("libSDL: DemoGLSurfaceView.onResume(): mRenderer.mGlSurfaceCreated " + mRenderer.mGlSurfaceCreated + " mRenderer.mPaused " + mRenderer.mPaused); + if( mRenderer.mGlSurfaceCreated && ! mRenderer.mPaused || Globals.NonBlockingSwapBuffers ) mRenderer.nativeGlContextRecreated(); }; diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index a61f74995..6f96df13f 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -17,7 +17,7 @@ AppNeedsTextInput=y AppUsesJoystick=n AppHandlesJoystickSensitivity=n AppUsesMultitouch=n -NonBlockingSwapBuffers=n +NonBlockingSwapBuffers=y RedefinedKeys="SPACE" AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmountAutoFire=0 diff --git a/project/jni/application/ballfield/ballfield.cpp b/project/jni/application/ballfield/ballfield.cpp index 32a12fe0b..d87fd2862 100644 --- a/project/jni/application/ballfield/ballfield.cpp +++ b/project/jni/application/ballfield/ballfield.cpp @@ -456,24 +456,6 @@ int main(int argc, char* argv[]) while(1) { SDL_Rect r; - if(SDL_PollEvent(&event) > 0) - { - if(event.type & (SDL_KEYUP | SDL_KEYDOWN)) - { - Uint8 *keys = SDL_GetKeyState(&i); - if(keys[SDLK_ESCAPE]) - break; - __android_log_print(ANDROID_LOG_INFO, "Ballfield", "SDL key event: state %d key %d mod %d unicode %d", event.key.state, (int)event.key.keysym.sym, (int)event.key.keysym.mod, (int)event.key.keysym.unicode); - } - if(event.type & SDL_VIDEORESIZE) - { - __android_log_print(ANDROID_LOG_INFO, "Ballfield", "SDL resize event: %d x %d", event.resize.w, event.resize.h); - } - if(event.type & SDL_ACTIVEEVENT) - { - __android_log_print(ANDROID_LOG_INFO, "Ballfield", "SDL active event: gain %d", event.active.gain); - } - } /* Timing */ tick = SDL_GetTicks(); @@ -523,7 +505,42 @@ int main(int argc, char* argv[]) SDL_FillRect(screen, &r, 0x67895566); } - SDL_Flip(screen); + SDL_Flip(SDL_GetVideoSurface()); + SDL_Event evt; + while( SDL_PollEvent(&evt) ) + { + if(evt.type == (SDL_KEYUP | SDL_KEYDOWN)) + { + Uint8 *keys = SDL_GetKeyState(&i); + if(keys[SDLK_ESCAPE]) + break; + __android_log_print(ANDROID_LOG_INFO, "Ballfield", "SDL key event: state %d key %d mod %d unicode %d", evt.key.state, (int)evt.key.keysym.sym, (int)evt.key.keysym.mod, (int)evt.key.keysym.unicode); + } + if(evt.type == SDL_VIDEORESIZE) + __android_log_print(ANDROID_LOG_INFO, "Ballfield", "SDL resize event: %d x %d", evt.resize.w, evt.resize.h); + if(evt.type == SDL_ACTIVEEVENT) + __android_log_print(ANDROID_LOG_INFO, "Ballfield", "======= SDL active event: gain %d state %d", evt.active.gain, evt.active.state); + if( evt.type == SDL_ACTIVEEVENT && evt.active.gain == 0 && evt.active.state & SDL_APPACTIVE ) + { + // We've lost GL context, we are not allowed to do any GFX output here, or app will crash! + while( 1 ) + { + SDL_PollEvent(&evt); + if( evt.type == SDL_ACTIVEEVENT && evt.active.gain && evt.active.state & SDL_APPACTIVE ) + { + __android_log_print(ANDROID_LOG_INFO, "Ballfield", "======= SDL active event: gain %d state %d", evt.active.gain, evt.active.state); + SDL_Flip(SDL_GetVideoSurface()); // One SDL_Flip() call is required here to restore OpenGL context + // Re-load all textures, matrixes and all other GL states if we're in SDL+OpenGL mode + // Re-load all images to SDL_Texture if we're using it + // Now we can draw + break; + } + // Process network stuff, maybe play some sounds using SDL_ANDROID_PauseAudioPlayback() / SDL_ANDROID_ResumeAudioPlayback() + SDL_Delay(300); + __android_log_print(ANDROID_LOG_INFO, "Ballfield", "Waiting"); + } + } + } /* Animate */ x_speed = 500.0 * sin(t * 0.37); diff --git a/project/jni/application/src b/project/jni/application/src index 299033683..104f796a6 120000 --- a/project/jni/application/src +++ b/project/jni/application/src @@ -1 +1 @@ -teeworlds \ No newline at end of file +ballfield \ No newline at end of file diff --git a/readme.txt b/readme.txt index 68ca345b6..ab5dfd175 100644 --- a/readme.txt +++ b/readme.txt @@ -239,27 +239,26 @@ between appPutToBackground() and appRestored() and update game time variables. Alternatively, you may enable option for unblocked SDL_Flip() in ChangeAppSettings script, then you'll have to implement special event loop right after each SDL_Flip() call: -SDL_Flip(); +SDL_Flip(SDL_GetVideoSurface()); SDL_Event evt; while( SDL_PollEvent(&evt) ) { - if( evt.type == SDL_ACTIVEEVENT && evt.active.gain == 0 && evt.active.state == SDL_APPACTIVE ) + if( evt.type == SDL_ACTIVEEVENT && evt.active.gain == 0 && evt.active.state & SDL_APPACTIVE ) { // We've lost GL context, we are not allowed to do any GFX output here, or app will crash! while( 1 ) { SDL_PollEvent(&evt); - if( evt.type == SDL_ACTIVEEVENT->SDL_APPACTIVE && evt.active.gain && evt.active.state == SDL_APPACTIVE ) + if( evt.type == SDL_ACTIVEEVENT && evt.active.gain && evt.active.state & SDL_APPACTIVE ) { - SDL_Flip(); // One SDL_Flip() call is required here to restore OpenGL context + SDL_Flip(SDL_GetVideoSurface()); // One SDL_Flip() call is required here to restore OpenGL context // Re-load all textures, matrixes and all other GL states if we're in SDL+OpenGL mode // Re-load all images to SDL_Texture if we're using it // Now we can draw break; } - // Process network stuff, maybe play some sounds using SDL_ANDROID_PauseAudioPlayback() / SDL_ANDROID_ResumeAudioPlayback() - SDL_Sleep(200); + SDL_Delay(300); } } }