Skip to content
Snippets Groups Projects
Commit 31bb6591 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Initial switch to low precision timer

parent 12522ca3
No related branches found
No related tags found
1 merge request!250Resolves #309 reduce unwanted timer precision
......@@ -55,6 +55,8 @@ static void run(ftl::Configurable *root) {
Universe *net = ftl::create<Universe>(root, "net");
ftl::ctrl::Master ctrl(root, net);
ftl::timer::setHighPrecision(true);
auto paths = root->get<vector<string>>("paths");
string file = "";
if (paths && (*paths).size() > 0) file = (*paths)[(*paths).size()-1];
......
......@@ -69,9 +69,20 @@ int64_t get_time();
*/
void setInterval(int ms);
/**
* The highprec parameter sets whether or not this
* timer should be high precision on the calling interval. A high precision
* timer involves spinning the cpu to achieve millisecond accuracy.
*/
void setHighPrecision(bool hp);
int getInterval();
/**
* Get current (monotonic) time in milliseconds.
*/
int64_t get_time();
int64_t get_time_micro();
double get_time_seconds();
......
......@@ -20,6 +20,7 @@ using namespace ftl::timer;
static int64_t last_frame = 0;
static int64_t mspf = 50;
static bool hprec_ = false;
static int64_t clock_adjust = 0;
static bool active = false;
static std::atomic<int> active_jobs = 0;
......@@ -59,7 +60,7 @@ static void waitTimePoint() {
int64_t msdelay = mspf - (now % mspf);
int64_t sincelast = now - last_frame*mspf;
if (sincelast > mspf) LOG(WARNING) << "Frame " << "(" << (target-last_frame) << ") dropped by " << sincelast << "ms";
if (hprec_ && sincelast > mspf) LOG(WARNING) << "Frame " << "(" << (target-last_frame) << ") dropped by " << (sincelast-mspf) << "ms";
// Use sleep_for for larger delays
......@@ -89,6 +90,7 @@ static void waitTimePoint() {
}
}
if (hprec_) {
// Spin loop until exact grab time
//LOG(INFO) << "Spin Delay: " << (now / 40) << " = " << (40 - (now%40));
......@@ -99,6 +101,10 @@ static void waitTimePoint() {
now = get_time();
};
}
} else {
if (sincelast != mspf) sleep_for(milliseconds(msdelay));
now = get_time();
}
last_frame = now/mspf;
}
......@@ -106,6 +112,10 @@ void ftl::timer::setInterval(int ms) {
mspf = ms;
}
void ftl::timer::setHighPrecision(bool hp) {
hprec_ = hp;
}
int ftl::timer::getInterval() {
return mspf;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment