Mercurial > mm7
comparison Render.cpp @ 1787:0c4d3c6a9d5a
DrawBuildingsD3D cleared
author | Ritor1 |
---|---|
date | Fri, 04 Oct 2013 17:30:47 +0600 |
parents | 4da5644df18f |
children | dfafcd39c67b |
comparison
equal
deleted
inserted
replaced
1786:11f36943e818 | 1787:0c4d3c6a9d5a |
---|---|
8716 Log::Warning(L"SetBillboardBlendOptions: invalid opacity type (%u)", a1); | 8716 Log::Warning(L"SetBillboardBlendOptions: invalid opacity type (%u)", a1); |
8717 assert(false); | 8717 assert(false); |
8718 break; | 8718 break; |
8719 } | 8719 } |
8720 } | 8720 } |
8721 | |
8722 //----- (00424EE0) -------------------------------------------------------- | |
8723 int BuildingVerticesClipping(unsigned int uNumVertices) | |
8724 { | |
8725 signed int previous_vertices_flag; // edi@1 | |
8726 double t; // st6@10 | |
8727 bool current_vertices_flag; // [sp+Ch] [bp-28h]@6 | |
8728 signed int depth_num_vertices; // [sp+18h] [bp-1Ch]@1 | |
8729 int pNextVertices; | |
8730 //Доп инфо "Программирование трёхмерных игр для windows" Ламот стр 910 | |
8731 | |
8732 memcpy(&array_50AC10[uNumVertices], array_50AC10, sizeof(array_50AC10[uNumVertices])); | |
8733 depth_num_vertices = 0; | |
8734 previous_vertices_flag = 0; | |
8735 if ( array_50AC10[0].vWorldViewPosition.x <= pODMRenderParams->shading_dist_mist ) | |
8736 previous_vertices_flag = 1;//предыдущая грань меньше границы видимости | |
8737 if ( (signed int)uNumVertices <= 0 ) | |
8738 return 0; | |
8739 for ( uint i = 1; i <= uNumVertices; ++i ) | |
8740 { | |
8741 current_vertices_flag = pODMRenderParams->shading_dist_mist >= array_50AC10[i].vWorldViewPosition.x; | |
8742 if ( previous_vertices_flag != current_vertices_flag )//одна из граней за границей видимости | |
8743 { | |
8744 if ( current_vertices_flag )//текущая грань меньше границы видимости(предыдущая грань за пределами видимости) | |
8745 { | |
8746 //t = far_clip - v0.x / v1.x - v0.x (формула получения точки пересечения отрезка с плоскостью) | |
8747 t = (pODMRenderParams->shading_dist_mist - array_50AC10[i - 1].vWorldViewPosition.x) / (array_50AC10[i].vWorldViewPosition.x - array_50AC10[i - 1].vWorldViewPosition.x); | |
8748 array_507D30[depth_num_vertices].vWorldViewPosition.y = (array_50AC10[i].vWorldViewPosition.y - array_50AC10[i - 1].vWorldViewPosition.y) * t + array_50AC10[i - 1].vWorldViewPosition.y; | |
8749 array_507D30[depth_num_vertices].vWorldViewPosition.z = (array_50AC10[i].vWorldViewPosition.z - array_50AC10[i - 1].vWorldViewPosition.z) * t + array_50AC10[i - 1].vWorldViewPosition.z; | |
8750 array_507D30[depth_num_vertices].u = (array_50AC10[i].u - array_50AC10[i - 1].u) * t + array_50AC10[i - 1].u; | |
8751 array_507D30[depth_num_vertices].v = (array_50AC10[i].v - array_50AC10[i - 1].v) * t + array_50AC10[i - 1].v; | |
8752 } | |
8753 else//предыдущая грань меньше границы видимости(текущая грань вышла за пределы видимости) | |
8754 { | |
8755 //t = far_clip - v1.x / v0.x - v1.x | |
8756 t = (pODMRenderParams->shading_dist_mist - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i - 1].vWorldViewPosition.x - array_50AC10[i].vWorldViewPosition.x); | |
8757 array_507D30[depth_num_vertices].vWorldViewPosition.y = (array_50AC10[i - 1].vWorldViewPosition.y - array_50AC10[i].vWorldViewPosition.y) * t + array_50AC10[i].vWorldViewPosition.y; | |
8758 array_507D30[depth_num_vertices].vWorldViewPosition.z = (array_50AC10[i - 1].vWorldViewPosition.z - array_50AC10[i].vWorldViewPosition.z) * t + array_50AC10[i].vWorldViewPosition.z; | |
8759 array_507D30[depth_num_vertices].u = (array_50AC10[i - 1].u - array_50AC10[i].u) * t + array_50AC10[i].u; | |
8760 array_507D30[depth_num_vertices].v = (array_50AC10[i - 1].v - array_50AC10[i].v) * t + array_50AC10[i].v; | |
8761 } | |
8762 array_507D30[depth_num_vertices].vWorldViewPosition.x = pODMRenderParams->shading_dist_mist; | |
8763 array_507D30[depth_num_vertices]._rhw = 1.0 / pODMRenderParams->shading_dist_mist; | |
8764 ++depth_num_vertices; | |
8765 } | |
8766 if ( current_vertices_flag )//оба в границе видимости | |
8767 { | |
8768 pNextVertices = depth_num_vertices++; | |
8769 memcpy(&array_507D30[pNextVertices], &array_50AC10[i], 0x30); | |
8770 } | |
8771 previous_vertices_flag = current_vertices_flag; | |
8772 } | |
8773 if ( depth_num_vertices < 3 ) | |
8774 return 0; | |
8775 return depth_num_vertices; | |
8776 } | |
8777 | |
8778 //----- (0047840D) -------------------------------------------------------- | |
8779 void Render::DrawBuildingsD3D() | |
8780 { | |
8781 int v9; // ecx@8 | |
8782 Texture *pFaceTexture; // eax@10 | |
8783 unsigned int v16; // edi@22 | |
8784 int v27; // eax@57 | |
8785 int vertex_id; // eax@58 | |
8786 unsigned int v34; // eax@80 | |
8787 int v40; // [sp-4h] [bp-5Ch]@2 | |
8788 int v49; // [sp+2Ch] [bp-2Ch]@10 | |
8789 int v50; // [sp+30h] [bp-28h]@34 | |
8790 int v51; // [sp+34h] [bp-24h]@35 | |
8791 int v52; // [sp+38h] [bp-20h]@36 | |
8792 int v53; // [sp+3Ch] [bp-1Ch]@8 | |
8793 int uNumVertices; // [sp+4Ch] [bp-Ch]@34 | |
8794 int unused; // [sp+50h] [bp-8h]@3 | |
8795 | |
8796 if ( !pRenderer->pRenderD3D ) | |
8797 { | |
8798 MessageBoxW(nullptr, L"D3D version of RenderBuildings called in software!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odbuild.cpp:73", 0); | |
8799 } | |
8800 | |
8801 unused = 0; | |
8802 if ( (signed int)pOutdoor->uNumBModels > 0 ) | |
8803 { | |
8804 for ( uint model_id = 0; model_id < pOutdoor->uNumBModels; model_id++ ) | |
8805 { | |
8806 if ( IsBModelVisible(model_id, &unused) ) | |
8807 { | |
8808 pOutdoor->pBModels[model_id].field_40 |= 1; | |
8809 if ( pOutdoor->pBModels[model_id].uNumFaces > 0 ) | |
8810 { | |
8811 for ( int face_id = 0; face_id < pOutdoor->pBModels[model_id].uNumFaces; face_id++ ) | |
8812 { | |
8813 if (!pOutdoor->pBModels[model_id].pFaces[face_id].Invisible()) | |
8814 { | |
8815 v53 = 0; | |
8816 array_77EC08[pODMRenderParams->uNumPolygons].flags = 0; | |
8817 array_77EC08[pODMRenderParams->uNumPolygons].field_32 = 0; | |
8818 v9 = pOutdoor->pBModels[model_id].pFaces[face_id].uTextureID; | |
8819 if (pOutdoor->pBModels[model_id].pFaces[face_id].uAttributes & FACE_TEXTURE_FRAME) | |
8820 v9 = pTextureFrameTable->GetFrameTexture(v9, pEventTimer->uTotalGameTimeElapsed); | |
8821 pFaceTexture = pBitmaps_LOD->GetTexture(v9); | |
8822 array_77EC08[pODMRenderParams->uNumPolygons].pTexture = pFaceTexture; | |
8823 if (pOutdoor->pBModels[model_id].pFaces[face_id].uAttributes & FACE_FLUID) | |
8824 array_77EC08[pODMRenderParams->uNumPolygons].flags |= 2; | |
8825 if (pOutdoor->pBModels[model_id].pFaces[face_id].uAttributes & FACE_DO_NOT_LIGHT ) | |
8826 HIBYTE(array_77EC08[pODMRenderParams->uNumPolygons].flags) |= 4; | |
8827 if ( pOutdoor->pBModels[model_id].pFaces[face_id].uAttributes & 4 ) | |
8828 HIBYTE(array_77EC08[pODMRenderParams->uNumPolygons].flags) |= 4; | |
8829 else | |
8830 { | |
8831 if ( pOutdoor->pBModels[model_id].pFaces[face_id].uAttributes & 0x20 ) | |
8832 HIBYTE(array_77EC08[pODMRenderParams->uNumPolygons].flags) |= 8; | |
8833 } | |
8834 if (pOutdoor->pBModels[model_id].pFaces[face_id].uAttributes & 0x0800) | |
8835 array_77EC08[pODMRenderParams->uNumPolygons].flags |= 0x2000; | |
8836 else | |
8837 { | |
8838 if (pOutdoor->pBModels[model_id].pFaces[face_id].uAttributes & FACE_DONT_CACHE_TEXTURE) | |
8839 HIBYTE(array_77EC08[pODMRenderParams->uNumPolygons].flags) |= 0x10u; | |
8840 } | |
8841 array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaU = pOutdoor->pBModels[model_id].pFaces[face_id].sTextureDeltaU; | |
8842 array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaV = pOutdoor->pBModels[model_id].pFaces[face_id].sTextureDeltaV; | |
8843 v16 = GetTickCount() >> 4; | |
8844 if ( pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.z && abs(pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.z) >= 59082 ) | |
8845 { | |
8846 if ( BYTE1(array_77EC08[pODMRenderParams->uNumPolygons].flags) & 4 ) | |
8847 array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaV += v16 & array_77EC08[pODMRenderParams->uNumPolygons].pTexture->uHeightMinus1; | |
8848 if ( BYTE1(array_77EC08[pODMRenderParams->uNumPolygons].flags) & 8 ) | |
8849 array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaV -= v16 & array_77EC08[pODMRenderParams->uNumPolygons].pTexture->uHeightMinus1; | |
8850 } | |
8851 else | |
8852 { | |
8853 if ( BYTE1(array_77EC08[pODMRenderParams->uNumPolygons].flags) & 4 ) | |
8854 array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaV -= v16 & array_77EC08[pODMRenderParams->uNumPolygons].pTexture->uHeightMinus1; | |
8855 if ( BYTE1(array_77EC08[pODMRenderParams->uNumPolygons].flags) & 8 ) | |
8856 array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaV += v16 & array_77EC08[pODMRenderParams->uNumPolygons].pTexture->uHeightMinus1; | |
8857 } | |
8858 if ( BYTE1(array_77EC08[pODMRenderParams->uNumPolygons].flags) & 0x10 ) | |
8859 array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaU -= v16 & array_77EC08[pODMRenderParams->uNumPolygons].pTexture->uWidthMinus1; | |
8860 else | |
8861 { | |
8862 if ( BYTE1(array_77EC08[pODMRenderParams->uNumPolygons].flags) & 0x20 ) | |
8863 array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaU += v16 & array_77EC08[pODMRenderParams->uNumPolygons].pTexture->uWidthMinus1; | |
8864 } | |
8865 v50 = 0; | |
8866 v49 = 0; | |
8867 uNumVertices = pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices; | |
8868 if ( pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices > 0 ) | |
8869 { | |
8870 for ( uint vertex_id = 1; vertex_id <= pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices; vertex_id++ ) | |
8871 { | |
8872 array_73D150[vertex_id - 1].vWorldPosition.x = pOutdoor->pBModels[model_id].pVertices.pVertices[pOutdoor->pBModels[model_id].pFaces[face_id].pVertexIDs[vertex_id - 1]].x; | |
8873 array_73D150[vertex_id - 1].vWorldPosition.y = pOutdoor->pBModels[model_id].pVertices.pVertices[pOutdoor->pBModels[model_id].pFaces[face_id].pVertexIDs[vertex_id - 1]].y; | |
8874 array_73D150[vertex_id - 1].vWorldPosition.z = pOutdoor->pBModels[model_id].pVertices.pVertices[pOutdoor->pBModels[model_id].pFaces[face_id].pVertexIDs[vertex_id - 1]].z; | |
8875 array_73D150[vertex_id - 1].u = (array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaU + (signed __int16)pOutdoor->pBModels[model_id].pFaces[face_id].pTextureUIDs[vertex_id - 1]) * (1.0 / (double)pFaceTexture->uTextureWidth); | |
8876 array_73D150[vertex_id - 1].v = (array_77EC08[pODMRenderParams->uNumPolygons].sTextureDeltaV + (signed __int16)pOutdoor->pBModels[model_id].pFaces[face_id].pTextureVIDs[vertex_id - 1]) * (1.0 / (double)pFaceTexture->uTextureHeight); | |
8877 } | |
8878 for ( uint i = 1; i <= pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices; i++ ) | |
8879 { | |
8880 if ( pOutdoor->pBModels[model_id].pVertices.pVertices[pOutdoor->pBModels[model_id].pFaces[face_id].pVertexIDs[0]].z == array_73D150[i - 1].vWorldPosition.z ) | |
8881 ++v53; | |
8882 pGame->pIndoorCameraD3D->ViewTransform(&array_73D150[i - 1], 1); | |
8883 if ( array_73D150[i - 1].vWorldViewPosition.x < 8.0 || array_73D150[i - 1].vWorldViewPosition.x > pODMRenderParams->shading_dist_mist ) | |
8884 { | |
8885 if ( array_73D150[i - 1].vWorldViewPosition.x >= 8.0 ) | |
8886 v49 = 1; | |
8887 else | |
8888 v50 = 1; | |
8889 } | |
8890 else | |
8891 pGame->pIndoorCameraD3D->Project(&array_73D150[i - 1], 1, 0); | |
8892 } | |
8893 } | |
8894 if ( v53 == pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices ) | |
8895 LOBYTE(array_77EC08[pODMRenderParams->uNumPolygons].field_32) |= 1; | |
8896 array_77EC08[pODMRenderParams->uNumPolygons].pODMFace = &pOutdoor->pBModels[model_id].pFaces[face_id]; | |
8897 array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices; | |
8898 array_77EC08[pODMRenderParams->uNumPolygons].field_59 = 5; | |
8899 v51 = (unsigned __int64)(-pOutdoor->vSunlight.x * (signed __int64)pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.x) >> 16; | |
8900 v53 = (unsigned __int64)(-pOutdoor->vSunlight.y * (signed __int64)pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.y) >> 16; | |
8901 v52 = (unsigned __int64)(-pOutdoor->vSunlight.z * (signed __int64)pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.z) >> 16; | |
8902 array_77EC08[pODMRenderParams->uNumPolygons].dimming_level = 20 - (20 * (signed int)(v51 + v53 + v52) >> 16); | |
8903 if ( array_77EC08[pODMRenderParams->uNumPolygons].dimming_level < 0 ) | |
8904 array_77EC08[pODMRenderParams->uNumPolygons].dimming_level = 0; | |
8905 if ( array_77EC08[pODMRenderParams->uNumPolygons].dimming_level > 31 ) | |
8906 array_77EC08[pODMRenderParams->uNumPolygons].dimming_level = 31; | |
8907 if ( pODMRenderParams->uNumPolygons >= 1999 + 5000) | |
8908 return; | |
8909 if ( ODMFace::IsBackfaceCulled(&pOutdoor->pBModels[model_id].pFaces[face_id], array_73D150, &array_77EC08[pODMRenderParams->uNumPolygons]) ) | |
8910 { | |
8911 pOutdoor->pBModels[model_id].pFaces[face_id].bVisible = 1; | |
8912 array_77EC08[pODMRenderParams->uNumPolygons].uBModelFaceID = face_id; | |
8913 array_77EC08[pODMRenderParams->uNumPolygons].uBModelID = model_id; | |
8914 v27 = 8 * (face_id | (model_id << 6)); | |
8915 LOBYTE(v27) = v27 | 6; | |
8916 array_77EC08[pODMRenderParams->uNumPolygons].field_50 = v27; | |
8917 for ( int vertex_id = 0; vertex_id < pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices; ++vertex_id) | |
8918 { | |
8919 memcpy(&array_50AC10[vertex_id], &array_73D150[vertex_id], sizeof(array_50AC10[vertex_id])); | |
8920 array_50AC10[vertex_id]._rhw = 1.0 / (array_73D150[vertex_id].vWorldViewPosition.x + 0.0000001); | |
8921 } | |
8922 static stru154 static_RenderBuildingsD3D_stru_73C834; | |
8923 /*static bool __init_flag = false; | |
8924 if (!__init_flag) | |
8925 { | |
8926 __init_flag = true; | |
8927 static_RenderBuildingsD3D_byte_73C84C_init_flag |= 1u; | |
8928 stru154::stru154(&static_RenderBuildingsD3D_stru_73C834); | |
8929 atexit(loc_4789D4); | |
8930 }*/ | |
8931 | |
8932 v40 = (int)&pOutdoor->pBModels[model_id].pFaces[face_id]; | |
8933 pGame->pLightmapBuilder->ApplyLights_OutdoorFace(&pOutdoor->pBModels[model_id].pFaces[face_id]); | |
8934 pDecalBuilder->ApplyDecals_OutdoorFace(&pOutdoor->pBModels[model_id].pFaces[face_id]); | |
8935 pGame->pLightmapBuilder->std__vector_000004_size = 0; | |
8936 int v31 = 0; | |
8937 if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 ) | |
8938 { | |
8939 v31 = v50 ? 3 : v49 != 0 ? 5 : 0; | |
8940 static_RenderBuildingsD3D_stru_73C834.GetFacePlaneAndClassify(&pOutdoor->pBModels[model_id].pFaces[face_id], &pOutdoor->pBModels[model_id].pVertices); | |
8941 if ( pDecalBuilder->uNumDecals > 0 ) | |
8942 { | |
8943 v40 = -1; | |
8944 pDecalBuilder->ApplyDecals(31 - array_77EC08[pODMRenderParams->uNumPolygons].dimming_level, 2, &static_RenderBuildingsD3D_stru_73C834, | |
8945 pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices, array_50AC10, 0, (char)v31, -1); | |
8946 } | |
8947 } | |
8948 if ( stru_F8AD28.uNumLightsApplied > 0 ) | |
8949 pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_RenderBuildingsD3D_stru_73C834, uNumVertices, array_50AC10, 0, (char)v31); | |
8950 if ( v50 ) | |
8951 { | |
8952 array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = sr_424CD7(pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices); | |
8953 uNumVertices = array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices; | |
8954 ODM_Project(array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices); | |
8955 } | |
8956 if ( v49 ) | |
8957 { | |
8958 array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = BuildingVerticesClipping(pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices); | |
8959 uNumVertices = array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices; | |
8960 ODM_Project(array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices); | |
8961 } | |
8962 if ( uNumVertices ) | |
8963 { | |
8964 if ( array_77EC08[pODMRenderParams->uNumPolygons].flags & 2 ) | |
8965 { | |
8966 if ( BYTE1(array_77EC08[pODMRenderParams->uNumPolygons].flags) & 0x3C ) | |
8967 v34 = pRenderer->pHDWaterBitmapIDs[0]; | |
8968 else | |
8969 v34 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]; | |
8970 v40 = (int)pBitmaps_LOD->pHardwareTextures[v34]; | |
8971 } | |
8972 else | |
8973 v40 = (int)pBitmaps_LOD->pHardwareTextures[v9]; | |
8974 pRenderer->DrawPolygon(uNumVertices, &array_77EC08[pODMRenderParams->uNumPolygons], &pOutdoor->pBModels[model_id].pFaces[face_id], (IDirect3DTexture2 *)v40); | |
8975 } | |
8976 } | |
8977 } | |
8978 } | |
8979 } | |
8980 } | |
8981 } | |
8982 } | |
8983 return; | |
8984 } |