浏览代码

*** empty log message ***

Joe Shochet 24 年之前
父节点
当前提交
086bed3a85

+ 26 - 41
direct/src/ffi/FFIExternalObject.py

@@ -10,6 +10,10 @@ DowncastMap = {}
 # FFIConstants.notify.setInfo(1)
 # FFIConstants.notify.setInfo(1)
 # FFIConstants.notify.setDebug(1)
 # FFIConstants.notify.setDebug(1)
 
 
+# Uncomment the notify statements if you need to debug,
+# otherwise leave them commented out to prevent runtime
+# overhead of calling them
+
 
 
 
 
 # Register a python class in the type map if it is a typed object
 # Register a python class in the type map if it is a typed object
@@ -41,8 +45,8 @@ class FFIExternalObject:
     def getLineageInternal(self, thisClass, targetBaseClass, chain):
     def getLineageInternal(self, thisClass, targetBaseClass, chain):
         # Recursively determine the path in the heirarchy tree from thisClass
         # Recursively determine the path in the heirarchy tree from thisClass
         # to the targetBaseClass
         # to the targetBaseClass
-        FFIConstants.notify.debug('getLineageInternal: checking %s to %s'
-                                  % (thisClass.__name__, targetBaseClass.__name__))
+        #FFIConstants.notify.debug('getLineageInternal: checking %s to %s'
+        #                          % (thisClass.__name__, targetBaseClass.__name__))
         if (targetBaseClass in thisClass.__bases__):
         if (targetBaseClass in thisClass.__bases__):
             # Found a link
             # Found a link
             return chain + [targetBaseClass]
             return chain + [targetBaseClass]
@@ -54,15 +58,15 @@ class FFIExternalObject:
             for base in thisClass.__bases__:
             for base in thisClass.__bases__:
                 res = self.getLineageInternal(base, targetBaseClass, chain+[base])
                 res = self.getLineageInternal(base, targetBaseClass, chain+[base])
                 if res:
                 if res:
-                    FFIConstants.notify.debug('getLineageInternal: found path: ' + `res`)
+                    # FFIConstants.notify.debug('getLineageInternal: found path: ' + `res`)
                     return res
                     return res
             # Not found anywhere
             # Not found anywhere
             return 0
             return 0
 
 
     def getDowncastFunctions(self, thisClass, baseClass):
     def getDowncastFunctions(self, thisClass, baseClass):
-        FFIConstants.notify.debug(
-            'getDowncastFunctions: Looking for downcast function from %s to %s'
-            % (baseClass.__name__, thisClass.__name__))
+        #FFIConstants.notify.debug(
+        #    'getDowncastFunctions: Looking for downcast function from %s to %s'
+        #    % (baseClass.__name__, thisClass.__name__))
         lineage = self.getLineage(thisClass, baseClass)
         lineage = self.getLineage(thisClass, baseClass)
         # Start with an empty list of downcast functions
         # Start with an empty list of downcast functions
         downcastFunctionList = []
         downcastFunctionList = []
@@ -80,36 +84,26 @@ class FFIExternalObject:
             fromClass = lineage[top - i]
             fromClass = lineage[top - i]
             downcastFuncName = ('downcastTo' + toClass.__name__
             downcastFuncName = ('downcastTo' + toClass.__name__
                                 + 'From' + fromClass.__name__)
                                 + 'From' + fromClass.__name__)
+            print downcastFuncName
             # Look over this classes global modules dictionaries
             # Look over this classes global modules dictionaries
             # for the downcast function name
             # for the downcast function name
             for globmod in toClass.__CModuleDowncasts__:
             for globmod in toClass.__CModuleDowncasts__:
-                if globmod.__dict__.has_key(downcastFuncName):
-                    func = globmod.__dict__[downcastFuncName]
-                    FFIConstants.notify.debug(
-                        'getDowncastFunctions: Found downcast function %s in %s'
-                        % (downcastFuncName, globmod.__name__))
+                func = globmod.__dict__.get(downcastFuncName)
+                if func:
+                    #FFIConstants.notify.debug(
+                    #    'getDowncastFunctions: Found downcast function %s in %s'
+                    #    % (downcastFuncName, globmod.__name__))
                     downcastFunctionList.append(func)
                     downcastFunctionList.append(func)
-                else:
-                    FFIConstants.notify.debug(
-                        'getDowncastFunctions: Did not find downcast function %s in %s'
-                        % (downcastFuncName, globmod.__name__))
         return downcastFunctionList
         return downcastFunctionList
         
         
     def setPointer(self):
     def setPointer(self):
