diff --git a/project/jni/application/teeworlds/src/engine/client/ec_gfx.cpp b/project/jni/application/teeworlds/src/engine/client/ec_gfx.cpp index 944ed22a9..5ae16888a 100644 --- a/project/jni/application/teeworlds/src/engine/client/ec_gfx.cpp +++ b/project/jni/application/teeworlds/src/engine/client/ec_gfx.cpp @@ -575,6 +575,9 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_f else if(format == IMG_ALPHA) { oglformat = GL_ALPHA; +#ifdef ANDROID + oglformat = GL_RGBA; // No pure alpha textures on Android +#endif glesType = GL_UNSIGNED_SHORT_4_4_4_4; } @@ -625,7 +628,7 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_f ((Uint16 *)tmpdata)[ y*(Uint32)w+x ] = CONVERT_RGB888_RGB565( ((* ((Uint32 *)(texdata+(y*w+x)*3))) & 0xFFFFFF) ); } } - else // RGBA + else // RGBA or ALPHA { for(y = 0; y < h; y++) for(x = 0; x < w; x++) diff --git a/project/jni/application/teeworlds/src/engine/client/ec_inp.cpp b/project/jni/application/teeworlds/src/engine/client/ec_inp.cpp index 4aea840ab..75b502dba 100644 --- a/project/jni/application/teeworlds/src/engine/client/ec_inp.cpp +++ b/project/jni/application/teeworlds/src/engine/client/ec_inp.cpp @@ -41,6 +41,11 @@ void inp_mouse_relative(int *x, int *y) *y = ny*sens; } +void inp_mouse_absolute(int *x, int *y) +{ + SDL_GetMouseState(x, y); +} + enum { INPUT_BUFFER_SIZE=32 diff --git a/project/jni/application/teeworlds/src/engine/client/ec_snd.cpp b/project/jni/application/teeworlds/src/engine/client/ec_snd.cpp index ce91167d1..fe51d9b15 100644 --- a/project/jni/application/teeworlds/src/engine/client/ec_snd.cpp +++ b/project/jni/application/teeworlds/src/engine/client/ec_snd.cpp @@ -14,6 +14,10 @@ extern "C" { #include #include #include +#ifdef ANDROID +#include +#include +#endif enum { @@ -143,9 +147,17 @@ static int iabs(int i) static void mix(short *final_out, unsigned frames) { - int mix_buffer[MAX_FRAMES*2] = {0}; int i, s; int master_vol; +#ifdef ANDROID + // The size of buffer SDL returns to us may vary greatly across devices, and will easily exceed MAX_FRAMES size -> segfault + // (on older devices the buffer should be large, otherwise the sound will be choppy) + // Why didn't they just use SDL_mixer there, and go on with own buggy mixer implementation? + int * mix_buffer = (int *)alloca(frames * 2 * sizeof(int)); + bzero(mix_buffer, frames * 2 * sizeof(int)); +#else + int mix_buffer[MAX_FRAMES*2] = {0}; +#endif /* aquire lock while we are mixing */ lock_wait(sound_lock); @@ -252,7 +264,7 @@ static void sdlcallback(void *unused, Uint8 *stream, int len) int snd_init() { - SDL_AudioSpec format; + SDL_AudioSpec format, format2; sound_lock = lock_create(); @@ -270,14 +282,14 @@ int snd_init() format.userdata = NULL; /* Open the audio device and start playing sound! */ - if(SDL_OpenAudio(&format, NULL) < 0) + if(SDL_OpenAudio(&format, &format2) < 0) { dbg_msg("client/sound", "unable to open audio: %s", SDL_GetError()); return -1; } else dbg_msg("client/sound", "sound init successful"); - + SDL_PauseAudio(0); sound_enabled = 1; diff --git a/project/jni/application/teeworlds/src/engine/e_config_variables.h b/project/jni/application/teeworlds/src/engine/e_config_variables.h index 4360d7f36..0d4e9d5b5 100644 --- a/project/jni/application/teeworlds/src/engine/e_config_variables.h +++ b/project/jni/application/teeworlds/src/engine/e_config_variables.h @@ -31,11 +31,10 @@ MACRO_CONFIG_INT(b_sort, 0, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(b_sort_order, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(b_max_requests, 10, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Number of requests to use when refreshing server browser") +MACRO_CONFIG_INT(snd_buffer_size, 512, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size") #ifdef ANDROID -MACRO_CONFIG_INT(snd_buffer_size, 1024, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size") MACRO_CONFIG_INT(snd_rate, 22050, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound mixing rate") #else -MACRO_CONFIG_INT(snd_buffer_size, 512, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size") MACRO_CONFIG_INT(snd_rate, 48000, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound mixing rate") #endif MACRO_CONFIG_INT(snd_enable, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound enable") diff --git a/project/jni/application/teeworlds/src/engine/e_if_inp.h b/project/jni/application/teeworlds/src/engine/e_if_inp.h index 8a546e8a1..aeee9ed16 100644 --- a/project/jni/application/teeworlds/src/engine/e_if_inp.h +++ b/project/jni/application/teeworlds/src/engine/e_if_inp.h @@ -38,6 +38,8 @@ typedef struct */ void inp_mouse_relative(int *x, int *y); +void inp_mouse_absolute(int *x, int *y); + /* Function: inp_mouse_scroll TODO diff --git a/project/jni/application/teeworlds/src/game/client/components/controls.cpp b/project/jni/application/teeworlds/src/game/client/components/controls.cpp index 091f3024b..422b074ad 100644 --- a/project/jni/application/teeworlds/src/game/client/components/controls.cpp +++ b/project/jni/application/teeworlds/src/game/client/components/controls.cpp @@ -178,6 +178,9 @@ bool CONTROLS::on_mousemove(float x, float y) if(gameclient.snap.gameobj && gameclient.snap.gameobj->paused) return false; mouse_pos += vec2(x, y); // TODO: ugly +#ifdef ANDROID + mouse_pos = vec2(x, y); +#endif // float camera_max_distance = 200.0f; diff --git a/project/jni/application/teeworlds/src/game/client/components/emoticon.cpp b/project/jni/application/teeworlds/src/game/client/components/emoticon.cpp index 934b2fcf4..38325f0e5 100644 --- a/project/jni/application/teeworlds/src/game/client/components/emoticon.cpp +++ b/project/jni/application/teeworlds/src/game/client/components/emoticon.cpp @@ -52,6 +52,9 @@ bool EMOTICON::on_mousemove(float x, float y) return false; selector_mouse += vec2(x,y); +#ifdef ANDROID + selector_mouse = vec2(x,y); +#endif return true; } @@ -92,10 +95,18 @@ void EMOTICON::on_render() was_active = true; int x, y; +#ifdef ANDROID + // No relative mouse here, we've got touchscreen + inp_mouse_absolute(&x, &y); + + selector_mouse.x = x; + selector_mouse.y = y; +#else inp_mouse_relative(&x, &y); selector_mouse.x += x; selector_mouse.y += y; +#endif if (length(selector_mouse) > 140) selector_mouse = normalize(selector_mouse) * 140; diff --git a/project/jni/application/teeworlds/src/game/client/components/menus.cpp b/project/jni/application/teeworlds/src/game/client/components/menus.cpp index 54c587ef7..7d9e3b4cd 100644 --- a/project/jni/application/teeworlds/src/game/client/components/menus.cpp +++ b/project/jni/application/teeworlds/src/game/client/components/menus.cpp @@ -928,6 +928,12 @@ bool MENUS::on_mousemove(float x, float y) mouse_pos.x += x; mouse_pos.y += y; + +#ifdef ANDROID + mouse_pos.x = x; + mouse_pos.y = y; +#endif + if(mouse_pos.x < 0) mouse_pos.x = 0; if(mouse_pos.y < 0) mouse_pos.y = 0; if(mouse_pos.x > gfx_screenwidth()) mouse_pos.x = gfx_screenwidth(); diff --git a/project/jni/application/teeworlds/src/game/client/gameclient.cpp b/project/jni/application/teeworlds/src/game/client/gameclient.cpp index 8d0e044c3..a8a62ddfe 100644 --- a/project/jni/application/teeworlds/src/game/client/gameclient.cpp +++ b/project/jni/application/teeworlds/src/game/client/gameclient.cpp @@ -245,8 +245,13 @@ void GAMECLIENT::dispatch_input() { // handle mouse movement int x=0, y=0; +#ifdef ANDROID + // No relative mouse here, we've got touchscreen + inp_mouse_absolute(&x, &y); +#else inp_mouse_relative(&x, &y); if(x || y) +#endif { for(int h = 0; h < input.num; h++) { diff --git a/project/jni/application/teeworlds/src/game/editor/ed_editor.cpp b/project/jni/application/teeworlds/src/game/editor/ed_editor.cpp index ccbc63102..07f105118 100644 --- a/project/jni/application/teeworlds/src/game/editor/ed_editor.cpp +++ b/project/jni/application/teeworlds/src/game/editor/ed_editor.cpp @@ -2698,6 +2698,14 @@ extern "C" void editor_update_and_render() float mx, my, mwx, mwy; int rx, ry; { +#ifdef ANDROID + // No relative mouse here, we've got touchscreen + inp_mouse_absolute(&rx, &ry); + editor.mouse_delta_x = rx - mouse_x; + editor.mouse_delta_y = ry - mouse_y; + mouse_x = rx; + mouse_y = ry; +#else inp_mouse_relative(&rx, &ry); editor.mouse_delta_x = rx; editor.mouse_delta_y = ry; @@ -2707,6 +2715,7 @@ extern "C" void editor_update_and_render() mouse_x += rx; mouse_y += ry; } +#endif if(mouse_x < 0) mouse_x = 0; if(mouse_y < 0) mouse_y = 0;