changeset 1574:2d9c8f609a3c

Here and there cleanings.
author Nomad
date Mon, 09 Sep 2013 17:17:53 +0200
parents 6d759814a817
children 43d3536a20f7
files Render.cpp SpriteObject.cpp _deleted.cpp mm7_6.cpp mm7_data.h
diffstat 5 files changed, 87 insertions(+), 118 deletions(-) [+]
line wrap: on
line diff
--- a/Render.cpp	Sun Sep 08 19:16:37 2013 +0600
+++ b/Render.cpp	Mon Sep 09 17:17:53 2013 +0200
@@ -6701,8 +6701,11 @@
 
   auto ecx0 = this;
   v3 = 0;
-  if ( ecx0->pRenderD3D )
-  {
+
+  if (!this->pRenderD3D)
+    __debugbreak(); // sw render
+
+  //{
     v4 = a3;
     if ( a3 <= 1.0 )
     {
@@ -6713,6 +6716,7 @@
     {
       v4 = 1.0;
     }
+    __debugbreak(); // banker's rounding again
     a3 = v4 * 255.0;
     v39 = a3 + 6.7553994e15;
     LODWORD(v40) = LODWORD(v39);
@@ -6774,7 +6778,7 @@
     ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
     ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
     ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESS));
-  }
+  /*}
   else
   {
     v40 = (1.0 - a3) * 65536.0;
@@ -6800,7 +6804,7 @@
 
     if ( pRenderer->uTargetGBits == 6 )
     {
-      v17 = _42690D_colors_cvt(this_);
+      v17 = sr_42690D_colors_cvt(this_);
       v18 = (65536 - LODWORD(a3)) * (v17 & 0x1F);
       this_ = (((65536 - LODWORD(a3)) * (unsigned __int16)(v17 & 0xF800) & 0xF800FFFF | v18 & 0x1F0000 | (65536 - LODWORD(a3)) * (v17 & 0x7E0) & 0x7E00000u) >> 16 << 16) | (((65536 - LODWORD(a3)) * (unsigned __int16)(v17 & 0xF800) & 0xF800FFFF | v18 & 0x1F0000 | (65536 - LODWORD(a3)) * (v17 & 0x7E0) & 0x7E00000u) >> 16);
       v19 = v40;
@@ -6831,7 +6835,7 @@
     }
     else
     {
-      v24 = _4268E3_smthn_to_a1r5g5b5(this_);
+      v24 = sr_4268E3_smthn_to_a1r5g5b5(this_);
       v25 = (65536 - LODWORD(a3)) * (v24 & 0x1F);
       this_ = (((65536 - LODWORD(a3)) * (v24 & 0x7C00) & 0x7C000000 | v25 & 0x1F0000 | (65536 - LODWORD(a3))
                                                                                     * (v24 & 0x3E0) & 0x3E00000u) >> 16 << 16) | (((65536 - LODWORD(a3)) * (v24 & 0x7C00) & 0x7C000000 | v25 & 0x1F0000 | (65536 - LODWORD(a3)) * (v24 & 0x3E0) & 0x3E00000u) >> 16);
@@ -6860,7 +6864,7 @@
       }
       while ( v32 != 1 );
     }
-  }
+  }*/
   return result;
 }
 
