comparison Render.cpp @ 1445:6de9c1316852

Слияние
author Ritor1
date Sat, 03 Aug 2013 00:00:31 +0600
parents a8b1bbac95d4 71a2cf416478
children bfe342ae0c1f
comparison
equal deleted inserted replaced
1444:7b1a94270756 1445:6de9c1316852
207 LABEL_9: 207 LABEL_9:
208 LOBYTE(result) = 0; 208 LOBYTE(result) = 0;
209 return result; 209 return result;
210 } 210 }
211 211
212
213 void Render::RenderTerrainD3D() // New function 212 void Render::RenderTerrainD3D() // New function
214 { 213 {
215 char result; // al@3
216 int v6; // ecx@8 214 int v6; // ecx@8
217 struct Polygon *pTile; // ebx@8 215 struct Polygon *pTilePolygon; // ebx@8
218 struct Polygon *v16;
219 unsigned int v18; // edi@22
220 int v35; // edi@63
221 int v37; // eax@73
222 int v39; // eax@80
223 char v40; // [sp-18h] [bp-70h]@2
224 int v41; // [sp-14h] [bp-6Ch]@2
225 int v42; // [sp-10h] [bp-68h]@2
226 int v43; // [sp-Ch] [bp-64h]@2
227 const char *v44; // [sp-8h] [bp-60h]@2
228 int v45; // [sp-4h] [bp-5Ch]@2
229 int v56;
230 int v57; // [sp+38h] [bp-20h]@36
231 int v64; // [sp+57h] [bp-1h]@2
232 int v62;
233 216
234 //warning: the game uses CW culling by default, ccw is incosistent 217 //warning: the game uses CW culling by default, ccw is incosistent
235 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); 218 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW);
236 219
237 static RenderVertexSoft pTerrainVertices[128 * 128];//vertexCountX and vertexCountZ 220 static RenderVertexSoft pTerrainVertices[128 * 128];//vertexCountX and vertexCountZ
269 // 252 //
270 for (unsigned int z = 0; z < 127; ++z) 253 for (unsigned int z = 0; z < 127; ++z)
271 { 254 {
272 for (unsigned int x = 0; x < 127; ++x) 255 for (unsigned int x = 0; x < 127; ++x)
273 { 256 {
274 pTile = &array_77EC08[pOutdoorCamera->uNumPolygons]; 257 pTilePolygon = &array_77EC08[pOutdoorCamera->uNumPolygons];
275 pTile->flags = 0; 258 pTilePolygon->flags = 0;
276 pTile->field_32 = 0; 259 pTilePolygon->field_32 = 0;
277 pTile->uTileBitmapID = pOutdoor->DoGetTileTexture(x, z); 260 pTilePolygon->uTileBitmapID = pOutdoor->DoGetTileTexture(x, z);
278 pTile->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[pTile->uTileBitmapID]; 261 pTilePolygon->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[pTilePolygon->uTileBitmapID];
279 if (pTile->uTileBitmapID == 0xFFFF) 262 if (pTilePolygon->uTileBitmapID == 0xFFFF)
280 continue; 263 continue;
281 264
282 //pTile->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(x, z); 265 //pTile->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(x, z);
283 pTile->flags = pOutdoor->GetSomeOtherTileInfo(x, z); 266 pTilePolygon->flags = pOutdoor->GetSomeOtherTileInfo(x, z);
284 pTile->field_32 = 0; 267 pTilePolygon->field_32 = 0;
285 pTile->field_59 = 1; 268 pTilePolygon->field_59 = 1;
286 pTile->sTextureDeltaU = 0; 269 pTilePolygon->sTextureDeltaU = 0;
287 pTile->sTextureDeltaV = 0; 270 pTilePolygon->sTextureDeltaV = 0;
288 // x,z x+1,z 271 // x,z x+1,z
289 // .____________. 272 // .____________.
290 // | | 273 // | |
291 // | | 274 // | |
292 // | | 275 // | |
307 array_73D150[3].u = 0; 290 array_73D150[3].u = 0;
308 array_73D150[3].v = 1; 291 array_73D150[3].v = 1;
309 //v58 = 0; 292 //v58 = 0;
310 //if (v58 == 4) // if all y == first y; primitive in xz plane 293 //if (v58 == 4) // if all y == first y; primitive in xz plane
311 //pTile->field_32 |= 0x0001; 294 //pTile->field_32 |= 0x0001;
312 pTile->pODMFace = nullptr; 295 pTilePolygon->pODMFace = nullptr;
313 pTile->uNumVertices = 4; 296 pTilePolygon->uNumVertices = 4;
314 pTile->field_59 = 5; 297 pTilePolygon->field_59 = 5;
315 298
316 //shading ()---------------------------------------------------------------------------- 299 //shading ()----------------------------------------------------------------------------
317 //uint norm_idx = pTerrainNormalIndices[2 * (z * 128 + x) + 1]; 300 //uint norm_idx = pTerrainNormalIndices[2 * (z * 128 + x) + 1];
318 uint norm_idx = pTerrainNormalIndices[2 * (x * 128 + z) + 1];// 1 , 1 301 uint norm_idx = pTerrainNormalIndices[2 * (x * 128 + z) + 2];
319 assert(norm_idx < uNumTerrainNormals); 302 assert(norm_idx < uNumTerrainNormals);
320 303
321 auto norm = pTerrainNormals + norm_idx; 304 auto norm = pTerrainNormals + norm_idx;
322 float _f = ((norm->x * (float)pOutdoor->vSunlight.x / 65536.0) - 305 float _f = ((norm->x * (float)pOutdoor->vSunlight.x / 65536.0) -
323 (norm->y * (float)pOutdoor->vSunlight.y / 65536.0) - 306 (norm->y * (float)pOutdoor->vSunlight.y / 65536.0) -
324 (norm->z * (float)pOutdoor->vSunlight.z / 65536.0)); 307 (norm->z * (float)pOutdoor->vSunlight.z / 65536.0));
325 pTile->dimming_level = 20.0 - floorf(20.0 * _f + 0.5f); 308 pTilePolygon->dimming_level = 20.0 - floorf(20.0 * _f + 0.5f);
326 //----------------------------------------------------------------------------------------------- 309 //-----------------------------------------------------------------------------------------------
327 310
328 ++pOutdoorCamera->uNumPolygons; 311 ++pOutdoorCamera->uNumPolygons;
329 ++pOutdoorCamera->field_44; 312 ++pOutdoorCamera->field_44;
330 assert(pOutdoorCamera->uNumPolygons < 20000); 313 assert(pOutdoorCamera->uNumPolygons < 20000);
331 314
332 pTile->uBModelID = 0; 315 pTilePolygon->uBModelID = 0;
333 pTile->uBModelFaceID = 0; 316 pTilePolygon->uBModelFaceID = 0;
334 pTile->field_50 = (8 * (0 | (0 << 6))) | 6; 317 pTilePolygon->field_50 = (8 * (0 | (0 << 6))) | 6;
335 for (unsigned int k = 0; k < pTile->uNumVertices; ++k) 318 for (unsigned int k = 0; k < pTilePolygon->uNumVertices; ++k)
336 { 319 {
337 memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft)); 320 memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft));
338 array_50AC10[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097); 321 array_50AC10[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097);
339 } 322 }
340 323
341 // check the transparency and texture (tiles) mapping ( ())---------------------- 324 // check the transparency and texture (tiles) mapping ( ())----------------------
342 bool transparent = false; 325 bool transparent = false;
343 if ( !( pTile->flags & 1 ) ) // TextureFrameTable 326 if ( !( pTilePolygon->flags & 1 ) ) // TextureFrameTable
344 { 327 {
345 if ( pTile->flags & 2 && pTile->uTileBitmapID == pRenderer->hd_water_tile_id) 328 if ( /*pTile->flags & 2 && */pTilePolygon->uTileBitmapID == pRenderer->hd_water_tile_id)
346 { 329 {
347 //transparent = false; 330 //transparent = false;
348 v6 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]; 331 v6 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame];
349 } 332 }
350 else 333 else
351 { 334 {
352 v6 = pTile->uTileBitmapID; 335 v6 = pTilePolygon->uTileBitmapID;
353 if ( !_strnicmp(pBitmaps_LOD->pTextures[pTile->uTileBitmapID].pName, "wtrdr", 5) ) 336 if ( !_strnicmp(pBitmaps_LOD->pTextures[pTilePolygon->uTileBitmapID].pName, "wtrdr", 5) )
354 transparent = true; 337 transparent = true;
355 } 338 }
356 339
357 assert(v6 < 1000); // many random crashes here 340 assert(v6 < 1000); // many random crashes here
358 341
359 // for all shore tiles - draw a tile water under them since they're half-empty 342 // for all shore tiles - draw a tile water under them since they're half-empty
360 if (!_strnicmp(pBitmaps_LOD->pTextures[pTile->uTileBitmapID].pName, "wtrdr", 5)) // all shore tile filenames are wtrdrXXX 343 if (!_strnicmp(pBitmaps_LOD->pTextures[pTilePolygon->uTileBitmapID].pName, "wtrdr", 5)) // all shore tile filenames are wtrdrXXX
361 pTile->DrawBorderTiles(); 344 pTilePolygon->DrawBorderTiles();
362 345
363 pRenderer->DrawTerrainPolygon(pTile->uNumVertices, pTile, pBitmaps_LOD->pHardwareTextures[v6], transparent, true); 346 pRenderer->DrawTerrainPolygon(pTilePolygon->uNumVertices, pTilePolygon, pBitmaps_LOD->pHardwareTextures[v6], transparent, true);
364 } 347 }
365 //else // 348 //else //
366 //pTile->DrawBorderTiles(); 349 //pTile->DrawBorderTiles();
367 //-------------------------------------------------------------------------------------------------------------------------------- 350 //--------------------------------------------------------------------------------------------------------------------------------
368 351
2768 } 2751 }
2769 2752
2770 //----- (0049F8B5) -------------------------------------------------------- 2753 //----- (0049F8B5) --------------------------------------------------------
2771 FILE *Render::SavePCXImage(const char *Filename, char *a3, int a4, int a5) 2754 FILE *Render::SavePCXImage(const char *Filename, char *a3, int a4, int a5)
2772 { 2755 {
2773 Render *v5; // esi@1 2756 //Render *v5; // esi@1
2774 FILE *result; // eax@1 2757 FILE *result; // eax@1
2775 FILE *v7; // edi@4 2758 FILE *v7; // edi@4
2776 int v8; // ecx@5 2759 int v8; // ecx@5
2777 int v9; // eax@5 2760 int v9; // eax@5
2778 int v10; // eax@7 2761 int v10; // eax@7
2790 PCXHeader_2 header2; // [sp+90h] [bp-14h]@4 2773 PCXHeader_2 header2; // [sp+90h] [bp-14h]@4
2791 void *ptr; // [sp+98h] [bp-Ch]@4 2774 void *ptr; // [sp+98h] [bp-Ch]@4
2792 int v24; // [sp+9Ch] [bp-8h]@2 2775 int v24; // [sp+9Ch] [bp-8h]@2
2793 char *i; // [sp+A0h] [bp-4h]@8 2776 char *i; // [sp+A0h] [bp-4h]@8
2794 2777
2795 v5 = this;
2796 result = fopen(Filename, "wb"); 2778 result = fopen(Filename, "wb");
2797 Filename = (const char *)result; 2779 Filename = (const char *)result;
2798 if ( result ) 2780 if ( result )
2799 { 2781 {
2800 v24 = a4; 2782 v24 = a4;
2851 { 2833 {
2852 a3 = (char *)ptr + v8; 2834 a3 = (char *)ptr + v8;
2853 i = (char *)ptr + 2 * v24; 2835 i = (char *)ptr + 2 * v24;
2854 do 2836 do
2855 { 2837 {
2856 *((char *)ptr + v10) = (signed int)(v5->uTargetRMask & *(short *)a5) >> (LOBYTE(v5->uTargetGBits) 2838 *((char *)ptr + v10) = (signed int)(this->uTargetRMask & *(short *)a5) >> (LOBYTE(this->uTargetGBits)
2857 + LOBYTE(v5->uTargetBBits) 2839 + LOBYTE(this->uTargetBBits)
2858 + v5->uTargetRBits 2840 + this->uTargetRBits
2859 - 8); 2841 - 8);
2860 a3[v10] = (signed int)(v5->uTargetGMask & *(short *)a5) >> (LOBYTE(v5->uTargetBBits) 2842 a3[v10] = (signed int)(this->uTargetGMask & *(short *)a5) >> (LOBYTE(this->uTargetBBits)
2861 + LOBYTE(v5->uTargetGBits) 2843 + LOBYTE(this->uTargetGBits)
2862 - 8); 2844 - 8);
2863 v11 = a5; 2845 v11 = a5;
2864 a5 += 2; 2846 a5 += 2;
2865 i[v10++] = (v5->uTargetBMask & *(char *)v11) << (8 - LOBYTE(v5->uTargetBBits)); 2847 i[v10++] = (this->uTargetBMask & *(char *)v11) << (8 - LOBYTE(this->uTargetBBits));
2866 } 2848 }
2867 while ( v10 < a4 ); 2849 while ( v10 < a4 );
2868 } 2850 }
2869 for ( i = 0; (signed int)i < v20; i += BYTE3(a5) ) 2851 for ( i = 0; (signed int)i < v20; i += BYTE3(a5) )
2870 { 2852 {
4945 } 4927 }
4946 // 4A26BC: could not find valid save-restore pair for esi 4928 // 4A26BC: could not find valid save-restore pair for esi
4947 // 4D864C: using guessed type char byte_4D864C; 4929 // 4D864C: using guessed type char byte_4D864C;
4948 4930
4949 //----- (004A2DA3) -------------------------------------------------------- 4931 //----- (004A2DA3) --------------------------------------------------------
4950 void Render::DrawSkyPolygon(unsigned int uNumVertices, struct Polygon *a3, IDirect3DTexture2 *pTexture) 4932 void Render::DrawSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture)
4951 { 4933 {
4952 int v7; // eax@7 4934 int v7; // eax@7
4953 float v13; // ST3C_4@8
4954 int i;
4955 4935
4956 if ( !this->uNumD3DSceneBegins ) 4936 if ( !this->uNumD3DSceneBegins )
4957 return; 4937 return;
4958 if ( uNumVertices >= 3 ) 4938 if ( uNumVertices >= 3 )
4959 { 4939 {
4962 { 4942 {
4963 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); 4943 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
4964 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE); 4944 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
4965 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO); 4945 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
4966 } 4946 }
4967 for ( i = 0; i < uNumVertices; ++i ) 4947 for ( uint i = 0; i < uNumVertices; ++i )
4968 { 4948 {
4969 pVertices[i].pos.x = array_50AC10[i].vWorldViewProjX; 4949 pVertices[i].pos.x = array_50AC10[i].vWorldViewProjX;
4970 pVertices[i].pos.y = array_50AC10[i].vWorldViewProjY; 4950 pVertices[i].pos.y = array_50AC10[i].vWorldViewProjY;
4971 pVertices[i].pos.z = 0.99989998; 4951 pVertices[i].pos.z = 0.99989998;
4972 pVertices[i].rhw = array_50AC10[i]._rhw; 4952 pVertices[i].rhw = array_50AC10[i]._rhw;
4973 4953
4974 pVertices[i].diffuse = ::GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, 1, 0); 4954 pVertices[i].diffuse = ::GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, 1, 0);
4975 v7 = 0; 4955 v7 = 0;
4976 if (this->bUsingSpecular) 4956 if (this->bUsingSpecular)
4977 { 4957 v7 = sub_47C3D7_get_fog_related_stuff(0, 1, array_50AC10[i].vWorldViewPosition.x);
4978 v13 = array_50AC10[i].vWorldViewPosition.x;
4979 v7 = sub_47C3D7_get_fog_related_stuff(0, 1, v13);
4980 }
4981 pVertices[i].specular = v7; 4958 pVertices[i].specular = v7;
4982 pVertices[i].texcoord.x = array_50AC10[i].u; 4959 pVertices[i].texcoord.x = array_50AC10[i].u;
4983 pVertices[i].texcoord.y = array_50AC10[i].v; 4960 pVertices[i].texcoord.y = array_50AC10[i].v;
4984 } 4961 }
4985 pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture); 4962 pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture);
5167 * (sin(*(float *)&v75) * -16192.0 - (double)SHIDWORD(v68))); 5144 * (sin(*(float *)&v75) * -16192.0 - (double)SHIDWORD(v68)));
5168 v7 = pFace->uPolygonType; 5145 v7 = pFace->uPolygonType;
5169 if ( v7 == 4 || v7 == 3 ) 5146 if ( v7 == 4 || v7 == 3 )
5170 v70 = v6; 5147 v70 = v6;
5171 stru_8019C8._48653D(65536, 0, 0, 0, 65536, 0); 5148 stru_8019C8._48653D(65536, 0, 0, 0, 65536, 0);
5172 v62._48607B(&stru_8019C8); 5149 v62.Create_48607B(&stru_8019C8);
5173 v62.uTileBitmapID = pFace->uBitmapID; 5150 v62.uTileBitmapID = pFace->uBitmapID;
5174 v62.pTexture = (Texture *)((signed __int16)v62.uTileBitmapID != -1 ? &pBitmaps_LOD->pTextures[(signed __int16)v62.uTileBitmapID] : 0); 5151 v62.pTexture = (Texture *)((signed __int16)v62.uTileBitmapID != -1 ? &pBitmaps_LOD->pTextures[(signed __int16)v62.uTileBitmapID] : 0);
5175 if ( !v62.pTexture ) 5152 if ( !v62.pTexture )
5176 return; 5153 return;
5177 v8 = pBLVRenderParams->sPartyRotX; 5154 v8 = pBLVRenderParams->sPartyRotX;