improved setLocation handling

This commit is contained in:
Joe Shochet 2005-03-15 23:37:44 +00:00
parent 7e8448cff2
commit 25dd2c7217
4 changed files with 54 additions and 37 deletions

View File

@ -789,8 +789,6 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
datagram.addUint32(zoneId) datagram.addUint32(zoneId)
self.send(datagram) self.send(datagram)
else: else:
def sendSetZoneMsg(self, zoneId, visibleZoneList=None): def sendSetZoneMsg(self, zoneId, visibleZoneList=None):
datagram = PyDatagram() datagram = PyDatagram()

View File

@ -341,13 +341,18 @@ class DistributedObject(PandaObject):
def addInterest(self, zoneId, note="", event=None): def addInterest(self, zoneId, note="", event=None):
self.cr.addInterest(self.getDoId(), zoneId, note, event) 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): def setLocation(self, parentId, zoneId):
self.notify.info("setLocation: %s parentId: %s zoneId: %s" % (self.doId, 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 # The store must run first so we know the old location
#self.cr.storeObjectLocation(self.doId, parentId, zoneId) #self.cr.storeObjectLocation(self.doId, parentId, zoneId)
self.__location = (parentId, zoneId) self.__location = (parentId, zoneId)
#if parentId != None and zoneId != None:
# base.cr.sendSetLocation(self.doId, parentId, zoneId)
def getLocation(self): def getLocation(self):
return self.__location return self.__location

View File

@ -142,24 +142,48 @@ class DistributedObjectAI(DirectObject.DirectObject):
def addInterest(self, zoneId, note="", event=None): def addInterest(self, zoneId, note="", event=None):
self.air.addInterest(self.getDoId(), zoneId, note, event) 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): def setLocation(self, parentId, zoneId):
if self.__location: oldParentId = self.parentId
# Make sure our parentId and/or zoneId are actually changing before doing any work oldZoneId = self.zoneId
oldParentId, oldZoneId = self.__location self.zoneId = zoneId
if oldParentId != parentId or oldZoneId != zoneId: self.parentId = parentId
# The store must run first so we know the old location self.air.changeDOZoneInTables(self, zoneId, oldZoneId)
self.air.sendSetLocation(self, parentId, zoneId) messenger.send(self.getZoneChangeEvent(), [zoneId, oldZoneId])
self.__location = (parentId, zoneId) # 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): def getLocation(self):
return self.__location return self.__location
if 0: # this is untested: else:
def setLocation(self, parentId, zoneId): # NON OTP
# The store must run first so we know the old location def handleZoneChange(self, newZoneId, oldZoneId):
self.air.storeObjectLocation(self.doId, parentId, zoneId) self.zoneId = newZoneId
self.__location = (parentId, zoneId) 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): def updateRequiredFields(self, dclass, di):
dclass.receiveUpdateBroadcastRequired(self, di) dclass.receiveUpdateBroadcastRequired(self, di)
@ -198,23 +222,6 @@ class DistributedObjectAI(DirectObject.DirectObject):
# does not include the quiet zone. # does not include the quiet zone.
return 'DOLogicalChangeZone-%s' % self.doId 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): def handleLogicalZoneChange(self, newZoneId, oldZoneId):
"""this function gets called as if we never go through the """this function gets called as if we never go through the
quiet zone. Note that it is called once you reach the newZone, quiet zone. Note that it is called once you reach the newZone,

View File

@ -19,6 +19,9 @@ import whrandom
from direct.task import Task from direct.task import Task
import __builtin__ import __builtin__
# Force direct and tk to be on
base.startDirect(fWantDirect = 1, fWantTk = 1)
visualizeZones = base.config.GetBool("visualize-zones", 0) visualizeZones = base.config.GetBool("visualize-zones", 0)
dnaDirectory = Filename.expandFrom(base.config.GetString("dna-directory", "$TTMODELS/src/dna")) dnaDirectory = Filename.expandFrom(base.config.GetString("dna-directory", "$TTMODELS/src/dna"))
fUseCVS = base.config.GetBool("level-editor-use-cvs", 1) fUseCVS = base.config.GetBool("level-editor-use-cvs", 1)
@ -217,9 +220,10 @@ except NameError:
__builtin__.DNASTORE = DNASTORE = DNAStorage() __builtin__.DNASTORE = DNASTORE = DNAStorage()
# Load the generic storage files # Load the generic storage files
loadDNAFile(DNASTORE, 'dna/storage.dna', CSDefault, 1)
loadDNAFile(DNASTORE, 'phase_4/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/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) # loadDNAFile(DNASTORE, 'phase_5.5/dna/storage_house_interior.dna', CSDefault, 1)
# Load all the neighborhood specific storage files # Load all the neighborhood specific storage files
if 'TT' in hoods: if 'TT' in hoods:
@ -749,7 +753,7 @@ class LevelEditor(NodePath, PandaObject):
t = direct.camera.lerpPosHpr(pos, hpr, 1.0, blendType = 'easeInOut', t = direct.camera.lerpPosHpr(pos, hpr, 1.0, blendType = 'easeInOut',
task = 'manipulateCamera') task = 'manipulateCamera')
# Note, if this dies an unatural death, this could screw things up # Note, if this dies an unatural death, this could screw things up
t.uponDeath = self.switchToDriveMode # t.uponDeath = self.switchToDriveMode
def switchToDriveMode(self,state): def switchToDriveMode(self,state):
""" Disable direct camera manipulation and enable player drive mode """ """ Disable direct camera manipulation and enable player drive mode """
@ -4104,7 +4108,10 @@ class LevelStyleManager:
# Create top level node for new menu # Create top level node for new menu
newMenu = hidden.attachNewNode(dnaType + 'Menu') newMenu = hidden.attachNewNode(dnaType + 'Menu')
# Compute angle per item # 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()) aspectRatio = direct.dr.getWidth()/float(direct.dr.getHeight())
# Add items # Add items
for i in range (numItems): for i in range (numItems):