Fixed Alien Blaster not working on simulation - I've added lot of debug 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?
This commit is contained in:
pelya
2010-05-12 19:49:48 +03:00
parent 2adcc9b8d8
commit 94df8e2921
15 changed files with 144 additions and 37 deletions

View File

@@ -40,7 +40,7 @@ realclean:
rebuild: realclean game
.SUFFIXES: .cc
.SUFFIXES: .cpp
# How to compile a c++ programm
$(GAME_NAME): $(OBJECT_FILES)
@@ -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 $<"
@@ -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

View File

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

View File

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

View File

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

View File

@@ -19,6 +19,8 @@
***************************************************************************/
using namespace std;
#include <android/log.h>
#include "intro.h"
#include "global.h"
#include "surfaceDB.h"
@@ -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 );
}

View File

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

View File

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

View File

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