changeset 2568:f2f2595fe308

rename Decals[], DecalCount
author Ritor1
date Thu, 21 May 2015 18:32:45 +0600
parents 117c219bf913
children d433439699be
files Build/Visual Studio 2012/World of Might and Magic.vcxproj Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Engine/Engine.cpp Engine/Graphics/DecalBuilder.cpp Engine/Graphics/DecalBuilder.h Engine/Graphics/LightmapBuilder.cpp Engine/Graphics/LightmapBuilder.h
diffstat 7 files changed, 98 insertions(+), 101 deletions(-) [+]
line wrap: on
line diff
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj	Wed May 20 15:12:33 2015 +0200
+++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj	Thu May 21 18:32:45 2015 +0600
@@ -138,6 +138,7 @@
     <ClCompile Include="..\..\Engine\Random.cpp" />
     <ClCompile Include="..\..\Engine\Registry.cpp" />
     <ClCompile Include="..\..\Engine\SaveLoad.cpp" />
+    <ClCompile Include="..\..\Engine\Serialization\LegacyImages.cpp" />
     <ClCompile Include="..\..\Engine\Spells\CastSpellInfo.cpp" />
     <ClCompile Include="..\..\Engine\Spells\Spells.cpp" />
     <ClCompile Include="..\..\Engine\stru298.cpp" />
@@ -316,6 +317,7 @@
     <ClInclude Include="..\..\Engine\Registry.h" />
     <ClInclude Include="..\..\Engine\resource.h" />
     <ClInclude Include="..\..\Engine\SaveLoad.h" />
+    <ClInclude Include="..\..\Engine\Serialization\LegacyImages.h" />
     <ClInclude Include="..\..\Engine\Spells\CastSpellInfo.h" />
     <ClInclude Include="..\..\Engine\Spells\Spells.h" />
     <ClInclude Include="..\..\Engine\stru123.h" />
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters	Wed May 20 15:12:33 2015 +0200
+++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters	Thu May 21 18:32:45 2015 +0600
@@ -112,6 +112,9 @@
     <Filter Include="Game">
       <UniqueIdentifier>{6dd9bc0c-a6d9-40ea-9eb9-d0f38abd514b}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Engine\Serialization">
+      <UniqueIdentifier>{19f2f2d9-edc3-4289-a610-8841b0d22b39}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\lib\zlib\adler32.c">
@@ -613,6 +616,9 @@
     <ClCompile Include="..\..\Game\MainMenuLoad.cpp">
       <Filter>Game</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\Engine\Serialization\LegacyImages.cpp">
+      <Filter>Engine\Serialization</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\lib\libavcodec\avcodec.h">
@@ -1393,6 +1399,9 @@
     <ClInclude Include="..\..\Game\MainMenuLoad.h">
       <Filter>Game</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\Engine\Serialization\LegacyImages.h">
+      <Filter>Engine\Serialization</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\lib\OpenAL\lib\x86\avcodec-55.def">
--- a/Engine/Engine.cpp	Wed May 20 15:12:33 2015 +0200
+++ b/Engine/Engine.cpp	Thu May 21 18:32:45 2015 +0600
@@ -462,8 +462,8 @@
     PickMouse(depth, cursor.x, cursor.y, false, v10, v11);
     pLightmapBuilder->StationaryLightsCount = 0;
     pLightmapBuilder->MobileLightsCount = 0;
-    pDecalBuilder->std__vector_pDecals_size = 0;
-    pDecalBuilder->field_308008 = 0;
+    pDecalBuilder->DecalsCount = 0;
+    pDecalBuilder->curent_decal_id = 0;
     if (!_44F07B())
         return false;
 
@@ -548,7 +548,7 @@
     if (/*uFlags & 0x04*/ debug_lights)
     {
         pLightmapBuilder->DrawDebugOutlines(-1);
-        //pDecalBuilder->DrawDecalDebugOutlines();
+        pDecalBuilder->DrawDecalDebugOutlines();
     }
     return true;
 }
--- a/Engine/Graphics/DecalBuilder.cpp	Wed May 20 15:12:33 2015 +0200
+++ b/Engine/Graphics/DecalBuilder.cpp	Thu May 21 18:32:45 2015 +0600
@@ -86,7 +86,7 @@
     pBloodsplatContainer->std__vector_pBloodsplats_size = 0;
     pBloodsplatContainer->uNumBloodsplats = 0;
   }
