/************************/ /*** Tile Layer Class ***/ /************************/ #include "system\global.h" #include #include "utils\utils.h" #include "system\vid.h" #include "gfx\prim.h" #include "LayerTile.h" const u32 XInc=16<<0; const u32 YInc=16<<16; /*****************************************************************************/ // Uses single buffer. Hopefully this will be adequate /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ CLayerTile::CLayerTile(sLayerHdr *Hdr,sTile *_TileList,sTri *_TriList,sQuad *_QuadList,sVtx *_VtxList) { LayerHdr=Hdr; TileList=_TileList; TriList=_TriList; QuadList=_QuadList; VtxList=_VtxList; Map=(sTileMapElem*)MakePtr(Hdr,sizeof(sLayerHdr)); MapWidth=LayerHdr->Width; MapHeight=LayerHdr->Height; } /*****************************************************************************/ CLayerTile::~CLayerTile() { MemFree(PrimGrid); } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void CLayerTile::init(DVECTOR &MapPos,int Shift,int Width,int Height) { int Size=Width*Height; ASSERT(Width>=SCREEN_TILE_WIDTH); ASSERT(Height>=SCREEN_TILE_HEIGHT); MapXYShift=Shift; PrimGridWidth=Width; PrimGridHeight=Height; PrimGrid=(sPrimGridElem*) MemAlloc(Size*sizeof(sPrimGridElem),"2d PrimGrid"); ASSERT(PrimGrid); MapX=0; MapY=0; for (int Y=0; YPrim); setTSetShadeTex(&ThisElem->Prim,1); // Grid ThisElem->Right=GetGridPos(X+1,Y); ThisElem->Down=GetGridPos(X,Y+1); } } UpdateWholeMap(); } /*****************************************************************************/ // AS not time critical, use row update routine for whole map void CLayerTile::UpdateWholeMap() { for (int Y=0; Y>MapXYShift; int YPos=MapPos.vy>>MapXYShift; int NewX=XPos>>4; int NewY=YPos>>4; ShiftX=XPos & 15; ShiftY=YPos & 15; if (NewX>MapX) { // update right column UpdateColumn(NewX+SCREEN_TILE_WIDTH-1,MapY); MapX=NewX; } else if (NewXMapY) { // update bottom row UpdateRow(MapX,NewY+SCREEN_TILE_HEIGHT-1); MapY=NewY; } else if (NewYPrim; /**/ sTile *Tile=&TileList[MapPtr->Tile]; /**/ setTSprtTPage(Prim,Tile->TPage); *(u32*)&Prim->u0=*(u32*)&Tile->u0; // copy uv AND clut // Next Elem MapPtr++; Grid=Grid->Right; } } /*****************************************************************************/ void CLayerTile::UpdateColumn(int X,int Y) { sPrimGridElem *Grid=GetGridPos(X,Y); sTileMapElem *MapPtr=GetMapPos(X,Y); for (int i=0; iPrim; /**/ sTile *Tile=&TileList[MapPtr->Tile]; /**/ setTSprtTPage(Prim,Tile->TPage); *(u32*)&Prim->u0=*(u32*)&Tile->u0; // copy uv AND clut // Next Elem MapPtr+=MapWidth; Grid=Grid->Down; } } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void CLayerTile::render() { sPrimGridElem *Grid=GetGridPos(MapX,MapY); s16 TileX,TileY; sOT *ThisOT=OtPtr+LayerOT; // Setup shift bits of pos TileY=-ShiftY; // Render it!! for (int Y=0; YDown; TileX=-ShiftX; for (int X=0; XPrim; if (Prim->clut) { /**/ Prim->x0=TileX; /**/ Prim->y0=TileY; addPrimNoCheck(ThisOT,Prim); } Grid=Grid->Right; TileX+=TILE_WIDTH; } Grid=GridDown; TileY+=TILE_HEIGHT; } }