SBSPSS/source/level/layerback.cpp

293 lines
7.7 KiB
C++
Raw Normal View History

2001-02-22 15:55:13 +01:00
/*************************/
/*** Shade Layer Class ***/
/*************************/
2001-01-13 18:04:56 +01:00
#include "system\global.h"
#include <DStructs.h>
#include "utils\utils.h"
#include "gfx\prim.h"
2001-03-09 22:17:14 +01:00
#include "gfx\sprbank.h"
2001-01-13 18:04:56 +01:00
#include "LayerTile.h"
2001-01-15 16:22:33 +01:00
#include "LayerBack.h"
2001-01-13 18:04:56 +01:00
2001-04-04 02:16:26 +02:00
#include "Game\game.h"
2001-03-09 22:17:14 +01:00
2001-03-09 23:10:53 +01:00
sBackRGBTable CLayerBack::BackRGBTable[]=
2001-03-09 22:17:14 +01:00
{
{255, 0, 0,0},
{255,255, 0,0},
{ 0,255, 0,0},
{ 0,255,255,0},
{ 0, 0,255,0},
{255, 0,255,0},
{255,255,255,0},
{128, 0, 0,0},
{128,128, 0,0},
{ 0,128, 0,0},
{ 0,128,128,0},
{ 0, 0,128,0},
{128, 0,128,0},
{128,128,128,0},
};
#define BackRGBTableSize sizeof(BackRGBTable)/sizeof(sBackRGBTable)
2001-01-13 18:04:56 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-04-19 17:12:21 +02:00
CLayerBack::CLayerBack(sLevelHdr *LevelHdr,sLayerHdr *Hdr) : CLayerTile(LevelHdr,Hdr)
2001-01-13 18:04:56 +01:00
{
2001-02-20 20:17:03 +01:00
Data=(sLayerShadeHdr*)MakePtr(Hdr,sizeof(sLayerHdr));
2001-02-20 16:56:16 +01:00
2001-04-30 23:49:54 +02:00
ASSERT(Data->BandCount<=LAYER_SHADE_RGB_MAX);
BandCount=Data->BandCount-1;
2001-04-07 23:17:27 +02:00
// Setup back gfx
2001-04-30 23:49:54 +02:00
/*
2001-04-07 23:17:27 +02:00
for (int i=0; i<SPRITE_MAX; i++)
{
int Type=i&1;
POLY_GT4 *Gt4=&SpriteList[i].Poly;
SpriteList[i].Type=Type;
setPolyGT4(Gt4);
Gt4->tpage=Data->BackGfx[Type].TPage;
Gt4->clut=Data->BackGfx[Type].Clut;
setUVWH(Gt4,Data->BackGfx[Type].U,Data->BackGfx[Type].V,Data->BackGfx[Type].W,Data->BackGfx[Type].H);
SpriteList[i].W=Data->BackGfx[Type].W;
SpriteList[i].H=Data->BackGfx[Type].H;
setSemiTrans(Gt4,1);
Gt4->u1--; Gt4->u3--;
Gt4->v2--; Gt4->v3--;
// Init all
setRGB0(Gt4,255,255,255);
setRGB1(Gt4,255,255,255);
setRGB2(Gt4,255,255,255);
setRGB3(Gt4,255,255,255);
SpriteList[i].Angle=0;
SpriteList[i].AngleInc=0;
SpriteList[i].PosInc.vx=0;
SpriteList[i].PosInc.vy=0;
SpriteList[i].Scale.vx=1024;
SpriteList[i].Scale.vy=1024;
SpriteList[i].ScaleInc.vx=0;
SpriteList[i].ScaleInc.vy=0;
InitSprite(&SpriteList[i]);
SpriteList[i].Pos.vx=getRndRange(512<<MOVE_SHIFT);
SpriteList[i].Pos.vy=getRndRange(256<<MOVE_SHIFT);
}
2001-04-30 23:49:54 +02:00
*/
2001-03-09 22:17:14 +01:00
2001-01-13 18:04:56 +01:00
}
/*****************************************************************************/
2001-01-15 16:22:33 +01:00
CLayerBack::~CLayerBack()
2001-01-13 18:04:56 +01:00
{
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-02-22 15:55:13 +01:00
void CLayerBack::init(DVECTOR &MapPos,int Shift)
2001-01-13 18:04:56 +01:00
{
2001-02-20 20:17:03 +01:00
MapXYShift=Shift;
2001-02-22 15:55:13 +01:00
BandHeight=(MapHeight*16)/(BandCount);
if (BandHeight>=512) BandHeight=511;
2001-02-20 20:17:03 +01:00
for (int i=0; i<BandCount; i++)
{
SetPolyG4(&Band[i]);
2001-04-30 23:49:54 +02:00
setRGB0(&Band[i],Data->RGB[i+0][0],Data->RGB[i+0][1],Data->RGB[i+0][2]);
setRGB1(&Band[i],Data->RGB[i+0][0],Data->RGB[i+0][1],Data->RGB[i+0][2]);
setRGB2(&Band[i],Data->RGB[i+1][0],Data->RGB[i+1][1],Data->RGB[i+1][2]);
setRGB3(&Band[i],Data->RGB[i+1][0],Data->RGB[i+1][1],Data->RGB[i+1][2]);
2001-02-20 20:17:03 +01:00
}
2001-03-09 22:17:14 +01:00
2001-03-09 23:10:53 +01:00
PosDx=0;
PosDy=0;
XOfs=MapPos.vy;
YOfs=MapPos.vy;
}
2001-01-13 18:04:56 +01:00
/*****************************************************************************/
2001-01-15 16:22:33 +01:00
void CLayerBack::shutdown()
2001-01-13 18:04:56 +01:00
{
}
2001-03-09 22:17:14 +01:00
/*****************************************************************************/
void CLayerBack::InitSprite(sBackSprite *SpritePtr)
{
2001-04-30 23:49:54 +02:00
/*
2001-03-09 22:17:14 +01:00
int StartPos=getRnd();
int Pos=getRnd();
2001-03-12 20:23:41 +01:00
int XInc=(getRndRange((1<<((MOVE_SHIFT*1)/3))-1)+1)<<MOVE_SHIFT;
int YInc=(getRndRange((1<<((MOVE_SHIFT*1)/3))-1)+1)<<MOVE_SHIFT;
2001-03-09 22:17:14 +01:00
2001-04-07 23:17:27 +02:00
if (Data->BackGfx[SpritePtr->Type].Flags & MOVE)
2001-04-12 19:19:20 +02:00
if (0)
2001-03-09 22:17:14 +01:00
{
2001-03-09 23:10:53 +01:00
switch(StartPos&3)
{
case 0: // Left
SpritePtr->Pos.vx=-63;
SpritePtr->Pos.vy=(Pos%(256+128))-63;
SpritePtr->PosInc.vx=XInc;
if (XInc&1)
SpritePtr->PosInc.vy=+YInc;
else
SpritePtr->PosInc.vy=-YInc;
break;
case 1: // Right
SpritePtr->Pos.vx=512+63;
SpritePtr->Pos.vy=(Pos%(256+128))-63;
2001-03-09 22:17:14 +01:00
SpritePtr->PosInc.vx=-XInc;
2001-03-09 23:10:53 +01:00
if (XInc&1)
SpritePtr->PosInc.vy=+YInc;
else
SpritePtr->PosInc.vy=-YInc;
break;
case 2: // Top
SpritePtr->Pos.vx=(Pos%(512+128))-63;
SpritePtr->Pos.vy=-63;
if (YInc&1)
SpritePtr->PosInc.vx=+XInc;
else
SpritePtr->PosInc.vx=-XInc;
SpritePtr->PosInc.vy=YInc;
break;
case 3: // Bottom
SpritePtr->Pos.vx=(Pos%(512+128))-63;
SpritePtr->Pos.vy=256+63;
if (YInc&1)
SpritePtr->PosInc.vx=+XInc;
else
SpritePtr->PosInc.vx=-XInc;
SpritePtr->PosInc.vy=-YInc;
break;
}
SpritePtr->Pos.vx<<=MOVE_SHIFT;
SpritePtr->Pos.vy<<=MOVE_SHIFT;
2001-03-09 22:17:14 +01:00
}
2001-04-07 23:17:27 +02:00
if (Data->BackGfx[SpritePtr->Type].Flags & SCALE)
2001-04-12 19:19:20 +02:00
if (0)
2001-03-09 23:10:53 +01:00
{
SpritePtr->Scale.vx=getRndRange(4095);
SpritePtr->Scale.vy=getRndRange(4095);
SpritePtr->ScaleInc.vx=getRndRange(31)+31;
if (SpritePtr->ScaleInc.vx&1) SpritePtr->ScaleInc.vx=-SpritePtr->ScaleInc.vx;
SpritePtr->ScaleInc.vy=getRndRange(31)+31;
if (SpritePtr->ScaleInc.vy&1) SpritePtr->ScaleInc.vy=-SpritePtr->ScaleInc.vy;
}
2001-04-07 23:17:27 +02:00
if (Data->BackGfx[SpritePtr->Type].Flags & SPIN)
2001-04-12 19:19:20 +02:00
if (0)
2001-03-09 23:10:53 +01:00
{
SpritePtr->AngleInc=getRndRange(31)+31;
if (SpritePtr->AngleInc&1) SpritePtr->AngleInc=-SpritePtr->AngleInc;
}
2001-03-09 22:17:14 +01:00
2001-04-07 23:17:27 +02:00
if (Data->BackGfx[SpritePtr->Type].Flags & COLOR)
2001-03-09 23:10:53 +01:00
{
2001-03-09 22:17:14 +01:00
int i;
i=getRndRange(BackRGBTableSize-1); SpritePtr->Poly.r0=BackRGBTable[i].R; SpritePtr->Poly.g0=BackRGBTable[i].G; SpritePtr->Poly.b0=BackRGBTable[i].B;
i=getRndRange(BackRGBTableSize-1); SpritePtr->Poly.r1=BackRGBTable[i].R; SpritePtr->Poly.g1=BackRGBTable[i].G; SpritePtr->Poly.b1=BackRGBTable[i].B;
i=getRndRange(BackRGBTableSize-1); SpritePtr->Poly.r2=BackRGBTable[i].R; SpritePtr->Poly.g2=BackRGBTable[i].G; SpritePtr->Poly.b2=BackRGBTable[i].B;
i=getRndRange(BackRGBTableSize-1); SpritePtr->Poly.r3=BackRGBTable[i].R; SpritePtr->Poly.g3=BackRGBTable[i].G; SpritePtr->Poly.b3=BackRGBTable[i].B;
2001-03-09 23:10:53 +01:00
}
2001-04-30 23:49:54 +02:00
*/
2001-03-09 22:17:14 +01:00
}
2001-01-13 18:04:56 +01:00
/*****************************************************************************/
2001-04-19 01:04:03 +02:00
//extern DVECTOR TileMapOfs;
2001-01-15 16:22:33 +01:00
void CLayerBack::think(DVECTOR &MapPos)
2001-02-20 16:56:16 +01:00
{
2001-03-09 22:17:14 +01:00
int _XOfs=MapPos.vx>>MapXYShift;
int _YOfs=MapPos.vy>>MapXYShift;
2001-04-19 01:04:03 +02:00
// _YOfs+=TileMapOfs.vy;
2001-03-09 22:17:14 +01:00
PosDx=(_XOfs-XOfs)<<MOVE_SHIFT;
PosDy=(_YOfs-YOfs)<<MOVE_SHIFT;
XOfs=_XOfs;
YOfs=_YOfs;
2001-05-02 01:27:30 +02:00
if (YOfs<1) YOfs=1;
2001-01-13 18:04:56 +01:00
}
/*****************************************************************************/
2001-03-09 22:17:14 +01:00
int Tran=0;
2001-01-15 16:22:33 +01:00
void CLayerBack::render()
2001-01-13 18:04:56 +01:00
{
2001-03-09 22:17:14 +01:00
const int OTPos=(MAX_OT-1);
sOT *ThisOT=OtPtr+OTPos;
int i,ThisY=-YOfs;
2001-04-30 23:49:54 +02:00
/*
2001-03-09 22:17:14 +01:00
// Render Back Sprites
2001-04-28 01:05:14 +02:00
#if 0
2001-03-09 22:17:14 +01:00
sBackSprite *SpritePtr=SpriteList;
2001-04-28 01:05:14 +02:00
2001-03-09 22:17:14 +01:00
for (i=0; i<SPRITE_MAX; i++)
{
SpritePtr->Pos.vx+=SpritePtr->PosInc.vx;
SpritePtr->Pos.vy+=SpritePtr->PosInc.vy;
SpritePtr->Pos.vx-=PosDx;
SpritePtr->Pos.vy-=PosDy;
SpritePtr->Angle+=SpritePtr->AngleInc;
SpritePtr->Angle&=4095;
SpritePtr->Scale.vx+=SpritePtr->ScaleInc.vx;
SpritePtr->Scale.vx&=4095;
SpritePtr->Scale.vy+=SpritePtr->ScaleInc.vy;
SpritePtr->Scale.vy&=4095;
int X=(SpritePtr->Pos.vx>>MOVE_SHIFT);
int Y=(SpritePtr->Pos.vy>>MOVE_SHIFT);
if (X<-64 || X>512+64 || Y<-64 || Y>256+64)
{
InitSprite(SpritePtr);
}
POLY_GT4 *Gt4=&SpriteList[i].Poly;
int ScaleX=msin(SpritePtr->Scale.vx);
int ScaleY=msin(SpritePtr->Scale.vy);
Gt4->tpage|=Tran<<5;
sBox Box;
2001-04-07 23:17:27 +02:00
RotateBox(&Box,SpritePtr->W,SpritePtr->W,ScaleX,ScaleY,SpritePtr->Angle);
2001-03-09 22:17:14 +01:00
Gt4->x0=X+Box.x0; Gt4->y0=Y+Box.y0;
Gt4->x1=X+Box.x1; Gt4->y1=Y+Box.y1;
Gt4->x2=X+Box.x2; Gt4->y2=Y+Box.y2;
Gt4->x3=X+Box.x3; Gt4->y3=Y+Box.y3;
AddPrim(ThisOT,Gt4);
SpritePtr++;
}
2001-04-28 01:05:14 +02:00
#endif
2001-04-30 23:49:54 +02:00
*/
2001-03-09 22:17:14 +01:00
// Render Back Shade
2001-05-02 01:27:30 +02:00
2001-03-09 22:17:14 +01:00
for (i=0; i<BandCount; i++)
2001-02-20 20:17:03 +01:00
{
2001-04-28 01:05:14 +02:00
setXYWH(&Band[i],0,ThisY,512,BandHeight*2);
2001-02-20 20:17:03 +01:00
addPrim(ThisOT,&Band[i]);
ThisY+=BandHeight;
}
2001-04-28 01:05:14 +02:00
if (Band[BandCount-1].y1<0)
{
Band[BandCount-1].y0=0;
Band[BandCount-1].y1=0;
Band[BandCount-1].y2=256;
Band[BandCount-1].y3=256;
}
2001-01-13 18:04:56 +01:00
}