True HW acceleration for Alien Blaster - it now runs 45 FPS on ADP1,

and 30 FPS on HTC Evo (it could run faster but they limited max FPS in GL renderer).
See file SdlForwardCompat.h to have an idea how to make your SDL 1.2 app HW accelerated with SDL 1.3 -
it's a compilation of hacks but whatever.
This commit is contained in:
pelya
2010-07-06 13:57:58 +03:00
parent 616cc0b5fd
commit 99698187cf
61 changed files with 401 additions and 230 deletions

View File

@@ -0,0 +1,122 @@
/*
Compatibility wrapper to compile the same code on both SDL 1.2 and 1.3 without many #ifdefs
*/
#ifndef __SDL_FORWARD_COMPAT_H__
#define __SDL_FORWARD_COMPAT_H__
#include <SDL.h>
#include <SDL_video.h>
#include <SDL_version.h>
#ifndef __cplusplus
#error "This header is for C++ only, you're unlucky, sorry"
#endif
#if SDL_VERSION_ATLEAST(1,3,0)
struct SdlCompat_AcceleratedSurface
{
SDL_Texture * t;
int w, h;
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);
}
ret->w = surface->w;
ret->h = surface->h;
if( ! ret->t )
{
SDL_SetError("SdlCompat_CreateAcceleratedSurface: Cannot allocate HW texture, W %d H %d format %x surface->flags %x", ret->w, ret->h, format, surface->flags );
}
ret->format = new SDL_PixelFormat();
*(ret->format) = *(surface->format);
return ret;
};
static inline int SDL_BlitSurface( SdlCompat_AcceleratedSurface * src, SDL_Rect * srcR, SdlCompat_AcceleratedSurface * unused, SDL_Rect * destR )
{
return SDL_RenderCopy(src->t, srcR, destR);
};
static inline void SDL_FreeSurface(SdlCompat_AcceleratedSurface * surface)
{
delete surface->format;
delete surface;
};
static inline void SDL_FillRect( SdlCompat_AcceleratedSurface * unused, const SDL_Rect* rect, Uint32 color )
{
Uint8 r, g, b, a;
SDL_GetRGBA( color, SDL_GetVideoSurface()->format, &r, &g, &b, &a );
SDL_SetRenderDrawColor(r, g, b, a);
SDL_RenderDrawRect(rect);
};
static inline int SDL_Flip(SdlCompat_AcceleratedSurface * unused)
{
SDL_RenderPresent();
return 0;
};
static inline int SDL_SetAlpha(SdlCompat_AcceleratedSurface * surface, Uint32 flag, Uint8 alpha)
{
if( ! (flag & SDL_SRCALPHA) )
alpha = SDL_ALPHA_OPAQUE;
return SDL_SetTextureAlphaMod(surface->t, alpha);
};
#else
// TODO: did not check if SDL 1.2 part compiles
typedef SDL_Surface SdlCompat_AcceleratedSurface;
static inline SdlCompat_AcceleratedSurface * SdlCompat_CreateAcceleratedSurface(SDL_Surface * surface)
{
return SDL_ConvertSurface(surface, surface->format, 0); // Just copy it
};
#endif
#endif

View File

