Implemented SDL_ACTIVEEVENT, did not test it and cannot say if it will work, also SDL 1.3 compilation is broken (use previous commit)

This commit is contained in:
pelya
2010-10-01 19:15:23 +03:00
parent 631f4cde0d
commit b83c805bb7
19 changed files with 88 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
CHANGE_APP_SETTINGS_VERSION=8 CHANGE_APP_SETTINGS_VERSION=9
AUTO= AUTO=
if [ "X$1" = "X-a" ]; then if [ "X$1" = "X-a" ]; then
@@ -104,6 +104,14 @@ if [ -n "$var" ] ; then
AppUsesMultitouch="$var" AppUsesMultitouch="$var"
fi fi
echo -n "\nApplication implements Android-specific routines to put to background, and will not draw anything to screen\n"
echo -n "between SDL_ACTIVEEVENT->SDL_APPACTIVE lost / gained notifications - you should check for them\n"
echo -n "rigth after SDL_Flip(), if (n) then SDL_Flip() will block till app in background (y) or (n) ($NonBlockingSwapBuffers): "
read var
if [ -n "$var" ] ; then
NonBlockingSwapBuffers="$var"
fi
echo -n "\nRedefine common keys to SDL keysyms: TOUCHSCREEN SEARCH/CALL/DPAD_CENTER VOLUMEUP VOLUMEDOWN MENU BACK CAMERA ENTER DEL" echo -n "\nRedefine common keys to SDL keysyms: TOUCHSCREEN SEARCH/CALL/DPAD_CENTER VOLUMEUP VOLUMEDOWN MENU BACK CAMERA ENTER DEL"
echo -n "\nMENU and BACK hardware keys and TOUCHSCREEN virtual 'key' are available on all devices, other keys may be absent" echo -n "\nMENU and BACK hardware keys and TOUCHSCREEN virtual 'key' are available on all devices, other keys may be absent"
echo -n "\nThe same key values are used if touchscreen keyboard is enabled, except for MENU and BACK\n($RedefinedKeys)\n: " echo -n "\nThe same key values are used if touchscreen keyboard is enabled, except for MENU and BACK\n($RedefinedKeys)\n: "
@@ -211,6 +219,7 @@ echo AppUsesMouse=$AppUsesMouse >> AndroidAppSettings.cfg
echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AndroidAppSettings.cfg echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AndroidAppSettings.cfg
echo AppUsesJoystick=$AppUsesJoystick >> AndroidAppSettings.cfg echo AppUsesJoystick=$AppUsesJoystick >> AndroidAppSettings.cfg
echo AppUsesMultitouch=$AppUsesMultitouch >> AndroidAppSettings.cfg echo AppUsesMultitouch=$AppUsesMultitouch >> AndroidAppSettings.cfg
echo NonBlockingSwapBuffers=$NonBlockingSwapBuffers >> AndroidAppSettings.cfg
echo RedefinedKeys=\"$RedefinedKeys\" >> AndroidAppSettings.cfg echo RedefinedKeys=\"$RedefinedKeys\" >> AndroidAppSettings.cfg
echo AppTouchscreenKeyboardKeysAmount=$AppTouchscreenKeyboardKeysAmount >> AndroidAppSettings.cfg echo AppTouchscreenKeyboardKeysAmount=$AppTouchscreenKeyboardKeysAmount >> AndroidAppSettings.cfg
echo AppTouchscreenKeyboardKeysAmountAutoFire=$AppTouchscreenKeyboardKeysAmountAutoFire >> AndroidAppSettings.cfg echo AppTouchscreenKeyboardKeysAmountAutoFire=$AppTouchscreenKeyboardKeysAmountAutoFire >> AndroidAppSettings.cfg
@@ -270,6 +279,12 @@ else
AppUsesMultitouch=false AppUsesMultitouch=false
fi fi
if [ "$NonBlockingSwapBuffers" = "y" ] ; then
NonBlockingSwapBuffers=true
else
NonBlockingSwapBuffers=false
fi
RedefinedKeycodes="-DSDL_ANDROID_KEYCODE_MOUSE=$MouseKeycode" RedefinedKeycodes="-DSDL_ANDROID_KEYCODE_MOUSE=$MouseKeycode"
KEY2=0 KEY2=0
for KEY in $RedefinedKeys; do for KEY in $RedefinedKeys; do
@@ -326,6 +341,7 @@ cat project/src/Globals.java | \
sed "s/public static boolean AppNeedsArrowKeys = .*;/public static boolean AppNeedsArrowKeys = $AppNeedsArrowKeys;/" | \ sed "s/public static boolean AppNeedsArrowKeys = .*;/public static boolean AppNeedsArrowKeys = $AppNeedsArrowKeys;/" | \
sed "s/public static boolean AppUsesJoystick = .*;/public static boolean AppUsesJoystick = $AppUsesJoystick;/" | \ sed "s/public static boolean AppUsesJoystick = .*;/public static boolean AppUsesJoystick = $AppUsesJoystick;/" | \
sed "s/public static boolean AppUsesMultitouch = .*;/public static boolean AppUsesMultitouch = $AppUsesMultitouch;/" | \ sed "s/public static boolean AppUsesMultitouch = .*;/public static boolean AppUsesMultitouch = $AppUsesMultitouch;/" | \
sed "s/public static boolean NonBlockingSwapBuffers = .*;/public static boolean NonBlockingSwapBuffers = $NonBlockingSwapBuffers;/" | \
sed "s/public static int AppTouchscreenKeyboardKeysAmount = .*;/public static int AppTouchscreenKeyboardKeysAmount = $AppTouchscreenKeyboardKeysAmount;/" | \ sed "s/public static int AppTouchscreenKeyboardKeysAmount = .*;/public static int AppTouchscreenKeyboardKeysAmount = $AppTouchscreenKeyboardKeysAmount;/" | \
sed "s/public static int AppTouchscreenKeyboardKeysAmountAutoFire = .*;/public static int AppTouchscreenKeyboardKeysAmountAutoFire = $AppTouchscreenKeyboardKeysAmountAutoFire;/" | \ sed "s/public static int AppTouchscreenKeyboardKeysAmountAutoFire = .*;/public static int AppTouchscreenKeyboardKeysAmountAutoFire = $AppTouchscreenKeyboardKeysAmountAutoFire;/" | \
sed "s%public static String ReadmeText = .*%public static String ReadmeText = \"$ReadmeText\".replace(\"^\",\"\\\n\");%" | \ sed "s%public static String ReadmeText = .*%public static String ReadmeText = \"$ReadmeText\".replace(\"^\",\"\\\n\");%" | \

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.schwardtnet.alienblaster" package="com.googlecode.opentyrian"
android:versionCode="110010" android:versionCode="2114"
android:versionName="1.1.0.10 - fixed restoring application from background" android:versionName="2.1.14 - game can be put to background with Home button and successfully restored back"
android:installLocation="preferExternal" android:installLocation="preferExternal"
> >
<application android:label="@string/app_name" <application android:label="@string/app_name"

