Skip to content

Commit

Permalink
Fixed Alien Blaster not working on simulation - I've added lot of deb…
Browse files Browse the repository at this point in the history
…ug spam, it should be removed.

The problem is in the least obvious place - the std::ostringstream output deadlocks for no reason -
see file project/jni/application/src/asstring.h.
The only reason I can think of is that previously I've has one big statically linked library,
and now libstlport and libapplication areseparate shared libraries. But why then all std::vectors etc work?
  • Loading branch information
pelya committed May 12, 2010
1 parent 2adcc9b commit 94df8e2
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 37 deletions.
2 changes: 1 addition & 1 deletion alienblaster/project/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ SDL_CURDIR_PATH := /data/data/de.schwardtnet.alienblaster/files
# this will make Up/Down/Left/Right key up events with X frames delay,
# so if application expects you to press and hold button it will process the event correctly.
# TODO: create a libsdl config file for that option and for key mapping/on-screen keyboard
SDL_TRACKBALL_KEYUP_DELAY := 0
SDL_TRACKBALL_KEYUP_DELAY := 1

include $(call all-subdir-makefiles)
6 changes: 3 additions & 3 deletions alienblaster/project/jni/application/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ realclean:

rebuild: realclean game

.SUFFIXES: .cc
.SUFFIXES: .cpp

# How to compile a c++ programm
$(GAME_NAME): $(OBJECT_FILES)
Expand All @@ -50,7 +50,7 @@ $(GAME_NAME): $(OBJECT_FILES)
@$(COMPILER) $(GAME_LIBS) -o $(GAME_NAME) $(OBJECT_FILES)
mv $(GAME_NAME) ../

%.o: %.cc
%.o: %.cpp
@echo ""
@echo ""
@echo "Compiling $<"
Expand All @@ -60,7 +60,7 @@ depend: dep

dep:
-touch Makefile.dep
-makedepend $(INCLUDE_PATH) -Y -f Makefile.dep *.cc 2> /dev/null
-makedepend $(INCLUDE_PATH) -Y -f Makefile.dep *.cpp 2> /dev/null
-rm -f Makefile.dep.bak

-include Makefile.dep
Empty file.
20 changes: 19 additions & 1 deletion alienblaster/project/jni/application/src/asstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,31 @@
#ifndef _AS_STRING_H_
#define _AS_STRING_H_

#include <sstream>
//#include <sstream>
#include <stdio.h>


// TODO: why the hell this function deadlocks? Is ostringstream illegal in Android? And why did it work earlier?
/*
template<typename T> std::string asString(const T& obj) {
std::ostringstream t;
t << obj;
std::string res(t.str());
return res;
}
*/

static inline std::string asString(int obj) {
char t[64];
sprintf(t, "%i", obj);
return std::string (t);
}

static inline std::string asString(unsigned int obj) {
char t[64];
sprintf(t, "%u", obj);
return std::string (t);
}

#endif
16 changes: 16 additions & 0 deletions alienblaster/project/jni/application/src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <android/log.h>

#include "SDL.h"
#include "mixer.h"
#include "game.h"
Expand Down Expand Up @@ -72,27 +74,37 @@ int difficultyLevel;
float actBackgroundPos;