-        if (self.this == 0):
-            # Null pointer, return None
-            return None
-        # If it is not a typed object, our work is done, just return the object
-        if (not isinstance(self, TypedObject.TypedObject)): 
-            return self
-        # Ok, it is a typed object. See what type it really is and downcast
-        # to that type (if necessary)
-        exactWrapperClass = self.wrapperClassForTypeHandle(self.getType())
+        # See what type it really is and downcast to that type (if necessary)
+        # Look up the TypeHandle in the dict. get() returns None if it is not there
+        exactWrapperClass = WrapperClassMap.get(self.getType().getIndex())
         # We do not need to downcast if we already have the same class
         # We do not need to downcast if we already have the same class
         if (exactWrapperClass and (exactWrapperClass != self.__class__)):
         if (exactWrapperClass and (exactWrapperClass != self.__class__)):
             # Create a new wrapper class instance
             # Create a new wrapper class instance
             exactObject = exactWrapperClass(None)
             exactObject = exactWrapperClass(None)
-
             # Get the downcast pointer that has had all the downcast
             # Get the downcast pointer that has had all the downcast
             # funcs called
             # funcs called
             downcastObject = self.downcast(exactWrapperClass)
             downcastObject = self.downcast(exactWrapperClass)
@@ -124,31 +118,22 @@ class FFIExternalObject:
         else:
         else:
             return self
             return self
  
  
-    def wrapperClassForTypeHandle(self, aTypeHandle):
-        if WrapperClassMap.has_key(aTypeHandle.getIndex()):
-            return WrapperClassMap[aTypeHandle.getIndex()]
-        else:
-            return None
-        
     def downcast(self, toClass):
     def downcast(self, toClass):
         fromClass = self.__class__
         fromClass = self.__class__
-        FFIConstants.notify.debug('downcast: downcasting from %s to %s' % \
-            (fromClass.__name__, toClass.__name__))
+        #FFIConstants.notify.debug('downcast: downcasting from %s to %s' % \
+        #    (fromClass.__name__, toClass.__name__))
 
 
         # Check the cache to see if we have looked this up before
         # Check the cache to see if we have looked this up before
-        if DowncastMap.has_key((fromClass, toClass)):
-            downcastChain = DowncastMap[(fromClass, toClass)]
-            FFIConstants.notify.debug('downcast: found cached downcast chain: ' + `downcastChain`)            
-        else:
+        downcastChain = DowncastMap.get((fromClass, toClass))
+        if downcastChain == None:
             downcastChain = self.getDowncastFunctions(toClass, fromClass)
             downcastChain = self.getDowncastFunctions(toClass, fromClass)
-            FFIConstants.notify.debug('downcast: computed downcast chain: ' + `downcastChain`)
+            #FFIConstants.notify.debug('downcast: computed downcast chain: ' + `downcastChain`)
             # Store it for next time
             # Store it for next time
             DowncastMap[(fromClass, toClass)] = downcastChain
             DowncastMap[(fromClass, toClass)] = downcastChain
-            
         newObject = self
         newObject = self
         for downcastFunc in downcastChain:
         for downcastFunc in downcastChain:
-            FFIConstants.notify.debug('downcast: downcasting %s using %s' % \
-                                      (newObject.__class__.__name__, downcastFunc))
+            #FFIConstants.notify.debug('downcast: downcasting %s using %s' % \
+            #                         (newObject.__class__.__name__, downcastFunc))
             newObject = downcastFunc(newObject)
             newObject = downcastFunc(newObject)
         return newObject
         return newObject
 
 

+ 7 - 0
direct/src/ffi/FFIInterrogateDatabase.py

