Android patches

This commit is contained in:
pelya
2014-03-15 19:44:27 +02:00
parent f177e48d88
commit 6dc8be0332
14 changed files with 97 additions and 19 deletions

View File

@@ -134,6 +134,7 @@ else
REV_NR="" REV_NR=""
fi fi
MODIFIED="0" # This prevents Andorid build from connecting to a public servers
if [ "$MODIFIED" -eq "2" ]; then if [ "$MODIFIED" -eq "2" ]; then
REV="${REV}M" REV="${REV}M"
fi fi

View File

@@ -16,6 +16,9 @@
#include "string_func.h" #include "string_func.h"
#include "fileio_func.h" #include "fileio_func.h"
#include "settings_type.h" #include "settings_type.h"
#ifdef __ANDROID__
#include <android/log.h>
#endif
#include <time.h> #include <time.h>
@@ -107,6 +110,9 @@ char *DumpDebugFacilityNames(char *buf, char *last)
*/ */
static void debug_print(const char *dbg, const char *buf) 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 defined(ENABLE_NETWORK)
if (_debug_socket != INVALID_SOCKET) { if (_debug_socket != INVALID_SOCKET) {
char buf2[1024 + 32]; char buf2[1024 + 32];

View File

@@ -639,6 +639,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
if (fs != NULL) { if (fs != NULL) {
int best_weight = -1; int best_weight = -1;
const char *best_font = NULL; const char *best_font = NULL;
int best_missing_glypths = 65536;
for (int i = 0; i < fs->nfont; i++) { for (int i = 0; i < fs->nfont; i++) {
FcPattern *font = fs->fonts[i]; FcPattern *font = fs->fonts[i];
@@ -664,12 +665,13 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
callback->SetFontNames(settings, (const char*)file); callback->SetFontNames(settings, (const char*)file);
bool missing = callback->FindMissingGlyphs(NULL); int missing = callback->FindMissingGlyphs(NULL);
DEBUG(freetype, 1, "Font \"%s\" misses%s glyphs", file, missing ? "" : " no"); DEBUG(freetype, 1, "Font \"%s\" misses %d glyphs for lang %s", file, missing, lang);
if (!missing) { if (missing < best_missing_glypths) {
best_weight = value; best_weight = value;
best_font = (const char *)file; best_font = (const char *)file;
best_missing_glypths = missing;
} }
} }
@@ -677,6 +679,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
ret = true; ret = true;
callback->SetFontNames(settings, best_font); callback->SetFontNames(settings, best_font);
InitFreeType(callback->Monospace()); InitFreeType(callback->Monospace());
DEBUG(freetype, 1, "Selected font %s for lang %s", best_font, lang);
} }
/* Clean up the list of filenames. */ /* Clean up the list of filenames. */

View File

@@ -13,6 +13,7 @@
#include "../openttd.h" #include "../openttd.h"
#include "../sound_type.h" #include "../sound_type.h"
#include "../debug.h" #include "../debug.h"
#include "../core/math_func.hpp"
#include "libtimidity.h" #include "libtimidity.h"
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
@@ -22,6 +23,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <timidity.h> #include <timidity.h>
#include <SDL.h>
#if defined(PSP) #if defined(PSP)
#include <pspaudiolib.h> #include <pspaudiolib.h>
#endif /* PSP */ #endif /* PSP */
@@ -51,6 +53,24 @@ static void AudioOutCallback(void *buf, unsigned int _reqn, void *userdata)
} }
} }
#endif /* PSP */ #endif /* PSP */
#ifdef __ANDROID__
/* Android does not have Midi chip, we have to route the libtimidity output through SDL audio output */
void Android_MidiMixMusic(Sint16 *stream, int len)
{
if (_midi.status == MIDI_PLAYING) {
Sint16 buf[16384];
while( len > 0 )
{
int minlen = min(sizeof(buf), len);
mid_song_read_wave(_midi.song, stream, min(sizeof(buf), len*2));
for( Uint16 i = 0; i < minlen; i++ )
stream[i] += buf[i];
stream += minlen;
len -= minlen;
}
}
}
#endif /* __ANDROID__ */
/** Factory for the libtimidity driver. */ /** Factory for the libtimidity driver. */
static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity; static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity;

