/*************************/ /*** Actor Sprite Tool ***/ /*************************/ #include "stdio.h" #include #include #include #include #include #include #include #include "MkActor.h" #include using namespace std; //#define OutputTGA // This has got really messy :o( //*************************************************************************** vector ActorList; int TPBase=-1,TPWidth=-1,TPHeight=-1; GString TPOutStr; GString RootPath; GString SpritePath; GString OutPath; GString IncludePath; //*************************************************************************** char * CycleCommands(char *String,int Num) { char Text[2048],*TextPtr; int Count; 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; 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 [ .. ] [ 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"); 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 &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='0' && c<='9') { ThisAnim.Frames.push_back(NewFrame); } Error=_findnext( FileHandle, &Find); } _findclose( FileHandle); } //*************************************************************************** void CMkActor::LoadFrameList() { int i,ListSize=AnimList.size(); for (i=0; iMaxW) MaxW=nfW; if (nfH>MaxH) MaxH=nfH; Bmp.Psx=(u8*)malloc(nfAreaBytes+16); ASSERT(Bmp.Psx); for (int y=0;y=&Bmp.Psx[nfAreaBytes]) ASSERT(!""); if ((x&1)) { *PixAddr&=0x0f; *PixAddr|=ScrNib<<4; } else { *PixAddr&=0xf0; *PixAddr|=ScrNib; } } } } //*************************************************************************** int CMkActor::FindDup(sBmp &Bmp) { int i,BmpListSize=BmpList.size(); int Size=Bmp.Frm.GetWidth()*Bmp.Frm.GetHeight(); Bmp.RGB=(u8*)malloc(Size*3); ASSERT(Bmp.RGB); Bmp.Frm.MakeRGB(Bmp.RGB); // Check for dups (Broken at the mo, ah well) // Gen Chksum u8 *RGB=Bmp.RGB; Bmp.ChkR=Bmp.ChkG=Bmp.ChkB=0; for (i=0; i16) { GObject::Error(ERR_FATAL,"%s has %i colors.\n",Name,ColorCount); } Bmp.OrigW=Bmp.Frm.GetWidth(); Bmp.OrigH=Bmp.Frm.GetHeight(); 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); // printf("%i %i \n",Bmp.CrossHairX,Bmp.CrossHairY); } //*************************************************************************** void CMkActor::LoadBmp(sFrame &ThisFrame) { GString Filename=SpriteDir+ThisFrame.Filename; int BmpListSize=BmpList.size(); sBmp NewBmp; // Init & Load Frame NewBmp.Frm.LoadBMP(Filename); NewBmp.RGB=0; NewBmp.Pak=0; NewBmp.Psx=0; CheckAndShrinkFrame(NewBmp); ThisFrame.XOfs=NewBmp.CrossHairX; ThisFrame.YOfs=NewBmp.CrossHairY; // Check Dups int Idx=FindDup(NewBmp); if (Idx!=-1) { DupCount++; ThisFrame.FrameIdx=Idx; return; } // Its unique, add to list BmpList.push_back(NewBmp); MakePsxGfx(BmpList[BmpListSize]); #if _DEBUG && defined(OutputTGA) void WriteTGA(GString Name,Frame Frm); WriteTGA(Name,NewBmp.Frm); #endif ThisFrame.FrameIdx=BmpListSize; } //*************************************************************************** void WriteTGA(GString Name,Frame Frm) { u8 *TGA=(u8*)malloc(Frm.GetWidth()*Frm.GetHeight()*3); ASSERT(TGA); Frm.FlipY(); Frm.MakeRGB(TGA); char OutName[256]; sprintf(OutName,"\\x\\%s.tga",Name); SaveTGA(OutName,Frm.GetWidth(),Frm.GetHeight(),TGA,true); free(TGA); } //*************************************************************************** //*************************************************************************** //*************************************************************************** void CMkActor::Process() { BuildFrameList(); LoadFrameList(); ProcessFrames(); } //*************************************************************************** void CMkActor::ProcessFrames() { int i,ListSize=BmpList.size(); TotalIn=0; TotalOut=0; for (i=0; i OutPal; PsxPalette=PCPalette; PsxPalette.SetPlusColZero(true); Count=PsxPalette.GetNumOfCols(); if (Count<16) Count=16; PsxPalette.MakePSXPal(OutPal); for (i=0; i Hdrs; // Write Dummy Hdrs FileHdr.AnimCount=AnimCount; Hdrs.resize(AnimCount); for (i=0; i Hdrs; FileHdr.MaxW=MaxW; FileHdr.MaxH=MaxH; FileHdr.FrameCount=FrameCount; // Write Dummy Hdrs Hdrs.resize(FrameCount); for (i=0; i