diff mm7_3.cpp @ 638:ccf8b4815a1f

GetActorTintColor fixed Outdoor sunlight works on terrain & bmodels (not sure about billboards though)
author Nomad
date Mon, 11 Mar 2013 21:43:26 +0200
parents f6aeea3eb893
children 1ff57450f090
line wrap: on
line diff
--- a/mm7_3.cpp	Mon Mar 11 17:07:51 2013 +0200
+++ b/mm7_3.cpp	Mon Mar 11 21:43:26 2013 +0200
@@ -4847,11 +4847,11 @@
       pLightmapBuilder = (LightmapBuilder *)(v51 + v53 + v52);
       v51 = 20 * (int)pLightmapBuilder;
       result = 20 - (20 * (signed int)pLightmapBuilder >> 16);
-      v7->field_58 = result;
+      v7->dimming_level = result;
       if ( result < 0 )
-        v7->field_58 = 0;
-      if ( v7->field_58 > 31 )
-        v7->field_58 = 31;
+        v7->dimming_level = 0;
+      if ( v7->dimming_level > 31 )
+        v7->dimming_level = 31;
       if ( pOutdoorCamera->numStru148s >= 1999 + 5000)
         return result;
       ++pOutdoorCamera->numStru148s;
@@ -4912,8 +4912,7 @@
             v38 = 0;
             v37 = array_50AC10;
             v36 = uNumVertices;
