2
0
Dave Schuyler 22 жил өмнө
parent
commit
71a1623c11

+ 43 - 2
direct/src/showbase/ControlManager.py

@@ -5,6 +5,7 @@ from ShowBaseGlobal import *
 #from IntervalGlobal import *
 #from IntervalGlobal import *
 
 
 import Avatar
 import Avatar
+import DevWalker
 import DirectNotifyGlobal
 import DirectNotifyGlobal
 import GhostWalker
 import GhostWalker
 import GravityWalker
 import GravityWalker
@@ -26,6 +27,7 @@ class ControlManager:
                     gravity = -32.1740 * 2.0)
                     gravity = -32.1740 * 2.0)
         #self.swimControls=NonPhysicsWalker.NonPhysicsWalker()
         #self.swimControls=NonPhysicsWalker.NonPhysicsWalker()
         self.ghostControls=GhostWalker.GhostWalker()
         self.ghostControls=GhostWalker.GhostWalker()
+        self.devControls=DevWalker.DevWalker()
         if self.wantAvatarPhysics:
         if self.wantAvatarPhysics:
             self.walkControls=GravityWalker.GravityWalker(
             self.walkControls=GravityWalker.GravityWalker(
                     gravity = -32.1740 * 2.0) # * 2.0 is a hack;
                     gravity = -32.1740 * 2.0) # * 2.0 is a hack;
@@ -61,6 +63,8 @@ class ControlManager:
         inputState.watch("jump", "alt-control", "alt-control-up")
         inputState.watch("jump", "alt-control", "alt-control-up")
         inputState.watch("jump", "shift-control", "shift-control-up")
         inputState.watch("jump", "shift-control", "shift-control-up")
         
         
+        inputState.watch("shift", "shift", "shift-up")
+        
         # FYI, ghost mode uses jump for slide.
         # FYI, ghost mode uses jump for slide.
         inputState.watch("slide", "slide-is-disabled", "slide-is-disabled")
         inputState.watch("slide", "slide-is-disabled", "slide-is-disabled")
         
         
@@ -76,6 +80,7 @@ class ControlManager:
         #inputState.watch("slideRight", "shift-arrow_right", "shift-arrow_right-up")
         #inputState.watch("slideRight", "shift-arrow_right", "shift-arrow_right-up")
         inputState.watch("slideRight", "slide-is-disabled", "slide-is-disabled")
         inputState.watch("slideRight", "slide-is-disabled", "slide-is-disabled")
 
 
+
     def add(self, controls, name="basic"):
     def add(self, controls, name="basic"):
         controls = self.controls.get(name)
         controls = self.controls.get(name)
         if controls is not None:
         if controls is not None:
@@ -93,7 +98,21 @@ class ControlManager:
                 self.currentControls.setCollisionsActive(1)
                 self.currentControls.setCollisionsActive(1)
         else:
         else:
             print "Unkown controls:", name
             print "Unkown controls:", name
+    
+    def setSpeeds_new(self, toonForwardSpeed, toonJumpForce,
+            toonReverseSpeed, toonRotateSpeed):
+        assert(self.debugPrint(
+            "setSpeeds(toonForwardSpeed=%s, toonJumpForce=%s, toonReverseSpeed=%s, toonRotateSpeed=%s)"%(
+            toonForwardSpeed, toonJumpForce,
+            toonReverseSpeed, toonRotateSpeed)))
+        for controls in self.controls.values():
+            controls.setWalkSpeed(
+                toonForwardSpeed,
+                toonJumpForce,
+                toonReverseSpeed,
+                toonRotateSpeed)
 
 
+
     def useSwimControls(self):
     def useSwimControls(self):
         assert(self.debugPrint("useSwimControls()"))
         assert(self.debugPrint("useSwimControls()"))
         if self.currentControls is not self.swimControls:
         if self.currentControls is not self.swimControls:
@@ -124,6 +143,16 @@ class ControlManager:
             if self.isEnabled:
             if self.isEnabled:
                 self.currentControls.enableAvatarControls()
                 self.currentControls.enableAvatarControls()
 
 
