mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 19:08:55 -04:00
for efficiency, import pandac modules once and store them locally
This commit is contained in:
parent
46a0c73e47
commit
5f9c4d55dc
@ -17,6 +17,11 @@ class EventManager:
|
|||||||
|
|
||||||
notify = None
|
notify = None
|
||||||
|
|
||||||
|
# for efficiency, only call import once per module
|
||||||
|
EventStorePandaNode = None
|
||||||
|
EventQueue = None
|
||||||
|
EventHandler = None
|
||||||
|
|
||||||
def __init__(self, eventQueue = None):
|
def __init__(self, eventQueue = None):
|
||||||
"""
|
"""
|
||||||
Create a C++ event queue and handler
|
Create a C++ event queue and handler
|
||||||
@ -61,8 +66,10 @@ class EventManager:
|
|||||||
# which will be downcast to that type
|
# which will be downcast to that type
|
||||||
ptr = eventParameter.getPtr()
|
ptr = eventParameter.getPtr()
|
||||||
|
|
||||||
|
if EventManager.EventStorePandaNode is None:
|
||||||
from pandac.PandaModules import EventStorePandaNode
|
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
|
# Actually, it's a kludgey wrapper around a PandaNode
|
||||||
# pointer. Return the node.
|
# pointer. Return the node.
|
||||||
ptr = ptr.getValue()
|
ptr = ptr.getValue()
|
||||||
@ -101,19 +108,22 @@ class EventManager:
|
|||||||
|
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
|
if None in (EventManager.EventQueue, EventManager.EventHandler):
|
||||||
from pandac.PandaModules import EventQueue, EventHandler
|
from pandac.PandaModules import EventQueue, EventHandler
|
||||||
|
EventManager.EventQueue = EventQueue
|
||||||
|
EventManager.EventHandler = EventHandler
|
||||||
|
|
||||||
if self.eventQueue == None:
|
if self.eventQueue == None:
|
||||||
self.eventQueue = EventQueue.getGlobalEventQueue()
|
self.eventQueue = EventManager.EventQueue.getGlobalEventQueue()
|
||||||
|
|
||||||
if self.eventHandler == None:
|
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
|
# If we are using the global event queue, then we also
|
||||||
# want to use the global event handler.
|
# want to use the global event handler.
|
||||||
self.eventHandler = EventHandler.getGlobalEventHandler(self.eventQueue)
|
self.eventHandler = EventManager.EventHandler.getGlobalEventHandler(self.eventQueue)
|
||||||
else:
|
else:
|
||||||
# Otherwise, we need our own event handler.
|
# Otherwise, we need our own event handler.
|
||||||
self.eventHandler = EventHandler(self.eventQueue)
|
self.eventHandler = EventManager.EventHandler(self.eventQueue)
|
||||||
|
|
||||||
taskMgr.add(self.eventLoopTask, 'eventManager')
|
taskMgr.add(self.eventLoopTask, 'eventManager')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user