Mercurial > mm7
view Vis.cpp @ 790:1e2be0f5eb30
Merge
author | Nomad |
---|---|
date | Sun, 24 Mar 2013 23:45:50 +0200 |
parents | bd611ae85d27 |
children | 0f56abdcce94 |
line wrap: on
line source
#include <assert.h> #include "Vis.h" #include "Outdoor.h" #include "Game.h" #include "Actor.h" #include "IndoorCamera.h" #include "Viewport.h" #include "Log.h" #include "mm7_data.h" //#include "MM7.h" 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_ObjectInfo *Vis::_4C1026(BLVFace *face, unsigned int a3, float pick_depth) { char *v4; // eax@4 signed int v5; // ecx@4 RenderVertexSoft pRay[2]; // [sp+20h] [bp-70h]@17 int v20; // [sp+84h] [bp-Ch]@10 static Vis_SelectionList static_sub_4C1026_stru_F8FE00; static_sub_4C1026_stru_F8FE00.uNumPointers = 0; static bool _init_flag = false; static RenderVertexSoft static_sub_4C1026_array_F8F200[64]; if (!_init_flag) { _init_flag = true; for (uint i = 0; i < 64; ++i) static_sub_4C1026_array_F8F200[i].flt_2C = 0.0f; } if (uCurrentlyLoadedLevelType == LEVEL_Indoor) { if ( (signed int)face->uNumVertices > 0 ) { for ( int i = 0; i < face->uNumVertices; i++) { static_sub_4C1026_array_F8F200[i].vWorldPosition.x = (double)pIndoor->pVertices[face->pVertexIDs[i]].x; static_sub_4C1026_array_F8F200[i].vWorldPosition.y = (double)pIndoor->pVertices[face->pVertexIDs[i]].y; static_sub_4C1026_array_F8F200[i].vWorldPosition.z = (double)pIndoor->pVertices[face->pVertexIDs[i]].z; } } } 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 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) -------------------------------------------------------- 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 int v13 = -1; //v5 = 0; //thisa = this; //v6 = pRenderer->pBillboardRenderListD3D; for (uint i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) { auto billboard = pRenderer->pBillboardRenderListD3D + i; if (IsPointInsideD3DBillboard(billboard, x, y)) { if (v13 == -1) v13 = i; else if ((unsigned int)pBillboardRenderList[billboard->uParentBillboardID].sZValue < pBillboardRenderList[pRenderer->pBillboardRenderListD3D[v13].uParentBillboardID].sZValue) v13 = i; } } 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) -------------------------------------------------------- void Vis::GetPolygonCenter(RenderVertexD3D3 *pVertices, unsigned int uNumVertices, float *pCenterX, float *pCenterY) { static RenderVertexD3D3 unk_F8EA00[64]; memcpy(unk_F8EA00, pVertices, 32 * uNumVertices); SortVerticesByX(unk_F8EA00, 0, uNumVertices - 1); *pCenterX = (unk_F8EA00[uNumVertices - 1].pos.x - unk_F8EA00[0].pos.x) * 0.5 + unk_F8EA00[0].pos.x; SortVerticesByY(unk_F8EA00, 0, uNumVertices - 1); *pCenterY = (unk_F8EA00[uNumVertices - 1].pos.y - unk_F8EA00[0].pos.y) * 0.5 + unk_F8EA00[0].pos.y; } //----- (004C1495) -------------------------------------------------------- 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 static RenderVertexSoft static_sub_4C1495_array_F8DDF8[64]; memcpy(static_sub_4C1495_array_F8DDF8, vertices, 48 * num_vertices); 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_Mouse(float fPickDepth, float fX, float fY, Vis_SelectionList *list, Vis_SelectionFilter *filter) { for (uint i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) { auto d3d_billboard = pRenderer->pBillboardRenderListD3D + i; if (is_part_of_selection((void *)i, filter) && IsPointInsideD3DBillboard(d3d_billboard, fX, fY)) { if (DoesRayIntersectBillboard(fPickDepth, i)) { auto billboard = &pBillboardRenderList[d3d_billboard->uParentBillboardID]; list->AddObject((void *)d3d_billboard->uParentBillboardID, VisObjectType_Sprite, billboard->sZValue); } } } } //----- (004C1607) -------------------------------------------------------- bool Vis::IsPointInsideD3DBillboard(RenderBillboardD3D *a1, float x, float y) { //RenderBillboardD3D *result; // eax@1 double v5; // st7@2 float v6; // ecx@2 float v7; // ST00_4@3 __int16 v8; // fps@6 double v9; // st6@6 char v10; // c0@6 char v11; // c2@6 char v12; // c3@6 __int16 v13; // fps@7 double v14; // st6@7 unsigned __int8 v15; // c0@7 char v16; // c2@7 unsigned __int8 v17; // c3@7 __int16 v18; // fps@8 double v19; // st6@8 char v20; // c0@8 char v21; // c2@8 char v22; // c3@8 __int16 v23; // fps@9 double v24; // st6@9 unsigned __int8 v25; // c0@9 char v26; // c2@9 unsigned __int8 v27; // c3@9 float v28; // [sp+4h] [bp-8h]@2 float v29; // [sp+8h] [bp-4h]@2 float a1a; // [sp+14h] [bp+8h]@2 if ( a1->uParentBillboardID == -1 ) return false; //result = a1; v5 = a1->pQuards[0].pos.x; a1a = a1->pQuards[3].pos.x; v6 = a1->pQuards[0].pos.y; //result = (RenderBillboardD3D *)LODWORD(result->pQuards[1].pos.y); v29 = v6; v28 = a1->pQuards[1].pos.y; if ( v5 > a1a ) { v7 = v5; //HIWORD(result) = HIWORD(v7); v5 = a1a; a1a = v7; } if ( v6 > (double)v28 ) { //result = (RenderBillboardD3D *)LODWORD(v28); v28 = v6; v29 = v28; } v9 = x + 1.0; //UNDEF(v8); //v10 = v9 < v5; //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) ) return true; else return false; } //----- (004C16B4) -------------------------------------------------------- void Vis::PickIndoorFaces_Mouse(float fDepth, RenderVertexSoft *pRay, Vis_SelectionList *list, Vis_SelectionFilter *filter) { int v5; // eax@1 signed int pFaceID; // edi@2 int v8; // ecx@7 int v9; // eax@7 unsigned int *pNumPointers; // eax@7 unsigned int v11; // ecx@7 Vis_ObjectInfo *v12; // edi@7 RenderVertexSoft a1; // [sp+Ch] [bp-44h]@1 BLVFace *pFace; // [sp+3Ch] [bp-14h]@7 void *v15; // [sp+40h] [bp-10h]@7 int v17; // [sp+48h] [bp-8h]@1 v5 = 0; v17 = 0; for ( a1.flt_2C = 0.0; v17 < (signed int)pBspRenderer->num_faces; ++v17 ) { pFaceID = pBspRenderer->faces[v5].uFaceID; if ( pFaceID >= 0 ) { if ( pFaceID < (signed int)pIndoor->uNumFaces ) { if ( is_part_of_selection(&pIndoor->pFaces[pFaceID], filter) ) { if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[pFaceID]) ) { if ( Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &a1, &pIndoor->pFaces[pFaceID], 0xFFFFFFFFu) ) { pGame->pIndoorCameraD3D->ViewTransform(&a1, 1); v9 = _48B561_mess_with_scaling_along_z(/*v8, */a1.vWorldViewPosition.x); LOWORD(v9) = 0; v15 = (void *)((8 * pFaceID | 6) + v9); pNumPointers = &list->uNumPointers; //v16 = 2; //v11 = list->uNumPointers; pFace = &pIndoor->pFaces[pFaceID]; v12 = &list->object_pool[list->uNumPointers]; v12->object = &pIndoor->pFaces[pFaceID]; v12 = (Vis_ObjectInfo *)((char *)v12 + 4); v12->object = v15; v12->sZValue = 2; ++*pNumPointers; } } } } } v5 = v17 + 1; } } //----- (004C17CF) -------------------------------------------------------- void Vis::PickOutdoorFaces_Mouse(float fDepth, RenderVertexSoft *pRay, Vis_SelectionList *list, Vis_SelectionFilter *filter, bool only_reachable) { if (!pOutdoor) return; for (uint i = 0; i < pOutdoor->uNumBModels; ++i) { int reachable; if (!IsBModelVisible(i, &reachable)) continue; if (!reachable && only_reachable) continue; auto bmodel = &pOutdoor->pBModels[i]; for (uint j = 0; j < bmodel->uNumFaces; ++j) { auto face = bmodel->pFaces + j; if (is_part_of_selection(face, filter)) { BLVFace blv_face; blv_face.FromODM(face); RenderVertexSoft intersection; if (Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &intersection, &blv_face, i)) { pGame->pIndoorCameraD3D->ViewTransform(&intersection, 1u); int v13 = _48B561_mess_with_scaling_along_z(/*v12, */intersection.vWorldViewPosition.x); v13 += (8 * (j | (i << 6)) | OBJECT_BModel); list->AddObject(face, VisObjectType_Face, v13); } if (blv_face.uAttributes & 0x80000000) face->uAttributes |= FACE_OUTLINED; else face->uAttributes &= ~FACE_OUTLINED; } } } } //----- (004C1930) -------------------------------------------------------- //bool Vis::j_DoesRayIntersectBillboard(float fDepth, unsigned int uD3DBillboardIdx) //{return DoesRayIntersectBillboard(fDepth, uD3DBillboardIdx);} //----- (004C1944) -------------------------------------------------------- int Vis::PickClosestActor(int object_id, unsigned int pick_depth, int a4, int a5, int a6) { //float v6; // ST00_4@3 //int result; // eax@4 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_SelectionList Vis_static_sub_4C1944_stru_F8BDE8; v8.object_type = VisObjectType_Sprite; v8.object_id = object_id; v8.field_8 = a6; v8.field_C = a5; v8.field_10 = a4; Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers = 0; PickBillboards_Keyboard(pick_depth, &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.object_pointers, 0, Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers - 1); if (!Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers) return -1; return Vis_static_sub_4C1944_stru_F8BDE8.object_pointers[0]->sZValue; } //----- (004C1A02) -------------------------------------------------------- void Vis::_4C1A02() { RenderVertexSoft v1; // [sp+8h] [bp-C0h]@1 RenderVertexSoft v2; // [sp+38h] [bp-90h]@1 RenderVertexSoft v3; // [sp+68h] [bp-60h]@1 RenderVertexSoft v4; // [sp+98h] [bp-30h]@1 v4.flt_2C = 0.0; v4.vWorldPosition.x = 0.0; v4.vWorldPosition.y = 65536.0; v4.vWorldPosition.z = 0.0; v3.flt_2C = 0.0; v3.vWorldPosition.x = 65536.0; v3.vWorldPosition.y = 0.0; v3.vWorldPosition.z = 0.0; memcpy(&v1, &v3, sizeof(v1)); v3.flt_2C = 0.0; v3.vWorldPosition.x = 0.0; v3.vWorldPosition.y = 65536.0; v3.vWorldPosition.z = 0.0; memcpy(&v2, &v4, sizeof(v2)); v4.flt_2C = 0.0; v4.vWorldPosition.x = 65536.0; v4.vWorldPosition.y = 0.0; v4.vWorldPosition.z = 0.0; memcpy(&this->stru_200C, &v1, 0x60u); memcpy(&v1, &v4, sizeof(v1)); memcpy(&v2, &v3, sizeof(v2)); memcpy(&this->stru_206C, &v1, 0x60u); } //----- (004C1ABA) -------------------------------------------------------- bool Vis::SortVectors_x(RenderVertexSoft *a2, int a3, int a4) { bool result; // eax@1 RenderVertexSoft *v5; // edx@2 int v6; // ebx@2 int i; // ecx@2 int v8; // esi@3 int v9; // esi@5 RenderVertexSoft *v10; // eax@8 RenderVertexSoft v11; // [sp+4h] [bp-6Ch]@8 RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 int v13; // [sp+64h] [bp-Ch]@7 Vis *thisa; // [sp+68h] [bp-8h]@1 RenderVertexSoft *v15; // [sp+6Ch] [bp-4h]@2 result = a4; thisa = this; if ( a4 > a3 ) { v5 = a2; v15 = &a2[a4]; v6 = a3 - 1; memcpy(&v12, &a2[a4], sizeof(v12)); for ( i = a4; ; i = v13 ) { v8 = (int)&v5[v6].vWorldViewPosition; do { v8 += 48; ++v6; } while ( *(float *)v8 < (double)v12.vWorldViewPosition.x ); v9 = (int)&v5[i].vWorldViewPosition; do { v9 -= 48; --i; } while ( *(float *)v9 > (double)v12.vWorldViewPosition.x ); v13 = i; if ( v6 >= i ) break; v10 = &v5[i]; memcpy(&v11, &a2[v6], sizeof(v11)); v5 = a2; memcpy(&a2[v6], v10, sizeof(a2[v6])); memcpy(v10, &v11, 0x30u); } memcpy(&v11, &v5[v6], sizeof(v11)); memcpy(&v5[v6], v15, sizeof(v5[v6])); memcpy(v15, &v11, 0x30u); SortVectors_x(v5, a3, v6 - 1); SortVectors_x(a2, v6 + 1, a4); } return true; } //----- (004C1BAA) -------------------------------------------------------- int Vis::get_object_zbuf_val(Vis_ObjectInfo *info) { switch (info->object_type) { case VisObjectType_Sprite: case VisObjectType_Face: return info->sZValue; 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; } } //----- (004C1BF1) -------------------------------------------------------- int Vis::get_picked_object_zbuf_val() { if (!default_list.uNumPointers) return -1; return get_object_zbuf_val(default_list.object_pointers[0]); } //----- (004C1C0C) -------------------------------------------------------- bool Vis::Intersect_Ray_Face(RenderVertexSoft *pRayStart, RenderVertexSoft *pRayEnd, float *pDepth, RenderVertexSoft *a4, BLVFace *a5, unsigned int a6) { //BLVFace *v7; // ebx@1 //bool result; // eax@1 double v9; // st7@3 //__int16 v10; // fps@3 //char v11; // c0@3 //char v12; // c2@3 //char v13; // c3@3 //__int16 v14; // fps@5 //char v15; // c0@5 //char v16; // c2@5 //char v17; // c3@5 double v18; // st5@6 //__int16 v19; // fps@6 //char v20; // c0@6 //char v21; // c2@6 //char v22; // c3@6 //unsigned __int8 v23; // c0@6 //char v24; // c2@6 //unsigned __int8 v25; // c3@6 //char v26; // zf@6 double v27; // st6@10 //__int16 v28; // fps@10 //unsigned __int8 v29; // c0@10 //char v30; // c2@10 //unsigned __int8 v31; // c3@10 //double v32; // st7@11 Vec2_short_ v33; // ST1E_4@11 Vec3_short_ v34; // ST04_6@11 //float a5a; // [sp+30h] [bp+18h]@10 //float a5b; // [sp+30h] [bp+18h]@13 if (a5->Portal() || a5->Invisible()) return false; int ray_dir_x = pRayEnd->vWorldPosition.x - pRayStart->vWorldPosition.x, ray_dir_y = pRayEnd->vWorldPosition.y - pRayStart->vWorldPosition.y, ray_dir_z = pRayEnd->vWorldPosition.z - pRayStart->vWorldPosition.z; v9 = ray_dir_z * a5->pFacePlane.vNormal.z + ray_dir_y * a5->pFacePlane.vNormal.y + ray_dir_x * a5->pFacePlane.vNormal.x; if (v9 >= 0) // ray faces face's normal ( > 0) or parallel ( == 0) return false; //ray = t dir + start //plane = (p - vertex) normal = -d // // //(t dir + start - vertex) normal = -d // // -d - (start - vertex) norm //t = -------------------- // dir norm float dir_mag = sqrtf(ray_dir_x * ray_dir_x + ray_dir_y * ray_dir_y + ray_dir_z * ray_dir_z); float ndir_x = ray_dir_x / dir_mag, ndir_y = ray_dir_y / dir_mag, ndir_z = ray_dir_z / dir_mag; int face_center_x = (a5->pBounding.x1 + a5->pBounding.x2) / 2, face_center_y = (a5->pBounding.y1 + a5->pBounding.y2) / 2, face_center_z = (a5->pBounding.z1 + a5->pBounding.z2) / 2; int to_plane_x = pRayStart->vWorldPosition.x - face_center_x, to_plane_y = pRayStart->vWorldPosition.y - face_center_y, to_plane_z = pRayStart->vWorldPosition.z - face_center_z; float t = /*-a5->pFacePlane.dist*/ - (to_plane_x * a5->pFacePlane.vNormal.x + to_plane_y * a5->pFacePlane.vNormal.y + to_plane_y * a5->pFacePlane.vNormal.z) / (ndir_x * a5->pFacePlane.vNormal.x + ndir_y * a5->pFacePlane.vNormal.y + ndir_z * a5->pFacePlane.vNormal.z); if (t <= *pDepth) { int intersection_x = pRayStart->vWorldPosition.x + ndir_x * t, intersection_y = pRayStart->vWorldPosition.y + ndir_y * t, intersection_z = pRayStart->vWorldPosition.z + ndir_z * t; if (intersection_x < a5->pBounding.x1 || intersection_x > a5->pBounding.x2 || intersection_y < a5->pBounding.y1 || intersection_y > a5->pBounding.y2 || intersection_z < a5->pBounding.z1 || intersection_z > a5->pBounding.z2) return false; a5->uAttributes |= 0x80000000; return true; } return false; // v7 = a5; //result = a5->uAttributes; v9 = pRayEnd->vWorldPosition.z * a5->pFacePlane.vNormal.z + pRayEnd->vWorldPosition.y * a5->pFacePlane.vNormal.y + pRayEnd->vWorldPosition.x * a5->pFacePlane.vNormal.x; if (v9 >= 0) // ray faces face's normal ( > 0) or parallel ( == 0) return false; a5->uAttributes |= 0x80000000; return false; v18 = -(a5->pFacePlane.vNormal.y * pRayStart->vWorldPosition.y + pRayStart->vWorldPosition.x * a5->pFacePlane.vNormal.x + pRayStart->vWorldPosition.z * a5->pFacePlane.vNormal.z + a5->pFacePlane.dist); if (v18 > 0) return false; //UNDEF(v19); //v20 = v9 < 0.0; //v21 = 0; //v22 = v9 == 0.0; //BYTE1(result) = HIBYTE(v19); /*v23 = v18 < 0.0; v24 = 0; v25 = v18 == 0.0; v26 = (BYTE1(result) & 0x41) == 0; BYTE1(result) = HIBYTE(v19); if ( v26 ) { if ( v18 < 0.0 ) goto LABEL_12; } else { if ( !(v23 | v25) ) { LABEL_12: LOBYTE(result) = 0; return result; } }*/ //a5a = v18; v27 = v18 / v9; //HIWORD(result) = HIWORD(pDepth); //UNDEF(v28); //v29 = v27 < *pDepth; //v30 = 0; //v31 = v27 == *pDepth; //BYTE1(result) = HIBYTE(v28); if (v27 > *pDepth) return false; a5->uAttributes |= 0x80000000; a4->vWorldPosition.x = v27 * pRayEnd->vWorldPosition.x + pRayStart->vWorldPosition.x; a4->vWorldPosition.y = v27 * pRayEnd->vWorldPosition.y + pRayStart->vWorldPosition.y; a4->vWorldPosition.z = v27 * pRayEnd->vWorldPosition.z + pRayStart->vWorldPosition.z; v33.x = (signed __int64)a4->vWorldPosition.x; v33.y = (signed __int64)a4->vWorldPosition.y; v34.x = v33.x; v34.y = 0; v34.z = (signed __int64)a4->vWorldPosition.z; if ( _4C1D2B(a5, v34, a6) == 0.0) return false; //a5b = v27; *pDepth = v27; return true; } //----- (004C1D2B) -------------------------------------------------------- int Vis::_4C1D2B(BLVFace *pFace, Vec3_short_ a2, unsigned int uModelID) { BLVFace *v4; // esi@1 int v5; // esi@10 bool v6; // edi@10 int v7; // ecx@12 signed int v8; // edx@12 signed int v9; // eax@13 signed int v10; // ebx@14 int v11; // edi@16 signed int v12; // ST28_4@18 signed __int64 v13; // qtt@18 signed int result; // eax@21 int v15; // [sp+10h] [bp-Ch]@10 signed int v16; // [sp+18h] [bp-4h]@10 v4 = pFace; if (a2.z < pFace->pBounding.z1 || a2.z > pFace->pBounding.z2 || a2.x < pFace->pBounding.x1 || a2.x > pFace->pBounding.x2 || a2.y < pFace->pBounding.y1 || a2.y > pFace->pBounding.y2) return false; if (uModelID != -1) _4C2186_BLV_IntersectBModel((int *)&pFace, (int *)&uModelID, word_F8BC48_displaced_face_intersect_plane_coords_a, word_F8BD18_displaced_face_intersect_plane_coords_b, &a2, pFace, uModelID); else _4C1EE5_BLV_IntersectBModel_2((int *)&pFace, (int *)&uModelID, word_F8BC48_displaced_face_intersect_plane_coords_a, word_F8BD18_displaced_face_intersect_plane_coords_b, &a2, pFace); v5 = 2 * v4->uNumVertices; v16 = 0; word_F8BC48_displaced_face_intersect_plane_coords_a[v5] = word_F8BC48_displaced_face_intersect_plane_coords_a[0]; word_F8BD18_displaced_face_intersect_plane_coords_b[v5] = word_F8BD18_displaced_face_intersect_plane_coords_b[0]; v15 = 0; v6 = word_F8BD18_displaced_face_intersect_plane_coords_b[0] >= (signed int)uModelID; if (v5 <= 0) return false; do { if ( v16 >= 2 ) break; v7 = 2 * v15; v8 = word_F8BD18_displaced_face_intersect_plane_coords_b[ + v15 + 1]; if ( v6 ^ v8 >= (signed int)uModelID ) { v9 = word_F8BC48_displaced_face_intersect_plane_coords_a[v7/2 + 1]; if ( v9 >= (signed int)pFace ) v10 = 0; else v10 = 2; v11 = v10 | word_F8BC48_displaced_face_intersect_plane_coords_a[v7/2] < (signed int)pFace; if ( v11 != 3 ) { if ( !v11 || (v12 = v9 - word_F8BC48_displaced_face_intersect_plane_coords_a[v7/2], LODWORD(v13) = v12 << 16, HIDWORD(v13) = v12 >> 16, word_F8BC48_displaced_face_intersect_plane_coords_a[v7/2] + ((signed int)(((unsigned __int64)(v13 / (v8 - word_F8BD18_displaced_face_intersect_plane_coords_b[v7/2]) * (signed int)((uModelID - word_F8BD18_displaced_face_intersect_plane_coords_b[v7/2]) << 16)) >> 16) + 32768) >> 16) >= (signed int)pFace) ) ++v16; } } ++v15; v6 = v8 >= (signed int)uModelID; } while ( v15 < v5 ); result = 1; if ( v16 != 1 ) LABEL_25: result = 0; return result; } //----- (004C1EE5) -------------------------------------------------------- bool Vis::_4C1EE5_BLV_IntersectBModel_2(int *a1, int *a2, __int16 *a3, __int16 *a4, Vec3_short_ *a5, BLVFace *pFace) { bool result; // eax@1 unsigned int v8; // ecx@1 Vec3_short_ *v9; // ecx@2 __int16 *v10; // edx@3 signed int v11; // ecx@4 char v12; // zf@6 Vec3_short_ *v13; // ecx@6 int v14; // edx@7 __int16 *v15; // edx@8 signed int v16; // ecx@9 int v17; // edx@11 __int16 *v18; // edx@12 signed int v19; // ecx@13 signed int a5a; // [sp+24h] [bp+18h]@2 signed int a5b; // [sp+24h] [bp+18h]@7 signed int a5c; // [sp+24h] [bp+18h]@11 result = (bool)pFace; v8 = pFace->uAttributes; if ( BYTE1(v8) & 1 ) { v9 = a5; a5a = 0; *a1 = v9->x; *a2 = v9->y; if ( pFace->uNumVertices ) { v10 = a4 + 1; do { v11 = a5a; a3[2 * a5a] = pFace->pXInterceptDisplacements[a5a] + pIndoor->pVertices[pFace->pVertexIDs[a5a]].x; *(v10 - 1) = pFace->pYInterceptDisplacements[v11] + pIndoor->pVertices[pFace->pVertexIDs[v11]].y; *(__int16 *)((char *)v10 + (int)a3 - (int)a4) = pFace->pXInterceptDisplacements[v11 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v11 + 1]].x; ++a5a; *v10 = pFace->pYInterceptDisplacements[v11 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v11 + 1]].y; v10 += 2; } while ( a5a < pFace->uNumVertices ); } } else { v12 = (BYTE1(v8) & 2) == 0; v13 = a5; if ( v12 ) { v17 = a5->y; a5c = 0; *a1 = v17; *a2 = v13->z; if ( pFace->uNumVertices ) { v18 = a4 + 1; do { v19 = a5c; a3[2 * a5c] = pFace->pYInterceptDisplacements[a5c] + pIndoor->pVertices[pFace->pVertexIDs[a5c]].y; *(v18 - 1) = pFace->pZInterceptDisplacements[v19] + pIndoor->pVertices[pFace->pVertexIDs[v19]].z; *(__int16 *)((char *)v18 + (int)(char *)a3 - (char *)a4) = pFace->pYInterceptDisplacements[v19 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v19 + 1]].y; ++a5c; *v18 = pFace->pZInterceptDisplacements[v19 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v19 + 1]].z; v18 += 2; } while ( a5c < pFace->uNumVertices ); } } else { v14 = a5->x; a5b = 0; *a1 = v14; *a2 = v13->z; if ( pFace->uNumVertices ) { v15 = a4 + 1; do { v16 = a5b; a3[2 * a5b] = pFace->pXInterceptDisplacements[a5b] + pIndoor->pVertices[pFace->pVertexIDs[a5b]].x; *(v15 - 1) = pFace->pZInterceptDisplacements[v16] + pIndoor->pVertices[pFace->pVertexIDs[v16]].z; *(__int16 *)((char *)v15 + (int)a3 - (int)a4) = pFace->pXInterceptDisplacements[v16 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v16 + 1]].x; ++a5b; *v15 = pFace->pZInterceptDisplacements[v16 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v16 + 1]].z; v15 += 2; } while ( a5b < pFace->uNumVertices ); } } } LOBYTE(result) = 1; return result; } //----- (004C2186) -------------------------------------------------------- bool Vis::_4C2186_BLV_IntersectBModel(int *a1, int *a2, __int16 *a3, __int16 *a4, Vec3_short_ *a5, BLVFace *a6, unsigned int uModelID) { bool result; // eax@1 int *v9; // esi@1 unsigned int v10; // ecx@1 unsigned int v11; // edx@3 signed int v12; // ecx@4 __int16 v13; // si@4 __int16 *v14; // ecx@4 unsigned int v15; // edx@8 signed int v16; // ecx@9 __int16 v17; // si@9 __int16 *v18; // ecx@9 unsigned int v19; // edx@12 signed int v20; // ecx@13 __int16 v21; // si@13 __int16 *v22; // ecx@13 signed int a1a; // [sp+14h] [bp+8h]@1 __int16 *a5a; // [sp+24h] [bp+18h]@3 __int16 *a5b; // [sp+24h] [bp+18h]@8 __int16 *a5c; // [sp+24h] [bp+18h]@12 result = (bool)a6; v9 = a1; v10 = a6->uAttributes; a1a = 0; if ( BYTE1(v10) & 1 ) { *v9 = a5->x; *a2 = a5->y; if ( a6->uNumVertices ) { v11 = 188 * uModelID + 72; a5a = a4 + 1; do { v12 = a1a; a3[2 * a1a] = a6->pXInterceptDisplacements[a1a] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[a1a]); + pOutdoor->pBModels[v11].pVertices.pVertices[a6->pVertexIDs[a1a]].x; *(a5a - 1) = a6->pYInterceptDisplacements[v12] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[v12] + 4); + pOutdoor->pBModels[v11].pVertices.pVertices[a6->pVertexIDs[v12]].y; *(__int16 *)((char *)a5a + (int)(char *)a3 - (char *)a4) = a6->pXInterceptDisplacements[v12 + 1] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] // + 12 * a6->pVertexIDs[v12 + 1]); + pOutdoor->pBModels[v11].pVertices.pVertices[a6->pVertexIDs[v12+1]].x; v13 = a6->pYInterceptDisplacements[v12 + 1] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[v12 + 1] + 4); + pOutdoor->pBModels[v11].pVertices.pVertices[a6->pVertexIDs[v12 + 1]].y; v14 = a5a; ++a1a; a5a += 2; *v14 = v13; } while ( a1a < a6->uNumVertices ); } } else { if ( BYTE1(v10) & 2 ) { *v9 = a5->x; *a2 = a5->z; if ( a6->uNumVertices ) { v15 = 188 * uModelID + 72; a5b = a4 + 1; do { v16 = a1a; a3[2 * a1a] = a6->pXInterceptDisplacements[a1a] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[a1a]); + pOutdoor->pBModels[v15].pVertices.pVertices[a6->pVertexIDs[a1a]].x; *(a5b - 1) = a6->pZInterceptDisplacements[v16] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[v16] + 8); + pOutdoor->pBModels[v15].pVertices.pVertices[a6->pVertexIDs[v16]].y; *(__int16 *)((char *)a5b + (int)a3 - (int)a4) = a6->pXInterceptDisplacements[v16 + 1] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] // + 12 * a6->pVertexIDs[v16 + 1]); + pOutdoor->pBModels[v15].pVertices.pVertices[a6->pVertexIDs[v16+1]].x; v17 = a6->pZInterceptDisplacements[v16 + 1] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[v16 + 1] + 8); + pOutdoor->pBModels[v15].pVertices.pVertices[a6->pVertexIDs[v16+1]].z; v18 = a5b; ++a1a; a5b += 2; *v18 = v17; } while ( a1a < a6->uNumVertices ); } } else { *v9 = a5->y; *a2 = a5->z; if ( a6->uNumVertices ) { v19 = 188 * uModelID + 72; a5c = a4 + 1; do { v20 = a1a; a3[2 * a1a] = a6->pYInterceptDisplacements[a1a] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[a1a] + 4); + pOutdoor->pBModels[v19].pVertices.pVertices[a6->pVertexIDs[a1a]].y; *(a5c - 1) = a6->pZInterceptDisplacements[v20] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[v20] + 8); + pOutdoor->pBModels[v19].pVertices.pVertices[a6->pVertexIDs[a1a]].z; *(__int16 *)((char *)a5c + (int)(char *)a3 - (char *)a4) = a6->pYInterceptDisplacements[v20 + 1] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] // + 12 * a6->pVertexIDs[v20 + 1] // + 4); + pOutdoor->pBModels[v19].pVertices.pVertices[a6->pVertexIDs[v20+1]].y; v21 = a6->pZInterceptDisplacements[v20 + 1] // + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[v20 + 1] + 8); + pOutdoor->pBModels[v19].pVertices.pVertices[a6->pVertexIDs[v20+1]].z; v22 = a5c; ++a1a; a5c += 2; *v22 = v21; } while ( a1a < a6->uNumVertices ); } } } LOBYTE(result) = 1; return result; } //----- (004C248E) -------------------------------------------------------- void Vis::CastPickRay(RenderVertexSoft *pRay, float fMouseX, float fMouseY, float fPickDepth) { int v5; // ebx@1 int v6; // edi@1 int v7; // esi@1 Vec3_int_ v8; // ST08_12@1 int v9; // ST04_4@1 int v10; // eax@1 RenderVertexSoft v11[2]; // [sp+2Ch] [bp-74h]@1 int v12; // [sp+8Ch] [bp-14h]@1 int v13; // [sp+90h] [bp-10h]@1 int outz; // [sp+94h] [bp-Ch]@1 int outy; // [sp+98h] [bp-8h]@1 int v16; // [sp+9Ch] [bp-4h]@1 v5 = pIndoorCamera->pos.y; v6 = pIndoorCamera->pos.x; v13 = pIndoorCamera->pos.x; v12 = pIndoorCamera->pos.y; v16 = pIndoorCamera->pos.z; v7 = pIndoorCamera->sRotationY + UnprojectX((signed __int64)fMouseX); v8.z = v16; v8.x = v6; v8.y = v5; v9 = pIndoorCamera->sRotationX + UnprojectY((signed __int64)fMouseY); v10 = _48B561_mess_with_scaling_along_z(/*(int)&fMouseX, */fPickDepth); Vec3_int_::Rotate(v10, v7, v9, v8, (int *)&fMouseX, &outy, &outz); v11[0].flt_2C = 0.0; v11[0].vWorldPosition.x = (double)SLODWORD(fMouseX); v11[0].vWorldPosition.y = (double)outy; v11[0].vWorldPosition.z = (double)outz; v11[1].flt_2C = 0.0; v11[1].vWorldPosition.x = (double)v13; v11[1].vWorldPosition.y = (double)v12; v11[1].vWorldPosition.z = (double)v16; memcpy(pRay, &v11[1], 0x30u); memcpy(&pRay[1], v11, sizeof(pRay[1])); } //----- (004C2551) -------------------------------------------------------- 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_ObjectInfo *result; // eax@6 v3 = this->uNumPointers; v4 = 0; if ( (signed int)v3 <= 0 ) { LABEL_6: result = 0; } else { v5 = (char *)&this->object_pool[0].sZValue; while ( *((int *)v5 + 1) != a2 || (*(int *)v5 & 0xFFFF) != a3 ) { ++v4; v5 += 12; if ( v4 >= (signed int)v3 ) goto LABEL_6; } result = &this->object_pool[v4]; } return result; } //----- (004C2591) -------------------------------------------------------- void Vis_SelectionList::create_object_pointers(PointerCreationType type) { switch (type) { case All: { for (uint i = 0; i < uNumPointers; ++i) object_pointers[i] = &object_pool[i]; } break; 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) { for (uint j = 0; j < i; ++j) { if (object_pointers[j] == &object_pool[i]) { create = false; break; } } if (create) object_pointers[i] = &object_pool[i]; } } 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); } } //----- (004C264A) -------------------------------------------------------- void Vis::sort_object_pointers(Vis_ObjectInfo **pPointers, int left, int right) { int v4; // edx@1 int v5; // ebx@1 int v6; // esi@2 signed int i; // ecx@2 int v8; // eax@3 int v9; // ebx@4 int v10; // ebx@6 Vis_ObjectInfo *v11; // eax@7 Vis *thisa; // [sp+4h] [bp-4h]@1 Vis_ObjectInfo *a3a; // [sp+14h] [bp+Ch]@2 v4 = left; v5 = right; thisa = this; if ( right > left ) { do { v6 = v4 - 1; a3a = pPointers[v5]; for ( i = v5; ; pPointers[i] = v11 ) { v8 = a3a->sZValue; LOWORD(v8) = 0; do { ++v6; v9 = pPointers[v6]->sZValue; LOWORD(v9) = 0; } while ( v9 < (unsigned int)v8 ); do { if ( i < 1 ) break; --i; v10 = pPointers[i]->sZValue; LOWORD(v10) = 0; } while ( v10 > (unsigned int)v8 ); v11 = pPointers[v6]; if ( v6 >= i ) break; pPointers[v6] = pPointers[i]; } v5 = right; pPointers[v6] = pPointers[right]; pPointers[right] = v11; sort_object_pointers(pPointers, v4, v6 - 1); v4 = v6 + 1; } while ( right > v6 + 1 ); } } //----- (004C26D0) -------------------------------------------------------- bool Vis::SortVerticesByX(RenderVertexD3D3 *a2, unsigned int uStart, unsigned int uEnd) { bool result; // eax@1 RenderVertexD3D3 *v5; // edx@2 RenderVertexD3D3 *v6; // esi@2 void *v7; // edi@2 unsigned int v8; // ebx@2 RenderVertexD3D3 *v9; // ecx@3 RenderVertexD3D3 *v10; // ecx@5 RenderVertexD3D3 *v11; // eax@8 RenderVertexD3D3 v12; // [sp+4h] [bp-4Ch]@8 RenderVertexD3D3 v13; // [sp+24h] [bp-2Ch]@2 Vis *thisa; // [sp+44h] [bp-Ch]@1 RenderVertexD3D3 *v15; // [sp+48h] [bp-8h]@2 unsigned int v16; // [sp+4Ch] [bp-4h]@2 result = uEnd; thisa = this; if ( (signed int)uEnd > (signed int)uStart ) { v5 = a2; v6 = &a2[uEnd]; v7 = &v13; v15 = &a2[uEnd]; v8 = uStart - 1; v16 = uEnd; while ( 1 ) { memcpy(v7, v6, 0x20u); v9 = &v5[v8]; do { ++v9; ++v8; } while ( v9->pos.x < (double)v13.pos.x ); v10 = &v5[v16]; do { --v10; --v16; } while ( v10->pos.x > (double)v13.pos.x ); if ( (signed int)v8 >= (signed int)v16 ) break; v11 = &v5[v16]; memcpy(&v12, &a2[v8], sizeof(v12)); v5 = a2; memcpy(&a2[v8], v11, sizeof(a2[v8])); v6 = &v12; v7 = v11; } memcpy(&v12, &v5[v8], sizeof(v12)); memcpy(&v5[v8], v15, sizeof(v5[v8])); memcpy(v15, &v12, 0x20u); SortVerticesByX(v5, uStart, v8 - 1); SortVerticesByX(a2, v8 + 1, uEnd); } return true; } //----- (004C27AD) -------------------------------------------------------- bool Vis::SortVerticesByY(RenderVertexD3D3 *a2, unsigned int uStart, unsigned int uEnd) { bool result; // eax@1 RenderVertexD3D3 *v5; // edx@2 RenderVertexD3D3 *v6; // esi@2 void *v7; // edi@2 unsigned int v8; // ebx@2 float *v9; // ecx@3 float *v10; // ecx@5 RenderVertexD3D3 *v11; // eax@8 RenderVertexD3D3 v12; // [sp+4h] [bp-4Ch]@8 RenderVertexD3D3 v13; // [sp+24h] [bp-2Ch]@2 Vis *thisa; // [sp+44h] [bp-Ch]@1 RenderVertexD3D3 *v15; // [sp+48h] [bp-8h]@2 unsigned int v16; // [sp+4Ch] [bp-4h]@2 result = uEnd; thisa = this; if ( (signed int)uEnd > (signed int)uStart ) { v5 = a2; v6 = &a2[uEnd]; v7 = &v13; v15 = &a2[uEnd]; v8 = uStart - 1; v16 = uEnd; while ( 1 ) { memcpy(v7, v6, 0x20u); v9 = &v5[v8].pos.y; do { v9+=8; ++v8; } while ( *v9 < (double)v13.pos.y ); v10 = &v5[v16].pos.y; do { v10-=8; --v16; } while ( *v10 > (double)v13.pos.y ); if ( (signed int)v8 >= (signed int)v16 ) break; v11 = &v5[v16]; memcpy(&v12, &a2[v8], sizeof(v12)); v5 = a2; memcpy(&a2[v8], v11, sizeof(a2[v8])); v6 = &v12; v7 = v11; } memcpy(&v12, &v5[v8], sizeof(v12)); memcpy(&v5[v8], v15, sizeof(v5[v8])); memcpy(v15, &v12, 0x20u); SortVerticesByY(v5, uStart, v8 - 1); SortVerticesByY(a2, v8 + 1, uEnd); } return true; } //----- (004C288E) -------------------------------------------------------- bool Vis::SortByScreenSpaceX(RenderVertexSoft *pArray, int sLeft, int sRight) { bool result; // eax@1 RenderVertexSoft *v5; // edx@2 int v6; // ebx@2 int i; // ecx@2 int v8; // esi@3 int v9; // esi@5 //RenderVertexSoft *v10; // eax@8 const void *v10; RenderVertexSoft v11; // [sp+4h] [bp-6Ch]@8 RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 //float v13; // [sp+4Ch] [bp-24h]@4 int v14; // [sp+64h] [bp-Ch]@7 //Vis *thisa; // [sp+68h] [bp-8h]@1 //void *thisa; //RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2 const void *v16; //thisa = this; if (sRight <= sLeft) return true; v5 = pArray; v16 = &pArray[sRight]; v6 = sLeft - 1; memcpy(&v12, &pArray[sRight], sizeof(v12)); for ( i = sRight; ; i = v14 ) { v8 = (int)&v5[v6].vWorldViewProjX; do { v8 += 48; ++v6; } while ( *(float *)v8 < v12.vWorldViewProjX); v9 = (int)&v5[i].vWorldViewProjX; do { v9 -= 48; --i; } while ( *(float *)v9 > v12.vWorldViewProjX); v14 = i; if ( v6 >= i ) break; v10 = &v5[i]; memcpy(&v11, &pArray[v6], sizeof(v11)); v5 = pArray; memcpy(&pArray[v6], v10, sizeof(pArray[v6])); memcpy((void *)v10, &v11, sizeof(0x30u)); } memcpy(&v11, &v5[v6], sizeof(v11)); memcpy(&v5[v6], v16, sizeof(v5[v6])); memcpy((void *)v16, &v11, sizeof(0x30u)); SortByScreenSpaceX(v5, sLeft, v6 - 1); SortByScreenSpaceX(pArray, v6 + 1, sRight); return true; } //----- (004C297E) -------------------------------------------------------- bool Vis::SortByScreenSpaceY(RenderVertexSoft *pArray, int sLeft, int sRight) { //bool result; // eax@1 RenderVertexSoft *v5; // edx@2 int v6; // ebx@2 int i; // ecx@2 int v8; // esi@3 int v9; // esi@5 //RenderVertexSoft *v10; // eax@8 const void *v10; //char v11; // [sp+4h] [bp-6Ch]@8 RenderVertexSoft v11; RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 //float v13; // [sp+50h] [bp-20h]@4 int v14; // [sp+64h] [bp-Ch]@7 //Vis *thisa; // [sp+68h] [bp-8h]@1 RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2 if (sRight <= sLeft) return true; v5 = pArray; v16 = &pArray[sRight]; v6 = sLeft - 1; memcpy(&v12, &pArray[sRight], sizeof(v12)); for ( i = sRight; ; i = v14 ) { v8 = (int)&v5[v6].vWorldViewProjY; do { v8 += 48; ++v6; } while ( *(float *)v8 < v12.vWorldViewProjY); v9 = (int)&v5[v6].vWorldViewProjY; do { v9 -= 48; --i; } while ( *(float *)v9 > v12.vWorldViewProjY); v14 = i; if ( v6 >= i ) break; v10 = &v5[i]; memcpy(&v11, &pArray[v6], sizeof(0x30)); v5 = pArray; memcpy(&pArray[v6], v10, sizeof(pArray[v6])); memcpy((void *)v10, &v11, sizeof(0x30)); } memcpy(&v11, &v5[v6], sizeof(0x30)); memcpy(&v5[v6], v16, sizeof(v5[v6])); memcpy((void *)v16, &v11, sizeof(0x30)); SortByScreenSpaceY(v5, sLeft, v6 - 1); SortByScreenSpaceY(pArray, v6 + 1, sRight); return true; } //----- (004C04AF) -------------------------------------------------------- Vis::Vis() { RenderVertexSoft v3; // [sp+Ch] [bp-60h]@1 RenderVertexSoft v4; // [sp+3Ch] [bp-30h]@1 v3.flt_2C = 0.0; v3.vWorldPosition.x = 0.0; v3.vWorldPosition.y = 65536.0; v3.vWorldPosition.z = 0.0; v4.flt_2C = 0.0; v4.vWorldPosition.x = 65536.0; v4.vWorldPosition.y = 0.0; v4.vWorldPosition.z = 0.0; 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(&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(&stru_206C, &v3, sizeof(stru_206C)); memcpy(&stru_209C, &v4, sizeof(stru_209C)); keyboard_pick_depth = 512; } //----- (004C055C) -------------------------------------------------------- Vis_SelectionList::Vis_SelectionList() { for (uint i = 0; i < 512; ++i) { object_pool[i].object = nullptr; object_pool[i].sZValue = -1; object_pool[i].object_type = VisObjectType_Any; } uNumPointers = 0; } //----- (004C05CC) -------------------------------------------------------- bool Vis::PickKeyboard(Vis_SelectionList *list, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter) { if (!list) list = &default_list; list->uNumPointers = 0; 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 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, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter) { RenderVertexSoft pMouseRay[2]; // [sp+1Ch] [bp-60h]@1 default_list.uNumPointers = 0; CastPickRay(pMouseRay, fMouseX, fMouseY, fDepth); PickBillboards_Mouse(fDepth, fMouseX, fMouseY, &default_list, sprite_filter); if (uCurrentlyLoadedLevelType == LEVEL_Indoor) PickIndoorFaces_Mouse(fDepth, pMouseRay, &default_list, face_filter); else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) PickOutdoorFaces_Mouse(fDepth, pMouseRay, &default_list, face_filter, false); else { Log::Warning(L"Picking mouse in undefined level"); // picking in main menu is default (buggy) game behaviour. should've returned false in Game::PickMouse return 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::PickBillboards_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) { for (int i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) { auto d3d_billboard = &pRenderer->pBillboardRenderListD3D[i]; if (is_part_of_selection((void *)i, filter)) { if (DoesRayIntersectBillboard(pick_depth, i)) { auto billboard = &pBillboardRenderList[d3d_billboard->uParentBillboardID]; list->AddObject((void *)d3d_billboard->uParentBillboardID, VisObjectType_Sprite, billboard->sZValue); } } } } // tests the object against selection filter to determine whether it can be picked or not //----- (004C0791) -------------------------------------------------------- bool Vis::is_part_of_selection(void *uD3DBillboardIdx_or_pBLVFace_or_pODMFace, Vis_SelectionFilter *filter) { //stru157 *v3; // esi@1 //int result; // eax@1 int v5; // edx@2 //int v6; // ecx@2 //char v7; // zf@3 int v8; // esi@5 std::string *v9; // ecx@7 Actor *v10; // edi@18 //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 int v16; // [sp-4h] [bp-10h]@7 switch (filter->object_type) { case VisObjectType_Any: return true; case VisObjectType_Sprite: { 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; } case VisObjectType_Face: { 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; } default: assert(false); } } //----- (004C091D) -------------------------------------------------------- bool Vis::DoesRayIntersectBillboard(float fDepth, unsigned int uD3DBillboardIdx) { int v3; // eax@3 //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 v10; // eax@17 double v11; // st6@18 double v12; // st7@18 double v13; // st4@18 float v14; // ST0C_4@22 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 double v20; // st6@32 double v21; // st7@32 int v22; // eax@32 double v23; // st7@36 //void *v24; // esi@40 float v25; // ST08_4@40 //float v26; // ST04_4@41 //float v27; // ST00_4@42 int v28; // eax@45 unsigned int v29; // eax@47 char result; // al@48 struct RenderVertexSoft pPickingRay[2]; //int v31; // [sp+20h] [bp-DCh]@5 struct RenderVertexSoft local_80[2]; //int v32; // [sp+80h] [bp-7Ch]@22 float v33; // [sp+E0h] [bp-1Ch]@33 float v34; // [sp+E4h] [bp-18h]@32 int v35; // [sp+E8h] [bp-14h]@5 int v36; // [sp+ECh] [bp-10h]@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_SelectionList Vis_static_stru_F91E10; Vis_static_stru_F91E10.uNumPointers = 0; v3 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].uParentBillboardID; if (v3 == -1) return false; if (pBillboardRenderList[v3].GetFloatZ() > fDepth) { LABEL_49: return false; } v37 = pBillboardRenderList[v3].sZValue & 0xFFFF0000; GetPolygonCenter(pRenderer->pBillboardRenderListD3D[v3].pQuards, 4, (float *)&v35, (float *)&v36); CastPickRay(pPickingRay, *(float *)&v35, *(float *)&v36, fDepth); if (uCurrentlyLoadedLevelType == LEVEL_Indoor) PickIndoorFaces_Mouse(fDepth, pPickingRay, &Vis_static_stru_F91E10, &vis_face_filter); else 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.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z) return 1; } else if ((double)(pViewport->uScreen_TL_X) <= *(float *)&v35 && (double)pViewport->uScreen_BR_X >= *(float *)&v35 && (double)pViewport->uScreen_TL_Y <= *(float *)&v36 && (double)pViewport->uScreen_BR_Y >= *(float *)&v36) return 1; v40 = 0; v10 = (int)&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y; LODWORD(v38) = (int)&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y; while ( 1 ) { v12 = *(float *)(v10 - 4); v11 = *(float *)v10; v13 = *(float *)(v10 - 4); Vis_static_stru_F91E10.uNumPointers = 0; if ( v13 >= (double)(pViewport->uScreen_TL_X)) { if ( v12 <= (double)pViewport->uScreen_BR_X ) { if ( v11 >= (double)pViewport->uScreen_TL_Y ) { if ( v11 <= (double)pViewport->uScreen_BR_Y ) { v14 = v11; v15 = v12; CastPickRay(local_80, SLODWORD(v15), v14, fDepth); if ( uCurrentlyLoadedLevelType == 1 ) PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter); else 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; 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; } } } } } ++v40; v10 = LODWORD(v38) + 32; LODWORD(v38) += 32; if ( v40 >= 4 ) { if ( uCurrentlyLoadedLevelType != 2 ) return false; v21 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.x; v20 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[3].pos.x; v22 = *(int *)(&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y); v34 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[3].pos.x; LODWORD(v38) = v22; v41 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[1].pos.y; if ( v21 > v20 ) { v33 = v21; v21 = v34; v20 = v33; } if ( v38 > (double)v41 ) v41 = v38; Vis_static_stru_F91E10.uNumPointers = 0; v23 = (v20 - v21) * 0.5; if ( v23 < (double)(pViewport->uScreen_TL_X) || v23 > (double)pViewport->uScreen_BR_X || (double)pViewport->uScreen_TL_Y > v41 || (double)pViewport->uScreen_BR_Y < v41 || ((v25 = v23, CastPickRay(local_80, SLODWORD(v25), v41, fDepth), uCurrentlyLoadedLevelType != 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.object_pointers), v29 = *(_DWORD *)(v28 + 4), LOWORD(v29) = 0, v29 <= v37)) ) return false; break; } } return true; } // F93E18: using guessed type char static_byte_F93E18_init; //----- (004C0D32) -------------------------------------------------------- void Vis::PickIndoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) { int result; // eax@1 signed int pFaceID; // esi@2 BLVFace *pFace; // edi@4 unsigned int v7; // eax@6 Vis_ObjectInfo *v8; // eax@6 signed int i; // [sp+18h] [bp-8h]@1 result = 0; for ( i = 0; i < (signed int)pBspRenderer->num_faces; ++i ) { pFaceID = pBspRenderer->faces[result].uFaceID; if ( pFaceID >= 0 ) { if ( pFaceID < (signed int)pIndoor->uNumFaces ) { pFace = &pIndoor->pFaces[pFaceID]; if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[pFaceID]) ) { if ( is_part_of_selection(pFace, filter) ) { v7 = 8 * pFaceID; LOBYTE(v7) = 8 * pFaceID | OBJECT_BModel; v8 = _4C1026(pFace, v7, pick_depth); if ( v8 ) list->AddObject(v8->object, v8->object_type, v8->sZValue); } } } } result = i + 1; } } //----- (004C0DEA) -------------------------------------------------------- void Vis::PickOutdoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) { for (uint i = 0; i < pOutdoor->uNumBModels; ++i) { int v17; if (!IsBModelVisible(i, &v17)) continue; if (!v17) continue; auto bmodel = pOutdoor->pBModels + i; for (uint j = 0; j < bmodel->uNumFaces; ++j) { auto face = bmodel->pFaces + j; if (is_part_of_selection(face, filter) ) { 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); } } } }