diff --git a/alienblaster/project/jni/Android.mk b/alienblaster/project/jni/Android.mk index c14cba715..234c81500 100644 --- a/alienblaster/project/jni/Android.mk +++ b/alienblaster/project/jni/Android.mk @@ -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) diff --git a/alienblaster/project/jni/application/src/Makefile b/alienblaster/project/jni/application/src/Makefile index d878306ee..ec16b2c8a 100644 --- a/alienblaster/project/jni/application/src/Makefile +++ b/alienblaster/project/jni/application/src/Makefile @@ -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 diff --git a/alienblaster/project/jni/application/src/Makefile.dep b/alienblaster/project/jni/application/src/Makefile.dep deleted file mode 100644 index e69de29bb..000000000 diff --git a/alienblaster/project/jni/application/src/asstring.h b/alienblaster/project/jni/application/src/asstring.h index a80f0ac99..518122e6b 100644 --- a/alienblaster/project/jni/application/src/asstring.h +++ b/alienblaster/project/jni/application/src/asstring.h @@ -20,13 +20,31 @@ #ifndef _AS_STRING_H_ #define _AS_STRING_H_ -#include +//#include +#include + +// TODO: why the hell this function deadlocks? Is ostringstream illegal in Android? And why did it work earlier? +/* template 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 diff --git a/alienblaster/project/jni/application/src/game.cpp b/alienblaster/project/jni/application/src/game.cpp index 54c72b129..98a4c1c74 100644 --- a/alienblaster/project/jni/application/src/game.cpp +++ b/alienblaster/project/jni/application/src/game.cpp @@ -22,6 +22,8 @@ using namespace std; #include #include #include +#include + #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(){ diff --git a/alienblaster/project/jni/application/src/global.h b/alienblaster/project/jni/application/src/global.h index ce4d62078..9d0a8f0ea 100644 --- a/alienblaster/project/jni/application/src/global.h +++ b/alienblaster/project/jni/application/src/global.h @@ -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; diff --git a/alienblaster/project/jni/application/src/intro.cpp b/alienblaster/project/jni/application/src/intro.cpp index bd9467030..9fa5ace40 100644 --- a/alienblaster/project/jni/application/src/intro.cpp +++ b/alienblaster/project/jni/application/src/intro.cpp @@ -19,6 +19,8 @@ ***************************************************************************/ using namespace std; +#include + #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 ); } diff --git a/alienblaster/project/jni/application/src/options.cpp b/alienblaster/project/jni/application/src/options.cpp index ba99f7352..7c5a0fd3b 100644 --- a/alienblaster/project/jni/application/src/options.cpp +++ b/alienblaster/project/jni/application/src/options.cpp @@ -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( newValue ); + keymap[keyword] = asString( newValue ); return true; } bool Options::setUInt(const unsigned int newValue, const string keyword) { - keymap[keyword] = asString( newValue ); + keymap[keyword] = asString( newValue ); return true; } diff --git a/alienblaster/project/jni/application/src/settings.cpp b/alienblaster/project/jni/application/src/settings.cpp index a5fa8d94a..09c2a7d34 100644 --- a/alienblaster/project/jni/application/src/settings.cpp +++ b/alienblaster/project/jni/application/src/settings.cpp @@ -22,6 +22,7 @@ using namespace std; #include #include #include +#include #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() { diff --git a/alienblaster/project/jni/application/src/surfaceDB.cpp b/alienblaster/project/jni/application/src/surfaceDB.cpp index da0ed2031..50eb6e11d 100644 --- a/alienblaster/project/jni/application/src/surfaceDB.cpp +++ b/alienblaster/project/jni/application/src/surfaceDB.cpp @@ -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); } diff --git a/alienblaster/project/jni/sdl/src/audio/android/SDL_androidaudio.c b/alienblaster/project/jni/sdl/src/audio/android/SDL_androidaudio.c index 46ca5603a..210d831ed 100644 --- a/alienblaster/project/jni/sdl/src/audio/android/SDL_androidaudio.c +++ b/alienblaster/project/jni/sdl/src/audio/android/SDL_androidaudio.c @@ -23,8 +23,6 @@ */ #include "SDL_config.h" -/* Output audio to nowhere... */ - #include "SDL_rwops.h" #include "SDL_timer.h" #include "SDL_audio.h" @@ -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 */ @@ -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 @@ -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); } @@ -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; @@ -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 @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; diff --git a/alienblaster/project/jni/sdl/src/video/android/SDL_androidvideo.c b/alienblaster/project/jni/sdl/src/video/android/SDL_androidvideo.c index c24231aad..4c35660e4 100644 --- a/alienblaster/project/jni/sdl/src/video/android/SDL_androidvideo.c +++ b/alienblaster/project/jni/sdl/src/video/android/SDL_androidvideo.c @@ -52,7 +52,6 @@ #include #include #include -#include #include #include #include // for memset() @@ -214,8 +213,6 @@ int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat) SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 200; // Always available on any screen and any orientation SDL_modelist[4] = NULL; - WaitForNativeRender = SDL_CreateMutex(); - WaitForNativeRender1 = SDL_CreateCond(); /* We're done! */ return(0); } @@ -230,6 +227,8 @@ SDL_Rect **ANDROID_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { + __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): application requested mode %dx%d", width, height); + if ( memBuffer1 ) SDL_free( memBuffer1 ); if ( memBuffer2 ) @@ -243,6 +242,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, memBuffer1 = SDL_malloc(memX * memY * (bpp / 8)); if ( ! memBuffer1 ) { + __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate buffer for requested mode"); SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } @@ -252,6 +252,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, { memBuffer2 = SDL_malloc(memX * memY * (bpp / 8)); if ( ! memBuffer2 ) { + __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate buffer for requested mode"); SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } @@ -265,6 +266,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { SDL_free(memBuffer); memBuffer = NULL; + __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate new pixel format for requested mode"); SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } @@ -275,10 +277,17 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, current->h = height; current->pitch = memX * (bpp / 8); current->pixels = memBuffer; + + if( ! WaitForNativeRender ) + { + WaitForNativeRender = SDL_CreateMutex(); + WaitForNativeRender1 = SDL_CreateCond(); + } /* Wait 'till we can draw */ ANDROID_FlipHWSurface(this, current); /* We're done */ + __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): done"); return(current); } @@ -353,13 +362,18 @@ static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects) static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface) { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Frame is ready to render"); + __android_log_print(ANDROID_LOG_INFO, "libSDL", "FlipHWSurface: Frame is ready to render"); + if( ! WaitForNativeRender ) + { + __android_log_print(ANDROID_LOG_ERROR, "libSDL", "FlipHWSurface: called before SetVideoMode"); + return 0; + } SDL_mutexP(WaitForNativeRender); while( WaitForNativeRenderState != Render_State_Finished ) { - if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 1000 ) != 0 ) + if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 5000 ) != 0 ) { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Frame failed to render"); + __android_log_print(ANDROID_LOG_INFO, "libSDL", "FlipHWSurface: Frame failed to render"); SDL_mutexV(WaitForNativeRender); return(0); } @@ -367,17 +381,21 @@ static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface) WaitForNativeRenderState = Render_State_Started; + SDL_mutexV(WaitForNativeRender); SDL_CondSignal(WaitForNativeRender1); - + SDL_mutexP(WaitForNativeRender); + if( surface->flags & SDL_DOUBLEBUF ) { - - if( WaitForNativeRenderState != Render_State_Started ) - SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 1000 ); + if( WaitForNativeRenderState == Render_State_Started ) + if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 5000 ) != 0 ) + { + __android_log_print(ANDROID_LOG_INFO, "libSDL", "FlipHWSurface: Frame rendering timed out"); + } if( WaitForNativeRenderState != Render_State_Started ) { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Frame rendering done"); + __android_log_print(ANDROID_LOG_INFO, "libSDL", "FlipHWSurface: Frame rendering done"); if( memBuffer == memBuffer1 ) memBuffer = memBuffer2; else @@ -390,8 +408,9 @@ static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface) { while( WaitForNativeRenderState != Render_State_Finished ) { - if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 1000 ) != 0 ) + if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 5000 ) != 0 ) { + __android_log_print(ANDROID_LOG_INFO, "libSDL", "FlipHWSurface: Frame is too slow to render"); SDL_mutexV(WaitForNativeRender); return(0); }; @@ -402,6 +421,8 @@ static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface) processAndroidTrackballKeyDelays( -1, 0 ); + __android_log_print(ANDROID_LOG_INFO, "libSDL", "FlipHWSurface: exit"); + return(0); }; @@ -424,7 +445,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeResize) ( JNIEnv* env, jobject thiz, jint { sWindowWidth = w; sWindowHeight = h; - __android_log_print(ANDROID_LOG_INFO, "libSDL", "resize w=%d h=%d", w, h); + __android_log_print(ANDROID_LOG_INFO, "libSDL", "Physical screen resolution is %dx%d", w, h); } /* Call to finalize the graphics state */ @@ -693,13 +714,16 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeRender) ( JNIEnv* env, jobject thiz, jfloa SDL_mutexP(WaitForNativeRender); WaitForNativeRenderState = Render_State_Finished; + + SDL_mutexV(WaitForNativeRender); SDL_CondSignal(WaitForNativeRender1); + SDL_mutexP(WaitForNativeRender); while( WaitForNativeRenderState != Render_State_Started ) { - if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 1000 ) != 0 ) + if( SDL_CondWaitTimeout( WaitForNativeRender1, WaitForNativeRender, 5000 ) != 0 ) { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Frame failed to render"); + __android_log_print(ANDROID_LOG_INFO, "libSDL", "nativeRender: Frame failed to render"); SDL_mutexV(WaitForNativeRender); return; } @@ -709,13 +733,14 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeRender) ( JNIEnv* env, jobject thiz, jfloa WaitForNativeRenderState = Render_State_Processing; - SDL_CondSignal(WaitForNativeRender1); - SDL_mutexV(WaitForNativeRender); + + SDL_CondSignal(WaitForNativeRender1); } else memBufferTemp = memBuffer; - + + /* if( sWindowWidth < memX || sWindowHeight < memY ) { // Move the large virtual surface with accelerometer @@ -784,10 +809,12 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeRender) ( JNIEnv* env, jobject thiz, jfloa glDrawTexiOES(0, 0, 1, sWindowWidth, sWindowHeight); } else + */ { // TODO: use accelerometer as joystick glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, memX, memY, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBufferTemp); glDrawTexiOES(0, sWindowHeight-memY, 1, memX, memY); + __android_log_print(ANDROID_LOG_INFO, "libSDL", "nativeRender: Frame rendered"); } //glFinish(); //glFlush(); diff --git a/alienblaster/project/jni/sdl_main/Android.mk b/alienblaster/project/jni/sdl_main/Android.mk index f5d323c39..8f62f6c6f 100644 --- a/alienblaster/project/jni/sdl_main/Android.mk +++ b/alienblaster/project/jni/sdl_main/Android.mk @@ -17,5 +17,6 @@ LOCAL_CPP_EXTENSION := .cpp LOCAL_SRC_FILES := sdl_main.c LOCAL_SHARED_LIBRARIES := sdl application +LOCAL_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY) diff --git a/alienblaster/project/jni/sdl_main/sdl_main.c b/alienblaster/project/jni/sdl_main/sdl_main.c index 7d507ae64..1ca6e593e 100644 --- a/alienblaster/project/jni/sdl_main/sdl_main.c +++ b/alienblaster/project/jni/sdl_main/sdl_main.c @@ -2,6 +2,7 @@ #include #include +#include #include "SDL_thread.h" #include "SDL_main.h" diff --git a/alienblaster/project/src/DemoActivity.java b/alienblaster/project/src/DemoActivity.java index f786a2b5f..4b1059986 100644 --- a/alienblaster/project/src/DemoActivity.java +++ b/alienblaster/project/src/DemoActivity.java @@ -113,14 +113,14 @@ class AccelerometerReader implements SensorListener { class DemoRenderer implements GLSurfaceView.Renderer { - public DemoRenderer(Activity context) + public DemoRenderer(Activity _context) { super(); - accelerometer = new AccelerometerReader(context); + context = _context; } public void onSurfaceCreated(GL10 gl, EGLConfig config) { - nativeInit(); + // nativeInit(); } public void onSurfaceChanged(GL10 gl, int w, int h) { @@ -129,6 +129,10 @@ class DemoRenderer implements GLSurfaceView.Renderer { } public void onDrawFrame(GL10 gl) { + if( accelerometer == null) { + accelerometer = new AccelerometerReader(context); + nativeInit(); + } float [] f = accelerometer.readAccelerometer(); nativeRender(f[0], f[1], f[2]); } @@ -142,6 +146,7 @@ class DemoRenderer implements GLSurfaceView.Renderer { private static native void nativeRender(float accX, float accY, float accZ); private static native void nativeDone(); private AccelerometerReader accelerometer = null; + private Activity context = null; } class DemoGLSurfaceView extends GLSurfaceView {