View File

@@ -161,7 +161,7 @@ static inline void OTTDfreeaddrinfo(struct addrinfo *ai)
# include <net/if.h> # include <net/if.h>
/* According to glibc/NEWS, <ifaddrs.h> appeared in glibc-2.3. */ /* According to glibc/NEWS, <ifaddrs.h> appeared in glibc-2.3. */
# if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) && !defined(__HAIKU__) && !defined(__INNOTEK_LIBC__) \ # 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 /* 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 following two lines and an alternative way will be used to fetch
* the list of IPs from the system. */ * the list of IPs from the system. */

View File

@@ -141,7 +141,11 @@ public:
}; };
/** The signals we want our crash handler to handle. */ /** 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 }; static const int _signals_to_handle[] = { SIGSEGV, SIGABRT, SIGFPE, SIGBUS, SIGILL };
#endif
/** /**
* Entry point for the crash handler. * Entry point for the crash handler.

View File

@@ -25,7 +25,7 @@
#ifdef __APPLE__ #ifdef __APPLE__
#include <sys/mount.h> #include <sys/mount.h>
#elif (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__) #elif ((defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__)) && !defined(__ANDROID__)
#define HAS_STATVFS #define HAS_STATVFS
#endif #endif
@@ -254,6 +254,11 @@ void cocoaSetupAutoreleasePool();
void cocoaReleaseAutoreleasePool(); void cocoaReleaseAutoreleasePool();
#endif #endif
#ifdef __ANDROID__
#define main SDL_main
extern "C" int CDECL main(int, char *[]);
#endif
int CDECL main(int argc, char *argv[]) int CDECL main(int argc, char *argv[])
{ {
int ret; int ret;

View File

@@ -22,6 +22,9 @@
#include "table/sprites.h" #include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
#ifdef __ANDROID__
#include <SDL_screenkeyboard.h>
#endif
char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES * 4 + 1]; char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES * 4 + 1];
static WChar _keyboard[2][OSK_KEYBOARD_ENTRIES]; static WChar _keyboard[2][OSK_KEYBOARD_ENTRIES];
@@ -413,6 +416,16 @@ void ShowOnScreenKeyboard(Window *parent, int button)
GetKeyboardLayout(); GetKeyboardLayout();
new OskWindow(&_osk_desc, parent, button); new OskWindow(&_osk_desc, parent, button);
#ifdef __ANDROID__
char text[256];
SDL_ANDROID_GetScreenKeyboardTextInput(text, sizeof(text) - 1); /* Invoke Android built-in screen keyboard */
OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
osk->qs->text.Assign(text);
free(osk->orig_str_buf);
osk->orig_str_buf = strdup(osk->qs->text.buf);
osk->SetDirty();
#endif
} }
/** /**

View File

@@ -9,8 +9,8 @@
/** @file script_date.cpp Implementation of ScriptDate. */ /** @file script_date.cpp Implementation of ScriptDate. */
#include "../../stdafx.h" /* Have to be included before time.h, if we want UINT32_MAX macro defined on Android */
#include <time.h> #include <time.h>
#include "../../stdafx.h"
#include "script_date.hpp" #include "script_date.hpp"
#include "../../date_func.h" #include "../../date_func.h"

View File

