SBSPSS/Utils/MkActor/MkActor.cpp

768 lines
17 KiB
C++
Raw Normal View History

2001-04-01 15:36:57 +02:00
/*************************/
/*** Actor Sprite Tool ***/
/*************************/
#include "stdio.h"
#include <misc.hpp>
#include <conio.h>
#include <iostream.h>
#include <vector>
#include <DaveLib.h>
#include <io.h>
2001-04-01 22:22:49 +02:00
#include <SprSet.h>
2001-04-01 15:36:57 +02:00
#include "MkActor.h"
#include <pak.h>
using namespace std;
2001-04-01 22:22:49 +02:00
//#define OutputTGA
2001-04-01 15:36:57 +02:00
2001-04-11 15:19:22 +02:00
// This has got really messy :o(
2001-06-15 21:19:45 +02:00
2001-04-01 15:36:57 +02:00
//***************************************************************************
vector<CMkActor> ActorList;
int TPBase=-1,TPWidth=-1,TPHeight=-1;
2001-06-25 22:41:25 +02:00
int DupThresh;
2001-04-01 15:36:57 +02:00
GString TPOutStr;
GString RootPath;
GString SpritePath;
GString OutPath;
GString IncludePath;
2001-06-18 23:26:55 +02:00
float Aspect=512.0f/320.0f;
2001-04-04 17:54:27 +02:00
//***************************************************************************
2001-04-01 15:36:57 +02:00
char * CycleCommands(char *String,int Num)
{
char Text[2048],*TextPtr;
int Count;
2001-06-18 23:26:55 +02:00
2001-04-01 15:36:57 +02:00
if (String[0]=='-' || String[0]=='/')
{
GString TpStr;
switch (String[1])
{
// Switches
case 'o':
OutPath = CheckFileString(String);
OutPath.Upper();
OutPath.Append('\\');
break;
case 'i':
IncludePath = CheckFileString(String);
IncludePath.Upper();
IncludePath.Append('\\');
break;
case 'd':
DebugOn =true;
break;
case 's':
SpritePath=CheckFileString(String);
SpritePath.Upper();
SpritePath.Append('\\');
break;
case 'r':
RootPath=CheckFileString(String);
RootPath.Upper();
RootPath.Append('\\');
break;
2001-06-18 23:26:55 +02:00
case 'a':
TpStr= CheckFileString(String);
Aspect=(float)atof(TpStr);
break;
2001-06-25 22:41:25 +02:00
case 'c':
TpStr= CheckFileString(String);
DupThresh=(int)atol(TpStr);
break;
2001-04-01 15:36:57 +02:00
case 't':
TpStr= CheckFileString(String);
TextPtr=Text;
strcpy(TextPtr,TpStr);
Count=ZeroAndCountCommas(TextPtr);
if (Count!=2) GObject::Error(ERR_FATAL,"Problem with option %s\n",String);
TPBase=atol(TextPtr);
TextPtr+=strlen(TextPtr)+1;
TPWidth=atol(TextPtr);
TextPtr+=strlen(TextPtr)+1;
TPHeight=atol(TextPtr);
break;
default:
GObject::Error(ERR_FATAL,"Unknown switch %s",String);
break;
}
}
else
{
GString Name=String;
Name.Upper();
ActorList.push_back(CMkActor(Name,RootPath,SpritePath));
}
return(String);
}
//***************************************************************************
void Usage(char *ErrStr)
{
printf("\nMkActor (usese scripts): by Dave\n");
printf("Usage: MkActor <file> [ <file>.. ] [ switches.. ]\n");
printf("Switches:\n");
printf(" -o:[FILE] Set output Dir\n");
printf(" -p:nn Root Dir\n");
printf(" -s:nn Sprite Dir\n");
printf(" -t:p,w,h Set TPage No,Width,Height\n");
printf(" -d: Enable Debug output\n");
2001-06-18 23:26:55 +02:00
printf(" -a: Aspect Ratio\n");
2001-04-01 15:36:57 +02:00
GObject::Error(ERR_FATAL,ErrStr);
}
//***************************************************************************
int main (int argc, char *argv[])
{
int i,ListSize;
CommandLine(argc,argv,CycleCommands);
if (OutPath.Empty()) Usage("No Output File Set\n");
ListSize=ActorList.size();
for (i=0; i<ListSize; i++)
{
ActorList[i].Load();
ActorList[i].Process();
ActorList[i].Write();
ActorList[i].CleanUp();
}
return 0;
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
CMkActor::CMkActor(GString &ActorName,GString &ActorPath,GString &SpritePath)
{
Name=ActorName;
ActorDir=ActorPath+ActorName;
ActorDir.Append('\\');
SpriteDir=ActorDir+SpritePath;
OutFile=OutPath+ActorName;
IncFile=IncludePath+"ACTOR_"+Name;
TexGrab.SetTPage(TPBase,TPWidth,TPHeight);
TexGrab.SetOutFile(OutFile+".Tex");
TexGrab.SetDebugOut(OutFile+".Lbm");
TexGrab.SetIncFile(IncFile+"_TEX.h");
TexGrab.NoSort();
TexGrab.AnimatedHeadersOnly(true);
TexGrab.DontOutputBoxes(true);
TexGrab.AllowRotate(false);
DupCount=0;
2001-04-11 15:19:22 +02:00
MaxW=0;
MaxH=0;
2001-06-18 23:26:55 +02:00
BlankCount=0;
2001-04-01 15:36:57 +02:00
}
//***************************************************************************
void CMkActor::CleanUp()
{
int i,ListSize=BmpList.size();
for (i=0; i<ListSize; i++)
{
if (BmpList[i].RGB) free(BmpList[i].RGB);
if (BmpList[i].Pak) free(BmpList[i].Pak);
if (BmpList[i].Psx) free(BmpList[i].Psx);
}
}
//***************************************************************************
void CMkActor::Load()
{
ReadScript(ActorDir+"AnimList.Txt",InAnimList);
}
//***************************************************************************
void CMkActor::ReadScript(const char *Filename,vector<GString> &List)
{
char *Script,*Ptr;
int Size;
File=fopen(Filename,"rb");
if (!File) return;
fseek(File,0,SEEK_END);
Size=ftell(File);
fseek(File,0,SEEK_SET);
Script=(char*)malloc(Size+1);
ASSERT(Script);
// Load It
fread(Script,Size,1,File);
fclose(File);
// Extract Names
Ptr=Script;
Script[Size]=0;
while (*Ptr)
{
GString Str;
while (*Ptr=='\n' || *Ptr=='\r'|| *Ptr==' ') *Ptr++; // Skip gaff
if (*Ptr)
{
if (*Ptr=='#')
{ // Skip commented lines
while (*Ptr!='\n' && *Ptr) Ptr++;
}
else
{ // Read data
while (*Ptr!=' ' && *Ptr!='\n' && *Ptr!='\r' && *Ptr)
{
Str.Append(*Ptr++);
}
List.push_back(Str);
}
}
}
free(Script);
}
//***************************************************************************
void CMkActor::BuildFrameList()
{
int i,ListSize=InAnimList.size();
char AnimName[256];
AnimList.resize(ListSize);
for (i=0; i<ListSize; i++)
{
sAnim &ThisAnim=AnimList[i];
sprintf(AnimName,"%s",InAnimList[i]);
2001-05-15 19:40:54 +02:00
ThisAnim.Name=&AnimName[0];
2001-04-01 15:36:57 +02:00
FindFrames(ThisAnim);
}
}
//***************************************************************************
void CMkActor::FindFrames(sAnim &ThisAnim)
{
GString Filename;
_finddata_t Find;
long FileHandle;
int Error=0;
2001-04-11 15:19:22 +02:00
GString BaseName=Name+"_"+ThisAnim.Name;
int BaseLen=strlen(BaseName);
Filename=SpriteDir+BaseName+"*.bmp";
2001-04-01 15:36:57 +02:00
if( (FileHandle= _findfirst( Filename, &Find)) == -1L )
{
2001-04-04 17:54:27 +02:00
GObject::Error(ERR_WARNING,"Cant find Anim %s.\n",ThisAnim.Name);
2001-04-01 15:36:57 +02:00
return;
}
while (Error==0)
{
sFrame NewFrame;
NewFrame.Filename=Find.name;
2001-04-11 15:19:22 +02:00
char c=NewFrame.Filename[BaseLen];
if (c>='0' && c<='9')
{
ThisAnim.Frames.push_back(NewFrame);
}
2001-04-01 22:22:49 +02:00
2001-04-01 15:36:57 +02:00
Error=_findnext( FileHandle, &Find);
}
_findclose( FileHandle);
}
//***************************************************************************
void CMkActor::LoadFrameList()
{
int i,ListSize=AnimList.size();
for (i=0; i<ListSize; i++)
{
sAnim &ThisAnim=AnimList[i];
int FrameCount=ThisAnim.Frames.size();
for (int f=0; f<FrameCount; f++)
{
2001-05-15 19:40:54 +02:00
printf("%s - Load Anim %2d/%2d\tFrame %2d/%2d \r",Name,i+1,ListSize,f,FrameCount);
LoadBmp(ThisAnim.Frames[f]);
2001-04-01 15:36:57 +02:00
}
}
printf("\t\t\t\t\t\t\r");
}
//***************************************************************************
void CMkActor::MakePsxGfx(sBmp &Bmp)
{
2001-06-15 21:19:45 +02:00
// capture blank frames
if (Bmp.Frm.IsBlank())
{
Bmp.Psx=0;
Bmp.PsxSize=0;
2001-06-18 23:26:55 +02:00
BlankCount++;
2001-06-15 21:19:45 +02:00
return;
}
2001-04-01 15:36:57 +02:00
// Copied from SprSet
int nfW,nfH,nfLineWidthBytes,nfAreaBytes;
2001-04-26 23:38:18 +02:00
Frame Frm=Bmp.Frm;
2001-04-01 15:36:57 +02:00
nfW=Frm.GetWidth();
nfH=Frm.GetHeight();
nfLineWidthBytes=GU_AlignVal(nfW,2)/2;
nfAreaBytes=nfLineWidthBytes*nfH;
Bmp.PsxSize=nfAreaBytes;
2001-04-11 15:19:22 +02:00
if (nfW>MaxW) MaxW=nfW;
if (nfH>MaxH) MaxH=nfH;
2001-04-26 23:38:18 +02:00
2001-04-01 22:22:49 +02:00
Bmp.Psx=(u8*)malloc(nfAreaBytes+16);
2001-04-01 15:36:57 +02:00
ASSERT(Bmp.Psx);
for (int y=0;y<nfH;y++)
{
for (int x=0;x<nfW;x++)
{
u8 * PixAddr;
u8 ScrNib;
ScrNib=Frm.SeeData()[y*nfW+x]&0xf;
PixAddr=&Bmp.Psx[(x/2)+(nfLineWidthBytes*y)];
2001-04-01 22:22:49 +02:00
if (PixAddr>=&Bmp.Psx[nfAreaBytes]) ASSERT(!"");
2001-04-01 15:36:57 +02:00
if ((x&1))
{
*PixAddr&=0x0f;
*PixAddr|=ScrNib<<4;
}
else
{
*PixAddr&=0xf0;
*PixAddr|=ScrNib;
}
}
}
}
//***************************************************************************
2001-04-11 15:19:22 +02:00
int CMkActor::FindDup(sBmp &Bmp)
2001-04-01 15:36:57 +02:00
{
2001-04-11 15:19:22 +02:00
int i,BmpListSize=BmpList.size();
2001-04-26 23:38:18 +02:00
int Size=Bmp.Frm.GetWidth()*Bmp.Frm.GetHeight();
2001-04-01 22:22:49 +02:00
2001-04-11 15:19:22 +02:00
Bmp.RGB=(u8*)malloc(Size*3);
ASSERT(Bmp.RGB);
2001-04-26 23:38:18 +02:00
Bmp.Frm.MakeRGB(Bmp.RGB);
2001-04-01 22:22:49 +02:00
// Check for dups (Broken at the mo, ah well)
2001-04-01 15:36:57 +02:00
// Gen Chksum
2001-06-25 22:41:25 +02:00
/*
2001-04-11 15:19:22 +02:00
u8 *RGB=Bmp.RGB;
Bmp.ChkR=Bmp.ChkG=Bmp.ChkB=0;
2001-04-01 15:36:57 +02:00
for (i=0; i<Size; i++)
{
2001-04-11 15:19:22 +02:00
Bmp.ChkR+=*RGB++;
Bmp.ChkG+=*RGB++;
Bmp.ChkB+=*RGB++;
2001-04-01 15:36:57 +02:00
}
2001-06-25 22:41:25 +02:00
*/
2001-04-01 15:36:57 +02:00
// Find existing
2001-04-11 15:19:22 +02:00
for (i=0; i<BmpListSize; i++)
2001-04-01 15:36:57 +02:00
{
sBmp &ThisBmp=BmpList[i];
2001-04-11 15:19:22 +02:00
ASSERT(Bmp.RGB);
ASSERT(ThisBmp.RGB);
if (IsImageSame(ThisBmp,Bmp))
2001-04-01 15:36:57 +02:00
{
2001-04-11 15:19:22 +02:00
free(Bmp.RGB);
return(i);
2001-04-01 15:36:57 +02:00
}
}
2001-04-11 15:19:22 +02:00
return(-1);
}
//***************************************************************************
bool CMkActor::IsImageSame(sBmp &Bmp0,sBmp &Bmp1)
{
int W0,H0,W1,H1,Size;
u8 *RGB0,*RGB1;
2001-06-25 22:41:25 +02:00
int DiffCount=0;
// if (Bmp0.ChkR!=Bmp1.ChkR || Bmp0.ChkG!=Bmp1.ChkG || Bmp0.ChkB!=Bmp1.ChkB) return(false);
2001-04-26 23:38:18 +02:00
W0=Bmp0.Frm.GetWidth();
H0=Bmp0.Frm.GetHeight();
W1=Bmp1.Frm.GetWidth();
H1=Bmp1.Frm.GetHeight();
2001-04-11 15:19:22 +02:00
if (W0!=W1 || H0!=H1) return(false);
2001-06-25 22:41:25 +02:00
Size=W0*H0;
2001-04-11 15:19:22 +02:00
RGB0=Bmp0.RGB;
RGB1=Bmp1.RGB;
for (int i=0; i<Size; i++)
{
2001-06-25 22:41:25 +02:00
// if (*RGB0++!=*RGB1++) return(false);
if (*RGB0++!=*RGB1++ || // R
*RGB0++!=*RGB1++ || // G
*RGB0++!=*RGB1++) // B
{
DiffCount++;
}
2001-04-11 15:19:22 +02:00
}
2001-06-25 22:41:25 +02:00
if (DiffCount<=DupThresh)
return(true);
else
return(false);
2001-04-11 15:19:22 +02:00
}
//***************************************************************************
2001-06-15 21:19:45 +02:00
void CMkActor::CheckAndShrinkFrame(sBmp &Bmp,const char *FrameName)
2001-04-11 15:19:22 +02:00
{
// Check Colors
2001-04-26 23:38:18 +02:00
int ColorCount=Bmp.Frm.GetNumOfCols();
2001-04-11 15:19:22 +02:00
if (ColorCount>16)
{
GObject::Error(ERR_FATAL,"%s has %i colors.\n",Name,ColorCount);
}
2001-06-15 21:19:45 +02:00
// Check Palette
if (BmpList.size())
{
Palette &BasePal=BmpList[0].Frm.GetPal();
Palette &ThisPal=Bmp.Frm.GetPal();
int Count=__min(BasePal.GetNumOfCols(),ThisPal.GetNumOfCols());
for (int p=1;p<Count; p++)
{
if (BasePal[p].GetR()!=ThisPal[p].GetR() ||
BasePal[p].GetG()!=ThisPal[p].GetG() ||
BasePal[p].GetB()!=ThisPal[p].GetB())
{
GObject::Error(ERR_WARNING,"Palette MisMatch : %s\n",FrameName);
break;
}
}
}
2001-04-11 15:19:22 +02:00
2001-04-26 23:38:18 +02:00
Bmp.OrigW=Bmp.Frm.GetWidth();
Bmp.OrigH=Bmp.Frm.GetHeight();
2001-04-11 15:19:22 +02:00
2001-04-26 23:38:18 +02:00
Rect BBox;
BBox=Bmp.Frm.FindBoundingRect();
BBox.W=GU_AlignVal(BBox.W,4);
Bmp.Frm.Crop(BBox);
Bmp.CrossHairX=BBox.X-(Bmp.OrigW/2);//+)/2;
Bmp.CrossHairY=-(Bmp.OrigH-BBox.Y);
2001-06-15 21:19:45 +02:00
2001-04-11 15:19:22 +02:00
}
//***************************************************************************
2001-05-15 19:40:54 +02:00
void CMkActor::LoadBmp(sFrame &ThisFrame)
2001-04-11 15:19:22 +02:00
{
2001-05-15 19:40:54 +02:00
GString Filename=SpriteDir+ThisFrame.Filename;
2001-04-11 15:19:22 +02:00
int BmpListSize=BmpList.size();
sBmp NewBmp;
2001-04-26 23:38:18 +02:00
// Init & Load Frame
NewBmp.Frm.LoadBMP(Filename);
2001-04-11 15:19:22 +02:00
NewBmp.RGB=0;
NewBmp.Pak=0;
NewBmp.Psx=0;
2001-06-15 21:19:45 +02:00
CheckAndShrinkFrame(NewBmp,ThisFrame.Filename);
2001-05-15 19:40:54 +02:00
ThisFrame.XOfs=NewBmp.CrossHairX;
ThisFrame.YOfs=NewBmp.CrossHairY;
2001-04-11 15:19:22 +02:00
// Check Dups
int Idx=FindDup(NewBmp);
2001-04-01 15:36:57 +02:00
if (Idx!=-1)
{
DupCount++;
2001-05-15 19:40:54 +02:00
ThisFrame.FrameIdx=Idx;
return;
2001-04-01 15:36:57 +02:00
}
2001-04-11 15:19:22 +02:00
// Its unique, add to list
2001-04-01 15:36:57 +02:00
BmpList.push_back(NewBmp);
2001-04-01 22:22:49 +02:00
2001-04-11 15:19:22 +02:00
MakePsxGfx(BmpList[BmpListSize]);
2001-04-01 22:22:49 +02:00
#if _DEBUG && defined(OutputTGA)
2001-04-11 15:19:22 +02:00
void WriteTGA(GString Name,Frame Frm);
2001-04-26 23:38:18 +02:00
WriteTGA(Name,NewBmp.Frm);
2001-04-01 22:22:49 +02:00
#endif
2001-05-15 19:40:54 +02:00
ThisFrame.FrameIdx=BmpListSize;
2001-04-01 15:36:57 +02:00
}
//***************************************************************************
2001-04-11 15:19:22 +02:00
void WriteTGA(GString Name,Frame Frm)
2001-04-01 15:36:57 +02:00
{
2001-04-11 15:19:22 +02:00
u8 *TGA=(u8*)malloc(Frm.GetWidth()*Frm.GetHeight()*3);
ASSERT(TGA);
Frm.FlipY();
Frm.MakeRGB(TGA);
2001-04-01 15:36:57 +02:00
2001-04-11 15:19:22 +02:00
char OutName[256];
sprintf(OutName,"\\x\\%s.tga",Name);
SaveTGA(OutName,Frm.GetWidth(),Frm.GetHeight(),TGA,true);
free(TGA);
2001-04-01 15:36:57 +02:00
}
2001-04-01 22:22:49 +02:00
2001-04-01 15:36:57 +02:00
//***************************************************************************
//***************************************************************************
//***************************************************************************
void CMkActor::Process()
{
BuildFrameList();
LoadFrameList();
ProcessFrames();
}
//***************************************************************************
void CMkActor::ProcessFrames()
{
int i,ListSize=BmpList.size();
2001-04-26 23:38:18 +02:00
TotalIn=0;
TotalOut=0;
2001-04-01 15:36:57 +02:00
for (i=0; i<ListSize; i++)
{
sBmp &ThisBmp=BmpList[i];
printf("%s - Processing Frame %2d\\%2d\r",Name,i+1,ListSize);
2001-06-15 21:19:45 +02:00
if (ThisBmp.Psx)
{
ThisBmp.PakSize=PAK_findPakSize(ThisBmp.Psx,ThisBmp.PsxSize);
ThisBmp.Pak=(u8*)malloc(ThisBmp.PakSize);
ASSERT(ThisBmp.Pak);
PAK_doPak(ThisBmp.Pak,ThisBmp.Psx,ThisBmp.PsxSize);
}
else
{ // Blank Frame
ThisBmp.Pak=0;
ThisBmp.PakSize=0;
}
2001-04-01 15:36:57 +02:00
TotalIn+=ThisBmp.PsxSize;
TotalOut+=ThisBmp.PakSize;
}
printf("\t\t\t\t\t\r");
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
void CMkActor::Write()
{
GString OutName=OutFile+".SBK";
File=fopen(OutName,"wb");
// Write Dummy Hdr
fwrite(&FileHdr,1,sizeof(sSpriteAnimBank),File);
2001-04-11 15:19:22 +02:00
PadFile(File);
2001-04-01 15:36:57 +02:00
// Write Palette
FileHdr.Palette=(u8*)WritePalette();
2001-04-26 23:38:18 +02:00
FileHdr.Clut=0;
2001-04-11 15:19:22 +02:00
PadFile(File);
2001-04-01 15:36:57 +02:00
// Write AnimList
FileHdr.AnimList=(sSpriteAnim*)WriteAnimList();
2001-04-11 15:19:22 +02:00
PadFile(File);
2001-04-01 15:36:57 +02:00
// Write FrameList
2001-05-15 19:40:54 +02:00
FileHdr.FrameList=(sSpriteFrameGfx*)WriteFrameList();
2001-04-11 15:19:22 +02:00
// PadFile(File);
2001-04-01 15:36:57 +02:00
// Rewrite Header
fseek(File, 0, SEEK_SET);
fwrite(&FileHdr,1,sizeof(sSpriteAnimBank),File);
fclose(File);
WriteInclude();
2001-06-18 23:26:55 +02:00
printf("%s. D=%i B=%i - WH=%i %i - In=%i Out=%i Sv=%i \n",Name,DupCount,BlankCount,FileHdr.MaxW,FileHdr.MaxH,TotalIn,TotalOut,TotalIn-TotalOut);
2001-04-01 15:36:57 +02:00
}
//***************************************************************************
int CMkActor::WritePalette()
{
int Pos=ftell(File);
2001-04-26 23:38:18 +02:00
Palette &PCPalette=BmpList[0].Frm.GetPal();
2001-04-01 15:36:57 +02:00
SprPal PsxPalette;
int i,Count;
vector<u16> OutPal;
PsxPalette=PCPalette;
PsxPalette.SetPlusColZero(true);
Count=PsxPalette.GetNumOfCols();
2001-04-04 17:54:27 +02:00
if (Count<16) Count=16;
2001-04-01 15:36:57 +02:00
PsxPalette.MakePSXPal(OutPal);
for (i=0; i<Count; i++)
{
u16 ThisCol=OutPal[i];
fwrite(&ThisCol,1,sizeof(u16),File);
}
return(Pos);
}
//***************************************************************************
int CMkActor::WriteAnimList()
{
int Pos=ftell(File);
2001-04-04 17:54:27 +02:00
int i,AnimCount=AnimList.size();
vector<sSpriteAnim> Hdrs;
2001-04-01 15:36:57 +02:00
// Write Dummy Hdrs
2001-04-04 17:54:27 +02:00
FileHdr.AnimCount=AnimCount;
Hdrs.resize(AnimCount);
for (i=0; i<AnimCount; i++)
2001-04-01 15:36:57 +02:00
{
2001-04-04 17:54:27 +02:00
fwrite(&Hdrs[i],1,sizeof(sSpriteAnim),File);
2001-04-01 15:36:57 +02:00
}
2001-04-11 15:19:22 +02:00
PadFile(File);
2001-04-04 17:54:27 +02:00
2001-04-01 15:36:57 +02:00
// Write Frame Lists
2001-04-04 17:54:27 +02:00
for (i=0; i<AnimCount; i++)
2001-04-01 15:36:57 +02:00
{
sAnim &ThisAnim=AnimList[i];
int f,FrameCount=ThisAnim.Frames.size();
2001-04-04 17:54:27 +02:00
Hdrs[i].FrameCount=FrameCount;
2001-05-15 19:40:54 +02:00
Hdrs[i].Anim=(sSpriteFrame*)ftell(File);
2001-04-04 17:54:27 +02:00
2001-04-01 15:36:57 +02:00
for (f=0; f<FrameCount; f++)
{
2001-05-15 19:40:54 +02:00
sFrame &ThisFrame=ThisAnim.Frames[f];
sSpriteFrame OutFrame;
OutFrame.FrameIdx=ThisFrame.FrameIdx;
OutFrame.XOfs=ThisFrame.XOfs;
OutFrame.YOfs=ThisFrame.YOfs;
fwrite(&OutFrame,1,sizeof(sSpriteFrame),File);
2001-04-01 15:36:57 +02:00
}
2001-04-11 15:19:22 +02:00
PadFile(File);
2001-04-04 17:54:27 +02:00
2001-04-01 15:36:57 +02:00
}
// ReWrite Headers
2001-04-04 17:54:27 +02:00
int SavePos=ftell(File);
fseek(File,Pos,SEEK_SET);
for (i=0; i<AnimCount; i++)
2001-04-01 15:36:57 +02:00
{
2001-04-04 17:54:27 +02:00
fwrite(&Hdrs[i],1,sizeof(sSpriteAnim),File);
2001-04-01 15:36:57 +02:00
}
fseek(File,SavePos,SEEK_SET);
2001-04-04 17:54:27 +02:00
2001-04-01 15:36:57 +02:00
return(Pos);
}
//***************************************************************************
int CMkActor::WriteFrameList()
{
int Pos=ftell(File);
2001-04-04 17:54:27 +02:00
int i,FrameCount=BmpList.size();
2001-05-15 19:40:54 +02:00
vector<sSpriteFrameGfx> Hdrs;
2001-04-01 15:36:57 +02:00
2001-04-11 15:19:22 +02:00
FileHdr.MaxW=MaxW;
FileHdr.MaxH=MaxH;
2001-04-04 17:54:27 +02:00
FileHdr.FrameCount=FrameCount;
2001-04-26 23:38:18 +02:00
// Write Dummy Hdrs
2001-04-04 17:54:27 +02:00
Hdrs.resize(FrameCount);
2001-05-15 19:40:54 +02:00
2001-04-04 17:54:27 +02:00
for (i=0; i<FrameCount; i++)
2001-04-01 15:36:57 +02:00
{
2001-05-15 19:40:54 +02:00
fwrite(&Hdrs[i],1,sizeof(sSpriteFrameGfx),File);
2001-04-01 15:36:57 +02:00
}
2001-04-11 15:19:22 +02:00
PadFile(File);
2001-04-04 17:54:27 +02:00
2001-04-01 15:36:57 +02:00
// Write Frame Lists
2001-04-04 17:54:27 +02:00
for (i=0; i<FrameCount; i++)
2001-04-01 15:36:57 +02:00
{
sBmp &ThisBmp=BmpList[i];
2001-04-04 17:54:27 +02:00
2001-06-18 23:26:55 +02:00
if (ThisBmp.Pak)
{
Hdrs[i].PAKSpr=(u8*)ftell(File);
Hdrs[i].W=ThisBmp.Frm.GetWidth();
Hdrs[i].H=ThisBmp.Frm.GetHeight();
// aspect
float aW=Hdrs[i].W*Aspect;
int dW=(int)aW-Hdrs[i].W;
int X0=dW/2;
int X1=dW-X0;
Hdrs[i].AspectX0=X0;
Hdrs[i].AspectX1=X1;
// printf("%i %i %i\n",Hdrs[i].W,X0,X1);
fwrite(ThisBmp.Pak,1,ThisBmp.PakSize,File);
}
else
{
Hdrs[i].PAKSpr=0;
Hdrs[i].W=0;
Hdrs[i].H=0;
}
2001-04-01 15:36:57 +02:00
}
2001-04-04 17:54:27 +02:00
// ReWrite Headers
2001-04-01 15:36:57 +02:00
int SavePos=ftell(File);
fseek(File,Pos,SEEK_SET);
2001-04-04 17:54:27 +02:00
for (i=0; i<FrameCount; i++)
2001-04-01 15:36:57 +02:00
{
2001-05-15 19:40:54 +02:00
fwrite(&Hdrs[i],1,sizeof(sSpriteFrameGfx),File);
2001-04-01 15:36:57 +02:00
}
fseek(File,SavePos,SEEK_SET);
2001-04-04 17:54:27 +02:00
2001-04-01 15:36:57 +02:00
return(Pos);
}
//***************************************************************************
void CMkActor::WriteInclude()
{
GString Filename=IncFile+"_Anim.h";
File=fopen(Filename,"wt");
fprintf(File,"// %s Anim Header\n",Name);
fprintf(File,"\n");
fprintf(File,"#ifndef\t__ANIM_%s_HEADER__\n",Name);
fprintf(File,"#define\t__ANIM_%s_HEADER__\n",Name);
fprintf(File,"\n");
fprintf(File,"\n");
fprintf(File,"enum\tANIM_%s_LIST\n",Name);
fprintf(File,"{\n");
int ListSize=AnimList.size();
for (int i=0; i<ListSize; i++)
{
sAnim &ThisAnim=AnimList[i];
GString AnimName=ThisAnim.Name;
AnimName.Upper();
fprintf(File,"\tANIM_%s_%s",Name,AnimName);
if (i==0)
{
fprintf(File,"=0");
}
fprintf(File,",\n");
}
fprintf(File,"\tNUM_ANIM_%s\n",Name);
fprintf(File,"};\n");
fprintf(File,"\n");
fprintf(File,"#endif\n");
fclose(File);
}
2001-04-11 15:19:22 +02:00