@@ -21,6 +21,7 @@ FFIConstants.notify.info('Importing interrogate library: ' + FFIConstants.Interr
 # to be dependent on the name of the interrogate library in this code
 # to be dependent on the name of the interrogate library in this code
 exec('from ' + FFIConstants.InterrogateModuleName + ' import *')
 exec('from ' + FFIConstants.InterrogateModuleName + ' import *')
 
 
+
 def constructGlobalFile(codeDir, CModuleName):
 def constructGlobalFile(codeDir, CModuleName):
     """
     """
     Open a file that will hold the global values and functions code
     Open a file that will hold the global values and functions code
@@ -370,6 +371,12 @@ class FFIInterrogateDatabase:
         self.typeIndexMap[typeIndex] = descriptor
         self.typeIndexMap[typeIndex] = descriptor
         #descriptor.environment = self.environment
         #descriptor.environment = self.environment
         descriptor.foreignTypeName = FFIRename.classNameFromCppName(getTypeName(typeIndex))
         descriptor.foreignTypeName = FFIRename.classNameFromCppName(getTypeName(typeIndex))
+
+        if (descriptor.foreignTypeName == "TypedObject"):
+            print "Found typed object descriptor"
+            FFITypes.TypedObjectDescriptor = descriptor
+            
+        
         descriptor.isNested = interrogate_type_is_nested(typeIndex)
         descriptor.isNested = interrogate_type_is_nested(typeIndex)
         if descriptor.isNested:
         if descriptor.isNested:
             outerTypeIndex = interrogate_type_outer_class(typeIndex)
             outerTypeIndex = interrogate_type_outer_class(typeIndex)

+ 10 - 1
direct/src/ffi/FFITypes.py

@@ -17,6 +17,9 @@ import FFIOverload
 
 
 from PythonUtil import *
 from PythonUtil import *
 
 
+TypedObjectDescriptor = None
+
+
 class BaseTypeDescriptor:
 class BaseTypeDescriptor:
     """
     """
     A type descriptor contains everything you need to know about a C++ function,
     A type descriptor contains everything you need to know about a C++ function,
@@ -803,10 +806,16 @@ class ClassTypeDescriptor(BaseTypeDescriptor):
         file.write(typeName)
         file.write(typeName)
         file.write('(None)\n')
         file.write('(None)\n')
         indent(file, nesting, 'returnObject.this = returnValue\n')
         indent(file, nesting, 'returnObject.this = returnValue\n')
+        # Zero this pointers get returned as the Python None object
+        indent(file, nesting, 'if (returnObject.this == 0): return None\n')
         if userManagesMemory:
         if userManagesMemory:
             indent(file, nesting, 'returnObject.userManagesMemory = 1\n')
             indent(file, nesting, 'returnObject.userManagesMemory = 1\n')
         if needsDowncast:
         if needsDowncast:
-            indent(file, nesting, 'return returnObject.setPointer()\n')
+            if (FFIOverload.inheritsFrom(self, TypedObjectDescriptor) or
+                self == TypedObjectDescriptor):
+                indent(file, nesting, 'return returnObject.setPointer()\n')
+            else:
+                indent(file, nesting, 'return returnObject\n')
         else:
         else:
             indent(file, nesting, 'return returnObject\n')
             indent(file, nesting, 'return returnObject\n')
             
             

+ 1 - 2
direct/src/showbase/EventManager.py

@@ -22,7 +22,7 @@ class EventManager:
         self.eventQueue = EventQueue.getGlobalEventQueue()
         self.eventQueue = EventQueue.getGlobalEventQueue()
         self.eventHandler = EventHandler(self.eventQueue)
         self.eventHandler = EventHandler(self.eventQueue)
 
 
-    def eventLoop(self, state):
+    def eventLoop(self, task):
         """
         """
         Process all the events on the C++ event queue
         Process all the events on the C++ event queue
         """
         """
@@ -56,7 +56,6 @@ class EventManager:
 	if event.hasName():
 	if event.hasName():
             # Get the event name
             # Get the event name
             eventName = event.getName()
             eventName = event.getName()
-
             numParameters = event.getNumParameters()
             numParameters = event.getNumParameters()
             paramList = []
             paramList = []
             for i in range(numParameters):
             for i in range(numParameters):

+ 3 - 4
direct/src/showbase/ShowBase.py

@@ -65,6 +65,8 @@ class ShowBase:
         # And put it in the list
         # And put it in the list
         self.cameraList = [ self.camera ]
         self.cameraList = [ self.camera ]
         self.dataRoot = NodePath(NamedNode('dataRoot'), DataRelation.getClassType())
         self.dataRoot = NodePath(NamedNode('dataRoot'), DataRelation.getClassType())
+        # Cache the node so we do not ask for it every frame
+        self.dataRootNode = self.dataRoot.node()
         self.dataUnused = NodePath(NamedNode('dataUnused'), DataRelation.getClassType())
         self.dataUnused = NodePath(NamedNode('dataUnused'), DataRelation.getClassType())
         self.pipe = makeGraphicsPipe()
         self.pipe = makeGraphicsPipe()
         self.win = makeGraphicsWindow(self.pipe,
         self.win = makeGraphicsWindow(self.pipe,
@@ -302,8 +304,7 @@ class ShowBase:
         # traverse the data graph.  This reads all the control
         # traverse the data graph.  This reads all the control
         # inputs (from the mouse and keyboard, for instance) and also
         # inputs (from the mouse and keyboard, for instance) and also
         # directly acts upon them (for instance, to move the avatar).
         # directly acts upon them (for instance, to move the avatar).
-        traverseDataGraph(self.dataRoot.node())
-
+        traverseDataGraph(self.dataRootNode)
         return Task.cont
         return Task.cont
 
 
     def igloop(self, state):
     def igloop(self, state):
@@ -311,10 +312,8 @@ class ShowBase:
         # CollisionTraverser set.
         # CollisionTraverser set.
         if self.cTrav:
         if self.cTrav:
             self.cTrav.traverse(self.render)
             self.cTrav.traverse(self.render)
-
         # Finally, render the frame.
         # Finally, render the frame.
         self.win.update()
         self.win.update()
-
         return Task.cont
         return Task.cont
 
 
     def restart(self):
     def restart(self):

+ 0 - 1
direct/src/task/Task.py

@@ -260,7 +260,6 @@ class TaskManager:
         self.currentTime, self.currentFrame = getTimeFrame()
         self.currentTime, self.currentFrame = getTimeFrame()
         if (TaskManager.notify == None):
         if (TaskManager.notify == None):
             TaskManager.notify = directNotify.newCategory("TaskManager")
             TaskManager.notify = directNotify.newCategory("TaskManager")
-        # TaskManager.notify.setDebug(1)
         self.taskTimerVerbose = 0
         self.taskTimerVerbose = 0
 
 
     def stepping(value):
     def stepping(value):