diff --git a/ChangeAppSettings.sh b/ChangeAppSettings.sh index ecd445e61..7843b1bb7 100755 --- a/ChangeAppSettings.sh +++ b/ChangeAppSettings.sh @@ -13,7 +13,7 @@ if [ "$CHANGE_APP_SETTINGS_VERSION" != "$AppSettingVersion" ]; then AUTO= fi -LibSdlVersionOld=$LibSdlVersion +LibSdlVersionOld=`readlink project/jni/sdl | grep -o '[0-9][.][0-9]'` CompiledLibrariesOld=$CompiledLibraries var="" diff --git a/project/AndroidManifest.xml b/project/AndroidManifest.xml index ddc078cbb..656163597 100644 --- a/project/AndroidManifest.xml +++ b/project/AndroidManifest.xml @@ -1,8 +1,8 @@ flags & SDL_SRCALPHA ) - { - format = SDL_PIXELFORMAT_RGBA4444; - ret->t = SDL_CreateTextureFromSurface(format, surface); - } - else if( surface->flags & SDL_SRCCOLORKEY ) - { - // Use 1-bit alpha as colorkey - Uint32 key; - SDL_GetColorKey(surface, &key); - format = SDL_PIXELFORMAT_RGBA5551; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); - - SDL_Surface * temp = SDL_CreateRGBSurface( SDL_SRCALPHA, surface->w, surface->h, bpp, Rmask, Gmask, Bmask, Amask ); - - SDL_FillRect( temp, NULL, SDL_MapRGBA(temp->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT) ); - - SDL_BlitSurface( surface, NULL, temp, NULL ); // Copies only opaque pixels, and sets their alpha to opaque - - ret->t = SDL_CreateTextureFromSurface(format, temp); - - SDL_FreeSurface(temp); - } - else - { - format = SDL_PIXELFORMAT_RGB565; - ret->t = SDL_CreateTextureFromSurface(format, surface); - } - */ - format = SDL_PIXELFORMAT_RGB565; if( surface->flags & SDL_SRCCOLORKEY ) format = SDL_PIXELFORMAT_RGBA5551; - ret->t = SDL_CreateTextureFromSurface(format, surface); + ret->s = SDL_ConvertSurface( surface, surface->format, 0 ); + ret->t = SDL_CreateTextureFromSurface(format, ret->s); ret->w = surface->w; ret->h = surface->h; @@ -79,6 +48,7 @@ static inline SdlCompat_AcceleratedSurface * SdlCompat_CreateAcceleratedSurface( return ret; } + ret->flags = surface->flags; if( surface->flags & SDL_SRCALPHA ) { SDL_SetTextureBlendMode( ret->t, SDL_BLENDMODE_BLEND ); @@ -98,6 +68,8 @@ static inline int SDL_BlitSurface( SdlCompat_AcceleratedSurface * src, SDL_Rect static inline void SDL_FreeSurface(SdlCompat_AcceleratedSurface * surface) { + SDL_DestroyTexture(surface->t); + SDL_FreeSurface(surface->s); delete surface->format; delete surface; }; @@ -106,8 +78,8 @@ static inline void SDL_FillRect( SdlCompat_AcceleratedSurface * unused, const SD { Uint8 r, g, b, a; SDL_GetRGBA( color, SDL_GetVideoSurface()->format, &r, &g, &b, &a ); - SDL_SetRenderDrawColor(r, g, b, a); - SDL_RenderDrawRect(rect); + SDL_SetRenderDrawColor(r, g, b, SDL_ALPHA_OPAQUE /* a */); + SDL_RenderFillRect(rect); }; static inline int SDL_Flip(SdlCompat_AcceleratedSurface * unused) @@ -123,6 +95,34 @@ static inline int SDL_SetAlpha(SdlCompat_AcceleratedSurface * surface, Uint32 fl return SDL_SetTextureAlphaMod(surface->t, alpha); }; +static inline void SdlCompat_ReloadSurfaceToVideoMemory(SdlCompat_AcceleratedSurface * surface) +{ + SDL_DestroyTexture(surface->t); + + // Allocate accelerated surface even if that means loss of color quality + Uint32 format; + format = SDL_PIXELFORMAT_RGB565; + + if( surface->flags & SDL_SRCCOLORKEY ) + format = SDL_PIXELFORMAT_RGBA5551; + surface->t = SDL_CreateTextureFromSurface(format, surface->s); + + if( ! surface->t ) + { + SDL_SetError("SdlCompat_CreateAcceleratedSurface: Cannot allocate HW texture, W %d H %d format %x surface->flags %x", surface->w, surface->h, format, surface->flags ); + return; + } + + if( surface->flags & SDL_SRCALPHA ) + { + SDL_SetTextureBlendMode( surface->t, SDL_BLENDMODE_BLEND ); + Uint8 alpha = 128; + if( SDL_GetSurfaceAlphaMod( surface->s, &alpha ) < 0 ) + alpha = 128; + SDL_SetTextureAlphaMod( surface->t, alpha ); + } +}; + #else typedef SDL_Surface SdlCompat_AcceleratedSurface; @@ -132,6 +132,10 @@ static inline SdlCompat_AcceleratedSurface * SdlCompat_CreateAcceleratedSurface( return SDL_ConvertSurface(surface, surface->format, surface->flags | SDL_HWSURFACE); }; +static inline void SdlCompat_ReloadSurfaceToVideoMemory(SDL_Surface * surface) +{ +}; + #endif #endif diff --git a/project/jni/application/alienblaster/main.cpp b/project/jni/application/alienblaster/main.cpp index 8b90f8043..37b9631b1 100644 --- a/project/jni/application/alienblaster/main.cpp +++ b/project/jni/application/alienblaster/main.cpp @@ -18,13 +18,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ***************************************************************************/ #include "game.h" +#include "surfaceDB.h" #include "SDL.h" #include #include using namespace std; +static void appPutToBackground() +{ + SDL_ANDROID_PauseAudioPlayback(); +} +static void appPutToForeground() +{ + surfaceDB.reloadAllSurfacesToVideoMemory(); + SDL_ANDROID_ResumeAudioPlayback(); +} + int main(int argc, char *argv[]) { + SDL_ANDROID_SetApplicationPutToBackgroundCallback(&appPutToBackground, &appPutToForeground); __android_log_print(ANDROID_LOG_INFO, "Alien Blaster", "main() 0"); SDL_Init(0); srand(0); diff --git a/project/jni/application/alienblaster/surfaceDB.cpp b/project/jni/application/alienblaster/surfaceDB.cpp index 8d4fba0cc..cc71679ba 100644 --- a/project/jni/application/alienblaster/surfaceDB.cpp +++ b/project/jni/application/alienblaster/surfaceDB.cpp @@ -116,3 +116,10 @@ SdlCompat_AcceleratedSurface *SurfaceDB::getSurface( string fn ) { } } +void SurfaceDB::reloadAllSurfacesToVideoMemory() +{ + for( StringSurfaceMap::iterator it = surfaceDB.begin(); it != surfaceDB.end(); it++ ) + { + SdlCompat_ReloadSurfaceToVideoMemory( it->second ); + } +}; diff --git a/project/jni/application/alienblaster/surfaceDB.h b/project/jni/application/alienblaster/surfaceDB.h index 435f782e7..c543d7ef6 100644 --- a/project/jni/application/alienblaster/surfaceDB.h +++ b/project/jni/application/alienblaster/surfaceDB.h @@ -51,6 +51,8 @@ class SurfaceDB { SdlCompat_AcceleratedSurface *loadSurface( std::string fn, bool alpha=false ); + void reloadAllSurfacesToVideoMemory(); + private: StringSurfaceMap surfaceDB; Uint8 transR, transG, transB; diff --git a/project/jni/application/alienblaster/video.cpp b/project/jni/application/alienblaster/video.cpp index 715108944..3e984cb6d 100644 --- a/project/jni/application/alienblaster/video.cpp +++ b/project/jni/application/alienblaster/video.cpp @@ -72,11 +72,6 @@ SdlCompat_AcceleratedSurface *Video::init(){ __android_log_print(ANDROID_LOG_INFO, "Alien Blaster", "Initializing video done"); - SDL_Surface * empty2 = SDL_CreateRGBSurface( 0, 16, 16, 16, 0xff, 0x00ff, 0x0000ff, 0 ); - SDL_FillRect(empty2, NULL, SDL_MapRGB(empty2->format, 0, 0, 0) ); - empty = SdlCompat_CreateAcceleratedSurface(empty2); - SDL_FreeSurface(empty2); - return screen; } @@ -89,9 +84,9 @@ void Video::clearScreen() { r.y = 0; r.w = screen->w; r.h = screen->h; - SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0, 0, 0) ); */ - SDL_BlitSurface(empty, NULL, screen, NULL); + SDL_FillRect(screen, NULL, 0); + //SDL_BlitSurface(empty, NULL, screen, NULL); } void Video::toggleFullscreen() { diff --git a/project/jni/application/alienblaster/video.h b/project/jni/application/alienblaster/video.h index f3328f57f..f7577aee1 100644 --- a/project/jni/application/alienblaster/video.h +++ b/project/jni/application/alienblaster/video.h @@ -32,7 +32,6 @@ class Video { private: SdlCompat_AcceleratedSurface *screen; - SdlCompat_AcceleratedSurface *empty; public: Video(); diff --git a/project/jni/application/src b/project/jni/application/src index 706424f94..4de17cd97 120000 --- a/project/jni/application/src +++ b/project/jni/application/src @@ -1 +1 @@ -sc2 \ No newline at end of file +alienblaster \ No newline at end of file diff --git a/project/jni/sdl b/project/jni/sdl index 73bcf85be..d92c7931b 120000 --- a/project/jni/sdl +++ b/project/jni/sdl @@ -1 +1 @@ -../sdl/sdl-1.2 \ No newline at end of file +../sdl/sdl-1.3 \ No newline at end of file diff --git a/project/res/values/strings.xml b/project/res/values/strings.xml index 8834ce584..be07da4d5 100644 --- a/project/res/values/strings.xml +++ b/project/res/values/strings.xml @@ -1,4 +1,4 @@ - Ur-Quan Masters + Alien Blaster diff --git a/project/sdl/sdl-1.3/src/audio/android/SDL_androidaudio.c b/project/sdl/sdl-1.3/src/audio/android/SDL_androidaudio.c index c0a824f48..31dab93bd 100644 --- a/project/sdl/sdl-1.3/src/audio/android/SDL_androidaudio.c +++ b/project/sdl/sdl-1.3/src/audio/android/SDL_androidaudio.c @@ -182,7 +182,7 @@ static int ANDROIDAUD_OpenAudio (_THIS, SDL_AudioSpec *spec) __android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROIDAUD_OpenAudio(): limiting samples size to ", (int)audioFormat->samples); } - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec(audioFormat); (*jniVM)->AttachCurrentThread(jniVM, &jniEnv, NULL); diff --git a/project/sdl/sdl-1.3/src/video/SDL_video.c b/project/sdl/sdl-1.3/src/video/SDL_video.c index 48fed2f66..567fd0842 100644 --- a/project/sdl/sdl-1.3/src/video/SDL_video.c +++ b/project/sdl/sdl-1.3/src/video/SDL_video.c @@ -3596,4 +3596,35 @@ SDL_SetTextInputRect(SDL_Rect *rect) } } +#ifdef ANDROID +void SDL_ANDROID_VideoContextLost() +{ + SDL_Texture * tex; + if( ! SDL_CurrentDisplay || ! SDL_CurrentRenderer || ! SDL_CurrentRenderer->window || ! SDL_CurrentRenderer->textures || SDL_GetWindowFlags(SDL_CurrentRenderer->window) & SDL_WINDOW_OPENGL ) + return; + + tex = SDL_CurrentRenderer->textures; + while( tex ) + { + SDL_CurrentRenderer->DestroyTexture( SDL_CurrentRenderer, tex ); + tex = tex->next; + } +} + +void SDL_ANDROID_VideoContextRecreated() +{ + SDL_Texture * tex; + if( ! SDL_CurrentDisplay || ! SDL_CurrentRenderer || ! SDL_CurrentRenderer->window || ! SDL_CurrentRenderer->textures || SDL_GetWindowFlags(SDL_CurrentRenderer->window) & SDL_WINDOW_OPENGL ) + return; + + tex = SDL_CurrentRenderer->textures; + SDL_SelectRenderer(SDL_CurrentRenderer->window); /* Re-apply glOrtho() and blend modes */ + while( tex ) + { + SDL_CurrentRenderer->CreateTexture( SDL_CurrentRenderer, tex ); + tex = tex->next; + } +} +#endif + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo-1.3.c b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo-1.3.c index 0a40b6cb2..2c08f868f 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo-1.3.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo-1.3.c @@ -183,3 +183,4 @@ void ANDROID_GL_DeleteContext (_THIS, SDL_GLContext context) { }; + diff --git a/project/src/Accelerometer.java b/project/src/Accelerometer.java index 8fa80d363..8218593d2 100644 --- a/project/src/Accelerometer.java +++ b/project/src/Accelerometer.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import android.app.Activity; import android.content.Context; diff --git a/project/src/AssetExtract.java b/project/src/AssetExtract.java index def4a9179..72f535f7e 100644 --- a/project/src/AssetExtract.java +++ b/project/src/AssetExtract.java @@ -1,6 +1,6 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change // spaces amount -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import java.util.zip.*; import java.io.*; diff --git a/project/src/Audio.java b/project/src/Audio.java index e0ded530d..a7a3bf744 100644 --- a/project/src/Audio.java +++ b/project/src/Audio.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import android.app.Activity; diff --git a/project/src/DataDownloader.java b/project/src/DataDownloader.java index 973ab3d38..8362a8d44 100644 --- a/project/src/DataDownloader.java +++ b/project/src/DataDownloader.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import android.app.Activity; import android.content.Context; diff --git a/project/src/GLSurfaceView_SDL.java b/project/src/GLSurfaceView_SDL.java index 0a386f23e..31e6563d7 100644 --- a/project/src/GLSurfaceView_SDL.java +++ b/project/src/GLSurfaceView_SDL.java @@ -18,7 +18,7 @@ fixed with a hammer and rasp to work with libSDL port */ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import java.io.Writer; import java.util.ArrayList; diff --git a/project/src/Globals.java b/project/src/Globals.java index 75fdf8e57..4a48484e5 100644 --- a/project/src/Globals.java +++ b/project/src/Globals.java @@ -1,14 +1,14 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount anywhere -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import android.app.Activity; import android.content.Context; class Globals { - public static String ApplicationName = "Ur-QuanMasters"; + public static String ApplicationName = "AlienBlaster"; // Should be zip file - public static String DataDownloadUrl = "Game data is 14 Mb|https://sites.google.com/site/xpelyax/Home/sc2-data.zip?attredirects=0%26d=1|https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/sc2-data.zip/download|http://sitesproxy.goapk.com/site/xpelyax/Home/sc2-data.zip^3DO remixed music (19 Mb) - enable it in Setup->Sound Options->3DO Remixes|:addons/3domusic/3domusic.zip:https://sites.google.com/site/xpelyax/Home/3domusic.zip?attredirects=0%26d=1|:addons/3domusic/3domusic.zip:https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/3domusic.zip/download|:addons/3domusic/3domusic.zip:http://sitesproxy.goapk.com/site/xpelyax/Home/3domusic.zip^UQM music remix pack (150 Mb) - enable it in Setup->Sound Options->UQM Remixes|:addons/remix/remix.zip:https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/remix.zip/download^3DO voice (115 Mb) - go to Setup->Sound Options and increase Voice volume from zero|:addons/3dovoice/3dovoice.zip:https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/3dovoice.zip/download^3DO video support - after installing this pack copy all files from|https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/3dovideo.zip/download^your 3DO Star Control II game CD from 'duckart' dir to the SD card to dir|https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/3dovideo.zip/download^'app-data/com.sourceforge.sc2/addons/3dovideo', to extract files from 3DO disk use|https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/3dovideo.zip/download^'3DO Commander' or 'uncd-rom' apps from http://madroms.free.fr/3do/|https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/3dovideo.zip/download^Then from the game change 'Setup->PC/3DO compat->Cutscenes' to Movies, and restart game|https://sourceforge.net/projects/libsdl-android/files/Ur-Quan%20Masters/3dovideo.zip/download"; + public static String DataDownloadUrl = "Data size is 2 Mb|http://sites.google.com/site/xpelyax/Home/alienblaster110_data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/alienblaster110_data.zip"; // Set this value to true if you're planning to render 3D using OpenGL - it eats some GFX resources, so disabled for 2D public static boolean NeedDepthBuffer = false; @@ -17,7 +17,7 @@ class Globals { public static boolean HorizontalOrientation = true; // Readme text to be shown on download page - public static String ReadmeText = "^You may press \"Home\" now - the data will be downloaded in background".replace("^","\n"); + public static String ReadmeText = "^You can press \"Home\" now - the data will be downloaded in background^In game press \"Menu\" for secondary fire, \"Volume Up/Down\" to cycle weapons".replace("^","\n"); public static boolean AppUsesMouse = false; @@ -27,9 +27,9 @@ class Globals { public static boolean AppUsesMultitouch = false; - public static int AppTouchscreenKeyboardKeysAmount = 2; + public static int AppTouchscreenKeyboardKeysAmount = 4; - public static int AppTouchscreenKeyboardKeysAmountAutoFire = 2; + public static int AppTouchscreenKeyboardKeysAmountAutoFire = 1; // Phone-specific config // It will download app data to /sdcard/alienblaster if set to true, @@ -48,5 +48,5 @@ class Globals { } class LoadLibrary { - public LoadLibrary() { System.loadLibrary("sdl"); System.loadLibrary("sdl_image"); }; + public LoadLibrary() { System.loadLibrary("sdl"); System.loadLibrary("sdl_mixer"); System.loadLibrary("sdl_image"); }; } diff --git a/project/src/MainActivity.java b/project/src/MainActivity.java index fd8e9ac34..d7addfc83 100644 --- a/project/src/MainActivity.java +++ b/project/src/MainActivity.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import android.app.Activity; import android.content.Context; diff --git a/project/src/Settings.java b/project/src/Settings.java index a9e6bfd0d..007deaa36 100644 --- a/project/src/Settings.java +++ b/project/src/Settings.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import android.app.Activity; import android.content.Context; diff --git a/project/src/Video.java b/project/src/Video.java index 19f1cd062..dcf31b911 100644 --- a/project/src/Video.java +++ b/project/src/Video.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package de.schwardtnet.alienblaster; import javax.microedition.khronos.opengles.GL10;