Преглед изворни кода

DistributedObject.activeStatus

David Rose пре 23 година
родитељ
комит
e83c431b91
2 измењених фајлова са 26 додато и 7 уклоњено
  1. 1 1
      direct/src/distributed/DistributedNode.py
  2. 25 6
      direct/src/distributed/DistributedObject.py

+ 1 - 1
direct/src/distributed/DistributedNode.py

@@ -65,7 +65,7 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath):
         DistributedAvatar) to override the behavior of setParent if
         DistributedAvatar) to override the behavior of setParent if
         desired.
         desired.
         """
         """
-        if not self.disabled:
+        if not self.isDisabled():
             assert(self.cr.token2nodePath.has_key(parentToken))
             assert(self.cr.token2nodePath.has_key(parentToken))
             parent = self.cr.token2nodePath[parentToken]
             parent = self.cr.token2nodePath[parentToken]
             self.wrtReparentTo(parent)
             self.wrtReparentTo(parent)

+ 25 - 6
direct/src/distributed/DistributedObject.py

@@ -3,6 +3,15 @@
 from PandaObject import *
 from PandaObject import *
 from DirectNotifyGlobal import *
 from DirectNotifyGlobal import *
 
 
+# Values for DistributedObject.activeState
+
+ESNew          = 1
+ESDeleted      = 2
+ESDisabling    = 3
+ESDisabled     = 4  # values here and lower are considered "disabled"
+ESGenerating   = 5  # values here and greater are considered "generated"
+ESGenerated    = 6
+
 class DistributedObject(PandaObject):
 class DistributedObject(PandaObject):
     """Distributed Object class:"""
     """Distributed Object class:"""
     notify = directNotify.newCategory("DistributedObject")
     notify = directNotify.newCategory("DistributedObject")
@@ -35,10 +44,10 @@ class DistributedObject(PandaObject):
             # object.
             # object.
             self.deleteImminent = 0
             self.deleteImminent = 0
 
 
-            # It's useful to have a "disabled" flag.  This is only
-            # trustworthy if the inheriting class properly calls up
-            # the chain for disable() and generate().
-            self.disabled = 1
+            # Keep track of our state as a distributed object.  This
+            # is only trustworthy if the inheriting class properly
+            # calls up the chain for disable() and generate().
+            self.activeState = ESNew
             
             
         return None
         return None
 
 
@@ -115,6 +124,7 @@ class DistributedObject(PandaObject):
         # a normal, nondisabled state; and *then* the disable function
         # a normal, nondisabled state; and *then* the disable function
         # can properly disable it (for instance, by parenting it to
         # can properly disable it (for instance, by parenting it to
         # hidden).
         # hidden).
+        self.activeState = ESDisabling
         messenger.send(self.uniqueName("disable"))
         messenger.send(self.uniqueName("disable"))
         self.disable()
         self.disable()
         return None
         return None
@@ -124,13 +134,21 @@ class DistributedObject(PandaObject):
         Sends a message to the world after the object has been
         Sends a message to the world after the object has been
         generated and all of its required fields filled in.
         generated and all of its required fields filled in.
         """
         """
+        self.activeState = ESGenerated
         messenger.send(self.uniqueName("generate"), [self])
         messenger.send(self.uniqueName("generate"), [self])
 
 
     def disable(self):
     def disable(self):
         """disable(self)
         """disable(self)
         Inheritors should redefine this to take appropriate action on disable
         Inheritors should redefine this to take appropriate action on disable
         """
         """
-        self.disabled = 1
+        self.activeState = ESDisabled
+
+    def isDisabled(self):
+        """isDisabled(self)
+        Returns true if the object has been disabled and/or deleted,
+        or if it is brand new and hasn't yet been generated.
+        """
+        return (self.activeState < ESGenerating)
 
 
     def delete(self):
     def delete(self):
         """delete(self)
         """delete(self)
@@ -147,13 +165,14 @@ class DistributedObject(PandaObject):
         """generate(self)
         """generate(self)
         Inheritors should redefine this to take appropriate action on generate
         Inheritors should redefine this to take appropriate action on generate
         """
         """
-        self.disabled = 0
+        self.activeState = ESGenerating
 
 
     def generateInit(self):
     def generateInit(self):
         """generateInit(self)
         """generateInit(self)
         This method is called when the DistributedObject is first introduced
         This method is called when the DistributedObject is first introduced
         to the world... Not when it is pulled from the cache.
         to the world... Not when it is pulled from the cache.
         """
         """
+        self.activeState = ESGenerating
     
     
     def getDoId(self):
     def getDoId(self):
         """getDoId(self)
         """getDoId(self)