This commit is contained in:
parent
5c55823d63
commit
e2956c44ee
12 changed files with 277 additions and 203 deletions
|
@ -346,6 +346,7 @@ BOOL CTileBank::SelectCancel()
|
||||||
BOOL CTileBank::IsTileValid(int Set,int Tile)
|
BOOL CTileBank::IsTileValid(int Set,int Tile)
|
||||||
{
|
{
|
||||||
if (Set<0 || Tile<0) return(FALSE);
|
if (Set<0 || Tile<0) return(FALSE);
|
||||||
|
if (Tile==0) return(TRUE);
|
||||||
ASSERT(Set<TileSet.size());
|
ASSERT(Set<TileSet.size());
|
||||||
|
|
||||||
return(TileSet[Set].IsTileValid(Tile));
|
return(TileSet[Set].IsTileValid(Tile));
|
||||||
|
|
|
@ -10,23 +10,11 @@
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
sOT *OtList[2],*OtPtr;
|
sOT *OtList[2],*OtPtr;
|
||||||
u32 *PrimDrawList;
|
|
||||||
u32 DmaStart[2];
|
u32 DmaStart[2];
|
||||||
u8 *PrimBuffer[2],*PrimListStart,*PrimListEnd;
|
u8 *PrimBuffer[2],*PrimListStart,*PrimListEnd;
|
||||||
u8 *CurrPrim,*EndPrim;
|
u8 *CurrPrim,*EndPrim;
|
||||||
int PrimFlipFlag;
|
int PrimFlipFlag;
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
void PrimDrawCallBack()
|
|
||||||
{
|
|
||||||
if (PrimDrawList)
|
|
||||||
{
|
|
||||||
DrawOTag2(PrimDrawList);
|
|
||||||
}
|
|
||||||
|
|
||||||
PrimDrawList=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void PrimInit()
|
void PrimInit()
|
||||||
{
|
{
|
||||||
|
@ -47,7 +35,6 @@ void PrimInit()
|
||||||
InitOTagR(OtList[0],MAX_OT);
|
InitOTagR(OtList[0],MAX_OT);
|
||||||
InitOTagR(OtList[1],MAX_OT);
|
InitOTagR(OtList[1],MAX_OT);
|
||||||
|
|
||||||
PrimDrawList=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,10 +45,9 @@ void PrimDisplay()
|
||||||
UnlinkOTagR(OtPtr, MAX_OT, &DmaStart[PrimFlipFlag]);
|
UnlinkOTagR(OtPtr, MAX_OT, &DmaStart[PrimFlipFlag]);
|
||||||
|
|
||||||
#ifdef USE_NTAGS
|
#ifdef USE_NTAGS
|
||||||
// DrawOTag((u32*)&DmaStart[PrimFlipFlag]);
|
DrawOTag((u32*)&DmaStart[PrimFlipFlag]);
|
||||||
PrimDrawList=&DmaStart[PrimFlipFlag];
|
|
||||||
#else
|
#else
|
||||||
// DrawOTag(OtPtr+(MAX_OT-1));
|
DrawOTag(OtPtr+(MAX_OT-1));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PrimFlipFlag^=1;
|
PrimFlipFlag^=1;
|
||||||
|
|
|
@ -306,7 +306,6 @@ extern u8 *PrimListStart,*PrimListEnd;
|
||||||
void PrimInit();
|
void PrimInit();
|
||||||
|
|
||||||
void PrimDisplay();
|
void PrimDisplay();
|
||||||
void PrimDrawCallBack();
|
|
||||||
|
|
||||||
void PrimClip(RECT *r, u32 Depth);
|
void PrimClip(RECT *r, u32 Depth);
|
||||||
void PrimFullScreen(int Depth);
|
void PrimFullScreen(int Depth);
|
||||||
|
|
|
@ -64,7 +64,7 @@ int Size=Width*Height;
|
||||||
// Tile prim
|
// Tile prim
|
||||||
setTSprt16(&ThisElem->Prim);
|
setTSprt16(&ThisElem->Prim);
|
||||||
setTSetShadeTex(&ThisElem->Prim,1);
|
setTSetShadeTex(&ThisElem->Prim,1);
|
||||||
// Table
|
// Grid
|
||||||
ThisElem->Right=GetGridPos(X+1,Y);
|
ThisElem->Right=GetGridPos(X+1,Y);
|
||||||
ThisElem->Down=GetGridPos(X,Y+1);
|
ThisElem->Down=GetGridPos(X,Y+1);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ int Size=Width*Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
// AS not critical, us row update routine for whole map
|
// AS not time critical, use row update routine for whole map
|
||||||
void CLayerTile::UpdateWholeMap()
|
void CLayerTile::UpdateWholeMap()
|
||||||
{
|
{
|
||||||
for (int Y=0; Y<PrimGridHeight; Y++)
|
for (int Y=0; Y<PrimGridHeight; Y++)
|
||||||
|
@ -92,26 +92,28 @@ void CLayerTile::shutdown()
|
||||||
// Get (wrapped) PrimGrid pos
|
// Get (wrapped) PrimGrid pos
|
||||||
sPrimGridElem *CLayerTile::GetGridPos(int X,int Y)
|
sPrimGridElem *CLayerTile::GetGridPos(int X,int Y)
|
||||||
{
|
{
|
||||||
|
sPrimGridElem *ThisGrid=(sPrimGridElem *)PrimGrid;
|
||||||
int Pos;
|
int Pos;
|
||||||
|
|
||||||
/**/ X%=PrimGridWidth;
|
/**/ X%=PrimGridWidth;
|
||||||
/**/ Y%=PrimGridHeight;
|
/**/ Y%=PrimGridHeight;
|
||||||
/**/ Pos=(X+(Y*PrimGridWidth));
|
/**/ Pos=(X+(Y*PrimGridWidth));
|
||||||
|
|
||||||
/**/ return(PrimGrid+Pos);
|
/**/ return(ThisGrid+Pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
// Get (wrapped) Map pos
|
// Get (wrapped) Map pos
|
||||||
sTileMapElem *CLayerTile::GetMapPos(int X,int Y)
|
sTileMapElem *CLayerTile::GetMapPos(int X,int Y)
|
||||||
{
|
{
|
||||||
|
sTileMapElem *ThisMap=(sTileMapElem *)Map;
|
||||||
int Pos;
|
int Pos;
|
||||||
|
|
||||||
/**/ X%=MapWidth;
|
/**/ X%=MapWidth;
|
||||||
/**/ Y%=MapHeight;
|
/**/ Y%=MapHeight;
|
||||||
/**/ Pos=(X+(Y*MapWidth));
|
/**/ Pos=(X+(Y*MapWidth));
|
||||||
|
|
||||||
/**/ return(Map+Pos);
|
/**/ return(ThisMap+Pos);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,21 +160,19 @@ int NewY=YPos>>4;
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void CLayerTile::UpdateRow(int X,int Y)
|
void CLayerTile::UpdateRow(int X,int Y)
|
||||||
{
|
{
|
||||||
sPrimGridElem *Table=GetGridPos(X,Y);
|
sPrimGridElem *Grid=GetGridPos(X,Y);
|
||||||
sTileMapElem *MapPtr=GetMapPos(X,Y);
|
sTileMapElem *MapPtr=GetMapPos(X,Y);
|
||||||
|
|
||||||
for (int i=0; i<SCREEN_TILE_WIDTH; i++)
|
for (int i=0; i<SCREEN_TILE_WIDTH; i++)
|
||||||
{
|
{
|
||||||
// Tile prim
|
// Tile prim
|
||||||
TSPRT_16 *Prim=&Table->Prim;
|
TSPRT_16 *Prim=&Grid->Prim;
|
||||||
/**/ sTile *Tile=&TileList[MapPtr->Tile];
|
/**/ sTile *Tile=&TileList[MapPtr->Tile];
|
||||||
/**/ setTSprtTPage(Prim,Tile->TPage);
|
/**/ setTSprtTPage(Prim,Tile->TPage);
|
||||||
*(u32*)&Prim->u0=*(u32*)&Tile->u0; // copy uv AND clut
|
*(u32*)&Prim->u0=*(u32*)&Tile->u0; // copy uv AND clut
|
||||||
/**/ Table->Tile=MapPtr->Tile;
|
|
||||||
/**/ Table->Flags=MapPtr->Flags;
|
|
||||||
// Next Elem
|
// Next Elem
|
||||||
MapPtr++;
|
MapPtr++;
|
||||||
Table=Table->Right;
|
Grid=Grid->Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -180,21 +180,19 @@ sTileMapElem *MapPtr=GetMapPos(X,Y);
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void CLayerTile::UpdateColumn(int X,int Y)
|
void CLayerTile::UpdateColumn(int X,int Y)
|
||||||
{
|
{
|
||||||
sPrimGridElem *Table=GetGridPos(X,Y);
|
sPrimGridElem *Grid=GetGridPos(X,Y);
|
||||||
sTileMapElem *MapPtr=GetMapPos(X,Y);
|
sTileMapElem *MapPtr=GetMapPos(X,Y);
|
||||||
|
|
||||||
for (int i=0; i<SCREEN_TILE_HEIGHT; i++)
|
for (int i=0; i<SCREEN_TILE_HEIGHT; i++)
|
||||||
{
|
{
|
||||||
// Tile prim
|
// Tile prim
|
||||||
TSPRT_16 *Prim=&Table->Prim;
|
TSPRT_16 *Prim=&Grid->Prim;
|
||||||
/**/ sTile *Tile=&TileList[MapPtr->Tile];
|
/**/ sTile *Tile=&TileList[MapPtr->Tile];
|
||||||
/**/ setTSprtTPage(Prim,Tile->TPage);
|
/**/ setTSprtTPage(Prim,Tile->TPage);
|
||||||
*(u32*)&Prim->u0=*(u32*)&Tile->u0; // copy uv AND clut
|
*(u32*)&Prim->u0=*(u32*)&Tile->u0; // copy uv AND clut
|
||||||
/**/ Table->Tile=MapPtr->Tile;
|
|
||||||
/**/ Table->Flags=MapPtr->Flags;
|
|
||||||
// Next Elem
|
// Next Elem
|
||||||
MapPtr+=MapWidth;
|
MapPtr+=MapWidth;
|
||||||
Table=Table->Down;
|
Grid=Grid->Down;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +201,7 @@ sTileMapElem *MapPtr=GetMapPos(X,Y);
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void CLayerTile::render()
|
void CLayerTile::render()
|
||||||
{
|
{
|
||||||
sPrimGridElem *Table=GetGridPos(MapX,MapY);
|
sPrimGridElem *Grid=GetGridPos(MapX,MapY);
|
||||||
s16 TileX,TileY;
|
s16 TileX,TileY;
|
||||||
|
|
||||||
// Setup shift bits of pos
|
// Setup shift bits of pos
|
||||||
|
@ -212,147 +210,23 @@ s16 TileX,TileY;
|
||||||
// Render it!!
|
// Render it!!
|
||||||
for (int Y=0; Y<SCREEN_TILE_HEIGHT; Y++)
|
for (int Y=0; Y<SCREEN_TILE_HEIGHT; Y++)
|
||||||
{
|
{
|
||||||
sPrimGridElem *TableDown=Table->Down;
|
sPrimGridElem *GridDown=Grid->Down;
|
||||||
TileX=-ShiftX;
|
TileX=-ShiftX;
|
||||||
|
|
||||||
for (int X=0; X<SCREEN_TILE_WIDTH; X++)
|
for (int X=0; X<SCREEN_TILE_WIDTH; X++)
|
||||||
{
|
{
|
||||||
TSPRT_16 *Prim=&Table->Prim;
|
TSPRT_16 *Prim=&Grid->Prim;
|
||||||
if (Prim->clut)
|
if (Prim->clut)
|
||||||
{
|
{
|
||||||
/**/ Prim->x0=TileX;
|
/**/ Prim->x0=TileX;
|
||||||
/**/ Prim->y0=TileY;
|
/**/ Prim->y0=TileY;
|
||||||
/**/ AddPrim(OtPtr,Prim);
|
/**/ AddPrim(OtPtr,Prim);
|
||||||
}
|
}
|
||||||
Table=Table->Right;
|
Grid=Grid->Right;
|
||||||
TileX+=TILE_WIDTH;
|
TileX+=TILE_WIDTH;
|
||||||
}
|
}
|
||||||
Table=TableDown;
|
Grid=GridDown;
|
||||||
TileY+=TILE_HEIGHT;
|
TileY+=TILE_HEIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
void CLayerTile::renderSolid()
|
|
||||||
{
|
|
||||||
sPrimGridElem *Table=GetGridPos(MapX,MapY);
|
|
||||||
s16 TileX,TileY;
|
|
||||||
|
|
||||||
// Setup shift bits of pos
|
|
||||||
TileY=-ShiftY;
|
|
||||||
|
|
||||||
// Render it!!
|
|
||||||
for (int Y=0; Y<SCREEN_TILE_HEIGHT; Y++)
|
|
||||||
{
|
|
||||||
sPrimGridElem *TableDown=Table->Down;
|
|
||||||
TileX=-ShiftX;
|
|
||||||
|
|
||||||
for (int X=0; X<SCREEN_TILE_WIDTH; X++)
|
|
||||||
{
|
|
||||||
TSPRT_16 *Prim=&Table->Prim;
|
|
||||||
/**/ Prim->x0=TileX;
|
|
||||||
/**/ Prim->y0=TileY;
|
|
||||||
/**/ AddPrim(OtPtr,Prim);
|
|
||||||
Table=Table->Right;
|
|
||||||
TileX+=TILE_WIDTH;
|
|
||||||
}
|
|
||||||
Table=TableDown;
|
|
||||||
TileY+=TILE_HEIGHT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
#define BLOCK_MULT 16
|
|
||||||
void CLayerTile::render3d()
|
|
||||||
{
|
|
||||||
sPrimGridElem *Table=GetGridPos(MapX,MapY);
|
|
||||||
s16 TileX,TileY;
|
|
||||||
VECTOR BlkPos;
|
|
||||||
s32 BlkXStore;
|
|
||||||
|
|
||||||
// Setup shift bits of pos
|
|
||||||
TileY=-ShiftY;
|
|
||||||
BlkPos.vx=((-15*TILE_WIDTH)-ShiftX)*BLOCK_MULT;
|
|
||||||
BlkPos.vy=((-8*TILE_HEIGHT)-ShiftY)*BLOCK_MULT;
|
|
||||||
BlkXStore=BlkPos.vx;
|
|
||||||
|
|
||||||
// Render it!!
|
|
||||||
for (int Y=0; Y<SCREEN_TILE_HEIGHT; Y++)
|
|
||||||
{
|
|
||||||
sPrimGridElem *TableDown=Table->Down;
|
|
||||||
TileX=-ShiftX;
|
|
||||||
|
|
||||||
for (int X=0; X<SCREEN_TILE_WIDTH; X++)
|
|
||||||
{
|
|
||||||
TSPRT_16 *Prim=&Table->Prim;
|
|
||||||
if (Prim->clut)
|
|
||||||
{ // Has 2d Data
|
|
||||||
/**/ Prim->x0=TileX;
|
|
||||||
/**/ Prim->y0=TileY;
|
|
||||||
/**/ AddPrim(OtPtr,Prim);
|
|
||||||
}
|
|
||||||
if (Table->Flags)
|
|
||||||
{ // Has 3d Data
|
|
||||||
/**/ CMX_SetTransMtxXY(&BlkPos);
|
|
||||||
/**/ RenderBlock(Table);
|
|
||||||
}
|
|
||||||
Table=Table->Right;
|
|
||||||
TileX+=TILE_WIDTH;
|
|
||||||
BlkPos.vx+=TILE_WIDTH*BLOCK_MULT;
|
|
||||||
}
|
|
||||||
Table=TableDown;
|
|
||||||
TileY+=TILE_HEIGHT;
|
|
||||||
BlkPos.vx=BlkXStore;
|
|
||||||
BlkPos.vy+=TILE_HEIGHT*BLOCK_MULT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
// 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
|
|
||||||
|
|
||||||
void CLayerTile::RenderBlock(sPrimGridElem *Elem)
|
|
||||||
{
|
|
||||||
sTile *Tile=&TileList[Elem->Tile];
|
|
||||||
u32 Flags=Elem->Flags;
|
|
||||||
sVtx *P0,*P1,*P2;
|
|
||||||
POLY_FT3 *TPrimPtr=(POLY_FT3*)GetPrimPtr();
|
|
||||||
sTileTable *TileTable=Tile->TileTable;
|
|
||||||
u32 T0,T1,T2;
|
|
||||||
|
|
||||||
//--- Tris ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
for (int i=0; i<TILE3D_FLAGS_MAX; i++)
|
|
||||||
{
|
|
||||||
int TriCount=TileTable->TriCount;
|
|
||||||
sTri *TList=TriList+TileTable->TriList;
|
|
||||||
if (Flags & 1)
|
|
||||||
{
|
|
||||||
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++;
|
|
||||||
addPrim(OtPtr,TPrimPtr);
|
|
||||||
gte_stsxy3_ft3(TPrimPtr);
|
|
||||||
TPrimPtr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TileTable++;
|
|
||||||
Flags>>=1;
|
|
||||||
}
|
|
||||||
SetPrimPtr((u8*)TPrimPtr);
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,14 +7,30 @@
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
/*
|
||||||
struct sPrimGridElem
|
struct sPrimGridElem
|
||||||
{
|
{
|
||||||
TSPRT_16 Prim;
|
TSPRT_16 Prim;
|
||||||
u16 Tile;
|
// u16 Tile;
|
||||||
u16 Flags;
|
// u16 Flags;
|
||||||
sPrimGridElem *Right;
|
sPrimGridElem *Right;
|
||||||
sPrimGridElem *Down;
|
sPrimGridElem *Down;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
struct sPrimGridElem
|
||||||
|
{
|
||||||
|
TSPRT_16 Prim;
|
||||||
|
sPrimGridElem *Right;
|
||||||
|
sPrimGridElem *Down;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sPrimGridElem3d : public sPrimGridElem
|
||||||
|
{
|
||||||
|
u16 Tile;
|
||||||
|
u16 Flags;
|
||||||
|
};
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
class CLayerTile
|
class CLayerTile
|
||||||
|
@ -47,30 +63,27 @@ virtual void shutdown();
|
||||||
virtual void think(VECTOR &MapPos);
|
virtual void think(VECTOR &MapPos);
|
||||||
virtual void render();
|
virtual void render();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void UpdateWholeMap();
|
virtual void UpdateWholeMap();
|
||||||
|
virtual void UpdateRow(int MapX,int MapY);
|
||||||
|
virtual void UpdateColumn(int MapX,int MapY);
|
||||||
|
|
||||||
sPrimGridElem *GetGridPos(int X,int Y);
|
sPrimGridElem *GetGridPos(int X,int Y);
|
||||||
sTileMapElem *GetMapPos(int X,int Y);
|
sTileMapElem *GetMapPos(int X,int Y);
|
||||||
void UpdateRow(int MapX,int MapY);
|
|
||||||
void UpdateColumn(int MapX,int MapY);
|
|
||||||
|
|
||||||
void renderSolid();
|
|
||||||
void render3d();
|
|
||||||
void RenderBlock(sPrimGridElem *Elem);
|
|
||||||
|
|
||||||
sLayerHdr *LayerHdr;
|
sLayerHdr *LayerHdr;
|
||||||
sTile *TileList;
|
sTile *TileList;
|
||||||
sTri *TriList;
|
sTri *TriList;
|
||||||
sQuad *QuadList;
|
sQuad *QuadList;
|
||||||
sVtx *VtxList;
|
sVtx *VtxList;
|
||||||
sTileMapElem *Map;
|
|
||||||
|
|
||||||
int MapWidth,MapHeight,MapXYShift;
|
int MapWidth,MapHeight,MapXYShift;
|
||||||
int PrimGridWidth,PrimGridHeight;
|
int PrimGridWidth,PrimGridHeight;
|
||||||
|
|
||||||
int MapX,MapY;
|
int MapX,MapY;
|
||||||
u16 ShiftX,ShiftY;
|
u16 ShiftX,ShiftY;
|
||||||
|
|
||||||
|
sTileMapElem *Map;
|
||||||
sPrimGridElem *PrimGrid;
|
sPrimGridElem *PrimGrid;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,34 @@ CLayerTile3d::~CLayerTile3d()
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void CLayerTile3d::init(VECTOR &MapPos,int Shift,int Width,int Height)
|
void CLayerTile3d::init(VECTOR &MapPos,int Shift,int Width,int Height)
|
||||||
{
|
{
|
||||||
CLayerTile::init(MapPos,Shift);
|
int Size=Width*Height;
|
||||||
|
|
||||||
|
ASSERT(Width>=SCREEN_TILE_WIDTH);
|
||||||
|
ASSERT(Height>=SCREEN_TILE_HEIGHT);
|
||||||
|
|
||||||
|
MapXYShift=Shift;
|
||||||
|
PrimGridWidth=Width;
|
||||||
|
PrimGridHeight=Height;
|
||||||
|
|
||||||
|
PrimGrid=(sPrimGridElem3d*) MemAlloc(Size*sizeof(sPrimGridElem3d),"3d PrimGrid");
|
||||||
|
ASSERT(PrimGrid);
|
||||||
|
MapX=0;
|
||||||
|
MapY=0;
|
||||||
|
for (int Y=0; Y<PrimGridHeight; Y++)
|
||||||
|
{
|
||||||
|
for (int X=0; X<PrimGridWidth; X++)
|
||||||
|
{
|
||||||
|
sPrimGridElem3d *ThisElem=GetGridPos3d(X,Y);
|
||||||
|
// Tile prim
|
||||||
|
setTSprt16(&ThisElem->Prim);
|
||||||
|
setTSetShadeTex(&ThisElem->Prim,1);
|
||||||
|
// Table
|
||||||
|
ThisElem->Right=GetGridPos3d(X+1,Y);
|
||||||
|
ThisElem->Down=GetGridPos3d(X,Y+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UpdateWholeMap();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -39,8 +66,179 @@ void CLayerTile3d::shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
// Get (wrapped) PrimGrid pos
|
||||||
|
sPrimGridElem3d *CLayerTile3d::GetGridPos3d(int X,int Y)
|
||||||
|
{
|
||||||
|
sPrimGridElem3d *ThisGrid=(sPrimGridElem3d*)PrimGrid;
|
||||||
|
int Pos;
|
||||||
|
|
||||||
|
/**/ X%=PrimGridWidth;
|
||||||
|
/**/ Y%=PrimGridHeight;
|
||||||
|
/**/ Pos=(X+(Y*PrimGridWidth));
|
||||||
|
|
||||||
|
/**/ return(ThisGrid+Pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
// Get (wrapped) Map pos
|
||||||
|
sTileMapElem3d *CLayerTile3d::GetMapPos3d(int X,int Y)
|
||||||
|
{
|
||||||
|
sTileMapElem3d *ThisMap=(sTileMapElem3d*)Map;
|
||||||
|
int Pos;
|
||||||
|
|
||||||
|
/**/ X%=MapWidth;
|
||||||
|
/**/ Y%=MapHeight;
|
||||||
|
/**/ Pos=(X+(Y*MapWidth));
|
||||||
|
|
||||||
|
/**/ return(ThisMap+Pos);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
void CLayerTile3d::UpdateRow(int X,int Y)
|
||||||
|
{
|
||||||
|
sPrimGridElem3d *Grid=GetGridPos3d(X,Y);
|
||||||
|
sTileMapElem3d *MapPtr=GetMapPos3d(X,Y);
|
||||||
|
|
||||||
|
for (int i=0; i<SCREEN_TILE_WIDTH; i++)
|
||||||
|
{
|
||||||
|
// Tile prim
|
||||||
|
TSPRT_16 *Prim=&Grid->Prim;
|
||||||
|
/**/ sTile *Tile=&TileList[MapPtr->Tile];
|
||||||
|
/**/ setTSprtTPage(Prim,Tile->TPage);
|
||||||
|
*(u32*)&Prim->u0=*(u32*)&Tile->u0; // copy uv AND clut
|
||||||
|
/**/ Grid->Tile=MapPtr->Tile;
|
||||||
|
/**/ Grid->Flags=MapPtr->Flags;
|
||||||
|
// Next Elem
|
||||||
|
MapPtr++;
|
||||||
|
Grid=(sPrimGridElem3d *)Grid->Right;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
void CLayerTile3d::UpdateColumn(int X,int Y)
|
||||||
|
{
|
||||||
|
sPrimGridElem3d *Grid=GetGridPos3d(X,Y);
|
||||||
|
sTileMapElem3d *MapPtr=GetMapPos3d(X,Y);
|
||||||
|
|
||||||
|
for (int i=0; i<SCREEN_TILE_HEIGHT; i++)
|
||||||
|
{
|
||||||
|
// Tile prim
|
||||||
|
TSPRT_16 *Prim=&Grid->Prim;
|
||||||
|
/**/ sTile *Tile=&TileList[MapPtr->Tile];
|
||||||
|
/**/ setTSprtTPage(Prim,Tile->TPage);
|
||||||
|
*(u32*)&Prim->u0=*(u32*)&Tile->u0; // copy uv AND clut
|
||||||
|
/**/ Grid->Tile=MapPtr->Tile;
|
||||||
|
/**/ Grid->Flags=MapPtr->Flags;
|
||||||
|
// Next Elem
|
||||||
|
MapPtr+=MapWidth;
|
||||||
|
Grid=(sPrimGridElem3d *)Grid->Down;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
#define BLOCK_MULT 16
|
||||||
void CLayerTile3d::render()
|
void CLayerTile3d::render()
|
||||||
{
|
{
|
||||||
// CLayerTile::render();
|
|
||||||
CLayerTile::render3d();
|
sPrimGridElem3d *Grid=GetGridPos3d(MapX,MapY);
|
||||||
|
s16 TileX,TileY;
|
||||||
|
VECTOR BlkPos;
|
||||||
|
s32 BlkXStore;
|
||||||
|
|
||||||
|
// Setup shift bits of pos
|
||||||
|
TileY=-ShiftY;
|
||||||
|
BlkPos.vx=((-15*TILE_WIDTH)-ShiftX)*BLOCK_MULT;
|
||||||
|
BlkPos.vy=((-8*TILE_HEIGHT)-ShiftY)*BLOCK_MULT;
|
||||||
|
BlkXStore=BlkPos.vx;
|
||||||
|
|
||||||
|
// Render it!!
|
||||||
|
for (int Y=0; Y<SCREEN_TILE_HEIGHT; Y++)
|
||||||
|
{
|
||||||
|
sPrimGridElem *GridDown=(sPrimGridElem3d *)Grid->Down;
|
||||||
|
TileX=-ShiftX;
|
||||||
|
|
||||||
|
for (int X=0; X<SCREEN_TILE_WIDTH; X++)
|
||||||
|
{
|
||||||
|
TSPRT_16 *Prim=&Grid->Prim;
|
||||||
|
if (Prim->clut)
|
||||||
|
{ // Has 2d Data
|
||||||
|
/**/ Prim->x0=TileX;
|
||||||
|
/**/ Prim->y0=TileY;
|
||||||
|
/**/ AddPrim(OtPtr,Prim);
|
||||||
|
}
|
||||||
|
if (Grid->Flags)
|
||||||
|
{ // Has 3d Data
|
||||||
|
/**/ CMX_SetTransMtxXY(&BlkPos);
|
||||||
|
/**/ RenderBlock(Grid);
|
||||||
|
}
|
||||||
|
Grid=(sPrimGridElem3d *)Grid->Right;
|
||||||
|
TileX+=TILE_WIDTH;
|
||||||
|
BlkPos.vx+=TILE_WIDTH*BLOCK_MULT;
|
||||||
|
}
|
||||||
|
Grid=(sPrimGridElem3d *)GridDown;
|
||||||
|
TileY+=TILE_HEIGHT;
|
||||||
|
BlkPos.vx=BlkXStore;
|
||||||
|
BlkPos.vy+=TILE_HEIGHT*BLOCK_MULT;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
// 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
|
||||||
|
|
||||||
|
void CLayerTile3d::RenderBlock(sPrimGridElem3d *Elem)
|
||||||
|
{
|
||||||
|
sTile *Tile=&TileList[Elem->Tile];
|
||||||
|
u32 Flags=Elem->Flags;
|
||||||
|
sVtx *P0,*P1,*P2;
|
||||||
|
POLY_FT3 *TPrimPtr=(POLY_FT3*)GetPrimPtr();
|
||||||
|
u16 *TileTable=Tile->TileTable;
|
||||||
|
u32 T0,T1,T2;
|
||||||
|
sTri *TList=TriList+Tile->TriStart;
|
||||||
|
|
||||||
|
//--- Tris ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
for (int i=0; i<TILE3D_FLAGS_MAX; i++)
|
||||||
|
{
|
||||||
|
int TriCount=*TileTable++; // Get Tri Count
|
||||||
|
sTri *NextList=TList+TriCount;
|
||||||
|
if (Flags & 1)
|
||||||
|
{
|
||||||
|
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++;
|
||||||
|
addPrim(OtPtr,TPrimPtr);
|
||||||
|
gte_stsxy3_ft3(TPrimPtr);
|
||||||
|
TPrimPtr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TList=NextList;
|
||||||
|
Flags>>=1;
|
||||||
|
}
|
||||||
|
SetPrimPtr((u8*)TPrimPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,13 @@ public:
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void UpdateRow(int MapX,int MapY);
|
||||||
|
void UpdateColumn(int MapX,int MapY);
|
||||||
|
|
||||||
|
sPrimGridElem3d *GetGridPos3d(int X,int Y);
|
||||||
|
sTileMapElem3d *GetMapPos3d(int X,int Y);
|
||||||
|
|
||||||
|
void RenderBlock(sPrimGridElem3d *Elem);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,6 @@ void MainLoop()
|
||||||
#ifdef __USER_paul__
|
#ifdef __USER_paul__
|
||||||
s_paulScene.think(frames);
|
s_paulScene.think(frames);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(DrawSync(1));
|
while(DrawSync(1));
|
||||||
|
|
||||||
// Render States
|
// Render States
|
||||||
|
@ -159,8 +158,8 @@ void MainLoop()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PrimDisplay();
|
PrimDisplay();
|
||||||
VidSwapDraw();
|
|
||||||
VSync(0);
|
VSync(0);
|
||||||
|
VidSwapDraw();
|
||||||
|
|
||||||
PadUpdate();
|
PadUpdate();
|
||||||
|
|
||||||
|
|
|
@ -144,8 +144,6 @@ static void VidVSyncCallback()
|
||||||
TickCount++;
|
TickCount++;
|
||||||
if (DrawLoadIcon) LoadingIcon();
|
if (DrawLoadIcon) LoadingIcon();
|
||||||
|
|
||||||
PrimDrawCallBack();
|
|
||||||
|
|
||||||
if (VbFunc)
|
if (VbFunc)
|
||||||
{
|
{
|
||||||
VbFunc();
|
VbFunc();
|
||||||
|
|
Binary file not shown.
|
@ -93,29 +93,21 @@ struct sTri
|
||||||
u16 P2; // 2
|
u16 P2; // 2
|
||||||
}; // 16
|
}; // 16
|
||||||
|
|
||||||
// u8 r0, g0, b0, code; // 4
|
|
||||||
// u8 r1, g1, b1, Mat; // 4
|
|
||||||
// u8 r2, g2, b2; // 3
|
|
||||||
// s8 OtOfs; // 1
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
struct sQuad
|
struct sQuad
|
||||||
{
|
{
|
||||||
u16 P0,P1,P2,P3; // 8
|
u16 P0; // 2
|
||||||
|
u16 P1; // 2
|
||||||
|
u16 P2; // 2
|
||||||
|
u16 P3; // 2
|
||||||
u8 uv0[2]; // 2
|
u8 uv0[2]; // 2
|
||||||
|
u16 Clut; // 2
|
||||||
u8 uv1[2]; // 2
|
u8 uv1[2]; // 2
|
||||||
|
u16 TPage; // 2
|
||||||
u8 uv2[2]; // 2
|
u8 uv2[2]; // 2
|
||||||
u8 uv3[2]; // 2
|
u8 uv3[2]; // 2
|
||||||
u16 TPage; // 2
|
|
||||||
u16 Clut; // 2
|
|
||||||
}; // 20
|
}; // 20
|
||||||
|
|
||||||
// u8 r0, g0, b0, code; // 4
|
|
||||||
// u8 r1, g1, b1, Mat; // 4
|
|
||||||
// u8 r2, g2, b2; // 3
|
|
||||||
// s8 OtOfs; // 1
|
|
||||||
// u8 r3, g3, b3, Pad3; // 4
|
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
/*
|
/*
|
||||||
struct sWeight
|
struct sWeight
|
||||||
|
@ -152,29 +144,36 @@ enum TILE3D_FLAGS
|
||||||
struct sTileMapElem
|
struct sTileMapElem
|
||||||
{
|
{
|
||||||
u16 Tile;
|
u16 Tile;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sTileMapElem3d : public sTileMapElem
|
||||||
|
{
|
||||||
u16 Flags;
|
u16 Flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
struct sTileTable
|
struct sTileTable
|
||||||
{
|
{
|
||||||
u16 TriList;
|
u16 TriList;
|
||||||
u16 TriCount;
|
u16 TriCount;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
struct sTile
|
struct sTile
|
||||||
{
|
{
|
||||||
// 3d Tile
|
// 3d Tile
|
||||||
sTileTable TileTable[TILE3D_FLAGS_MAX];
|
// sTileTable TileTable[TILE3D_FLAGS_MAX]; // 20 (4*5)
|
||||||
|
u16 TriStart; // 2
|
||||||
|
u16 TileTable[TILE3D_FLAGS_MAX]; // 10
|
||||||
// 2d Tile
|
// 2d Tile
|
||||||
u8 u0,v0;
|
u8 u0,v0; // 2
|
||||||
u16 Clut;
|
u16 Clut; // 2
|
||||||
u16 TPage;
|
u16 TPage; // 2
|
||||||
u16 Pad; // :o( need this?
|
u16 Pad; // :o( need this? // 2
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
bool operator==(sTile const &v1) {return(false);}
|
bool operator==(sTile const &v1) {return(false);}
|
||||||
#endif
|
#endif
|
||||||
};
|
}; // 20
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// Layers
|
// Layers
|
||||||
|
|
Loading…
Add table
Reference in a new issue