mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-18 01:30:56 +00:00
Adds CRTMachine::run_until, which will run until a condition is true.
I want to get to being able to say "run until the beam is 60% of the way down", "run until a new packet of audio has been delivered", etc.
This commit is contained in:
parent
a2847f4f8e
commit
8349005c4b
@ -45,12 +45,20 @@ class Machine {
|
|||||||
virtual std::string debug_type() { return ""; }
|
virtual std::string debug_type() { return ""; }
|
||||||
|
|
||||||
/// Runs the machine for @c duration seconds.
|
/// Runs the machine for @c duration seconds.
|
||||||
virtual void run_for(Time::Seconds duration) {
|
void run_for(Time::Seconds duration) {
|
||||||
const double cycles = (duration * clock_rate_) + clock_conversion_error_;
|
const double cycles = (duration * clock_rate_) + clock_conversion_error_;
|
||||||
clock_conversion_error_ = std::fmod(cycles, 1.0);
|
clock_conversion_error_ = std::fmod(cycles, 1.0);
|
||||||
run_for(Cycles(static_cast<int>(cycles)));
|
run_for(Cycles(static_cast<int>(cycles)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs for the machine for at least @c duration seconds, and then until @c condition is true.
|
||||||
|
void run_until(Time::Seconds minimum_duration, std::function<bool()> condition) {
|
||||||
|
run_for(minimum_duration);
|
||||||
|
while(!condition()) {
|
||||||
|
run_for(0.002);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Runs the machine for @c cycles.
|
/// Runs the machine for @c cycles.
|
||||||
virtual void run_for(const Cycles cycles) = 0;
|
virtual void run_for(const Cycles cycles) = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user