diff stru6.cpp @ 45:bcc051713d20

BLV render & seffects
author Nomad
date Mon, 22 Oct 2012 20:45:14 +0200
parents 509744251c8e
children 5159d2e6f559
line wrap: on
line diff
--- a/stru6.cpp	Sun Oct 21 23:26:23 2012 +0600
+++ b/stru6.cpp	Mon Oct 22 20:45:14 2012 +0200
@@ -88,92 +88,61 @@
 {
   int v8; // eax@1
 
-  v8 = this->uNumProjectiles;
+  v8 = uNumProjectiles;
   if ( v8 != 32 )
   {
-    this->pProjectiles[v8].srcX = srcX;
-    *((float *)&this->array_0[0].uSpellAnimLength + 7 * (this->uNumProjectiles + 21)) = srcY;
-    this->pProjectiles[this->uNumProjectiles].srcZ = srcZ;
-    this->pProjectiles[this->uNumProjectiles].dstX = dstX;
-    this->pProjectiles[this->uNumProjectiles].dstY = dstY;
-    this->pProjectiles[this->uNumProjectiles].dstZ = dstZ;
-    this->pProjectiles[this->uNumProjectiles++].uTextureID = uTextureID;
+    pProjectiles[v8].srcX = srcX;
+    *((float *)&this->array_0[0].uSpellAnimLength + 7 * (uNumProjectiles + 21)) = srcY;
+    pProjectiles[uNumProjectiles].srcZ = srcZ;
+    pProjectiles[uNumProjectiles].dstX = dstX;
+    pProjectiles[uNumProjectiles].dstY = dstY;
+    pProjectiles[uNumProjectiles].dstZ = dstZ;
+    pProjectiles[uNumProjectiles++].uTextureID = uTextureID;
   }
 }
 
 //----- (004A7298) --------------------------------------------------------
-int stru6::DrawProjectiles()
+void stru6::DrawProjectiles()
 {
-  stru6 *v1; // ebx@1
-  char *v2; // eax@1
-  signed int v3; // ecx@1
-  unsigned __int8 v4; // zf@3
-  unsigned __int8 v5; // sf@3
-  IndoorCameraD3D *v6; // edi@3
-  int result; // eax@3
-  int v8; // esi@4
-  int v9; // eax@5
   float v10; // ST1C_4@8
   float v11; // ST0C_4@8
   IDirect3DTexture2 *v12; // [sp+20h] [bp-78h]@6
-  RenderVertexSoft v13[2]; // [sp+30h] [bp-68h]@1
-  float v14; // [sp+90h] [bp-8h]@3
-  int v15; // [sp+94h] [bp-4h]@3
-
-  v1 = this;
-  v2 = (char *)&v13[0].flt_2C;
-  v3 = 2;
-  do
-  {
-    *(float *)v2 = 0.0;
-    v2 += 48;
-    --v3;
-  }
-  while ( v3 );
-  v15 = 0;
-  v4 = v1->uNumProjectiles == 0;
-  v5 = v1->uNumProjectiles < 0;
-  v6 = pGame->pIndoorCameraD3D;
-  result = LODWORD(v6->flt_D0);
-  v14 = v6->flt_D0;
-  if ( !(v5 | v4) )
+  RenderVertexSoft v[2]; // [sp+30h] [bp-68h]@1
+  
+  for (uint i = 0; i < uNumProjectiles; ++i)
   {
-    v8 = (int)&v1->pProjectiles[0].srcY;
-    do
-    {
-      v13[0].vWorldPosition.x = *(float *)(v8 - 4);
-      v13[0].vWorldPosition.y = *(float *)v8;
-      v13[0].vWorldPosition.z = *(float *)(v8 + 4);
-      v13[1].vWorldPosition.x = *(float *)(v8 + 8);
-      v13[1].vWorldPosition.y = *(float *)(v8 + 12);
-      v13[1].vWorldPosition.z = *(float *)(v8 + 16);
-      v6->ViewTransform(v13, 2u);
-      sr_42620A(v13);
-      v6->_436BB7_project_and_stuff(v13, 2u, 0);
-      v9 = *(int *)(v8 + 20);
-      if ( v9 == -1 )
-        v12 = 0;
-      else
-        v12 = pBitmaps_LOD->pHardwareTextures[v9];
-      v10 = v14 / v13[1].vWorldViewPosition.x * 20.0;
-      v11 = v14 / v13[0].vWorldViewPosition.x * 20.0;
-      pRenderer->DrawProjectile(
-        v13[0].vWorldViewProjX,
-        v13[0].vWorldViewProjY,
-        v13[0].vWorldViewPosition.x,
-        v11,
-        v13[1].vWorldViewProjX,
-        v13[1].vWorldViewProjY,
-        v13[1].vWorldViewPosition.x,
-        v10,
-        v12);
-      ++v15;
-      v8 += 28;
-      result = v15;
-    }
-    while ( v15 < v1->uNumProjectiles );
-  }
-  return result;
+    auto p = pProjectiles + i;
+
+    v[0].vWorldPosition.x = p->srcX;
+    v[0].vWorldPosition.y = p->srcY;
+    v[0].vWorldPosition.z = p->srcZ;
+    v[1].vWorldPosition.x = p->dstX;
+    v[1].vWorldPosition.y = p->dstY;
+    v[1].vWorldPosition.z = p->dstZ;
+    pGame->pIndoorCameraD3D->ViewTransform(v, 2);
+
+    sr_42620A(v);
+
+    pGame->pIndoorCameraD3D->_436BB7_project_and_stuff(v, 2, 0);
+
+    if (p->uTextureID != -1)
+      v12 = pBitmaps_LOD->pHardwareTextures[p->uTextureID];
+    else
+      v12 = 0;
+
+    v10 = pGame->pIndoorCameraD3D->flt_D0 / v[1].vWorldViewPosition.x * 20.0;
+    v11 = pGame->pIndoorCameraD3D->flt_D0 / v[0].vWorldViewPosition.x * 20.0;
+    pRenderer->DrawProjectile(
+        v[0].vWorldViewProjX,
+        v[0].vWorldViewProjY,
+        v[0].vWorldViewPosition.x,
+         v11,
+        v[1].vWorldViewProjX,
+        v[1].vWorldViewProjY,
+        v[1].vWorldViewPosition.x,
+         v10,
+         v12);
+   }
 }
 
 //----- (004A73AA) --------------------------------------------------------
