浏览代码

special objects should not inherit NodePath's compareTo()

David Rose 24 年之前
父节点
当前提交
04f34561c1
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 12 1
      direct/src/actor/Actor.py
  2. 11 0
      direct/src/distributed/DistributedNode.py

+ 12 - 1
direct/src/actor/Actor.py

@@ -213,7 +213,18 @@ class Actor(PandaObject, NodePath):
         except:
             self.Actor_deleted = 1
             self.cleanup()
- 
+
+    def __cmp__(self, other):
+        # Actor inherits from NodePath, which inherits a definition of
+        # __cmp__ from FFIExternalObject that uses the NodePath's
+        # compareTo() method to compare different NodePaths.  But we
+        # don't want this behavior for Actors; Actors should only be
+        # compared pointerwise.  A NodePath that happens to reference
+        # the same node is still different from the Actor.  Thus, we
+        # redefine __cmp__ to always return a failed comparison.
+        return 1
+
+
     def __str__(self):
         """__str__(self)
         Actor print function"""

+ 11 - 0
direct/src/distributed/DistributedNode.py

@@ -32,6 +32,17 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath):
     def generate(self):
         DistributedObject.DistributedObject.generate(self)
 
+    def __cmp__(self, other):
+        # DistributedNode inherits from NodePath, which inherits a
+        # definition of __cmp__ from FFIExternalObject that uses the
+        # NodePath's compareTo() method to compare different
+        # NodePaths.  But we don't want this behavior for
+        # DistributedNodes; DistributedNodes should only be compared
+        # pointerwise.  A NodePath that happens to reference the same
+        # node is still different from the DistributedNode.  Thus, we
+        # redefine __cmp__ to always return a failed comparison.
+        return 1
+
     ### setParent ###
 
     def b_setParent(self, parentString):