SBSPSS/source/level/layertile.cpp

176 lines
4.2 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-04-19 01:04:03 +02:00
//DVECTOR TileMapOfs={0,4}; // To line layers up :oP
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-04-19 17:12:21 +02:00
CLayerTile::CLayerTile(sLevelHdr *LevelHdr,sLayerHdr *Hdr)
2000-12-07 16:56:20 +01:00
{
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-02-22 15:55:13 +01:00
printf("%i %i\n",MapWidth,MapHeight);
2001-04-19 17:12:21 +02:00
TileBank2d=LevelHdr->TileBank2d;
2001-01-03 23:12:25 +01:00
Map=(sTileMapElem*)MakePtr(Hdr,sizeof(sLayerHdr));
2000-12-07 16:56:20 +01:00
}
/*****************************************************************************/
CLayerTile::~CLayerTile()
{
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-04-17 22:09:03 +02:00
MapXY.vy=YPos/12;
2001-04-19 01:04:03 +02:00
/* if (LayerHdr->SubType==1) // BODGE AND A HALF
2001-02-22 18:01:34 +01:00
{
2001-04-19 01:04:03 +02:00
MapXY.vx+=TileMapOfs.vx; MapXY.vy+=TileMapOfs.vy;
2001-02-22 18:01:34 +01:00
}
2001-04-19 01:04:03 +02:00
*/
2001-01-03 23:12:25 +01:00
ShiftX=XPos & 15;
2001-04-17 22:09:03 +02:00
// ShiftY=YPos & 15;
ShiftY=YPos%12;
2001-01-03 23:12:25 +01:00
2001-02-22 15:55:13 +01:00
if (MapXY.vx+SCREEN_TILE_WIDTH<=MapWidth)
RenderW=SCREEN_TILE_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-02-22 15:55:13 +01:00
if (MapXY.vy+SCREEN_TILE_HEIGHT<=MapHeight)
RenderH=SCREEN_TILE_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-19 01:04:03 +02:00
#if 1 // FT4 version
2001-04-17 22:09:03 +02:00
void CLayerTile::render()
{
2001-04-19 01:04:03 +02:00
2001-04-17 22:09:03 +02:00
sTileMapElem *MapPtr=GetMapPos();
u8 *PrimPtr=GetPrimPtr();
s16 TileX,TileY;
sOT *ThisOT=OtPtr+LayerOT;
// Setup shift bits of pos
TileY=-ShiftY;
// Render it!!
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-04-19 01:04:03 +02:00
sTile2d *Tile=&TileBank2d[ThisTile];
2001-04-17 22:09:03 +02:00
POLY_FT4 *Ft4=(POLY_FT4*)PrimPtr;
setPolyFT4(Ft4);
setShadeTex(Ft4,1);
setXYWH(Ft4,TileX,TileY,16,12);
setUVWH(Ft4,Tile->u0,Tile->v0,15,15);
Ft4->tpage=Tile->TPage;
Ft4->clut=Tile->Clut;
2001-04-19 01:04:03 +02:00
// addPrimNoCheck(ThisOT,Ft4);
addPrim(ThisOT,Ft4);
2001-04-17 22:09:03 +02:00
PrimPtr+=sizeof(POLY_FT4);
}
TileX+=TILE_WIDTH;
}
MapPtr+=MapWidth;
TileY+=TILE_HEIGHT;
}
SetPrimPtr(PrimPtr);
}
#else
2000-12-12 21:56:51 +01:00
void CLayerTile::render()
2000-12-07 02:15:53 +01:00
{
2001-02-22 15:55:13 +01:00
sTileMapElem *MapPtr=GetMapPos();
u8 *PrimPtr=GetPrimPtr();
2001-01-03 23:12:25 +01:00
s16 TileX,TileY;
2001-01-15 16:22:33 +01:00
sOT *ThisOT=OtPtr+LayerOT;
2001-02-22 15:55:13 +01:00
2000-12-09 18:22:06 +01:00
// Setup shift bits of pos
2001-01-03 23:12:25 +01:00
TileY=-ShiftY;
2000-12-09 18:22:06 +01:00
2001-01-03 23:12:25 +01:00
// Render it!!
2001-02-22 15:55:13 +01:00
for (int Y=0; Y<RenderH; Y++)
2000-12-09 18:22:06 +01:00
{
2001-02-22 15:55:13 +01:00
sTileMapElem *MapRow=MapPtr;
2001-01-03 23:12:25 +01:00
TileX=-ShiftX;
2001-02-22 15:55:13 +01:00
for (int X=0; X<RenderW; X++)
2000-12-09 18:22:06 +01:00
{
2001-03-08 00:20:09 +01:00
int ThisTile=*MapRow++;
if (ThisTile)
2000-12-12 21:56:51 +01:00
{
2001-04-19 01:04:03 +02:00
/**/ sTile2d *Tile=&TileBank2d[ThisTile];
2001-02-22 15:55:13 +01:00
TSPRT_16 *SprPtr=(TSPRT_16*)PrimPtr;
setTSprt16(SprPtr);
setTSetShadeTex(SprPtr,1);
/**/ SprPtr->x0=TileX;
/**/ SprPtr->y0=TileY;
/**/ setTSprtTPage(SprPtr,Tile->TPage);
*(u32*)&SprPtr->u0=*(u32*)&Tile->u0; // copy uv AND clut
addPrimNoCheck(ThisOT,SprPtr);
PrimPtr+=sizeof(TSPRT_16);
2000-12-12 21:56:51 +01:00
}
2001-03-08 00:20:09 +01:00
// MapRow++;
2001-01-03 23:12:25 +01:00
TileX+=TILE_WIDTH;
2000-12-09 18:22:06 +01:00
}
2001-02-22 15:55:13 +01:00
MapPtr+=MapWidth;
2001-01-03 23:12:25 +01:00
TileY+=TILE_HEIGHT;
2000-12-09 18:22:06 +01:00
}
2001-02-22 15:55:13 +01:00
SetPrimPtr(PrimPtr);
2000-12-07 02:15:53 +01:00
}
2001-04-17 22:09:03 +02:00
#endif