SBSPSS/source/level/layertile3d.cpp

329 lines
8.4 KiB
C++
Raw Normal View History

2000-12-14 17:38:34 +01:00
/***************************/
/*** 3d Tile Layer Class ***/
/***************************/
2000-12-14 17:01:49 +01:00
#include "system\global.h"
2001-06-21 21:19:15 +02:00
#include "system\vid.h"
2000-12-14 17:01:49 +01:00
#include <DStructs.h>
#include "utils\utils.h"
#include "gfx\prim.h"
2001-04-19 21:56:43 +02:00
#include "game\game.h"
2000-12-14 17:01:49 +01:00
#include "LayerTile.h"
2000-12-14 17:38:34 +01:00
#include "LayerTile3d.h"
2000-12-14 17:01:49 +01:00
2001-04-19 21:56:43 +02:00
#if defined(__USER_sbart__) || defined(__USER_daveo__)
#define _SHOW_POLYZ_ 1
#include "gfx\font.h"
2001-04-19 01:04:03 +02:00
static FontBank *Font;
2001-03-10 17:54:47 +01:00
#endif
2001-04-19 01:04:03 +02:00
2001-06-21 21:25:19 +02:00
static const int BLOCK_SIZE =16;
static const int SCREEN_TILE_ADJ_U =2;
2001-06-28 19:48:30 +02:00
static const int SCREEN_TILE_ADJ_D =1;
2001-06-21 21:25:19 +02:00
static const int SCREEN_TILE_ADJ_L =2;
static const int SCREEN_TILE_ADJ_R =3;
2001-06-28 19:48:30 +02:00
2001-06-21 21:25:19 +02:00
static const int SCREEN_TILE3D_WIDTH =(INGAME_SCREENW/BLOCK_SIZE)+SCREEN_TILE_ADJ_L+SCREEN_TILE_ADJ_R;
static const int SCREEN_TILE3D_HEIGHT =(INGAME_SCREENH/BLOCK_SIZE)+SCREEN_TILE_ADJ_U+SCREEN_TILE_ADJ_D;
2001-06-28 19:48:30 +02:00
static const int RENDER_X_OFS =INGAME_SCREENOFS_X-(SCREEN_TILE_ADJ_L*BLOCK_SIZE)+INGAME_RENDER_OFS_X;
static const int RENDER_Y_OFS =INGAME_SCREENOFS_Y-(SCREEN_TILE_ADJ_U*BLOCK_SIZE)+INGAME_RENDER_OFS_Y;
2001-04-19 21:56:43 +02:00
2001-07-12 22:10:15 +02:00
/*****************************************************************************/
sFlipTable FlipTable[4]=
{
{{+4096,0,+4096,0},0<<31}, //00 <0
{{-4096,0,+4096,0},1<<31}, //01 >0
{{+4096,0,-4096,0},1<<31}, //10 >0
{{-4096,0,-4096,0},0<<31} //11 <0
};
2000-12-14 17:01:49 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-04-19 17:12:21 +02:00
CLayerTile3d::CLayerTile3d(sLevelHdr *LevelHdr,sLayerHdr *Hdr) : CLayerTile(LevelHdr,Hdr)
2000-12-14 17:01:49 +01:00
{
2001-06-28 19:48:30 +02:00
ElemBank3d=LevelHdr->ElemBank3d;
2001-04-19 17:12:21 +02:00
TriList=LevelHdr->TriList;
QuadList=LevelHdr->QuadList;
VtxList=LevelHdr->VtxList;
2001-07-12 22:10:15 +02:00
VtxIdxList=LevelHdr->VtxIdxList;
2001-03-08 00:20:09 +01:00
2001-03-10 17:54:47 +01:00
#if defined(_SHOW_POLYZ_)
2001-04-19 01:04:03 +02:00
Font=new ("PrimFont") FontBank;
Font->initialise( &standardFont );
Font->setOt( 0 );
Font->setTrans(1);
2001-03-09 00:12:02 +01:00
#endif
2000-12-14 17:01:49 +01:00
}
/*****************************************************************************/
2000-12-14 17:38:34 +01:00
CLayerTile3d::~CLayerTile3d()
2000-12-14 17:01:49 +01:00
{
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-01-04 22:53:14 +01:00
2001-02-22 15:55:13 +01:00
void CLayerTile3d::init(DVECTOR &MapPos,int Shift)
{
CLayerTile::init(MapPos,Shift);
2000-12-14 17:01:49 +01:00
}
/*****************************************************************************/
2000-12-14 17:38:34 +01:00
void CLayerTile3d::shutdown()
2000-12-14 17:01:49 +01:00
{
2001-04-19 01:04:03 +02:00
#if defined(_SHOW_POLYZ_)
Font->dump();
delete Font;
#endif
2001-01-17 23:19:53 +01:00
}
2001-03-09 00:02:47 +01:00
/*****************************************************************************/
2001-05-09 23:56:48 +02:00
2001-03-09 00:02:47 +01:00
void CLayerTile3d::think(DVECTOR &MapPos)
{
2001-04-19 21:56:43 +02:00
MapXY.vx=MapPos.vx>>4;
MapXY.vy=MapPos.vy>>4;
2001-03-09 00:02:47 +01:00
2001-06-21 21:19:15 +02:00
MapXY.vx-=SCREEN_TILE_ADJ_L;
MapXY.vy-=SCREEN_TILE_ADJ_U;
2001-03-09 00:02:47 +01:00
2001-04-19 21:56:43 +02:00
ShiftX=(MapPos.vx & 15);
ShiftY=(MapPos.vy & 15);
2001-03-09 00:02:47 +01:00
2001-03-12 16:24:37 +01:00
RenderOfs.vx=RenderOfs.vy=0;
if (MapXY.vx<0)
{
2001-06-21 21:19:15 +02:00
RenderOfs.vx=-MapXY.vx*BLOCK_SIZE;
2001-03-12 16:24:37 +01:00
MapXY.vx=0;
}
if (MapXY.vy<0)
{
2001-06-21 21:19:15 +02:00
RenderOfs.vy=-MapXY.vy*BLOCK_SIZE;
2001-03-12 16:24:37 +01:00
MapXY.vy=0;
}
2001-03-09 00:02:47 +01:00
2001-05-09 23:56:48 +02:00
if (MapXY.vx+SCREEN_TILE3D_WIDTH<=MapWidth)
RenderW=SCREEN_TILE3D_WIDTH;
2001-03-09 00:02:47 +01:00
else
RenderW=MapWidth-MapXY.vx;
2001-05-09 23:56:48 +02:00
if (MapXY.vy+SCREEN_TILE3D_HEIGHT<=MapHeight)
RenderH=SCREEN_TILE3D_HEIGHT;
2001-03-09 00:02:47 +01:00
else
RenderH=MapHeight-MapXY.vy;
}
2001-01-04 22:53:14 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-07-12 22:10:15 +02:00
void CLayerTile3d::CacheElemVtx(sElem3d *Elem)
{
int Count=Elem->VtxTriCount;
sVtx *V0,*V1,*V2;
u16 *IdxTable=&VtxIdxList[Elem->VtxIdxStart];
u32 *OutVtx=(u32*)SCRATCH_RAM;
u32 *OutPtr;
2001-06-28 19:48:30 +02:00
2001-07-12 22:10:15 +02:00
V0=&VtxList[*IdxTable++];
V1=&VtxList[*IdxTable++];
V2=&VtxList[*IdxTable++];
gte_ldv3(V0,V1,V2);
while (Count--)
{
gte_rtpt_b(); // 22 cycles
// Preload next (when able) - Must check this
V0=&VtxList[*IdxTable++];
V1=&VtxList[*IdxTable++];
V2=&VtxList[*IdxTable++];
OutPtr=OutVtx;
OutVtx+=3;
gte_ldv3(V0,V1,V2);
gte_stsxy3c(OutPtr); // read XY back
}
}
/*****************************************************************************/
void CLayerTile3d::render()
2001-06-28 19:48:30 +02:00
{
2001-07-12 22:10:15 +02:00
sTileMapElem *MapPtr=GetMapPos();
u8 *PrimPtr=GetPrimPtr();
POLY_FT3 *TPrimPtr=(POLY_FT3*)PrimPtr;
u32 *XYList=(u32*)SCRATCH_RAM;
u32 T0,T1,T2;
u32 P0,P1,P2;
s32 ClipZ;
sOT *ThisOT;
VECTOR BlkPos;
// Setup Trans Matrix
BlkPos.vx=RENDER_X_OFS-(ShiftX)+RenderOfs.vx;
BlkPos.vy=RENDER_Y_OFS-(ShiftY)+RenderOfs.vy;
for (int Y=0; Y<RenderH; Y++)
{
sTileMapElem *MapRow=MapPtr;
s32 BlkXOld=BlkPos.vx;
for (int X=0; X<RenderW; X++)
{
u16 Tile=MapRow->Tile;
u16 TileIdx=Tile>>2;
u16 Flip=Tile&3;
sFlipTable *FTab=&FlipTable[Flip];
sElem3d *Elem=&ElemBank3d[TileIdx];
2001-06-28 19:48:30 +02:00
2001-07-12 22:10:15 +02:00
int TriCount=Elem->TriCount;
sTri *TList=&TriList[Elem->TriStart];
CMX_SetTransMtxXY(&BlkPos);
CMX_SetRotMatrixXY(&FTab->Mtx);
CacheElemVtx(Elem);
while (TriCount--) // Blank tiles rejected here (as no tri-count)
{
P0=XYList[TList->P0];
P1=XYList[TList->P1];
P2=XYList[TList->P2];
gte_ldsxy0(P0);
gte_ldsxy1(P1);
gte_ldsxy2(P2);
setlen(TPrimPtr, GPU_PolyFT3Tag);
TPrimPtr->code=TList->PolyCode;
gte_nclip_b(); // 8 cycles
setShadeTex(TPrimPtr,1);
T0=*(u32*)&TList->uv0; // Get UV0 & TPage
T1=*(u32*)&TList->uv1; // Get UV1 & Clut
T2=*(u16*)&TList->uv2; // Get UV2
*(u32*)&TPrimPtr->u0=T0; // Set UV0
*(u32*)&TPrimPtr->u1=T1; // Set UV1
*(u16*)&TPrimPtr->u2=T2; // Set UV2
gte_stopz(&ClipZ);
ThisOT=OtPtr+TList->OTOfs;
ClipZ^=FTab->ClipCode;
TList++;
if (ClipZ<0)
{
*(u32*)&TPrimPtr->x0=P0; // Set XY0
*(u32*)&TPrimPtr->x1=P1; // Set XY1
*(u32*)&TPrimPtr->x2=P2; // Set XY2
addPrim(ThisOT,TPrimPtr);
TPrimPtr++;
}
}
MapRow++;
BlkPos.vx+=BLOCK_SIZE;
}
MapPtr+=MapWidth;
BlkPos.vx=BlkXOld;
BlkPos.vy+=BLOCK_SIZE;
}
SetPrimPtr((u8*)TPrimPtr);
#if defined(_SHOW_POLYZ_)
char Txt[256];
int TCount=((u8*)TPrimPtr-PrimPtr)/sizeof(POLY_FT3);
int QCount=0;
sprintf(Txt,"TC %i\nQC %i",TCount,QCount);
Font->print( 128, 32, Txt);
#endif
}
/*
2001-04-19 01:04:03 +02:00
void CLayerTile3d::render()
{
sTileMapElem *MapPtr=GetMapPos();
u8 *PrimPtr=GetPrimPtr();
POLY_FT3 *TPrimPtr=(POLY_FT3*)PrimPtr;
sVtx *P0,*P1,*P2;
u32 T0,T1,T2;
s32 ClipZ;
sOT *ThisOT;
2001-04-19 21:56:43 +02:00
VECTOR BlkPos;
2001-04-19 01:04:03 +02:00
2001-04-19 21:56:43 +02:00
// Setup Trans Matrix
2001-05-11 03:10:06 +02:00
BlkPos.vx=RENDER_X_OFS-(ShiftX)+RenderOfs.vx;
BlkPos.vy=RENDER_Y_OFS-(ShiftY)+RenderOfs.vy;
2001-04-19 01:04:03 +02:00
for (int Y=0; Y<RenderH; Y++)
{
sTileMapElem *MapRow=MapPtr;
s32 BlkXOld=BlkPos.vx;
for (int X=0; X<RenderW; X++)
{
2001-06-28 19:48:30 +02:00
u16 Tile=MapRow->Tile;
u16 TileIdx=Tile>>2;
u16 Flip=Tile&3;
sFlipTable *FTab=&FlipTable[Flip];
sElem3d *Elem=&ElemBank3d[TileIdx];
int TriCount=Elem->TriCount;
sTri *TList=&TriList[Elem->TriStart];
2001-07-12 22:10:15 +02:00
u16 *IdxTable=&VtxIdxList[Elem->VtxIdxStart];
2001-04-19 01:04:03 +02:00
2001-07-12 22:10:15 +02:00
// P0=&VtxList[TList->P0]; P1=&VtxList[TList->P1]; P2=&VtxList[TList->P2];
P0=&VtxList[IdxTable[TList->P0]];
P1=&VtxList[IdxTable[TList->P1]];
P2=&VtxList[IdxTable[TList->P2]];
2001-06-28 23:01:28 +02:00
CMX_SetTransMtxXY(&BlkPos);
CMX_SetRotMatrixXY(&FTab->Mtx);
2001-04-19 01:04:03 +02:00
while (TriCount--) // Blank tiles rejected here (as no tri-count)
{
gte_ldv3(P0,P1,P2);
setlen(TPrimPtr, GPU_PolyFT3Tag);
2001-05-02 20:40:41 +02:00
TPrimPtr->code=TList->PolyCode;
2001-04-19 01:04:03 +02:00
gte_rtpt_b();
2001-07-10 00:13:44 +02:00
// setShadeTex(TPrimPtr,1);
2001-04-19 01:04:03 +02:00
T0=*(u32*)&TList->uv0; // Get UV0 & TPage
T1=*(u32*)&TList->uv1; // Get UV1 & Clut
T2=*(u16*)&TList->uv2; // Get UV2
*(u32*)&TPrimPtr->u0=T0; // Set UV0
*(u32*)&TPrimPtr->u1=T1; // Set UV1
*(u16*)&TPrimPtr->u2=T2; // Set UV2
2001-07-10 00:13:44 +02:00
extern u8 GlobalRGB[];
setRGB0(TPrimPtr,GlobalRGB[1],GlobalRGB[1],GlobalRGB[1]);
2001-04-19 01:04:03 +02:00
2001-05-02 00:28:01 +02:00
ThisOT=OtPtr+TList->OTOfs;
2001-04-19 01:04:03 +02:00
TList++;
2001-06-28 19:48:30 +02:00
P0=&VtxList[TList->P0]; P1=&VtxList[TList->P1]; P2=&VtxList[TList->P2]; // Pre-fetch next Tri
2001-04-20 00:27:41 +02:00
gte_nclip_b();
2001-04-19 01:04:03 +02:00
gte_stsxy3_ft3(TPrimPtr);
2001-04-20 00:27:41 +02:00
gte_stopz(&ClipZ);
2001-06-28 19:48:30 +02:00
ClipZ^=FTab->ClipCode;
if (ClipZ<0)
2001-04-19 01:04:03 +02:00
{
addPrim(ThisOT,TPrimPtr);
TPrimPtr++;
}
}
MapRow++;
2001-06-21 21:19:15 +02:00
BlkPos.vx+=BLOCK_SIZE;
2001-04-19 01:04:03 +02:00
}
MapPtr+=MapWidth;
BlkPos.vx=BlkXOld;
2001-06-21 21:19:15 +02:00
BlkPos.vy+=BLOCK_SIZE;
2001-04-19 01:04:03 +02:00
}
SetPrimPtr((u8*)TPrimPtr);
#if defined(_SHOW_POLYZ_)
char Txt[256];
int TCount=((u8*)TPrimPtr-PrimPtr)/sizeof(POLY_FT3);
int QCount=0;
sprintf(Txt,"TC %i\nQC %i",TCount,QCount);
Font->print( 128, 32, Txt);
#endif
}
2001-07-12 22:10:15 +02:00
*/