From 25dd2c7217391f9301fe7b27f8b8cdfab867b275 Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Tue, 15 Mar 2005 23:37:44 +0000 Subject: [PATCH] improved setLocation handling --- direct/src/distributed/ClientRepository.py | 2 - direct/src/distributed/DistributedObject.py | 9 ++- direct/src/distributed/DistributedObjectAI.py | 67 ++++++++++--------- direct/src/leveleditor/LevelEditor.py | 13 +++- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index 1077e5cd7b..76a1368278 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -789,8 +789,6 @@ class ClientRepository(ConnectionRepository.ConnectionRepository): datagram.addUint32(zoneId) self.send(datagram) - - else: def sendSetZoneMsg(self, zoneId, visibleZoneList=None): datagram = PyDatagram() diff --git a/direct/src/distributed/DistributedObject.py b/direct/src/distributed/DistributedObject.py index 29ed2df3f9..32920e6b7f 100644 --- a/direct/src/distributed/DistributedObject.py +++ b/direct/src/distributed/DistributedObject.py @@ -341,13 +341,18 @@ class DistributedObject(PandaObject): def addInterest(self, zoneId, note="", event=None): self.cr.addInterest(self.getDoId(), zoneId, note, event) + def b_setLocation(self, parentId, zoneId): + self.d_setLocation(parentId, zoneId) + self.setLocation(parentId, zoneId) + + def d_setLocation(self, parentId, zoneId): + self.cr.sendSetLocation(self.doId, parentId, zoneId) + def setLocation(self, parentId, zoneId): self.notify.info("setLocation: %s parentId: %s zoneId: %s" % (self.doId, parentId, zoneId)) # The store must run first so we know the old location #self.cr.storeObjectLocation(self.doId, parentId, zoneId) self.__location = (parentId, zoneId) - #if parentId != None and zoneId != None: - # base.cr.sendSetLocation(self.doId, parentId, zoneId) def getLocation(self): return self.__location diff --git a/direct/src/distributed/DistributedObjectAI.py b/direct/src/distributed/DistributedObjectAI.py index cf40ffc7b4..c05f037150 100644 --- a/direct/src/distributed/DistributedObjectAI.py +++ b/direct/src/distributed/DistributedObjectAI.py @@ -142,24 +142,48 @@ class DistributedObjectAI(DirectObject.DirectObject): def addInterest(self, zoneId, note="", event=None): self.air.addInterest(self.getDoId(), zoneId, note, event) + def b_setLocation(self, parentId, zoneId): + self.d_setLocation(parentId, zoneId) + self.setLocation(parentId, zoneId) + + def d_setLocation(self, parentId, zoneId): + self.air.sendSetLocation(self, parentId, zoneId) + def setLocation(self, parentId, zoneId): - if self.__location: - # Make sure our parentId and/or zoneId are actually changing before doing any work - oldParentId, oldZoneId = self.__location - if oldParentId != parentId or oldZoneId != zoneId: - # The store must run first so we know the old location - self.air.sendSetLocation(self, parentId, zoneId) - self.__location = (parentId, zoneId) + oldParentId = self.parentId + oldZoneId = self.zoneId + self.zoneId = zoneId + self.parentId = parentId + self.air.changeDOZoneInTables(self, zoneId, oldZoneId) + messenger.send(self.getZoneChangeEvent(), [zoneId, oldZoneId]) + # if we are not going into the quiet zone, send a 'logical' zone + # change message + if zoneId != DistributedObjectAI.QuietZone: + lastLogicalZone = oldZoneId + if oldZoneId == DistributedObjectAI.QuietZone: + lastLogicalZone = self.lastNonQuietZone + self.handleLogicalZoneChange(zoneId, lastLogicalZone) + self.lastNonQuietZone = zoneId + # self.air.storeObjectLocation(self.doId, parentId, zoneId) + self.__location = (parentId, zoneId) def getLocation(self): return self.__location - if 0: # this is untested: - def setLocation(self, parentId, zoneId): - # The store must run first so we know the old location - self.air.storeObjectLocation(self.doId, parentId, zoneId) - self.__location = (parentId, zoneId) - + else: + # NON OTP + def handleZoneChange(self, newZoneId, oldZoneId): + self.zoneId = newZoneId + self.air.changeDOZoneInTables(self, newZoneId, oldZoneId) + messenger.send(self.getZoneChangeEvent(), [newZoneId, oldZoneId]) + # if we are not going into the quiet zone, send a 'logical' zone change + # message + if newZoneId != DistributedObjectAI.QuietZone: + lastLogicalZone = oldZoneId + if oldZoneId == DistributedObjectAI.QuietZone: + lastLogicalZone = self.lastNonQuietZone + self.handleLogicalZoneChange(newZoneId, lastLogicalZone) + self.lastNonQuietZone = newZoneId def updateRequiredFields(self, dclass, di): dclass.receiveUpdateBroadcastRequired(self, di) @@ -198,23 +222,6 @@ class DistributedObjectAI(DirectObject.DirectObject): # does not include the quiet zone. return 'DOLogicalChangeZone-%s' % self.doId - def handleZoneChange(self, newParentId, newZoneId, oldParentId, oldZoneId): - if wantOtpServer: - assert oldParentId == self.parentId - ##assert oldZoneId == self.zoneId - self.parentId = newParentId - self.zoneId = newZoneId - self.air.changeDOZoneInTables(self, newZoneId, oldZoneId) - messenger.send(self.getZoneChangeEvent(), [newZoneId, oldZoneId]) - # if we are not going into the quiet zone, send a 'logical' zone change - # message - if newZoneId != DistributedObjectAI.QuietZone: - lastLogicalZone = oldZoneId - if oldZoneId == DistributedObjectAI.QuietZone: - lastLogicalZone = self.lastNonQuietZone - self.handleLogicalZoneChange(newZoneId, lastLogicalZone) - self.lastNonQuietZone = newZoneId - def handleLogicalZoneChange(self, newZoneId, oldZoneId): """this function gets called as if we never go through the quiet zone. Note that it is called once you reach the newZone, diff --git a/direct/src/leveleditor/LevelEditor.py b/direct/src/leveleditor/LevelEditor.py index 8a6c453e8e..d681773b87 100644 --- a/direct/src/leveleditor/LevelEditor.py +++ b/direct/src/leveleditor/LevelEditor.py @@ -19,6 +19,9 @@ import whrandom from direct.task import Task import __builtin__ +# Force direct and tk to be on +base.startDirect(fWantDirect = 1, fWantTk = 1) + visualizeZones = base.config.GetBool("visualize-zones", 0) dnaDirectory = Filename.expandFrom(base.config.GetString("dna-directory", "$TTMODELS/src/dna")) fUseCVS = base.config.GetBool("level-editor-use-cvs", 1) @@ -217,9 +220,10 @@ except NameError: __builtin__.DNASTORE = DNASTORE = DNAStorage() # Load the generic storage files + loadDNAFile(DNASTORE, 'dna/storage.dna', CSDefault, 1) loadDNAFile(DNASTORE, 'phase_4/dna/storage.dna', CSDefault, 1) loadDNAFile(DNASTORE, 'phase_5/dna/storage_town.dna', CSDefault, 1) - loadDNAFile(DNASTORE, 'phase_5.5/dna/storage_estate.dna', CSDefault, 1) + # loadDNAFile(DNASTORE, 'phase_5.5/dna/storage_estate.dna', CSDefault, 1) # loadDNAFile(DNASTORE, 'phase_5.5/dna/storage_house_interior.dna', CSDefault, 1) # Load all the neighborhood specific storage files if 'TT' in hoods: @@ -749,7 +753,7 @@ class LevelEditor(NodePath, PandaObject): t = direct.camera.lerpPosHpr(pos, hpr, 1.0, blendType = 'easeInOut', task = 'manipulateCamera') # Note, if this dies an unatural death, this could screw things up - t.uponDeath = self.switchToDriveMode + # t.uponDeath = self.switchToDriveMode def switchToDriveMode(self,state): """ Disable direct camera manipulation and enable player drive mode """ @@ -4104,7 +4108,10 @@ class LevelStyleManager: # Create top level node for new menu newMenu = hidden.attachNewNode(dnaType + 'Menu') # Compute angle per item - angle = deg2Rad(360.0/numItems) + if numItems == 0: + angle = 0.0 + else: + angle = deg2Rad(360.0/numItems) aspectRatio = direct.dr.getWidth()/float(direct.dr.getHeight()) # Add items for i in range (numItems):