/*************************/ /*** Actor Sprite Tool ***/ /*************************/ #include "stdio.h" #include #include #include #include #include #include #include #include "MkActor.h" #include using namespace std; //#define CheckDups 1 //#define OutputTGA //*************************************************************************** vector ActorList; int TPBase=-1,TPWidth=-1,TPHeight=-1; GString TPOutStr; GString RootPath; GString SpritePath; GString OutPath; GString IncludePath; //*************************************************************************** void RepAlign(FILE *File,char *Txt=0) { /* int Align=ftell(File)&3; if (Align) { if (Txt) printf("%s MisAlign %i\n",Txt,Align); else printf("%s MisAlign %i\n","File",Align); } */ PadFile(File); } //*************************************************************************** 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]) ASSERT(!""); 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 BmpListSize=BmpList.size(); sBmp NewBmp; SprFrame &NewFrame=NewBmp.Bmp; FileInfo ThisInfo; // ThisInfo.SetInfo(name, CrossHair, ThisZeroColZero, MoveUVs, AllowRotate, ShrinkToFit, m_allocateAs16bit); ThisInfo.SetInfo(Filename, false, true, false, false, true, false); NewBmp.RGB=0; NewBmp.Pak=0; NewBmp.Psx=0; NewBmp.VRamFlag=VRamFlag; NewFrame.LoadBMP(Filename); int ColorCount=NewFrame.GetNumOfCols(); if (ColorCount>16) { GObject::Error(ERR_WARNING,"%s has %i colors.\n",Name,ColorCount); } #ifdef CheckDups int Size=NewFrame.GetWidth()*NewFrame.GetHeight(); NewBmp.RGB=(u8*)malloc(Size*3); ASSERT(NewBmp.RGB); NewFrame.MakeRGB(NewBmp.RGB); // Check for dups (Broken at the mo, ah well) // 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(); if (Count<16) Count=16; // if (Count>16) // { // GObject::Error(ERR_WARNING,"Too Many Colors.\n"); // } FileHdr.ColorCount=Count; PsxPalette.MakePSXPal(OutPal); for (i=0; i Hdrs; // Write Dummy Hdrs FileHdr.AnimCount=AnimCount; Hdrs.resize(AnimCount); for (i=0; i Hdrs; // Write Dummy Hdrs FileHdr.FrameCount=FrameCount; Hdrs.resize(FrameCount); for (i=0; i