@@ -323,17 +323,17 @@ struct GameOptionsWindow : Window {
switch (widget) { switch (widget) {
case WID_GO_BASE_GRF_DESCRIPTION: case WID_GO_BASE_GRF_DESCRIPTION:
SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode())); SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING); DrawString(r.left, r.right, r.top, STR_BLACK_RAW_STRING);
break; break;
case WID_GO_BASE_SFX_DESCRIPTION: case WID_GO_BASE_SFX_DESCRIPTION:
SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode())); SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING); DrawString(r.left, r.right, r.top, STR_BLACK_RAW_STRING);
break; break;
case WID_GO_BASE_MUSIC_DESCRIPTION: case WID_GO_BASE_MUSIC_DESCRIPTION:
SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode())); SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING); DrawString(r.left, r.right, r.top, STR_BLACK_RAW_STRING);
break; break;
} }
} }
@@ -344,7 +344,7 @@ struct GameOptionsWindow : Window {
case WID_GO_BASE_GRF_DESCRIPTION: case WID_GO_BASE_GRF_DESCRIPTION:
/* Find the biggest description for the default size. */ /* Find the biggest description for the default size. */
for (int i = 0; i < BaseGraphics::GetNumSets(); i++) { for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode())); SetDParamStr(0, "123");
size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width)); size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
} }
break; break;
@@ -363,7 +363,7 @@ struct GameOptionsWindow : Window {
case WID_GO_BASE_SFX_DESCRIPTION: case WID_GO_BASE_SFX_DESCRIPTION:
/* Find the biggest description for the default size. */ /* Find the biggest description for the default size. */
for (int i = 0; i < BaseSounds::GetNumSets(); i++) { for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode())); SetDParamStr(0, "123");
size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width)); size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
} }
break; break;
@@ -371,7 +371,7 @@ struct GameOptionsWindow : Window {
case WID_GO_BASE_MUSIC_DESCRIPTION: case WID_GO_BASE_MUSIC_DESCRIPTION:
/* Find the biggest description for the default size. */ /* Find the biggest description for the default size. */
for (int i = 0; i < BaseMusic::GetNumSets(); i++) { for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode())); SetDParamStr(0, "123");
size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width)); size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
} }
break; break;

View File

@@ -21,6 +21,10 @@
/** Factory for the SDL sound driver. */ /** Factory for the SDL sound driver. */
static FSoundDriver_SDL iFSoundDriver_SDL; static FSoundDriver_SDL iFSoundDriver_SDL;
#ifdef __ANDROID__
extern void Android_MidiMixMusic(Sint16 *stream, int len);
#endif
/** /**
* Callback that fills the sound buffer. * Callback that fills the sound buffer.
* @param userdata Ignored. * @param userdata Ignored.
@@ -30,6 +34,9 @@ static FSoundDriver_SDL iFSoundDriver_SDL;
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len) static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
{ {
MxMixSamples(stream, len / 4); MxMixSamples(stream, len / 4);
#if defined(__ANDROID__) && defined(LIBTIMIDITY)
Android_MidiMixMusic((Sint16 *)stream, len / 2);
#endif
} }
const char *SoundDriver_SDL::Start(const char * const *parm) const char *SoundDriver_SDL::Start(const char * const *parm)

View File

@@ -2005,7 +2005,7 @@ const char *GetCurrentLanguageIsoCode()
* @return If glyphs are missing, return \c true, else return \c false. * @return If glyphs are missing, return \c true, else return \c false.
* @post If \c true is returned and str is not NULL, *str points to a string that is found to contain at least one missing glyph. * @post If \c true is returned and str is not NULL, *str points to a string that is found to contain at least one missing glyph.
*/ */
bool MissingGlyphSearcher::FindMissingGlyphs(const char **str) int MissingGlyphSearcher::FindMissingGlyphs(const char **str)
{ {
InitFreeType(this->Monospace()); InitFreeType(this->Monospace());
const Sprite *question_mark[FS_END]; const Sprite *question_mark[FS_END];
@@ -2015,6 +2015,7 @@ bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
} }
this->Reset(); this->Reset();
int missing = 0;
for (const char *text = this->NextString(); text != NULL; text = this->NextString()) { for (const char *text = this->NextString(); text != NULL; text = this->NextString()) {
FontSize size = this->DefaultSize(); FontSize size = this->DefaultSize();
if (str != NULL) *str = text; if (str != NULL) *str = text;
@@ -2025,11 +2026,11 @@ bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
size = FS_LARGE; size = FS_LARGE;
} else if (!IsInsideMM(c, SCC_SPRITE_START, SCC_SPRITE_END) && IsPrintable(c) && !IsTextDirectionChar(c) && c != '?' && GetGlyph(size, c) == question_mark[size]) { } else if (!IsInsideMM(c, SCC_SPRITE_START, SCC_SPRITE_END) && IsPrintable(c) && !IsTextDirectionChar(c) && c != '?' && GetGlyph(size, c) == question_mark[size]) {
/* The character is printable, but not in the normal font. This is the case we were testing for. */ /* The character is printable, but not in the normal font. This is the case we were testing for. */
return true; missing++;
} }
} }
} }
return false; return missing;
} }
/** Helper for searching through the language pack. */ /** Helper for searching through the language pack. */

