view OutdoorCamera.cpp @ 1395:8d4ec56416ef

Fix to ticket #69 array_50A2B0 being accessed outside of bounds
author Nomad
date Thu, 18 Jul 2013 17:07:49 +0200
parents cc9a3a24d61d
children 75fafd8ced59
line wrap: on
line source

#include "OutdoorCamera.h"
#include "IndoorCamera.h"
#include "Outdoor_stuff.h"
#include "Game.h"
#include "LightmapBuilder.h"
#include "Viewport.h"
#include "Math.h"
#include "mm7_data.h"
#include "Allocator.h"

//----- (00481E55) --------------------------------------------------------
void OutdoorCamera::Project(unsigned int uNumVertices)
{
  double v1; // st7@2
  double v2; // st6@2
  double v3; // st5@2
  int v4; // eax@2
  unsigned int v5; // edx@2
  double v6; // st4@3
  double v7; // st3@3

  if ( (signed int)uNumVertices > 0 )
  {
    v1 = (double)pOutdoorCamera->int_fov_rad;
    v2 = (double)pViewport->uScreenCenterX;
    v3 = (double)pViewport->uScreenCenterY;
    v4 = 0;
    v5 = uNumVertices;
    do
    {
      v6 = v1 * array_507D30[v4]._rhw;
      v7 = v6 * array_507D30[v4].vWorldViewPosition.y;
      memcpy(&array_50AC10[v4], &array_507D30[v4], sizeof(array_50AC10[v4]));
      array_50AC10[v4].vWorldViewProjX = v2 - v7;
      array_50AC10[v4].vWorldViewProjY = v3 - v6 * array_507D30[v4].vWorldViewPosition.z;
      ++v4;
      --v5;
    }
    while ( v5 );
  }
}
//----- (00485F64) --------------------------------------------------------
void OutdoorCamera::_485F64()
{
  int v1; // eax@1
  int v2; // eax@2
  signed __int64 v3; // qtt@4
  int v4; // eax@4

  this->uCameraFovInDegrees = 75;
  v1 = stru_5C6E00->uPiMask & 0xD5;
  if ( v1 >= (signed int)stru_5C6E00->uIntegerHalfPi )
    v2 = -stru_5C6E00->pTanTable[stru_5C6E00->uIntegerPi - v1];
  else
    v2 = stru_5C6E00->pTanTable[v1];
  LODWORD(v3) = (viewparams->uSomeZ - viewparams->uSomeX) << 31;
  HIDWORD(v3) = (viewparams->uSomeZ - viewparams->uSomeX) << 15 >> 16;
  v4 = (signed int)(v3 / v2) >> 16;
  this->int_fov_rad = v4;
  this->field_4C = 360000;
  this->int_fov_rad_inv = 65536 / v4;
  this->field_50 = 115;
  //sr_6BE060[1] = 1;
  RotationToInts();
}

//----- (0048600E) --------------------------------------------------------
void OutdoorCamera::RotationToInts()
{
  camera_rotation_y_int_sine   = stru_5C6E00->Sin(pIndoorCamera->sRotationY);
  camera_rotation_y_int_cosine = stru_5C6E00->Cos(pIndoorCamera->sRotationY);
  camera_rotation_x_int_sine   = stru_5C6E00->Sin(pIndoorCamera->sRotationX);
  camera_rotation_x_int_cosine = stru_5C6E00->Cos(pIndoorCamera->sRotationX);
}
//----- (00486A28) --------------------------------------------------------
void OutdoorCamera::AllocSoftwareDrawBuffers()
{
  if ( !this || !pSpans )
  {
    ReleaseSoftwareDrawBuffers();
    pSpans = (Span *)pAllocator->AllocNamedChunk(pSpans, 0x493E0u, "SPANS");
    pEdges = (Edge *)pAllocator->AllocNamedChunk(pEdges, 0x4C2C0u, "EDGES");
    pSurfs = (Surf *)pAllocator->AllocNamedChunk(pSurfs, 0x11940u, "SURFS");
    pNewEdges = (Edge *)pAllocator->AllocNamedChunk(pNewEdges, 0x6180u, "NEWEDGES");
    memset(pSpans, 0, 0x493E0u);
    memset(pEdges, 0, 0x4C2C0u);
    memset(pSurfs, 0, 0x11940u);
    memset(pNewEdges, 0, 0x6180u);
  }
}

//----- (00486AFC) --------------------------------------------------------
void OutdoorCamera::ReleaseSoftwareDrawBuffers()
{
  pAllocator->FreeChunk(pSpans);
  pAllocator->FreeChunk(pEdges);
  pAllocator->FreeChunk(pSurfs);
  pAllocator->FreeChunk(pNewEdges);
  pSpans = 0;
  pEdges = 0;
  pSurfs = 0;
  pNewEdges = 0;
}