-  std__vector_pDecals_size = 0;
+  DecalsCount = 0;
 }
 
 //----- (0049B540) --------------------------------------------------------
@@ -218,13 +218,13 @@
 
   unsigned int a8b = 0;
 
-  if ( a6 == 0.0 )
+  if ( a6 == 0.0f )
     return 1;
-  decal = &this->std__vector_pDecals[this->field_308008];
-  this->std__vector_pDecals[this->field_308008].field_C18 = (DecalBuilder_stru0 *)blood;
-  this->std__vector_pDecals[this->field_308008].field_C1C = 0;
+  decal = &this->Decals[this->curent_decal_id];
+  this->Decals[this->curent_decal_id].field_C18 = (DecalBuilder_stru0 *)blood;
+  this->Decals[this->curent_decal_id].field_C1C = 0;
   if ( a3 & 2 )
-    this->std__vector_pDecals[this->field_308008].field_C1C = 1;
+    this->Decals[this->curent_decal_id].field_C1C = 1;
   this->field_30C028 = a6 - a8;
   this->field_30C02C = sqrt((a6 + a6 - this->field_30C028) * this->field_30C028);
 
@@ -289,13 +289,13 @@
     pIndoorCameraD3D->Project(decal->pVertices, decal->uNumVertices, 0);
     if ( !(uClipFlags & 1) )
     {
-      ++this->field_308008;
+      ++this->curent_decal_id;
       v34 = 1024;
-      if ( this->field_308008 == 1024 )
-        this->field_308008 = 0;
-      if ( (signed int)(this->std__vector_pDecals_size + 1) <= 1024 )
-        v34 = this->std__vector_pDecals_size + 1;
-      this->std__vector_pDecals_size = v34;
+      if ( this->curent_decal_id == 1024 )
+        this->curent_decal_id = 0;
+      if ( (signed int)(this->DecalsCount + 1) <= 1024 )
+        v34 = this->DecalsCount + 1;
+      this->DecalsCount = v34;
       return 1;
     }
     if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
