SBSPSS/source/level/layertile3d.cpp

263 lines
6.2 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"
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-04-19 21:56:43 +02:00
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-04-19 17:12:21 +02:00
TileBank3d=LevelHdr->TileBank3d;
TriList=LevelHdr->TriList;
QuadList=LevelHdr->QuadList;
VtxList=LevelHdr->VtxList;
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
/*****************************************************************************/
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-04-19 21:56:43 +02:00
// MapXY.vx-=SCREEN_TILE_ADJ_LEFT;
// MapXY.vy-=SCREEN_TILE_ADJ_UP;
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)
{
RenderOfs.vx=-MapXY.vx*BLOCK_MULT;
MapXY.vx=0;
}
if (MapXY.vy<0)
{
RenderOfs.vy=-MapXY.vy*BLOCK_MULT;
MapXY.vy=0;
}
2001-03-09 00:02:47 +01:00
if (MapXY.vx+SCREEN_TILE_WIDTH3D<=MapWidth)
RenderW=SCREEN_TILE_WIDTH3D;
else
RenderW=MapWidth-MapXY.vx;
if (MapXY.vy+SCREEN_TILE_HEIGHT3D<=MapHeight)
RenderH=SCREEN_TILE_HEIGHT3D;
else
RenderH=MapHeight-MapXY.vy;
}
2001-01-04 22:53:14 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-04-19 01:04:03 +02:00
#if 1
2001-04-20 00:27:41 +02:00
2001-04-19 01:04:03 +02:00
void CLayerTile3d::render()
{
2001-04-20 00:27:41 +02:00
const int XOfs=-(BLOCK_MULT*15)-(SCREEN_TILE_ADJ_LEFT*BLOCK_MULT)+24;
const int YOfs=-(BLOCK_MULT*7)-(SCREEN_TILE_ADJ_UP*BLOCK_MULT)+32;
2001-04-19 01:04:03 +02:00
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
BlkPos.vx=XOfs-(ShiftX);
BlkPos.vy=YOfs-(ShiftY);
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++)
{
sTile3d *Tile=&TileBank3d[MapRow->Tile];
int TriCount=Tile->TriCount;
sTri *TList=&TriList[Tile->TriStart];
while (TriCount--) // Blank tiles rejected here (as no tri-count)
{
P0=&VtxList[TList->P0]; P1=&VtxList[TList->P1]; P2=&VtxList[TList->P2];
CMX_SetTransMtxXY(&BlkPos);
gte_ldv3(P0,P1,P2);
setlen(TPrimPtr, GPU_PolyFT3Tag);
2001-05-02 20:40:41 +02:00
TPrimPtr->code=TList->PolyCode;
setRGB0(TPrimPtr,128,128,128);
2001-04-19 01:04:03 +02:00
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
2001-05-02 00:28:01 +02:00
ASSERT(TList->OTOfs<MAX_OT);
ThisOT=OtPtr+TList->OTOfs;
2001-04-19 01:04:03 +02:00
TList++;
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);
if (ClipZ<=0)
2001-04-19 01:04:03 +02:00
{
addPrim(ThisOT,TPrimPtr);
TPrimPtr++;
}
}
MapRow++;
BlkPos.vx+=BLOCK_MULT;
}
MapPtr+=MapWidth;
BlkPos.vx=BlkXOld;
BlkPos.vy+=BLOCK_MULT;
}
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
}
#else
2000-12-14 17:38:34 +01:00
void CLayerTile3d::render()
2000-12-14 17:01:49 +01:00
{
2001-04-19 01:04:03 +02:00
/*
2001-03-09 00:02:47 +01:00
const int XOfs=-(BLOCK_MULT*15)-(SCREEN_TILE_ADJ_LEFT*BLOCK_MULT);
const int YOfs=-(BLOCK_MULT*7)-(SCREEN_TILE_ADJ_UP*BLOCK_MULT);
2001-03-08 00:20:09 +01:00
2001-03-09 00:02:47 +01:00
sTileMapElem *MapPtr=GetMapPos();
2001-02-22 15:55:13 +01:00
u8 *PrimPtr=GetPrimPtr();
2001-03-08 00:20:09 +01:00
POLY_FT3 *TPrimPtr=(POLY_FT3*)PrimPtr;
2001-01-04 22:53:14 +01:00
VECTOR BlkPos;
2001-03-12 21:30:38 +01:00
//sOT *ThisOT=OtPtr+LayerOT;
2001-03-08 00:20:09 +01:00
sVtx *P0,*P1,*P2;
u32 T0,T1,T2;
2001-03-09 00:02:47 +01:00
s32 ClipZ;
2001-01-17 23:19:53 +01:00
2001-03-08 00:20:09 +01:00
2001-03-12 16:24:37 +01:00
// Setup Trans Matrix
2001-03-09 00:02:47 +01:00
BlkPos.vx=XOfs-((MapXY.vx*BLOCK_MULT)+ShiftX);
BlkPos.vy=YOfs-((MapXY.vy*BLOCK_MULT)+ShiftY);
2001-03-12 16:24:37 +01:00
BlkPos.vx+=RenderOfs.vx;
BlkPos.vy+=RenderOfs.vy;
2001-03-08 00:20:09 +01:00
CMX_SetTransMtxXY(&BlkPos);
for (int Y=0; Y<RenderH; Y++)
{
// Get strip render size
int TriStart=MapPtr[0];
int TriEnd=MapPtr[RenderW];
int TriCount=TriEnd-TriStart;
sTri *TList=&TriList[TriStart];
while (TriCount>0)
{
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();
2001-03-09 00:02:47 +01:00
2001-03-08 00:20:09 +01: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-03-12 21:30:38 +01:00
int ZP=P0->vz>>5;
2001-03-12 22:04:18 +01:00
if (ZP<-4) ZP=-4;
if (ZP>8) ZP=8;
2001-03-12 21:30:38 +01:00
sOT *ThisOT=OtPtr+(LayerOT+ZP);
2001-03-12 16:24:37 +01:00
2001-03-08 00:20:09 +01:00
TList++;
2001-03-09 00:02:47 +01:00
gte_nclip_b();
2001-03-08 00:20:09 +01:00
gte_stsxy3_ft3(TPrimPtr);
2001-03-09 00:02:47 +01:00
gte_stopz(&ClipZ);
2001-03-08 00:20:09 +01:00
if (ClipZ<=0)
{
2001-03-12 21:30:38 +01:00
addPrimNoCheck(ThisOT,TPrimPtr);
// addPrim(ThisOT,TPrimPtr);
2001-03-08 00:20:09 +01:00
TPrimPtr++;
}
TriCount--;
}
MapPtr+=MapWidth;
}
2001-03-09 00:12:02 +01:00
int PolyCount=((u8*)TPrimPtr-PrimPtr)/sizeof(POLY_FT3);
2001-01-04 22:53:14 +01:00
2001-03-08 00:20:09 +01:00
SetPrimPtr((u8*)TPrimPtr);
2001-03-09 00:12:02 +01:00
2001-03-10 17:54:47 +01:00
#if defined(_SHOW_POLYZ_)
2001-03-09 00:12:02 +01:00
char Txt[256];
sprintf(Txt,"Poly Count=%i",PolyCount);
Font->print( 32, 32, Txt);
#endif
2001-04-19 01:04:03 +02:00
*/
2001-01-04 22:53:14 +01:00
}
2001-04-19 01:04:03 +02:00
#endif