added fps limit
This commit is contained in:
parent
794fa5bba0
commit
7012c8c38d
2 changed files with 16 additions and 5 deletions
18
src/Game.cpp
18
src/Game.cpp
|
@ -43,11 +43,19 @@ Game::Game(SDL_Window *window, SDL_Renderer *renderer)
|
|||
|
||||
void Game::Run()
|
||||
{
|
||||
float deltaTime = (SDL_GetTicks() - m_TickCount) / 1000.0f;
|
||||
uint64_t ticks = SDL_GetTicks() - m_TickCount;
|
||||
ticks = ticks > 0 ? ticks : 1;
|
||||
int fps = 1000/(ticks);
|
||||
m_TickCount = SDL_GetTicks();
|
||||
uint64_t currentTicksNS = SDL_GetTicksNS();
|
||||
uint64_t frameTicks = currentTicksNS - m_TickCount;
|
||||
if(frameTicks < m_MinTicksPerFrame)
|
||||
{
|
||||
SDL_DelayNS(m_MinTicksPerFrame - frameTicks);
|
||||
currentTicksNS = SDL_GetTicksNS();
|
||||
frameTicks = currentTicksNS - m_TickCount;
|
||||
}
|
||||
float deltaTime = frameTicks / c_NSPerSecond;
|
||||
m_TickCount = currentTicksNS;
|
||||
long fps = 1/deltaTime;
|
||||
|
||||
|
||||
HandleMovement();
|
||||
m_Player1->Update(deltaTime);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue