debugging statements and cleanup to help track down disable problems

This commit is contained in:
David Rose 2002-09-14 17:42:38 +00:00
parent b7380ee5e9
commit 5c328305cf
4 changed files with 33 additions and 12 deletions

View File

@ -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

View File

@ -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 #######

View File

@ -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

View File

@ -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