View File

@@ -1,6 +1,6 @@
# The namespace in Java file, with dots replaced with underscores # The namespace in Java file, with dots replaced with underscores
SDL_JAVA_PACKAGE_PATH := de_schwardtnet_alienblaster SDL_JAVA_PACKAGE_PATH := com_googlecode_opentyrian
# Path to shared libraries - Android 1.6 cannot load them properly, thus we have to specify absolute path here # Path to shared libraries - Android 1.6 cannot load them properly, thus we have to specify absolute path here
# SDL_SHARED_LIBRARIES_PATH := /data/data/de.schwardtnet.alienblaster/lib # SDL_SHARED_LIBRARIES_PATH := /data/data/de.schwardtnet.alienblaster/lib
@@ -10,7 +10,7 @@ SDL_JAVA_PACKAGE_PATH := de_schwardtnet_alienblaster
# Typically /sdcard/alienblaster # Typically /sdcard/alienblaster
# Or /data/data/de.schwardtnet.alienblaster/files if you're planning to unpack data in application private folder # Or /data/data/de.schwardtnet.alienblaster/files if you're planning to unpack data in application private folder
# Your application will just set current directory there # Your application will just set current directory there
SDL_CURDIR_PATH := de.schwardtnet.alienblaster SDL_CURDIR_PATH := com.googlecode.opentyrian
# Android Dev Phone G1 has trackball instead of cursor keys, and # Android Dev Phone G1 has trackball instead of cursor keys, and
# sends trackball movement events as rapid KeyDown/KeyUp events, # sends trackball movement events as rapid KeyDown/KeyUp events,
@@ -23,7 +23,7 @@ SDL_TRACKBALL_KEYUP_DELAY := 1
# resized in HW-accelerated way, however it eats a tiny bit of CPU # resized in HW-accelerated way, however it eats a tiny bit of CPU
SDL_VIDEO_RENDER_RESIZE := 1 SDL_VIDEO_RENDER_RESIZE := 1
COMPILED_LIBRARIES := sdl_mixer sdl_image COMPILED_LIBRARIES := sdl_net
APPLICATION_ADDITIONAL_CFLAGS := -finline-functions -O2 APPLICATION_ADDITIONAL_CFLAGS := -finline-functions -O2
@@ -33,7 +33,7 @@ APPLICATION_SUBDIRS_BUILD :=
APPLICATION_CUSTOM_BUILD_SCRIPT := APPLICATION_CUSTOM_BUILD_SCRIPT :=
SDL_ADDITIONAL_CFLAGS := -DSDL_ANDROID_KEYCODE_MOUSE=UNKNOWN -DSDL_ANDROID_KEYCODE_0=RETURN -DSDL_ANDROID_KEYCODE_1=LCTRL -DSDL_ANDROID_KEYCODE_2=PAGEUP -DSDL_ANDROID_KEYCODE_3=PAGEDOWN -DSDL_ANDROID_KEYCODE_4=LCTRL SDL_ADDITIONAL_CFLAGS := -DSDL_ANDROID_KEYCODE_MOUSE=UNKNOWN -DSDL_ANDROID_KEYCODE_0=SPACE -DSDL_ANDROID_KEYCODE_1=RETURN -DSDL_ANDROID_KEYCODE_2=LCTRL -DSDL_ANDROID_KEYCODE_3=LALT -DSDL_ANDROID_KEYCODE_4=SPACE
# If SDL_Mixer should link to libMAD # If SDL_Mixer should link to libMAD
SDL_MIXER_USE_LIBMAD := SDL_MIXER_USE_LIBMAD :=

