728x90

std::chrono를 이용하여 원하는 fps로 동작하게 하는 코드 까먹을까봐 박제함.

 

 

#include <iostream>

#include <chrono>

#include <cstdint>

 

const int fps = 60;

 

using namespace std;

using namespace chrono;

using frame = duration<int32_t, ratio<1, fps>>;

using ms = duration<float, milli>;

 

int main()

{

    time_point<steady_clock> fpsTimer(steady_clock::now());

    frame FPS{};

 

    while (true)

    {

        FPS = duration_cast<frame>(steady_clock::now() - fpsTimer);

 

        if (FPS.count() >= 1)

        {

            fpsTimer = steady_clock::now();

            cout << "LastFrame: " << duration_cast<ms>(FPS).count() << "ms | FPS: " << FPS.count() * fps << endl;

        }

    }

    return 0;

}

 

출처 : https://www.gamedev.net/forums/topic/690860-60-fps-game-loop-using-stdchrono/

 

60 FPS game loop using std::chrono

Hi everyone, out of curiosity yesterday I was trying out chrono header with the goal of creating a 60fps loop, the code below is what I have so far and I wanted your opinion about it, if it is the proper way to do it, how it is usually done or how I could

gamedev.net

 

추가 : Making an accurate Sleep() function | computerBear (blat-blatnik.github.io)

 

728x90

+ Recent posts