diff Viewport.cpp @ 692:066e2b29b30f

viewport.cpp added
author Gloval
date Sat, 16 Mar 2013 21:57:32 +0400
parents
children e0a1fccc89b1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Viewport.cpp	Sat Mar 16 21:57:32 2013 +0400
@@ -0,0 +1,264 @@
+#include "Viewport.h"
+
+#include "Party.h"
+#include "VectorTypes.h"
+#include "Indoor.h"
+#include "Render.h"
+#include "mm7_data.h"
+
+
+//----- (004C0262) --------------------------------------------------------
+void Viewport::SetScreen( signed int sTL_X, signed int sTL_Y, signed int sBR_X, signed int sBR_Y )
+    {
+    unsigned int tl_x; // edx@1
+    unsigned int br_x; // esi@1
+    unsigned int tl_y; // edi@3
+    unsigned int br_y; // eax@3
+    int v10; // eax@7
+
+    tl_x = sTL_X;
+    br_x = sBR_X;
+    if ( sTL_X > sBR_X )
+        {
+        br_x = sBR_X ^ sTL_X ^ sBR_X;                           // swap x's
+        tl_x = br_x ^ sBR_X ^ sTL_X;
+        }
+    tl_y = sTL_Y;
+    br_y = sBR_Y;
+    if ( (signed int)sTL_Y > (signed int)sBR_Y )
+        {
+        br_y = sBR_Y ^ sTL_Y ^ sBR_Y;                           // swap y's 
+        tl_y = br_y ^ sBR_Y ^ sTL_Y;
+        }
+    this->uScreen_TL_X = tl_x;
+    this->uScreen_TL_Y = tl_y;
+    this->uScreen_BR_X = br_x;
+    this->uScreen_BR_Y = br_y;
+    this->uScreenWidth = br_x - tl_x + 1;
+    this->uScreenCenterX = (signed int)(br_x + tl_x) >> 1;
+    if ( pRenderer->pRenderD3D == 0 )
+        {
+        this->uScreenHeight = br_y - tl_y + 1;
+        this->uScreenCenterY = this->uScreen_BR_Y - ((unsigned __int64)(this->field_30 * (signed __int64)(br_y - tl_y + 1)) >> 16);
+        }
+    else
+        {
+        this->uScreenHeight = br_y - tl_y + 1;
+        this->uScreenCenterY = (signed int)(br_y + tl_y) >> 1;
+        }
+    SetViewport(this->uScreen_TL_X, this->uScreen_TL_Y, this->uScreen_BR_X, this->uScreen_BR_Y);
+    }
+
+//----- (004C02F8) --------------------------------------------------------
+void Viewport::_4C02F8(int a2)
+    {
+    this->field_30 = a2;
+    SetScreen(this->uScreen_TL_X, this->uScreen_TL_Y, this->uScreen_BR_X, this->uScreen_BR_Y);
+    }
+
+//----- (004C0312) --------------------------------------------------------
+void Viewport::SetViewport( signed int uX, signed int uY, signed int uZ, signed int uW )
+    {
+    unsigned int x; // ebx@1
+    unsigned int y; // edi@3
+    unsigned int z; // edx@5
+    unsigned int w; // eax@7
+
+    x = uX;
+    if ( uX < this->uScreen_TL_X )
+        x = this->uScreen_TL_X;
+    y = uY;
+    if ( uY < this->uScreen_TL_Y )
+        y = this->uScreen_TL_Y;
+    z = uZ;
+    if ( uZ > this->uScreen_BR_X )
+        z = this->uScreen_BR_X;
+    w = uW;
+    if ( uW > this->uScreen_BR_Y )
+        w = this->uScreen_BR_Y;
+    this->uViewportY = y;
+    this->uViewportX = x;
+    this->uViewportZ = z;
+    this->uViewportW = w;
+    }
+
+//----- (00443219) --------------------------------------------------------
+ void ViewingParams::_443219()
+    {
+    this->sPartyPosZ += 512;
+    _4432E7();
+    }
+
+//----- (00443225) --------------------------------------------------------
+void ViewingParams::_443225()
+    {
+    this->sPartyPosX -= 512;
+    _4432E7();
+    }
+
+//----- (00443231) --------------------------------------------------------
+void ViewingParams::_443231()
+    {
+    this->sPartyPosZ -= 512;
+    _4432E7();
+    }
+
+//----- (0044323D) --------------------------------------------------------
+void ViewingParams::_44323D()
+    {
+    this->sPartyPosX += 512;
+    _4432E7();
+    }
+
+//----- (00443249) --------------------------------------------------------
+void ViewingParams::_443249()
+    {
+    int v1; // edx@1
+
+    v1 = (unsigned __int64)((signed __int64)this->field_2C << 15) >> 16;
+    this->field_2C = v1;
+    if ( v1 < 384 )
+        this->field_2C = 384;
+    this->sPartyPosX = pParty->vPosition.x;
+    this->sPartyPosZ = pParty->vPosition.y;
+    _4432E7();
+    }
+
+//----- (00443291) --------------------------------------------------------
+void ViewingParams::_443291()
+    {
+    int v1; // edx@1
+    int v2; // eax@1
+
+    v1 = 2 * this->field_2C;
+    v2 = 1536;
+    this->field_2C = v1;
+    if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
+        v2 = 3072;
+    if ( v1 > v2 )
+        this->field_2C = v2;
+    this->sPartyPosX = pParty->vPosition.x;
+    this->sPartyPosZ = pParty->vPosition.y;
+    _4432E7();
+    }
+
+//----- (004432E7) --------------------------------------------------------
+void ViewingParams::_4432E7()
+    {
+    ViewingParams *v1; // esi@1
+    int v2; // ebx@1
+    signed int v3; // edx@1
+    int v4; // ecx@1
+    int v5; // edi@3
+    int v6; // eax@3
+    int v7; // eax@5
+    int result; // eax@7
+
+    v1 = this;
+    v2 = this->field_3A;
+    v3 = 88 >> this->field_2C / 384;
+    v4 = (44 - v3) << 9;
+    if ( v1->sPartyPosZ > v2 + v4 )
+        v1->sPartyPosZ = v2 + v4;
+
+    v5 = v1->field_38;
+    v6 = (v3 - 44) << 9;
+    if ( v1->sPartyPosX < v5 + v6 )
+        v1->sPartyPosX = v5 + v6;
+
+    v7 = v2 + v6;
+    if ( v1->sPartyPosZ < v7 )
+        v1->sPartyPosZ = v7;
+
+    result = v5 + v4;
+    if ( v1->sPartyPosX > v5 + v4 )
+        v1->sPartyPosX = result;
+    }
+
+//----- (00443343) --------------------------------------------------------
+void ViewingParams::InitGrayPalette()
+    {
+    for  (unsigned short i=0; i<256; ++i)
+        pPalette[i]=GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(i, i, i);
+    }
+
+//----- (00443365) --------------------------------------------------------
+void ViewingParams::_443365()
+    {
+    ViewingParams *v1; // esi@1
+    __int16 *v2; // edi@3
+    Vec3_short_ *v3; // eax@4
+    unsigned int v4; // edx@4
+    signed int v5; // eax@8
+    Vec3_short_ *v6; // eax@12
+    signed int v7; // edi@12
+    signed int v8; // eax@16
+    char v9; // zf@20
+    int result; // eax@21
+    unsigned int v11; // [sp+4h] [bp-1Ch]@3
+    unsigned int *v12; // [sp+8h] [bp-18h]@3
+    unsigned int v13; // [sp+Ch] [bp-14h]@8
+    unsigned int v14; // [sp+10h] [bp-10h]@2
+    unsigned int v15; // [sp+14h] [bp-Ch]@2
+    unsigned int v16; // [sp+18h] [bp-8h]@2
+    unsigned int v17; // [sp+1Ch] [bp-4h]@2
+
+    v1 = this;
+    InitGrayPalette();
+    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+        {
+        v16 = 0x40000000u;
+        v14 = 0x40000000u;
+        v17 = 0xC0000000u;
+        v15 = 0xC0000000u;
+        if ( (signed int)pIndoor->pMapOutlines->uNumOutlines > 0 )
+            {
+            v2 = (__int16 *)(pIndoor->pMapOutlines->pOutlines);
+            v11 = pIndoor->pMapOutlines->uNumOutlines;
+            v12 = (uint *)pIndoor->pMapOutlines->pOutlines;
+            do
+                {
+                v3 = &pIndoor->pVertices[*v2];
+                v4 = v3->x;
+                if ( (signed int)v4 < (signed int)v16 )
+                    v16 = v3->x;
+                if ( (signed int)v4 > (signed int)v17 )
+                    v17 = v3->x;
+                v5 = v3->y;
+                v13 = v5;
+                if ( v5 < (signed int)v14 )
+                    v14 = v4;
+                if ( v5 > (signed int)v15 )
+                    v15 = v4;
+                v6 = &pIndoor->pVertices[v2[1]];
+                v7 = v6->x;
+                if ( v7 < (signed int)v16 )
+                    v16 = v4;
+                if ( v7 > (signed int)v17 )
+                    v17 = v4;
+                v8 = v6->y;
+                if ( v8 < (signed int)v14 )
+                    v14 = v13;
+                if ( v8 > (signed int)v15 )
+                    v15 = v13;
+                v2 = (__int16 *)(v12 + 3);
+                v9 = v11-- == 1;
+                v12 += 3;
+                }
+                while ( !v9 );
+            }
+        v1->uMinimapZoom = 1024;
+        v1->field_38 = (signed int)(v16 + v17) / 2;
+        v1->field_28 = 10;
+        result = (signed int)(v14 + v15) / 2;
+        v1->field_3A = result;
+        }
+    else
+        {
+        v1->field_38 = 0;
+        v1->field_3A = 0;
+        v1->uMinimapZoom = dword_576E2C;
+        v1->field_28 = dword_576E28;
+        }
+    v1->field_2C = 384;
+    }
\ No newline at end of file