View File

@@ -5,6 +5,6 @@ APP_PROJECT_PATH := $(call my-dir)/..
# sdl_image depends on png and jpeg # sdl_image depends on png and jpeg
# sdl_ttf depends on freetype # sdl_ttf depends on freetype
APP_MODULES := application sdl sdl_main stlport tremor png jpeg freetype sdl_mixer sdl_image APP_MODULES := application sdl sdl_main stlport tremor png jpeg freetype sdl_net
APP_ABI := armeabi APP_ABI := armeabi

View File

@@ -1,5 +1,5 @@
# The application settings for Android libSDL port # The application settings for Android libSDL port
AppSettingVersion=8 AppSettingVersion=9
LibSdlVersion=1.2 LibSdlVersion=1.2
AppName="OpenTyrian" AppName="OpenTyrian"
AppFullName=com.googlecode.opentyrian AppFullName=com.googlecode.opentyrian
@@ -11,6 +11,7 @@ AppUsesMouse=y
AppNeedsArrowKeys=y AppNeedsArrowKeys=y
AppUsesJoystick=n AppUsesJoystick=n
AppUsesMultitouch=n AppUsesMultitouch=n
NonBlockingSwapBuffers=n
RedefinedKeys="SPACE RETURN LCTRL LALT SPACE" RedefinedKeys="SPACE RETURN LCTRL LALT SPACE"
AppTouchscreenKeyboardKeysAmount=4 AppTouchscreenKeyboardKeysAmount=4
AppTouchscreenKeyboardKeysAmountAutoFire=1 AppTouchscreenKeyboardKeysAmountAutoFire=1

View File

@@ -1 +1 @@
alienblaster opentyrian

View File

@@ -1 +1 @@
../sdl/sdl-1.3 ../sdl/sdl-1.2

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">Alien Blaster</string> <string name="app_name">OpenTyrian</string>
</resources> </resources>

View File

@@ -71,17 +71,19 @@ static SDL_ANDROID_ApplicationPutToBackgroundCallback_t appRestoredCallback = ap
int SDL_ANDROID_CallJavaSwapBuffers() int SDL_ANDROID_CallJavaSwapBuffers()
{ {
glContextLost = 0;
SDL_ANDROID_drawTouchscreenKeyboard(); SDL_ANDROID_drawTouchscreenKeyboard();
SDL_ANDROID_processAndroidTrackballDampening(); SDL_ANDROID_processAndroidTrackballDampening();
(*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaSwapBuffers ); if( ! (*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaSwapBuffers ) )
return 0;
if( glContextLost ) if( glContextLost )
{ {
glContextLost = 0; glContextLost = 0;
__android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context recreated, refreshing textures"); __android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context recreated, refreshing textures");
SDL_ANDROID_VideoContextRecreated(); SDL_ANDROID_VideoContextRecreated();
appRestoredCallback(); appRestoredCallback();
SDL_PrivateAppActive(1, SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
} }
return 1;
} }
@@ -114,6 +116,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeGlContextLost) ( JNIEnv* env, jobject thiz
__android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context lost, waiting for new OpenGL context"); __android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context lost, waiting for new OpenGL context");
glContextLost = 1; glContextLost = 1;
appPutToBackgroundCallback(); appPutToBackgroundCallback();
SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
SDL_ANDROID_VideoContextLost(); SDL_ANDROID_VideoContextLost();
} }

