From c736210029134ac80c1f41aa0c92a8892615a734 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 29 Jun 2009 21:03:43 +0000 Subject: [PATCH] support reserveDoId --- direct/src/distributed/ClientRepository.py | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index 716bb36bc0..367d0550cf 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -117,6 +117,14 @@ class ClientRepository(ClientRepositoryBase): return self.doIdAllocator.allocate() + def reserveDoId(self, doId): + """ Removes the indicate doId from the available pool, as if + it had been explicitly allocated. You may pass it to + freeDoId() later if you wish. """ + + self.doIdAllocator.initialReserveId(doId) + return doId + def freeDoId(self, doId): """ Returns a doId back into the free pool for re-use. """ @@ -124,7 +132,8 @@ class ClientRepository(ClientRepositoryBase): self.doIdAllocator.free(doId) def createDistributedObject(self, className = None, distObj = None, - zoneId = 0, optionalFields = None): + zoneId = 0, optionalFields = None, + doId = None): """ To create a DistributedObject, you must pass in either the name of the object's class, or an already-created instance of @@ -148,14 +157,24 @@ class ClientRepository(ClientRepositoryBase): broadcast to all of the other clients; if you wish to broadcast additional field values at this time as well, pass a list of field names in the optionalFields parameters. - """ + + Normally, doId is None, to mean allocate a new doId for the + object. If you wish to use a particular doId, pass it in + here. It will be reserved from the allocation pool using + self.reserveDoId(). You are responsible for ensuring this + doId falls within the client's allowable doId range and has + not already been assigned to another object. """ if not className: if not distObj: self.notify.error("Must specify either a className or a distObj.") className = distObj.__class__.__name__ - doId = self.allocateDoId() + if doId is None: + doId = self.allocateDoId() + else: + self.reserveDoId(doId) + dclass = self.dclassesByName.get(className) if not dclass: self.notify.error("Unknown distributed class: %s" % (distObj.__class__))