This commit is contained in:
parent
0127ef78a1
commit
3ccf82adbe
4 changed files with 117 additions and 32 deletions
|
@ -213,6 +213,7 @@ void CGameScene::render()
|
||||||
SetTransMatrix(&CamMtx);
|
SetTransMatrix(&CamMtx);
|
||||||
|
|
||||||
Level.render();
|
Level.render();
|
||||||
|
CActorPool::CleanUpCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -39,11 +39,14 @@ CActorCache::~CActorCache()
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int CActorCache::GetSizeType(int Size)
|
int CActorCache::GetSizeType(int Size)
|
||||||
{
|
{
|
||||||
if (Size<= 16) return(16);
|
// if (Size<= 16) return(16);
|
||||||
if (Size<= 32) return(32);
|
// if (Size<= 32) return(32);
|
||||||
if (Size<= 64) return(64);
|
// if (Size<= 64) return(64);
|
||||||
if (Size<=128) return(128);
|
// if (Size<=128) return(128);
|
||||||
if (Size<=256) return(256);
|
// if (Size<=256) return(256);
|
||||||
|
// Size>>=4;
|
||||||
|
// Size<<=4;
|
||||||
|
return(Size);
|
||||||
ASSERT(!"SPRITE SIZE NOT SUPPORTED");
|
ASSERT(!"SPRITE SIZE NOT SUPPORTED");
|
||||||
|
|
||||||
return(-1);
|
return(-1);
|
||||||
|
@ -79,10 +82,10 @@ int Slot=0;
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
sPoolNode *CActorCache::RemoveHeadNode(sNodeList *Root)
|
sPoolNode *CActorCache::RemoveHeadNode(sNodeList *Root)
|
||||||
{
|
{
|
||||||
sPoolNode *Node=Root->List;
|
sPoolNode *Node=Root->Head;
|
||||||
sPoolNode *Next=Node->Next;
|
sPoolNode *Next=Node->Next;
|
||||||
|
|
||||||
Root->List=Node->Next;
|
Root->Head=Node->Next;
|
||||||
Next->Prev=0;
|
Next->Prev=0;
|
||||||
Node->Next=0;
|
Node->Next=0;
|
||||||
return(Node);
|
return(Node);
|
||||||
|
@ -108,7 +111,7 @@ sPoolNode *Next=Node->Next;
|
||||||
// Add node to end of list
|
// Add node to end of list
|
||||||
void CActorCache::AddNode(sPoolNode *Node,sNodeList *Root)
|
void CActorCache::AddNode(sPoolNode *Node,sNodeList *Root)
|
||||||
{
|
{
|
||||||
sPoolNode *Prev=Root->LastNode;
|
sPoolNode *Prev=Root->Tail;
|
||||||
sPoolNode *Next=0;
|
sPoolNode *Next=0;
|
||||||
|
|
||||||
if (Prev)
|
if (Prev)
|
||||||
|
@ -117,12 +120,40 @@ sPoolNode *Next=0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Root->List=Node;
|
Root->Head=Node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node->Prev=Prev;
|
Node->Prev=Prev;
|
||||||
Node->Next=0;
|
Node->Next=0;
|
||||||
Root->LastNode=Node;
|
Root->Tail=Node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
if (!SrcHead) return;
|
||||||
|
|
||||||
|
if (!DstTail)
|
||||||
|
{
|
||||||
|
Dst->Head=SrcHead;
|
||||||
|
SrcHead->Prev=0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DstTail->Next=SrcHead;
|
||||||
|
SrcHead->Prev=DstTail;
|
||||||
|
}
|
||||||
|
|
||||||
|
SrcTail->Next=0;
|
||||||
|
Dst->Tail=SrcTail;
|
||||||
|
Src->Head=0;
|
||||||
|
Src->Tail=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -196,8 +227,8 @@ void CActorCache::Reset()
|
||||||
{
|
{
|
||||||
if (SlotList[i].ListMem) MemFree(SlotList[i].ListMem);
|
if (SlotList[i].ListMem) MemFree(SlotList[i].ListMem);
|
||||||
SlotList[i].ListMem=0;
|
SlotList[i].ListMem=0;
|
||||||
SlotList[i].NodeList.List=0;
|
SlotList[i].NodeList.Head=0;
|
||||||
SlotList[i].NodeList.LastNode=0;
|
SlotList[i].NodeList.Tail=0;
|
||||||
SlotList[i].RefCount=0;
|
SlotList[i].RefCount=0;
|
||||||
SlotList[i].FrameCount=0;
|
SlotList[i].FrameCount=0;
|
||||||
SlotList[i].Width=0;
|
SlotList[i].Width=0;
|
||||||
|
@ -285,9 +316,9 @@ sActorPool *List=ActorList;
|
||||||
|
|
||||||
while (List)
|
while (List)
|
||||||
{
|
{
|
||||||
List->CachePool=Cache.GetSlotList(List->CacheSlot);
|
List->PoolCache=Cache.GetSlotList(List->CacheSlot);
|
||||||
List->ThisCache.List=0;
|
List->ActorCache.Head=0;
|
||||||
List->ThisCache.LastNode=0;
|
List->ActorCache.Tail=0;
|
||||||
List=List->Next;
|
List=List->Next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,7 +370,6 @@ int TotalFrames=0;
|
||||||
|
|
||||||
sSpriteAnimBank *Spr=(sSpriteAnimBank*)CFileIO::loadFile(Filename,"ActorGfx");
|
sSpriteAnimBank *Spr=(sSpriteAnimBank*)CFileIO::loadFile(Filename,"ActorGfx");
|
||||||
|
|
||||||
// printf("Add Actor %i\n",(int)Filename);
|
|
||||||
Spr->AnimList=(sSpriteAnim*) MakePtr(Spr,(int)Spr->AnimList);
|
Spr->AnimList=(sSpriteAnim*) MakePtr(Spr,(int)Spr->AnimList);
|
||||||
Spr->FrameList=(sSpriteFrame*) MakePtr(Spr,(int)Spr->FrameList);
|
Spr->FrameList=(sSpriteFrame*) MakePtr(Spr,(int)Spr->FrameList);
|
||||||
Spr->Palette=(u8*) MakePtr(Spr,(int)Spr->Palette);
|
Spr->Palette=(u8*) MakePtr(Spr,(int)Spr->Palette);
|
||||||
|
@ -387,6 +417,18 @@ void CActorPool::AddActor(sActorPool *NewActor)
|
||||||
Cache.LoadPalette(NewActor);
|
Cache.LoadPalette(NewActor);
|
||||||
LastActor=NewActor;
|
LastActor=NewActor;
|
||||||
}
|
}
|
||||||
|
/*****************************************************************************/
|
||||||
|
void CActorPool::CleanUpCache()
|
||||||
|
{
|
||||||
|
sActorPool *Actor=ActorList;
|
||||||
|
|
||||||
|
while (Actor)
|
||||||
|
{
|
||||||
|
CActorCache::AddNodeList(&Actor->ActorCache ,Actor->PoolCache);
|
||||||
|
Actor=Actor->Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -439,18 +481,40 @@ POLY_FT4 *Ft4;
|
||||||
|
|
||||||
CurrentFrame=GetFrame(Anim,Frame);
|
CurrentFrame=GetFrame(Anim,Frame);
|
||||||
// Is cached?
|
// Is cached?
|
||||||
ThisNode=PoolEntry->ThisCache.List;
|
ThisNode=PoolEntry->ActorCache.Head;
|
||||||
while (ThisNode)
|
while (ThisNode)
|
||||||
{
|
{ // Try local Cache (From Head forward)
|
||||||
if (ThisNode->Actor==PoolEntry->Filename && ThisNode->Anim==Anim && ThisNode->Frame==Frame) break;
|
if (ThisNode->Actor==PoolEntry->Filename && ThisNode->Anim==Anim && ThisNode->Frame==Frame) break;
|
||||||
ThisNode=ThisNode->Next;
|
ThisNode=ThisNode->Next;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
if (!ThisNode)
|
||||||
|
{ // Try main cache ( from tail back)
|
||||||
|
|
||||||
|
ThisNode=PoolEntry->PoolCache->Tail;
|
||||||
|
while (ThisNode)
|
||||||
|
{
|
||||||
|
if (ThisNode->Actor==PoolEntry->Filename && ThisNode->Anim==Anim && ThisNode->Frame==Frame) break;
|
||||||
|
if (ThisNode->Prev==PoolEntry->PoolCache->Tail) ThisNode->Prev=0;
|
||||||
|
ThisNode=ThisNode->Prev;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (ThisNode)
|
||||||
|
{
|
||||||
|
CActorCache::RemoveNode(ThisNode,PoolEntry->PoolCache);
|
||||||
|
CActorCache::AddNode(ThisNode,&PoolEntry->ActorCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
if (!ThisNode)
|
if (!ThisNode)
|
||||||
{ // Not cached frame
|
{ // Not cached frame
|
||||||
ThisNode=CActorCache::RemoveHeadNode(PoolEntry->CachePool);
|
ThisNode=CActorCache::RemoveHeadNode(PoolEntry->PoolCache);
|
||||||
CActorCache::AddNode(ThisNode,&PoolEntry->ThisCache);
|
CActorCache::AddNode(ThisNode,&PoolEntry->ActorCache);
|
||||||
RECT R;
|
RECT R;
|
||||||
|
ASSERT(ThisNode);
|
||||||
|
|
||||||
ThisNode->Actor=PoolEntry->Filename;
|
ThisNode->Actor=PoolEntry->Filename;
|
||||||
ThisNode->Anim=Anim;
|
ThisNode->Anim=Anim;
|
||||||
|
@ -640,14 +704,13 @@ void CModelGfx::SetModel(int Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int DX=1;
|
//int DX=1;
|
||||||
int DY=1;
|
//int DY=1;
|
||||||
int PXOfs=-16;
|
const int PXOfs=-16;
|
||||||
int PYOfs=-6;
|
const int PYOfs=-6;
|
||||||
int blah=0;
|
|
||||||
void CModelGfx::Render(DVECTOR &Pos)
|
void CModelGfx::Render(DVECTOR &Pos,SVECTOR *Angle=0,VECTOR *Scale=0)
|
||||||
{
|
{
|
||||||
Model=&CModelGfx::ModelTable[blah];
|
|
||||||
#define BLOCK_MULT 16
|
#define BLOCK_MULT 16
|
||||||
u8 *PrimPtr=GetPrimPtr();
|
u8 *PrimPtr=GetPrimPtr();
|
||||||
POLY_FT3 *TPrimPtr=(POLY_FT3*)PrimPtr;
|
POLY_FT3 *TPrimPtr=(POLY_FT3*)PrimPtr;
|
||||||
|
@ -659,6 +722,14 @@ DVECTOR MapXY;
|
||||||
VECTOR RenderPos;
|
VECTOR RenderPos;
|
||||||
int TriCount=Model->TriCount;
|
int TriCount=Model->TriCount;
|
||||||
sTri *TList=&ModelTriList[Model->TriStart];
|
sTri *TList=&ModelTriList[Model->TriStart];
|
||||||
|
MATRIX Mtx;
|
||||||
|
|
||||||
|
SetIdentNoTrans(&Mtx);
|
||||||
|
if (Scale || Angle)
|
||||||
|
{
|
||||||
|
if (Angle) RotMatrix(Angle,&Mtx);
|
||||||
|
if (Scale) ScaleMatrix(&Mtx,Scale);
|
||||||
|
}
|
||||||
|
|
||||||
MapXY.vx=Pos.vx>>4;
|
MapXY.vx=Pos.vx>>4;
|
||||||
MapXY.vy=Pos.vy>>4;
|
MapXY.vy=Pos.vy>>4;
|
||||||
|
@ -669,6 +740,7 @@ int ShiftY=(Pos.vy & 15);
|
||||||
RenderPos.vx=(PXOfs*16)+((MapXY.vx*16)+ShiftX);
|
RenderPos.vx=(PXOfs*16)+((MapXY.vx*16)+ShiftX);
|
||||||
RenderPos.vy=(PYOfs*16)+((MapXY.vy*16)+ShiftY);
|
RenderPos.vy=(PYOfs*16)+((MapXY.vy*16)+ShiftY);
|
||||||
|
|
||||||
|
gte_SetRotMatrix(&Mtx);
|
||||||
CMX_SetTransMtxXY(&RenderPos);
|
CMX_SetTransMtxXY(&RenderPos);
|
||||||
|
|
||||||
while (TriCount--)
|
while (TriCount--)
|
||||||
|
|
|
@ -27,8 +27,8 @@ struct sPoolNode
|
||||||
|
|
||||||
struct sNodeList
|
struct sNodeList
|
||||||
{
|
{
|
||||||
sPoolNode *List;
|
sPoolNode *Head;
|
||||||
sPoolNode *LastNode;
|
sPoolNode *Tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sPoolSlot
|
struct sPoolSlot
|
||||||
|
@ -46,8 +46,8 @@ struct sActorPool
|
||||||
FileEquate Filename;
|
FileEquate Filename;
|
||||||
sSpriteAnimBank *ActorGfx;
|
sSpriteAnimBank *ActorGfx;
|
||||||
int CacheSlot;
|
int CacheSlot;
|
||||||
sNodeList *CachePool;
|
sNodeList *PoolCache;
|
||||||
sNodeList ThisCache;
|
sNodeList ActorCache;
|
||||||
sActorPool *Next;
|
sActorPool *Next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ public:
|
||||||
static sPoolNode *RemoveHeadNode(sNodeList *Root);
|
static sPoolNode *RemoveHeadNode(sNodeList *Root);
|
||||||
static void RemoveNode(sPoolNode *Node,sNodeList *Root);
|
static void RemoveNode(sPoolNode *Node,sNodeList *Root);
|
||||||
static void AddNode(sPoolNode *Node,sNodeList *Root);
|
static void AddNode(sPoolNode *Node,sNodeList *Root);
|
||||||
|
static void AddNodeList(sNodeList *Src,sNodeList *Dst);
|
||||||
static u8 *UnpackBuffer;
|
static u8 *UnpackBuffer;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -112,6 +113,7 @@ static void SetUpCache();
|
||||||
|
|
||||||
static void AddActor(FileEquate Filename) {GetActor(Filename);}
|
static void AddActor(FileEquate Filename) {GetActor(Filename);}
|
||||||
static CActorGfx *GetActor(FileEquate Filename);
|
static CActorGfx *GetActor(FileEquate Filename);
|
||||||
|
static void CleanUpCache();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static sActorPool *FindActor(FileEquate Filename);
|
static sActorPool *FindActor(FileEquate Filename);
|
||||||
|
@ -164,9 +166,10 @@ virtual ~CModelGfx(){};
|
||||||
static void SetData(sModel *Table,sTri *TList,sQuad *QList,sVtx *VList);
|
static void SetData(sModel *Table,sTri *TList,sQuad *QList,sVtx *VList);
|
||||||
void SetModel(int Type);
|
void SetModel(int Type);
|
||||||
|
|
||||||
void Render(DVECTOR &Pos);
|
void Render(DVECTOR &Pos,SVECTOR *Angle=0,VECTOR *Scale=0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
static sModel *ModelTable;
|
static sModel *ModelTable;
|
||||||
static sTri *ModelTriList;
|
static sTri *ModelTriList;
|
||||||
static sQuad *ModelQuadList;
|
static sQuad *ModelQuadList;
|
||||||
|
|
|
@ -92,6 +92,15 @@ inline void SetIdentScaleNoTrans(MATRIX *Mtx,u32 Scale)
|
||||||
// Mtx->t[0]=0; Mtx->t[1]=0; Mtx->t[2]=0;
|
// Mtx->t[0]=0; Mtx->t[1]=0; Mtx->t[2]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
inline void SetIdentScaleNoTrans(MATRIX *Mtx,SVECTOR *Scale)
|
||||||
|
{
|
||||||
|
Mtx->m[0][0]=Scale->vx; Mtx->m[0][1]=0; Mtx->m[0][2]=0;
|
||||||
|
Mtx->m[1][0]=0; Mtx->m[1][1]=Scale->vy; Mtx->m[1][2]=0;
|
||||||
|
Mtx->m[2][0]=0; Mtx->m[2][1]=0; Mtx->m[2][2]=Scale->vz;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
inline void InverseMatrix(MATRIX *m, MATRIX &im) //assumes no scale, just transformation and rotation
|
inline void InverseMatrix(MATRIX *m, MATRIX &im) //assumes no scale, just transformation and rotation
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue