void CLoadScreen::Init()
{
	activeController = this;

	//! hide the cursor until we are ingame
	SDL_ShowCursor(SDL_DISABLE);

	//! When calling this function, mod archives have to be loaded
	//! and gu->myPlayerNum has to be set.
	skirmishAIHandler.LoadPreGame();

#ifdef HEADLESS
	mt_loading = false;
#else
	const int mtCfg = configHandler->GetInt("LoadingMT");
	// user override
	mt_loading = (mtCfg > 0);
	// runtime detect. disable for intel/mesa drivers, they crash at multithreaded OpenGL (date: Nov. 2011)
	mt_loading |= (mtCfg < 0) && !globalRendering->haveMesa && !globalRendering->haveIntel;
#endif

	//! Create a thread during the loading that pings the host/server, so it knows that this client is still alive/loading
	netHeartbeatThread = new boost::thread(boost::bind<void, CNetProtocol, CNetProtocol*>(&CNetProtocol::UpdateLoop, net));

	game = new CGame(mapName, modName, saveFile);

	//FIXME: remove when LuaLoadScreen was added
	{
		const CTeam* team = teamHandler->Team(gu->myTeam);
		assert(team);
		const std::string mapStartPic(mapInfo->GetStringValue("Startpic"));

		if (mapStartPic.empty())
			RandomStartPicture(team->side);
		else
			LoadStartPicture(mapStartPic);

		const std::string mapStartMusic(mapInfo->GetStringValue("Startmusic"));
		if (!mapStartMusic.empty())
			Channels::BGMusic.StreamPlay(mapStartMusic);
	}

	try {
		//! Create the Game Loading Thread
		if (mt_loading)
			gameLoadThread = new COffscreenGLThread( boost::bind(&CGame::LoadGame, game, mapName) );

	} catch (const opengl_error& gle) {
		LOG_L(L_WARNING, "Offscreen GL Context creation failed, "
				"falling back to single-threaded loading. The problem was: %s",
				gle.what());
		mt_loading = false;
	}

	if (!mt_loading) {
		LOG("LoadingScreen: single-threaded");
		game->LoadGame(mapName);
	}
}
Exemple #2
0
void CLoadScreen::Init()
{
	activeController = this;

	//! hide the cursor until we are ingame
	SDL_ShowCursor(SDL_DISABLE);

	//! When calling this function, mod archives have to be loaded
	//! and gu->myPlayerNum has to be set.
	skirmishAIHandler.LoadPreGame();

#ifdef HEADLESS
	mt_loading = false;
#else
	mt_loading = configHandler->Get("LoadingMT", true);
#endif

	//! Create a thread during the loading that pings the host/server, so it knows that this client is still alive/loading
	netHeartbeatThread = new boost::thread(boost::bind<void, CNetProtocol, CNetProtocol*>(&CNetProtocol::UpdateLoop, net));

	game = new CGame(mapName, modName, saveFile);

	//FIXME: remove when LuaLoadScreen was added
	{
		const CTeam* team = teamHandler->Team(gu->myTeam);
		assert(team);
		const std::string mapStartPic(mapInfo->GetStringValue("Startpic"));

		if (mapStartPic.empty())
			RandomStartPicture(team->side);
		else
			LoadStartPicture(mapStartPic);

		const std::string mapStartMusic(mapInfo->GetStringValue("Startmusic"));
		if (!mapStartMusic.empty())
			Channels::BGMusic.StreamPlay(mapStartMusic);
	}

	try {
		//! Create the Game Loading Thread
		if (mt_loading)
			gameLoadThread = new COffscreenGLThread( boost::bind(&CGame::LoadGame, game, mapName) );

	} catch (opengl_error& gle) {
		//! Offscreen GL Context creation failed,
		//! fallback to singlethreaded loading.
		logOutput.Print(std::string(gle.what()));
		logOutput.Print("Fallback to singlethreaded loading.");
		mt_loading = false;
	}

	if (!mt_loading) {
		Draw();
		game->LoadGame(mapName);
	}
}