Browse Source

Changed input to Event in entity na

Dave Schuyler 22 years ago
parent
commit
15f382d754

+ 9 - 8
direct/src/level/CutScene.py

@@ -107,12 +107,12 @@ class CutScene(Entity.Entity, DirectObject.DirectObject):
         self.subjectNodePath.setPos(self.pos)
         self.subjectNodePath.setHpr(self.hpr)
         #self.setSubjectNodePath(self.subjectNodePath)
-        self.setStartStop(self.startStop)
+        self.setStartStop(self.startStopEvent)
 
     def destroy(self):
         assert(self.debugPrint("destroy()"))
-        self.ignore(self.startStop)
-        self.startStop = None
+        self.ignore(self.startStopEvent)
+        self.startStopEvent = None
         Entity.Entity.destroy(self)
         #DirectObject.DirectObject.destroy(self)
     
@@ -142,6 +142,7 @@ class CutScene(Entity.Entity, DirectObject.DirectObject):
             track = Parallel(name = trackName)
             track = self.getEffect(self, track, self.subjectNodePath, self.duration)
             track = self.getMotion(self, track, self.subjectNodePath, self.duration)
+            track = Sequence(Wait(0.8), track)
             track.start(0.0)
             self.track = track
         else:
@@ -151,11 +152,11 @@ class CutScene(Entity.Entity, DirectObject.DirectObject):
     
     def setStartStop(self, event):
         assert(self.debugPrint("setStartStop(event=%s)"%(event,)))
-        if self.startStop:
-            self.ignore(self.startStop)
-        self.startStop = "switch-%s"%(event,)
-        if self.startStop:
-            self.accept(self.startStop, self.startOrStop)
+        if self.startStopEvent:
+            self.ignore(self.startStopEvent)
+        self.startStopEvent = "switch-%s"%(event,)
+        if self.startStopEvent:
+            self.accept(self.startStopEvent, self.startOrStop)
     
     def getName(self):
         #return "CutScene-%s"%(self.entId,)

+ 20 - 20
direct/src/level/EntityTypes.py

