mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
combine DS_again with DS_restart
This commit is contained in:
parent
c82dbc649b
commit
a74bf92e67
@ -3,7 +3,7 @@ AsyncTaskManager interface. It replaces the old full-Python
|
|||||||
implementation of the Task system. """
|
implementation of the Task system. """
|
||||||
|
|
||||||
__all__ = ['Task', 'TaskManager',
|
__all__ = ['Task', 'TaskManager',
|
||||||
'cont', 'done', 'again', 'pickup', 'restart']
|
'cont', 'done', 'again', 'pickup']
|
||||||
|
|
||||||
from direct.directnotify.DirectNotifyGlobal import *
|
from direct.directnotify.DirectNotifyGlobal import *
|
||||||
from direct.showbase import ExceptionVarDump
|
from direct.showbase import ExceptionVarDump
|
||||||
@ -57,7 +57,6 @@ done = AsyncTask.DSDone
|
|||||||
cont = AsyncTask.DSCont
|
cont = AsyncTask.DSCont
|
||||||
again = AsyncTask.DSAgain
|
again = AsyncTask.DSAgain
|
||||||
pickup = AsyncTask.DSPickup
|
pickup = AsyncTask.DSPickup
|
||||||
restart = AsyncTask.DSRestart
|
|
||||||
|
|
||||||
# Alias PythonTask to Task for historical purposes.
|
# Alias PythonTask to Task for historical purposes.
|
||||||
Task = PythonTask
|
Task = PythonTask
|
||||||
@ -69,7 +68,6 @@ Task.DtoolClassDict['done'] = done
|
|||||||
Task.DtoolClassDict['cont'] = cont
|
Task.DtoolClassDict['cont'] = cont
|
||||||
Task.DtoolClassDict['again'] = again
|
Task.DtoolClassDict['again'] = again
|
||||||
Task.DtoolClassDict['pickup'] = pickup
|
Task.DtoolClassDict['pickup'] = pickup
|
||||||
Task.DtoolClassDict['restart'] = restart
|
|
||||||
|
|
||||||
class TaskManager:
|
class TaskManager:
|
||||||
notify = directNotify.newCategory("TaskManager")
|
notify = directNotify.newCategory("TaskManager")
|
||||||
|
@ -376,21 +376,20 @@ is_runnable() {
|
|||||||
// DS_cont: the task has more work to do, keep it active
|
// DS_cont: the task has more work to do, keep it active
|
||||||
// and call this function again in the next epoch.
|
// and call this function again in the next epoch.
|
||||||
//
|
//
|
||||||
// DS_again: put the task to sleep for get_delay()
|
// DS_again: like DS_cont, but next time call the
|
||||||
// seconds, then put it back on the active queue.
|
// 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
|
// DS_pickup: like DS_cont, but if the task chain has a
|
||||||
// frame budget and that budget has not yet been met,
|
// frame budget and that budget has not yet been met,
|
||||||
// re-run the task again without waiting for the next
|
// re-run the task again without waiting for the next
|
||||||
// frame. Otherwise, run it next epoch as usual.
|
// 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
|
// DS_abort: abort the task, and interrupt the whole
|
||||||
// AsyncTaskManager.
|
// AsyncTaskManager.
|
||||||
//
|
//
|
||||||
|
@ -51,9 +51,8 @@ PUBLISHED:
|
|||||||
enum DoneStatus {
|
enum DoneStatus {
|
||||||
DS_done, // normal task completion
|
DS_done, // normal task completion
|
||||||
DS_cont, // run task again next epoch
|
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_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
|
DS_abort, // abort the task and interrupt the whole task manager
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -716,10 +716,6 @@ service_one_task(AsyncTaskChain::AsyncTaskChainThread *thread) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
switch (ds) {
|
switch (ds) {
|
||||||
case AsyncTask::DS_restart:
|
|
||||||
task->_start_time = _manager->_clock->get_frame_time();
|
|
||||||
// Fall through.
|
|
||||||
|
|
||||||
case AsyncTask::DS_cont:
|
case AsyncTask::DS_cont:
|
||||||
// The task is still alive; put it on the next frame's active
|
// The task is still alive; put it on the next frame's active
|
||||||
// queue.
|
// queue.
|
||||||
@ -733,6 +729,7 @@ service_one_task(AsyncTaskChain::AsyncTaskChainThread *thread) {
|
|||||||
{
|
{
|
||||||
double now = _manager->_clock->get_frame_time();
|
double now = _manager->_clock->get_frame_time();
|
||||||
task->_wake_time = now + task->get_delay();
|
task->_wake_time = now + task->get_delay();
|
||||||
|
task->_start_time = task->_wake_time;
|
||||||
task->_state = AsyncTask::S_sleeping;
|
task->_state = AsyncTask::S_sleeping;
|
||||||
_sleeping.push_back(task);
|
_sleeping.push_back(task);
|
||||||
push_heap(_sleeping.begin(), _sleeping.end(), AsyncTaskSortWakeTime());
|
push_heap(_sleeping.begin(), _sleeping.end(), AsyncTaskSortWakeTime());
|
||||||
|
@ -409,14 +409,13 @@ do_python_task() {
|
|||||||
if (PyInt_Check(result)) {
|
if (PyInt_Check(result)) {
|
||||||
int retval = PyInt_AS_LONG(result);
|
int retval = PyInt_AS_LONG(result);
|
||||||
switch (retval) {
|
switch (retval) {
|
||||||
case DS_restart:
|
case DS_again:
|
||||||
Py_XDECREF(_generator);
|
Py_XDECREF(_generator);
|
||||||
_generator = NULL;
|
_generator = NULL;
|
||||||
// Fall through.
|
// Fall through.
|
||||||
|
|
||||||
case DS_done:
|
case DS_done:
|
||||||
case DS_cont:
|
case DS_cont:
|
||||||
case DS_again:
|
|
||||||
case DS_pickup:
|
case DS_pickup:
|
||||||
// Legitimate value.
|
// Legitimate value.
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user