comparison Render.cpp @ 1427:1987f2cca08f

m
author Ritor1
date Thu, 01 Aug 2013 09:26:05 +0600
parents 5930342f092b
children 71a2cf416478
comparison
equal deleted inserted replaced
1424:5930342f092b 1427:1987f2cca08f
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) + 2]; 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
4945 } 4928 }
4946 // 4A26BC: could not find valid save-restore pair for esi 4929 // 4A26BC: could not find valid save-restore pair for esi
4947 // 4D864C: using guessed type char byte_4D864C; 4930 // 4D864C: using guessed type char byte_4D864C;
4948 4931
4949 //----- (004A2DA3) -------------------------------------------------------- 4932 //----- (004A2DA3) --------------------------------------------------------
4950 void Render::DrawSkyPolygon(unsigned int uNumVertices, struct Polygon *a3, IDirect3DTexture2 *pTexture) 4933 void Render::DrawSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture)
4951 { 4934 {
4952 int v7; // eax@7 4935 int v7; // eax@7
4953 float v13; // ST3C_4@8
4954 int i;
4955 4936
4956 if ( !this->uNumD3DSceneBegins ) 4937 if ( !this->uNumD3DSceneBegins )
4957 return; 4938 return;
4958 if ( uNumVertices >= 3 ) 4939 if ( uNumVertices >= 3 )
4959 { 4940 {
4962 { 4943 {
4963 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); 4944 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
4964 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE); 4945 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
4965 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO); 4946 this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
4966 } 4947 }
4967 for ( i = 0; i < uNumVertices; ++i ) 4948 for ( uint i = 0; i < uNumVertices; ++i )
4968 { 4949 {
4969 pVertices[i].pos.x = array_50AC10[i].vWorldViewProjX; 4950 pVertices[i].pos.x = array_50AC10[i].vWorldViewProjX;
4970 pVertices[i].pos.y = array_50AC10[i].vWorldViewProjY; 4951 pVertices[i].pos.y = array_50AC10[i].vWorldViewProjY;
4971 pVertices[i].pos.z = 0.99989998; 4952 pVertices[i].pos.z = 0.99989998;
4972 pVertices[i].rhw = array_50AC10[i]._rhw; 4953 pVertices[i].rhw = array_50AC10[i]._rhw;
4973 4954
4974 pVertices[i].diffuse = ::GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, 1, 0); 4955 pVertices[i].diffuse = ::GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, 1, 0);
4975 v7 = 0; 4956 v7 = 0;
4976 if (this->bUsingSpecular) 4957 if (this->bUsingSpecular)
4977 { 4958 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; 4959 pVertices[i].specular = v7;
4982 pVertices[i].texcoord.x = array_50AC10[i].u; 4960 pVertices[i].texcoord.x = array_50AC10[i].u;
4983 pVertices[i].texcoord.y = array_50AC10[i].v; 4961 pVertices[i].texcoord.y = array_50AC10[i].v;
4984 } 4962 }
4985 pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture); 4963 pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture);
5167 * (sin(*(float *)&v75) * -16192.0 - (double)SHIDWORD(v68))); 5145 * (sin(*(float *)&v75) * -16192.0 - (double)SHIDWORD(v68)));
5168 v7 = pFace->uPolygonType; 5146 v7 = pFace->uPolygonType;
5169 if ( v7 == 4 || v7 == 3 ) 5147 if ( v7 == 4 || v7 == 3 )
5170 v70 = v6; 5148 v70 = v6;
5171 stru_8019C8._48653D(65536, 0, 0, 0, 65536, 0); 5149 stru_8019C8._48653D(65536, 0, 0, 0, 65536, 0);
5172 v62._48607B(&stru_8019C8); 5150 v62.Create_48607B(&stru_8019C8);
5173 v62.uTileBitmapID = pFace->uBitmapID; 5151 v62.uTileBitmapID = pFace->uBitmapID;
5174 v62.pTexture = (Texture *)((signed __int16)v62.uTileBitmapID != -1 ? &pBitmaps_LOD->pTextures[(signed __int16)v62.uTileBitmapID] : 0); 5152 v62.pTexture = (Texture *)((signed __int16)v62.uTileBitmapID != -1 ? &pBitmaps_LOD->pTextures[(signed __int16)v62.uTileBitmapID] : 0);
5175 if ( !v62.pTexture ) 5153 if ( !v62.pTexture )
5176 return; 5154 return;
5177 v8 = pBLVRenderParams->sPartyRotX; 5155 v8 = pBLVRenderParams->sPartyRotX;