diff --git a/alienblaster/project/sdl/sdl-1.3/src/audio/android/SDL_androidaudio.c b/alienblaster/project/sdl/sdl-1.3/src/audio/android/SDL_androidaudio.c index 993d7475b..5cfc17b47 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/audio/android/SDL_androidaudio.c +++ b/alienblaster/project/sdl/sdl-1.3/src/audio/android/SDL_androidaudio.c @@ -22,6 +22,7 @@ This file written by Ryan C. Gordon (icculus@icculus.org) */ #include "SDL_config.h" +#include "SDL_version.h" #include "SDL_rwops.h" #include "SDL_timer.h" @@ -39,10 +40,8 @@ #define _THIS SDL_AudioDevice *this -// TODO: make audio single-threaded, the same way as video - /* Audio driver functions */ -static int ANDROIDAUD_OpenAudio(_THIS, const char *devname, int iscapture); + static void ANDROIDAUD_WaitAudio(_THIS); static void ANDROIDAUD_PlayAudio(_THIS); static Uint8 *ANDROIDAUD_GetAudioBuf(_THIS); @@ -50,11 +49,9 @@ static void ANDROIDAUD_CloseAudio(_THIS); static void ANDROIDAUD_ThreadInit(_THIS); static void ANDROIDAUD_ThreadDeinit(_THIS); -/* Audio driver bootstrap functions */ -static int ANDROIDAUD_Available(void) -{ - return(1); -} +#if SDL_VERSION_ATLEAST(1,3,0) + +static int ANDROIDAUD_OpenAudio(_THIS, const char *devname, int iscapture); static void ANDROIDAUD_DeleteDevice() { @@ -62,6 +59,7 @@ static void ANDROIDAUD_DeleteDevice() static int ANDROIDAUD_CreateDevice(SDL_AudioDriverImpl * impl) { + /* Set the function pointers */ impl->OpenDevice = ANDROIDAUD_OpenAudio; impl->WaitDevice = ANDROIDAUD_WaitAudio; @@ -81,6 +79,54 @@ AudioBootStrap ANDROIDAUD_bootstrap = { ANDROIDAUD_CreateDevice, 0 }; +#else + +static int ANDROIDAUD_OpenAudio(_THIS, SDL_AudioSpec *spec); + +static int ANDROIDAUD_Available(void) +{ + return(1); +} + +static void ANDROIDAUD_DeleteDevice(SDL_AudioDevice *device) +{ + SDL_free(device); +} + +static SDL_AudioDevice *ANDROIDAUD_CreateDevice(int devindex) +{ + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); + if ( this ) { + SDL_memset(this, 0, (sizeof *this)); + this->hidden = NULL; + } else { + SDL_OutOfMemory(); + return(0); + } + + /* Set the function pointers */ + this->OpenAudio = ANDROIDAUD_OpenAudio; + this->WaitAudio = ANDROIDAUD_WaitAudio; + this->PlayAudio = ANDROIDAUD_PlayAudio; + this->GetAudioBuf = ANDROIDAUD_GetAudioBuf; + this->CloseAudio = ANDROIDAUD_CloseAudio; + this->ThreadInit = ANDROIDAUD_ThreadInit; + this->WaitDone = ANDROIDAUD_ThreadDeinit; + this->free = ANDROIDAUD_DeleteDevice; + + return this; +} + +AudioBootStrap ANDROIDAUD_bootstrap = { + ANDROIDAUD_DRIVER_NAME, "SDL Android audio driver", + ANDROIDAUD_Available, ANDROIDAUD_CreateDevice +}; + +#endif + static unsigned char * audioBuffer = NULL; static size_t audioBufferSize = 0; diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c index 068cf6dcf..fe51dfbf7 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c @@ -29,6 +29,7 @@ #include "SDL_config.h" +#include "SDL_version.h" #include "SDL_video.h" #include "SDL_mouse.h" #include "SDL_mutex.h" @@ -64,13 +65,49 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j { if( action == MOUSE_DOWN || action == MOUSE_UP ) { +#if SDL_VERSION_ATLEAST(1,3,0) SDL_SendMouseMotion(NULL, 0, x, y); SDL_SendMouseButton(NULL, (action == MOUSE_DOWN) ? SDL_PRESSED : SDL_RELEASED, 1 ); +#else + SDL_PrivateMouseMotion(0, 0, x, y); + SDL_PrivateMouseButton( (action == MOUSE_DOWN) ? SDL_PRESSED : SDL_RELEASED, 1, x, y ); +#endif } if( action == MOUSE_MOVE ) +#if SDL_VERSION_ATLEAST(1,3,0) SDL_SendMouseMotion(NULL, 0, x, y); +#else + SDL_PrivateMouseMotion(0, 0, x, y); +#endif } +#if SDL_VERSION_ATLEAST(1,3,0) + +#define SDL_KEY(X) SDL_SCANCODE_ ## X + +#else + +#define SDL_KEY2(X) SDLK_ ## X +#define SDL_KEY(X) SDL_KEY2(X) + +#define SDL_SendKeyboardKey SDL_PrivateKeyboard + +// Randomly redefining SDL 1.3 scancodes to SDL 1.2 keycodes +#define KP_0 KP0 +#define KP_1 KP1 +#define KP_2 KP2 +#define KP_3 KP3 +#define KP_4 KP4 +#define KP_5 KP5 +#define KP_6 KP6 +#define KP_7 KP7 +#define KP_8 KP8 +#define KP_9 KP9 +#define NUMLOCKCLEAR NUMLOCK +#define GRAVE DOLLAR + +#endif + static SDL_scancode TranslateKey(int scancode) { if ( scancode >= SDL_arraysize(keymap) ) @@ -78,13 +115,11 @@ static SDL_scancode TranslateKey(int scancode) return keymap[scancode]; } - JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint key, jint action ) { //if( ! processAndroidTrackballKeyDelays(key, action) ) - int posted = SDL_SendKeyboardKey( action ? SDL_PRESSED : SDL_RELEASED, TranslateKey(key) ); - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SendKeyboardKey state %d code %d posted %d, SDL_PollEvent %d", (int)action, TranslateKey(key), posted, ret); + SDL_SendKeyboardKey( action ? SDL_PRESSED : SDL_RELEASED, TranslateKey(key) ); } @@ -255,189 +290,127 @@ void ANDROID_InitOSKeymap() { int i; +#if (SDL_VERSION_ATLEAST(1,3,0)) SDLKey defaultKeymap[SDL_NUM_SCANCODES]; SDL_GetDefaultKeymap(defaultKeymap); SDL_SetKeymap(0, defaultKeymap, SDL_NUM_SCANCODES); +#endif // TODO: keys are mapped rather randomly for (i=0; i 0 ) - { - AndroidTrackballKeyDelays[idx] --; - if( AndroidTrackballKeyDelays[idx] == 0 ) - SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(idx) ); - } - } - } - else - { - idx = -1; - // Too lazy to do switch or function - if( key == KEYCODE_DPAD_UP ) - idx = 0; - else if( key == KEYCODE_DPAD_DOWN ) - idx = 1; - else if( key == KEYCODE_DPAD_LEFT ) - idx = 2; - else if( key == KEYCODE_DPAD_RIGHT ) - idx = 3; - if( idx >= 0 ) - { - if( action && AndroidTrackballKeyDelays[idx] == 0 ) - { - // User pressed key for the first time - idx2 = (idx + 2) % 4; // Opposite key for current key - if it's still pressing, release it - if( AndroidTrackballKeyDelays[idx2] > 0 ) - { - AndroidTrackballKeyDelays[idx2] = 0; - SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(idx2) ); - } - SDL_SendKeyboardKey( SDL_PRESSED, TranslateKey(key) ); - } - else if( !action && AndroidTrackballKeyDelays[idx] == 0 ) - { - // User released key - make a delay, do not send release event - AndroidTrackballKeyDelays[idx] = SDL_TRACKBALL_KEYUP_DELAY; - } - else if( action && AndroidTrackballKeyDelays[idx] > 0 ) - { - // User pressed key another time - add some more time for key to be pressed - AndroidTrackballKeyDelays[idx] += SDL_TRACKBALL_KEYUP_DELAY; - if( AndroidTrackballKeyDelays[idx] < SDL_TRACKBALL_KEYUP_DELAY * 4 ) - AndroidTrackballKeyDelays[idx] = SDL_TRACKBALL_KEYUP_DELAY * 4; - } - return 1; - } - } - return 0; -} diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c index d5c127a50..d6f014546 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c +++ b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c @@ -43,23 +43,9 @@ #include "SDL_androidvideo.h" -/* Initialization/Query functions */ -static int ANDROID_VideoInit(_THIS); -static int ANDROID_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); -static void ANDROID_GetDisplayModes(_THIS, SDL_VideoDisplay * display); -static int ANDROID_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); -static void ANDROID_VideoQuit(_THIS); - -static void ANDROID_GL_SwapBuffers(_THIS, SDL_Window * window); -// Stubs -static SDL_GLContext ANDROID_GL_CreateContext(_THIS, SDL_Window * window); -static int ANDROID_GL_MakeCurrent (_THIS, SDL_Window * window, SDL_GLContext context); -static void ANDROID_GL_DeleteContext (_THIS, SDL_GLContext context); - - // The device screen dimensions to draw on -static int sWindowWidth = 320; -static int sWindowHeight = 480; +int SDL_ANDROID_sWindowWidth = 320; +int SDL_ANDROID_sWindowHeight = 480; // Extremely wicked JNI environment to call Java functions from C code static JNIEnv* JavaEnv = NULL; @@ -67,150 +53,11 @@ static jclass JavaRendererClass = NULL; static jobject JavaRenderer = NULL; static jmethodID JavaSwapBuffers = NULL; -static void SdlGlRenderInit(); - -/* ANDROID driver bootstrap functions */ - -static int ANDROID_Available(void) -{ - return 1; -} - -static void ANDROID_DeleteDevice(SDL_VideoDevice *device) -{ - SDL_free(device); -} - -static SDL_VideoDevice *ANDROID_CreateDevice(int devindex) -{ - SDL_VideoDevice *device; - - /* Initialize all variables that we clean on shutdown */ - device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); - if ( device ) { - SDL_memset(device, 0, sizeof (*device)); - } - if ( (device == NULL) ) { - SDL_OutOfMemory(); - if ( device ) { - SDL_free(device); - } - return(0); - } - - /* Set the function pointers */ - device->VideoInit = ANDROID_VideoInit; - device->GetDisplayBounds = ANDROID_GetDisplayBounds; - device->GetDisplayModes = ANDROID_GetDisplayModes; - device->SetDisplayMode = ANDROID_SetDisplayMode; - device->PumpEvents = ANDROID_PumpEvents; - device->VideoQuit = ANDROID_VideoQuit; - device->free = ANDROID_DeleteDevice; - - device->GL_SwapWindow = ANDROID_GL_SwapBuffers; - device->GL_CreateContext = ANDROID_GL_CreateContext; - device->GL_MakeCurrent = ANDROID_GL_MakeCurrent; - device->GL_DeleteContext = ANDROID_GL_DeleteContext; - - return device; -} - -VideoBootStrap ANDROID_bootstrap = { - "android", "SDL Android video driver", - ANDROID_Available, ANDROID_CreateDevice -}; - - -int ANDROID_VideoInit(_THIS) -{ - SDL_VideoDisplay display; - SDL_DisplayMode mode; - - mode.w = sWindowWidth; - mode.h = sWindowHeight; - mode.refresh_rate = 0; - mode.format = SDL_PIXELFORMAT_RGB565; - mode.driverdata = NULL; - - SDL_zero(display); - display.desktop_mode = mode; - display.current_mode = mode; - display.driverdata = NULL; - SDL_AddVideoDisplay(&display); - - return 1; -} - - -void ANDROID_GetDisplayModes(_THIS, SDL_VideoDisplay * display) -{ - SDL_DisplayMode mode; - mode.w = sWindowWidth; - mode.h = sWindowHeight; - mode.refresh_rate = 0; - mode.format = SDL_PIXELFORMAT_RGB565; - mode.driverdata = NULL; - SDL_AddDisplayMode(display, &mode); - - /* - struct compatModes_t { int x, int y } compatModes[] = - { {800, 600}, {640, 480}, {320, 240}, {320, 200} }; - - for(int i = 0; i < sizeof(compatModes) / sizeof(compatModes[0]); i++) - if( sWindowWidth >= compatModes[i].x && sWindowHeight >= compatModes[i].y ) - { - mode.w = compatModes[i].x; - mode.h = compatModes[i].y; - SDL_AddDisplayMode(display, &mode); - } - */ -} - -int ANDROID_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect) -{ - rect->w = sWindowWidth; - rect->h = sWindowHeight; - return 1; -}; - -int ANDROID_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) -{ - return 1; -}; - - -/* Note: If we are terminated, this could be called in the middle of - another SDL video routine -- notably UpdateRects. -*/ -void ANDROID_VideoQuit(_THIS) -{ -} - -void ANDROID_PumpEvents(_THIS) -{ -} - -static inline int CallJavaSwapBuffers() +int SDL_ANDROID_CallJavaSwapBuffers() { return (*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaSwapBuffers ); } -void ANDROID_GL_SwapBuffers(_THIS, SDL_Window * window) -{ - CallJavaSwapBuffers(); -}; - -SDL_GLContext ANDROID_GL_CreateContext(_THIS, SDL_Window * window) -{ - return (SDL_GLContext)1; -}; -int ANDROID_GL_MakeCurrent (_THIS, SDL_Window * window, SDL_GLContext context) -{ - return 1; -}; -void ANDROID_GL_DeleteContext (_THIS, SDL_GLContext context) -{ -}; /* JNI-C++ wrapper stuff */ @@ -224,8 +71,8 @@ void ANDROID_GL_DeleteContext (_THIS, SDL_GLContext context) JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoRenderer_nativeResize) ( JNIEnv* env, jobject thiz, jint w, jint h ) { - sWindowWidth = w; - sWindowHeight = h; + SDL_ANDROID_sWindowWidth = w; + SDL_ANDROID_sWindowHeight = h; __android_log_print(ANDROID_LOG_INFO, "libSDL", "Physical screen resolution is %dx%d", w, h); } diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h index 8e538d64a..ab7f7e87f 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -26,9 +26,12 @@ #include "../SDL_sysvideo.h" -extern void ANDROID_PumpEvents(_THIS); extern void ANDROID_InitOSKeymap(); +extern int SDL_ANDROID_sWindowWidth; +extern int SDL_ANDROID_sWindowHeight; +extern int SDL_ANDROID_CallJavaSwapBuffers(); + // Keycodes ripped from Java SDK enum KEYCODES_ANDROID