diff --git a/source/gfx/actor.cpp b/source/gfx/actor.cpp index 94717890f..441894e33 100644 --- a/source/gfx/actor.cpp +++ b/source/gfx/actor.cpp @@ -6,19 +6,21 @@ #include "mem\memory.h" #include "fileio\fileio.h" #include "utils\utils.h" -#include "utils\pak.h" +//#include "utils\pak.h" #include "gfx\prim.h" #include "gfx\actor.h" #include "gfx\otpos.h" +#include "gfx\animtex.h" #include +/*****************************************************************************/ +const int BBOX_ADJ=4; + /*****************************************************************************/ CActorCache CActorPool::Cache; sActorPool *CActorPool::ActorList,*CActorPool::LastActor; -u8 *CActorCache::UnpackBuffer; - /*****************************************************************************/ /*** Cache *******************************************************************/ /*****************************************************************************/ @@ -28,8 +30,6 @@ CActorCache::CActorCache() { SlotList[i].ListMem=0; } - UnpackBuffer=0; - } /*****************************************************************************/ @@ -37,23 +37,6 @@ CActorCache::~CActorCache() { } -/*****************************************************************************/ -int CActorCache::GetSizeType(int Size) -{ -// if (Size<= 16) return(16); -// if (Size<= 32) return(32); -// if (Size<= 64) return(64); -// if (Size<=128) return(128); -// if (Size<=256) return(256); - return((Size+15)&-16); -// Size>>=4; -// Size<<=4; -// return(Size); - ASSERT(!"SPRITE SIZE NOT SUPPORTED"); - - return(-1); -} - /*****************************************************************************/ int CActorCache::ReAllocSlot(int W,int H) { @@ -248,7 +231,7 @@ int MaxH=0; if (MaxH>2); int TexY=CACHE_Y+V; - List->Actor=(FileEquate)0; - List->TexX=TexX; - List->TexY=TexY; + List->Frame=0; + List->DstRect.x=TexX; + List->DstRect.y=TexY; List->U=U&255; List->V=V&255; List->TPage=getTPage(0,0,TexX,TexY); @@ -306,8 +289,7 @@ void CActorCache::Reset() SlotList[i].Width=0; SlotList[i].Height=0; } - if (UnpackBuffer) MemFree(UnpackBuffer); - UnpackBuffer=0; + CPakTex::Shutdown(); CurrentTPX=0; CurrentPalette=0; @@ -513,13 +495,13 @@ sActorPool *Actor=ActorList; while (Actor) { -// Actor->LastCache.Head=0;//Actor->LocalCache.Head; -// Actor->LastCache.Tail=0;//Actor->LocalCache.Tail; + Actor->LastCache.Head=Actor->LocalCache.Head; + Actor->LastCache.Tail=Actor->LocalCache.Tail; CActorCache::AddNodeList(&Actor->LocalCache ,Actor->GlobalCache); Actor->LocalCache.Head=0; Actor->LocalCache.Tail=0; -// ASSERT(Actor->GlobalCache->Head); -// ASSERT(Actor->GlobalCache->Tail); + ASSERT(Actor->GlobalCache->Head); + ASSERT(Actor->GlobalCache->Tail); Actor=Actor->Next; } /* @@ -567,7 +549,6 @@ u16 ThisFrame=ThisAnim->Anim[Frame]; } /*****************************************************************************/ -const int BBOX_ADJ=4; POLY_FT4 *CActorGfx::Render(DVECTOR &Pos,int Anim,int Frame,bool XFlip,bool YFlip) { sPoolNode *ThisNode,*FindNode; @@ -580,7 +561,7 @@ POLY_FT4 *Ft4; FindNode=PoolEntry->LocalCache.Head; while (FindNode) { // Try local Cache (From Head forward) - if (FindNode->Actor==PoolEntry->Filename && FindNode->Anim==Anim && FindNode->Frame==Frame) + if (FindNode->Frame==CurrentFrame) { ThisNode=FindNode; break; @@ -594,7 +575,7 @@ POLY_FT4 *Ft4; FindNode=PoolEntry->LastCache.Head; while (FindNode) { - if (FindNode->Actor==PoolEntry->Filename && FindNode->Anim==Anim && FindNode->Frame==Frame) + if (FindNode->Frame==CurrentFrame) { ThisNode=FindNode; CActorCache::RemoveNode(ThisNode,PoolEntry->GlobalCache); @@ -613,7 +594,7 @@ POLY_FT4 *Ft4; FindNode=PoolEntry->GlobalCache->Tail; while (FindNode) { - if (FindNode->Actor==PoolEntry->Filename && FindNode->Anim==Anim && FindNode->Frame==Frame) + if (FindNode->Frame==CurrentFrame) { ThisNode=FindNode; CActorCache::RemoveNode(ThisNode,PoolEntry->GlobalCache); @@ -630,18 +611,12 @@ POLY_FT4 *Ft4; ThisNode=CActorCache::RemoveHeadNode(PoolEntry->GlobalCache); ASSERT(ThisNode); CActorCache::AddNode(ThisNode,&PoolEntry->LocalCache); - RECT R; - ThisNode->Actor=PoolEntry->Filename; - ThisNode->Anim=Anim; - ThisNode->Frame=Frame; - - PAK_doUnpak(CActorCache::UnpackBuffer,CurrentFrame->PAKSpr); - R.x=ThisNode->TexX; - R.y=ThisNode->TexY; - R.w=CurrentFrame->W>>2; // div 4 cos 16 color - R.h=CurrentFrame->H; - LoadImage( &R, (u32*)CActorCache::UnpackBuffer); + ThisNode->Frame=CurrentFrame; + + ThisNode->DstRect.w=CurrentFrame->W>>2; // div 4 cos 16 color + ThisNode->DstRect.h=CurrentFrame->H; + CPakTex::Add(CurrentFrame->PAKSpr,&ThisNode->DstRect); } Ft4=GetPrimFT4(); diff --git a/source/gfx/actor.h b/source/gfx/actor.h index 3af1688ef..ded38835b 100644 --- a/source/gfx/actor.h +++ b/source/gfx/actor.h @@ -13,16 +13,13 @@ #endif /*****************************************************************************/ -// Pack together Actor anim & frame for quicker check later struct sPoolNode { - FileEquate Actor; - u16 Anim; - u16 Frame; - u16 TPage; - u16 TexX,TexY; - u8 U,V; - sPoolNode *Prev,*Next; + sSpriteFrame *Frame; + RECT DstRect; + u16 TPage; + u8 U,V; + sPoolNode *Prev,*Next; }; struct sNodeList @@ -66,19 +63,14 @@ public: CACHE_Y =256, CACHE_W =8, CACHE_H =1, -/* - CACHE_X =512+256, - CACHE_Y =256, - CACHE_W =4, - CACHE_H =1, -*/ CACHE_PALX =CACHE_X, CACHE_PALY =510, CACHE_PALW =64, CACHE_PALH =1, CACHE_TYPE_MAX =8, + }; CActorCache(); @@ -96,20 +88,18 @@ static sPoolNode *RemoveHeadNode(sNodeList *Root); static void RemoveNode(sPoolNode *Node,sNodeList *Root); static void AddNode(sPoolNode *Node,sNodeList *Root); static void AddNodeList(sNodeList *Src,sNodeList *Dst); -static u8 *UnpackBuffer; protected: int ReAllocSlot(int W,int H); int GetSlot(int W,int H); void InitCache(int Type,int Count); - int GetSizeType(int Size); + int GetSizeType(int Size) {return((Size+15)&-16);} sPoolSlot SlotList[CACHE_TYPE_MAX]; int CurrentTPX; int CurrentPalette; int SlotCount; - }; /*****************************************************************************/ @@ -133,6 +123,7 @@ static void AddActor(sActorPool *ThisActor); static CActorCache Cache; static sActorPool *ActorList,*LastActor; + }; /*****************************************************************************/ diff --git a/source/gfx/animtex.cpp b/source/gfx/animtex.cpp index e4c2f2d48..114af25e3 100644 --- a/source/gfx/animtex.cpp +++ b/source/gfx/animtex.cpp @@ -9,13 +9,16 @@ #include "gfx\animtex.h" #include "gfx\tpage.h" #include "utils\utils.h" +#include "utils\pak.h" #ifndef __SYSTEM_GSTATE_H__ #include "system\gstate.h" #endif CAnimTex *AnimTexList=0; -CMoveTex CMoveTex::MoveTexList[CMoveTex::MOVETEX_MAX]; +CPakTex CPakTex::PakTexList[CPakTex::PAKTEX_MAX]; +int CPakTex::PakTexCount; +u8 *CPakTex::UnpackBuffer; /*****************************************************************************/ CAnimTex::CAnimTex() @@ -144,43 +147,54 @@ int Time = GameState::getFramesSinceLast(); ThisTex->Count%=(ThisTex->Rect.h<<2); ThisTex=ThisTex->NextTex; } - CMoveTex::MoveTex(); - } /*****************************************************************************/ /*****************************************************************************/ +/*** Pak Tex Stuff ***********************************************************/ /*****************************************************************************/ -/* -void CMoveTex::Add(sTexInfo &SrcFrame,sTexInfo &DstFrame) +/*****************************************************************************/ +CPakTex::CPakTex() { -int Idx; - - for (Idx=0; Idxx,ThisTex.Dst->y); - ThisTex.Src=0; + ASSERT(UnpackBuffer); + PAK_doUnpak(UnpackBuffer,PakTexList[i].PakSpr); + LoadImage( PakTexList[i].DstRect, (u32*)UnpackBuffer); } -*/ + PakTexCount=0; } /*****************************************************************************/ diff --git a/source/gfx/animtex.h b/source/gfx/animtex.h index f6dc8d907..651444950 100644 --- a/source/gfx/animtex.h +++ b/source/gfx/animtex.h @@ -32,26 +32,28 @@ private: }; /*****************************************************************************/ -class CMoveTex + +class CPakTex { public: enum { - MOVETEX_MAX=16, + PAKTEX_MAX=16, }; - CMoveTex() - { -// Src=0; - } - -//static void Add(sTexInfo &SrcFrame,sTexInfo &DstFrame); -static void MoveTex(); + CPakTex(); +static void Init(int MaxSize); +static void Shutdown(); +static void Add(u8 *PakSpr,RECT *DstRect); +static void DMAPakTex(); +protected: + u8 *PakSpr; + RECT *DstRect; private: -// sTexInfo *Src,*Dst; - -static CMoveTex MoveTexList[]; +static CPakTex PakTexList[]; +static int PakTexCount; +static u8 *UnpackBuffer; }; /*****************************************************************************/ diff --git a/source/gfx/prim.cpp b/source/gfx/prim.cpp index da60e0cfc..346f79444 100644 --- a/source/gfx/prim.cpp +++ b/source/gfx/prim.cpp @@ -44,6 +44,7 @@ void PrimInit() void PrimDisplay() { CAnimTex::AnimateTex(); + CPakTex::DMAPakTex(); UnlinkOTagR(BaseOtPtr, MAX_OT_ALL, &DmaStart[PrimFlipFlag]); #ifdef USE_NTAGS