@@ -43,8 +43,8 @@ class LogicGate(Entity):
     type = 'logicGate'
     output = 'bool'
     attribs = (
-        ('input_input1_bool', 0, 'entId', {'output':'bool'}),
-        ('input_input2_bool', 0, 'entId', {'output':'bool'}),
+        ('input1Event', 0, 'entId', {'output':'bool'}),
+        ('input2Event', 0, 'entId', {'output':'bool'}),
         ('isInput1', 0, 'bool'),
         ('isInput2', 0, 'bool'),
         ('logicType', 'or', 'choice',
@@ -91,7 +91,7 @@ class CutScene(Entity):
     attribs = (
         ('pos', Point3(0,0,0), 'pos'),
         ('hpr', Vec3(0,0,0), 'hpr'),
-        ('startStop', 0),
+        ('startStopEvent', 0, 'entId', {'output':'bool'}),
         ('effect', 'irisInOut'),
         ('motion', 'foo1'),
         ('duration', 5.0),
@@ -121,7 +121,7 @@ class Switch(Entity, NodepathImpl):
         ('scale', Vec3(1), 'scale'),
         ('color', Vec4(1,1,1,1), 'color'),
         ('model', '', 'bamfilename'),
-        ('input_isOn_bool', 0, 'entId', {'output':'bool'}),
+        ('isOnEvent', 0, 'entId', {'output':'bool'}),
         ('isOn', 0, 'bool'),
         ('secondsOn', 1, 'float'),
         )
@@ -159,23 +159,23 @@ class Door(Entity):
     output = 'bool'
     attribs = (
         ('parent', 0, 'entId'),
-        ('pos', Point3(0,0,0), 'pos'),
-        ('hpr', Vec3(0,0,0), 'hpr'),
-        ('scale', Vec3(1,1,1), 'scale'),
-        ('color', Vec4(1,1,1,1), 'color'),
-        ('model', "", 'bamfilename'),
+        ('pos', Point3(0,0,0), 'pos'), # Client Only
+        ('hpr', Vec3(0,0,0), 'hpr'), # Client Only
+        ('scale', Vec3(1,1,1), 'scale'), # Client Only
+        ('color', Vec4(1,1,1,1), 'color'), # Client Only
+        ('model', "", 'bamfilename'), # Client Only
         ('doorwayNum', 0), # Obsolete
-        ('input_Lock0_bool', 0, 'entId', {'output':'bool'}),
-        ('input_Lock1_bool', 0, 'entId', {'output':'bool'}),
-        ('input_Lock2_bool', 0, 'entId', {'output':'bool'}),
-        ('input_Lock3_bool', 0, 'entId', {'output':'bool'}),
-        ('input_isOpen_bool', 0, 'entId', {'output':'bool'}),
-        ('isLock0Unlocked', 0, 'bool'),
-        ('isLock1Unlocked', 0, 'bool'),
-        ('isLock2Unlocked', 0, 'bool'),
-        ('isLock3Unlocked', 0, 'bool'),
-        ('isOpen', 0, 'bool'),
-        ('secondsOpen', 1, 'float'),
+        ('unlock0Event', 0, 'entId', {'output':'bool'}), # AI Only
+        ('unlock1Event', 0, 'entId', {'output':'bool'}), # AI Only
+        ('unlock2Event', 0, 'entId', {'output':'bool'}), # AI Only
+        ('unlock3Event', 0, 'entId', {'output':'bool'}), # AI Only
+        ('isOpenEvent', 0, 'entId', {'output':'bool'}),
+        ('isLock0Unlocked', 0, 'bool'), # AI Only
+        ('isLock1Unlocked', 0, 'bool'), # AI Only
+        ('isLock2Unlocked', 0, 'bool'), # AI Only
+        ('isLock3Unlocked', 0, 'bool'), # AI Only
+        ('isOpen', 0, 'bool'), # AI Only
+        ('secondsOpen', 1, 'float'), # AI Only
         )
 
 class Grid(Nodepath):

+ 51 - 47
direct/src/level/LogicGateAI.py

@@ -1,39 +1,40 @@
-"""LogicGateAI.py: contains the OrLoEntity class"""
+"""
+LogicGateAI.py
 
+    Logic Gates:
+
+         and: 0 0 = 0     or: 0 0 = 0    xor: 0 0 = 0
+              0 1 = 0         0 1 = 1         0 1 = 1
+              1 0 = 0         1 0 = 1         1 0 = 1
+              1 1 = 1         1 1 = 1         1 1 = 0
+
+        nand: 0 0 = 1    nor: 0 0 = 1   xnor: 0 0 = 1
+              0 1 = 1         0 1 = 0         0 1 = 0
+              1 0 = 1         1 0 = 0         1 0 = 0
+              1 1 = 0         1 1 = 0         1 1 = 1
+
+    In the following:
+        1: send a true message
+        0: send a false message
+        -: don't send a message
+
+        a b  and  or  xor  nand  nor  xnor
+       (0 0)  (0) (0)  (0)   (1)  (1)   (1)  <--- initial state
+        1 0    -   1    1     -    0     0
+        0 0    -   0    0     -    1     1
+        1 0    -   1    1     -    0     0
+        1 1    1   -    0     0    -     1
+        0 1    0   -    1     1    -     0
+        1 1    1   -    0     0    -     1
+        0 1    0   -    1     1    -     0
+        0 0    -   0    0     -    1     1
+"""
 
 import PandaObject
 import DirectNotifyGlobal
 import Entity
 
 
-# Logic Gates:
-#
-#  and: 0 0 = 0     or: 0 0 = 0    xor: 0 0 = 0
-#       0 1 = 0         0 1 = 1         0 1 = 1
-#       1 0 = 0         1 0 = 1         1 0 = 1
-#       1 1 = 1         1 1 = 1         1 1 = 0
-#
-# nand: 0 0 = 1    nor: 0 0 = 1   xnor: 0 0 = 1
-#       0 1 = 1         0 1 = 0         0 1 = 0
-#       1 0 = 1         1 0 = 0         1 0 = 0
-#       1 1 = 0         1 1 = 0         1 1 = 1
-#
-# In the following:
-#   1: send a true message
-#   0: send a false message
-#   -: don't send a message
-#
-#   a b  and  or  xor  nand  nor  xnor
-#  (0 0)  (0) (0)  (0)   (1)  (1)   (1)  <--- initial state
-#   1 0    -   1    1     -    0     0
-#   0 0    -   0    0     -    1     1
-#   1 0    -   1    1     -    0     0
-#   1 1    1   -    0     0    -     1
-#   0 1    0   -    1     1    -     0
-#   1 1    1   -    0     0    -     1
-#   0 1    0   -    1     1    -     0
-#   0 0    -   0    0     -    1     1
-
 def andTest(self, a, b):
     assert(self.debugPrint("andTest(a=%s, b=%s)"%(a, b)))
     if b:
@@ -83,12 +84,15 @@ class LogicGateAI(Entity.Entity, PandaObject.PandaObject):
         assert(self.debugPrint(
                 "LogicGateAI(entId=%s)"
                 %(entId)))
-        self.input1 = None
-        self.input2 = None
+        self.input1Event = None
+        self.input2Event = None
+        PandaObject.PandaObject.__init__(self)
         Entity.Entity.__init__(self, level, entId)
         self.setLogicType(self.logicType)
-        self.setInput_input1_bool(self.input_input1_bool)
-        self.setInput_input2_bool(self.input_input2_bool)
+        self.setIsInput1(self.isInput1)
+        self.setIsInput2(self.isInput2)
+        self.setInput1Event(self.input1Event)
+        self.setInput2Event(self.input2Event)
 
     def destroy(self):
         assert(self.debugPrint("destroy()"))
@@ -119,21 +123,21 @@ class LogicGateAI(Entity.Entity, PandaObject.PandaObject):
             self.isInput2=isTrue
             self.logicTest(self, isTrue, self.isInput1)
     
-    def setInput_input1_bool(self, event):
-        assert(self.debugPrint("setInput_input1_bool(event=%s)"%(event,)))
-        if self.input1:
-            self.ignore(self.input1)
-        self.input1 = "switch-%s"%(event,)
-        if self.input1:
-            self.accept(self.input1, self.setIsInput1)
+    def setInput1Event(self, event):
+        assert(self.debugPrint("setInput1Event(event=%s)"%(event,)))
+        if self.input1Event:
+            self.ignore(self.input1Event)
+        self.input1Event = "switch-%s"%(event,)
+        if self.input1Event:
+            self.accept(self.input1Event, self.setIsInput1)
     
-    def setInput_input2_bool(self, event):
-        assert(self.debugPrint("setInput_input2_bool(event=%s)"%(event,)))
-        if self.input2:
-            self.ignore(self.input2)
-        self.input2 = "switch-%s"%(event,)
-        if self.input2:
-            self.accept(self.input2, self.setIsInput2)
+    def setInput2Event(self, event):
+        assert(self.debugPrint("setInput2Event(event=%s)"%(event,)))
+        if self.input2Event:
+            self.ignore(self.input2Event)
+        self.input2Event = "switch-%s"%(event,)
+        if self.input2Event:
+            self.accept(self.input2Event, self.setIsInput2)
     
     def getName(self):
         #return "logicGate-%s"%(self.entId,)

+ 102 - 0
direct/src/showbase/PhysicsWalker.py

@@ -67,6 +67,9 @@ class PhysicsWalker(DirectObject.DirectObject):
         Set up the avatar collisions
         """
         assert(self.debugPrint("initializeCollisions()"))
+        
+        assert not avatarNodePath.isEmpty()
+        
         self.cTrav = collisionTraverser
 
         # Set up the collision sphere
@@ -308,6 +311,105 @@ class PhysicsWalker(DirectObject.DirectObject):
         # Clear the contact vector so we can tell if we contact something next frame:
         self.actorNode.setContactVector(Vec3.zero())
         return Task.cont
+
+    def handleAvatarControls_wip(self, task):
+        """
+        Check on the arrow keys and update the avatar.
+        """
+        #assert(self.debugPrint("handleAvatarControls(task=%s)"%(task,)))
+        physObject=self.actorNode.getPhysicsObject()
+        rotAvatarToPhys=Mat3.rotateMatNormaxis(-self.avatarNodePath.getH(), Vec3.up())
+        #rotPhysToAvatar=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
+        contact=self.actorNode.getContactVector()
+        
+        # hack fix for falling through the floor:
+        if contact==Vec3.zero() and self.avatarNodePath.getZ()<-50.0:
+            # reset:
+            self.avatarNodePath.setPos(Vec3(0.0, 0.0, 20.0))
+
+        # Determine what the speeds are based on the buttons:
+        self.__speed=(self.__forwardButton and self.avatarControlForwardSpeed or 
+                    self.__reverseButton and -self.avatarControlReverseSpeed)
+        self.__slideSpeed=self.__slideButton and (
+                (self.__leftButton and -self.avatarControlForwardSpeed) or 
+                (self.__rightButton and self.avatarControlForwardSpeed))
+        self.__rotationSpeed=not self.__slideButton and (
+                (self.__leftButton and self.avatarControlRotateSpeed) or
+                (self.__rightButton and -self.avatarControlRotateSpeed))
+        # How far did we move based on the amount of time elapsed?
+        dt=min(ClockObject.getGlobalClock().getDt(), 0.1)
+
+        doPhysics=1
+        if not contact.almostEqual(Vec3.zero()):
+            contactLength = contact.length()
+            contact.normalize()
+            angle=contact.dot(Vec3.up())
+            if angle>self.__standableGround:
+                # ...avatar is on standable ground.
+                #print "standableGround"
+                if self.__old_contact==Vec3.zero():
+                    jumpTime = 0.0
+                    if contactLength>self.__hardLandingForce:
+                        # ...avatar was airborne.
+                        messenger.send("jumpHardLand")
+                    else:
+                        messenger.send("jumpLand")
+                if self.__jumpButton:
+                    self.__jumpButton=0
+                    messenger.send("jumpStart")
+                    jump=Vec3(contact+Vec3.up())
+                    #jump=Vec3(rotAvatarToPhys.xform(jump))
+                    jump.normalize()
+                    jump*=self.avatarControlJumpForce
+                    physObject.addImpulse(Vec3(jump))
+                else:
+                    physObject.setVelocity(Vec3(0.0))
+                    self.__vel.set(0.0, 0.0, 0.0)
+                    doPhysics=0
+        if contact!=self.__old_contact:
+            # We must copy the vector to preserve it:
+            self.__old_contact=Vec3(contact)
+        #print "doPhysics", doPhysics
+        #print "contact", contact
+        if doPhysics:
+            self.phys.doPhysics(dt)
+        # Check to see if we're moving at all:
+        if self.__speed or self.__slideSpeed or self.__rotationSpeed:
+            distance = dt * self.__speed
+            slideDistance = dt * self.__slideSpeed
+            rotation = dt * self.__rotationSpeed
+
+            #debugTempH=self.avatarNodePath.getH()
+            assert self.avatarNodePath.getHpr().almostEqual(physObject.getOrientation().getHpr(), 0.0001)
+            assert self.avatarNodePath.getPos().almostEqual(physObject.getPosition(), 0.0001)
+
+            # update pos:
+            # Take a step in the direction of our previous heading.
+            self.__vel=Vec3(Vec3.forward() * distance + 
+                          Vec3.right() * slideDistance)
+            # rotMat is the rotation matrix corresponding to
+            # our previous heading.
+            rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
+            step=rotMat.xform(self.__vel)
+            physObject.setPosition(Point3(
+                physObject.getPosition()+step))
+            # update hpr:
+            o=physObject.getOrientation()
+            r=LOrientationf()
+            r.setHpr(Vec3(rotation, 0.0, 0.0))
+            physObject.setOrientation(o*r)
+            # sync the change:
+            self.actorNode.updateTransform()
+
+            assert self.avatarNodePath.getHpr().almostEqual(physObject.getOrientation().getHpr(), 0.0001)
+            assert self.avatarNodePath.getPos().almostEqual(physObject.getPosition(), 0.0001)
+            #assert self.avatarNodePath.getH()==debugTempH-rotation
+            messenger.send("avatarMoving")
+        else:
+            self.__vel.set(0.0, 0.0, 0.0)
+        # Clear the contact vector so we can tell if we contact something next frame:
+        self.actorNode.setContactVector(Vec3.zero())
+        return Task.cont
     
     def resetPhys(self):
         assert(self.debugPrint("resetPhys()"))