Mercurial > mm7
diff Render.cpp @ 86:ec84db4c8f9d
4.01.13
author | Ritor1 |
---|---|
date | Mon, 04 Feb 2013 09:17:35 +0600 |
parents | 7ad8eaa172c5 |
children | 7bdf8f1150eb |
line wrap: on
line diff
--- a/Render.cpp Tue Jan 29 10:03:07 2013 +0600 +++ b/Render.cpp Mon Feb 04 09:17:35 2013 +0600 @@ -908,8 +908,8 @@ //__debugbreak();Ritor1: it's temporarily //return 0; - unsigned int v0; // ebx@1 - unsigned int v1; // edi@1 + unsigned int pDirectionIndicator1; // ebx@1 + unsigned int pDirectionIndicator2; // edi@1 unsigned int v2; // eax@1 int v3; // eax@3 int v4; // edi@3 @@ -981,11 +981,11 @@ int v70; // edi@178 int v71; // eax@178 int v72; // ecx@178 - int v73; // ebx@180 + int x; // ebx@180 int v74; // eax@182 int v75; // eax@184 IndoorCameraD3D *pIndoorCameraD3D_3; // ecx@184 - int v77; // ecx@184 + int uStartZ; // ecx@184 int v79; // ebx@185 int v127; // esi@185 int v86; // edi@196 @@ -1005,7 +1005,7 @@ } v102; int v105; // [sp+1Ch] [bp-58h]@1 int v106; // [sp+20h] [bp-54h]@3 - int v107; // [sp+24h] [bp-50h]@3 + int uEndZ; // [sp+24h] [bp-50h]@3 int v108; // [sp+28h] [bp-4Ch]@9 int v109; // [sp+2Ch] [bp-48h]@9 int v110; // [sp+30h] [bp-44h]@9 @@ -1027,12 +1027,10 @@ int v126; // [sp+70h] [bp-4h]@9 v105 = pIndoorCamera->sRotationY / ((signed int)stru_5C6E00->uIntegerHalfPi / 2); - v0 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerDoublePi - pIndoorCamera->sRotationY); - v1 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + v0); - v124 = ((pIndoorCamera->uMapGridCellX << 16) + 3 * stru_5C6E00->SinCos( - stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + v0))) >> 16; - v123 = ((pIndoorCamera->uMapGridCellZ << 16) - + 3 * stru_5C6E00->SinCos(v1 - stru_5C6E00->uIntegerHalfPi)) >> 16; + pDirectionIndicator1 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerDoublePi - pIndoorCamera->sRotationY);//1536 + pDirectionIndicator2 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + pDirectionIndicator1);//512 + v124 = ((pIndoorCamera->uMapGridCellX << 16) + 3 * stru_5C6E00->SinCos(stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + pDirectionIndicator1))) >> 16; + v123 = ((pIndoorCamera->uMapGridCellZ << 16) + 3 * stru_5C6E00->SinCos(pDirectionIndicator2 - stru_5C6E00->uIntegerHalfPi)) >> 16; v120 = pOutdoorCamera->outdoor_grid_band_3 + v124;//+- range X v119 = pOutdoorCamera->outdoor_grid_band_3 + v123; v2 = pOutdoorCamera->uCameraFovInDegrees + 15; @@ -1042,10 +1040,10 @@ if ( v2 > 90 ) v2 = 90; v3 = (v2 << 11) / 720; - v4 = stru_5C6E00->uDoublePiMask & (v0 - v3); - v5 = stru_5C6E00->uDoublePiMask & (v3 + v0); + v4 = stru_5C6E00->uDoublePiMask & (pDirectionIndicator1 - v3); + v5 = stru_5C6E00->uDoublePiMask & (v3 + pDirectionIndicator1); v106 = stru_5C6E00->SinCos(v4); - v107 = stru_5C6E00->SinCos(v4 - stru_5C6E00->uIntegerHalfPi); + uEndZ = stru_5C6E00->SinCos(v4 - stru_5C6E00->uIntegerHalfPi); v111 = stru_5C6E00->SinCos(v5); v6 = stru_5C6E00->SinCos(v5 - stru_5C6E00->uIntegerHalfPi); v7 = v4 & stru_5C6E00->uPiMask; @@ -1070,8 +1068,8 @@ v110 = (v106 >= 0 ? 1: -1);//2 * (v106 >= 0) - 1; v126 = v124; v118 = v123; - v109 = (v107 >= 0 ? 1: -1);//2 * (v107 >= 0) - 1; - v107 = (v111 >= 0 ? 1: -1);//2 * (v111 >= 0) - 1; + v109 = (uEndZ >= 0 ? 1: -1);//2 * (v107 >= 0) - 1; + uEndZ = (v111 >= 0 ? 1: -1);//2 * (v111 >= 0) - 1; terrain_76E1C8[0] = 65535; //v116 = 1; v106 = (v6 >= 0 ? 1: -1);//2 * (v6 >= 0) - 1; @@ -1118,7 +1116,7 @@ v114 += v111;// if ( v111 + v114 >= 65536 ) { - v126 += v107; + v126 += uEndZ; v114 = (unsigned __int16)v114;// } v118 += v106; @@ -1126,7 +1124,7 @@ else { v125 += v108; - v126 += v107; + v126 += uEndZ; if ( v125 >= 65536 ) { v118 += v106; @@ -1573,52 +1571,41 @@ for ( i = v69; i >= 1; --i ) { //v70 = i; - v71 = terrain_76D7C8[i]; - v72 = terrain_76DBC8[i]; + v71 = terrain_76D7C8[i];//88 + v72 = terrain_76DBC8[i];//0 if ( v71 < v72 )//swap { terrain_76DBC8[i] = v71; terrain_76D7C8[i] = v72; } - v73 = terrain_76DBC8[i]; + x = terrain_76DBC8[i];//0 v111 = 0; - if ( v73 <= 0 ) - v73 = -v73; + if ( x <= 0 ) + x = -x; v74 = terrain_76D7C8[i]; if ( v74 <= 0 ) v74 = -v74; v75 = v74 + 2; //pIndoorCameraD3D_3 = pGame->pIndoorCameraD3D; - v107 = v75; + uEndZ = v75; //pIndoorCameraD3D_4 = pIndoorCameraD3D_3; - v77 = v73 - 2; - if ( v73 - 2 < v75 ) + uStartZ = x - 2; + if ( x - 2 < v75 ) { v127 = 0; //v79 = (v73 - 66) << 9; //v116 = v77; //pHeight = v79; - v111 = v75 - v77; - for (int j = v77; j < v107; ++j) - {// âûñîòà ÷åòûðåõ âåðøèí ÿ÷åéêè - /* *(float *)&v106 = (double)pHeight; - *(float *)((char *)&ptr_801A08->vWorldPosition.x + v127) = *(float *)&v106;//x - pHeight = (64 - *(int *)((char *)terrain_76D9C8 + v70)) << 9; - *(float *)((char *)&ptr_801A08->vWorldPosition.y + v127) = (double)pHeight;//y - pHeight = pOutdoor->GetHeightOnTerrain(v112, *(int *)((char *)terrain_76D9C8 + v70)); - *(float *)((char *)&ptr_801A08->vWorldPosition.z + v127) = (double)pHeight;//z*/ - ptr_801A08[v127].vWorldPosition.x = (v73 - 66 + v127) * 512; + v111 = v75 - uStartZ; + for (int z = uStartZ; z < uEndZ; ++z) + { + ptr_801A08[v127].vWorldPosition.x = (-64 + x) * 512; ptr_801A08[v127].vWorldPosition.y = (64 - terrain_76D9C8[i]) * 512; - ptr_801A08[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( j, terrain_76D9C8[i]); - - /* *(float *)((char *)&ptr_801A04->vWorldPosition.x + v127) = *(float *)&v106;//x - pHeight = (63 - *(int *)((char *)terrain_76D9C8 + v70)) << 9; - *(float *)((char *)&ptr_801A04->vWorldPosition.y + v127) = (double)pHeight;//y - pHeight = pOutdoor->GetHeightOnTerrain(v112, *(int *)((char *)terrain_76D9C8 + v70) + 1); - *(float *)((char *)&ptr_801A04->vWorldPosition.z + v127) = (double)pHeight;//z */ - ptr_801A04[v127].vWorldPosition.x = (v73 - 66 + v127) * 512; + ptr_801A08[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( z, terrain_76D9C8[i]); + + ptr_801A04[v127].vWorldPosition.x = (-64 + x) * 512; ptr_801A04[v127].vWorldPosition.y = (63 - terrain_76D9C8[i]) * 512; - ptr_801A04[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( j, terrain_76D9C8[i] + 1); + ptr_801A04[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( z, terrain_76D9C8[i] + 1); if ( !byte_4D864C || !(pGame->uFlags & 0x80) ) { @@ -1637,7 +1624,7 @@ v102.v103 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[i]); v102.v104 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[i]); if ( pRenderer->pRenderD3D )//Ritor1: do comment to test - Render::DrawTerrainD3D(v111, 1, (int)&v102); + Render::RenderTerrainD3D();//Render::DrawTerrainD3D(v111, 0, (int)&v102); else Render::DrawTerrainSW(v111, 0, (int)&v102); } @@ -1714,7 +1701,253 @@ // 47FFC4: inconsistent fpu stack // 4D864C: using guessed type char byte_4D864C; - +void Render::RenderTerrainD3D() // New function +{ + char result; // al@3 + //int v1; // eax@3 + //int v2; // ebx@4 + //struct ODMFace *v4; // esi@6 + int v6; // ecx@8 + //int v7; // ecx@8 + struct stru148 *v8; // ebx@8 + //char v11; // zf@8 + struct stru148 *v16; + unsigned int v18; // edi@22 + //int v20; // edi@34 + //int v28; // eax@50 + //int v29; // ecx@55 + //int v30; // eax@57 + int v31; // eax@57 + int v35; // edi@63 + int v37; // eax@73 + int v39; // eax@80 + char v40; // [sp-18h] [bp-70h]@2 + int v41; // [sp-14h] [bp-6Ch]@2 + int v42; // [sp-10h] [bp-68h]@2 + int v43; // [sp-Ch] [bp-64h]@2 + const char *v44; // [sp-8h] [bp-60h]@2 + int v45; // [sp-4h] [bp-5Ch]@2 + //float v48; // [sp+14h] [bp-44h]@8 + //void *v52; // [sp+24h] [bp-34h]@3 + bool v54; // [sp+2Ch] [bp-2Ch]@10 + int v55; // [sp+30h] [bp-28h]@34 + int v56; + int v57; // [sp+38h] [bp-20h]@36 + int v58; // [sp+3Ch] [bp-1Ch]@8 + int v63; // [sp+50h] [bp-8h]@3 + int v64; // [sp+57h] [bp-1h]@2 + int v62; + + v63 = 0; + + // basic optimizations + unsigned int uStartX, uEndX, + uStartZ, uEndZ; + if (pIndoorCamera->sRotationY >= 0 && pIndoorCamera->sRotationY <= 1024) + { + /* CAMERA + ï/2 512 + ^ + \ | / + \ | / + ï _____\|/______ + 0 + 1024 | x 0 + | + - y + 3ï/2 1536 + */ + uStartX = 0, uEndX = 128; + uStartZ = 0, uEndZ = 64 + 16; + } + else if (pIndoorCamera->sRotationY >= 512 && pIndoorCamera->sRotationY <= 1536) + { + /* ï/2 512 + + y + \ | + \ | +CAMERA ï _____\| ______ + 0 + 1024 /| x 0 + / | + / - y + 3ï/2 1536 + */ + uStartX = 0, uEndX = 64 + 16; + uStartZ = 0, uEndZ = 128; + } + else if (pIndoorCamera->sRotationY >= 1536 || pIndoorCamera->sRotationY <= 512) + { + /* ï/2 512 + + y + | / + | / + ï _____ |/______ + 0 CAMERA + 1024 |\ x 0 + | \ + - y \ + 3ï/2 1536 + */ + uStartX = 64 - 16, uEndX = 128; + uStartZ = 0, uEndZ = 128; + } + else + { + uStartX = 0, uEndX = 128; + uStartZ = 64 - 16, uEndZ = 128; + } + +// uStartX = 0, uEndX = 128; +// uStartZ = 0, uEndZ = 128; + + + static RenderVertexSoft pTerrainVertices[128 * 128]; + for (unsigned int z = uStartZ; z < uEndZ; ++z) + for (unsigned int x = uStartX; x < uEndX; ++x) + { + pTerrainVertices[z * 128 + x].vWorldPosition.x = (-64 + (signed)x) * 512; + pTerrainVertices[z * 128 + x].vWorldPosition.y = (64 - (signed)z) * 512; + pTerrainVertices[z * 128 + x].vWorldPosition.z = 32 * pOutdoor->pTerrain.pHeightmap[z * 128 + x]; + + struct IndoorCameraD3D *pIndoorCameraD3D = pGame->pIndoorCameraD3D; + pIndoorCameraD3D->ViewTransform(&pTerrainVertices[z * 128 + x], 1); + pIndoorCameraD3D->Project(&pTerrainVertices[z * 128 + x], 1, 0); + } + + + + for (unsigned int z = uStartZ; z < uEndZ - 1; ++z) + for (unsigned int x = uStartX; x < uEndX - 1; ++x) + { + v8 = &array_77EC08[pOutdoorCamera->numStru148s]; + v8->flags = 0; + v8->field_32 = 0; + + //unsigned int uTileID = pOutdoor->pTerrain.pTilemap[z * 128 + x]; + //struct TileDesc *pTile = pOutdoor->pTerrain->pTileTable->GetTileById(uTileID); + v8->uTileBitmapID = pOutdoor->DoGetTileTexture(x, z); + /*if (uTileID == 1 || //dirttyl BitmapID 88 + uTileID == 2 || //dirt1 BitmapID 126 + uTileID == 3 || //dirttyl BitmapID 88 + uTileID == 4 || //dirt2 BitmapID 127 + uTileID == 11 || //dirttyl BitmapID 127 + + uTileID == 90 || //grastyl BitmapID 110 + uTileID == 92 || //grastyl BitmapID 110 + + uTileID == 102 || //grdrtNE BitmapID 128 + uTileID == 104 || //grdrtNW BitmapID 130 + uTileID == 105 || //grdrtSW BitmapID 131 + uTileID == 106 || //grdrtE BitmapID 132 + uTileID == 107 || //grdrtW BitmapID 133 + uTileID == 108 || //grdrtN BitmapID 134 + uTileID == 109 || //grdrtS BitmapID 135 + uTileID == 110 || //grdrtXNE BitmapID 136 + uTileID == 112 || //grdrtXNW BitmapID 138 + uTileID == 113 || //grdrtXSW BitmapID 139 + + uTileID == 126 || uTileID == 127 || uTileID == 128 || uTileID == 129 || + uTileID == 130 || //wtrtyl BitmapID 89 + uTileID == 131 || //wtrtyl BitmapID 89 + uTileID == 132 || //wtrtyl BitmapID 89 + uTileID == 133 || //wtrtyl BitmapID 89 + uTileID == 134 || //wtrtyl BitmapID 89 + uTileID == 135 || //wtrtyl BitmapID 89 + uTileID == 136 || //wtrtyl BitmapID 89 + uTileID == 137 || //wtrtyl BitmapID 89 + + uTileID == 139 || //wtrdrSE BitmapID 141 + uTileID == 141 || //wrtdrSW BitmapID 143 + uTileID == 142 || //wrtdrE BitmapID 144 + uTileID == 143 || //wrtdrW BitmapID 145 + uTileID == 145 || //wtrdrS BitmapID 147 + uTileID == 147 || //wtrdrXSE BitmapID 149 + uTileID == 149 ) //wtrdrXSW BitmapID 151 + continue;*/ + + /*if (uTileID == 199 || //dirttyl BitmapID 0 + uTileID == 200 || //dirttyl BitmapID 0 + uTileID == 201 || //dirttyl BitmapID 0 + uTileID == 202 || //dirttyl BitmapID 0 + uTileID == 203 || //dirttyl BitmapID 0 + uTileID == 204 || //dirttyl BitmapID 0 + uTileID == 212 || //dirttyl BitmapID 0 + uTileID == 217) //dirttyl BitmapID 0 + continue;*/ + + v6 = v8->uTileBitmapID; + v8->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v6]; + + if (v8->uTileBitmapID == 0xFFFF) + continue; + + v8->sTextureDeltaU = 0; + v8->sTextureDeltaV = 0; + + +/* world coordinates, z -> height + 32767 + +y + + -32768 -x +x 32767 + + -y + -32768 +*/ + + memcpy(array_73D150 + 0, &pTerrainVertices[z * 128 + x], sizeof(RenderVertexSoft)); + array_73D150[0].u = 0; + array_73D150[0].v = 0; + + memcpy(array_73D150 + 1, &pTerrainVertices[z * 128 + x + 1], sizeof(RenderVertexSoft)); + array_73D150[1].u = 1; + array_73D150[1].v = 0; + + memcpy(array_73D150 + 2, &pTerrainVertices[(z + 1) * 128 + x + 1], sizeof(RenderVertexSoft)); + array_73D150[2].u = 1; + array_73D150[2].v = 1; + + memcpy(array_73D150 + 3, &pTerrainVertices[(z + 1) * 128 + x], sizeof(RenderVertexSoft)); + array_73D150[3].u = 0; + array_73D150[3].v = 1; + + + v55 = 0; + v54 = false; + v58 = 0; + + if (v58 == 4) // if all y == first y; primitive in xz plane + v8->field_32 |= 0x0001; + + v8->pODMFace = nullptr; + v8->uNumVertices = 4; + v8->field_59 = 5; + + v8->field_58 = 0; + + ++pOutdoorCamera->numStru148s; + ++pOutdoorCamera->field_44; + + + + v8->uBModelID = 0; + v8->uBModelFaceID = 0; + v31 = (8 * (0 | (0 << 6))); + v8->field_50 = v31 | 6; + + for (unsigned int k = 0; k < 4; ++k) + { + memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft)); + array_50AC10[k].flt_20 = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097); + } + + + pRenderer->DrawTerrainPolygon(v8, pBitmaps_LOD->pHardwareTextures[v6]); + + --pOutdoorCamera->numStru148s; + --pOutdoorCamera->field_44; + + } + + } //----- (0048034E) -------------------------------------------------------- void Render::DrawTerrainD3D(int a1, int a2, int a3) @@ -1758,7 +1991,7 @@ stru148 *v38; // ecx@55 unsigned int v39; // eax@59 stru148 *v40; // ebx@62 - unsigned __int16 v41; // ax@62 + unsigned __int16 pTileBitmapsID; // ax@62 int v42; // eax@63 LightmapBuilder *v43; // ecx@63 int v44; // eax@63 @@ -1788,7 +2021,7 @@ double v68; // st5@120 double v69; // st7@133 int v70; // edi@138 - RenderVertexSoft *v71; // esi@147 + stru148 *v71; // esi@147 unsigned int v72; // ecx@147 unsigned int v73; // eax@150 int v74; // eax@154 @@ -1881,464 +2114,432 @@ && !sub_481EFA(v8, v9, v101, pVertices, 1)) )*/ if ( !&stru_76E5C8[(v5 << 7) + v6] ) goto LABEL_162; - v8 = &pVerticesSR_806210[v4]; pVertices2 = &pVerticesSR_801A10[v4 + 1]; v102 = v8; if (!v82) { - pVertices = &pVerticesSR_801A10[v4]; - v101 = &pVerticesSR_806210[v4 + 1]; + pVertices = &pVerticesSR_801A10[v4]; + v101 = &pVerticesSR_806210[v4 + 1]; } else { - pVertices = &pVerticesSR_801A10[v4 + 1]; - v101 = &pVerticesSR_806210[v4]; - } - + pVertices = &pVerticesSR_801A10[v4 + 1]; + v101 = &pVerticesSR_806210[v4]; + } sX = floorf(v8->vWorldPosition.x + 0.5f); sY = floorf(v8->vWorldPosition.z + 0.5f); - v89 = WorldPosToGridCellX(floorf((v101->vWorldPosition.x + v8->vWorldPosition.x) / 2 + 0.5f)); v97 = WorldPosToGridCellZ(floorf((pVertices->vWorldPosition.z + v8->vWorldPosition.z) / 2 + 0.5f)); WorldPosToGridCellX(sX); WorldPosToGridCellZ(sY); - if ((!byte_4D864C || !(pGame->uFlags & 0x80)) && !sub_481EFA(v8, pVertices, v101, pVertices2, 1)) - if ( v8->vWorldPosition.y != pVertices->vWorldPosition.y || pVertices->vWorldPosition.y != pVertices2->vWorldPosition.y || pVertices2->vWorldPosition.y != v101->vWorldPosition.y ) + if ( v8->vWorldPosition.y != pVertices->vWorldPosition.y || pVertices->vWorldPosition.y != pVertices2->vWorldPosition.y + || pVertices2->vWorldPosition.y != v101->vWorldPosition.y ) break; v16 = &array_77EC08[pOutdoorCamera->numStru148s]; v16->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY); - if ( v16->uTileBitmapID != -1 ) - { - v19 = v97; - v16->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(sX, sY); - v16->field_32 = 0; - v20 = v93; - v16->field_59 = 1; - v16->field_5D = (char)v19; - v16->field_34 = *(_WORD *)(v20 + 2); - v21 = v89; - v16->field_5C = v89; - v22 = pTerrainNormalIndices[2 * (v19 + 128 * v21) + 1]; - if ( v22 < 0 || v22 > uNumTerrainNormals - 1 ) - v23 = 0; - else - v23 = &pTerrainNormals[v22]; - v24 = v92 * v23->y; - //v99 = v23; - thisf = 20.0 - (-v24 - v91 * v23->z - v90 * v23->x) * 20.0; - //v25 = thisf + 6.7553994e15; - //v27 = pOutdoorCamera->numStru148s > 1999; - //v26 = pOutdoorCamera->numStru148s - 1999 < 0; - v16->field_58 = floorf(thisf + 0.5f); - if ( pOutdoorCamera->numStru148s >= 1999 ) - return; - ++pOutdoorCamera->numStru148s; - if ( !sub_481FC9(v8, pVertices, v101, v16) ) + if ( v16->uTileBitmapID != -1 ) + { + v19 = v97; + v16->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(sX, sY); + v16->field_32 = 0; + v20 = v93; + v16->field_59 = 1; + v16->field_5D = (char)v19; + v16->field_34 = *(_WORD *)(v20 + 2); + v21 = v89; + v16->field_5C = v89; + v22 = pTerrainNormalIndices[2 * (v19 + 128 * v21) + 1]; + if ( v22 < 0 || v22 > uNumTerrainNormals - 1 ) + v23 = 0; + else + v23 = &pTerrainNormals[v22]; + v24 = v92 * v23->y; + //v99 = v23; + thisf = 20.0 - (-v24 - v91 * v23->z - v90 * v23->x) * 20.0; + //v25 = thisf + 6.7553994e15; + //v27 = pOutdoorCamera->numStru148s > 1999; + //v26 = pOutdoorCamera->numStru148s - 1999 < 0; + v16->field_58 = floorf(thisf + 0.5f); + if ( pOutdoorCamera->numStru148s >= 1999 ) + return; + ++pOutdoorCamera->numStru148s; + if ( !sub_481FC9(v8, pVertices, v101, v16) ) //goto LABEL_126; { - --pOutdoorCamera->numStru148s; - goto LABEL_162; - } - v28 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097); - memcpy(&array_50AC10[0], v102, 0x30u); - array_50AC10[0].flt_20 = v28; - array_50AC10[0].u = 0.0; - array_50AC10[0].v = 0.0; - v29 = pVertices->vWorldViewPosition.x + 0.0000001000000011686097; - memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1])); - array_50AC10[1].flt_20 = 1.0 / v29; - array_50AC10[1].u = 0.0; - array_50AC10[1].v = 1.0; - v30 = pVertices2->vWorldViewPosition.x + 0.0000001000000011686097; - memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2])); - array_50AC10[2].flt_20 = 1.0 / v30; - array_50AC10[2].u = 1.0; - array_50AC10[2].v = 1.0; - v31 = v101->vWorldViewPosition.x + 0.0000001000000011686097; - memcpy(&array_50AC10[3], v101, sizeof(array_50AC10[3])); - array_50AC10[3].flt_20 = 1.0 / v31; - array_50AC10[3].u = 1.0; - array_50AC10[3].v = 0.0; - - /*if ( !(byte_76D5C0 & 1) ) - { - byte_76D5C0 |= 1u; - stru154(stru_76D5A8); - atexit(loc_481199); - }*/ - v32 = (struct8 *)array_50AC10; - v97 = (int)pGame->pLightmapBuilder; - pGame->pLightmapBuilder->StackLights_TerrainFace(v99, &v95, array_50AC10, 4, 1); - pDecalBuilder->_49BE8A(v16, *(float *)&v99, (int)&v95, array_50AC10, 4u, 1); - a5 = 4; - if ( byte_4D864C && pGame->uFlags & 0x80 ) - { - thisa = pGame->pIndoorCameraD3D; - if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 ) + --pOutdoorCamera->numStru148s; goto LABEL_162; - thisa->ViewTransform(array_50AC10, a5); - thisa->Project(array_50AC10, a5, 0); - } - this_3 = v102->vWorldViewPosition.x < 8.0 - || pVertices->vWorldViewPosition.x < 8.0 - || v101->vWorldViewPosition.x < 8.0 - || pVertices2->vWorldViewPosition.x < 8.0; - v3a = (double)pOutdoorCamera->shading_dist_mist; - v108 = v3a < v102->vWorldViewPosition.x - || v3a < pVertices->vWorldViewPosition.x - || v3a < v101->vWorldViewPosition.x - || v3a < pVertices2->vWorldViewPosition.x; - v33 = 0; - pGame->pLightmapBuilder->std__vector_000004_size = 0; - if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 ) - { - if ( this_3 ) - v33 = 3; - else - v33 = v108 != 0 ? 5 : 0; - static_sub_0048034E_stru_154._49B0C9(v99, v95); - if ( pDecalBuilder->uNumDecals > 0 ) - pDecalBuilder->ApplyDecals(31 - v16->field_58, - 4, - &static_sub_0048034E_stru_154, - a5, - array_50AC10, - 0, - *(float *)&v33, - -1); - } - if ( stru_F8AD28.uNumLightsApplied > 0 ) - pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33); - v34 = a5; - //v35 = byte_4D864C == 0; - v16->uNumVertices = a5; - if ( !byte_4D864C || ~pGame->uFlags & 0x80 ) - { - if ( this_3 ) + } + memcpy(&array_50AC10[0], v102, 0x30u); + array_50AC10[0].flt_20 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097); + array_50AC10[0].u = 0.0; + array_50AC10[0].v = 0.0; + memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1])); + array_50AC10[1].flt_20 = 1.0 / (pVertices->vWorldViewPosition.x + 0.0000001000000011686097); + array_50AC10[1].u = 0.0; + array_50AC10[1].v = 1.0; + memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2])); + array_50AC10[2].flt_20 = 1.0 / (pVertices2->vWorldViewPosition.x + 0.0000001000000011686097); + array_50AC10[2].u = 1.0; + array_50AC10[2].v = 1.0; + memcpy(&array_50AC10[3], v101, sizeof(array_50AC10[3])); + array_50AC10[3].flt_20 = 1.0 / (v101->vWorldViewPosition.x + 0.0000001000000011686097); + array_50AC10[3].u = 1.0; + array_50AC10[3].v = 0.0; + /*if ( !(byte_76D5C0 & 1) ) + { + byte_76D5C0 |= 1u; + stru154(stru_76D5A8); + atexit(loc_481199); + }*/ + v32 = (struct8 *)array_50AC10; + v97 = (int)pGame->pLightmapBuilder; + pGame->pLightmapBuilder->StackLights_TerrainFace(v23, &v95, array_50AC10, 4, 1); + pDecalBuilder->_49BE8A(v16, *(float *)&v23, (int)&v95, array_50AC10, 4, 1); + a5 = 4; + if ( byte_4D864C && pGame->uFlags & 0x80 ) + { + thisa = pGame->pIndoorCameraD3D; + if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 ) + goto LABEL_162; + thisa->ViewTransform(array_50AC10, a5); + thisa->Project(array_50AC10, a5, 0); + } + this_3 = v102->vWorldViewPosition.x < 8.0 || pVertices->vWorldViewPosition.x < 8.0 + || v101->vWorldViewPosition.x < 8.0 || pVertices2->vWorldViewPosition.x < 8.0; + v3a = (double)pOutdoorCamera->shading_dist_mist; + v108 = v3a < v102->vWorldViewPosition.x || v3a < pVertices->vWorldViewPosition.x + || v3a < v101->vWorldViewPosition.x || v3a < pVertices2->vWorldViewPosition.x; + v33 = 0; + pGame->pLightmapBuilder->std__vector_000004_size = 0; + if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 ) { - v36 = sr_424CD7(v34); - v16->uNumVertices = v36; - OutdoorCamera::Project(v36); + if ( this_3 ) + v33 = 3; + else + v33 = v108 != 0 ? 5 : 0; + static_sub_0048034E_stru_154._49B0C9(v23, v95); + if ( pDecalBuilder->uNumDecals > 0 ) + pDecalBuilder->ApplyDecals(31 - v16->field_58, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1); } - if ( v108 ) - { - v36 = sr_424EE0_MakeFanFromTriangle(v34); - v16->uNumVertices = v36; - OutdoorCamera::Project(v36); - } - } - //v37 = *(int *)&v16->flags; - if ( ~v16->flags & 1 ) - { - if ( v16->flags & 2 && v16->uTileBitmapID == pRenderer->field_1036AC_bitmapid ) + if ( stru_F8AD28.uNumLightsApplied > 0 ) + pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33); + v34 = a5; + //v35 = byte_4D864C == 0; + v16->uNumVertices = a5; + if ( !byte_4D864C || ~pGame->uFlags & 0x80 ) { - v80 = false; - v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid]; - } - else - { - v39 = v16->uTileBitmapID; - v80 = true; + if ( this_3 ) + { + v36 = sr_424CD7(v34); + v16->uNumVertices = v36; + OutdoorCamera::Project(v36); + } + if ( v108 ) + { + v36 = sr_424EE0_MakeFanFromTriangle(v34); + v16->uNumVertices = v36; + OutdoorCamera::Project(v36); + } } - //v79 = 0; - v78 = pBitmaps_LOD->pHardwareTextures[v39]; - v77 = (int)v16; - v76 = v16->uNumVertices; + //v37 = *(int *)&v16->flags; + if ( ~v16->flags & 1 ) + { + if ( v16->flags & 2 && v16->uTileBitmapID == pRenderer->field_1036AC_bitmapid ) + { + v80 = false; + v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid]; + } + else + { + v39 = v16->uTileBitmapID; + v80 = true; + } + //v79 = 0; + //v78 = pBitmaps_LOD->pHardwareTextures[v39]; + v16->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v39];// Ritor1: It's temporary + v77 = (int)v16; + //v76 = v16->uNumVertices; //LABEL_161: - pRenderer->DrawTerrainPolygon(v76, v16, v78, false, v80); - goto LABEL_162; - } - v38 = v16; + pRenderer->DrawTerrainPolygon(v16, pBitmaps_LOD->pHardwareTextures[v39]);//pRenderer->DrawTerrainPolygon(v16->uNumVertices, v16, pBitmaps_LOD->pHardwareTextures[v39], false, v80); + goto LABEL_162; + } + v38 = v16; LABEL_56: - v38->_4811A3(); - } + v38->_4811A3(); + } LABEL_162: - v4 = v88 + 1; - if ( ++v88 >= v84 ) + v4 = v88 + 1; + if ( ++v88 >= v84 ) + return; + } + v40 = &array_77EC08[pOutdoorCamera->numStru148s]; + v40->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY); + if ( v40->uTileBitmapID == -1 ) + goto LABEL_162; + v42 = pOutdoor->GetSomeOtherTileInfo(sX, sY); + BYTE1(v42) |= 0x80u; + v43 = pGame->pLightmapBuilder; + *(int *)&v40->flags = v42; + v44 = v93; + v40->field_59 = 1; + v40->field_5D = (char)v43; + v40->field_34 = *(_WORD *)(v44 + 2); + v45 = v89; + v40->field_5C = v89; + v46 = 4 * ((char)v43 + (v45 << 7)); + v85 = v46; + v47 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v46 + 2);// v47 = pTerrainNormalIndices[v46 + 1]; + if ( v47 < 0 || v47 > (signed int)(uNumTerrainNormals - 1) ) + v48 = 0; + else + v48 = &pTerrainNormals[v47]; + v49 = v92 * v48->y; + //v99 = v48; + thisg = 20.0 - (-v49 - v91 * v48->z - v90 * v48->x) * 20.0; + v50 = thisg + 6.755399441055744e15; + v40->field_58 = LOBYTE(v50); + if ( LOBYTE(v50) < 0 ) + v40->field_58 = 0; + if ( pOutdoorCamera->numStru148s >= 1999 ) return; - } - v40 = &array_77EC08[pOutdoorCamera->numStru148s]; - v41 = pOutdoor->GetTileTexture(sX, sY); - v40->uTileBitmapID = v41; - if ( v41 == -1 ) - goto LABEL_162; - v42 = pOutdoor->GetSomeOtherTileInfo(sX, sY); - BYTE1(v42) |= 0x80u; - v43 = pGame->pLightmapBuilder; - *(int *)&v40->flags = v42; - v44 = v93; - v40->field_59 = 1; - v40->field_5D = (char)v43; - v40->field_34 = *(_WORD *)(v44 + 2); - v45 = v89; - v40->field_5C = v89; - v46 = 4 * ((char)v43 + (v45 << 7)); - v85 = v46; - v47 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v46 + 2);// v47 = pTerrainNormalIndices[v46 + 1]; - if ( v47 < 0 || v47 > (signed int)(uNumTerrainNormals - 1) ) - v48 = 0; - else - v48 = &pTerrainNormals[v47]; - v49 = v92 * v48->y; - //v99 = v48; - thisg = 20.0 - (-v49 - v91 * v48->z - v90 * v48->x) * 20.0; - v50 = thisg + 6.755399441055744e15; - v40->field_58 = LOBYTE(v50); - if ( LOBYTE(v50) < 0 ) - v40->field_58 = 0; - if ( pOutdoorCamera->numStru148s >= 1999 ) - return; - ++pOutdoorCamera->numStru148s; - if ( !sub_481FC9(pVertices, pVertices2, v8, v40) ) - //goto LABEL_77; - { + ++pOutdoorCamera->numStru148s; + /*if ( !sub_481FC9(pVertices, pVertices2, v8, v40) ) // Ritor1: It's temporary + //goto LABEL_77; + { + --pOutdoorCamera->numStru148s; + goto LABEL_112; + }*/ + memcpy(&array_50AC10[0], v102, 0x30u); + array_50AC10[0].flt_20 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097); + array_50AC10[0].u = 0.0; + array_50AC10[0].v = 0.0; + memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1])); + array_50AC10[1].flt_20 = 1.0 / pVertices->vWorldViewPosition.x + 0.0000001000000011686097; + array_50AC10[1].u = 0.0; + array_50AC10[1].v = 1.0; + memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2])); + array_50AC10[2].flt_20 = 1.0 / pVertices2->vWorldViewPosition.x + 0.0000001000000011686097; + array_50AC10[2].u = 1.0; + array_50AC10[2].v = 1.0; + static stru154 static_sub_0048034E_stru_76D590; + /*static bool __init_flag2 = false; + if (!__init_flag2) + { + __init_flag2 = true; + stru154::stru154(&static_sub_0048034E_stru_76D590); + }*/ + /*if ( !(byte_76D5C0 & 2) ) + { + byte_76D5C0 |= 2; + stru148(stru_76D590); + atexit(loc_48118F); + }*/ + v96 = pGame->pLightmapBuilder; + pGame->pLightmapBuilder->StackLights_TerrainFace(v48, (float *)&a4, array_50AC10, 3, 0); + pDecalBuilder->_49BE8A(v40, *(float *)&v48, (int)&a4, array_50AC10, 3, 0); + uNumVertices = 3; + if ( byte_4D864C && pGame->uFlags & 0x80 ) + { + thisb = pGame->pIndoorCameraD3D; + if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &uNumVertices, 0) == 1 && !uNumVertices ) + { +//LABEL_77: + --pOutdoorCamera->numStru148s; + goto LABEL_112; + } + thisb->ViewTransform(array_50AC10, uNumVertices); + thisb->Project(array_50AC10, uNumVertices, 0); + } + this_3a = v102->vWorldViewPosition.x < 8.0 || pVertices->vWorldViewPosition.x < 8.0 || pVertices2->vWorldViewPosition.x < 8.0; + v54 = (double)pOutdoorCamera->shading_dist_mist; + v108 = v54 < v102->vWorldViewPosition.x || v54 < pVertices->vWorldViewPosition.x || v54 < pVertices2->vWorldViewPosition.x; + pVertices = 0; + v96->std__vector_000004_size = 0; + if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 ) + { + if ( this_3a ) + pVertices = (RenderVertexSoft *)3; + 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); + if ( pDecalBuilder->uNumDecals > 0 ) + pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices, -1); + } + if ( stru_F8AD28.uNumLightsApplied > 0 ) + v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices); + v55 = uNumVertices; + //v35 = byte_4D864C == 0; + v40->uNumVertices = uNumVertices; + if ( !byte_76D5C0 || !(pGame->uFlags & 0x80) ) + { + if ( this_3a ) + { + v56 = sr_424CD7(v55); + } + else + { + if ( !v108 ) + goto LABEL_105; + v56 = sr_424EE0_MakeFanFromTriangle(v55); + } + v40->uNumVertices = v56; + OutdoorCamera::Project(v56); + } +LABEL_105: + v57 = *(int *)&v40->flags; + if ( BYTE1(v57) & 1 ) + { + v40->_4811A3(); + } + else + { + if ( v57 & 2 && v40->uTileBitmapID == pRenderer->field_1036AC_bitmapid ) + { + v81 = 0; + v58 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid]; + } + else + { + v58 = v40->uTileBitmapID; + v81 = 1; + } + pRenderer->DrawTerrainPolygon(v40, pBitmaps_LOD->pHardwareTextures[v58]); + } +LABEL_112: + v59 = &array_77EC08[pOutdoorCamera->numStru148s]; + //a8 = (RenderVertexSoft *)&array_77EC08[pOutdoorCamera->numStru148s]; + v59->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY); + if ( v59->uTileBitmapID == -1 ) + goto LABEL_162; + *(int *)&v59->flags = pOutdoor->GetSomeOtherTileInfo(sX, sY); + v61 = v93; + v59->field_59 = 1; + v59->field_34 = *(_WORD *)(v61 + 2); + v59->field_5C = v89; + v59->field_5D = v97; + v62 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v85); + if ( v62 > (signed int)(uNumTerrainNormals - 1) ) + v63 = 0; + else + v63 = &pTerrainNormals[v62]; + v64 = v92 * v63->y; + //v99 = v63; + thish = 20.0 - (-v64 - v91 * v63->y - v90 * v63->x) * 20.0; + v59->field_58 = floorf(thish + 0.5f); + if ( v59->field_58 < 0 ) + v59->field_58 = 0; + if ( pOutdoorCamera->numStru148s >= 1999 ) + return; + ++pOutdoorCamera->numStru148s; + if ( !sub_481FC9(v101, v102, pVertices2, v59) ) + { +//LABEL_126: --pOutdoorCamera->numStru148s; - goto LABEL_112; - } - v51 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097); - memcpy(&array_50AC10[0], v102, 0x30u); - array_50AC10[0].flt_20 = v51; - array_50AC10[0].u = 0.0; - array_50AC10[0].v = 0.0; - v52 = pVertices->vWorldViewPosition.x + 0.0000001000000011686097; - memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1])); - array_50AC10[1].flt_20 = 1.0 / v52; - array_50AC10[1].u = 0.0; - array_50AC10[1].v = 1.0; - v53 = pVertices2->vWorldViewPosition.x + 0.0000001000000011686097; - memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2])); - array_50AC10[2].flt_20 = 1.0 / v53; - array_50AC10[2].u = 1.0; - array_50AC10[2].v = 1.0; - - static stru154 static_sub_0048034E_stru_76D590; - /*static bool __init_flag2 = false; - if (!__init_flag2) - { - __init_flag2 = true; - - stru154::stru154(&static_sub_0048034E_stru_76D590); - }*/ - /*if ( !(byte_76D5C0 & 2) ) - { - byte_76D5C0 |= 2; - stru148(stru_76D590); - atexit(loc_48118F); - }*/ - v96 = pGame->pLightmapBuilder; - pGame->pLightmapBuilder->StackLights_TerrainFace(v99, (float *)&a4, array_50AC10, 3, 0); - pDecalBuilder->_49BE8A(v40, *(float *)&v99, (int)&a4, array_50AC10, 3, 0); - uNumVertices = 3; - if ( byte_4D864C && pGame->uFlags & 0x80 ) - { - thisb = pGame->pIndoorCameraD3D; - if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &uNumVertices, 0) == 1 && !uNumVertices ) - { -//LABEL_77: - --pOutdoorCamera->numStru148s; - goto LABEL_112; - } - thisb->ViewTransform(array_50AC10, uNumVertices); - thisb->Project(array_50AC10, uNumVertices, 0); - } - this_3a = v102->vWorldViewPosition.x < 8.0 || pVertices->vWorldViewPosition.x < 8.0 || pVertices2->vWorldViewPosition.x < 8.0; - v54 = (double)pOutdoorCamera->shading_dist_mist; - v108 = v54 < v102->vWorldViewPosition.x || v54 < pVertices->vWorldViewPosition.x || v54 < pVertices2->vWorldViewPosition.x; - pVertices = 0; - v96->std__vector_000004_size = 0; - if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 ) - { - if ( this_3a ) - pVertices = (RenderVertexSoft *)3; - else - pVertices = (RenderVertexSoft *)(v108 != 0 ? 5 : 0); - //a8 = (RenderVertexSoft *)(this_3a ? 3 : v108 != 0 ? 5 : 0); - static_sub_0048034E_stru_76D590._49B0C9(v99, *(float *)&a4); - if ( pDecalBuilder->uNumDecals > 0 ) - pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices, -1); - } - if ( stru_F8AD28.uNumLightsApplied > 0 ) - v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices); - v55 = uNumVertices; - //v35 = byte_4D864C == 0; - v40->uNumVertices = uNumVertices; - if ( !byte_76D5C0 || !(pGame->uFlags & 0x80) ) - { - if ( this_3a ) - { - v56 = sr_424CD7(v55); + goto LABEL_162; + } + memcpy(&array_50AC10[0], v102, 0x30u); + array_50AC10[0].flt_20 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097); + array_50AC10[0].u = 0.0; + array_50AC10[0].v = 0.0; + memcpy(&array_50AC10[1], pVertices2, sizeof(array_50AC10[1])); + array_50AC10[1].flt_20 = 1.0 / pVertices2->vWorldViewPosition.x + 0.0000001000000011686097; + array_50AC10[1].u = 1.0; + array_50AC10[1].v = 1.0; + memcpy(&array_50AC10[2], v101, sizeof(array_50AC10[2])); + array_50AC10[2].flt_20 = 1.0 / v101->vWorldViewPosition.x + 0.0000001000000011686097; + array_50AC10[2].u = 1.0; + array_50AC10[2].v = 0.0; + static stru154 static_sub_0048034E_stru_76D578; + /*static bool __init_flag1 = false; + if (!__init_flag1) + { + __init_flag1 = true; + stru154::stru154(&static_sub_0048034E_stru_76D578); + }*/ + v96 = pGame->pLightmapBuilder; + pGame->pLightmapBuilder->StackLights_TerrainFace(v63, &v87, array_50AC10, 3, 1); + pDecalBuilder->_49BE8A(v40, *(float *)&v63, (int)&v87, array_50AC10, 3, 1); + v100 = 3; + if ( byte_4D864C && pGame->uFlags & 0x80 ) + { + thisc = pGame->pIndoorCameraD3D; + if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, (unsigned int *)&v100, 0) == 1 && !v100 ) + //goto LABEL_126; + { + --pOutdoorCamera->numStru148s; + goto LABEL_162; + } + thisc->ViewTransform(array_50AC10, v100); + thisc->Project(array_50AC10, v100, 0); + } + this_3b = v102->vWorldViewPosition.x < 8.0 || pVertices2->vWorldViewPosition.x < 8.0 + || v101->vWorldViewPosition.x < 8.0; + v69 = (double)pOutdoorCamera->shading_dist_mist; + v108 = v69 < v102->vWorldViewPosition.x || v69 < pVertices2->vWorldViewPosition.x || v69 < v101->vWorldViewPosition.x; + v70 = 0; + v96->std__vector_000004_size = 0; + if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 ) + { + if ( this_3b ) + v70 = 3; + else + v70 = v108 != 0 ? 5 : 0; + static_sub_0048034E_stru_76D578._49B0C9(v63, v87); + if ( pDecalBuilder->uNumDecals > 0 ) + pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70, -1); + } + if ( stru_F8AD28.uNumLightsApplied > 0 ) + v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70); + v71 = v59; + v72 = v100; + //v35 = byte_4D864C == 0; + v59->uNumVertices = v100;//??? + if ( !byte_4D864C && pGame->uFlags & 0x80 ) + goto LABEL_154; + if ( this_3b ) + { + v73 = sr_424CD7(v72); } else { if ( !v108 ) - goto LABEL_105; - v56 = sr_424EE0_MakeFanFromTriangle(v55); - } - v40->uNumVertices = v56; - OutdoorCamera::Project(v56); - } -LABEL_105: - v57 = *(int *)&v40->flags; - if ( BYTE1(v57) & 1 ) - { - v40->_4811A3(); - } - else - { - if ( v57 & 2 && v40->uTileBitmapID == pRenderer->field_1036AC_bitmapid ) - { - v81 = 0; - v58 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid]; - } - else - { - v58 = v40->uTileBitmapID; - v81 = 1; - } - pRenderer->DrawTerrainPolygon(v40->uNumVertices, v40, pBitmaps_LOD->pHardwareTextures[v58], 0, v81); - } -LABEL_112: - v59 = &array_77EC08[pOutdoorCamera->numStru148s]; - //a8 = (RenderVertexSoft *)&array_77EC08[pOutdoorCamera->numStru148s]; - v59->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY); - if ( v59->uTileBitmapID == -1 ) - goto LABEL_162; - *(int *)&v59->flags = pOutdoor->GetSomeOtherTileInfo(sX, sY); - v61 = v93; - v59->field_59 = 1; - v59->field_34 = *(_WORD *)(v61 + 2); - v59->field_5C = v89; - v59->field_5D = v97; - v62 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v85); - if ( v62 > (signed int)(uNumTerrainNormals - 1) ) - v63 = 0; - else - v63 = &pTerrainNormals[v62]; - v64 = v92 * v63->y; - //v99 = v63; - thish = 20.0 - (-v64 - v91 * v63->y - v90 * v63->x) * 20.0; - v59->field_58 = floorf(thish + 0.5f); - if ( v59->field_58 < 0 ) - v59->field_58 = 0; - if ( pOutdoorCamera->numStru148s >= 1999 ) - return; - ++pOutdoorCamera->numStru148s; - if ( !sub_481FC9(v101, v102, pVertices2, v59) ) - { -//LABEL_126: - --pOutdoorCamera->numStru148s; - goto LABEL_162; - } - v66 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097); - memcpy(&array_50AC10[0], v102, 0x30u); - array_50AC10[0].flt_20 = v66; - array_50AC10[0].u = 0.0; - array_50AC10[0].v = 0.0; - v67 = pVertices2->vWorldViewPosition.x + 0.0000001000000011686097; - memcpy(&array_50AC10[1], pVertices2, sizeof(array_50AC10[1])); - array_50AC10[1].flt_20 = 1.0 / v67; - array_50AC10[1].u = 1.0; - array_50AC10[1].v = 1.0; - v68 = v101->vWorldViewPosition.x + 0.0000001000000011686097; - memcpy(&array_50AC10[2], v101, sizeof(array_50AC10[2])); - array_50AC10[2].flt_20 = 1.0 / v68; - array_50AC10[2].u = 1.0; - array_50AC10[2].v = 0.0; - - static stru154 static_sub_0048034E_stru_76D578; - /*static bool __init_flag1 = false; - if (!__init_flag1) - { - __init_flag1 = true; - - stru154::stru154(&static_sub_0048034E_stru_76D578); - }*/ - - v96 = pGame->pLightmapBuilder; - pGame->pLightmapBuilder->StackLights_TerrainFace(v99, &v87, array_50AC10, 3u, 1); - pDecalBuilder->_49BE8A(v40, *(float *)&v99, (int)&v87, array_50AC10, 3u, 1); - v100 = 3; - if ( byte_4D864C && pGame->uFlags & 0x80 ) - { - thisc = pGame->pIndoorCameraD3D; - if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, (unsigned int *)&v100, 0) == 1 && !v100 ) - //goto LABEL_126; - { - --pOutdoorCamera->numStru148s; - goto LABEL_162; - } - thisc->ViewTransform(array_50AC10, v100); - thisc->Project(array_50AC10, v100, 0); - } - this_3b = v102->vWorldViewPosition.x < 8.0 - || pVertices2->vWorldViewPosition.x < 8.0 - || v101->vWorldViewPosition.x < 8.0; - v69 = (double)pOutdoorCamera->shading_dist_mist; - v108 = v69 < v102->vWorldViewPosition.x || v69 < pVertices2->vWorldViewPosition.x || v69 < v101->vWorldViewPosition.x; - v70 = 0; - v96->std__vector_000004_size = 0; - if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 ) - { - if ( this_3b ) - v70 = 3; - else - v70 = v108 != 0 ? 5 : 0; - static_sub_0048034E_stru_76D578._49B0C9(v99, v87); - if ( pDecalBuilder->uNumDecals > 0 ) - pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70, -1); - } - if ( stru_F8AD28.uNumLightsApplied > 0 ) - v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70); - v71 = (RenderVertexSoft *)v59; - v72 = v100; - //v35 = byte_4D864C == 0; - v59->uNumVertices = v100;//??? - if ( !byte_4D864C && pGame->uFlags & 0x80 ) + { +LABEL_154: + v74 = v71->flags; + if ( !(BYTE1(v74) & 1) ) + { + if ( v74 & 2 && v71->uTileBitmapID == pRenderer->field_1036AC_bitmapid ) + { + v80 = false; + v75 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid]; + } + else + { + v75 = v71->uTileBitmapID; + v80 = true; + } + //v79 = 0; + //v78 = pBitmaps_LOD->pHardwareTextures[v75]; + v71->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v75];// Ritor1: It's temporary + //v77 = (int)v71; + //v76 = v71->uNumVertices; + //goto LABEL_161; + pRenderer->DrawTerrainPolygon(v71, pBitmaps_LOD->pHardwareTextures[v75]);//pRenderer->DrawTerrainPolygon(v76, (stru148 *)v71, v78, v79, v80); + goto LABEL_162; + } + v38 = (stru148 *)v71; + goto LABEL_56; + } + v73 = sr_424EE0_MakeFanFromTriangle(v72); + } + v71->uNumVertices = v73; + OutdoorCamera::Project(v73); goto LABEL_154; - if ( this_3b ) - { - v73 = sr_424CD7(v72); - } - else - { - if ( !v108 ) - { -LABEL_154: - v74 = v71[1].vWorldPosition.x; - if ( !(BYTE1(v74) & 1) ) - { - if ( v74 & 2 && LOWORD(v71[1].vWorldViewProjY) == pRenderer->field_1036AC_bitmapid ) - { - v80 = false; - v75 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid]; - } - else - { - v75 = v71[1].vWorldViewProjY; - v80 = true; - } - //v79 = 0; - v78 = pBitmaps_LOD->pHardwareTextures[v75]; - v77 = (int)v71; - v76 = v71->vWorldViewPosition.z; - //goto LABEL_161; - { - pRenderer->DrawTerrainPolygon(v76, (stru148 *)v71, v78, v79, v80); - goto LABEL_162; - } - } - v38 = (stru148 *)v71; - goto LABEL_56; - } - v73 = sr_424EE0_MakeFanFromTriangle(v72); - } - v71->vWorldViewPosition.z = v73; - OutdoorCamera::Project(v73); - goto LABEL_154; - } -} + } + } // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int); // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int); // 4D864C: using guessed type char byte_4D864C; @@ -7126,7 +7327,119 @@ return ::GetActorTintColor(a3, a4, a2, a5, a6); } - +void Render::DrawTerrainPolygon(stru148 *a3, IDirect3DTexture2 *pTexture)//new function +{ + int v5; // ebx@1 + int v6; // edi@1 + int v8; // eax@7 + float v9; // eax@12 + float *v10; // esi@12 + float v11; // ecx@14 + double v12; // st7@14 + double v13; // st7@14 + double v14; // st7@14 + signed int v15; // eax@14 + int v16; // eax@15 + float v17; // ST48_4@15 + char v18; // zf@17 + int v19; // eax@18 + int v20; // eax@18 + int v21; // edx@20 + signed int v22; // ecx@20 + int v23; // eax@20 + const char *v24; // ST4C_4@20 + unsigned int v25; // ST50_4@20 + int v26; // ST54_4@20 + int v27; // eax@20 + _UNKNOWN *v28; // eax@21 + int v29; // ecx@23 + int v30; // eax@23 + int v31; // eax@23 + int v32; // eax@24 + int v33; // eax@25 + int v34; // eax@25 + int v35; // eax@25 + int v36; // eax@25 + signed int v37; // ecx@26 + int v38; // eax@26 + _UNKNOWN *v39; // eax@27 + int v40; // edx@28 + int v41; // eax@29 + int v42; // eax@29 + int v43; // eax@29 + int v44; // eax@29 + unsigned int v46; // eax@29 + int v47; // eax@30 + int v48; // eax@30 + int v49; // eax@30 + double v52; // st6@35 + const char *v55; // [sp+4Ch] [bp-1Ch]@20 + int v57; // [sp+5Ch] [bp-Ch]@3 + signed int v59; // [sp+60h] [bp-8h]@12 + int v61; // [sp+64h] [bp-4h]@4 + int i; + + v6 = (int)this; + v5 = 0; + if (!this->uNumD3DSceneBegins) + return; + + + + + this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1); + this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); + if (this->bUsingSpecular) + { + this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1); + this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2); + this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1); + } + + pVertices[0].pos.x = array_50AC10[0].vWorldViewProjX; + pVertices[0].pos.y = array_50AC10[0].vWorldViewProjY; + pVertices[0].pos.z = 1.0 - 1.0 / (1000 * array_50AC10[0].vWorldViewPosition.x / (double)pOutdoorCamera->shading_dist_mist); + pVertices[0].rhw = 1.0 / (array_50AC10[0].vWorldViewPosition.x + 0.0000001000000011686097); + pVertices[0].diffuse = GetActorTintColor(a3->field_58, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0); + pVertices[0].specular = 0; + pVertices[0].texcoord.x = array_50AC10[0].u; + pVertices[0].texcoord.y = array_50AC10[0].v; + + pVertices[1].pos.x = array_50AC10[3].vWorldViewProjX; + pVertices[1].pos.y = array_50AC10[3].vWorldViewProjY; + pVertices[1].pos.z = 1.0 - 1.0 / (1000 * array_50AC10[3].vWorldViewPosition.x / (double)pOutdoorCamera->shading_dist_mist); + pVertices[1].rhw = 1.0 / (array_50AC10[3].vWorldViewPosition.x + 0.0000001000000011686097); + pVertices[1].diffuse = GetActorTintColor(a3->field_58, 0, array_50AC10[3].vWorldViewPosition.x, 0, 0); + pVertices[1].specular = 0; + pVertices[1].texcoord.x = array_50AC10[3].u; + pVertices[1].texcoord.y = array_50AC10[3].v; + + pVertices[2].pos.x = array_50AC10[1].vWorldViewProjX; + pVertices[2].pos.y = array_50AC10[1].vWorldViewProjY; + pVertices[2].pos.z = 1.0 - 1.0 / (1000 * array_50AC10[1].vWorldViewPosition.x / (double)pOutdoorCamera->shading_dist_mist); + pVertices[2].rhw = 1.0 / (array_50AC10[1].vWorldViewPosition.x + 0.0000001000000011686097); + pVertices[2].diffuse = GetActorTintColor(a3->field_58, 0, array_50AC10[1].vWorldViewPosition.x, 0, 0); + pVertices[2].specular = 0; + pVertices[2].texcoord.x = array_50AC10[1].u; + pVertices[2].texcoord.y = array_50AC10[1].v; + + memcpy(pVertices + 3, pVertices + 2, sizeof(RenderVertexD3D3)); + memcpy(pVertices + 4, pVertices + 1, sizeof(RenderVertexD3D3)); + + pVertices[5].pos.x = array_50AC10[2].vWorldViewProjX; + pVertices[5].pos.y = array_50AC10[2].vWorldViewProjY; + pVertices[5].pos.z = 1.0 - 1.0 / (1000 * array_50AC10[2].vWorldViewPosition.x / (double)pOutdoorCamera->shading_dist_mist); + pVertices[5].rhw = 1.0 / (array_50AC10[2].vWorldViewPosition.x + 0.0000001000000011686097); + pVertices[5].diffuse = GetActorTintColor(a3->field_58, 0, array_50AC10[2].vWorldViewPosition.x, 0, 0); + pVertices[5].specular = 0; + pVertices[5].texcoord.x = array_50AC10[2].u; + pVertices[5].texcoord.y = array_50AC10[2].v; + + + this->pRenderD3D->pDevice->SetTexture(0, pTexture); + this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, pVertices, 6, D3DDP_DONOTLIGHT); + +} //----- (004A26BC) -------------------------------------------------------- void Render::DrawTerrainPolygon(unsigned int uNumVertices, stru148 *a4, IDirect3DTexture2 *a5, int a6, int a7) { @@ -7276,13 +7589,9 @@ v51 = a7; } } - ErrD3D(pRenderD3D->pDevice->SetTexture(0, a5)); - ErrD3D(pRenderD3D->pDevice->DrawPrimitive( - D3DPT_TRIANGLEFAN, - D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, - arary_77E5C8, - uNumVertices, - 16)); + this->pRenderD3D->pDevice->SetTexture(0, a5); + this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, + arary_77E5C8, uNumVertices, 16); if ( a6 ) { ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));