diff --git a/project/java/Audio.java b/project/java/Audio.java index 5e9e7d755..17df707b0 100644 --- a/project/java/Audio.java +++ b/project/java/Audio.java @@ -35,7 +35,14 @@ class AudioThread { public int fillBuffer() { + if( Globals.AudioBufferConfig == 0 && mAudio.getPlaybackHeadPosition() * 1000 / mAudio.getPlaybackRate() >= 30 ) + { + try{ + Thread.sleep(10); + } catch(InterruptedException e) {} + } mAudio.write( mAudioBuffer, 0, mVirtualBufSize ); + return 1; } diff --git a/project/jni/application/openttd/AndroidAppSettings.cfg b/project/jni/application/openttd/AndroidAppSettings.cfg index 7d662d0aa..ae0a70b1e 100644 --- a/project/jni/application/openttd/AndroidAppSettings.cfg +++ b/project/jni/application/openttd/AndroidAppSettings.cfg @@ -17,7 +17,7 @@ AppUsesJoystick=n AppHandlesJoystickSensitivity=n AppUsesMultitouch=n NonBlockingSwapBuffers=n -RedefinedKeys="LALT RETURN KP_PLUS KP_MINUS DELETE" +RedefinedKeys="LALT RETURN KP_PLUS KP_MINUS DELETE ESCAPE" AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmountAutoFire=0 MultiABI=n diff --git a/project/jni/application/openttd/openttd-trunk-android.patch b/project/jni/application/openttd/openttd-trunk-android.patch index 273f493b1..aa143219f 100644 --- a/project/jni/application/openttd/openttd-trunk-android.patch +++ b/project/jni/application/openttd/openttd-trunk-android.patch @@ -1,6 +1,6 @@ Index: src/sound/sdl_s.cpp =================================================================== ---- src/sound/sdl_s.cpp (revision 21200) +--- src/sound/sdl_s.cpp (revision 21293) +++ src/sound/sdl_s.cpp (working copy) @@ -20,9 +20,16 @@ @@ -13,7 +13,7 @@ Index: src/sound/sdl_s.cpp static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len) { MxMixSamples(stream, len / 4); -+#if defined(ANDROID) && defined(LIBTIMIDITY) ++#ifdef ANDROID + Android_MidiMixMusic((Sint16 *)stream, len / 2); +#endif } @@ -21,9 +21,9 @@ 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 21200) +--- src/music/libtimidity.cpp (revision 21293) +++ src/music/libtimidity.cpp (working copy) -@@ -22,10 +22,13 @@ +@@ -23,10 +23,13 @@ #include #include #include @@ -37,7 +37,7 @@ Index: src/music/libtimidity.cpp enum MidiState { MIDI_STOPPED = 0, MIDI_PLAYING = 1, -@@ -50,6 +53,24 @@ +@@ -51,6 +54,24 @@ } } #endif /* PSP */ @@ -64,7 +64,7 @@ Index: src/music/libtimidity.cpp Index: src/os/unix/unix.cpp =================================================================== ---- src/os/unix/unix.cpp (revision 21200) +--- src/os/unix/unix.cpp (revision 21293) +++ src/os/unix/unix.cpp (working copy) @@ -24,7 +24,7 @@ @@ -75,7 +75,7 @@ Index: src/os/unix/unix.cpp #define HAS_STATVFS #endif -@@ -245,6 +245,11 @@ +@@ -239,6 +239,11 @@ void cocoaReleaseAutoreleasePool(); #endif @@ -87,11 +87,27 @@ Index: src/os/unix/unix.cpp int CDECL main(int argc, char *argv[]) { int ret; +Index: src/os/unix/crashlog_unix.cpp +=================================================================== +--- src/os/unix/crashlog_unix.cpp (revision 21293) ++++ 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/network/core/os_abstraction.h =================================================================== ---- src/network/core/os_abstraction.h (revision 21200) +--- src/network/core/os_abstraction.h (revision 21293) +++ src/network/core/os_abstraction.h (working copy) -@@ -161,7 +161,7 @@ +@@ -159,7 +159,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__) \ @@ -102,7 +118,7 @@ Index: src/network/core/os_abstraction.h * the list of IPs from the system. */ Index: src/debug.cpp =================================================================== ---- src/debug.cpp (revision 21200) +--- src/debug.cpp (revision 21293) +++ src/debug.cpp (working copy) @@ -16,6 +16,9 @@ #include "string_func.h" @@ -114,8 +130,8 @@ Index: src/debug.cpp #include -@@ -76,6 +79,9 @@ - */ +@@ -70,6 +73,9 @@ + static void debug_print(const char *dbg, const char *buf) { +#ifdef ANDROID diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c index 9c922216a..058b6bd35 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c @@ -113,7 +113,7 @@ int SDL_ANDROID_sFakeWindowWidth = 640; int SDL_ANDROID_sFakeWindowHeight = 480; static int sdl_opengl = 0; static SDL_Window *SDL_VideoWindow = NULL; -static SDL_Surface *SDL_CurrentVideoSurface = NULL; +SDL_Surface *SDL_CurrentVideoSurface = NULL; static Uint32 SDL_VideoThreadID = 0; static int HwSurfaceCount = 0; static SDL_Surface ** HwSurfaceList = NULL; 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 3cd82ae8f..4ae3f22d5 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 @@ -115,6 +115,8 @@ void UpdateScreenUnderFingerRect(int x, int y) JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId, jint force, jint radius ) { + if( !SDL_CurrentVideoSurface ) + return; if(pointerId < 0) pointerId = 0; if(pointerId > MAX_MULTITOUCH_POINTERS) @@ -234,6 +236,8 @@ static int processAndroidTrackball(int key, int action); JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint key, jint action ) { + if( !SDL_CurrentVideoSurface ) + return; if( isTrackballUsed ) if( processAndroidTrackball(key, action) ) return; @@ -276,6 +280,8 @@ static void updateOrientation ( float accX, float accY, float accZ ); JNIEXPORT void JNICALL JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobject thiz, jfloat accPosX, jfloat accPosY, jfloat accPosZ ) { + if( !SDL_CurrentVideoSurface ) + return; // Calculate two angles from three coordinates - TODO: this is faulty! //float accX = atan2f(-accPosX, sqrtf(accPosY*accPosY+accPosZ*accPosZ) * ( accPosY > 0 ? 1.0f : -1.0f ) ) * M_1_PI * 180.0f; //float accY = atan2f(accPosZ, accPosY) * M_1_PI; @@ -292,6 +298,8 @@ JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobjec JNIEXPORT void JNICALL JAVA_EXPORT_NAME(AccelerometerReader_nativeOrientation) ( JNIEnv* env, jobject thiz, jfloat accX, jfloat accY, jfloat accZ ) { + if( !SDL_CurrentVideoSurface ) + return; updateOrientation (accX, accY, accZ); // TODO: make values in range 0.0:1.0 } diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h index 8818740c7..2fa0cfd39 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -33,6 +33,7 @@ extern int SDL_ANDROID_sRealWindowWidth; extern int SDL_ANDROID_sRealWindowHeight; extern int SDL_ANDROID_sFakeWindowWidth; // SDL 1.2 only extern int SDL_ANDROID_sFakeWindowHeight; // SDL 1.2 only +extern SDL_Surface *SDL_CurrentVideoSurface; extern SDL_Rect SDL_ANDROID_ForceClearScreenRect; extern int SDL_ANDROID_ShowScreenUnderFinger; extern SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect, SDL_ANDROID_ShowScreenUnderFingerRectSrc; diff --git a/project/jni/sdl_main/sdl_main.c b/project/jni/sdl_main/sdl_main.c index 6c1bb540d..fb81a4d2d 100644 --- a/project/jni/sdl_main/sdl_main.c +++ b/project/jni/sdl_main/sdl_main.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include "SDL_thread.h" @@ -30,7 +31,8 @@ extern C_LINKAGE void JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring cmdline ) { int i = 0; - char curdir[512], realcurdir[512]; + char curdir[PATH_MAX] = ""; + char realcurdir[PATH_MAX] = ""; const jbyte *jstr; const char * str = "sdl"; int argc = 0;