view Viewport.cpp @ 937:ae747684f644

stru279 removed.
author Nomad
date Wed, 01 May 2013 12:45:02 +0200
parents 710cf848ad24
children c0d0656aa662
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

    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 ( sTL_Y > 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 - fixpoint_sub0(field_30, uScreenHeight);
    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->indoor_center_y;
    v3 = 88 >> this->field_2C / 384;
    v4 = (44 - v3) << 9;
    if ( v1->sViewCenterY > v2 + v4 )
        v1->sViewCenterY = v2 + v4;

    v5 = v1->indoor_center_x;
    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()
    {
  
    Vec3_short_ *v3; // eax@4
    Vec3_short_ *v6; // eax@12
    int minimum_y; // [sp+10h] [bp-10h]@2
    int maximum_y; // [sp+14h] [bp-Ch]@2
    int minimum_x; // [sp+18h] [bp-8h]@2
     int maximum_x; // [sp+1Ch] [bp-4h]@2

 
    InitGrayPalette();
    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
        {
        minimum_x = 0x40000000;
        minimum_y = 0x40000000;

        maximum_x = -0x40000000;
        maximum_y = -0x40000000;
        for (int i=0; i<pIndoor->pMapOutlines->uNumOutlines; ++i)
            {
            v3 = &pIndoor->pVertices[pIndoor->pMapOutlines->pOutlines[i].uFace1ID];

            if ( v3->x < minimum_x )
                minimum_x = v3->x;
            if ( v3->x > maximum_x )
                maximum_x = v3->x;
            if ( v3->y < minimum_y )
                minimum_y = v3->x;
            if ( v3->y > maximum_y )
                maximum_y = v3->x;

            v6 = &pIndoor->pVertices[pIndoor->pMapOutlines->pOutlines[i].uFace2ID];

            if ( v6->x < minimum_x )
                minimum_x = v3->x;
            if ( v6->x > maximum_x )
                maximum_x = v3->x;
 
            if ( v6->y < minimum_y )
                minimum_y = v3->y;
            if ( v6->y > maximum_y )
                maximum_y = v3->y;
            }

        uMinimapZoom = 1024;
        indoor_center_x = (signed int)(minimum_x + maximum_x) / 2;
        field_28 = 10;
        indoor_center_y = (signed int)(minimum_y + maximum_y) / 2;
        }
    else
        {
        indoor_center_x = 0;
        indoor_center_y = 0;
        uMinimapZoom = dword_576E2C;
        field_28 = dword_576E28;
        }
    field_2C = 384;
    }