diff --git a/ClockReceiver/JustInTime.hpp b/ClockReceiver/JustInTime.hpp index ad328dbe4..90150138e 100644 --- a/ClockReceiver/JustInTime.hpp +++ b/ClockReceiver/JustInTime.hpp @@ -76,6 +76,48 @@ template class RealTimeActor { + public: + template RealTimeActor(Args&&... args) : object_(std::forward(args)...) {} + + forceinline void operator += (const LocalTimeScale &rhs) { + if constexpr (multiplier == 1 && divider == 1) { + object_.run_for(TargetTimeScale(rhs)); + return; + } + + if constexpr (multiplier == 1) { + accumulated_time_ += rhs; + } else { + accumulated_time_ += rhs * multiplier; + } + + if constexpr (divider == 1) { + const auto duration = accumulated_time_.template flush(); + object_.run_for(duration); + } else { + const auto duration = accumulated_time_.template divide(LocalTimeScale(divider)); + if(duration > TargetTimeScale(0)) + object_.run_for(duration); + } + } + + forceinline T *operator->() { return &object_; } + forceinline const T *operator->() const { return &object_; } + forceinline T *last_valid() { return &object_; } + forceinline void flush() {} + + private: + T object_; + LocalTimeScale accumulated_time_; +}; + /*! A AsyncJustInTimeActor acts like a JustInTimeActor but additionally contains an AsyncTaskQueue. Any time the amount of accumulated time crosses a threshold provided at construction time,