瀏覽代碼

player-look -- modified player head and arm control
player-movement -- mods allowing manipulation of player movement.
player-puppet -- mods allowing manipulation of player via contraints.
foot-switch -- mods for overriding built-in footstep sounds, decals, and dust.

Marc Chapman 8 年之前
父節點
當前提交
31f1d27a49
共有 2 個文件被更改,包括 171 次插入9 次删除
  1. 138 8
      Engine/source/T3D/player.cpp
  2. 33 1
      Engine/source/T3D/player.h

+ 138 - 8
Engine/source/T3D/player.cpp

@@ -2117,7 +2117,10 @@ void Player::processTick(const Move* move)
       else if (delta.rot.z > M_PI_F)
          delta.rot.z -= M_2PI_F;
 
-      setPosition(delta.pos,delta.rot);
+      if (!ignore_updates)
+      {
+         setPosition(delta.pos,delta.rot);
+      }
       updateDeathOffsets();
       updateLookAnimation();
 
@@ -2215,7 +2218,8 @@ void Player::interpolateTick(F32 dt)
    Point3F pos = delta.pos + delta.posVec * dt;
    Point3F rot = delta.rot + delta.rotVec * dt;
 
-   setRenderPosition(pos,rot,dt);
+   if (!ignore_updates)
+      setRenderPosition(pos,rot,dt);
 
 /*
    // apply camera effects - is this the best place? - bramage
@@ -2533,6 +2537,30 @@ AngAxisF gPlayerMoveRot;
 
 void Player::updateMove(const Move* move)
 {
+   struct Move my_move;
+   if (override_movement && movement_op < 3)
+   {
+      my_move = *move;
+      switch (movement_op)
+      {
+      case 0: // add
+         my_move.x += movement_data.x;
+         my_move.y += movement_data.y;
+         my_move.z += movement_data.z;
+         break;
+      case 1: // mult
+         my_move.x *= movement_data.x;
+         my_move.y *= movement_data.y;
+         my_move.z *= movement_data.z;
+         break;
+      case 2: // replace
+         my_move.x = movement_data.x;
+         my_move.y = movement_data.y;
+         my_move.z = movement_data.z;
+         break;
+      }
+      move = &my_move;
+   }
    delta.move = *move;
 
 #ifdef TORQUE_OPENVR
@@ -2839,6 +2867,9 @@ void Player::updateMove(const Move* move)
       moveSpeed = 0.0f;
    }
 
+   // apply speed bias here.
+   speed_bias = speed_bias + (speed_bias_goal - speed_bias)*0.1f;
+   moveSpeed *= speed_bias;
    // Acceleration due to gravity
    VectorF acc(0.0f, 0.0f, mGravity * mGravityMod * TickSec);
 
@@ -3538,6 +3569,19 @@ void Player::updateDamageState()
 
 void Player::updateLookAnimation(F32 dt)
 {
+   // If the preference setting overrideLookAnimation is true, the player's
+   // arm and head no longer animate according to the view direction. They
+   // are instead given fixed positions.
+   if (overrideLookAnimation)
+   {
+      if (mArmAnimation.thread) 
+         mShapeInstance->setPos(mArmAnimation.thread, armLookOverridePos);
+      if (mHeadVThread) 
+         mShapeInstance->setPos(mHeadVThread, headVLookOverridePos);
+      if (mHeadHThread) 
+         mShapeInstance->setPos(mHeadHThread, headHLookOverridePos);
+      return;
+   }
    // Calculate our interpolated head position.
    Point3F renderHead = delta.head + delta.headVec * dt;
 
@@ -3930,7 +3974,7 @@ void Player::updateActionThread()
             // Put footprints on surface, if appropriate for material.
 
             if( material && material->mShowFootprints
-                && mDataBlock->decalData )
+                && mDataBlock->decalData && !footfallDecalOverride )
             {
                Point3F normal;
                Point3F tangent;
@@ -3941,8 +3985,8 @@ void Player::updateActionThread()
             
             // Emit footpuffs.
 
-            if( rInfo.t <= 0.5 && mWaterCoverage == 0.0
-                && material && material->mShowDust )
+            if (!footfallDustOverride && rInfo.t <= 0.5f && mWaterCoverage == 0.0f
+                                         && material && material->mShowDust )
             {
                // New emitter every time for visibility reasons
                ParticleEmitter * emitter = new ParticleEmitter;
@@ -3975,6 +4019,7 @@ void Player::updateActionThread()
 
             // Play footstep sound.
             
+            if (footfallSoundOverride <= 0)
             playFootstepSound( triggeredLeft, material, rInfo.object );
          }
       }
@@ -6222,7 +6267,8 @@ void Player::readPacketData(GameConnection *connection, BitStream *stream)
    stream->read(&mHead.z);
    stream->read(&rot.z);
    rot.x = rot.y = 0;
-   setPosition(pos,rot);
+   if (!ignore_updates)
+      setPosition(pos,rot);
    delta.head = mHead;
    delta.rot = rot;
 
@@ -6469,7 +6515,8 @@ void Player::unpackUpdate(NetConnection *con, BitStream *stream)
             }
             delta.pos = pos;
             delta.rot = rot;
-            setPosition(pos,rot);
+            if (!ignore_updates)
+               setPosition(pos,rot);
          }
       }
       else 
@@ -6481,7 +6528,8 @@ void Player::unpackUpdate(NetConnection *con, BitStream *stream)
          delta.rotVec.set(0.0f, 0.0f, 0.0f);
          delta.warpTicks = 0;
          delta.dt = 0.0f;
-         setPosition(pos,rot);
+         if (!ignore_updates)
+            setPosition(pos,rot);
       }
    }
    F32 energy = stream->readFloat(EnergyLevelBits) * mDataBlock->maxEnergy;
@@ -6942,6 +6990,8 @@ void Player::calcClassRenderData()
 
 void Player::playFootstepSound( bool triggeredLeft, Material* contactMaterial, SceneObject* contactObject )
 {
+   if (footfallSoundOverride > 0)
+      return;
    MatrixF footMat = getTransform();
    if( mWaterCoverage > 0.0 )
    {
@@ -7473,6 +7523,27 @@ ConsoleMethod(Player, isAnimationLocked, bool, 2, 2, "isAnimationLocked()")
 }
 
 
+void Player::setLookAnimationOverride(bool flag) 
+{ 
+   overrideLookAnimation = flag; 
+#if 0
+   setMaskBits(LookOverrideMask);
+#else
+   setMaskBits(ActionMask);
+#endif
+}
+
+ConsoleMethod(Player, setLookAnimationOverride, void, 3, 3, "setLookAnimationOverride(flag)")
+{
+   object->setLookAnimationOverride(dAtob(argv[2]));
+}
+
+ConsoleMethod(Player, copyHeadRotation, void, 3, 3, "copyHeadRotation(other_player)")
+{
+   Player* other_player = dynamic_cast<Player*>(Sim::findObject(argv[2]));
+   if (other_player)
+      object->copyHeadRotation(other_player);
+}
 void Player::process_client_triggers(bool triggeredLeft, bool triggeredRight)
 {
    bool mark_landing = false;
@@ -7505,6 +7576,65 @@ void Player::process_client_triggers(bool triggeredLeft, bool triggeredRight)
       fx_c_triggers &= ~(PLAYER_LANDING_S_TRIGGER);
    }
 }
+U32 Player::unique_movement_tag_counter = 1;
+
+void Player::setMovementSpeedBias(F32 bias) 
+{ 
+   speed_bias_goal = bias; 
+}
+
+U32 Player::setMovementOverride(F32 bias, const Point3F* mov, U32 op) 
+{ 
+   if (mov)
+   {
+      movement_data = *mov;
+      override_movement = true;
+      movement_op = (U8)op;
+   }
+   else
+      override_movement = false;
+
+   speed_bias_goal = bias;
+
+   last_movement_tag = unique_movement_tag_counter++;
+   return last_movement_tag;
+}
+
+void Player::restoreMovement(U32 tag) 
+{ 
+   if (tag != 0 && tag == last_movement_tag)
+   {
+      speed_bias_goal = 1.0;
+      override_movement = false;
+   }
+}
+
+ConsoleMethod(Player, setMovementSpeedBias, void, 3, 3, "setMovementSpeedBias(F32 bias)")
+{
+   object->setMovementSpeedBias(dAtof(argv[2]));
+}
+
+void Player::overrideFootfallFX(bool decals, bool sounds, bool dust) 
+{ 
+   if (decals)
+      footfallDecalOverride++; 
+   if (sounds)
+      footfallSoundOverride++; 
+   if (dust)
+      footfallDustOverride++; 
+   noFootfallFX = (footfallDecalOverride > 0 && footfallSoundOverride > 0 && footfallDustOverride > 0);
+}
+
+void Player::restoreFootfallFX(bool decals, bool sounds, bool dust) 
+{ 
+   if (decals && footfallDecalOverride) 
+      footfallDecalOverride--; 
+   if (sounds && footfallSoundOverride) 
+      footfallSoundOverride--; 
+   if (dust && footfallDustOverride) 
+      footfallDustOverride--; 
+   noFootfallFX = (footfallDecalOverride > 0 && footfallSoundOverride > 0 && footfallDustOverride > 0);
+}
 #ifdef TORQUE_OPENVR
 void Player::setControllers(Vector<OpenVRTrackedObject*> controllerList)
 {

+ 33 - 1
Engine/source/T3D/player.h

@@ -406,7 +406,8 @@ protected:
       ActionMask   = Parent::NextFreeMask << 0,
       MoveMask     = Parent::NextFreeMask << 1,
       ImpactMask   = Parent::NextFreeMask << 2,
-      NextFreeMask = Parent::NextFreeMask << 3
+      TriggerMask      = Parent::NextFreeMask << 3,
+      NextFreeMask     = Parent::NextFreeMask << 4
    };
 
    SimObjectPtr<ParticleEmitter> mSplashEmitter[PlayerData::NUM_SPLASH_EMITTERS];
@@ -804,6 +805,17 @@ public:
    virtual U32 lockAnimation();
    virtual bool isAnimationLocked() const { return ((anim_clip_flags & BLOCK_USER_CONTROL) != 0); }
    
+protected:
+   bool         overrideLookAnimation;
+   F32          armLookOverridePos;
+   F32          headVLookOverridePos;
+   F32          headHLookOverridePos;
+public:
+   void         setLookAnimationOverride(bool flag);
+   void         copyHeadRotation(const Player* p) { mHead = p->mHead; }
+public:
+   bool ignore_updates;
+   void resetContactTimer() { mContactTimer = 0; }
 private:
    U8     move_trigger_states;
    U32    fx_s_triggers;
@@ -837,6 +849,26 @@ public:
    };
    U32  getClientEventTriggers() const { return fx_c_triggers; }
    U32  getServerEventTriggers() const { return fx_s_triggers; }
+private:
+   F32      speed_bias;
+   F32      speed_bias_goal;
+   bool     override_movement;
+   Point3F  movement_data;
+   U8       movement_op;
+   U32      last_movement_tag;
+   static U32   unique_movement_tag_counter;
+public:
+   void     setMovementSpeedBias(F32 bias);
+   U32      setMovementOverride(F32 bias, const Point3F* mov=0, U32 op=1);
+   void     restoreMovement(U32 tag);
+private:
+   S32      footfallDecalOverride;
+   S32      footfallSoundOverride;
+   S32      footfallDustOverride;
+   bool     noFootfallFX;
+public:
+   void     overrideFootfallFX(bool decals=true, bool sounds=true, bool dust=true);
+   void     restoreFootfallFX(bool decals=true, bool sounds=true, bool dust=true);
 };
 
 typedef Player::Pose PlayerPose;