CMT.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. // CMT.cpp : Defines the entry point for the console application.
  2. //
  3. #include "../stdafx.h"
  4. #include <cmath>
  5. #include <string>
  6. #include <vector>
  7. #include <queue>
  8. #include <cmath>
  9. #include <boost/algorithm/string.hpp>
  10. #include <boost/filesystem/operations.hpp>
  11. #include <boost/thread.hpp>
  12. #include <SDL_mixer.h>
  13. #include "SDL_Extensions.h"
  14. #include "SDL_framerate.h"
  15. #include "CGameInfo.h"
  16. #include "mapHandler.h"
  17. #include "../global.h"
  18. #include "CPreGame.h"
  19. #include "CCastleInterface.h"
  20. #include "../CConsoleHandler.h"
  21. #include "CCursorHandler.h"
  22. #include "../lib/CGameState.h"
  23. #include "../CCallback.h"
  24. #include "CPlayerInterface.h"
  25. #include "CAdvmapInterface.h"
  26. #include "../hch/CBuildingHandler.h"
  27. #include "../hch/CVideoHandler.h"
  28. #include "../hch/CHeroHandler.h"
  29. #include "../hch/CCreatureHandler.h"
  30. #include "../hch/CSpellHandler.h"
  31. #include "../hch/CMusicHandler.h"
  32. #include "../hch/CVideoHandler.h"
  33. #include "../hch/CLodHandler.h"
  34. #include "../hch/CDefHandler.h"
  35. #include "../hch/CAmbarCendamo.h"
  36. #include "../hch/CGeneralTextHandler.h"
  37. #include "Graphics.h"
  38. #include "Client.h"
  39. #include "CConfigHandler.h"
  40. #include "../lib/Connection.h"
  41. #include "../lib/VCMI_Lib.h"
  42. #include "../lib/VCMIDirs.h"
  43. #include <cstdlib>
  44. #include "../lib/NetPacks.h"
  45. #include "CMessage.h"
  46. #include "../hch/CObjectHandler.h"
  47. #ifdef _WIN32
  48. #include "SDL_syswm.h"
  49. #endif
  50. #if __MINGW32__
  51. #undef main
  52. #endif
  53. /*
  54. * CMT.cpp, part of VCMI engine
  55. *
  56. * Authors: listed in file AUTHORS in main folder
  57. *
  58. * License: GNU General Public License v2.0 or later
  59. * Full text of license available in license.txt file, in main folder
  60. *
  61. */
  62. std::string NAME_AFFIX = "client";
  63. std::string NAME = NAME_VER + std::string(" (") + NAME_AFFIX + ')'; //application name
  64. CGuiHandler GH;
  65. static CClient *client;
  66. SDL_Surface *screen = NULL, //main screen surface
  67. *screen2 = NULL,//and hlp surface (used to store not-active interfaces layer)
  68. *screenBuf = screen; //points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed
  69. static boost::thread *mainGUIThread;
  70. SystemOptions GDefaultOptions;
  71. VCMIDirs GVCMIDirs;
  72. std::queue<SDL_Event*> events;
  73. boost::mutex eventsM;
  74. static bool gOnlyAI = false;
  75. static bool setResolution = false; //set by event handling thread after resolution is adjusted
  76. void processCommand(const std::string &message);
  77. static void setScreenRes(int w, int h, int bpp, bool fullscreen);
  78. void dispose();
  79. void playIntro();
  80. static void listenForEvents();
  81. #ifndef _WIN32
  82. #ifndef _GNU_SOURCE
  83. #define _GNU_SOURCE
  84. #endif
  85. #include <getopt.h>
  86. #endif
  87. void init()
  88. {
  89. timeHandler tmh, pomtime;
  90. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  91. int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
  92. #else
  93. int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000;
  94. #endif
  95. CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask);
  96. tlog0 << "\tInitializing minors: " << pomtime.getDif() << std::endl;
  97. {
  98. //read system options
  99. CLoadFile settings(GVCMIDirs.UserPath + "/config/sysopts.bin", false);
  100. if(settings.sfile)
  101. {
  102. settings >> GDefaultOptions;
  103. }
  104. else //file not found (probably, may be also some kind of access problem
  105. {
  106. tlog2 << "Warning: Cannot read system options, default settings will be used.\n";
  107. //Try to create file
  108. tlog2 << "VCMI will try to save default system options...\n";
  109. GDefaultOptions.settingsChanged();
  110. }
  111. }
  112. THC tlog0<<"\tLoading default system settings: "<<pomtime.getDif()<<std::endl;
  113. //initializing audio
  114. // Note: because of interface button range, volume can only be a
  115. // multiple of 11, from 0 to 99.
  116. CGI->soundh = new CSoundHandler;
  117. CGI->soundh->init();
  118. CGI->soundh->setVolume(GDefaultOptions.soundVolume);
  119. CGI->musich = new CMusicHandler;
  120. //CGI->musich->init();
  121. //CGI->musich->setVolume(GDefaultOptions.musicVolume);
  122. tlog0<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl;
  123. tlog0<<"Initializing screen and sound handling: "<<tmh.getDif()<<std::endl;
  124. initDLL(::console,logfile);
  125. CGI->setFromLib();
  126. CGI->soundh->initCreaturesSounds(CGI->creh->creatures);
  127. CGI->soundh->initSpellsSounds(CGI->spellh->spells);
  128. tlog0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
  129. pomtime.getDif();
  130. CGI->curh = new CCursorHandler;
  131. CGI->curh->initCursor();
  132. CGI->curh->show();
  133. tlog0<<"Screen handler: "<<pomtime.getDif()<<std::endl;
  134. pomtime.getDif();
  135. graphics = new Graphics();
  136. graphics->loadHeroAnims();
  137. tlog0<<"\tMain graphics: "<<tmh.getDif()<<std::endl;
  138. tlog0<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
  139. CMessage::init();
  140. tlog0<<"Message handler: "<<tmh.getDif()<<std::endl;
  141. //CPG = new CPreGame(); //main menu and submenus
  142. //tlog0<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
  143. }
  144. #ifndef _WIN32
  145. static void prog_version(void)
  146. {
  147. printf("%s\n", NAME_VER);
  148. printf(" data directory: %s\n", DATA_DIR);
  149. printf(" library directory: %s\n", LIB_DIR);
  150. printf(" binary directory: %s\n", BIN_DIR);
  151. }
  152. static void prog_help(const char *progname)
  153. {
  154. printf("%s - A Heroes of Might and Magic 3 clone\n", NAME_VER);
  155. printf("Copyright (C) 2007-2010 VCMI dev team - see AUTHORS file\n");
  156. printf("This is free software; see the source for copying conditions. There is NO\n");
  157. printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
  158. printf("\n");
  159. printf("Usage:\n");
  160. printf(" -h, --help display this help and exit\n");
  161. printf(" -v, --version display version information and exit\n");
  162. }
  163. #endif
  164. #ifdef _WIN32
  165. int _tmain(int argc, _TCHAR* argv[])
  166. #else
  167. int main(int argc, char** argv)
  168. #endif
  169. {
  170. #ifndef _WIN32
  171. struct option long_options[] = {
  172. { "help", 0, NULL, 'h' },
  173. { "version", 0, NULL, 'v' },
  174. { NULL, 0, NULL, 0 }
  175. };
  176. while(1) {
  177. int c;
  178. int option_index;
  179. c = getopt_long (argc, argv, "hv",
  180. long_options, &option_index);
  181. if (c == EOF)
  182. break;
  183. else if (c == '?')
  184. return -1;
  185. switch(c) {
  186. case 'h':
  187. prog_help(argv[0]);
  188. return 0;
  189. break;
  190. case 'v':
  191. prog_version();
  192. return 0;
  193. break;
  194. }
  195. }
  196. if (optind < argc) {
  197. printf ("Extra arguments: %s\n", argv[optind++]);
  198. return 1;
  199. }
  200. #endif
  201. //Set environment vars to make window centered. Sometimes work, sometimes not. :/
  202. putenv("SDL_VIDEO_WINDOW_POS");
  203. putenv("SDL_VIDEO_CENTERED=1");
  204. tlog0 << "Starting... " << std::endl;
  205. timeHandler total, pomtime;
  206. std::cout.flags(std::ios::unitbuf);
  207. logfile = new std::ofstream("VCMI_Client_log.txt");
  208. console = new CConsoleHandler;
  209. *console->cb = boost::bind(&processCommand, _1);
  210. console->start();
  211. atexit(dispose);
  212. tlog0 <<"Creating console and logfile: "<<pomtime.getDif() << std::endl;
  213. conf.init();
  214. tlog0 <<"Loading settings: "<<pomtime.getDif() << std::endl;
  215. tlog0 << NAME << std::endl;
  216. srand ( time(NULL) );
  217. //CPG=NULL;
  218. CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.)
  219. if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO))
  220. {
  221. tlog1<<"Something was wrong: "<< SDL_GetError() << std::endl;
  222. exit(-1);
  223. }
  224. atexit(SDL_Quit);
  225. setScreenRes(800,600,conf.cc.bpp,conf.cc.fullscreen);
  226. tlog0 <<"\tInitializing screen: "<<pomtime.getDif() << std::endl;
  227. // Initialize video
  228. CGI->videoh = new CVideoPlayer;
  229. tlog0<<"\tInitializing video: "<<pomtime.getDif()<<std::endl;
  230. //we can properly play intro only in the main thread, so we have to move loading to the separate thread
  231. boost::thread loading(init);
  232. playIntro();
  233. SDL_FillRect(screen,NULL,0);
  234. SDL_Flip(screen);
  235. loading.join();
  236. tlog0<<"Initialization of VCMI (together): "<<total.getDif()<<std::endl;
  237. CGI->musich->playMusic(musicBase::mainMenu, -1);
  238. GH.curInt = new CGPreGame; //will set CGP pointer to itself
  239. mainGUIThread = new boost::thread(&CGuiHandler::run, boost::ref(GH));
  240. listenForEvents();
  241. return 0;
  242. }
  243. void processCommand(const std::string &message)
  244. {
  245. std::istringstream readed;
  246. readed.str(message);
  247. std::string cn; //command name
  248. readed >> cn;
  249. int3 src, dst;
  250. // int heronum;//TODO use me
  251. int3 dest;
  252. if(LOCPLINT && LOCPLINT->cingconsole)
  253. LOCPLINT->cingconsole->print(message);
  254. if(message==std::string("die, fool"))
  255. exit(EXIT_SUCCESS);
  256. else if(cn==std::string("activate"))
  257. {
  258. int what;
  259. readed >> what;
  260. switch (what)
  261. {
  262. case 0:
  263. GH.topInt()->activate();
  264. break;
  265. case 1:
  266. adventureInt->activate();
  267. break;
  268. case 2:
  269. LOCPLINT->castleInt->activate();
  270. break;
  271. }
  272. }
  273. else if(cn=="redraw")
  274. {
  275. GH.totalRedraw();
  276. }
  277. else if(cn=="screen")
  278. {
  279. tlog0 << "Screenbuf points to ";
  280. if(screenBuf == screen)
  281. tlog1 << "screen";
  282. else if(screenBuf == screen2)
  283. tlog1 << "screen2";
  284. else
  285. tlog1 << "?!?";
  286. tlog1 << std::endl;
  287. SDL_SaveBMP(screen, "Screen_c.bmp");
  288. SDL_SaveBMP(screen2, "Screen2_c.bmp");
  289. }
  290. else if(cn=="save")
  291. {
  292. std::string fname;
  293. readed >> fname;
  294. client->save(fname);
  295. }
  296. //else if(cn=="list")
  297. //{
  298. // if(CPG)
  299. // for(int i = 0; i < CPG->ourScenSel->mapsel.ourGames.size(); i++)
  300. // tlog0 << i << ".\t" << CPG->ourScenSel->mapsel.ourGames[i]->filename << std::endl;
  301. //}
  302. else if(cn=="load")
  303. {
  304. // TODO: this code should end the running game and manage to call startGame instead
  305. std::string fname;
  306. readed >> fname;
  307. client->loadGame(fname);
  308. }
  309. //else if(cn=="ln")
  310. //{
  311. // int num;
  312. // readed >> num;
  313. // std::string &name = CPG->ourScenSel->mapsel.ourGames[num]->filename;
  314. // client->load(name.substr(0, name.size()-6));
  315. //}
  316. else if(cn=="resolution" || cn == "r")
  317. {
  318. if(LOCPLINT)
  319. {
  320. tlog1 << "Resolution can be set only before starting the game.\n";
  321. return;
  322. }
  323. std::map<std::pair<int,int>, config::GUIOptions >::iterator j;
  324. int i=1, hlp=1;
  325. tlog4 << "Available screen resolutions:\n";
  326. for(j=conf.guiOptions.begin(); j!=conf.guiOptions.end(); j++)
  327. tlog4 << i++ <<". " << j->first.first << " x " << j->first.second << std::endl;
  328. tlog4 << "Type number from 1 to " << i-1 << " to set appropriate resolution or 0 to cancel.\n";
  329. std::cin >> i;
  330. if(i < 0 || i > conf.guiOptions.size() || std::cin.bad() || std::cin.fail())
  331. {
  332. std::cin.clear();
  333. tlog1 << "Invalid resolution ID! Not a number between 0 and " << conf.guiOptions.size() << ". No settings changed.\n";
  334. }
  335. else if(!i)
  336. {
  337. return;
  338. }
  339. else
  340. {
  341. for(j=conf.guiOptions.begin(); j!=conf.guiOptions.end() && hlp++<i; j++); //move j to the i-th resolution info
  342. conf.cc.resx = j->first.first;
  343. conf.cc.resy = j->first.second;
  344. tlog0 << "Screen resolution set to " << conf.cc.resx << " x " << conf.cc.resy <<". It will be aplied when the game starts.\n";
  345. }
  346. }
  347. else if(message=="get txt")
  348. {
  349. boost::filesystem::create_directory("Extracted_txts");
  350. tlog0<<"Command accepted. Opening .lod file...\t";
  351. CLodHandler * txth = new CLodHandler;
  352. txth->init(std::string(DATA_DIR "/Data/H3bitmap.lod"),"");
  353. tlog0<<"done.\nScanning .lod file\n";
  354. int curp=0;
  355. std::string pattern = ".TXT", pom;
  356. for(int i=0;i<txth->entries.size(); i++)
  357. {
  358. pom = txth->entries[i].nameStr;
  359. if(boost::algorithm::find_last(pom,pattern))
  360. {
  361. txth->extractFile(std::string(DATA_DIR "/Extracted_txts/")+pom,pom);
  362. }
  363. if(i%8) continue;
  364. int p2 = ((float)i/(float)txth->entries.size())*(float)100;
  365. if(p2!=curp)
  366. {
  367. curp = p2;
  368. tlog0<<"\r"<<curp<<"%";
  369. }
  370. }
  371. tlog0<<"\rExtracting done :)\n";
  372. }
  373. else if(cn=="crash")
  374. {
  375. int *ptr = NULL;
  376. *ptr = 666;
  377. //disaster!
  378. }
  379. else if(cn == "onlyai")
  380. {
  381. gOnlyAI = true;
  382. }
  383. else if(cn == "mp" && adventureInt)
  384. {
  385. if(const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(adventureInt->selection))
  386. tlog0 << h->movement << "; max: " << h->maxMovePoints(true) << "/" << h->maxMovePoints(false) << std::endl;
  387. }
  388. else if(client && client->serv && client->serv->connected) //send to server
  389. {
  390. PlayerMessage pm(LOCPLINT->playerID,message);
  391. *client->serv << &pm;
  392. }
  393. }
  394. //plays intro, ends when intro is over or button has been pressed (handles events)
  395. void playIntro()
  396. {
  397. if(CGI->videoh->openAndPlayVideo("3DOLOGO.SMK", 60, 40, screen, true))
  398. {
  399. CGI->videoh->openAndPlayVideo("AZVS.SMK", 60, 80, screen, true);
  400. }
  401. }
  402. void dispose()
  403. {
  404. delete logfile;
  405. if (console)
  406. delete console;
  407. }
  408. static void setScreenRes(int w, int h, int bpp, bool fullscreen)
  409. {
  410. // VCMI will only work with 3 or 4 bytes per pixel
  411. if (bpp < 24) bpp = 24;
  412. if (bpp > 32) bpp = 32;
  413. // Try to use the best screen depth for the display
  414. int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0));
  415. if(suggestedBpp == 0)
  416. {
  417. tlog1 << "Error: SDL says that " << w << "x" << h << " resolution is not available!\n";
  418. return;
  419. }
  420. bool bufOnScreen = (screenBuf == screen);
  421. if(suggestedBpp != bpp)
  422. {
  423. tlog2 << "Warning: SDL says that " << bpp << "bpp is wrong and suggests " << suggestedBpp << std::endl;
  424. }
  425. if(screen) //screen has been already initialized
  426. SDL_QuitSubSystem(SDL_INIT_VIDEO);
  427. SDL_InitSubSystem(SDL_INIT_VIDEO);
  428. if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == NULL)
  429. {
  430. tlog1 << "Requested screen resolution is not available (" << w << "x" << h << "x" << suggestedBpp << "bpp)\n";
  431. throw "Requested screen resolution is not available\n";
  432. }
  433. tlog0 << "New screen flags: " << screen->flags << std::endl;
  434. if(screen2)
  435. SDL_FreeSurface(screen2);
  436. screen2 = CSDL_Ext::copySurface(screen);
  437. SDL_EnableUNICODE(1);
  438. SDL_WM_SetCaption(NAME.c_str(),""); //set window title
  439. SDL_ShowCursor(SDL_DISABLE);
  440. SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
  441. #ifdef _WIN32
  442. SDL_SysWMinfo wm;
  443. SDL_VERSION(&wm.version);
  444. int getwm = SDL_GetWMInfo(&wm);
  445. if(getwm == 1)
  446. {
  447. int sw = GetSystemMetrics(SM_CXSCREEN),
  448. sh = GetSystemMetrics(SM_CYSCREEN);
  449. RECT curpos;
  450. GetWindowRect(wm.window,&curpos);
  451. int ourw = curpos.right - curpos.left,
  452. ourh = curpos.bottom - curpos.top;
  453. SetWindowPos(wm.window, 0, (sw - ourw)/2, (sh - ourh)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
  454. }
  455. else
  456. {
  457. tlog3 << "Something went wrong, getwm=" << getwm << std::endl;
  458. tlog3 << "SDL says: " << SDL_GetError() << std::endl;
  459. tlog3 << "Window won't be centered.\n";
  460. }
  461. #endif
  462. //TODO: centering game window on other platforms (or does the environment do their job correctly there?)
  463. screenBuf = bufOnScreen ? screen : screen2;
  464. }
  465. static void listenForEvents()
  466. {
  467. while(1) //main SDL events loop
  468. {
  469. SDL_Event *ev = new SDL_Event();
  470. //tlog0 << "Waiting... ";
  471. int ret = SDL_WaitEvent(ev);
  472. //tlog0 << "got " << (int)ev->type;
  473. if (ret == 0 || (ev->type==SDL_QUIT) ||
  474. (ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4 && (ev->key.keysym.mod & KMOD_ALT)))
  475. {
  476. if (client)
  477. client->stop();
  478. if (mainGUIThread)
  479. {
  480. GH.terminate = true;
  481. mainGUIThread->join();
  482. delete mainGUIThread;
  483. mainGUIThread = NULL;
  484. }
  485. delete console;
  486. console = NULL;
  487. SDL_Delay(750);
  488. SDL_Quit();
  489. tlog0 << "Ending...\n";
  490. break;
  491. }
  492. else if(LOCPLINT && ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4)
  493. {
  494. boost::unique_lock<boost::recursive_mutex> lock(*LOCPLINT->pim);
  495. bool full = !(screen->flags&SDL_FULLSCREEN);
  496. setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,full);
  497. GH.totalRedraw();
  498. delete ev;
  499. continue;
  500. }
  501. else if(ev->type == SDL_USEREVENT && ev->user.code == 1)
  502. {
  503. setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,conf.cc.fullscreen);
  504. setResolution = true;
  505. delete ev;
  506. continue;
  507. }
  508. else if (ev->type == SDL_USEREVENT && ev->user.code == 2) //something want to quit to main menu
  509. {
  510. client->stop();
  511. delete client;
  512. client = NULL;
  513. delete ev;
  514. GH.curInt = CGP;
  515. GH.defActionsDef = 63;
  516. continue;
  517. }
  518. //tlog0 << " pushing ";
  519. eventsM.lock();
  520. events.push(ev);
  521. eventsM.unlock();
  522. //tlog0 << " done\n";
  523. }
  524. }
  525. void startGame(StartInfo * options)
  526. {
  527. GH.curInt =NULL;
  528. if(gOnlyAI)
  529. {
  530. for (size_t i =0; i < options->playerInfos.size(); i++)
  531. {
  532. options->playerInfos[i].human = false;
  533. }
  534. }
  535. if(screen->w != conf.cc.resx || screen->h != conf.cc.resy)
  536. {
  537. //push special event to order event reading thread to change resolution
  538. SDL_Event ev;
  539. ev.type = SDL_USEREVENT;
  540. ev.user.code = 1;
  541. SDL_PushEvent(&ev);
  542. }
  543. else
  544. setResolution = true;
  545. client = new CClient;
  546. switch(options->mode) //new game
  547. {
  548. case 0:
  549. case 2:
  550. client->newGame(NULL, options);
  551. break;
  552. case 1:
  553. std::string fname = options->mapname;
  554. boost::algorithm::erase_last(fname,".vlgm1");
  555. client->loadGame(fname);
  556. break;
  557. }
  558. CGI->musich->stopMusic();
  559. //allow event handling thread change resolution
  560. eventsM.unlock();
  561. while(!setResolution) boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  562. eventsM.lock();
  563. client->connectionHandler = new boost::thread(&CClient::run, client);
  564. }