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