SBSPSS/source/level/layertile3d.cpp

190 lines
5.0 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"
#include <DStructs.h>
#include "utils\utils.h"
#include "gfx\prim.h"
#include "LayerTile.h"
2000-12-14 17:38:34 +01:00
#include "LayerTile3d.h"
2000-12-14 17:01:49 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2000-12-14 17:38:34 +01:00
CLayerTile3d::CLayerTile3d(sLayerHdr *Hdr,sTile *TileList,sTri *TriList,sQuad *QuadList,sVtx *VtxList) : CLayerTile(Hdr,TileList,TriList,QuadList,VtxList)
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);
2001-01-17 23:19:53 +01:00
CreateRenderFlagTable();
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-02-09 18:01:04 +01:00
MemFree(RenderFlagTable);
2000-12-14 17:01:49 +01:00
}
/*****************************************************************************/
2001-01-17 23:19:53 +01:00
void CLayerTile3d::CreateRenderFlagTable()
{
s16 *Ptr;
RenderFlagTable=(s16*) MemAlloc(SCREEN_TILE_WIDTH*SCREEN_TILE_HEIGHT*sizeof(s32),"RenderFlagTable");
Ptr=RenderFlagTable;
for (int Y=0; Y<SCREEN_TILE_HEIGHT; Y++)
{
for (int X=0; X<SCREEN_TILE_WIDTH; X++)
{
s16 Flag=1<<TILE3D_FLAGS_F;
if (X<(SCREEN_TILE_WIDTH/2)+1)
{
Flag|=1<<TILE3D_FLAGS_R;
}
if (X>(SCREEN_TILE_WIDTH/2)-1)
{
Flag|=1<<TILE3D_FLAGS_L;
}
if (Y<(SCREEN_TILE_HEIGHT/2)+1)
{
Flag|=1<<TILE3D_FLAGS_D;
}
if (Y>(SCREEN_TILE_HEIGHT/2)-1)
{
Flag|=1<<TILE3D_FLAGS_U;
}
*Ptr++=Flag;
}
}
}
2001-01-04 22:53:14 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
#define BLOCK_MULT 16
2001-01-17 23:19:53 +01:00
2000-12-14 17:38:34 +01:00
void CLayerTile3d::render()
2000-12-14 17:01:49 +01:00
{
2001-02-22 15:55:13 +01:00
sTileMapElem3d *MapPtr=GetMapPos3d();
u8 *PrimPtr=GetPrimPtr();
2001-01-04 22:53:14 +01:00
s16 TileX,TileY;
VECTOR BlkPos;
s32 BlkXStore;
2001-01-15 16:22:33 +01:00
sOT *ThisOT=OtPtr+LayerOT;
2001-01-17 23:19:53 +01:00
s16 *RenderFlags=RenderFlagTable;
2001-01-04 22:53:14 +01:00
// Setup shift bits of pos
TileY=-ShiftY;
BlkPos.vx=((-15*TILE_WIDTH)-ShiftX)*BLOCK_MULT;
2001-01-17 23:19:53 +01:00
BlkPos.vy=((-7*TILE_HEIGHT)-ShiftY)*BLOCK_MULT;
2001-01-04 22:53:14 +01:00
BlkXStore=BlkPos.vx;
// Render it!!
2001-02-22 15:55:13 +01:00
for (int Y=0; Y<RenderH; Y++)
2001-01-04 22:53:14 +01:00
{
2001-02-22 15:55:13 +01:00
sTileMapElem3d *MapRow=MapPtr;
2001-01-04 22:53:14 +01:00
TileX=-ShiftX;
2001-02-22 15:55:13 +01:00
for (int X=0; X<RenderW; X++)
2001-01-04 22:53:14 +01:00
{
2001-02-22 15:55:13 +01:00
/**/ sTile *Tile=&TileList[MapRow->Tile];
if (Tile->Clut)
{
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);
2001-01-04 22:53:14 +01:00
}
2001-02-22 15:55:13 +01:00
if (MapRow->Flags)
2001-01-04 22:53:14 +01:00
{ // Has 3d Data
2001-02-22 15:55:13 +01:00
CMX_SetTransMtxXY(&BlkPos);
PrimPtr=RenderBlock(Tile,MapRow->Flags & *RenderFlags,PrimPtr);
2001-01-04 22:53:14 +01:00
}
2001-02-22 15:55:13 +01:00
MapRow++;
2001-01-04 22:53:14 +01:00
TileX+=TILE_WIDTH;
BlkPos.vx+=TILE_WIDTH*BLOCK_MULT;
2001-01-17 23:19:53 +01:00
RenderFlags++;
2001-01-04 22:53:14 +01:00
}
2001-02-22 15:55:13 +01:00
MapPtr+=MapWidth;
2001-01-04 22:53:14 +01:00
TileY+=TILE_HEIGHT;
BlkPos.vx=BlkXStore;
BlkPos.vy+=TILE_HEIGHT*BLOCK_MULT;
}
2001-02-22 15:55:13 +01:00
SetPrimPtr(PrimPtr);
2001-01-04 22:53:14 +01:00
}
/*****************************************************************************/
// NOTE: Tiles will be sorted by z order (cos they 'should' be simple objects
// NOTE: Tiles are split into facing strips, to reduce overdraw :o)
// NOTE: Matrix already setup for block
2001-02-22 15:55:13 +01:00
u8 *CLayerTile3d::RenderBlock(sTile *Tile,s16 RenderFlags,u8 *PrimPtr)
2001-01-04 22:53:14 +01:00
{
sVtx *P0,*P1,*P2;
2001-02-22 15:55:13 +01:00
POLY_FT3 *TPrimPtr=(POLY_FT3*)PrimPtr;
2001-01-04 22:53:14 +01:00
u16 *TileTable=Tile->TileTable;
u32 T0,T1,T2;
sTri *TList=TriList+Tile->TriStart;
2001-01-15 16:22:33 +01:00
sOT *ThisOT=OtPtr+LayerOT;
2001-01-04 22:53:14 +01:00
2001-01-17 23:19:53 +01:00
//--- Tris ---------------------------------------------------------------------------
2001-01-04 22:53:14 +01:00
for (int i=0; i<TILE3D_FLAGS_MAX; i++)
{
int TriCount=*TileTable++; // Get Tri Count
sTri *NextList=TList+TriCount;
2001-02-22 15:55:13 +01:00
// if (RenderFlags & 1)
2001-01-04 22:53:14 +01:00
{
while (TriCount--)
{
P0=&VtxList[TList->P0]; P1=&VtxList[TList->P1]; P2=&VtxList[TList->P2];
gte_ldv3(P0,P1,P2);
/**/ setPolyFT3(TPrimPtr);
/**/ setShadeTex(TPrimPtr,1);
/**/ setlen(TPrimPtr, GPU_PolyFT3Tag);
gte_rtpt_b();
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
TList++;
2001-01-15 16:22:33 +01:00
addPrimNoCheck(ThisOT,TPrimPtr);
2001-01-04 22:53:14 +01:00
gte_stsxy3_ft3(TPrimPtr);
TPrimPtr++;
}
}
TList=NextList;
2001-02-22 15:55:13 +01:00
RenderFlags>>=1;
2001-01-04 22:53:14 +01:00
}
2001-02-22 15:55:13 +01:00
return((u8*)TPrimPtr);
2001-01-04 22:53:14 +01:00
2001-02-22 15:55:13 +01:00
}