diff --git a/Utils/Libs/DaveLib/List.h b/Utils/Libs/DaveLib/List.h new file mode 100644 index 000000000..8d8211d96 --- /dev/null +++ b/Utils/Libs/DaveLib/List.h @@ -0,0 +1,61 @@ +/**********************/ +/*** Vtx List Class ***/ +/**********************/ + +#if !defined __VTXLIST_CLASS_HEADER__ +#define __VTXLIST_CLASS_HEADER__ + +#include + +/*****************************************************************************/ + +template class CList +{ +public: + + int Find(T &Item) + { + int ListSize=List.size(); + + for (int i=0; i &GetList() {return(List);} + + T& operator []( int nIndex ) {return(List[nIndex]);} + +private: + std::vector List; + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/Libs/GLib/GLib.dsw b/Utils/Libs/GLib/GLib.dsw new file mode 100644 index 000000000..991e49581 --- /dev/null +++ b/Utils/Libs/GLib/GLib.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "Glib"=.\Glib.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Utils/Libs/GLib/Glib.dsp b/Utils/Libs/GLib/Glib.dsp new file mode 100644 index 000000000..19dcb0907 --- /dev/null +++ b/Utils/Libs/GLib/Glib.dsp @@ -0,0 +1,346 @@ +# Microsoft Developer Studio Project File - Name="GLib" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=GLib - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "Glib.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "Glib.mak" CFG="GLib - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "GLib - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "GLib - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/tp2psx/glibdev/build/GLib", GXNAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "GLib - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "lib\Release" +# PROP Intermediate_Dir "lib\Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MD /W3 /Gi- /GX /O2 /I "include" /I "include\pc" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "GLib - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "lib\debug" +# PROP Intermediate_Dir "lib\debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "include" /I "include\pc" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "__GL_DEBUG__" /FR /YX /FD /GZ /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "GLib - Win32 Release" +# Name "GLib - Win32 Debug" +# Begin Group "Core Source" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=Source\Gal.c +# End Source File +# Begin Source File + +SOURCE=Source\Gmain.c +# End Source File +# Begin Source File + +SOURCE=Source\Gtimer.c +# End Source File +# Begin Source File + +SOURCE=Source\Gutils.c +# End Source File +# Begin Source File + +SOURCE=Source\Ll.c +# End Source File +# Begin Source File + +SOURCE=Source\Objs.c +# End Source File +# Begin Source File + +SOURCE=Source\Tasker.c +# End Source File +# Begin Source File + +SOURCE=Source\Tick.c +# End Source File +# End Group +# Begin Group "Core Headers" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Glib\Include\Gal.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Gdebug.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Gmain.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Gsys.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Gtimer.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Gtimsys.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Gtypes.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Gutils.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Ll.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Objs.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Tasker.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Tick.h +# End Source File +# End Group +# Begin Group "PC Source" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=Source\Pc\Dpanim.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Frame.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Ganim.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Gdebug.c +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Gfname.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Gobject.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Gstring.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Gsys.c +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Gtimsys.c +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Iff.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Ilbm.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Misc.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Niff.cpp +# End Source File +# Begin Source File + +SOURCE=Source\Pc\Pal.cpp +# End Source File +# Begin Source File + +SOURCE=Source\PC\REGEX.C +# End Source File +# Begin Source File + +SOURCE=Source\Pc\tquant.cpp +# End Source File +# End Group +# Begin Group "PC Headers" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Dpanim.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Frame.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Ganim.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Gfname.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Gobject.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Gstring.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Iff.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Ilbm.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Misc.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Mtypes.h +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Niff.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\Pal.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\GLIB\Include\PC\REGEX.H +# End Source File +# Begin Source File + +SOURCE=..\..\Glib\Include\Pc\tquant.h +# End Source File +# End Group +# Begin Group "Template" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Template\Template.cpp +# PROP Exclude_From_Scan -1 +# PROP BASE Exclude_From_Build 1 +# PROP Exclude_From_Build 1 +# End Source File +# Begin Source File + +SOURCE=..\..\Template\Template.h +# PROP Exclude_From_Scan -1 +# PROP BASE Exclude_From_Build 1 +# PROP Exclude_From_Build 1 +# End Source File +# End Group +# Begin Group "PCRE" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=Source\PC\pcre\chartables.c +# End Source File +# Begin Source File + +SOURCE=Source\PC\pcre\internal.h +# End Source File +# Begin Source File + +SOURCE=Source\PC\pcre\maketables.c +# End Source File +# Begin Source File + +SOURCE=Source\PC\pcre\pcre.c +# End Source File +# Begin Source File + +SOURCE=..\..\GLIB\Include\PC\pcre.h +# End Source File +# Begin Source File + +SOURCE=Source\PC\pcre\study.c +# End Source File +# End Group +# End Target +# End Project diff --git a/Utils/Libs/GinLib/animheader.cpp b/Utils/Libs/GinLib/animheader.cpp new file mode 100644 index 000000000..a3f9be78d --- /dev/null +++ b/Utils/Libs/GinLib/animheader.cpp @@ -0,0 +1,270 @@ +/*========================================================================= + + ANIMHEADER.CPP + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#include + +/* Glib + ---- */ +#include +#include + +/* Local + ----- */ +#include "animheader.h" + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ +using namespace std; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ +static int GetHex(char const * Str); + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int GetHex(char const * Str) +{ + char Buffer[1024]; + strcpy(Buffer,Str); + + strstream i(Buffer,1024); + + int Val; + + i>>hex>>Val; + return(Val); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +void MakeAnimHeader( char * line, AnimHeaderItem * item ) +{ + int len; + int pos; + char anim[1024]; + char animno[8]; + + pos = 0; + len = strlen( line ); + + if (len > 4) + { + int count = 0; + + // FIND ANIM + while(count != 3) + { + while(line[pos] != '_') + { + pos++; + if (pos >= len) + { + GObject::Error(ERR_FATAL,"Header scan overrun line - %s\n", line); + } + } + pos++; + count++; + } + + // GET ANIM NAME + count = 0; + while(line[pos] != ' ') + { + anim[count++] = line[pos++]; + if (pos > len) + { + GObject::Error(ERR_FATAL,"Header scan overrun line - %s\n", line); + } + } + anim[count] = 0; + + // GET ANIM NUMBER + pos += 3; + count = 0; + while(line[pos] != ',') + { + animno[count++] = line[pos++]; + if (pos > len) + { + GObject::Error(ERR_FATAL,"Header scan overrun line - %s\n", line); + } + } + animno[count] = 0; + + strupr( anim ); + item->m_AnimName = anim; + item->m_Frame = atoi( animno ); + } + else + { + GObject::Error(ERR_FATAL,"Incorrect header line - %s\n", line); + } +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void readAnimHeaderFile(char const * Name, std::vector & Items) +{ + char Line[1024]; + + try + { + ifstream InStream; + + InStream.open(Name,ios::in); + + if (InStream) + { + InStream.getline(Line,1024); // HEADER GUARD + InStream.getline(Line,1024); // HEADER GUARD + InStream.getline(Line,1024); // ENUM + InStream.getline(Line,1024); // { + InStream.getline(Line,1024); // ANIM COUNT + + while (!InStream.eof() && Line[0] != '}') + { + InStream.getline(Line,1024); + + if (strlen(Line) && Line[0] != '}') + { + AnimHeaderItem MyItem; + + MakeAnimHeader( Line, &MyItem ); + + InStream.getline(Line,1024); // NUMBER OF FRAMES + + Items.push_back( MyItem ); + } + } + InStream.close(); + } + else + { + throw("Error opening anim header file"); + } + } + + catch (char const * E) + { + GObject::Error(ERR_FATAL,"Error in AddToTexList : %s",E); + } + +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void AnimHeaderFile::load(char const * name) +{ + vector items; + + readAnimHeaderFile(name,items); + + int numOfItems; + + numOfItems=items.size(); + + for (int f=0;f::iterator it; + + srchStr=str; + + makeTexNameCompliant(srchStr); + + it=m_strToInfo.find(srchStr); + + if (it == m_strToInfo.end()) + { + return(false); + } + else + { + result=m_strToInfo[srchStr]; + return(true); + } +} + +/*=========================================================================== + end */ + + diff --git a/Utils/Libs/GinLib/animheader.h b/Utils/Libs/GinLib/animheader.h new file mode 100644 index 000000000..f31367a36 --- /dev/null +++ b/Utils/Libs/GinLib/animheader.h @@ -0,0 +1,87 @@ +/*========================================================================= + + ANIMHEADER.H + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +#pragma warning( disable : 4786 ) + +#ifndef __ANIMHEADER_H__ +#define __ANIMHEADER_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#include +#include + +/* Glib + ---- */ +#include +#include + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +struct AnimHeaderItem +{ + GString m_AnimName; + int m_Frame; +}; + +class AnimHeaderFile +{ + +private: + GString m_lastLoadedFile; + std::map m_strToInfo; + + void makeTexNameCompliant(GString & str); + +public: + void load(char const * name); + bool find(GString const & str,AnimHeaderItem & result); + + + char const * getLastFileLoaded(void) + {return(m_lastLoadedFile);} +}; + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ +void readAnimHeaderFile(char const * Name,std::vector & Items); + +/*---------------------------------------------------------------------- */ + +#endif /* __ANIMHEADER_H__ */ + +/*=========================================================================== + end */ + diff --git a/Utils/Libs/GinLib/ginio.cpp b/Utils/Libs/GinLib/ginio.cpp new file mode 100644 index 000000000..5150e9223 --- /dev/null +++ b/Utils/Libs/GinLib/ginio.cpp @@ -0,0 +1,180 @@ +/*========================================================================= + + FILENAME.CPP + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* Glib + ---- */ + +/* Local + ----- */ +#include "ginio.h" + + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ +using namespace std; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ +vector GinFile::ChunkHandlers; + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +GinChunk::GinChunk(void) +{ + Size=0; +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +GinChunk::~GinChunk(void) +{ + DumpData(); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void GinChunk::Load(Gifstream & In) +{ + Data.resize(Size); + In.read((char *)(&Data[0]),Size); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void GinFile::AddHandler(GinChunk * New) +{ + ChunkHandlers.push_back(New); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +GinChunk * GinFile::GetHandler(char const * Name) +{ + GString ChunkName(Name); + + GinChunk * RetChunk; + + RetChunk=NULL; + + for (int f=0;fGetName())) + RetChunk=ChunkHandlers[f]->MakeNew(); + } + + + return(RetChunk); +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +bool GinFile::GinHdr::ReadHdr(Gifstream & In) +{ + vector Str; + bool Done; + GString RetStr; + + Done=false; + + Str.reserve(1000); + + + while (In && !In.eof() && !Done) + { + char c=In.get(); + + if (!c) + Done=true; + + Str.push_back(c); + } + + if (Done) + { + Name=&Str[0]; + + In.Align(4); + + if (In) + { + Size=In.Get32(); + } + else + Done=false; + } + + + return(Done); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void GinChunk::DumpData(void) +{ + Size=0; + Data.resize(0); +} + +/*=========================================================================== + end */ diff --git a/Utils/Libs/GinLib/ginio.h b/Utils/Libs/GinLib/ginio.h new file mode 100644 index 000000000..a28ef7aba --- /dev/null +++ b/Utils/Libs/GinLib/ginio.h @@ -0,0 +1,233 @@ +/*========================================================================= + + FILENAME.CPP + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +#ifndef __GINIO_H__ +#define __GINIO_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#pragma warning( disable : 4786 ) +#include +#include +#include +#include + +/* Glib + ---- */ + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +class GinChunk : public GObject +{ +public: + GinChunk(void); + virtual ~GinChunk(void); + + void LoadFile(Gifstream & In); + + virtual char const * GetName(void) const + {return("DEFAULT"); } + + void SetNameSize(char const * NewName,int NewSize) + { + Name=NewName; + Size=NewSize; + } + virtual void Load(Gifstream & In); + + virtual GinChunk * MakeNew(void) + {return(new GinChunk);} + +protected: + + + void DumpData(void); + + GString Name; + int Size; + std::vector Data; +}; + + +class GinFile : public GObject +{ +public: + GinFile(void) + { + ReadUnknownChunks=false; + } + + ~GinFile(void) + { + int i; + for (i=0; iSetNameSize(MyHdr.Name,MyHdr.Size); + ChunkReader->Load(In); + Chunks.push_back(ChunkReader); + } + + if (In) + In.seekg(ChunkLenAligned+ChunkPos,std::ios::beg); + else + { + Error(ERR_FATAL,"Error loading chunk"); + } + } + + In.close(); + } + else + Error(ERR_FATAL,"Can't open gin file %s",File); + } + + int FindChunks(char const * Type,std::vector & RetChunks) + { + int NumOfChunks; + + NumOfChunks=0; + + for (int f=0;fGetName(); + + if (Name==Type) + { + RetChunks.push_back(Chunks[f]); + NumOfChunks++; + } + } + + return(NumOfChunks); + } + +protected: + + struct GinHdr + { + GinHdr(void) + {Size=0;} + + bool ReadHdr(Gifstream & In); + + bool PeekHdr(Gifstream & In) + { + int InPos; + bool Ret; + + InPos=In.tellg(); + + Ret=ReadHdr(In); + + if (Ret) + In.seekg(InPos,std::ios::beg); + + return(Ret); + } + + GString Name; + int Size; + }; + + + std::vector Chunks; + bool ReadUnknownChunks; + + static std::vector ChunkHandlers; + static GinChunk * GetHandler(char const * Name); +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ + + + +/*---------------------------------------------------------------------- */ + +#endif /* __GINIO_H__ */ + +/*=========================================================================== + end */ diff --git a/Utils/Libs/GinLib/ginlib.dsp b/Utils/Libs/GinLib/ginlib.dsp new file mode 100644 index 000000000..a3e1a7d65 --- /dev/null +++ b/Utils/Libs/GinLib/ginlib.dsp @@ -0,0 +1,152 @@ +# Microsoft Developer Studio Project File - Name="GinLib" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=GinLib - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "ginlib.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "ginlib.mak" CFG="GinLib - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "GinLib - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "GinLib - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/TP2psx/utils/GinLib", FUQBAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "GinLib - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\glib\include" /I "..\glib\include\pc" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "GinLib - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\glib\include" /I "..\glib\include\pc" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fr /YX /FD /GZ /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "GinLib - Win32 Release" +# Name "GinLib - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\animheader.cpp +# End Source File +# Begin Source File + +SOURCE=.\ginio.cpp +# End Source File +# Begin Source File + +SOURCE=.\gintex.cpp +# End Source File +# Begin Source File + +SOURCE=.\mapread.cpp +# End Source File +# Begin Source File + +SOURCE=.\Maths.cpp +# End Source File +# Begin Source File + +SOURCE=.\repread.cpp +# End Source File +# Begin Source File + +SOURCE=.\script.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\animheader.h +# End Source File +# Begin Source File + +SOURCE=.\ginio.h +# End Source File +# Begin Source File + +SOURCE=.\gintex.h +# End Source File +# Begin Source File + +SOURCE=.\IniClass.h +# End Source File +# Begin Source File + +SOURCE=.\mapread.h +# End Source File +# Begin Source File + +SOURCE=.\Maths.h +# End Source File +# Begin Source File + +SOURCE=.\repread.h +# End Source File +# Begin Source File + +SOURCE=.\script.h +# End Source File +# End Group +# End Target +# End Project diff --git a/Utils/Libs/GinLib/gintex.cpp b/Utils/Libs/GinLib/gintex.cpp new file mode 100644 index 000000000..174093a17 --- /dev/null +++ b/Utils/Libs/GinLib/gintex.cpp @@ -0,0 +1,970 @@ +#include + +#include +#include "gintex.h" +#include "Maths.h" + + +using namespace std; + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +// Unconditional string compare +// REturns 1 on equal +int IsStrSame(char *Str0,char *Str1,int Len) +{ + if (Len==-1) + { + Len=strlen(Str0); + if (strlen(Str1)!=Len) return(0); + } + for (int Loop=0;Loop='a' && C0<='z') C0+='A'-'a'; + if (C1>='a' && C1<='z') C1+='A'-'a'; + if (C0!=C1) return(0); + } + return(1); +} +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +int CMat4::GetTexId(int v) +{ + int NumOfTextures; + + NumOfTextures=Mats.size(); + + if (v>=NumOfTextures) + { + GObject::Error(ERR_WARNING,"erroneous material id of %d\n",v); + v = 0; + } + + if (v>=NumOfTextures) + GObject::Error(ERR_FATAL,"material asked for when none exists",v); + + return Mats[v].TexId; +} + + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMat4::Load(Gifstream & In) +{ + int m = In.Get32(); + int o = In.Get32(); + + Mats.resize(m); + for (int i=0; i Str; + bool Done; + + Str.reserve(200); + Done=false; + + In.Align(4); + + while (!Done) + { + char c; + c=In.get(); + if (!c) + Done=true; + Str.push_back(c); + } + + Names.push_back(&Str[0]); + } +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CGinTree::Load(Gifstream & In) +{ + LoadTree(In,-1); +} + +/*****************************************************************************/ +void CGinTree::LoadTree(Gifstream & In,int Parent) +{ +CNode ThisNode; + + In.Align(4); + + In.read(ThisNode.Name, 32); + In.read((char*)&ThisNode.XPos, 4); + In.read((char*)&ThisNode.YPos, 4); + In.read((char*)&ThisNode.ZPos, 4); + + In.read((char*)&ThisNode.XAng, 4); + In.read((char*)&ThisNode.YAng, 4); + In.read((char*)&ThisNode.ZAng, 4); + In.read((char*)&ThisNode.WAng, 4); + + In.read((char*)&ThisNode.Xapk, 4); + In.read((char*)&ThisNode.Yapk, 4); + In.read((char*)&ThisNode.Zapk, 4); + + In.read((char*)&ThisNode.Xapu, 4); + In.read((char*)&ThisNode.Yapu, 4); + In.read((char*)&ThisNode.Zapu, 4); + In.read((char*)&ThisNode.Wapu, 4); + +int ChildCount= In.Get32(); + SceneTree[0].AddChild( SceneTree,ThisNode,Parent); + +int Idx=ThisNode.Idx; + for (int Loop=0;Loop &VersionChunk=GinFile.GetVersionChunk(); +std::vector &TexNamesChunk=GinFile.GetTexNamesChunk(); +std::vector &MatChunk=GinFile.GetMatChunk(); +std::vector &MshChunk=GinFile.GetMshChunk(); +std::vector &PointsChunk=GinFile.GetPointsChunk(); +std::vector &TrisChunk=GinFile.GetTrisChunk(); +std::vector &VColTrisChunk=GinFile.GetVColTrisChunk(); +std::vector &UVtrisChunk=GinFile.GetUVtrisChunk(); +std::vector &SceneTreeChunk=GinFile.GetSceneTreeChunk(); +std::vector &AnimTreeChunk=GinFile.GetAnimTreeChunk(); +std::vector &KeyAnimTreeChunk=GinFile.GetKeyAnimTreeChunk(); +std::vector &SkinTreeChunk=GinFile.GetSkinTreeChunk(); +std::vector &UserPropChunk=GinFile.GetUserPropChunk(); +std::vector &CameraChunk=GinFile.GetCameraChunk(); + +int Node,NodeCount; + + +// Build Scene Tree +CGinTree *GT = (CGinTree*)SceneTreeChunk[0]; +std::vector const &GinTree=GT->GetTree(); + + NodeCount=GinTree.size(); + for (Node=0;NodeParentIdx; + ThisNode->Mtx=Identity; +// Build Node Mtx's + if (ParentIdx!=-1) + { + +// LocalMtx +TMATRIX ThisMtx,ParentMtx; +CNode *ParentNode=&SceneTree[ParentIdx]; + + ParentMtx=ParentNode->Mtx; + +TQUAT ThisQ(ThisNode->XAng,ThisNode->YAng,ThisNode->ZAng,ThisNode->WAng); + ThisQ.QuatToMat(&ThisMtx); + ThisMtx.SetPosition(ThisNode->XPos,ThisNode->YPos,ThisNode->ZPos); + ThisNode->Mtx=ParentMtx*ThisMtx; + +// WorldMtx + ThisNode->WorldMtx=GetWorldMatrix(SceneTree,ParentIdx); + } + } + +/* + for (Node=0;NodeMtx; + +TQUAT ThisQ(ThisNode.XAng,ThisNode.YAng,ThisNode.ZAng,ThisNode.WAng); + ThisQ.QuatToMat(&ThisMtx); + ThisMtx.t[0]=ThisNode.XPos; ThisMtx.t[1]=ThisNode.YPos; ThisMtx.t[2]=ThisNode.ZPos; + SceneTree[Node].Mtx=ParentMtx*ThisMtx; + } + } +*/ + + +//----------------------------------------------------------------------------- +// Load Materials + int MatN = MatChunk.size(); + if (MatN) + { + CMat4 * Materials = (CMat4*)MatChunk[0]; + AllMaterials = Materials->GetMaterials(); + + if (TexNamesChunk.size()) + { + CTexName * T=(CTexName *)(TexNamesChunk[0]); + vector const & Strs=T->GetTexNames(); + TextureList = Strs; + int NumOfMeshes=MshChunk.size(); + for (int j=0; j const & Mat4Id = M->GetChunk(); + for (int i=0; i=0) + { + int tid = Materials->GetTexId(Mat4Id[i].MatId); + if (tid >= Strs.size() || tid < 0) + { + GObject::Error(ERR_WARNING,"Texture index odd (aksed for %d, max is %d) adjusting to 0\n",tid,Strs.size()); + tid=0; + } + // else + { + GString const & TexFile=Strs[tid]; + /* Only add texture to list if it hasn't been on it before */ + if (find(AllTexNames.begin(),AllTexNames.end(),TexFile) == AllTexNames.end()) AllTexNames.push_back(TexFile); + } + } + } + } + } + } + else + { + GObject::Error(ERR_WARNING,"No Materials\n"); + } + +//----------------------------------------------------------------------------- +// Load Models and Meshes + for (int m=0; mgetObj(); + CNode *ThisNode=GetNodePtr(GinFile.GetModelName(CurMod)); + + if (loadPoints( CurMod, PointsChunk,ThisNode) != -1) + { + vector const &MeshChunks = M->GetChunk(); + for (int mn=0; mnTriMaterial.push_back(MatIdx); + loadVCol( CurMod, MeshChunks[mn].MeshNum, VColTrisChunk,ThisNode); + loadUV( CurMod, MeshChunks[mn].MeshNum, UVtrisChunk,ThisNode); + int Size=ThisNode->Tris.size(); + ThisNode->UVTris.resize(Size); + ThisNode->VColTris.resize(Size); + ThisNode->TriMaterial.resize(Size); + } + } + } + } + +//----------------------------------------------------------------------------- +// Load Anims +// Sort KeyFrame Anims +CKeyAnimTree *KATC= (CKeyAnimTree*)KeyAnimTreeChunk[0]; +CAnimTree *NATC = (CAnimTree*)AnimTreeChunk[0]; +std::vectorconst &KeyAnimTree=KATC->GetTree(); +std::vectorconst &AnimTree=NATC->GetTree(); + + NodeCount=KeyAnimTree.size(); + for (Node=0;NodeGetCam()); + } + } + + +//----------------------------------------------------------------------------- +// Load Skin Weight + if (SkinTreeChunk.size()) + { +CSkinTree *ST = (CSkinTree*)SkinTreeChunk[0]; +std::vector const &SkinTree=ST->GetTree(); + NodeCount=SkinTree.size(); + for (Node=0;NodeGetModNum()+1); // Skip SceneRoot); + if (ThisNode) + { + std::vector const & Prop=UP->GetUserProp(); + int Size=Prop.size()-1; + if (Size>0) + { + // ThisNode->UserProp.resize(Size); + // for (int c=0;cUserProp[c]=Prop[c]; + + char *PropPtr=(char*)&Prop[0]; + ThisNode->UserProp.Import(PropPtr); + } + } + } + } + +//----------------------------------------------------------------------------- +// Build Pruned Tree + ResetPruneTree(); + SetPruneNodes(0); + BuildPruneTree(0,-1); + +//----------------------------------------------------------------------------- +// Print Trees + +// PrintSceneTree(); +// PrintPruneTree(); + + +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CScene::PrintTreeNode(int Idx,const int Tree) +{ +/* +CNode &Node=SceneTree[Idx]; +int NodeIdx,NodeParentIdx; +std::vector ChildList; + if (Tree==0) + { + ChildList=Node.ChildList; + NodeIdx=Node.Idx; + NodeParentIdx=Node.ParentIdx; + } + else + { + ChildList=Node.PruneChildList; + NodeIdx=Node.PruneIdx; + NodeParentIdx=Node.PruneParentIdx; + } + +int ChildCount=ChildList.size(); + + for (int Sp=0;Sp &Points ,CNode *ThisNode) +{ + for (int f=0; fGetModNum() == CurMod) + { + std::vector const & ThesePts=T->GetPts(); + int Size= ThesePts.size(); + ThisNode->Pts.resize(Size); + ThisNode->RelPts.resize(Size); + + +TMATRIX IMtx=ThisNode->Mtx; + IMtx.inverse(ThisNode->Mtx); + + for (int g=0;gPts[g] = ThesePts[g]; +/*Rel Pnt*/ +//TVECTOR InVtx(ThesePts[g].x,ThesePts[g].y,ThesePts[g].z); +TVECTOR InVtx=ThesePts[g];//(ThesePts[g].x,ThesePts[g].y,ThesePts[g].z); +TVECTOR OutVtx=IMtx*InVtx; +// ThisNode->RelPts[g].x = OutVtx.GetX(); +// ThisNode->RelPts[g].y = OutVtx.GetY(); +// ThisNode->RelPts[g].z = OutVtx.GetZ(); + ThisNode->RelPts[g]=OutVtx; + } + return (Size); + } + } + return -1; +} + +/*****************************************************************************/ +int CScene::loadTris( int CurMod, int CurMesh, vector &Tris,CNode *ThisNode) +{ + for (int i=0; iGetModNum() == CurMod && T->GetMeshNum() == CurMesh) + { + std::vector const & TheseTris=T->GetTris(); + int Size = TheseTris.size(); + + ThisNode->TriBase=ThisNode->Tris.size(); + + for (int j=0; jTris.push_back(TheseTris[j]); + return (Size); + } + } + return -1; +} + +/*****************************************************************************/ +int CScene::loadUV( int CurMod, int CurMesh, vector &UVTris,CNode *ThisNode) +{ + for (int i=0; iGetModNum() == CurMod && T->GetMeshNum() == CurMesh) + { + std::vector const & TheseTris=T->GetUVTris(); + int Size = TheseTris.size(); + + for (int j=0; jUVTris.push_back(TheseTris[j]); + return (Size); + } + } + return -1; +} + +/*****************************************************************************/ +int CScene::loadVCol( int CurMod, int CurMesh, vector &VColTris,CNode *ThisNode) +{ + for (int i=0; iGetModNum() == CurMod && T->GetMeshNum() == CurMesh) + { + std::vector const & TheseTris=T->GetVcolTris(); + int Size = TheseTris.size(); + + for (int j=0; jVColTris.push_back(TheseTris[j]); + return (Size); + } + } + return -1; +} + + +/*****************************************************************************/ +int CScene::addMaterialIdx( int idx ) +{ + int c = UsedMaterials.size(); + for (int i=0; i const & SharedTextures,vector & Dest) +{ + for (int f=0;f const &Tree,int Idx) +{ +CNode ThisNode=Tree[Idx]; +int ParentIdx=ThisNode.ParentIdx; +TMATRIX ParentMtx=Identity; + + if (ParentIdx!=-1) ParentMtx=GetWorldMatrix(Tree,ParentIdx); + +TMATRIX ThisMtx=Identity; +TMATRIX PosMtx=Identity; +TMATRIX RotMtx=Identity; +TMATRIX StrMtx=Identity; +TMATRIX SclMtx=Identity; +TMATRIX IStrMtx=Identity; + +// Pos + PosMtx=Identity; + PosMtx.SetPosition(ThisNode.XPos,ThisNode.YPos,ThisNode.ZPos); +// Rot +TQUAT RotQ(ThisNode.XAng,ThisNode.YAng,ThisNode.ZAng,ThisNode.WAng); + RotQ.QuatToMat(&RotMtx); +// Stretch +TQUAT StrQ(ThisNode.Xapu,ThisNode.Yapu,ThisNode.Zapu,ThisNode.Wapu); + StrQ.QuatToMat(&StrMtx); + IStrMtx=StrMtx.inverse(); +// Scale + SclMtx=Identity; + SclMtx.ApplyScaleXYZ(ThisNode.Xapk,ThisNode.Yapk,ThisNode.Zapk); + + ThisMtx= PosMtx*RotMtx*StrMtx*SclMtx*IStrMtx; + + return(ParentMtx*ThisMtx); +} + +//---------------------------------------------------------------------------- +TVECTOR GetWorldPos(std::vector const &Tree,int Idx) +{ +CNode ThisNode=Tree[Idx]; +TVECTOR ThisPos(ThisNode.XPos,ThisNode.YPos,ThisNode.ZPos); +TMATRIX WorldMtx=GetWorldMatrix(Tree,ThisNode.ParentIdx); + +// if (WorldMtx!=ThisNode.WorldMtx) printf("!!!"); + return(WorldMtx*ThisPos); +} + +//---------------------------------------------------------------------------- +TVECTOR GetWorldPos(TMATRIX &WorldMtx,TVECTOR &ThisPos) +{ + return(WorldMtx*ThisPos); +} + +TVECTOR CNode::GetWorldPos(TVECTOR &Pos) +{ + + return(::GetWorldPos(WorldMtx,Pos)); +} + +TQUAT CNode::GetWorldAng(TQUAT &Q) +{ + return(TQUAT(0,0,0,0)); +} diff --git a/Utils/Libs/GinLib/gintex.h b/Utils/Libs/GinLib/gintex.h new file mode 100644 index 000000000..9e599dca8 --- /dev/null +++ b/Utils/Libs/GinLib/gintex.h @@ -0,0 +1,780 @@ +/********************/ +/*** Daves GinTex ***/ +/********************/ + +#pragma warning( disable : 4786 ) + +#ifndef __GINTEX_H__ +#define __GINTEX_H__ + +#include + +#include "ginio.h" +#include "maths.h" +#include "IniClass.h" + + +/*****************************************************************************/ +int IsStrSame(char *Str0,char *Str1,int Len=-1); + +/*****************************************************************************/ +/*** Version Chunk ***********************************************************/ +/*****************************************************************************/ +class CVers : public GinChunk +{ +public: + virtual char const * GetName(void) const {return("VERS");} + int GetVersion(void) {return(Version);} + +protected: + virtual GinChunk * MakeNew(void) {return(new CVers);} + + virtual void Load(Gifstream & In) + { + Version=In.Get32(); + } + + int Version; +}; + +/*****************************************************************************/ +/*** Material Chunk **********************************************************/ +/*****************************************************************************/ +struct Material +{ + int TexId; + int Flags; +}; +class CMat4 : public GinChunk +{ +public: + virtual char const * GetName(void) const {return("MAT4");} + std::vector const & GetMaterials(void) const {return(Mats);} + int GetTexId(int v); + +protected: + virtual GinChunk * MakeNew(void) {return(new CMat4);} + virtual void Load(Gifstream & In); + std::vector Mats; +}; + +/*****************************************************************************/ +/*** Mesh Chunk **************************************************************/ +/*****************************************************************************/ +struct MeshChunk +{ + int MatId; + int NumFace; + int MeshNum; + int Attrib; + int Normals; + int Vcol; + int Tex; +}; + +class CMesh : public GinChunk +{ +public: + virtual char const * GetName(void) const {return("MESH");} + std::vector const & GetChunk(void) const {return(Chunk);} + int getObj( void ) const {return Obj;} + +protected: + int Obj; + std::vector Chunk; + virtual GinChunk * MakeNew(void) {return(new CMesh);} + virtual void Load(Gifstream & In); +}; + +/*****************************************************************************/ +/*** Model Chunk *************************************************************/ +/*****************************************************************************/ +struct Mod4Chunk +{ + long nCurObj; + char Name[32]; + float Radius; + float CentreX,CentreY,CentreZ; + float ApX,ApY,ApZ; +}; + +class CMod4: public GinChunk +{ +public: + virtual char const * GetName(void) const {return("MOD4");} + std::vector const & GetChunk(void) const {return(Chunk);} + char * GetModelName() {return(Chunk[0].Name);} + +protected: + std::vector Chunk; + virtual GinChunk * MakeNew(void) {return(new CMod4);} + virtual void Load(Gifstream & In); +}; + +/*****************************************************************************/ +/*** Texture Name Chunk ******************************************************/ +/*****************************************************************************/ +class CTexName : public GinChunk +{ +public: + + virtual char const * GetName(void) const {return("TEX4");} + std::vector const & GetTexNames(void) const {return(Names);} + virtual GinChunk * MakeNew(void) {return(new CTexName);} + virtual void Load(Gifstream & In); + +protected: + std::vector Names; +}; + +/*****************************************************************************/ +/*** Vtx Chunk ***************************************************************/ +/*****************************************************************************/ +/*struct vec +{ + float x,y,z; + vec() {x = y = z = 0.f;} + vec(float _x, float _y, float _z) {x = _x; y = _y;z = _z;} +}; +*/ +class CPts4: public GinChunk +{ + virtual char const * GetName(void) const {return("PTS4");} + virtual GinChunk * MakeNew(void) {return(new CPts4);} + virtual void Load(Gifstream & In) + { + ModNum = In.Get32(); + int nv = In.Get32(); + Pnts.resize(nv); + for (int i = 0; i< nv ;i++) + { + float x,y,z; + In.read((char*)&x, 4); + In.read((char*)&y, 4); + In.read((char*)&z, 4); + Pnts[i] = TVECTOR(x,y,z); + } + } + +public: + + std::vector const & GetPts(void) const {return(Pnts);} + int GetModNum(void) const {return ModNum;} + +protected: + + int ModNum; + std::vector Pnts; +}; + +/*****************************************************************************/ +/*** Poly Chunk **************************************************************/ +/*****************************************************************************/ +struct sGinTri +{ + int p[3]; + int vis[3]; + +BOOL operator==(sGinTri const &v1) + { + for (int i=0; i<3;i++) + { + if (p[i]!=v1.p[i]) return(FALSE); + if (vis[i]!=v1.vis[i]) return(FALSE); + } + return (TRUE); + } + +}; + +class CPoly: public GinChunk +{ + virtual char const * GetName(void) const {return("POLY");} + virtual GinChunk * MakeNew(void) {return(new CPoly);} + + virtual void Load(Gifstream & In) + { + ModNum = In.Get16(); + MeshNum = In.Get16(); + int nf = In.Get32(); + + Tris.resize(nf); + for(int i=0; i const & GetTris(void) const {return(Tris);} + + int GetModNum(void) const {return ModNum;} + int GetMeshNum(void) const {return MeshNum;} + +protected: + + int ModNum,MeshNum; + std::vector Tris; +}; + +/*****************************************************************************/ +/*** Vtx Color Chunk *********************************************************/ +/*****************************************************************************/ +struct sRGB +{ + float r,g,b; +}; + +struct sVColTri +{ + sRGB p[3]; +}; + +class CVcol: public GinChunk +{ + virtual char const * GetName(void) const {return("VCOL");} + virtual GinChunk * MakeNew(void) {return(new CVcol);} + + virtual void Load(Gifstream & In) + { + ModNum = In.Get32(); + MeshNum = In.Get32(); + int nf = In.Get32(); + + Tris.resize(nf); + for(int i=0; i const & GetVcolTris(void) const {return(Tris);} + int GetModNum(void) const {return ModNum;} + int GetMeshNum(void) const {return MeshNum;} + +protected: + int ModNum,MeshNum; + std::vector Tris; +}; + +/*****************************************************************************/ +/*** Texture UV's Chunk ******************************************************/ +/*****************************************************************************/ +struct sUV +{ + float u,v; +BOOL operator==(sUV const &v1) + { + return(u==v1.u && v==v1.v); + } + +}; + +struct sUVTri +{ + sUV p[3]; +BOOL operator==(sUVTri const &v1) + { + for (int i=0; i<3;i++) + { + if (!(p[i]==v1.p[i])) return(FALSE); + } + return (TRUE); + } +}; + +class CUVtri: public GinChunk +{ + virtual char const * GetName(void) const {return("MAP4");} + virtual GinChunk * MakeNew(void) {return(new CUVtri);} + + virtual void Load(Gifstream & In) + { + ModNum = In.Get16(); + MeshNum = In.Get16(); + int nf = In.Get32(); + + Tris.resize(nf); + for(int i=0; i const & GetUVTris(void) const {return(Tris);} + int GetModNum(void) const {return ModNum;} + int GetMeshNum(void) const {return MeshNum;} + +protected: + + int ModNum,MeshNum; + std::vector Tris; +}; + +/*****************************************************************************/ +/*** Scene Tree Chunk ********************************************************/ +/*****************************************************************************/ +struct sGinWeight +{ + long VertNo; + float Weight; + float X,Y,Z; +}; +struct sGinAnim +{ + int Frame; + float XPos,YPos,ZPos; + float XAng,YAng,ZAng,WAng; + float kX,kY,kZ; + float uX,uY,uZ,uW; +}; + +class CNode +{ +public: + + int IsNodePrefix(char *InName) // Checks prefix + { + return(IsStrSame(InName,Name,strlen(InName))); + } + int IsNodeName(char *InName) // Checks full name + { + return(IsStrSame(InName,Name)); + } + + void AddChild(std::vector &Tree,CNode &Node,int Parent) + { + Node.ChildList.clear(); + int TreeSize=Tree.size(); + Node.ParentIdx=Parent; + Node.Idx=TreeSize; + Node.Active=true; + if (Parent!=-1) Tree[Parent].ChildList.push_back(Node.Idx); + if (!(Parent==-1 && Node.Idx)) Tree.push_back(Node); + } + + void AddPruneChild(std::vector &SceneTree,std::vector &PruneTree,int Parent) + { + PruneIdx=PruneTree.size(); + PruneTree.push_back(Idx); + if (Parent!=-1) + { + PruneParentIdx=SceneTree[Parent].PruneIdx; + SceneTree[Parent].PruneChildList.push_back(Idx); + } + else + { + PruneParentIdx=-1; + } + } + + TVECTOR GetWorldPos(TVECTOR &Pos);// {return(WorldMtx*Pos);} + TVECTOR GetWorldPos(float X,float Y,float Z) {return(GetWorldPos(TVECTOR (X,Y,Z)));} + TVECTOR GetWorldPos() {return(GetWorldPos(TVECTOR (XPos,YPos,ZPos)));} + + TQUAT GetWorldAng(TQUAT &Q);// {return(WorldMtx*Pos);} + TQUAT GetWorldAng(float X,float Y,float Z,float W) {return(GetWorldAng(TQUAT (X,Y,Z,W)));} + TQUAT GetWorldAng() {return(GetWorldAng(TQUAT (XAng,YAng,ZAng,WAng)));} + + int GetChildCount() {return(ChildList.size());} + int GetPruneChildCount() {return(PruneChildList.size());} + std::vector const &GetPts() const {return(Pts);} + std::vector const &GetRelPts() const {return(RelPts);} + std::vector const &GetTris() const {return(Tris);} + std::vector const &GetVColTris() const {return(VColTris);} + std::vector const &GetUVTris() const {return(UVTris);} + std::vector const &GetTriMaterial() const {return(TriMaterial);} + std::vector const &GetAnim() const {return(Anim);} + std::vector const &GetKeyAnim() const {return(KeyAnim);} + std::vector const &GetShrunkAnim() const {return(ShrunkAnim);} + std::vector const &GetShrunkKeyAnim() const {return(ShrunkKeyAnim);} + + char *GetName() {return(Name);} + + int Idx,ParentIdx; + int PruneIdx,PruneParentIdx; + char Name[32]; + + float XPos,YPos,ZPos; + float XAng,YAng,ZAng,WAng; + float Xapk,Yapk,Zapk; + float Xapu,Yapu,Zapu,Wapu; + int Active; + TMATRIX Mtx,WorldMtx; + CIni UserProp; + + std::vector ChildList; + std::vector PruneChildList; + std::vector Weights; + std::vector Pts; + std::vector RelPts; + std::vector Tris; + std::vector VColTris; + std::vector UVTris; + std::vector TriMaterial; + std::vector Anim; + std::vector KeyAnim; +// Shrunk Anim stuff + int StartFrame,EndFrame; + std::vector ShrunkAnim; + std::vector ShrunkKeyAnim; + + long Flags,Pad; + int TriggerCount,TriggerIdx; + int TriBase; +}; + +class CGinTree: public GinChunk +{ + virtual char const * GetName(void) const {return("TREE");} + virtual GinChunk * MakeNew(void) {return(new CGinTree);} + + virtual void Load(Gifstream & In); + void LoadTree(Gifstream & In,int Parent); + +public: + + std::vector const & GetTree(void) const{return(SceneTree);} + +protected: + std::vector SceneTree; + +}; + +/*****************************************************************************/ +/*** Skin Chunk **************************************************************/ +/*****************************************************************************/ +class CSkinTree: public GinChunk +{ + virtual char const * GetName(void) const {return("BONE");} + virtual GinChunk * MakeNew(void) {return(new CSkinTree);} + virtual void Load(Gifstream & In); + void LoadTree(Gifstream & In,int Parent); + +public: + std::vector const & GetTree(void) const{return(SkinTree);} + +protected: + std::vector SkinTree; +}; + +/*****************************************************************************/ +/*** Tree Anim Chunk *********************************************************/ +/*****************************************************************************/ + +class CAnimTree: public GinChunk +{ + virtual char const * GetName(void) const {return("ANIM");} + virtual GinChunk * MakeNew(void) {return(new CAnimTree);} + virtual void Load(Gifstream & In); + void LoadTree(Gifstream & In,int Parent,int FrameCount); + +public: + std::vector const & GetTree(void) const{return(AnimTree);} +// int GetFrameCount() {return(FrameCount);} + +protected: +// int FrameCount; + std::vector AnimTree; + +}; + +/*****************************************************************************/ +/*** Tree Key Anim Chunk *****************************************************/ +/*****************************************************************************/ + +class CKeyAnimTree: public GinChunk +{ + virtual char const * GetName(void) const {return("KEY4");} + virtual GinChunk * MakeNew(void) {return(new CKeyAnimTree);} + virtual void Load(Gifstream & In); + void LoadTree(Gifstream & In,int Parent); + +public: + std::vector const & GetTree(void) const{return(AnimTree);} + +protected: + std::vector AnimTree; + +}; + +/*****************************************************************************/ +/*** User Prop Chunk *********************************************************/ +/*****************************************************************************/ + +class CUserProp: public GinChunk +{ + virtual char const * GetName(void) const {return("PROP");} + virtual GinChunk * MakeNew(void) {return(new CUserProp);} + + virtual void Load(Gifstream & In) + { + ModNum = In.Get32()-1; + int Size = In.Get32(); + Prop.resize(Size+1); + for(int i=0; i const & GetUserProp() const {return(Prop);} + int GetModNum(void) const {return ModNum;} + +protected: + + int ModNum; + std::vector Prop; +}; + +/*****************************************************************************/ +/*** Camera Chunk ************************************************************/ +/*****************************************************************************/ +struct sCam +{ + std::vector CamPos; + std::vector Target; +} ; + +class CCamera: public GinChunk +{ + virtual char const * GetName(void) const {return("CAM4");} + virtual GinChunk * MakeNew(void) {return(new CCamera);} + virtual void Load(Gifstream & In) + { + int Frame,FrameCount = In.Get32(); + ThisCam.CamPos.resize(FrameCount); + ThisCam.Target.resize(FrameCount); + for (Frame = 0; Frame< FrameCount;Frame++) + { + float x,y,z; + In.read((char*)&x, 4); + In.read((char*)&y, 4); + In.read((char*)&z, 4); + ThisCam.CamPos[Frame] = TVECTOR(x,y,z); + } + for (Frame = 0; Frame< FrameCount;Frame++) + { + float x,y,z; + In.read((char*)&x, 4); + In.read((char*)&y, 4); + In.read((char*)&z, 4); + ThisCam.Target[Frame]= TVECTOR(x,y,z); + } + } + +public: + + sCam const & GetCam(void) const {return(ThisCam);} + +protected: + + sCam ThisCam; +}; + +/*****************************************************************************/ +/*** Gin Loader **************************************************************/ +/*****************************************************************************/ +class Gin4File : public GObject +{ +public: + Gin4File(void) + { + MyFile.AddHandler(new CTexName); + MyFile.AddHandler(new CVers); + MyFile.AddHandler(new CMesh); + MyFile.AddHandler(new CMod4); + MyFile.AddHandler(new CMat4); + MyFile.AddHandler(new CPts4); + MyFile.AddHandler(new CPoly); + MyFile.AddHandler(new CVcol); + MyFile.AddHandler(new CUVtri); + MyFile.AddHandler(new CGinTree); + MyFile.AddHandler(new CAnimTree); + MyFile.AddHandler(new CKeyAnimTree); + MyFile.AddHandler(new CSkinTree); + MyFile.AddHandler(new CUserProp); + MyFile.AddHandler(new CCamera); + } + + void Load(char const * Name); + + std::vector GetVersionChunk() {return(VersionChunk);} + std::vector GetTexNamesChunk() {return(TexNamesChunk);} + std::vector GetMatChunk() {return(MatChunk);} + std::vector GetMod4Chunk() {return(Mod4Chunk);} + std::vector GetMshChunk() {return(MshChunk);} + std::vector GetPointsChunk() {return(PointsChunk);} + std::vector GetTrisChunk() {return(TrisChunk);} + std::vector GetVColTrisChunk() {return(VColTrisChunk);} + std::vector GetUVtrisChunk() {return(UVtrisChunk);} + std::vector GetSceneTreeChunk() {return(SceneTreeChunk);} + std::vector GetAnimTreeChunk() {return(AnimTreeChunk);} + std::vector GetKeyAnimTreeChunk(){return(KeyAnimTreeChunk);} + std::vector GetSkinTreeChunk() {return(SkinTreeChunk);} + std::vector GetUserPropChunk() {return(UserPropChunk);} + std::vector GetCameraChunk() {return(CameraChunk);} + + char * GetModelName(int ModelNum) + { + CMod4 *Mod=(CMod4*)Mod4Chunk[ModelNum]; + return(Mod->GetModelName()); + }; + + +protected: + GinFile MyFile; + + std::vector VersionChunk; + std::vector TexNamesChunk; + std::vector MatChunk; + std::vector Mod4Chunk; + std::vector MshChunk; + std::vector PointsChunk; + std::vector TrisChunk; + std::vector VColTrisChunk; + std::vector UVtrisChunk; + std::vector SceneTreeChunk; + std::vector AnimTreeChunk; + std::vector KeyAnimTreeChunk; + std::vector SkinTreeChunk; + std::vector UserPropChunk; + std::vector CameraChunk; + +}; + +/*****************************************************************************/ +/*** Scene Storage ***********************************************************/ +/*****************************************************************************/ + +class CScene +{ +public: + + void LoadWithTextures(char const * Name); + void Load(char const * Name); + +//------------------ +//--- Tree Stuff --- +//------------------ + + CNode &GetNode(int Idx) {return(SceneTree[Idx]);} + CNode *GetNodePtr(int Idx) {return(&GetNode(Idx));} + CNode *GetNodePtr(char *Name,int Start=0) + { + int TreeSize=GetSceneTreeSize(); + for (int N=Start; N const & GetTexNames(void) const {return(AllTexNames);} + std::vector const & GetTexList(void) const {return(TextureList);} + std::vector const & GetMaterials(void) const {return(AllMaterials);} + std::vector const & GetUsedMaterialIdx(void) const {return(UsedMaterials);} + std::vector const & GetCamera(void) const {return(Camera);} + void GetNonSharedTextures(std::vector const & SharedTextures,std::vector & Dest); + +protected: + int loadPoints(int CurMod, std::vector &Points,CNode *ThisNode); + int loadTris(int CurMod, int CurMesh, std::vector &Tris,CNode *ThisNode); + int loadUV(int CurMod, int CurMesh, std::vector &UVTris,CNode *ThisNode); + int loadVCol(int CurMod, int CurMesh, std::vector &VColTris,CNode *ThisNode); + int addMaterialIdx( int idx ); + + int _CountAllChildren(int Idx) + { + CNode &ThisNode=GetNode(Idx); + int NodeCount=0; + int ChildCount= ThisNode.GetPruneChildCount(); + for (int Loop=0;Loop AllTexNames; + std::vector TextureList; + std::vector AllMaterials; + std::vector UsedMaterials; + + std::vector SceneTree; + std::vector PruneTree; + std::vector Camera; + int CurTree; + + int PrintTreeSpace; + +}; + +/*****************************************************************************/ +TMATRIX GetWorldMatrix(std::vector const &Tree,int Idx); +TVECTOR GetWorldPos(std::vector const &Tree,int Idx); +TVECTOR GetWorldPos(TMATRIX &WorldMtx,TVECTOR &ThisPos); + +#endif + diff --git a/Utils/Libs/GinLib/mapread.cpp b/Utils/Libs/GinLib/mapread.cpp new file mode 100644 index 000000000..7724e4868 --- /dev/null +++ b/Utils/Libs/GinLib/mapread.cpp @@ -0,0 +1,533 @@ +/*========================================================================= + + EXPORT.CPP + + Author: + Created: + Project: + Purpose: + + Copyright (c) 1998 Climax Development Ltd + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +#include "mapread.h" + + +/* Glib + ---- */ +#include + +/* Local + ----- */ + +/* Graphics + -------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +#define TILE_SHIFT 8 + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Positional Vars + --------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +int CMapFile::GetVersion( char * version ) +{ + int ret = 0; + int len; + char whole[8]; + char frac[8]; + + len = strlen(version); + if (len) + { + int pos = 0; + int opos = 0; + + while (version[pos] != '.') + { + whole[pos] = version[pos]; + pos++; + if (pos > len) + GObject::Error(ERR_FATAL,"Corrupt Version - %s\n", version); + } + + pos++; + while (version[pos]) + { + frac[opos] = version[pos]; + pos++; + opos++; + if (pos > len) + GObject::Error(ERR_FATAL,"Corrupt Version - %s\n", version); + } + } + + ret = atoi( whole ); + ret *= 100; + ret += atoi( frac ); + + GObject::Error(ERR_WARNING, "Map Version %d\n", ret ); + + return ret; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +int CMapFile::FindFrame( const char * frame ) +{ + char InFile[_MAX_FNAME]; + char CompFile[_MAX_FNAME]; + + _splitpath( frame, NULL, NULL, InFile, NULL ); + + for (int f=0;f sizeof(MapCTile)) GObject::Error(ERR_FATAL, "MapCTile STRUCT MISMATCH" ); + Tiles = (TILE_PACKET *)malloc( (MapWidth * MapHeight * sizeof( TILE_PACKET )) ); + + if (!Tiles) + GObject::Error(ERR_FATAL, "can't allocate tiles" ); + + + t = Tiles; + nbSpawnPoints=0; + lowestY = 65536; + for (y=0;yframe = tile.frame; + t->r = (u8)(tile.r * 255.f); + t->g = (u8)(tile.g * 255.f); + t->b = (u8)(tile.b * 255.f); + t->pad = 0; + + if (tile.flag&TF_SPAWN) + { + if (nbSpawnPoints>=MAX_SPAWNING_TILES) + { + GObject::Error(ERR_FATAL, "Max Spawning Positions exceeded for level" ); + } + Spawn[nbSpawnPoints].x = x; + Spawn[nbSpawnPoints].y = y; + nbSpawnPoints++; + + } + + t->angle = angle; + t->flags = (int)(tile.flag&(~TF_SPAWN)); + t->height = (int)tile.py; + t->frame = frame; + t->xflip = tile.xflip; + t->yflip = tile.yflip; + t->type = tile.type; + +// if (t->flags & TF_NO_BUILD) +// GObject::Error(ERR_WARNING, "No build flag found\n" ); + + if (frame < 0) t->flags |= TF_HIDDEN; + + if (!(tile.flag & TF_HIDDEN) && (x < MapWidth-1) && (y < MapHeight-1)) + { + if (lowestY > tile.py) lowestY = tile.py; + } + + t++; + } + } + + GObject::Error( ERR_WARNING, "Lowest land height = %f\n", lowestY ); + + t = Tiles; + for (y=0;yheight -= (int)lowestY; + if (t->height < 0) t->height = 0; + +// if (t->height > sizeof(u16)) +// { +// GObject::Error( ERR_FATAL, "Land height overflow - %d\n", t->height ); +// } + + t++; + } + } + + + // READ OBJECT LIST + + MapFile.Read( &nbModels ); + MapFile.Read( &ModelSize ); + if (ModelSize > sizeof(CModel)) GObject::Error(ERR_FATAL, "Struct mismatch in CModel" ); + + Models = (MODEL_PACKET *)malloc( nbModels * sizeof(MODEL_PACKET) ); + + if (!Models) + GObject::Error(ERR_FATAL, "Can't allocate models\n" ); + + + MODEL_PACKET * m = Models; + for (i=0;iAnimAndFlags = animflag; + m->xp = (u16)(model.PosX / (1 << TILE_SHIFT)); + m->yp = (u16)(model.PosY - lowestY); + m->zp = (u16)(model.PosZ / (1 << TILE_SHIFT)); + m->ya = (u16)angle; + +// if (m->yp > sizeof(u16)) +// { +// GObject::Error( ERR_FATAL, "Object Y position overflow - %d\n", m->yp ); +// } + + m++; + } +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +int CMapFile::FindFileEquate( char * name ) +{ + strupr( name ); + + for (int i=0;i SourcePal; + vector DestPal; + + SourcePal.resize(MapWidth*MapHeight*3); + TileToPalNum.resize(MapWidth*MapHeight); + DestPal.resize(NUM_OF_PAL_ENTRIES*3); + MapPal.resize(NUM_OF_PAL_ENTRIES); + + for (int f=0;fmType = 0; + + if (T->height<0) + { + O->ypos = 0; +// printf("low height %d\n", T->height); + } else + if (T->height>255*4.f) + { + O->ypos = 255; +// printf("hi height %d\n", T->height); + } else + { + O->ypos = (T->height/4.f); + } + + + O->mNeighbours = 0; + O->mDirection = 0; + + if (T->frame > 4095) GObject::Error(ERR_FATAL, "Tile index overflow" ); + + O->mTileIndex = T->frame; + O->mTileIndex |= (T->angle << 12); // STUFF ANGLE IN TOP BITS OF TILE INDEX + O->ColIdx = GetPalNum( x, y ); + O->mFlags = T->flags; + + if (T->xflip) O->mTileIndex |= (1 << 15); // SET X/Y FLIP IN TOP BITS OF TILE INDEX + if (T->yflip) O->mTileIndex |= (1 << 14); + + switch(T->type) + { + case TT_VOID: + O->mType = (u8)CELL_Void; + break; + case TT_PATH: + O->mType = (u8)CELL_Path; + break; + } +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +void CMapFile::Export( const char * file ) +{ + FILE * level; + + MakeMapPalette(); + + level = fopen( file, "wb" ); + if (level) + { + WriteMapPalette( level ); + + fwrite( &MapWidth, sizeof( int ), 1, level ); + fwrite( &MapHeight, sizeof( int ), 1, level ); + + for (int y=0;y +#include + + +/* Glib + ---- */ +#include +#include +#include + +/* Local + ----- */ +#include "repread.h" +#include "animheader.h" + + +/*---------------------------------------------------------------------- +Tyepdefs && Defines + ------------------- */ + +#define MAX_MASKX 8 +#define MAX_MASKY 8 + +#define MAX_LINES 512 + +enum CELL_MODES +{ + CELL_Void =(0), + + CELL_Hidden =(1), + + CELL_Path =(2), + CELL_Water =(3), + CELL_Queue =(4), + CELL_Thing =(5), +// CELL_TrackRide =(6), + CELL_NoGo =(7), + CELL_Entrance =(8), + CELL_Exit =(9), + CELL_QueueEdit =(10), + CELL_CoasterPylon =(11), + +// actions + + CELL_Delete =(50), + CELL_DeleteLine =(51), + + CELL_PatrolArea =(52), + CELL_BacktrackVoid =(53), + +// special modes + +// CM_SpecialMode =(128), // yes, these 2 are supposed to be the same + CM_CalcNeighbours =(128), + CM_CalcTile =(129), + CM_CalcDirections =(130), + CM_SetParent =(131), + CM_CreateBridges =(132), + CM_CreateBridgeSpans =(133), + + CM_ShowTransparent =(256), + + CM_NoModify =(512), +}; + + +enum MAP_TILE_FLAGS +{ + TF_NONE = (0<<0), + TF_HIDDEN = (1<<0), + TF_NO_BUILD = (1<<1), + TF_SPAWN = (1<<2), + TF_ENTRANCE = (1<<3), + TF_TRACKRIDE = (1<<4), + TF_NO_WALK = (1<<5), +}; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +enum +{ + MAP_MAX_FILE_NAME_LENGTH = 512, +}; + +enum TILE_TYPE +{ + TT_VOID = 0, + TT_PATH = 1, +}; + +struct CFileName +{ + bool Stripped; + char Name[MAP_MAX_FILE_NAME_LENGTH]; + char FullName[MAP_MAX_FILE_NAME_LENGTH]; +}; + +struct TILE_PACKET +{ + u8 r, g, b, pad; + int height; + int flags; + int frame; + int angle; + int xflip; + int yflip; + int type; +}; + +#pragma pack(1) +struct OUT_TILE_PACKET // *** TS - Must be reflected in Tile.h - CTile *** +{ + u8 mType; // 1 + + u8 ypos; // 1 + u8 mNeighbours; // 1 + u8 mDirection; // 1 - 4 + + u16 mTileIndex; // 2 + u8 ColIdx; // 1 + u8 mFlags; // 1 - 4 +}; +#pragma pack() + +/* CELL_MODES mType; // 4 make a u8 saves 3 + + s16 Height; // Make a u8 saves 1 + u8 mNeighbours; // Take out saves 1 + u8 mDirection; // 2 bits, put in flags saves 1 + + u16 mTileIndex; // 2 - Also contains frame angle + + u8 ColIdx; // 1 + u8 mFlags; // 1 + + u8 heightoffset; // 1 Take out saves 1 + s8 mOverlapCounter; // 1 Take out saves 1 + u16 FogTblIndex; // 2 Put into frame structure saves 2*/ + + + +enum MODEL_FLAGS +{ + MODEL_ANIMATE_FLAG = (1 << 24), + MODEL_BUSSTOP_FLAG = (1 << 25), + MODEL_BOOTH_FLAG = (1 << 26), + MODEL_ENTRANCE_FLAG = (1 << 27), + MODEL_OTHERANIM_FLAG = (1 << 28), + MODEL_FLAGS_MASK = (0xff << 24), +}; + +struct MODEL_PACKET +{ + u32 AnimAndFlags; + u16 xp, yp, zp, ya; +}; + + +struct MapCTile +{ + float r,g,b; + u16 type; + u16 neighbours; + u8 object; + u8 flag; + float px,py,pz; + float nx,ny,nz; + u32 frame; + char FrameName[128]; + int PSXFrame; + + int angle; + float u0; + float v0; + float u1; + float v1; + float u2; + float v2; + float u3; + float v3; + +// *** NOTE: PLEASE ADD NEW VARIABLES HERE *** + + float ambientr, ambientg, ambientb; + + bool xflip; + bool yflip; +}; + +struct SPAWNPOS +{ + u8 x, y; +}; + +struct CObject +{ + CFileName Name; + int Width; + int Height; + int Depth; + bool Mask[MAX_MASKX][MAX_MASKY]; +}; + +struct CModel +{ + float PosX; + float PosY; + float PosZ; + float AngX; + float AngY; + float AngZ; + + char MeshName[512]; + u32 Mesh; +// MeshFile * Mesh; + + bool Highlight; + +// *** NOTE: PLEASE ADD NEW VARIABLES HERE AND CHANGE THE VERSION NO. *** + + bool Snap; + bool ShowAxis; + + bool m_Animates; + bool m_Busstop; + bool m_Booth; + bool m_Entrance; + bool m_OtherAnim; +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Class + ----- */ + +/*------------------------------------------*/ +/* */ +/*------------------------------------------*/ + +class CChunkFile +{ +public: + CChunkFile() + { + } + + ~CChunkFile() + { + } + + void Open( const char * file) + { + int fileSize; + fileSize=FileSize(file); + + if (fileSize < 0) + GObject::Error(ERR_FATAL,"Error finding size of file %s",file); + + Buffer=new u8[fileSize]; + + if (!Buffer) + GObject::Error(ERR_FATAL,"can't alloc mem"); + + std::ifstream inFile; + + inFile.open(file,std::ios::binary); + + if (inFile) + { + inFile.read((char*)(Buffer),fileSize); + inFile.close(); + } + else + GObject::Error(ERR_FATAL,"Error opening %s",file); + } + + + void Seek( int l = 0 ) { Ptr = &Buffer[l]; } + void Close() { free( Buffer ); } + + void Skip( int s ) { Ptr += s; } + + void Read( int * ptr ) + { + *ptr = *((int *)Ptr); + Ptr += 4; + } + + void Read( void * ptr, int len ) + { + for (int i=0;i & textures) + { + m_errorOnMissingFile=false; + + MapFile.Open( mapFile ); + + Objects = NULL; + Tiles = NULL; + TileNames = NULL; + Models = NULL; + + Parse(); + + for (int f=0;f MapPal; + std::vector TileToPalNum; + + const char * AnimHeaderFile; + + std::vector RepItems; + std::vector AnimItems; + + + enum + { + NUM_OF_PAL_ENTRIES = 64, + MAX_SPAWNING_TILES = 2, + }; + + + void MakeAnimName( char * out, char * in ); + + + CChunkFile MapFile; + + u8 VersionText[4]; + int nbTiles; + CFileName * TileNames; + + int nbObjects; + CObject * Objects; + + int MapWidth; + int MapHeight; + int TileSize; + TILE_PACKET * Tiles; + + int nbModels; + int ModelSize; + MODEL_PACKET * Models; + + int nbSpawnPoints; + SPAWNPOS Spawn[MAX_SPAWNING_TILES]; + + bool m_errorOnMissingFile; +}; + + + +/* Functions + --------- */ + + + + +/*---------------------------------------------------------------------- */ + +#endif /* __EXPORT_H__ */ + +/*=========================================================================== + end */ diff --git a/Utils/Libs/GinLib/pak.cpp b/Utils/Libs/GinLib/pak.cpp new file mode 100644 index 000000000..7df476799 --- /dev/null +++ b/Utils/Libs/GinLib/pak.cpp @@ -0,0 +1,320 @@ +/*========================================================================= + + PAK.CPP + + Author: Gary Liddon @ Climax (from work by Nick Pelling && Carl Muller) + Created: + Project: Diablo PSX + Purpose: PAK decompress \ compress code + + Copyright (c) 1997 Climax Development Ltd + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* Glib + ---- */ + +/* Local + ----- */ +#include +#include "pak.h" + +/* Graphics + -------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ +#define UNPAKBUFFERSIZE 4096 +#define STRMAX 80 +#define BUFFERSIZE 30000 +#define TRIGGER 20000 +#define MAXUNIQUE 127 + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +struct Block +{ + int data[128]; + BOOL blockrep; + int blocksize; + int blockoffset; + + u8 * Dest; + int outsize; + + virtual void fputc(u8 Val) + { + *Dest=Val; + Dest++; + outsize++; + } + + void writeBlock(void); +}; + +struct CountBlock : Block +{ + virtual void fputc(u8 Val) + { + Dest++; + outsize++; + } +}; + +/*---------------------------------------------------------------------- + Positional Vars + --------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ +static void writeblock(struct block *theblock); + +/*---------------------------------------------------------------------- + Vars + ---- */ +/*---------------------------------------------------------------------- + Data + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void Block::writeBlock(void) +{ + if ((blockrep) && (blocksize == 0)) + { + /* Terminator */ + fputc(128); + fputc(0); + } + else if (blockrep) + { + fputc(blockoffset); + fputc(blocksize); + } + else /* Unique bytes */ + { + fputc(blocksize & 127); + + for (int i = 0; i <= blocksize; i++) + fputc(data[i]); + } + + // Get ready for next block + blockrep = FALSE; + blockoffset = 0; + blocksize = -1; +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int lowLevelPak(u8 * Dest,u8 const * buffer,int insize,Block & theblock) +{ + long begin, end, bestlength; + int offset, bestoffset; + unsigned char const * theptr; + unsigned char const * ptr1; + unsigned char const * ptr2; + unsigned char const * ptr3; + long BACKDIST, FORWARDDIST, MINBLOCK; + + theblock.Dest=Dest; + theblock.outsize=0; + theblock.blockrep=FALSE; + + BACKDIST = -128; + FORWARDDIST = 255; + MINBLOCK = 3; + + int inpos = 0; + + theblock.blocksize = -1; + theblock.data[++theblock.blocksize] = buffer[inpos++]; + theblock.data[++theblock.blocksize] = buffer[inpos++]; + + while (inpos < insize) + { + /* See if we should load new data into the buffer */ + + begin = -inpos; + end = insize - inpos; + + if (begin < BACKDIST) + begin = BACKDIST; + + if (end > FORWARDDIST) + end = FORWARDDIST; + + bestoffset = begin; + bestlength = 1; + theptr = buffer + (inpos); + + ptr1 = buffer + (inpos + begin); + + for (offset = begin; offset < 0; offset++) + { + if (*ptr1 == *theptr) + { + if (memcmp(ptr1, theptr, bestlength + 1) == 0) + { + bestlength++; + bestoffset = offset; + ptr2 = ptr1 + bestlength; + ptr3 = theptr + bestlength; + + while (*ptr2 == *ptr3) + { + ptr2++; + ptr3++; + bestlength++; + if (bestlength >= end) + break; + } + } + } + + if (bestlength >= end) + { + bestlength = end; + break; + } + + ptr1++; + } + + + if (bestlength < MINBLOCK) + { + /* See if last block is unique */ + + if (theblock.blockrep) /* Flush previous special block */ + { + theblock.writeBlock(); + theblock.data[++theblock.blocksize] = buffer[inpos++]; + } + else + { + /* Add to it */ + + if (theblock.blocksize >= MAXUNIQUE) + theblock.writeBlock(); + + theblock.data[++theblock.blocksize] = buffer[inpos++]; + } + } + else + { + /* We have found a match */ + theblock.writeBlock(); + theblock.blockrep = TRUE; + theblock.blocksize = bestlength; + theblock.blockoffset = bestoffset; + inpos += bestlength; + } + } + + /* Flush buffer */ + + theblock.writeBlock(); + + /* Terminate file */ + + theblock.blockrep = TRUE; + theblock.blocksize = 0; + theblock.blockoffset = 0; + theblock.writeBlock(); + + return(theblock.outsize); +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int PAK_doPak(u8 * Dest,u8 const * buffer,int insize) +{ + Block outBlock; + return(lowLevelPak(Dest,buffer,insize,outBlock)); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int PAK_findPakSize(u8 const * buffer,int insize) +{ + CountBlock outBlock; + return(lowLevelPak(NULL,buffer,insize,outBlock)); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int PAK_doUnpak(u8 * Dest,u8 const * Source) +{ + int outsize = 0; + + while (1) /* ie, continue until end mark */ + { + u8 const * From; + + int size; + int ch; + + ch = *Source++; + + if (ch < 128) /* if it is in range {0..127} then */ + { + size = (ch + 1); + From=Source; + Source+=size; + } + else + { + size = *Source++; + + if (size == 0) /* distance == 0 => end of file */ + break; + + From=Dest+(s8)ch; + } + + memcpy(Dest,From,size); + Dest+=size; + outsize += size; + } + + return(outsize); +} + +/*=========================================================================== + end */ + + + + diff --git a/Utils/Libs/GinLib/pak.h b/Utils/Libs/GinLib/pak.h new file mode 100644 index 000000000..a9f805509 --- /dev/null +++ b/Utils/Libs/GinLib/pak.h @@ -0,0 +1,60 @@ +/*========================================================================= + + PAK.H + + Author: Carl Muller (algorithm Nick Pelling && Carl Muller) + Created: + Project: + Purpose: + + Copyright (c) 1997 Climax Development Ltd + +===========================================================================*/ + +#ifndef __PAK_PAK_H__ +#define __PAK_PAK_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* Glib + ---- */ +#include + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ +int PAK_doPak(u8 * Dest,u8 const * source,int insize); +int PAK_doUnpak(u8 * Dest,u8 const * Source); +int PAK_findPakSize(u8 const * souce,int insize); + +/*---------------------------------------------------------------------- */ + +#endif /* __PAK_PAK_H__ */ + +/*=========================================================================== + end */ diff --git a/Utils/Libs/GinLib/repread.cpp b/Utils/Libs/GinLib/repread.cpp new file mode 100644 index 000000000..8a82e8a2f --- /dev/null +++ b/Utils/Libs/GinLib/repread.cpp @@ -0,0 +1,251 @@ +/*========================================================================= + + FILENAME.CPP + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#include + +/* Glib + ---- */ +#include +#include +#include +/* Local + ----- */ +#include "repread.h" + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ +using namespace std; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ +static int GetHex(char const * Str); + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int GetHex(char const * Str) +{ + char Buffer[1024]; + strcpy(Buffer,Str); + + strstream i(Buffer,1024); + + int Val; + + i>>hex>>Val; + return(Val); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void readRepFile(char const * Name,std::vector & Items) +{ + char Line[1024]; + + try + { + ifstream InStream; + + InStream.open(Name,ios::in); + + if (InStream) + { + int frameNumber; + + frameNumber=0; + + + InStream.getline(Line,1024); + + pcre * MyPattern; + int Matches; + const int NumOfOffsets=60; + int Offsets[NumOfOffsets]; + char const * ErrTxt; + int ErrNum; + + MyPattern=pcre_compile("(\\S+)\\s+\\$(\\S+)\\s+\\$(\\S+)\\s+\\$(\\S+)\\s+\\$(\\S+)\\s+\\$(\\S+)\\s+\\$(\\S+)\\s+(\\d+)",0,&ErrTxt,&ErrNum,NULL); + + while (!InStream.eof()) + { + + char SwitchText[100]; + + InStream.getline(Line,1024); + + if (strlen(Line)) + { + Matches=pcre_exec(MyPattern,NULL,Line,strlen(Line),0,Offsets,NumOfOffsets); + + if (Matches != 9) + throw("error parsing rep file"); + + int Tpage,Clut,u,v,w,h; + bool Rotated; + + Tpage=GetHex(&Line[Offsets[4]]); + Clut=GetHex(&Line[Offsets[6]]); + u=GetHex(&Line[Offsets[8]]); + v=GetHex(&Line[Offsets[10]]); + w=GetHex(&Line[Offsets[12]]); + h=GetHex(&Line[Offsets[14]]); + Rotated=atoi(&Line[Offsets[16]]) != 0; + + + memcpy(SwitchText,&Line[Offsets[2]],Offsets[3]-Offsets[2]); + SwitchText[Offsets[3]-Offsets[2]]=0; + + RepItem MyItem; + + MyItem.m_texName=SwitchText; + MyItem.m_texName.Lower(); + + MyItem.m_tpage=Tpage; + MyItem.m_clut=Clut; + MyItem.m_u=u; + MyItem.m_v=v; + MyItem.m_w=w; + MyItem.m_h=h; + MyItem.m_rotated=Rotated; + MyItem.m_frameNumber=frameNumber; + + Items.push_back(MyItem); + + frameNumber++; + } + + } + InStream.close(); + } + else + throw("Error opening report file"); + } + + catch (char const * E) + { + GObject::Error(ERR_FATAL,"Error in AddToTexList : %s",E); + } + +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void RepFile::load(char const * name) +{ + vector items; + + readRepFile(name,items); + + int numOfItems; + + numOfItems=items.size(); + + for (int f=0;f::iterator it; + + srchStr=str; + + makeTexNameCompliant(srchStr); + + it=m_strToInfo.find(srchStr); + + if (it == m_strToInfo.end()) + return(false); + else + { + result=m_strToInfo[srchStr]; + return(true); + } +} + +/*=========================================================================== + end */ + + diff --git a/Utils/Libs/GinLib/repread.h b/Utils/Libs/GinLib/repread.h new file mode 100644 index 000000000..6be988fcf --- /dev/null +++ b/Utils/Libs/GinLib/repread.h @@ -0,0 +1,98 @@ +/*========================================================================= + + FILENAME.CPP + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +#pragma warning( disable : 4786 ) + +#ifndef __REPREAD_H__ +#define __REPREAD_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#include +#include + +/* Glib + ---- */ +#include +#include + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +struct RepItem +{ + GString m_texName; + u16 m_tpage; + u16 m_clut; + u8 m_u,m_v,m_w,m_h; + bool m_rotated; + int m_frameNumber; +}; + +class RepFile +{ + +private: + GString m_lastLoadedFile; + std::map m_strToInfo; + + virtual void makeTexNameCompliant(GString & str); + +public: + void load(char const * name); + bool find(GString const & str,RepItem & result); + + + char const * getLastFileLoaded(void) + {return(m_lastLoadedFile);} +}; + +class RepFileNoDir : public RepFile +{ +private: + virtual void makeTexNameCompliant(GString & str); + +}; + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ +void readRepFile(char const * Name,std::vector & Items); + +/*---------------------------------------------------------------------- */ + +#endif /* __REPREAD_H__ */ + +/*=========================================================================== + end */ + diff --git a/Utils/Libs/GinLib/script.cpp b/Utils/Libs/GinLib/script.cpp new file mode 100644 index 000000000..85f828e59 --- /dev/null +++ b/Utils/Libs/GinLib/script.cpp @@ -0,0 +1,337 @@ +/*========================================================================= + + FILENAME.CPP + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "script.h" + +/* Std Lib + ------- */ + +/* Glib + ---- */ + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ +using namespace std; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +const int DEFAULT_LINE_LENGTH=8192; + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +ScriptFile::ScriptFile(void) +{ + m_isOpen=false; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +ScriptFile::~ScriptFile(void) +{ + close(); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void ScriptFile::close(void) +{ + if (m_isOpen) + m_inStream.close(); + + m_isOpen=false; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void ScriptFile::open(char const * fileName) +{ + if (m_isOpen) + close(); + + m_inStream.open(fileName,ios::binary|ios::in); + + if (m_inStream) + { + m_fileName=fileName; + + } + else + GObject::Error(ERR_FATAL,"unable to open script file %s",fileName); + + m_isOpen=true; + m_lineCount=0; +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void ScriptFile::scriptError(void) +{ + GObject::Error(ERR_FATAL,"Ill formatted script file %s, line %d",(char const *)m_fileName,m_lineCount); +} + + +/*---------------------------------------------------------------------- + Function: ak + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void ScriptFile::checkIsOpen(void) +{ + if (!m_isOpen) + GObject::Error(ERR_FATAL,"file operation needed by ScriptFile but no file is open"); +} +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +bool ScriptFile::getNextNonBlankLine(char * line,int lineLen) +{ + checkIsOpen(); + + do + { + if (m_inStream.eof()) + return(false); + + m_inStream.getline(line,lineLen); + + + int lineLength; + + lineLength=strlen(line); + + for (int f=0;f + +/* Glib + ---- */ +#include + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +class ScriptFile +{ +private: + std::ifstream m_inStream; + bool m_isOpen; + GString m_fileName; + int m_lineCount; + + void scriptError(void); + + bool getNextNonBlankLine(char * Line,int LineLen); + + void stripTrailingSpace(char * Line); + GString getCommandString(char * Com); + bool isCommand(char * Line); + void checkIsOpen(void); + +protected: + bool eof(void); + GString peekNextCommand(void); + bool nextLineIsCommand(void); + GString getNextLine(void); + + void open(char const * fileName); + void close(void); + int getLineCount(void) + {return(m_lineCount);} + + + +public: + + + ScriptFile(void); + ~ScriptFile(void); +}; + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ + + + +/*---------------------------------------------------------------------- */ + +#endif /* __SCRIPT_H__ */ + +/*=========================================================================== + end */ + diff --git a/Utils/Libs/TexGrab/AllFiles.cpp b/Utils/Libs/TexGrab/AllFiles.cpp new file mode 100644 index 000000000..eb6914d20 --- /dev/null +++ b/Utils/Libs/TexGrab/AllFiles.cpp @@ -0,0 +1,203 @@ +/*========================================================================= + + AllFiles.CPP + + Author: Gary + Created: 011200 + Project: SpongeBob + Purpose: File cycler stuff + +===========================================================================*/ + + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "sprset.h" + +#include "AllFiles.h" + +/*---------------------------------------------------------------------- + Function: void AllFiles::AddFile(const char * Name) + Purpose: Add a file to the list, it takes all the current + properties that the AllFiles object has. + Params: Name of file to add + ---------------------------------------------------------------------- */ +void AllFiles::AddFile(const char * Name) +{ + DoCycle(Name,RecurseFiles); +} + +/*---------------------------------------------------------------------- + Function: void AllFiles::FileCallback(char const * FName,int FileNum) + ---------------------------------------------------------------------- */ +#include +#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; + + CScene MyFile; + MyFile.Load(FName); + + MyFile.GetNonSharedTextures(AllExternalSharedTextures,NonSharedTextures); + + + vector NewEntrys; + + for (int f=0;f MyItems; + + ::readRepFile(Name,MyItems); + + for (int f=0;f +//#include +//#include +//#include +//#include +//#include + +//#include +//#include + +//#include "sprset.h" + +using namespace std; + +/*---------------------------------------------------------------------- + AllFiles Class + 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);} + + FIVec const & GetFileInfoVector(void) const {return(AllFileInfos);} + + void setAllocateAs16Bit(bool newVal) {m_allocateAs16bit=newVal;} + void setNoSort(void) {m_noSort=true;} + + void SortOrder(); + void AddFile(const char * Name); + void AddMemFrame(char const * FName,Frame &Frame); + void ReadRepFile(char const * Name); + + +protected: + vector 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; +}; + + +#endif /* _ */ + +/*=========================================================================== + end */ diff --git a/Utils/Libs/TexGrab/TexGrab.cpp b/Utils/Libs/TexGrab/TexGrab.cpp new file mode 100644 index 000000000..bc753db80 --- /dev/null +++ b/Utils/Libs/TexGrab/TexGrab.cpp @@ -0,0 +1,134 @@ +/*========================================================================= + + TexGrab.CPP + + Author: Dave @ Fareham (based on work by Gary Liddon) + Created: 011200 + Project: SpongeBob + Purpose: Main file for the new TexGrab lib, based on ParkGrab + +===========================================================================*/ + + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "TexGrab.h" + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +CTexGrab::CTexGrab() +{ + m_PagePlacements=false; + m_compressTpages=false; + m_noWriteTpages=false; + m_useHalfTpage=false; + m_AnimatedHeadersOnly=false; + m_DontOutputBoxes=false; + m_AlignHeaders=false; + +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +CTexGrab::~CTexGrab() +{ +} + + /*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CTexGrab::Process() +{ +SprSet MySprSet; + + MySprSet.setHalfTpage(m_useHalfTpage); + MySprSet.setAnimatedHeader(m_AnimatedHeadersOnly); + MySprSet.setDontOutputBoxes(m_DontOutputBoxes); + MySprSet.setAlignHeaders(m_AlignHeaders); + MySprSet.setCompressTpages(m_compressTpages); + MySprSet.setNoWriteTpages(m_noWriteTpages); + + MyFiles.SortOrder(); + + if (MyFiles.GetMaxSize()) + MySprSet.SetMaxSize(MyFiles.GetMaxSize()); + + MySprSet.AddFiles(MyFiles.GetFileInfoVector()); + + if (m_IncOutFile) + MySprSet.SetIncOutFile(m_IncOutFile); + + if (m_SprFile) + MySprSet.WriteSprFile(m_SprFile); + + if (m_OutFile) + { + if (m_PagePlacements) + { + MySprSet.Write(m_OutFile,m_PageBase,m_WidthPages,m_HeightPages); + + if (m_OutLbm) + MySprSet.WriteLBM(m_OutLbm); + + if (m_ReportFile) + MySprSet.WriteReport(m_ReportFile); + + if (m_rawTpageFile) + MySprSet.writeRawTPage(m_rawTpageFile); + + } + else + GObject::Error(ERR_FATAL,"-t option hasn't been specified"); + } +} + +/*---------------------------------------------------------------------- + Function: void CTexGrab::AddFile(char *Name) + Purpose: Add bitmaps to file list + Params: Name = Filename + ---------------------------------------------------------------------- */ +void CTexGrab::AddFile(char *Name) +{ +GString UpperName(Name); + + UpperName.Upper(); + + MyFiles.AddFile(UpperName); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + ---------------------------------------------------------------------- */ + +/* + +/*=========================================================================== + end */ diff --git a/Utils/Libs/TexGrab/TexGrab.dsp b/Utils/Libs/TexGrab/TexGrab.dsp new file mode 100644 index 000000000..b3bf98a4f --- /dev/null +++ b/Utils/Libs/TexGrab/TexGrab.dsp @@ -0,0 +1,169 @@ +# Microsoft Developer Studio Project File - Name="TexGrab" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=TexGrab - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "TexGrab.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "TexGrab.mak" CFG="TexGrab - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "TexGrab - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "TexGrab - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "TexGrab - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "..\GinLib" /I "..\glib\include" /I "..\glib\include\pc" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "TexGrab - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\GinLib" /I "..\glib\include" /I "..\glib\include\pc" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "TexGrab - Win32 Release" +# Name "TexGrab - Win32 Debug" +# Begin Source File + +SOURCE=.\AllFiles.cpp +# End Source File +# Begin Source File + +SOURCE=.\AllFiles.h +# End Source File +# Begin Source File + +SOURCE=.\bmploader.cpp +# End Source File +# Begin Source File + +SOURCE=.\bmploader.h +# End Source File +# Begin Source File + +SOURCE=.\cross.cpp +# End Source File +# Begin Source File + +SOURCE=.\cross.h +# End Source File +# Begin Source File + +SOURCE=.\grect.cpp +# End Source File +# Begin Source File + +SOURCE=.\grect.h +# End Source File +# Begin Source File + +SOURCE=.\main.cpp + +!IF "$(CFG)" == "TexGrab - Win32 Release" + +!ELSEIF "$(CFG)" == "TexGrab - Win32 Debug" + +# PROP Exclude_From_Build 1 + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\pak.cpp +# End Source File +# Begin Source File + +SOURCE=.\pak.h +# End Source File +# Begin Source File + +SOURCE=.\sprset.cpp +# End Source File +# Begin Source File + +SOURCE=.\sprset.h +# End Source File +# Begin Source File + +SOURCE=.\TexGrab.cpp +# End Source File +# Begin Source File + +SOURCE=.\TexGrab.h +# End Source File +# Begin Source File + +SOURCE=.\tpage.cpp +# End Source File +# Begin Source File + +SOURCE=.\tpage.h +# End Source File +# Begin Source File + +SOURCE=.\VImage.cpp +# End Source File +# Begin Source File + +SOURCE=.\vimage.h +# End Source File +# End Target +# End Project diff --git a/Utils/Libs/TexGrab/TexGrab.h b/Utils/Libs/TexGrab/TexGrab.h new file mode 100644 index 000000000..dc7dfc653 --- /dev/null +++ b/Utils/Libs/TexGrab/TexGrab.h @@ -0,0 +1,120 @@ +/*========================================================================= + + TexGrab.h + + Author: Dave + Created: 011200 + Project: Spongebob + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ + +#ifndef __TEXGRAB_LIB_H__ +#define __TEXGRAB_LIB_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "sprset.h" +#include "allfiles.h" + +using namespace std; + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Class defintions + ---------------- */ + +class CTexGrab +{ +public: + CTexGrab(); + ~CTexGrab(); + + void AddFile(char *Name); + void Process(); + + void CompressTpages(bool f) {m_compressTpages=f;} + void NoWriteTpages(bool f) {m_noWriteTpages=f;} + void UseHalfTpage(bool f) {m_useHalfTpage=f;} + void AnimatedHeadersOnly(bool f) {m_AnimatedHeadersOnly=f;} + void DontOutputBoxes(bool f) {m_DontOutputBoxes=f;} + void AlignHeaders(bool f) {m_AlignHeaders=f;} + void AllowRotate(bool f) {MyFiles.SetAllowRotate(f);} + void FileRecursion(bool f) {MyFiles.SetFileRecursion(f);} + void tNoSort() {MyFiles.setNoSort();} + + void ReadRepFile(GString String) {MyFiles.ReadRepFile(String);} + + void CrossHair(bool f) {MyFiles.SetCrossHair(f);} + void ZeroColZero(bool f) {MyFiles.SetZeroColZero(f);} + void MoveUVs(bool f) {MyFiles.SetMoveUVs(f);} + void ShrinkToFit(bool f) {MyFiles.SetShrinkToFit(f);} + + void SetOutFile(char *Name) {m_OutFile=Name;} + void SetSprFile(char *Name) {m_SprFile=Name;} + void SetDebugOut(char *Name) {m_OutLbm=Name;} + void SetRepFile(char *Name) {m_ReportFile=Name;} + void SetIncFile(char *Name) {m_IncOutFile=Name;} + void SetRawTPageFile(char *Name) {m_rawTpageFile=Name;} + + void MaxSize(int Size) {MyFiles.SetMaxSize(Size);} + void SetTPage(int Base,int W,int H) {m_PageBase=Base; m_WidthPages=W; m_HeightPages=H; m_PagePlacements=true;} + void ForceOffsets(int XOfs,int YOfs) {MyFiles.SetXOff(XOfs); MyFiles.SetYOff(YOfs); MyFiles.SetForceOffsets(true);} + + + +protected: + + AllFiles MyFiles; + + GString m_OutFile; + GString m_OutLbm; + GString m_SprFile; + GString m_ReportFile; + GString m_IncOutFile; + GString m_rawTpageFile; + + int m_PageBase; + int m_WidthPages; + int m_HeightPages; + bool m_PagePlacements; + bool m_compressTpages; + bool m_noWriteTpages; + bool m_useHalfTpage; + bool m_AnimatedHeadersOnly; + bool m_DontOutputBoxes; + bool m_AlignHeaders; + +}; + +/*---------------------------------------------------------------------- */ + +#endif + +/*=========================================================================== + end */ diff --git a/Utils/Libs/TexGrab/VImage.cpp b/Utils/Libs/TexGrab/VImage.cpp new file mode 100644 index 000000000..c21746ebe --- /dev/null +++ b/Utils/Libs/TexGrab/VImage.cpp @@ -0,0 +1,472 @@ +/*========================================================================= + + FILENAME.CPP + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* Glib + ---- */ +#include "pak.h" + +/* Local + ----- */ +#include "vimage.h" + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ +using namespace std; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +VRAMImage::VRAMImage(int NewWidthInTpages,int NewHeightInPixels) : VRAMData(NULL) +{ + WidthInTpages=NewWidthInTpages; + HeightInPixels=NewHeightInPixels; + HeightInTPages=NewHeightInPixels / 256; + + if (!HeightInTPages) + { + aTPageHeight = 128; + HeightInTPages = 1; + } + else + { + aTPageHeight = HeightInTPages * 256; + } + TPageSizeInBytes = 128 * aTPageHeight; + + WidthInBytes=WidthInTpages*128; + + VramAreaBytes=WidthInBytes * HeightInPixels; + + VRAMData=new u8[VramAreaBytes]; + lbmData = new u8[WidthInTpages*256*HeightInPixels]; + + if (!lbmData) + Error(ERM_OUTOFMEM); + + if (!VRAMData) + Error(ERM_OUTOFMEM); + + memset(VRAMData,0,VramAreaBytes); + m_doCompress=false; +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +VRAMImage::~VRAMImage(void) +{ + if (lbmData) + delete lbmData; + if (VRAMData) + delete VRAMData; +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +void VRAMImage::getTpData(unsigned int tp,std::vector & dest) const +{ + const int TPAGES_IN_ALL =WidthInTpages * HeightInTPages; + + if (tp >= TPAGES_IN_ALL) + Error(ERR_FATAL,"illegal tpage number"); + + int tpX,tpY; + u8 const * srcTpData; + dest.resize(TPageSizeInBytes); + + + tpX=(tp%WidthInTpages)*128; + tpY=(tp/WidthInTpages)*aTPageHeight; + + srcTpData=&VRAMData[tpX+tpY*WidthInBytes]; + + for (int x=0;x<128;x++) + for (int y=0;y & Body) +{ + try + { + GString Com; + + char TmpName[100]; + char CompTmpName[100]; + + tmpnam(TmpName); + tmpnam(CompTmpName); + + GString ComStr(CmdLine); + + ComStr.Replace("%1",TmpName); + ComStr.Replace("%2",CompTmpName); + + ofstream Out; + Out.open(TmpName,ios::binary|ios::trunc); + + if (Out) + { + int CompSize; + Out.write((char const *)&Body[0],Body.size()); + Out.close(); + + cout<<(char const *)ComStr<<"from "< tpageData; + tpageData.resize(TPageSizeInBytes); + + for (int f=0;f tpageData; + vector dataToWrite; + + tpageData.resize(TPageSizeInBytes); + dataToWrite.resize(TPageSizeInBytes); + + for (int f=0;f myData; + + myData.resize(128*64); + + memcpy(&myData[0],srcData,128*64); + + #ifdef __USE_LZNP__ + + CompressMem("lznp %1 %2",myData); + dataWriteSize=myData.size(); + memcpy(&dataToWrite[0],&myData[0],dataWriteSize); + + #else + dataWriteSize=PAK_findPakSize(&myData[0],128*64); + PAK_doPak(&dataToWrite[0],&myData[0],128*64); + #endif + + } + else + { + dataWriteSize=128*64; + memcpy(&dataToWrite[0],srcData,128*64); + } + for (int a=0;a<16;a++) printf("%i, ",(int)dataToWrite[a]); + printf("\n"); + Str.write((char *)(&dataToWrite[0]),dataWriteSize); + } + + } + else + Str.write((char *)(VRAMData),VramAreaBytes); +} + + + + + + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void VRAMImage::PlotPal(SprPal const & PalToPlot) +{ + TPRect Tp=PalToPlot.GetTPRect(); + + int W=WidthInTpages*256; + + W/=2; + + u16 * Addr=(u16 *)&VRAMData[Tp.Y*W+Tp.X/2]; + + std::vector OutWords; + + PalToPlot.MakePSXPal(OutWords); + + int f; + + for (f=0;f> 4; + else + lbmData[x+y*W]=VRAMData[(y*(W/2))+(x/2)]&0x0f; + } + + ThisFr.SetFrame(lbmData,W,H,GazPalette); + ThisFr.SaveLbm(Name); + + cout<<"Written "< +#include + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ +using namespace std; + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ +struct RGB +{ + u8 r,g,b; +}; + +class BITMAP +{ +public: + BITMAP(void) + { + m_width=0; + m_height=0; + } + + void setSize(int width,int height) + { + bitMap.resize(width*height); + + m_width=width; + m_height=height; + } + + void clear(void) + { + if (m_width && m_height) + memset(&bitMap[0],0,m_width*m_height); + } + + void line(unsigned int y,unsigned int x,u8 pix) + { + if (x >= m_width) + { + GObject::Error(ERR_WARNING,"Out of X boundary - %d %d\n", x, m_width); + x = m_width-1; + } + if (y >= m_height) + { + GObject::Error(ERR_WARNING,"Out of Y boundary - %d %d\n", y, m_height); + y = m_height-1; + } + bitMap[y*m_width+x]=pix; + + } + + u8 const * getBitMap(void) const + {return(&bitMap[0]);} + +protected: + int m_width; + int m_height; + vector bitMap; +}; + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +#include +#include +#include +#include + + +#define BI_RGB 0 +#define BI_RLE8 1 +#define BI_RLE4 2 +#define BI_BITFIELDS 3 + +#define OS2INFOHEADERSIZE 12 +#define WININFOHEADERSIZE 40 + + +typedef struct BITMAPFILEHEADER +{ + unsigned long bfType; + unsigned long bfSize; + unsigned short bfReserved1; + unsigned short bfReserved2; + unsigned long bfOffBits; +} BITMAPFILEHEADER; + + +/* Used for both OS/2 and Windows BMP. + * Contains only the parameters needed to load the image + */ +typedef struct BITMAPINFOHEADER +{ + unsigned long biWidth; + unsigned long biHeight; + unsigned short biBitCount; + unsigned long biCompression; +} BITMAPINFOHEADER; + + +typedef struct WINBMPINFOHEADER /* size: 40 */ +{ + unsigned long biWidth; + unsigned long biHeight; + unsigned short biPlanes; + unsigned short biBitCount; + unsigned long biCompression; + unsigned long biSizeImage; + unsigned long biXPelsPerMeter; + unsigned long biYPelsPerMeter; + unsigned long biClrUsed; + unsigned long biClrImportant; +} WINBMPINFOHEADER; + + +typedef struct OS2BMPINFOHEADER /* size: 12 */ +{ + unsigned short biWidth; + unsigned short biHeight; + unsigned short biPlanes; + unsigned short biBitCount; +} OS2BMPINFOHEADER; + + + +/* read_bmfileheader: + * Reads a BMP file header and check that it has the BMP magic number. + */ +static int read_bmfileheader(Gifstream & f, BITMAPFILEHEADER *fileheader) +{ + fileheader->bfType = f.Get16(); + fileheader->bfSize= f.Get32(); + fileheader->bfReserved1= f.Get16(); + fileheader->bfReserved2= f.Get16(); + fileheader->bfOffBits= f.Get32(); + + if (fileheader->bfType != 19778) + return -1; + + return 0; +} + + + +/* read_win_bminfoheader: + * Reads information from a BMP file header. + */ +static int read_win_bminfoheader(Gifstream & f, BITMAPINFOHEADER *infoheader) +{ + WINBMPINFOHEADER win_infoheader; + + win_infoheader.biWidth = f.Get32(); + win_infoheader.biHeight = f.Get32(); + win_infoheader.biPlanes = f.Get16(); + win_infoheader.biBitCount = f.Get16(); + win_infoheader.biCompression = f.Get32(); + win_infoheader.biSizeImage = f.Get32(); + win_infoheader.biXPelsPerMeter = f.Get32(); + win_infoheader.biYPelsPerMeter = f.Get32(); + win_infoheader.biClrUsed = f.Get32(); + win_infoheader.biClrImportant = f.Get32(); + + infoheader->biWidth = win_infoheader.biWidth; + infoheader->biHeight = win_infoheader.biHeight; + infoheader->biBitCount = win_infoheader.biBitCount; + infoheader->biCompression = win_infoheader.biCompression; + + return 0; +} + + + +/* read_os2_bminfoheader: + * Reads information from an OS/2 format BMP file header. + */ +static int read_os2_bminfoheader(Gifstream & f, BITMAPINFOHEADER *infoheader) +{ + OS2BMPINFOHEADER os2_infoheader; + + os2_infoheader.biWidth = f.Get16(); + os2_infoheader.biHeight = f.Get32(); + os2_infoheader.biPlanes = f.Get32(); + os2_infoheader.biBitCount = f.Get32(); + + infoheader->biWidth = os2_infoheader.biWidth; + infoheader->biHeight = os2_infoheader.biHeight; + infoheader->biBitCount = os2_infoheader.biBitCount; + infoheader->biCompression = 0; + + return 0; +} + + +/* read_bmicolors: + * Loads the color pallete for 1,4,8 bit formats. + */ +static void read_bmicolors(int ncols, RGB *pal, Gifstream & f,int win_flag) +{ + int i; + + for (i=0; i> 1; + } + } + + pix = b[j]; + bmp->line(line,i,pix); + } +} + + + +/* read_4bit_line: + * Support function for reading the 4 bit bitmap file format. + */ +static void read_4bit_line(int length, Gifstream & f, BITMAP *bmp, int line) +{ + unsigned char b[8]; + unsigned long n; + int i, j, k; + int temp; + int pix; + + for (i=0; i> 4; + b[k*2] = temp & 15; + n = n >> 8; + } + } + + pix = b[j]; + bmp->line(line,i,pix); + } +} + + + +/* read_8bit_line: + * Support function for reading the 8 bit bitmap file format. + */ +static void read_8bit_line(int length, Gifstream & f, BITMAP *bmp, int line) +{ + unsigned char b[4]; + unsigned long n; + int i, j, k; + int pix; + + for (i=0; i> 8; + } + } + pix = b[j]; + bmp->line(line,i,pix); + } +} + + +/* read_24bit_line: + * Support function for reading the 24 bit bitmap file format, doing + * our best to convert it down to a 256 color pallete. + */ +static void read_24bit_line(int length, Gifstream & f, BITMAP *bmp, int line) +{ +#if 0 + int i, nbytes; + RGB c; + + nbytes=0; + + for (i=0; iline[line][i*3+_rgb_r_shift_24/8] = c.r; + bmp->line[line][i*3+_rgb_g_shift_24/8] = c.g; + bmp->line[line][i*3+_rgb_b_shift_24/8] = c.b; + nbytes += 3; + } + + nbytes = nbytes % 4; + if (nbytes != 0) + for (i=nbytes; i<4; i++) + f.get();; +#endif +} + + + +/* read_image: + * For reading the noncompressed BMP image format. + */ +static void read_image(Gifstream & f, BITMAP *bmp, BITMAPINFOHEADER *infoheader) +{ + int i, line; + + for (i=0; i<(int)infoheader->biHeight; i++) { + line = i; + + switch (infoheader->biBitCount) { + + case 1: + read_1bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1); + break; + + case 4: + read_4bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1); + break; + + case 8: + read_8bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1); + break; + + case 24: + read_24bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1); + break; + } + } +} + + + +/* read_RLE8_compressed_image: + * For reading the 8 bit RLE compressed BMP image format. + */ +static void read_RLE8_compressed_image(Gifstream & f, BITMAP *bmp, BITMAPINFOHEADER *infoheader) +{ + unsigned char count, val, val0; + int j, pos, line; + int eolflag, eopicflag; + + eopicflag = 0; + line = infoheader->biHeight - 1; + + while (eopicflag == 0) { + pos = 0; /* x position in bitmap */ + eolflag = 0; /* end of line flag */ + + while ((eolflag == 0) && (eopicflag == 0)) { + count = f.get(); + val = f.get(); + + if (count > 0) { /* repeat pixel count times */ + for (j=0;jline(line,pos,val); + pos++; + } + } + else { + switch (val) { + + case 0: /* end of line flag */ + eolflag=1; + break; + + case 1: /* end of picture flag */ + eopicflag=1; + break; + + case 2: /* displace picture */ + count = f.get(); + val = f.get(); + pos += count; + line -= val; + break; + + default: /* read in absolute mode */ + for (j=0; jline(line,pos,val0); + pos++; + } + + if (j%2 == 1) + val0 = f.get(); /* align on word boundary */ + break; + + } + } + + if (pos > (int)infoheader->biWidth) + eolflag=1; + } + + line--; + if (line < 0) + eopicflag = 1; + } +} + + + +/* read_RLE4_compressed_image: + * For reading the 4 bit RLE compressed BMP image format. + */ +static void read_RLE4_compressed_image(Gifstream & f, BITMAP *bmp, BITMAPINFOHEADER *infoheader) +{ + unsigned char b[8]; + unsigned char count; + unsigned short val0, val; + int j, k, pos, line; + int eolflag, eopicflag; + + eopicflag = 0; /* end of picture flag */ + line = infoheader->biHeight - 1; + + while (eopicflag == 0) { + pos = 0; + eolflag = 0; /* end of line flag */ + + while ((eolflag == 0) && (eopicflag == 0)) { + count = f.get(); + val = f.get(); + + if (count > 0) { /* repeat pixels count times */ + b[1] = val & 15; + b[0] = (val >> 4) & 15; + for (j=0; jline(line,pos,b[j%2]); + pos++; + } + } + else { + switch (val) { + + case 0: /* end of line */ + eolflag=1; + break; + + case 1: /* end of picture */ + eopicflag=1; + break; + + case 2: /* displace image */ + count = f.get(); + val = f.get(); + pos += count; + line -= val; + break; + + default: /* read in absolute mode */ + for (j=0; j> 4; + b[2*k] = val0 & 15; + val0 = val0 >> 4; + } + } + bmp->line(line,pos,b[j%4]); + pos++; + } + break; + } + } + + if (pos > (int)infoheader->biWidth) + eolflag=1; + } + + line--; + if (line < 0) + eopicflag = 1; + } +} + + + +/* load_bmp: + * Loads a Windows BMP file, returning a bitmap structure and storing + * the pallete data in the specified pallete (this should be an array of + * at least 256 RGB structures). + * + * Thanks to Seymour Shlien for contributing this function. + */ + +void load_bmp(Frame & frm,char const *filename) +{ + BITMAPFILEHEADER fileheader; + BITMAPINFOHEADER infoheader; + + RGB pal[256]; + BITMAP bmp; + + Gifstream f(Gifstream::LITTLE_ENDIAN); + + int ncol; + unsigned long biSize; + + f.open(filename,ios::in|ios::binary); + + if (!f) + GObject::Error(ERR_FATAL,"couldn't open file %s",filename); + + if (read_bmfileheader(f, &fileheader) != 0) + { + GObject::Error(ERR_FATAL,"error reading bmp hdr for %s",filename); + } + + biSize = f.Get32(); + + if (biSize == WININFOHEADERSIZE) + { + if (read_win_bminfoheader(f, &infoheader) != 0) + GObject::Error(ERR_FATAL,"error reading windows bmp info hdr for %s",filename); + + /* compute number of colors recorded */ + ncol = (fileheader.bfOffBits - 54) / 4; + read_bmicolors(ncol, pal, f, 1); + } + else if (biSize == OS2INFOHEADERSIZE) + { + if (read_os2_bminfoheader(f, &infoheader) != 0) + GObject::Error(ERR_FATAL,"error reading os2 bmp info hdr for %s",filename); + + /* compute number of colors recorded */ + ncol = (fileheader.bfOffBits - 26) / 3; + read_bmicolors(ncol, pal, f, 0); + } + else + { + GObject::Error(ERR_FATAL,"error finding correct hdr for bmp %s",filename); + } + + if (infoheader.biBitCount != 4 && infoheader.biBitCount != 8) + GObject::Error(ERR_FATAL,"only handles 4 && 8 bit bmps not %d : %s",infoheader.biBitCount,filename); + + + bmp.setSize(infoheader.biWidth, infoheader.biHeight); + + bmp.clear(); + + switch (infoheader.biCompression) + { + + case BI_RGB: + read_image(f, &bmp, &infoheader); + break; + + case BI_RLE8: + read_RLE8_compressed_image(f, &bmp, &infoheader); + break; + + case BI_RLE4: + read_RLE4_compressed_image(f, &bmp, &infoheader); + break; + + default: + GObject::Error(ERR_FATAL,"unknown compression foramt for %s",filename); + break; + } + + f.close(); + + + { + Palette palObj; + + + + for (int f=0;f + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ +void load_bmp(Frame & frm,char const *filename); + +/*---------------------------------------------------------------------- */ + +#endif /* __BMPLOADER_H__ */ + +/*=========================================================================== + end */ \ No newline at end of file diff --git a/Utils/Libs/TexGrab/cross.cpp b/Utils/Libs/TexGrab/cross.cpp new file mode 100644 index 000000000..100a1c0de --- /dev/null +++ b/Utils/Libs/TexGrab/cross.cpp @@ -0,0 +1,158 @@ +/*========================================================================= + + CROSS.CPP + + Author: Gary Liddon @ Climax + Created: + Project: Diablo Playstation Conversion + Purpose: Find A Crosshair on a frame + + Copyright (c) 1996 Director's Cut Ltd. + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* STL + --- */ + +/* Glib + ---- */ + +/* Local + ----- */ +#include "cross.h" + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +using namespace std; + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Classes + ------- */ + + +/*---------------------------------------------------------------------- + Description: + Find a cross hair in this frame for animation offset and store it + into member vars x and y. + + Returns: + True if a cross hair is found + ---------------------------------------------------------------------- */ +bool CROSS_RES::FindCrossHair( + Frame const & Fr, /* Frame we're looking for a cross-hair in */ + u8 CrossCol /* Pixel value of cross hair we're looking for */ + ) +{ + u8 const * FrmData; + int * CountCol=NULL; + int * CountRow=NULL; + + int Width; + int Height; + bool RetVal; + + RetVal=false; + + Width=Fr.GetWidth(); + Height=Fr.GetHeight(); + + if (Width && Height) + { + int Col; + int Row; + + if (!(CountCol=new int[Width])) + { + cout<<"Width is "< Largest) + { + Largest=CountCol[f]; + LargestIndex=f; + } + } + + return(LargestIndex); +} + +/*=========================================================================== + end */ + diff --git a/Utils/Libs/TexGrab/cross.h b/Utils/Libs/TexGrab/cross.h new file mode 100644 index 000000000..cda039c74 --- /dev/null +++ b/Utils/Libs/TexGrab/cross.h @@ -0,0 +1,67 @@ +/*========================================================================= + + CROSS.CPP + + Author: Gary Liddon @ Climax + Created: + Project: Diablo Playstation Conversion + Purpose: Find A Crosshair on a frame + + Copyright (c) 1996 Director's Cut Ltd. + +===========================================================================*/ + +#ifndef __CROSS_HPP__ +#define __CROSS_HPP__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* STL + --- */ + +/* Glib + ---- */ +#include +#include + + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Description: + This structure is used to find centering cross hairs + in frame objects using the FindCrossHair method. + If a cross hair is found, the results are put in + the x and y member vars. + ---------------------------------------------------------------------- */ +struct CROSS_RES +{ + int x; /* x co-ord of cross found */ + int y; /* y co-ord of cross found */ + + bool FindCrossHair(Frame const & Fr,u8 CrossCol); + +private: + int FindLargestIndex(int * CountCol,int Width); +}; + + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- */ + +#endif /* __CROSS_HPP__ */ + +/*=========================================================================== + end */ + + diff --git a/Utils/Libs/TexGrab/grect.cpp b/Utils/Libs/TexGrab/grect.cpp new file mode 100644 index 000000000..80e1dc2fd --- /dev/null +++ b/Utils/Libs/TexGrab/grect.cpp @@ -0,0 +1,138 @@ +/*========================================================================= + + GRECT.CPP + + Author: Gary Liddon @ Climax + Created: + Project: + Purpose: + + Copyright (c) 1997 Climax Development Ltd + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#include + +/* Glib + ---- */ +#include + +/* Local + ----- */ +#include "grect.h" + + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ +using namespace std; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Positional Vars + --------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ +static Rect & AddAnotherRect(RectVec & Result); +static void AddRectMessage(Rect const & T); + + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +Rect & AddAnotherRect(RectVec & Result) +{ + Result.resize(Result.size()+1); + return(Result[Result.size()-1]); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +void CutRect(Rect const & ToBeCut,Rect const & TheCutter,RectVec & Result) +{ + Rect Cutter=TheCutter; + + ToBeCut.ClipRect(Cutter); + + if (Cutter) + { + /* Is there a top rectangle hanging about? */ + + if (ToBeCut.Y != Cutter.Y) + { + Rect & TopRect=AddAnotherRect(Result); + TopRect=ToBeCut; + TopRect.H=Cutter.Y-TopRect.Y; + AddRectMessage(TopRect); + } + + /* Is there a bottom rectangle hanging about? */ + + if ((ToBeCut.Y+ToBeCut.H) != (Cutter.Y+Cutter.H)) + { + Rect & TopRect=AddAnotherRect(Result); + TopRect=ToBeCut; + TopRect.Y=Cutter.Y+Cutter.H; + TopRect.H=(ToBeCut.Y+ToBeCut.H)-(Cutter.Y+Cutter.H); + AddRectMessage(TopRect); + } + + /* Is there a left rectangle hanging about? */ + + if (ToBeCut.X != Cutter.X) + { + Rect & TopRect=AddAnotherRect(Result); + TopRect=Cutter; + TopRect.X=ToBeCut.X; + TopRect.W=Cutter.X-ToBeCut.X; + AddRectMessage(TopRect); + } + + /* Is there a right rectangle hanging about? */ + + if ((ToBeCut.X+ToBeCut.W) != (Cutter.X+Cutter.W)) + { + Rect & TopRect=AddAnotherRect(Result); + TopRect=Cutter; + TopRect.X=Cutter.X+Cutter.W; + TopRect.W=(ToBeCut.X+ToBeCut.W)-(Cutter.X+Cutter.W); + AddRectMessage(TopRect); + } + } + +} + +void AddRectMessage(Rect const & T) +{ +} + + +/*=========================================================================== + end */ diff --git a/Utils/Libs/TexGrab/grect.h b/Utils/Libs/TexGrab/grect.h new file mode 100644 index 000000000..32460a47c --- /dev/null +++ b/Utils/Libs/TexGrab/grect.h @@ -0,0 +1,63 @@ +/*========================================================================= + + GRECT.CPP + + Author: Gary Liddon @ Climax + Created: + Project: + Purpose: + + Copyright (c) 1997 Climax Development Ltd + +===========================================================================*/ + +#ifndef __GRECT_H__ +#define __GRECT_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#include + +/* Glib + ---- */ +#include + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +typedef std::vector RectVec; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ +void CutRect(Rect const & ToBeCut,Rect const & TheCutter,RectVec & Result); +void ReportRectVec(RectVec & Result); +void GRectTest(void); + +/*---------------------------------------------------------------------- */ + +#endif /* __GRECT_H__ */ + +/*=========================================================================== + end */ diff --git a/Utils/Libs/TexGrab/pak.cpp b/Utils/Libs/TexGrab/pak.cpp new file mode 100644 index 000000000..40da81b94 --- /dev/null +++ b/Utils/Libs/TexGrab/pak.cpp @@ -0,0 +1,359 @@ +/*========================================================================= + + PAK.CPP + + Author: Gary Liddon @ Climax (from work by Nick Pelling && Carl Muller) + Created: + Project: Diablo PSX + Purpose: PAK decompress \ compress code + + Copyright (c) 1997 Climax Development Ltd + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* Glib + ---- */ + +/* Local + ----- */ +#include +#include "pak.h" + +/* Graphics + -------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ +#define UNPAKBUFFERSIZE 4096 +#define STRMAX 80 +#define BUFFERSIZE 30000 +#define TRIGGER 20000 +#define MAXUNIQUE 127 + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +struct Block +{ + int data[128]; + BOOL blockrep; + int blocksize; + int blockoffset; + + u8 * Dest; + int outsize; + + virtual void fputc(u8 Val) + { + *Dest=Val; + Dest++; + outsize++; + } + + void writeBlock(void); +}; + +struct CountBlock : Block +{ + virtual void fputc(u8 Val) + { + Dest++; + outsize++; + } +}; + +/*---------------------------------------------------------------------- + Vars + ---- */ +static int s_lastAmountOfCompressedData; + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ +static void writeblock(struct block *theblock); + +/*---------------------------------------------------------------------- + Vars + ---- */ +/*---------------------------------------------------------------------- + Data + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void Block::writeBlock(void) +{ + if ((blockrep) && (blocksize == 0)) + { + /* Terminator */ + fputc(128); + fputc(0); + } + else if (blockrep) + { + fputc(blockoffset); + fputc(blocksize); + } + else /* Unique bytes */ + { + fputc(blocksize & 127); + + for (int i = 0; i <= blocksize; i++) + fputc(data[i]); + } + + // Get ready for next block + blockrep = FALSE; + blockoffset = 0; + blocksize = -1; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +static bool memequ(u8 const * p1,u8 const * p2,int size) +{ + bool same; + + same=true; + + for (int f=0;f FORWARDDIST) + end = FORWARDDIST; + + bestoffset = begin; + bestlength = 1; + theptr = buffer + (inpos); + + ptr1 = buffer + (inpos + begin); + + for (offset = begin; offset < 0; offset++) + { + if (*ptr1 == *theptr) + { + if (memequ(ptr1, theptr, bestlength + 1)) + { + bestlength++; + bestoffset = offset; + ptr2 = ptr1 + bestlength; + ptr3 = theptr + bestlength; + + while (*ptr2 == *ptr3) + { + ptr2++; + ptr3++; + bestlength++; + if (bestlength >= end) + break; + } + } + } + + if (bestlength >= end) + { + bestlength = end; + break; + } + + ptr1++; + } + + + if (bestlength < MINBLOCK) + { + /* See if last block is unique */ + + if (theblock.blockrep) /* Flush previous special block */ + { + theblock.writeBlock(); + theblock.data[++theblock.blocksize] = buffer[inpos++]; + } + else + { + /* Add to it */ + + if (theblock.blocksize >= MAXUNIQUE) + theblock.writeBlock(); + + theblock.data[++theblock.blocksize] = buffer[inpos++]; + } + } + else + { + /* We have found a match */ + theblock.writeBlock(); + theblock.blockrep = TRUE; + theblock.blocksize = bestlength; + theblock.blockoffset = bestoffset; + inpos += bestlength; + } + } + + /* Flush buffer */ + + theblock.writeBlock(); + + /* Terminate file */ + + theblock.blockrep = TRUE; + theblock.blocksize = 0; + theblock.blockoffset = 0; + theblock.writeBlock(); + + return(theblock.outsize); +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int PAK_doPak(u8 * Dest,u8 const * buffer,int insize) +{ + Block outBlock; + return(lowLevelPak(Dest,buffer,insize,outBlock)); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int PAK_findPakSize(u8 const * buffer,int insize) +{ + CountBlock outBlock; + return(lowLevelPak(NULL,buffer,insize,outBlock)); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int PAK_doUnpak(u8 * Dest,u8 const * Source) +{ + int outsize = 0; + u8 const * originalSource; + + originalSource=Source; + + while (1) /* ie, continue until end mark */ + { + u8 const * From; + + int size; + int ch; + + ch = *Source++; + + if (ch < 128) /* if it is in range {0..127} then */ + { + size = (ch + 1); + From=Source; + Source+=size; + } + else + { + size = *Source++; + + if (size == 0) /* distance == 0 => end of file */ + break; + + From=Dest+(s8)ch; + } + + u8 * endAddr; + endAddr=(u8*)(u32(From)+size); + + outsize += size; + + while (From!=endAddr) + { + *Dest=*From; + Dest++; + From++; + } + } + + s_lastAmountOfCompressedData=Source-originalSource; + + return(outsize); +} + +int PAK_getLastAmountOfDataRead(void) +{ + return(s_lastAmountOfCompressedData); +} + +/*=========================================================================== + end */ + + + + diff --git a/Utils/Libs/TexGrab/pak.h b/Utils/Libs/TexGrab/pak.h new file mode 100644 index 000000000..f3f5df83f --- /dev/null +++ b/Utils/Libs/TexGrab/pak.h @@ -0,0 +1,61 @@ +/*========================================================================= + + PAK.H + + Author: Carl Muller (algorithm Nick Pelling && Carl Muller) + Created: + Project: + Purpose: + + Copyright (c) 1997 Climax Development Ltd + +===========================================================================*/ + +#ifndef __PAK_PAK_H__ +#define __PAK_PAK_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* Glib + ---- */ +#include + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ +int PAK_doPak(u8 * Dest,u8 const * source,int insize); +int PAK_doUnpak(u8 * Dest,u8 const * Source); +int PAK_findPakSize(u8 const * souce,int insize); +int PAK_getLastAmountOfDataRead(void); + +/*---------------------------------------------------------------------- */ + +#endif /* __PAK_PAK_H__ */ + +/*=========================================================================== + end */ diff --git a/Utils/Libs/TexGrab/sprset.cpp b/Utils/Libs/TexGrab/sprset.cpp new file mode 100644 index 000000000..0ae449560 --- /dev/null +++ b/Utils/Libs/TexGrab/sprset.cpp @@ -0,0 +1,1310 @@ +/*========================================================================= + + SPRSET.CPP + + Author: Gary Liddon @ Fareham + Created: + Project: TPW Parkgrab + Purpose: Object that reads in all the frames for sprites + processes them into tpages and spits it all out to + disk + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#include +#include +#include + +/* Glib + ---- */ +#include +#include +#include +#include +#include + +/* Local + ----- */ +#include "sprset.h" +#include "cross.h" + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +using namespace std; + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Data + ---- */ + +static const char BadFileChars[] = +{ + '+', '-', '*', '/', '\\', '#', ',', + '.', '(', ')', '!', '"', '£', '$', + '%', '^', '&', '=', '#', ':', ';', '<', + '>', '?', '@', '{', '}', '[', ']', '¬', +}; + +static const int nbBadFileChars = (sizeof(BadFileChars) / sizeof(char)); + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +GString ReplaceBadFileChars(GString s) +{ + GString out; + const char *textin = (const char*)s; + char *textout = new char[s.Len()+1]; + memset(textout, 0, s.Len()+1); + int i, p; + + p=0; + for (i=0; i (*PalIt).GetNumOfCols()) + (*PalIt)=ThisPal; + + PalIndex=PalIt-AllSprPals.begin(); + } + } + + /* If Palindex == -1 then we couldn't find the palette we wanted so add this one to the pool */ + + if (PalIndex==-1) + { + AllSprPals.resize(AllSprPals.size()+1); + SprPal & ThisSprPal=AllSprPals[AllSprPals.size()-1]; + PalIndex=AllSprPals.size()-1; + ThisSprPal=ThisPal; + ThisSprPal.SetPlusColZero((*it).GetPlusColZero()); + ThisSprPal.SetZeroColZero((*it).GetZeroColZero()); + ThisSprPal.SetName((*it).GetName()); + } + + /* Set the sprframe to have the write pal index */ + + (*it).SetPalIndex(PalIndex); + AllSprPals[PalIndex].SetPalIndex(PalIndex); + } + + cout<<"Found "<SaveAs16ColLbm(FileName); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +#include + +void SprSet::WriteReport(char const * File) +{ + const int DirLen=1024; + char Dir[DirLen+1]; + GString CurrDir; + + CurrDir=getcwd(Dir,DirLen); + CurrDir.Upper(); + CurrDir=CurrDir+"\\"; + + GString OutFileName(File); + OutFileName.Lower(); + + Gofstream Out; + + Out.open(OutFileName,ios::out); + + if (Out) + { + Out<<"File\tTPage\tClut\tu\tv\tw\th\tRotated"<GetActualName(); + u=Frm.GetTPRect().X; + v=Frm.GetTPRect().Y; + w=Frm.GetWidth(); + h=Frm.GetHeight(); + + RelName=GFName::makerelative(CurrDir,Name,Dir); + + Out<<(char const *)RelName<<"\t$"<PlotFrame(AllSprFrames[f]); + + for (f=0;fPlotPal(AllSprPals[f]); + + /* + struct SpriteBankHdr + { + u16 NumOfSprites; + u16 NumOfTPages; + + u16 TpageStart; + u16 WidthInTpages; + + u16 HeightInTpages; + u16 NumOfSpareBoxes; + }; + */ + + Gofstream Out(Gofstream::LITTLE_ENDIAN); + + GString OutFileName(File); + OutFileName.Lower(); + + Out.open(OutFileName,ios::out|ios::binary); + + TPRectVec spareVRAM; + + MyVram.getUnusedSpace(spareVRAM); + + if (Out) + { +int FrameCount=AllSprFrames.size(); + if (m_AnimatedHeadersOnly) + { + FrameCount=0; + for (f=0;fsetDoCompress(m_compressTpages); + Vi->Write(Out); + } + + Out.close(); + } + else + Error(ERR_FATAL,"Error wring file %s",(char const *)OutFileName); + + WriteHeaderFile(GetHeaderFileName(File)); +} + + +GString SprSet::GetHeaderFileName(char const * File) +{ + GString HeaderFileName; + + if (IncOutFile == "") + { + GFName HeaderFile(File); + HeaderFile.Ext("h"); + HeaderFileName=HeaderFile.FullName(); + } + else + HeaderFileName=IncOutFile; + + HeaderFileName.Lower(); + + return(HeaderFileName); +} + +void SprSet::WriteHeaderFile(char const * HName) +{ + ofstream HOut; + int f; + + GFName HeaderFile(HName); + + GString OFileDefine; + OFileDefine="__SPR_"; + OFileDefine+=HeaderFile.File(); + OFileDefine+="_H__"; + OFileDefine.Upper(); + + GString HeaderFileName(HeaderFile.FullName()); + HeaderFileName.Lower(); + + HOut.open(HeaderFileName,ios::out); + + if (HOut) + { + HOut<<"#ifndef "<<(char const *)OFileDefine< CopySprPals; /* Make a copy of the palettes */ + + CopySprPals=AllSprPals; + + std::sort(CopySprPals.begin(),CopySprPals.end()); /* Sort em according to how many cols */ + + for (f=0;f AllocRects; + + AllocRects.resize(AllSprFrames.size()); + + std::vector oldTypes; + + oldTypes.resize(AllSprFrames.size()); + + for (f=0;fgetAllocateAs16Bit()) + oldTypes[f]=AllocRects[f].convertTo16Bit(); + } + + /* Allocate int VRAM */ + + if(Vr.AllocVRAM(AllocRects,false,true,true)) + { + /* + Now go back through all the sprite frames and tell them where + they are going to sit in VRAM + */ + + for (f=0;fgetAllocateAs16Bit()) + AllocRects[f].convertFrom16Bit(oldTypes[AllocRects[f].GetId()]); + + AllSprFrames[AllocRects[f].GetId()].SetVRAMPos(AllocRects[f]); + } + } + else + { + Error(ERR_FATAL,"Couldn't fit frames into VRAM"); + } + + /* Go through and tell all pals and frames what the base tpage is */ + + for (f=0;fWriteInTpageChunks(out); + } + else + Error(ERR_FATAL,"Error opening raw file %s",file); +} + +/*---------------------------------------------------------------------- + Function: + Purpose: Write out sprs and pals to a sprite file (not a VRAM block) + Params: + Returns: + ---------------------------------------------------------------------- */ +void SprSet::WriteSprFile(char const * Name) +{ + std::vector SprOffsets; + std::vector PalOffsets; + + ProcessPals(); + + Gofstream SpriteOut(Gofstream::LITTLE_ENDIAN); + + GString SpriteOutName(Name); + SpriteOutName.Lower(); + SpriteOut.open(SpriteOutName,ios::binary|ios::out|ios::trunc); + + if (SpriteOut) + { + int NumOfSprs; + int NumOfPals; + int PalOffsetTable; + int SprOffsetTable; + + /* + struct SPR_RAM_HDR + { + int NumOfPals; + int NumOfSprs; + int PalOffsets[NumOfPals]; + int SprOfffsets[NumOfSprs]; + RAM_FRAME_HDR Frames[NumOfSprs]; + Pals Pals[NumOfPals]; + Data [NumOfSprs] + } + + */ + + NumOfSprs=AllSprFrames.size(); + NumOfPals=AllSprPals.size(); + + SpriteOut.Put32(NumOfPals); + SpriteOut.Put32(NumOfSprs); + + SprOffsets.resize(NumOfSprs); + PalOffsets.resize(NumOfPals); + + PalOffsetTable=SpriteOut.tellp(); + SpriteOut.seekp(sizeof(u32)*NumOfPals,ios::cur); + + SprOffsetTable=SpriteOut.tellp(); + SpriteOut.seekp(sizeof(u32)*NumOfSprs,ios::cur); + + int f; + + for (f=0;f MaxSize) + NewWidth=MaxSize; + + if (NewHeight > MaxSize) + NewHeight=MaxSize; + + if (NewWidth != GetWidth() || NewHeight != GetHeight()) + { + cout<<"Reducing frame "<GetActualFileName()<GetActualFileName()< 254 || Height > 254) + { + Error(ERR_FATAL,"Images only allowed to 254x254, this is %dx%d : %s",Width,Height,MyFileInfo.GetActualFileName()); + } + + +} + +struct fRGBA + { + void Set(float _R,float _G,float _B,float _A) + {R=_R;G=_G;B=_B;A=_A;} + + float R,G,B,A; + }; + +void SprFrame::ResizeAndReduce(Frame & Frm,int TargCols,float XPerc,float YPerc,bool ZeroSeeThrough) +{ + std::vector FullColNewScreen; + std::vector DestBytePic; + std::vector Bitmap; + + u8 Pal[256*3]; + u8 * Dest; + int f; + + Bitmap.resize(Frm.GetWidth()*Frm.GetHeight()*4); + + Frm.MakeRGBA(&Bitmap[0],ZeroSeeThrough); + + int Width,Height; + + Width=Frm.GetWidth(); + Height=Frm.GetHeight(); + + int NewWidth=float(Width)*XPerc; + int NewHeight=float(Height)*YPerc; + + if (!(Dest=new u8[NewWidth*NewHeight])) + GObject::Error(ERM_OUTOFMEM); + + FullColNewScreen.resize(NewWidth*NewHeight); + DestBytePic.resize(NewWidth*NewHeight*3); + + /* Now Super Sample it down */ + + const int Samples=8; + + int DestW=NewWidth; + int DestH=NewHeight; + float YMul=float(Height)/DestH; + float XMul=float(Width)/DestW; + + for (int dy=0;dy1.0f) + R=1.0f; + + if (G>1.0f) + B=1.0f; + + if (B>1.0f) + B=1.0f; + + int DestIndex=(dy*NewWidth+dx); + + FullColNewScreen[DestIndex].Set(R,G,B,A); + } + } + + /* Convert Back to RGBA into a dest byte picture */ + + const float Bound=0.5f; + + for (f=0;f Bound) + { + DestBytePic[f*3+0]=R*255; + DestBytePic[f*3+1]=G*255; + DestBytePic[f*3+2]=B*255; + } + else + { + DestBytePic[f*3+0]=0; + DestBytePic[f*3+1]=0; + DestBytePic[f*3+2]=0; + } + } + + /* Now reduce colours */ + Palette NewPal; + + if (ZeroSeeThrough) + { + int Cols=TargCols-1; + + tquant(&DestBytePic[0],Dest,Pal,Cols,NewWidth*NewHeight); + + for (f=0;f Bound) + Dest[f]=Dest[f]+1; + else + Dest[f]=0; + } + + for (f=1;f Body; + + Frame NewFrame; + + NewFrame=*this; + + Rect OriginalRect; + + OriginalRect=NewFrame; + + OriginalRect.X=0; + OriginalRect.Y=0; + OriginalRect.W=GU_AlignVal(OriginalRect.W,AlignPixels); + + NewFrame.Crop(OriginalRect); + + int nfW,nfH,nfLineWidthBytes,nfAreaBytes; + + nfW=NewFrame.GetWidth(); + nfH=NewFrame.GetHeight(); + nfLineWidthBytes=GU_AlignVal(nfW,2)/2; + nfAreaBytes=nfLineWidthBytes*nfH; + + Body.resize(nfAreaBytes); + + for (int y=0;y OutPal; + MakePSXPal(OutPal); + + Out.Put32(OutPal.size()); + + for (int f=0;f>3; + G=Col.GetG()>>3; + B=Col.GetB()>>3; + return((R&0x1f)<<0)|((G&0x1f)<<5)|((B&0x1f)<<10); +} +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void SprPal::MakePSXPal(std::vector & OutWords) const +{ + + int NumOfCols; + int f; + + NumOfCols=(*this).GetNumOfCols(); + OutWords.resize(NumOfCols); + + if (GetZeroColZero() || GetPlusColZero()) + { + OutWords[0]=0; + + for (f=1;f + +/* Glib + ---- */ +#include +#include +#include +#include + +/* Local + ----- */ +#include "tpage.h" +#include "vimage.h" + + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/* Encapsulates a file and all the infomation parkgrab needs to process it + ----------------------------------------------------------------------- */ +class FileInfo + { + public: + FileInfo(void) + { + CrossHair=false; + ForceOffsets=false; + MemFrame=0; + } + + FileInfo(FileInfo const & Fi) + { + operator=(Fi); + } + + void operator=(FileInfo const & Fi) + { + FileName = Fi.FileName; + strcpy(ActualFileName,Fi.ActualFileName); + CrossHair=Fi.CrossHair; + ZeroColZero = Fi.ZeroColZero; + PlusColZero = Fi.PlusColZero; + MoveUVs = Fi.MoveUVs; + AllowRotate=Fi.AllowRotate; + ForceOffsets=Fi.ForceOffsets; + XOff=Fi.XOff; + YOff=Fi.YOff; + ShrinkToFit=Fi.ShrinkToFit; + m_allocateAs16Bit=Fi.m_allocateAs16Bit; + MemFrame=Fi.MemFrame; + } + + void SetForceOffsets(int x,int y) + { + ForceOffsets=true; + XOff=x; + YOff=y; + } + + GString CheckForPlus(GString s) + { + GString out; + const char *textin = (const char*)s; + char *textout = new char[s.Len()+1]; + memset(textout, 0, s.Len()+1); + int p; + bool plus; + + p=0; + if (textin[0] == '+') plus = true; + else plus = false; +/* for (i=0; i FIVec; +typedef std::vector::iterator FIVecIt; +typedef std::vector::const_iterator FIVecConstIt; + + +/* A Palette of graphics with sprset specific stuff + ---------------------------------------------- */ +class SprPal : public Palette +{ +public: + SprPal(void) + {} + + SprPal(SprPal const & Pal) + {MakeCopy(Pal);} + + void operator=(SprPal const & Pal) + {MakeCopy(Pal);} + + void operator=(Palette const & Pal) + {Palette::CopyPal(Pal);} + + bool operator==(Palette const & Pal) + {return(Palette::operator==(Pal));} + + bool operator<(SprPal const & Pal) + {return(GetNumOfCols() < Pal.GetNumOfCols());} + + void SetPalIndex(int NewPalIndex) + {PalIndex=NewPalIndex;} + + int GetPalIndex(void) const + {return(PalIndex);} + + void SetVRAMPos(TPRect & NewRect) + { + MyRect=NewRect; + } + + void SetTpBase(int NewTpBase) + { + TpBase=NewTpBase; + BaseTpX=((TpBase&0xf)*64); + BaseTpY=(TpBase>>4)*256; + } + + u16 GetClut(void) + { + int x=(MyRect.X/4)+BaseTpX; + int y=MyRect.Y+BaseTpY; + return((y<<6)|((x>>4)&0x3f)); + } + + TPRect const & GetTPRect(void) const + {return(MyRect);} + + char const * GetName(void) const + {return(Name);} + + void SetName(char const * NewName) + {Name=NewName;} + + void SetZeroColZero(bool New) + {ZeroColZero=New;} + + bool GetZeroColZero(void) const + {return(ZeroColZero);} + + void SetPlusColZero(bool New) + {PlusColZero=New;} + + bool GetPlusColZero(void) const + {return(PlusColZero);} + + void Write(Gofstream & Out) const; + void MakePSXPal(std::vector & OutWord) const; + u16 GetPsxCol(Colour const & Col) const; + +protected: + int PalIndex; + int TpBase; + int BaseTpX; + int BaseTpY; + bool ZeroColZero; + bool PlusColZero; + TPRect MyRect; + GString Name; + + void MakeCopy(SprPal const & NewPal) + { + Palette::CopyPal(NewPal); + PalIndex=NewPal.PalIndex; + TpBase=NewPal.TpBase; + BaseTpX=NewPal.BaseTpX; + BaseTpY=NewPal.BaseTpY; + MyRect=NewPal.MyRect; + Name=NewPal.Name; + ZeroColZero=NewPal.ZeroColZero; + PlusColZero=NewPal.PlusColZero; + } +}; + +/* A Frame of graphics with sprset specific stuff + ---------------------------------------------- */ +class SprFrame : public Frame +{ +public: + enum BDEPTH + { + BITS_4, + BITS_8, + }; + + SprFrame(void); + SprFrame(SprFrame const & NewFrame) + {MakeCopy(NewFrame);} + + void operator=(SprFrame const & NewFrame) + {MakeCopy(NewFrame);} + + void SetFrameAndInfo(Frame const & Fr,FileInfo const & MyFileInfo,int MaxSize); + FileInfo * GetFileInfo(void) + { + return (&MyFileInfo); + } + + void Process(void); + + void SetPalIndex(int NewPalIndex) + {PalIndex=NewPalIndex;} + + int GetPalIndex(void) const + {return(PalIndex);} + + void SetVRAMPos(TPRect const & Rect); + + BDEPTH GetBitDepth(void) const + { + BDEPTH RetDepth; + int NumOfCols; + + NumOfCols=MyPal.GetNumOfCols(); + + if (NumOfCols<=16) + RetDepth=BITS_4; + else + RetDepth=BITS_8; + + return(RetDepth); + } + + TPRect const & GetTPRect(void) const + {return(MyRect);} + + bool IsRotated(void) const + {return(MyRect.GetRotate());} + + void SetTpBase(int NewTpBase) + { + TpBase=NewTpBase; + BaseTpX=((TpBase&0xf)*64); + BaseTpY=(TpBase>>4)*256; + } + + void SetClut(u16 NewClut) + {Clut=NewClut;} + + u16 GetClut(void) const + {return(Clut);} + + void WriteHeader(Gofstream & Out); + + bool GetZeroColZero(void) const + {return(MyFileInfo.GetZeroColZero());} + + bool GetPlusColZero(void) const + {return(MyFileInfo.GetPlusColZero());} + + bool GetAllowRotate(void) const + {return(MyFileInfo.GetAllowRotate());} + + + void Write(Gofstream & Out) const; + + void WriteHeaderNotInVram(Gofstream & Out); + + + int getV(void) + {return(MyRect.X&0xff);} + + int getU(void) + { + u16 tpage; + int u; + int pageX; + + tpage=GetTpage(); + pageX=(tpage&0xf)*256; + u=MyRect.X-pageX; + + switch(GetBitDepth()) + { + case BITS_8: + u/=2; + break; + } + + return(u); + } + + u16 GetTpage(void) + { + int tp; + BDEPTH RetDepth; + + RetDepth=GetBitDepth(); + + int abr=0; + int x=BaseTpX + (MyRect.X/4); //MA + int y=BaseTpY + MyRect.Y; //MA + + switch(RetDepth) + { + case BITS_4: + tp=0; + break; + case BITS_8: + tp=1; + break; + } + + return((((tp)&0x3)<<7)|(((abr)&0x3)<<5)|(((y)&0x100)>>4)|(((x)&0x3ff)>>6)| (((y)&0x200)<<2)); + } + + bool IsAnimated() + { + return(MyFileInfo.getAllocateAs16Bit()); + } +protected: + void ResizeAndReduce(Frame & Frm,int TargCols,float XPerc,float YPerc,bool ZeroSeeThrough); + + + void MakeCopy(SprFrame const & NewFrame) + { + Frame::CopyFrame(NewFrame); + + Clut=NewFrame.Clut; + TpBase=NewFrame.TpBase; + BaseTpX=NewFrame.BaseTpX; + BaseTpY=NewFrame.BaseTpY; + PalIndex=NewFrame.PalIndex; + MyFileInfo=NewFrame.MyFileInfo; + MyRect=NewFrame.MyRect; + } + + + u16 Clut; + int TpBase; + int BaseTpX; + int BaseTpY; + + GString loadFileName; + + int PalIndex; + FileInfo MyFileInfo; + TPRect MyRect; +}; + +/* A collection of sprites + ----------------------- */ +class SprSet : protected GObject +{ +public: + SprSet(void) + { + Vi=NULL; + MaxSize=0; + } + + void SetMaxSize(int New) + {MaxSize=New;} + + void AddFiles(FIVec const & FileList); + + void Write(char const * FileName,int TpNumber,int WidthInTpages,int HeightInTpages); + void WriteLBM(char const * FileName); + void WriteSprFile(char const * Name); + void WriteReport(char const * Name); + void writeRawTPage(char const * File); + void SetIncOutFile(char const * NewIncOutFile) + {IncOutFile=NewIncOutFile;IncOutFile.Lower();} + + void setAnimatedHeader(bool newVal) + {m_AnimatedHeadersOnly=newVal;} + + void setDontOutputBoxes(bool newVal) + {m_DontOutputBoxes=newVal;} + + void setAlignHeaders(bool newVal) + {m_AlignHeaders=newVal;} + + void setHalfTpage(bool newVal) + {m_halfTpage=newVal;} + + void setCompressTpages(bool newVal) + {m_compressTpages=newVal;} + + void setNoWriteTpages(bool newVal) + {m_noWriteTpages=newVal;} + +protected: + void WriteHeaderFile(char const * HName); + + void ProcessPals(void); + void AddFile(FileInfo const & ThisInfo); + void AddAnm(FileInfo const & ThisInfo); + void AddLbm(FileInfo const & ThisInfo); + void AddFrame(Frame const & Fr,FileInfo const & ThisInfo); + + void AddFramesAndPalsToVRAM(VRAM & Vr,int TpNumber,int WidthInTpages,int HeightInPixels); + + GString GetHeaderFileName(char const * File); + + + typedef std::vector SprFrVec; + typedef std::vector::iterator SprFrIt; + + typedef std::vector SprPalVec; + typedef std::vector::iterator SprPalVecIt; + + GString IncOutFile; + + bool m_AnimatedHeadersOnly; + bool m_DontOutputBoxes; + bool m_AlignHeaders; + bool m_halfTpage; + bool m_compressTpages; + bool m_noWriteTpages; + + SprFrVec AllSprFrames; + SprPalVec AllSprPals; + VRAMImage * Vi; + + int MaxSize; +}; + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ + +/*---------------------------------------------------------------------- */ + +#else /* __SPRSET_H__ */ + +class SprPal; +class SprFrame; + +#endif + +/*=========================================================================== + end */ diff --git a/Utils/Libs/TexGrab/tpage.cpp b/Utils/Libs/TexGrab/tpage.cpp new file mode 100644 index 000000000..84921f5c6 --- /dev/null +++ b/Utils/Libs/TexGrab/tpage.cpp @@ -0,0 +1,857 @@ +/*========================================================================= + + FILENAME.CPP + + Author: Gary Liddon @ + Created: + Project: + Purpose: + + Copyright (c) 1997 Climax Development Ltd + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ +#include +#include "conio.h" + +/* Glib + ---- */ +#include "gutils.h" + +/* Local + ----- */ +#include "tpage.h" +#include "grect.h" + +/* Graphics + -------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +using namespace std; + + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +struct TPInfo +{ + int XAlign; + int TpWidth; + int BorderX; + int BorderY; +}; + +/* Information about where I can place this frame in the Tpage + ----------------------------------------------------------- */ +/*---------------------------------------------------------------------- + Vars + ---- */ +static TPInfo const InfStruct[TP_NUM_OF_TP_TYPES]= +{ + {1,256,1,1}, /* TP_4 */ + {2,512,2,1}, /* TP_8 */ + {4,256,4,1}, /* TP_16 */ + {0,0,0,0}, /* TP_SCREEN */ + {16*4,1024*4,0,0}, /* TP_PAL */ +}; + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ +int TPRect::W2Alloc=1; +int TPRect::H2Alloc=1; + +/*---------------------------------------------------------------------- + Data + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +VRAM::VRAM(int nTpWidth,int nTpHeightInPixels) +{ + Big2Little=false; + RotateEveryEmpty=false; + + + TpWidth=-1; + TpHeightInPixels=-1; + + Clear(nTpWidth,nTpHeightInPixels); +} + +void VRAM::Clear(int nTpWidth,int nTpHeightInPixels) +{ + if (nTpWidth >= 0 ) + TpWidth=nTpWidth; + + if (nTpHeightInPixels >= 0) + TpHeightInPixels=nTpHeightInPixels; + + InitEmpty(0,0,TpWidth*256,TpHeightInPixels); +} + + +/*---------------------------------------------------------------------- + Function: void VRAM::InitEmpty(void) + Purpose: Initialise the VRAM as empty + Params: + Returns: + ---------------------------------------------------------------------- */ +void VRAM::InitEmpty(int vX,int vY,int nW,int nH) +{ + const int Width16=256; + const int Height16=256; + + W=nW; + H=nH; + X=vX; + Y=vY; + + VRAMWidthPages=W/Width16; + VRAMHeightPages=H/Height16; + + if (!VRAMHeightPages) + { + VRAMHeightPages = 1; + } + + NumOfTPages=VRAMWidthPages*VRAMHeightPages; + + VecOfPages.resize(NumOfTPages,TPRectList()); + + Unused.reserve(4000); + Used.reserve(2000); + + Unused.resize(0); + Used.resize(0); + + for (int f=0;fXAlign; + + WorkingWidth=GU_AlignVal(ThisRect.W,Pi.XAlign); + + Pi.MinX=Tpi->BorderX; + Pi.MinY=Tpi->BorderY; + Pi.MaxX=W-Tpi->BorderX-WorkingWidth; + Pi.MaxY=H-Tpi->BorderY-ThisRect.H; + + Pi.TpWidthPix=Tpi->TpWidth; + + Pi.MinXTp=Tpi->BorderX; + Pi.MaxXTp=Tpi->TpWidth-Tpi->BorderX-WorkingWidth; + + Pi.MinYTp=Tpi->BorderY; + Pi.MaxYTp=(256-Tpi->BorderY)-ThisRect.H; +} + +bool VRAM::TryRect(TPRect & BlankRect,TPRect & ThisRect) +{ + POS_INFO Pi; + PosFromTPrect(ThisRect,Pi); + + int MinTpX=Pi.MinXTp+(BlankRect.X/Pi.TpWidthPix)*Pi.TpWidthPix; + int MaxTpX=Pi.MaxXTp+(BlankRect.X/Pi.TpWidthPix)*Pi.TpWidthPix; + int MinTpY=Pi.MinYTp+(BlankRect.Y/256)*256; + int MaxTpY=Pi.MaxYTp+(BlankRect.Y/256)*256; + + /* Move to avoid edges of the map */ + int MinX = MinTpX > Pi.MinX ? MinTpX : Pi.MinX; + int MaxX = MaxTpX < Pi.MaxX ? MaxTpX : Pi.MaxX; + int MinY = MinTpY > Pi.MinY ? MinTpY : Pi.MinY; + int MaxY = MaxTpY < Pi.MaxY ? MaxTpY : Pi.MaxY; + + int ThisX=GU_AlignVal(BlankRect.X,Pi.XAlign); + int ThisY=BlankRect.Y; + + if (ThisXMaxX) + return(false); + + if (ThisYMaxY) + return(false); + + ThisRect.SetXY(ThisX,ThisY); + + if (!InColisionWithUsed(ThisRect)) + { + RemovedFromUnused(ThisRect); + AddToUsed(ThisRect); + return(true); + } + + return(false); +} + +/*---------------------------------------------------------------------- + Function: TPRect VRAM::AllocVRAM(TPageType nType,int nW,int nH,bool Rotated) + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +class Predicate +{ +public: + bool operator()(TPRect const & R1,TPRect const & R2) const + { + u32 R1Val=(R1.H<<16)|(R1.W); + u32 R2Val=(R2.H<<16)|(R2.W); + return (R1ValR2Val); + } +}; + +/*---------------------------------------------------------------------- + Function: TPRect VRAM::AllocVRAM(TpRectVec & RectVec) + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +bool VRAM::AllocVRAM(TPRectVec & RectVec,bool nRotateEveryEmpty,bool nBig2Little,bool nWiderThanHigher) +{ + int f; + + RotateEveryEmpty=nRotateEveryEmpty; + Big2Little=nBig2Little; + WiderThanHigher=nWiderThanHigher; + + if (WiderThanHigher) + { + for (f=0;f RectVec[f].W) && CanRotate(RectVec[f])) + RectVec[f].SetRotate(!RectVec[f].GetRotate()); + } + } + + if (!Big2Little) + std::sort(RectVec.begin(),RectVec.end(),Predicate()); + else + std::sort(RectVec.begin(),RectVec.end(),Predicate2()); + + bool AllocedEverything=true; + + for (f=0;f + +/* Glib + ---- */ +#include + +/* Local + ----- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ +struct POS_INFO +{ + int MinXTp; /* Minimum x placeable within a Tpage */ + int MaxXTp; /* Maximum x placeable within a Tpage */ + + int MinYTp; /* Minimum y placeable within a Tpage */ + int MaxYTp; /* Maximum y placeable within a Tpage */ + + int MinX; /* Minimum global x */ + int MaxX; /* Maximum global x */ + + int MinY; /* Minimum global y */ + int MaxY; /* Maximum global y */ + + int XAlign; /* X Alignment */ + int TpWidthPix; /* Width of each tpages for this rect */ +}; + + +/* Different Tpage Types + --------------------- */ +enum TPageType +{ + TP_4= 0, + TP_8, + TP_16, + TP_SCREEN, + TP_PAL, + TP_NUM_OF_TP_TYPES, +}; + + +/* A Rectangle in the Tpage + ------------------------ */ +class TPRect : public Rect +{ +public: + TPRect(void); + TPRect(TPageType nType,int nW,int nH); + TPRect(TPRect const & NewR) {MakeCopy(NewR);} + + void InitFromFrame(Frame const & Fr); + void SetAlloced(bool nAlloced=true); + bool SetRotate(bool Rot=true); + void operator=(TPRect const & NewR) {MakeCopy(NewR);} + bool operator< (TPRect const & R) const {return(GetId() TPRectVec; + +/* VRAM + ---- */ + +typedef std::list TPRectList; +typedef std::vector TPRectListVec; + +class VRAM : public GObject +{ +public: + VRAM(int nTpWidth=16,int nTpHeightInPixels=512); + + int GetNumOfItems(void); + int GetNumOfUsedPages(); + + bool AllocVRAM(TPRect & OriginalRect); + bool AllocVRAM(TPRectVec & RectVec,bool nRotateEveryEmpty,bool nBig2Little,bool nWiderThanHigher); + + TPRect const & GetVRAM(VHND hnd) const; + + TPRectVec & GetUsed(void) + {return(Used);} + + TPRectVec & GetUnused(void) + {return(Unused);} + + void Clear(int nTpWidth=-1,int nTpHeight=-1); + + void SetBig2Little(bool Val=true) + { Big2Little=Val;} + + void SetRotateEveryEmpty(bool Val=true) + { RotateEveryEmpty=Val;} + + bool CanRotate(TPRect & ThisRect); + + void getUnusedSpace(TPRectVec & unusedBoxes); + +protected: + void PosFromTPrect(TPRect & ThisRect,POS_INFO & Pi); + bool TryRect(TPRect & BlankRect,TPRect & ThisRect); + + TPRectListVec VecOfPages; + + bool TryNFit(TPRectList & TpList,TPRect & ThisRect); + + void AddEmpty(int x,int y,int w,int h); + bool InColisionWithUsed(TPRect const & R); + void InitEmpty(int vX,int vY,int W,int H); + bool CheckValidAlloc(TPageType nType,int nW,int nH); + int GetXAlign(TPageType nType); + int GetMaxWidthTp(TPageType nType); + void RemovedFromUnused(TPRect const & ThisRect); + void AddToUsed(TPRect const & ThisRect); + void RectFromTpRect(Rect & R,TPRect const & ThisRect); + + TPRect & NewItem(TPRectVec & TPRects); + + TPRect & NewUnused(void) + { return(NewItem(Unused)); } + + TPRect & NewUsed(void) + { return(NewItem(Used)); } + + + TPRectVec Unused; + TPRectVec Used; + TPRect ErrorRect; + + int X,Y,W,H; + int NumOfTPages; + int TpWidth; + int TpHeightInPixels; + + int VRAMWidthPages; + int VRAMHeightPages; + + bool Big2Little; + bool RotateEveryEmpty; + bool WiderThanHigher; +}; + +/* Error codes for VHND + -------------------- */ +enum +{ + VHND_NULL = -1, +}; + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ +void TestTPageStuff(void); + +/*---------------------------------------------------------------------- */ + +#endif /* __TPAGE_HPP__ */ + +/*=========================================================================== + end */ + + diff --git a/Utils/Libs/TexGrab/vimage.h b/Utils/Libs/TexGrab/vimage.h new file mode 100644 index 000000000..43a1d4b43 --- /dev/null +++ b/Utils/Libs/TexGrab/vimage.h @@ -0,0 +1,103 @@ +/*========================================================================= + + VIMAGE.CPP + + Author: Gary Liddon @ Climax + Created: + Project: TPW Parkgrab + Purpose: An object that represents a bit of VRAM + + Copyright (c) 1998 G R Liddon + +===========================================================================*/ + +#ifndef __VIMAGE_H__ +#define __VIMAGE_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/* Glib + ---- */ +#include +#include + +/* Local + ----- */ +#include "sprset.h" + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +class VRAMImage : protected GObject +{ +public: + + VRAMImage(int NewWidthInTpages,int NewHeightInPixels); + ~VRAMImage(void); + + void WriteInTpageChunks(std::ofstream & Str); + void Write(std::ofstream & Str); + void PlotPal(SprPal const & PalToPlot); + void PlotFrame(SprFrame const & FrameToPlot); + void SaveAs16ColLbm(const char * Name); + + void setDoCompress(bool newVal) + {m_doCompress=newVal;} + + bool getDoCompress(void) const + {return(m_doCompress);} + + void getTpData(unsigned int tp,std::vector & dest) const; + +protected: + void PlotFrame4(SprFrame const & Fr); + void PlotFrame8(SprFrame const & Fr); + u16 GetPsxCol(Colour const & Col) const; + + int WidthInBytes; + int WidthInTpages; + int HeightInTPages; + int HeightInPixels; + int aTPageHeight; + int TPageSizeInBytes; + int VramAreaBytes; + bool m_doCompress; + + u8 * lbmData; + u8 * VRAMData; +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/* Vars + ---- */ + +/* Data + ---- */ + +/* Functions + --------- */ + +/*---------------------------------------------------------------------- */ + +#else /* __VIMAGE_H__ */ + +class VRAMImage; + +#endif + +/*=========================================================================== + end */