for efficiency, import pandac modules once and store them locally

This commit is contained in:
Darren Ranalli 2006-10-28 12:59:46 +00:00
parent 46a0c73e47
commit 5f9c4d55dc

View File

@ -17,6 +17,11 @@ class EventManager:
notify = None
# for efficiency, only call import once per module
EventStorePandaNode = None
EventQueue = None
EventHandler = None
def __init__(self, eventQueue = None):
"""
Create a C++ event queue and handler
@ -61,8 +66,10 @@ class EventManager:
# which will be downcast to that type
ptr = eventParameter.getPtr()
if EventManager.EventStorePandaNode is None:
from pandac.PandaModules import EventStorePandaNode
if isinstance(ptr, EventStorePandaNode):
EventManager.EventStorePandaNode = EventStorePandaNode
if isinstance(ptr, EventManager.EventStorePandaNode):
# Actually, it's a kludgey wrapper around a PandaNode
# pointer. Return the node.
ptr = ptr.getValue()
@ -101,19 +108,22 @@ class EventManager:
def restart(self):
if None in (EventManager.EventQueue, EventManager.EventHandler):
from pandac.PandaModules import EventQueue, EventHandler
EventManager.EventQueue = EventQueue
EventManager.EventHandler = EventHandler
if self.eventQueue == None:
self.eventQueue = EventQueue.getGlobalEventQueue()
self.eventQueue = EventManager.EventQueue.getGlobalEventQueue()
if self.eventHandler == None:
if self.eventQueue == EventQueue.getGlobalEventQueue():
if self.eventQueue == EventManager.EventQueue.getGlobalEventQueue():
# If we are using the global event queue, then we also
# want to use the global event handler.
self.eventHandler = EventHandler.getGlobalEventHandler(self.eventQueue)
self.eventHandler = EventManager.EventHandler.getGlobalEventHandler(self.eventQueue)
else:
# Otherwise, we need our own event handler.
self.eventHandler = EventHandler(self.eventQueue)
self.eventHandler = EventManager.EventHandler(self.eventQueue)
taskMgr.add(self.eventLoopTask, 'eventManager')