/*************************/ /*** 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; int DupThresh; GString TPOutStr; GString RootPath; GString SpritePath; GString OutPath; GString IncludePath; float Aspect=512.0f/320.0f; //*************************************************************************** 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 'a': TpStr= CheckFileString(String); Aspect=(float)atof(TpStr); break; case 'c': TpStr= CheckFileString(String); DupThresh=(int)atol(TpStr); 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"); printf(" -a: Aspect Ratio\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); } // 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 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