combine DS_again with DS_restart

This commit is contained in:
David Rose 2008-09-29 18:37:10 +00:00
parent c82dbc649b
commit a74bf92e67
5 changed files with 12 additions and 20 deletions

View File

@ -3,7 +3,7 @@ AsyncTaskManager interface. It replaces the old full-Python
implementation of the Task system. """
__all__ = ['Task', 'TaskManager',
'cont', 'done', 'again', 'pickup', 'restart']
'cont', 'done', 'again', 'pickup']
from direct.directnotify.DirectNotifyGlobal import *
from direct.showbase import ExceptionVarDump
@ -57,7 +57,6 @@ done = AsyncTask.DSDone
cont = AsyncTask.DSCont
again = AsyncTask.DSAgain
pickup = AsyncTask.DSPickup
restart = AsyncTask.DSRestart
# Alias PythonTask to Task for historical purposes.
Task = PythonTask
@ -69,7 +68,6 @@ Task.DtoolClassDict['done'] = done
Task.DtoolClassDict['cont'] = cont
Task.DtoolClassDict['again'] = again
Task.DtoolClassDict['pickup'] = pickup
Task.DtoolClassDict['restart'] = restart
class TaskManager:
notify = directNotify.newCategory("TaskManager")

View File

@ -376,21 +376,20 @@ is_runnable() {
// DS_cont: the task has more work to do, keep it active
// and call this function again in the next epoch.
//
// DS_again: put the task to sleep for get_delay()
// seconds, then put it back on the active queue.
// DS_again: like DS_cont, but next time call the
// function from the beginning, almost as if it were
// freshly added to the task manager. The task's
// get_start_time() will be reset to now, and its
// get_elapsed_time() will be reset to 0. If the task
// has a set_delay(), it will wait again for that amount
// of time to elapse before restarting. Timing
// accounting, however, is not reset.
//
// DS_pickup: like DS_cont, but if the task chain has a
// frame budget and that budget has not yet been met,
// re-run the task again without waiting for the next
// frame. Otherwise, run it next epoch as usual.
//
// DS_restart: like DS_cont, but next time call the
// function from the beginning, almost as if it were
// freshly added to the task manager. The task's
// get_start_time() will be reset to now, and its
// get_elapsed_time() will be reset to 0. Timing
// accounting, however, is not reset.
//
// DS_abort: abort the task, and interrupt the whole
// AsyncTaskManager.
//

View File

@ -51,9 +51,8 @@ PUBLISHED:
enum DoneStatus {
DS_done, // normal task completion
DS_cont, // run task again next epoch
DS_again, // run task again after at least get_delay() seconds
DS_again, // start the task over from the beginning
DS_pickup, // run task again this frame, if frame budget allows
DS_restart, // start the task over from the beginning
DS_abort, // abort the task and interrupt the whole task manager
};

View File

@ -716,10 +716,6 @@ service_one_task(AsyncTaskChain::AsyncTaskChainThread *thread) {
} else {
switch (ds) {
case AsyncTask::DS_restart:
task->_start_time = _manager->_clock->get_frame_time();
// Fall through.
case AsyncTask::DS_cont:
// The task is still alive; put it on the next frame's active
// queue.
@ -733,6 +729,7 @@ service_one_task(AsyncTaskChain::AsyncTaskChainThread *thread) {
{
double now = _manager->_clock->get_frame_time();
task->_wake_time = now + task->get_delay();
task->_start_time = task->_wake_time;
task->_state = AsyncTask::S_sleeping;
_sleeping.push_back(task);
push_heap(_sleeping.begin(), _sleeping.end(), AsyncTaskSortWakeTime());

View File

@ -409,14 +409,13 @@ do_python_task() {
if (PyInt_Check(result)) {
int retval = PyInt_AS_LONG(result);
switch (retval) {
case DS_restart:
case DS_again:
Py_XDECREF(_generator);
_generator = NULL;
// Fall through.
case DS_done:
case DS_cont:
case DS_again:
case DS_pickup:
// Legitimate value.
Py_DECREF(result);