View File

@@ -235,7 +235,7 @@ public:
*/ */
virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0; virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0;
bool FindMissingGlyphs(const char **str); int FindMissingGlyphs(const char **str);
}; };
void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = NULL); void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = NULL);

View File

@@ -25,6 +25,9 @@
#include "../fileio_func.h" #include "../fileio_func.h"
#include "sdl_v.h" #include "sdl_v.h"
#include <SDL.h> #include <SDL.h>
#ifdef __ANDROID__
#include <SDL_screenkeyboard.h>
#endif
static FVideoDriver_SDL iFVideoDriver_SDL; static FVideoDriver_SDL iFVideoDriver_SDL;
@@ -349,6 +352,15 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
* surface, for example). */ * surface, for example). */
_requested_hwpalette = want_hwpalette; _requested_hwpalette = want_hwpalette;
#ifdef __ANDROID__
SDL_Rect r;
r.h = SDL_ListModes(NULL, 0)[0]->h / 10;
r.w = r.h;
r.x = SDL_ListModes(NULL, 0)[0]->w - r.w;
r.y = SDL_ListModes(NULL, 0)[0]->h - r.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, &r);
#endif
/* DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK */ /* DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK */
newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | (want_hwpalette ? SDL_HWPALETTE : 0) | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | (want_hwpalette ? SDL_HWPALETTE : 0) | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
if (newscreen == NULL) { if (newscreen == NULL) {
@@ -521,6 +533,8 @@ static uint ConvertSdlKeyIntoMy(SDL_keysym *sym, WChar *character)
if (sym->scancode == 49) key = WKC_BACKSPACE; if (sym->scancode == 49) key = WKC_BACKSPACE;
#elif defined(__sgi__) #elif defined(__sgi__)
if (sym->scancode == 22) key = WKC_BACKQUOTE; if (sym->scancode == 22) key = WKC_BACKQUOTE;
#elif defined(__ANDROID__)
if (sym->scancode == SDLK_BACKQUOTE) key = WKC_BACKQUOTE;
#else #else
if (sym->scancode == 49) key = WKC_BACKQUOTE; if (sym->scancode == 49) key = WKC_BACKQUOTE;
#endif #endif
@@ -597,7 +611,7 @@ int VideoDriver_SDL::PollEvent()
} }
HandleMouseEvents(); HandleMouseEvents();
break; break;
#ifndef __ANDROID__
case SDL_ACTIVEEVENT: case SDL_ACTIVEEVENT:
if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break; if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break;
@@ -608,7 +622,7 @@ int VideoDriver_SDL::PollEvent()
_cursor.in_window = false; _cursor.in_window = false;
} }
break; break;
#endif /* not __ANDROID__ */
case SDL_QUIT: case SDL_QUIT:
HandleExitGameRequest(); HandleExitGameRequest();
break; break;
@@ -623,13 +637,14 @@ int VideoDriver_SDL::PollEvent()
HandleKeypress(keycode, character); HandleKeypress(keycode, character);
} }
break; break;
#ifndef __ANDROID__
case SDL_VIDEORESIZE: { case SDL_VIDEORESIZE: {
int w = max(ev.resize.w, 64); int w = max(ev.resize.w, 64);
int h = max(ev.resize.h, 64); int h = max(ev.resize.h, 64);
CreateMainSurface(w, h); CreateMainSurface(w, h);
break; break;
} }
#endif /* not __ANDROID__ */
case SDL_VIDEOEXPOSE: { case SDL_VIDEOEXPOSE: {
/* Force a redraw of the entire screen. Note /* Force a redraw of the entire screen. Note
* that SDL 1.2 seems to do this automatically * that SDL 1.2 seems to do this automatically
@@ -661,6 +676,9 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
SetupKeyboard(); SetupKeyboard();
_draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL; _draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL;
#ifdef __ANDROID__
_draw_threaded = false;
#endif
return NULL; return NULL;
} }