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

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