diff --git a/direct/src/distributed/AstronDatabaseInterface.py b/direct/src/distributed/AstronDatabaseInterface.py index e5bdbc5626..0c47d21173 100644 --- a/direct/src/distributed/AstronDatabaseInterface.py +++ b/direct/src/distributed/AstronDatabaseInterface.py @@ -32,7 +32,7 @@ class AstronDatabaseInterface: """ # Save the callback: - ctx = self.air.contextAllocator.allocate() + ctx = self.air.getContext() self._callbacks[ctx] = callback # Pack up/count valid fields. @@ -72,7 +72,6 @@ class AstronDatabaseInterface: self._callbacks[ctx](doId) del self._callbacks[ctx] - self.air.contextAllocator.free(ctx) def queryObject(self, databaseId, doId, callback): """ @@ -84,7 +83,7 @@ class AstronDatabaseInterface: """ # Save the callback: - ctx = self.air.contextAllocator.allocate() + ctx = self.air.getContext() self._callbacks[ctx] = callback # Generate and send the datagram: @@ -138,7 +137,6 @@ class AstronDatabaseInterface: finally: del self._callbacks[ctx] - self.air.contextAllocator.free(ctx) def updateObject(self, databaseId, doId, dclass, newFields, oldFields=None, callback=None): """ @@ -192,7 +190,7 @@ class AstronDatabaseInterface: # Generate and send the datagram: dg = PyDatagram() if oldFields is not None: - ctx = self.air.contextAllocator.allocate() + ctx = self.air.getContext() self._callbacks[ctx] = callback if fieldCount == 1: dg.addServerHeader(databaseId, self.air.ourChannel, @@ -260,7 +258,6 @@ class AstronDatabaseInterface: finally: del self._callbacks[ctx] - self.air.contextAllocator.free(ctx) def handleDatagram(self, msgType, di): if msgType == DBSERVER_CREATE_OBJECT_RESP: diff --git a/direct/src/distributed/AstronInternalRepository.py b/direct/src/distributed/AstronInternalRepository.py index f05f12efb0..311ec3e4d5 100644 --- a/direct/src/distributed/AstronInternalRepository.py +++ b/direct/src/distributed/AstronInternalRepository.py @@ -43,7 +43,7 @@ class AstronInternalRepository(ConnectionRepository): self.channelAllocator = UniqueIdAllocator(baseChannel, baseChannel+maxChannels-1) self._registeredChannels = set() - self.contextAllocator = UniqueIdAllocator(0, 100) + self.__contextCounter = 0 self.dbInterface = AstronDatabaseInterface(self) @@ -61,6 +61,10 @@ class AstronInternalRepository(ConnectionRepository): self.readDCFile(dcFileNames) + def getContext(self): + self.__contextCounter = (self.__contextCounter + 1) & 0xFFFFFFFF + return self.__contextCounter + def allocateChannel(self): """ Allocate an unused channel out of this AIR's configured channel space.