@@ -207,7 +176,7 @@
     local_0.flt_10 = 0.0;
     local_0.flt_14 = 0.0;
     local_0.flt_18 = 0.0;
-    local_0.field_20 = (rand() & 0x40) + 96;
+    local_0.timeToLive = (rand() & 0x40) + 96;
     local_0.uTextureID = uTextureID;
     local_0.flt_28 = 1.0;
     pGame->pParticleEngine->AddParticle(&local_0);
@@ -239,7 +208,7 @@
     local_0.flt_14 = 0.0;
     local_0.flt_18 = 0.0;
     local_0.flt_28 = 1.0;
-    local_0.field_20 = (rand() & 0x7F) + 128;
+    local_0.timeToLive = (rand() & 0x7F) + 128;
     local_0.uTextureID = uTextureID;
     pGame->pParticleEngine->AddParticle(&local_0);
     local_0.x = (double)a2->vPosition.x - 4.0;
@@ -262,7 +231,7 @@
   local_0.uDiffuse = uDiffuse;
   local_0.z = v4;
   v5 = 10;
-  local_0.field_20 = (rand() & 0x7F) + 128;
+  local_0.timeToLive = (rand() & 0x7F) + 128;
   local_0.uTextureID = uTextureID;
   local_0.flt_28 = 1.0;
   do
@@ -312,7 +281,7 @@
   local_0.x = v5;
   local_0.y = (double)a2->vPosition.y;
   local_0.z = (double)a2->vPosition.z;
-  local_0.field_20 = (rand() & 0x7F) + 128;
+  local_0.timeToLive = (rand() & 0x7F) + 128;
   local_0.uTextureID = pBitmaps_LOD->LoadTexture("effpar01", TEXTURE_DEFAULT);
   i = 10;
   local_0.flt_28 = 1.0;
@@ -388,7 +357,7 @@
   v4 = (double)a1->vPosition.y;
   local_0.bFree = 2048;
   local_0.uDiffuse = 0x7F7F7Fu;
