From fef867ebcb3b9de1435503eab0687b00f8575e57 Mon Sep 17 00:00:00 2001 From: pelya Date: Sat, 22 Sep 2012 17:14:31 +0300 Subject: [PATCH] Toggled back mouse events ratelimiting, changed magnifying glass grag&drop to be more snappy, updated OpenTTD --- project/java/Video.java | 2 +- .../commandergenius/commandergenius | 2 +- .../openttd/AndroidAppSettings.cfg | 12 +- .../openttd/openttd-trunk-android.patch | 335 ++++++++++++------ .../src/video/android/SDL_renderer_gles.c | 2 - .../src/video/android/SDL_androidinput.c | 11 +- 6 files changed, 251 insertions(+), 113 deletions(-) diff --git a/project/java/Video.java b/project/java/Video.java index 2dd54234c..829cb16fd 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -673,7 +673,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer public int mWidth = 0; public int mHeight = 0; - public static final boolean mRatelimitTouchEvents = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO); + public static final boolean mRatelimitTouchEvents = true; //(Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO); } class DemoGLSurfaceView extends GLSurfaceView_SDL { diff --git a/project/jni/application/commandergenius/commandergenius b/project/jni/application/commandergenius/commandergenius index d1b8a7ae0..023025901 160000 --- a/project/jni/application/commandergenius/commandergenius +++ b/project/jni/application/commandergenius/commandergenius @@ -1 +1 @@ -Subproject commit d1b8a7ae03b1a0960722abbab38bbb8fca98e7cd +Subproject commit 023025901a1d96a46d826791bf9cf264ddf5c9ee diff --git a/project/jni/application/openttd/AndroidAppSettings.cfg b/project/jni/application/openttd/AndroidAppSettings.cfg index 8b7350211..7f206d5a5 100644 --- a/project/jni/application/openttd/AndroidAppSettings.cfg +++ b/project/jni/application/openttd/AndroidAppSettings.cfg @@ -23,7 +23,7 @@ ForceRelativeMouseMode=n AppNeedsArrowKeys=n AppNeedsTextInput=y AppUsesJoystick=n -AppHandlesJoystickSensitivity=n +AppUsesAccelerometer=n AppUsesMultitouch=n NonBlockingSwapBuffers=n RedefinedKeys="LALT RETURN NO_REMAP NO_REMAP SPACE DELETE" @@ -34,16 +34,16 @@ StartupMenuButtonTimeout=3000 HiddenMenuOptions='OptionalDownloadConfig' FirstStartMenuOptions='' MultiABI=n -AppVersionCode=12220 -AppVersionName="1.2.2.20" -ResetSdlConfigForThisVersion=n -DeleteFilesOnUpgrade="%" +AppVersionCode=12221 +AppVersionName="1.2.2.21" +ResetSdlConfigForThisVersion=y +DeleteFilesOnUpgrade=".openttd/openttd.cfg" CompiledLibraries="jpeg png freetype timidity lzma lzo2" CustomBuildScript=y AppCflags='' AppLdflags='' AppSubdirsBuild='' -AppCmdline='openttd' +AppCmdline='openttd -b 32bpp-anim' ReadmeText='^You may press "Home" now - the data will be downloaded in background' MinimumScreenSize=s AdmobPublisherId=n diff --git a/project/jni/application/openttd/openttd-trunk-android.patch b/project/jni/application/openttd/openttd-trunk-android.patch index 2adb7d02b..643a59f20 100644 --- a/project/jni/application/openttd/openttd-trunk-android.patch +++ b/project/jni/application/openttd/openttd-trunk-android.patch @@ -1,22 +1,59 @@ -Index: src/main_gui.cpp +Index: src/os/unix/unix.cpp =================================================================== ---- src/main_gui.cpp (revision 24340) -+++ src/main_gui.cpp (working copy) -@@ -458,7 +458,11 @@ - Hotkey('C', "center", GHK_CENTER), - Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM), - Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE), +--- src/os/unix/unix.cpp (revision 24501) ++++ src/os/unix/unix.cpp (working copy) +@@ -25,7 +25,7 @@ + + #ifdef __APPLE__ + #include +-#elif (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__) ++#elif ((defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__)) && !defined(ANDROID) + #define HAS_STATVFS + #endif + +@@ -254,6 +254,11 @@ + void cocoaReleaseAutoreleasePool(); + #endif + +#ifdef ANDROID -+ Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_NONVITAL_WINDOWS), -+#else - Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS), ++#define main SDL_main ++extern "C" int CDECL main(int, char *[]); +#endif - Hotkey(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS), - Hotkey('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN), - #if defined(_DEBUG) ++ + int CDECL main(int argc, char *argv[]) + { + int ret; +Index: src/os/unix/crashlog_unix.cpp +=================================================================== +--- src/os/unix/crashlog_unix.cpp (revision 24501) ++++ src/os/unix/crashlog_unix.cpp (working copy) +@@ -141,7 +141,11 @@ + }; + + /** The signals we want our crash handler to handle. */ ++#ifdef ANDROID ++static const int _signals_to_handle[] = { }; // Default Android signal handler will give us stack trace ++#else + static const int _signals_to_handle[] = { SIGSEGV, SIGABRT, SIGFPE, SIGBUS, SIGILL }; ++#endif + + /** + * Entry point for the crash handler. +Index: src/openttd.cpp +=================================================================== +--- src/openttd.cpp (revision 24501) ++++ src/openttd.cpp (working copy) +@@ -695,7 +695,6 @@ + LoadFromConfig(true); + + if (resolution.width != 0) _cur_resolution = resolution; +- + /* + * The width and height must be at least 1 pixel and width times + * height times bytes per pixel must still fit within a 32 bits Index: src/script/api/script_date.cpp =================================================================== ---- src/script/api/script_date.cpp (revision 24340) +--- src/script/api/script_date.cpp (revision 24501) +++ src/script/api/script_date.cpp (working copy) @@ -9,8 +9,8 @@ @@ -28,22 +65,33 @@ Index: src/script/api/script_date.cpp #include "script_date.hpp" #include "../../date_func.h" -Index: src/network/core/os_abstraction.h +Index: src/debug.cpp =================================================================== ---- src/network/core/os_abstraction.h (revision 24340) -+++ src/network/core/os_abstraction.h (working copy) -@@ -161,7 +161,7 @@ - # include - /* According to glibc/NEWS, appeared in glibc-2.3. */ - # if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) && !defined(__HAIKU__) && !defined(__INNOTEK_LIBC__) \ -- && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX) -+ && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX) && !defined(ANDROID) - /* If for any reason ifaddrs.h does not exist on your system, comment out - * the following two lines and an alternative way will be used to fetch - * the list of IPs from the system. */ +--- src/debug.cpp (revision 24501) ++++ src/debug.cpp (working copy) +@@ -16,6 +16,9 @@ + #include "string_func.h" + #include "fileio_func.h" + #include "settings_type.h" ++#ifdef ANDROID ++#include ++#endif + + #include + +@@ -82,6 +85,9 @@ + */ + static void debug_print(const char *dbg, const char *buf) + { ++#ifdef ANDROID ++ __android_log_print(ANDROID_LOG_INFO, "OpenTTD", "[%s] %s", dbg, buf); ++#endif + #if defined(ENABLE_NETWORK) + if (_debug_socket != INVALID_SOCKET) { + char buf2[1024 + 32]; Index: src/window.cpp =================================================================== ---- src/window.cpp (revision 24340) +--- src/window.cpp (revision 24501) +++ src/window.cpp (working copy) @@ -2354,6 +2354,10 @@ * But there is no company related window open anyway, so _current_company is not used. */ @@ -58,7 +106,7 @@ Index: src/window.cpp Index: src/video/sdl_v.cpp =================================================================== ---- src/video/sdl_v.cpp (revision 24340) +--- src/video/sdl_v.cpp (revision 24501) +++ src/video/sdl_v.cpp (working copy) @@ -25,6 +25,9 @@ #include "../fileio_func.h" @@ -90,16 +138,71 @@ Index: src/video/sdl_v.cpp if (sym->scancode == 49) key = WKC_BACKSPACE; #elif defined(__sgi__) if (sym->scancode == 22) key = WKC_BACKQUOTE; -+#elif defined(ANDROID) ++#elif defined(__ANDROID__) + if (sym->scancode == SDLK_BACKQUOTE) key = WKC_BACKQUOTE; #else if (sym->scancode == 49) key = WKC_BACKQUOTE; #endif -@@ -519,6 +531,9 @@ +@@ -456,7 +468,7 @@ + } + HandleMouseEvents(); + break; +- ++#ifndef __ANDROID__ + case SDL_ACTIVEEVENT: + if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break; + +@@ -467,7 +479,7 @@ + _cursor.in_window = false; + } + break; +- ++#endif + case SDL_QUIT: + HandleExitGameRequest(); + break; +@@ -480,13 +492,14 @@ + HandleKeypress(ConvertSdlKeyIntoMy(&ev.key.keysym)); + } + break; +- ++#ifndef __ANDROID__ + case SDL_VIDEORESIZE: { + int w = max(ev.resize.w, 64); + int h = max(ev.resize.h, 64); + CreateMainSurface(w, h); + break; + } ++#endif + case SDL_VIDEOEXPOSE: { + /* Force a redraw of the entire screen. Note + * that SDL 1.2 seems to do this automatically +@@ -506,6 +519,20 @@ + if (s != NULL) return s; + + GetVideoModes(); ++ ++#ifdef __ANDROID__ ++ // The GUI is way too small for HDPI devices, so we'll leave the default 640x80 here ++ /* ++ FILE * config_exists = fopen(".openttd/openttd.cfg", "r"); ++ if( config_exists ) ++ fclose(config_exists); ++ else { ++ _cur_resolution.width = SDL_GetVideoInfo()->current_w; ++ _cur_resolution.height = SDL_GetVideoInfo()->current_h; ++ } ++ */ ++#endif ++ + if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) { + return SDL_CALL SDL_GetError(); + } +@@ -519,6 +546,9 @@ SDL_CALL SDL_EnableUNICODE(1); _draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL; -+#ifdef ANDROID ++#ifdef __ANDROID__ + _draw_threaded = false; +#endif @@ -107,7 +210,7 @@ Index: src/video/sdl_v.cpp } Index: src/sound/sdl_s.cpp =================================================================== ---- src/sound/sdl_s.cpp (revision 24340) +--- src/sound/sdl_s.cpp (revision 24501) +++ src/sound/sdl_s.cpp (working copy) @@ -21,6 +21,10 @@ /** Factory for the SDL sound driver. */ @@ -132,7 +235,7 @@ Index: src/sound/sdl_s.cpp const char *SoundDriver_SDL::Start(const char * const *parm) Index: src/music/libtimidity.cpp =================================================================== ---- src/music/libtimidity.cpp (revision 24340) +--- src/music/libtimidity.cpp (revision 24501) +++ src/music/libtimidity.cpp (working copy) @@ -22,6 +22,7 @@ #include @@ -167,52 +270,20 @@ Index: src/music/libtimidity.cpp /** Factory for the libtimidity driver. */ static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity; -Index: src/os/unix/crashlog_unix.cpp -=================================================================== ---- src/os/unix/crashlog_unix.cpp (revision 24340) -+++ src/os/unix/crashlog_unix.cpp (working copy) -@@ -141,7 +141,11 @@ - }; - - /** The signals we want our crash handler to handle. */ -+#ifdef ANDROID -+static const int _signals_to_handle[] = { }; // Default Android signal handler will give us stack trace -+#else - static const int _signals_to_handle[] = { SIGSEGV, SIGABRT, SIGFPE, SIGBUS, SIGILL }; -+#endif - - /** - * Entry point for the crash handler. -Index: src/os/unix/unix.cpp -=================================================================== ---- src/os/unix/unix.cpp (revision 24340) -+++ src/os/unix/unix.cpp (working copy) -@@ -25,7 +25,7 @@ - - #ifdef __APPLE__ - #include --#elif (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__) -+#elif ((defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__)) && !defined(ANDROID) - #define HAS_STATVFS - #endif - -@@ -254,6 +254,11 @@ - void cocoaReleaseAutoreleasePool(); - #endif - -+#ifdef ANDROID -+#define main SDL_main -+extern "C" int CDECL main(int, char *[]); -+#endif -+ - int CDECL main(int argc, char *argv[]) - { - int ret; Index: src/table/misc_settings.ini =================================================================== ---- src/table/misc_settings.ini (revision 24340) +--- src/table/misc_settings.ini (revision 24501) +++ src/table/misc_settings.ini (working copy) -@@ -128,28 +128,28 @@ +@@ -104,7 +104,7 @@ + type = SLE_INT + length = 2 + var = _cur_resolution +-def = ""640,480"" ++def = ""800,480"" + + [SDTG_STR] + name = ""screenshot_format"" +@@ -128,35 +128,35 @@ name = ""small_font"" type = SLE_STRB var = _freetype.small_font @@ -245,33 +316,99 @@ Index: src/table/misc_settings.ini [SDTG_VAR] ifdef = WITH_FREETYPE -Index: src/debug.cpp + name = ""small_size"" + type = SLE_UINT + var = _freetype.small_size +-def = 8 ++def = 10 + min = 0 + max = 72 + +@@ -165,7 +165,7 @@ + name = ""medium_size"" + type = SLE_UINT + var = _freetype.medium_size +-def = 10 ++def = 12 + min = 0 + max = 72 + +@@ -183,7 +183,7 @@ + name = ""mono_size"" + type = SLE_UINT + var = _freetype.mono_size +-def = 10 ++def = 12 + min = 0 + max = 72 + +@@ -191,25 +191,25 @@ + ifdef = WITH_FREETYPE + name = ""small_aa"" + var = _freetype.small_aa +-def = false ++def = true + + [SDTG_BOOL] + ifdef = WITH_FREETYPE + name = ""medium_aa"" + var = _freetype.medium_aa +-def = false ++def = true + + [SDTG_BOOL] + ifdef = WITH_FREETYPE + name = ""large_aa"" + var = _freetype.large_aa +-def = false ++def = true + + [SDTG_BOOL] + ifdef = WITH_FREETYPE + name = ""mono_aa"" + var = _freetype.mono_aa +-def = false ++def = true + + [SDTG_VAR] + name = ""sprite_cache_size_px"" +Index: src/settings.cpp =================================================================== ---- src/debug.cpp (revision 24340) -+++ src/debug.cpp (working copy) -@@ -16,6 +16,9 @@ - #include "string_func.h" - #include "fileio_func.h" - #include "settings_type.h" -+#ifdef ANDROID -+#include +--- src/settings.cpp (revision 24501) ++++ src/settings.cpp (working copy) +@@ -1632,6 +1632,16 @@ + if (!minimal) { + _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false); + _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true); ++#ifdef __ANDROID__ ++ FILE * config_exists = fopen(".openttd/openttd.cfg", "r"); ++ if( config_exists ) ++ fclose(config_exists); ++ else { ++ _grfconfig_newgame = new GRFConfig("opengfx+biggui.grf"); ++ FillGRFDetails(_grfconfig_newgame, false); ++ } +#endif - - #include - -@@ -82,6 +85,9 @@ - */ - static void debug_print(const char *dbg, const char *buf) - { -+#ifdef ANDROID -+ __android_log_print(ANDROID_LOG_INFO, "OpenTTD", "[%s] %s", dbg, buf); -+#endif - #if defined(ENABLE_NETWORK) - if (_debug_socket != INVALID_SOCKET) { - char buf2[1024 + 32]; ++ + NewsDisplayLoadConfig(ini, "news_display"); + AILoadConfig(ini, "ai_players"); + GameLoadConfig(ini, "game_scripts"); +Index: src/network/core/os_abstraction.h +=================================================================== +--- src/network/core/os_abstraction.h (revision 24501) ++++ src/network/core/os_abstraction.h (working copy) +@@ -161,7 +161,7 @@ + # include + /* According to glibc/NEWS, appeared in glibc-2.3. */ + # if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) && !defined(__HAIKU__) && !defined(__INNOTEK_LIBC__) \ +- && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX) ++ && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX) && !defined(ANDROID) + /* If for any reason ifaddrs.h does not exist on your system, comment out + * the following two lines and an alternative way will be used to fetch + * the list of IPs from the system. */ Index: findversion.sh =================================================================== ---- findversion.sh (revision 24340) +--- findversion.sh (revision 24501) +++ findversion.sh (working copy) @@ -134,6 +134,7 @@ REV_NR="" diff --git a/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c b/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c index 6bac554f2..9cb471e91 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c @@ -482,8 +482,6 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) if( renderer->info.max_texture_width < texture_w || renderer->info.max_texture_height < texture_h ) __android_log_print(ANDROID_LOG_WARN, "libSDL", "GLES: Allocated texture of size %dx%d which is bigger than largest possible device texture %dx%d", texture_w, texture_h, renderer->info.max_texture_width, renderer->info.max_texture_height ); - else if( texture_w > 1024 || texture_h > 1024 ) - __android_log_print(ANDROID_LOG_WARN, "libSDL", "GLES: Allocated texture of size %dx%d which is bigger than 1024x1024 - this code will not work on HTC G1", texture_w, texture_h ); data->format = format; data->formattype = type; diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c index a09ab652b..29ed45191 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c @@ -550,7 +550,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t if( action == MOUSE_DOWN ) { if( (moveMouseWithKbX >= 0 || leftClickMethod == LEFT_CLICK_NEAR_CURSOR) && - abs(currentMouseX - x) < SDL_ANDROID_sFakeWindowWidth / 8 && abs(currentMouseY - y) < SDL_ANDROID_sFakeWindowHeight / 8 ) + abs(currentMouseX - x) < SDL_ANDROID_sFakeWindowWidth / 10 && abs(currentMouseY - y) < SDL_ANDROID_sFakeWindowHeight / 10 ) { SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_LEFT ); moveMouseWithKbX = currentMouseX; @@ -580,6 +580,8 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t { if( moveMouseWithKbX >= 0 ) { + // Mouse lazily follows magnifying glass, not very intuitive for drag&drop + /* if( abs(moveMouseWithKbX - x) > SDL_ANDROID_sFakeWindowWidth / 12 ) moveMouseWithKbSpeedX += moveMouseWithKbX > x ? -1 : 1; else @@ -591,9 +593,10 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t moveMouseWithKbX += moveMouseWithKbSpeedX; moveMouseWithKbY += moveMouseWithKbSpeedY; - - if( abs(moveMouseWithKbX - x) > SDL_ANDROID_sFakeWindowWidth / 8 || - abs(moveMouseWithKbY - y) > SDL_ANDROID_sFakeWindowHeight / 8 ) + */ + // Mouse follows touch instantly, when it's out of the snapping distance from mouse cursor + if( abs(moveMouseWithKbX - x) >= SDL_ANDROID_sFakeWindowWidth / 10 || + abs(moveMouseWithKbY - y) >= SDL_ANDROID_sFakeWindowHeight / 10 ) { moveMouseWithKbX = -1; moveMouseWithKbY = -1;