This commit is contained in:
Daveo 2001-02-22 14:55:13 +00:00
parent d0780ad261
commit 6d989f8c1f
8 changed files with 94 additions and 329 deletions

View File

@ -1,6 +1,6 @@
/******************************/
/*** Solid Tile Layer Class ***/
/******************************/
/*************************/
/*** Shade Layer Class ***/
/*************************/
#include "system\global.h"
#include <DStructs.h>
@ -20,7 +20,6 @@ CLayerBack::CLayerBack(sLayerHdr *Hdr,sTile *TileList,sTri *TriList,sQuad *QuadL
Data=(sLayerShadeHdr*)MakePtr(Hdr,sizeof(sLayerHdr));
ASSERT(Data->Count<=LAYER_SHADE_RGB_MAX);
printf("%i Back Shades",Data->Count);
BandCount=Data->Count-1;
}
@ -33,11 +32,12 @@ CLayerBack::~CLayerBack()
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CLayerBack::init(DVECTOR &MapPos,int Shift,int Width,int Height)
void CLayerBack::init(DVECTOR &MapPos,int Shift)
{
MapXYShift=Shift;
BandHeight=(Height*16)/(BandCount);
BandHeight=(MapHeight*16)/(BandCount);
if (BandHeight>=512) BandHeight=511;
for (int i=0; i<BandCount; i++)
{
@ -47,7 +47,6 @@ void CLayerBack::init(DVECTOR &MapPos,int Shift,int Width,int Height)
setRGB2(&Band[i],Data->Data[i+1].RGB[0],Data->Data[i+1].RGB[1],Data->Data[i+1].RGB[2]);
setRGB3(&Band[i],Data->Data[i+1].RGB[0],Data->Data[i+1].RGB[1],Data->Data[i+1].RGB[2]);
}
}
/*****************************************************************************/
@ -56,9 +55,11 @@ void CLayerBack::shutdown()
}
/*****************************************************************************/
extern DVECTOR TileMapOfs;
void CLayerBack::think(DVECTOR &MapPos)
{
YOfs=MapPos.vy>>MapXYShift;
YOfs+=TileMapOfs.vy;
}
/*****************************************************************************/

View File

@ -13,7 +13,7 @@ public:
CLayerBack(sLayerHdr *Hdr,sTile *TileList,sTri *TriList,sQuad *QuadList,sVtx *VtxList);
~CLayerBack();
void init(DVECTOR &MapPos,int Shift,int Width,int Height);
void init(DVECTOR &MapPos,int Shift);
void shutdown();
void think(DVECTOR &MapPos);
void render();

View File

