Mercurial > mm7
changeset 1375:270134611caf
Merge
author | Grumpy7 |
---|---|
date | Tue, 16 Jul 2013 00:00:05 +0200 |
parents | 2e5c994f0833 (current diff) 87155494292c (diff) |
children | 437d4ed49f26 132a6a0d5cef |
files | |
diffstat | 6 files changed, 224 insertions(+), 346 deletions(-) [+] |
line wrap: on
line diff
--- a/Indoor.cpp Mon Jul 15 23:59:04 2013 +0200 +++ b/Indoor.cpp Tue Jul 16 00:00:05 2013 +0200 @@ -771,7 +771,7 @@ v7 = GetPortalScreenCoord(v1); if ( v7 ) { - if ( sub_424829(v7, &stru_F8A590, pBLVRenderParams->field_7C, v1) ) + if ( PortalFrustrum(v7, &stru_F8A590, pBLVRenderParams->field_7C, v1) ) { if ( v2->uPolygonType == 1 ) { @@ -1379,7 +1379,7 @@ face_min_screenspace_x <= nodes[node_id].uViewportZ && face_max_screenspace_y >= nodes[node_id].uViewportY && face_min_screenspace_y <= nodes[node_id].uViewportW && - sub_424829(num_vertices, &nodes[num_nodes].field_C, &nodes[node_id].field_C, uFaceID)) + PortalFrustrum(num_vertices, &nodes[num_nodes].field_C, &nodes[node_id].field_C, uFaceID)) { pTransitionSector = pFace->uSectorID; if (nodes[node_id].uSectorID == pTransitionSector ) @@ -1532,7 +1532,7 @@ && v23 <= *((short *)v20 + 2007) && v12 >= *((short *)v20 + 2006) && v22 <= *((short *)v20 + 2008) - && sub_424829(v10, &v3->nodes[v3->num_nodes].field_C, (BspRenderer_stru2 *)(v20 + 4020), uFaceID) ) + && PortalFrustrum(v10, &v3->nodes[v3->num_nodes].field_C, (BspRenderer_stru2 *)(v20 + 4020), uFaceID) ) { v16 = v21->uSectorID; if ( *((short *)v20 + 2004) == v16 ) @@ -1591,7 +1591,7 @@ v3 = GetPortalScreenCoord(v2); if ( v3 ) { - if ( sub_424829(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1) ) + if ( PortalFrustrum(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1) ) { v4 = stru_F8A590._viewport_space_y; v5 = pBLVRenderParams->pRenderTarget; @@ -6831,139 +6831,106 @@ check_event_triggers(); } //----- (00424829) -------------------------------------------------------- -bool sub_424829(int pNumVertices, BspRenderer_stru2 *a2, BspRenderer_stru2 *a3, int uFaceID) +bool PortalFrustrum(int pNumVertices, BspRenderer_stru2 *a2, BspRenderer_stru2 *a3, int uFaceID) { - //int v4; // edi@1 - //BspRenderer_stru2 *v5; // ebx@1 - int v6; // eax@3 + //int v6; // eax@3 int min_y; // esi@5 int max_y; // edx@5 - //int v9; // ecx@6 - int v10; // eax@12 - //int v11; // edi@13 - //int v12; // edx@18 + int current_ID; // eax@12 int v13; // eax@22 - //int v14; // edi@28 int v15; // ecx@29 - //int v16; // edi@30 - //int v17; // edx@35 int v18; // eax@39 int v19; // eax@44 int v20; // ecx@44 - //int v21; // edi@45 int v22; // edi@46 - //__int16 *v23; // ecx@47 int v24; // edx@48 - //int v25; // eax@50 int v26; // eax@55 signed int v27; // edi@55 - //int v28; // edx@56 int v29; // edx@57 - //int v30; // eax@59 int v31; // eax@64 signed int v32; // edi@64 - //int v33; // edx@65 int v34; // eax@66 int v35; // dx@66 __int16 v36; // dx@67 __int16 v37; // di@67 __int16 v38; // dx@67 - //BspRenderer_stru2 *v39; // ecx@69 - //int v40; // edx@69 - //int v41; // edi@70 - //__int16 *v42; // eax@76 - //__int16 *v43; // eax@81 - //__int16 *v45; // eax@87 int v46; // edx@87 - //__int16 v47; // cx@88 - //int v48; // eax@93 int v49; // esi@93 - //__int16 *v50; // ecx@94 - //int v51; // eax@95 - //int v52; // eax@97 int v53; // [sp+Ch] [bp-34h]@44 int v54; // [sp+10h] [bp-30h]@0 - int v55; // [sp+14h] [bp-2Ch]@12 - //__int16 *v56; // [sp+14h] [bp-2Ch]@47 - //__int16 v57; // [sp+14h] [bp-2Ch]@76 - //__int16 v58; // [sp+14h] [bp-2Ch]@81 + int min_y_ID2; // [sp+14h] [bp-2Ch]@12 int v59; // [sp+14h] [bp-2Ch]@87 - //BspRenderer_stru2 *v60; // [sp+18h] [bp-28h]@1 int v61; // [sp+1Ch] [bp-24h]@29 int v62; // [sp+20h] [bp-20h]@0 - signed int v63; // [sp+24h] [bp-1Ch]@3 - signed int v64; // [sp+28h] [bp-18h]@3 - int v65; // [sp+2Ch] [bp-14h]@5 - //int v66; // [sp+2Ch] [bp-14h]@39 - //int v67; // [sp+30h] [bp-10h]@22 - int v68; // [sp+34h] [bp-Ch]@12 + signed int direction1; // [sp+24h] [bp-1Ch]@3 + signed int direction2; // [sp+28h] [bp-18h]@3 + int min_y_ID; // [sp+2Ch] [bp-14h]@5 + //int v68; // [sp+34h] [bp-Ch]@12 int v69; // [sp+34h] [bp-Ch]@29 int v70; // [sp+34h] [bp-Ch]@46 int v71; // [sp+34h] [bp-Ch]@75 int v72; // [sp+34h] [bp-Ch]@80 - //int v73; // [sp+38h] [bp-8h]@11 - //int v74; // [sp+3Ch] [bp-4h]@1 - //int a3a; // [sp+48h] [bp+8h]@76 - //int a3b; // [sp+48h] [bp+8h]@87 - - //try graphic engine with function returning 1 always, and without - //return true; + if ( pNumVertices <= 1 ) return false; min_y = PortalFace._screen_space_y[0]; - v65 = 0; + min_y_ID = 0; max_y = PortalFace._screen_space_y[0]; + //face direction(направление фейса) if ( !PortalFace.direction ) { - v63 = 1; - v64 = -1; + direction1 = 1; + direction2 = -1; } else { - v63 = -1; - v64 = 1; - } - - for ( v6 = 1; v6 < pNumVertices; ++v6 ) - { - if ( PortalFace._screen_space_y[v6] >= min_y ) + direction1 = -1; + direction2 = 1; + } + + //get min and max y for portal(дать минимальное и максимальное значение y для портала) + for ( uint i = 1; i < pNumVertices; ++i ) + { + if ( PortalFace._screen_space_y[i] >= min_y ) { - if ( PortalFace._screen_space_y[v6] > max_y ) - max_y = PortalFace._screen_space_y[v6]; + if ( PortalFace._screen_space_y[i] > max_y ) + max_y = PortalFace._screen_space_y[i]; } - if ( PortalFace._screen_space_y[v6] < min_y ) + else { - v65 = v6; - min_y = PortalFace._screen_space_y[v6]; + min_y_ID = i; + min_y = PortalFace._screen_space_y[i]; } } if ( max_y == min_y ) return false; - v10 = v65; + //***************************************************************************************************************************** a2->_viewport_space_y = min_y; a2->_viewport_space_w = max_y; - v55 = v65; - - for ( v68 = 0; v68 < pNumVertices; ++v68 ) - { - v10 += v64; - if ( v10 < pNumVertices ) + current_ID = min_y_ID; + min_y_ID2 = min_y_ID; + + for ( uint i = 0; i < pNumVertices; ++i ) + { + current_ID += direction2; + if ( current_ID < pNumVertices ) { - if ( v10 < 0 ) - v10 += pNumVertices; + if ( current_ID < 0 ) + current_ID += pNumVertices; } else - v10 -= pNumVertices; - if ( PortalFace._screen_space_y[v10] <= PortalFace._screen_space_y[v65] ) + current_ID -= pNumVertices; + if ( PortalFace._screen_space_y[current_ID] <= PortalFace._screen_space_y[min_y_ID] )//определение минимальной у { - v55 = v10; - v65 = v10; + min_y_ID2 = current_ID; + min_y_ID = current_ID; } - if ( PortalFace._screen_space_y[v10] == max_y ) + if ( PortalFace._screen_space_y[current_ID] == max_y ) break; } - v13 = v55 + v64; + + v13 = min_y_ID2 + direction2; if ( v13 < pNumVertices ) { if ( v13 < 0 ) @@ -6971,18 +6938,19 @@ } else v13 -= pNumVertices; - if ( PortalFace._screen_space_y[v13] != PortalFace._screen_space_y[v55] ) - { - v62 = PortalFace._screen_space_x[v55] << 16; - v54 = ((PortalFace._screen_space_x[v13] - PortalFace._screen_space_x[v55]) << 16) / (PortalFace._screen_space_y[v13] - PortalFace._screen_space_y[v55]); - a2->viewport_left_side[min_y] = LOWORD(PortalFace._screen_space_x[v55]); - } - v15 = v65; - v61 = v65; - + if ( PortalFace._screen_space_y[v13] != PortalFace._screen_space_y[min_y_ID2] ) + { + v62 = PortalFace._screen_space_x[min_y_ID2] << 16; + v54 = ((PortalFace._screen_space_x[v13] - PortalFace._screen_space_x[min_y_ID2]) << 16) / (PortalFace._screen_space_y[v13] - PortalFace._screen_space_y[min_y_ID2]); + a2->viewport_left_side[min_y] = PortalFace._screen_space_x[min_y_ID2]; + } + //**************************************************************************************************************************************** + // + v15 = min_y_ID; + v61 = min_y_ID; for ( v69 = 0; v69 < pNumVertices; ++v69 ) { - v15 += v63; + v15 += direction1; if ( v15 < pNumVertices ) { if ( v15 < 0 ) @@ -6990,15 +6958,15 @@ } else v15 -= pNumVertices; - if ( PortalFace._screen_space_y[v15] <= PortalFace._screen_space_y[v65] ) + if ( PortalFace._screen_space_y[v15] <= PortalFace._screen_space_y[min_y_ID] ) { v61 = v15; - v65 = v15; + min_y_ID = v15; } if ( PortalFace._screen_space_y[v15] == max_y ) break; } - v18 = v63 + v61; + v18 = direction1 + v61; if ( v18 < pNumVertices ) { if ( v18 < 0 ) @@ -7012,8 +6980,9 @@ { v61 = PortalFace._screen_space_x[v20] << 16; v53 = ((PortalFace._screen_space_x[v19] - PortalFace._screen_space_x[v20]) << 16) / PortalFace._screen_space_y[v19] - PortalFace._screen_space_y[v20]; - a2->viewport_right_side[max_y] = LOWORD(PortalFace._screen_space_x[v20]); - } + a2->viewport_right_side[max_y] = PortalFace._screen_space_x[v20]; + } + //**************************************************************************************************************************************** v22 = min_y; if ( min_y <= max_y ) { @@ -7024,7 +6993,7 @@ v24 = v13; if ( v22 >= PortalFace._screen_space_y[v13] && v22 != max_y ) { - v13 = v64 + v13; + v13 = direction2 + v13; if ( v13 < pNumVertices ) { if ( v13 < 0 ) @@ -7043,7 +7012,7 @@ v29 = v18; if ( v70 >= PortalFace._screen_space_y[v18] && v70 != max_y ) { - v18 += v63; + v18 += direction1; if ( v18 < pNumVertices ) { if ( v18 < 0 ) @@ -7169,16 +7138,8 @@ BLVFace *pFace; // ebx@1 int pNextVertices; // edx@11 int t; // ST28_4@12 - signed int v13; // edx@12 - signed __int64 v14; // qtt@12 - signed int v17; // eax@14 - signed __int64 v18; // qtt@14 - signed int v20; // edx@17 - int v25; // eax@22 int pScreenX; // eax@22 - int v31; // eax@27 int pScreenY; // eax@27 - int v35; // ST30_4@30 signed int left_num_vertices; // edi@31 signed int right_num_vertices; // ebx@41 signed int top_num_vertices; // edi@51 @@ -7189,12 +7150,10 @@ int v65; // ecx@83 signed int v71; // [sp+14h] [bp-14h]@75 bool current_vertices_flag; // [sp+18h] [bp-10h]@9 - int thisb; // [sp+18h] [bp-10h]@12 int thisf; // [sp+18h] [bp-10h]@74 signed int depth_num_vertices; // [sp+1Ch] [bp-Ch]@9 int v80; // [sp+1Ch] [bp-Ch]@76 bool next_vertices_flag; // [sp+20h] [bp-8h]@10 - signed int v90; // [sp+24h] [bp-4h]@51 pFace = &pIndoor->pFaces[uFaceID]; memset(&PortalFace, 0, sizeof(stru367)); @@ -7241,8 +7200,6 @@ &PortalFace._view_transformed_z[i + 3], &PortalFace._view_transformed_x[i + 3], &PortalFace._view_transformed_y[i + 3], 0); } } - //х: 55681665, 55681665, 53050369, 47787777, 45156481, 45156481 - //x: 0x0351 a281,0x0351 a281,0x0329 7c01,0x02d9 2f01,0x02b1 0881,0x02b1 0881 //***************************************************************************************************************************************** //check vertices for the nearest plane(проверка вершин есть ли в области за ближайшей плоскостью) if ( pFace->uNumVertices <= 0 ) @@ -7287,11 +7244,8 @@ { if ( next_vertices_flag )//следующая вершина за ближней границей { - v13 = 524288 - PortalFace._view_transformed_z[i + 2]; - LODWORD(v14) = v13 << 16; - HIDWORD(v14) = v13 >> 16; //t = near_clip - v0.z / v1.z - v0.z - t = v14 / PortalFace._view_transformed_z[i + 3] - PortalFace._view_transformed_z[i + 2]; + t = fixpoint_div(524288 - PortalFace._view_transformed_z[i + 2], PortalFace._view_transformed_z[i + 3] - PortalFace._view_transformed_z[i + 2]); //New_x = (v1.x - v0.x)*t + v0.x PortalFace._view_transformed_x[depth_num_vertices] = ((unsigned __int64)((PortalFace._view_transformed_x[i + 3] - PortalFace._view_transformed_x[i + 2]) * t) >> 16) + PortalFace._view_transformed_x[i + 2]; @@ -7303,11 +7257,8 @@ } else// текущая вершина за ближней границей { - v17 = 524288 - PortalFace._view_transformed_z[i + 3]; - LODWORD(v18) = v17 << 16; - HIDWORD(v18) = v17 >> 16; //t = near_clip - v1.z / v0.z - v1.z - t = v18 / PortalFace._view_transformed_z[i + 2] - PortalFace._view_transformed_z[i + 3]; + t = fixpoint_div(524288 - PortalFace._view_transformed_z[i + 3], PortalFace._view_transformed_z[i + 2] - PortalFace._view_transformed_z[i + 3]); //New_x = (v0.x - v1.x)*t + v1.x PortalFace._view_transformed_x[depth_num_vertices] = ((unsigned __int64)((PortalFace._view_transformed_x[i + 2] - PortalFace._view_transformed_x[i + 3]) * t) >> 16) + PortalFace._view_transformed_x[i + 3]; @@ -7379,15 +7330,13 @@ PortalFace._screen_space_x[i + 12] = pBLVRenderParams->uViewportCenterX - ((unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)pScreenX) >> 16); PortalFace._screen_space_y[i + 12] = pBLVRenderParams->uViewportCenterY - ((unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)pScreenY) >> 16); } - //х -34, 4, 61, 83, 83, -34 - //y 211, 152, 172, 216, 273, 293 // результат: при повороте камеры, когда граница портала сдвигается к краю экрана, портал остается прозрачным(видимым) //****************************************************************************************************************************************** //check for left_clip plane(порверка по левой границе) left_num_vertices = 0; PortalFace._screen_space_x[depth_num_vertices + 12] = PortalFace._screen_space_x[12]; PortalFace._screen_space_y[depth_num_vertices + 12] = PortalFace._screen_space_y[12]; - current_vertices_flag = PortalFace._screen_space_x[12] >= (signed int)pBLVRenderParams->uViewportX; + current_vertices_flag = PortalFace._screen_space_x[12] >= (signed int)pBLVRenderParams->uViewportX;//8.0 if ( depth_num_vertices < 1 ) return 0; for ( uint i = 1; i <= depth_num_vertices; ++i ) @@ -7398,22 +7347,20 @@ if ( next_vertices_flag ) { //t = left_clip - v0.x / v1.x - v0.x - t = (signed __int64)(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 11]) - / (PortalFace._screen_space_x[i + 12] - PortalFace._screen_space_x[i + 11]); + t = fixpoint_div(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 11], PortalFace._screen_space_x[i + 12] - PortalFace._screen_space_x[i + 11]); //New_y = (v1.y - v0.y)*t + v0.y - PortalFace._screen_space_y[left_num_vertices + 9] = (signed int)(PortalFace._screen_space_y[i + 12]- PortalFace._screen_space_y[i + 11]) - * t + PortalFace._screen_space_y[i + 11]; + PortalFace._screen_space_y[left_num_vertices + 9] = ((signed int)((PortalFace._screen_space_y[i + 12]- PortalFace._screen_space_y[i + 11]) + * t) >> 16) + PortalFace._screen_space_y[i + 11]; //New_x = left_clip PortalFace._screen_space_x[left_num_vertices + 9] = pBLVRenderParams->uViewportX; } else { //t = left_clip - v1.x / v0.x - v1.x - t = (signed __int64)(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 12]) - / (PortalFace._screen_space_x[i + 11] - PortalFace._screen_space_x[i + 12]); + t = fixpoint_div(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 12], PortalFace._screen_space_x[i + 11] - PortalFace._screen_space_x[i + 12]); //New_y = (v0.y - v1.y)*t + v1.y - PortalFace._screen_space_y[left_num_vertices + 9] = (signed int)( PortalFace._screen_space_y[i + 11] - PortalFace._screen_space_y[i + 12]) - * t + PortalFace._screen_space_y[i + 12]; + PortalFace._screen_space_y[left_num_vertices + 9] = ((signed int)(( PortalFace._screen_space_y[i + 11] - PortalFace._screen_space_y[i + 12]) + * t) >> 16) + PortalFace._screen_space_y[i + 12]; //New_x = left_clip PortalFace._screen_space_x[left_num_vertices + 9] = pBLVRenderParams->uViewportX; } @@ -7432,7 +7379,7 @@ right_num_vertices = 0; PortalFace._screen_space_x[left_num_vertices + 9] = PortalFace._screen_space_x[9]; PortalFace._screen_space_y[left_num_vertices + 9] = PortalFace._screen_space_y[9]; - current_vertices_flag = PortalFace._screen_space_x[9] <= (signed int)pBLVRenderParams->uViewportZ; + current_vertices_flag = PortalFace._screen_space_x[9] <= (signed int)pBLVRenderParams->uViewportZ;//468.0 if (left_num_vertices < 1) return 0; for ( uint i = 1; i <= left_num_vertices; ++i ) @@ -7443,22 +7390,20 @@ if ( next_vertices_flag ) { //t = right_clip - v1.x / v0.x - v1.x - t = (signed __int64)(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 9]) - / (PortalFace._screen_space_x[i + 8] - PortalFace._screen_space_x[i + 9]); + t = fixpoint_div(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 8], PortalFace._screen_space_x[i + 9] - PortalFace._screen_space_x[i + 8]); //New_y = (v0.y - v1.y)*t + v1.y - PortalFace._screen_space_y[right_num_vertices + 6] = (signed int)(PortalFace._screen_space_y[i + 8] - PortalFace._screen_space_y[i + 9]) - * t + PortalFace._screen_space_y[i + 9]; + PortalFace._screen_space_y[right_num_vertices + 6] = ((signed int)((PortalFace._screen_space_y[i + 9] - PortalFace._screen_space_y[i + 8]) + * t) >> 16) + PortalFace._screen_space_y[i + 8]; //New_x = right_clip PortalFace._screen_space_x[right_num_vertices + 6] = pBLVRenderParams->uViewportZ; } else { //t = right_clip - v0.x / v1.x - v0.x - t = (signed __int64)(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 8]) - / (PortalFace._screen_space_x[i + 9] - PortalFace._screen_space_x[i + 8]); + t = fixpoint_div(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 9], PortalFace._screen_space_x[i + 8] - PortalFace._screen_space_x[i + 9]); //New_y = (v1.y - v0.y)*t + v0.y - PortalFace._screen_space_y[right_num_vertices + 6] = (signed int)(PortalFace._screen_space_y[i + 9] - PortalFace._screen_space_y[i + 8]) - * t + PortalFace._screen_space_y[i + 8]; + PortalFace._screen_space_y[right_num_vertices + 6] = ((signed int)((PortalFace._screen_space_y[i + 8] - PortalFace._screen_space_y[i + 9]) + * t) >> 16) + PortalFace._screen_space_y[i + 9]; //New_x = right_clip PortalFace._screen_space_x[right_num_vertices + 6] = pBLVRenderParams->uViewportZ; } @@ -7478,7 +7423,7 @@ PortalFace._screen_space_x[right_num_vertices + 6] = PortalFace._screen_space_x[6]; PortalFace._screen_space_y[right_num_vertices + 6] = PortalFace._screen_space_y[6]; - current_vertices_flag = PortalFace._screen_space_y[6] >= (signed int)pBLVRenderParams->uViewportY; + current_vertices_flag = PortalFace._screen_space_y[6] >= (signed int)pBLVRenderParams->uViewportY;//8.0 if ( right_num_vertices < 1 ) return 0; for ( uint i = 1; i <= right_num_vertices; ++i ) @@ -7488,18 +7433,16 @@ { if ( next_vertices_flag ) { - t = (signed __int64)(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 5]) - / (PortalFace._screen_space_y[i + 6] - PortalFace._screen_space_y[i + 5]); - PortalFace._screen_space_x[top_num_vertices + 3] = (signed int)(PortalFace._screen_space_x[i + 6] - PortalFace._screen_space_x[i + 5]) - * t + PortalFace._screen_space_x[i + 5]; + t = fixpoint_div(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 5], PortalFace._screen_space_y[i + 6] - PortalFace._screen_space_y[i + 5]); + PortalFace._screen_space_x[top_num_vertices + 3] = ((signed int)((PortalFace._screen_space_x[i + 6] - PortalFace._screen_space_x[i + 5]) + * t) >> 16) + PortalFace._screen_space_x[i + 5]; PortalFace._screen_space_y[top_num_vertices + 3] = pBLVRenderParams->uViewportY; } else { - t = (signed __int64)(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 6]) - / (PortalFace._screen_space_y[i + 5] - PortalFace._screen_space_y[i + 6]); - PortalFace._screen_space_x[top_num_vertices + 3] = (signed int)(PortalFace._screen_space_x[i + 5]- PortalFace._screen_space_x[i + 6]) - * t + PortalFace._screen_space_x[i + 6]; + t = fixpoint_div(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 6], PortalFace._screen_space_y[i + 5] - PortalFace._screen_space_y[i + 6]); + PortalFace._screen_space_x[top_num_vertices + 3] = ((signed int)((PortalFace._screen_space_x[i + 5]- PortalFace._screen_space_x[i + 6]) + * t) >> 16) + PortalFace._screen_space_x[i + 6]; PortalFace._screen_space_y[top_num_vertices + 3] = pBLVRenderParams->uViewportY; } top_num_vertices++; @@ -7517,7 +7460,7 @@ bottom_num_vertices = 0; PortalFace._screen_space_x[top_num_vertices + 3] = PortalFace._screen_space_x[3]; PortalFace._screen_space_y[top_num_vertices + 3] = PortalFace._screen_space_y[3]; - current_vertices_flag = PortalFace._screen_space_y[3] <= (signed int)pBLVRenderParams->uViewportW; + current_vertices_flag = PortalFace._screen_space_y[3] <= (signed int)pBLVRenderParams->uViewportW;//351.0 if ( top_num_vertices < 1 ) return 0; for ( uint i =1; i <= top_num_vertices; ++i ) @@ -7527,18 +7470,16 @@ { if ( next_vertices_flag ) { - t = (signed __int64)(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 3]) - / (PortalFace._screen_space_y[i + 2] - PortalFace._screen_space_y[i + 3]); - PortalFace._screen_space_x[bottom_num_vertices] = (signed int)(PortalFace._screen_space_x[i + 2] - PortalFace._screen_space_x[i + 3]) - * t + PortalFace._screen_space_x[i + 3]; + t = fixpoint_div(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 2], PortalFace._screen_space_y[i + 3] - PortalFace._screen_space_y[i + 2]); + PortalFace._screen_space_x[bottom_num_vertices] = ((signed int)((PortalFace._screen_space_x[i + 3] - PortalFace._screen_space_x[i + 2]) + * t) >> 16) + PortalFace._screen_space_x[i + 2]; PortalFace._screen_space_y[bottom_num_vertices] = pBLVRenderParams->uViewportW; } else { - t = (signed __int64)(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 2]) - / (PortalFace._screen_space_y[i + 3] - PortalFace._screen_space_y[i + 2]); - PortalFace._screen_space_x[bottom_num_vertices] = (signed int)(PortalFace._screen_space_x[i + 3] - PortalFace._screen_space_x[i + 2]) - * t + PortalFace._screen_space_x[i + 2]; + t = fixpoint_div(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 3], PortalFace._screen_space_y[i + 2] - PortalFace._screen_space_y[i + 3]); + PortalFace._screen_space_x[bottom_num_vertices] = ((signed int)((PortalFace._screen_space_x[i + 2] - PortalFace._screen_space_x[i + 3]) + * t) >> 16) + PortalFace._screen_space_x[i + 3]; PortalFace._screen_space_y[bottom_num_vertices] = pBLVRenderParams->uViewportW; } bottom_num_vertices++; @@ -7551,8 +7492,6 @@ } current_vertices_flag = next_vertices_flag; } - //out_x: 83,8,8,61,83 - //out_y: 273,293,152,172,216 //*************************************************************************************************************************************** if ( !bottom_num_vertices )
--- a/IndoorCameraD3D.cpp Mon Jul 15 23:59:04 2013 +0200 +++ b/IndoorCameraD3D.cpp Tue Jul 16 00:00:05 2013 +0200 @@ -136,17 +136,17 @@ int a2b; // [sp+18h] [bp+Ch]@5 int a3a; // [sp+1Ch] [bp+10h]@5 - to_x = (x - pBLVRenderParams->vPartyPos.x) << 16; - to_y = (y - pBLVRenderParams->vPartyPos.y) << 16; + to_x = x - pBLVRenderParams->vPartyPos.x; + to_y = y - pBLVRenderParams->vPartyPos.y; if ( pBLVRenderParams->sPartyRotX ) { to_z = (z - pBLVRenderParams->vPartyPos.z) << 16; if ( pRenderer->pRenderD3D ) { - v14 = ((unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sCosineY) >> 16) - + ((unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sSineY) >> 16); - v9 = ((unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sSineY) >> 16) - - ((unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sCosineY) >> 16); + v14 = (unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sCosineY) + + (unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sSineY); + v9 = (unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sSineY) + - (unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sCosineY); } else { @@ -169,10 +169,10 @@ if ( pRenderer->pRenderD3D ) { v10 = pOutX; - *pOutX = ((unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sCosineY) >> 16) - + ((unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sSineY) >> 16); - *pOutZ = ((unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sSineY) >> 16) - - ((unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sCosineY) >> 16); + *pOutX = (unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sCosineY) + + (unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sSineY); + *pOutZ = (unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sSineY) + - (unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sCosineY); } else {
--- a/TurnEngine.cpp Mon Jul 15 23:59:04 2013 +0200 +++ b/TurnEngine.cpp Tue Jul 16 00:00:05 2013 +0200 @@ -802,16 +802,16 @@ // 50FE08: using guessed type stru298 stru_50FE08; //----- (0040680F) -------------------------------------------------------- -void stru262_TurnBased::_40680F( int a2 ) - { +void stru262_TurnBased::_40680F( int queue_index ) + { TurnBased_QueueElem *v2; // eax@1 unsigned int v3; // eax@1 - unsigned int v4; // edi@2 + unsigned int actor_id; // edi@2 Actor *v5; // ebx@2 unsigned int *v6; // esi@7 AIDirection *v7; // esi@10 int v8; // eax@10 - unsigned int v9; // ecx@10 + int v9; // ecx@10 signed int v10; // eax@13 unsigned __int8 v11; // sf@19 unsigned __int8 v12; // of@19 @@ -821,141 +821,121 @@ AIDirection a3; // [sp+Ch] [bp-44h]@10 AIDirection v18; // [sp+28h] [bp-28h]@10 int a2a; // [sp+44h] [bp-Ch]@2 - unsigned int v20; // [sp+48h] [bp-8h]@10 + int v20; // [sp+48h] [bp-8h]@10 TurnBased_QueueElem *v21; // [sp+4Ch] [bp-4h]@1 signed int v22; // [sp+58h] [bp+8h]@10 - v2 = &pQueue[a2]; + v2 = &pQueue[queue_index]; v21 = v2; v2->uActionLength = 0; v3 = v2->uPackedID; - if ( (unsigned __int8)v3 & 3 ) + if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor) { - v3 = PID_ID(v3); - v4 = v3; + + actor_id = PID_ID(pQueue[queue_index].uPackedID); a2a = v3; - v5 = &pActors[v3]; - LOWORD(v3) = v5->uAIState; - if ( (short)v3 != 5 ) + v5 = &pActors[actor_id]; + v3 = v5->uAIState; + if (!(v3 == AIState::Dying || v3 == AIState::Dead || v3 == AIState::Summoned || + v3 == AIState::Disabled || v3 == AIState::Removed)) { - if ( (short)v3 != 4 && (short)v3 != 11 && (short)v3 != 19 && (short)v3 != 17 ) - { - v6 = (unsigned int *)&ai_near_actors_targets_pid[(int)v4]; - Actor::_SelectTarget((unsigned int)v4, &ai_near_actors_targets_pid[(int)v4], true); - if ( v5->pMonsterInfo.uHostilityType && !*v6 ) + + Actor::_SelectTarget(actor_id, &ai_near_actors_targets_pid[actor_id], true); + v22 = ai_near_actors_targets_pid[actor_id]; + if ( v5->pMonsterInfo.uHostilityType && !v22) v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly; - v22 = *v6; - v7 = Actor::GetDirectionInfo(PID(OBJECT_Actor,(int)v4), *v6, &a3, 0); + v7 = Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v22, &a3, 0); v8 = v5->uActorRadius; - memcpy(&a3, v7, sizeof(a3)); - memcpy(&v18, &a3, sizeof(v18)); + memcpy(&a3, v7, sizeof(AIDirection)); + memcpy(&v18, &a3, sizeof(AIDirection)); v9 = a3.uDistance - v8; v20 = a3.uDistance - v8; - if ( ((a3.uDistance - v8) & 0x80000000u) != 0 ) + if ( v20 < 0 ) { v9 = 0; v20 = 0; } + if (PID_TYPE(v22) == OBJECT_Actor) //v10 = (unsigned __int8)*(&byte_5C8D1A[89 * (pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID - 1) / 3] + (v5->pMonsterInfo.uID - 1) / 3); v10 = pFactionTable->relations[(pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID) / 3 + 1][(v5->pMonsterInfo.uID - 1) / 3 + 1]; else v10 = 4; - if ( v10 == 1 ) - { + + switch (v10) + { + case 1: if ( (double)(signed int)v20 < 307.2 ) - goto LABEL_25; - } - else + v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; + break; + case 2: + if ( v20 < 1024 ) + v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; + break; + case 3: + if ( v20 < 2560 ) + v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; + break; + case 4: + if ( v20 < 5120 ) + v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; + break; + } + + if ( v5->pMonsterInfo.uHostilityType == 4 && v22 && (signed int)v9 < 5120 ) { - if ( v10 == 2 ) + v14 = stru_50C198.special_ability_use_check(v5, actor_id); + v21->field_C = 0; + switch (v14) { - v12 = __OFSUB__(v9, 1024); - v11 = ((v9 - 1024) & 0x80000000u) != 0; + case 1: + if ( v5->pMonsterInfo.uMissleAttack2Type ) + { + Actor::AI_MissileAttack2(actor_id, v22, &v18); + v21->field_C = 1; + } + break; + case 2: + if(v5->pMonsterInfo.uSpell1ID) + { + Actor::AI_SpellAttack1(actor_id, v22, &v18); + v21->field_C = 1; + } + break; + case 3: + if(v5->pMonsterInfo.uSpell2ID) + { + Actor::AI_SpellAttack2(actor_id, v22, &v18); + v21->field_C = 1; + } + + break; + default: + if ( v5->pMonsterInfo.uMissleAttack1Type ) + { + Actor::AI_MissileAttack1(actor_id, v22, &v18); + v21->field_C = 1; + } } - else - { - if ( v10 == 3 ) + if (!v21->field_C) + if ( (double)v20 < 307.2) { - v12 = __OFSUB__(v9, 2560); - v11 = ((v9 - 2560) & 0x80000000u) != 0; + Actor::AI_MeleeAttack(actor_id, v22, &v18); + v21->field_C = 3; } else { - if ( v10 != 4 ) - goto LABEL_26; - v12 = __OFSUB__(v9, 5120); - v11 = ((v9 - 5120) & 0x80000000u) != 0; - } - } - if ( v11 ^ v12 ) - { -LABEL_25: - v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; - goto LABEL_26; - } - } -LABEL_26: - if ( v5->pMonsterInfo.uHostilityType != 4 || !v22 || (signed int)v9 >= 5120 ) - { - v13 = a2a; - goto LABEL_47; - } - v13 = a2a; - v14 = stru_50C198.special_ability_use_check(v5, a2a); - if ( v14 == 1 ) - { - if ( v5->pMonsterInfo.uMissleAttack2Type ) - { - Actor::AI_MissileAttack2(v13, v22, &v18); - goto LABEL_43; - } - } + Actor::AI_Stand(actor_id, v22, 64, &v18); + v21->field_C = 0; + } + } else { - if ( v14 > 1 && v14 <= 3 ) - { - if ( v14 == 2 ) - v15 = v5->pMonsterInfo.uSpell1ID; - else - v15 = v5->pMonsterInfo.uSpell2ID; - if ( v15 ) - { - if ( v14 == 2 ) - Actor::AI_SpellAttack1(v13, v22, &v18); - else - Actor::AI_SpellAttack2(v13, v22, &v18); - goto LABEL_43; - } - goto LABEL_44; - } - if ( v5->pMonsterInfo.uMissleAttack1Type ) - { - Actor::AI_MissileAttack1(v13, v22, &v18); -LABEL_43: - //v3 = v21; - v21->field_C = 1; -LABEL_48: - v21->uActionLength = v5->uCurrentActionLength; - //return (signed __int16)v3; - return; - } + Actor::AI_Stand(actor_id, v22, 64, &v18); + v21->field_C = 0; } -LABEL_44: - if ( (double)(signed int)v20 < 307.2 ) - { - Actor::AI_MeleeAttack(v13, v22, &v18); - //v3 = v21; - v21->field_C = 3; - goto LABEL_48; - } -LABEL_47: - Actor::AI_Stand(v13, v22, 64, &v18); - //v3 = v21; - v21->field_C = 0; - goto LABEL_48; - } - } + v21->uActionLength = v5->uCurrentActionLength; + } } } @@ -1011,11 +991,9 @@ //----- (00406B9F) -------------------------------------------------------- void stru262_TurnBased::_406B9F() { - unsigned int v5; // esi@5 Actor *v6; // ebx@5 AIDirection a3; // [sp+0h] [bp-50h]@15 AIDirection v9; // [sp+1Ch] [bp-34h]@15 - unsigned int v12; // [sp+40h] [bp-10h]@5 unsigned int v13; // [sp+44h] [bp-Ch]@8 int i; @@ -1265,87 +1243,48 @@ return 1; } -//----- (00406FA8) -------------------------------------------------------- + //----- (00406FA8) -------------------------------------------------------- void stru262_TurnBased::_406FA8() { - unsigned __int8 v1; // zf@1 - unsigned __int8 v2; // sf@1 - TurnBased_QueueElem *v3; // edi@2 - int v4; // eax@4 - Actor *v5; // ebx@4 - unsigned __int16 v6; // cx@4 - unsigned int *v7; // edx@8 - unsigned int v8; // esi@8 - unsigned __int8 v9; // of@13 + Actor *curr_acror; // ebx@4 AIDirection a3; // [sp+Ch] [bp-6Ch]@8 - AIDirection v11; // [sp+28h] [bp-50h]@8 + AIDirection v9; // [sp+28h] [bp-50h]@8 AIDirection a4; // [sp+44h] [bp-34h]@8 - stru262_TurnBased *v13; // [sp+60h] [bp-18h]@1 - TurnBased_QueueElem *v14; // [sp+64h] [bp-14h]@2 + unsigned int target_pid; // [sp+60h] [bp-18h]@1 int uActorID; // [sp+68h] [bp-10h]@4 - unsigned int a2; // [sp+6Ch] [bp-Ch]@8 - int v17; // [sp+70h] [bp-8h]@1 - unsigned int v18; // [sp+74h] [bp-4h]@2 + int i; - v17 = 0; - v1 = this->uActorQueueSize == 0; - v2 = this->uActorQueueSize < 0; - v13 = this; - if ( !(v2 | v1) ) + for (i=0; i<uActorQueueSize; ++i ) { - v3 = this->pQueue; - v18 = (char *)&pTurnEngine - (char *)this; - v14 = this->pQueue; - do + if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) { - if (PID_TYPE(v3->uPackedID) != OBJECT_Player) - { - v4 = PID_ID(v3->uPackedID); - uActorID = v4; - v5 = &pActors[v4]; - v6 = v5->uAIState; - if ( v6 != 5 ) // Dead + uActorID=PID_ID(pQueue[i].uPackedID); + curr_acror = &pActors[uActorID]; + if ( !( curr_acror->uAIState == AIState::Summoned|| curr_acror->uAIState == AIState::Dead || + curr_acror->uAIState == AIState::Removed || curr_acror->uAIState == AIState::Disabled) ) + { + target_pid = ai_near_actors_targets_pid[uActorID]; + Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true); + memcpy(&v9, Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &a3, 0), sizeof(AIDirection)); + memcpy(&a4, &v9, sizeof(AIDirection)); + curr_acror->uCurrentActionTime += pEventTimer->uTimeElapsed; + if ( curr_acror->uCurrentActionTime > curr_acror->uCurrentActionLength ) { - if ( v6 != 11 )// Removed + if ( curr_acror->uAIState == AIState::Dying ) { - if ( v6 != 19 ) //Disabled - { - if ( v6 != 17 ) //Summoned - { - v7 = (unsigned int *)&ai_near_actors_targets_pid[v4]; - a2 = *v7; - v8 = a2; - Actor::_SelectTarget(v4, (int *)v7, true); - memcpy(&v11, Actor::GetDirectionInfo(*(int *)((char *)&v3->uPackedID + v18), v8, &a3, 0), sizeof(AIDirection)); - memcpy(&a4, &v11, sizeof(AIDirection)); - v5->uCurrentActionTime += pMiscTimer->uTimeElapsed; - if ( (signed int)v5->uCurrentActionTime >= v5->uCurrentActionLength ) - { - if (v5->uAIState == Dying) - { - v5->uCurrentActionTime = 0; - v5->uCurrentActionLength = 0; - v5->uAIState = Dead; - v5->UpdateAnimation(); - return; - } - if ( rand() % 2 ) - Actor::AI_Stand(uActorID, a2, 64, &a4); - else - Actor::AI_Bored(uActorID, a2, &a4); - } - } - } + curr_acror->uCurrentActionTime = 0; + curr_acror->uCurrentActionLength = 0; + curr_acror->uAIState = AIState::Dead; + curr_acror->UpdateAnimation(); + break; } + if ( rand() % 2 ) + Actor::AI_Stand(uActorID, target_pid, 64, &a4); + else + Actor::AI_Bored(uActorID, target_pid, &a4); } } - ++v17; - v3 = v14 + 1; - v9 = __OFSUB__(v17, v13->uActorQueueSize); - v2 = v17 - v13->uActorQueueSize < 0; - ++v14; } - while ( v2 ^ v9 ); } }
--- a/TurnEngine.h Mon Jul 15 23:59:04 2013 +0200 +++ b/TurnEngine.h Tue Jul 16 00:00:05 2013 +0200 @@ -56,7 +56,7 @@ void _40652A(); void _4065B0(); void AIRangedAttacks(unsigned int queue_index); - void _40680F(int a2); + void _40680F(int queue_index); void _406A63(); void _406AFE(); void _406B9F();
--- a/mm7_4.cpp Mon Jul 15 23:59:04 2013 +0200 +++ b/mm7_4.cpp Tue Jul 16 00:00:05 2013 +0200 @@ -3497,7 +3497,7 @@ result = GetPortalScreenCoord(sFaceID); if ( result ) { - result = sub_424829(result, &stru_F8A590, pBLVRenderParams->field_7C, v2); + result = PortalFrustrum(result, &stru_F8A590, pBLVRenderParams->field_7C, v2); if ( result ) { result = (int)v3->GetTexture(); @@ -3962,7 +3962,7 @@ v59 = GetPortalScreenCoord(uFaceID); v3 = v59; } - if ( v3 && (pRenderer->pRenderD3D || sub_424829(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1)) ) + if ( v3 && (pRenderer->pRenderD3D || PortalFrustrum(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1)) ) { v4 = v2->GetTexture(); v5 = 0;
--- a/mm7_data.h Mon Jul 15 23:59:04 2013 +0200 +++ b/mm7_data.h Tue Jul 16 00:00:05 2013 +0200 @@ -1151,7 +1151,7 @@ void __cdecl sub_423B4A(); int __fastcall GetPortalScreenCoord(unsigned int uFaceID); signed int __fastcall sub_424579(int uFaceID, struct stru320 *a2); -bool sub_424829(int pNumVertices, struct BspRenderer_stru2 *a2, struct BspRenderer_stru2 *a3, int uFaceID); +bool PortalFrustrum(int pNumVertices, struct BspRenderer_stru2 *a2, struct BspRenderer_stru2 *a3, int uFaceID); signed int __fastcall sr_424CD7(unsigned int uVertexID); // idb signed int __fastcall sr_424EE0_MakeFanFromTriangle(unsigned int uVertexID); // idb signed int __fastcall sr_4250FE(unsigned int uVertexID); // idb