| 22 | } |
| 23 | |
| 24 | void Scheduler::update() { |
| 25 | u32 current_time = fl::millis(); |
| 26 | |
| 27 | // Use index-based iteration to avoid iterator invalidation issues |
| 28 | for (fl::size i = 0; i < mTasks.size();) { |
| 29 | Handle& t = mTasks[i]; |
| 30 | |
| 31 | if (!t.is_valid() || t._is_canceled()) { |
| 32 | // erase() returns bool in fl::vector, not iterator |
| 33 | mTasks.erase(mTasks.begin() + i); |
| 34 | // Don't increment i since we just removed an element |
| 35 | } else { |
| 36 | // Check if task is ready to run (frame tasks will return false here) |
| 37 | bool should_run = t._ready_to_run(current_time); |
| 38 | |
| 39 | if (should_run) { |
| 40 | // Update last run time for recurring tasks |
| 41 | t._set_last_run_time(current_time); |
| 42 | |
| 43 | // Execute the task |
| 44 | if (t._has_then()) { |
| 45 | t._execute_then(); |
| 46 | } else { |
| 47 | warn_no_then(t._id(), t._trace_label()); |
| 48 | } |
| 49 | |
| 50 | // Remove one-shot tasks, keep recurring ones |
| 51 | bool is_recurring = (t._type() == TaskType::kEveryMs || t._type() == TaskType::kAtFramerate); |
| 52 | if (is_recurring) { |
| 53 | ++i; // Keep recurring tasks |
| 54 | } else { |
| 55 | // erase() returns bool in fl::vector, not iterator |
| 56 | mTasks.erase(mTasks.begin() + i); |
| 57 | // Don't increment i since we just removed an element |
| 58 | } |
| 59 | } else { |
| 60 | ++i; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void Scheduler::update_before_frame_tasks() { |
| 67 | update_tasks_of_type(TaskType::kBeforeFrame); |
no test coverage detected