-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#changelog #core #framerate
- Loading branch information
Showing
9 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
#include "ofUtils.h" | ||
|
||
|
||
|
||
class ofTimer { | ||
public: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "ofTimerFps.h" | ||
|
||
void ofTimerFps::reset() { | ||
wakeTime = steady_clock::now(); | ||
} | ||
|
||
ofTimerFps::ofTimerFps(){ | ||
reset(); | ||
}; | ||
|
||
void ofTimerFps::setFps(int fps) { | ||
interval = duration_cast<microseconds>(1s) / fps; | ||
} | ||
|
||
void ofTimerFps::waitNext() { | ||
// Lazy wakeup | ||
std::this_thread::sleep_until(wakeTime - 36ms); //4ms | ||
|
||
// Processor Coffee | ||
while(steady_clock::now() < (wakeTime)) { // 0.05ms 0.5us // - 0.5us - 1ns | ||
std::this_thread::yield(); | ||
} | ||
|
||
lastWakeTime = wakeTime; | ||
wakeTime += interval; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Written by Dimitre Lima in 2024 | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <ctime> | ||
#include <iostream> | ||
#include <thread> | ||
|
||
using namespace std::chrono; | ||
using namespace std::chrono_literals; | ||
|
||
class ofTimerFps { | ||
public: | ||
ofTimerFps(); | ||
void setFps(int fps); | ||
void reset(); | ||
void waitNext(); | ||
|
||
using space = std::chrono::duration<long long, std::nano>; | ||
space interval; | ||
time_point<steady_clock> wakeTime; | ||
time_point<steady_clock> lastWakeTime; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters