浏览代码

Fix threaded handlers initialization, cleanup

AlexVinS 11 年之前
父节点
当前提交
c948891fc6
共有 5 个文件被更改,包括 22 次插入39 次删除
  1. 1 1
      client/CAdvmapInterface.cpp
  2. 17 21
      client/CMT.cpp
  3. 1 7
      client/Graphics.cpp
  4. 3 7
      client/gui/CGuiHandler.cpp
  5. 0 3
      client/gui/SDL_Extensions.cpp

+ 1 - 1
client/CAdvmapInterface.cpp

@@ -925,7 +925,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 			k -= SDLK_KP0 + 1;
 			#else
 			k -= SDLK_KP_1;
-			#endif // 0			
+			#endif // VCMI_SDL1			
 			if(k < 0 || k > 8)
 				return;
 

+ 17 - 21
client/CMT.cpp

@@ -137,28 +137,16 @@ void startGameFromFile(const std::string &fname)
 void init()
 {
 	CStopWatch tmh, pomtime;
-    logGlobal->infoStream() << "\tInitializing minors: " << pomtime.getDiff();
-
-	//initializing audio
-	// Note: because of interface button range, volume can only be a
-	// multiple of 11, from 0 to 99.
-	CCS->soundh = new CSoundHandler;
-	CCS->soundh->init();
-	CCS->soundh->setVolume(settings["general"]["sound"].Float());
-	CCS->musich = new CMusicHandler;
-	CCS->musich->init();
-	CCS->musich->setVolume(settings["general"]["music"].Float());
-    logGlobal->infoStream()<<"\tInitializing sound: "<<pomtime.getDiff();
-    logGlobal->infoStream()<<"Initializing screen and sound handling: "<<tmh.getDiff();
 
 	loadDLLClasses();
 	const_cast<CGameInfo*>(CGI)->setFromLib();
 
     logGlobal->infoStream()<<"Initializing VCMI_Lib: "<<tmh.getDiff();
 
-	pomtime.getDiff();
+
 	if(!gNoGUI)
 	{
+		pomtime.getDiff();
 		CCS->curh = new CCursorHandler;
 		graphics = new Graphics(); // should be before curh->init()
 
@@ -168,7 +156,7 @@ void init()
 		pomtime.getDiff();
 
 		graphics->loadHeroAnims();
-		logGlobal->infoStream()<<"\tMain graphics: "<<tmh.getDiff();
+		logGlobal->infoStream()<<"\tMain graphics: "<<pomtime.getDiff();
 		logGlobal->infoStream()<<"Initializing game graphics: "<<tmh.getDiff();
 
 		CMessage::init();
@@ -400,11 +388,21 @@ int main(int argc, char** argv)
 
     logGlobal->infoStream()<<"\tInitializing video: "<<pomtime.getDiff();
 
-#if defined(__ANDROID__) || !defined(VCMI_SDL1)
+#if defined(__ANDROID__)
 	//on Android threaded init is broken
 	#define VCMI_NO_THREADED_LOAD
 #endif // defined
 
+	//initializing audio
+	// Note: because of interface button range, volume can only be a
+	// multiple of 11, from 0 to 99.
+	CCS->soundh = new CSoundHandler;
+	CCS->soundh->init();
+	CCS->soundh->setVolume(settings["general"]["sound"].Float());
+	CCS->musich = new CMusicHandler;
+	CCS->musich->init();
+	CCS->musich->setVolume(settings["general"]["music"].Float());
+    logGlobal->infoStream()<<"Initializing screen and sound handling: "<<pomtime.getDiff();
 
 #ifndef VCMI_NO_THREADED_LOAD
 	//we can properly play intro only in the main thread, so we have to move loading to the separate thread
@@ -1043,10 +1041,8 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo
 	
 	if(!recreateWindow(w,h,bpp,fullscreen))
 	{
-		return;
-	}
-
-	
+		throw std::runtime_error("Requested screen resolution is not available\n");
+	}	
 #endif // VCMI_SDL1
 }
 
@@ -1144,7 +1140,7 @@ static void handleEvent(SDL_Event & ev)
 			fullScreenChanged();
 			break;
 		default:
-			logGlobal->errorStream() << "Error: unknown user event. Code " << ev.user.code;		
+			logGlobal->errorStream() << "Unknown user event. Code " << ev.user.code;		
 			break;	
 		}
 

+ 1 - 7
client/Graphics.cpp

@@ -75,13 +75,7 @@ void Graphics::loadPaletteAndColors()
 		neutralColorPalette[i].r = reader.readUInt8();
 		neutralColorPalette[i].g = reader.readUInt8();
 		neutralColorPalette[i].b = reader.readUInt8();
-		#ifdef VCMI_SDL1
-		neutralColorPalette[i].unused = reader.readUInt8();
-		neutralColorPalette[i].unused = !neutralColorPalette[i].unused;
-		#else
-		neutralColorPalette[i].a = reader.readUInt8();
-		neutralColorPalette[i].a = !neutralColorPalette[i].a;
-		#endif // 0
+		CSDL_Ext::colorSetAlpha(neutralColorPalette[i], !reader.readUInt8());
 	}
 	//colors initialization
 	SDL_Color colors[]  = { 

+ 3 - 7
client/gui/CGuiHandler.cpp

@@ -304,6 +304,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
 			it->textEdited(sEvent->edit);
 		}
 	}	
+	//todo: muiltitouch
 	#endif // VCMI_SDL1
 	else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
 	{
@@ -472,7 +473,7 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key )
 	case SDLK_RIGHT:
 		return SDLK_KP6;
 	default:
-		assert(0);
+		throw std::runtime_error("Wrong key!");assert(0);
 	}	
 	#else
 	switch(key)
@@ -486,10 +487,9 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key )
 	case SDLK_RIGHT:
 		return SDLK_KP_6;
 	default:
-		assert(0);
+		throw std::runtime_error("Wrong key!");
 	}	
 	#endif // 0
-	throw std::runtime_error("Wrong key!");
 }
 
 SDLKey CGuiHandler::numToDigit( SDLKey key )
@@ -548,11 +548,7 @@ bool CGuiHandler::isNumKey( SDLKey key, bool number )
 
 bool CGuiHandler::isArrowKey( SDLKey key )
 {
-	#ifdef VCMI_SDL1
-	return key >= SDLK_UP && key <= SDLK_LEFT;
-	#else
 	return key == SDLK_UP || key == SDLK_DOWN || key == SDLK_LEFT || key == SDLK_RIGHT;
-	#endif
 }
 
 bool CGuiHandler::amIGuiThread()

+ 0 - 3
client/gui/SDL_Extensions.cpp

@@ -515,9 +515,6 @@ void CSDL_Ext::update(SDL_Surface * what)
 	if(0 !=SDL_UpdateTexture(screenTexture, nullptr, what->pixels, what->pitch))
 		logGlobal->errorStream() << __FUNCTION__ << "SDL_UpdateTexture " << SDL_GetError();		
 	#endif // VCMI_SDL1
-
-		
-	
 }
 void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color)
 {