Mercurial > mm7
comparison Render.cpp @ 1338:9749edd941c6
shading terrain
author | Ritor1 |
---|---|
date | Fri, 05 Jul 2013 17:37:12 +0600 |
parents | 18665b8f66b2 |
children | 65379a50e4eb 883fea17dd9a |
comparison
equal
deleted
inserted
replaced
1337:c6695ebd8fe6 | 1338:9749edd941c6 |
---|---|
1668 } | 1668 } |
1669 // 47FFC4: inconsistent fpu stack | 1669 // 47FFC4: inconsistent fpu stack |
1670 // 4D864C: using guessed type char byte_4D864C; | 1670 // 4D864C: using guessed type char byte_4D864C; |
1671 | 1671 |
1672 | 1672 |
1673 void Render::RenderTerrainD3D() // New function. It's temporary | 1673 void Render::RenderTerrainD3D() // New function |
1674 { | 1674 { |
1675 char result; // al@3 | 1675 char result; // al@3 |
1676 //int v1; // eax@3 | |
1677 //int v2; // ebx@4 | |
1678 //struct ODMFace *v4; // esi@6 | |
1679 int v6; // ecx@8 | 1676 int v6; // ecx@8 |
1680 //int v7; // ecx@8 | 1677 struct stru148 *pTile; // ebx@8 |
1681 struct stru148 *v8; // ebx@8 | |
1682 // RenderVertexSoft *v8a; // edi@3 | |
1683 //char v11; // zf@8 | |
1684 struct stru148 *v16; | 1678 struct stru148 *v16; |
1685 unsigned int v18; // edi@22 | 1679 unsigned int v18; // edi@22 |
1686 //int v20; // edi@34 | |
1687 //int v28; // eax@50 | |
1688 //int v29; // ecx@55 | |
1689 //int v30; // eax@57 | |
1690 int v31; // eax@57 | |
1691 int v35; // edi@63 | 1680 int v35; // edi@63 |
1692 int v37; // eax@73 | 1681 int v37; // eax@73 |
1693 int v39; // eax@80 | 1682 int v39; // eax@80 |
1694 char v40; // [sp-18h] [bp-70h]@2 | 1683 char v40; // [sp-18h] [bp-70h]@2 |
1695 int v41; // [sp-14h] [bp-6Ch]@2 | 1684 int v41; // [sp-14h] [bp-6Ch]@2 |
1696 int v42; // [sp-10h] [bp-68h]@2 | 1685 int v42; // [sp-10h] [bp-68h]@2 |
1697 int v43; // [sp-Ch] [bp-64h]@2 | 1686 int v43; // [sp-Ch] [bp-64h]@2 |
1698 const char *v44; // [sp-8h] [bp-60h]@2 | 1687 const char *v44; // [sp-8h] [bp-60h]@2 |
1699 int v45; // [sp-4h] [bp-5Ch]@2 | 1688 int v45; // [sp-4h] [bp-5Ch]@2 |
1700 //float v48; // [sp+14h] [bp-44h]@8 | |
1701 //void *v52; // [sp+24h] [bp-34h]@3 | |
1702 bool v54; // [sp+2Ch] [bp-2Ch]@10 | |
1703 int v55; // [sp+30h] [bp-28h]@34 | |
1704 int v56; | 1689 int v56; |
1705 int v57; // [sp+38h] [bp-20h]@36 | 1690 int v57; // [sp+38h] [bp-20h]@36 |
1706 int v58; // [sp+3Ch] [bp-1Ch]@8 | |
1707 int v63; // [sp+50h] [bp-8h]@3 | |
1708 int v64; // [sp+57h] [bp-1h]@2 | 1691 int v64; // [sp+57h] [bp-1h]@2 |
1709 int v62; | 1692 int v62; |
1710 //struct IndoorCameraD3D *pIndoorCameraD3D; | |
1711 //RenderVertexSoft *pVertices; // [sp+C4h] [bp-Ch]@6 | |
1712 | |
1713 | 1693 |
1714 //warning: the game uses CW culling by default, ccw is incosistent | 1694 //warning: the game uses CW culling by default, ccw is incosistent |
1715 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); | 1695 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); |
1716 | 1696 |
1717 | 1697 static RenderVertexSoft pTerrainVertices[128 * 128];//vertexCountX and vertexCountZ |
1718 v63 = 0; | 1698 |
1719 // basic optimizations | 1699 //Генерация местоположения вершин------------------------------------------------------------------------- |
1720 unsigned int uStartX, uEndX, uStartZ, uEndZ; | 1700 //решётка вершин делится на две части от -64 до 0 и от 0 до 64 |
1721 if (pIndoorCamera->sRotationY >= 0 && pIndoorCamera->sRotationY <= 1024) | 1701 // |
1722 { | 1702 // -64 X 0 64 |
1723 uStartX = 0, uEndX = 128; | 1703 // --------------- 64 |
1724 uStartZ = 0, uEndZ = 64 + 16; | 1704 // | | | |
1725 } | 1705 // | | | |
1726 else if (pIndoorCamera->sRotationY >= 512 && pIndoorCamera->sRotationY <= 1536) | 1706 // | | | |
1727 { | 1707 // 0|------+------| Z |
1728 uStartX = 0, uEndX = 64 + 16; | 1708 // | | | |
1729 uStartZ = 0, uEndZ = 128; | 1709 // | | | |
1730 } | 1710 // | | | |
1731 else if (pIndoorCamera->sRotationY >= 1536 || pIndoorCamera->sRotationY <= 512) | 1711 // --------------- |
1732 { | 1712 // -64 |
1733 uStartX = 64 - 16, uEndX = 128; | 1713 |
1734 uStartZ = 0, uEndZ = 128; | 1714 int blockScale = 512; |
1735 } | 1715 int heightScale = 32; |
1736 else | 1716 for (unsigned int z = 0; z < 128; ++z) |
1737 { | 1717 { |
1738 uStartX = 0, uEndX = 128; | 1718 for (unsigned int x = 0; x < 128; ++x) |
1739 uStartZ = 64 - 16, uEndZ = 128; | 1719 { |
1740 } | 1720 pTerrainVertices[z * 128 + x].vWorldPosition.x = (-64 + (signed)x) * blockScale; |
1741 uStartX = 0, uEndX = 128; | 1721 pTerrainVertices[z * 128 + x].vWorldPosition.y = (64 - (signed)z) * blockScale; |
1742 uStartZ = 0, uEndZ = 128; | 1722 pTerrainVertices[z * 128 + x].vWorldPosition.z = heightScale * pOutdoor->pTerrain.pHeightmap[z * 128 + x]; |
1743 static RenderVertexSoft pTerrainVertices[128 * 128]; | |
1744 for (unsigned int z = uStartZ; z < uEndZ; ++z) | |
1745 { | |
1746 for (unsigned int x = uStartX; x < uEndX; ++x) | |
1747 { | |
1748 pTerrainVertices[z * 128 + x].vWorldPosition.x = (-64 + (signed)x) * 512; | |
1749 pTerrainVertices[z * 128 + x].vWorldPosition.y = (64 - (signed)z) * 512; | |
1750 pTerrainVertices[z * 128 + x].vWorldPosition.z = 32 * pOutdoor->pTerrain.pHeightmap[z * 128 + x]; | |
1751 //pIndoorCameraD3D = pGame->pIndoorCameraD3D; | |
1752 pGame->pIndoorCameraD3D->ViewTransform(&pTerrainVertices[z * 128 + x], 1); | 1723 pGame->pIndoorCameraD3D->ViewTransform(&pTerrainVertices[z * 128 + x], 1); |
1753 pGame->pIndoorCameraD3D->Project(&pTerrainVertices[z * 128 + x], 1, 0); | 1724 pGame->pIndoorCameraD3D->Project(&pTerrainVertices[z * 128 + x], 1, 0); |
1754 } | 1725 } |
1755 } | 1726 } |
1756 | 1727 //-------------------------------------------------------------------------------------------------------------------- |
1757 for (unsigned int z = uStartZ; z < uEndZ - 1; ++z) | 1728 |
1758 { | 1729 // |
1759 for (unsigned int x = uStartX; x < uEndX - 1; ++x) | 1730 for (unsigned int z = 0; z < 128; ++z) |
1760 { | 1731 { |
1761 v8 = &array_77EC08[pOutdoorCamera->numStru148s]; | 1732 for (unsigned int x = 0; x < 128; ++x) |
1762 v8->flags = 0; | 1733 { |
1763 v8->field_32 = 0; | 1734 pTile = &array_77EC08[pOutdoorCamera->numStru148s]; |
1764 //unsigned int uTileID = pOutdoor->pTerrain.pTilemap[z * 128 + x]; | 1735 pTile->flags = 0; |
1765 //struct TileDesc *pTile = pTileTable->GetTileById(uTileID); | 1736 pTile->field_32 = 0; |
1766 v8->uTileBitmapID = pOutdoor->DoGetTileTexture(x, z); | 1737 pTile->uTileBitmapID = pOutdoor->DoGetTileTexture(x, z); |
1767 //v6 = v8->uTileBitmapID; | 1738 pTile->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[pTile->uTileBitmapID]; |
1768 v8->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v8->uTileBitmapID]; | 1739 if (pTile->uTileBitmapID == 0xFFFF) |
1769 if (v8->uTileBitmapID == 0xFFFF) | |
1770 continue; | 1740 continue; |
1771 | 1741 |
1772 v8->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(x, z); | 1742 //pTile->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(x, z); |
1773 v8->field_32 = 0; | 1743 pTile->flags = pOutdoor->GetSomeOtherTileInfo(x, z); |
1774 v8->field_59 = 1; | 1744 pTile->field_32 = 0; |
1775 //v8->field_5D = (char)WorldPosToGridCellZ(floorf((pVertices->vWorldPosition.z + v8a->vWorldPosition.z) / 2 + 0.5f)); | 1745 pTile->field_59 = 1; |
1776 //v8->field_5C = WorldPosToGridCellX(floorf((v101->vWorldPosition.x + v8->vWorldPosition.x) / 2 + 0.5f));; | 1746 pTile->sTextureDeltaU = 0; |
1777 v8->sTextureDeltaU = 0; | 1747 pTile->sTextureDeltaV = 0; |
1778 v8->sTextureDeltaV = 0; | 1748 // x,z x+1,z |
1779 memcpy(array_73D150 + 0, &pTerrainVertices[z * 128 + x], sizeof(RenderVertexSoft)); | 1749 // .____________. |
1750 // | | | |
1751 // | | | |
1752 // | | | |
1753 // | | | |
1754 // | | | |
1755 // .____________. | |
1756 // x,z+1 x+1,z+1 | |
1757 memcpy(&array_73D150[0], &pTerrainVertices[z * 128 + x], sizeof(RenderVertexSoft));//x, z | |
1780 array_73D150[0].u = 0; | 1758 array_73D150[0].u = 0; |
1781 array_73D150[0].v = 0; | 1759 array_73D150[0].v = 0; |
1782 memcpy(array_73D150 + 1, &pTerrainVertices[z * 128 + x + 1], sizeof(RenderVertexSoft)); | 1760 memcpy(&array_73D150[1], &pTerrainVertices[z * 128 + x + 1], sizeof(RenderVertexSoft));//x + 1, z |
1783 array_73D150[1].u = 1; | 1761 array_73D150[1].u = 1; |
1784 array_73D150[1].v = 0; | 1762 array_73D150[1].v = 0; |
1785 memcpy(array_73D150 + 2, &pTerrainVertices[(z + 1) * 128 + x + 1], sizeof(RenderVertexSoft)); | 1763 memcpy(&array_73D150[2], &pTerrainVertices[(z + 1) * 128 + x + 1], sizeof(RenderVertexSoft));//x + 1, z + 1 |
1786 array_73D150[2].u = 1; | 1764 array_73D150[2].u = 1; |
1787 array_73D150[2].v = 1; | 1765 array_73D150[2].v = 1; |
1788 memcpy(array_73D150 + 3, &pTerrainVertices[(z + 1) * 128 + x], sizeof(RenderVertexSoft)); | 1766 memcpy(&array_73D150[3], &pTerrainVertices[(z + 1) * 128 + x], sizeof(RenderVertexSoft));//x, z + 1 |
1789 array_73D150[3].u = 0; | 1767 array_73D150[3].u = 0; |
1790 array_73D150[3].v = 1; | 1768 array_73D150[3].v = 1; |
1791 v55 = 0; | 1769 //v58 = 0; |
1792 v54 = false; | 1770 //if (v58 == 4) // if all y == first y; primitive in xz plane |
1793 v58 = 0; | 1771 //pTile->field_32 |= 0x0001; |
1794 if (v58 == 4) // if all y == first y; primitive in xz plane | 1772 pTile->pODMFace = nullptr; |
1795 v8->field_32 |= 0x0001; | 1773 pTile->uNumVertices = 4; |
1796 v8->pODMFace = nullptr; | 1774 pTile->field_59 = 5; |
1797 v8->uNumVertices = 4; | 1775 |
1798 v8->field_59 = 5; | 1776 //shading (затенение)---------------------------------------------------------------------------- |
1799 | 1777 //uint norm_idx = pTerrainNormalIndices[2 * (z * 128 + x) + 1]; |
1800 | 1778 uint norm_idx = pTerrainNormalIndices[2 * (x * 128 + z) + 1];//есть несовпадение в 1 кубик, тень надо поднять на 1 |
1801 uint norm_idx = pTerrainNormalIndices[2 * (x + 128 * z) + 1]; | |
1802 assert(norm_idx < uNumTerrainNormals); | 1779 assert(norm_idx < uNumTerrainNormals); |
1803 | 1780 |
1804 auto norm = pTerrainNormals + norm_idx; | 1781 auto norm = pTerrainNormals + norm_idx; |
1805 float _f = (norm->x * (float)pOutdoor->vSunlight.x / 65536.0 - | 1782 float _f = ((norm->x * (float)pOutdoor->vSunlight.x / 65536.0) - |
1806 norm->y * (float)pOutdoor->vSunlight.y / 65536.0 - | 1783 (norm->y * (float)pOutdoor->vSunlight.y / 65536.0) - |
1807 norm->z * (float)pOutdoor->vSunlight.z / 65536.0); | 1784 (norm->z * (float)pOutdoor->vSunlight.z / 65536.0)); |
1808 v8->dimming_level = 20.0 - floorf(20.0 * _f + 0.5f); | 1785 pTile->dimming_level = 20.0 - floorf(20.0 * _f + 0.5f); |
1786 //----------------------------------------------------------------------------------------------- | |
1809 | 1787 |
1810 ++pOutdoorCamera->numStru148s; | 1788 ++pOutdoorCamera->numStru148s; |
1811 ++pOutdoorCamera->field_44; | 1789 ++pOutdoorCamera->field_44; |
1812 assert(pOutdoorCamera->numStru148s < 20000); | 1790 assert(pOutdoorCamera->numStru148s < 20000); |
1813 | 1791 |
1814 v8->uBModelID = 0; | 1792 pTile->uBModelID = 0; |
1815 v8->uBModelFaceID = 0; | 1793 pTile->uBModelFaceID = 0; |
1816 v31 = (8 * (0 | (0 << 6))); | 1794 pTile->field_50 = (8 * (0 | (0 << 6))) | 6; |
1817 v8->field_50 = v31 | 6; | 1795 for (unsigned int k = 0; k < pTile->uNumVertices; ++k) |
1818 for (unsigned int k = 0; k < v8->uNumVertices; ++k) | |
1819 { | 1796 { |
1820 memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft)); | 1797 memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft)); |
1821 array_50AC10[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097); | 1798 array_50AC10[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097); |
1822 } | 1799 } |
1823 | 1800 |
1801 // check the transparency and texture (tiles) mapping (проверка прозрачности и наложение текстур (тайлов))---------------------- | |
1824 bool transparent = false; | 1802 bool transparent = false; |
1825 if ( v8->flags & 2 && v8->uTileBitmapID == pRenderer->hd_water_tile_id) | 1803 if ( !( pTile->flags & 1 ) ) // не поддерживается TextureFrameTable |
1826 { | 1804 { |
1827 //v80 = false; | 1805 if ( pTile->flags & 2 && pTile->uTileBitmapID == pRenderer->hd_water_tile_id) |
1828 v6 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]; | 1806 { |
1829 } | 1807 //transparent = false; |
1830 else | 1808 v6 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]; |
1831 { | 1809 } |
1832 v6 = v8->uTileBitmapID; | 1810 else |
1833 if ( !_strnicmp(pBitmaps_LOD->pTextures[v8->uTileBitmapID].pName, "wtrdr", 5) ) | 1811 { |
1834 transparent = true; | 1812 v6 = pTile->uTileBitmapID; |
1835 } | 1813 if ( !_strnicmp(pBitmaps_LOD->pTextures[pTile->uTileBitmapID].pName, "wtrdr", 5) ) |
1814 transparent = true; | |
1815 } | |
1836 | 1816 |
1837 assert(v6 < 1000); // many random crashes here | 1817 assert(v6 < 1000); // many random crashes here |
1838 | 1818 |
1839 // for all shore tiles - draw a tile water under them since they're half-empty | 1819 // for all shore tiles - draw a tile water under them since they're half-empty |
1840 if (!_strnicmp(pBitmaps_LOD->pTextures[v8->uTileBitmapID].pName, "wtrdr", 5)) // all shore tile filenames are wtrdrXXX | 1820 if (!_strnicmp(pBitmaps_LOD->pTextures[pTile->uTileBitmapID].pName, "wtrdr", 5)) // all shore tile filenames are wtrdrXXX |
1841 { | 1821 pTile->DrawBorderTiles(); |
1842 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE); // no Z writing: the shore tile will be draw in the same place, so taking care about z-fighting | 1822 |
1843 pRenderer->DrawTerrainPolygon(v8->uNumVertices, v8, pBitmaps_LOD->pHardwareTextures[pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]], false, true); | 1823 pRenderer->DrawTerrainPolygon(pTile->uNumVertices, pTile, pBitmaps_LOD->pHardwareTextures[v6], transparent, true); |
1844 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE); | 1824 } |
1845 | 1825 //else //здесь уже пограничные тайлы воды |
1846 } | 1826 //pTile->DrawBorderTiles(); |
1847 | 1827 //-------------------------------------------------------------------------------------------------------------------------------- |
1848 pRenderer->DrawTerrainPolygon(v8->uNumVertices, v8, pBitmaps_LOD->pHardwareTextures[v6], transparent, true); | |
1849 | |
1850 | 1828 |
1851 --pOutdoorCamera->numStru148s; | 1829 --pOutdoorCamera->numStru148s; |
1852 --pOutdoorCamera->field_44; | 1830 --pOutdoorCamera->field_44; |
1853 } | 1831 } |
1854 } | 1832 } |
1868 float v11; // eax@6 | 1846 float v11; // eax@6 |
1869 double v12; // ST5C_8@6 | 1847 double v12; // ST5C_8@6 |
1870 double v13; // ST2C_8@6 | 1848 double v13; // ST2C_8@6 |
1871 int v14; // eax@6 | 1849 int v14; // eax@6 |
1872 double v15; // st7@6 | 1850 double v15; // st7@6 |
1873 stru148 *v16; // ebx@12 | 1851 stru148 *pTile; // ebx@12 |
1874 unsigned __int16 v17; // ax@12 | 1852 unsigned __int16 v17; // ax@12 |
1875 int v18; // eax@13 | 1853 int v18; // eax@13 |
1876 int v19; // ecx@13 | |
1877 int v20; // eax@13 | |
1878 int v21; // eax@13 | |
1879 signed int v22; // eax@13 | 1854 signed int v22; // eax@13 |
1880 Vec3_float_ *v23; // eax@15 | 1855 Vec3_float_ *norm; // eax@15 |
1881 double v24; // st6@17 | 1856 //double v24; // st6@17 |
1882 double v25; // ST54_8@17 | 1857 double v25; // ST54_8@17 |
1883 unsigned __int8 v26; // sf@17 | 1858 unsigned __int8 v26; // sf@17 |
1884 unsigned __int8 v27; // of@17 | 1859 unsigned __int8 v27; // of@17 |
1885 double v28; // st5@19 | 1860 double v28; // st5@19 |
1886 double v29; // st5@19 | 1861 double v29; // st5@19 |
1891 int v33; // edi@38 | 1866 int v33; // edi@38 |
1892 unsigned int v34; // ecx@47 | 1867 unsigned int v34; // ecx@47 |
1893 char v35; // zf@47 | 1868 char v35; // zf@47 |
1894 unsigned int v36; // eax@50 | 1869 unsigned int v36; // eax@50 |
1895 int v37; // eax@54 | 1870 int v37; // eax@54 |
1896 stru148 *v38; // ecx@55 | 1871 //stru148 *v38; // ecx@55 |
1897 unsigned int v39; // eax@59 | 1872 unsigned int v39; // eax@59 |
1898 stru148 *v40; // ebx@62 | 1873 stru148 *v40; // ebx@62 |
1899 unsigned __int16 pTileBitmapsID; // ax@62 | 1874 unsigned __int16 pTileBitmapsID; // ax@62 |
1900 int v42; // eax@63 | 1875 int v42; // eax@63 |
1901 LightmapBuilder *v43; // ecx@63 | 1876 LightmapBuilder *v43; // ecx@63 |
1943 int v85; // [sp+70h] [bp-60h]@63 | 1918 int v85; // [sp+70h] [bp-60h]@63 |
1944 float a4; // [sp+74h] [bp-5Ch]@73 | 1919 float a4; // [sp+74h] [bp-5Ch]@73 |
1945 float v87; // [sp+78h] [bp-58h]@122 | 1920 float v87; // [sp+78h] [bp-58h]@122 |
1946 int v88; // [sp+7Ch] [bp-54h]@1 | 1921 int v88; // [sp+7Ch] [bp-54h]@1 |
1947 int v89; // [sp+80h] [bp-50h]@6 | 1922 int v89; // [sp+80h] [bp-50h]@6 |
1948 float v90; // [sp+84h] [bp-4Ch]@1 | |
1949 float v91; // [sp+88h] [bp-48h]@1 | |
1950 float v92; // [sp+8Ch] [bp-44h]@1 | |
1951 int v93; // [sp+90h] [bp-40h]@2 | 1923 int v93; // [sp+90h] [bp-40h]@2 |
1952 int X; // [sp+94h] [bp-3Ch]@1 | 1924 int X; // [sp+94h] [bp-3Ch]@1 |
1953 float v95; // [sp+98h] [bp-38h]@21 | 1925 float v95; // [sp+98h] [bp-38h]@21 |
1954 LightmapBuilder *v96; // [sp+9Ch] [bp-34h]@73 | 1926 LightmapBuilder *v96; // [sp+9Ch] [bp-34h]@73 |
1955 int v97; // [sp+A0h] [bp-30h]@6 | 1927 int v97; // [sp+A0h] [bp-30h]@6 |
1983 v83 = a3; | 1955 v83 = a3; |
1984 X = abs(unk4); | 1956 X = abs(unk4); |
1985 v4 = 0; | 1957 v4 = 0; |
1986 v88 = 0; | 1958 v88 = 0; |
1987 v84 = a1 - 1; | 1959 v84 = a1 - 1; |
1988 v90 = (float)pOutdoor->vSunlight.x / 65536.0; | |
1989 v91 = (float)pOutdoor->vSunlight.y / 65536.0; | |
1990 v92 = (float)pOutdoor->vSunlight.z / 65536.0; | |
1991 /* if ( a1 - 1 > 0 ) | 1960 /* if ( a1 - 1 > 0 ) |
1992 { | 1961 { |
1993 while ( 1 ) | 1962 while ( 1 ) |
1994 { | 1963 { |
1995 v5 = abs(X);//v5 = 13108 | 1964 v5 = abs(X);//v5 = 13108 |
2041 WorldPosToGridCellZ(sY); | 2010 WorldPosToGridCellZ(sY); |
2042 if ((!byte_4D864C || !(pGame->uFlags & 0x80)) && !sub_481EFA(v8, pVertices, v101, pVertices2, 1)) | 2011 if ((!byte_4D864C || !(pGame->uFlags & 0x80)) && !sub_481EFA(v8, pVertices, v101, pVertices2, 1)) |
2043 if ( v8->vWorldPosition.y != pVertices->vWorldPosition.y || pVertices->vWorldPosition.y != pVertices2->vWorldPosition.y | 2012 if ( v8->vWorldPosition.y != pVertices->vWorldPosition.y || pVertices->vWorldPosition.y != pVertices2->vWorldPosition.y |
2044 || pVertices2->vWorldPosition.y != v101->vWorldPosition.y ) | 2013 || pVertices2->vWorldPosition.y != v101->vWorldPosition.y ) |
2045 break;*/ | 2014 break;*/ |
2046 v16 = &array_77EC08[pOutdoorCamera->numStru148s]; | 2015 pTile = &array_77EC08[pOutdoorCamera->numStru148s]; |
2047 v16->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY); | 2016 pTile->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY); |
2048 if ( v16->uTileBitmapID != -1 ) | 2017 if ( pTile->uTileBitmapID != -1 ) |
2049 { | 2018 { |
2050 v19 = v97; | 2019 pTile->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(sX, sY); |
2051 v16->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(sX, sY); | 2020 pTile->field_32 = 0; |
2052 v16->field_32 = 0; | 2021 pTile->field_59 = 1; |
2053 v20 = v93; | 2022 pTile->terrain_grid_x = (char)v97; |
2054 v16->field_59 = 1; | 2023 pTile->field_34 = *(_WORD *)(v93 + 2); |
2055 v16->terrain_grid_x = (char)v19; | 2024 pTile->terrain_grid_z = v89; |
2056 v16->field_34 = *(_WORD *)(v20 + 2); | 2025 v22 = pTerrainNormalIndices[2 * (v97 + 128 * v89) + 1]; |
2057 v21 = v89; | |
2058 v16->terrain_grid_z = v89; | |
2059 v22 = pTerrainNormalIndices[2 * (v19 + 128 * v21) + 1]; | |
2060 if ( v22 < 0 || v22 > uNumTerrainNormals - 1 ) | 2026 if ( v22 < 0 || v22 > uNumTerrainNormals - 1 ) |
2061 v23 = 0; | 2027 norm = 0; |
2062 else | 2028 else |
2063 v23 = &pTerrainNormals[v22]; | 2029 norm = &pTerrainNormals[v22]; |
2064 v24 = v92 * v23->z; | 2030 thisf = 20.0 - ( -(((float)pOutdoor->vSunlight.x / 65536.0) * norm->x) - |
2065 //v99 = v23; | 2031 (((float)pOutdoor->vSunlight.y / 65536.0) * norm->y) - |
2066 thisf = 20.0 - (-v24 - v91 * v23->y - v90 * v23->x) * 20.0; | 2032 (((float)pOutdoor->vSunlight.z / 65536.0) * norm->z)) * 20.0; |
2067 //v25 = thisf + 6.7553994e15; | 2033 //v25 = thisf + 6.7553994e15; |
2068 //v27 = pOutdoorCamera->numStru148s > 1999; | 2034 //v27 = pOutdoorCamera->numStru148s > 1999; |
2069 //v26 = pOutdoorCamera->numStru148s - 1999 < 0; | 2035 //v26 = pOutdoorCamera->numStru148s - 1999 < 0; |
2070 v16->dimming_level = floorf(thisf + 0.5f); | 2036 pTile->dimming_level = floorf(thisf + 0.5f); |
2071 if ( pOutdoorCamera->numStru148s >= 1999 ) | 2037 if ( pOutdoorCamera->numStru148s >= 1999 ) |
2072 return; | 2038 return; |
2073 ++pOutdoorCamera->numStru148s; | 2039 ++pOutdoorCamera->numStru148s; |
2074 //if ( !sub_481FC9(v8, pVertices, v101, v16) )//Ritor1: It's temporary | 2040 //if ( !sub_481FC9(v8, pVertices, v101, v16) )//Ritor1: It's temporary |
2075 //goto LABEL_126; | 2041 //goto LABEL_126; |
2099 stru154(stru_76D5A8); | 2065 stru154(stru_76D5A8); |
2100 atexit(loc_481199); | 2066 atexit(loc_481199); |
2101 }*/ | 2067 }*/ |
2102 v32 = (struct8 *)array_50AC10; | 2068 v32 = (struct8 *)array_50AC10; |
2103 v97 = (int)pGame->pLightmapBuilder; | 2069 v97 = (int)pGame->pLightmapBuilder; |
2104 pGame->pLightmapBuilder->StackLights_TerrainFace(v23, &v95, array_50AC10, 4, 1); | 2070 pGame->pLightmapBuilder->StackLights_TerrainFace(norm, &v95, array_50AC10, 4, 1); |
2105 pDecalBuilder->_49BE8A(v16, v23, &v95, array_50AC10, 4, 1); | 2071 pDecalBuilder->_49BE8A(pTile, norm, &v95, array_50AC10, 4, 1); |
2106 a5 = 4; | 2072 a5 = 4; |
2107 if ( byte_4D864C && pGame->uFlags & 0x80 ) | 2073 if ( byte_4D864C && pGame->uFlags & 0x80 ) |
2108 { | 2074 { |
2109 thisa = pGame->pIndoorCameraD3D; | 2075 thisa = pGame->pIndoorCameraD3D; |
2110 if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 ) | 2076 if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 ) |
2123 { | 2089 { |
2124 if ( this_3 ) | 2090 if ( this_3 ) |
2125 v33 = 3; | 2091 v33 = 3; |
2126 else | 2092 else |
2127 v33 = v108 != 0 ? 5 : 0; | 2093 v33 = v108 != 0 ? 5 : 0; |
2128 static_sub_0048034E_stru_154.ClassifyPolygon(v23, v95); | 2094 static_sub_0048034E_stru_154.ClassifyPolygon(norm, v95); |
2129 if ( pDecalBuilder->uNumDecals > 0 ) | 2095 if ( pDecalBuilder->uNumDecals > 0 ) |
2130 pDecalBuilder->ApplyDecals(31 - v16->dimming_level, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1); | 2096 pDecalBuilder->ApplyDecals(31 - pTile->dimming_level, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1); |
2131 } | 2097 } |
2132 if ( stru_F8AD28.uNumLightsApplied > 0 ) | 2098 if ( stru_F8AD28.uNumLightsApplied > 0 ) |
2133 pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33); | 2099 pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33); |
2134 v34 = a5; | 2100 v34 = a5; |
2135 //v35 = byte_4D864C == 0; | 2101 //v35 = byte_4D864C == 0; |
2136 v16->uNumVertices = a5; | 2102 pTile->uNumVertices = a5; |
2137 if ( !byte_4D864C || ~pGame->uFlags & 0x80 ) | 2103 if ( !byte_4D864C || ~pGame->uFlags & 0x80 ) |
2138 { | 2104 { |
2139 if ( this_3 ) | 2105 if ( this_3 ) |
2140 { | 2106 { |
2141 v36 = sr_424CD7(v34); | 2107 v36 = sr_424CD7(v34); |
2142 v16->uNumVertices = v36; | 2108 pTile->uNumVertices = v36; |
2143 OutdoorCamera::Project(v36); | 2109 OutdoorCamera::Project(v36); |
2144 } | 2110 } |
2145 if ( v108 ) | 2111 if ( v108 ) |
2146 { | 2112 { |
2147 v36 = sr_424EE0_MakeFanFromTriangle(v34); | 2113 v36 = sr_424EE0_MakeFanFromTriangle(v34); |
2148 v16->uNumVertices = v36; | 2114 pTile->uNumVertices = v36; |
2149 OutdoorCamera::Project(v36); | 2115 OutdoorCamera::Project(v36); |
2150 } | 2116 } |
2151 } | 2117 } |
2152 //v37 = *(int *)&v16->flags; | 2118 //v37 = *(int *)&v16->flags; |
2153 if ( ~v16->flags & 1 ) | 2119 if ( ~pTile->flags & 1 ) |
2154 { | 2120 { |
2155 if ( v16->flags & 2 && v16->uTileBitmapID == pRenderer->hd_water_tile_id ) | 2121 if ( pTile->flags & 2 && pTile->uTileBitmapID == pRenderer->hd_water_tile_id ) |
2156 { | 2122 { |
2157 v80 = false; | 2123 v80 = false; |
2158 v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]; | 2124 v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]; |
2159 } | 2125 } |
2160 else | 2126 else |
2161 { | 2127 { |
2162 v39 = v16->uTileBitmapID; | 2128 v39 = pTile->uTileBitmapID; |
2163 v80 = true; | 2129 v80 = true; |
2164 } | 2130 } |
2165 //v79 = 0; | 2131 //v79 = 0; |
2166 //v78 = pBitmaps_LOD->pHardwareTextures[v39]; | 2132 //v78 = pBitmaps_LOD->pHardwareTextures[v39]; |
2167 v16->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v39];// Ritor1: It's temporary | 2133 pTile->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v39];// Ritor1: It's temporary |
2168 v77 = (int)v16; | 2134 v77 = (int)pTile; |
2169 //v76 = v16->uNumVertices; | 2135 //v76 = v16->uNumVertices; |
2170 //LABEL_161: | 2136 //LABEL_161: |
2171 pRenderer->DrawTerrainPolygon(v16->uNumVertices, v16, pBitmaps_LOD->pHardwareTextures[v39], false, v80); | 2137 pRenderer->DrawTerrainPolygon(pTile->uNumVertices, pTile, pBitmaps_LOD->pHardwareTextures[v39], false, v80); |
2172 goto LABEL_162; | 2138 goto LABEL_162; |
2173 } | 2139 } |
2174 v38 = v16; | |
2175 LABEL_56: | 2140 LABEL_56: |
2176 v38->_4811A3(); | 2141 pTile->DrawBorderTiles(); |
2177 } | 2142 } |
2178 LABEL_162: | 2143 LABEL_162: |
2179 v4 = v88 + 1; | 2144 v4 = v88 + 1; |
2180 if ( ++v88 >= v84 ) | 2145 if ( ++v88 >= v84 ) |
2181 return; | 2146 return; |
2296 } | 2261 } |
2297 LABEL_105: | 2262 LABEL_105: |
2298 v57 = *(int *)&v40->flags; | 2263 v57 = *(int *)&v40->flags; |
2299 if ( BYTE1(v57) & 1 ) | 2264 if ( BYTE1(v57) & 1 ) |
2300 { | 2265 { |
2301 v40->_4811A3(); | 2266 v40->DrawBorderTiles(); |
2302 } | 2267 } |
2303 else | 2268 else |
2304 { | 2269 { |
2305 if ( v57 & 2 && v40->uTileBitmapID == pRenderer->hd_water_tile_id ) | 2270 if ( v57 & 2 && v40->uTileBitmapID == pRenderer->hd_water_tile_id ) |
2306 { | 2271 { |