diff --git a/direct/src/actor/DistributedActor.py b/direct/src/actor/DistributedActor.py index bf3b2867c0..47c4556304 100644 --- a/direct/src/actor/DistributedActor.py +++ b/direct/src/actor/DistributedActor.py @@ -12,6 +12,11 @@ class DistributedActor(DistributedNode.DistributedNode, Actor.Actor): except: self.DistributedActor_initialized = 1 DistributedNode.DistributedNode.__init__(self, cr) + + # Since actors are probably fairly heavyweight, we'd + # rather cache them than delete them if possible. + self.setCacheable(1) + return None diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index 6148b665a3..da4665e579 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -227,8 +227,14 @@ class ClientRepository(DirectObject.DirectObject): del(self.doId2do[doId]) del(self.doId2cdc[doId]) assert(len(self.doId2do) == len(self.doId2cdc)) - # cache the object - self.cache.cache(distObj) + + # Only cache the object if it is a "cacheable" type + # object; this way we don't clutter up the caches with + # trivial objects that don't benefit from caching. + if distObj.getCacheable(): + self.cache.cache(distObj) + else: + distObj.deleteOrDelay() else: ClientRepository.notify.warning("Disable failed. DistObj " + str(doId) + diff --git a/direct/src/distributed/DistributedObject.py b/direct/src/distributed/DistributedObject.py index c2dfe0b07f..4ae2770d36 100644 --- a/direct/src/distributed/DistributedObject.py +++ b/direct/src/distributed/DistributedObject.py @@ -10,11 +10,21 @@ class DistributedObject(PandaObject): except: self.DistributedObject_initialized = 1 self.cr = cr - # A few objects will set neverDisable to 1... Examples are localToon, and anything - # that lives in the UberZone. This keeps them from being disabled when you change - # zones, even to the quiet zone. + + # A few objects will set neverDisable to 1... Examples are + # localToon, and anything that lives in the UberZone. This + # keeps them from being disabled when you change zones, + # even to the quiet zone. self.setNeverDisable(0) + # Most DistributedObjects are simple and require no real + # effort to load. Some, particularly actors, may take + # some significant time to load; these we can optimize by + # caching them when they go away instead of necessarily + # deleting them. The object should set cacheable to 1 if + # it needs to be optimized in this way. + self.setCacheable(0) + # This flag tells whether the object can be deleted right away, # or not. self.delayDeleteFlag = 0 @@ -31,6 +41,14 @@ class DistributedObject(PandaObject): def getNeverDisable(self): return self.neverDisable + def setCacheable(self, bool): + assert((bool == 1) or (bool == 0)) + self.cacheable = bool + return None + + def getCacheable(self): + return self.cacheable + def deleteOrDelay(self): if self.delayDeleteFlag: self.deleteImminent = 1