SBSPSS/source/gfx/actor.cpp

892 lines
20 KiB
C++
Raw Normal View History

2001-04-01 09:22:30 +02:00
/******************/
/*** Actor Bank ***/
/******************/
2001-06-21 21:19:15 +02:00
#include "system\vid.h"
2001-04-01 09:22:30 +02:00
#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 "gfx\prim.h"
2001-04-01 23:38:59 +02:00
#include "gfx\actor.h"
2001-05-02 00:28:01 +02:00
#include "gfx\otpos.h"
2001-05-14 21:40:30 +02:00
#include "gfx\animtex.h"
2001-04-01 09:22:30 +02:00
#include <dstructs.h>
2001-05-14 21:40:30 +02:00
/*****************************************************************************/
const int BBOX_ADJ=4;
2001-04-09 23:27:21 +02:00
/*****************************************************************************/
2001-04-25 18:41:16 +02:00
CActorCache CActorPool::Cache;
sActorPool *CActorPool::ActorList,*CActorPool::LastActor;
/*****************************************************************************/
/*** Cache *******************************************************************/
/*****************************************************************************/
CActorCache::CActorCache()
{
for (int i=0;i<CACHE_TYPE_MAX; i++)
{
2001-04-25 21:11:45 +02:00
SlotList[i].ListMem=0;
2001-04-25 18:41:16 +02:00
}
}
/*****************************************************************************/
CActorCache::~CActorCache()
{
}
2001-04-09 23:27:21 +02:00
2001-05-05 20:38:24 +02:00
/*****************************************************************************/
int CActorCache::ReAllocSlot(int W,int H)
{
int i;
int Slot=-1;
int SlotW=+32000,SlotH=+32000;
// Find best slot which fits in
for (i=0;i<SlotCount; i++)
{
int ThisW=(SlotList[i].Width-W);
int ThisH=(SlotList[i].Height-H);
if (ThisW<SlotW || ThisH<SlotH)
{
Slot=i;
SlotW=ThisW;
SlotH=ThisH;
}
}
if (SlotList[Slot].Width<W)
{
SlotList[Slot].Width=W;
}
if (SlotList[Slot].Height<H)
{
SlotList[Slot].Height=H;
}
return(Slot);
}
2001-04-25 18:41:16 +02:00
/*****************************************************************************/
int CActorCache::GetSlot(int W,int H)
2001-04-04 18:51:04 +02:00
{
2001-04-25 18:41:16 +02:00
int i;
int Slot=0;
W=GetSizeType(W);
H=GetSizeType(H);
for (i=0; i<SlotCount && !Slot; i++)
{ // Slot exist?
if (SlotList[i].Width==W && SlotList[i].Height==H) Slot=i;
}
if (!Slot)
{ // Use New Slot
2001-05-05 20:38:24 +02:00
if (SlotCount>=CACHE_TYPE_MAX)
{ // No free slots, grab an existing one, and alter size to fit
Slot=ReAllocSlot(W,H);
}
else
{
2001-04-25 18:41:16 +02:00
Slot=SlotCount;
SlotList[Slot].Width=W;
SlotList[Slot].Height=H;
2001-05-05 18:34:58 +02:00
SlotCount++;
2001-05-05 20:38:24 +02:00
}
2001-04-25 18:41:16 +02:00
}
2001-06-14 23:17:10 +02:00
// SlotList[Slot].RefCount++;
2001-04-25 18:41:16 +02:00
return(Slot);
}
/*****************************************************************************/
2001-05-12 01:52:38 +02:00
sPoolNode *CActorCache::RemoveHeadNode(sNodeList *RootNode)
2001-04-25 18:41:16 +02:00
{
2001-05-12 01:52:38 +02:00
sPoolNode *ThisNode=RootNode->Head;
sPoolNode *NextNode=ThisNode->Next;
2001-04-25 18:41:16 +02:00
2001-05-12 01:52:38 +02:00
RootNode->Head=NextNode;
ThisNode->Next=0;
if (NextNode)
{
NextNode->Prev=0;
}
else
{ // Its Tail Node
RootNode->Tail=0;
}
return(ThisNode);
2001-04-25 18:41:16 +02:00
}
/*****************************************************************************/
2001-05-12 01:52:38 +02:00
void CActorCache::RemoveNode(sPoolNode *ThisNode,sNodeList *RootNode)
2001-04-25 18:41:16 +02:00
{
2001-05-12 01:52:38 +02:00
sPoolNode *PrevNode=ThisNode->Prev;
sPoolNode *NextNode=ThisNode->Next;
2001-04-25 18:41:16 +02:00
2001-05-12 01:52:38 +02:00
if (PrevNode)
2001-04-25 18:41:16 +02:00
{ // Not Head Node
2001-05-12 01:52:38 +02:00
PrevNode->Next=NextNode;
2001-04-25 18:41:16 +02:00
}
2001-05-12 01:52:38 +02:00
else
{ // Head Node
RootNode->Head=NextNode;
}
if (NextNode)
2001-04-25 18:41:16 +02:00
{ // Not Tail Node
2001-05-12 01:52:38 +02:00
NextNode->Prev=PrevNode;
2001-04-25 18:41:16 +02:00
}
2001-05-12 01:52:38 +02:00
else
{ // Tail Node
RootNode->Tail=PrevNode;
}
ThisNode->Next=0;
ThisNode->Prev=0;
2001-04-25 18:41:16 +02:00
}
/*****************************************************************************/
// Add node to end of list
2001-05-12 01:52:38 +02:00
void CActorCache::AddNode(sPoolNode *ThisNode,sNodeList *RootNode)
2001-04-09 23:27:21 +02:00
{
2001-05-12 01:52:38 +02:00
sPoolNode *TailNode=RootNode->Tail;
2001-04-25 18:41:16 +02:00
2001-05-12 01:52:38 +02:00
if (TailNode)
{
TailNode->Next=ThisNode;
2001-04-25 18:41:16 +02:00
}
else
2001-05-12 01:52:38 +02:00
{ // List is empty
RootNode->Head=ThisNode;
2001-04-09 23:27:21 +02:00
}
2001-05-12 01:52:38 +02:00
ThisNode->Prev=TailNode;
ThisNode->Next=0;
ASSERT(ThisNode);
RootNode->Tail=ThisNode;
2001-04-27 22:28:47 +02:00
}
/*****************************************************************************/
// Add node list to end of list
void CActorCache::AddNodeList(sNodeList *Src,sNodeList *Dst)
{
sPoolNode *SrcHead=Src->Head;
sPoolNode *SrcTail=Src->Tail;
sPoolNode *DstHead=Dst->Head;
sPoolNode *DstTail=Dst->Tail;
2001-05-12 01:52:38 +02:00
/*
2001-04-27 22:28:47 +02:00
if (!SrcHead) return;
2001-05-12 01:52:38 +02:00
if (DstTail)
2001-04-27 22:28:47 +02:00
{
2001-05-12 01:52:38 +02:00
DstTail->Next=SrcHead;
2001-04-27 22:28:47 +02:00
}
else
2001-05-12 01:52:38 +02:00
{ // List is empty
Dst->Head=SrcHead;
2001-04-27 22:28:47 +02:00
}
2001-05-12 01:52:38 +02:00
SrcHead->Prev=DstTail;
2001-04-27 22:28:47 +02:00
Dst->Tail=SrcTail;
Src->Head=0;
Src->Tail=0;
2001-05-12 01:52:38 +02:00
*/
while(SrcHead)
{
sPoolNode *Next=SrcHead->Next;
AddNode(SrcHead,Dst);
SrcHead=Next;
}
2001-04-09 23:27:21 +02:00
}
2001-04-01 22:22:49 +02:00
/*****************************************************************************/
2001-04-25 18:41:16 +02:00
int CActorCache::ReserveSlot(int W,int H,int FrameCount)
2001-04-01 22:22:49 +02:00
{
2001-04-25 18:41:16 +02:00
int Slot=GetSlot(W,H);
2001-06-14 23:17:10 +02:00
// SlotList[Slot].FrameCount+=FrameCount;
2001-04-25 18:41:16 +02:00
return(Slot);
}
2001-04-09 23:27:21 +02:00
2001-04-25 18:41:16 +02:00
/*****************************************************************************/
void CActorCache::AllocCache()
{
int TPW=CACHE_W/SlotCount;
2001-04-25 21:11:45 +02:00
int MaxW=0;
int MaxH=0;
2001-04-27 23:42:38 +02:00
2001-05-12 01:52:38 +02:00
TPW=1;
2001-05-05 18:34:58 +02:00
2001-05-05 20:38:24 +02:00
ASSERT(SlotCount<=CACHE_W);
2001-04-27 23:42:38 +02:00
2001-04-25 18:41:16 +02:00
for (int i=0; i<SlotCount; i++)
2001-04-09 23:27:21 +02:00
{
2001-04-25 21:11:45 +02:00
if (MaxW<SlotList[i].Width) MaxW=SlotList[i].Width;
if (MaxH<SlotList[i].Height) MaxH=SlotList[i].Height;
2001-04-25 18:41:16 +02:00
InitCache(i,TPW);
}
2001-05-14 21:40:30 +02:00
CPakTex::Init(MaxW*MaxH);
2001-04-25 18:41:16 +02:00
}
/*****************************************************************************/
// This needs improving to 'grab' free areas left from bigger grabs (YIKES!)
void CActorCache::InitCache(int Slot,int TPW)
{
sPoolSlot *ThisSlot=&SlotList[Slot];
int W=(TPW*(TPAGE_W))/ThisSlot->Width;
int H=(TPAGE_H)/ThisSlot->Height;
int Total=W*H;
sPoolNode *List;
// Init List
2001-05-12 01:52:38 +02:00
ThisSlot->SlotCount=Total;
2001-04-25 21:11:45 +02:00
ThisSlot->ListMem=(u8*)MemAlloc(Total*sizeof(sPoolNode),"CacheNodeList");
List=(sPoolNode*)ThisSlot->ListMem;
2001-04-25 18:41:16 +02:00
// Create List Entries
for (int Y=0; Y<H; Y++)
2001-04-09 23:27:21 +02:00
{
2001-04-25 18:41:16 +02:00
for (int X=0; X<W; X++)
2001-04-09 23:27:21 +02:00
{
2001-04-25 18:41:16 +02:00
int U=(X*ThisSlot->Width);
2001-06-11 22:36:53 +02:00
int V=(Y*ThisSlot->Height);
int TexX=(CACHE_X+CurrentTPX+(U>>2));
int TexY=(CACHE_Y+V);
2001-04-25 18:41:16 +02:00
2001-05-14 21:40:30 +02:00
List->Frame=0;
List->DstRect.x=TexX;
List->DstRect.y=TexY;
2001-04-25 18:41:16 +02:00
List->U=U&255;
List->V=V&255;
2001-04-27 23:42:38 +02:00
List->TPage=getTPage(0,0,TexX,TexY);
2001-04-25 18:41:16 +02:00
AddNode(List,&ThisSlot->NodeList);
List++;
2001-04-09 23:27:21 +02:00
}
}
2001-04-25 18:41:16 +02:00
CurrentTPX+=(TPW*TPAGE_W)>>2;
2001-04-01 22:22:49 +02:00
}
2001-04-09 23:27:21 +02:00
/*****************************************************************************/
2001-04-25 18:41:16 +02:00
void CActorCache::Reset()
2001-04-09 23:27:21 +02:00
{
2001-04-25 18:41:16 +02:00
// Free and init lists
for (int i=0;i<CACHE_TYPE_MAX; i++)
{
2001-04-25 21:11:45 +02:00
if (SlotList[i].ListMem) MemFree(SlotList[i].ListMem);
SlotList[i].ListMem=0;
2001-04-27 22:28:47 +02:00
SlotList[i].NodeList.Head=0;
SlotList[i].NodeList.Tail=0;
2001-06-14 23:17:10 +02:00
// SlotList[i].RefCount=0;
// SlotList[i].FrameCount=0;
2001-04-25 18:41:16 +02:00
SlotList[i].Width=0;
SlotList[i].Height=0;
}
2001-05-14 21:40:30 +02:00
CPakTex::Shutdown();
2001-04-25 18:41:16 +02:00
CurrentTPX=0;
CurrentPalette=0;
SlotCount=0;
// Clear VRam
2001-04-27 23:42:38 +02:00
RECT R={CACHE_X,CACHE_Y,TPAGE_W*CACHE_W,TPAGE_H*CACHE_H};
2001-04-25 18:41:16 +02:00
ClearImage(&R,0,255,0);
}
/*****************************************************************************/
void CActorCache::LoadPalette(sActorPool *Actor)
{
2001-04-26 23:15:36 +02:00
if (!Actor->ActorGfx->Clut)
2001-05-09 19:30:40 +02:00
{
2001-04-26 23:15:36 +02:00
RECT R;
2001-05-09 19:30:40 +02:00
int PalNo;
2001-04-25 18:41:16 +02:00
2001-04-26 23:15:36 +02:00
if (Actor->Filename==ACTORS_SPONGEBOB_SBK)
{
2001-05-09 19:30:40 +02:00
PalNo=0;
2001-04-26 23:15:36 +02:00
}
else
{
2001-05-09 19:30:40 +02:00
PalNo=CurrentPalette+1;
2001-04-26 23:15:36 +02:00
}
2001-04-25 18:41:16 +02:00
2001-05-09 19:30:40 +02:00
int X=PalNo%CACHE_W;
int Y=PalNo/CACHE_W;
R.x=CACHE_PALX+(X*CACHE_PALW);
R.y=CACHE_PALY-Y;
2001-04-26 23:15:36 +02:00
R.w=CACHE_PALW;
R.h=CACHE_PALH;
DrawSync(0);
LoadImage( &R, (u32*)Actor->ActorGfx->Palette);
Actor->ActorGfx->Clut=getClut(R.x,R.y);
CurrentPalette++;
}
2001-04-09 23:27:21 +02:00
}
2001-04-02 00:55:15 +02:00
2001-04-01 09:22:30 +02:00
/*****************************************************************************/
2001-04-09 23:27:21 +02:00
/*****************************************************************************/
/*****************************************************************************/
void CActorPool::Init()
2001-04-01 09:22:30 +02:00
{
2001-04-25 18:41:16 +02:00
ActorList=0;
2001-04-25 21:33:39 +02:00
Cache.Reset();
2001-04-25 18:41:16 +02:00
}
/*****************************************************************************/
void CActorPool::Reset()
{
sActorPool *List=ActorList;
while (List)
{
sActorPool *Next=List->Next;
if (List->Filename!=ACTORS_SPONGEBOB_SBK)
{
MemFree(List->ActorGfx);
delete List;
}
else
{
List->Next=0;
}
List=Next;
}
2001-04-25 21:33:39 +02:00
LastActor=ActorList;
2001-04-25 18:41:16 +02:00
Cache.Reset();
2001-04-09 23:27:21 +02:00
}
2001-04-02 00:55:15 +02:00
2001-04-09 23:27:21 +02:00
/*****************************************************************************/
2001-04-25 18:41:16 +02:00
void CActorPool::SetUpCache()
2001-04-09 23:27:21 +02:00
{
2001-04-25 18:41:16 +02:00
Cache.AllocCache();
// SetUp Actors
sActorPool *List=ActorList;
while (List)
{
2001-05-12 01:52:38 +02:00
List->GlobalCache=Cache.GetSlotList(List->CacheSlot);
List->LocalCache.Head=0;
List->LocalCache.Tail=0;
List->LastCache.Head=0;
List->LastCache.Tail=0;
2001-04-25 18:41:16 +02:00
List=List->Next;
}
}
/*****************************************************************************/
sActorPool *CActorPool::FindActor(FileEquate Filename)
{
sActorPool *List=ActorList;
while (List)
2001-04-09 23:27:21 +02:00
{
2001-04-25 18:41:16 +02:00
if (List->ActorGfx && List->Filename==Filename) return(List);
List=List->Next;
2001-04-09 23:27:21 +02:00
}
2001-04-25 18:41:16 +02:00
return(0);
2001-04-09 23:27:21 +02:00
}
2001-04-01 09:22:30 +02:00
2001-04-09 23:27:21 +02:00
/*****************************************************************************/
2001-04-25 18:41:16 +02:00
CActorGfx *CActorPool::GetActor(FileEquate Filename)
2001-04-09 23:27:21 +02:00
{
2001-04-25 18:41:16 +02:00
sActorPool *ThisActor;
CActorGfx *NewActor;
int TotalFrames=0;
bool NewFlag=false;
// Find Actor in Pool
ThisActor=FindActor(Filename);
if (!ThisActor)
2001-04-09 23:27:21 +02:00
{
2001-04-25 18:41:16 +02:00
ThisActor=LoadActor(Filename);
NewFlag=true;
2001-04-09 23:27:21 +02:00
}
2001-04-25 18:41:16 +02:00
NewActor=new ("CActorGfx") CActorGfx(ThisActor);
2001-04-30 23:49:54 +02:00
2001-04-25 18:41:16 +02:00
if (NewFlag)
{
TotalFrames=NewActor->GetTotalFrameCount();
}
ThisActor->CacheSlot=Cache.ReserveSlot(ThisActor->ActorGfx->MaxW,ThisActor->ActorGfx->MaxH,TotalFrames);
return(NewActor);
2001-04-09 23:27:21 +02:00
}
/*****************************************************************************/
2001-04-25 18:41:16 +02:00
sActorPool *CActorPool::LoadActor(FileEquate Filename)
2001-04-09 23:27:21 +02:00
{
int i;
2001-04-25 18:41:16 +02:00
int TotalFrames=0;
2001-04-09 23:27:21 +02:00
2001-04-25 21:11:45 +02:00
sSpriteAnimBank *Spr=(sSpriteAnimBank*)CFileIO::loadFile(Filename,"ActorGfx");
2001-04-09 23:27:21 +02:00
2001-05-15 19:40:54 +02:00
Spr->AnimList=(sSpriteAnim*) MakePtr(Spr,(int)Spr->AnimList);
Spr->FrameList=(sSpriteFrameGfx*) MakePtr(Spr,(int)Spr->FrameList);
Spr->Palette=(u8*) MakePtr(Spr,(int)Spr->Palette);
2001-04-01 22:22:49 +02:00
// FixUp AnimList
2001-04-09 23:27:21 +02:00
for (i=0; i<Spr->AnimCount; i++)
2001-04-01 22:22:49 +02:00
{
2001-04-09 23:27:21 +02:00
sSpriteAnim *ThisAnim=&Spr->AnimList[i];
2001-05-15 19:40:54 +02:00
ThisAnim->Anim=(sSpriteFrame*) MakePtr(Spr,(int)ThisAnim->Anim);
2001-04-25 18:41:16 +02:00
TotalFrames+=ThisAnim->FrameCount;
2001-04-01 22:22:49 +02:00
}
2001-04-25 18:41:16 +02:00
2001-06-18 23:26:06 +02:00
// FixUp FrameList (not blank ones)
2001-04-09 23:27:21 +02:00
for (i=0; i<Spr->FrameCount; i++)
2001-04-01 09:22:30 +02:00
{
2001-05-15 19:40:54 +02:00
sSpriteFrameGfx *ThisFrame=&Spr->FrameList[i];
2001-06-18 23:26:06 +02:00
if (ThisFrame->PAKSpr)
{
ThisFrame->PAKSpr=(u8*) MakePtr(Spr,(int)ThisFrame->PAKSpr);
}
2001-04-01 09:22:30 +02:00
}
2001-04-09 23:27:21 +02:00
// Store it
2001-04-25 18:41:16 +02:00
sActorPool *NewActor;
2001-04-02 00:55:15 +02:00
2001-04-25 18:41:16 +02:00
NewActor=new ("ActorPool") sActorPool();
NewActor->Filename=Filename;
NewActor->ActorGfx=Spr;
AddActor(NewActor);
2001-04-09 23:27:21 +02:00
2001-04-25 18:41:16 +02:00
return(NewActor);
2001-04-09 23:27:21 +02:00
}
/*****************************************************************************/
2001-04-25 18:41:16 +02:00
void CActorPool::AddActor(sActorPool *NewActor)
2001-04-09 23:27:21 +02:00
{
2001-04-25 18:41:16 +02:00
// Insert into list
2001-04-09 23:27:21 +02:00
2001-04-25 18:41:16 +02:00
if (!LastActor)
{ // Empty List
ActorList=NewActor;
2001-04-09 23:27:21 +02:00
}
2001-04-25 18:41:16 +02:00
else
{
LastActor->Next=NewActor;
}
NewActor->Next=0;
Cache.LoadPalette(NewActor);
LastActor=NewActor;
2001-04-09 23:27:21 +02:00
}
2001-05-12 01:52:38 +02:00
2001-04-27 22:28:47 +02:00
/*****************************************************************************/
void CActorPool::CleanUpCache()
{
sActorPool *Actor=ActorList;
2001-05-12 01:52:38 +02:00
while (Actor)
{
2001-05-14 21:40:30 +02:00
Actor->LastCache.Head=Actor->LocalCache.Head;
Actor->LastCache.Tail=Actor->LocalCache.Tail;
2001-05-12 01:52:38 +02:00
CActorCache::AddNodeList(&Actor->LocalCache ,Actor->GlobalCache);
Actor->LocalCache.Head=0;
Actor->LocalCache.Tail=0;
2001-05-14 21:40:30 +02:00
ASSERT(Actor->GlobalCache->Head);
ASSERT(Actor->GlobalCache->Tail);
2001-05-12 01:52:38 +02:00
Actor=Actor->Next;
}
2001-04-27 22:28:47 +02:00
}
2001-04-09 23:27:21 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-04-25 18:41:16 +02:00
/*****************************************************************************/
CActorGfx::CActorGfx(sActorPool *ThisActor)
2001-04-09 23:27:21 +02:00
{
2001-06-14 23:17:10 +02:00
setActor(ThisActor);
2001-04-01 09:22:30 +02:00
}
/*****************************************************************************/
CActorGfx::~CActorGfx()
{
2001-04-09 23:27:21 +02:00
}
2001-06-14 23:17:10 +02:00
/*****************************************************************************/
void CActorGfx::setActor(sActorPool *ThisActor)
{
PoolEntry=ThisActor;
// ShadowXOfs=DEF_SHADOW_OFS;
// ShadowYOfs=DEF_SHADOW_OFS;
// ShadowFlag=false;
OtPos=OTPOS__ACTOR_POS;
}
2001-04-01 09:22:30 +02:00
/*****************************************************************************/
2001-04-30 23:49:54 +02:00
POLY_FT4 *CActorGfx::Render(DVECTOR &Pos,int Anim,int Frame,bool XFlip,bool YFlip)
2001-04-01 09:22:30 +02:00
{
2001-05-12 01:52:38 +02:00
sPoolNode *ThisNode,*FindNode;
2001-04-25 18:41:16 +02:00
POLY_FT4 *Ft4;
2001-04-09 23:27:21 +02:00
2001-05-15 19:40:54 +02:00
// Calc Frame Ptrs
sSpriteAnimBank *SpriteBank=PoolEntry->ActorGfx;
sSpriteAnim *ThisAnim=SpriteBank->AnimList+Anim;
CurrentFrame=&ThisAnim->Anim[Frame];
CurrentFrameGfx=&SpriteBank->FrameList[CurrentFrame->FrameIdx];
2001-05-12 01:52:38 +02:00
2001-06-15 21:19:45 +02:00
if (!CurrentFrameGfx->PAKSpr) return(0); // Blank Frame
2001-05-15 19:40:54 +02:00
// Try to find Pre-cached sprite
ThisNode=0;
2001-05-12 01:52:38 +02:00
// Check Local Cache
FindNode=PoolEntry->LocalCache.Head;
while (FindNode)
2001-04-27 22:28:47 +02:00
{ // Try local Cache (From Head forward)
2001-05-15 19:40:54 +02:00
if (FindNode->Frame==CurrentFrameGfx)
2001-04-27 22:28:47 +02:00
{
2001-05-12 01:52:38 +02:00
ThisNode=FindNode;
break;
2001-04-27 22:28:47 +02:00
}
2001-05-12 01:52:38 +02:00
FindNode=FindNode->Next;
}
// Check Last Cache
if (!ThisNode)
{
FindNode=PoolEntry->LastCache.Head;
while (FindNode)
2001-04-27 22:28:47 +02:00
{
2001-05-15 19:40:54 +02:00
if (FindNode->Frame==CurrentFrameGfx)
2001-05-12 01:52:38 +02:00
{
ThisNode=FindNode;
CActorCache::RemoveNode(ThisNode,PoolEntry->GlobalCache);
CActorCache::AddNode(ThisNode,&PoolEntry->LocalCache);
break;
}
if (FindNode==PoolEntry->LastCache.Tail) break;
FindNode=FindNode->Next;
2001-04-27 22:28:47 +02:00
}
2001-05-12 01:52:38 +02:00
2001-04-27 22:28:47 +02:00
}
2001-05-12 01:52:38 +02:00
2001-05-15 19:40:54 +02:00
// Check Global Cache (From Tail back)
2001-05-12 01:52:38 +02:00
if (!ThisNode)
2001-04-27 22:28:47 +02:00
{
2001-05-12 01:52:38 +02:00
FindNode=PoolEntry->GlobalCache->Tail;
while (FindNode)
{
2001-05-15 19:40:54 +02:00
if (FindNode->Frame==CurrentFrameGfx)
2001-05-12 01:52:38 +02:00
{
ThisNode=FindNode;
CActorCache::RemoveNode(ThisNode,PoolEntry->GlobalCache);
CActorCache::AddNode(ThisNode,&PoolEntry->LocalCache);
break;
}
FindNode=FindNode->Prev;
}
2001-04-27 22:28:47 +02:00
}
2001-05-12 01:52:38 +02:00
// Could not find it, get new
2001-04-25 18:41:16 +02:00
if (!ThisNode)
{ // Not cached frame
2001-05-12 01:52:38 +02:00
ThisNode=CActorCache::RemoveHeadNode(PoolEntry->GlobalCache);
2001-04-27 22:28:47 +02:00
ASSERT(ThisNode);
2001-05-12 01:52:38 +02:00
CActorCache::AddNode(ThisNode,&PoolEntry->LocalCache);
2001-05-14 21:40:30 +02:00
2001-05-15 19:40:54 +02:00
ThisNode->Frame=CurrentFrameGfx;
2001-05-14 21:40:30 +02:00
2001-05-15 19:40:54 +02:00
ThisNode->DstRect.w=CurrentFrameGfx->W>>2; // div 4 cos 16 color
ThisNode->DstRect.h=CurrentFrameGfx->H;
CPakTex::Add(CurrentFrameGfx->PAKSpr,&ThisNode->DstRect);
2001-04-25 18:41:16 +02:00
}
2001-04-01 22:22:49 +02:00
2001-04-25 18:41:16 +02:00
Ft4=GetPrimFT4();
2001-05-15 19:40:54 +02:00
SetUpFT4(Ft4,ThisNode,Pos.vx,Pos.vy,XFlip,YFlip);
2001-04-01 23:38:59 +02:00
setRGB0(Ft4,128,128,128);
2001-04-25 18:41:16 +02:00
Ft4->tpage=ThisNode->TPage;
Ft4->clut=PoolEntry->ActorGfx->Clut;
2001-05-09 18:27:33 +02:00
addPrim(OtPtr+OtPos,Ft4);
2001-06-14 23:17:10 +02:00
/*
2001-04-30 23:49:54 +02:00
if (ShadowFlag)
2001-04-01 23:38:59 +02:00
{
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-05-09 18:27:33 +02:00
addPrim(OtPtr+OtPos,sFt4);
2001-04-01 23:38:59 +02:00
}
2001-06-14 23:17:10 +02:00
*/
2001-04-25 21:11:45 +02:00
// Set BBox
2001-06-11 22:45:48 +02:00
//int HalfW=CurrentFrameGfx->W>>1;
// Sizes now depend on aspect corrected sizes, so get sizes back from poly
int BBoxW=Ft4->x1-Ft4->x0;
int BBoxH=Ft4->y2-Ft4->y0;
int HalfW=BBoxW>>1;
2001-04-25 21:11:45 +02:00
2001-05-12 19:24:44 +02:00
BBox.XMin=-HalfW+BBOX_ADJ;
BBox.XMax=+HalfW-BBOX_ADJ;
2001-06-11 22:45:48 +02:00
BBox.YMin=-BBoxH+BBOX_ADJ;
2001-05-12 19:24:44 +02:00
BBox.YMax=0-BBOX_ADJ;
2001-04-26 15:00:44 +02:00
2001-04-01 23:38:59 +02:00
return(Ft4);
}
2001-04-26 15:00:44 +02:00
/*****************************************************************************/
POLY_FT4 *CActorGfx::RotateScale(POLY_FT4 *Ft4,DVECTOR &Pos,int Angle,int XScale,int YScale)
{
int dX,dY;
int CosAngle,SinAngle;
int CosX,CosY,SinX,SinY;
sBBox SBox,CBox;
2001-06-11 22:36:53 +02:00
int W=Ft4->x1-Ft4->x0;
int H=Ft4->y2-Ft4->y0;
2001-04-26 15:00:44 +02:00
Angle&=4095;
2001-06-11 22:36:53 +02:00
// dX=(CurrentFrameGfx->W*XScale)>>(12+1); // +1 for half
// dY=(CurrentFrameGfx->H*YScale)>>(12);
dX=(W*XScale)>>(12+1); // +1 for half
dY=(H*YScale)>>(12);
2001-04-26 15:00:44 +02:00
CosAngle=mcos(Angle);
SinAngle=msin(Angle);
SBox.XMin=(SinAngle*-dX)>>12;
SBox.XMax=(SinAngle*+dX)>>12;
SBox.YMin=(SinAngle*-dY)>>12;
SBox.YMax=0;
CBox.XMin=(CosAngle*-dX)>>12;
CBox.XMax=(CosAngle*+dX)>>12;
CBox.YMin=(CosAngle*-dY)>>12;
CBox.YMax=0;
2001-04-26 16:36:30 +02:00
int x0,x1,x2,x3;
int y0,y1,y2,y3;
int XMin,XMax;
int YMin,YMax;
x0=CBox.XMin-SBox.YMin; y0=SBox.XMin+CBox.YMin;
x1=CBox.XMax-SBox.YMin; y1=SBox.XMax+CBox.YMin;
x2=CBox.XMin+SBox.YMax; y2=SBox.XMin-CBox.YMax;
x3=CBox.XMax+SBox.YMax; y3=SBox.XMax-CBox.YMax;
XMin=x0;
if (XMin>x1) XMin=x1;
if (XMin>x2) XMin=x2;
if (XMin>x3) XMin=x3;
XMax=x0;
if (XMax<x1) XMax=x1;
if (XMax<x2) XMax=x2;
if (XMax<x3) XMax=x3;
YMin=y0;
if (YMin>y1) YMin=y1;
if (YMin>y2) YMin=y2;
if (YMin>y3) YMin=y3;
YMax=y0;
if (YMax<y1) YMax=y1;
if (YMax<y2) YMax=y2;
if (YMax<y3) YMax=y3;
2001-05-12 19:24:44 +02:00
BBox.XMin=XMin+BBOX_ADJ;
BBox.XMax=XMax-BBOX_ADJ;
BBox.YMin=YMin+BBOX_ADJ;
BBox.YMax=YMax-BBOX_ADJ;
2001-04-26 16:36:30 +02:00
Ft4->x0=Pos.vx+x0; Ft4->y0=Pos.vy+y0;
Ft4->x1=Pos.vx+x1; Ft4->y1=Pos.vy+y1;
Ft4->x2=Pos.vx+x2; Ft4->y2=Pos.vy+y2;
Ft4->x3=Pos.vx+x3; Ft4->y3=Pos.vy+y3;
2001-04-26 15:00:44 +02:00
return(Ft4);
}
2001-04-01 23:38:59 +02:00
/*****************************************************************************/
2001-05-15 19:40:54 +02:00
void CActorGfx::SetUpFT4(POLY_FT4 *Ft4,sPoolNode *Node,int X,int Y,bool XFlip,bool YFlip)
2001-04-01 23:38:59 +02:00
{
2001-06-18 23:26:06 +02:00
u8 W=CurrentFrameGfx->W-1;
u8 H=CurrentFrameGfx->H-1;
2001-04-25 18:41:16 +02:00
u8 U=Node->U;
u8 V=Node->V;
2001-04-01 09:22:30 +02:00
2001-04-01 23:38:59 +02:00
if (XFlip)
2001-04-04 17:54:27 +02:00
{
2001-05-15 19:40:54 +02:00
X-=CurrentFrame->XOfs;
2001-04-04 17:54:27 +02:00
X-=W;
2001-06-18 23:26:06 +02:00
Ft4->u0=U+W;
2001-06-11 22:36:53 +02:00
Ft4->u1=U;//-1;//
2001-06-18 23:26:06 +02:00
Ft4->u2=U+W;
2001-06-11 22:36:53 +02:00
Ft4->u3=U;//-1;//
2001-04-04 17:54:27 +02:00
}
2001-04-01 23:38:59 +02:00
else
{
2001-05-15 19:40:54 +02:00
X+=CurrentFrame->XOfs;
2001-04-01 23:38:59 +02:00
Ft4->u0=U;
2001-06-18 23:26:06 +02:00
Ft4->u1=U+W;
2001-04-01 23:38:59 +02:00
Ft4->u2=U;
2001-06-18 23:26:06 +02:00
Ft4->u3=U+W;
2001-04-04 17:54:27 +02:00
2001-04-01 23:38:59 +02:00
}
if (YFlip)
2001-04-04 17:54:27 +02:00
{
2001-05-15 19:40:54 +02:00
Y-=CurrentFrame->YOfs;
2001-04-04 17:54:27 +02:00
Y-=H;
2001-06-18 23:26:06 +02:00
Ft4->v0=V+H;
Ft4->v1=V+H;
2001-06-11 22:36:53 +02:00
Ft4->v2=V-1;//
Ft4->v3=V-1;//
2001-04-04 17:54:27 +02:00
}
2001-04-01 23:38:59 +02:00
else
{
2001-05-15 19:40:54 +02:00
Y+=CurrentFrame->YOfs;
2001-04-01 23:38:59 +02:00
Ft4->v0=V;
Ft4->v1=V;
2001-06-18 23:26:06 +02:00
Ft4->v2=V+H;
Ft4->v3=V+H;
2001-04-01 23:38:59 +02:00
}
setXYWH(Ft4,X,Y,W,H);
2001-06-21 21:19:15 +02:00
#if INGAME_SCREENW==512
2001-06-18 23:26:06 +02:00
// Correct Aspect
Ft4->x0-=CurrentFrameGfx->AspectX0;
Ft4->x1+=CurrentFrameGfx->AspectX1;
Ft4->x2-=CurrentFrameGfx->AspectX0;
Ft4->x3+=CurrentFrameGfx->AspectX1;
2001-06-21 21:19:15 +02:00
#endif
2001-04-01 09:22:30 +02:00
}
2001-06-18 23:26:06 +02:00
/*****************************************************************************/
/*****************************************************************************/
2001-04-21 00:20:58 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
sModel *CModelGfx::ModelTable;
sTri *CModelGfx::ModelTriList;
sQuad *CModelGfx::ModelQuadList;
sVtx *CModelGfx::ModelVtxList;
/*****************************************************************************/
void CModelGfx::SetData(sModel *Table,sTri *TList,sQuad *QList,sVtx *VList)
{
ModelTable=Table;
ModelTriList=TList;
ModelQuadList=QList;
ModelVtxList=VList;
2001-05-05 01:08:57 +02:00
2001-04-21 00:20:58 +02:00
}
/*****************************************************************************/
void CModelGfx::SetModel(int Type)
{
Model=&CModelGfx::ModelTable[Type];
}
/*****************************************************************************/
2001-05-09 18:27:33 +02:00
void CModelGfx::Render(DVECTOR &Pos,SVECTOR *Angle,VECTOR *Scale)
2001-04-21 00:20:58 +02:00
{
#define BLOCK_MULT 16
u8 *PrimPtr=GetPrimPtr();
POLY_FT3 *TPrimPtr=(POLY_FT3*)PrimPtr;
sVtx *P0,*P1,*P2;
u32 T0,T1,T2;
s32 ClipZ;
sOT *ThisOT;
DVECTOR MapXY;
VECTOR RenderPos;
int TriCount=Model->TriCount;
sTri *TList=&ModelTriList[Model->TriStart];
2001-04-27 22:28:47 +02:00
MATRIX Mtx;
2001-05-21 18:05:09 +02:00
// If has scale && angle then need to use PSX scale matrix, otherwise, force values
if (Angle)
{
RotMatrix_gte(Angle,&Mtx);
if (Scale)
{
ScaleMatrix(&Mtx,Scale);
}
}
2001-05-09 17:34:19 +02:00
else
2001-05-21 18:05:09 +02:00
{
if (Scale)
{
SetIdentNoTrans(&Mtx,Scale);
}
else
{
2001-05-09 17:34:19 +02:00
SetIdentNoTrans(&Mtx);
2001-05-21 18:05:09 +02:00
}
}
2001-04-21 00:20:58 +02:00
MapXY.vx=Pos.vx>>4;
MapXY.vy=Pos.vy>>4;
int ShiftX=(Pos.vx & 15);
int ShiftY=(Pos.vy & 15);
2001-06-21 21:19:15 +02:00
RenderPos.vx=INGAME_SCREENOFS_X+((MapXY.vx*16)+ShiftX);
RenderPos.vy=INGAME_SCREENOFS_Y+((MapXY.vy*16)+ShiftY);
2001-04-21 00:20:58 +02:00
2001-04-27 22:28:47 +02:00
gte_SetRotMatrix(&Mtx);
2001-04-21 00:20:58 +02:00
CMX_SetTransMtxXY(&RenderPos);
while (TriCount--)
{
P0=&ModelVtxList[TList->P0]; P1=&ModelVtxList[TList->P1]; P2=&ModelVtxList[TList->P2];
gte_ldv3(P0,P1,P2);
setlen(TPrimPtr, GPU_PolyFT3Tag);
2001-05-02 20:40:41 +02:00
TPrimPtr->code=TList->PolyCode;
setRGB0(TPrimPtr,128,128,128);
2001-04-21 00:20:58 +02:00
gte_rtpt_b();
T0=*(u32*)&TList->uv0; // Get UV0 & TPage
T1=*(u32*)&TList->uv1; // Get UV1 & Clut
T2=*(u16*)&TList->uv2; // Get UV2
*(u32*)&TPrimPtr->u0=T0; // Set UV0
*(u32*)&TPrimPtr->u1=T1; // Set UV1
*(u16*)&TPrimPtr->u2=T2; // Set UV2
2001-05-09 17:34:19 +02:00
/*
2001-05-05 01:08:57 +02:00
if (TList->OTOfs>ActorOT)
{
ThisOT=OtPtr+(ActorOT+1);
}
else
{
ThisOT=OtPtr+(ActorOT-1);
}
2001-05-09 17:34:19 +02:00
*/
ThisOT=OtPtr+TList->OTOfs;
2001-05-05 01:08:57 +02:00
2001-04-21 00:20:58 +02:00
TList++;
2001-05-09 17:34:19 +02:00
addPrim(ThisOT,TPrimPtr);
gte_stsxy3_ft3(TPrimPtr);
TPrimPtr++;
/* Models are not clipped
2001-04-21 00:20:58 +02:00
gte_nclip_b();
gte_stsxy3_ft3(TPrimPtr);
gte_stopz(&ClipZ);
if (ClipZ<=0)
{
addPrim(ThisOT,TPrimPtr);
TPrimPtr++;
}
2001-05-09 17:34:19 +02:00
*/
2001-04-21 00:20:58 +02:00
}
SetPrimPtr((u8*)TPrimPtr);
}