changeset 734:2f4e33c1ed24

stru154
author Nomad
date Fri, 22 Mar 2013 16:16:40 +0200
parents 700b58aac975
children 6daaa2f18d0d cd9ae9a2c99c
files Game.h Indoor_stuff.h Render.cpp mm7_2.cpp mm7_3.cpp mm7_4.cpp
diffstat 6 files changed, 114 insertions(+), 180 deletions(-) [+]
line wrap: on
line diff
--- a/Game.h	Fri Mar 22 13:24:12 2013 +0200
+++ b/Game.h	Fri Mar 22 16:16:40 2013 +0200
@@ -34,7 +34,7 @@
   GAME_STATE_NEWGAME_OUT_GAMEMENU = 0x4,
   GAME_STATE_5 = 0x5,
   GAME_STATE_6 = 0x6,
-  GAME_STATE_7 = 0x7,
+  GAME_STATE_GAME_QUITTING_TO_MAIN_MENU = 7,
   GAME_STATE_8 = 0x8,
   GAME_STATE_FINAL_WINDOW = 0x9,
   GAME_STATE_A = 0xA
--- a/Indoor_stuff.h	Fri Mar 22 13:24:12 2013 +0200
+++ b/Indoor_stuff.h	Fri Mar 22 16:16:40 2013 +0200
@@ -385,9 +385,9 @@
   inline ~stru154()
   {}
 
-  int _49B04D(struct ODMFace *a2, struct BSPVertexBuffer *a3);
-  int _49B0C9(struct Vec3_float_ *pNormal, float dist);
-  int _49B13D(struct ODMFace *pFace, struct BSPVertexBuffer *pVertices, struct Vec3_float_ *a3, float *a4);
+  void GetFacePlaneAndClassify(struct ODMFace *a2, struct BSPVertexBuffer *a3);
+  void ClassifyPolygon(struct Vec3_float_ *pNormal, float dist);
+  void GetFacePlane(struct ODMFace *pFace, struct BSPVertexBuffer *pVertices, struct Vec3_float_ *pOutNormal, float *pOutDist);
 
 
   void (__thiscall ***vdestructor_ptr)(stru154 *, bool);
--- a/Render.cpp	Fri Mar 22 13:24:12 2013 +0200
+++ b/Render.cpp	Fri Mar 22 16:16:40 2013 +0200
@@ -2150,7 +2150,7 @@
               v33 = 3;
             else
               v33 = v108 != 0 ? 5 : 0;
-            static_sub_0048034E_stru_154._49B0C9(v23, v95);
+            static_sub_0048034E_stru_154.ClassifyPolygon(v23, v95);
             if ( pDecalBuilder->uNumDecals > 0 )
               pDecalBuilder->ApplyDecals(31 - v16->dimming_level, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1);
           }
@@ -2295,7 +2295,7 @@
         else
           pVertices = (RenderVertexSoft *)(v108 != 0 ? 5 : 0);
         //a8 = (RenderVertexSoft *)(this_3a ? 3 : v108 != 0 ? 5 : 0);
-        static_sub_0048034E_stru_76D590._49B0C9(v48, *(float *)&a4);
+        static_sub_0048034E_stru_76D590.ClassifyPolygon(v48, *(float *)&a4);
         if ( pDecalBuilder->uNumDecals > 0 )
           pDecalBuilder->ApplyDecals(31 - v40->dimming_level, 4, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices, -1);
       }
@@ -2418,7 +2418,7 @@
           v70 = 3;
         else
           v70 = v108 != 0 ? 5 : 0;
-        static_sub_0048034E_stru_76D578._49B0C9(v63, v87);
+        static_sub_0048034E_stru_76D578.ClassifyPolygon(v63, v87);
         if ( pDecalBuilder->uNumDecals > 0 )
           pDecalBuilder->ApplyDecals(31 - v40->dimming_level, 4, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70, -1);
       }
--- a/mm7_2.cpp	Fri Mar 22 13:24:12 2013 +0200
+++ b/mm7_2.cpp	Fri Mar 22 16:16:40 2013 +0200
@@ -10076,9 +10076,15 @@
   uCPUSpeed = 2048; // about 2GHz
 
 
-  if (MM7_Initialize())
-  {
-    Log::Warning(L"MM init: ok");
+  if (!MM7_Initialize())
+  {
+    Log::Warning(L"MM init: failed");
+    pGame->Deinitialize();
+    return 1;
+  }
+
+
+  Log::Warning(L"MM init: ok");
 
     pEventTimer->Pause();
     if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
@@ -10207,7 +10213,7 @@
           uGameState = 0;
           continue;
         }
