diff --git a/project/jni/application/vcmi/vcmi-android.diff b/project/jni/application/vcmi/vcmi-android.diff index 94fa39cd9..7a64ad5cd 100644 --- a/project/jni/application/vcmi/vcmi-android.diff +++ b/project/jni/application/vcmi/vcmi-android.diff @@ -2,14 +2,6 @@ Index: server/CGameHandler.cpp =================================================================== --- server/CGameHandler.cpp (revision 2170) +++ server/CGameHandler.cpp (working copy) -@@ -24,6 +24,7 @@ - #include - #include - #include "../lib/CCreatureSet.h" -+ - - /* - * CGameHandler.cpp, part of VCMI engine @@ -1786,7 +1787,7 @@ iw.player = h1->tempOwner; iw.components.push_back(Component(Component::SEC_SKILL, 18, ScholarLevel, 0)); @@ -170,48 +162,82 @@ Index: global.h }; extern DLL_EXPORT CLogger tlog0; //green - standard progress info +Index: client/GUIBase.cpp +=================================================================== +--- client/GUIBase.cpp (revision 2170) ++++ client/GUIBase.cpp (working copy) +@@ -11,6 +11,7 @@ + #include "../CThreadHelper.h" + #include "CConfigHandler.h" + #include ++ + + /* + * GUIBase.cpp, part of VCMI engine +@@ -364,6 +365,26 @@ + } + } HANDLE_EXCEPTION + } ++ ++void CGuiHandler::loopInitFromMainThread() ++{ ++ setThreadName(-1, "CGuiHandler::run"); ++ CCS->curh->centerCursor(); ++ mainFPSmng->init(); // resets internal clock, needed for FPS manager ++} ++ ++bool CGuiHandler::loopFromMainThread() ++{ ++ if(terminate) ++ return false; ++ if(curInt) ++ curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment ++ ++ mainFPSmng->framerateDelay(); // holds a constant FPS ++ return true; ++} ++ ++ + + CGuiHandler::CGuiHandler() + :lastClick(-500, -500) Index: client/CMT.cpp =================================================================== --- client/CMT.cpp (revision 2170) +++ client/CMT.cpp (working copy) -@@ -55,6 +55,8 @@ - #if __MINGW32__ - #undef main - #endif -+ -+ - - namespace po = boost::program_options; - -@@ -92,6 +94,7 @@ +@@ -90,8 +92,10 @@ + void dispose(); + void playIntro(); static void listenForEvents(); ++static bool loopListenForEvents(bool block); void requestChangingResolution(); void startGame(StartInfo * options, CConnection *serv = NULL); + #ifndef _WIN32 #ifndef _GNU_SOURCE -@@ -102,6 +105,7 @@ +@@ -126,6 +130,7 @@ + GDefaultOptions.settingsChanged(); + } + } ++ + THC tlog0<<"\tLoading default system settings: "<soundh->init(); + CCS->soundh->setVolume(GDefaultOptions.soundVolume); + CCS->musich = new CMusicHandler; ++ + //CGI->musich->init(); + //CGI->musich->setVolume(GDefaultOptions.musicVolume); + tlog0<<"\tInitializing sound: "<(CGI)->setFromLib(); +@@ -184,11 +191,15 @@ } @@ -225,95 +251,55 @@ Index: client/CMT.cpp #endif +#endif { -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__); tlog0 << "Starting... " << std::endl; -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__); po::options_description opts("Allowed options"); - opts.add_options() - ("help,h", "display help and exit") - ("version,v", "display version information and exit") - ("battle,b", po::value(), "runs game in duel mode (battle-only") - ("nointro,i", "skips intro movies"); -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__); - - po::variables_map vm; - if(argc > 1) -@@ -210,6 +224,7 @@ - tlog1 << "Failure during parsing command-line options:\n" << e.what() << std::endl; - } - } -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__); - - po::notify(vm); - if(vm.count("help")) -@@ -222,10 +237,12 @@ - prog_version(); - return 0; - } -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__); - - //Set environment vars to make window centered. Sometimes work, sometimes not. :/ - putenv((char*)"SDL_VIDEO_WINDOW_POS"); - putenv((char*)"SDL_VIDEO_CENTERED=1"); -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__); - - timeHandler total, pomtime; - std::cout.flags(std::ios::unitbuf); -@@ -235,8 +252,10 @@ +@@ -235,7 +246,6 @@ console->start(); atexit(dispose); tlog0 <<"Creating console and logfile: "<playerInfos[1].color = 1; startGame(si); } -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__); ++#ifdef ANDROID ++ GH.loopInitFromMainThread(); ++ while( GH.loopFromMainThread() ) ++ { ++ while( loopListenForEvents(false) ); ++ } ++#else mainGUIThread = new boost::thread(&CGuiHandler::run, boost::ref(GH)); listenForEvents(); -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__); ++#endif return 0; } -@@ -535,10 +560,12 @@ +@@ -535,10 +557,12 @@ tlog2 << "Warning: SDL says that " << bpp << "bpp is wrong and suggests " << suggestedBpp << std::endl; } @@ -326,47 +312,88 @@ Index: client/CMT.cpp if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == NULL) { -@@ -717,3 +744,4 @@ +@@ -583,14 +607,27 @@ + setResolution = true; + } + ++ + static void listenForEvents() + { +- while(1) //main SDL events loop +- { ++ while(loopListenForEvents(true)); //main SDL events loop ++} ++ ++static bool loopListenForEvents(bool block) ++{ + SDL_Event *ev = new SDL_Event(); + + //tlog0 << "Waiting... "; +- int ret = SDL_WaitEvent(ev); ++ int ret = 1; ++ if( block ) ++ ret = SDL_WaitEvent(ev); ++ else ++ { ++ if(!SDL_PollEvent(ev)) { ++ delete ev; ++ return false; ++ } ++ } + //tlog0 << "got " << (int)ev->type; + if (ret == 0 || (ev->type==SDL_QUIT) || + (ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4 && (ev->key.keysym.mod & KMOD_ALT))) +@@ -609,7 +646,7 @@ + SDL_Delay(750); + SDL_Quit(); + tlog0 << "Ending...\n"; +- break; ++ return false; + } + else if(LOCPLINT && ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4) + { +@@ -618,7 +655,7 @@ + setScreenRes(conf.cc.screenx, conf.cc.screeny, conf.cc.bpp, full); + GH.totalRedraw(); + delete ev; +- continue; ++ return true; + } + else if(ev->type == SDL_USEREVENT) + { +@@ -648,7 +685,7 @@ + } + + delete ev; +- continue; ++ return true; + } + + //tlog0 << " pushing "; +@@ -656,7 +693,7 @@ + events.push(ev); + eventsM.unlock(); + //tlog0 << " done\n"; +- } ++ return true; + } + + void startGame(StartInfo * options, CConnection *serv/* = NULL*/) +@@ -717,3 +754,4 @@ ev.user.code = 1; SDL_PushEvent(&ev); } + -Index: client/CVideoHandler.cpp +Index: client/GUIBase.h =================================================================== ---- client/CVideoHandler.cpp (revision 2170) -+++ client/CVideoHandler.cpp (working copy) -@@ -6,6 +6,7 @@ - #include "SDL_Extensions.h" - #include "CPlayerInterface.h" - #include "boost/filesystem.hpp" -+ - - extern SystemOptions GDefaultOptions; - //reads events and returns true on key down -@@ -62,6 +63,7 @@ - void DLLHandler::Instantiate(const char *filename) - { - name = filename; -+ tlog1 << "Loading dynamic library " << filename << std::endl; - #ifdef _WIN32 - dll = LoadLibraryA(filename); - if(!dll) -@@ -72,6 +74,7 @@ - #else - dll = dlopen(filename,RTLD_LOCAL | RTLD_LAZY); - #endif -+ tlog1 << "Loading dynamic library " << filename << dll ? " successful" : " failed" <