@ -15,6 +15,9 @@ const u32 YInc=16<<16;
/*****************************************************************************/
// Uses single buffer. Hopefully this will be adequate
// Changed from strip scroll to whole map update (cos of camera)
DVECTOR TileMapOfs={0,4}; // To line layers up :oP
/*****************************************************************************/
/*****************************************************************************/
@ -25,12 +28,12 @@ CLayerTile::CLayerTile(sLayerHdr *Hdr,sTile *_TileList,sTri *_TriList,sQuad *_Qu
MapWidth=LayerHdr->Width;
MapHeight=LayerHdr->Height;
printf("%i %i\n",MapWidth,MapHeight);
TileList=_TileList;
TriList=_TriList;
QuadList=_QuadList;
VtxList=_VtxList;
Map=(sTileMapElem*)MakePtr(Hdr,sizeof(sLayerHdr));
PrimGrid=0;
}
/*****************************************************************************/
@ -41,80 +44,15 @@ CLayerTile::~CLayerTile()
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CLayerTile::init(DVECTOR &MapPos,int Shift,int Width,int Height)
void CLayerTile::init(DVECTOR &MapPos,int Shift)
{
int Size=Width*Height;
ASSERT(Width>=SCREEN_TILE_WIDTH);
ASSERT(Height>=SCREEN_TILE_HEIGHT);
MapXYShift=Shift;
PrimGridWidth=Width;
PrimGridHeight=Height;
PrimGrid=(sPrimGridElem*) MemAlloc(Size*sizeof(sPrimGridElem),"2d PrimGrid");
ASSERT(PrimGrid);
MapX=0;
MapY=0;
for (int Y=0; Y<PrimGridHeight; Y++)
{
for (int X=0; X<PrimGridWidth; X++)
{
sPrimGridElem *ThisElem=GetGridPos(X,Y);
// Tile prim
setTSprt16(&ThisElem->Prim);
setTSetShadeTex(&ThisElem->Prim,1);
// Grid
ThisElem->Right=GetGridPos(X+1,Y);
ThisElem->Down=GetGridPos(X,Y+1);
}
}
UpdateWholeMap();
}
/*****************************************************************************/
// AS not time critical, use row update routine for whole map
void CLayerTile::UpdateWholeMap()
{
for (int Y=0; Y<PrimGridHeight; Y++)
{
UpdateRow(MapX,MapY+Y);
}
MapXY=MapPos;
}
/*****************************************************************************/
void CLayerTile::shutdown()
{
if (PrimGrid) MemFree(PrimGrid);
}
/*****************************************************************************/
// Get (wrapped) PrimGrid pos
sPrimGridElem *CLayerTile::GetGridPos(int X,int Y)
{
sPrimGridElem *ThisGrid=(sPrimGridElem *)PrimGrid;
int Pos;
/**/ X%=PrimGridWidth;
/**/ Y%=PrimGridHeight;
/**/ Pos=(X+(Y*PrimGridWidth));
/**/ return(ThisGrid+Pos);
}
/*****************************************************************************/
// Get (wrapped) Map pos
sTileMapElem *CLayerTile::GetMapPos(int X,int Y)
{
sTileMapElem *ThisMap=(sTileMapElem *)Map;
int Pos;
/**/ X%=MapWidth;
/**/ Y%=MapHeight;
/**/ Pos=(X+(Y*MapWidth));
/**/ return(ThisMap+Pos);
}
/*****************************************************************************/
@ -122,86 +60,28 @@ int Pos;
/*****************************************************************************/
void CLayerTile::think(DVECTOR &MapPos)
{
// Update rows and Columns :o)
// As these are on the borders, they 'shouldnt' alter any being rendered
int XPos=MapPos.vx>>MapXYShift;
int YPos=MapPos.vy>>MapXYShift;
int NewX=XPos>>4;
int NewY=YPos>>4;
MapXY.vx=XPos>>4;
MapXY.vy=YPos>>4;
/**/ MapXY.vx+=TileMapOfs.vx;
/**/ MapXY.vy+=TileMapOfs.vy;
ShiftX=XPos & 15;
ShiftY=YPos & 15;
//!!#ifdef __USER_paul__
MapX=NewX;
MapY=NewY;
UpdateWholeMap();
/*
#else
if (NewX>MapX)
{ // update right column
UpdateColumn(NewX+SCREEN_TILE_WIDTH-1,MapY);
MapX=NewX;
}
if (MapXY.vx+SCREEN_TILE_WIDTH<=MapWidth)
RenderW=SCREEN_TILE_WIDTH;
else
if (NewX<MapX)
{ // update left column
UpdateColumn(NewX,MapY);
MapX=NewX;
}
RenderW=MapWidth-MapXY.vx;
if (NewY>MapY)
{ // update bottom row
UpdateRow(MapX,NewY+SCREEN_TILE_HEIGHT-1);
MapY=NewY;
}
if (MapXY.vy+SCREEN_TILE_HEIGHT<=MapHeight)
RenderH=SCREEN_TILE_HEIGHT;
else
if (NewY<MapY)
{ // update top row
UpdateRow(MapX,NewY);
MapY=NewY;
}
#endif
*/
}
RenderH=MapHeight-MapXY.vy;
/*****************************************************************************/
void CLayerTile::UpdateRow(int X,int Y)
{
sPrimGridElem *Grid=GetGridPos(X,Y);
sTileMapElem *MapPtr=GetMapPos(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
// Next Elem
MapPtr++;
Grid=Grid->Right;
}
}
/*****************************************************************************/
void CLayerTile::UpdateColumn(int X,int Y)
{
sPrimGridElem *Grid=GetGridPos(X,Y);
sTileMapElem *MapPtr=GetMapPos(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
// Next Elem
MapPtr+=MapWidth;
Grid=Grid->Down;
}
}
/*****************************************************************************/
@ -209,32 +89,43 @@ sTileMapElem *MapPtr=GetMapPos(X,Y);
/*****************************************************************************/
void CLayerTile::render()
{
sPrimGridElem *Grid=GetGridPos(MapX,MapY);
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<SCREEN_TILE_HEIGHT; Y++)
for (int Y=0; Y<RenderH; Y++)
{
sPrimGridElem *GridDown=Grid->Down;
sTileMapElem *MapRow=MapPtr;
TileX=-ShiftX;
for (int X=0; X<SCREEN_TILE_WIDTH; X++)
for (int X=0; X<RenderW; X++)
{
TSPRT_16 *Prim=&Grid->Prim;
if (Prim->clut)
/**/ sTile *Tile=&TileList[MapRow->Tile];
if (Tile->Clut)
{
/**/ Prim->x0=TileX;
/**/ Prim->y0=TileY;
addPrimNoCheck(ThisOT,Prim);
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);
}
Grid=Grid->Right;
MapRow++;
TileX+=TILE_WIDTH;
}
Grid=GridDown;
MapPtr+=MapWidth;
TileY+=TILE_HEIGHT;
}
SetPrimPtr(PrimPtr);
}