-        if ( uGameState == 7 )
+        if ( uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)
           __debugbreak();
         /*{
           pAudioPlayer->StopChannels(-1, -1);
@@ -10224,11 +10230,9 @@
         AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
       }
     }
-  }
-  else
-    Log::Warning(L"MM init: failed");
+
   pGame->Deinitialize();
-return 1;
+  return 1;
 }
 
 
--- a/mm7_3.cpp	Fri Mar 22 13:24:12 2013 +0200
+++ b/mm7_3.cpp	Fri Mar 22 16:16:40 2013 +0200
@@ -4870,7 +4870,7 @@
         if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
         {
           v31 = (LightmapBuilder *)(v50 ? 3 : v49 != 0 ? 5 : 0);
-          static_RenderBuildingsD3D_stru_73C834._49B04D(pFace, (BSPVertexBuffer *)v56 - 1);
+          static_RenderBuildingsD3D_stru_73C834.GetFacePlaneAndClassify(pFace, (BSPVertexBuffer *)v56 - 1);
           if ( pDecalBuilder->uNumDecals > 0 )
           {
             v40 = -1;
@@ -5243,7 +5243,7 @@
           v35 = (BSPVertexBuffer *)(v78 - 2);
           v12->field_108 = 1;
 
-          static_sub_004789DE_stru_73C818._49B04D((ODMFace *)v3, v35);
+          static_sub_004789DE_stru_73C818.GetFacePlaneAndClassify((ODMFace *)v3, v35);
           v55 = static_sub_004789DE_stru_73C818.face_plane.vNormal.x;
           v56 = static_sub_004789DE_stru_73C818.face_plane.vNormal.y;
           v57 = static_sub_004789DE_stru_73C818.face_plane.vNormal.z;
--- a/mm7_4.cpp	Fri Mar 22 13:24:12 2013 +0200
+++ b/mm7_4.cpp	Fri Mar 22 16:16:40 2013 +0200
@@ -4770,204 +4770,134 @@
 
 
 //----- (0049B04D) --------------------------------------------------------
-int stru154::_49B04D(ODMFace *a2, BSPVertexBuffer *a3)
+void stru154::GetFacePlaneAndClassify(ODMFace *a2, BSPVertexBuffer *a3)
 {
-  stru154 *v3; // edi@1
-  signed int v4; // eax@1
-  signed int result; // eax@9
-  signed int v6; // [sp-8h] [bp-18h]@8
+  //stru154 *v3; // edi@1
+  //signed int v4; // eax@1
+  //signed int result; // eax@9
+  //signed int v6; // [sp-8h] [bp-18h]@8
   Vec3_float_ v; // [sp+4h] [bp-Ch]@1
+  float v7;
 
   v.x = 0.0;
-  v3 = this;
   v.y = 0.0;
   v.z = 0.0;
-  _49B13D(a2, a3, &v, (float *)&a3);
-  v4 = 2;
-  if ( a2->pFacePlane.vNormal.z )
-  {
-    if ( !a2->pFacePlane.vNormal.x && !a2->pFacePlane.vNormal.y )
-      v4 = 1;
-  }
+  GetFacePlane(a2, a3, &v, &v7);
+
+  if (fabsf(a2->pFacePlane.vNormal.z) < 1e-6f)
+    polygonType = POLYGON_VerticalWall;
+  else if (fabsf(a2->pFacePlane.vNormal.x) < 1e-6f &&
+           fabsf(a2->pFacePlane.vNormal.y) < 1e-6f)
+    polygonType = POLYGON_Floor;
   else
-  {
-    v4 = 0;
-  }
-  if ( v4 )
-  {
-    if ( v4 == 1 )
-      v6 = 3;
-    else
-      v6 = 4;
-    result = v6;
-  }
-  else
-  {
-    result = 1;
-  }
-  v3->face_plane.vNormal.x = v.x;
-  v3->face_plane.vNormal.y = v.y;
-  v3->face_plane.vNormal.z = v.z;
-  v3->face_plane.dist = *(float *)&a3;
-  v3->polygonType = (PolygonType)result;
-  return result;
+    polygonType = POLYGON_InBetweenFloorAndWall;
+
+  face_plane.vNormal.x = v.x;
+  face_plane.vNormal.y = v.y;
+  face_plane.vNormal.z = v.z;
+  face_plane.dist = v7;
 }
 
 //----- (0049B0C9) --------------------------------------------------------
-int stru154::_49B0C9(Vec3_float_ *pNormal, float dist)
+void stru154::ClassifyPolygon(Vec3_float_ *pNormal, float dist)
 {
-  signed int v3; // esi@1
-  signed int result; // eax@9
-  double v5; // st7@12
-  double v6; // st6@12
-  double v7; // st5@12
-  signed int v8; // [sp+0h] [bp-4h]@8
-
-  v3 = 2;
-  if ( pNormal->z == 0.0 )
-  {
-    v3 = 0;
-  }
+  if (fabsf(pNormal->z) < 1e-6f)
+    polygonType = POLYGON_VerticalWall;
+  else if (fabsf(pNormal->x) < 1e-6f &&
+           fabsf(pNormal->y) < 1e-6f)
+    polygonType = POLYGON_Floor;
   else
-  {
-    if ( pNormal->x == 0.0 && pNormal->y == 0.0 )
-      v3 = 1;
-  }
-  if ( v3 )
-  {
-    if ( v3 == 1 )
-      v8 = 3;
-    else
-      v8 = 4;
-    result = v8;
-  }
-  else
-  {
-    result = 1;
-  }
-  v5 = pNormal->z;
-  v6 = pNormal->y;
-  v7 = pNormal->x;
-  this->polygonType = (PolygonType)result;
-  this->face_plane.vNormal.x = v7;
-  this->face_plane.dist = dist;
-  this->face_plane.vNormal.y = v6;
-  this->face_plane.vNormal.z = v5;
-  return result;
+    polygonType = POLYGON_InBetweenFloorAndWall;
+
+  face_plane.vNormal.x = pNormal->x;
+  face_plane.dist = dist;
+  face_plane.vNormal.y = pNormal->y;
+  face_plane.vNormal.z = pNormal->z;
 }
 
 //----- (0049B13D) --------------------------------------------------------
-int stru154::_49B13D(ODMFace *pFace, BSPVertexBuffer *pVertices, Vec3_float_ *a3, float *a4)
+void stru154::GetFacePlane(ODMFace *pFace, BSPVertexBuffer *pVertices, Vec3_float_ *pOutNormal, float *pOutDist)
 {
   ODMFace *v5; // ebx@1
-  int v6; // eax@1
-  unsigned __int16 *v7; // ebx@2
-  Vec3_int_ *v8; // eax@3
+  //int v6; // eax@1
+  //unsigned __int16 *v7; // ebx@2
+  //Vec3_int_ *v8; // eax@3
   Vec3_int_ *v9; // ecx@3
-  double v10; // st7@3
-  int v11; // ecx@3
+  //double v10; // st7@3
+  //int v11; // ecx@3
   Vec3_int_ *v12; // ecx@3
-  double v13; // st7@3
-  double v14; // st6@3
-  double v15; // st5@3
-  int v16; // ecx@3
+  //double v13; // st7@3
+  //double v14; // st6@3
+  //double v15; // st5@3
+  //int v16; // ecx@3
   Vec3_int_ *v17; // eax@3
-  double v18; // st5@3
+  //double v18; // st5@3
   Vec3_float_ *v19; // eax@3
-  int result; // eax@8
-  float v21; // ecx@10
-  double v22; // st7@10
-  double v23; // st6@10
+  //int result; // eax@8
+  //float v21; // ecx@10
+  //double v22; // st7@10
+  //double v23; // st6@10
   Vec3_float_ v2; // [sp+4h] [bp-64h]@3
-  float v25; // [sp+18h] [bp-50h]@3
+  //float v25; // [sp+18h] [bp-50h]@3
   float v26; // [sp+1Ch] [bp-4Ch]@3
   float v27; // [sp+20h] [bp-48h]@3
   float v28; // [sp+24h] [bp-44h]@3
-  float v29; // [sp+2Ch] [bp-3Ch]@3
-  float v30; // [sp+30h] [bp-38h]@3
-  float v31; // [sp+34h] [bp-34h]@3
-  float v32; // [sp+38h] [bp-30h]@3
-  float v33; // [sp+3Ch] [bp-2Ch]@3
+  //float v29; // [sp+2Ch] [bp-3Ch]@3
+  //float v30; // [sp+30h] [bp-38h]@3
+  //float v31; // [sp+34h] [bp-34h]@3
+  //float v32; // [sp+38h] [bp-30h]@3
+  //float v33; // [sp+3Ch] [bp-2Ch]@3
   Vec3_float_ v1; // [sp+40h] [bp-28h]@1
-  float v35; // [sp+4Ch] [bp-1Ch]@3
-  float v36; // [sp+50h] [bp-18h]@3
-  float v37; // [sp+54h] [bp-14h]@3
+  //float v35; // [sp+4Ch] [bp-1Ch]@3
+  //float v36; // [sp+50h] [bp-18h]@3
+  //float v37; // [sp+54h] [bp-14h]@3
   Vec3_float_ v38; // [sp+58h] [bp-10h]@3
-  int v39; // [sp+64h] [bp-4h]@1
-
-  v39 = 0;
+  //int v39; // [sp+64h] [bp-4h]@1
+
+  //v39 = 0;
   v1.x = 0.0;
   v5 = pFace;
-  v6 = pFace->uNumVertices;
+  //v6 = pFace->uNumVertices;
   v1.y = 0.0;
   v1.z = 0.0;
-  if ( v6 - 1 <= 0 )
-  {
-LABEL_8:
-    a3->x = (double)(v5->pFacePlane.vNormal.x & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.x >> 16);
-    a3->y = (double)(v5->pFacePlane.vNormal.y & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.y >> 16);
-    a3->z = (double)(v5->pFacePlane.vNormal.z & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.z >> 16);
-    result = (int)a4;
-    *a4 = (double)(v5->pFacePlane.dist & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.dist >> 16);
-  }
-  else
-  {
-    v7 = &pFace->pVertexIDs[1];
-    while ( 1 )
-    {
-      v8 = pVertices->pVertices;
-      v9 = &v8[*(v7 - 1)];
-      v35 = (double)v9->x;
-      v36 = (double)v9->y;
-      v10 = (double)v9->z;
-      v11 = *v7;
-      v37 = v10;
-      v12 = &v8[v11];
-      v13 = (double)v12->x;
-      v14 = (double)v12->y;
-      v15 = (double)v12->z;
-      v16 = v7[1];
-      v25 = v15;
-      v17 = &v8[v16];
-      v18 = (double)v17->x;
-      v29 = (double)v17->y;
-      v30 = (double)v17->z;
-      v31 = v13 - v35;
-      v32 = v14 - v36;
-      v33 = v25 - v37;
-      v1.x = v31;
-      v26 = v18 - v13;
-      v1.y = v32;
-      v27 = v29 - v14;
-      v1.z = v33;
-      v28 = v30 - v25;
+
+  if (pFace->uNumVertices >= 2)
+  {
+    int i = 0;
+    while ( i < pFace->uNumVertices - 2 )
+    {
+      v9 = &pVertices->pVertices[pFace->pVertexIDs[i]];
+      v12 = &pVertices->pVertices[pFace->pVertexIDs[i + 1]];
+      v17 = &pVertices->pVertices[pFace->pVertexIDs[i + 2]];
+
+      v1.x = v12->x - v9->x;
+      v26 = v17->x - v12->x;
+      v1.y = v12->y - v9->y;
+      v27 = v17->y - v12->y;
+      v1.z = v12->z - v9->z;
+      v28 = v17->z - v12->z;
       v19 = Vec3_float_::Cross(&v1, &v2, v26, v27, v28);
       v38.x = v19->x;
       v38.y = v19->y;
       v38.z = v19->z;
-      if ( v38.x != 0.0 )
-        break;
-      if ( v38.y != 0.0 || v38.z != 0.0 )
-        break;
-      ++v39;
-      ++v7;
-      if ( v39 >= pFace->uNumVertices - 1 )
-      {
-        v5 = pFace;
-        goto LABEL_8;
-      }
-    }
-    v38.Normalize();
-    v21 = v38.y;
-    a3->x = v38.x;
-    v22 = v37 * v38.z;
-    v23 = v36 * v38.y;
-    a3->y = v21;
-    a3->z = v38.z;
-    result = (int)a4;
-    *a4 = -(v22 + v23 + v35 * v38.x);
-  }
-  return result;
+      if ( v38.x != 0.0  || v38.y != 0.0 || v38.z != 0.0)
+      {
+        v38.Normalize();
+
+        pOutNormal->x = v38.x;
+        pOutNormal->y = v38.y;
+        pOutNormal->z = v38.z;
+
+        *pOutDist = -(v9->x * v38.x + v9->y * v38.y + v9->z * v38.z);
+        return;
+      }
+    }
+  }
+
+  pOutNormal->x = (double)(v5->pFacePlane.vNormal.x & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.x >> 16);
+  pOutNormal->y = (double)(v5->pFacePlane.vNormal.y & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.y >> 16);
+  pOutNormal->z = (double)(v5->pFacePlane.vNormal.z & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.z >> 16);
+  *pOutDist = (double)(v5->pFacePlane.dist & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.dist >> 16);
 }