Called once per frame to run all of the tasks. Returns JFALSE if it cannot be run due to the time interval.
| 550 | // Called once per frame to run all of the tasks. |
| 551 | // Returns JFALSE if it cannot be run due to the time interval. |
| 552 | JBool task_run() |
| 553 | { |
| 554 | if (!s_taskCount) |
| 555 | { |
| 556 | return JTRUE; |
| 557 | } |
| 558 | TFE_ZONE("Task System"); |
| 559 | |
| 560 | // Limit the update rate by the minimum interval. |
| 561 | // Dark Forces uses discrete 'ticks' to track time and the game behavior is very odd with 0 tick frames. |
| 562 | const f64 time = TFE_System::getTime(); |
| 563 | const bool timeLimiter = s_enableTimeLimiter && !TFE_Settings::getGraphicsSettings()->useSmoothDeltaTime && !TFE_Input::isReplaySystemLive(); |
| 564 | if (time - s_prevTime < s_minIntervalInSec && timeLimiter) |
| 565 | { |
| 566 | return JFALSE; |
| 567 | } |
| 568 | s_prevTime = time; |
| 569 | s_currentMsg = MSG_RUN_TASK; |
| 570 | s_frameActiveTaskCount = 0; |
| 571 | |
| 572 | // Return if the task system is paused. |
| 573 | if (s_taskSystemPaused) |
| 574 | { |
| 575 | if (s_taskPauseTask) |
| 576 | { |
| 577 | s_curTask = s_taskPauseTask; |
| 578 | if (s_curTask->nextTick <= s_curTick) |
| 579 | { |
| 580 | s_frameActiveTaskCount++; |
| 581 | |
| 582 | s_curContext = &s_curTask->context; |
| 583 | s32 level = max(0, s_curContext->level + 1); |
| 584 | TaskFunc runFunc = s_curContext->callstack[level]; |
| 585 | assert(runFunc); |
| 586 | |
| 587 | if (runFunc) |
| 588 | { |
| 589 | runFunc(s_currentMsg); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | return JTRUE; |
| 594 | } |
| 595 | |
| 596 | // Keep processing tasks until the "framebreak" task is hit. |
| 597 | // Once the framebreak task completes (if it is not sleeping), then break out of the loop - processing will resume |
| 598 | // on the next task on the next frame. |
| 599 | // Note: the original code just loop here forever, but we break it up between frames to play nice with modern operating systems. |
| 600 | while (s_curTask) |
| 601 | { |
| 602 | TASK_MSG("Current Task: '%s'.", s_curTask->name); |
| 603 | JBool framebreak = s_curTask->framebreak; |
| 604 | |
| 605 | // This should only be false when hitting the "framebreak" task which is sleeping. |
| 606 | if (s_curTask->nextTick <= s_curTick) |
| 607 | { |
| 608 | s_frameActiveTaskCount++; |
| 609 |
no test coverage detected