/*========================================================================= MAIN.CPP Author: Gary Liddon @ Fareham Created: 28th September 1998 Project: Theme Park World PSX Purpose: Main file for tpw sprite grabber (it's sprgrab II!) Copyright (c) 1998 G R Liddon ===========================================================================*/ /*---------------------------------------------------------------------- Version info 1.0 - 1.1 Various changes by various authors 1.2 GL Added -r switch to allow \ disallow sprite rotation 1.3 GL Added -x option to allow saving out of non VRAM sprs 1.31 GL Added -f option so you can force offsets to a value 1.4 TS Added replacement of bad characters in filenames 1.5 GL Added support for BMP files 1.6 GL Made all out files lower case Checked for errrors when writing files (Doh!) 1.7 GL Added -q (turn on\of grabbers shrink to fit routine) Also Added -k option to report where each texture has gone in the VRAM, This will be read by mikes gin -> ars program for deciding what to do about shared textures 1.71 GL Added widths and heights of textures to report file 1.72 GL Actually made the -q switch do what it was supposed to. Doh! 1.8 GL Added -i switch to set output dir for inc files 1.81 GL Corrected bug in 1.8 that meant no .h was written 1.9 GL -e to set maximum size for textures 1.91 GL Changed so that files prefixed with a "+" have col zero as see-through 2.0 GL Added reading of gin files and import of rep files 2.1 GL Added spare tpage space defintions 2.11 GL Added the rather excellent -j option 2.12 GL Fixed a bug, stopped -j textures from being reduced 2.13 GL Removed the -j option and changed it so that all textures starting with ! are auto -j'd ;) 2.14 GL Replaced bit map loader, will move this code into Frame at some point 2.15 GL Restricted it so that only images up to 254x254 are allowed 2.16 GL Fixed bug that meant 256 col images were often shagged 2.17 TS Added '@' filename pre-fix to denote scrolling and transparent textures 2.2 GL Changed the autocropping so that if the image is blank it allocates a 1x1 texture instead of a texture the size of the input lbm 2.21 GL added -twisting_my_melon_man siwtch (don't ask) 2.3 GL added -y command to give us tpage compression 2.31 GL -y didn't work (not even a little bit) but it does now ;) 2.4 GL Added -~ switch to write out a raw tpage chunked version of the VRAM file 2.41 GL Added -^ switch to stop any tpages being written 2.5 TS Added -h half a tpage flag 2.6 DO Added -w only output animated texture frame headers Added -b dont output spare boxes Added -a align headers to 2k /*---------------------------------------------------------------------- Includes -------- */ /* Std Lib ------- */ #include #include /* Glib ---- */ #include #include #include #include #include /* TP Lib ------- */ #include #include /* Local ----- */ #include "sprset.h" /*---------------------------------------------------------------------- Tyepdefs && Defines ------------------- */ using namespace std; /*---------------------------------------------------------------------- Class defintions ---------------- */ /* Hold's a list of all the files to be processed on along with the options that apply to them ------------------------------------------------------------------------------------------- */ class AllFiles : protected FileCycler { public: AllFiles(void) { RecurseFiles=false; CrossHair=false; ZeroColZero=false; MoveUVs=false; AllowRotate=true; ForceOffsets=false; ShrinkToFit=true; m_allocateAs16bit=false; MaxSize=0; m_noSort=false; } void SetFileRecursion(bool NewRecurseFiles) {RecurseFiles=NewRecurseFiles;} void SetCrossHair(bool NewCrossHair) {CrossHair=NewCrossHair;} void SetZeroColZero(bool NewColZero) {ZeroColZero=NewColZero;} void SetMoveUVs(bool NewMoveUVs) {MoveUVs=NewMoveUVs;} void SetAllowRotate(bool NewAllowRotate) {AllowRotate=NewAllowRotate;} void SetForceOffsets(bool NewForceOffsets) {ForceOffsets=NewForceOffsets;} void SetShrinkToFit(bool NewSetShrinkToFit) {ShrinkToFit=NewSetShrinkToFit;} void SetXOff(int NewXOff) {XOff=NewXOff;} void SetYOff(int NewYOff) {YOff=NewYOff;} void SetMaxSize(int New) {MaxSize=New;} int GetMaxSize(void) const {return(MaxSize);} void AddFile(const char * Name); FIVec const & GetFileInfoVector(void) const {return(AllFileInfos);} void SortOrder(); void ReadRepFile(char const * Name) { vector MyItems; ::readRepFile(Name,MyItems); for (int f=0;f UniqueTexturesSoFar; vector AllExternalSharedTextures; void FileCallback(char const * FName,int FileNum); bool ShrinkToFit; bool RecurseFiles; bool CrossHair; bool ZeroColZero; bool MoveUVs; bool AllowRotate; bool ForceOffsets; bool m_allocateAs16bit; bool m_noSort; int XOff,YOff; FIVec AllFileInfos; int MaxSize; }; /*---------------------------------------------------------------------- Function Prototypes ------------------- */ static char * CycleCommands(char *String,int Num); static void Usage(void); static bool CheckPlusMinus(const char * Str); static GString CheckFileString(const char * Str); static GString OutFile; static GString OutLbm; static GString SprFile; static GString ReportFile; static GString IncOutFile; static int PageBase; static int WidthPages; static int HeightPages; static bool PagePlacements=false; static bool s_compressTpages=false; static bool s_noWriteTpages=false; static bool s_useHalfTpage=false; static bool s_AnimatedHeadersOnly=false; static bool s_DontOutputBoxes=false; static bool s_AlignHeaders=false; static GString s_rawTpageFile; /*---------------------------------------------------------------------- Vars ---- */ static AllFiles MyFiles; /*---------------------------------------------------------------------- Data ---- */ static const float Version = 2.6; /*---------------------------------------------------------------------- Function: Purpose: Params: Returns: ---------------------------------------------------------------------- */ int main(int argc,char ** argv) { cerr<<"GRLiddon() PARKGRAB TPW Spr Grabber "<+|-. Aborts out of there was a problem. Params: Str = Text of item Returns: true if a plus option ---------------------------------------------------------------------- */ bool CheckPlusMinus(const char * Str) { if (strlen(Str)==3 && (Str[0]=='-' || Str[0]=='/') && (Str[2]=='-' || Str[2]=='+')) { } else GObject::Error(ERR_FATAL,"Problem with cmd line option %s",Str); return(Str[2]=='+'); } /*---------------------------------------------------------------------- Function: void CheckPlusMinus(const char * Str) Purpose: Check to see if this cmd line item is of the type -+|-. Aborts out of there was a problem. Params: Str = Text of item Returns: true if a plus option ---------------------------------------------------------------------- */ GString CheckFileString(const char * Str) { GString RetStr; if (strlen(Str)>3 && (Str[0]=='-' || Str[0]=='/') && (Str[2]==':' || Str[2]==':')) RetStr=&Str[3]; else GObject::Error(ERR_FATAL,"Problem with cmd line option %s",Str); return(RetStr); } /*---------------------------------------------------------------------- Function: void Usage(void) Notes: Usage of the util ---------------------------------------------------------------------- */ void Usage(void) { cout<<"Usage: PARKGRAB [ .. ] [ switches.. ]\n"; cout<<"Switches:\n"<\t\t\tSet recurse sub dirs (default off)"<\t\t\tSet cross hair offset detection (default off)"<\t\t\tSet colour zero trans (default off)"<\t\t\tSet move in u/v coords (default off)"<\t\t\tSet if spr rotation allowed (default on)"<\t\t\tShrink to bounds of lbm (default on)"<\t\t\tCompress tpages (default off)"<\t\t\tDo not write a tpage (default off)"<\t\t\tForce tpage height to half (default off)"<\t\t\tOnly write animated headers (default off)"<\t\t\tDo not write spare boxes (default off)"<\t\t\tAlign headers to 2k chunk (default off)"<\t\tSet maximum size for textures"<\t\tRead in a shared texture file for gin files"<\t\tOutput Vram filename"<\t\tOutput Sprfile filename"<\t\tWrite out an lbm of the tpage "<\t\tWrite out a vram report"<\t\tWrite out raw VRAM image"< #include void AllFiles::FileCallback(char const * FName,int FileNum) { FileInfo MyInfo; bool ThisZeroColZero; GFName FileName(FName); GString Ext(FileName.Ext()); Ext.Lower(); if (Ext=="gin") { vector NonSharedTextures; // Gin4File MyFile; CScene MyFile; MyFile.Load(FName); MyFile.GetNonSharedTextures(AllExternalSharedTextures,NonSharedTextures); vector NewEntrys; for (int f=0;f