From a74bf92e677498aa2dbe2466df1a2c98066fab8d Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 29 Sep 2008 18:37:10 +0000 Subject: [PATCH] combine DS_again with DS_restart --- direct/src/task/TaskNew.py | 4 +--- panda/src/event/asyncTask.cxx | 17 ++++++++--------- panda/src/event/asyncTask.h | 3 +-- panda/src/event/asyncTaskChain.cxx | 5 +---- panda/src/event/pythonTask.cxx | 3 +-- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/direct/src/task/TaskNew.py b/direct/src/task/TaskNew.py index 5eace065f5..87dc75df34 100644 --- a/direct/src/task/TaskNew.py +++ b/direct/src/task/TaskNew.py @@ -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") diff --git a/panda/src/event/asyncTask.cxx b/panda/src/event/asyncTask.cxx index 96fed2670a..6c97319d7b 100644 --- a/panda/src/event/asyncTask.cxx +++ b/panda/src/event/asyncTask.cxx @@ -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. // diff --git a/panda/src/event/asyncTask.h b/panda/src/event/asyncTask.h index 91f6c51ed2..b5972e7a99 100644 --- a/panda/src/event/asyncTask.h +++ b/panda/src/event/asyncTask.h @@ -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 }; diff --git a/panda/src/event/asyncTaskChain.cxx b/panda/src/event/asyncTaskChain.cxx index 46731995f0..05f8663a43 100644 --- a/panda/src/event/asyncTaskChain.cxx +++ b/panda/src/event/asyncTaskChain.cxx @@ -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()); diff --git a/panda/src/event/pythonTask.cxx b/panda/src/event/pythonTask.cxx index 328f048481..5273e21967 100644 --- a/panda/src/event/pythonTask.cxx +++ b/panda/src/event/pythonTask.cxx @@ -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);