From c188d2935ced3ef62cbd78bca00be45291593eda Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 24 Oct 2008 21:50:17 +0000 Subject: [PATCH] defer loading taskMgr until after importing PandaModules --- direct/src/showbase/EventManager.py | 6 +-- direct/src/task/MiniTask.py | 62 +++++++++++++++++++++++++++++ direct/src/task/TaskOrig.py | 5 +++ 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100755 direct/src/task/MiniTask.py diff --git a/direct/src/showbase/EventManager.py b/direct/src/showbase/EventManager.py index 101698de1a..7d02934f3e 100644 --- a/direct/src/showbase/EventManager.py +++ b/direct/src/showbase/EventManager.py @@ -4,9 +4,7 @@ __all__ = ['EventManager'] from MessengerGlobal import * -from direct.task.TaskManagerGlobal import taskMgr from direct.directnotify.DirectNotifyGlobal import * -from direct.task.Task import Task # This module may not import pandac.PandaModules, since it is imported # by the Toontown Launcher before the complete PandaModules have been @@ -62,7 +60,7 @@ class EventManager: """ self.doEvents() messenger.send("event-loop-done") - return Task.cont + return task.cont def parseEventParameter(self, eventParameter): """ @@ -209,6 +207,8 @@ class EventManager: # Otherwise, we need our own event handler. self.eventHandler = EventManager.EventHandler(self.eventQueue) + # Should be safe to import the global taskMgr by now. + from direct.task.TaskManagerGlobal import taskMgr taskMgr.add(self.eventLoopTask, 'eventManager') def shutdown(self): diff --git a/direct/src/task/MiniTask.py b/direct/src/task/MiniTask.py new file mode 100755 index 0000000000..d2aec195a2 --- /dev/null +++ b/direct/src/task/MiniTask.py @@ -0,0 +1,62 @@ +"""This module implements a minimum task manager. It is similar in +principle to the full-featured task manager implemented in Task.py, +but it has a sharply reduced feature set--completely bare-bones, in +fact--and it is designed to be a pure-python implementation that does +not require any C++ Panda support, so that it can be loaded before +Panda has been fully downloaded. """ + +__all__ = ['MiniTask', 'MiniTaskManager'] + +class MiniTask: + done = 0 + cont = 1 + + def __init__(self, callback): + self.__call__ = callback + +class MiniTaskManager: + + def __init__(self): + self.taskList = [] + self.running = 0 + + def add(self, task, name): + assert isinstance(task, MiniTask) + task.name = name + self.taskList.append(task) + + def remove(self, task): + self.taskList.remove(task) + + def __executeTask(self, task): + return task(task) + + def step(self): + i = 0 + while (i < len(self.taskList)): + task = self.taskList[i] + ret = task(task) + + # See if the task is done + if (ret == task.cont): + # Leave it for next frame, its not done yet + pass + + else: + # Remove the task + self.taskList.remove(task) + # Do not increment the iterator + continue + + # Move to the next element + i += 1 + + def run(self): + self.running = 1 + while self.running: + self.step() + + def stop(self): + # Set a flag so we will stop before beginning next frame + self.running = 0 + diff --git a/direct/src/task/TaskOrig.py b/direct/src/task/TaskOrig.py index 3088ee4cfe..2d41276cc6 100644 --- a/direct/src/task/TaskOrig.py +++ b/direct/src/task/TaskOrig.py @@ -10,6 +10,11 @@ __all__ = ['Task', 'TaskSortList', 'TaskManager', # subset of PandaModules that we know is available immediately. # Methods that require more advanced C++ methods may import the # appropriate files within their own scope. + +# Actually, the above is no longer true. The Task module is no longer +# imported before PandaModules is available. Instead, we make use of +# the much more limited MiniTask.py for initial startup. + from pandac.libpandaexpressModules import * from direct.directnotify.DirectNotifyGlobal import *