diff --git a/ChangeAppSettings.sh b/ChangeAppSettings.sh index 8a5a3c67a..7dd683fc7 100755 --- a/ChangeAppSettings.sh +++ b/ChangeAppSettings.sh @@ -124,6 +124,16 @@ else SwVideoMode=n fi +if [ -z "$CompatibilityHacksStaticInit" -o -z "$AUTO" ]; then +echo +echo -n "Application initializes SDL audio/video inside static constructors (which is bad, you won't be able to run ndk-gdb) (y)/(n) ($CompatibilityHacksStaticInit): " +read var +if [ -n "$var" ] ; then + CompatibilityHacksStaticInit="$var" + CHANGED=1 +fi +fi + if [ -z "$VideoDepthBpp" -o -z "$AUTO" ]; then echo echo "Video color depth - 16 BPP is the fastest and supported for all modes, 24 bpp is supported only for" @@ -564,6 +574,7 @@ echo SwVideoMode=$SwVideoMode >> AndroidAppSettings.cfg echo SdlVideoResize=$SdlVideoResize >> AndroidAppSettings.cfg echo SdlVideoResizeKeepAspect=$SdlVideoResizeKeepAspect >> AndroidAppSettings.cfg echo CompatibilityHacks=$CompatibilityHacks >> AndroidAppSettings.cfg +echo CompatibilityHacksStaticInit=$CompatibilityHacksStaticInit >> AndroidAppSettings.cfg echo AppUsesMouse=$AppUsesMouse >> AndroidAppSettings.cfg echo AppNeedsTwoButtonMouse=$AppNeedsTwoButtonMouse >> AndroidAppSettings.cfg echo ShowMouseCursor=$ShowMouseCursor >> AndroidAppSettings.cfg @@ -662,6 +673,12 @@ else CompatibilityHacks=false fi +if [ "$CompatibilityHacksStaticInit" = "y" ] ; then + CompatibilityHacksStaticInit=true +else + CompatibilityHacksStaticInit=false +fi + if [ "$AppUsesMouse" = "y" ] ; then AppUsesMouse=true else @@ -805,7 +822,8 @@ cat project/src/Globals.java | \ sed "s/public static boolean NeedDepthBuffer = .*;/public static boolean NeedDepthBuffer = $NeedDepthBuffer;/" | \ sed "s/public static boolean NeedStencilBuffer = .*;/public static boolean NeedStencilBuffer = $NeedStencilBuffer;/" | \ sed "s/public static boolean NeedGles2 = .*;/public static boolean NeedGles2 = $NeedGles2;/" | \ - sed "s/public static boolean CompatibilityHacks = .*;/public static boolean CompatibilityHacks = $CompatibilityHacks;/" | \ + sed "s/public static boolean CompatibilityHacksVideo = .*;/public static boolean CompatibilityHacksVideo = $CompatibilityHacks;/" | \ + sed "s/public static boolean CompatibilityHacksStaticInit = .*;/public static boolean CompatibilityHacksStaticInit = $CompatibilityHacksStaticInit;/" | \ sed "s/public static boolean HorizontalOrientation = .*;/public static boolean HorizontalOrientation = $HorizontalOrientation;/" | \ sed "s/public static boolean InhibitSuspend = .*;/public static boolean InhibitSuspend = $InhibitSuspend;/" | \ sed "s/public static boolean AppUsesMouse = .*;/public static boolean AppUsesMouse = $AppUsesMouse;/" | \ diff --git a/project/java/Globals.java b/project/java/Globals.java index ba560fb0a..def135c37 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -37,7 +37,8 @@ class Globals { public static boolean NeedDepthBuffer = false; public static boolean NeedStencilBuffer = false; public static boolean NeedGles2 = false; - public static boolean CompatibilityHacks = false; + public static boolean CompatibilityHacksVideo = false; + public static boolean CompatibilityHacksStaticInit = false; public static boolean HorizontalOrientation = true; public static boolean InhibitSuspend = false; public static String ReadmeText = "^You may press \"Home\" now - the data will be downloaded in background".replace("^","\n"); diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 411d03296..13b81b001 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -135,6 +135,8 @@ public class MainActivity extends Activity { mAudioThread = new AudioThread(this); System.out.println("libSDL: Loading settings"); Settings.Load(this); + if(!Globals.CompatibilityHacksStaticInit) + LoadApplicationLibrary(this); } if( !Settings.settingsChanged ) @@ -224,6 +226,7 @@ public class MainActivity extends Activity { mGLView.setFocusable(true); mGLView.requestFocus(); DimSystemStatusBar.get().dim(_videoLayout); + DimSystemStatusBar.get().dim(mGLView); } @Override @@ -683,6 +686,37 @@ public class MainActivity extends Activity { }; + public static void LoadApplicationLibrary(final Context context) + { + String libs[] = { "application", "sdl_main" }; + try + { + for(String l : libs) + { + System.loadLibrary(l); + } + } + catch ( UnsatisfiedLinkError e ) + { + System.out.println("libSDL: error loading lib: " + e.toString()); + try + { + for(String l : libs) + { + String libname = System.mapLibraryName(l); + File libpath = new File(context.getCacheDir(), libname); + System.out.println("libSDL: loading lib " + libpath.getPath()); + System.load(libpath.getPath()); + libpath.delete(); + } + } + catch ( UnsatisfiedLinkError ee ) + { + System.out.println("libSDL: error loading lib: " + ee.toString()); + } + } + } + public int getApplicationVersion() { try { diff --git a/project/java/Settings.java b/project/java/Settings.java index bf2b326b1..d40dfb406 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -2359,7 +2359,7 @@ class Settings Globals.SmoothVideo }; - if(Globals.SwVideoMode && !Globals.CompatibilityHacks) + if(Globals.SwVideoMode && !Globals.CompatibilityHacksVideo) { CharSequence[] items2 = { p.getResources().getString(R.string.pointandclick_keepaspectratio), @@ -2454,7 +2454,7 @@ class Settings nativeSetVideoDepth(Globals.VideoDepthBpp, Globals.NeedGles2 ? 1 : 0); if(Globals.SmoothVideo) nativeSetSmoothVideo(); - if( Globals.CompatibilityHacks ) + if( Globals.CompatibilityHacksVideo ) { Globals.MultiThreadedVideo = true; Globals.SwVideoMode = true; diff --git a/project/java/Video.java b/project/java/Video.java index 69325af45..f90c512b1 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -389,33 +389,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer mGlContextLost = false; - String libs[] = { "application", "sdl_main" }; - try - { - for(String l : libs) - { - System.loadLibrary(l); - } - } - catch ( UnsatisfiedLinkError e ) - { - System.out.println("libSDL: error loading lib: " + e.toString()); - try - { - for(String l : libs) - { - String libname = System.mapLibraryName(l); - File libpath = new File(context.getCacheDir(), libname); - System.out.println("libSDL: loading lib " + libpath.getPath()); - System.load(libpath.getPath()); - libpath.delete(); - } - } - catch ( UnsatisfiedLinkError ee ) - { - System.out.println("libSDL: error loading lib: " + ee.toString()); - } - } + if(Globals.CompatibilityHacksStaticInit) + MainActivity.LoadApplicationLibrary(context); Settings.Apply(context); DifferentTouchInput.ExternalMouseDetected = false; @@ -426,7 +401,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer // Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code nativeInit( Globals.DataDir, Globals.CommandLine, - ( (Globals.SwVideoMode && Globals.MultiThreadedVideo) || Globals.CompatibilityHacks ) ? 1 : 0 ); + ( (Globals.SwVideoMode && Globals.MultiThreadedVideo) || Globals.CompatibilityHacksVideo ) ? 1 : 0 ); System.exit(0); // The main() returns here - I don't bother with deinit stuff, just terminate process } diff --git a/project/jni/application/fheroes2/AndroidAppSettings.cfg b/project/jni/application/fheroes2/AndroidAppSettings.cfg index 130c862cf..69ff62ab3 100644 --- a/project/jni/application/fheroes2/AndroidAppSettings.cfg +++ b/project/jni/application/fheroes2/AndroidAppSettings.cfg @@ -14,6 +14,7 @@ SwVideoMode=y SdlVideoResize=y SdlVideoResizeKeepAspect=n CompatibilityHacks=n +CompatibilityHacksStaticInit=n AppUsesMouse=y AppNeedsTwoButtonMouse=y ShowMouseCursor=n @@ -38,7 +39,7 @@ ResetSdlConfigForThisVersion=n DeleteFilesOnUpgrade="%" CompiledLibraries="sdl_net sdl_mixer sdl_image sdl_ttf png intl" CustomBuildScript=n -AppCflags='-finline-functions -O2 -DWITH_ZLIB -DWITH_MIXER -DWITH_XML -DWITH_IMAGE -DWITH_TTF -DWITH_AI=simple -DWITH_NET' # -DWITH_DEBUG +AppCflags='-finline-functions -O2 -DWITH_ZLIB -DWITH_MIXER -DWITH_XML -DWITH_IMAGE -DWITH_TTF -DWITH_AI=simple -DWITH_NET' AppLdflags='' AppSubdirsBuild='fheroes2/src/engine/* fheroes2/src/xmlccwrap/* fheroes2/src/fheroes2/ai fheroes2/src/fheroes2/ai/simple fheroes2/src/fheroes2/agg fheroes2/src/fheroes2/algorithm fheroes2/src/fheroes2/army fheroes2/src/fheroes2/battle2 fheroes2/src/fheroes2/castle fheroes2/src/fheroes2/dialog fheroes2/src/fheroes2/editor fheroes2/src/fheroes2/game fheroes2/src/fheroes2/gui fheroes2/src/fheroes2/heroes fheroes2/src/fheroes2/image fheroes2/src/fheroes2/kingdom fheroes2/src/fheroes2/maps fheroes2/src/fheroes2/monster fheroes2/src/fheroes2/network fheroes2/src/fheroes2/objects fheroes2/src/fheroes2/pocketpc fheroes2/src/fheroes2/resource fheroes2/src/fheroes2/spell fheroes2/src/fheroes2/system fheroes2/src/fheroes2/test' AppCmdline='fheroes2' diff --git a/project/jni/application/fheroes2/fheroes2.diff b/project/jni/application/fheroes2/fheroes2.diff index 22399267b..41cde3108 100644 --- a/project/jni/application/fheroes2/fheroes2.diff +++ b/project/jni/application/fheroes2/fheroes2.diff @@ -72,3 +72,34 @@ Index: src/fheroes2/network/localclient.cpp cursor.Show(); display.Flip(); +Index: src/fheroes2/network/network.cpp +=================================================================== +--- src/fheroes2/network/network.cpp (revision 2750) ++++ src/fheroes2/network/network.cpp (working copy) +@@ -159,7 +159,9 @@ + Network::SetProtocolVersion(static_cast(MAJOR_VERSION << 8) | MINOR_VERSION); + + if(SDL::Init(INIT_TIMER)) ++#ifndef ANDROID + try ++#endif + { + std::atexit(SDL::Quit); + +@@ -177,6 +179,7 @@ + + return FH2Server::Main(NULL); + } ++#ifndef ANDROID + catch(std::bad_alloc) + { + } +@@ -184,7 +187,7 @@ + { + VERBOSE(conf.String()); + } +- ++#endif + return 0; + } +