--- a/SpriteObject.cpp	Sun Sep 08 19:16:37 2013 +0600
+++ b/SpriteObject.cpp	Mon Sep 09 17:17:53 2013 +0200
@@ -82,11 +82,11 @@
     pSpriteObjects[v6].vVelocity.z = 0;
     if ( a4 )
     {
-      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+      v13 = fixpoint_sub0(stru_5C6E00->Cos(angle), stru_5C6E00->Cos(pitch));
+      a5a = fixpoint_sub0(stru_5C6E00->Sin(angle), stru_5C6E00->Cos(pitch));
+      pSpriteObjects[v6].vVelocity.x = fixpoint_sub0(v13, a4);
+      pSpriteObjects[v6].vVelocity.y = fixpoint_sub0(a5a, a4);
+      pSpriteObjects[v6].vVelocity.z = fixpoint_sub0(stru_5C6E00->Sin(pitch), a4);
     }
     else
     {
@@ -107,11 +107,11 @@
     pSpriteObjects[v6].vVelocity.z = 0;
     if ( a4 )
     {
-      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+      v13 = fixpoint_sub0(stru_5C6E00->Cos(angle), stru_5C6E00->Cos(pitch));
+      a5a = fixpoint_sub0(stru_5C6E00->Sin(angle), stru_5C6E00->Cos(pitch));
+      pSpriteObjects[v6].vVelocity.x = fixpoint_sub0(v13, a4);
+      pSpriteObjects[v6].vVelocity.y = fixpoint_sub0(a5a, a4);
+      pSpriteObjects[v6].vVelocity.z = fixpoint_sub0(stru_5C6E00->Sin(pitch), a4);
     }
     else
     {
@@ -132,11 +132,11 @@
     pSpriteObjects[v6].vVelocity.z = 0;
     if ( a4 )
     {
-      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+      v13 = fixpoint_sub0(stru_5C6E00->Cos(angle), stru_5C6E00->Cos(pitch)) >> 16;
+      a5a = fixpoint_sub0(stru_5C6E00->Sin(angle), stru_5C6E00->Cos(pitch)) >> 16;
+      pSpriteObjects[v6].vVelocity.x = fixpoint_sub0(v13, a4);
+      pSpriteObjects[v6].vVelocity.y = fixpoint_sub0(a5a, a4);
+      pSpriteObjects[v6].vVelocity.z = fixpoint_sub0(stru_5C6E00->Sin(pitch), a4);
     }
     else
     {
@@ -157,11 +157,11 @@
     pSpriteObjects[v6].vVelocity.z = 0;
     if ( a4 )
     {
-      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+      v13 = fixpoint_sub0(stru_5C6E00->Cos(angle), stru_5C6E00->Cos(pitch));
+      a5a = fixpoint_sub0(stru_5C6E00->Sin(angle), stru_5C6E00->Cos(pitch));
+      pSpriteObjects[v6].vVelocity.x = fixpoint_sub0(v13, a4);
+      pSpriteObjects[v6].vVelocity.y = fixpoint_sub0(a5a, a4);
+      pSpriteObjects[v6].vVelocity.z = fixpoint_sub0(stru_5C6E00->Sin(pitch), a4);
     }
     else
     {
@@ -182,11 +182,11 @@
     pSpriteObjects[v6].vVelocity.z = 0;
     if ( a4 )
     {
-      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
-      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+      v13 = fixpoint_sub0(stru_5C6E00->Cos(angle), stru_5C6E00->Cos(pitch));
+      a5a = fixpoint_sub0(stru_5C6E00->Sin(angle), stru_5C6E00->Cos(pitch));
+      pSpriteObjects[v6].vVelocity.x = fixpoint_sub0(v13, a4);
+      pSpriteObjects[v6].vVelocity.y = fixpoint_sub0(a5a, a4);
+      pSpriteObjects[v6].vVelocity.z = fixpoint_sub0(stru_5C6E00->Sin(pitch), a4);
     }
     else
     {
@@ -331,9 +331,9 @@
     if ( !(v2->uFlags & OBJECT_DESC_BOUNCE) || (v21 = -v1->vVelocity.z >> 1, v1->vVelocity.z = v21, (signed __int16)v21 < 10) )
       v1->vVelocity.z = 0;
 
-    v1->vVelocity.x = (signed __int16)((unsigned __int64)(58500i64 * (signed __int64)(signed int)v1->vVelocity.x) >> 16);
-    v1->vVelocity.y = (signed __int16)((unsigned __int64)(58500i64 * (signed __int64)(signed int)v1->vVelocity.y) >> 16);
-    v1->vVelocity.z = (signed __int16)((unsigned __int64)(58500i64 * (signed __int64)(signed int)v1->vVelocity.z) >> 16);
+    v1->vVelocity.x = fixpoint_sub0(58500, v1->vVelocity.x);
+    v1->vVelocity.y = fixpoint_sub0(58500, v1->vVelocity.y);
+    v1->vVelocity.z = fixpoint_sub0(58500, v1->vVelocity.z);
 
     if ( (v1->vVelocity.y * v1->vVelocity.y + v1->vVelocity.x * v1->vVelocity.x) < 400 )
         {
@@ -620,12 +620,12 @@
   int v18; // eax@52
   int v19; // ecx@52
   Vec3_short_ *v20; // ecx@53
-  int v21; // ecx@57
+  //int v21; // ecx@57
   __int16 v22; // ax@57
   int v23; // edi@62
-  int v24; // edi@62
-  int v25; // eax@62
-  unsigned __int64 v26; // qax@62
+  //int v24; // edi@62
+  //int v25; // eax@62
+  //unsigned __int64 v26; // qax@62
   unsigned __int8 v27; // sf@64
   unsigned __int8 v28; // of@64
   __int16 v29; // di@67
@@ -641,7 +641,7 @@
   int v39; // [sp+80h] [bp-10h]@33
   Actor *v39b;
   int v40; // [sp+84h] [bp-Ch]@28
-  int v41; // [sp+88h] [bp-8h]@34
+  //int v41; // [sp+88h] [bp-8h]@34
   int v42; // [sp+8Ch] [bp-4h]@4
 
   //uLayingItemID_ = uLayingItemID;
@@ -791,7 +791,7 @@
       pSpriteObject->vPosition.y += fixpoint_sub0(stru_721530.field_7C, stru_721530.direction.y);
       //v40 = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.direction.z) >> 16;
       pSpriteObject->vPosition.z += fixpoint_sub0(stru_721530.field_7C, stru_721530.direction.z);
-      pSpriteObject->uSectorID = LOWORD(stru_721530.uSectorID);
+      pSpriteObject->uSectorID = stru_721530.uSectorID;
       stru_721530.field_70 += stru_721530.field_7C;
       if ( pObject->uFlags & 0x40 && !_46BFFA_check_object_intercept(uLayingItemID, stru_721530.uFaceID) )
         return;
@@ -801,15 +801,8 @@
         v40 = integer_sqrt(pSpriteObject->vVelocity.x * pSpriteObject->vVelocity.x + pSpriteObject->vVelocity.y * pSpriteObject->vVelocity.y);
         v23 = stru_5C6E00->Atan2(pSpriteObject->vPosition.x - pLevelDecorations[v15].vPosition.x,
                 pSpriteObject->vPosition.y - pLevelDecorations[v15].vPosition.y);
-        v42 = stru_5C6E00->Cos(v23);
-        v41 = (unsigned __int64)(v42 * (signed __int64)v40) >> 16;
-        v24 = v23;
-        pSpriteObject->vVelocity.x = (unsigned int)(v42 * v40) >> 16;
-        v25 = stru_5C6E00->Sin(v23);
-        v42 = v25;
-        v26 = v25 * (signed __int64)v40;
-        v41 = v26 >> 16;
-        pSpriteObject->vVelocity.y = WORD1(v26);
+        pSpriteObject->vVelocity.x = fixpoint_sub0(stru_5C6E00->Cos(v23), v40);
+        pSpriteObject->vVelocity.y = fixpoint_sub0(stru_5C6E00->Sin(v23), v40);
       }
       else
       {
@@ -823,25 +816,17 @@
                                                                     + v16->pFacePlane_old.vNormal.y * pSpriteObject->vVelocity.y) >> 16;
           if ( (stru_721530.speed >> 3) > v42 )
             v42 = stru_721530.speed >> 3;
-          v40 = v16->pFacePlane_old.vNormal.x;
-          v40 = (unsigned __int64)(v42 * (signed __int64)v40) >> 16;
-          v41 = v16->pFacePlane_old.vNormal.y;
-          v41 = (unsigned __int64)(v42 * (signed __int64)v41) >> 16;
-          v39 = v16->pFacePlane_old.vNormal.z;
-          v39 = (unsigned __int64)(v42 * (signed __int64)v39) >> 16;
-          pSpriteObject->vVelocity.x += 2 * v40;
-          pSpriteObject->vVelocity.y += 2 * v41;
+          pSpriteObject->vVelocity.x += 2 * fixpoint_sub0(v42, v16->pFacePlane_old.vNormal.x);
+          pSpriteObject->vVelocity.y += 2 * fixpoint_sub0(v42, v16->pFacePlane_old.vNormal.y);
+          v39 = fixpoint_sub0(v42, v16->pFacePlane_old.vNormal.z);
           if ( v16->pFacePlane_old.vNormal.z <= 32000 )
           {
             v22 = 2 * v39;
           }
           else
           {
-            v21 = v39;
-            v40 = 32000;
             pSpriteObject->vVelocity.z += v39;
-            v41 = (unsigned __int64)(v40 * (signed __int64)v21) >> 16;
-            v22 = (unsigned int)(v40 * v21) >> 16;
+            v22 = fixpoint_sub0(32000, v39);
           }
           pSpriteObject->vVelocity.z += v22;
           if ( BYTE3(v16->uAttributes) & 0x10 )
@@ -876,20 +861,12 @@
 LABEL_63:
       //v2 = v37;
 LABEL_64:
-      v41 = pSpriteObject->vVelocity.x;
-      v40 = 58500;
-      v41 = (unsigned __int64)(58500i64 * v41) >> 16;
-      pSpriteObject->vVelocity.x = v41;
-      v41 = pSpriteObject->vVelocity.y;
-      v41 = (unsigned __int64)(v40 * (signed __int64)v41) >> 16;
-      v40 = 58500;
-      pSpriteObject->vVelocity.y = v41;
-      v41 = pSpriteObject->vVelocity.z;
-      v41 = (unsigned __int64)(v40 * (signed __int64)v41) >> 16;
+      pSpriteObject->vVelocity.x = fixpoint_sub0(58500, pSpriteObject->vVelocity.x);
+      pSpriteObject->vVelocity.y = fixpoint_sub0(58500, pSpriteObject->vVelocity.y);
+      pSpriteObject->vVelocity.z = fixpoint_sub0(58500, pSpriteObject->vVelocity.z);
       ++uFaceID;
       v28 = __OFSUB__(uFaceID, 100);
       v27 = uFaceID - 100 < 0;
-      pSpriteObject->vVelocity.z = v41;
       if ( !(v27 ^ v28) )
         return;
       v8 = 0;
@@ -916,18 +893,10 @@
         pSpriteObject->vVelocity.z -= LOWORD(pEventTimer->uTimeElapsed) * GetGravityStrength();
       v8 = 0;
     }
-    v42 = pSpriteObject->vVelocity.x;
-    uFaceID = 58500;
-    v42 = (unsigned __int64)(58500i64 * v42) >> 16;
-    pSpriteObject->vVelocity.x = v42;
-    v42 = pSpriteObject->vVelocity.y;
-    v42 = (unsigned __int64)(uFaceID * (signed __int64)v42) >> 16;
-    uFaceID = 58500;
-    pSpriteObject->vVelocity.y = v42;
-    v42 = pSpriteObject->vVelocity.z;
-    v42 = (unsigned __int64)(uFaceID * (signed __int64)v42) >> 16;
+    pSpriteObject->vVelocity.x = fixpoint_sub0(58500, pSpriteObject->vVelocity.x);
+    pSpriteObject->vVelocity.y = fixpoint_sub0(58500, pSpriteObject->vVelocity.y);
+    pSpriteObject->vVelocity.z = fixpoint_sub0(58500, pSpriteObject->vVelocity.z);
     v9 = pSpriteObject->vVelocity.x;
-    pSpriteObject->vVelocity.z = v42;
     if ( v9 * v9 + pSpriteObject->vVelocity.y * pSpriteObject->vVelocity.y < 400 )
     {
       pSpriteObject->vVelocity.z = v8;
--- a/_deleted.cpp	Sun Sep 08 19:16:37 2013 +0600
+++ b/_deleted.cpp	Mon Sep 09 17:17:53 2013 +0200
@@ -12319,7 +12319,6 @@
   }
   return 0;
 }
-
 //----- (0046271C) --------------------------------------------------------
 void CreateDefaultBLVLevel()
 {
@@ -12344,6 +12343,37 @@
   ofn.lpTemplateName = 0;
   ofn.lpstrFileTitle = pTmpBuf.data();
 }
+//----- (004268E3) --------------------------------------------------------
+int __fastcall sr_4268E3_smthn_to_a1r5g5b5(unsigned int uColor)
+{
+  unsigned int v1; // eax@1
+  unsigned int v2; // edx@1
+  int v3; // eax@1
+  int v4; // edx@1
+  unsigned int v5; // ecx@1
+
+  v1 = uColor >> 9;
+  v2 = uColor >> 6;
+  LOWORD(v1) = (uColor >> 9) & 0x7C00;
+  LOWORD(v2) = (uColor >> 6) & 0x3E0;
+  v3 = v2 | v1;
+  v4 = (unsigned __int8)uColor >> 3;
+  v5 = uColor >> 16;
+  LOWORD(v5) = v5 & 0x8000;
+  return v5 | v4 | v3;
+}
+//----- (0042690D) --------------------------------------------------------
+int __fastcall sr_42690D_colors_cvt(unsigned int a1)
+{
+  unsigned int v1; // eax@1
+  unsigned int v2; // edx@1
+
+  v1 = a1 >> 8;
+  v2 = a1 >> 5;
+  LOWORD(v1) = (a1 >> 8) & 0xF800;
+  LOWORD(v2) = (a1 >> 5) & 0x7E0;
+  return ((unsigned __int8)a1 >> 3) | v2 | v1;
+}
 
 const wchar_t *UIMessage2String(UIMessageType msg)
 {
--- a/mm7_6.cpp	Sun Sep 08 19:16:37 2013 +0600
+++ b/mm7_6.cpp	Mon Sep 09 17:17:53 2013 +0200
@@ -209,38 +209,6 @@
   return result;
 }
 
-//----- (004268E3) --------------------------------------------------------
-int __fastcall _4268E3_smthn_to_a1r5g5b5(unsigned int uColor)
-{
-  unsigned int v1; // eax@1
-  unsigned int v2; // edx@1
-  int v3; // eax@1
-  int v4; // edx@1
-  unsigned int v5; // ecx@1
-
-  v1 = uColor >> 9;
-  v2 = uColor >> 6;
-  LOWORD(v1) = (uColor >> 9) & 0x7C00;
-  LOWORD(v2) = (uColor >> 6) & 0x3E0;
-  v3 = v2 | v1;
-  v4 = (unsigned __int8)uColor >> 3;
-  v5 = uColor >> 16;
-  LOWORD(v5) = v5 & 0x8000;
-  return v5 | v4 | v3;
-}
-
-//----- (0042690D) --------------------------------------------------------
-int __fastcall _42690D_colors_cvt(unsigned int a1)
-{
-  unsigned int v1; // eax@1
-  unsigned int v2; // edx@1
-
-  v1 = a1 >> 8;
-  v2 = a1 >> 5;
-  LOWORD(v1) = (a1 >> 8) & 0xF800;
-  LOWORD(v2) = (a1 >> 5) & 0x7E0;
-  return ((unsigned __int8)a1 >> 3) | v2 | v1;
-}
 
 //----- (00426A5A) --------------------------------------------------------
 void stru319::LootActor(Actor *pActor)
--- a/mm7_data.h	Sun Sep 08 19:16:37 2013 +0600
+++ b/mm7_data.h	Mon Sep 09 17:17:53 2013 +0200
@@ -1122,8 +1122,6 @@
 bool PortalFrustrum(int pNumVertices, struct BspRenderer_PortalViewportData *a2, struct BspRenderer_PortalViewportData *near_portal, int uFaceID);
 int sr_424CD7(unsigned int uVertexID); // idb
 int __fastcall sr_424EE0_MakeFanFromTriangle(unsigned int uVertexID); // idb
-int __fastcall _4268E3_smthn_to_a1r5g5b5(unsigned int uColor); // idb
-int __fastcall _42690D_colors_cvt(unsigned int a1);
 void __fastcall GivePartyExp(unsigned int pEXPNum);
 bool __fastcall sub_427769_spell(unsigned int uSpellID);
 void _42777D_CastSpell_UseWand_ShootArrow(int a1, unsigned int uPlayerID, unsigned int a4, __int16 a5, int a6);