@@ -317,13 +317,13 @@
       MessageBoxA(nullptr, "Lightpoly builder native indoor clipping not implemented", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:263", 0);
     if ( a8b != 0 )
     {
-      ++this->field_308008;
+      ++this->curent_decal_id;
       v34 = 1024;
-      if ( this->field_308008 == 1024 )
-        this->field_308008 = 0;
-      if ( (signed int)(this->std__vector_pDecals_size + 1) <= 1024 )
-        v34 = this->std__vector_pDecals_size + 1;
-      this->std__vector_pDecals_size = v34;
+      if ( this->curent_decal_id == 1024 )
+        this->curent_decal_id = 0;
+      if ( (signed int)(this->DecalsCount + 1) <= 1024 )
+        v34 = this->DecalsCount + 1;
+      this->DecalsCount = v34;
       return 1;
     }
     result = 1;
@@ -537,14 +537,14 @@
 //----- (0049C2CD) --------------------------------------------------------
 void DecalBuilder::DrawDecals(float z_bias)
 {
-  for (uint i = 0; i < std__vector_pDecals_size; ++i)
-    pRenderer->DrawDecal(std__vector_pDecals + i, z_bias);
+  for (uint i = 0; i < DecalsCount; ++i)
+    pRenderer->DrawDecal(&Decals[i], z_bias);
 }
 
 //----- (0049C304) --------------------------------------------------------
 void DecalBuilder::DrawBloodsplats()
 {
-  if (!std__vector_pDecals_size)
+  if (!DecalsCount)
     return;
 
   pRenderer->BeginDecals();
@@ -557,8 +557,8 @@
 //----- (0049C550) --------------------------------------------------------
 void DecalBuilder::DrawDecalDebugOutlines()
 {
-  for(int i = 0; i < std__vector_pDecals_size; i++)
-	pIndoorCameraD3D->debug_outline_sw(std__vector_pDecals[i].pVertices, std__vector_pDecals[i].uNumVertices, 0xC86400u, 0.0);
+  for(int i = 0; i < DecalsCount; i++)
+	pIndoorCameraD3D->debug_outline_sw(Decals[i].pVertices, Decals[i].uNumVertices, 0xC86400u, 0.0f);
 }
 
 //----- (0040E4C2) --------------------------------------------------------
--- a/Engine/Graphics/DecalBuilder.h	Wed May 20 15:12:33 2015 +0200
+++ b/Engine/Graphics/DecalBuilder.h	Thu May 21 18:32:45 2015 +0600
@@ -137,27 +137,12 @@
   //----- (0049B408) --------------------------------------------------------
   DecalBuilder()
   {
-    char *v2; // eax@1
-    signed int v3; // ecx@1
-
-    DecalBuilder* v1 = this;
-    /*_eh_vector_constructor_iterator_(
-    this->std__vector_pDecals,
-    3104,
-    1024,
-    (void ( *)(void *))Decal::Decal,
-    (void ( *)(void *))Decal::dtor);*/
-  v1->std__vector_pDecals_size = 0;
-  v1->field_308008 = 0;
-  v2 = (char *)&v1->pVertices[0].flt_2C;
-  v3 = 256;
-  do
-  {
-    *(float *)v2 = 0.0;
-    v2 += 48;
-    --v3;
-  }
-  while ( v3 );
+	  this->DecalsCount = 0;
+	  this->curent_decal_id = 0;
+	  for (uint i = 0; i < 256; ++i)
+	  {
+		this->pVertices[i].flt_2C = 0.0f;
+	  }
   }
 
   //----- (0049B471) --------------------------------------------------------
@@ -179,9 +164,9 @@
 
 
   //void ( ***vdestructor_ptr)(DecalBuilder *, bool);
-  Decal std__vector_pDecals[1024];
-  unsigned int std__vector_pDecals_size;
-  int field_308008;
+  Decal Decals[1024];
+  unsigned int DecalsCount;
+  int curent_decal_id;//field_308008
   RenderVertexSoft pVertices[256];
   int std__vector_30B00C[1024];
   int uNumDecals;
--- a/Engine/Graphics/LightmapBuilder.cpp	Wed May 20 15:12:33 2015 +0200
+++ b/Engine/Graphics/LightmapBuilder.cpp	Thu May 21 18:32:45 2015 +0600
@@ -65,13 +65,13 @@
   {
     if ( pSlot >= 20 )
       break;
-    ApplyLight_ODM((StationaryLight *)pMobileLightsStack[i].pLights, pFace, (unsigned int *)&pSlot, 1);
+    ApplyLight_ODM((StationaryLight *)pMobileLightsStack[i].pLights, pFace, (unsigned int *)&pSlot, true);
   }
   for ( uint i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i )
   {
     if ( pSlot >= 20 )
       break;
-    ApplyLight_ODM(&pStationaryLightsStack->pLights[i], pFace, (unsigned int *)&pSlot, 0);
+    ApplyLight_ODM(&pStationaryLightsStack->pLights[i], pFace, (unsigned int *)&pSlot, false);
   }
   result = pSlot;
   Lights.uNumLightsApplied = pSlot;
@@ -79,7 +79,7 @@
 }
 
 //----- (0045D0D5) --------------------------------------------------------
-bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *a3, RenderVertexSoft *TerrainVertices, unsigned int uStripType, int X, unsigned int *pSlot)
+bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *light_tile_dist, RenderVertexSoft *TerrainVertices, unsigned int uStripType, int X, unsigned int *pSlot)
 {
   //For outdoor terrain light (II)
   bool result; // eax@1
@@ -108,11 +108,11 @@
     return false;
   if ( uStripType == 4 )
   {
-    tX_0 = TerrainVertices[0].vWorldPosition.x;
-    tX_1 = TerrainVertices[3].vWorldPosition.x;
+	tX_0 = TerrainVertices[0].vWorldPosition.x;
+	tX_1 = TerrainVertices[3].vWorldPosition.x;
 
-    tY_0 = TerrainVertices[1].vWorldPosition.y;
-    tY_1 = TerrainVertices[0].vWorldPosition.y;
+	tY_0 = TerrainVertices[1].vWorldPosition.y;
+	tY_1 = TerrainVertices[0].vWorldPosition.y;
   }
   else if(uStripType == 3)
   {
@@ -153,10 +153,10 @@
     || (float)pLight->vPosition.z <= bounding_z1 || (float)pLight->vPosition.z >= bounding_z2 )
     return false;
 
-  Vec3_float_::NegDot(&TerrainVertices->vWorldPosition, pNormal, a3);
+  Vec3_float_::NegDot(&TerrainVertices->vWorldPosition, pNormal, light_tile_dist);
   float p_dot = ((float)pLight->vPosition.x * pNormal->x 
               + (float)pLight->vPosition.y * pNormal->y 
-              + (float)pLight->vPosition.z * pNormal->z + *a3)+0.5f;
+              + (float)pLight->vPosition.z * pNormal->z + *light_tile_dist)+0.5f;
   if  ( p_dot > pLight->uRadius )
     return false;
 
