From 6d989f8c1f70c3c7a4d5290172012e62c250131d Mon Sep 17 00:00:00 2001 From: Daveo Date: Thu, 22 Feb 2001 14:55:13 +0000 Subject: [PATCH] --- source/level/layerback.cpp | 15 +-- source/level/layerback.h | 2 +- source/level/layertile.cpp | 189 ++++++++--------------------------- source/level/layertile.h | 33 ++---- source/level/layertile3d.cpp | 169 ++++++------------------------- source/level/layertile3d.h | 12 +-- source/level/level.cpp | 1 - source/player/player.cpp | 2 +- 8 files changed, 94 insertions(+), 329 deletions(-) diff --git a/source/level/layerback.cpp b/source/level/layerback.cpp index d84f73ea9..7141f5ebc 100644 --- a/source/level/layerback.cpp +++ b/source/level/layerback.cpp @@ -1,6 +1,6 @@ -/******************************/ -/*** Solid Tile Layer Class ***/ -/******************************/ +/*************************/ +/*** Shade Layer Class ***/ +/*************************/ #include "system\global.h" #include @@ -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; iData[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; } /*****************************************************************************/ diff --git a/source/level/layerback.h b/source/level/layerback.h index cb646891c..858be2fb9 100644 --- a/source/level/layerback.h +++ b/source/level/layerback.h @@ -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(); diff --git a/source/level/layertile.cpp b/source/level/layertile.cpp index 1b726df67..3428efb58 100644 --- a/source/level/layertile.cpp +++ b/source/level/layertile.cpp @@ -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; YPrim); - 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>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 (NewXMapY) - { // 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 (NewYPrim; -/**/ 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; iPrim; -/**/ 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; YDown; + sTileMapElem *MapRow=MapPtr; TileX=-ShiftX; - for (int X=0; XPrim; - 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); + } diff --git a/source/level/layertile.h b/source/level/layertile.h index 4f8fd448d..101cff0f6 100644 --- a/source/level/layertile.h +++ b/source/level/layertile.h @@ -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; - }; diff --git a/source/level/layertile3d.cpp b/source/level/layertile3d.cpp index c413640fa..5fdb9f5e3 100644 --- a/source/level/layertile3d.cpp +++ b/source/level/layertile3d.cpp @@ -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; YPrim); - 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; iPrim; -/**/ 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; iPrim; -/**/ 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; YDown; + sTileMapElem3d *MapRow=MapPtr; TileX=-ShiftX; - for (int X=0; XPrim; - 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>=1; + RenderFlags>>=1; } - SetPrimPtr((u8*)TPrimPtr); -} + return((u8*)TPrimPtr); +} diff --git a/source/level/layertile3d.h b/source/level/layertile3d.h index 7c6e74432..7c7900d61 100644 --- a/source/level/layertile3d.h +++ b/source/level/layertile3d.h @@ -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; diff --git a/source/level/level.cpp b/source/level/level.cpp index dfb04de5d..752f43677 100644 --- a/source/level/level.cpp +++ b/source/level/level.cpp @@ -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" diff --git a/source/player/player.cpp b/source/player/player.cpp index 1daf023b5..3e57b3884 100644 --- a/source/player/player.cpp +++ b/source/player/player.cpp @@ -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