-  local_0.field_20 = 1;
+  local_0.timeToLive = 1;
   local_0.y = v4;
   local_0.z = (double)a1->vPosition.z;
   local_0.flt_10 = 0.0;
@@ -422,7 +391,7 @@
   v5 = rand();
   v6 = 10;
   Dst.flt_28 = 1.0;
-  Dst.field_20 = (v5 & 0x7F) + 128;
+  Dst.timeToLive = (v5 & 0x7F) + 128;
   do
   {
     Dst.flt_10 = (double)(rand() & 0x1FF) - 255.0;
@@ -475,7 +444,7 @@
   v6 = rand();
   local_0.flt_28 = 1.0;
   v7 = 0.0 * a4;
-  local_0.field_20 = (v6 & 0x7F) + 128;
+  local_0.timeToLive = (v6 & 0x7F) + 128;
   local_0.uTextureID = uTextureID;
   a1a = v7;
   local_0.flt_10 = v7;
@@ -557,7 +526,7 @@
     local_0.flt_18 = 0.0;
     v10 = rand();
     LODWORD(local_0.flt_28) = 0x40400000u;
-    local_0.field_20 = (v10 & 0x3F) + 64;
+    local_0.timeToLive = (v10 & 0x3F) + 64;
     local_0.uTextureID = pSpriteFrameTable->GetFrame(v5->uSpriteID, v3->uSpriteFrameID)->pHwSpriteIDs[0];
     pGame->pParticleEngine->AddParticle(&local_0);
     v11 = (double)v3->vPosition.x;
@@ -565,7 +534,7 @@
     local_0.x = v11;
     local_0.y = (double)v3->vPosition.y;
     local_0.z = (double)v3->vPosition.z;
-    local_0.field_20 = (rand() & 0x3F) + 64;
+    local_0.timeToLive = (rand() & 0x3F) + 64;
     pGame->pParticleEngine->AddParticle(&local_0);
     v2->array_0[v3->field_54 & 0x1F].flt_4 = (double)v3->vPosition.x;
     v2->array_0[v3->field_54 & 0x1F].flt_8 = (double)v3->vPosition.y;
@@ -587,7 +556,7 @@
     local_0.flt_10 = 0.0;
     local_0.flt_14 = 0.0;
     local_0.flt_18 = 0.0;
-    local_0.field_20 = (rand() & 0x3F) + 64;
+    local_0.timeToLive = (rand() & 0x3F) + 64;
     local_0.uTextureID = pSpriteFrameTable->GetFrame(v5->uSpriteID, a2->uSpriteFrameID)->pHwSpriteIDs[0];
     pGame->pParticleEngine->AddParticle(&local_0);
   }
@@ -637,7 +606,7 @@
 
   memset(&Dst, 0, 0x68u);
   Dst.bFree = 1036;
-  Dst.field_20 = (rand() & 0x7F) + 128;
+  Dst.timeToLive = (rand() & 0x7F) + 128;
   v3 = pActor;
   Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar02", TEXTURE_DEFAULT);
   pActora = 50;
@@ -687,7 +656,7 @@
   v5 = rand();
   local_0.flt_28 = 1.0;
   v6 = 8;
-  local_0.field_20 = (v5 & 0x7F) + 128;
+  local_0.timeToLive = (v5 & 0x7F) + 128;
   v7 = v4->uTextureID_effpar1;
   v12 = (double)x;
   local_0.uTextureID = v7;
@@ -752,7 +721,7 @@
   memset(&local_0, 0, 0x68u);
   local_0.bFree = 1029;
   local_0.uDiffuse = 0x7E7E7Eu;
-  local_0.field_20 = (rand() & 0x7F) + 128;
+  local_0.timeToLive = (rand() & 0x7F) + 128;
   local_0.uTextureID = v2->uTextureID_effpar1;
   v3 = 8;
   local_0.flt_28 = 1.0;
@@ -1489,11 +1458,8 @@
 }
 
 //----- (004A8C27) --------------------------------------------------------
