From 5c328305cf06061c5ee1ccb3dc3e959baf95e5b8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 14 Sep 2002 17:42:38 +0000 Subject: [PATCH] debugging statements and cleanup to help track down disable problems --- direct/src/distributed/CRCache.py | 12 ++++++++++++ direct/src/distributed/DistributedNode.py | 11 ++++++----- direct/src/distributed/DistributedObject.py | 17 +++++++++++++++-- direct/src/distributed/DistributedSmoothNode.py | 5 ----- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/direct/src/distributed/CRCache.py b/direct/src/distributed/CRCache.py index 1d627ce8b0..4b18f6a083 100644 --- a/direct/src/distributed/CRCache.py +++ b/direct/src/distributed/CRCache.py @@ -16,6 +16,7 @@ class CRCache: """ Delete each item in the cache then clear all references to them """ + assert(self.checkCache()) CRCache.notify.debug("Flushing the cache") for distObj in self.dict.values(): distObj.delete() @@ -26,6 +27,7 @@ class CRCache: def cache(self, distObj): # Only distributed objects are allowed in the cache assert(isinstance(distObj, DistributedObject.DistributedObject)) + assert(self.checkCache()) # Get the doId doId = distObj.getDoId() # Error check @@ -53,6 +55,7 @@ class CRCache: return None def retrieve(self, doId): + assert(self.checkCache()) if self.dict.has_key(doId): # Find the object distObj = self.dict[doId] @@ -70,6 +73,7 @@ class CRCache: return self.dict.has_key(doId) def delete(self, doId): + assert(self.checkCache()) assert(self.dict.has_key(doId)) # Look it up distObj = self.dict[doId] @@ -79,3 +83,11 @@ class CRCache: # and delete it distObj.delete() + def checkCache(self): + # For debugging; this verifies that the cache is sensible and + # returns true if so. + from PandaModules import NodePath + for obj in self.dict.values(): + if isinstance(obj, NodePath): + assert(not obj.isEmpty() and obj.getTopNode() == hidden.node()) + return 1 diff --git a/direct/src/distributed/DistributedNode.py b/direct/src/distributed/DistributedNode.py index d054d70807..9d85d17568 100644 --- a/direct/src/distributed/DistributedNode.py +++ b/direct/src/distributed/DistributedNode.py @@ -1,11 +1,11 @@ """DistributedNode module: contains the DistributedNode class""" from ShowBaseGlobal import * -import NodePath +from PandaModules import NodePath import DistributedObject import Task -class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath): +class DistributedNode(DistributedObject.DistributedObject, NodePath): """Distributed Node class:""" def __init__(self, cr): @@ -65,9 +65,10 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath): DistributedAvatar) to override the behavior of setParent if desired. """ - assert(self.cr.token2nodePath.has_key(parentToken)) - parent = self.cr.token2nodePath[parentToken] - self.wrtReparentTo(parent) + if not self.disabled: + assert(self.cr.token2nodePath.has_key(parentToken)) + parent = self.cr.token2nodePath[parentToken] + self.wrtReparentTo(parent) return None ###### set pos and hpr functions ####### diff --git a/direct/src/distributed/DistributedObject.py b/direct/src/distributed/DistributedObject.py index a8a08e9af3..f795d59bf8 100644 --- a/direct/src/distributed/DistributedObject.py +++ b/direct/src/distributed/DistributedObject.py @@ -34,6 +34,12 @@ class DistributedObject(PandaObject): # This flag tells whether a delete has been requested on this # object. 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 + return None #def __del__(self): @@ -118,7 +124,7 @@ class DistributedObject(PandaObject): """disable(self) Inheritors should redefine this to take appropriate action on disable """ - pass + self.disabled = 1 def delete(self): """delete(self) @@ -135,7 +141,7 @@ class DistributedObject(PandaObject): """generate(self) Inheritors should redefine this to take appropriate action on generate """ - pass + self.disabled = 0 def generateInit(self): """generateInit(self) @@ -176,6 +182,13 @@ class DistributedObject(PandaObject): def uniqueName(self, idString): return (idString + "-" + str(self.getDoId())) + + def isLocal(self): + # This returns true if the distributed object is "local," + # which means the client created it instead of the AI, and it + # gets some other special handling. Normally, only the local + # avatar class overrides this to return true. + return 0 diff --git a/direct/src/distributed/DistributedSmoothNode.py b/direct/src/distributed/DistributedSmoothNode.py index 7f6ff779a6..cf9f8f7a98 100644 --- a/direct/src/distributed/DistributedSmoothNode.py +++ b/direct/src/distributed/DistributedSmoothNode.py @@ -327,8 +327,3 @@ class DistributedSmoothNode(DistributedNode.DistributedNode): self.reloadPosition() else: NodePath.wrtReparentTo(self, parent) - - - def isLocal(self): - # Local toon will override this to return true - return 0