comparison LightmapBuilder.cpp @ 1449:27b7ee003c7c

Merge
author Gloval
date Tue, 06 Aug 2013 00:56:33 +0400
parents c9e3b93ec570
children c4ab816fcc5e
comparison
equal deleted inserted replaced
1448:5a5d0c713d47 1449:27b7ee003c7c
1 #include <assert.h>
2
1 #include "LightmapBuilder.h" 3 #include "LightmapBuilder.h"
2 #include "Game.h" 4 #include "Game.h"
3 #include "stru314.h" 5 #include "stru314.h"
4 #include "Outdoor.h" 6 #include "Outdoor.h"
5 #include "Outdoor_stuff.h" 7 #include "Outdoor_stuff.h"
737 { 739 {
738 HIWORD(result) = HIWORD(a1); 740 HIWORD(result) = HIWORD(a1);
739 v5 = (char *)&a1->flt_2C; 741 v5 = (char *)&a1->flt_2C;
740 do 742 do
741 { 743 {
744 __debugbreak(); // warning C4700: uninitialized local variable 'v7' used
742 if ( *(float *)v5 < 0.0 745 if ( *(float *)v5 < 0.0
743 || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) ) 746 || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) )
744 { 747 {
745 v12 = *(float *)v5; 748 v12 = *(float *)v5;
746 //UNDEF(v13); 749 //UNDEF(v13);
747 v14 = 0.0 < v12; 750 v14 = 0.0 < v12;
748 v15 = 0; 751 v15 = 0;
749 v16 = 0.0 == v12; 752 v16 = 0.0 == v12;
753 __debugbreak(); // warning C4700: uninitialized local variable 'v13' used
750 LOWORD(result) = v13; 754 LOWORD(result) = v13;
751 if ( v12 >= 0.0 ) 755 if ( v12 >= 0.0 )
752 v11 = *(float *)v5; 756 v11 = *(float *)v5;
753 else 757 else
754 v11 = 0.0; 758 v11 = 0.0;
876 a1.x = v16 - a1.x; 880 a1.x = v16 - a1.x;
877 a1.y = (float)v23 - a1.y; 881 a1.y = (float)v23 - a1.y;
878 a1.Normalize(); 882 a1.Normalize();
879 if ( uLightType & 4 ) 883 if ( uLightType & 4 )
880 { 884 {
885 __debugbreak(); // warning C4700: uninitialized local variable 'v18' used
881 v22[1] = v18; 886 v22[1] = v18;
882 uLightType = dword_4D86D8; 887 uLightType = dword_4D86D8;
883 v22[0] = v18; 888 v22[0] = v18;
884 v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x); 889 v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x);
885 v20 = v19 * *(float *)&uLightType * a2; 890 v20 = v19 * *(float *)&uLightType * a2;
1309 return 1; 1314 return 1;
1310 } 1315 }
1311 // 4E94D2: using guessed type char _4E94D2_light_type; 1316 // 4E94D2: using guessed type char _4E94D2_light_type;
1312 1317
1313 //----- (0045D3C7) -------------------------------------------------------- 1318 //----- (0045D3C7) --------------------------------------------------------
1314 bool LightmapBuilder::_45D3C7(stru148 *a1) 1319 bool LightmapBuilder::_45D3C7(struct Polygon *a1)
1315 { 1320 {
1316 LightmapBuilder *v2; // ebx@1 1321 LightmapBuilder *v2; // ebx@1
1317 stru148 *result; // eax@1 1322 struct Polygon *result; // eax@1
1318 float v4; // ecx@2 1323 float v4; // ecx@2
1319 Span *i; // edi@5 1324 Span *i; // edi@5
1320 1325
1321 v2 = this; 1326 v2 = this;
1322 result = (stru148 *)a1->prolly_head; 1327 result = (struct Polygon *)a1->prolly_head;
1323 if ( result && (v4 = result->field_4, *(int *)&v4) != 0 && *(unsigned int *)(LODWORD(v4) + 60) ) 1328 if ( result && (v4 = result->field_4, *(int *)&v4) != 0 && *(unsigned int *)(LODWORD(v4) + 60) )
1324 { 1329 {
1325 for ( i = a1->prolly_head; ; i = i->pNext ) 1330 for ( i = a1->prolly_head; ; i = i->pNext )
1326 { 1331 {
1327 result = i->pParent; 1332 result = i->pParent;
1328 if ( result->field_108 ) 1333 if ( result->field_108 )
1329 result = (stru148 *)_45D426( 1334 result = (struct Polygon *)_45D426(
1330 i, 1335 i,
1331 a1->pEdgeList1, 1336 a1->pEdgeList1,
1332 a1->uEdgeList1Size, 1337 a1->uEdgeList1Size,
1333 (Edge *)a1->pEdgeList2, 1338 (Edge *)a1->pEdgeList2,
1334 a1->uEdgeList2Size); 1339 a1->uEdgeList2Size);
1469 else 1474 else
1470 { 1475 {
1471 v25 = 1.0; 1476 v25 = 1.0;
1472 } 1477 }
1473 v9->field_10 = v25; 1478 v9->field_10 = v25;
1479 __debugbreak(); // warning C4700: uninitialized local variable 'v27' used
1474 if ( v9->field_14 < 0.0 1480 if ( v9->field_14 < 0.0
1475 || (v26 = v9->field_14, 1481 || (v26 = v9->field_14,
1476 //UNDEF(v27), 1482 //UNDEF(v27),
1477 v28 = 1.0 < v26, 1483 v28 = 1.0 < v26,
1478 v29 = 0, 1484 v29 = 0,
1483 v32 = v9->field_14; 1489 v32 = v9->field_14;
1484 //UNDEF(v33); 1490 //UNDEF(v33);
1485 v34 = 0.0 < v32; 1491 v34 = 0.0 < v32;
1486 v35 = 0; 1492 v35 = 0;
1487 v36 = 0.0 == v32; 1493 v36 = 0.0 == v32;
1494 __debugbreak(); // warning C4700: uninitialized local variable 'v33' used
1488 BYTE1(result) = HIBYTE(v33); 1495 BYTE1(result) = HIBYTE(v33);
1489 if ( v32 >= 0.0 ) 1496 if ( v32 >= 0.0 )
1490 v31 = v9->field_14; 1497 v31 = v9->field_14;
1491 else 1498 else
1492 v31 = 0.0; 1499 v31 = 0.0;
1573 LOBYTE(result) = 1; 1580 LOBYTE(result) = 1;
1574 return result; 1581 return result;
1575 } 1582 }
1576 1583
1577 //----- (0045D73F) -------------------------------------------------------- 1584 //----- (0045D73F) --------------------------------------------------------
1578 void LightmapBuilder::DrawLightmaps(int a2) 1585 void LightmapBuilder::DrawLightmapsType(int type)
1579 { 1586 {
1580 if ( a2 == 2 ) 1587 if (type == 2)
1581 DoDrawLightmaps(); 1588 Draw_183808_Lightmaps();
1582 } 1589 }
1583 1590
1584 //----- (0045D74F) -------------------------------------------------------- 1591 //----- (0045D74F) --------------------------------------------------------
1585 char LightmapBuilder::_45D74F_MessWithLight(int a2, int *a3) 1592 bool LightmapBuilder::DrawLightmaps(int *indices)
1586 { 1593 {
1587 char v3; // zf@1 1594 //char v3; // zf@1
1588 IDirect3DDevice3 *v4; // eax@2 1595 IDirect3DDevice3 *v4; // eax@2
1589 HRESULT v5; // eax@2 1596 HRESULT v5; // eax@2
1590 //char *v6; // eax@2 1597 //char *v6; // eax@2
1591 struct IDirect3DTexture2 *v7; // edi@4 1598 struct IDirect3DTexture2 *v7; // edi@4
1592 HRESULT v8; // eax@8 1599 HRESULT v8; // eax@8
1593 HRESULT v9; // eax@8 1600 HRESULT v9; // eax@8
1594 HRESULT v10; // eax@8 1601 HRESULT v10; // eax@8
1595 HRESULT v11; // eax@8 1602 HRESULT v11; // eax@8
1596 HRESULT v12; // eax@8 1603 HRESULT v12; // eax@8
1597 int *v13; // eax@8 1604 //int *v13; // eax@8
1598 float v14; // ecx@15 1605 //float v14; // ecx@15
1599 IDirect3DDevice3 *v15; // eax@21 1606 //IDirect3DDevice3 *v15; // eax@21
1600 HRESULT v16; // eax@21 1607 //HRESULT v16; // eax@21
1601 IDirect3DDevice3 *v17; // eax@21 1608 //IDirect3DDevice3 *v17; // eax@21
1602 HRESULT v18; // eax@21 1609 //HRESULT v18; // eax@21
1603 IDirect3DDevice3 *v19; // eax@21 1610 //IDirect3DDevice3 *v19; // eax@21
1604 HRESULT v20; // eax@21 1611 //HRESULT v20; // eax@21
1605 IDirect3DDevice3 *v21; // eax@21 1612 //IDirect3DDevice3 *v21; // eax@21
1606 HRESULT v22; // eax@21 1613 //HRESULT v22; // eax@21
1607 //IDirect3DDevice3 *v23; // eax@23 1614 //IDirect3DDevice3 *v23; // eax@23
1608 std::string v25; // [sp+44h] [bp-44h]@12 1615 std::string v25; // [sp+44h] [bp-44h]@12
1609 signed int v26; // [sp+48h] [bp-40h]@21 1616 signed int v26; // [sp+48h] [bp-40h]@21
1610 signed int v27; // [sp+4Ch] [bp-3Ch]@21 1617 signed int v27; // [sp+4Ch] [bp-3Ch]@21
1611 Lightmap *v28; // [sp+50h] [bp-38h]@2 1618 Lightmap *v28; // [sp+50h] [bp-38h]@2
1612 int v29; // [sp+54h] [bp-34h]@2 1619 int v29; // [sp+54h] [bp-34h]@2
1613 //float v30; // [sp+58h] [bp-30h]@2 1620 //float v30; // [sp+58h] [bp-30h]@2
1614 int arg4; // [sp+68h] [bp-20h]@8 1621 Vec3_float_ arg4;
1615 float v32; // [sp+6Ch] [bp-1Ch]@8 1622 //int arg4; // [sp+68h] [bp-20h]@8
1616 float v33; // [sp+70h] [bp-18h]@8 1623 //float v32; // [sp+6Ch] [bp-1Ch]@8
1624 //float v33; // [sp+70h] [bp-18h]@8
1617 int v34; // [sp+74h] [bp-14h]@19 1625 int v34; // [sp+74h] [bp-14h]@19
1618 int v35; // [sp+78h] [bp-10h]@2 1626 int v35; // [sp+78h] [bp-10h]@2
1619 int *v36; // [sp+7Ch] [bp-Ch]@10 1627 //int *v36; // [sp+7Ch] [bp-Ch]@10
1620 int a1; // [sp+80h] [bp-8h]@12 1628 //int a1; // [sp+80h] [bp-8h]@12
1621 float v38; // [sp+84h] [bp-4h]@1 1629 //float v38; // [sp+84h] [bp-4h]@1
1622 1630
1623 v3 = this->std__vector_000004_size == 0; 1631 if (std__vector_000004_size == 0)
1624 LODWORD(v38) = (int)this; 1632 return 1;
1625 if ( !v3 ) 1633
1626 { 1634
1627 //v30 = 0.0; 1635 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP));
1628 //v4 = pRenderer->pRenderD3D->pDevice; 1636
1629 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 3u)); 1637 v7 = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03");
1630 //v6 = (char *)stru_69BD44.c_str(); 1638 if ( pRenderer->bUsingSpecular )
1631 //if ( !stru_69BD44.c_str() ) 1639 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE);
1632 // v6 = (char *)&dword_4D86F0; 1640
1633 v7 = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03"); 1641 if ( !byte_4D864C || !(pGame->uFlags & GAME_FLAGS_1_01) )
1634 if ( pRenderer->bUsingSpecular ) 1642 {
1635 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0);
1636 if ( !byte_4D864C || !(pGame->uFlags & 1) )
1637 {
1638 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE)); 1643 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
1639 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE)); 1644 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
1640 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, v7)); 1645 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, v7));
1641 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); 1646 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
1642 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); 1647 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
1643 v13 = a3; 1648
1644 v33 = 1.0; 1649 arg4.x = 1.0f;
1645 v32 = 1.0; 1650 arg4.y = 1.0f;
1646 *(float *)&arg4 = 1.0; 1651 arg4.z = 1.0f;
1647 if ( a3 ) 1652 if (indices)
1648 { 1653 {
1649 if ( *a3 != -1 ) 1654 for (auto i = indices; *i != -1; ++i)
1650 { 1655 {
1651 v36 = a3; 1656 v28 = &std__vector_000004[*i];
1652 do 1657 if ( !DrawLightmap(v28, &arg4, 0.0) )
1653 { 1658 assert(false && "Invalid lightmap detected!");
1654 v28 = (Lightmap *)(3100 * *v13 + LODWORD(v38) + 4);
1655 if ( !DrawLightmap(v28, (Vec3_float_ *)&arg4, 0.0) )
1656 {
1657 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1230", 0);
1658 a1 = 5080812;
1659 }
1660 v13 = v36 + 1;
1661 v36 = v13;
1662 }
1663 while ( *v13 != -1 );
1664 } 1659 }
1665 } 1660 }
1666 else 1661 else
1667 { 1662 {
1668 v14 = v38; 1663 for (auto i = 0; i < std__vector_000004_size; ++i)
1669 v36 = 0;
1670 if ( *(unsigned int *)(LODWORD(v38) + 1587204) > 0 )
1671 { 1664 {
1672 a1 = LODWORD(v38) + 4; 1665 auto _a1 = &std__vector_000004[(int)i];
1673 while ( 1 ) 1666 if ( !DrawLightmap(_a1, &arg4, 0.0) )
1674 {
1675 if ( !DrawLightmap((Lightmap *)a1, (Vec3_float_ *)&arg4, 0.0) )
1676 { 1667 {
1677 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1238", 0); 1668 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1238", 0);
1678 v35 = 5080812; 1669 v35 = 5080812;
1679 } 1670 }
1680 v36 = (int *)((char *)v36 + 1);
1681 a1 += 3100;
1682 if ( (signed int)v36 >= *(unsigned int *)(LODWORD(v38) + 1587204) )
1683 break;
1684 v14 = v38;
1685 }
1686 } 1671 }
1687 } 1672 }
1688 v15 = pRenderer->pRenderD3D->pDevice; 1673
1689 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); 1674 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
1690 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); 1675 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
1691 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); 1676 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
1692 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE)); 1677 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
1693 } 1678 }
1679
1694 if ( pRenderer->bUsingSpecular ) 1680 if ( pRenderer->bUsingSpecular )
1695 { 1681 {
1696 //LODWORD(v30) = 1; 1682 //LODWORD(v30) = 1;
1697 //v29 = 28; 1683 //v29 = 28;
1698 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice; 1684 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice;
1703 //v28 = (Lightmap *)v23; 1689 //v28 = (Lightmap *)v23;
1704 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, pRenderer->uFogColor)); 1690 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, pRenderer->uFogColor));
1705 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice; 1691 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice;
1706 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0)); 1692 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
1707 } 1693 }
1708 } 1694
1709 return 1; 1695 return true;
1710 } 1696 }
1711 1697
1712 1698
1713 //----- (0045DA56) -------------------------------------------------------- 1699 //----- (0045DA56) --------------------------------------------------------
1714 bool LightmapBuilder::DrawLightmaps2(float z_bias) 1700 bool LightmapBuilder::DoDraw_183808_Lightmaps(float z_bias)
1715 { 1701 {
1716 Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2 1702 Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2
1717 v.z = 1.0; 1703 v.z = 1.0;
1718 v.y = 1.0; 1704 v.y = 1.0;
1719 v.x = 1.0; 1705 v.x = 1.0;
1794 1780
1795 return true; 1781 return true;
1796 } 1782 }
1797 1783
1798 //----- (0045DCA9) -------------------------------------------------------- 1784 //----- (0045DCA9) --------------------------------------------------------
1799 void LightmapBuilder::DoDrawLightmaps() 1785 void LightmapBuilder::Draw_183808_Lightmaps()
1800 { 1786 {
1801 if (!std__vector_183808_size) 1787 if (!std__vector_183808_size)
1802 return; 1788 return;
1803 1789
1804 if (pRenderer->bUsingSpecular) 1790 if (pRenderer->bUsingSpecular)
1813 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex)); 1799 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex));
1814 1800
1815 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); 1801 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
1816 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); 1802 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
1817 1803
1818 DrawLightmaps2(0.00050000002); 1804 DoDraw_183808_Lightmaps(0.00050000002);
1819 1805
1820 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); 1806 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
1821 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); 1807 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
1822 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); 1808 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
1823 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE)); 1809 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));