changeset 140:f4d7a9a8c363

Walk/run and other actions
author Nomad
date Tue, 12 Feb 2013 02:02:26 +0200
parents 7eeea515f5ff
children cca78efb377e
files Keyboard.cpp Render.cpp mm7_3.cpp mm7_6.cpp
diffstat 4 files changed, 133 insertions(+), 173 deletions(-) [+]
line wrap: on
line diff
--- a/Keyboard.cpp	Tue Feb 12 00:58:00 2013 +0200
+++ b/Keyboard.cpp	Tue Feb 12 02:02:26 2013 +0200
@@ -953,28 +953,16 @@
 //----- (0045B06E) --------------------------------------------------------
 bool Keyboard::IsShiftHeld()
 {
-  bool result; // eax@2
-  char v2; // zf@3
-
   if (bUsingAsynKeyboard)
   {
     if ( pAsyncKeyboard->_45B4EC(0x2Au) )
     {
-LABEL_6:
-      LOBYTE(result) = 1;
-      return result;
+      return true;
     }
-    v2 = pAsyncKeyboard->_45B4EC(0x36u) == 0;
+    return pAsyncKeyboard->_45B4EC(0x36u) != 0;
   }
   else
-  {
-    LOWORD(result) = GetAsyncKeyState(VK_SHIFT);
-    v2 = result == 0;
-  }
-  if ( !v2 )
-    goto LABEL_6;
-  LOBYTE(result) = 0;
-  return result;
+    return GetAsyncKeyState(VK_SHIFT);
 }
 
 //----- (0045B0A9) --------------------------------------------------------
--- a/Render.cpp	Tue Feb 12 00:58:00 2013 +0200
+++ b/Render.cpp	Tue Feb 12 02:02:26 2013 +0200
@@ -1,3 +1,5 @@
+#include <assert.h>
+
 #include "Render.h"
 #include "OutdoorCamera.h"
 #include "IndoorCamera.h"
@@ -1824,6 +1826,8 @@
         memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft));
         array_50AC10[k].flt_20 = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097);
       }
+
+      assert(v6 < 1000); // many random crashes here
       pRenderer->DrawTerrainPolygon(v8, pBitmaps_LOD->pHardwareTextures[v6]);
       --pOutdoorCamera->numStru148s;
       --pOutdoorCamera->field_44;
--- a/mm7_3.cpp	Tue Feb 12 00:58:00 2013 +0200
+++ b/mm7_3.cpp	Tue Feb 12 02:02:26 2013 +0200
@@ -3011,20 +3011,20 @@
   //double v14; // st7@84
   //int v15; // eax@87
   //double v16; // st7@87
-  int v17; // eax@88
-  double v18; // st7@88
-  int v19; // eax@89
-  double v20; // st7@89
-  int v21; // eax@92
-  double v22; // st7@92
-  int v23; // eax@96
-  double v24; // st7@96
-  int v25; // eax@97
-  double v26; // st7@97
-  int v27; // eax@98
-  double v28; // st7@98
-  signed __int64 v29; // qax@98
-  unsigned int v30; // eax@103
+  //int v17; // eax@88
+  //double v18; // st7@88
+  //int v19; // eax@89
+  //double v20; // st7@89
+  //int v21; // eax@92
+  //double v22; // st7@92
+  //int v23; // eax@96
+  //double v24; // st7@96
+  //int v25; // eax@97
+  //double v26; // st7@97
+  //int v27; // eax@98
+  //double v28; // st7@98
+  //signed __int64 v29; // qax@98
+  //unsigned int v30; // eax@103
   int v31; // eax@130
   int v32; // ecx@141
   signed int v33; // eax@143
@@ -3087,9 +3087,9 @@
   signed int v90; // [sp-14h] [bp-A8h]@246
   signed int v91; // [sp-10h] [bp-A4h]@246
   int v92; // [sp-Ch] [bp-A0h]@246
-  int v93; // [sp-8h] [bp-9Ch]@104
+  //int v93; // [sp-8h] [bp-9Ch]@104
   unsigned int v94; // [sp-8h] [bp-9Ch]@246
