SBSPSS/source/gfx/actor.cpp

261 lines
6.3 KiB
C++
Raw Normal View History

2001-04-01 09:22:30 +02:00
/******************/
/*** Actor Bank ***/
/******************/
#include "system\global.h"
#include "mem\memory.h"
#include "fileio\fileio.h"
#include "utils\utils.h"
2001-04-01 22:22:49 +02:00
#include "utils\pak.h"
#include "gfx\prim.h"
2001-04-01 23:38:59 +02:00
#include "gfx\actor.h"
2001-04-01 09:22:30 +02:00
#include <dstructs.h>
/*****************************************************************************/
CActorGfx *CActorPool::ActorList[CActorPool::MAX_ACTORS];
2001-04-02 20:25:09 +02:00
u8 CActorPool::UnpackBuffer[CActorPool::MAX_ACTOR_SIZE];
2001-04-01 09:22:30 +02:00
/*****************************************************************************/
/*****************************************************************************/
2001-04-01 22:22:49 +02:00
/*****************************************************************************/
void CActorGfx::Init(FileEquate _Filename)
{
CActorPool::GetActor(Filename);
}
2001-04-02 00:55:15 +02:00
int DefTPX=512;
int DefTPY=256;
int ShadowXOfs=32;
int ShadowYOfs=32;
int TPInc=64;
2001-04-01 09:22:30 +02:00
/*****************************************************************************/
2001-04-02 00:55:15 +02:00
CActorGfx::CActorGfx(FileEquate _Filename,int Idx)
2001-04-01 09:22:30 +02:00
{
2001-04-01 22:22:49 +02:00
int i;
2001-04-02 00:55:15 +02:00
2001-04-01 09:22:30 +02:00
Filename=_Filename;
2001-04-02 00:55:15 +02:00
ActorNo=Idx;
2001-04-01 22:22:49 +02:00
SpriteBank=(sSpriteAnimBank*)CFileIO::loadFile(Filename);
2001-04-01 09:22:30 +02:00
2001-04-01 22:22:49 +02:00
SpriteBank->AnimList=(sSpriteAnim*) MakePtr(SpriteBank,(int)SpriteBank->AnimList);
SpriteBank->FrameList=(sSpriteFrame*) MakePtr(SpriteBank,(int)SpriteBank->FrameList);
SpriteBank->Palette=(u8*) MakePtr(SpriteBank,(int)SpriteBank->Palette);
// FixUp AnimList
2001-04-02 00:55:15 +02:00
DAVE_DBGMSG("Anims %i\n",SpriteBank->AnimCount);
2001-04-01 22:22:49 +02:00
for (i=0; i<SpriteBank->AnimCount; i++)
{
sSpriteAnim *ThisAnim=&SpriteBank->AnimList[i];
ThisAnim->Anim=(u16*) MakePtr(SpriteBank,(int)ThisAnim->Anim);
}
// FixUp FrameList
2001-04-02 00:55:15 +02:00
DAVE_DBGMSG("Anims %i\n",SpriteBank->FrameCount);
2001-04-01 22:22:49 +02:00
for (i=0; i<SpriteBank->FrameCount; i++)
2001-04-01 09:22:30 +02:00
{
2001-04-01 22:22:49 +02:00
sSpriteFrame *ThisFrame=&SpriteBank->FrameList[i];
ThisFrame->PAKSpr=(u8*) MakePtr(SpriteBank,(int)ThisFrame->PAKSpr);
2001-04-01 09:22:30 +02:00
}
2001-04-02 00:55:15 +02:00
TexX=DefTPX+(TPInc*ActorNo);
TexY=DefTPY+4;
ClutX=TexX;
ClutY=DefTPY;
// upload clut
RECT Rect;
Rect.x=ClutX;
Rect.y=ClutY;
Rect.w=SpriteBank->ColorCount;
Rect.h=1;
LoadImage( &Rect, (u32*)SpriteBank->Palette);
2001-04-01 09:22:30 +02:00
}
/*****************************************************************************/
CActorGfx::~CActorGfx()
{
2001-04-01 22:22:49 +02:00
MemFree(SpriteBank);
2001-04-01 09:22:30 +02:00
}
2001-04-02 20:25:09 +02:00
/*****************************************************************************/
sSpriteFrame *CActorGfx::GetFrame(int Anim,int Frame)
{
sSpriteAnim *ThisAnim=SpriteBank->AnimList+Anim;
u16 ThisFrame=ThisAnim->Anim[Frame];
return(SpriteBank->FrameList+ThisFrame);
}
/*****************************************************************************/
int CActorGfx::getFrameWidth(int Anim,int Frame)
{
sSpriteFrame *ThisFrame=GetFrame(Anim,Frame);
return(ThisFrame->W);
}
/*****************************************************************************/
int CActorGfx::getFrameHeight(int Anim,int Frame)
{
sSpriteFrame *ThisFrame=GetFrame(Anim,Frame);
return(ThisFrame->H);
}
2001-04-01 09:22:30 +02:00
/*****************************************************************************/
2001-04-01 23:38:59 +02:00
POLY_FT4 *CActorGfx::Render(DVECTOR &Pos,int Anim,int Frame,bool XFlip,bool YFlip,bool Shadow)
2001-04-01 09:22:30 +02:00
{
2001-04-02 20:25:09 +02:00
sSpriteFrame *FrameGfx=GetFrame(Anim,Frame);
2001-04-01 22:22:49 +02:00
2001-04-02 20:25:09 +02:00
PAK_doUnpak(CActorPool::UnpackBuffer,FrameGfx->PAKSpr);
2001-04-01 22:22:49 +02:00
// Gfx
2001-04-02 00:55:15 +02:00
RECT Rect;
Rect.x=TexX;
Rect.y=TexY;
2001-04-02 20:25:09 +02:00
Rect.w=FrameGfx->W/4;
Rect.h=FrameGfx->H;
LoadImage( &Rect, (u32*)CActorPool::UnpackBuffer);
2001-04-01 22:22:49 +02:00
2001-04-01 23:38:59 +02:00
POLY_FT4 *Ft4=GetPrimFT4();
2001-04-02 20:25:09 +02:00
SetUpFT4(Ft4,FrameGfx,Pos.vx,Pos.vy,XFlip,YFlip);
2001-04-01 23:38:59 +02:00
setRGB0(Ft4,128,128,128);
2001-04-02 00:55:15 +02:00
setTPage(Ft4,0,0,TexX,TexY);
setClut(Ft4, ClutX, ClutY);
2001-04-02 00:59:40 +02:00
AddPrimToList(Ft4,10);
2001-04-01 22:22:49 +02:00
2001-04-01 23:38:59 +02:00
if (Shadow)
{
POLY_FT4 *sFt4=GetPrimFT4();
*sFt4=*Ft4;
sFt4->x0-=ShadowXOfs;
sFt4->x1-=ShadowXOfs;
sFt4->y0+=ShadowYOfs;
sFt4->y1+=ShadowYOfs;
setSemiTrans(sFt4,1);
setRGB0(sFt4,0,0,0);
2001-04-02 00:59:40 +02:00
AddPrimToList(sFt4,10);
2001-04-01 23:38:59 +02:00
}
return(Ft4);
}
/*****************************************************************************/
void CActorGfx::SetUpFT4(POLY_FT4 *Ft4,sSpriteFrame *ThisFrame,int X,int Y,bool XFlip,bool YFlip)
{
int U=0;
int V=4;
int W=ThisFrame->W;
int H=ThisFrame->H;
2001-04-01 09:22:30 +02:00
2001-04-01 23:38:59 +02:00
if (XFlip)
{
Ft4->u0=U+W-1;
Ft4->u1=U;
Ft4->u2=U+W-1;
Ft4->u3=U;
}
else
{
Ft4->u0=U;
Ft4->u1=U+W;
Ft4->u2=U;
Ft4->u3=U+W;
}
if (YFlip)
{
Ft4->v0=V+H-1;
Ft4->v1=V+H-1;
Ft4->v2=V;
Ft4->v3=V;
}
else
{
Ft4->v0=V;
Ft4->v1=V;
Ft4->v2=V+H;
Ft4->v3=V+H;
}
2001-04-02 00:55:15 +02:00
X-=ThisFrame->XOfs;
Y-=ThisFrame->YOfs;
2001-04-01 23:38:59 +02:00
setXYWH(Ft4,X,Y,W,H);
2001-04-01 09:22:30 +02:00
}
2001-04-01 23:38:59 +02:00
2001-04-01 09:22:30 +02:00
/*****************************************************************************/
void CActorGfx::Dump()
{
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CActorPool::Init()
{
for (int i=0; i<MAX_ACTORS; i++)
{
ActorList[i]=0;
}
}
/*****************************************************************************/
int CActorPool::FindIdx(FileEquate Filename)
{
for (int i=0; i<MAX_ACTORS; i++)
{
if (ActorList[i] && ActorList[i]->GetFilename()==Filename) return(i);
}
return(-1);
}
/*****************************************************************************/
int CActorPool::FindFreeIdx()
{
for (int i=0; i<MAX_ACTORS; i++)
{
if (!ActorList[i]) return(i);
}
return(-1);
}
/*****************************************************************************/
/*** Load ********************************************************************/
/*****************************************************************************/
2001-04-02 20:25:09 +02:00
int ActorNo=0;
2001-04-01 09:22:30 +02:00
CActorGfx *CActorPool::GetActor(FileEquate Filename)
{
CActorGfx *NewActor;
int Idx;
2001-04-02 00:55:15 +02:00
2001-04-02 20:25:09 +02:00
Filename=(FileEquate)(ACTORS_SPONGEBOB_SBK+ActorNo);
2001-04-01 09:22:30 +02:00
// Already Loaded?
Idx=FindIdx(Filename);
if (Idx!=-1) return(ActorList[Idx]);
// Create and Load
Idx=FindFreeIdx();
ASSERT(Idx!=-1);
2001-04-02 00:55:15 +02:00
NewActor=new ("ActorPool") CActorGfx(Filename,Idx);
2001-04-01 09:22:30 +02:00
ActorList[Idx]=NewActor;
return(NewActor);
}
/*****************************************************************************/
/*** Dump ********************************************************************/
/*****************************************************************************/
void CActorPool::DumpActor(FileEquate Filename)
{
2001-04-01 22:22:49 +02:00
CActorGfx *ThisActor;
2001-04-01 09:22:30 +02:00
int Idx;
// Is Loaded?
Idx=FindIdx(Filename);
ASSERT(Idx!=-1);
ThisActor=ActorList[Idx];
ActorList[Idx]=0;
delete ThisActor;
}