Game::Game() {
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 0");
videoserver = new Video();
screen = 0;
screen = videoserver->init();
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 1");
settings = new Settings();
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 11");
intro = new Intro( screen );
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 12");
setDifficulty = new SetDifficulty( screen );
menuArcadeMode = new MenuArcadeMode( screen );
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 13");

pauseSprite = surfaceDB.loadSurface( FN_PAUSED );
youLoseSprite = surfaceDB.loadSurface( FN_YOU_LOSE );
youWinSprite = surfaceDB.loadSurface( FN_YOU_WIN );
// for arcadeMode
gameOverSprite = surfaceDB.loadSurface( FN_GAME_OVER );
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 14");

nukeEffectSurface = surfaceDB.loadSurface( FN_NUKE_EFFECT );

bossAlarm = Mixer::mixer().loadSample( FN_SOUND_BOSS_ALARM, 60 );

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 15");

fontTime = new Font( FN_FONT_NUMBERS_TIME );
fontSizeTime = fontTime->getCharWidth();

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 16");

racers = 0;
explosions = 0;
enemys = 0;
Expand Down Expand Up @@ -126,6 +138,8 @@ Game::Game() {
background = new Background();
loadLevel( FN_LEVEL_ONE_PLAYER );

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 2");

SDL_Surface *loadingSprite = surfaceDB.loadSurface( FN_LOADING );
SDL_Rect dest;
dest.x = (SCREEN_WIDTH - loadingSprite->w ) / 2;
Expand All @@ -134,7 +148,9 @@ Game::Game() {
dest.h = loadingSprite->h;
SDL_BlitSurface( loadingSprite, 0, screen, &dest );
SDL_Flip( screen );
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() 3");
initAllSurfaces();
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Game::Game() done");
}

Game::~Game(){
Expand Down
2 changes: 1 addition & 1 deletion alienblaster/project/jni/application/src/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int getRandValue( const int *choicesWeights, int nrChoices, int sumWeights=0 );
void initAllSurfaces();

// screen options
const int SCREEN_WIDTH = 640;
const int SCREEN_WIDTH = 320;
const int SCREEN_HEIGHT = 480;
const int BIT_DEPTH = 16;

Expand Down
4 changes: 4 additions & 0 deletions alienblaster/project/jni/application/src/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
***************************************************************************/
using namespace std;

#include <android/log.h>

#include "intro.h"
#include "global.h"
#include "surfaceDB.h"
Expand All @@ -44,6 +46,8 @@ Intro::~Intro() {}

void Intro::run( GameStates &gameState ) {

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Intro::run()");

if ( playMusicOn && Mixer::mixer().whichMusicPlaying() != MUSIC_INTRO ) {
Mixer::mixer().playMusic( MUSIC_INTRO, -1, 1000 );
}
Expand Down
4 changes: 2 additions & 2 deletions alienblaster/project/jni/application/src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ bool Options::setStr(const string newValue, const string keyword) {


bool Options::setInt(const int newValue, const string keyword) {
keymap[keyword] = asString<int>( newValue );
keymap[keyword] = asString( newValue );
return true;
}


bool Options::setUInt(const unsigned int newValue, const string keyword) {
keymap[keyword] = asString<unsigned int>( newValue );
keymap[keyword] = asString( newValue );
return true;
}

Expand Down
26 changes: 26 additions & 0 deletions alienblaster/project/jni/application/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using namespace std;
#include <cassert>
#include <string>
#include <map>
#include <android/log.h>
#include "SDL.h"
#include "options.h"
#include "settings.h"
Expand All @@ -38,17 +39,26 @@ Settings *settings;
Settings::Settings() {
opfile = NULL;

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::Settings() 0");

introSprite = surfaceDB.loadSurface( FN_ALIENBLASTER_INTRO );

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::Settings() 1");

activeChoiceSprite = surfaceDB.loadSurface( FN_INTRO_SHOW_CHOICE );
bluePlain = surfaceDB.loadSurface( FN_SETTINGS_BLUE, true );
whitePlain = surfaceDB.loadSurface( FN_SETTINGS_WHITE, false );

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::Settings() 2");

fontMenu = new Font ( FN_FONT_SETTINGS );
fontMenuHighlighted = new Font ( FN_FONT_SETTINGS_HIGHLIGHTED );
fontNormal = new Font( FN_FONT_SETTINGS_SMALL );
fontKey = new Font ( FN_FONT_SETTINGS_SMALL_BLUE );
fontHighlighted = new Font( FN_FONT_SETTINGS_SMALL_HIGHLIGHTED );

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::Settings() 3");

playerEventNames[ PE_UNKNOWN ] = "UNKNOWN";
playerEventNames[ PE_UP ] = "UP";
playerEventNames[ PE_DOWN ] = "DOWN";
Expand Down Expand Up @@ -77,9 +87,16 @@ Settings::Settings() {
defaultSettings[ string("PLAYER1-") + playerEventNames[ PE_FIRE_WEAPONS ] ] = SDLK_LCTRL;
defaultSettings[ string("PLAYER1-") + playerEventNames[ PE_FIRE_SPECIALS ] ] = SDLK_LALT;

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::Settings() 4");

setKeyNames();

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::Settings() 5");

loadSettings();

__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::Settings() done");

}


Expand All @@ -97,24 +114,33 @@ void Settings::loadSettings() {
if (opfile) {
delete opfile;
}
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() 1");
opfile = new Options( FN_SETTINGS );
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() 2");
playerKeys.clear();
for(int i=0; i < MAX_PLAYER_CNT; ++i) {
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() 21: %d", i);
PlayerEventKeys pk;
for(int t=1; t < PlayerEventCnt; ++t) {
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() 22: %d %d", i, t);
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() 221: %d %d str %s", i, t, asString(i).c_str());
int key;
string keyname = string("PLAYER") + asString(i) + "-" + playerEventNames[(PlayerEvent)t];
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() 23: %d %d", i, t);
if (!opfile->getInt( keyname , key)) {
key = defaultSettings[ keyname ];
restoredSettings = true;
}
pk[ (PlayerEvent)t ] = (SDLKey)key;
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() 24: %d %d", i, t);
}
playerKeys.push_back(pk);
}
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() 3");
if (restoredSettings) {
saveSettings();
}
__android_log_print(ANDROID_LOG_VERBOSE, "alienblaster", "Settings::loadSettings() done");
}

void Settings::saveSettings() {
Expand Down
3 changes: 3 additions & 0 deletions alienblaster/project/jni/application/src/surfaceDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ SDL_Surface *SurfaceDB::loadSurface( string fn, bool alpha ) {
ifstream inputFile ( fn.c_str(), ios::in);
if (!inputFile.good()) {
cout << "ERROR: file " << fn << " does not exist!" << endl;
#ifdef ANDROID
__android_log_print(ANDROID_LOG_ERROR, "Alien Blaster", (string( "Cannot load image " ) + fn).c_str() );
#endif
exit(1);
}

Expand Down
22 changes: 14 additions & 8 deletions alienblaster/project/jni/sdl/src/audio/android/SDL_androidaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
#include "SDL_config.h"

/* Output audio to nowhere... */

#include "SDL_rwops.h"
#include "SDL_timer.h"
#include "SDL_audio.h"
Expand Down Expand Up @@ -61,6 +59,7 @@ static void ANDROIDAUD_DeleteDevice(SDL_AudioDevice *device)

static SDL_AudioDevice *ANDROIDAUD_CreateDevice(int devindex)
{
__android_log_print(ANDROID_LOG_VERBOSE, "libSDL", "ANDROIDAUD_CreateDevice");
SDL_AudioDevice *this;

/* Initialize all variables that we clean on shutdown */
Expand Down Expand Up @@ -153,6 +152,7 @@ static void ANDROIDAUD_CloseAudio(_THIS)

static int ANDROIDAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
__android_log_print(ANDROID_LOG_VERBOSE, "libSDL", "ANDROIDAUD_OpenAudio");
if( ! (spec->format == AUDIO_S8 || spec->format == AUDIO_S16) )
return (-1); // TODO: enable format conversion? Don't know how to do that in SDL

Expand Down Expand Up @@ -186,6 +186,8 @@ static int ANDROIDAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)

SDL_mutexV(audioMutex);

__android_log_print(ANDROID_LOG_VERBOSE, "libSDL", "ANDROIDAUD_OpenAudio exit");

return(0);
}

Expand All @@ -197,6 +199,7 @@ static void ANDROIDAUD_WaitAudio(_THIS)

static void ANDROIDAUD_PlayAudio(_THIS)
{
__android_log_print(ANDROID_LOG_VERBOSE, "libSDL", "ANDROIDAUD_PlayAudio: enter");
SDL_mutexP(audioMutex);

//audioBuffer = this->hidden->mixbuf;
Expand All @@ -210,6 +213,7 @@ static void ANDROIDAUD_PlayAudio(_THIS)
this->hidden->mixbuf = audioBuffer;

SDL_mutexV(audioMutex);
__android_log_print(ANDROID_LOG_VERBOSE, "libSDL", "ANDROIDAUD_PlayAudio: exit");
}

#ifndef SDL_JAVA_PACKAGE_PATH
Expand All @@ -225,7 +229,7 @@ extern jintArray JAVA_EXPORT_NAME(AudioThread_nativeAudioInit) (JNIEnv * env, jo
int initData[4] = { 0, 0, 0, 0 }; // { rate, channels, encoding, bufsize };

if( audioMutex == NULL )
return;
return ret;

SDL_mutexP(audioMutex);

Expand All @@ -246,12 +250,10 @@ extern jintArray JAVA_EXPORT_NAME(AudioThread_nativeAudioInit) (JNIEnv * env, jo
return (ret);
};

extern jobject JAVA_EXPORT_NAME(AudioThread_nativeAudioInit2) (JNIEnv * env, jobject jobj, jbyteArray buf)
extern jint JAVA_EXPORT_NAME(AudioThread_nativeAudioInit2) (JNIEnv * env, jobject jobj, jbyteArray buf)
{
jobject ret = NULL;

if( audioMutex == NULL )
return;
return 0;

SDL_mutexP(audioMutex);

Expand All @@ -273,7 +275,6 @@ extern jobject JAVA_EXPORT_NAME(AudioThread_nativeAudioInit2) (JNIEnv * env, job
SDL_memset(audioBuffer, audioFormat->silence, audioFormat->size);
char t[512];
//sprintf(t, "AudioThread_nativeAudioInit2() got byte array from JNI: size %i samples %i direct memory %i", audioBufferSize, audioFormat->samples, (isCopy == JNI_FALSE) );
__android_log_print(ANDROID_LOG_INFO, "libSDL", t);

/*
audioBuffer = (Uint8 *) SDL_AllocAudioMem(audioBufferSize);
Expand All @@ -300,6 +301,8 @@ extern jint JAVA_EXPORT_NAME(AudioThread_nativeAudioBufferLock) ( JNIEnv * env,

if( audioMutex == NULL )
return(-1);

__android_log_print(ANDROID_LOG_VERBOSE, "libSDL", "nativeAudioBufferLock");

SDL_mutexP(audioMutex);

Expand Down Expand Up @@ -338,6 +341,9 @@ extern jint JAVA_EXPORT_NAME(AudioThread_nativeAudioBufferUnlock) ( JNIEnv * env
audioPlayed = 0;

SDL_mutexV(audioMutex);

__android_log_print(ANDROID_LOG_VERBOSE, "libSDL", "nativeAudioBufferUnlock");

SDL_CondSignal(audioCond);

return 0;
Expand Down
Loading

0 comments on commit 94df8e2

Please sign in to comment.