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-08-04 18:13:47 +02:00
|
|
|
#include "game\game.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;
|
2001-08-13 18:33:04 +02:00
|
|
|
while(DrawSync(1));
|
2001-04-26 23:15:36 +02:00
|
|
|
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;
|
|
|
|
OtPos=OTPOS__ACTOR_POS;
|
|
|
|
}
|
|
|
|
|
2001-04-01 09:22:30 +02:00
|
|
|
/*****************************************************************************/
|
2001-08-04 18:13:47 +02:00
|
|
|
sPoolNode *CActorGfx::CacheFrame(int Anim,int Frame)
|
2001-04-01 09:22:30 +02:00
|
|
|
{
|
2001-05-12 01:52:38 +02:00
|
|
|
sPoolNode *ThisNode,*FindNode;
|
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-08-04 18:13:47 +02:00
|
|
|
return(ThisNode);
|
2001-07-22 03:18:20 +02:00
|
|
|
}
|
|
|
|
|
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-08-03 00:04:30 +02:00
|
|
|
int AspectX0,AspectX1;
|
2001-08-04 18:13:47 +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-08-03 00:04:30 +02:00
|
|
|
AspectX0=CurrentFrameGfx->AspectX1;
|
|
|
|
AspectX1=CurrentFrameGfx->AspectX0;
|
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-08-03 00:04:30 +02:00
|
|
|
AspectX0=CurrentFrameGfx->AspectX0;
|
|
|
|
AspectX1=CurrentFrameGfx->AspectX1;
|
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
|
2001-08-03 00:04:30 +02:00
|
|
|
Ft4->x0-=AspectX0;
|
|
|
|
Ft4->x1+=AspectX1;
|
|
|
|
Ft4->x2-=AspectX0;
|
|
|
|
Ft4->x3+=AspectX1;
|
2001-06-21 21:19:15 +02:00
|
|
|
#endif
|
2001-04-01 09:22:30 +02:00
|
|
|
}
|
|
|
|
|
2001-08-04 18:13:47 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
POLY_FT4 *CActorGfx::Render(DVECTOR &Pos,int Anim,int Frame,bool XFlip,bool YFlip)
|
|
|
|
{
|
|
|
|
sPoolNode *ThisNode=CacheFrame(Anim,Frame);
|
2001-08-04 23:27:12 +02:00
|
|
|
if (!ThisNode) return(0); // Blank Frame
|
2001-08-04 18:13:47 +02:00
|
|
|
POLY_FT4 *Ft4=GetPrimFT4();
|
|
|
|
|
|
|
|
SetUpFT4(Ft4,ThisNode,Pos.vx,Pos.vy,XFlip,YFlip);
|
|
|
|
Ft4->tpage=ThisNode->TPage;
|
|
|
|
Ft4->clut=PoolEntry->ActorGfx->Clut;
|
|
|
|
setShadeTex(Ft4,1);
|
|
|
|
setRGB0(Ft4,127,127,127);
|
|
|
|
addPrim(OtPtr+OtPos,Ft4);
|
|
|
|
|
|
|
|
// Set BBox
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
BBox.XMin=-HalfW+BBOX_ADJ;
|
|
|
|
BBox.XMax=+HalfW-BBOX_ADJ;
|
|
|
|
BBox.YMin=-BBoxH+BBOX_ADJ;
|
|
|
|
BBox.YMax=0-BBOX_ADJ;
|
|
|
|
|
|
|
|
return(Ft4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static const VECTOR ZeroPos={0,0,0};
|
|
|
|
static const int ScaleXAspect=2050; // Odd hard coded number, sorry
|
|
|
|
|
2001-08-14 19:07:48 +02:00
|
|
|
POLY_FT4 *CActorGfx::RotateScale(POLY_FT4 *Ft4,DVECTOR &Pos,int Angle,int XScale,int YScale,bool Force)
|
2001-08-04 18:13:47 +02:00
|
|
|
{
|
|
|
|
MATRIX Mtx;
|
|
|
|
VECTOR Scale;
|
|
|
|
|
|
|
|
Angle&=4095;
|
2001-08-14 19:07:48 +02:00
|
|
|
if (Angle==0 && XScale==ONE && YScale==ONE && !Force) return(Ft4);
|
2001-08-04 18:13:47 +02:00
|
|
|
|
2001-08-13 21:01:44 +02:00
|
|
|
Scale.vx=XScale;
|
|
|
|
Scale.vy=YScale;
|
2001-08-04 18:13:47 +02:00
|
|
|
Scale.vz=ONE;
|
|
|
|
SetIdentNoTrans(&Mtx);
|
|
|
|
RotMatrixZ(Angle,&Mtx);
|
2001-08-13 21:01:44 +02:00
|
|
|
ScaleMatrix(&Mtx,&Scale);
|
|
|
|
CorrectMatrixScale(&Mtx);
|
2001-08-04 18:13:47 +02:00
|
|
|
gte_SetRotMatrix(&Mtx);
|
|
|
|
CMX_SetTransMtxXY(&ZeroPos);
|
|
|
|
|
|
|
|
|
|
|
|
SVECTOR I,O;
|
|
|
|
s32 Tmp;
|
|
|
|
I.vz=0;
|
|
|
|
I.vy=-CurrentFrameGfx->H;
|
|
|
|
I.vx=-CurrentFrameGfx->W0; RotTransSV(&I,&O,&Tmp); Ft4->x0=O.vx; Ft4->y0=O.vy;
|
|
|
|
I.vx=+CurrentFrameGfx->W1; RotTransSV(&I,&O,&Tmp); Ft4->x1=O.vx; Ft4->y1=O.vy;
|
|
|
|
I.vy=0;
|
|
|
|
I.vx=-CurrentFrameGfx->W0; RotTransSV(&I,&O,&Tmp); Ft4->x2=O.vx; Ft4->y2=O.vy;
|
|
|
|
I.vx=+CurrentFrameGfx->W1; RotTransSV(&I,&O,&Tmp); Ft4->x3=O.vx; Ft4->y3=O.vy;
|
|
|
|
|
|
|
|
// Adjust BBox
|
|
|
|
int XMin,XMax;
|
|
|
|
int YMin,YMax;
|
|
|
|
|
|
|
|
XMin=Ft4->x0;
|
|
|
|
if (XMin>Ft4->x1) XMin=Ft4->x1;
|
|
|
|
if (XMin>Ft4->x2) XMin=Ft4->x2;
|
|
|
|
if (XMin>Ft4->x3) XMin=Ft4->x3;
|
|
|
|
XMax=Ft4->x0;
|
|
|
|
if (XMax<Ft4->x1) XMax=Ft4->x1;
|
|
|
|
if (XMax<Ft4->x2) XMax=Ft4->x2;
|
|
|
|
if (XMax<Ft4->x3) XMax=Ft4->x3;
|
|
|
|
YMin=Ft4->y0;
|
|
|
|
if (YMin>Ft4->y1) YMin=Ft4->y1;
|
|
|
|
if (YMin>Ft4->y2) YMin=Ft4->y2;
|
|
|
|
if (YMin>Ft4->y3) YMin=Ft4->y3;
|
|
|
|
YMax=Ft4->y0;
|
|
|
|
if (YMax<Ft4->y1) YMax=Ft4->y1;
|
|
|
|
if (YMax<Ft4->y2) YMax=Ft4->y2;
|
|
|
|
if (YMax<Ft4->y3) YMax=Ft4->y3;
|
|
|
|
|
|
|
|
BBox.XMin=XMin+BBOX_ADJ;
|
|
|
|
BBox.XMax=XMax-BBOX_ADJ;
|
|
|
|
BBox.YMin=YMin+BBOX_ADJ;
|
|
|
|
BBox.YMax=YMax-BBOX_ADJ;
|
|
|
|
|
|
|
|
Ft4->x0+=Pos.vx; Ft4->y0+=Pos.vy;
|
|
|
|
Ft4->x1+=Pos.vx; Ft4->y1+=Pos.vy;
|
|
|
|
Ft4->x2+=Pos.vx; Ft4->y2+=Pos.vy;
|
|
|
|
Ft4->x3+=Pos.vx; Ft4->y3+=Pos.vy;
|
|
|
|
|
|
|
|
return(Ft4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CActorGfx::getFrameOffsets(int _anim,int _frame,int *_x,int *_y)
|
|
|
|
{
|
|
|
|
sSpriteAnimBank *SpriteBank;
|
|
|
|
sSpriteAnim *ThisAnim;
|
|
|
|
sSpriteFrame *pFrame;
|
|
|
|
|
|
|
|
SpriteBank=PoolEntry->ActorGfx;
|
|
|
|
ThisAnim=SpriteBank->AnimList+_anim;
|
|
|
|
pFrame=&ThisAnim->Anim[_frame];
|
|
|
|
*_x=pFrame->XOfs;
|
|
|
|
*_y=pFrame->YOfs;
|
|
|
|
}
|
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;
|
2001-07-24 22:17:50 +02:00
|
|
|
sElem3d *CModelGfx::ElemBank;
|
|
|
|
sTri *CModelGfx::TriList;
|
|
|
|
sQuad *CModelGfx::QuadList;
|
|
|
|
sVtx *CModelGfx::VtxList;
|
|
|
|
u16 *CModelGfx::VtxIdxList;
|
2001-04-21 00:20:58 +02:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-06-28 19:48:30 +02:00
|
|
|
void CModelGfx::SetData(sLevelHdr *LevelHdr)
|
2001-04-21 00:20:58 +02:00
|
|
|
{
|
2001-06-28 19:48:30 +02:00
|
|
|
ModelTable=LevelHdr->ModelList;
|
2001-07-24 22:17:50 +02:00
|
|
|
ElemBank=LevelHdr->ElemBank3d;
|
|
|
|
TriList=LevelHdr->TriList;
|
|
|
|
QuadList=LevelHdr->QuadList;
|
|
|
|
VtxList=LevelHdr->VtxList;
|
|
|
|
VtxIdxList=LevelHdr->VtxIdxList;
|
2001-04-21 00:20:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CModelGfx::SetModel(int Type)
|
|
|
|
{
|
|
|
|
Model=&CModelGfx::ModelTable[Type];
|
2001-07-24 22:17:50 +02:00
|
|
|
Elem=&ElemBank[Model->ElemID];
|
2001-04-21 00:20:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-07-24 22:17:50 +02:00
|
|
|
static const int ElemXMin=-(16/2);
|
|
|
|
static const int ElemXMax=+(16/2);
|
|
|
|
static const int ElemYMin=-(16/2);
|
|
|
|
static const int ElemYMax=+(16/2);
|
|
|
|
static const int ElemZMin=-(16*4);
|
|
|
|
static const int ElemZMax=+(16*4);
|
|
|
|
|
|
|
|
static VECTOR VtxTable[8]=
|
|
|
|
{
|
|
|
|
{ElemXMin,ElemYMin,ElemZMin}, // FLU
|
|
|
|
{ElemXMax,ElemYMin,ElemZMin}, // FRU
|
|
|
|
{ElemXMin,ElemYMax,ElemZMin}, // FLD
|
|
|
|
{ElemXMax,ElemYMax,ElemZMin}, // FRD
|
|
|
|
|
|
|
|
{ElemXMin,ElemYMin,ElemZMax}, // BLU
|
|
|
|
{ElemXMax,ElemYMin,ElemZMax}, // BRU
|
|
|
|
{ElemXMin,ElemYMax,ElemZMax}, // BLD
|
|
|
|
{ElemXMax,ElemYMax,ElemZMax}, // BRD
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CModelGfx::RenderTile(DVECTOR &Pos,int TileID)
|
|
|
|
{
|
|
|
|
sElem3d *ThisElem=&ElemBank[TileID];
|
|
|
|
u32 *XYList=(u32*)SCRATCH_RAM;
|
|
|
|
u32 *OutVtx=XYList;
|
|
|
|
VECTOR *V0,*V1,*V2,*InVtx=VtxTable;
|
|
|
|
VECTOR RenderPos;
|
|
|
|
MATRIX Mtx;
|
|
|
|
|
|
|
|
SetIdentNoTrans(&Mtx);
|
|
|
|
RenderPos.vx=(INGAME_SCREENOFS_X)+Pos.vx;
|
|
|
|
RenderPos.vy=(INGAME_SCREENOFS_Y)+Pos.vy;
|
|
|
|
gte_SetRotMatrix(&Mtx);
|
|
|
|
CMX_SetTransMtxXY(&RenderPos);
|
|
|
|
|
|
|
|
V0=InVtx++;
|
|
|
|
V1=InVtx++;
|
|
|
|
V2=InVtx++;
|
|
|
|
gte_ldv3(V0,V1,V2);
|
|
|
|
for (int i=0; i<(int)((sizeof(VtxTable)/sizeof(VECTOR))+1); i++)
|
|
|
|
{
|
|
|
|
u32 *OutPtr;
|
|
|
|
gte_rtpt(); // 22 cycles
|
|
|
|
V0=InVtx++;
|
|
|
|
V1=InVtx++;
|
|
|
|
V2=InVtx++;
|
|
|
|
gte_ldv3(V0,V1,V2);
|
|
|
|
OutPtr=OutVtx;
|
|
|
|
OutVtx+=3;
|
|
|
|
gte_stsxy3c(OutPtr); // read XY back
|
|
|
|
}
|
|
|
|
XYList+=8;
|
|
|
|
RenderElem(ThisElem,Pos,0,0,0,XYList);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CModelGfx::RenderElem(sElem3d *ThisElem,DVECTOR &Pos,SVECTOR *Angle,VECTOR *Scale,s32 ClipFlag,u32 *TransBuffer)
|
2001-04-21 00:20:58 +02:00
|
|
|
{
|
|
|
|
u8 *PrimPtr=GetPrimPtr();
|
2001-07-24 22:17:50 +02:00
|
|
|
u32 T0,T1,T2,T3;
|
2001-04-21 00:20:58 +02:00
|
|
|
s32 ClipZ;
|
|
|
|
sOT *ThisOT;
|
|
|
|
VECTOR RenderPos;
|
2001-07-24 22:17:50 +02:00
|
|
|
MATRIX Mtx;
|
2001-08-04 20:21:12 +02:00
|
|
|
//u32 const *XYList=(u32*)SCRATCH_RAM;
|
|
|
|
u8 const *XYList=(u8*)SCRATCH_RAM;
|
2001-04-27 22:28:47 +02:00
|
|
|
|
2001-08-04 18:13:47 +02:00
|
|
|
|
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
|
|
|
|
2001-07-23 21:26:37 +02:00
|
|
|
RenderPos.vx=(INGAME_SCREENOFS_X)+Pos.vx;
|
|
|
|
RenderPos.vy=(INGAME_SCREENOFS_Y)+Pos.vy;
|
2001-04-27 22:28:47 +02:00
|
|
|
gte_SetRotMatrix(&Mtx);
|
2001-04-21 00:20:58 +02:00
|
|
|
CMX_SetTransMtxXY(&RenderPos);
|
|
|
|
|
2001-07-24 22:17:50 +02:00
|
|
|
// --- Cache Vtx ----------
|
|
|
|
{
|
|
|
|
int Count=ThisElem->VtxTriCount;
|
|
|
|
sVtx *V0,*V1,*V2;
|
|
|
|
u16 *IdxTable=&VtxIdxList[ThisElem->VtxIdxStart];
|
|
|
|
|
|
|
|
V0=&VtxList[*IdxTable++];
|
|
|
|
V1=&VtxList[*IdxTable++];
|
|
|
|
V2=&VtxList[*IdxTable++];
|
|
|
|
gte_ldv3(V0,V1,V2);
|
|
|
|
|
|
|
|
while (Count--)
|
|
|
|
{
|
|
|
|
u32 *OutPtr;
|
|
|
|
gte_rtpt_b(); // 22 cycles
|
|
|
|
// Preload next (when able) - Must check this
|
|
|
|
V0=&VtxList[*IdxTable++];
|
|
|
|
V1=&VtxList[*IdxTable++];
|
|
|
|
V2=&VtxList[*IdxTable++];
|
|
|
|
OutPtr=TransBuffer;
|
|
|
|
TransBuffer+=3;
|
|
|
|
gte_ldv3(V0,V1,V2);
|
|
|
|
gte_stsxy3c(OutPtr); // read XY back
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- Render Tri's -------------
|
|
|
|
|
|
|
|
int TriCount=ThisElem->TriCount;
|
|
|
|
sTri *TList=&TriList[ThisElem->TriStart];
|
2001-04-21 00:20:58 +02:00
|
|
|
while (TriCount--)
|
|
|
|
{
|
2001-07-25 23:37:17 +02:00
|
|
|
POLY_GT3 *ThisPrim=(POLY_GT3*)PrimPtr;
|
2001-07-24 22:17:50 +02:00
|
|
|
|
2001-08-04 20:21:12 +02:00
|
|
|
T0=*(u32*)(XYList+TList->P0);
|
|
|
|
T1=*(u32*)(XYList+TList->P1);
|
|
|
|
T2=*(u32*)(XYList+TList->P2);
|
|
|
|
gte_ldsxy0(T0);
|
|
|
|
gte_ldsxy1(T1);
|
|
|
|
gte_ldsxy2(T2);
|
2001-07-24 22:17:50 +02:00
|
|
|
|
2001-07-25 23:37:17 +02:00
|
|
|
setlen(ThisPrim, GPU_PolyGT3Tag);
|
2001-07-24 22:17:50 +02:00
|
|
|
ThisPrim->code=TList->PolyCode;
|
|
|
|
gte_nclip_b(); // 8 cycles
|
|
|
|
|
|
|
|
setShadeTex(ThisPrim,1);
|
|
|
|
|
2001-08-04 20:21:12 +02:00
|
|
|
*(u32*)&ThisPrim->x0=T0; // Set XY0
|
|
|
|
*(u32*)&ThisPrim->x1=T1; // Set XY1
|
|
|
|
*(u32*)&ThisPrim->x2=T2; // Set XY2
|
2001-04-21 00:20:58 +02:00
|
|
|
T0=*(u32*)&TList->uv0; // Get UV0 & TPage
|
|
|
|
T1=*(u32*)&TList->uv1; // Get UV1 & Clut
|
2001-07-23 21:26:37 +02:00
|
|
|
T2=*(u32*)&TList->uv2; // Get UV2
|
2001-07-24 22:17:50 +02:00
|
|
|
|
|
|
|
gte_stopz(&ClipZ);
|
2001-05-09 17:34:19 +02:00
|
|
|
ThisOT=OtPtr+TList->OTOfs;
|
2001-07-24 22:17:50 +02:00
|
|
|
ClipZ|=ClipFlag; // <-- Evil!!
|
2001-04-21 00:20:58 +02:00
|
|
|
TList++;
|
2001-07-24 22:17:50 +02:00
|
|
|
if (ClipZ<0)
|
|
|
|
{
|
2001-08-04 20:21:12 +02:00
|
|
|
*(u32*)&ThisPrim->u0=T0; // Set UV0
|
|
|
|
*(u32*)&ThisPrim->u1=T1; // Set UV1
|
|
|
|
*(u32*)&ThisPrim->u2=T2; // Set UV2
|
2001-07-24 22:17:50 +02:00
|
|
|
addPrim(ThisOT,ThisPrim);
|
2001-07-25 23:37:17 +02:00
|
|
|
PrimPtr+=sizeof(POLY_GT3);
|
2001-07-24 22:17:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- Render Quads -----------
|
|
|
|
int QuadCount=ThisElem->QuadCount;
|
|
|
|
sQuad *QList=&QuadList[ThisElem->QuadStart];
|
|
|
|
while (QuadCount--)
|
|
|
|
{
|
2001-07-25 23:37:17 +02:00
|
|
|
POLY_GT4 *ThisPrim=(POLY_GT4*)PrimPtr;
|
2001-07-24 22:17:50 +02:00
|
|
|
|
2001-08-04 20:21:12 +02:00
|
|
|
T0=*(u32*)(XYList+QList->P0);
|
|
|
|
T1=*(u32*)(XYList+QList->P1);
|
|
|
|
T2=*(u32*)(XYList+QList->P2);
|
|
|
|
T3=*(u32*)(XYList+QList->P3);
|
|
|
|
gte_ldsxy0(T0);
|
|
|
|
gte_ldsxy1(T1);
|
|
|
|
gte_ldsxy2(T2);
|
2001-07-24 22:17:50 +02:00
|
|
|
|
2001-07-25 23:37:17 +02:00
|
|
|
setlen(ThisPrim, GPU_PolyGT4Tag);
|
2001-07-24 22:17:50 +02:00
|
|
|
ThisPrim->code=QList->PolyCode;
|
|
|
|
gte_nclip_b(); // 8 cycles
|
|
|
|
|
|
|
|
setShadeTex(ThisPrim,1);
|
|
|
|
|
2001-08-04 20:21:12 +02:00
|
|
|
*(u32*)&ThisPrim->x0=T0; // Set XY0
|
|
|
|
*(u32*)&ThisPrim->x1=T1; // Set XY1
|
|
|
|
*(u32*)&ThisPrim->x2=T2; // Set XY2
|
|
|
|
*(u32*)&ThisPrim->x3=T3; // Set XY3
|
2001-07-24 22:17:50 +02:00
|
|
|
T0=*(u32*)&QList->uv0; // Get UV0 & TPage
|
|
|
|
T1=*(u32*)&QList->uv1; // Get UV1 & Clut
|
|
|
|
T2=*(u32*)&QList->uv2; // Get UV2
|
|
|
|
T3=*(u32*)&QList->uv3; // Get UV2
|
2001-07-23 16:53:45 +02:00
|
|
|
gte_stopz(&ClipZ);
|
2001-07-24 22:17:50 +02:00
|
|
|
ThisOT=OtPtr+QList->OTOfs;
|
|
|
|
ClipZ|=ClipFlag; // <-- Evil!!
|
|
|
|
QList++;
|
|
|
|
if (ClipZ<0)
|
2001-07-23 16:53:45 +02:00
|
|
|
{
|
2001-08-04 20:21:12 +02:00
|
|
|
*(u32*)&ThisPrim->u0=T0; // Set UV0
|
|
|
|
*(u32*)&ThisPrim->u1=T1; // Set UV1
|
|
|
|
*(u32*)&ThisPrim->u2=T2; // Set UV2
|
|
|
|
*(u32*)&ThisPrim->u3=T3; // Set UV2
|
2001-07-24 22:17:50 +02:00
|
|
|
addPrim(ThisOT,ThisPrim);
|
2001-07-25 23:37:17 +02:00
|
|
|
PrimPtr+=sizeof(POLY_GT4);
|
2001-07-23 16:53:45 +02:00
|
|
|
}
|
2001-04-21 00:20:58 +02:00
|
|
|
}
|
|
|
|
|
2001-07-24 22:17:50 +02:00
|
|
|
SetPrimPtr(PrimPtr);
|
2001-06-28 19:48:30 +02:00
|
|
|
|
2001-04-21 00:20:58 +02:00
|
|
|
}
|
2001-07-23 21:26:37 +02:00
|
|
|
|