SDL 1.3 compiles but restoring from background does not work in Alien Blaster

This commit is contained in:
pelya
2010-09-30 18:00:47 +03:00
parent f540aef198
commit f025a0ab9c
26 changed files with 132 additions and 78 deletions

View File

@@ -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=""

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sourceforge.sc2"
android:versionCode="1011"
android:versionName="1.0.11 - game can be put to background with Home button and successfully restored back"
package="de.schwardtnet.alienblaster"
android:versionCode="110010"
android:versionName="1.1.0.10 - fixed restoring application from background"
android:installLocation="preferExternal"
>
<application android:label="@string/app_name"

View File

@@ -1,6 +1,6 @@
# The namespace in Java file, with dots replaced with underscores
SDL_JAVA_PACKAGE_PATH := com_sourceforge_sc2
SDL_JAVA_PACKAGE_PATH := de_schwardtnet_alienblaster
# Path to shared libraries - Android 1.6 cannot load them properly, thus we have to specify absolute path here
# SDL_SHARED_LIBRARIES_PATH := /data/data/de.schwardtnet.alienblaster/lib
@@ -10,7 +10,7 @@ SDL_JAVA_PACKAGE_PATH := com_sourceforge_sc2
# Typically /sdcard/alienblaster
# Or /data/data/de.schwardtnet.alienblaster/files if you're planning to unpack data in application private folder
# Your application will just set current directory there
SDL_CURDIR_PATH := com.sourceforge.sc2
SDL_CURDIR_PATH := de.schwardtnet.alienblaster
# Android Dev Phone G1 has trackball instead of cursor keys, and
# sends trackball movement events as rapid KeyDown/KeyUp events,
@@ -23,17 +23,17 @@ SDL_TRACKBALL_KEYUP_DELAY := 1
# resized in HW-accelerated way, however it eats a tiny bit of CPU
SDL_VIDEO_RENDER_RESIZE := 1
COMPILED_LIBRARIES := sdl_image
COMPILED_LIBRARIES := sdl_mixer sdl_image
APPLICATION_ADDITIONAL_CFLAGS := -O2 -finline-functions -DTHREADLIB_SDL=1 -DTIMELIB=SDL -DOVCODEC_TREMOR=1 -DNETPLAY=1 -DHAVE_REGEX=1 -DHAVE_GETOPT_LONG=1 -DHAVE_ZIP=1
APPLICATION_ADDITIONAL_CFLAGS := -finline-functions -O2
APPLICATION_ADDITIONAL_LDFLAGS := -Lobj/local/armeabi -ltremor
APPLICATION_ADDITIONAL_LDFLAGS :=
APPLICATION_SUBDIRS_BUILD :=
APPLICATION_CUSTOM_BUILD_SCRIPT :=
SDL_ADDITIONAL_CFLAGS := -DSDL_ANDROID_KEYCODE_MOUSE=UNKNOWN -DSDL_ANDROID_KEYCODE_0=RETURN -DSDL_ANDROID_KEYCODE_1=RSHIFT -DSDL_ANDROID_KEYCODE_2=KP_PLUS -DSDL_ANDROID_KEYCODE_3=KP_MINUS -DSDL_ANDROID_KEYCODE_4=ESCAPE -DSDL_ANDROID_KEYCODE_5=F10
SDL_ADDITIONAL_CFLAGS := -DSDL_ANDROID_KEYCODE_MOUSE=UNKNOWN -DSDL_ANDROID_KEYCODE_0=RETURN -DSDL_ANDROID_KEYCODE_1=LCTRL -DSDL_ANDROID_KEYCODE_2=PAGEUP -DSDL_ANDROID_KEYCODE_3=PAGEDOWN -DSDL_ANDROID_KEYCODE_4=LCTRL
# If SDL_Mixer should link to libMAD
SDL_MIXER_USE_LIBMAD :=

View File

@@ -5,6 +5,6 @@ APP_PROJECT_PATH := $(call my-dir)/..
# sdl_image depends on png and jpeg
# sdl_ttf depends on freetype
APP_MODULES := application sdl sdl_main stlport tremor png jpeg freetype sdl_image
APP_MODULES := application sdl sdl_main stlport tremor png jpeg freetype sdl_mixer sdl_image
APP_ABI := armeabi

View File

@@ -1,4 +1,5 @@
AppSettingVersion=6
# The application settings for Android libSDL port
AppSettingVersion=8
LibSdlVersion=1.3
AppName="Alien Blaster"
AppFullName=de.schwardtnet.alienblaster
@@ -14,9 +15,11 @@ RedefinedKeys="RETURN LCTRL PAGEUP PAGEDOWN LCTRL"
AppTouchscreenKeyboardKeysAmount=4
AppTouchscreenKeyboardKeysAmountAutoFire=1
MultiABI=n
AppVersionCode=110009
AppVersionName="1.1.0.09"
AppVersionCode=110010
AppVersionName="1.1.0.10 - fixed restoring application from background"
CompiledLibraries="sdl_mixer sdl_image"
CustomBuildScript=n
AppCflags='-finline-functions -O2'
AppLdflags=''
AppSubdirsBuild=''
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'

View File

@@ -18,55 +18,24 @@
struct SdlCompat_AcceleratedSurface
{
SDL_Texture * t;
SDL_Surface * s;
int w, h;
int flags;
SDL_PixelFormat * format;
};
static inline SdlCompat_AcceleratedSurface * SdlCompat_CreateAcceleratedSurface(SDL_Surface * surface)
{
SdlCompat_AcceleratedSurface * ret = new SdlCompat_AcceleratedSurface();
// Allocate accelerated surface even if that means loss of color quality
Uint32 format;
/*
if( surface->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

View File

@@ -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 <stdlib.h>
#include <android/log.h>
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);

View File

@@ -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 );
}
};

View File

@@ -51,6 +51,8 @@ class SurfaceDB {
SdlCompat_AcceleratedSurface *loadSurface( std::string fn, bool alpha=false );
void reloadAllSurfacesToVideoMemory();
private:
StringSurfaceMap surfaceDB;
Uint8 transR, transG, transB;

View File

@@ -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() {

View File

@@ -32,7 +32,6 @@ class Video {
private:
SdlCompat_AcceleratedSurface *screen;
SdlCompat_AcceleratedSurface *empty;
public:
Video();

View File

@@ -1 +1 @@
sc2
alienblaster

View File

@@ -1 +1 @@
../sdl/sdl-1.2
../sdl/sdl-1.3

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Ur-Quan Masters</string>
<string name="app_name">Alien Blaster</string>
</resources>

View File

@@ -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);

View File

@@ -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: */

View File

@@ -183,3 +183,4 @@ void ANDROID_GL_DeleteContext (_THIS, SDL_GLContext context)
{
};

View File

@@ -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;

View File

@@ -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.*;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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"); };
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;