/*************************/ /*** Actor Sprite Tool ***/ /*************************/ #include "stdio.h" #include #include #include #include #include #include #include "MkActor.h" #include using namespace std; //*************************************************************************** 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&Bmp.Psx[nfAreaBytes]) printf("!"); if ((x&1)) { *PixAddr&=0x0f; *PixAddr|=ScrNib<<4; } else { *PixAddr&=0xf0; *PixAddr|=ScrNib; } } } } //*************************************************************************** int CMkActor::LoadBmp(GString &Name,bool VRamFlag) { GString Filename=SpriteDir+Name; int Idx,i,ListSize; int W,H,Size; sBmp NewBmp; Frame &Bmp=NewBmp.Bmp; NewBmp.Filename=Filename; NewBmp.RGB=0; NewBmp.Pak=0; NewBmp.Psx=0; NewBmp.VRamFlag=VRamFlag; Bmp.LoadBMP(Filename); W=Bmp.GetWidth(); H=Bmp.GetHeight(); Size=W*H; NewBmp.RGB=(u8*)malloc(Size*3); ASSERT(NewBmp.RGB); Bmp.MakeRGB(NewBmp.RGB); #if _DEBUG && 0 { u8 *TGA=(u8*)malloc(Size*3); ASSERT(TGA); Bmp.FlipY(); Bmp.MakeRGB(TGA); Bmp.FlipY(); char OutName[256]; sprintf(OutName,"\\x\\%s.tga",Name); SaveTGA(OutName,W,H,TGA,true); free(TGA); } #endif // Gen Chksum u8 *RGB=NewBmp.RGB; NewBmp.ChkR=NewBmp.ChkG=NewBmp.ChkB=0; for (i=0; i OutPal; PsxPalette=PCPalette; PsxPalette.SetPlusColZero(true); Count=PsxPalette.GetNumOfCols(); FileHdr.ColorCount=Count; PsxPalette.MakePSXPal(OutPal); for (i=0; i Out; // Write Dummy Hdrs FileHdr.AnimCount=ListSize; Out.resize(ListSize); for (i=0; i Out; // Write Dummy Hdrs FileHdr.FrameCount=ListSize; Out.resize(ListSize); for (i=0; i