diff --git a/direct/src/ffi/FFIExternalObject.py b/direct/src/ffi/FFIExternalObject.py index a0b42bc831..5ec311ab57 100644 --- a/direct/src/ffi/FFIExternalObject.py +++ b/direct/src/ffi/FFIExternalObject.py @@ -10,6 +10,10 @@ DowncastMap = {} # FFIConstants.notify.setInfo(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 @@ -41,8 +45,8 @@ class FFIExternalObject: def getLineageInternal(self, thisClass, targetBaseClass, chain): # Recursively determine the path in the heirarchy tree from thisClass # 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__): # Found a link return chain + [targetBaseClass] @@ -54,15 +58,15 @@ class FFIExternalObject: for base in thisClass.__bases__: res = self.getLineageInternal(base, targetBaseClass, chain+[base]) if res: - FFIConstants.notify.debug('getLineageInternal: found path: ' + `res`) + # FFIConstants.notify.debug('getLineageInternal: found path: ' + `res`) return res # Not found anywhere return 0 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) # Start with an empty list of downcast functions downcastFunctionList = [] @@ -80,36 +84,26 @@ class FFIExternalObject: fromClass = lineage[top - i] downcastFuncName = ('downcastTo' + toClass.__name__ + 'From' + fromClass.__name__) + print downcastFuncName # Look over this classes global modules dictionaries # for the downcast function name 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) - else: - FFIConstants.notify.debug( - 'getDowncastFunctions: Did not find downcast function %s in %s' - % (downcastFuncName, globmod.__name__)) return downcastFunctionList 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 if (exactWrapperClass and (exactWrapperClass != self.__class__)): # Create a new wrapper class instance exactObject = exactWrapperClass(None) - # Get the downcast pointer that has had all the downcast # funcs called downcastObject = self.downcast(exactWrapperClass) @@ -124,31 +118,22 @@ class FFIExternalObject: else: return self - def wrapperClassForTypeHandle(self, aTypeHandle): - if WrapperClassMap.has_key(aTypeHandle.getIndex()): - return WrapperClassMap[aTypeHandle.getIndex()] - else: - return None - def downcast(self, toClass): 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 - 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) - FFIConstants.notify.debug('downcast: computed downcast chain: ' + `downcastChain`) + #FFIConstants.notify.debug('downcast: computed downcast chain: ' + `downcastChain`) # Store it for next time DowncastMap[(fromClass, toClass)] = downcastChain - newObject = self 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) return newObject diff --git a/direct/src/ffi/FFIInterrogateDatabase.py b/direct/src/ffi/FFIInterrogateDatabase.py index 427725c57c..14bb422d42 100644 --- a/direct/src/ffi/FFIInterrogateDatabase.py +++ b/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 exec('from ' + FFIConstants.InterrogateModuleName + ' import *') + def constructGlobalFile(codeDir, CModuleName): """ Open a file that will hold the global values and functions code @@ -370,6 +371,12 @@ class FFIInterrogateDatabase: self.typeIndexMap[typeIndex] = descriptor #descriptor.environment = self.environment 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) if descriptor.isNested: outerTypeIndex = interrogate_type_outer_class(typeIndex) diff --git a/direct/src/ffi/FFITypes.py b/direct/src/ffi/FFITypes.py index 5b1e4b2235..a45a2f372b 100644 --- a/direct/src/ffi/FFITypes.py +++ b/direct/src/ffi/FFITypes.py @@ -17,6 +17,9 @@ import FFIOverload from PythonUtil import * +TypedObjectDescriptor = None + + class BaseTypeDescriptor: """ 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('(None)\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: indent(file, nesting, 'returnObject.userManagesMemory = 1\n') 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: indent(file, nesting, 'return returnObject\n') diff --git a/direct/src/showbase/EventManager.py b/direct/src/showbase/EventManager.py index 3a34d51504..6457b0acb1 100644 --- a/direct/src/showbase/EventManager.py +++ b/direct/src/showbase/EventManager.py @@ -22,7 +22,7 @@ class EventManager: self.eventQueue = EventQueue.getGlobalEventQueue() self.eventHandler = EventHandler(self.eventQueue) - def eventLoop(self, state): + def eventLoop(self, task): """ Process all the events on the C++ event queue """ @@ -56,7 +56,6 @@ class EventManager: if event.hasName(): # Get the event name eventName = event.getName() - numParameters = event.getNumParameters() paramList = [] for i in range(numParameters): diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 7c680944c1..6904845f1c 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -65,6 +65,8 @@ class ShowBase: # And put it in the list self.cameraList = [ self.camera ] 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.pipe = makeGraphicsPipe() self.win = makeGraphicsWindow(self.pipe, @@ -302,8 +304,7 @@ class ShowBase: # traverse the data graph. This reads all the control # inputs (from the mouse and keyboard, for instance) and also # directly acts upon them (for instance, to move the avatar). - traverseDataGraph(self.dataRoot.node()) - + traverseDataGraph(self.dataRootNode) return Task.cont def igloop(self, state): @@ -311,10 +312,8 @@ class ShowBase: # CollisionTraverser set. if self.cTrav: self.cTrav.traverse(self.render) - # Finally, render the frame. self.win.update() - return Task.cont def restart(self): diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index d2d1f2d8cd..893c06a05a 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -260,7 +260,6 @@ class TaskManager: self.currentTime, self.currentFrame = getTimeFrame() if (TaskManager.notify == None): TaskManager.notify = directNotify.newCategory("TaskManager") - # TaskManager.notify.setDebug(1) self.taskTimerVerbose = 0 def stepping(value):