  #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<std::string>(), "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: "<<pomtime.getDif() << std::endl;
-+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
- 
+-
  	conf.init();
-+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
  	tlog0 <<"Loading settings: "<<pomtime.getDif() << std::endl;
  	tlog0 << NAME << std::endl;
- 
-@@ -244,6 +263,7 @@
- 	
- 	CCS = new CClientState;
- 	CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler etc.)
-+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
- 
- 	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO))
- 	{
-@@ -251,6 +271,7 @@
- 		exit(-1);
- 	}
- 	atexit(SDL_Quit);
-+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
- 
- 	setScreenRes(conf.cc.pregameResx, conf.cc.pregameResy, conf.cc.bpp, conf.cc.fullscreen);
- 	tlog0 <<"\tInitializing screen: "<<pomtime.getDif() << std::endl;
-@@ -261,6 +282,7 @@
+@@ -260,14 +270,18 @@
+ 	tlog0<<"\tInitializing video: "<<pomtime.getDif()<<std::endl;
  
  	//we can properly play intro only in the main thread, so we have to move loading to the separate thread
- 	boost::thread loading(init);
-+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
- 
+-	boost::thread loading(init);
+-
++#ifdef ANDROID
++	init();
  	if(!vm.count("battle") && !vm.count("nointro"))
  		playIntro();
-@@ -269,6 +291,7 @@
++#else
++	boost::thread loading(init);
+ 
++
+ 	SDL_FillRect(screen,NULL,0);
  	CSDL_Ext::update(screen);
  	loading.join();
++#endif
  	tlog0<<"Initialization of VCMI (together): "<<total.getDif()<<std::endl;
-+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
  
  	if(!vm.count("battle"))
- 	{
-@@ -284,8 +307,10 @@
+@@ -284,8 +298,16 @@
  		si->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;
  	}
  

===================================================================
--- server/CGameHandler.cpp	(revision 2170)
+++ server/CGameHandler.cpp	(working copy)
@@ -24,6 +24,7 @@
 #include <boost/random/variate_generator.hpp>
 #include <boost/random/poisson_distribution.hpp>
 #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));

 };
 
 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 <boost/lexical_cast.hpp>
+
 
 /*
  * 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)
@@ -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
@@ -126,6 +130,7 @@
 			GDefaultOptions.settingsChanged();
 		}
 	}
+
 	THC tlog0<<"\tLoading default system settings: "<<pomtime.getDif()<<std::endl;
 
 	//initializing audio
@@ -135,10 +140,12 @@
 	CCS->soundh->init();
 	CCS->soundh->setVolume(GDefaultOptions.soundVolume);
 	CCS->musich = new CMusicHandler;
+
 	//CGI->musich->init();
 	//CGI->musich->setVolume(GDefaultOptions.musicVolume);
 	tlog0<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl;
 	tlog0<<"Initializing screen and sound handling: "<<tmh.getDif()<<std::endl;
+
 
 	initDLL(::console,logfile);
 	const_cast<CGameInfo*>(CGI)->setFromLib();
@@ -184,11 +191,15 @@
 }
 
 
