Skip to content

Commit

Permalink
Clean up main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonasher authored Jul 31, 2024
2 parents b1620b3 + 1804427 commit 825a64b
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,21 @@ impl Context {
}

pub fn execute(&mut self) {
// Execute callbacks if there are any in the queue
loop {
let callback = self.callback_queue.pop_front();
match callback {
Some(callback) => callback(self),
None => break,
}
}
// Start plan loop
loop {
let timed_plan = self.plan_queue.get_next_timed_plan();
match timed_plan {
Some(timed_plan) => {
self.current_time = timed_plan.time;
(timed_plan.callback)(self);
loop {
let callback = self.callback_queue.pop_front();
match callback {
Some(callback) => callback(self),
None => break,
}
}
}
None => break,
// If there is a callback, run it.
if let Some(callback) = self.callback_queue.pop_front() {
callback(self);
continue;
}

// There aren't any callbacks, so look at the first timed plan.
if let Some(timed_plan) = self.plan_queue.get_next_timed_plan() {
self.current_time = timed_plan.time;
(timed_plan.callback)(self);
} else {
// OK, there aren't any timed plans, so we're done.
break;
}
}
}
Expand Down

0 comments on commit 825a64b

Please sign in to comment.