defer loading taskMgr until after importing PandaModules

This commit is contained in:
David Rose 2008-10-24 21:50:17 +00:00
parent 37ce4c9329
commit c188d2935c
3 changed files with 70 additions and 3 deletions

View File

@ -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):

62
direct/src/task/MiniTask.py Executable file
View File

@ -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

View File

@ -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 *