Mercurial > mm7
diff Vis.cpp @ 214:8646cad02950
Слияние
author | Ritor1 |
---|---|
date | Sun, 17 Feb 2013 00:19:51 +0600 |
parents | f96601c7e503 982c1ec5a983 |
children | bcd55744c2f4 |
line wrap: on
line diff
--- a/Vis.cpp Sun Feb 17 00:19:34 2013 +0600 +++ b/Vis.cpp Sun Feb 17 00:19:51 2013 +0600 @@ -1,45 +1,53 @@ +#include <assert.h> + #include "Vis.h" #include "Outdoor.h" #include "Game.h" #include "Actor.h" #include "IndoorCamera.h" #include "Viewport.h" -#include "stru157.h" #include "mm7_data.h" //#include "MM7.h" -static Vis_stru1 Vis_static_sub_4C1944_stru_F8BDE8; +static Vis_SelectionList Vis_static_sub_4C1944_stru_F8BDE8; + +Vis_SelectionFilter vis_sprite_filter_1 = {VisObjectType_Sprite, OBJECT_Decoration, 0, 0, 2}; // 00F93E1C +Vis_SelectionFilter vis_sprite_filter_2 = {VisObjectType_Sprite, OBJECT_Decoration, 0, 0, 2}; // 00F93E30 +Vis_SelectionFilter vis_face_filter = {VisObjectType_Face, OBJECT_Any, -1, 0, 0}; // 00F93E44 +Vis_SelectionFilter vis_door_filter = {VisObjectType_Face, OBJECT_BLVDoor, -1, 0x100000, 0}; // 00F93E58 +Vis_SelectionFilter vis_sprite_filter_3 = {VisObjectType_Sprite, OBJECT_Decoration, -1, 0, 4}; // 00F93E6C +Vis_SelectionFilter vis_sprite_filter_4 = {VisObjectType_Any, OBJECT_Item, -1, 0, 0}; // static to sub_44EEA7 //----- (004C1026) -------------------------------------------------------- -Vis_stru1_stru0 *Vis::_4C1026(BLVFace *a2, unsigned int a3, float a4) +Vis_ObjectInfo *Vis::_4C1026(BLVFace *face, unsigned int a3, float pick_depth) { char *v4; // eax@4 signed int v5; // ecx@4 - BLVFace *v6; // ecx@7 - unsigned int v7; // edi@7 + //BLVFace *v6; // ecx@7 + //unsigned int v7; // edi@7 Vec3_short_ *v8; // eax@9 char *v9; // edx@9 signed int v10; // esi@10 - Vec3_int_ **v11; // edx@13 - char *v12; // eax@13 - double v13; // st7@14 - signed int v14; // ebx@14 - Vis *v15; // ebx@15 - Vis_stru1_stru0 *result; // eax@21 - Vis_stru1_stru0 *v17; // ecx@24 + //Vec3_int_ **v11; // edx@13 + //char *v12; // eax@13 + //double v13; // st7@14 + //signed int v14; // ebx@14 + //Vis *v15; // ebx@15 + //Vis_ObjectInfo *result; // eax@21 + //Vis_ObjectInfo *v17; // ecx@24 RenderVertexSoft pRay[2]; // [sp+20h] [bp-70h]@17 int v20; // [sp+84h] [bp-Ch]@10 - int v21; // [sp+88h] [bp-8h]@16 - int v22; // [sp+8Ch] [bp-4h]@16 + //int v21; // [sp+88h] [bp-8h]@16 + //int v22; // [sp+8Ch] [bp-4h]@16 signed int v23; // [sp+98h] [bp+8h]@7 - auto ecx0 = this; + //auto ecx0 = this; - static Vis_stru1 static_sub_4C1026_stru_F8FE00; + static Vis_SelectionList static_sub_4C1026_stru_F8FE00; static_sub_4C1026_stru_F8FE00.uNumPointers = 0; static bool _init_flag = false; @@ -51,138 +59,150 @@ static_sub_4C1026_array_F8F200[i].flt_2C = 0.0f; } - v6 = a2; + //v6 = a2; v23 = 0; - v7 = v6->uNumVertices; - if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) + //v7 = face->uNumVertices; + if (uCurrentlyLoadedLevelType == LEVEL_Indoor) { - if ( (signed int)v7 > 0 ) + __debugbreak(); // refactor for BLV picking + if ( (signed int)face->uNumVertices > 0 ) { v8 = pIndoor->pVertices; v9 = (char *)&static_sub_4C1026_array_F8F200[0].vWorldPosition.y; do { v10 = v23++; - v20 = v8[v6->pVertexIDs[v10]].x; + v20 = v8[face->pVertexIDs[v10]].x; *((float *)v9 - 1) = (double)v20; - v20 = v8[v6->pVertexIDs[v10]].y; + v20 = v8[face->pVertexIDs[v10]].y; *(float *)v9 = (double)v20; v9 += 48; - v20 = v8[v6->pVertexIDs[v10]].z; + v20 = v8[face->pVertexIDs[v10]].z; *((float *)v9 - 11) = (double)v20; } - while ( v23 < (signed int)v7 ); + while ( v23 < (signed int)face->uNumVertices ); + } + } + else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) + { + uint bmodel_id = a3 >> 9; + auto v = (Vec3_int_ *)pOutdoor->pBModels[bmodel_id].pVertices.pVertices; + for (uint i = 0; i < face->uNumVertices; ++i) + { + static_sub_4C1026_array_F8F200[i].vWorldPosition.x = v[face->pVertexIDs[i]].x; + static_sub_4C1026_array_F8F200[i].vWorldPosition.y = v[face->pVertexIDs[i]].y; + static_sub_4C1026_array_F8F200[i].vWorldPosition.z = v[face->pVertexIDs[i]].z; } } - else - { - if ( (signed int)v7 > 0 ) - { - v11 = &pOutdoor->pBModels[a3 >> 9].pVertices.pVertices; - v12 = (char *)&static_sub_4C1026_array_F8F200[0].vWorldPosition.y; - do - { - *((float *)v12 - 1) = (double)(*v11)[v6->pVertexIDs[v23]].x; - v13 = (double)(*v11)[v6->pVertexIDs[v23]].y; - v14 = v23++; - *(float *)v12 = v13; - v12 += 48; - *((float *)v12 - 11) = (double)(*v11)[v6->pVertexIDs[v14]].z; - } - while ( v23 < (signed int)v7 ); - } - } - pGame->pIndoorCameraD3D->ViewTransform(static_sub_4C1026_array_F8F200, v7); - pGame->pIndoorCameraD3D->Project(static_sub_4C1026_array_F8F200, v7, 1); - v15 = this; - SortVectors_x(static_sub_4C1026_array_F8F200, 0, v7 - 1); - if ( static_sub_4C1026_array_F8F200[0].vWorldViewPosition.x > (double)a4 - || (_4C1495(static_sub_4C1026_array_F8F200, v7, (float *)&v21, (float *)&v22), - _4C12C3_FindSomeBillboard(static_sub_4C1026_array_F8F200, v7, *(float *)&v21, *(float *)&v22)) - || ((CastPickRay(pRay, *(float *)&v21, *(float *)&v22, a4), uCurrentlyLoadedLevelType != LEVEL_Indoor) ? PickOutdoor(a4, pRay, &static_sub_4C1026_stru_F8FE00, &a5, 1) : PickIndoor(a4, pRay, &static_sub_4C1026_stru_F8FE00, &a5), - (static_sub_4C1026_stru_F8FE00.create_object_pointers(0), - sort_object_pointers( - static_sub_4C1026_stru_F8FE00.array_1804, - 0, - static_sub_4C1026_stru_F8FE00.uNumPointers - 1), - !static_sub_4C1026_stru_F8FE00.uNumPointers) - || (result = static_sub_4C1026_stru_F8FE00.sub_4C2551(2, a3)) == 0 - || (signed int)static_sub_4C1026_stru_F8FE00.uNumPointers > 1 - && ((signed int)static_sub_4C1026_stru_F8FE00.uNumPointers <= 0 ? (v17 = 0) : (v17 = static_sub_4C1026_stru_F8FE00.array_1804[0]), - result != v17)) ) - result = 0; - return result; + else assert(false); + + pGame->pIndoorCameraD3D->ViewTransform(static_sub_4C1026_array_F8F200, face->uNumVertices); + pGame->pIndoorCameraD3D->Project(static_sub_4C1026_array_F8F200, face->uNumVertices, 1); + + //v15 = this; + SortVectors_x(static_sub_4C1026_array_F8F200, 0, face->uNumVertices - 1); + if (static_sub_4C1026_array_F8F200[0].vWorldViewPosition.x > pick_depth) + return nullptr; + + float screenspace_center_x, + screenspace_center_y; + GetPolygonScreenSpaceCenter(static_sub_4C1026_array_F8F200, face->uNumVertices, &screenspace_center_x, &screenspace_center_y); + if (IsPolygonOccludedByBillboard(static_sub_4C1026_array_F8F200, face->uNumVertices, screenspace_center_x, screenspace_center_y)) + return nullptr; + + CastPickRay(pRay, screenspace_center_x, screenspace_center_y, pick_depth); + + if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) + PickOutdoorFaces_Mouse(pick_depth, pRay, &static_sub_4C1026_stru_F8FE00, &vis_face_filter, true); + else if (uCurrentlyLoadedLevelType == LEVEL_Indoor) + PickIndoorFaces_Mouse(pick_depth, pRay, &static_sub_4C1026_stru_F8FE00, &vis_face_filter); + else assert(false); + + static_sub_4C1026_stru_F8FE00.create_object_pointers(); + sort_object_pointers(static_sub_4C1026_stru_F8FE00.object_pointers, 0, static_sub_4C1026_stru_F8FE00.uNumPointers - 1); + if (!static_sub_4C1026_stru_F8FE00.uNumPointers) + return nullptr; + + if (!static_sub_4C1026_stru_F8FE00.sub_4C2551(2, a3)) + return nullptr; + + if (static_sub_4C1026_stru_F8FE00.uNumPointers) + return static_sub_4C1026_stru_F8FE00.object_pointers[0]; + else return nullptr; } // F91E08: using guessed type char static_sub_4C1026_byte_F91E08__init_flags; //----- (004C12C3) -------------------------------------------------------- -char Vis::_4C12C3_FindSomeBillboard(RenderVertexSoft *a1, int a2, float a3, float a4) +bool Vis::IsPolygonOccludedByBillboard(RenderVertexSoft *vertices, int num_vertices, float x, float y) { - signed int v5; // esi@1 - RenderBillboardD3D *v6; // edi@2 - double v7; // st7@9 - int v8; // edx@9 - RenderVertexSoft *v9; // ecx@10 - char result; // al@24 - Vis *thisa; // [sp+10h] [bp-8h]@1 - float thisb; // [sp+10h] [bp-8h]@9 - signed int v13; // [sp+14h] [bp-4h]@1 - float a3a; // [sp+28h] [bp+10h]@9 - float a4a; // [sp+2Ch] [bp+14h]@9 + //signed int v5; // esi@1 + //RenderBillboardD3D *v6; // edi@2 + //double v7; // st7@9 + //int v8; // edx@9 + //RenderVertexSoft *v9; // ecx@10 + //char result; // al@24 + //Vis *thisa; // [sp+10h] [bp-8h]@1 + //float thisb; // [sp+10h] [bp-8h]@9 + //signed int v13; // [sp+14h] [bp-4h]@1 + //float a3a; // [sp+28h] [bp+10h]@9 + //float a4a; // [sp+2Ch] [bp+14h]@9 - v13 = -1; - v5 = 0; - thisa = this; - if ( (signed int)pRenderer->uNumBillboardsToDraw <= 0 ) - { - return 0; - } - v6 = pRenderer->pBillboardRenderListD3D; - do - { - if ( IsPointInsideD3DBillboard(v6, a3, a4) - && (v13 == -1 - || (unsigned int)pBillboardRenderList[v6->uParentBillboardID].sZValue < pBillboardRenderList[pRenderer->pBillboardRenderListD3D[v13].uParentBillboardID].sZValue) ) - v13 = v5; - ++v5; - ++v6; - } - while ( v5 < (signed int)pRenderer->uNumBillboardsToDraw ); - if ( v13 == -1 ) + int v13 = -1; + //v5 = 0; + //thisa = this; + + //v6 = pRenderer->pBillboardRenderListD3D; + for (uint i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) { - return 0; - } - v7 = 3.4028235e38; - v8 = a2; - a4a = 3.4028235e38; - a3a = -3.4028235e38; - thisb = -3.4028235e38; - if ( a2 > 0 ) - { - v9 = a1; - do + auto billboard = pRenderer->pBillboardRenderListD3D + i; + if (IsPointInsideD3DBillboard(billboard, x, y)) { - if ( v9->vWorldViewProjX < v7 ) - v7 = v9->vWorldViewProjX; - if ( v9->vWorldViewProjX > (double)a3a ) - a3a = v9->vWorldViewProjX; - if ( v9->vWorldViewProjY < (double)a4a ) - a4a = v9->vWorldViewProjY; - if ( v9->vWorldViewProjY > (double)thisb ) - thisb = v9->vWorldViewProjY; - ++v9; - --v8; + if (v13 == -1) + v13 = i; + else if ((unsigned int)pBillboardRenderList[billboard->uParentBillboardID].sZValue < pBillboardRenderList[pRenderer->pBillboardRenderListD3D[v13].uParentBillboardID].sZValue) + v13 = i; } - while ( v8 ); } - if ( v7 < pRenderer->pBillboardRenderListD3D[v13].pQuards[0].pos.x - || pRenderer->pBillboardRenderListD3D[v13].pQuards[0].pos.y > (double)a4a - || pRenderer->pBillboardRenderListD3D[v13].pQuards[3].pos.x < (double)a3a - || pRenderer->pBillboardRenderListD3D[v13].pQuards[1].pos.y < (double)thisb ) - result = 0; - else - result = 1; - return result; + + if ( v13 == -1 ) + return false; + + //v8 = num_vertices; + //v7 = 3.4028235e38; + float min_x = FLT_MAX; + //a4a = 3.4028235e38; + float min_y = FLT_MAX; + //a3a = -3.4028235e38; + float max_x = -FLT_MAX; + //thisb = -3.4028235e38; + float max_y = -FLT_MAX; + for (uint i = 0; i < num_vertices; ++i) + { + //v9 = a1; + //do + //{ + auto v = vertices + i; + + if (v->vWorldViewProjX < min_x) + min_x = v->vWorldViewProjX; + if (v->vWorldViewProjX > max_x) + max_x = v->vWorldViewProjX; + + if (v->vWorldViewProjY < min_y) + min_y = v->vWorldViewProjY; + if (v->vWorldViewProjY > max_y) + max_y = v->vWorldViewProjY; + //++v9; + //--v8; + //} + //while ( v8 ); + } + + if (min_x < pRenderer->pBillboardRenderListD3D[v13].pQuards[0].pos.x || pRenderer->pBillboardRenderListD3D[v13].pQuards[0].pos.y > min_y || + pRenderer->pBillboardRenderListD3D[v13].pQuards[3].pos.x < max_x || pRenderer->pBillboardRenderListD3D[v13].pQuards[1].pos.y < max_y) + return false; + + return true; } //----- (004C1417) -------------------------------------------------------- @@ -200,96 +220,45 @@ } //----- (004C1495) -------------------------------------------------------- -float *Vis::_4C1495(RenderVertexSoft *Src, int a2, float *a3, float *a4) +void Vis::GetPolygonScreenSpaceCenter(RenderVertexSoft *vertices, int num_vertices, float *out_center_x, float *out_center_y) { char *v5; // eax@2 signed int v6; // ecx@2 float *result; // eax@5 - Vis *thisa; // [sp+0h] [bp-4h]@1 - thisa = this; - - static bool static_sub_4C1495_byte_F8E9F8__init_flags = false; // weak static RenderVertexSoft static_sub_4C1495_array_F8DDF8[64]; - if ( !static_sub_4C1495_byte_F8E9F8__init_flags ) - { - static_sub_4C1495_byte_F8E9F8__init_flags = true; - for (uint i = 0; i < 64; ++i) - static_sub_4C1495_array_F8DDF8[i].flt_2C = 0.0f; - } + memcpy(static_sub_4C1495_array_F8DDF8, vertices, 48 * num_vertices); - memcpy(static_sub_4C1495_array_F8DDF8, Src, 48 * a2); - sort_objects_2(static_sub_4C1495_array_F8DDF8, 0, a2 - 1); - *a3 = (*(float *)&Vis_static_sub_4C1944_stru_F8BDE8.array_1804[12 * a2 + 509] - - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX) - * 0.5 - + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX; - sort_objects_3(static_sub_4C1495_array_F8DDF8, 0, a2 - 1); - result = a4; - *a4 = (*(float *)&Vis_static_sub_4C1944_stru_F8BDE8.array_1804[12 * a2 + 510] - - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY) - * 0.5 - + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY; - return result; + SortByScreenSpaceX(static_sub_4C1495_array_F8DDF8, 0, num_vertices - 1); + *out_center_x = (static_sub_4C1495_array_F8DDF8[num_vertices - 1].vWorldViewProjX - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX) * 0.5 + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX; + + SortByScreenSpaceY(static_sub_4C1495_array_F8DDF8, 0, num_vertices - 1); + *out_center_y = (static_sub_4C1495_array_F8DDF8[num_vertices - 1].vWorldViewProjY - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY) * 0.5 + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY; } //----- (004C1542) -------------------------------------------------------- -void Vis::PickBillboards(float fPickDepth, float fX, float fY, Vis_stru1 *a4, stru157 *a2) +void Vis::PickBillboards_Mouse(float fPickDepth, float fX, float fY, Vis_SelectionList *list, Vis_SelectionFilter *filter) { - int v6; // ST1C_4@6 - //Vis_stru1_stru0 *v7; // edi@6 - //Vis *thisa; // [sp+20h] [bp-Ch]@1 - int v9; // [sp+24h] [bp-8h]@2 - //unsigned int uD3DBillboardIdx; // [sp+28h] [bp-4h]@1 - - /*uD3DBillboardIdx = 0; - thisa = this; - if ( (signed int)pRenderer->uNumBillboardsToDraw > 0 ) + for (uint i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) { - v9 = pRenderer->pBillboardRenderListD3D;//[0].uParentBillboardID; - do + auto d3d_billboard = pRenderer->pBillboardRenderListD3D + i; + if (is_part_of_selection((void *)i, filter) && IsPointInsideD3DBillboard(d3d_billboard, fX, fY)) { - if ( is_part_of_selection((BLVFace *)uD3DBillboardIdx, a2) - && IsPointInsideD3DBillboard((RenderBillboardD3D *)(v9 - 38), fX, fY) ) - { - if ( DoesRayIntersectBillboard(fPickDepth, uD3DBillboardIdx) ) - { - v6 = pBillboardRenderList[v9->uParentBillboardID].sZValue; - v7 = &a4->array_0004[a4->uNumPointers]; - v7->pObjectInfo = (void *)v9->uParentBillboardID; - v7 = (Vis_stru1_stru0 *)((char *)v7 + 4); - v7->pObjectInfo = (void *)v6; - v7->sZValue = 1; - ++a4->uNumPointers; - } - } - ++uD3DBillboardIdx; - ++v9; - } - while ( (signed int)uD3DBillboardIdx < (signed int)pRenderer->uNumBillboardsToDraw ); - }*/ - for (unsigned int i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) - { - v9 = (int)&pRenderer->pBillboardRenderListD3D[i]; - - if (is_part_of_selection((BLVFace *)i, a2)) - if (IsPointInsideD3DBillboard(&pRenderer->pBillboardRenderListD3D[i], fX, fY)) if (DoesRayIntersectBillboard(fPickDepth, i)) { - v6 = pBillboardRenderList[pRenderer->pBillboardRenderListD3D[i].uParentBillboardID].sZValue; + auto billboard = &pBillboardRenderList[d3d_billboard->uParentBillboardID]; - a4->array_0004[a4->uNumPointers].pObjectInfo = (void *)pRenderer->pBillboardRenderListD3D[i].uParentBillboardID; - a4->array_0004[a4->uNumPointers].sZValue = v6; - a4->array_0004[a4->uNumPointers++].uObjectType = 1; + list->AddObject((void *)d3d_billboard->uParentBillboardID, VisObjectType_Sprite, billboard->sZValue); } - } + } + } } //----- (004C1607) -------------------------------------------------------- bool Vis::IsPointInsideD3DBillboard(RenderBillboardD3D *a1, float x, float y) { - RenderBillboardD3D *result; // eax@1 + //RenderBillboardD3D *result; // eax@1 double v5; // st7@2 float v6; // ecx@2 float v7; // ST00_4@3 @@ -317,27 +286,28 @@ float v29; // [sp+8h] [bp-4h]@2 float a1a; // [sp+14h] [bp+8h]@2 - result = a1; if ( a1->uParentBillboardID == -1 ) - goto LABEL_14; + return false; + + //result = a1; v5 = a1->pQuards[0].pos.x; a1a = a1->pQuards[3].pos.x; - v6 = result->pQuards[0].pos.y; - result = (RenderBillboardD3D *)LODWORD(result->pQuards[1].pos.y); + v6 = a1->pQuards[0].pos.y; + //result = (RenderBillboardD3D *)LODWORD(result->pQuards[1].pos.y); v29 = v6; - LODWORD(v28) = (int)result; + v28 = a1->pQuards[1].pos.y; if ( v5 > a1a ) { v7 = v5; - HIWORD(result) = HIWORD(v7); + //HIWORD(result) = HIWORD(v7); v5 = a1a; a1a = v7; } if ( v6 > (double)v28 ) { - result = (RenderBillboardD3D *)LODWORD(v28); + //result = (RenderBillboardD3D *)LODWORD(v28); v28 = v6; - LODWORD(v29) = (int)result; + v29 = v28; } v9 = x + 1.0; //UNDEF(v8); @@ -345,19 +315,17 @@ //v11 = 0; //v12 = v9 == v5; //BYTE1(result) = HIBYTE(v8);//crash - if ( v9 >= v5 - && (v14 = x - 1.0, v14<=a1a)///*UNDEF(v13),*/ v15 = v14 < a1a, v16 = 0, v17 = v14 == a1a, BYTE1(result) = HIBYTE(v13), v15 | v17) - && (v19 = y + 1.0, v19>=v29)///*UNDEF(v18),*/ v20 = v19 < v29, v21 = 0, v22 = v19 == v29, BYTE1(result) = HIBYTE(v18), v19 >= v29) - && (v24 = y - 1.0, v24<=v28))///*UNDEF(v23),*/ v25 = v24 < v28, v26 = 0, v27 = v24 == v28, BYTE1(result) = HIBYTE(v23), v25 | v27) ) - LOBYTE(result) = 1; + if (v9 >= v5 && + (v14 = x - 1.0, v14<=a1a) &&///*UNDEF(v13),*/ v15 = v14 < a1a, v16 = 0, v17 = v14 == a1a, BYTE1(result) = HIBYTE(v13), v15 | v17) + (v19 = y + 1.0, v19>=v29) &&///*UNDEF(v18),*/ v20 = v19 < v29, v21 = 0, v22 = v19 == v29, BYTE1(result) = HIBYTE(v18), v19 >= v29) + (v24 = y - 1.0, v24<=v28))///*UNDEF(v23),*/ v25 = v24 < v28, v26 = 0, v27 = v24 == v28, BYTE1(result) = HIBYTE(v23), v25 | v27) ) + return true; else -LABEL_14: - LOBYTE(result) = 0; - return (bool)result; + return false; } //----- (004C16B4) -------------------------------------------------------- -void Vis::PickIndoor(float fDepth, RenderVertexSoft *pRay, Vis_stru1 *a4, stru157 *a5) +void Vis::PickIndoorFaces_Mouse(float fDepth, RenderVertexSoft *pRay, Vis_SelectionList *list, Vis_SelectionFilter *filter) { int v5; // eax@1 signed int v6; // edi@2 @@ -366,7 +334,7 @@ int v9; // eax@7 unsigned int *pNumPointers; // eax@7 unsigned int v11; // ecx@7 - Vis_stru1_stru0 *v12; // edi@7 + Vis_ObjectInfo *v12; // edi@7 RenderVertexSoft a1; // [sp+Ch] [bp-44h]@1 BLVFace *v14; // [sp+3Ch] [bp-14h]@7 void *v15; // [sp+40h] [bp-10h]@7 @@ -374,6 +342,8 @@ int v17; // [sp+48h] [bp-8h]@1 Vis *thisa; // [sp+4Ch] [bp-4h]@1 + __debugbreak(); // refactor for BLV picking + v5 = 0; thisa = this; v17 = 0; @@ -385,7 +355,7 @@ if ( v6 < (signed int)pIndoor->uNumFaces ) { v7 = v6; - if ( is_part_of_selection(&pIndoor->pFaces[v6], a5) ) + if ( is_part_of_selection(&pIndoor->pFaces[v6], filter) ) { if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[v7]) ) { @@ -395,14 +365,14 @@ v9 = _48B561_mess_with_scaling_along_z(/*v8, */a1.vWorldViewPosition.x); LOWORD(v9) = 0; v15 = (void *)((8 * v6 | 6) + v9); - pNumPointers = &a4->uNumPointers; + pNumPointers = &list->uNumPointers; v16 = 2; - v11 = a4->uNumPointers; + v11 = list->uNumPointers; v14 = &pIndoor->pFaces[v7]; - v12 = &a4->array_0004[v11]; - v12->pObjectInfo = &pIndoor->pFaces[v7]; - v12 = (Vis_stru1_stru0 *)((char *)v12 + 4); - v12->pObjectInfo = v15; + v12 = &list->object_pool[v11]; + v12->object = &pIndoor->pFaces[v7]; + v12 = (Vis_ObjectInfo *)((char *)v12 + 4); + v12->object = v15; v12->sZValue = v16; ++*pNumPointers; } @@ -415,99 +385,40 @@ } //----- (004C17CF) -------------------------------------------------------- -void Vis::PickOutdoor(float fDepth, RenderVertexSoft *pRay, Vis_stru1 *a4, stru157 *a5, char a6) -{ - int v6; // esi@1 - unsigned int v7; // ecx@1 - BSPModel *v8; // ebx@3 - bool v9; // eax@3 - int v10; // eax@8 - ODMFace *v11; // esi@10 - int v12; // ecx@12 - int v13; // eax@12 - unsigned int *pNumPointers; // eax@12 - Vis_stru1_stru0 *v15; // edi@12 - BLVFace thisa; // [sp+10h] [bp-B8h]@1 - RenderVertexSoft a1; // [sp+70h] [bp-58h]@1 - void *v18; // [sp+A0h] [bp-28h]@12 - void *v19; // [sp+A4h] [bp-24h]@12 - int v20; // [sp+A8h] [bp-20h]@12 - int v21; // [sp+ACh] [bp-1Ch]@8 - Vis *v22; // [sp+B0h] [bp-18h]@1 - int v23; // [sp+B4h] [bp-14h]@9 - int v24; // [sp+B8h] [bp-10h]@1 - unsigned int v25; // [sp+BCh] [bp-Ch]@2 - unsigned int v26; // [sp+C0h] [bp-8h]@1 - int v27; // [sp+C4h] [bp-4h]@8 - - v22 = this; - v6 = 0; - v7 = 0; - v24 = 0; - v26 = 0; - a1.flt_2C = 0.0; +void Vis::PickOutdoorFaces_Mouse(float fDepth, RenderVertexSoft *pRay, Vis_SelectionList *list, Vis_SelectionFilter *filter, bool one_sided) +{ if (!pOutdoor) return; - if ( (signed int)pOutdoor->uNumBModels > 0 ) + + for (uint i = 0; i < pOutdoor->uNumBModels; ++i) { - v25 = 0; - do + int v24; + if (!IsBModelVisible(i, &v24)) + continue; + if (one_sided && !v24) + continue; + + auto bmodel = &pOutdoor->pBModels[i]; + + for (uint j = 0; j < bmodel->uNumFaces; ++j) { - v8 = &pOutdoor->pBModels[v25 / 0xBC]; - v9 = IsBModelVisible(v7, &v24); - if ( a6 ) + auto face = bmodel->pFaces + j; + if (is_part_of_selection(face, filter)) { - if ( v9 && v24 != v6 ) + BLVFace blv_face; + blv_face.FromODM(face); + + RenderVertexSoft intersection; + if (Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &intersection, &blv_face, i)) { -LABEL_8: - v10 = v8->uNumFaces; - v27 = v6; - v21 = v10; - if ( v10 > v6 ) - { - v23 = v6; - do - { - v11 = (ODMFace *)((char *)v8->pFaces + v23); - if ( is_part_of_selection((BLVFace *)((char *)v8->pFaces + v23), a5) ) - { - thisa.FromODM(v11); - if ( Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &a1, &thisa, v26) ) - { - pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u); - v18 = v11; - v13 = _48B561_mess_with_scaling_along_z(/*v12, */a1.vWorldViewPosition.x); - LOWORD(v13) = 0; - v20 = 2; - v19 = (void *)((8 * (v27 | (v26 << 6)) | 6) + v13); - pNumPointers = &a4->uNumPointers; - v15 = &a4->array_0004[a4->uNumPointers]; - v15->pObjectInfo = v18; - v15 = (Vis_stru1_stru0 *)((char *)v15 + 4); - v15->pObjectInfo = v19; - v15->sZValue = v20; - ++*pNumPointers; - } - } - ++v27; - v23 += 308; - } - while ( v27 < v21 ); - v6 = 0; - } - goto LABEL_15; + pGame->pIndoorCameraD3D->ViewTransform(&intersection, 1u); + int v13 = _48B561_mess_with_scaling_along_z(/*v12, */intersection.vWorldViewPosition.x); + LOWORD(v13) = (8 * (j | (i << 6)) | OBJECT_BModel) + v13; + + list->AddObject(face, VisObjectType_Face, v13); } } - else - { - if ( v9 ) - goto LABEL_8; - } -LABEL_15: - v25 += 188; - v7 = v26++ + 1; } - while ( (signed int)v26 < (signed int)pOutdoor->uNumBModels ); } } @@ -516,39 +427,38 @@ //{return DoesRayIntersectBillboard(fDepth, uD3DBillboardIdx);} //----- (004C1944) -------------------------------------------------------- -int Vis::_4C1944(int a2, unsigned int a3, int a4, int a5, int a6) +int Vis::_4C1944(int object_id, unsigned int a3, int a4, int a5, int a6) { float v6; // ST00_4@3 int result; // eax@4 - stru157 v8; // [sp+18h] [bp-20h]@3 + Vis_SelectionFilter v8; // [sp+18h] [bp-20h]@3 __int64 v9; // [sp+2Ch] [bp-Ch]@3 Vis *v14; // [sp+34h] [bp-4h]@1 v14 = this; - static Vis_stru1 Vis_static_sub_4C1944_stru_F8BDE8; + static Vis_SelectionList Vis_static_sub_4C1944_stru_F8BDE8; - v8.field_4 = a2; + v8.object_id = object_id; v8.field_8 = a6; v8.field_C = a5; v8.field_10 = a4; v9 = a3; Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers = 0; v6 = (double)a3; - v8.field_0 = 1; - _4C06F8(v6, &Vis_static_sub_4C1944_stru_F8BDE8, &v8); - Vis_static_sub_4C1944_stru_F8BDE8.create_object_pointers(1u); + v8.object_type = VisObjectType_Sprite; + PickBillboards_Keyboard(v6, &Vis_static_sub_4C1944_stru_F8BDE8, &v8); + Vis_static_sub_4C1944_stru_F8BDE8.create_object_pointers(Vis_SelectionList::Unique); sort_object_pointers( - Vis_static_sub_4C1944_stru_F8BDE8.array_1804, + Vis_static_sub_4C1944_stru_F8BDE8.object_pointers, 0, Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers - 1); if ( (signed int)Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers <= 0 ) result = -1; else - result = Vis_static_sub_4C1944_stru_F8BDE8.array_1804[0]->sZValue; + result = Vis_static_sub_4C1944_stru_F8BDE8.object_pointers[0]->sZValue; return result; } -// F8DDF0: using guessed type char Vis_static_sub_4C1944_byte_F8DDF0_init; //----- (004C1A02) -------------------------------------------------------- void Vis::_4C1A02() @@ -641,39 +551,27 @@ } //----- (004C1BAA) -------------------------------------------------------- -int Vis::get_object_zbuf_val(Vis_stru1_stru0 *a2) +int Vis::get_object_zbuf_val(Vis_ObjectInfo *info) { - unsigned int v2; // eax@1 - int result; // eax@3 - std::string v4; // [sp-18h] [bp-1Ch]@4 - const char *v5; // [sp-8h] [bp-Ch]@4 - int v6; // [sp-4h] [bp-8h]@4 - Vis *v7; // [sp+0h] [bp-4h]@1 + switch (info->object_type) + { + case VisObjectType_Sprite: + case VisObjectType_Face: + return info->sZValue; - v7 = this; - v2 = a2->uObjectType; - if ( (signed int)v2 <= 0 || (signed int)v2 > 2 ) - { - MessageBoxW(nullptr, L"Undefined type requested for: CVis::get_object_zbuf_val()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1037", 0); - result = -1; + default: + MessageBoxW(nullptr, L"Undefined type requested for: CVis::get_object_zbuf_val()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1037", 0); + return -1; } - else - { - result = a2->sZValue; - } - return result; } //----- (004C1BF1) -------------------------------------------------------- int Vis::get_picked_object_zbuf_val() { - int result; // eax@2 + if (!default_list.uNumPointers) + return -1; - if ( (signed int)this->stru1.uNumPointers <= 0 ) - result = -1; - else - result = get_object_zbuf_val(this->stru1.array_1804[0]); - return result; + return get_object_zbuf_val(default_list.object_pointers[0]); } //----- (004C1C0C) -------------------------------------------------------- @@ -1141,12 +1039,12 @@ } //----- (004C2551) -------------------------------------------------------- -Vis_stru1_stru0 *Vis_stru1::sub_4C2551(int a2, int a3) +Vis_ObjectInfo *Vis_SelectionList::sub_4C2551(int a2, int a3) { unsigned int v3; // esi@1 signed int v4; // edx@1 char *v5; // eax@2 - Vis_stru1_stru0 *result; // eax@6 + Vis_ObjectInfo *result; // eax@6 v3 = this->uNumPointers; v4 = 0; @@ -1157,7 +1055,7 @@ } else { - v5 = (char *)&this->array_0004[0].sZValue; + v5 = (char *)&this->object_pool[0].sZValue; while ( *((int *)v5 + 1) != a2 || (*(int *)v5 & 0xFFFF) != a3 ) { ++v4; @@ -1165,92 +1063,51 @@ if ( v4 >= (signed int)v3 ) goto LABEL_6; } - result = &this->array_0004[v4]; + result = &this->object_pool[v4]; } return result; } //----- (004C2591) -------------------------------------------------------- -Vis_stru1_stru0 **Vis_stru1::create_object_pointers(unsigned int flag) +void Vis_SelectionList::create_object_pointers(PointerCreationType type) { - Vis_stru1_stru0 **result; // eax@1 - signed int v3; // esi@2 - Vis_stru1_stru0 *v4; // edx@3 - unsigned __int8 v5; // zf@7 - unsigned __int8 v6; // sf@7 - Vis_stru1_stru0 **v7; // ebx@8 - Vis_stru1_stru0 *v8; // esi@8 - signed int v9; // edi@9 - Vis_stru1_stru0 **v10; // edx@10 - std::string v11; // [sp-18h] [bp-28h]@19 - const char *v12; // [sp-8h] [bp-18h]@19 - int v13; // [sp-4h] [bp-14h]@19 - char v14; // [sp+Ch] [bp-4h]@19 + switch (type) + { + case All: + { + for (uint i = 0; i < uNumPointers; ++i) + object_pointers[i] = &object_pool[i]; + } + break; - result = 0; - if ( flag ) - { - if ( flag == 1 ) - { - v5 = this->uNumPointers == 0; - v6 = (this->uNumPointers & 0x80000000u) != 0; - BYTE3(flag) = 1; - if ( !(v6 | v5) ) + case Unique: // seems quite retarted; the inner if condition will never trigger, since we compare pointers, not values. pointers will always be unique + { // but it may be decompilation error thou + bool create = true; + + for (uint i = 0; i < uNumPointers; ++i) { - v7 = this->array_1804; - v8 = this->array_0004; - do + for (uint j = 0; j < i; ++j) { - v9 = 0; - if ( (signed int)result > 0 ) + if (object_pointers[j] == &object_pool[i]) { - v10 = this->array_1804; - while ( *v10 != v8 ) - { - ++v9; - ++v10; - if ( v9 >= (signed int)result ) - goto LABEL_15; - } - BYTE3(flag) = 0; + create = false; + break; } -LABEL_15: - if ( BYTE3(flag) ) - *v7 = v8; - result = (Vis_stru1_stru0 **)((char *)result + 1); - ++v7; - ++v8; } - while ( (signed int)result < (signed int)this->uNumPointers ); + + if (create) + object_pointers[i] = &object_pool[i]; } } - else - { + break; + + default: MessageBoxW(nullptr, L"Unknown pointer creation flag passed to ::create_object_pointers()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1358", 0); - } } - else - { - v3 = 0; - if ( (signed int)this->uNumPointers > 0 ) - { - result = this->array_1804; - v4 = this->array_0004; - do - { - *result = v4; - ++v3; - ++result; - ++v4; - } - while ( v3 < (signed int)this->uNumPointers ); - } - } - return result; } //----- (004C264A) -------------------------------------------------------- -void Vis::sort_object_pointers(Vis_stru1_stru0 **pPointers, int left, int right) +void Vis::sort_object_pointers(Vis_ObjectInfo **pPointers, int left, int right) { int v4; // edx@1 int v5; // ebx@1 @@ -1259,9 +1116,9 @@ int v8; // eax@3 int v9; // ebx@4 int v10; // ebx@6 - Vis_stru1_stru0 *v11; // eax@7 + Vis_ObjectInfo *v11; // eax@7 Vis *thisa; // [sp+4h] [bp-4h]@1 - Vis_stru1_stru0 *a3a; // [sp+14h] [bp+Ch]@2 + Vis_ObjectInfo *a3a; // [sp+14h] [bp+Ch]@2 v4 = left; v5 = right; @@ -1425,15 +1282,14 @@ memcpy(&v12, &v5[v8], sizeof(v12)); memcpy(&v5[v8], v15, sizeof(v5[v8])); memcpy(v15, &v12, 0x20u); - //__debugbreak(); - SortVerticesByX(v5, uStart, v8 - 1); - SortVerticesByX(a2, v8 + 1, uEnd); + SortVerticesByY(v5, uStart, v8 - 1); + SortVerticesByY(a2, v8 + 1, uEnd); } return true; } //----- (004C288E) -------------------------------------------------------- -bool Vis::sort_objects_2(RenderVertexSoft *pArray, int sLeft, int sRight) +bool Vis::SortByScreenSpaceX(RenderVertexSoft *pArray, int sLeft, int sRight) { bool result; // eax@1 RenderVertexSoft *v5; // edx@2 @@ -1448,11 +1304,11 @@ //float v13; // [sp+4Ch] [bp-24h]@4 int v14; // [sp+64h] [bp-Ch]@7 //Vis *thisa; // [sp+68h] [bp-8h]@1 - void *thisa; + //void *thisa; //RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2 const void *v16; - thisa = this; + //thisa = this; if (sRight <= sLeft) return true; v5 = pArray; @@ -1487,13 +1343,13 @@ memcpy(&v11, &v5[v6], sizeof(v11)); memcpy(&v5[v6], v16, sizeof(v5[v6])); memcpy((void *)v16, &v11, sizeof(0x30u)); - sort_objects_2(v5, sLeft, v6 - 1); - sort_objects_2(pArray, v6 + 1, sRight); + SortByScreenSpaceX(v5, sLeft, v6 - 1); + SortByScreenSpaceX(pArray, v6 + 1, sRight); return true; } //----- (004C297E) -------------------------------------------------------- -bool Vis::sort_objects_3(RenderVertexSoft *pArray, int sLeft, int sRight) +bool Vis::SortByScreenSpaceY(RenderVertexSoft *pArray, int sLeft, int sRight) { //bool result; // eax@1 RenderVertexSoft *v5; // edx@2 @@ -1545,8 +1401,8 @@ memcpy(&v11, &v5[v6], sizeof(0x30)); memcpy(&v5[v6], v16, sizeof(v5[v6])); memcpy((void *)v16, &v11, sizeof(0x30)); - sort_objects_3(v5, sLeft, v6 - 1); - sort_objects_3(pArray, v6 + 1, sRight); + SortByScreenSpaceY(v5, sLeft, v6 - 1); + SortByScreenSpaceY(pArray, v6 + 1, sRight); return true; } @@ -1554,12 +1410,9 @@ //----- (004C04AF) -------------------------------------------------------- Vis::Vis() { - Vis *v1; // ebx@1 - Vis *result; // eax@1 RenderVertexSoft v3; // [sp+Ch] [bp-60h]@1 RenderVertexSoft v4; // [sp+3Ch] [bp-30h]@1 - v1 = this; v3.flt_2C = 0.0; v3.vWorldPosition.x = 0.0; v3.vWorldPosition.y = 65536.0; @@ -1568,202 +1421,197 @@ v4.vWorldPosition.x = 65536.0; v4.vWorldPosition.y = 0.0; v4.vWorldPosition.z = 0.0; - memcpy(&v1->stru_200C, &v4, sizeof(v1->stru_200C)); + memcpy(&stru_200C, &v4, sizeof(stru_200C)); + v4.flt_2C = 0.0; v4.vWorldPosition.x = 0.0; v4.vWorldPosition.y = 65536.0; v4.vWorldPosition.z = 0.0; - memcpy(&v1->stru_203C, &v3, sizeof(v1->stru_203C)); + memcpy(&stru_203C, &v3, sizeof(stru_203C)); + v3.flt_2C = 0.0; v3.vWorldPosition.x = 65536.0; v3.vWorldPosition.y = 0.0; v3.vWorldPosition.z = 0.0; - memcpy(&v1->stru_206C, &v3, sizeof(v1->stru_206C)); - result = v1; - memcpy(&v1->stru_209C, &v4, sizeof(v1->stru_209C)); - v1->field_20CC = 512; + memcpy(&stru_206C, &v3, sizeof(stru_206C)); + memcpy(&stru_209C, &v4, sizeof(stru_209C)); + + keyboard_pick_depth = 512; } //----- (004C055C) -------------------------------------------------------- -Vis_stru1::Vis_stru1() +Vis_SelectionList::Vis_SelectionList() { for (uint i = 0; i < 512; ++i) { - array_0004[i].pObjectInfo = 0; - array_0004[i].sZValue = -1; - array_0004[i].uObjectType = 0; + object_pool[i].object = nullptr; + object_pool[i].sZValue = -1; + object_pool[i].object_type = VisObjectType_Any; } uNumPointers = 0; } //----- (004C05CC) -------------------------------------------------------- -bool Vis::PickKeyboard(Vis_stru1 *a2, stru157 *a3, stru157 *a4) +bool Vis::PickKeyboard(Vis_SelectionList *list, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter) { - Vis_stru1 *v4; // esi@1 - Vis *v5; // ebx@1 - char *v6; // edi@3 - float v7; // ST00_4@3 - bool result; // eax@6 - float v9; // [sp+4h] [bp-14h]@3 + if (!list) + list = &default_list; + list->uNumPointers = 0; - v4 = a2; - v5 = this; - if ( !a2 ) - v4 = &this->stru1; - v4->uNumPointers = 0; - v6 = (char *)&this->field_20CC; - v7 = (double)this->field_20CC; - _4C06F8(v7, v4, a3); - v9 = (double)*(signed int *)v6; - if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) - _4C0D32_BLV(v9, v4, a4); + PickBillboards_Keyboard(keyboard_pick_depth, list, sprite_filter); + if (uCurrentlyLoadedLevelType == LEVEL_Indoor) + PickIndoorFaces_Keyboard(keyboard_pick_depth, list, face_filter); + else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) + PickOutdoorFaces_Keyboard(keyboard_pick_depth, list, face_filter); else - _4C0DEA_ODM(v9, v4, a4); - v4->create_object_pointers(1u); - sort_object_pointers(v4->array_1804, 0, v4->uNumPointers - 1); + assert(false); + + list->create_object_pointers(Vis_SelectionList::Unique); + sort_object_pointers(list->object_pointers, 0, list->uNumPointers - 1); + return true; } //----- (004C0646) -------------------------------------------------------- -bool Vis::PickMouse(float fDepth, float fMouseX, float fMouseY, stru157 *a5, stru157 *a6) +bool Vis::PickMouse(float fDepth, float fMouseX, float fMouseY, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter) { RenderVertexSoft pMouseRay[2]; // [sp+1Ch] [bp-60h]@1 - stru1.uNumPointers = 0; + default_list.uNumPointers = 0; CastPickRay(pMouseRay, fMouseX, fMouseY, fDepth); - PickBillboards(fDepth, fMouseX, fMouseY, &stru1, a5); + PickBillboards_Mouse(fDepth, fMouseX, fMouseY, &default_list, sprite_filter); if (uCurrentlyLoadedLevelType == LEVEL_Indoor) - PickIndoor(fDepth, pMouseRay, &stru1, a6); + PickIndoorFaces_Mouse(fDepth, pMouseRay, &default_list, face_filter); else - PickOutdoor(fDepth, pMouseRay, &stru1, a6, 0); - stru1.create_object_pointers(0); - sort_object_pointers(stru1.array_1804, 0, stru1.uNumPointers - 1); + PickOutdoorFaces_Mouse(fDepth, pMouseRay, &default_list, face_filter, false); + default_list.create_object_pointers(Vis_SelectionList::All); + sort_object_pointers(default_list.object_pointers, 0, default_list.uNumPointers - 1); + return true; } //----- (004C06F8) -------------------------------------------------------- -void Vis::_4C06F8(float arg0, Vis_stru1 *a3, stru157 *a2) +void Vis::PickBillboards_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) { - int v4; // ST18_4@5 - Vis_stru1_stru0 *v5; // edi@5 - void **v7; // [sp+24h] [bp-8h]@2 - unsigned int uD3DBillboardIdx; // [sp+28h] [bp-4h]@1 + for (int i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) + { + auto d3d_billboard = &pRenderer->pBillboardRenderListD3D[i]; - uD3DBillboardIdx = 0; - auto ecx0 = this; - if ( (signed int)pRenderer->uNumBillboardsToDraw > 0 ) - { - v7 = (void **)&pRenderer->pBillboardRenderListD3D[0].uParentBillboardID; - do + if (is_part_of_selection((void *)i, filter)) { - if ( is_part_of_selection((BLVFace *)uD3DBillboardIdx, a2) ) + if (DoesRayIntersectBillboard(pick_depth, i)) { - if ( DoesRayIntersectBillboard(arg0, uD3DBillboardIdx) ) - { - v4 = pBillboardRenderList[(int)*v7].sZValue; - v5 = &a3->array_0004[a3->uNumPointers]; - v5->pObjectInfo = *v7; - v5 = (Vis_stru1_stru0 *)((char *)v5 + 4); - v5->pObjectInfo = (void *)v4; - v5->sZValue = 1; - ++a3->uNumPointers; - } + auto billboard = &pBillboardRenderList[d3d_billboard->uParentBillboardID]; + + list->AddObject((void *)d3d_billboard->uParentBillboardID, VisObjectType_Sprite, billboard->sZValue); } - ++uD3DBillboardIdx; - v7 += 39; } - while ( (signed int)uD3DBillboardIdx < (signed int)pRenderer->uNumBillboardsToDraw ); } } + +// tests the object against selection filter to determine whether it can be picked or not //----- (004C0791) -------------------------------------------------------- -bool Vis::is_part_of_selection(BLVFace *uD3DBillboardIdx_or_pBLVFace_or_pODMFace, stru157 *a2) +bool Vis::is_part_of_selection(void *uD3DBillboardIdx_or_pBLVFace_or_pODMFace, Vis_SelectionFilter *filter) { - stru157 *v3; // esi@1 - int result; // eax@1 + //stru157 *v3; // esi@1 + //int result; // eax@1 int v5; // edx@2 - int v6; // ecx@2 - char v7; // zf@3 + //int v6; // ecx@2 + //char v7; // zf@3 int v8; // esi@5 std::string *v9; // ecx@7 Actor *v10; // edi@18 - char v11; // zf@26 - const char *v12; // [sp-20h] [bp-2Ch]@7 + //const char *v12; // [sp-20h] [bp-2Ch]@7 int v13; // [sp-1Ch] [bp-28h]@7 - std::string v14; // [sp-18h] [bp-24h]@7 - const char *v15; // [sp-8h] [bp-14h]@7 + //std::string v14; // [sp-18h] [bp-24h]@7 + //const char *v15; // [sp-8h] [bp-14h]@7 int v16; // [sp-4h] [bp-10h]@7 - v3 = a2; - result = a2->field_0; - if ( a2->field_0 != 1 ) + switch (filter->object_type) { - if ( result != 2 - || (uCurrentlyLoadedLevelType != LEVEL_Indoor ? (v11 = LOWORD(uD3DBillboardIdx_or_pBLVFace_or_pODMFace[3].pFacePlane.vNormal.y) == 0, - result = uD3DBillboardIdx_or_pBLVFace_or_pODMFace->pFacePlane_old.dist) : (v11 = pIndoor->pFaceExtras[uD3DBillboardIdx_or_pBLVFace_or_pODMFace->uFaceExtraID].uEventID == 0, result = uD3DBillboardIdx_or_pBLVFace_or_pODMFace->uAttributes), - a2->field_4 != 1) ) - goto LABEL_16; - if ( v11 || result & a2->field_C ) - goto LABEL_33; - v7 = (result & a2->field_8) == 0; - goto LABEL_32; - } - v5 = a2->field_10; - result = (pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].sZValue & 0xFFFF) >> 3; - v6 = pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].sZValue & 7; - if ( v5 & 2 ) - { - v7 = v6 == a2->field_4; - goto LABEL_32; - } - if ( v5 & 4 ) - { - v8 = a2->field_4; - if ( v6 != v8 ) - goto LABEL_16; - if ( v8 != 5 ) + case VisObjectType_Any: + return true; + + case VisObjectType_Sprite: { - v15 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:207"; - v12 = "Unsupported \"exclusion if no event\" type in CVis::is_part_of_selection"; -LABEL_15: - MessageBoxA(nullptr, v12, v15, 0); - return true; + v5 = filter->field_10; + int object_idx = (pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].object_pid & 0xFFFF) >> 3; + int object_type = pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].object_pid & 7; + if ( v5 & 2 ) + { + if (object_type == filter->object_id) + return false; + return true; + } + if ( v5 & 4 ) + { + v8 = filter->object_id; + if ( object_type != filter->object_id) + return true; + if (v8 != OBJECT_Decoration) + { + MessageBoxA(nullptr, "Unsupported \"exclusion if no event\" type in CVis::is_part_of_selection", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:207", 0); + return true; + } + if (pLevelDecorations[object_idx].uCog || pLevelDecorations[object_idx].field_16_event_id) + return true; + return pLevelDecorations[object_idx].IsInteractive(); + } + if (object_type == filter->object_id) + { + if (object_type != OBJECT_Actor) + { + MessageBoxA(nullptr, "Default case reached in VIS", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:245", 0); + return true; + } + + v10 = &pActors[object_idx]; + int result = 1 << LOBYTE(v10->uAIState); + if ( result & filter->field_C + || !(result & filter->field_8) + || v5 & 8 && (result = MonsterStats::BelongsToSupertype(v10->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD)) == 0 ) + return false; + if ( !(filter->field_10 & 1) ) + return true; + + result = v10->GetActorsRelation(nullptr); + if (result == 0) + return false; + return true; + } + return false; } - result *= 32; - if ( *(__int16 *)((char *)&pLevelDecorations[0].uCog + result) - || *(__int16 *)((char *)&pLevelDecorations[0].field_16_event_id + result) ) - goto LABEL_16; - result = pLevelDecorations[result / sizeof(LevelDecoration)].IsInteractive(); - goto LABEL_11; - } - if ( v6 == a2->field_4 ) - { - if ( v6 != 3 ) + + case VisObjectType_Face: { - v15 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:245"; - v12 = "Default case reached in VIS"; - goto LABEL_15; + uint face_attrib = 0; + bool no_event = true; + if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) + { + auto face = (ODMFace *)uD3DBillboardIdx_or_pBLVFace_or_pODMFace; + no_event = face->sCogTriggeredID == 0; + face_attrib = face->uAttributes; + } + else if (uCurrentlyLoadedLevelType == LEVEL_Indoor) + { + auto face = (BLVFace *)uD3DBillboardIdx_or_pBLVFace_or_pODMFace; + no_event = pIndoor->pFaceExtras[face->uFaceExtraID].uEventID == 0; + face_attrib = face->uAttributes; + } + else + assert(false); + + if (filter->object_id != OBJECT_BLVDoor) + return true; + if (no_event || face_attrib & filter->field_C) + return false; + return (face_attrib & filter->field_8) != 0; } - v10 = &pActors[result]; - result = 1 << LOBYTE(v10->uAIState); - if ( result & a2->field_C - || !(result & a2->field_8) - || v5 & 8 && (result = MonsterStats::BelongsToSupertype(v10->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD)) == 0 ) - goto LABEL_33; - if ( !(v3->field_10 & 1) ) - goto LABEL_16; - result = v10->GetActorsRelation(nullptr); -LABEL_11: - v7 = result == 0; -LABEL_32: - if ( v7 ) - goto LABEL_33; -LABEL_16: - return true; + + default: + assert(false); } -LABEL_33: - LOBYTE(result) = 0; - return result; } //----- (004C091D) -------------------------------------------------------- @@ -1773,8 +1621,8 @@ //signed int v5; // ecx@4 //float v6; // ST04_4@6 //float v7; // ST00_4@7 - int v8; // eax@10 - unsigned int v9; // eax@12 + //int v8; // eax@10 + //unsigned int v9; // eax@12 int v10; // eax@17 double v11; // st6@18 double v12; // st7@18 @@ -1783,8 +1631,8 @@ float v15; // ST08_4@22 //float v16; // ST04_4@23 //float v17; // ST00_4@24 - signed int v18; // eax@27 - unsigned int v19; // eax@29 + //signed int v18; // eax@27 + //unsigned int v19; // eax@29 double v20; // st6@32 double v21; // st7@32 int v22; // eax@32 @@ -1804,13 +1652,13 @@ float v34; // [sp+E4h] [bp-18h]@32 int v35; // [sp+E8h] [bp-14h]@5 int v36; // [sp+ECh] [bp-10h]@5 - unsigned int v37; // [sp+F0h] [bp-Ch]@5 + int v37; // [sp+F0h] [bp-Ch]@5 float v38; // [sp+F4h] [bp-8h]@17 //void *v39; // [sp+F8h] [bp-4h]@1 signed int v40; // [sp+108h] [bp+Ch]@17 float v41; // [sp+108h] [bp+Ch]@32 - static Vis_stru1 Vis_static_stru_F91E10; + static Vis_SelectionList Vis_static_stru_F91E10; Vis_static_stru_F91E10.uNumPointers = 0; v3 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].uParentBillboardID; if (v3 == -1) @@ -1820,26 +1668,20 @@ LABEL_49: return false; } - else - { + v37 = pBillboardRenderList[v3].sZValue & 0xFFFF0000; GetPolygonCenter(pRenderer->pBillboardRenderListD3D[v3].pQuards, 4, (float *)&v35, (float *)&v36); - this->CastPickRay(pPickingRay, *(float *)&v35, *(float *)&v36, fDepth); - if (uCurrentlyLoadedLevelType == 1) - PickIndoor(fDepth, pPickingRay, &Vis_static_stru_F91E10, &a5); + CastPickRay(pPickingRay, *(float *)&v35, *(float *)&v36, fDepth); + if (uCurrentlyLoadedLevelType == LEVEL_Indoor) + PickIndoorFaces_Mouse(fDepth, pPickingRay, &Vis_static_stru_F91E10, &vis_face_filter); else - PickOutdoor(fDepth, pPickingRay, &Vis_static_stru_F91E10, &a5, 0); - Vis_static_stru_F91E10.create_object_pointers(0); - sort_object_pointers(Vis_static_stru_F91E10.array_1804, 0, Vis_static_stru_F91E10.uNumPointers - 1); + PickOutdoorFaces_Mouse(fDepth, pPickingRay, &Vis_static_stru_F91E10, &vis_face_filter, false); + Vis_static_stru_F91E10.create_object_pointers(); + sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1); if (Vis_static_stru_F91E10.uNumPointers) { - if (Vis_static_stru_F91E10.uNumPointers <= 0) - v8 = 0; - else v8 = (int)Vis_static_stru_F91E10.array_1804; - v9 = *(_DWORD *)(v8 + 4); - LOWORD(v9) = 0; - if (v9 > v37) - return 1; + if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z) + return 1; } else if ((double)(pViewport->uScreenX) <= *(float *)&v35 && (double)pViewport->uScreenZ >= *(float *)&v35 && @@ -1867,18 +1709,21 @@ v15 = v12; CastPickRay(local_80, SLODWORD(v15), v14, fDepth); if ( uCurrentlyLoadedLevelType == 1 ) - PickIndoor(fDepth, local_80, &Vis_static_stru_F91E10, &a5); + PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter); else - PickOutdoor(fDepth, local_80, &Vis_static_stru_F91E10, &a5, 0); - Vis_static_stru_F91E10.create_object_pointers(0); - sort_object_pointers(Vis_static_stru_F91E10.array_1804, 0, Vis_static_stru_F91E10.uNumPointers - 1); + PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false); + Vis_static_stru_F91E10.create_object_pointers(); + sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1); if ( !Vis_static_stru_F91E10.uNumPointers ) break; - v18 = Vis_static_stru_F91E10.uNumPointers <= 0 ? 0 : (int)Vis_static_stru_F91E10.array_1804; - v19 = *(_DWORD *)(v18 + 4); - LOWORD(v19) = 0; - if ( v19 > v37 ) + else + { + //v18 = Vis_static_stru_F91E10.uNumPointers <= 0 ? 0 : (int); + //v19 = *(_DWORD *)(v18 + 4); + //LOWORD(v19) = 0; + if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z) break; + } } } } @@ -1911,12 +1756,12 @@ || (double)pViewport->uScreenY > v41 || (double)pViewport->uScreenW < v41 || ((v25 = v23, CastPickRay(local_80, SLODWORD(v25), v41, fDepth), uCurrentlyLoadedLevelType != 1) ? - (PickOutdoor(fDepth, local_80, &Vis_static_stru_F91E10, &a5, 0)) : - (PickIndoor(fDepth, local_80, &Vis_static_stru_F91E10, &a5)), - (Vis_static_stru_F91E10.create_object_pointers(0), - sort_object_pointers(Vis_static_stru_F91E10.array_1804, 0, Vis_static_stru_F91E10.uNumPointers - 1), + (PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false)) : + (PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter)), + (Vis_static_stru_F91E10.create_object_pointers(), + sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1), Vis_static_stru_F91E10.uNumPointers) - && (Vis_static_stru_F91E10.uNumPointers <= 0 ? (v28 = 0) : (v28 = (int)Vis_static_stru_F91E10.array_1804), + && (Vis_static_stru_F91E10.uNumPointers <= 0 ? (v28 = 0) : (v28 = (int)Vis_static_stru_F91E10.object_pointers), v29 = *(_DWORD *)(v28 + 4), LOWORD(v29) = 0, v29 <= v37)) ) @@ -1924,23 +1769,21 @@ break; } } - result = 1; - } - return result; + return true; } // F93E18: using guessed type char static_byte_F93E18_init; //----- (004C0D32) -------------------------------------------------------- -int Vis::_4C0D32_BLV(float a1, Vis_stru1 *arg4, stru157 *a2) +void Vis::PickIndoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) { int result; // eax@1 signed int v5; // esi@2 BLVFace *v6; // edi@4 unsigned int v7; // eax@6 - Vis_stru1_stru0 *v8; // eax@6 - int v9; // ST18_4@7 - unsigned int v10; // ST1C_4@7 - unsigned int v11; // ecx@7 + Vis_ObjectInfo *v8; // eax@6 + //int v9; // ST18_4@7 + //unsigned int v10; // ST1C_4@7 + //unsigned int v11; // ecx@7 signed int i; // [sp+18h] [bp-8h]@1 Vis *thisa; // [sp+1Ch] [bp-4h]@1 @@ -1956,108 +1799,46 @@ v6 = &pIndoor->pFaces[v5]; if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[v5]) ) { - if ( is_part_of_selection(v6, a2) ) + if ( is_part_of_selection(v6, filter) ) { v7 = 8 * v5; - LOBYTE(v7) = 8 * v5 | 6; - v8 = _4C1026(v6, v7, a1); + LOBYTE(v7) = 8 * v5 | OBJECT_BModel; + v8 = _4C1026(v6, v7, pick_depth); if ( v8 ) - { - v9 = v8->sZValue; - v10 = v8->uObjectType; - v11 = 3 * arg4->uNumPointers; - arg4->array_0004[arg4->uNumPointers].pObjectInfo = v8->pObjectInfo; - arg4->array_0004[4 * v11 / 0xC].sZValue = v9; - arg4->array_0004[4 * v11 / 0xC].uObjectType = v10; - ++arg4->uNumPointers; - } + list->AddObject(v8->object, v8->object_type, v8->sZValue); } } } } result = i + 1; } - return result; } //----- (004C0DEA) -------------------------------------------------------- -void Vis::_4C0DEA_ODM(float arg0, Vis_stru1 *a3, stru157 *a2) +void Vis::PickOutdoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) { - int v4; // esi@1 - BSPModel *v5; // ebx@3 - unsigned __int8 v6; // zf@5 - char v7; // sf@5 - unsigned __int8 v8; // of@5 - ODMFace *v9; // esi@7 - unsigned int v10; // eax@8 - Vis_stru1_stru0 *v11; // eax@8 - unsigned int v12; // ecx@9 - BLVFace f; // [sp+10h] [bp-84h]@1 - void *v14; // [sp+70h] [bp-24h]@9 - int v15; // [sp+74h] [bp-20h]@9 - unsigned int v16; // [sp+78h] [bp-1Ch]@9 - int v17; // [sp+7Ch] [bp-18h]@1 - Vis *v18; // [sp+80h] [bp-14h]@1 - int v19; // [sp+84h] [bp-10h]@6 - unsigned int v20; // [sp+88h] [bp-Ch]@2 - int v21; // [sp+8Ch] [bp-8h]@5 - int a1; // [sp+90h] [bp-4h]@1 + for (uint i = 0; i < pOutdoor->uNumBModels; ++i) + { + int v17; + if (!IsBModelVisible(i, &v17)) + continue; + if (!v17) + continue; - auto ecx0 = this; - v18 = ecx0; - v4 = 0; - v17 = 0; - a1 = 0; - if ( (signed int)pOutdoor->uNumBModels > 0 ) - { - v20 = 0; - do + auto bmodel = pOutdoor->pBModels + i; + for (uint j = 0; j < bmodel->uNumFaces; ++j) { - v5 = &pOutdoor->pBModels[v20 / 0xBC]; - if ( IsBModelVisible(a1, &v17) ) + auto face = bmodel->pFaces + j; + + if (is_part_of_selection(face, filter) ) { - if ( v17 != v4 ) - { - v8 = __OFSUB__(v5->uNumFaces, v4); - v6 = v5->uNumFaces == v4; - v7 = ((v5->uNumFaces - v4) & 0x80000000u) != 0; - v21 = v4; - if ( !((unsigned __int8)(v7 ^ v8) | v6) ) - { - v19 = v4; - do - { - v9 = (ODMFace *)((char *)v5->pFaces + v19); - if ( is_part_of_selection((BLVFace *)((char *)v5->pFaces + v19), a2) ) - { - f.FromODM(v9); - v10 = 8 * (v21 | (a1 << 6)); - LOBYTE(v10) = v10 | 6; - v11 = _4C1026(&f, v10, arg0); - if ( v11 ) - { - v14 = v11->pObjectInfo; - v15 = v11->sZValue; - v12 = a3->uNumPointers; - v16 = v11->uObjectType; - v12 *= 3; - *((int *)&a3->array_0004[0].pObjectInfo + v12) = (int)v14; - *(&a3->array_0004[0].sZValue + v12) = v15; - *(&a3->array_0004[0].uObjectType + v12) = v16; - ++a3->uNumPointers; - } - } - ++v21; - v19 += 308; - } - while ( v21 < (signed int)v5->uNumFaces ); - v4 = 0; - } - } + BLVFace blv_face; + blv_face.FromODM(face); + + int pid = 8 * (j | (i << 6)) | OBJECT_BModel; + if (auto object_info = _4C1026(&blv_face, pid, pick_depth)) + list->AddObject(object_info->object, object_info->object_type, object_info->sZValue); } - ++a1; - v20 += 188; } - while ( a1 < (signed int)pOutdoor->uNumBModels ); } } \ No newline at end of file