/*========================================================================= FILENAME.CPP Author: Gary Liddon @ Created: Project: Purpose: Copyright (c) 1997 Climax Development Ltd ===========================================================================*/ /*---------------------------------------------------------------------- Includes -------- */ /* Std Lib ------- */ #include #include "conio.h" /* Glib ---- */ #include "gutils.h" /* Local ----- */ #include "tpage.h" #include "grect.h" /* Graphics -------- */ /*---------------------------------------------------------------------- Tyepdefs && Defines ------------------- */ using namespace std; /*---------------------------------------------------------------------- Structure defintions -------------------- */ struct TPInfo { int XAlign; int TpWidth; int BorderX; int BorderY; }; /* Information about where I can place this frame in the Tpage ----------------------------------------------------------- */ /*---------------------------------------------------------------------- Vars ---- */ static TPInfo const InfStruct[TP_NUM_OF_TP_TYPES]= { {1,256,1,1}, /* TP_4 */ {2,512,2,1}, /* TP_8 */ {4,256,4,1}, /* TP_16 */ {0,0,0,0}, /* TP_SCREEN */ {16*4,1024*4,0,0}, /* TP_PAL */ }; /*---------------------------------------------------------------------- Function Prototypes ------------------- */ /*---------------------------------------------------------------------- Vars ---- */ int TPRect::W2Alloc=1; int TPRect::H2Alloc=1; /*---------------------------------------------------------------------- Data ---- */ /*---------------------------------------------------------------------- Function: Purpose: Params: Returns: ---------------------------------------------------------------------- */ VRAM::VRAM(int nTpWidth,int nTpHeightInPixels) { Big2Little=false; RotateEveryEmpty=false; TpWidth=-1; TpHeightInPixels=-1; Clear(nTpWidth,nTpHeightInPixels); } void VRAM::Clear(int nTpWidth,int nTpHeightInPixels) { if (nTpWidth >= 0 ) TpWidth=nTpWidth; if (nTpHeightInPixels >= 0) TpHeightInPixels=nTpHeightInPixels; InitEmpty(0,0,TpWidth*256,TpHeightInPixels); } /*---------------------------------------------------------------------- Function: void VRAM::InitEmpty(void) Purpose: Initialise the VRAM as empty Params: Returns: ---------------------------------------------------------------------- */ void VRAM::InitEmpty(int vX,int vY,int nW,int nH) { const int Width16=256; const int Height16=256; W=nW; H=nH; X=vX; Y=vY; VRAMWidthPages=W/Width16; VRAMHeightPages=H/Height16; if (!VRAMHeightPages) { VRAMHeightPages = 1; } NumOfTPages=VRAMWidthPages*VRAMHeightPages; VecOfPages.resize(NumOfTPages,TPRectList()); Unused.reserve(4000); Used.reserve(2000); Unused.resize(0); Used.resize(0); for (int f=0;fXAlign; WorkingWidth=GU_AlignVal(ThisRect.W,Pi.XAlign); Pi.MinX=Tpi->BorderX; Pi.MinY=Tpi->BorderY; Pi.MaxX=W-Tpi->BorderX-WorkingWidth; Pi.MaxY=H-Tpi->BorderY-ThisRect.H; Pi.TpWidthPix=Tpi->TpWidth; Pi.MinXTp=Tpi->BorderX; Pi.MaxXTp=Tpi->TpWidth-Tpi->BorderX-WorkingWidth; Pi.MinYTp=Tpi->BorderY; Pi.MaxYTp=(256-Tpi->BorderY)-ThisRect.H; } bool VRAM::TryRect(TPRect & BlankRect,TPRect & ThisRect) { POS_INFO Pi; PosFromTPrect(ThisRect,Pi); int MinTpX=Pi.MinXTp+(BlankRect.X/Pi.TpWidthPix)*Pi.TpWidthPix; int MaxTpX=Pi.MaxXTp+(BlankRect.X/Pi.TpWidthPix)*Pi.TpWidthPix; int MinTpY=Pi.MinYTp+(BlankRect.Y/256)*256; int MaxTpY=Pi.MaxYTp+(BlankRect.Y/256)*256; /* Move to avoid edges of the map */ int MinX = MinTpX > Pi.MinX ? MinTpX : Pi.MinX; int MaxX = MaxTpX < Pi.MaxX ? MaxTpX : Pi.MaxX; int MinY = MinTpY > Pi.MinY ? MinTpY : Pi.MinY; int MaxY = MaxTpY < Pi.MaxY ? MaxTpY : Pi.MaxY; int ThisX=GU_AlignVal(BlankRect.X,Pi.XAlign); int ThisY=BlankRect.Y; if (ThisXMaxX) return(false); if (ThisYMaxY) return(false); ThisRect.SetXY(ThisX,ThisY); if (!InColisionWithUsed(ThisRect)) { RemovedFromUnused(ThisRect); AddToUsed(ThisRect); return(true); } return(false); } /*---------------------------------------------------------------------- Function: TPRect VRAM::AllocVRAM(TPageType nType,int nW,int nH,bool Rotated) Purpose: Params: Returns: ---------------------------------------------------------------------- */ class Predicate { public: bool operator()(TPRect const & R1,TPRect const & R2) const { u32 R1Val=(R1.H<<16)|(R1.W); u32 R2Val=(R2.H<<16)|(R2.W); return (R1ValR2Val); } }; /*---------------------------------------------------------------------- Function: TPRect VRAM::AllocVRAM(TpRectVec & RectVec) Purpose: Params: Returns: ---------------------------------------------------------------------- */ bool VRAM::AllocVRAM(TPRectVec & RectVec,bool nRotateEveryEmpty,bool nBig2Little,bool nWiderThanHigher) { int f; RotateEveryEmpty=nRotateEveryEmpty; Big2Little=nBig2Little; WiderThanHigher=nWiderThanHigher; if (WiderThanHigher) { for (f=0;f RectVec[f].W) && CanRotate(RectVec[f])) RectVec[f].SetRotate(!RectVec[f].GetRotate()); } } if (!Big2Little) std::sort(RectVec.begin(),RectVec.end(),Predicate()); else std::sort(RectVec.begin(),RectVec.end(),Predicate2()); bool AllocedEverything=true; for (f=0;f