+    def useDevControls(self):
+        assert(self.debugPrint("useDevControls()"))
+        if self.currentControls is not self.devControls:
+            self.currentControls.disableAvatarControls()
+            self.currentControls.setCollisionsActive(0)
+            self.devControls.setCollisionsActive(1)
+            self.currentControls = self.devControls
+            if self.isEnabled:
+                self.currentControls.enableAvatarControls()
+
     def delete(self):
     def delete(self):
         self.disable()
         self.disable()
         #self.monitorTask.remove()
         #self.monitorTask.remove()
@@ -149,12 +178,17 @@ class ControlManager:
             toonJumpForce,
             toonJumpForce,
             toonReverseSpeed,
             toonReverseSpeed,
             toonRotateSpeed)
             toonRotateSpeed)
+        self.devControls.setWalkSpeed(
+            toonForwardSpeed,
+            toonJumpForce,
+            toonReverseSpeed,
+            toonRotateSpeed)
     
     
     def getSpeeds(self):
     def getSpeeds(self):
         return self.currentControls.getSpeeds()
         return self.currentControls.getSpeeds()
     
     
     def initializeCollisions(self, cTrav,
     def initializeCollisions(self, cTrav,
-            wallBitmask, floorBitmask, ghostBitMask, avatarRadius, floorOffset):
+            wallBitmask, floorBitmask, ghostBitmask, avatarRadius, floorOffset):
         assert(self.debugPrint("initializeCollisions()"))
         assert(self.debugPrint("initializeCollisions()"))
         
         
         self.walkControls.initializeCollisions(cTrav, self.avatar,
         self.walkControls.initializeCollisions(cTrav, self.avatar,
@@ -170,10 +204,16 @@ class ControlManager:
         self.swimControls.setCollisionsActive(0)
         self.swimControls.setCollisionsActive(0)
         
         
         self.ghostControls.initializeCollisions(cTrav, self.avatar,
         self.ghostControls.initializeCollisions(cTrav, self.avatar,
-                ghostBitMask, floorBitmask, avatarRadius, floorOffset)
+                ghostBitmask, floorBitmask, avatarRadius, floorOffset)
         self.ghostControls.setAirborneHeightFunc(self.avatar.getAirborneHeight)
         self.ghostControls.setAirborneHeightFunc(self.avatar.getAirborneHeight)
         self.ghostControls.disableAvatarControls()
         self.ghostControls.disableAvatarControls()
         self.ghostControls.setCollisionsActive(0)
         self.ghostControls.setCollisionsActive(0)
+        
+        self.devControls.initializeCollisions(cTrav, self.avatar,
+                wallBitmask, floorBitmask, avatarRadius, floorOffset)
+        self.devControls.setAirborneHeightFunc(self.avatar.getAirborneHeight)
+        self.devControls.disableAvatarControls()
+        self.devControls.setCollisionsActive(0)
 
 
         self.walkControls.setCollisionsActive(1)
         self.walkControls.setCollisionsActive(1)
         self.walkControls.enableAvatarControls()
         self.walkControls.enableAvatarControls()
@@ -183,6 +223,7 @@ class ControlManager:
         self.walkControls.deleteCollisions()
         self.walkControls.deleteCollisions()
         self.swimControls.deleteCollisions()
         self.swimControls.deleteCollisions()
         self.ghostControls.deleteCollisions()
         self.ghostControls.deleteCollisions()
+        self.devControls.deleteCollisions()
 
 
     def collisionsOn(self):
     def collisionsOn(self):
         assert(self.debugPrint("collisionsOn()"))
         assert(self.debugPrint("collisionsOn()"))

+ 3 - 2
direct/src/showbase/DevWalker.py

@@ -135,8 +135,9 @@ class DevWalker(DirectObject.DirectObject):
         """
         """
         assert(self.debugPrint("disableAvatarControls"))
         assert(self.debugPrint("disableAvatarControls"))
         print id(self), "DW.disableAvatarControls()"
         print id(self), "DW.disableAvatarControls()"
-        self.task.remove()
-        self.task = None
+        if self.task:
+            self.task.remove()
+            self.task = None
     
     
     if __debug__:
     if __debug__:
         def debugPrint(self, message):
         def debugPrint(self, message):

+ 4 - 0
direct/src/showbase/GravityWalker.py

@@ -416,6 +416,10 @@ class GravityWalker(DirectObject.DirectObject):
         if __debug__:
         if __debug__:
             if self.wantDebugIndicator:
             if self.wantDebugIndicator:
                 onScreenDebug.add("velocity", velocity.pPrintValues())
                 onScreenDebug.add("velocity", velocity.pPrintValues())
+    
+    def reset(self):
+        assert(self.debugPrint("reset()"))
+        self.lifter.setVelocity(0.0)
 
 
     def enableAvatarControls(self):
     def enableAvatarControls(self):
         """
         """

+ 1 - 1
direct/src/showbase/InputState.py

@@ -73,7 +73,7 @@ class InputState(DirectObject.DirectObject):
     def set(self, name, isSet):
     def set(self, name, isSet):
         assert(self.debugPrint("set(name=%s, isSet=%s)"%(name, isSet)))
         assert(self.debugPrint("set(name=%s, isSet=%s)"%(name, isSet)))
         self.state[name] = isSet
         self.state[name] = isSet
-        messenger.send(name, [isSet])
+        #*#messenger.send(name, [isSet])
     
     
     def isSet(self, name):
     def isSet(self, name):
         """
         """

+ 4 - 0
direct/src/showbase/NonPhysicsWalker.py

@@ -195,6 +195,10 @@ class NonPhysicsWalker(DirectObject.DirectObject):
         else:
         else:
             self.vel.set(0.0, 0.0, 0.0)
             self.vel.set(0.0, 0.0, 0.0)
         return Task.cont
         return Task.cont
+    
+    def reset(self):
+        assert(self.debugPrint("reset()"))
+        pass
 
 
     def enableAvatarControls(self):
     def enableAvatarControls(self):
         """
         """

+ 4 - 5
direct/src/showbase/PhysicsWalker.py

@@ -401,10 +401,9 @@ class PhysicsWalker(DirectObject.DirectObject):
         
         
         # hack fix for falling through the floor:
         # hack fix for falling through the floor:
         if contact==Vec3.zero() and self.avatarNodePath.getZ()<-50.0:
         if contact==Vec3.zero() and self.avatarNodePath.getZ()<-50.0:
-            # reset:
             # DCR: don't reset X and Y; allow player to move
             # DCR: don't reset X and Y; allow player to move
+            self.reset()
             self.avatarNodePath.setZ(50.0)
             self.avatarNodePath.setZ(50.0)
-            self.resetPhys()
 
 
         # get the button states:
         # get the button states:
         forward = inputState.isSet("forward")
         forward = inputState.isSet("forward")
@@ -664,8 +663,8 @@ class PhysicsWalker(DirectObject.DirectObject):
             if self.wantAvatarPhysicsIndicator:
             if self.wantAvatarPhysicsIndicator:
                 onScreenDebug.add("velocity", velocity.pPrintValues())
                 onScreenDebug.add("velocity", velocity.pPrintValues())
     
     
-    def resetPhys(self):
-        assert(self.debugPrint("resetPhys()"))
+    def reset(self):
+        assert(self.debugPrint("reset()"))
         self.actorNode.getPhysicsObject().resetPosition(self.avatarNodePath.getPos())
         self.actorNode.getPhysicsObject().resetPosition(self.avatarNodePath.getPos())
         self.priorParent.setVector(Vec3.zero())
         self.priorParent.setVector(Vec3.zero())
         self.highMark = 0
         self.highMark = 0
@@ -687,7 +686,7 @@ class PhysicsWalker(DirectObject.DirectObject):
 
 
         if __debug__:
         if __debug__:
             self.accept("control-f3", self.spawnTest) #*#
             self.accept("control-f3", self.spawnTest) #*#
-            self.accept("f3", self.resetPhys) # for debugging only.
+            self.accept("f3", self.reset) # for debugging only.
 
 
         taskName = "AvatarControls%s"%(id(self),)
         taskName = "AvatarControls%s"%(id(self),)
         # remove any old
         # remove any old