| 400 | } |
| 401 | |
| 402 | void selectNextTask() |
| 403 | { |
| 404 | // Find the next task to run. |
| 405 | Task* task = s_curTask; |
| 406 | while (1) |
| 407 | { |
| 408 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 409 | // Execution: |
| 410 | // * Go to the next task |
| 411 | // * Check to see if there are sub-tasks |
| 412 | // * If so, the assign current to the sub-task. |
| 413 | // * Execute the task. |
| 414 | // * Once we are on the last sub-task, then go back to the parent. |
| 415 | // * Once the parent executes, then we move on to parent->next and start all over. |
| 416 | if (task->next) |
| 417 | { |
| 418 | // Move the to the next task. |
| 419 | task = task->next; |
| 420 | // If the task has sub-tasks, loop until we find the last one. |
| 421 | // This is usually only one deep. |
| 422 | while (task->subtaskNext) |
| 423 | { |
| 424 | task = task->subtaskNext; |
| 425 | } |
| 426 | // Then execute the task. |
| 427 | if (task->nextTick <= s_curTick || task->framebreak) |
| 428 | { |
| 429 | s_currentMsg = MSG_RUN_TASK; |
| 430 | s_curTask = task; |
| 431 | return; |
| 432 | } |
| 433 | } |
| 434 | else if (task->subtaskParent) |
| 435 | { |
| 436 | // Otherwise, try to execute the parent. |
| 437 | task = task->subtaskParent; |
| 438 | if (task->nextTick <= s_curTick || task->framebreak) |
| 439 | { |
| 440 | s_currentMsg = MSG_RUN_TASK; |
| 441 | s_curTask = task; |
| 442 | return; |
| 443 | } |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | // If no selection is possible, assign the first task. |
| 452 | if (!s_curTask && s_taskCount) |
| 453 | { |
| 454 | s_curTask = (Task*)chunkedArrayGet(s_tasks, 0); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | void itask_run(Task* task, MessageType msg) |
| 459 | { |
no test coverage detected