@@ -193,52 +193,53 @@
 }
 
 //----- (0045CE50) --------------------------------------------------------
-bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4)
+bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, bool bLightBackfaces)
 {
   //For outdoor light (IV)
   int result; // eax@0
-  int v10; // ecx@8
+  double v10; // ecx@8
   char v14; // dl@11
 
-  v10 = (pFace->pFacePlane.dist
-              + pLight->vPosition.x * pFace->pFacePlane.vNormal.x
-              + pLight->vPosition.y * pFace->pFacePlane.vNormal.y
-              + pLight->vPosition.z * pFace->pFacePlane.vNormal.z) >> 16;
-  if ( pLight->uRadius > 0
-    && (pLight->vPosition.x > pFace->pBoundingBox.x1 - pLight->uRadius) && pLight->vPosition.x < pLight->uRadius + pFace->pBoundingBox.x2
+  if (!pLight->uRadius)
+    return false;
+
+  if ( (pLight->vPosition.x > pFace->pBoundingBox.x1 - pLight->uRadius) && pLight->vPosition.x < pLight->uRadius + pFace->pBoundingBox.x2
     && (pLight->vPosition.y > pFace->pBoundingBox.y1 - pLight->uRadius) && pLight->vPosition.y < pLight->uRadius + pFace->pBoundingBox.y2
-    && (pLight->vPosition.z > pFace->pBoundingBox.z1 - pLight->uRadius) && pLight->vPosition.z < pLight->uRadius + pFace->pBoundingBox.z2
-    && ((a4) || v10 >= 0) && v10 <= pLight->uRadius )
+    && (pLight->vPosition.z > pFace->pBoundingBox.z1 - pLight->uRadius) && pLight->vPosition.z < pLight->uRadius + pFace->pBoundingBox.z2)
   {
-    Lights._blv_lights_radii[*pSlot] = pLight->uRadius;
-    Lights._blv_lights_inv_radii[*pSlot] = 65536 / pLight->uRadius;
-    Lights._blv_lights_xs[*pSlot] = pLight->vPosition.x;
-    Lights._blv_lights_ys[*pSlot] = pLight->vPosition.y;
-    Lights._blv_lights_zs[*pSlot] = pLight->vPosition.z;
-    Lights._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689;
-    Lights._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689;
-    Lights._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689;
-    //v11 = abs(v10);
-    //v12 = pRenderer->bUsingSpecular;
-    Lights._blv_lights_light_dot_faces[*pSlot] = abs(v10);
-    Lights._blv_lights_types[*pSlot] = pLight->uLightType;
-    //v13 = pRenderer->pRenderD3D;
-    v14 = Lights._blv_lights_types[*pSlot];
-    if ( /*pRenderer->pRenderD3D &&*/ pRenderer->bUsingSpecular && v14 & 4 )
-      v14 = _4E94D2_light_type;
-    Lights._blv_lights_types[*pSlot] = v14;
-    result = 4 * *pSlot;
-    if ( /*v13*/true && pRenderer->bUsingSpecular )
-    {
-      if ( Lights._blv_lights_types[*pSlot] & 4 )
-      {
-        *(float *)((char *)Lights._blv_lights_rs + result) = *(float *)((char *)Lights._blv_lights_rs + result)
-                                                                * 0.33000001;
-        *(float *)((char *)Lights._blv_lights_gs + result) = *(float *)((char *)Lights._blv_lights_gs + result)
-                                                                * 0.33000001;
-        *(float *)((char *)Lights._blv_lights_bs + result) = *(float *)((char *)Lights._blv_lights_bs + result)
-                                                                * 0.33000001;
-      }
+	v10 = (double)(pLight->vPosition.x * pFace->pFacePlane.vNormal.x
+				 + pLight->vPosition.y * pFace->pFacePlane.vNormal.y
+				 + pLight->vPosition.z * pFace->pFacePlane.vNormal.z + pFace->pFacePlane.dist);
+	if(((bLightBackfaces) || v10 >= 0.0f) && fabsf(v10) <= pLight->uRadius)
+	{
+		Lights._blv_lights_radii[*pSlot] = pLight->uRadius;
+		Lights._blv_lights_inv_radii[*pSlot] = 65536 / pLight->uRadius;
+		Lights._blv_lights_xs[*pSlot] = pLight->vPosition.x;
+		Lights._blv_lights_ys[*pSlot] = pLight->vPosition.y;
+		Lights._blv_lights_zs[*pSlot] = pLight->vPosition.z;
+		Lights._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR / 255.0f;
+		Lights._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG / 255.0f;
+		Lights._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB / 255.0f;
+		Lights._blv_lights_light_dot_faces[*pSlot] = abs((int)floorf(v10 + 0.5f));
+		Lights._blv_lights_types[*pSlot] = pLight->uLightType;
+		v14 = Lights._blv_lights_types[*pSlot];
+		if ( pRenderer->bUsingSpecular && Lights._blv_lights_types[*pSlot] & 4 )
+		  v14 = _4E94D2_light_type;
+		Lights._blv_lights_types[*pSlot] = v14;
+		result = 4 * *pSlot;
+		if ( pRenderer->bUsingSpecular )
+		{
+		  __debugbreak();
+		  if ( Lights._blv_lights_types[*pSlot] & 4 )
+		  {
+			*(float *)((char *)Lights._blv_lights_rs + result) = *(float *)((char *)Lights._blv_lights_rs + result)
+																	* 0.33000001;
+			*(float *)((char *)Lights._blv_lights_gs + result) = *(float *)((char *)Lights._blv_lights_gs + result)
+																	* 0.33000001;
+			*(float *)((char *)Lights._blv_lights_bs + result) = *(float *)((char *)Lights._blv_lights_bs + result)
+																	* 0.33000001;
+		  }
+		}
     }
     ++*pSlot;
     return true;
@@ -264,7 +265,7 @@
     if (uNumLightsApplied >= 20)
       break;
 
-    ApplyLight_BLV((StationaryLight *)(pMobileLightsStack->pLights + i), pFace, &uNumLightsApplied, true, 0);
+    ApplyLight_BLV((StationaryLight *)&pMobileLightsStack->pLights[i], pFace, &uNumLightsApplied, true, 0);
   }
 
   for (uint i = 0; i < pSector->uNumLights; ++i)
@@ -282,7 +283,7 @@
     if (uNumLightsApplied >= 20)
       break;
 
-    ApplyLight_BLV(pStationaryLightsStack->pLights + i, pFace, &uNumLightsApplied, false, &_4E94D0_light_type);
+    ApplyLight_BLV(&pStationaryLightsStack->pLights[i], pFace, &uNumLightsApplied, false, &_4E94D0_light_type);
   }
 
   Lights.uNumLightsApplied = uNumLightsApplied;
--- a/Engine/Graphics/LightmapBuilder.h	Wed May 20 15:12:33 2015 +0200
+++ b/Engine/Graphics/LightmapBuilder.h	Thu May 21 18:32:45 2015 +0600
@@ -46,7 +46,7 @@
   //bool _45D3C7_sw(struct Polygon *a1);
   bool StackLight_TerrainFace(struct StationaryLight *pLight, struct Vec3_float_ *pNormal, float *a3, struct RenderVertexSoft *a1, unsigned int uStripType, int X, unsigned int *pSlot);
   bool StackLights_TerrainFace(struct Vec3_float_ *pNormal, float *a3, struct RenderVertexSoft *a1, unsigned int uStripType, bool bLightBackfaces);
-  bool ApplyLight_ODM(struct StationaryLight *pLight, struct ODMFace *pFace, unsigned int *pSlot, char a4);
+  bool ApplyLight_ODM(struct StationaryLight *pLight, struct ODMFace *pFace, unsigned int *pSlot, bool bLightBackfaces);
   bool ApplyLights_OutdoorFace(struct ODMFace *pFace);
   double _45CC0C_light(struct Vec3_float_ a1, float a2, float a3, struct Vec3_float_ *pNormal, float a5, int uLightType);
   int _45CBD4(struct RenderVertexSoft *a2, int a3, int *a4, int *a5);