소스 검색

visibility based off of camera position

Darren Ranalli 22 년 전
부모
커밋
832a96a639
1개의 변경된 파일30개의 추가작업 그리고 15개의 파일을 삭제
  1. 30 15
      direct/src/level/DistributedLevel.py

+ 30 - 15
direct/src/level/DistributedLevel.py

@@ -82,6 +82,11 @@ class DistributedLevel(DistributedObject.DistributedObject,
         # add the UberZone
         # add the UberZone
         self.zoneNum2Node[0] = self.geom
         self.zoneNum2Node[0] = self.geom
 
 
+        self.zoneNums = self.zoneNum2Node.keys()
+        self.zoneNums.sort()
+        self.notify.debug('zones: %s' % self.zoneNums)
+        assert sameElements(self.zoneNums, self.spec['zones'].keys() + [0])
+
         # fix up the floor collisions for walkable zones
         # fix up the floor collisions for walkable zones
         for zoneNum, zoneNode in self.zoneNum2Node.items():
         for zoneNum, zoneNode in self.zoneNum2Node.items():
             # skip the UberZone
             # skip the UberZone
@@ -89,28 +94,34 @@ class DistributedLevel(DistributedObject.DistributedObject,
                 continue
                 continue
 
 
             # if this is a walkable zone, fix up the model
             # if this is a walkable zone, fix up the model
-            floorColl = zoneNode.find('**/*FloorCollision*')
-            if not floorColl.isEmpty():
-                # rename the floor collision node, and make sure no other
+            floorColls = zoneNode.findAllMatches('**/+CollisionNode').asList()
+            if len(floorColls) > 0:
+                # rename the floor collision nodes, and make sure no other
                 # nodes under the ZoneNode have that name
                 # nodes under the ZoneNode have that name
-                floorCollName = 'Zone%sFloor' % zoneNum
+                floorCollName = '%s' % zoneNum
                 others = zoneNode.findAllMatches(
                 others = zoneNode.findAllMatches(
                     '**/%s' % floorCollName).asList()
                     '**/%s' % floorCollName).asList()
                 for other in others:
                 for other in others:
                     other.setName('%s_renamed' % floorCollName)
                     other.setName('%s_renamed' % floorCollName)
-                floorColl.setName(floorCollName)
+                for floorColl in floorColls:
+                    floorColl.setName(floorCollName)
 
 
                 # listen for zone enter events from floor collisions
                 # listen for zone enter events from floor collisions
                 def handleZoneEnter(collisionEntry,
                 def handleZoneEnter(collisionEntry,
                                     self=self, zoneNum=zoneNum):
                                     self=self, zoneNum=zoneNum):
                     # eat the collisionEntry
                     # eat the collisionEntry
-                    self.enterZone(zoneNum)
+                    self.toonEnterZone(zoneNum)
                 self.accept('enter%s' % floorCollName, handleZoneEnter)
                 self.accept('enter%s' % floorCollName, handleZoneEnter)
 
 
-        self.zoneNums = self.zoneNum2Node.keys()
-        self.zoneNums.sort()
-        self.notify.debug('zones: %s' % self.zoneNums)
-        assert sameElements(self.zoneNums, self.spec['zones'].keys() + [0])
+        # listen for camera-ray/floor collision events
+        def handleCameraRayFloorCollision(collEntry, self=self):
+            name = collEntry.getIntoNode().getName()
+            try:
+                zoneNum = int(name)
+                self.camEnterZone(zoneNum)
+            except:
+                self.notify.warning('Invalid floor collision node: %s' % name)
+        self.accept('on-floor', handleCameraRayFloorCollision)
 
 
         # hack in another doorway
         # hack in another doorway
         dw = self.geom.attachNewNode('Doorway27')
         dw = self.geom.attachNewNode('Doorway27')
@@ -230,24 +241,28 @@ class DistributedLevel(DistributedObject.DistributedObject,
         # we have not entered any zone yet
         # we have not entered any zone yet
         self.curZoneNum = None
         self.curZoneNum = None
 
 
-        # TODO: make this data-driven
-        firstZone = 1
-        self.enterZone(firstZone)
-
         # if no viz, listen to all the zones
         # if no viz, listen to all the zones
         if not DistributedLevel.WantVisibility:
         if not DistributedLevel.WantVisibility:
             zones = list(self.zoneNums)
             zones = list(self.zoneNums)
             zones.remove(0)
             zones.remove(0)
             self.sendSetZone(0, zones)
             self.sendSetZone(0, zones)
 
 
+    def toonEnterZone(self, zoneNum):
+        self.notify.debug('toonEnterZone%s' % zoneNum)
+
+    def camEnterZone(self, zoneNum):
+        self.notify.debug('camEnterZone%s' % zoneNum)
+        self.enterZone(zoneNum)
+
     def enterZone(self, zoneNum):
     def enterZone(self, zoneNum):
+        self.notify.debug("switching to zone %s" % zoneNum)
+
         if not DistributedLevel.WantVisibility:
         if not DistributedLevel.WantVisibility:
             return
             return
         
         
         if zoneNum == self.curZoneNum:
         if zoneNum == self.curZoneNum:
             return
             return
         
         
-        print "enterZone %s" % zoneNum
         zoneSpec = self.spec['zones'][zoneNum]
         zoneSpec = self.spec['zones'][zoneNum]
         # use dicts to efficiently ensure that there are no duplicates
         # use dicts to efficiently ensure that there are no duplicates
         visibleZoneNums = list2dict([0, zoneNum])
         visibleZoneNums = list2dict([0, zoneNum])