-HRESULT stru6::RenderSpecialEffects()
+void stru6::RenderSpecialEffects()
 {
-  stru6 *v1; // ebx@1
-  int *v2; // edi@1
-  HRESULT result; // eax@3
   double v4; // st7@4
   double v5; // st6@4
   double v6; // st7@4
@@ -1518,41 +1484,36 @@
   SpriteFrame *v70; // [sp+E4h] [bp-8h]@8
   unsigned int v26; // [sp+E8h] [bp-4h]@3
 
-  //by the time we first get in this function, dword_0005D4  is still not initialized in the original exe
-  //maybe the following code in never executed at all
-
-  v1 = this;
-  v2 = &this->uNumProjectiles;
-  if ( this->uNumProjectiles )
+  if (uNumProjectiles)
   {
     DrawProjectiles();
-    *v2 = 0;
+    uNumProjectiles = 0;
   }
-  result = v1->uFadeTime;
-  v1->field_204 = 0;
-  v26 = result;
-  if ( result > 0 )
+
+  field_204 = 0;
+  v26 = uFadeTime;
+  if ( v26 > 0 )
   {
-    v4 = (double)(signed int)v26 / (double)v1->uFadeTime2;
+    v4 = (double)(signed int)v26 / (double)uFadeTime2;
     v5 = 1.0 - v4 * v4;
     v6 = v5;
     if ( v5 > 0.9 )
       v6 = 1.0 - (v5 - 0.9) * 10.0;
     v7 = v6;
-    pRenderer->_4A52F1(v1->uFadeColor, v7);
-    result = pEventTimer->uTimeElapsed;
-    v1->uFadeTime -= pEventTimer->uTimeElapsed;
+    pRenderer->_4A52F1(uFadeColor, v7);
+    uFadeTime -= pEventTimer->uTimeElapsed;
   }
-  if ( v1->uAnimLength > 0 )
+
+  if (uAnimLength > 0)
   {
     v8 = 8
        * pSpriteFrameTable->pSpriteSFrames[pSpriteFrameTable->FastFindSprite("spell84")].uAnimLength
-       - v1->uAnimLength;
+       - uAnimLength;
     v9 = pSpriteFrameTable->FastFindSprite("spell84");
     v10 = pSpriteFrameTable->GetFrame(v9, v8);
     v11 = v10->pHwSpriteIDs[0];
     v70 = v10;
-    v1->uAnimLength -= pEventTimer->uTimeElapsed;
+    uAnimLength -= pEventTimer->uTimeElapsed;
     if ( pRenderer->pRenderD3D )
     {
       v12 = (double)(signed int)pViewport->uViewportX;
@@ -1615,15 +1576,15 @@
       pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0);
       pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true);
       pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, true);
-      result = pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2);
     }
     else
     {
       vsr.pTarget = pRenderer->pTargetSurface;
       vsr.uParentBillboardID = -1;
       vsr.pTargetZ = pRenderer->pActiveZBuffer;
-      vsr.field_8 = (signed int)(pViewport->uViewportZ - pViewport->uViewportX) / 2;
-      vsr.field_C = pViewport->uViewportW;
+      vsr.uScreenSpaceX = (signed int)(pViewport->uViewportZ - pViewport->uViewportX) / 2;
+      vsr.uScreenSpaceY = pViewport->uViewportW;
       v24 = 16777216;
       LODWORD(v18) = 0;
       HIDWORD(v18) = (signed __int16)(LOWORD(pViewport->uViewportZ) - LOWORD(pViewport->uViewportX));
@@ -1638,15 +1599,13 @@
       vsr.uViewportX = pViewport->uViewportX;
       vsr.uViewportZ = pViewport->uViewportZ;
       vsr.uViewportY = pViewport->uViewportY;
-      result = pViewport->uViewportW;
-      vsr.field_28 = 0;
+      vsr.sZValue = 0;
       vsr.uViewportW = pViewport->uViewportW;
       vsr.uFlags = 0;
       if ( v11 >= 0 )
-        result = pSprites_LOD->pSpriteHeaders[v11]._4ACC38(&vsr, 1);
+        pSprites_LOD->pSpriteHeaders[v11]._4ACC38(&vsr, 1);
     }
   }
-  return result;
 }
 
 //----- (004A902A) --------------------------------------------------------