-            pDecalBuilder->ApplyDecals(
-              31 - v7->field_58,
+            pDecalBuilder->ApplyDecals(31 - v7->dimming_level,
               2,
               &static_RenderBuildingsD3D_stru_73C834,
               uNumVertices,
@@ -5170,8 +5169,8 @@
         *(float *)&v84 = v13 * 31.0;
         v14 = *(float *)&v84 + 6.7553994e15;
         v71 = LODWORD(v14);
-        v15 = (int)&v12->field_58;
-        v12->field_58 = 31 - LOBYTE(v14);
+        v15 = (int)&v12->dimming_level;
+        v12->dimming_level = 31 - LOBYTE(v14);
         if ( (char)(31 - LOBYTE(v14)) < 0 )
           *(char *)v15 = 0;
         if ( *(char *)v15 > 31 )
@@ -5529,11 +5528,11 @@
   float v15; // [sp+8h] [bp-30h]@1
   float v16; // [sp+Ch] [bp-2Ch]@1
 
-  v14 = (double)pOutdoor->vSunlight.x * 0.000015258789;
+  v14 = (double)pOutdoor->vSunlight.x / 65536.0;
   result = 0;
   v1 = (unsigned int)&array_77EC08[pOutdoorCamera->numStru148s];
-  v15 = (double)pOutdoor->vSunlight.y * 0.000015258789;
-  v16 = (double)pOutdoor->vSunlight.z * 0.000015258789;
+  v15 = (double)pOutdoor->vSunlight.y / 65536.0;
+  v16 = (double)pOutdoor->vSunlight.z / 65536.0;
   if ( v1 > (unsigned int)array_77EC08 )
   {
     v2 = (char *)&array_77EC08[0].pODMFace;
@@ -6136,7 +6135,7 @@
   if (pOutdoor->uSky_TextureID == -1)
     return;
 
-  _this.field_58 = 0;
+  _this.dimming_level = 0;
   _this.uNumVertices = 4;
   _this.v_18.x = -stru_5C6E00->Sin(pIndoorCamera->sRotationX + 16);
   _this.v_18.y = 0;
@@ -6404,7 +6403,7 @@
   if ( !v62.pTexture )
     return;
   v8 = pBLVRenderParams->sPartyRotX;
-  v62.field_58 = 0;
+  v62.dimming_level = 0;
   v62.uNumVertices = v3;
   v9 = stru_5C6E00->Sin(pBLVRenderParams->sPartyRotX + 16);
   v62.v_18.y = 0;
@@ -6904,8 +6903,8 @@
       v10 = 27;
     if ( v10 < a4 )
       v10 = a4;
-    if ( v10 > pOutdoor->field_CBC_terrain_triangles_shade_type )
-      v10 = pOutdoor->field_CBC_terrain_triangles_shade_type;
+    if ( v10 > pOutdoor->max_terrain_dimming_level )
+      v10 = pOutdoor->max_terrain_dimming_level;
     return PaletteManager::Get_Dark_or_Red_LUT(v4, v10, 1);
   }
   v6 = 0;
@@ -7004,7 +7003,7 @@
         *a5 = 31;
         *a6 = -1;
       }
-      v16 = v8->field_58 - terrain_gamma;
+      v16 = v8->dimming_level - terrain_gamma;
       if ( v16 >= 0 )
       {
         if ( v16 > 27 )
@@ -7037,8 +7036,8 @@
         *v14 = v20;
       if ( *v14 < v16 )
         *v14 = v16;
-      if ( *v14 > pOutdoor->field_CBC_terrain_triangles_shade_type )
-        *v14 = pOutdoor->field_CBC_terrain_triangles_shade_type;
+      if ( *v14 > pOutdoor->max_terrain_dimming_level )
+        *v14 = pOutdoor->max_terrain_dimming_level;
       goto LABEL_45;
     }
     if ( v9 >= day_fogrange_1 << 16 )
@@ -7366,7 +7365,7 @@
 
 
 //----- (0047C4FC) --------------------------------------------------------
-signed int __fastcall GetActorTintColor(int tint, int a2, float a3, int a4, RenderBillboard *a5)
+signed int __fastcall GetActorTintColor(int max_dimm, int min_dimm, float distance, int a4, RenderBillboard *a5)
 {
   //int v5; // esi@1
   signed int v6; // edx@1
@@ -7385,11 +7384,11 @@
   //double v19; // ST0C_8@44
   signed int v20; // [sp+10h] [bp-4h]@10
   float a3a; // [sp+1Ch] [bp+8h]@33
-  float a3b; // [sp+1Ch] [bp+8h]@34
+  //float a3b; // [sp+1Ch] [bp+8h]@34
   float a3c; // [sp+1Ch] [bp+8h]@44
   //float a3d; // [sp+1Ch] [bp+8h]@44
   float a4b; // [sp+20h] [bp+Ch]@18
-  int a4a; // [sp+20h] [bp+Ch]@33
+  //int a4a; // [sp+20h] [bp+Ch]@33
   //float a4c; // [sp+20h] [bp+Ch]@44
   //float a4d; // [sp+20h] [bp+Ch]@44
   int a5a; // [sp+24h] [bp+10h]@44
@@ -7398,12 +7397,13 @@
   v6 = 0;
 
   if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-    return 8 * (31 - tint) | ((8 * (31 - tint) | ((31 - tint) << 11)) << 8);
+    return 8 * (31 - max_dimm) | ((8 * (31 - max_dimm) | ((31 - max_dimm) << 11)) << 8);
+
   if (pParty->armageddon_timer)
     return 0xFFFF0000;
 
   v8 = pWeather->field_FA0;
-  if ( bUnderwater == 1 )
+  if (bUnderwater)
     v8 = 0;
   if ( v8 )
   {
@@ -7416,11 +7416,11 @@
     v9 = (double)v20 * 1024.0;
     if ( a4 )
       goto LABEL_19;
-    if ( a3 <= v9 )
-    {
-      if ( a3 > 0.0 )
-      {
-        a4b = a3 * 216.0 / v9;
+    if ( distance <= v9 )
+    {
+      if ( distance > 0.0 )
+      {
+        a4b = distance * 216.0 / v9;
         v10 = a4b + 6.7553994e15;
         v6 = LODWORD(v10);
         if ( SLODWORD(v10) > 216 )
@@ -7431,7 +7431,7 @@
     {
       v6 = 216;
     }
-    if ( a3 != 0.0 )
+    if ( distance != 0.0 )
     {
 LABEL_20:
       if ( a5 )
@@ -7447,10 +7447,11 @@
 
 
 
-  if ( a3 == 0.0 )
+  if (fabsf(distance) < 1.0e-6f)
     return 0xFFF8F8F8;
 
-  v11 = 8 * (tint - a2);
+  // dim in measured in 8-steps
+  v11 = 8 * (max_dimm - min_dimm);
     //v12 = v11;
     if ( v11 >= 0 )
     {
@@ -7460,27 +7461,32 @@
     else
       v11 = 0;
 
-    if ( a4 )
-    {
-      a3b = pOutdoor->fFogDensity * 216.0;
+    float fog_density_mult = 216.0f;
+    if (a4)
+      fog_density_mult += distance / (double)pOutdoorCamera->shading_dist_shade * 32.0;
+
+    v6 = v11 + floorf(pOutdoor->fFogDensity * fog_density_mult + 0.5f);
+    /*if ( a4 )
+    {
+      //a3b = pOutdoor->fFogDensity * 216.0;
       //v14 = a3b + 6.7553994e15;
-      a4a = floorf(a3b + 0.5f);//LODWORD(v14);
-    }
-    else
-    {
-      a3a = (a3 / (double)pOutdoorCamera->shading_dist_shade * 32.0 + 216.0) * pOutdoor->fFogDensity;
+      //a4a = floorf(a3b + 0.5f);//LODWORD(v14);
+    }
+    else
+    {
+      //a3a = (distance / (double)pOutdoorCamera->shading_dist_shade * 32.0 + 216.0) * pOutdoor->fFogDensity;
       //v13 = a3a + 6.7553994e15;
-      a4a = floorf(a3a + 0.5f);//LODWORD(v13);
-    }
-    v6 = a4a + v11;
+      //a4a = floorf(a3a + 0.5f);//LODWORD(v13);
+    }
+    v6 = a4a + v11;*/
     if ( a5 )
       v6 = 8 * _43F55F_get_billboard_light_level(a5, v6 >> 3);
     if ( v6 > 216 )
       v6 = 216;
     if ( v6 < v11 )
       v6 = v11;
-    if ( v6 > 8 * pOutdoor->field_CBC_terrain_triangles_shade_type )
-      v6 = 8 * pOutdoor->field_CBC_terrain_triangles_shade_type;
+    if ( v6 > 8 * pOutdoor->max_terrain_dimming_level )
+      v6 = 8 * pOutdoor->max_terrain_dimming_level;
     if ( !bUnderwater )
       return (255 - v6) | ((255 - v6) << 16) | ((255 - v6) << 8);
     else