Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ fps sleep while loop

#include "chrono_io.h"
#include <chrono>
#include <cstdint>
#include <iostream>
#include <thread>

int
main()
{
    using namespace date;
    using namespace std;
    using namespace std::chrono;

    using frames = duration<int64_t, ratio<1, 5>>;  // 5Hz
    auto nextFrame = system_clock::now();
    auto lastFrame = nextFrame - frames{1};;

    while (true)
    {
        // Perform intersection test

        this_thread::sleep_until(nextFrame);
        // just for monitoring purposes
        cout << "Time: " << system_clock::now() - lastFrame << '
';
        lastFrame = nextFrame;
        nextFrame += frames{1};
    }
}
Comment

c++ fps sleep while loop

#include <chrono>
#include <cstdint>
#include <iostream>
#include <thread>

int
main()
{
    using namespace std;
    using namespace std::chrono;

    using frames = duration<int64_t, ratio<1, 5>>;  // 5Hz
    auto nextFrame = system_clock::now();
    auto lastFrame = nextFrame - frames{1};;

    while (true)
    {
        // Perform intersection test

        this_thread::sleep_until(nextFrame);
        cout << "Time: "  // just for monitoring purposes
             << duration_cast<milliseconds>(system_clock::now() - lastFrame).count()
             << "ms
";
        lastFrame = nextFrame;
        nextFrame += frames{1};
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: time optimisation c++ 
Cpp :: C++ if...else Statement 
Cpp :: how to make a substring after certain position 
Cpp :: columntransformer onehotencoder 
Cpp :: 10011101 
Cpp :: cpp console progressbar 
Cpp :: sprintf add two xeroes for a float number 
Cpp :: C++ Ranged Based for Loop 
Cpp :: // A C++ program to show that we can use reference to 
Cpp :: Magical Doors codechef solution in c++ 
Cpp :: ++i v.s i++ 
Cpp :: The program must enter a natural number n from the console and find the number previous to n that is not divisible by 2 , 3 and 5 . 
Cpp :: Smooth Poti values on Arduino 
Cpp :: Consider a pair of integers, (a,b). The following operations can be performed on (a,b) in any order, zero or more times: - (a,b) - ( a+b, b ) - (a,b) - ( a, a+b ) 
Cpp :: c++ rainbow text 
Cpp :: how to calculate the sum of primary diagonal matrix and secondary diagonal matrix using c++ 
Cpp :: cuda atomic swap 
Cpp :: c++ auto loop 
Cpp :: vector remove class 
Cpp :: program to find third smallest number c++ 
Cpp :: in c++ 
Cpp :: ceil value in c++ using formula 
Cpp :: do while loop c++ 
C :: install kubernetes kubectl on mac 
C :: Animated sprite from few images pygame 
C :: golden cobblestone modpack 
C :: prime check in c 
C :: Successeur récurssive 
C :: srand time null 
C :: hi servicenow 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =