2
0

Client.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. #include "CMusicHandler.h"
  2. #include "../lib/CCampaignHandler.h"
  3. #include "../CCallback.h"
  4. #include "../CConsoleHandler.h"
  5. #include "CGameInfo.h"
  6. #include "../lib/CGameState.h"
  7. #include "CPlayerInterface.h"
  8. #include "../StartInfo.h"
  9. #include "../lib/BattleState.h"
  10. #include "../lib/CArtHandler.h"
  11. #include "../lib/CDefObjInfoHandler.h"
  12. #include "../lib/CGeneralTextHandler.h"
  13. #include "../lib/CHeroHandler.h"
  14. #include "../lib/CTownHandler.h"
  15. #include "../lib/CObjectHandler.h"
  16. #include "../lib/CBuildingHandler.h"
  17. #include "../lib/CSpellHandler.h"
  18. #include "../lib/Connection.h"
  19. #include "../lib/Interprocess.h"
  20. #include "../lib/NetPacks.h"
  21. #include "../lib/VCMI_Lib.h"
  22. #include "../lib/map.h"
  23. #include "mapHandler.h"
  24. #include "CConfigHandler.h"
  25. #include "Client.h"
  26. #include "GUIBase.h"
  27. #include <boost/bind.hpp>
  28. #include <boost/foreach.hpp>
  29. #include <boost/thread.hpp>
  30. #include <boost/thread/shared_mutex.hpp>
  31. #include <boost/lexical_cast.hpp>
  32. #include <sstream>
  33. #include "CPreGame.h"
  34. #include "CBattleInterface.h"
  35. #include "../CThreadHelper.h"
  36. #include "../lib/ERMScriptModule.h"
  37. #define NOT_LIB
  38. #include "../lib/RegisterTypes.cpp"
  39. extern std::string NAME;
  40. namespace intpr = boost::interprocess;
  41. /*
  42. * Client.cpp, part of VCMI engine
  43. *
  44. * Authors: listed in file AUTHORS in main folder
  45. *
  46. * License: GNU General Public License v2.0 or later
  47. * Full text of license available in license.txt file, in main folder
  48. *
  49. */
  50. template <typename T> class CApplyOnCL;
  51. class CBaseForCLApply
  52. {
  53. public:
  54. virtual void applyOnClAfter(CClient *cl, void *pack) const =0;
  55. virtual void applyOnClBefore(CClient *cl, void *pack) const =0;
  56. virtual ~CBaseForCLApply(){}
  57. template<typename U> static CBaseForCLApply *getApplier(const U * t=NULL)
  58. {
  59. return new CApplyOnCL<U>;
  60. }
  61. };
  62. template <typename T> class CApplyOnCL : public CBaseForCLApply
  63. {
  64. public:
  65. void applyOnClAfter(CClient *cl, void *pack) const
  66. {
  67. T *ptr = static_cast<T*>(pack);
  68. ptr->applyCl(cl);
  69. }
  70. void applyOnClBefore(CClient *cl, void *pack) const
  71. {
  72. T *ptr = static_cast<T*>(pack);
  73. ptr->applyFirstCl(cl);
  74. }
  75. };
  76. static CApplier<CBaseForCLApply> *applier = NULL;
  77. void CClient::init()
  78. {
  79. hotSeat = false;
  80. connectionHandler = NULL;
  81. pathInfo = NULL;
  82. applier = new CApplier<CBaseForCLApply>;
  83. registerTypes2(*applier);
  84. IObjectInterface::cb = this;
  85. serv = NULL;
  86. gs = NULL;
  87. cb = NULL;
  88. terminate = false;
  89. }
  90. CClient::CClient(void)
  91. :waitingRequest(false)
  92. {
  93. init();
  94. }
  95. CClient::CClient(CConnection *con, StartInfo *si)
  96. :waitingRequest(false)
  97. {
  98. init();
  99. newGame(con,si);
  100. }
  101. CClient::~CClient(void)
  102. {
  103. delete pathInfo;
  104. delete applier;
  105. }
  106. void CClient::waitForMoveAndSend(int color)
  107. {
  108. try
  109. {
  110. assert(vstd::contains(battleints, color));
  111. BattleAction ba = battleints[color]->activeStack(gs->curB->getStack(gs->curB->activeStack, false));
  112. *serv << &MakeAction(ba);
  113. return;
  114. }HANDLE_EXCEPTION
  115. tlog1 << "We should not be here!" << std::endl;
  116. }
  117. void CClient::run()
  118. {
  119. setThreadName(-1, "CClient::run");
  120. try
  121. {
  122. CPack *pack = NULL;
  123. while(!terminate)
  124. {
  125. pack = serv->retreivePack(); //get the package from the server
  126. if (terminate)
  127. {
  128. delete pack;
  129. pack = NULL;
  130. break;
  131. }
  132. handlePack(pack);
  133. pack = NULL;
  134. }
  135. }
  136. catch (const std::exception& e)
  137. {
  138. tlog3 << "Lost connection to server, ending listening thread!\n";
  139. tlog1 << e.what() << std::endl;
  140. if(!terminate) //rethrow (-> boom!) only if closing connection was unexpected
  141. {
  142. tlog1 << "Something wrong, lost connection while game is still ongoing...\n";
  143. throw;
  144. }
  145. }
  146. }
  147. void CClient::save(const std::string & fname)
  148. {
  149. if(gs->curB)
  150. {
  151. tlog1 << "Game cannot be saved during battle!\n";
  152. return;
  153. }
  154. *serv << &SaveGame(fname);
  155. }
  156. #include <fstream>
  157. void initVillagesCapitols(Mapa * map)
  158. {
  159. std::ifstream ifs(DATA_DIR "/config/townsDefs.txt");
  160. int ccc;
  161. ifs>>ccc;
  162. for(int i=0;i<ccc*2;i++)
  163. {
  164. const CGDefInfo *n;
  165. if(i<ccc)
  166. {
  167. n = CGI->state->villages[i];
  168. map->defy.push_back(CGI->state->forts[i]);
  169. }
  170. else
  171. n = CGI->state->capitols[i%ccc];
  172. ifs >> const_cast<CGDefInfo*>(n)->name;
  173. if(!n)
  174. tlog1 << "*HUGE* Warning - missing town def for " << i << std::endl;
  175. else
  176. map->defy.push_back(const_cast<CGDefInfo*>(n));
  177. }
  178. }
  179. void CClient::endGame( bool closeConnection /*= true*/ )
  180. {
  181. // Game is ending
  182. // Tell the network thread to reach a stable state
  183. if(closeConnection)
  184. stopConnection();
  185. tlog0 << "Closed connection." << std::endl;
  186. GH.curInt = NULL;
  187. LOCPLINT->terminate_cond.setn(true);
  188. LOCPLINT->pim->lock();
  189. tlog0 << "\n\nEnding current game!" << std::endl;
  190. if(GH.topInt())
  191. GH.topInt()->deactivate();
  192. GH.listInt.clear();
  193. GH.objsToBlit.clear();
  194. GH.statusbar = NULL;
  195. tlog0 << "Removed GUI." << std::endl;
  196. delete CGI->mh;
  197. const_cast<CGameInfo*>(CGI)->mh = NULL;
  198. const_cast<CGameInfo*>(CGI)->state.dellNull();
  199. tlog0 << "Deleted mapHandler and gameState." << std::endl;
  200. CPlayerInterface * oldInt = LOCPLINT;
  201. LOCPLINT = NULL;
  202. oldInt->pim->unlock();
  203. while (!playerint.empty())
  204. {
  205. CGameInterface *pint = playerint.begin()->second;
  206. playerint.erase(playerint.begin());
  207. delete pint;
  208. }
  209. BOOST_FOREACH(CCallback *cb, callbacks)
  210. {
  211. delete cb;
  212. }
  213. tlog0 << "Deleted playerInts." << std::endl;
  214. tlog0 << "Client stopped." << std::endl;
  215. }
  216. void CClient::loadGame( const std::string & fname )
  217. {
  218. tlog0 <<"\n\nLoading procedure started!\n\n";
  219. CServerHandler sh;
  220. sh.startServer();
  221. timeHandler tmh;
  222. {
  223. char sig[8];
  224. CMapHeader dum;
  225. const_cast<CGameInfo*>(CGI)->mh = new CMapHandler();
  226. StartInfo *si;
  227. CLoadFile lf(fname + ".vlgm1");
  228. lf >> sig >> dum >> si;
  229. tlog0 <<"Reading save signature: "<<tmh.getDif()<<std::endl;
  230. lf >> *VLC;
  231. const_cast<CGameInfo*>(CGI)->setFromLib();
  232. tlog0 <<"Reading handlers: "<<tmh.getDif()<<std::endl;
  233. lf >> gs;
  234. tlog0 <<"Reading gamestate: "<<tmh.getDif()<<std::endl;
  235. const_cast<CGameInfo*>(CGI)->state = gs;
  236. const_cast<CGameInfo*>(CGI)->mh->map = gs->map;
  237. pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1));
  238. CGI->mh->init();
  239. initVillagesCapitols(gs->map);
  240. tlog0 <<"Initing maphandler: "<<tmh.getDif()<<std::endl;
  241. }
  242. serv = sh.connectToServer();
  243. serv->addStdVecItems(gs);
  244. tmh.update();
  245. ui8 pom8;
  246. *serv << ui8(3) << ui8(1); //load game; one client
  247. *serv << fname;
  248. *serv >> pom8;
  249. if(pom8)
  250. throw "Server cannot open the savegame!";
  251. else
  252. tlog0 << "Server opened savegame properly.\n";
  253. *serv << ui32(gs->scenarioOps->playerInfos.size()+1); //number of players + neutral
  254. for(std::map<int, PlayerSettings>::iterator it = gs->scenarioOps->playerInfos.begin();
  255. it != gs->scenarioOps->playerInfos.end(); ++it)
  256. {
  257. *serv << ui8(it->first); //players
  258. }
  259. *serv << ui8(255); // neutrals
  260. tlog0 <<"Sent info to server: "<<tmh.getDif()<<std::endl;
  261. {
  262. CLoadFile lf(fname + ".vcgm1");
  263. lf >> *this;
  264. }
  265. }
  266. void CClient::newGame( CConnection *con, StartInfo *si )
  267. {
  268. enum {SINGLE, HOST, GUEST} networkMode = SINGLE;
  269. std::set<ui8> myPlayers;
  270. if (con == NULL)
  271. {
  272. CServerHandler sh;
  273. serv = sh.connectToServer();
  274. }
  275. else
  276. {
  277. serv = con;
  278. networkMode = (con->connectionID == 1) ? HOST : GUEST;
  279. }
  280. for(std::map<int, PlayerSettings>::iterator it =si->playerInfos.begin();
  281. it != si->playerInfos.end(); ++it)
  282. {
  283. if(networkMode == SINGLE //single - one client has all player
  284. || networkMode != SINGLE && serv->connectionID == it->second.human //multi - client has only "its players"
  285. || networkMode == HOST && it->second.human == false) //multi - host has all AI players
  286. {
  287. myPlayers.insert(ui8(it->first)); //add player
  288. }
  289. }
  290. if(networkMode != GUEST)
  291. myPlayers.insert(255); //neutral
  292. timeHandler tmh;
  293. const_cast<CGameInfo*>(CGI)->state = new CGameState();
  294. tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
  295. CConnection &c(*serv);
  296. ////////////////////////////////////////////////////
  297. if(networkMode == SINGLE)
  298. {
  299. ui8 pom8;
  300. c << ui8(2) << ui8(1); //new game; one client
  301. c << *si;
  302. c >> pom8;
  303. if(pom8)
  304. throw "Server cannot open the map!";
  305. else
  306. tlog0 << "Server opened map properly.\n";
  307. }
  308. c << myPlayers;
  309. ui32 seed, sum;
  310. c >> si >> sum >> seed;
  311. tlog0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl;
  312. tlog0 << "\tUsing random seed: "<<seed << std::endl;
  313. gs = const_cast<CGameInfo*>(CGI)->state;
  314. gs->scenarioOps = si;
  315. gs->init(si, sum, seed);
  316. tlog0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
  317. if(gs->map)
  318. {
  319. const_cast<CGameInfo*>(CGI)->mh = new CMapHandler();
  320. CGI->mh->map = gs->map;
  321. tlog0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
  322. CGI->mh->init();
  323. initVillagesCapitols(gs->map);
  324. pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1));
  325. tlog0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
  326. }
  327. int humanPlayers = 0;
  328. for(std::map<int, PlayerSettings>::iterator it = gs->scenarioOps->playerInfos.begin();
  329. it != gs->scenarioOps->playerInfos.end(); ++it)//initializing interfaces for players
  330. {
  331. ui8 color = it->first;
  332. gs->currentPlayer = color;
  333. if(!vstd::contains(myPlayers, color))
  334. continue;
  335. if(si->mode != StartInfo::DUEL)
  336. {
  337. CCallback *cb = new CCallback(gs,color,this);
  338. if(!it->second.human)
  339. {
  340. playerint[color] = static_cast<CGameInterface*>(CAIHandler::getNewAI(conf.cc.defaultPlayerAI));
  341. }
  342. else
  343. {
  344. playerint[color] = new CPlayerInterface(color);
  345. humanPlayers++;
  346. }
  347. battleints[color] = playerint[color];
  348. playerint[color]->init(cb);
  349. }
  350. else
  351. {
  352. CBattleCallback * cbc = new CBattleCallback(gs, color, this);
  353. battleints[color] = CAIHandler::getNewBattleAI("StupidAI");
  354. battleints[color]->init(cbc);
  355. }
  356. }
  357. if(si->mode == StartInfo::DUEL)
  358. {
  359. CPlayerInterface *p = new CPlayerInterface(-1);
  360. p->observerInDuelMode = true;
  361. battleints[254] = playerint[254] = p;
  362. GH.curInt = p;
  363. p->init(new CCallback(gs, -1, this));
  364. battleStarted(gs->curB);
  365. }
  366. else
  367. {
  368. loadNeutralBattleAI();
  369. }
  370. serv->addStdVecItems(const_cast<CGameInfo*>(CGI)->state);
  371. hotSeat = (humanPlayers > 1);
  372. // CScriptingModule *erm = getERMModule();
  373. // privilagedGameEventReceivers.push_back(erm);
  374. // privilagedBattleEventReceivers.push_back(erm);
  375. // icb = this;
  376. // acb = this;
  377. // erm->init();
  378. }
  379. template <typename Handler>
  380. void CClient::serialize( Handler &h, const int version )
  381. {
  382. h & hotSeat;
  383. if(h.saving)
  384. {
  385. ui8 players = playerint.size();
  386. h & players;
  387. for(std::map<ui8,CGameInterface *>::iterator i = playerint.begin(); i != playerint.end(); i++)
  388. {
  389. h & i->first & i->second->dllName;
  390. i->second->serialize(h,version);
  391. }
  392. }
  393. else
  394. {
  395. ui8 players;
  396. h & players;
  397. for(int i=0; i < players; i++)
  398. {
  399. std::string dllname;
  400. ui8 pid;
  401. h & pid & dllname;
  402. CGameInterface *nInt = NULL;
  403. if(dllname.length())
  404. {
  405. if(pid == 255)
  406. {
  407. CBattleCallback * cbc = new CBattleCallback(gs, pid, this);
  408. CBattleGameInterface *cbgi = CAIHandler::getNewBattleAI(dllname);
  409. battleints[pid] = cbgi;
  410. cbgi->init(cb);
  411. //TODO? consider serialization
  412. continue;
  413. }
  414. else
  415. nInt = CAIHandler::getNewAI(dllname);
  416. }
  417. else
  418. nInt = new CPlayerInterface(pid);
  419. CCallback *callback = new CCallback(gs,pid,this);
  420. callbacks.insert(callback);
  421. battleints[pid] = playerint[pid] = nInt;
  422. nInt->init(callback);
  423. nInt->serialize(h, version);
  424. }
  425. if(!vstd::contains(battleints, NEUTRAL_PLAYER))
  426. loadNeutralBattleAI();
  427. }
  428. }
  429. void CClient::handlePack( CPack * pack )
  430. {
  431. CBaseForCLApply *apply = applier->apps[typeList.getTypeID(pack)]; //find the applier
  432. if(apply)
  433. {
  434. apply->applyOnClBefore(this,pack);
  435. tlog5 << "\tMade first apply on cl\n";
  436. gs->apply(pack);
  437. tlog5 << "\tApplied on gs\n";
  438. apply->applyOnClAfter(this,pack);
  439. tlog5 << "\tMade second apply on cl\n";
  440. }
  441. else
  442. {
  443. tlog1 << "Message cannot be applied, cannot find applier!\n";
  444. }
  445. delete pack;
  446. }
  447. void CClient::updatePaths()
  448. {
  449. const CGHeroInstance *h = getSelectedHero();
  450. if (h)//if we have selected hero...
  451. gs->calculatePaths(h, *pathInfo);
  452. }
  453. void CClient::finishCampaign( CCampaignState * camp )
  454. {
  455. }
  456. void CClient::proposeNextMission( CCampaignState * camp )
  457. {
  458. GH.pushInt(new CBonusSelection(camp));
  459. GH.curInt = CGP;
  460. }
  461. void CClient::stopConnection()
  462. {
  463. terminate = true;
  464. if (serv) //request closing connection
  465. {
  466. tlog0 << "Connection has been requested to be closed.\n";
  467. boost::unique_lock<boost::mutex>(*serv->wmx);
  468. *serv << &CloseServer();
  469. tlog0 << "Sent closing signal to the server\n";
  470. }
  471. if(connectionHandler)//end connection handler
  472. {
  473. if(connectionHandler->get_id() != boost::this_thread::get_id())
  474. connectionHandler->join();
  475. tlog0 << "Connection handler thread joined" << std::endl;
  476. delete connectionHandler;
  477. connectionHandler = NULL;
  478. }
  479. if (serv) //and delete connection
  480. {
  481. serv->close();
  482. delete serv;
  483. serv = NULL;
  484. tlog3 << "Our socket has been closed." << std::endl;
  485. }
  486. }
  487. void CClient::battleStarted(const BattleInfo * info)
  488. {
  489. CPlayerInterface * att, * def;
  490. if(vstd::contains(playerint, info->sides[0]) && playerint[info->sides[0]]->human)
  491. att = static_cast<CPlayerInterface*>( playerint[info->sides[0]] );
  492. else
  493. att = NULL;
  494. if(vstd::contains(playerint, info->sides[1]) && playerint[info->sides[1]]->human)
  495. def = static_cast<CPlayerInterface*>( playerint[info->sides[1]] );
  496. else
  497. def = NULL;
  498. new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], Rect((conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2, 800, 600), att, def);
  499. if(vstd::contains(battleints,info->sides[0]))
  500. battleints[info->sides[0]]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 0);
  501. if(vstd::contains(battleints,info->sides[1]))
  502. battleints[info->sides[1]]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 1);
  503. if(vstd::contains(battleints,254))
  504. battleints[254]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 1);
  505. }
  506. void CClient::loadNeutralBattleAI()
  507. {
  508. battleints[255] = CAIHandler::getNewBattleAI(conf.cc.defaultBattleAI);
  509. battleints[255]->init(new CBattleCallback(gs, 255, this));
  510. }
  511. void CClient::commitPackage( CPackForClient *pack )
  512. {
  513. CommitPackage cp;
  514. cp.packToCommit = pack;
  515. *serv << &cp;
  516. }
  517. template void CClient::serialize( CISer<CLoadFile> &h, const int version );
  518. template void CClient::serialize( COSer<CSaveFile> &h, const int version );
  519. void CServerHandler::startServer()
  520. {
  521. th.update();
  522. serverThread = new boost::thread(&CServerHandler::callServer, this); //runs server executable; //TODO: will it work on non-windows platforms?
  523. if(verbose)
  524. tlog0 << "Setting up thread calling server: " << th.getDif() << std::endl;
  525. }
  526. void CServerHandler::waitForServer()
  527. {
  528. if(!serverThread)
  529. startServer();
  530. th.update();
  531. intpr::scoped_lock<intpr::interprocess_mutex> slock(shared->sr->mutex);
  532. while(!shared->sr->ready)
  533. {
  534. shared->sr->cond.wait(slock);
  535. }
  536. if(verbose)
  537. tlog0 << "Waiting for server: " << th.getDif() << std::endl;
  538. }
  539. CConnection * CServerHandler::connectToServer()
  540. {
  541. if(!shared->sr->ready)
  542. waitForServer();
  543. th.update();
  544. CConnection *ret = justConnectToServer(conf.cc.server, port);
  545. if(verbose)
  546. tlog0<<"\tConnecting to the server: "<<th.getDif()<<std::endl;
  547. return ret;
  548. }
  549. CServerHandler::CServerHandler(bool runServer /*= false*/)
  550. {
  551. serverThread = NULL;
  552. shared = NULL;
  553. port = boost::lexical_cast<std::string>(conf.cc.port);
  554. boost::interprocess::shared_memory_object::remove("vcmi_memory"); //if the application has previously crashed, the memory may not have been removed. to avoid problems - try to destroy it
  555. try
  556. {
  557. shared = new SharedMem();
  558. } HANDLE_EXCEPTIONC(tlog1 << "Cannot open interprocess memory: ";)
  559. }
  560. CServerHandler::~CServerHandler()
  561. {
  562. delete shared;
  563. delete serverThread; //detaches, not kills thread
  564. }
  565. void CServerHandler::callServer()
  566. {
  567. setThreadName(-1, "CServerHandler::callServer");
  568. std::string comm = std::string(BIN_DIR PATH_SEPARATOR SERVER_NAME " ") + port + " > server_log.txt";
  569. std::system(comm.c_str());
  570. tlog0 << "Server finished\n";
  571. }
  572. CConnection * CServerHandler::justConnectToServer(const std::string &host, const std::string &port)
  573. {
  574. CConnection *ret = NULL;
  575. while(!ret)
  576. {
  577. try
  578. {
  579. tlog0 << "Establishing connection...\n";
  580. ret = new CConnection( host.size() ? host : conf.cc.server,
  581. port.size() ? port : boost::lexical_cast<std::string>(conf.cc.port),
  582. NAME);
  583. }
  584. catch(...)
  585. {
  586. tlog1 << "\nCannot establish connection! Retrying within 2 seconds" << std::endl;
  587. SDL_Delay(2000);
  588. }
  589. }
  590. return ret;
  591. }