I have many instances of std::this_thread::sleep_for(remaining_loop_time_duration)`.
To speed up simulation, we now were asked to use a special custom clock reference (queried using GetSimTime
), which runs faster than real-time by a factor > 1.0.
To avoid large restructuring of my code I simply want to use a custom clock like this:
struct speedy_clock {
using duration = std::chrono::microseconds;
using rep = duration::rep;
using period = duration::period;
using time_point = std::chrono::time_point<motion_clock>;
static const bool is_steady = false;
static time_point now() noexcept {
SimTime time;
GetSimTime(&time);
unsigned int seconds_since_epoch = time.Seconds;
unsigned int microseconds_within_second = time.USec;
std::chrono::seconds seconds_duration(seconds_since_epoch);
std::chrono::microseconds microseconds_duration(microseconds_within_second);
// Calculate the total duration
std::chrono::microseconds total_duration = seconds_duration + microseconds_duration;
return ans_motion_util::motion_clock::time_point(total_duration);
}
};
My goal is of course, that all instances of std::this_thread::sleep_for() sleep with regard to the accelerated time GetSimTime
provided via my speedy_clock
. Is this doable or do I need to write my own version of sleep for.