This commit is contained in:
Daveo 2001-04-09 21:27:21 +00:00
parent 3dfa898b73
commit 944a38a726
6 changed files with 331 additions and 156 deletions

View File

@ -221,7 +221,7 @@ void CNpcEnemy::CacheActor(int Type)
{ {
int m_type = mapEditConvertTable[Type - NPC_ENEMY_MAPEDIT_OFFSET]; int m_type = mapEditConvertTable[Type - NPC_ENEMY_MAPEDIT_OFFSET];
CActorPool::GetActor(m_data[m_type].skelType); CActorPool::AddActor(m_data[m_type].skelType);
} }

View File

@ -12,6 +12,10 @@
#include <dstructs.h> #include <dstructs.h>
/*****************************************************************************/
int ShadowXOfs=32;
int ShadowYOfs=32;
/*****************************************************************************/ /*****************************************************************************/
CActorPool::ACTOR_TYPE CActorPool::actorType[38] = CActorPool::ACTOR_TYPE CActorPool::actorType[38] =
@ -57,69 +61,261 @@ CActorPool::ACTOR_TYPE CActorPool::actorType[38] =
}; };
/*****************************************************************************/ /*****************************************************************************/
CActorGfx *CActorPool::ActorList[CActorPool::MAX_ACTORS]; sActorPool CActorPool::ActorPool[MAX_ACTORS];
u8 CActorPool::UnpackBuffer[CActorPool::MAX_ACTOR_SIZE];
CSlotCache CActorGfx::SlotCache;
u8 CActorGfx::UnpackBuffer[CActorPool::MAX_ACTOR_SIZE];
/*****************************************************************************/ /*****************************************************************************/
/*** Slot Cache **************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ void CSlotCache::Init()
void CActorGfx::Init(FileEquate _Filename)
{ {
CActorPool::GetActor(Filename); for (int Y=0; Y<DYN_SLOTH; Y++)
{
for (int X=0; X<DYN_SLOTW; X++)
{
Cache[X][Y].W=0;
}
}
} }
int DefTPX=512; /*****************************************************************************/
int DefTPY=256; bool CSlotCache::FindSlot(int SprW,int SprH,u16 &TexX,u16 &TexY,u8 &u,u8 &v)
int ShadowXOfs=32; {
int ShadowYOfs=32; int W=(SprW+(DYN_W-1))/DYN_W;
int TPInc=64; int H=(SprH+(DYN_H-1))/DYN_H;
for (int Y=0; Y<DYN_SLOTH; Y++)
{
for (int X=0; X<DYN_SLOTW; X++)
{
if (TakeSlot(X,Y,W,H))
{
printf("TakeSlot %i %i\n",X,Y);
TexX=DYN_SLOTX+(X*DYN_W/4);
TexY=DYN_SLOTY+(Y*DYN_H);
u=(X&3)*64;
v=(Y&3)*64;
return(true);
}
}
}
return(false);
}
/*****************************************************************************/ /*****************************************************************************/
CActorGfx::CActorGfx(FileEquate _Filename,int Idx) bool CSlotCache::TakeSlot(int SX,int SY,int SW,int SH)
{
int W,H;
if (SX+SW>DYN_SLOTW) return(false);
if (SY+SH>DYN_SLOTH) return(false);
if ((SX&3)==3 && SW>1) return(false);
for (H=0; H<SH; H++)
{
for (W=0; W<SW; W++)
{
if (Cache[SX+W][SY+H].W) return(false);
}
}
// Slot good
for (H=0; H<SH; H++)
{
for (W=0; W<SW; W++)
{
Cache[SX+W][SY+H].W=SW;
Cache[SX+W][SY+H].H=SH;
}
}
return(true);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CActorPool::Init()
{
int i;
for (i=0; i<MAX_ACTORS; i++)
{
ActorPool[i].SpriteBank=0;
}
CActorGfx::ResetCache();
}
/*****************************************************************************/
int CActorPool::FindActorInPool(FileEquate Filename)
{
for (int i=0; i<MAX_ACTORS; i++)
{
if (ActorPool[i].SpriteBank && ActorPool[i].Filename==Filename) return(i);
}
return(-1);
}
/*****************************************************************************/
int CActorPool::FindFreeActor()
{
for (int i=0; i<MAX_ACTORS; i++)
{
if (ActorPool[i].SpriteBank==0) return(i);
}
return(-1);
}
/*****************************************************************************/
int CActorPool::LoadActor(FileEquate Filename)
{ {
int i; int i;
Filename=_Filename; sSpriteAnimBank *Spr=(sSpriteAnimBank*)CFileIO::loadFile(Filename);
ActorNo=Idx;
SpriteBank=(sSpriteAnimBank*)CFileIO::loadFile(Filename);
SpriteBank->AnimList=(sSpriteAnim*) MakePtr(SpriteBank,(int)SpriteBank->AnimList); Spr->AnimList=(sSpriteAnim*) MakePtr(Spr,(int)Spr->AnimList);
SpriteBank->FrameList=(sSpriteFrame*) MakePtr(SpriteBank,(int)SpriteBank->FrameList); Spr->FrameList=(sSpriteFrame*) MakePtr(Spr,(int)Spr->FrameList);
SpriteBank->Palette=(u8*) MakePtr(SpriteBank,(int)SpriteBank->Palette); Spr->Palette=(u8*) MakePtr(Spr,(int)Spr->Palette);
// FixUp AnimList // FixUp AnimList
DAVE_DBGMSG("Anims %i\n",SpriteBank->AnimCount); DAVE_DBGMSG("Anims %i\n",Spr->AnimCount);
for (i=0; i<SpriteBank->AnimCount; i++) for (i=0; i<Spr->AnimCount; i++)
{ {
sSpriteAnim *ThisAnim=&SpriteBank->AnimList[i]; sSpriteAnim *ThisAnim=&Spr->AnimList[i];
ThisAnim->Anim=(u16*) MakePtr(SpriteBank,(int)ThisAnim->Anim); ThisAnim->Anim=(u16*) MakePtr(Spr,(int)ThisAnim->Anim);
} }
// FixUp FrameList // FixUp FrameList
DAVE_DBGMSG("Anims %i\n",SpriteBank->FrameCount); DAVE_DBGMSG("Anims %i\n",Spr->FrameCount);
for (i=0; i<SpriteBank->FrameCount; i++) for (i=0; i<Spr->FrameCount; i++)
{ {
sSpriteFrame *ThisFrame=&SpriteBank->FrameList[i]; sSpriteFrame *ThisFrame=&Spr->FrameList[i];
ThisFrame->PAKSpr=(u8*) MakePtr(SpriteBank,(int)ThisFrame->PAKSpr); ThisFrame->PAKSpr=(u8*) MakePtr(Spr,(int)ThisFrame->PAKSpr);
} }
TexX=DefTPX+(TPInc*ActorNo); // Store it
TexY=DefTPY+4; int Idx=FindFreeActor();
ClutX=TexX; ASSERT(Idx!=-1);
ClutY=DefTPY;
// upload clut sActorPool &ThisActor=ActorPool[Idx];
RECT Rect;
Rect.x=ClutX; ThisActor.Filename=Filename;
Rect.y=ClutY; ThisActor.SpriteBank=Spr;
Rect.w=SpriteBank->ColorCount; ThisActor.RefCount=1;
Rect.h=1; ThisActor.Clut=LoadPalette(ThisActor,Idx);
LoadImage( &Rect, (u32*)SpriteBank->Palette);
return(Idx);
}
/*****************************************************************************/
#define DYN_PALW 64
#define DYN_PALH 1
#define DYN_PALX DYN_PALW*(8+4)
#define DYN_PALY 511
u16 CActorPool::LoadPalette(sActorPool &ThisActor,int Idx)
{
RECT R;
R.x=DYN_PALX+(Idx*DYN_PALW);
R.y=DYN_PALY;
R.w=DYN_PALW;
R.h=DYN_PALH;
LoadImage( &R, (u32*)ThisActor.SpriteBank->Palette);
int Clut=getClut(R.x,R.y);
return(Clut);
}
/*****************************************************************************/
void CActorPool::AddActor(FileEquate Filename)
{
sActorPool *Actor;
int Idx=FindActorInPool(Filename);
if (Idx!=-1) return;
// Load it
LoadActor(Filename);
}
/*****************************************************************************/
CActorGfx *CActorPool::GetActor(FileEquate Filename)
{
CActorGfx *Actor;
int Idx;
// Find Actor in Pool
Idx=FindActorInPool(Filename);
if (Idx==-1) ASSERT(!"Actor Not Loaded");
sActorPool &ThisActor=ActorPool[Idx];
Actor=new ("CActorGfx") CActorGfx;
Actor->SetData(Filename,ThisActor.SpriteBank,ThisActor.Clut);
ThisActor.RefCount++;
return(Actor);
}
/*****************************************************************************/
/*** Dump ********************************************************************/
/*****************************************************************************/
// Dumps all apart from spongeybob
void CActorPool::DumpActors()
{
for (int i=0; i<MAX_ACTORS; i++)
{
if (ActorPool[i].SpriteBank && ActorPool[i].Filename!=ACTORS_SPONGEBOB_SBK)
{
if (ActorPool[i].SpriteBank) MemFree(ActorPool[i].SpriteBank);
ActorPool[i].SpriteBank=0;
}
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CActorGfx::CActorGfx()
{
} }
/*****************************************************************************/ /*****************************************************************************/
CActorGfx::~CActorGfx() CActorGfx::~CActorGfx()
{ {
Dump(); }
/*****************************************************************************/
void CActorGfx::SetData(FileEquate Filename,sSpriteAnimBank *_SpriteBank,u16 _Clut)
{
SpriteBank=_SpriteBank;
Clut=_Clut;
if (Filename!=ACTORS_SPONGEBOB_SBK)
{
bool SlotStatus=SlotCache.FindSlot(_SpriteBank->MaxW,_SpriteBank->MaxH,TexX,TexY,U,V);
ASSERT(SlotStatus);
}
else
{
TexX=512;
TexY=256;
U=0;
V=0;
}
TPage=getTPage(0,0,TexX,TexY);
}
/*****************************************************************************/
void CActorGfx::ResetCache()
{
RECT R;
SlotCache.Init();
R.x=512;
R.y=256;
R.w=512;
R.h=250;
ClearImage(&R,0,255,0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -132,25 +328,26 @@ u16 ThisFrame=ThisAnim->Anim[Frame];
} }
/*****************************************************************************/ /*****************************************************************************/
POLY_FT4 *CActorGfx::Render(DVECTOR &Pos,int Anim,int Frame,bool XFlip,bool YFlip,bool Shadow) POLY_FT4 *CActorGfx::Render(DVECTOR &Pos,int Anim,int Frame,bool XFlip,bool YFlip,bool Shadow)
{ {
sSpriteFrame *FrameGfx=GetFrame(Anim,Frame); sSpriteFrame *FrameGfx=GetFrame(Anim,Frame);
PAK_doUnpak(CActorPool::UnpackBuffer,FrameGfx->PAKSpr); PAK_doUnpak(UnpackBuffer,FrameGfx->PAKSpr);
// Gfx // Gfx
RECT Rect; RECT Rect;
Rect.x=TexX; Rect.x=TexX;
Rect.y=TexY; Rect.y=TexY;
Rect.w=FrameGfx->W/4; Rect.w=FrameGfx->W/4;
Rect.h=FrameGfx->H; Rect.h=FrameGfx->H;
LoadImage( &Rect, (u32*)UnpackBuffer);
LoadImage( &Rect, (u32*)CActorPool::UnpackBuffer);
POLY_FT4 *Ft4=GetPrimFT4(); POLY_FT4 *Ft4=GetPrimFT4();
SetUpFT4(Ft4,FrameGfx,Pos.vx,Pos.vy,XFlip,YFlip); SetUpFT4(Ft4,FrameGfx,Pos.vx,Pos.vy,XFlip,YFlip);
setRGB0(Ft4,128,128,128); setRGB0(Ft4,128,128,128);
setTPage(Ft4,0,0,TexX,TexY); Ft4->tpage=TPage;
setClut(Ft4, ClutX, ClutY); Ft4->clut=Clut;
AddPrimToList(Ft4,10); AddPrimToList(Ft4,10);
if (Shadow) if (Shadow)
@ -172,10 +369,8 @@ POLY_FT4 *Ft4=GetPrimFT4();
/*****************************************************************************/ /*****************************************************************************/
void CActorGfx::SetUpFT4(POLY_FT4 *Ft4,sSpriteFrame *Frame,int X,int Y,bool XFlip,bool YFlip) void CActorGfx::SetUpFT4(POLY_FT4 *Ft4,sSpriteFrame *Frame,int X,int Y,bool XFlip,bool YFlip)
{ {
int U=0; u8 W=Frame->W;
int V=4; u8 H=Frame->H;
int W=Frame->W;
int H=Frame->H;
if (XFlip) if (XFlip)
{ {
@ -218,78 +413,4 @@ int H=Frame->H;
setXYWH(Ft4,X,Y,W,H); setXYWH(Ft4,X,Y,W,H);
} }
/*****************************************************************************/
void CActorGfx::Dump()
{
MemFree(SpriteBank);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
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 ********************************************************************/
/*****************************************************************************/
CActorGfx *CActorPool::GetActor(FileEquate Filename)
{
CActorGfx *NewActor;
int Idx;
// Already Loaded?
Idx=FindIdx(Filename);
if (Idx!=-1) return(ActorList[Idx]);
// Create and Load
Idx=FindFreeIdx();
ASSERT(Idx!=-1);
NewActor=new ("ActorPool") CActorGfx(Filename,Idx);
ActorList[Idx]=NewActor;
return(NewActor);
}
/*****************************************************************************/
/*** Dump ********************************************************************/
/*****************************************************************************/
// Dumps all apart from spongeybob
void CActorPool::DumpActors()
{
for (int i=0; i<MAX_ACTORS; i++)
{
if (ActorList[i] && ActorList[i]->GetFilename()!=ACTORS_SPONGEBOB_SBK)
{
CActorGfx *ThisActor=ActorList[i];
delete ThisActor;
ActorList[i]=0;
}
}
}

View File

@ -12,39 +12,56 @@
#include <biglump.h> #include <biglump.h>
#endif #endif
/*****************************************************************************/ struct sSlot
class CActorGfx
{ {
public: u16 W,H;
CActorGfx(FileEquate Filename,int No);
virtual ~CActorGfx();
void Init(FileEquate _Filename);
POLY_FT4 *Render(DVECTOR &Pos,int Anim,int Frame,bool FlipX=false,bool FlipY=false,bool Shadow=false);
void Dump();
int getFrameCount(int Anim) {return(SpriteBank->AnimList[Anim].FrameCount);}
FileEquate GetFilename() {return(Filename);}
private:
void SetUpFT4(POLY_FT4 *Ft4,sSpriteFrame *ThisFrame,int X,int Y,bool XFlip,bool YFlip);
sSpriteFrame *GetFrame(int Anim,int Frame);
FileEquate Filename;
sSpriteAnimBank *SpriteBank;
int ActorNo; // qwik bodge for mo :oP
int TexX,TexY;
int ClutX,ClutY;
}; };
/*****************************************************************************/ /*****************************************************************************/
struct sActorPool
{
FileEquate Filename;
sSpriteAnimBank *SpriteBank;
u16 RefCount;
u16 Clut;
};
/*****************************************************************************/
class CSlotCache
{
public:
enum
{
DYN_W =64,
DYN_H =64,
DYN_TPAGEW =4*256,
DYN_TPAGEH =1*256,
DYN_SLOTW =(DYN_TPAGEW/DYN_W),
DYN_SLOTH =(DYN_TPAGEH/DYN_H),
DYN_SLOTX =512+256,
DYN_SLOTY =256,
};
CSlotCache(){};
~CSlotCache(){};
void Init();
bool FindSlot(int SprW,int SprH,u16 &TexX,u16 &TexY,u8 &u,u8 &v);
protected:
bool TakeSlot(int SX,int SY,int SW,int SH);
sSlot Cache[DYN_SLOTW][DYN_SLOTH];
};
/*****************************************************************************/
class CActorGfx;
class CActorPool class CActorPool
{ {
public: public:
enum enum
{ {
MAX_ACTORS=8, MAX_ACTORS =32,
MAX_ACTOR_SIZE=128*128, MAX_ACTOR_SIZE= 128*128,
}; };
enum ACTOR_TYPE enum ACTOR_TYPE
@ -57,21 +74,55 @@ public:
static void Init(); static void Init();
static void AddActor(FileEquate Filename) {GetActor(Filename);} static void AddActor(FileEquate Filename);
static CActorGfx *GetActor(FileEquate Filename); static CActorGfx *GetActor(FileEquate Filename);
static void DumpActors(); static void DumpActors();
static u8 UnpackBuffer[MAX_ACTOR_SIZE];
static ACTOR_TYPE getActorType( int actorNum ) {return actorType[actorNum];} static ACTOR_TYPE getActorType( int actorNum ) {return actorType[actorNum];}
private: protected:
static int FindIdx(FileEquate Filename); static int FindActorInPool(FileEquate Filename);
static int FindFreeIdx(); static int FindFreeActor();
static int LoadActor(FileEquate Filename);
static u16 LoadPalette(sActorPool &ThisActor,int Idx);
static CActorGfx *ActorList[MAX_ACTORS];
static ACTOR_TYPE actorType[38]; static sActorPool ActorPool[];
static ACTOR_TYPE actorType[];
};
/*****************************************************************************/
class CActorGfx
{
public:
CActorGfx();
virtual ~CActorGfx();
void SetData(FileEquate Filename,sSpriteAnimBank *_SpriteBank,u16 _Clut);
static void ResetCache();
POLY_FT4 *Render(DVECTOR &Pos,int Anim,int Frame,bool FlipX=false,bool FlipY=false,bool Shadow=false);
int getFrameCount(int Anim) {return(SpriteBank->AnimList[Anim].FrameCount);}
protected:
void SetUpFT4(POLY_FT4 *Ft4,sSpriteFrame *ThisFrame,int X,int Y,bool XFlip,bool YFlip);
sSpriteFrame *GetFrame(int Anim,int Frame);
sSpriteAnimBank *SpriteBank;
// RECT DrawRect;
u16 Clut;
u16 TPage,TexX,TexY;
u8 U,V;
static CSlotCache SlotCache;
static u8 UnpackBuffer[CActorPool::MAX_ACTOR_SIZE];
}; };

View File

@ -418,7 +418,9 @@ void CLevel::init()
// Load it // Load it
sLvlTab *lvlTab=&LvlTable[s_globalLevelSelectThing]; sLvlTab *lvlTab=&LvlTable[s_globalLevelSelectThing];
CActorGfx::ResetCache();
CSoundMediator::setSong((CSoundMediator::SONGID)lvlTab->songId); CSoundMediator::setSong((CSoundMediator::SONGID)lvlTab->songId);
if (!LevelBuffer) if (!LevelBuffer)
{ {
initNewLevel(lvlTab); initNewLevel(lvlTab);

Binary file not shown.

View File

@ -264,7 +264,8 @@ struct sSpriteAnimBank
u16 ColorCount; // 2 u16 ColorCount; // 2
u16 AnimCount; // 2 u16 AnimCount; // 2
u16 FrameCount; // 2 u16 FrameCount; // 2
u16 Pad; // 2 u16 MaxW,MaxH; // 4
u16 Pad;
u8 *Palette; // 4 u8 *Palette; // 4
sSpriteAnim *AnimList; // 4 sSpriteAnim *AnimList; // 4