changeset 1641:466c5e15f524

Excess wrapper (IndoorLocation_drawstru) removed.
author Nomad
date Tue, 17 Sep 2013 18:39:32 +0200
parents afc1c3514dd5
children 8971dc85b8fb bd28d08e2c75
files Indoor.cpp Indoor.h IndoorCameraD3D.cpp Render.cpp mm7_3.cpp mm7_data.h
diffstat 6 files changed, 108 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/Indoor.cpp	Tue Sep 17 17:40:59 2013 +0200
+++ b/Indoor.cpp	Tue Sep 17 18:39:32 2013 +0200
@@ -93,7 +93,7 @@
 
 
 //----- (0043F39E) --------------------------------------------------------
-void __fastcall PrepareDrawLists_BLV(IndoorLocation_drawstru *_this)
+void __fastcall PrepareDrawLists_BLV()
 {
   //int *v1; // ecx@1
   //double v2; // ST30_8@3
@@ -108,7 +108,7 @@
   //unsigned __int8 v11; // [sp+1Ch] [bp-4h]@3
   //signed int v12; // [sp+1Ch] [bp-4h]@8
 
-  pBLVRenderParams->Reset(_this);
+  pBLVRenderParams->Reset();
   pMobileLightsStack->uNumLightsActive = 0;
   //uNumMobileLightsApplied = 0;
   uNumDecorationsDrawnThisFrame = 0;
@@ -163,9 +163,9 @@
 
 
 //----- (004407D9) --------------------------------------------------------
-int BLVRenderParams::Reset(IndoorLocation_drawstru *a2)
+void BLVRenderParams::Reset()
 {
-  IndoorLocation_drawstru *v2; // ebx@1
+  //IndoorLocation_drawstru *v2; // ebx@1
   //int v4; // ST08_4@1
   //int v5; // ST04_4@1
   //int v6; // ST00_4@1
@@ -173,12 +173,12 @@
   int v8; // ST08_4@2
   int v9; // ST04_4@2
   int v10; // ST00_4@2
-  unsigned int v11; // edi@4
-  unsigned int v12; // ecx@4
-  int v13; // edx@4
-  signed int v14; // ecx@4
-  unsigned int v15; // edx@4
-  unsigned int v16; // eax@4
+  //unsigned int v11; // edi@4
+  //unsigned int v12; // ecx@4
+  //int v13; // edx@4
+  //signed int v14; // ecx@4
+  //unsigned int v15; // edx@4
+  //unsigned int v16; // eax@4
   double v17; // st7@5
   int v18; // eax@5
   double v19; // st7@5
@@ -190,12 +190,20 @@
   int v25; // eax@5
   int v26; // eax@5
   signed int v27; // eax@6
-  int result; // eax@6
+  //int result; // eax@6
   int v29; // [sp+24h] [bp+8h]@5
 
-  v2 = a2;
-  this->field_0_timer_ = a2->field_0_timer;
-  this->uFlags = a2->uFlags;
+  this->field_0_timer_ = pEventTimer->uTotalGameTimeElapsed;
+
+  this->uFlags = 0;
+  if (viewparams->draw_sw_outlines)
+    this->uFlags |= BLV_RENDER_DRAW_SW_OUTLINES;
+  if (viewparams->draw_d3d_outlines)
+    this->uFlags |= BLV_RENDER_DRAW_D3D_OUTLINES;
+
+  //v2 = a2;
+  //this->field_0_timer_ = a2->field_0_timer;
+  //this->uFlags = a2->uFlags;
   //this->vPartyPos.x = a2->vPosition.x;
   //this->vPartyPos.y = a2->vPosition.y;
   //this->vPartyPos.z = a2->vPosition.z;
@@ -228,17 +236,17 @@
     this->fSineY = sin((3.141592653589793 + 3.141592653589793) * (double)pGame->pIndoorCameraD3D->sRotationY * 0.00048828125);
     this->fCosineNegX = cos((3.141592653589793 + 3.141592653589793) * (double)-pGame->pIndoorCameraD3D->sRotationX * 0.00048828125);
     this->fSineNegX = sin((3.141592653589793 + 3.141592653589793) * (double)-pGame->pIndoorCameraD3D->sRotationX * 0.00048828125);
-    this->field_64 = a2->field_3C;
-    v11 = this->uViewportW;
-    v12 = this->uViewportX;
-    v13 = this->uViewportZ - v12;
-    v14 = this->uViewportZ + v12;
-    this->field_70 = v13 + 1;
-    v15 = this->uViewportY;
-    this->uViewportHeight = v11 - v15 + 1;
-    v16 = this->uViewportW;
-    this->uViewportCenterX = v14 >> 1;
-    this->uViewportCenterY = (signed int)(v16 + v15) >> 1;
+    this->field_64 = pViewport->field_30;
+    
+    this->uViewportX = pViewport->uScreen_TL_X;
+    this->uViewportY = pViewport->uScreen_TL_Y;
+    this->uViewportZ = pViewport->uScreen_BR_X;
+    this->uViewportW = pViewport->uScreen_BR_Y;
+
+    this->uViewportWidth = uViewportZ - uViewportX + 1;
+    this->uViewportHeight = uViewportW - uViewportY + 1;
+    this->uViewportCenterX = (uViewportZ + uViewportX) / 2;
+    this->uViewportCenterY = (uViewportY + uViewportW) / 2;
   }
   else
   {
@@ -268,26 +276,22 @@
     this->uViewportCenterX = (signed int)(v24 + v23) >> 1;
     this->uViewportCenterY = this->uViewportW - ((unsigned __int64)(v26 * (signed __int64)v29) >> 16);*/
   }
-  v27 = (unsigned int)(signed __int64)((double)this->field_70 * 0.5 / tan((double)(v2->field_1C_mb_fov >> 1) * 0.01745329)
-                                     + 0.5) << 16;
-  this->field_40 = v27;
-  this->field_44 = 0x100000000i64 / v27;
-  this->pRenderTarget = v2->pRenderTarget;
-  this->uTargetWidth = v2->uTargetWidth;
-  this->uTargetHeight = v2->uTargetHeight;
-  this->uViewportX = v2->uViewportX;
-  this->uViewportY = v2->uViewportY;
-  this->uViewportZ = v2->uViewportZ;
-  this->uViewportW = v2->uViewportW;
-  this->pTargetZBuffer = v2->pTargetZ;
-  result = 0;
+  //v27 = (unsigned int)(signed __int64)((double)this->uViewportWidth * 0.5
+  //                                             / tan((double)(v2->fov_deg >> 1) * 0.01745329)
+  //                                             + 0.5) << 16;
+  extern float _calc_fov(int viewport_width, int angle_degree);
+  this->fov_rad_fixpoint = fixpoint_from_int(_calc_fov(uViewportWidth, 65), 0);
+  this->fov_rad_inv_fixpoint = 0x100000000i64 / this->fov_rad_fixpoint;
+  this->pRenderTarget = pRenderer->pTargetSurface;
+  this->uTargetWidth = 640;
+  this->uTargetHeight = 480;
+  this->pTargetZBuffer = pRenderer->pActiveZBuffer;
   this->field_8C = 0;
   this->field_84 = 0;
   this->uNumFacesRenderedThisFrame = 0;
   this->field_88 = 0;
   pBLVRenderParams->field_90 = 64;
   pBLVRenderParams->field_94 = 6;
-  return result;
 }
 
 //----- (00440B44) --------------------------------------------------------
@@ -318,6 +322,8 @@
   }
 }
 
+
+/*
 //----- (00440BED) --------------------------------------------------------
 void __fastcall sub_440BED(IndoorLocation_drawstru *_this)
 {
@@ -335,7 +341,7 @@
     IndoorLocation::ExecDraw(pRenderer->pRenderD3D != 0);
   pRenderer->DrawBillboardList_BLV();
 
-/*  if ( !pRenderer->pRenderD3D )
+  if ( !pRenderer->pRenderD3D )
   {
     if (pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_D3D_OUTLINES)
       pBspRenderer->DrawFaceOutlines();
@@ -365,9 +371,9 @@
 		  }
 	  }
     }
-  }*/
+  }
 }
-
+*/
 
 
 
@@ -376,11 +382,11 @@
 void IndoorLocation::Draw()
 {
   //int v0; // eax@1
-  IndoorLocation_drawstru _this; // [sp+0h] [bp-4Ch]@5
+  //IndoorLocation_drawstru _this; // [sp+0h] [bp-4Ch]@5
   int v2; // [sp+44h] [bp-8h]@5
   int v3; // [sp+48h] [bp-4h]@5
 
-  _this.uFlags = 0;
+  /*_this.uFlags = 0;
   if (viewparams->draw_sw_outlines)
     _this.uFlags |= BLV_RENDER_DRAW_SW_OUTLINES;
   if (viewparams->draw_d3d_outlines)
@@ -390,12 +396,12 @@
   _this.uFlags |= BLV_RENDER_DRAW_D3D_OUTLINES;
 
   _this.field_0_timer = pEventTimer->uTotalGameTimeElapsed;
-  _this.field_1C_mb_fov = 65;
-  _this.vPosition.x = pParty->vPosition.x - fixpoint_sub0(stru_5C6E00->Cos(pParty->sRotationY), pParty->y_rotation_granularity);
-  _this.vPosition.y = pParty->vPosition.y - fixpoint_sub0(stru_5C6E00->Sin(pParty->sRotationY), pParty->y_rotation_granularity);
-  _this.vPosition.z = pParty->vPosition.z + pParty->sEyelevel;
-  _this.sRotationX = pParty->sRotationX;
-  _this.sRotationY = pParty->sRotationY;
+  //_this.fov_deg = 65;
+  //_this.vPosition.x = pParty->vPosition.x - fixpoint_sub0(stru_5C6E00->Cos(pParty->sRotationY), pParty->y_rotation_granularity);
+  //_this.vPosition.y = pParty->vPosition.y - fixpoint_sub0(stru_5C6E00->Sin(pParty->sRotationY), pParty->y_rotation_granularity);
+  //_this.vPosition.z = pParty->vPosition.z + pParty->sEyelevel;
+  //_this.sRotationX = pParty->sRotationX;
+  //_this.sRotationY = pParty->sRotationY;
   _this.pRenderTarget = pRenderer->pTargetSurface;
   _this.uViewportX = pViewport->uScreen_TL_X;
   _this.uViewportY = pViewport->uScreen_TL_Y;
@@ -405,8 +411,16 @@
 
   _this.uTargetWidth = 640;
   _this.uTargetHeight = 480;
-  _this.pTargetZ = pRenderer->pActiveZBuffer;
-  sub_440BED(&_this);
+  _this.pTargetZ = pRenderer->pActiveZBuffer;*/
+
+  //sub_440BED(&_this); -- inlined
+  {
+    PrepareDrawLists_BLV();
+    if (pBLVRenderParams->uPartySectorID)
+      IndoorLocation::ExecDraw(pRenderer->pRenderD3D != 0);
+    pRenderer->DrawBillboardList_BLV();
+  }
+
   pParty->uFlags &= ~2;
   pGame->DrawParticles();
   trail_particle_generator.UpdateParticles();
@@ -4584,8 +4598,8 @@
     v0->uIndoorSectorID = a5;
     if ( v29 )
     {
-      LODWORD(v20) = pBLVRenderParams->field_40 << 16;
-      HIDWORD(v20) = pBLVRenderParams->field_40 >> 16;
+      LODWORD(v20) = pBLVRenderParams->fov_rad_fixpoint << 16;
+      HIDWORD(v20) = pBLVRenderParams->fov_rad_fixpoint >> 16;
       v21 = v20 / x;
       v0->_screenspace_x_scaler_packedfloat = (unsigned __int64)(v10->scale * v20 / x) >> 16;
       a5a = (unsigned __int64)(v10->scale * (signed __int64)v21) >> 16;
@@ -5013,8 +5027,8 @@
               v15->uIndoorSectorID = uSectorID;
               if ( v16 )
               {
-                LODWORD(v21) = pBLVRenderParams->field_40 << 16;
-                HIDWORD(v21) = pBLVRenderParams->field_40 >> 16;
+                LODWORD(v21) = pBLVRenderParams->fov_rad_fixpoint << 16;
+                HIDWORD(v21) = pBLVRenderParams->fov_rad_fixpoint >> 16;
                 v37 = v21 / x;
                 //LODWORD(v31) = v12->scale;
                 v37 = v21 / x;
@@ -6636,8 +6650,8 @@
           pScreenY = 0x400000;  // 64.0
       }
     }
-    PortalFace._screen_space_x[i + 12] = pBLVRenderParams->uViewportCenterX - ((unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)pScreenX) >> 16);
-    PortalFace._screen_space_y[i + 12] = pBLVRenderParams->uViewportCenterY - ((unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)pScreenY) >> 16);
+    PortalFace._screen_space_x[i + 12] = pBLVRenderParams->uViewportCenterX - ((unsigned __int64)(SHIWORD(pBLVRenderParams->fov_rad_fixpoint) * (signed __int64)pScreenX) >> 16);
+    PortalFace._screen_space_y[i + 12] = pBLVRenderParams->uViewportCenterY - ((unsigned __int64)(SHIWORD(pBLVRenderParams->fov_rad_fixpoint) * (signed __int64)pScreenY) >> 16);
   }
   // результат: при повороте камеры, когда граница портала сдвигается к краю экрана, портал остается прозрачным(видимым)
   //******************************************************************************************************************************************
--- a/Indoor.h	Tue Sep 17 17:40:59 2013 +0200
+++ b/Indoor.h	Tue Sep 17 18:39:32 2013 +0200
@@ -468,51 +468,24 @@
 
 
 
+
 #define BLV_RENDER_DRAW_SW_OUTLINES  1
 #define BLV_RENDER_DRAW_D3D_OUTLINES 2
 
-/*  263 */
-#pragma pack(push, 1)
-struct IndoorLocation_drawstru
-{
-  int field_0_timer;
-  int uFlags;              // & INDOOR_CAMERA_DRAW_D3D_OUTLINES:  render d3d outlines
-  Vec3_int_ vPosition;
-  int sRotationY;
-  int sRotationX;
-  int field_1C_mb_fov;
-  unsigned __int16 *pRenderTarget;
-  unsigned int uTargetWidth;
-  unsigned int uTargetHeight;
-  signed int uViewportX;
-  signed int uViewportY;
-  signed int uViewportZ;
-  signed int uViewportW;
-  int field_3C;
-  int *pTargetZ;
-};
-#pragma pack(pop)
-
-
-
-
-
-
-
-
-
-
-
-
 /*  162 */
 #pragma pack(push, 1)
 struct BLVRenderParams
 {
   inline BLVRenderParams():
     uFlags(0)
-  {}
+  {
+    uViewportX = 0;
+    uViewportY = 0;
+    uViewportZ = 0;
+    uViewportW = 0;
+  }
 
-  int Reset(struct IndoorLocation_drawstru *a2);
+  void Reset();
 
   int field_0_timer_;
   int uFlags;              // & INDOOR_CAMERA_DRAW_D3D_OUTLINES:  render d3d outlines
@@ -528,8 +501,8 @@
   float fSineY;
   float fCosineNegX;
   float fSineNegX;
-  int field_40;
-  int field_44;//float
+  int fov_rad_fixpoint;
+  int fov_rad_inv_fixpoint;//float
   unsigned __int16 *pRenderTarget;
   unsigned int uTargetWidth;
   unsigned int uTargetHeight;
@@ -540,7 +513,7 @@
   int field_64;
   int *pTargetZBuffer;
   int uViewportHeight;
-  int field_70;
+  int uViewportWidth;
   int uViewportCenterX;
   int uViewportCenterY;
   struct BspRenderer_PortalViewportData *field_7C;
--- a/IndoorCameraD3D.cpp	Tue Sep 17 17:40:59 2013 +0200
+++ b/IndoorCameraD3D.cpp	Tue Sep 17 18:39:32 2013 +0200
@@ -12,6 +12,14 @@
 #include "stru9.h"
 
 
+// calculates FOV (Field of View) angle in radians for IndoorCamera::Initialize and BLVRenderParams::Reset
+float _calc_fov(int viewport_width, int angle_degree)
+{
+  return viewport_width * 0.5 / tan(angle_degree / 2 * 0.01745329) + 0.5;
+}
+
+
+
 //----- (004361EF) --------------------------------------------------------
 IndoorCameraD3D::IndoorCameraD3D()
 {
@@ -1535,17 +1543,17 @@
     //v8 = a2b + 6.7553994e15;
     *a6 = pViewport->uViewportBR_Y - floorf(a2b + 0.5f);
   }
-  else
+  /*else
   {
-    LODWORD(v9) = pBLVRenderParams->field_40 << 16;
-    HIDWORD(v9) = pBLVRenderParams->field_40 >> 16;
+    LODWORD(v9) = pBLVRenderParams->fov_rad_fixpoint << 16;
+    HIDWORD(v9) = pBLVRenderParams->fov_rad_fixpoint >> 16;
     v10 = v9 / x;
-    LODWORD(v9) = pBLVRenderParams->field_40 << 16;
-    HIDWORD(v9) = pBLVRenderParams->field_40 >> 16;
+    LODWORD(v9) = pBLVRenderParams->fov_rad_fixpoint << 16;
+    HIDWORD(v9) = pBLVRenderParams->fov_rad_fixpoint >> 16;
     *a5 = pBLVRenderParams->uViewportCenterX
         - ((signed int)(((unsigned __int64)(v10 * (signed __int64)y) >> 16) + 32768) >> 16);
     *a6 = pBLVRenderParams->uViewportCenterY - ((signed int)(((unsigned __int64)(v9 / x * z) >> 16) + 32768) >> 16);
-  }
+  }*/
 }
 
 //----- (00436A6D) --------------------------------------------------------
--- a/Render.cpp	Tue Sep 17 17:40:59 2013 +0200
+++ b/Render.cpp	Tue Sep 17 18:39:32 2013 +0200
@@ -5124,15 +5124,15 @@
   HIDWORD(v69) = pGame->pIndoorCameraD3D->sRotationX;
   HIDWORD(v68) = pGame->pIndoorCameraD3D->vPartyPos.z;
   *(float *)&v74 = (double)pBLVRenderParams->uViewportCenterY;
-  v70 = (signed __int64)((double)(pBLVRenderParams->field_40 * pGame->pIndoorCameraD3D->vPartyPos.z)
-                       / (((double)pBLVRenderParams->field_40 + 16192.0)
+  v70 = (signed __int64)((double)(pBLVRenderParams->fov_rad_fixpoint * pGame->pIndoorCameraD3D->vPartyPos.z)
+                       / (((double)pBLVRenderParams->fov_rad_fixpoint + 16192.0)
                         * 65536.0)
                        + *(float *)&v74);
   v5 = (double)pGame->pIndoorCameraD3D->sRotationX * 0.0030664064;
   *(float *)&v75 = v5;
   v80 = cos(v5) * 16192.0;
   v6 = (signed __int64)(*(float *)&v74
-                      - (double)pBLVRenderParams->field_40
+                      - (double)pBLVRenderParams->fov_rad_fixpoint
                       / ((v80 + 0.0000001)
                        * 65535.0)
                       * (sin(*(float *)&v75) * -16192.0 - (double)SHIDWORD(v68)));
--- a/mm7_3.cpp	Tue Sep 17 17:40:59 2013 +0200
+++ b/mm7_3.cpp	Tue Sep 17 18:39:32 2013 +0200
@@ -4177,7 +4177,7 @@
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
   {
     v10 = 16192.0;
-    v3 = (double)pBLVRenderParams->field_40 * 0.000015258789;
+    v3 = (double)pBLVRenderParams->fov_rad_fixpoint * 0.000015258789;
   }
   else
   {
@@ -4236,7 +4236,7 @@
   {
 	for(int i = 0; i < a1->uNumVertices; i++)
     {
-		v6 = (double)pBLVRenderParams->field_40 * 0.000015258789 / a1->field_B4[i*4];
+		v6 = (double)pBLVRenderParams->fov_rad_fixpoint * 0.000015258789 / a1->field_B4[i*4];
 		if ( pRenderer->pRenderD3D )
 		{
 			pGame->pIndoorCameraD3D->Project(
@@ -5571,16 +5571,11 @@
     //pIndoorCamera->Initialize(65, viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X + 1,
     //                              viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y + 1);
 
-    int degFov = 65;
     int uViewportWidth = viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X + 1;
-    int uViewportHeight = viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y + 1;
-
-    double v5 = (double)(signed int)(signed __int64)((double)(signed int)uViewportWidth
-                                          * 0.5
-                                          / tan((double)(degFov >> 1) * 0.01745329)
-                                          + 0.5);
-    fov_rad = v5;
-    fov_rad_inv = 65536.0 / v5;
+
+    extern float _calc_fov(int viewport_width, int angle_degree);
+    fov_rad = _calc_fov(uViewportWidth, 65);
+    fov_rad_inv = 65536.0 / fov_rad;
   }
   pODMRenderParams->int_fov_rad = (signed __int64)fov_rad;
   pODMRenderParams->int_fov_rad_inv = (signed __int64)fov_rad_inv;
--- a/mm7_data.h	Tue Sep 17 17:40:59 2013 +0200
+++ b/mm7_data.h	Tue Sep 17 18:39:32 2013 +0200
@@ -3,16 +3,12 @@
 #include "VectorTypes.h"
 #include "OSAPI.h"
 #include <array>
+
 typedef char _UNKNOWN;
-
-
-
 typedef unsigned int uint;
 
 
 
-#define COERCE_UNSIGNED_INT64(a) (__debugbreak(), a)
-
 
 
 
@@ -1145,7 +1141,7 @@
 bool  ShouldLoadTexturesForRaceAndGender(unsigned int _this);
 void WetsuitOn(unsigned int uPlayerID); // idb
 void WetsuitOff(unsigned int uPlayerID);
-void __fastcall PrepareDrawLists_BLV(struct IndoorLocation_drawstru *_this);
+void __fastcall PrepareDrawLists_BLV();
 void FindBillboardsLightLevels_BLV();
 int __fastcall _43F55F_get_billboard_light_level(struct RenderBillboard *a1, int uBaseLightLevel);
 int __fastcall _43F5C8_get_point_light_level_with_respect_to_lights(unsigned int uBaseLightLevel, int uSectorID, float x, float y, float z);
@@ -1155,7 +1151,6 @@
 void PrepareItemsRenderList_BLV();
 void AddBspNodeToRenderList(unsigned int node_id);
 void __fastcall sub_4406BC(unsigned int node_id, unsigned int uFirstNode); // idb
-void __fastcall sub_440BED(struct IndoorLocation_drawstru *_this);
 bool sub_44100D();
 __int16 __fastcall sub_441A4E(int a1);
 void DrawBook_Map_sub(unsigned int tl_x, unsigned int tl_y, unsigned int br_x, int br_y, int _48074); // idb