-  int v95; // [sp-4h] [bp-98h]@104
+  //int v95; // [sp-4h] [bp-98h]@104
   int v96; // [sp-4h] [bp-98h]@246
   int v97; // [sp+Ch] [bp-88h]@180
   Vec3_int_ v98;
@@ -3262,10 +3262,9 @@
                                                                     * stru_5C6E00->uIntegerPi)
                                                        / 180)) >> 16);*/
   __int64 dturn = (unsigned __int64)(pEventTimer->dt_in_some_format * (signed __int64)((signed int)(pParty->y_rotation_speed * stru_5C6E00->uIntegerPi) / 180)) >> 16;
-LABEL_118:
-  while ( pPartyActionQueue->uNumActions )
-  {
-    switch ( pPartyActionQueue->Next() )
+  while (pPartyActionQueue->uNumActions)
+  {
+    switch (pPartyActionQueue->Next())
     {
       case PARTY_FlyUp:
       {
@@ -3371,8 +3370,6 @@
 
       case PARTY_StrafeLeft:
       {
-        //v13 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
-        //v14 = (double)_walk_speed;
         *(float *)&v128 = pParty->uWalkSpeed;
 
         float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0);
@@ -3390,14 +3387,8 @@
 
       case PARTY_StrafeRight:
       {
-        //v126 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
         *(float *)&v128 = pParty->uWalkSpeed;
-        /*v124 = (unsigned __int64)(v126 * (signed __int64)((signed int)(signed __int64)(pParty->uWalkSpeed * fWalkSpeedMultiplier) >> 1)) >> 16;
-        v2 += v124;
-        v126 = stru_5C6E00->SinCos(_angle_y);
-        v124 = (unsigned __int64)(v126
-                                * (signed __int64)((signed int)(signed __int64)(*(float *)&v128 * fWalkSpeedMultiplier) >> 1)) >> 16;
-        v1 -= v124;*/
+
         float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0);
         int dx = sin_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
         v2 += 3 * dx / 4;
@@ -3412,151 +3403,125 @@
       break;
 
       case PARTY_WalkForward:
-        v17 = stru_5C6E00->SinCos(_angle_y);
-        v18 = (double)_walk_speed;
-        v126 = v17;
-        *(float *)&v128 = v18;
-        v124 = (unsigned __int64)(v17 * (signed __int64)(signed int)(signed __int64)(v18 * fWalkSpeedMultiplier)) >> 16;
-        v2 += v124;
-        v126 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
-        v124 = (unsigned __int64)(v126
-                                * (signed __int64)(signed int)(signed __int64)(*(float *)&v128 * fWalkSpeedMultiplier)) >> 16;
-        v1 += v124;
+      {
+        *(float *)&v128 = _walk_speed;
+
+        float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0),
+              cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
+
+        int dx = cos_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
+        v2 += dx;
+        
+        int dy = sin_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
+        v1 += dy;
+
         v128 = v1;
         v124 = 1;
-      break;
-
-      case PARTY_WalkBackward:
-        v19 = stru_5C6E00->SinCos(_angle_y);
-        v20 = (double)_walk_speed;
-        v126 = v19;
-        *(float *)&v128 = v20;
-        v124 = (unsigned __int64)(v19
-                                * (signed __int64)(signed int)(signed __int64)(v20 * fBackwardWalkSpeedMultiplier)) >> 16;
-        v2 -= v124;
-        v126 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
-        v124 = (unsigned __int64)(v126
-                                * (signed __int64)(signed int)(signed __int64)(*(float *)&v128
-                                                                             * fBackwardWalkSpeedMultiplier)) >> 16;
-        v1 -= v124;
-        v128 = v1;
-        v124 = 1;
+      }
       break;
 
       case PARTY_RunForward:
-        if ( pParty->bFlying )
-        {
-          v21 = stru_5C6E00->SinCos(_angle_y);
-          v22 = (double)_walk_speed;
-          v126 = v21;
-          *(float *)&v128 = v22;
-          v129 = (unsigned __int64)(v21
-                                  * (signed __int64)(signed int)(4
-                                                               * (unsigned __int64)(signed __int64)(v22
-                                                                                                  * fWalkSpeedMultiplier))) >> 16;
-          v2 += v129;
-          v126 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
-          v129 = (unsigned __int64)(v126
-                                  * (signed __int64)(signed int)(4
-                                                               * (unsigned __int64)(signed __int64)(*(float *)&v128
-                                                                                                  * fWalkSpeedMultiplier))) >> 16;
-          v1 += v129;
-          goto LABEL_93;
-        }
-        if ( partyAtHighSlope && !v108 )
-        {
-          v23 = stru_5C6E00->SinCos(_angle_y);
-          v24 = (double)_walk_speed;
-          v126 = v23;
-          *(float *)&v128 = v24;
-          v129 = (unsigned __int64)(v23 * (signed __int64)(signed int)(signed __int64)(v24 * fWalkSpeedMultiplier)) >> 16;
-          v2 += v129;
-          v126 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
-          v129 = (unsigned __int64)(v126
-                                  * (signed __int64)(signed int)(signed __int64)(*(float *)&v128 * fWalkSpeedMultiplier)) >> 16;
-          v1 += v129;
+      {
+        *(float *)&v128 = _walk_speed;
+
+        float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0),
+              cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
+
+        int dx = cos_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;        
+        int dy = sin_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
+
+        if (pParty->bFlying)
+        {
+          v2 += 4 * dx;
+          v1 += 4 * dy;
+
+          v128 = v1;
+        }
+        else if (partyAtHighSlope && !v108)
+        {
+          v2 += dx;
+          v1 += dy;
+
           v128 = v1;
           v124 = 1;
-          break;
-        }
-        v25 = stru_5C6E00->SinCos(_angle_y);
-        v26 = (double)_walk_speed;
-        v114 = v25;
-        *(float *)&v128 = v26;
-        v129 = (unsigned __int64)(v25
-                                * (signed __int64)(signed int)(2
-                                                             * (unsigned __int64)(signed __int64)(v26
-                                                                                                * fWalkSpeedMultiplier))) >> 16;
-        v2 += v129;
-        v114 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
-        v129 = (unsigned __int64)((signed int)v114
-                                * (signed __int64)(signed int)(2
-                                                             * (unsigned __int64)(signed __int64)(*(float *)&v128
-                                                                                                * fWalkSpeedMultiplier))) >> 16;
-        v1 += v129;
-        v114 = 1;
+        }
+        else
+        {
+          v2 += 2 * dx;
+          v1 += 2 * dy;
+          
+          v128 = v1;
+          v114 = 1;
+        }
+      }
+      break;
+
+
+      case PARTY_WalkBackward:
+      {
+        *(float *)&v128 = _walk_speed;
+
+        float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0),
+              cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
+
+        int dx = cos_y * pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier;
+        v2 -= dx;
+        
+        int dy = sin_y * pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier;
+        v1 -= dy;
+
         v128 = v1;
-        break;
+        v124 = 1;
+      }
+      break;
+
 
       case PARTY_RunBackward:
-        v27 = stru_5C6E00->SinCos(_angle_y);
-        v28 = (double)_walk_speed;
-        v126 = v27;
-        *(float *)&v128 = v28;
-        v29 = (signed __int64)(v28 * fBackwardWalkSpeedMultiplier);
-        if ( pParty->bFlying )
-        {
-          v129 = (unsigned __int64)(v126 * (signed __int64)(4 * (signed int)v29)) >> 16;
-          v2 -= v129;
-          v126 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
-          v129 = (unsigned __int64)(v126
-                                  * (signed __int64)(signed int)(4
-                                                               * (unsigned __int64)(signed __int64)(*(float *)&v128
-                                                                                                  * fBackwardWalkSpeedMultiplier))) >> 16;
-          v1 -= v129;
-LABEL_93:
+      {
+        float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0),
+              cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
+
+        int dx = cos_y * pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier;        
+        int dy = sin_y * pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier;
+
+        if (pParty->bFlying)
+        {
+          v2 -= 4 * dx;
+          v1 -= 4 * dy;
           v128 = v1;
         }
         else
         {
-          v129 = (unsigned __int64)(v126 * (signed __int64)(signed int)v29) >> 16;
-          v2 -= v129;
-          v126 = stru_5C6E00->SinCos(_angle_y - stru_5C6E00->uIntegerHalfPi);
-          v129 = (unsigned __int64)(v126
-                                  * (signed __int64)(signed int)(signed __int64)(*(float *)&v128
-                                                                               * fBackwardWalkSpeedMultiplier)) >> 16;
-          v1 -= v129;
-//LABEL_86:
+          v2 -= dx;
+          v1 -= dy;
+
           v128 = v1;
           v124 = 1;
         }
-        break;
+      }
+      break;
+
+      
+      case PARTY_CenterView:
+        _angle_x = 0;
+      break;
+
       case PARTY_LookUp:
         _angle_x += (signed __int64)(flt_6BE150_look_up_down_dangle * 25.0);
         if ( _angle_x > 128 )
           _angle_x = 128;
-        v30 = uActiveCharacter;
-        if ( !uActiveCharacter )
-          goto LABEL_118;
-        v95 = 0;
-        v93 = 63;
-        goto _play_player_sound;
+        if (uActiveCharacter)
+          pPlayers[uActiveCharacter]->PlaySound(63, 0);
+      break;
+
       case PARTY_LookDown:
         _angle_x += (signed __int64)(flt_6BE150_look_up_down_dangle * -25.0);
         if ( _angle_x < -128 )
           _angle_x = -128;
-        v30 = uActiveCharacter;
-        if ( uActiveCharacter )
-        {
-          v95 = 0;
-          v93 = 64;
-_play_player_sound:
-          pPlayers[v30]->PlaySound(v93, v95);
-        }
-        goto LABEL_118;
-      case PARTY_CenterView:
-        _angle_x = 0;
-        goto LABEL_118;
+        if (uActiveCharacter)
+          pPlayers[uActiveCharacter]->PlaySound(64, 0);
+      break;
+
       case PARTY_Jump:
         if ( (!partyAtHighSlope || v108) && !bJumping && pParty->field_24 && !(pParty->uFlags & 4) && !(BYTE1(pParty->uFlags) & 2) )
         {
@@ -3564,20 +3529,23 @@
           bJumping = 1;
           v121 = (signed __int64)((double)(pParty->field_24 << 6) * 1.5 + (double)v121);
         }
-        goto LABEL_118;
+      break;
+
       default:
-        goto LABEL_118;
+        assert(false);
+
       case PARTY_Land:
-        if ( pParty->bFlying )
+        if (pParty->bFlying)
         {
           BYTE1(pParty->uFlags) |= 1u;
           pParty->uFallSpeed = 0;
         }
-        pParty->bFlying = 0;
+        pParty->bFlying = false;
         pPartyActionQueue->uNumActions = 0;
-        goto LABEL_123;
-    }
-  }
+      break;
+    }
+  }
+
 LABEL_123:
   pParty->sRotationY = _angle_y;
   pParty->sRotationX = _angle_x;
--- a/mm7_6.cpp	Tue Feb 12 00:58:00 2013 +0200
+++ b/mm7_6.cpp	Tue Feb 12 02:02:26 2013 +0200
@@ -8921,7 +8921,7 @@
       pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
   }
 
-  pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
+  //pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
 LABEL_6:
   if ( !pEventTimer->bPaused )
   {
@@ -8949,7 +8949,7 @@
               pTurnEngine->uActionPointsLeft -= 26;
 _do_move_forward:
               v5 = pActionQueue;
-              if ( pParty->uFlags2 & 2 )
+              if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)
                 partyAction = PARTY_RunForward;
               else
                 partyAction = PARTY_WalkForward;