From fc6e13ce30635ae2b39d7b2d535c561c7ce18907 Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 30 Mar 2016 21:36:18 +0200 Subject: [PATCH] Added deltaTime + Fps? --- Fifth/CGame.cpp | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/Fifth/CGame.cpp b/Fifth/CGame.cpp index ffd0d1a..0eb0c7f 100644 --- a/Fifth/CGame.cpp +++ b/Fifth/CGame.cpp @@ -57,39 +57,15 @@ int CGame::onExecute() { while(SDL_PollEvent(&event)){ _onEvent(&event); } - - float now = SDL_GetTicks(); - _delta += (now - _lastTime) / _ns; - _lastTime = now; - - while(_delta >= 1) { // Todo implement variable time step instead of this laggy thing - if(_delta > 20) { // To make sure it doesn't freeze - //NFile::log(LogType::WARNING, "Game exeeding delta limit (", 20, "), cleaning up particles."); - instance.entityManager.particleCleanup(); - } - - _handleKeyStates(); - _onLoop(); - _updates++; - _delta--; - - auto sayer = instance.entityManager.getEntity("n:bush"); - if(sayer) - sayer->say(_title.str() + " Gravity: " + std::to_string(instance.gravity), "TESTFONT", ChatBubbleType::INSTANT_TALK); - } - + _handleKeyStates(); + _onLoop(); _onRender(); - _frames++; + _deltaTime = (std::clock() - _timeStart) / (double)(CLOCKS_PER_SEC / 1000); - if(SDL_GetTicks() - _timer > 1000) { - _timer += 1000; - _title.str(""); - _title << _updates << " ups, " << _frames << " fps"; - _updates = 0; - _frames = 0; - } + SDL_SetWindowTitle(instance.window.getWindow(), std::to_string(1000 / _deltaTime).c_str()); + } NFile::log(LogType::ALERT, "Ending game..."); @@ -425,4 +401,4 @@ int CGame::_onCleanup() { NFile::log(LogType::ALERT, "Exiting game."); return 0; -} \ No newline at end of file +}