Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
11cbc3ebf8

+ 5 - 0
direct/src/actor/DistributedActor.py

@@ -12,6 +12,11 @@ class DistributedActor(DistributedNode.DistributedNode, Actor.Actor):
         except:
         except:
             self.DistributedActor_initialized = 1
             self.DistributedActor_initialized = 1
             DistributedNode.DistributedNode.__init__(self, cr)
             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
         return None
 
 
         
         

+ 8 - 2
direct/src/distributed/ClientRepository.py

@@ -227,8 +227,14 @@ class ClientRepository(DirectObject.DirectObject):
             del(self.doId2do[doId])
             del(self.doId2do[doId])
             del(self.doId2cdc[doId])
             del(self.doId2cdc[doId])
             assert(len(self.doId2do) == len(self.doId2cdc))
             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:
         else:
             ClientRepository.notify.warning("Disable failed. DistObj " +
             ClientRepository.notify.warning("Disable failed. DistObj " +
                                             str(doId) +
                                             str(doId) +

+ 21 - 3
direct/src/distributed/DistributedObject.py

@@ -10,11 +10,21 @@ class DistributedObject(PandaObject):
         except:
         except:
             self.DistributedObject_initialized = 1
             self.DistributedObject_initialized = 1
             self.cr = cr
             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)
             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,
             # This flag tells whether the object can be deleted right away,
             # or not.
             # or not.
             self.delayDeleteFlag = 0
             self.delayDeleteFlag = 0
@@ -31,6 +41,14 @@ class DistributedObject(PandaObject):
     def getNeverDisable(self):
     def getNeverDisable(self):
         return self.neverDisable
         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):
     def deleteOrDelay(self):
         if self.delayDeleteFlag:
         if self.delayDeleteFlag:
             self.deleteImminent = 1
             self.deleteImminent = 1