I\'m trying to limit the frames per second in a loop that is performing intersection checking, using C++ with chrono and thread.
Here is my code:
std::ch
I usualy do something like this:
#include
#include
int main()
{
using clock = std::chrono::steady_clock;
auto next_frame = clock::now();
while(true)
{
next_frame += std::chrono::milliseconds(1000 / 5); // 5Hz
// do stuff
std::cout << std::time(0) << '\n'; // 5 for each second
// wait for end of frame
std::this_thread::sleep_until(next_frame);
}
}
Output: (five for each second value)
1470173964
1470173964
1470173964
1470173964
1470173964
1470173965
1470173965
1470173965
1470173965
1470173965
1470173966
1470173966
1470173966
1470173966
1470173966