@@ -52,10 +52,10 @@ void Background::generateBackground( int length ) {
minTileHeight = 9999999;
// load all tiles
vector< SDL_Surface* > tmpTiles;
vector< SdlCompat_AcceleratedSurface* > tmpTiles;
for(int i=tileNames.size()-1; i>=0; i--) {
SDL_Surface *tile = surfaceDB.loadSurface( tileNames[i] );
SdlCompat_AcceleratedSurface *tile = surfaceDB.loadSurface( tileNames[i] );
if (tile != NULL) {
tmpTiles.push_back( tile );
@@ -92,13 +92,13 @@ void Background::generateBackground( int length ) {
}
void Background::draw( SDL_Surface* screen ) {
void Background::draw( SdlCompat_AcceleratedSurface* screen ) {
step = (step+1) % (tilesPerColumn*minTileHeight);
draw( screen, step );
}
void Background::draw( SDL_Surface* screen, int step ) {
void Background::draw( SdlCompat_AcceleratedSurface* screen, int step ) {
if (step < 0) {
step *= -1;
}

View File

@@ -22,8 +22,7 @@
#include <vector>
#include <string>
class SDL_Surface;
#include "SdlForwardCompat.h"
class Background {
public:
@@ -32,8 +31,8 @@ class Background {
void clearTileList();
void addTile( std::string tilename );
void generateBackground( int length );
void draw( SDL_Surface* screen );
void draw( SDL_Surface* screen, int step );
void draw( SdlCompat_AcceleratedSurface* screen );
void draw( SdlCompat_AcceleratedSurface* screen, int step );
private:
@@ -44,7 +43,7 @@ class Background {
int step;
std::vector< std::string > tileNames;
std::vector< SDL_Surface* > tileSurfaces;
std::vector< SdlCompat_AcceleratedSurface* > tileSurfaces;
};

View File

@@ -104,7 +104,7 @@ bool Banner::movingAway() {
return ( 3000 <= timeLived );
}
void Banner::draw(SDL_Surface *screen) {
void Banner::draw(SdlCompat_AcceleratedSurface *screen) {
SDL_Rect r;
r.x = lroundf(pos.getX());
r.y = lroundf(pos.getY());

View File

@@ -26,8 +26,8 @@
#include "global.h"
class Banner {
SDL_Surface *sprite;
SDL_Surface *spriteBonus;
SdlCompat_AcceleratedSurface *sprite;
SdlCompat_AcceleratedSurface *spriteBonus;
int sound;
@@ -42,7 +42,7 @@ class Banner {
~Banner();
void update( int dT );
void draw( SDL_Surface *screen );
void draw( SdlCompat_AcceleratedSurface *screen );
bool isExpired();
bool movingAway();
};

View File

@@ -73,7 +73,7 @@ void Banners::update( int dT ) {
}
}
void Banners::draw(SDL_Surface *screen) {
void Banners::draw(SdlCompat_AcceleratedSurface *screen) {
switch ( banners.size() ) {
case 0: break;
case 1: banners[0]->draw( screen ); break;

View File

@@ -39,7 +39,7 @@ class Banners {
void expireBanners();
void deleteAllBanners();
void update( int dT );
void draw(SDL_Surface *screen);
void draw(SdlCompat_AcceleratedSurface *screen);
};

View File

@@ -474,7 +474,7 @@ void Enemy::doDamage( ShotTypes shotType, int fromWhichPlayer ) {
}
void Enemy::drawGroundEnemy( SDL_Surface *screen ) {
void Enemy::drawGroundEnemy( SdlCompat_AcceleratedSurface *screen ) {
if ( ENEMY_FLYING[ enemyType ] ) return;
SDL_Rect destR;
@@ -487,7 +487,7 @@ void Enemy::drawGroundEnemy( SDL_Surface *screen ) {
SDL_BlitSurface( spriteEnemy, 0, screen, &destR );
}
void Enemy::drawAirEnemy( SDL_Surface *screen ) {
void Enemy::drawAirEnemy( SdlCompat_AcceleratedSurface *screen ) {
if ( !ENEMY_FLYING[ enemyType ] ) return;
SDL_Rect destR;
@@ -500,7 +500,7 @@ void Enemy::drawAirEnemy( SDL_Surface *screen ) {
SDL_BlitSurface( spriteEnemy, 0, screen, &destR );
}
void Enemy::drawShadow( SDL_Surface *screen ) {
void Enemy::drawShadow( SdlCompat_AcceleratedSurface *screen ) {
if ( !ENEMY_FLYING[ enemyType ] ) return;
SDL_Rect destR;
@@ -514,7 +514,7 @@ void Enemy::drawShadow( SDL_Surface *screen ) {
}
void Enemy::drawStats( SDL_Surface *screen ) {
void Enemy::drawStats( SdlCompat_AcceleratedSurface *screen ) {
// draw status of the bosses
float pixPerHP = spriteEnemy->w / (float)(ENEMY_HITPOINTS[ enemyType ]);
SDL_Rect destR;

View File

@@ -32,8 +32,8 @@ class BoundingBox;
class Enemy {
private:
SDL_Surface *spriteEnemy;
SDL_Surface *spriteShadow;
SdlCompat_AcceleratedSurface *spriteEnemy;
SdlCompat_AcceleratedSurface *spriteShadow;
// for collision with racers or shots.
// A rectangle with racersize * 0.9 is used.
BoundingBox *boundingBox;
@@ -97,10 +97,10 @@ class Enemy {
void updateBoundingBox();
public:
void drawGroundEnemy( SDL_Surface *screen );
void drawAirEnemy( SDL_Surface *screen );
void drawShadow( SDL_Surface *screen );
void drawStats( SDL_Surface *screen );
void drawGroundEnemy( SdlCompat_AcceleratedSurface *screen );
void drawAirEnemy( SdlCompat_AcceleratedSurface *screen );
void drawShadow( SdlCompat_AcceleratedSurface *screen );
void drawStats( SdlCompat_AcceleratedSurface *screen );
// collision system
// return if the line between the two points collides with the boundingBox

View File

@@ -208,13 +208,13 @@ void Enemys::generateEnemys( int dT ) {
}
case TANK:
{
// SDL_Surface *spriteTank = surfaceDB.loadSurface( FN_ENEMY_TANK );
// SDL_Surface *spriteTankWreck = surfaceDB.loadSurface( FN_WRECK_TANK );
// SdlCompat_AcceleratedSurface *spriteTank = surfaceDB.loadSurface( FN_ENEMY_TANK );
// SdlCompat_AcceleratedSurface *spriteTankWreck = surfaceDB.loadSurface( FN_WRECK_TANK );
string fn1, fn2;
levelConf->getStr( LVL_ENEMY_TANK, fn1 );
levelConf->getStr( LVL_WRECK_TANK, fn2 );
SDL_Surface *spriteTank = surfaceDB.loadSurface( fn1 );
SDL_Surface *spriteTankWreck = surfaceDB.loadSurface( fn2 );
SdlCompat_AcceleratedSurface *spriteTank = surfaceDB.loadSurface( fn1 );
SdlCompat_AcceleratedSurface *spriteTankWreck = surfaceDB.loadSurface( fn2 );
int halfWidthTank = spriteTank->w / 2;
int halfHeightTank = spriteTank->h / 2;
int halfWidthTankWreck = spriteTankWreck->w / 2;
@@ -338,28 +338,28 @@ void Enemys::deleteExpiredEnemys() {
}
}
void Enemys::drawGroundEnemys(SDL_Surface *screen) {
void Enemys::drawGroundEnemys(SdlCompat_AcceleratedSurface *screen) {
vector<Enemy *>::iterator i;
for (i = enemys.begin(); i != enemys.end(); ++i) {
(*i)->drawGroundEnemy(screen);
}
}
void Enemys::drawAirEnemys(SDL_Surface *screen) {
void Enemys::drawAirEnemys(SdlCompat_AcceleratedSurface *screen) {
vector<Enemy *>::iterator i;
for (i = enemys.begin(); i != enemys.end(); ++i) {
(*i)->drawAirEnemy(screen);
}
}
void Enemys::drawShadows(SDL_Surface *screen) {
void Enemys::drawShadows(SdlCompat_AcceleratedSurface *screen) {
vector<Enemy *>::iterator i;
for (i = enemys.begin(); i != enemys.end(); ++i) {
(*i)->drawShadow(screen);
}
}
void Enemys::drawBossStats( SDL_Surface *screen ) {
void Enemys::drawBossStats( SdlCompat_AcceleratedSurface *screen ) {
for ( unsigned int i = 0; i < enemys.size(); i++ ) {
if ( enemys[ i ]->getType() >= NR_ENEMY_TYPES_NORMAL ) {
enemys[ i ]->drawStats( screen );
@@ -367,7 +367,7 @@ void Enemys::drawBossStats( SDL_Surface *screen ) {
}
}
void Enemys::drawAllStats( SDL_Surface *screen ) {
void Enemys::drawAllStats( SdlCompat_AcceleratedSurface *screen ) {
for ( unsigned int i = 0; i < enemys.size(); i++ ) {
enemys[ i ]->drawStats( screen );
}

View File

@@ -67,11 +67,11 @@ class Enemys {
void doNukeDamage();
// draws the enemys.
void drawGroundEnemys( SDL_Surface *screen );
void drawAirEnemys( SDL_Surface *screen );
void drawShadows( SDL_Surface *screen );
void drawBossStats( SDL_Surface *screen );
void drawAllStats( SDL_Surface *screen );
void drawGroundEnemys( SdlCompat_AcceleratedSurface *screen );
void drawAirEnemys( SdlCompat_AcceleratedSurface *screen );
void drawShadows( SdlCompat_AcceleratedSurface *screen );
void drawBossStats( SdlCompat_AcceleratedSurface *screen );
void drawAllStats( SdlCompat_AcceleratedSurface *screen );
};
#endif

View File

@@ -70,7 +70,7 @@ void Explosion::update( int dT ) {
}
}
void Explosion::drawAirExplosion(SDL_Surface *screen) {
void Explosion::drawAirExplosion(SdlCompat_AcceleratedSurface *screen) {
if (expired) return;
if ( ! ( explosionType == EXPLOSION_NORMAL_AIR ) ) return;
@@ -89,7 +89,7 @@ void Explosion::drawAirExplosion(SDL_Surface *screen) {
SDL_BlitSurface( sprite, &src, screen, &dest );
}
void Explosion::drawGroundExplosion(SDL_Surface *screen) {
void Explosion::drawGroundExplosion(SdlCompat_AcceleratedSurface *screen) {
if (expired) return;
if ( ! ( explosionType == EXPLOSION_NORMAL_GROUND ) ) return;

View File

@@ -29,7 +29,7 @@ class Explosion {
// a sprite, that contains horizontally all animationframes of the explosion.
// it is assumed, that every frame is quadratic.
SDL_Surface *sprite;
SdlCompat_AcceleratedSurface *sprite;
// how many frames does this explosion have?
int nrAnimStages;
@@ -57,8 +57,8 @@ class Explosion {
~Explosion();
// updates the position and the counters
void update( int dT );
void drawAirExplosion(SDL_Surface *screen);
void drawGroundExplosion(SDL_Surface *screen);
void drawAirExplosion(SdlCompat_AcceleratedSurface *screen);
void drawGroundExplosion(SdlCompat_AcceleratedSurface *screen);
bool isExpired() { return expired; }
};

View File

@@ -38,14 +38,14 @@ void Explosions::addExplosion(Explosion *explosion) {
}
}
void Explosions::drawAirExplosions(SDL_Surface *screen) {
void Explosions::drawAirExplosions(SdlCompat_AcceleratedSurface *screen) {
vector<Explosion *>::iterator i;
for (i = explosions.begin(); i != explosions.end(); ++i) {
(*i)->drawAirExplosion(screen);
}
}
void Explosions::drawGroundExplosions(SDL_Surface *screen) {
void Explosions::drawGroundExplosions(SdlCompat_AcceleratedSurface *screen) {
vector<Explosion *>::iterator i;
for (i = explosions.begin(); i != explosions.end(); ++i) {
(*i)->drawGroundExplosion(screen);

View File

@@ -22,6 +22,7 @@
#include <vector>
#include "SDL.h"
#include "SdlForwardCompat.h"
class Explosion;
@@ -41,8 +42,8 @@ class Explosions {
// deletes the explosions, that have timed out
void expireExplosions();
// draws all explosions
void drawAirExplosions( SDL_Surface *screen );
void drawGroundExplosions( SDL_Surface *screen );
void drawAirExplosions( SdlCompat_AcceleratedSurface *screen );
void drawGroundExplosions( SdlCompat_AcceleratedSurface *screen );
};
#endif

View File

@@ -25,11 +25,13 @@ using namespace std;
#include <iostream>
Font::Font(string fn) {
sprite = surfaceDB.loadSurface( fn );
sprites[0] = surfaceDB.loadSurface( fn + "-1.bmp" );
sprites[1] = surfaceDB.loadSurface( fn + "-2.bmp" );
sprites[2] = surfaceDB.loadSurface( fn + "-3.bmp" );
charset = " ABCDEFGHIJKLMNOPQRSTUVWXYZÜÄÖabcdefghijklmnopqrstuvwxyzüäöß0123456789!\"§$%&/()=?*+'#,.-;:_@°\\";
// 94 Zeichen
charWidth = sprite->w / 94;
charHeight = sprite->h;
charWidth = sprites[0]->w / MAX_CHARS_PER_TEXTURE;
charHeight = sprites[0]->h;
}
Font::~Font() {
@@ -45,10 +47,10 @@ int Font::getCharWidth() {
}
int Font::getCharHeight() {
return sprite->h;
return sprites[0]->h;
}
void Font::drawInt(SDL_Surface *screen, int posx, int posy, int val, int alignDigitCnt, int flags) {
void Font::drawInt(SdlCompat_AcceleratedSurface *screen, int posx, int posy, int val, int alignDigitCnt, int flags) {
int indent = 0;
int digitCnt = 1;
int i=1;
@@ -85,17 +87,16 @@ void Font::drawInt(SDL_Surface *screen, int posx, int posy, int val, int alignDi
destR.h = charHeight;
unsigned int charsetpos = charset.find( (char)((val % 10) + '0') );
if (charsetpos != string::npos ) {
srcR.x = charsetpos * charWidth;
} else {
srcR.x = charWidth;
}
if (charsetpos == string::npos )
charsetpos = 0; // Space
srcR.x = (charsetpos % MAX_CHARS_PER_TEXTURE) * charWidth;
// srcR.x = (1 + 2*26 + (val % 10)) * charWidth;
srcR.y = 0;
srcR.w = charWidth;
srcR.h = charHeight;
SDL_BlitSurface( sprite, &srcR, screen, &destR );
SDL_BlitSurface( sprites[charsetpos / MAX_CHARS_PER_TEXTURE], &srcR, screen, &destR );
}
val /= 10;
digitCnt--;
@@ -105,7 +106,7 @@ void Font::drawInt(SDL_Surface *screen, int posx, int posy, int val, int alignDi
void Font::drawStr(SDL_Surface *screen, int posx, int posy, const string &text, int flags) {
void Font::drawStr(SdlCompat_AcceleratedSurface *screen, int posx, int posy, const string &text, int flags) {
int indent = 0;
if ( flags & (FONT_ALIGN_CENTERED | FONT_ALIGN_RIGHT) ) {
@@ -131,21 +132,21 @@ void Font::drawStr(SDL_Surface *screen, int posx, int posy, const string &text,
for(unsigned int i=0; i < text.size(); ++i) {
x = 0;
charsetpos = charset.find(text[i]);
if (charsetpos != string::npos ) {
x = charsetpos * charWidth;
}
if (charsetpos == string::npos )
charsetpos = 0; // Space
x = (charsetpos % MAX_CHARS_PER_TEXTURE) * charWidth;
destR.x = posx + indent;
destR.y = posy;
destR.w = charWidth;
destR.h = sprite->h;
destR.h = sprites[0]->h;
srcR.x = x;
srcR.y = 0;
srcR.w = charWidth;
srcR.h = sprite->h;
srcR.h = sprites[0]->h;
SDL_BlitSurface( sprite, &srcR, screen, &destR );
SDL_BlitSurface( sprites[charsetpos / MAX_CHARS_PER_TEXTURE], &srcR, screen, &destR );
if (!(flags & FONT_MONOSPACE) && text[i] == ' ') {
posx += ((charWidth * 2) / 3);

View File

@@ -22,6 +22,7 @@
#include "SDL.h"
#include <string>
#include "SdlForwardCompat.h"
// *** Code ***
//
@@ -58,7 +59,8 @@ const int FONT_MONOSPACE = (1<<3);
class Font {
private:
SDL_Surface *sprite;
enum { MAX_CHARS_PER_TEXTURE = 32 }; // OpenGL ES does not allow textures wider than 1024 bytes, so we have to split it
SdlCompat_AcceleratedSurface *sprites[3]; // Our font has only 94 letters
int charWidth;
int charHeight;
std::string charset;
@@ -70,8 +72,8 @@ class Font {
void setCharWidth(int width);
int getCharWidth();
int getCharHeight();
void drawInt(SDL_Surface *screen, int posx, int posy, int val, int alignDigitCnt, int flags = 0);
void drawStr(SDL_Surface *screen, int posx, int posy, const std::string &text, int flags = 0);
void drawInt(SdlCompat_AcceleratedSurface *screen, int posx, int posy, int val, int alignDigitCnt, int flags = 0);
void drawStr(SdlCompat_AcceleratedSurface *screen, int posx, int posy, const std::string &text, int flags = 0);
};
#endif

View File

@@ -22,6 +22,7 @@ using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sstream>
#include <android/log.h>
#include "SDL.h"
@@ -140,7 +141,7 @@ Game::Game() {
__android_log_print(ANDROID_LOG_INFO, "Alien Blaster", "Game() 9");
SDL_Surface *loadingSprite = surfaceDB.loadSurface( FN_LOADING );
SdlCompat_AcceleratedSurface *loadingSprite = surfaceDB.loadSurface( FN_LOADING );
__android_log_print(ANDROID_LOG_INFO, "Alien Blaster", "Game() 10");
SDL_Rect dest;
dest.x = (SCREEN_WIDTH - loadingSprite->w ) / 2;
@@ -337,8 +338,13 @@ void Game::playOn() {
int A = SDL_GetTicks();
frameCnt = 0;
tickCnt = 0;
cout << "frameCnt: " << frameCnt << " tickCnt: " << tickCnt
<< " SDL_GetTicks()=" << A << endl;
{
std::ostringstream logout;
logout << "frameCnt: " << frameCnt << " tickCnt: " << tickCnt
<< " SDL_GetTicks()=" << A;
__android_log_print(ANDROID_LOG_INFO, "Alien Blaster", logout.str().c_str());
}
while ( gameState == GS_PLAYON ) {
handleEventsPlayOn();
@@ -365,12 +371,17 @@ void Game::playOn() {
if ( racers->bothPlayersLost() ) gameState = GS_ROUNDFINISHED;
}
int B = SDL_GetTicks();
cout << "frameCnt: " << frameCnt << " tickCnt: " << tickCnt
<< " SDL_GetTicks()=" << B << endl;
cout << "Miliseconds: " << B-A << endl;
cout << "Frames/sec : " << (float)frameCnt / ((float)(B-A) / 1000.0) << endl;
cout << "ms/Frame : " << (float)tickCnt / (float)frameCnt << endl;
{
std::ostringstream logout;
int B = SDL_GetTicks();
logout << "frameCnt: " << frameCnt << " tickCnt: " << tickCnt
<< " SDL_GetTicks()=" << B << endl;
logout << "Milliseconds: " << B-A << endl;
logout << "Frames/sec : " << (float)frameCnt / ((float)(B-A) / 1000.0) << endl;
logout << "ms/Frame : " << (float)tickCnt / (float)frameCnt << endl;
__android_log_print(ANDROID_LOG_INFO, "Alien Blaster", logout.str().c_str());
}
}
@@ -636,9 +647,11 @@ void Game::drawNukeEffect() {
// effect-process: transparent -> nearly opaque -> transparent
int timeFromMaximum = (NUKE_EFFECT_DURATION / 2) - (timeNukeEnd - SDL_GetTicks());
timeFromMaximum = abs(timeFromMaximum);
SDL_SetAlpha( nukeEffectSurface, SDL_SRCALPHA | SDL_RLEACCEL,
lroundf(((NUKE_EFFECT_DURATION / 2) - timeFromMaximum) * 128.0 /
(NUKE_EFFECT_DURATION / 2)) );
SDL_BlitSurface( nukeEffectSurface, 0, screen, 0 );
int randRange = (int)

View File

@@ -21,8 +21,10 @@
#define GAME_HH
#include "SDL.h"
#include "SdlForwardCompat.h"
#include <string>
class Video;
class SurfaceDB;
class Racers;
@@ -46,14 +48,14 @@ enum GameStates { GS_QUIT, GS_SCREENSHOTS, GS_INTRO, GS_SET_DIFFICULTY,
game objects and their dependencies. */
class Game {
// Video system
SDL_Surface *screen;
SdlCompat_AcceleratedSurface *screen;
SDL_Surface *pauseSprite;
SDL_Surface *youLoseSprite;
SDL_Surface *youWinSprite;
SDL_Surface *gameOverSprite;
SDL_Surface *nukeEffectSurface;
SDL_Surface *hud;
SdlCompat_AcceleratedSurface *pauseSprite;
SdlCompat_AcceleratedSurface *youLoseSprite;
SdlCompat_AcceleratedSurface *youWinSprite;
SdlCompat_AcceleratedSurface *gameOverSprite;
SdlCompat_AcceleratedSurface *nukeEffectSurface;
SdlCompat_AcceleratedSurface *hud;
// Time system
Font *fontTime;

View File

@@ -366,8 +366,8 @@ void initAllSurfaces() {
surfaceDB.loadSurface("./images/lightFighterShieldDamaged.bmp");
surfaceDB.loadSurface("./images/heavyFighterShieldDamaged.bmp");
surfaceDB.loadSurface("./images/heavyFighterDeflector.bmp", true);
surfaceDB.loadSurface("./images/font-20red.bmp");
surfaceDB.loadSurface("./images/font-20blue.bmp");
//surfaceDB.loadSurface("./images/font-20red");
//surfaceDB.loadSurface("./images/font-20blue");
surfaceDB.loadSurface("./images/explosion.bmp");
surfaceDB.loadSurface("./images/explosionEnemy.bmp");
surfaceDB.loadSurface("./images/bannerExcellent.bmp", true);

View File

@@ -21,6 +21,7 @@
#define GLOBAL_H
#include <string>
#include "SdlForwardCompat.h"
class Racers;
class Enemys;
@@ -617,16 +618,16 @@ const std::string FN_INTRO_SHOW_CHOICE = "./images/menuIcon.bmp";
const std::string FN_FONT_PATH = "./images/";
const std::string FN_FONT_SUFFIX_SURFACE = ".bmp";
const std::string FN_FONT_INTRO = "./images/font-20white.bmp";
const std::string FN_FONT_INTRO_HIGHLIGHTED = "./images/font-20lightblue.bmp";
const std::string FN_FONT_NUMBERS_TIME = "./images/font-20red.bmp";
const std::string FN_FONT_NUMBERS_LEFT = "./images/font-20red.bmp";
const std::string FN_FONT_NUMBERS_RIGHT = "./images/font-20blue.bmp";
const std::string FN_FONT_SETTINGS = "./images/font-20white.bmp";
const std::string FN_FONT_SETTINGS_HIGHLIGHTED = "./images/font-20lightblue.bmp";
const std::string FN_FONT_SETTINGS_SMALL = "./images/font-14white.bmp";
const std::string FN_FONT_SETTINGS_SMALL_BLUE = "./images/font-14lightblue.bmp";
const std::string FN_FONT_SETTINGS_SMALL_HIGHLIGHTED = "./images/font-14red.bmp";
const std::string FN_FONT_INTRO = "./images/font-20white";
const std::string FN_FONT_INTRO_HIGHLIGHTED = "./images/font-20lightblue";
const std::string FN_FONT_NUMBERS_TIME = "./images/font-20red";
const std::string FN_FONT_NUMBERS_LEFT = "./images/font-20red";
const std::string FN_FONT_NUMBERS_RIGHT = "./images/font-20blue";
const std::string FN_FONT_SETTINGS = "./images/font-20white";
const std::string FN_FONT_SETTINGS_HIGHLIGHTED = "./images/font-20lightblue";
const std::string FN_FONT_SETTINGS_SMALL = "./images/font-14white";
const std::string FN_FONT_SETTINGS_SMALL_BLUE = "./images/font-14lightblue";
const std::string FN_FONT_SETTINGS_SMALL_HIGHLIGHTED = "./images/font-14red";
const std::string FN_SETTINGS_BLUE = "./images/bluePlain.bmp";
const std::string FN_SETTINGS_WHITE = "./images/whitePlain.bmp";

View File

@@ -30,7 +30,7 @@ using namespace std;
Items *infoscreenItems;
Infoscreen::Infoscreen( SDL_Surface *scr ) {
Infoscreen::Infoscreen( SdlCompat_AcceleratedSurface *scr ) {
screen = scr;
font = new Font( FN_FONT_INTRO );
fontHighlighted = new Font( FN_FONT_INTRO_HIGHLIGHTED );
@@ -61,7 +61,7 @@ void Infoscreen::run() {
}
}
void Infoscreen::putBitmapAtPosition( int x, int y, SDL_Surface* bitmap ) {
void Infoscreen::putBitmapAtPosition( int x, int y, SdlCompat_AcceleratedSurface* bitmap ) {
SDL_Rect d;
d.x = x - bitmap->w / 2;
d.y = y - bitmap->h / 2;

View File

@@ -66,12 +66,12 @@ const int NR_INFOSCREEN_CHOICES = 15;
class Infoscreen {
private:
SDL_Surface *screen;
SDL_Surface *activeChoiceSprite;
SDL_Surface *lightFighterIcon1;
SDL_Surface *lightFighterIcon2;
SDL_Surface *heavyFighterIcon1;
SDL_Surface *heavyFighterIcon2;
SdlCompat_AcceleratedSurface *screen;
SdlCompat_AcceleratedSurface *activeChoiceSprite;
SdlCompat_AcceleratedSurface *lightFighterIcon1;
SdlCompat_AcceleratedSurface *lightFighterIcon2;
SdlCompat_AcceleratedSurface *heavyFighterIcon1;
SdlCompat_AcceleratedSurface *heavyFighterIcon2;
Font *font;
Font *fontHighlighted;
Item *newItem;
@@ -83,14 +83,14 @@ class Infoscreen {
int choose, confirm;
public:
Infoscreen( SDL_Surface *scr );
Infoscreen( SdlCompat_AcceleratedSurface *scr );
~Infoscreen();
void run();
private:
void handleEvents();
void draw();
void putBitmapAtPosition( int x, int y, SDL_Surface* bitmap );
void putBitmapAtPosition( int x, int y, SdlCompat_AcceleratedSurface* bitmap );
};
#endif

View File

@@ -30,7 +30,7 @@ using namespace std;
#include "settings.h"
#include "infoscreen.h"
Intro::Intro( SDL_Surface *scr ) {
Intro::Intro( SdlCompat_AcceleratedSurface *scr ) {
__android_log_print(ANDROID_LOG_INFO, "Alien Blaster", "Intro() 1");
screen = scr;
__android_log_print(ANDROID_LOG_INFO, "Alien Blaster", "Intro() 2");
@@ -184,17 +184,19 @@ void Intro::showScreenshots() {
Mixer::mixer().playMusic( MUSIC_INTRO, -1, 1000 );
}
SDL_Surface *surfS = SDL_LoadBMP( FN_ALIENBLASTER_INTRO.c_str() );
SDL_Surface *surf0 = SDL_LoadBMP( FN_SCREENSHOT0.c_str() );
SDL_Surface *surf1 = SDL_LoadBMP( FN_SCREENSHOT1.c_str() );
SDL_Surface *surf2 = SDL_LoadBMP( FN_SCREENSHOT2.c_str() );
SDL_Surface *surf3 = SDL_LoadBMP( FN_SCREENSHOT3.c_str() );
SDL_Surface *surf4 = SDL_LoadBMP( FN_SCREENSHOT4.c_str() );
SDL_Surface *surf5 = SDL_LoadBMP( FN_SCREENSHOT5.c_str() );
SDL_Surface *surf6 = SDL_LoadBMP( FN_SCREENSHOT6.c_str() );
SDL_Surface *surf7 = SDL_LoadBMP( FN_SCREENSHOT7.c_str() );
SDL_Surface *surf8 = SDL_LoadBMP( FN_SCREENSHOT8.c_str() );
SDL_Surface *surf9 = SDL_LoadBMP( FN_SCREENSHOT9.c_str() );
// TODO: Too lazy to fix that
/*
SdlCompat_AcceleratedSurface *surfS = SDL_LoadBMP( FN_ALIENBLASTER_INTRO.c_str() );
SdlCompat_AcceleratedSurface *surf0 = SDL_LoadBMP( FN_SCREENSHOT0.c_str() );
SdlCompat_AcceleratedSurface *surf1 = SDL_LoadBMP( FN_SCREENSHOT1.c_str() );
SdlCompat_AcceleratedSurface *surf2 = SDL_LoadBMP( FN_SCREENSHOT2.c_str() );
SdlCompat_AcceleratedSurface *surf3 = SDL_LoadBMP( FN_SCREENSHOT3.c_str() );
SdlCompat_AcceleratedSurface *surf4 = SDL_LoadBMP( FN_SCREENSHOT4.c_str() );
SdlCompat_AcceleratedSurface *surf5 = SDL_LoadBMP( FN_SCREENSHOT5.c_str() );
SdlCompat_AcceleratedSurface *surf6 = SDL_LoadBMP( FN_SCREENSHOT6.c_str() );
SdlCompat_AcceleratedSurface *surf7 = SDL_LoadBMP( FN_SCREENSHOT7.c_str() );
SdlCompat_AcceleratedSurface *surf8 = SDL_LoadBMP( FN_SCREENSHOT8.c_str() );
SdlCompat_AcceleratedSurface *surf9 = SDL_LoadBMP( FN_SCREENSHOT9.c_str() );
SDL_BlitSurface( surfS, 0, screen, 0 );
SDL_Flip(screen);
@@ -210,9 +212,12 @@ void Intro::showScreenshots() {
if (blendImages( screen, surf6, 0, surf7, 0, sps ))
if (blendImages( screen, surf7, 0, surf8, 0, sps ))
blendImages( screen, surf8, 0, surf9, 0, sps );
*/
}
bool Intro::blendImages( SDL_Surface *screen, SDL_Surface *surf0, SDL_Rect *r1, SDL_Surface *surf1, SDL_Rect *r2, int sps ) {
// TODO: Too lazy to fix that
/*
bool Intro::blendImages( SdlCompat_AcceleratedSurface *screen, SdlCompat_AcceleratedSurface *surf0, SDL_Rect *r1, SdlCompat_AcceleratedSurface *surf1, SDL_Rect *r2, int sps ) {
SDL_Event event;
int i = 0;
@@ -242,3 +247,4 @@ bool Intro::blendImages( SDL_Surface *screen, SDL_Surface *surf0, SDL_Rect *r1,
}
return true;
}
*/

View File

@@ -22,6 +22,7 @@
#include <string>
#include "SDL.h"
#include "SdlForwardCompat.h"
#include "game.h"
class Font;
@@ -36,9 +37,9 @@ const int NR_INTRO_CHOICES = 6;
class Intro {
private:
SDL_Surface *screen;
SDL_Surface *introSprite;
SDL_Surface *activeChoiceSprite;
SdlCompat_AcceleratedSurface *screen;
SdlCompat_AcceleratedSurface *introSprite;
SdlCompat_AcceleratedSurface *activeChoiceSprite;
Font *font;
Font *fontHighlighted;
Infoscreen *infoscreen;
@@ -50,11 +51,11 @@ class Intro {
int confirm;
public:
Intro( SDL_Surface *scr );
Intro( SdlCompat_AcceleratedSurface *scr );
~Intro();
void run( GameStates &gameState );
void showScreenshots();
bool blendImages( SDL_Surface *screen, SDL_Surface *surf0, SDL_Rect *r1, SDL_Surface *surf1, SDL_Rect *r2, int sps );
// bool blendImages( SdlCompat_AcceleratedSurface *screen, SdlCompat_AcceleratedSurface *surf0, SDL_Rect *r1, SdlCompat_AcceleratedSurface *surf1, SDL_Rect *r2, int sps );
private:
void handleEvents( GameStates &gameState );

View File

@@ -121,7 +121,7 @@ void Item::updateBoundingBox() {
boundingBox->moveLeftBound( lroundf(pos.getX() - sprite->w * 0.5) );
}
void Item::draw(SDL_Surface *screen) {
void Item::draw(SdlCompat_AcceleratedSurface *screen) {
SDL_Rect r;
r.x = lroundf(pos.getX()) - sprite->w / 2;
r.y = lroundf(pos.getY()) - sprite->h / 2;

View File

@@ -28,7 +28,7 @@
class BoundingBox;
class Item {
SDL_Surface *sprite;
SdlCompat_AcceleratedSurface *sprite;
BoundingBox *boundingBox;
Vector2D pos;
@@ -47,7 +47,7 @@ class Item {
void deleteItem();
void draw(SDL_Surface *screen);
void draw(SdlCompat_AcceleratedSurface *screen);
inline bool isExpired() { return (timeLived >= ITEM_LIFETIME); }
inline Vector2D getPos() { return pos; }

View File

@@ -62,7 +62,7 @@ void Items::update( int dT ) {
}
}
void Items::draw(SDL_Surface *screen) {
void Items::draw(SdlCompat_AcceleratedSurface *screen) {
vector<Item *>::iterator i;
for (i = items.begin(); i != items.end(); ++i) {
(*i)->draw(screen);

View File

@@ -40,7 +40,7 @@ class Items {
void generate( int dT );
void expireItems();
void update( int dT );
void draw(SDL_Surface *screen);
void draw(SdlCompat_AcceleratedSurface *screen);
void deleteAllItems();
inline unsigned int getNrItems() { return items.size(); }

View File

@@ -32,7 +32,7 @@ using namespace std;
#include <iostream>
#include <fstream>
MenuArcadeMode::MenuArcadeMode( SDL_Surface *scr ) {
MenuArcadeMode::MenuArcadeMode( SdlCompat_AcceleratedSurface *scr ) {
screen = scr;
arcadeSprite = surfaceDB.loadSurface( FN_ARCADE_LOGO );
activeChoiceSprite = surfaceDB.loadSurface( FN_INTRO_SHOW_CHOICE );

View File

@@ -36,11 +36,11 @@ const int NR_MENU_ARCADE_CHOICES = 2;
class MenuArcadeMode {
private:
SDL_Surface *screen;
SDL_Surface *arcadeSprite;
SDL_Surface *activeChoiceSprite;
SDL_Surface *lightFighterIcon1;
SDL_Surface *heavyFighterIcon1;
SdlCompat_AcceleratedSurface *screen;
SdlCompat_AcceleratedSurface *arcadeSprite;
SdlCompat_AcceleratedSurface *activeChoiceSprite;
SdlCompat_AcceleratedSurface *lightFighterIcon1;
SdlCompat_AcceleratedSurface *heavyFighterIcon1;
Font *font;
Font *fontHighlighted;
@@ -54,7 +54,7 @@ class MenuArcadeMode {
bool playerOneLightFighter;
public:
MenuArcadeMode( SDL_Surface *scr );
MenuArcadeMode( SdlCompat_AcceleratedSurface *scr );
~MenuArcadeMode();
void run( GameStates &gameState, int points=-1 );
bool getPlayerOneLightFighter();

View File

@@ -231,7 +231,7 @@ void Racer::clipWorld() {
}
void Racer::drawStats( SDL_Surface *screen ) {
void Racer::drawStats( SdlCompat_AcceleratedSurface *screen ) {
SDL_Rect srcR, destR;
int indent = 5;
@@ -320,7 +320,7 @@ void Racer::drawStats( SDL_Surface *screen ) {
}
void Racer::drawShadow( SDL_Surface *screen ) {
void Racer::drawShadow( SdlCompat_AcceleratedSurface *screen ) {
SDL_Rect destR;
destR.x = lroundf(pos.getX()) - (spriteShadow->w / 2) - 10;
destR.y = lroundf(pos.getY()) - (spriteShadow->h / 2) + 10;
@@ -330,7 +330,7 @@ void Racer::drawShadow( SDL_Surface *screen ) {
}
void Racer::drawRacer( SDL_Surface *screen ) {
void Racer::drawRacer( SdlCompat_AcceleratedSurface *screen ) {
SDL_Rect srcR;
SDL_Rect destR;

View File

@@ -40,13 +40,13 @@ class ShieldGlow;
/* The Racer is the vehicle, that the player can steer. */
class Racer {
SDL_Surface *spriteRacerBase;
SdlCompat_AcceleratedSurface *spriteRacerBase;
SDL_Rect drawRectBase;
SDL_Surface *spriteShadow;
SDL_Surface *spriteDeflector;
SdlCompat_AcceleratedSurface *spriteShadow;
SdlCompat_AcceleratedSurface *spriteDeflector;
SDL_Rect drawRectDeflector;
SDL_Surface *spriteHPStat;
SDL_Surface *spriteFighterIcon;
SdlCompat_AcceleratedSurface *spriteHPStat;
SdlCompat_AcceleratedSurface *spriteFighterIcon;
// for collision with other racers or shots.
// A rectangle with racersize * 0.9 is used.
@@ -57,8 +57,8 @@ class Racer {
Font *font; // font used for displaying ammo and lapcnt
int fontSize;
SDL_Surface *spriteSecondaryWeapons;
SDL_Surface *spriteSpecials;
SdlCompat_AcceleratedSurface *spriteSecondaryWeapons;
SdlCompat_AcceleratedSurface *spriteSpecials;
int sndShotPrimary;
int sndShotSecondary;
@@ -155,9 +155,9 @@ class Racer {
// switch special, if the activespecial is out of ammo
void specialKeyUp();
void drawRacer( SDL_Surface *screen );
void drawShadow( SDL_Surface *screen );
void drawStats( SDL_Surface *screen );
void drawRacer( SdlCompat_AcceleratedSurface *screen );
void drawShadow( SdlCompat_AcceleratedSurface *screen );
void drawStats( SdlCompat_AcceleratedSurface *screen );
// collision system
// return if the line between the two points collides with the boundingBox

View File

@@ -114,21 +114,21 @@ void Racers::rechargeShield( int dT ) {
}
}
void Racers::drawRacers( SDL_Surface *screen ) {
void Racers::drawRacers( SdlCompat_AcceleratedSurface *screen ) {
vector<Racer *>::iterator i;
for (i = racers.begin(); i != racers.end(); ++i) {
(*i)->drawRacer(screen);
}
}
void Racers::drawShadows( SDL_Surface *screen ) {
void Racers::drawShadows( SdlCompat_AcceleratedSurface *screen ) {
vector<Racer *>::iterator i;
for (i = racers.begin(); i != racers.end(); ++i) {
(*i)->drawShadow(screen);
}
}
void Racers::drawStats( SDL_Surface *screen ) {
void Racers::drawStats( SdlCompat_AcceleratedSurface *screen ) {
vector<Racer *>::iterator i;
for (i = racers.begin(); i != racers.end(); ++i) {
(*i)->drawStats(screen);

View File

@@ -69,9 +69,9 @@ class Racers {
// recharge the shields
void rechargeShield( int dT );
// draws the racers.
void drawRacers( SDL_Surface *screen );
void drawShadows( SDL_Surface *screen );
void drawStats( SDL_Surface *screen );
void drawRacers( SdlCompat_AcceleratedSurface *screen );
void drawShadows( SdlCompat_AcceleratedSurface *screen );
void drawStats( SdlCompat_AcceleratedSurface *screen );
// returns, which racer has shot more enemys
//int getWinner();

View File

@@ -29,7 +29,7 @@ using namespace std;
#include "racer.h"
#include "racers.h"
SetDifficulty::SetDifficulty( SDL_Surface *scr ) {
SetDifficulty::SetDifficulty( SdlCompat_AcceleratedSurface *scr ) {
screen = scr;
introSprite = surfaceDB.loadSurface( FN_ALIENBLASTER_INTRO );
activeChoiceSprite = surfaceDB.loadSurface( FN_INTRO_SHOW_CHOICE );
@@ -163,7 +163,7 @@ void SetDifficulty::handleEvents( GameStates &gameState ) {
break;
}
case SDLK_F5: {
SDL_WM_ToggleFullScreen( screen );
//SDL_WM_ToggleFullScreen( screen );
break;
}
case SDLK_F7: {

View File

@@ -36,13 +36,13 @@ const int NR_DIFFICULTY_CHOICES = 5;
class SetDifficulty {
private:
SDL_Surface *screen;
SDL_Surface *introSprite;
SDL_Surface *activeChoiceSprite;
SDL_Surface *lightFighterIcon1;
SDL_Surface *lightFighterIcon2;
SDL_Surface *heavyFighterIcon1;
SDL_Surface *heavyFighterIcon2;
SdlCompat_AcceleratedSurface *screen;
SdlCompat_AcceleratedSurface *introSprite;
SdlCompat_AcceleratedSurface *activeChoiceSprite;
SdlCompat_AcceleratedSurface *lightFighterIcon1;
SdlCompat_AcceleratedSurface *lightFighterIcon2;
SdlCompat_AcceleratedSurface *heavyFighterIcon1;
SdlCompat_AcceleratedSurface *heavyFighterIcon2;
Font *font;
Font *fontHighlighted;
@@ -56,7 +56,7 @@ class SetDifficulty {
int choose;
public:
SetDifficulty( SDL_Surface *scr );
SetDifficulty( SdlCompat_AcceleratedSurface *scr );
~SetDifficulty();
void run( GameStates &gameState, bool onePlayerGame );
bool getPlayerOneLightFighter();

View File

@@ -134,7 +134,7 @@ void Settings::saveSettings() {
}
void Settings::draw( SDL_Surface *screen, bool getNewKey ) {
void Settings::draw( SdlCompat_AcceleratedSurface *screen, bool getNewKey ) {
videoserver->clearScreen();
SDL_Rect r;
r.x = screen->w / 2 - introSprite->w / 2;
@@ -149,7 +149,7 @@ void Settings::draw( SDL_Surface *screen, bool getNewKey ) {
}
void Settings::showSpecialKeys( SDL_Surface *screen ) {
void Settings::showSpecialKeys( SdlCompat_AcceleratedSurface *screen ) {
fontNormal->drawStr(screen, screen->w/2, screen->h - 2*fontNormal->getCharHeight() - 10,
"F1: Configure Keys F5: Fullscreen", FONT_ALIGN_CENTERED );
fontNormal->drawStr(screen, screen->w/2, screen->h - fontNormal->getCharHeight() - 5,
@@ -158,7 +158,7 @@ void Settings::showSpecialKeys( SDL_Surface *screen ) {
}
void Settings::showSettings( SDL_Surface *screen, bool getNewKey ) {
void Settings::showSettings( SdlCompat_AcceleratedSurface *screen, bool getNewKey ) {
int playerOfActiveItem = -1;
if ( actChoice <= SC_FIRE_SPEC_1 ) playerOfActiveItem = 0;
else if ( actChoice <= SC_FIRE_SPEC_2 ) playerOfActiveItem = 1;
@@ -242,7 +242,7 @@ void Settings::showSettings( SDL_Surface *screen, bool getNewKey ) {
}
}
void Settings::showMenu( SDL_Surface *screen ) {
void Settings::showMenu( SdlCompat_AcceleratedSurface *screen ) {
SDL_Rect r;
r.x = 230 - activeChoiceSprite->w - 8;
r.w = activeChoiceSprite->w;
@@ -267,7 +267,7 @@ void Settings::showMenu( SDL_Surface *screen ) {
} else fontMenu->drawStr( screen, 230, 400, "Finish" );
}
void Settings::settingsDialog( SDL_Surface *screen ) {
void Settings::settingsDialog( SdlCompat_AcceleratedSurface *screen ) {
bool run = true;
actChoice = SC_FINISH;
wasLeftColumn = true;

View File

@@ -24,6 +24,8 @@
#include <map>
#include <vector>
#include "SDL.h"
#include "SdlForwardCompat.h"
class Font;
class Options;
@@ -60,15 +62,15 @@ class Settings {
Settings();
~Settings();
void settingsDialog(SDL_Surface *screen);
void settingsDialog(SdlCompat_AcceleratedSurface *screen);
const PlayerKeys getPlayerKeys(unsigned int player) const;
private:
SDL_Surface *introSprite;
SDL_Surface *activeChoiceSprite;
SDL_Surface *bluePlain;
SDL_Surface *whitePlain;
SdlCompat_AcceleratedSurface *introSprite;
SdlCompat_AcceleratedSurface *activeChoiceSprite;
SdlCompat_AcceleratedSurface *bluePlain;
SdlCompat_AcceleratedSurface *whitePlain;
SettingsChoices actChoice;
bool wasLeftColumn;
Options *opfile;
@@ -85,11 +87,11 @@ class Settings {
void loadDefaultSettings();
void loadSettings();
void saveSettings();
void draw( SDL_Surface *screen, bool getNewKey=false );
void showSpecialKeys( SDL_Surface *screen );
void showSettings( SDL_Surface *screen, bool getNewKey );
void showMenu( SDL_Surface *screen );
void changeCurrentSettings(SDL_Surface *screen, int player);
void draw( SdlCompat_AcceleratedSurface *screen, bool getNewKey=false );
void showSpecialKeys( SdlCompat_AcceleratedSurface *screen );
void showSettings( SdlCompat_AcceleratedSurface *screen, bool getNewKey );
void showMenu( SdlCompat_AcceleratedSurface *screen );
void changeCurrentSettings(SdlCompat_AcceleratedSurface *screen, int player);
void setKeyNames();
};

View File

@@ -42,7 +42,7 @@ ShieldGlow::ShieldGlow( ShipTypes shipType ) {
ShieldGlow::~ShieldGlow() {}
void ShieldGlow::draw( SDL_Surface *screen, Vector2D pos, int time ) {
void ShieldGlow::draw( SdlCompat_AcceleratedSurface *screen, Vector2D pos, int time ) {
if ( time < 0 || RACER_SHIELD_DAMAGE_LIFETIME < time ) return;
int actFrame = time / timePerFrame;

View File

@@ -25,7 +25,7 @@
#include "global.h"
class ShieldGlow {
SDL_Surface *spriteShieldGlow;
SdlCompat_AcceleratedSurface *spriteShieldGlow;
int nrFrames;
int frameWidth;
int halfFrameWidth;
@@ -36,7 +36,7 @@ class ShieldGlow {
ShieldGlow( ShipTypes shipType );
~ShieldGlow();
void draw( SDL_Surface *screen, Vector2D drawPos, int time );
void draw( SdlCompat_AcceleratedSurface *screen, Vector2D drawPos, int time );
};

View File

@@ -642,7 +642,7 @@ void Shot::addExplosion() {
////////////////////
void Shot::drawShadow(SDL_Surface *screen) {
void Shot::drawShadow(SdlCompat_AcceleratedSurface *screen) {
switch (shotType) {
case SHOT_KICK_ASS_ROCKET:
case SHOT_HF_KICK_ASS_ROCKET:
@@ -680,7 +680,7 @@ void Shot::drawShadow(SDL_Surface *screen) {
}
}
void Shot::drawGroundShot(SDL_Surface *screen) {
void Shot::drawGroundShot(SdlCompat_AcceleratedSurface *screen) {
switch (shotType) {
case SHOT_KICK_ASS_ROCKET:
case SHOT_HF_KICK_ASS_ROCKET:
@@ -704,7 +704,7 @@ void Shot::drawGroundShot(SDL_Surface *screen) {
}
}
void Shot::drawGroundAirShot(SDL_Surface *screen) {
void Shot::drawGroundAirShot(SdlCompat_AcceleratedSurface *screen) {
switch (shotType) {
case SHOT_DUMBFIRE:
case SHOT_DUMBFIRE_DOUBLE:
@@ -798,7 +798,7 @@ void Shot::drawGroundAirShot(SDL_Surface *screen) {
}
}
void Shot::drawAirShot(SDL_Surface *screen) {
void Shot::drawAirShot(SdlCompat_AcceleratedSurface *screen) {
switch (shotType) {
case SHOT_NORMAL:
case SHOT_NORMAL_HEAVY:

View File

@@ -36,8 +36,8 @@ class Shot {
int fromWhichPlayer;
ShotTypes shotType;
SDL_Surface *sprite;
SDL_Surface *spriteShadow;
SdlCompat_AcceleratedSurface *sprite;
SdlCompat_AcceleratedSurface *spriteShadow;
bool collidedWithGround; // defaultValue = false
@@ -55,10 +55,10 @@ class Shot {
// and makes a neat explosion
void moveAndCollide( int dT );
// draws the shot
void drawShadow(SDL_Surface *screen);
void drawGroundShot(SDL_Surface *screen);
void drawAirShot(SDL_Surface *screen);
void drawGroundAirShot(SDL_Surface *screen);
void drawShadow(SdlCompat_AcceleratedSurface *screen);
void drawGroundShot(SdlCompat_AcceleratedSurface *screen);
void drawAirShot(SdlCompat_AcceleratedSurface *screen);
void drawGroundAirShot(SdlCompat_AcceleratedSurface *screen);
bool isExpired() { return (timeToLive <= 0); }
Vector2D getPos() { return pos; }

View File

@@ -67,28 +67,28 @@ void Shots::expireShots() {
}
}
void Shots::drawShadows(SDL_Surface *screen) {
void Shots::drawShadows(SdlCompat_AcceleratedSurface *screen) {
vector<Shot *>::iterator i;
for (i = shots.begin(); i != shots.end(); ++i) {
(*i)->drawShadow(screen);
}
}
void Shots::drawGroundShots(SDL_Surface *screen) {
void Shots::drawGroundShots(SdlCompat_AcceleratedSurface *screen) {
vector<Shot *>::iterator i;
for (i = shots.begin(); i != shots.end(); ++i) {
(*i)->drawGroundShot(screen);
}
}
void Shots::drawAirShots(SDL_Surface *screen) {
void Shots::drawAirShots(SdlCompat_AcceleratedSurface *screen) {
vector<Shot *>::iterator i;
for (i = shots.begin(); i != shots.end(); ++i) {
(*i)->drawAirShot(screen);
}
}
void Shots::drawGroundAirShots(SDL_Surface *screen) {
void Shots::drawGroundAirShots(SdlCompat_AcceleratedSurface *screen) {
vector<Shot *>::iterator i;
for (i = shots.begin(); i != shots.end(); ++i) {
(*i)->drawGroundAirShot(screen);

View File

@@ -23,6 +23,7 @@
#include <vector>
#include "SDL.h"
#include "geometry.h"
#include "SdlForwardCompat.h"
class Shot;
@@ -45,10 +46,10 @@ class Shots {
void moveAndCollide( int dT );
// draw the shots
void drawShadows(SDL_Surface *screen);
void drawAirShots(SDL_Surface *screen);
void drawGroundShots(SDL_Surface *screen);
void drawGroundAirShots(SDL_Surface *screen);
void drawShadows(SdlCompat_AcceleratedSurface *screen);
void drawAirShots(SdlCompat_AcceleratedSurface *screen);
void drawGroundShots(SdlCompat_AcceleratedSurface *screen);
void drawGroundAirShots(SdlCompat_AcceleratedSurface *screen);
Shot* getNearestRocket(Vector2D position);
bool existsRocket();

View File

@@ -52,7 +52,7 @@ void SmokePuff::update( int dT ) {
}
}
void SmokePuff::drawSmokePuff( SDL_Surface *screen ) {
void SmokePuff::drawSmokePuff( SdlCompat_AcceleratedSurface *screen ) {
if (expired) return;
SDL_Rect dest;

View File

@@ -29,7 +29,7 @@ class SmokePuff {
// a sprite, that contains horizontally all animationframes of the smokePuff.
// it is assumed, that every frame is quadratic.
SDL_Surface *sprite;
SdlCompat_AcceleratedSurface *sprite;
// how many frames does this explosion have?
int nrAnimStages;
@@ -54,7 +54,7 @@ class SmokePuff {
~SmokePuff();
// updates the position and the counters
void update( int dT );
void drawSmokePuff(SDL_Surface *screen);
void drawSmokePuff(SdlCompat_AcceleratedSurface *screen);
bool isExpired() { return expired; }
};

View File

@@ -61,7 +61,7 @@ void SmokePuffs::update( int dT ) {
}
}
void SmokePuffs::draw(SDL_Surface *screen) {
void SmokePuffs::draw(SdlCompat_AcceleratedSurface *screen) {
vector<SmokePuff *>::iterator i;
for (i = smokePuffs.begin(); i != smokePuffs.end(); ++i) {
(*i)->drawSmokePuff( screen );

View File

@@ -37,7 +37,7 @@ class SmokePuffs {
void addSmokePuff( Vector2D pos, Vector2D vel, SmokePuffTypes whichType );
void expireSmokePuffs();
void update( int dT );
void draw(SDL_Surface *screen);
void draw(SdlCompat_AcceleratedSurface *screen);
unsigned int getNrSmokePuffs() { return smokePuffs.size(); }
};

View File

@@ -40,12 +40,12 @@ void Sonic::setPos( Vector2D pos1, Vector2D pos2 ) {
active = true;
}
void Sonic::drawAtPos( SDL_Surface *screen, Vector2D pos1, Vector2D pos2 ) {
void Sonic::drawAtPos( SdlCompat_AcceleratedSurface *screen, Vector2D pos1, Vector2D pos2 ) {
setPos( pos1, pos2 );
draw( screen );
}
void Sonic::draw( SDL_Surface *screen ) {
void Sonic::draw( SdlCompat_AcceleratedSurface *screen ) {
if ( !active ) return;
timeStage += 2;
timeStage = (timeStage % (int)(waveLength + 0.5f)) + 1;

View File

@@ -22,6 +22,8 @@
#include <SDL.h>
#include "geometry.h"
#include "SdlForwardCompat.h"
class Sonic {
public:
@@ -30,13 +32,13 @@ class Sonic {
void setActive( bool newActivation ) { active = newActivation; };
void setWaveLength( float wvLength ) { waveLength = wvLength; };
void setPos( Vector2D pos1, Vector2D pos2 );
void drawAtPos( SDL_Surface *screen, Vector2D pos1, Vector2D pos2 );
void draw( SDL_Surface *screen );
void drawAtPos( SdlCompat_AcceleratedSurface *screen, Vector2D pos1, Vector2D pos2 );
void draw( SdlCompat_AcceleratedSurface *screen );
private:
SDL_Surface *sonicBall;
SdlCompat_AcceleratedSurface *sonicBall;
bool active;
Vector2D pos1;
Vector2D pos2;

View File

@@ -45,9 +45,9 @@ SurfaceDB::~SurfaceDB() {
}
}
SDL_Surface *SurfaceDB::loadSurface( string fn, bool alpha ) {
SdlCompat_AcceleratedSurface *SurfaceDB::loadSurface( string fn, bool alpha ) {
SDL_Surface *searchResult = getSurface( fn );
SdlCompat_AcceleratedSurface *searchResult = getSurface( fn );
if ( searchResult ) {
return searchResult;
}
@@ -103,11 +103,12 @@ SDL_Surface *SurfaceDB::loadSurface( string fn, bool alpha ) {
SDL_MapRGB(newSurface->format, transR, transG, transB) );
}
surfaceDB[ fn ] = newSurface;
return newSurface;
surfaceDB[ fn ] = SdlCompat_CreateAcceleratedSurface( newSurface );
SDL_FreeSurface(newSurface);
return surfaceDB[ fn ];
}
SDL_Surface *SurfaceDB::getSurface( string fn ) {
SdlCompat_AcceleratedSurface *SurfaceDB::getSurface( string fn ) {
if ( surfaceDB.empty() ) {
return 0;
} else {

View File

@@ -22,12 +22,13 @@
#include "SDL.h"
#include "SdlForwardCompat.h"
#include <string>
#include <map>
#include <functional>
typedef std::map<std::string, SDL_Surface *, std::greater<std::string> > StringSurfaceMap;
typedef std::map<std::string, SdlCompat_AcceleratedSurface *, std::greater<std::string> > StringSurfaceMap;
class SurfaceDB;
@@ -48,13 +49,13 @@ class SurfaceDB {
Uint8 transparentB=255 );
~SurfaceDB();
SDL_Surface *loadSurface( std::string fn, bool alpha=false );
SdlCompat_AcceleratedSurface *loadSurface( std::string fn, bool alpha=false );
private:
StringSurfaceMap surfaceDB;
Uint8 transR, transG, transB;
SDL_Surface *getSurface( std::string fn );
SdlCompat_AcceleratedSurface *getSurface( std::string fn );
};

View File

@@ -35,7 +35,7 @@ Video::~Video(){
// kill something
}
SDL_Surface *Video::init(){
SdlCompat_AcceleratedSurface *Video::init(){
// --------------------------------------------------
// SDL initialisation
// -----------------------------------------------------
@@ -47,12 +47,18 @@ SDL_Surface *Video::init(){
__android_log_print(ANDROID_LOG_ERROR, "Alien Blaster", "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
exit(1);
}
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, BIT_DEPTH, SDL_DOUBLEBUF /* | SDL_FULLSCREEN */ );
if (!screen) {
SDL_Surface * screen2 = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, BIT_DEPTH, SDL_DOUBLEBUF /* | SDL_FULLSCREEN */ );
if (!screen2) {
printf("Couldn't set %dx%d, %dbit video mode: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, BIT_DEPTH, SDL_GetError());
__android_log_print(ANDROID_LOG_ERROR, "Alien Blaster", "Couldn't set %dx%d, %dbit video mode: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, BIT_DEPTH, SDL_GetError());
exit(2);
}
// Dummy texture
screen2 = SDL_CreateRGBSurface( 0, 16, 16, 16, 0xff, 0x00ff, 0x0000ff, 0 );
SDL_Surface * screen3 = SDL_DisplayFormat( screen2 );
SDL_FreeSurface(screen2);
screen = SdlCompat_CreateAcceleratedSurface(screen3);
SDL_FreeSurface(screen3);
SDL_WM_SetCaption("AlienBlaster", "AlienBlaster");
SDL_WM_SetIcon(SDL_LoadBMP( FN_ALIENBLASTER_ICON.c_str() ), NULL);
@@ -74,10 +80,13 @@ void Video::clearScreen() {
}
void Video::toggleFullscreen() {
// TODO: fix that?
/*
if ( fullscreen ) {
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, BIT_DEPTH, SDL_DOUBLEBUF );
} else {
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, BIT_DEPTH, SDL_DOUBLEBUF | SDL_FULLSCREEN );
}
*/
fullscreen = !fullscreen;
}

View File

@@ -21,6 +21,8 @@
#define VIDEO_H
#include "SDL.h"
#include "SdlForwardCompat.h"
class Video;
@@ -29,12 +31,12 @@ extern Video *videoserver;
class Video {
private:
SDL_Surface *screen;
SdlCompat_AcceleratedSurface *screen;
public:
Video();
~Video();
SDL_Surface *init();
SdlCompat_AcceleratedSurface *init();
bool fullscreen;

View File

@@ -94,7 +94,7 @@ void Wreck::update( int dT ) {
}
void Wreck::draw(SDL_Surface *screen) {
void Wreck::draw(SdlCompat_AcceleratedSurface *screen) {
SDL_Rect r;
r.x = lroundf(pos.getX()) - sprite->w / 2;
r.y = lroundf(pos.getY()) - sprite->h / 2;

View File

@@ -26,7 +26,7 @@
#include "global.h"
class Wreck {
SDL_Surface *sprite;
SdlCompat_AcceleratedSurface *sprite;
Vector2D pos;
Vector2D vel;
@@ -36,7 +36,7 @@ class Wreck {
Wreck( Vector2D position, WreckTypes wreckType );
~Wreck();
void update( int dT );
void draw(SDL_Surface *screen);
void draw(SdlCompat_AcceleratedSurface *screen);
bool isExpired();
void deleteWreck();

View File

@@ -55,7 +55,7 @@ void Wrecks::updateWrecks( int dT ) {
}
}
void Wrecks::draw(SDL_Surface *screen) {
void Wrecks::draw(SdlCompat_AcceleratedSurface *screen) {
vector<Wreck *>::iterator i;
for (i = wrecks.begin(); i != wrecks.end(); ++i) {
(*i)->draw(screen);

View File

@@ -22,6 +22,7 @@
#include "SDL.h"
#include <vector>
#include "SdlForwardCompat.h"
class Wreck;
@@ -35,7 +36,7 @@ class Wrecks {
void addWreck(Wreck *wreck);
void expireWrecks();
void updateWrecks( int dT );
void draw(SDL_Surface *screen);
void draw(SdlCompat_AcceleratedSurface *screen);
void deleteAllWrecks();
unsigned int getNrWrecks() { return wrecks.size(); }

View File

@@ -1732,10 +1732,12 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
SDL_PIXELFORMAT_BGR565,
SDL_PIXELFORMAT_ARGB1555,
SDL_PIXELFORMAT_ABGR1555,
SDL_PIXELFORMAT_RGBA5551,
SDL_PIXELFORMAT_RGB555,
SDL_PIXELFORMAT_BGR555,
SDL_PIXELFORMAT_ARGB4444,
SDL_PIXELFORMAT_ABGR4444,
SDL_PIXELFORMAT_RGBA4444,
SDL_PIXELFORMAT_RGB444,
SDL_PIXELFORMAT_ARGB2101010,
SDL_PIXELFORMAT_INDEX8,
@@ -1820,8 +1822,10 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_ARGB1555,
SDL_PIXELFORMAT_ABGR1555,
SDL_PIXELFORMAT_RGBA5551,
SDL_PIXELFORMAT_ARGB4444,
SDL_PIXELFORMAT_ABGR4444,
SDL_PIXELFORMAT_RGBA4444,
SDL_PIXELFORMAT_ARGB2101010,
SDL_PIXELFORMAT_UNKNOWN
};

Binary file not shown.