view Viewport.cpp @ 706:d6236f6a9882

Rough function rearranging to new files
author Gloval
date Tue, 19 Mar 2013 21:53:21 +0400
parents e0a1fccc89b1
children a5e587c8e30e
line wrap: on
line source

#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->uScreenHeight = br_y - tl_y + 1;
    this->uScreenCenterX = (signed int)(br_x + tl_x) /2;
    if ( pRenderer->pRenderD3D == 0 )
        this->uScreenCenterY = this->uScreen_BR_Y - ((unsigned __int64)(this->field_30 * (signed __int64)(uScreenHeight)) >> 16);
    else
        this->uScreenCenterY = uScreenHeight/2;
    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 sTL_X, signed int sTL_Y, signed int sBR_X, signed int sBR_Y )
    {
    signed int tl_x; // ebx@1
    signed int tl_y; // edi@3
    signed int br_x; // edx@5
    signed int br_y; // eax@7

    tl_x = sTL_X;
    if ( sTL_X < this->uScreen_TL_X )
        tl_x = this->uScreen_TL_X;
    tl_y = sTL_Y;
    if ( sTL_Y < this->uScreen_TL_Y )
        tl_y = this->uScreen_TL_Y;
    br_x = sBR_X;
    if ( sBR_X > this->uScreen_BR_X )
        br_x = this->uScreen_BR_X;
    br_y = sBR_Y;
    if ( sBR_Y > this->uScreen_BR_Y )
        br_y = this->uScreen_BR_Y;
    this->uViewportTL_Y = tl_y;
    this->uViewportTL_X = tl_x;
    this->uViewportBR_X = br_x;
    this->uViewportBR_Y = br_y;
    }

//----- (00443219) --------------------------------------------------------
 void ViewingParams::_443219()
    {
    this->sViewCenterY += 512;
    AdjustPosition();
    }

//----- (00443225) --------------------------------------------------------
void ViewingParams::_443225()
    {
    this->sViewCenterX -= 512;
    AdjustPosition();
    }

//----- (00443231) --------------------------------------------------------
void ViewingParams::_443231()
    {
    this->sViewCenterY -= 512;
    AdjustPosition();
    }

//----- (0044323D) --------------------------------------------------------
void ViewingParams::_44323D()
    {
    this->sViewCenterX += 512;
    AdjustPosition();
    }

//----- (00443249) --------------------------------------------------------
void ViewingParams::CenterOnParty()
    {
    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->sViewCenterX = pParty->vPosition.x;
    this->sViewCenterY = pParty->vPosition.y;
    AdjustPosition();
    }

//----- (00443291) --------------------------------------------------------
void ViewingParams::CenterOnParty2()
    {
    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->sViewCenterX = pParty->vPosition.x;
    this->sViewCenterY = pParty->vPosition.y;
    AdjustPosition();
    }

//----- (004432E7) --------------------------------------------------------
void ViewingParams::AdjustPosition()
    {
    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


    v1 = this;
    v2 = this->field_3A;
    v3 = 88 >> this->field_2C / 384;
    v4 = (44 - v3) << 9;
    if ( v1->sViewCenterY > v2 + v4 )
        v1->sViewCenterY = v2 + v4;

    v5 = v1->field_38;
    v6 = (v3 - 44) << 9;
    if ( v1->sViewCenterX < v5 + v6 )
        v1->sViewCenterX = v5 + v6;

    v7 = v2 + v6;
    if ( v1->sViewCenterY < v7 )
        v1->sViewCenterY = v7;

    if ( v1->sViewCenterX > v5 + v4 )
        v1->sViewCenterX = v5 + v4;
    }

//----- (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;
    }