SBSPSS/source/gfx/animtex.cpp

203 lines
4.5 KiB
C++
Raw Normal View History

2000-08-29 21:54:56 +02:00
/**************************/
/*** Anim Texture Stuph ***/
/**************************/
#include "system\global.h"
#include "mem\memory.h"
#include "fileio\fileio.h"
#include "gfx\animtex.h"
#include "gfx\tpage.h"
#include "utils\utils.h"
2001-05-14 21:40:30 +02:00
#include "utils\pak.h"
2000-08-29 21:54:56 +02:00
#ifndef __SYSTEM_GSTATE_H__
#include "system\gstate.h"
#endif
CAnimTex *AnimTexList=0;
2001-05-14 21:40:30 +02:00
CPakTex CPakTex::PakTexList[CPakTex::PAKTEX_MAX];
int CPakTex::PakTexCount;
u8 *CPakTex::UnpackBuffer;
2000-08-29 21:54:56 +02:00
/*****************************************************************************/
2000-09-11 17:34:59 +02:00
CAnimTex::CAnimTex()
{
NextTex=0;
}
2000-08-29 21:54:56 +02:00
2000-09-11 17:34:59 +02:00
/*****************************************************************************/
CAnimTex::~CAnimTex()
{
if (TexData) MemFree(TexData);
}
2000-08-29 21:54:56 +02:00
2000-09-11 17:34:59 +02:00
/*****************************************************************************/
2000-08-29 21:54:56 +02:00
void CAnimTex::AddAnimTex(sFrameHdr *Frame,FileEquate Filename)
{
int TPageX,TPageY,X,Y,W,H;
CAnimTex *ThisTex=new ("CAnimTex::AddAnimTex") CAnimTex;
2000-09-11 17:34:59 +02:00
ThisTex->NextTex=AnimTexList;
2000-08-29 21:54:56 +02:00
AnimTexList=ThisTex;
X=(u8)Frame->U;
Y=(u8)Frame->V;
W=(u8)Frame->W;
H=(u8)Frame->H;
switch (((Frame->TPage)>>7)&0x003)
{
case 0:
ThisTex->PixPerWord=4;
break;
case 1:
ThisTex->PixPerWord=2;
break;
case 2:
ThisTex->PixPerWord=1;
break;
default:
ASSERT(!"Unknown Pixel Depth");
break;
};
X/=ThisTex->PixPerWord;
W/=ThisTex->PixPerWord;
TPageX=(Frame->TPage<<6)&0x7c0;
TPageY=(Frame->TPage<<4)&0x100;
TPageX+=X;
TPageY+=Y;
ThisTex->Rect.x=TPageX;
ThisTex->Rect.y=TPageY;
ThisTex->Rect.w=W;
ThisTex->Rect.h=H;
ThisTex->TexData=0;
ThisTex->Count=0; ThisTex->Speed=-1;
ThisTex->TPage=Frame->TPage;
ThisTex->TexName=Filename;
int Size=W*H;
ThisTex->TexData=(u32*)MemAlloc(Size*sizeof(u16), "AnTx");
DrawSync(0);
StoreImage(&ThisTex->Rect,(u32*)ThisTex->TexData);
}
/*****************************************************************************/
void CAnimTex::DumpThisTPage(FileEquate TexName)
{
2000-09-11 17:34:59 +02:00
CAnimTex *PrevTex, *ThisTex, *NextTex;
2000-08-29 21:54:56 +02:00
2000-09-11 17:34:59 +02:00
PrevTex=NULL;
ThisTex=AnimTexList;
2000-08-29 21:54:56 +02:00
2000-09-11 17:34:59 +02:00
while(ThisTex)
2000-08-29 21:54:56 +02:00
{
2000-09-11 17:34:59 +02:00
NextTex=ThisTex->NextTex;
if(ThisTex->TexName==TexName)
{
if (PrevTex) PrevTex->NextTex=NextTex;
if (ThisTex==AnimTexList) AnimTexList=NextTex;
delete ThisTex;
}
2000-08-29 21:54:56 +02:00
else
2000-09-11 17:34:59 +02:00
{
PrevTex=ThisTex;
}
ThisTex=NextTex;
2000-08-29 21:54:56 +02:00
}
}
/*****************************************************************************/
void CAnimTex::AnimateTex()
{
CAnimTex *ThisTex=AnimTexList;
RECT Rect;
int Count,CountComp;
int H,W;
2000-12-20 23:46:12 +01:00
int Time = GameState::getFramesSinceLast();
2000-08-29 21:54:56 +02:00
while (ThisTex)
{
Rect=ThisTex->Rect;
H=Rect.h;
Count=((ThisTex->Count>>2)+ThisTex->Rect.h)%ThisTex->Rect.h; // Allow for backwards
CountComp=H-Count;
// Top Chunk
if (Count)
{
int Offset = (CountComp*Rect.w)>>1;
Rect.h=Count;
LoadImage(&Rect,ThisTex->TexData+Offset);
}
// Bottom Chunk
if (CountComp)
{
Rect.y+=Count;
Rect.h=CountComp;
LoadImage(&Rect,ThisTex->TexData);
}
2000-12-20 23:46:12 +01:00
ThisTex->Count+=(ThisTex->Speed * Time);
2000-08-29 21:54:56 +02:00
ThisTex->Count%=(ThisTex->Rect.h<<2);
ThisTex=ThisTex->NextTex;
}
}
/*****************************************************************************/
2001-01-30 18:38:31 +01:00
/*****************************************************************************/
2001-05-14 21:40:30 +02:00
/*** Pak Tex Stuff ***********************************************************/
/*****************************************************************************/
2001-01-30 18:38:31 +01:00
/*****************************************************************************/
2001-05-14 21:40:30 +02:00
CPakTex::CPakTex()
2001-01-30 18:38:31 +01:00
{
2001-05-14 21:40:30 +02:00
PakTexCount=0;
UnpackBuffer=0;
}
2001-01-30 18:38:31 +01:00
2001-05-14 21:40:30 +02:00
/*****************************************************************************/
void CPakTex::Init(int MaxSize)
{
ASSERT(UnpackBuffer==0);
UnpackBuffer=(u8*)MemAlloc(MaxSize,"CPakTex::UnpackBuffer");
PakTexCount=0;
}
2001-01-30 18:38:31 +01:00
2001-05-14 21:40:30 +02:00
/*****************************************************************************/
void CPakTex::Shutdown()
{
if (UnpackBuffer) MemFree(UnpackBuffer);
UnpackBuffer=0;
2001-01-30 18:38:31 +01:00
}
2001-05-14 21:40:30 +02:00
2001-01-30 18:38:31 +01:00
/*****************************************************************************/
2001-05-14 21:40:30 +02:00
void CPakTex::Add(u8 *PakSpr,RECT *DstRect)
2001-01-30 18:38:31 +01:00
{
2001-05-14 21:40:30 +02:00
ASSERT(PakTexCount<PAKTEX_MAX);
PakTexList[PakTexCount].PakSpr=PakSpr;
PakTexList[PakTexCount].DstRect=DstRect;
PakTexCount++;
}
2001-01-30 18:38:31 +01:00
2001-05-14 21:40:30 +02:00
/*****************************************************************************/
void CPakTex::DMAPakTex()
{
for (int i=0; i<PakTexCount; i++)
2001-01-30 18:38:31 +01:00
{
2001-05-14 21:40:30 +02:00
ASSERT(UnpackBuffer);
PAK_doUnpak(UnpackBuffer,PakTexList[i].PakSpr);
LoadImage( PakTexList[i].DstRect, (u32*)UnpackBuffer);
2001-01-30 21:54:27 +01:00
}
2001-05-14 21:40:30 +02:00
PakTexCount=0;
2001-01-30 18:38:31 +01:00
}
/*****************************************************************************/
2000-08-29 21:54:56 +02:00