View File

@ -9,20 +9,6 @@
#include "gfx\prim.h"
/*****************************************************************************/
struct sPrimGridElem
{
TSPRT_16 Prim;
sPrimGridElem *Right;
sPrimGridElem *Down;
};
struct sPrimGridElem3d : public sPrimGridElem
{
u16 Tile;
u16 Flags;
};
/*****************************************************************************/
const s32 LayerOT=MAX_OT-1;
@ -43,26 +29,23 @@ public:
{
TILE_WIDTH=16,
TILE_HEIGHT=16,
SCREEN_TILE_WIDTH=32,
SCREEN_TILE_HEIGHT=16,
SCREEN_TILE_WIDTH=34,
SCREEN_TILE_HEIGHT=18,
SCREEN_TILE_SIZE=SCREEN_TILE_WIDTH*SCREEN_TILE_HEIGHT
};
CLayerTile(sLayerHdr *Hdr,sTile *TileList,sTri *TriList,sQuad *QuadList,sVtx *VtxList);
virtual ~CLayerTile();
virtual void init(DVECTOR &MapPos,int Shift,int Width=SCREEN_TILE_WIDTH,int Height=SCREEN_TILE_HEIGHT);
virtual void init(DVECTOR &MapPos,int Shift);
virtual void shutdown();
virtual void think(DVECTOR &MapPos);
virtual void render();
int GetMapOfs() {return(MapXY.vx+(MapXY.vy*MapWidth));}
virtual sTileMapElem *GetMapPos() {return(Map+GetMapOfs());}
protected:
virtual void UpdateWholeMap();
virtual void UpdateRow(int MapX,int MapY);
virtual void UpdateColumn(int MapX,int MapY);
sPrimGridElem *GetGridPos(int X,int Y);
sTileMapElem *GetMapPos(int X,int Y);
sLayerHdr *LayerHdr;
sTile *TileList;
@ -71,14 +54,12 @@ virtual void UpdateColumn(int MapX,int MapY);
sVtx *VtxList;
int MapWidth,MapHeight,MapXYShift;
int PrimGridWidth,PrimGridHeight;
int RenderW,RenderH;
int MapX,MapY;
DVECTOR MapXY;
u16 ShiftX,ShiftY;
sTileMapElem *Map;
sPrimGridElem *PrimGrid;
};

View File

@ -28,44 +28,17 @@ CLayerTile3d::~CLayerTile3d()
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CLayerTile3d::init(DVECTOR &MapPos,int Shift,int Width,int Height)
void CLayerTile3d::init(DVECTOR &MapPos,int 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();
CLayerTile::init(MapPos,Shift);
CreateRenderFlagTable();
}
/*****************************************************************************/
void CLayerTile3d::shutdown()
{
MemFree(RenderFlagTable);
MemFree(PrimGrid);
}
/*****************************************************************************/
@ -103,83 +76,6 @@ s16 *Ptr;
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// 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;
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
@ -187,52 +83,58 @@ sTileMapElem3d *MapPtr=GetMapPos3d(X,Y);
void CLayerTile3d::render()
{
sPrimGridElem3d *Grid=GetGridPos3d(MapX,MapY);
sTileMapElem3d *MapPtr=GetMapPos3d();
u8 *PrimPtr=GetPrimPtr();
s16 TileX,TileY;
VECTOR BlkPos;
s32 BlkXStore;
sOT *ThisOT=OtPtr+LayerOT;
s16 *RenderFlags=RenderFlagTable;
// Setup shift bits of pos
TileY=-ShiftY;
BlkPos.vx=((-15*TILE_WIDTH)-ShiftX)*BLOCK_MULT;
// BlkPos.vy=((-8*TILE_HEIGHT)-ShiftY)*BLOCK_MULT;
BlkPos.vy=((-7*TILE_HEIGHT)-ShiftY)*BLOCK_MULT;
BlkXStore=BlkPos.vx;
// Render it!!
for (int Y=0; Y<SCREEN_TILE_HEIGHT; Y++)
for (int Y=0; Y<RenderH; Y++)
{
sPrimGridElem *GridDown=(sPrimGridElem3d *)Grid->Down;
sTileMapElem3d *MapRow=MapPtr;
TileX=-ShiftX;
for (int X=0; X<SCREEN_TILE_WIDTH; X++)
for (int X=0; X<RenderW; X++)
{
TSPRT_16 *Prim=&Grid->Prim;
if (Prim->clut)
{ // Has 2d Data
/**/ Prim->x0=TileX;
/**/ Prim->y0=TileY;
addPrimNoCheck(ThisOT,Prim);
/**/ 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);
}
if (Grid->Flags)
if (MapRow->Flags)
{ // Has 3d Data
/**/ CMX_SetTransMtxXY(&BlkPos);
/**/ RenderBlock(Grid,*RenderFlags);
CMX_SetTransMtxXY(&BlkPos);
PrimPtr=RenderBlock(Tile,MapRow->Flags & *RenderFlags,PrimPtr);
}
Grid=(sPrimGridElem3d *)Grid->Right;
MapRow++;
TileX+=TILE_WIDTH;
BlkPos.vx+=TILE_WIDTH*BLOCK_MULT;
RenderFlags++;
}
Grid=(sPrimGridElem3d *)GridDown;
MapPtr+=MapWidth;
TileY+=TILE_HEIGHT;
BlkPos.vx=BlkXStore;
BlkPos.vy+=TILE_HEIGHT*BLOCK_MULT;
}
SetPrimPtr(PrimPtr);
}
/*****************************************************************************/
@ -240,27 +142,22 @@ s16 *RenderFlags=RenderFlagTable;
// NOTE: Tiles are split into facing strips, to reduce overdraw :o)
// NOTE: Matrix already setup for block
void CLayerTile3d::RenderBlock(sPrimGridElem3d *Elem,s16 RenderFlags)
u8 *CLayerTile3d::RenderBlock(sTile *Tile,s16 RenderFlags,u8 *PrimPtr)
{
sTile *Tile=&TileList[Elem->Tile];
u32 Flags=Elem->Flags & RenderFlags;
sVtx *P0,*P1,*P2;
POLY_FT3 *TPrimPtr=(POLY_FT3*)GetPrimPtr();
POLY_FT3 *TPrimPtr=(POLY_FT3*)PrimPtr;
u16 *TileTable=Tile->TileTable;
u32 T0,T1,T2;
sTri *TList=TriList+Tile->TriStart;
sOT *ThisOT=OtPtr+LayerOT;
Flags=0xff & RenderFlags;
// Flags=0xff;// & RenderFlags;
//--- Tris ---------------------------------------------------------------------------
for (int i=0; i<TILE3D_FLAGS_MAX; i++)
{
int TriCount=*TileTable++; // Get Tri Count
sTri *NextList=TList+TriCount;
// if (Flags & 1)
// if (RenderFlags & 1)
{
while (TriCount--)
{
@ -285,8 +182,8 @@ sOT *ThisOT=OtPtr+LayerOT;
}
}
TList=NextList;
Flags>>=1;
RenderFlags>>=1;
}
SetPrimPtr((u8*)TPrimPtr);
}
return((u8*)TPrimPtr);
}

View File

@ -13,19 +13,15 @@ public:
CLayerTile3d(sLayerHdr *Hdr,sTile *TileList,sTri *TriList,sQuad *QuadList,sVtx *VtxList);
~CLayerTile3d();
void init(DVECTOR &MapPos,int Shift,int Width,int Height);
void init(DVECTOR &MapPos,int Shift);
void shutdown();
void render();
sTileMapElem3d *GetMapPos3d() {return(((sTileMapElem3d*)Map)+GetMapOfs());}
protected:
void CreateRenderFlagTable();
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,s16 RenderFlags);
u8 *RenderBlock(sTile *Tile,s16 RenderFlags,u8 *PrimPtr);
s16 *RenderFlagTable;

View File

@ -13,7 +13,6 @@
#include "level\level.h"
#include "level\layertile.h"
#include "level\layerback.h"
#include "level\layertilesolid.h"
#include "level\layertile3d.h"
#include "level\layercollision.h"

View File

@ -149,7 +149,7 @@ int MAP3D_CENTRE_Y=500;
int MAP3D_BLOCKSTEPSIZE=315;
int MAP2D_CENTRE_X=-256;
int MAP2D_CENTRE_Y=-136;
int MAP2D_CENTRE_Y=-136-(4*16);
int MAP2D_BLOCKSTEPSIZE=16;
int CAMERA_SCROLLLIMIT=8; // SB is this many tiles off centre at most