View File

@@ -1,5 +1,5 @@
// 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 com.googlecode.opentyrian;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;

View File

@@ -1,6 +1,6 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change // This string is autogenerated by ChangeAppSettings.sh, do not change
// spaces amount // spaces amount
package de.schwardtnet.alienblaster; package com.googlecode.opentyrian;
import java.util.zip.*; import java.util.zip.*;
import java.io.*; import java.io.*;

View File

@@ -1,5 +1,5 @@
// 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 com.googlecode.opentyrian;
import android.app.Activity; import android.app.Activity;

View File

@@ -1,5 +1,5 @@
// 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 com.googlecode.opentyrian;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;

View File

@@ -18,7 +18,7 @@
fixed with a hammer and rasp to work with libSDL port */ fixed with a hammer and rasp to work with libSDL port */
// 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 com.googlecode.opentyrian;
import java.io.Writer; import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
@@ -950,6 +950,8 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
mRenderer.onSurfaceDestroyed(); mRenderer.onSurfaceDestroyed();
mEglHelper.finish(); mEglHelper.finish();
mNeedStart = true; mNeedStart = true;
if( Globals.NonBlockingSwapBuffers )
return false;
} }
while (needToWait()) { while (needToWait()) {
//Log.v("SDL", "GLSurfaceView_SDL::run(): paused"); //Log.v("SDL", "GLSurfaceView_SDL::run(): paused");
@@ -992,6 +994,8 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
mRenderer.onSurfaceDestroyed(); mRenderer.onSurfaceDestroyed();
mEglHelper.finish(); mEglHelper.finish();
mNeedStart = true; mNeedStart = true;
if( Globals.NonBlockingSwapBuffers )
return false;
} }
} catch (java.lang.InterruptedException e) { } catch (java.lang.InterruptedException e) {

View File

@@ -1,14 +1,14 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount anywhere // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount anywhere
package de.schwardtnet.alienblaster; package com.googlecode.opentyrian;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
class Globals { class Globals {
public static String ApplicationName = "AlienBlaster"; public static String ApplicationName = "OpenTyrian";
// Should be zip file // Should be zip file
public static String DataDownloadUrl = "Data size is 2 Mb|http://sites.google.com/site/xpelyax/Home/alienblaster110_data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/alienblaster110_data.zip"; public static String DataDownloadUrl = "Data files size is 11 Mb|http://sites.google.com/site/xpelyax/Home/tyrian21-data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/tyrian21-data.zip";
// Set this value to true if you're planning to render 3D using OpenGL - it eats some GFX resources, so disabled for 2D // Set this value to true if you're planning to render 3D using OpenGL - it eats some GFX resources, so disabled for 2D
public static boolean NeedDepthBuffer = false; public static boolean NeedDepthBuffer = false;
@@ -17,15 +17,17 @@ class Globals {
public static boolean HorizontalOrientation = true; public static boolean HorizontalOrientation = true;
// Readme text to be shown on download page // Readme text to be shown on download page
public static String ReadmeText = "^You can press \"Home\" now - the data will be downloaded in background^In game press \"Menu\" for secondary fire, \"Volume Up/Down\" to cycle weapons".replace("^","\n"); public static String ReadmeText = "^You may press \"Home\" now - the data will be downloaded in background".replace("^","\n");
public static boolean AppUsesMouse = false; public static boolean AppUsesMouse = true;
public static boolean AppNeedsArrowKeys = true; public static boolean AppNeedsArrowKeys = true;
public static boolean AppUsesJoystick = false; public static boolean AppUsesJoystick = false;
public static boolean AppUsesMultitouch = false; public static boolean AppUsesMultitouch = false;
public static boolean NonBlockingSwapBuffers = false;
public static int AppTouchscreenKeyboardKeysAmount = 4; public static int AppTouchscreenKeyboardKeysAmount = 4;
@@ -48,5 +50,5 @@ class Globals {
} }
class LoadLibrary { class LoadLibrary {
public LoadLibrary() { System.loadLibrary("sdl"); System.loadLibrary("sdl_mixer"); System.loadLibrary("sdl_image"); }; public LoadLibrary() { System.loadLibrary("sdl"); System.loadLibrary("sdl_net"); };
} }

View File

@@ -1,5 +1,5 @@
// 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 com.googlecode.opentyrian;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;

View File

@@ -1,5 +1,5 @@
// 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 com.googlecode.opentyrian;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;

View File

@@ -1,5 +1,5 @@
// 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 com.googlecode.opentyrian;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
@@ -111,6 +111,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
// Make main thread priority lower so audio thread won't get underrun // Make main thread priority lower so audio thread won't get underrun
// Thread.currentThread().setPriority((Thread.currentThread().getPriority() + Thread.MIN_PRIORITY)/2); // Thread.currentThread().setPriority((Thread.currentThread().getPriority() + Thread.MIN_PRIORITY)/2);
mGlContextLost = false;
System.loadLibrary("application"); System.loadLibrary("application");
System.loadLibrary("sdl_main"); System.loadLibrary("sdl_main");
Settings.Apply(context); Settings.Apply(context);
@@ -126,8 +127,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
synchronized (this) { synchronized (this) {
this.notify(); this.notify();
} }
mGlContextLost = false; if( ! super.SwapBuffers() && Globals.NonBlockingSwapBuffers )
super.SwapBuffers(); return 0;
if(mGlContextLost) { if(mGlContextLost) {
mGlContextLost = false; mGlContextLost = false;
Settings.SetupTouchscreenKeyboardGraphics(context); // Reload on-screen buttons graphics Settings.SetupTouchscreenKeyboardGraphics(context); // Reload on-screen buttons graphics

View File

@@ -168,6 +168,7 @@ where callback_t is function pointer of type "void (*) void".
The default callbacks will call another Android-specific functions: The default callbacks will call another Android-specific functions:
SDL_ANDROID_PauseAudioPlayback() and SDL_ANDROID_ResumeAudioPlayback() SDL_ANDROID_PauseAudioPlayback() and SDL_ANDROID_ResumeAudioPlayback()
which will pause and resume audio from HW layer, so appplication does not need to destroy and re-init audio. which will pause and resume audio from HW layer, so appplication does not need to destroy and re-init audio.
Also, the usual event SDL_ACTIVEEVENT with flag SDL_APPACTIVE will be sent when that happens.
If you're using pure SDL 1.2 API (with or without HW acceleration) you don't need to worry about anything - If you're using pure SDL 1.2 API (with or without HW acceleration) you don't need to worry about anything -
the SDL itself will re-create GL textures and fill them with pixel data from existing SDL HW surfaces, the SDL itself will re-create GL textures and fill them with pixel data from existing SDL HW surfaces,
@@ -191,19 +192,41 @@ and want a beep when someone connects to you) - you may unpause audio for some s
that will require another thread to watch the network, because main thread will be blocked inside SDL_Flip(). that will require another thread to watch the network, because main thread will be blocked inside SDL_Flip().
The application is not allowed to do any GFX output without OpenGL context (or it will crash), The application is not allowed to do any GFX output without OpenGL context (or it will crash),
that's why SDL_Flip() call will block until we're re-acquired context, and the callbacks will be called that's why SDL_Flip() call will block until we're re-acquired context, and the callbacks will be called
from inside SDL_Flip(). so you won't receive SDL_WINDOWEVENT_HIDDEN / SDL_WINDOWEVENT_SHOWN, from inside SDL_Flip().
because if SDL sends them the application will get them only after SDL_Flip() successfully
re-acquired GL context, and it's too late to pause audio and save application state,
so please use callbacks instead of SDL window events on Android OS (also if your application
is single-threaded you don't need any mutexes inside callbacks).
The whole idea behind callbacks is that the existing application should not be modified to The whole idea behind callbacks is that the existing application should not be modified to
operate correctly - the whole time in background will just look to app as one very long SDL_Flip(), operate correctly - the whole time in background will just look to app as one very long SDL_Flip(),
so it's good idea to implement some maximum time cap on game frame, so it won't process so it's good idea to implement some maximum time cap on game frame, so it won't process
the game to the end level 'till the app is in background, or calculate the difference in time the game to the end level 'till the app is in background, or calculate the difference in time
between appPutToBackground() and appRestored() and update game time variables. 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_Event evt;
while( SDL_PollEvent(&evt) )
{
if( evt.type == SDL_ACTIVEEVENT->SDL_APPACTIVE && 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 )
{
SDL_Flip(); // One SDL_Flip() call is required here to restore OpenGL context
// Re-load our textures if we're in SDL+OpenGL mode
// Now we can draw
break;
}
// Process network stuff, maybe play some sounds using SDL_ANDROID_PauseAudioPlayback() / SDL_ANDROID_ResumeAudioPlayback()
SDL_Sleep(200);
}
}
}
Known bugs Known bugs
========== ==========