# HG changeset patch # User Ritor1 # Date 1432478962 -21600 # Node ID 4d199006c7161a1218df1de1ddf81c17db1c32a6 # Parent d433439699beeb9a9af61b66b899f41f6fd8dc6d debug_terrain_polygin diff -r d433439699be -r 4d199006c716 Build/Visual Studio 2012/World of Might and Magic.vcxproj --- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj Thu May 21 18:33:07 2015 +0600 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj Sun May 24 20:49:22 2015 +0600 @@ -142,6 +142,7 @@ + @@ -258,7 +259,6 @@ - @@ -326,6 +326,7 @@ + @@ -524,7 +525,6 @@ - diff -r d433439699be -r 4d199006c716 Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters --- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Thu May 21 18:33:07 2015 +0600 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Sun May 24 20:49:22 2015 +0600 @@ -486,7 +486,6 @@ Engine - GUI\NewUI\Core @@ -619,6 +618,9 @@ Engine\Serialization + + Engine + @@ -1266,7 +1268,6 @@ Engine - GUI\NewUI\Core @@ -1402,6 +1403,9 @@ Engine\Serialization + + Engine + diff -r d433439699be -r 4d199006c716 Engine/Graphics/IndoorCameraD3D.cpp --- a/Engine/Graphics/IndoorCameraD3D.cpp Thu May 21 18:33:07 2015 +0600 +++ b/Engine/Graphics/IndoorCameraD3D.cpp Sun May 24 20:49:22 2015 +0600 @@ -593,24 +593,9 @@ //----- (00437A55) -------------------------------------------------------- void IndoorCameraD3D::debug_outline_d3d(const RenderVertexD3D3 *pLineVertices, unsigned int uNumLines, int uDiffuse, float z_stuff) { - unsigned int v5; // esi@1 - const RenderVertexD3D3 *v6; // ecx@2 - unsigned int v7; // ebx@2 - const RenderVertexD3D3 *v8; // edi@3 - - v5 = 0; - if ( (signed int)(uNumLines - 1) > 0 ) - { - v6 = pLineVertices; - v5 = uNumLines - 1; - for ( v7 = uNumLines - 1; v7; --v7 ) - { - v8 = v6 + 1; - pRenderer->do_draw_debug_line_d3d(v6, uDiffuse, v6 + 1, uDiffuse, z_stuff); - v6 = v8; - } - } - pRenderer->do_draw_debug_line_d3d(&pLineVertices[v5], uDiffuse, pLineVertices, uDiffuse, z_stuff); + for (int i = 0; i < uNumLines-1; ++i) + pRenderer->do_draw_debug_line_d3d(&pLineVertices[i], uDiffuse, &pLineVertices[i+1], uDiffuse, z_stuff); + pRenderer->do_draw_debug_line_d3d(&pLineVertices[uNumLines-1], uDiffuse, pLineVertices, uDiffuse, z_stuff); } //----- (004379EE) -------------------------------------------------------- diff -r d433439699be -r 4d199006c716 Engine/Graphics/LightmapBuilder.cpp --- a/Engine/Graphics/LightmapBuilder.cpp Thu May 21 18:33:07 2015 +0600 +++ b/Engine/Graphics/LightmapBuilder.cpp Sun May 24 20:49:22 2015 +0600 @@ -845,22 +845,20 @@ arg4.x = 1.0f; arg4.y = 1.0f; arg4.z = 1.0f; - if (lights_flag) + + if (indices != -1) { - if (indices != -1) - { - for (unsigned int i = 0; i < MobileLightsCount; ++i) - { - if ( !pRenderer->DrawLightmap(&MobileLights[i], &arg4, 0.0) ) - Error("Invalid lightmap detected! (%u)", i); - } - } - else - { - for (unsigned int i = 0; i < StationaryLightsCount; ++i) - if ( !pRenderer->DrawLightmap(&StationaryLights[i], &arg4, 0.0) ) - Error("Invalid lightmap detected! (%u)", i); - } + for (unsigned int i = 0; i < MobileLightsCount; ++i) + { + if ( !pRenderer->DrawLightmap(&MobileLights[i], &arg4, 0.0) ) + Error("Invalid lightmap detected! (%u)", i); + } + } + else + { + for (unsigned int i = 0; i < StationaryLightsCount; ++i) + if ( !pRenderer->DrawLightmap(&StationaryLights[i], &arg4, 0.0) ) + Error("Invalid lightmap detected! (%u)", i); } pRenderer->EndLightmaps(); diff -r d433439699be -r 4d199006c716 Engine/Graphics/Render.cpp --- a/Engine/Graphics/Render.cpp Thu May 21 18:33:07 2015 +0600 +++ b/Engine/Graphics/Render.cpp Sun May 24 20:49:22 2015 +0600 @@ -223,7 +223,6 @@ return LOBYTE(v13) | ((LOBYTE(v11) | (((v6 << 8) | v9) << 8)) << 8);*/ } - void Render::RenderTerrainD3D() // New function { int v6; // ecx@8 @@ -369,6 +368,7 @@ memcpy(&VertexRenderList[k], &array_73D150[k], sizeof(struct RenderVertexSoft)); VertexRenderList[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097); } + //shading (затенение)---------------------------------------------------------------------------- //uint norm_idx = pTerrainNormalIndices[2 * (z * 128 + x) + 1]; uint norm_idx = pTerrainNormalIndices[2 * (x * 128 + z) + 1]; @@ -388,7 +388,7 @@ //MessageBoxA(nullptr, "Ritor1: function StackLights_TerrainFace needed refactoring and result - slows", "", 0); //__debugbreak(); - pEngine->pLightmapBuilder->StackLights_TerrainFace(norm, &Light_tile_dist, VertexRenderList, 4, 1);//Ritor1: slows + pEngine->pLightmapBuilder->StackLights_TerrainFace(norm, &Light_tile_dist, VertexRenderList, 4, 1);//Ritor1: slows //pDecalBuilder->_49BE8A(pTilePolygon, norm, &Light_tile_dist, VertexRenderList, 4, 1); } unsigned int a5 = 4; @@ -453,20 +453,20 @@ transparent = true; } - assert(v6 < 1000); // many random crashes here - - // for all shore tiles - draw a tile water under them since they're half-empty - if (!_strnicmp(pBitmaps_LOD->pTextures[pTilePolygon->uTileBitmapID].pName, "wtrdr", 5)) // all shore tile filenames are wtrdrXXX - DrawBorderTiles(pTilePolygon); - - pRenderer->DrawTerrainPolygon(pTilePolygon->uNumVertices, pTilePolygon, pBitmaps_LOD->pHardwareTextures[v6], transparent, true); + assert(v6 < 1000); // many random crashes here + + // for all shore tiles - draw a tile water under them since they're half-empty + if (!_strnicmp(pBitmaps_LOD->pTextures[pTilePolygon->uTileBitmapID].pName, "wtrdr", 5)) // all shore tile filenames are wtrdrXXX + DrawBorderTiles(pTilePolygon); + + pRenderer->DrawTerrainPolygon(pTilePolygon->uNumVertices, pTilePolygon, pBitmaps_LOD->pHardwareTextures[v6], transparent, true); } //else //здесь уже пограничные тайлы воды //pTile->DrawBorderTiles(); //-------------------------------------------------------------------------------------------------------------------------------- - --pODMRenderParams->uNumPolygons; - --pODMRenderParams->field_44; + //--pODMRenderParams->uNumPolygons; + //--pODMRenderParams->field_44; } } } @@ -4601,32 +4601,23 @@ //----- (004A26BC) -------------------------------------------------------- void Render::DrawTerrainPolygon(unsigned int uNumVertices, struct Polygon *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders) { - unsigned int v8; // ebx@1 int v11; // eax@5 int v20; // eax@14 unsigned int v45; // eax@28 - v8 = 0; if (!this->uNumD3DSceneBegins) return; if ( uNumVertices < 3) return; - //v61 = pVertices; - - /* v9 = pEngine->pLightmapBuilder; - v65 = v9; - v10 = v9->StationaryLightsCount;*/ if ( byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_01_lightmap_related) { v11 = ::GetActorTintColor(a4->dimming_level, 0, VertexRenderList[0].vWorldViewPosition.x, 0, 0); pEngine->pLightmapBuilder->DrawLightmaps(v11/*, 0*/); } - else - { - if (transparent || !pEngine->pLightmapBuilder->StationaryLightsCount || - byte_4D864C && pEngine->uFlags & 2 ) - { + else if (transparent || !pEngine->pLightmapBuilder->StationaryLightsCount || + byte_4D864C && pEngine->uFlags & GAME_FLAGS_2_SATURATE_LIGHTMAPS ) + { if (clampAtTextureBorders) this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP); else @@ -4657,29 +4648,25 @@ d3d_vertex_buffer[i].pos.z = 1.0 - 1.0 / ((VertexRenderList[i].vWorldViewPosition.x * 1000) / (double)pODMRenderParams->shading_dist_mist); d3d_vertex_buffer[i].rhw = 1.0 / (VertexRenderList[i].vWorldViewPosition.x + 0.0000001); d3d_vertex_buffer[i].diffuse = ::GetActorTintColor(a4->dimming_level, 0, VertexRenderList[i].vWorldViewPosition.x, 0, 0); - if ( this->bUsingSpecular ) - { + d3d_vertex_buffer[i].specular = 0; + if ( this->bUsingSpecular ) d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_specular(0, 0, VertexRenderList[i].vWorldViewPosition.x); - } - else - { - d3d_vertex_buffer[i].specular = 0; - } + d3d_vertex_buffer[i].texcoord.x = VertexRenderList[i].u; d3d_vertex_buffer[i].texcoord.y = VertexRenderList[i].v; } this->pRenderD3D->pDevice->SetTexture(0, a5); - this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, d3d_vertex_buffer, uNumVertices, 16); + this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, d3d_vertex_buffer, uNumVertices, D3DDP_DONOTLIGHT); if (transparent) { ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); } - } - else - { + } + else if(pEngine->pLightmapBuilder->StationaryLightsCount) + { for (uint i = 0; i < uNumVertices; ++i) { @@ -4688,17 +4675,10 @@ d3d_vertex_buffer[i].pos.z = 1.0 - 1.0 / ((VertexRenderList[i].vWorldViewPosition.x * 1000) / (double)pODMRenderParams->shading_dist_mist); d3d_vertex_buffer[i].rhw = 1.0 / (VertexRenderList[i].vWorldViewPosition.x + 0.0000001); d3d_vertex_buffer[i].diffuse = GetActorTintColor(a4->dimming_level, 0, VertexRenderList[i].vWorldViewPosition.x, 0, 0); + d3d_vertex_buffer[i].specular = 0; if ( this->bUsingSpecular ) - { d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_specular(0, 0, VertexRenderList[i].vWorldViewPosition.x); - } - else - { - d3d_vertex_buffer[i].specular = 0; - } - //__debugbreak(); // warning C4700: uninitialized local variable 'v20' used - //d3d_vertex_buffer[i].specular = v20; - d3d_vertex_buffer[i].texcoord.x = VertexRenderList[i].u; + d3d_vertex_buffer[i].texcoord.x = VertexRenderList[i].u; d3d_vertex_buffer[i].texcoord.y = VertexRenderList[i].v; } ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE)); @@ -4707,20 +4687,18 @@ ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE)); ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0)); - ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, + ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,//рисуется текстурка с светом D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, d3d_vertex_buffer, uNumVertices, - 16)); - //v63 = (const char *)v7->pRenderD3D->pDevice; - ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE)); - //(*(void (**)(void))(*(int *)v63 + 88))(); + D3DDP_DONOTLIGHT)); + //ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE)); pEngine->pLightmapBuilder->DrawLightmaps(-1/*, 0*/); for (uint i = 0; i < uNumVertices; ++i) { d3d_vertex_buffer[i].diffuse = -1; } - ErrD3D(pRenderD3D->pDevice->SetTexture(0, a5)); + ErrD3D(pRenderD3D->pDevice->SetTexture(0, a5));//текстурка ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP)); if ( !pRenderer->bUsingSpecular ) { @@ -4733,7 +4711,7 @@ D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, d3d_vertex_buffer, uNumVertices, - 16)); + D3DDP_DONOTLIGHT)); if ( pRenderer->bUsingSpecular ) { ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE)); @@ -4751,22 +4729,21 @@ D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, d3d_vertex_buffer, uNumVertices, - 16)); + D3DDP_DONOTLIGHT)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); - //v44 = pRenderer->pRenderD3D->pDevice; v45 = GetLevelFogColor(); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, v45 & 0xFFFFFF)); - v8 = 0; - ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0)); + ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, FALSE)); } ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); - ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, v8)); - } + ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); + //} } //if (pIndoorCamera->flags & INDOOR_CAMERA_DRAW_TERRAIN_OUTLINES || pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_TERRAIN_OUTLINES) - if (pIndoorCameraD3D->debug_flags & ODM_RENDER_DRAW_TERRAIN_OUTLINES) + //if (pIndoorCameraD3D->debug_flags & ODM_RENDER_DRAW_TERRAIN_OUTLINES) + if (debug_terrain_polygin) pIndoorCameraD3D->debug_outline_d3d(d3d_vertex_buffer, uNumVertices, 0x00FFFFFF, 0.0); } // 4A26BC: could not find valid save-restore pair for esi @@ -5214,7 +5191,7 @@ } else { - if (!pEngine->pLightmapBuilder->StationaryLightsCount || byte_4D864C && pEngine->uFlags & 2) + if (!pEngine->pLightmapBuilder->StationaryLightsCount || byte_4D864C && pEngine->uFlags & GAME_FLAGS_2_SATURATE_LIGHTMAPS) { for (uint i = 0; i < uNumVertices; ++i) { @@ -8843,27 +8820,22 @@ ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); } - - //----- (00437C96) -------------------------------------------------------- void Render::do_draw_debug_line_d3d(const RenderVertexD3D3 *pLineBegin, signed int sDiffuseBegin, const RenderVertexD3D3 *pLineEnd, signed int sDiffuseEnd, float z_stuff) { - double v6; // st7@2 - std::string v9; // [sp-18h] [bp-60h]@3 - RenderVertexD3D3 v13[2]; // [sp+8h] [bp-40h]@2 - - //if ( pRenderer->pRenderD3D ) - { - v6 = 0.001 - z_stuff; - memcpy(v13, pLineBegin, 0x20u); - memcpy(&v13[1], pLineEnd, sizeof(v13[1])); - v13[0].pos.z = v6; - v13[1].pos.z = v6; - v13[0].diffuse = sDiffuseBegin; - v13[1].diffuse = sDiffuseEnd; - ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr)); - ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_LINELIST, 452, v13, 2, 16)); - } + RenderVertexD3D3 vertices[2]; // [sp+8h] [bp-40h]@2 + + memcpy(&vertices[0], pLineBegin, sizeof(vertices[0])); + memcpy(&vertices[1], pLineEnd, sizeof(vertices[1])); + + vertices[0].pos.z = 0.001 - z_stuff; + vertices[1].pos.z = 0.001 - z_stuff; + + vertices[0].diffuse = sDiffuseBegin; + vertices[1].diffuse = sDiffuseEnd; + + ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr)); + ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_LINELIST, 452, vertices, 2, D3DDP_DONOTLIGHT)); } diff -r d433439699be -r 4d199006c716 Engine/Graphics/Render.h --- a/Engine/Graphics/Render.h Thu May 21 18:33:07 2015 +0600 +++ b/Engine/Graphics/Render.h Sun May 24 20:49:22 2015 +0600 @@ -103,7 +103,6 @@ #pragma pack(pop) extern std::array array_77EC08; - /* 142 */ #pragma pack(push, 1) struct stru149 @@ -292,6 +291,8 @@ //float DrawBezierTerrain(); virtual void RenderTerrainD3D(); + + //void DrawTerrainSW(int a1, int a2, int a3, int a4); //void ExecOutdoorDrawSW(); diff -r d433439699be -r 4d199006c716 Engine/Graphics/Viewport.cpp --- a/Engine/Graphics/Viewport.cpp Thu May 21 18:33:07 2015 +0600 +++ b/Engine/Graphics/Viewport.cpp Sun May 24 20:49:22 2015 +0600 @@ -396,12 +396,12 @@ POINT a2; // [sp+84h] [bp-8h]@3 int clickable_distance = 512; - int distance = HIWORD(v0); - bool in_range = distance < clickable_distance; v1 = pMouse->GetCursorPos(&a2); //if ( pRenderer->pRenderD3D ) v0 = pEngine->pVisInstance->get_picked_object_zbuf_val(); + int distance = HIWORD(v0); + bool in_range = distance < clickable_distance; //else // v0 = pRenderer->pActiveZBuffer[v1->x + pSRZBufferLineOffsets[v1->y]]; diff -r d433439699be -r 4d199006c716 Engine/mm7_data.h --- a/Engine/mm7_data.h Thu May 21 18:33:07 2015 +0600 +++ b/Engine/mm7_data.h Sun May 24 20:49:22 2015 +0600 @@ -785,4 +785,5 @@ extern bool draw_terrain_dist_mist; extern bool no_actors; extern bool lights_flag; -extern bool debug_lights; \ No newline at end of file +extern bool debug_lights; +extern bool debug_terrain_polygin; \ No newline at end of file diff -r d433439699be -r 4d199006c716 OSWindow.cpp --- a/OSWindow.cpp Thu May 21 18:33:07 2015 +0600 +++ b/OSWindow.cpp Sun May 24 20:49:22 2015 +0600 @@ -32,8 +32,9 @@ bool bSnow = false; bool draw_terrain_dist_mist = false;//новая дальность отрисовки тайлов bool no_actors = false; // remove all monsters / убрать всех монстров -bool lights_flag = false; +bool lights_flag = true; bool debug_lights = false; +bool debug_terrain_polygin = false; bool OSWindow::OnMouseLeftClick(int x, int y) { @@ -664,8 +665,14 @@ AppendMenuW(debug_lights, MF_ENABLED | MF_STRING, 40125, L"Debug lights on"); AppendMenuW(debug_lights, MF_ENABLED | MF_STRING, 40126, L"Debug lights off"); } - AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40023, L"Lighting Mode"); - AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40024, L"Lighting Geometry"); + HMENU debug_terrain = CreatePopupMenu(); + AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_terrain, L"Debug Terrain");//40104 + { + AppendMenuW(debug_terrain, MF_ENABLED | MF_STRING, 40127, L"Debug Terrain on"); + AppendMenuW(debug_terrain, MF_ENABLED | MF_STRING, 40128, L"Debug Terrain off"); + } + AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING | MF_GRAYED, 40023, L"Lighting Mode"); + AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING | MF_GRAYED, 40024, L"Lighting Geometry"); //AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING/* | MF_GRAYED*/, 40123, L"Lights Off"); AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING | MF_GRAYED, 40105, L"Colored Lights"); @@ -931,6 +938,8 @@ case 40124: lights_flag = false; break; case 40125: debug_lights = true; break; case 40126: debug_lights = false; break; + case 40127: debug_terrain_polygin = true; break; + case 40128: debug_terrain_polygin = false; break; } return true;