Mercurial > mm7
changeset 2193:4842f58715ea
sub_47C3D7_get_fog_related_stuff to sub_47C3D7_get_fog_specular cleanup, IsTerrainSlopeTooHigh restoring commented out min,min/max,max implementation, some small changes in OnMapLoad, sub_4465DF_check_season attempted to pick the best readabilty/maintainability tradeoff
author | Grumpy7 |
---|---|
date | Thu, 30 Jan 2014 22:09:10 +0100 |
parents | 0ae56373cc35 |
children | d0e321190c86 |
files | Render.cpp mm7_3.cpp mm7_unsorted_subs.h |
diffstat | 3 files changed, 79 insertions(+), 244 deletions(-) [+] |
line wrap: on
line diff
--- a/Render.cpp Tue Jan 28 22:41:49 2014 +0600 +++ b/Render.cpp Thu Jan 30 22:09:10 2014 +0100 @@ -1917,7 +1917,7 @@ if ( this->bUsingSpecular ) { - d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_related_stuff(0, 0, array_50AC10[i].vWorldViewPosition.x); + d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_specular(0, 0, array_50AC10[i].vWorldViewPosition.x); } else { @@ -1958,7 +1958,7 @@ d3d_vertex_buffer[i].diffuse = GetActorTintColor(a3->dimming_level, 0, array_50AC10[i].vWorldViewPosition.x, 0, 0); if ( this->bUsingSpecular ) { - d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_related_stuff(0, 0, array_50AC10[i].vWorldViewPosition.x); + d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_specular(0, 0, array_50AC10[i].vWorldViewPosition.x); } else { @@ -4691,7 +4691,7 @@ d3d_vertex_buffer[i].diffuse = ::GetActorTintColor(a4->dimming_level, 0, array_50AC10[i].vWorldViewPosition.x, 0, 0); if ( this->bUsingSpecular ) { - d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_related_stuff(0, 0, array_50AC10[i].vWorldViewPosition.x); + d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_specular(0, 0, array_50AC10[i].vWorldViewPosition.x); } else { @@ -4722,7 +4722,7 @@ d3d_vertex_buffer[i].diffuse = GetActorTintColor(a4->dimming_level, 0, array_50AC10[i].vWorldViewPosition.x, 0, 0); if ( this->bUsingSpecular ) { - d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_related_stuff(0, 0, array_50AC10[i].vWorldViewPosition.x); + d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_specular(0, 0, array_50AC10[i].vWorldViewPosition.x); } else { @@ -4830,7 +4830,7 @@ pVertices[i].diffuse = ::GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, 1, 0); v7 = 0; if (this->bUsingSpecular) - v7 = sub_47C3D7_get_fog_related_stuff(0, 1, array_50AC10[i].vWorldViewPosition.x); + v7 = sub_47C3D7_get_fog_specular(0, 1, array_50AC10[i].vWorldViewPosition.x); pVertices[i].specular = v7; pVertices[i].texcoord.x = array_50AC10[i].u; pVertices[i].texcoord.y = array_50AC10[i].v; @@ -5938,7 +5938,7 @@ unsigned int specular = 0; if (bUsingSpecular) - specular = sub_47C3D7_get_fog_related_stuff(0, 0, a2->zbuffer_depth); + specular = sub_47C3D7_get_fog_specular(0, 0, a2->zbuffer_depth); v14 = (double)((int)pSprite->uBufferWidth / 2 - pSprite->uAreaX); v15 = (double)((int)pSprite->uBufferHeight - pSprite->uAreaY);
--- a/mm7_3.cpp Tue Jan 28 22:41:49 2014 +0600 +++ b/mm7_3.cpp Thu Jan 30 22:09:10 2014 +0100 @@ -2818,9 +2818,8 @@ } //----- (0047C3D7) -------------------------------------------------------- -int __fastcall sub_47C3D7_get_fog_related_stuff(int a1, int a2, float a3) +int __fastcall sub_47C3D7_get_fog_specular(int a1, int a2, float a3) { - int v3; // ecx@1 double v5; // st7@10 signed int v7; // ecx@11 double v8; // st6@12 @@ -2829,85 +2828,35 @@ float v11; // ST14_4@17 double v12; // ST08_8@17 - v3 = pWeather->bNight; - if ( bUnderwater == 1 ) - v3 = 0; if ( pParty->armageddon_timer || !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater ) return 0xFF000000; - if ( v3 ) + if ( a3 == 0.0 ) + return (-1 - 216) << 24; + if ( a2 ) + return (-1 - 248) << 24; + if (a3 < (double)day_fogrange_1) + return -1 << 24; + if (a3 < (double)day_fogrange_2) + return (-1 - 216) << 24; + + if ( pWeather->bNight && !bUnderwater) { v5 = (double)day_fogrange_1; - if ( a3 < v5 ) - { - v7 = 0; - if ( a3 == 0.0 ) - { - v7 = 216; - } - goto LABEL_21; - } - else - { - v8 = (double)day_fogrange_2; - if ( a3 > v8 ) - { - v7 = 216; - if ( a3 == 0.0 ) - { - v7 = 216; - } - goto LABEL_21; - } - v7 = (signed __int64)((a3 - v5) / (v8 - v5) * 216.0); - } + v8 = (double)day_fogrange_2; + v7 = (signed __int64)((a3 - v5) / (v8 - v5) * 216.0); } else { v9 = (double)day_fogrange_1; - if ( a3 < v9 ) - { - v7 = 0; - if ( a3 == 0.0 ) - { - v7 = 216; - } - goto LABEL_21; - } - else - { - v10 = (double)day_fogrange_2; - if ( a3 > v10 ) - { - v7 = 216; - if ( a3 == 0.0 ) - { - v7 = 216; - } - goto LABEL_21; - } - else - { - v11 = (a3 - v9) * 216.0 / (v10 - v9); - v12 = v11 + 6.7553994e15; - v7 = LODWORD(v12); - } - } + v10 = (double)day_fogrange_2; + v11 = (a3 - v9) * 216.0 / (v10 - v9); + v7 = bankersRounding(v11); } if ( v7 > 216 ) { v7 = 216; } - else - { - if ( a3 == 0.0 ) - { - v7 = 216; - } - } -LABEL_21: - if ( a2 ) - v7 = 248; - return (-1 - v7) << 24; + return ( -1 - v7) << 24; } //----- (0047C4FC) -------------------------------------------------------- @@ -3106,7 +3055,7 @@ //int v7; // ecx@6 //int v8; // edx@6 //int v9; // eax@6 - int y_min; // esi@10 + //int y_min; // esi@10 //int v11; // [sp+14h] [bp-8h]@1 //int v12; // [sp+18h] [bp-4h]@1 @@ -3156,56 +3105,9 @@ y3 */ } - //int y_min = min(y1, min(y2, y3)),// не верно при подъёме на склон - //y_max = max(y1, max(y2, y3)); - //return (y_max - y_min) > 512; - - if ( y1 >= y2 ) - { - y_min = y2; - if ( y2 < y3 ) - { - if ( y1 <= y2 ) - { - if ( y2 > y3 ) - y3 = y2; - } - else - { - if ( y1 > y3 ) - y3 = y1; - } - return y3 - y_min > 512; - } - y_min = y3; - if ( y1 <= y2 ) - { - if ( y2 > y3 ) - y3 = y2; - } - else - { - if ( y1 > y3 ) - y3 = y1; - } - return y3 - y_min > 512; - } - else if ( y1 >= y3 ) - y_min = y3; - else - y_min = y1; - - if ( y1 <= y2 ) - { - if ( y2 > y3 ) - y3 = y2; - } - else - { - if ( y1 > y3 ) - y3 = y1; - } - return y3 - y_min > 512; + int y_min = min(y1, min(y2, y3));// не верно при подъёме на склон + int y_max = max(y1, max(y2, y3)); + return (y_max - y_min) > 512; } //----- (0048257A) -------------------------------------------------------- @@ -3788,30 +3690,27 @@ void OnMapLoad() { __int16 v4; // cx@9 - __int16 v5; // di@9 int v6; // eax@9 - signed __int64 v8; // qax@26 + unsigned __int64 v8; // qax@26 unsigned int v9; // ecx@26 - signed __int64 v10; // qax@26 - signed __int64 v11; // qax@26 - int v12; // ST50_4@26 - signed __int64 v13; // qax@26 - signed __int64 v14; // qax@26 + unsigned __int64 v10; // qax@26 + unsigned __int64 v11; // qax@26 + unsigned __int64 v13; // qax@26 + unsigned __int64 v14; // qax@26 int v15; // ST58_4@26 - signed __int64 v16; // qax@26 + unsigned __int64 v16; // qax@26 int hours; // ebx@26 unsigned __int64 v18; // [sp+Ch] [bp-44h]@12 - signed __int64 seconds; // [sp+14h] [bp-3Ch]@26 + unsigned int seconds; // [sp+14h] [bp-3Ch]@26 unsigned __int64 v20; // [sp+1Ch] [bp-34h]@7 - int minutes; // [sp+2Ch] [bp-24h]@26 - int years; // [sp+34h] [bp-1Ch]@26 - int weeks; // [sp+38h] [bp-18h]@26 + unsigned int minutes; // [sp+2Ch] [bp-24h]@26 + unsigned int years; // [sp+34h] [bp-1Ch]@26 + unsigned int weeks; // [sp+38h] [bp-18h]@26 int v26; // [sp+3Ch] [bp-14h]@15 - int days; // [sp+3Ch] [bp-14h]@26 - int months; // [sp+40h] [bp-10h]@26 + unsigned int days; // [sp+3Ch] [bp-14h]@26 + unsigned int months; // [sp+40h] [bp-10h]@26 __int16 v29; // [sp+46h] [bp-Ah]@9 __int16 v30; // [sp+48h] [bp-8h]@9 - __int16 v31; // [sp+4Ah] [bp-6h]@9 __int16 v32; // [sp+4Ch] [bp-4h]@9 __int16 v33; // [sp+4Eh] [bp-2h]@9 @@ -3853,19 +3752,11 @@ if ( v20 ) v18 = pParty->uTimePlayed - v20; else - v18 = 0i64; + v18 = 0; v26 = (signed int)(signed __int64)((double)(signed __int64)v18 * 0.234375) / 60 / 60 / 24; - if ( v26 / 7 / 4 / 12 ) - { - if ( array_5B5928_timers[dword_5B65C8_timers_count].field_10 ) - { - ++dword_5B65C8_timers_count; - array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = 0; - continue; - } - } - if (v26 / 7 / 4 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_12 != 0 || + if ( v26 / 7 / 4 / 12 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_10 || + v26 / 7 / 4 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_12 != 0 || v26 / 7 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_14 != 0 || v26 != 0 || !v20) { @@ -3876,55 +3767,40 @@ } else { - v8 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375); - v9 = v8; - v10 = (signed int)v8 / 60; + v8 = (__int64)((double)pParty->uTimePlayed * 0.234375); + seconds = v8 % 60; + v10 = v8 / 60; minutes = v10 % 60; - v11 = (signed int)(v10 / 60); - v12 = v11 % 24; - v13 = (signed int)(v11 / 24); + v11 = v10 / 60; + hours = v11 % 24; + v13 = v11 / 24; days = v13 % 7; - v14 = (signed int)(v13 / 7); - v15 = v14 % 4; - v16 = (signed int)(v14 / 4); + v14 = v13 / 7; + weeks = v14 % 4; + v16 = v14 / 4; + months = v16 % 12; years = v16 / 12; - unsigned __int64 _1 = (unsigned __int64)((double)pParty->uTimePlayed * 0.234375) >> 32; - __int64 _2 = ((__int64)v9 << 32) | _1; - - seconds = _2 % 60; - //v19 = (signed __int64)__PAIR__((unsigned __int64)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) >> 32, - // v9) - // % 60; - - hours = v12; - weeks = v15; - months = v16 % 12; if ( array_5B5928_timers[dword_5B65C8_timers_count].field_10 ) ++years; + else if ( array_5B5928_timers[dword_5B65C8_timers_count].field_12 ) + ++months; + else if ( array_5B5928_timers[dword_5B65C8_timers_count].field_14 ) + ++weeks; else { - if ( array_5B5928_timers[dword_5B65C8_timers_count].field_12 ) - ++months; - else - { - if ( array_5B5928_timers[dword_5B65C8_timers_count].field_14 ) - ++weeks; - else - { - ++days; - minutes = array_5B5928_timers[dword_5B65C8_timers_count].field_18; - hours = array_5B5928_timers[dword_5B65C8_timers_count].field_16; - seconds = array_5B5928_timers[dword_5B65C8_timers_count].field_1A; - } - } + ++days; + minutes = array_5B5928_timers[dword_5B65C8_timers_count].field_18; + hours = array_5B5928_timers[dword_5B65C8_timers_count].field_16; + seconds = array_5B5928_timers[dword_5B65C8_timers_count].field_1A; } array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = (signed __int64)((double)((seconds + 60 * minutes + 3600 * hours - + 0x93A80 * weeks - + 0x15180 * days - + 0x24EA00 * (months + 12i64 * years)) << 7) + + 86400 * days + + 604800 * weeks + + 2419200 * months + + 29030400 * years) << 7) * 0.033333335); ++dword_5B65C8_timers_count; @@ -4002,69 +3878,28 @@ //----- (004465DF) -------------------------------------------------------- bool sub_4465DF_check_season(int a1) { - unsigned int v1; // eax@1 - unsigned int v2; // edx@1 - int v3; // ecx@2 - int v4; // ecx@3 - char v6; // zf@9 - - v1 = pParty->uCurrentMonth + 1; - v2 = pParty->uDaysPlayed + 1; - if ((v1 == (a1 + 1) * 3 && v2 >= 21) || v1 == (a1 + 1) % 4 * 3 + 1 || v1 == (a1 + 1) % 4 * 3 + 2 || (v1 == (a1 + 2) % 4 * 3 && v2 < 21)) - return true; - return false; + unsigned int monthPlusOne; // eax@1 + unsigned int daysPlusOne; // edx@1 + + monthPlusOne = pParty->uCurrentMonth + 1; + daysPlusOne = pParty->uDaysPlayed + 1; switch (a1) { - case 3: - if (v1 != 12)//12.21 -> 3.20 - { - if ((signed int)v1 >= 1 && (signed int)v1 <= 2) - return true; - v6 = v1 == 3; - if (!v6 || (signed int)v2 >= 21) - return false; - return true; - } + case 3: //winter 12.21 -> 3.20 + return (monthPlusOne == 12 && daysPlusOne >= 21 || monthPlusOne == 1 || monthPlusOne == 2 || monthPlusOne == 3 && daysPlusOne <= 20); break; - case 2: - if (v1 != 9)//9.21 -> 12.20 - { - if ((signed int)v1 >= 10 && (signed int)v1 <= 11) - return true; - v6 = v1 == 12; - if (!v6 || (signed int)v2 >= 21) - return false; - return true; - } + case 2:// autumn/fall 9.21 -> 12.20 + return (monthPlusOne == 9 && daysPlusOne >= 21 || monthPlusOne == 10 || monthPlusOne == 11 || monthPlusOne == 12 && daysPlusOne <= 20); break; - case 1: - if (v1 != 6)//6.21 -> 9.20 - { - if ((signed int)v1 >= 7 && (signed int)v1 <= 8) - return true; - v6 = v1 == 9; - if (!v6 || (signed int)v2 >= 21) - return false; - return true; - } + case 1://summer 6.21 -> 9.20 + return (monthPlusOne == 6 && daysPlusOne >= 21 || monthPlusOne == 7 || monthPlusOne == 8 || monthPlusOne == 9 && daysPlusOne <= 20); break; - case 0: - if (v1 != 3)//3.21 -> 9.20 - { - if ((signed int)v1 >= 4 && (signed int)v1 <= 5) - return true; - v6 = v1 == 6; - if (!v6 || (signed int)v2 >= 21) - return false; - return true; - } + case 0: //spring 3.21 -> 6.20 + return (monthPlusOne == 3 && daysPlusOne >= 21 || monthPlusOne == 4 || monthPlusOne == 5 || monthPlusOne == 6 && daysPlusOne <= 20); break; - default: - return false; } - if ( (signed int)v2 >= 21 ) - return true; + Error("Unknown season"); return false; }
--- a/mm7_unsorted_subs.h Tue Jan 28 22:41:49 2014 +0600 +++ b/mm7_unsorted_subs.h Thu Jan 30 22:09:10 2014 +0100 @@ -180,7 +180,7 @@ bool __fastcall IsBModelVisible(unsigned int uModelID, int *unused); void ODM_LoadAndInitialize(const char *pLevelFilename, struct ODMRenderParams *thisa); unsigned int GetLevelFogColor(); -int __fastcall sub_47C3D7_get_fog_related_stuff(int a1, int a2, float a3); +int __fastcall sub_47C3D7_get_fog_specular(int a1, int a2, float a3); int __fastcall GetActorTintColor(int max_dim, int min_dim, float distance, int a4, struct RenderBillboard *a5); unsigned int WorldPosToGridCellX(int); // weak unsigned int WorldPosToGridCellZ(int); // weak