CGuiHandler.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * CGuiHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CGuiHandler.h"
  12. #include "../lib/CondSh.h"
  13. #include <SDL_timer.h>
  14. #include "CIntObject.h"
  15. #include "CursorHandler.h"
  16. #include "SDL_Extensions.h"
  17. #include "../CGameInfo.h"
  18. #include "../../lib/CThreadHelper.h"
  19. #include "../../lib/CConfigHandler.h"
  20. #include "../CMT.h"
  21. #include "../CPlayerInterface.h"
  22. #include "../battle/BattleInterface.h"
  23. extern std::queue<SDL_Event> SDLEventsQueue;
  24. extern boost::mutex eventsM;
  25. boost::thread_specific_ptr<bool> inGuiThread;
  26. SObjectConstruction::SObjectConstruction(CIntObject *obj)
  27. :myObj(obj)
  28. {
  29. GH.createdObj.push_front(obj);
  30. GH.captureChildren = true;
  31. }
  32. SObjectConstruction::~SObjectConstruction()
  33. {
  34. assert(GH.createdObj.size());
  35. assert(GH.createdObj.front() == myObj);
  36. GH.createdObj.pop_front();
  37. GH.captureChildren = GH.createdObj.size();
  38. }
  39. SSetCaptureState::SSetCaptureState(bool allow, ui8 actions)
  40. {
  41. previousCapture = GH.captureChildren;
  42. GH.captureChildren = false;
  43. prevActions = GH.defActionsDef;
  44. GH.defActionsDef = actions;
  45. }
  46. SSetCaptureState::~SSetCaptureState()
  47. {
  48. GH.captureChildren = previousCapture;
  49. GH.defActionsDef = prevActions;
  50. }
  51. static inline void
  52. processList(const ui16 mask, const ui16 flag, std::list<CIntObject*> *lst, std::function<void (std::list<CIntObject*> *)> cb)
  53. {
  54. if (mask & flag)
  55. cb(lst);
  56. }
  57. void CGuiHandler::processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb)
  58. {
  59. processList(CIntObject::LCLICK,activityFlag,&lclickable,cb);
  60. processList(CIntObject::RCLICK,activityFlag,&rclickable,cb);
  61. processList(CIntObject::MCLICK,activityFlag,&mclickable,cb);
  62. processList(CIntObject::HOVER,activityFlag,&hoverable,cb);
  63. processList(CIntObject::MOVE,activityFlag,&motioninterested,cb);
  64. processList(CIntObject::KEYBOARD,activityFlag,&keyinterested,cb);
  65. processList(CIntObject::TIME,activityFlag,&timeinterested,cb);
  66. processList(CIntObject::WHEEL,activityFlag,&wheelInterested,cb);
  67. processList(CIntObject::DOUBLECLICK,activityFlag,&doubleClickInterested,cb);
  68. processList(CIntObject::TEXTINPUT,activityFlag,&textInterested,cb);
  69. }
  70. void CGuiHandler::handleElementActivate(CIntObject * elem, ui16 activityFlag)
  71. {
  72. processLists(activityFlag,[&](std::list<CIntObject*> * lst){
  73. lst->push_front(elem);
  74. });
  75. elem->active_m |= activityFlag;
  76. }
  77. void CGuiHandler::handleElementDeActivate(CIntObject * elem, ui16 activityFlag)
  78. {
  79. processLists(activityFlag,[&](std::list<CIntObject*> * lst){
  80. auto hlp = std::find(lst->begin(),lst->end(),elem);
  81. assert(hlp != lst->end());
  82. lst->erase(hlp);
  83. });
  84. elem->active_m &= ~activityFlag;
  85. }
  86. void CGuiHandler::popInt(std::shared_ptr<IShowActivatable> top)
  87. {
  88. assert(listInt.front() == top);
  89. top->deactivate();
  90. disposed.push_back(top);
  91. listInt.pop_front();
  92. objsToBlit -= top;
  93. if(!listInt.empty())
  94. listInt.front()->activate();
  95. totalRedraw();
  96. pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED);
  97. }
  98. void CGuiHandler::pushInt(std::shared_ptr<IShowActivatable> newInt)
  99. {
  100. assert(newInt);
  101. assert(!vstd::contains(listInt, newInt)); // do not add same object twice
  102. //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
  103. screenBuf = screen2;
  104. if(!listInt.empty())
  105. listInt.front()->deactivate();
  106. listInt.push_front(newInt);
  107. CCS->curh->set(Cursor::Map::POINTER);
  108. newInt->activate();
  109. objsToBlit.push_back(newInt);
  110. totalRedraw();
  111. pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED);
  112. }
  113. void CGuiHandler::popInts(int howMany)
  114. {
  115. if(!howMany) return; //senseless but who knows...
  116. assert(listInt.size() >= howMany);
  117. listInt.front()->deactivate();
  118. for(int i=0; i < howMany; i++)
  119. {
  120. objsToBlit -= listInt.front();
  121. disposed.push_back(listInt.front());
  122. listInt.pop_front();
  123. }
  124. if(!listInt.empty())
  125. {
  126. listInt.front()->activate();
  127. totalRedraw();
  128. }
  129. fakeMouseMove();
  130. pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED);
  131. }
  132. std::shared_ptr<IShowActivatable> CGuiHandler::topInt()
  133. {
  134. if(listInt.empty())
  135. return std::shared_ptr<IShowActivatable>();
  136. else
  137. return listInt.front();
  138. }
  139. void CGuiHandler::totalRedraw()
  140. {
  141. #ifdef VCMI_ANDROID
  142. SDL_FillRect(screen2, NULL, SDL_MapRGB(screen2->format, 0, 0, 0));
  143. #endif
  144. for(auto & elem : objsToBlit)
  145. elem->showAll(screen2);
  146. CSDL_Ext::blitAt(screen2,0,0,screen);
  147. }
  148. void CGuiHandler::updateTime()
  149. {
  150. int ms = mainFPSmng->getElapsedMilliseconds();
  151. std::list<CIntObject*> hlp = timeinterested;
  152. for (auto & elem : hlp)
  153. {
  154. if(!vstd::contains(timeinterested,elem)) continue;
  155. (elem)->onTimer(ms);
  156. }
  157. }
  158. void CGuiHandler::handleEvents()
  159. {
  160. //player interface may want special event handling
  161. if(nullptr != LOCPLINT && LOCPLINT->capturedAllEvents())
  162. return;
  163. boost::unique_lock<boost::mutex> lock(eventsM);
  164. while(!SDLEventsQueue.empty())
  165. {
  166. continueEventHandling = true;
  167. auto ev = SDLEventsQueue.front();
  168. current = &ev;
  169. SDLEventsQueue.pop();
  170. // In a sequence of mouse motion events, skip all but the last one.
  171. // This prevents freezes when every motion event takes longer to handle than interval at which
  172. // the events arrive (like dragging on the minimap in world view, with redraw at every event)
  173. // so that the events would start piling up faster than they can be processed.
  174. if ((ev.type == SDL_MOUSEMOTION) && !SDLEventsQueue.empty() && (SDLEventsQueue.front().type == SDL_MOUSEMOTION))
  175. continue;
  176. handleCurrentEvent();
  177. }
  178. }
  179. void CGuiHandler::handleCurrentEvent()
  180. {
  181. if(current->type == SDL_KEYDOWN || current->type == SDL_KEYUP)
  182. {
  183. SDL_KeyboardEvent key = current->key;
  184. if(current->type == SDL_KEYDOWN && key.keysym.sym >= SDLK_F1 && key.keysym.sym <= SDLK_F15 && settings["session"]["spectate"].Bool())
  185. {
  186. //TODO: we need some central place for all interface-independent hotkeys
  187. Settings s = settings.write["session"];
  188. switch(key.keysym.sym)
  189. {
  190. case SDLK_F5:
  191. if(settings["session"]["spectate-locked-pim"].Bool())
  192. LOCPLINT->pim->unlock();
  193. else
  194. LOCPLINT->pim->lock();
  195. s["spectate-locked-pim"].Bool() = !settings["session"]["spectate-locked-pim"].Bool();
  196. break;
  197. case SDLK_F6:
  198. s["spectate-ignore-hero"].Bool() = !settings["session"]["spectate-ignore-hero"].Bool();
  199. break;
  200. case SDLK_F7:
  201. s["spectate-skip-battle"].Bool() = !settings["session"]["spectate-skip-battle"].Bool();
  202. break;
  203. case SDLK_F8:
  204. s["spectate-skip-battle-result"].Bool() = !settings["session"]["spectate-skip-battle-result"].Bool();
  205. break;
  206. case SDLK_F9:
  207. //not working yet since CClient::run remain locked after BattleInterface removal
  208. // if(LOCPLINT->battleInt)
  209. // {
  210. // GH.popInts(1);
  211. // vstd::clear_pointer(LOCPLINT->battleInt);
  212. // }
  213. break;
  214. default:
  215. break;
  216. }
  217. return;
  218. }
  219. //translate numpad keys
  220. if(key.keysym.sym == SDLK_KP_ENTER)
  221. {
  222. key.keysym.sym = SDLK_RETURN;
  223. key.keysym.scancode = SDL_SCANCODE_RETURN;
  224. }
  225. bool keysCaptured = false;
  226. for(auto i = keyinterested.begin(); i != keyinterested.end() && continueEventHandling; i++)
  227. {
  228. if((*i)->captureThisEvent(key))
  229. {
  230. keysCaptured = true;
  231. break;
  232. }
  233. }
  234. std::list<CIntObject*> miCopy = keyinterested;
  235. for(auto i = miCopy.begin(); i != miCopy.end() && continueEventHandling; i++)
  236. if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureThisEvent(key)))
  237. (**i).keyPressed(key);
  238. }
  239. else if(current->type == SDL_MOUSEMOTION)
  240. {
  241. handleMouseMotion();
  242. }
  243. else if(current->type == SDL_MOUSEBUTTONDOWN)
  244. {
  245. switch(current->button.button)
  246. {
  247. case SDL_BUTTON_LEFT:
  248. if(lastClick == current->motion && (SDL_GetTicks() - lastClickTime) < 300)
  249. {
  250. std::list<CIntObject*> hlp = doubleClickInterested;
  251. for(auto i = hlp.begin(); i != hlp.end() && continueEventHandling; i++)
  252. {
  253. if(!vstd::contains(doubleClickInterested, *i)) continue;
  254. if((*i)->pos.isInside(current->motion.x, current->motion.y))
  255. {
  256. (*i)->onDoubleClick();
  257. }
  258. }
  259. }
  260. lastClick = current->motion;
  261. lastClickTime = SDL_GetTicks();
  262. handleMouseButtonClick(lclickable, EIntObjMouseBtnType::LEFT, true);
  263. break;
  264. case SDL_BUTTON_RIGHT:
  265. handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, true);
  266. break;
  267. case SDL_BUTTON_MIDDLE:
  268. handleMouseButtonClick(mclickable, EIntObjMouseBtnType::MIDDLE, true);
  269. break;
  270. default:
  271. break;
  272. }
  273. }
  274. else if(current->type == SDL_MOUSEWHEEL)
  275. {
  276. std::list<CIntObject*> hlp = wheelInterested;
  277. for(auto i = hlp.begin(); i != hlp.end() && continueEventHandling; i++)
  278. {
  279. if(!vstd::contains(wheelInterested,*i)) continue;
  280. // SDL doesn't have the proper values for mouse positions on SDL_MOUSEWHEEL, refetch them
  281. int x = 0, y = 0;
  282. SDL_GetMouseState(&x, &y);
  283. (*i)->wheelScrolled(current->wheel.y < 0, (*i)->pos.isInside(x, y));
  284. }
  285. }
  286. else if(current->type == SDL_TEXTINPUT)
  287. {
  288. for(auto it : textInterested)
  289. {
  290. it->textInputed(current->text);
  291. }
  292. }
  293. else if(current->type == SDL_TEXTEDITING)
  294. {
  295. for(auto it : textInterested)
  296. {
  297. it->textEdited(current->edit);
  298. }
  299. }
  300. //todo: muiltitouch
  301. else if(current->type == SDL_MOUSEBUTTONUP)
  302. {
  303. switch(current->button.button)
  304. {
  305. case SDL_BUTTON_LEFT:
  306. handleMouseButtonClick(lclickable, EIntObjMouseBtnType::LEFT, false);
  307. break;
  308. case SDL_BUTTON_RIGHT:
  309. handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, false);
  310. break;
  311. case SDL_BUTTON_MIDDLE:
  312. handleMouseButtonClick(mclickable, EIntObjMouseBtnType::MIDDLE, false);
  313. break;
  314. }
  315. }
  316. current = nullptr;
  317. } //event end
  318. void CGuiHandler::handleMouseButtonClick(CIntObjectList & interestedObjs, EIntObjMouseBtnType btn, bool isPressed)
  319. {
  320. auto hlp = interestedObjs;
  321. for(auto i = hlp.begin(); i != hlp.end() && continueEventHandling; i++)
  322. {
  323. if(!vstd::contains(interestedObjs, *i)) continue;
  324. auto prev = (*i)->mouseState(btn);
  325. if(!isPressed)
  326. (*i)->updateMouseState(btn, isPressed);
  327. if((*i)->pos.isInside(current->motion.x, current->motion.y))
  328. {
  329. if(isPressed)
  330. (*i)->updateMouseState(btn, isPressed);
  331. (*i)->click(btn, isPressed, prev);
  332. }
  333. else if(!isPressed)
  334. (*i)->click(btn, boost::logic::indeterminate, prev);
  335. }
  336. }
  337. void CGuiHandler::handleMouseMotion()
  338. {
  339. //sending active, hovered hoverable objects hover() call
  340. std::vector<CIntObject*> hlp;
  341. for(auto & elem : hoverable)
  342. {
  343. if(elem->pos.isInside(current->motion.x, current->motion.y))
  344. {
  345. if (!(elem)->hovered)
  346. hlp.push_back((elem));
  347. }
  348. else if ((elem)->hovered)
  349. {
  350. (elem)->hover(false);
  351. (elem)->hovered = false;
  352. }
  353. }
  354. for(auto & elem : hlp)
  355. {
  356. elem->hover(true);
  357. elem->hovered = true;
  358. }
  359. handleMoveInterested(current->motion);
  360. }
  361. void CGuiHandler::simpleRedraw()
  362. {
  363. //update only top interface and draw background
  364. if(objsToBlit.size() > 1)
  365. CSDL_Ext::blitAt(screen2,0,0,screen); //blit background
  366. if(!objsToBlit.empty())
  367. objsToBlit.back()->show(screen); //blit active interface/window
  368. }
  369. void CGuiHandler::handleMoveInterested(const SDL_MouseMotionEvent & motion)
  370. {
  371. //sending active, MotionInterested objects mouseMoved() call
  372. std::list<CIntObject*> miCopy = motioninterested;
  373. for(auto & elem : miCopy)
  374. {
  375. if(elem->strongInterest || Rect::createAround(elem->pos, 1).isInside( motion.x, motion.y)) //checking bounds including border fixes bug #2476
  376. {
  377. (elem)->mouseMoved(motion);
  378. }
  379. }
  380. }
  381. void CGuiHandler::fakeMouseMove()
  382. {
  383. SDL_Event event;
  384. SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0, 0, 0};
  385. int x, y;
  386. sme.state = SDL_GetMouseState(&x, &y);
  387. sme.x = x;
  388. sme.y = y;
  389. event.motion = sme;
  390. SDL_PushEvent(&event);
  391. }
  392. void CGuiHandler::renderFrame()
  393. {
  394. // Updating GUI requires locking pim mutex (that protects screen and GUI state).
  395. // During game:
  396. // When ending the game, the pim mutex might be hold by other thread,
  397. // that will notify us about the ending game by setting terminate_cond flag.
  398. //in PreGame terminate_cond stay false
  399. bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded
  400. while(!terminate_cond->get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate
  401. boost::this_thread::sleep(boost::posix_time::milliseconds(1));
  402. if(acquiredTheLockOnPim)
  403. {
  404. // If we are here, pim mutex has been successfully locked - let's store it in a safe RAII lock.
  405. boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim, boost::adopt_lock);
  406. if(nullptr != curInt)
  407. curInt->update();
  408. if(settings["general"]["showfps"].Bool())
  409. drawFPSCounter();
  410. SDL_UpdateTexture(screenTexture, nullptr, screen->pixels, screen->pitch);
  411. SDL_RenderClear(mainRenderer);
  412. SDL_RenderCopy(mainRenderer, screenTexture, nullptr, nullptr);
  413. CCS->curh->render();
  414. SDL_RenderPresent(mainRenderer);
  415. disposed.clear();
  416. }
  417. mainFPSmng->framerateDelay(); // holds a constant FPS
  418. }
  419. CGuiHandler::CGuiHandler()
  420. : lastClick(-500, -500),lastClickTime(0), defActionsDef(0), captureChildren(false)
  421. {
  422. continueEventHandling = true;
  423. curInt = nullptr;
  424. current = nullptr;
  425. statusbar = nullptr;
  426. // Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate
  427. mainFPSmng = new CFramerateManager(60);
  428. //do not init CFramerateManager here --AVS
  429. terminate_cond = new CondSh<bool>(false);
  430. }
  431. CGuiHandler::~CGuiHandler()
  432. {
  433. delete mainFPSmng;
  434. delete terminate_cond;
  435. }
  436. void CGuiHandler::breakEventHandling()
  437. {
  438. continueEventHandling = false;
  439. }
  440. void CGuiHandler::drawFPSCounter()
  441. {
  442. const static SDL_Color yellow = {255, 255, 0, 0};
  443. static SDL_Rect overlay = { 0, 0, 64, 32};
  444. Uint32 black = SDL_MapRGB(screen->format, 10, 10, 10);
  445. SDL_FillRect(screen, &overlay, black);
  446. std::string fps = boost::lexical_cast<std::string>(mainFPSmng->fps);
  447. graphics->fonts[FONT_BIG]->renderTextLeft(screen, fps, yellow, Point(10, 10));
  448. }
  449. SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key)
  450. {
  451. switch(key)
  452. {
  453. case SDLK_DOWN:
  454. return SDLK_KP_2;
  455. case SDLK_UP:
  456. return SDLK_KP_8;
  457. case SDLK_LEFT:
  458. return SDLK_KP_4;
  459. case SDLK_RIGHT:
  460. return SDLK_KP_6;
  461. default:
  462. throw std::runtime_error("Wrong key!");
  463. }
  464. }
  465. SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key)
  466. {
  467. #define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName;
  468. switch(key)
  469. {
  470. REMOVE_KP(0)
  471. REMOVE_KP(1)
  472. REMOVE_KP(2)
  473. REMOVE_KP(3)
  474. REMOVE_KP(4)
  475. REMOVE_KP(5)
  476. REMOVE_KP(6)
  477. REMOVE_KP(7)
  478. REMOVE_KP(8)
  479. REMOVE_KP(9)
  480. REMOVE_KP(PERIOD)
  481. REMOVE_KP(MINUS)
  482. REMOVE_KP(PLUS)
  483. REMOVE_KP(EQUALS)
  484. case SDLK_KP_MULTIPLY:
  485. return SDLK_ASTERISK;
  486. case SDLK_KP_DIVIDE:
  487. return SDLK_SLASH;
  488. case SDLK_KP_ENTER:
  489. return SDLK_RETURN;
  490. default:
  491. return SDLK_UNKNOWN;
  492. }
  493. #undef REMOVE_KP
  494. }
  495. bool CGuiHandler::isNumKey(SDL_Keycode key, bool number)
  496. {
  497. if(number)
  498. return key >= SDLK_KP_1 && key <= SDLK_KP_0;
  499. else
  500. return (key >= SDLK_KP_1 && key <= SDLK_KP_0) || key == SDLK_KP_MINUS || key == SDLK_KP_PLUS || key == SDLK_KP_EQUALS;
  501. }
  502. bool CGuiHandler::isArrowKey(SDL_Keycode key)
  503. {
  504. return key == SDLK_UP || key == SDLK_DOWN || key == SDLK_LEFT || key == SDLK_RIGHT;
  505. }
  506. bool CGuiHandler::amIGuiThread()
  507. {
  508. return inGuiThread.get() && *inGuiThread;
  509. }
  510. void CGuiHandler::pushSDLEvent(int type, int usercode)
  511. {
  512. SDL_Event event;
  513. event.type = type;
  514. event.user.code = usercode; // not necessarily used
  515. SDL_PushEvent(&event);
  516. }
  517. CFramerateManager::CFramerateManager(int rate)
  518. {
  519. this->rate = rate;
  520. this->rateticks = (1000.0 / rate);
  521. this->fps = 0;
  522. this->accumulatedFrames = 0;
  523. this->accumulatedTime = 0;
  524. this->lastticks = 0;
  525. this->timeElapsed = 0;
  526. }
  527. void CFramerateManager::init()
  528. {
  529. this->lastticks = SDL_GetTicks();
  530. }
  531. void CFramerateManager::framerateDelay()
  532. {
  533. ui32 currentTicks = SDL_GetTicks();
  534. timeElapsed = currentTicks - lastticks;
  535. accumulatedFrames++;
  536. // FPS is higher than it should be, then wait some time
  537. if(timeElapsed < rateticks)
  538. {
  539. SDL_Delay((Uint32)ceil(this->rateticks) - timeElapsed);
  540. }
  541. currentTicks = SDL_GetTicks();
  542. // recalculate timeElapsed for external calls via getElapsed()
  543. // limit it to 100 ms to avoid breaking animation in case of huge lag (e.g. triggered breakpoint)
  544. timeElapsed = std::min<ui32>(currentTicks - lastticks, 100);
  545. lastticks = SDL_GetTicks();
  546. accumulatedTime += timeElapsed;
  547. if(accumulatedFrames >= 100)
  548. {
  549. //about 2 second should be passed
  550. fps = static_cast<int>(ceil(1000.0 / (accumulatedTime / accumulatedFrames)));
  551. accumulatedTime = 0;
  552. accumulatedFrames = 0;
  553. }
  554. }