SBSPSS/source/level/layertile.cpp

149 lines
3.6 KiB
C++
Raw Normal View History

2000-12-07 02:15:53 +01:00
/************************/
/*** Tile Layer Class ***/
/************************/
#include "system\global.h"
#include <DStructs.h>
2000-12-07 16:56:20 +01:00
#include "utils\utils.h"
2000-12-09 18:22:06 +01:00
#include "system\vid.h"
2000-12-07 16:56:20 +01:00
#include "gfx\prim.h"
2000-12-07 02:15:53 +01:00
#include "LayerTile.h"
2001-01-03 23:12:25 +01:00
const u32 XInc=16<<0;
const u32 YInc=16<<16;
/*****************************************************************************/
2001-07-09 22:02:33 +02:00
static const int TILE2D_WIDTH=16;
static const int TILE2D_HEIGHT=12;
static const int SCREEN_TILE2D_WIDTH=((512/TILE2D_WIDTH)+1);
static const int SCREEN_TILE2D_HEIGHT=((256/TILE2D_HEIGHT)+1);
2000-12-12 21:56:51 +01:00
2000-12-07 16:56:20 +01:00
/*****************************************************************************/
2000-12-07 02:15:53 +01:00
/*****************************************************************************/
/*****************************************************************************/
2001-07-09 22:02:33 +02:00
2001-04-19 17:12:21 +02:00
CLayerTile::CLayerTile(sLevelHdr *LevelHdr,sLayerHdr *Hdr)
2000-12-07 16:56:20 +01:00
{
2001-07-09 22:02:33 +02:00
int Count=SCREEN_TILE2D_WIDTH*SCREEN_TILE2D_HEIGHT;
int MemSize=Count*sizeof(TSPRT);
2001-01-03 23:12:25 +01:00
LayerHdr=Hdr;
2001-02-20 16:56:16 +01:00
MapWidth=LayerHdr->Width;
MapHeight=LayerHdr->Height;
2001-06-28 19:48:30 +02:00
ElemBank2d=LevelHdr->ElemBank2d;
2001-01-03 23:12:25 +01:00
Map=(sTileMapElem*)MakePtr(Hdr,sizeof(sLayerHdr));
2001-07-09 22:02:33 +02:00
PrimBank=(TSPRT*)MemAlloc(MemSize,"Mid Polyz");
TSPRT *PrimPtr=PrimBank;
for (int i=0; i<Count; i++)
{
setTSprt(PrimPtr);
2001-07-23 21:26:37 +02:00
setTSetShadeTex(PrimPtr,1);
2001-07-09 22:02:33 +02:00
PrimPtr->w=TILE2D_WIDTH;
PrimPtr->h=TILE2D_HEIGHT;
PrimPtr++;
}
2000-12-07 16:56:20 +01:00
}
/*****************************************************************************/
CLayerTile::~CLayerTile()
{
2001-07-09 22:02:33 +02:00
MemFree(PrimBank);
2000-12-12 21:56:51 +01:00
}
/*****************************************************************************/
/*****************************************************************************/
2000-12-07 02:15:53 +01:00
/*****************************************************************************/
2001-02-22 15:55:13 +01:00
void CLayerTile::init(DVECTOR &MapPos,int Shift)
2000-12-07 02:15:53 +01:00
{
2000-12-14 17:38:34 +01:00
MapXYShift=Shift;
2001-02-22 15:55:13 +01:00
MapXY=MapPos;
2000-12-07 02:15:53 +01:00
}
/*****************************************************************************/
2000-12-12 21:56:51 +01:00
void CLayerTile::shutdown()
{
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-01-09 21:38:20 +01:00
void CLayerTile::think(DVECTOR &MapPos)
2000-12-12 21:56:51 +01:00
{
2000-12-14 17:38:34 +01:00
int XPos=MapPos.vx>>MapXYShift;
int YPos=MapPos.vy>>MapXYShift;
2001-02-22 15:55:13 +01:00
MapXY.vx=XPos>>4;
2001-07-09 22:02:33 +02:00
MapXY.vy=YPos/TILE2D_HEIGHT;
2001-04-19 01:04:03 +02:00
2001-01-03 23:12:25 +01:00
ShiftX=XPos & 15;
2001-07-09 22:02:33 +02:00
ShiftY=YPos%TILE2D_HEIGHT;
2001-01-03 23:12:25 +01:00
2001-07-18 18:45:39 +02:00
if (MapXY.vx<0)
{
MapXY.vx=0;
ShiftX=0;
}
if (MapXY.vy<0)
{
MapXY.vy=0;
ShiftY=0;
}
2001-05-09 23:56:48 +02:00
if (MapXY.vx+SCREEN_TILE2D_WIDTH<=MapWidth)
RenderW=SCREEN_TILE2D_WIDTH;
2000-12-12 21:56:51 +01:00
else
2001-02-22 15:55:13 +01:00
RenderW=MapWidth-MapXY.vx;
2000-12-12 21:56:51 +01:00
2001-05-09 23:56:48 +02:00
if (MapXY.vy+SCREEN_TILE2D_HEIGHT<=MapHeight)
RenderH=SCREEN_TILE2D_HEIGHT;
2000-12-12 21:56:51 +01:00
else
2001-02-22 15:55:13 +01:00
RenderH=MapHeight-MapXY.vy;
2000-12-12 21:56:51 +01:00
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-04-17 22:09:03 +02:00
void CLayerTile::render()
{
sTileMapElem *MapPtr=GetMapPos();
s16 TileX,TileY;
sOT *ThisOT=OtPtr+LayerOT;
2001-07-09 22:02:33 +02:00
TSPRT *PrimPtr=PrimBank;
2001-04-17 22:09:03 +02:00
// Setup shift bits of pos
TileY=-ShiftY;
// Render it!!
2001-07-09 22:02:33 +02:00
2001-04-17 22:09:03 +02:00
for (int Y=0; Y<RenderH; Y++)
{
sTileMapElem *MapRow=MapPtr;
TileX=-ShiftX;
for (int X=0; X<RenderW; X++)
{
2001-04-19 01:04:03 +02:00
int ThisTile=MapRow->Tile;
MapRow++;
2001-04-17 22:09:03 +02:00
if (ThisTile)
{
2001-06-28 19:48:30 +02:00
sElem2d *Tile=&ElemBank2d[ThisTile];
2001-07-09 22:02:33 +02:00
PrimPtr->x0=TileX;
PrimPtr->y0=TileY;
setTSprtTPage(PrimPtr,Tile->TPage);
*(u32*)&PrimPtr->u0=*(u32*)&Tile->u0; // copy uv AND clut
addPrim(ThisOT,PrimPtr);
PrimPtr++;
2001-04-17 22:09:03 +02:00
}
2001-05-09 23:56:48 +02:00
TileX+=TILE2D_WIDTH;
2001-04-17 22:09:03 +02:00
}
MapPtr+=MapWidth;
2001-05-09 23:56:48 +02:00
TileY+=TILE2D_HEIGHT;
2001-04-17 22:09:03 +02:00
}
}