This commit is contained in:
Daveo 2000-12-02 18:55:49 +00:00
parent 7551b4f12e
commit 8788076d39
37 changed files with 11186 additions and 0 deletions

61
Utils/Libs/DaveLib/List.h Normal file
View File

@ -0,0 +1,61 @@
/**********************/
/*** Vtx List Class ***/
/**********************/
#if !defined __VTXLIST_CLASS_HEADER__
#define __VTXLIST_CLASS_HEADER__
#include <Vector>
/*****************************************************************************/
template <class T> class CList
{
public:
int Find(T &Item)
{
int ListSize=List.size();
for (int i=0; i<ListSize; i++)
{
if (List[i]==Item) return(i);
}
return(-1);
}
int Add(T &Item)
{
int ListSize=List.size();
int Idx=Find(Item); // Check if exists
if (Idx!=-1) return(Idx);
List.push_back(Item);
return(ListSize);
}
int push_back(T &Item)
{
int ListSize=List.size();
List.push_back(Item);
return(ListSize);
}
void clear()
{
List.clear();
}
int size() {return(List.size());}
std::vector<T> &GetList() {return(List);}
T& operator []( int nIndex ) {return(List[nIndex]);}
private:
std::vector<T> List;
};
/*****************************************************************************/
#endif

29
Utils/Libs/GLib/GLib.dsw Normal file
View File

@ -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>
{{{
}}}
###############################################################################

346
Utils/Libs/GLib/Glib.dsp Normal file
View File

@ -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

View File

@ -0,0 +1,270 @@
/*=========================================================================
ANIMHEADER.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <strstream>
/* Glib
---- */
#include <pcre.h>
#include <gobject.hpp>
/* 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<AnimHeaderItem> & 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<AnimHeaderItem> items;
readAnimHeaderFile(name,items);
int numOfItems;
numOfItems=items.size();
for (int f=0;f<numOfItems;f++)
{
AnimHeaderItem dummyResult;
// if (find(items[f].m_texName,dummyResult))
// GObject::Error(ERR_FATAL,"%s already defined in anim header file database",(char const *)items[f].m_texName);
// makeTexNameCompliant(items[f].m_texName);
// m_strToInfo[items[f].m_texName]=items[f];
}
m_lastLoadedFile=name;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void AnimHeaderFile::makeTexNameCompliant(GString & str)
{
str.Lower();
str.Filter("\\",'/');
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool AnimHeaderFile::find(GString const & str,AnimHeaderItem & result)
{
GString srchStr;
map<GString,AnimHeaderItem>::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 */

View File

@ -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 <vector>
#include <map>
/* Glib
---- */
#include <gtypes.h>
#include <gstring.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
struct AnimHeaderItem
{
GString m_AnimName;
int m_Frame;
};
class AnimHeaderFile
{
private:
GString m_lastLoadedFile;
std::map<GString,AnimHeaderItem> 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<AnimHeaderItem> & Items);
/*---------------------------------------------------------------------- */
#endif /* __ANIMHEADER_H__ */
/*===========================================================================
end */

180
Utils/Libs/GinLib/ginio.cpp Normal file
View File

@ -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<GinChunk *> 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;f<ChunkHandlers.size() && !RetChunk;f++)
{
if (ChunkName==GString(ChunkHandlers[f]->GetName()))
RetChunk=ChunkHandlers[f]->MakeNew();
}
return(RetChunk);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool GinFile::GinHdr::ReadHdr(Gifstream & In)
{
vector<char> 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 */

233
Utils/Libs/GinLib/ginio.h Normal file
View File

@ -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 <vector>
#include <fstream>
#include <misc.hpp>
#include <gstring.hpp>
/* 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<u8> Data;
};
class GinFile : public GObject
{
public:
GinFile(void)
{
ReadUnknownChunks=false;
}
~GinFile(void)
{
int i;
for (i=0; i<ChunkHandlers.size(); i++) delete ChunkHandlers[i];
ChunkHandlers.clear();
for (i=0; i<Chunks.size(); i++) delete Chunks[i];
Chunks.clear();
}
void ResetChunks()
{
for (int f=0;f<Chunks.size();f++) delete Chunks[f];
Chunks.clear();
}
void SetReadUnknownChunks(bool New)
{
ReadUnknownChunks=New;
}
static void AddHandler(GinChunk * New);
void Load(char const * File)
{
ResetChunks();
Gifstream In(Gifstream::LITTLE_ENDIAN);
In.open(File,std::ios::binary);
if (In)
{
GinHdr MyHdr;
while (MyHdr.ReadHdr(In))
{
int ChunkLenAligned;
int ChunkPos;
GinChunk * ChunkReader;
ChunkReader=GetHandler(MyHdr.Name);
if (!ChunkReader && ReadUnknownChunks)
ChunkReader=new GinChunk;
ChunkLenAligned=GU_AlignVal(MyHdr.Size,4);
ChunkPos=In.tellg();
if (ChunkReader)
{
ChunkReader->SetNameSize(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<GinChunk const *> & RetChunks)
{
int NumOfChunks;
NumOfChunks=0;
for (int f=0;f<Chunks.size();f++)
{
GString Name;
Name=Chunks[f]->GetName();
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<GinChunk *> Chunks;
bool ReadUnknownChunks;
static std::vector<GinChunk *> ChunkHandlers;
static GinChunk * GetHandler(char const * Name);
};
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
/*---------------------------------------------------------------------- */
#endif /* __GINIO_H__ */
/*===========================================================================
end */

View File

@ -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

View File

@ -0,0 +1,970 @@
#include <algorithm>
#include <gfname.hpp>
#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<Len;Loop++)
{
char C0=Str0[Loop];
char C1=Str1[Loop];
if (C0>='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<m; i++)
{
for (int j=0; j<8; j++)
In.Get32();
int tf = (int)In.Get32();
int temp2 = In.Get32();
if (temp2&1 == 0)
{
tf = -1;
}
Mats[i].TexId = tf;
Mats[i].Flags = temp2;
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CMesh::Load(Gifstream & In)
{
Obj = In.Get32();
int NbMesh = In.Get32();
Chunk.resize(NbMesh);
for (int i=0; i<NbMesh; i++)
{
Chunk[i].MatId = s16(In.Get16());
Chunk[i].NumFace = s16(In.Get16());
Chunk[i].MeshNum = In.Get32();
Chunk[i].Attrib = In.Get32();
Chunk[i].Normals = In.Get32();
Chunk[i].Vcol = In.Get32();
Chunk[i].Tex = In.Get32();
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CMod4::Load(Gifstream & In)
{
Mod4Chunk ThisChunk;
In.read((char*)&ThisChunk.nCurObj , sizeof(long));
In.read(ThisChunk.Name, 32);
In.read((char*)&ThisChunk.Radius, sizeof(float));
In.read((char*)&ThisChunk.CentreX, sizeof(float));
In.read((char*)&ThisChunk.CentreY, sizeof(float));
In.read((char*)&ThisChunk.CentreZ, sizeof(float));
In.read((char*)&ThisChunk.ApX, sizeof(float));
In.read((char*)&ThisChunk.ApY, sizeof(float));
In.read((char*)&ThisChunk.ApZ, sizeof(float));
Chunk.push_back(ThisChunk);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CTexName::Load(Gifstream & In)
{
int NumOfNames;
NumOfNames=In.Get32();
for (int f=0;f<NumOfNames;f++)
{
vector<char> 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<ChildCount;Loop++) LoadTree(In,Idx);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CSkinTree::Load(Gifstream & In)
{
In.Get32(); // Skip Obj number
LoadTree(In,-1);
}
/*****************************************************************************/
void CSkinTree::LoadTree(Gifstream & In,int Parent)
{
CNode ThisNode;
int WeightCount;
In.Align(4);
In.read(ThisNode.Name, 32);
WeightCount=In.Get32();
if (WeightCount)
{
ThisNode.Weights.resize(WeightCount);
for (int Weight=0;Weight<WeightCount;Weight++)
{
ThisNode.Weights[Weight].VertNo=In.Get32();
In.read((char*)&ThisNode.Weights[Weight].Weight, 4);
In.read((char*)&ThisNode.Weights[Weight].X, 4);
In.read((char*)&ThisNode.Weights[Weight].Y, 4);
In.read((char*)&ThisNode.Weights[Weight].Z, 4);
}
}
int ChildCount= In.Get32();
SkinTree[0].AddChild( SkinTree,ThisNode,Parent);
int Idx=ThisNode.Idx;
for (int Loop=0;Loop<ChildCount;Loop++) LoadTree(In,Idx);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
const int CHANNEL_TYPE_TREE = 7; // NODE ANIMATION
void CAnimTree::Load(Gifstream & In)
{
int AnimType=In.Get32();
if (AnimType!=CHANNEL_TYPE_TREE) return;
int FrameCount = In.Get32();
LoadTree(In,-1,FrameCount);
}
/*****************************************************************************/
void CAnimTree::LoadTree(Gifstream & In,int Parent,int FrameCount)
{
CNode ThisNode;
In.Align(4);
ThisNode.Anim.resize(FrameCount);
for (int Frame=0;Frame<FrameCount;Frame++)
{
In.read((char*)&ThisNode.Anim[Frame].XPos, 4);
In.read((char*)&ThisNode.Anim[Frame].YPos, 4);
In.read((char*)&ThisNode.Anim[Frame].ZPos, 4);
In.read((char*)&ThisNode.Anim[Frame].XAng, 4);
In.read((char*)&ThisNode.Anim[Frame].YAng, 4);
In.read((char*)&ThisNode.Anim[Frame].ZAng, 4);
In.read((char*)&ThisNode.Anim[Frame].WAng, 4);
In.read((char*)&ThisNode.Anim[Frame].kX, 4);
In.read((char*)&ThisNode.Anim[Frame].kY, 4);
In.read((char*)&ThisNode.Anim[Frame].kZ, 4);
In.read((char*)&ThisNode.Anim[Frame].uX, 4);
In.read((char*)&ThisNode.Anim[Frame].uY, 4);
In.read((char*)&ThisNode.Anim[Frame].uZ, 4);
In.read((char*)&ThisNode.Anim[Frame].uW, 4);
}
int ChildCount= In.Get32();
AnimTree[0].AddChild( AnimTree,ThisNode,Parent);
int Idx=ThisNode.Idx;
for (int Loop=0;Loop<ChildCount;Loop++) LoadTree(In,Idx,FrameCount);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CKeyAnimTree::Load(Gifstream & In)
{
int AnimType=In.Get32();
if (AnimType!=CHANNEL_TYPE_TREE) return;
AnimType=In.Get32(); // Skip Node type thingy
LoadTree(In,-1);
}
/*****************************************************************************/
void CKeyAnimTree::LoadTree(Gifstream & In,int Parent)
{
CNode ThisNode;
int KeyCount;
In.Align(4);
KeyCount=In.Get32();
ThisNode.KeyAnim.resize(KeyCount);
for (int Frame=0;Frame<KeyCount;Frame++)
{
ThisNode.KeyAnim[Frame].Frame=In.Get32();
In.read((char*)&ThisNode.KeyAnim[Frame].XPos, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].YPos, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].ZPos, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].XAng, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].YAng, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].ZAng, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].WAng, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].kX, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].kY, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].kZ, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].uX, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].uY, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].uZ, 4);
In.read((char*)&ThisNode.KeyAnim[Frame].uW, 4);
}
int ChildCount= In.Get32();
AnimTree[0].AddChild( AnimTree,ThisNode,Parent);
int Idx=ThisNode.Idx;
for (int Loop=0;Loop<ChildCount;Loop++) LoadTree(In,Idx);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
bool CScene::SetPruneNodes(int Idx)
{
CNode &ThisNode=GetNode(Idx);
bool NoPrune=false;
int ChildCount=ThisNode.GetChildCount();
for (int Loop=0;Loop<ChildCount;Loop++) NoPrune|= SetPruneNodes(ThisNode.ChildList[Loop]);
int HasData=ThisNode.Weights.size() | ThisNode.Pts.size();
if (!NoPrune && !HasData)
{
ThisNode.Active=false;
return(false);
}
else
{
return(true);
}
}
/*****************************************************************************/
void CScene::BuildPruneTree(int Idx, int ParentIdx)
{
CNode &ThisNode=GetNode(Idx);
if (!ThisNode.Active) return;
ThisNode.AddPruneChild(SceneTree,PruneTree,ParentIdx);
int ChildCount=ThisNode.GetChildCount();
for (int Loop=0;Loop<ChildCount;Loop++) BuildPruneTree(ThisNode.ChildList[Loop],ThisNode.Idx);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
int IsAnimDiff(sGinAnim const &Frm0,sGinAnim const &Frm1)
{
if (Frm0.XPos!=Frm1.XPos) return(1);
if (Frm0.YPos!=Frm1.YPos) return(1);
if (Frm0.ZPos!=Frm1.ZPos) return(1);
if (Frm0.XAng!=Frm1.XAng) return(1);
if (Frm0.YAng!=Frm1.YAng) return(1);
if (Frm0.ZAng!=Frm1.ZAng) return(1);
if (Frm0.WAng!=Frm1.WAng) return(1);
return(0);
}
/*****************************************************************************/
void LoadAndShrinkAnim(CNode const &KeyNode,CNode const &AnimNode,CNode &OutNode)
{
// Calc Extents from Key Frames
int Key,Frame;
int StartKey=0,EndKey=KeyNode.KeyAnim.size();
if (!EndKey) // No keys, create 1 and return
{
sGinAnim ForceKey;
ForceKey.Frame=0;
ForceKey.XPos=OutNode.XPos; ForceKey.YPos=OutNode.YPos; ForceKey.ZPos=OutNode.ZPos;
ForceKey.XAng=OutNode.XAng; ForceKey.YAng=OutNode.YAng; ForceKey.ZAng=OutNode.ZAng; ForceKey.WAng=OutNode.WAng;
OutNode.KeyAnim.push_back(ForceKey);
OutNode.ShrunkKeyAnim.push_back(ForceKey);
EndKey=0;
OutNode.StartFrame= 0;
OutNode.EndFrame= 0;
}
else
{
EndKey--;
while ((!IsAnimDiff(KeyNode.KeyAnim[StartKey], KeyNode.KeyAnim[StartKey+1])) && StartKey!=EndKey) StartKey++;
while ((!IsAnimDiff(KeyNode.KeyAnim[EndKey ], KeyNode.KeyAnim[EndKey-1])) && StartKey!=EndKey) EndKey--;
OutNode.StartFrame= KeyNode.KeyAnim[StartKey].Frame;
OutNode.EndFrame= KeyNode.KeyAnim[EndKey].Frame;
EndKey++;
}
OutNode.EndFrame++;
// Transfer Key Frames
int KeyAnimSize=KeyNode.KeyAnim.size();
for (Key=0;Key<KeyAnimSize;Key++) OutNode.KeyAnim.push_back(KeyNode.KeyAnim[Key]); // Transfer All key frames
for (Key=StartKey; Key<EndKey; Key++) OutNode.ShrunkKeyAnim.push_back(KeyNode.KeyAnim[Key]); // Transfer Shrunk key frames
// Transfer Normal frames
int AnimSize=AnimNode.Anim.size();
if (AnimSize)
{
for (Frame=0;Frame<AnimSize;Frame++) OutNode.Anim.push_back(AnimNode.Anim[Frame]); // Transfer All Normal Anim
for (Frame=OutNode.StartFrame; Frame<OutNode.EndFrame; Frame++) OutNode.ShrunkAnim.push_back(AnimNode.Anim[Frame]); // Transfer Shrunk Normal Anim
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void Gin4File::Load(char const * Name)
{
MyFile.Load(Name);
MyFile.FindChunks("VERS",VersionChunk);
MyFile.FindChunks("TEX4",TexNamesChunk);
MyFile.FindChunks("MAT4",MatChunk);
MyFile.FindChunks("MOD4",Mod4Chunk);
MyFile.FindChunks("MESH",MshChunk);
MyFile.FindChunks("PTS4",PointsChunk);
MyFile.FindChunks("POLY",TrisChunk);
MyFile.FindChunks("VCOL",VColTrisChunk);
MyFile.FindChunks("MAP4",UVtrisChunk);
MyFile.FindChunks("TREE",SceneTreeChunk);
MyFile.FindChunks("ANIM",AnimTreeChunk);
MyFile.FindChunks("KEY4",KeyAnimTreeChunk);
MyFile.FindChunks("BONE",SkinTreeChunk);
MyFile.FindChunks("PROP",UserPropChunk);
MyFile.FindChunks("CAM4",CameraChunk);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CScene::Load(const char *Name)
{
Gin4File GinFile;
FileName=Name;
MTH_Init();
GinFile.Load(Name);
std::vector<GinChunk const *> &VersionChunk=GinFile.GetVersionChunk();
std::vector<GinChunk const *> &TexNamesChunk=GinFile.GetTexNamesChunk();
std::vector<GinChunk const *> &MatChunk=GinFile.GetMatChunk();
std::vector<GinChunk const *> &MshChunk=GinFile.GetMshChunk();
std::vector<GinChunk const *> &PointsChunk=GinFile.GetPointsChunk();
std::vector<GinChunk const *> &TrisChunk=GinFile.GetTrisChunk();
std::vector<GinChunk const *> &VColTrisChunk=GinFile.GetVColTrisChunk();
std::vector<GinChunk const *> &UVtrisChunk=GinFile.GetUVtrisChunk();
std::vector<GinChunk const *> &SceneTreeChunk=GinFile.GetSceneTreeChunk();
std::vector<GinChunk const *> &AnimTreeChunk=GinFile.GetAnimTreeChunk();
std::vector<GinChunk const *> &KeyAnimTreeChunk=GinFile.GetKeyAnimTreeChunk();
std::vector<GinChunk const *> &SkinTreeChunk=GinFile.GetSkinTreeChunk();
std::vector<GinChunk const *> &UserPropChunk=GinFile.GetUserPropChunk();
std::vector<GinChunk const *> &CameraChunk=GinFile.GetCameraChunk();
int Node,NodeCount;
// Build Scene Tree
CGinTree *GT = (CGinTree*)SceneTreeChunk[0];
std::vector<CNode> const &GinTree=GT->GetTree();
NodeCount=GinTree.size();
for (Node=0;Node<NodeCount;Node++)
{
CNode ThisNode=GinTree[Node];
SceneTree[0].AddChild(SceneTree,ThisNode,ThisNode.ParentIdx);
}
// Build Node Mtx's
for (Node=0;Node<NodeCount;Node++)
{
CNode *ThisNode=&SceneTree[Node];
int ParentIdx=ThisNode->ParentIdx;
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;Node<NodeCount;Node++)
{
CNode GinNode=GinTree[Node];
SceneTree[0].AddChild(SceneTree,GinNode,GinNode.ParentIdx);
// Build Node Mtx's
CNode ThisNode=SceneTree[Node];
SceneTree[Node].Mtx=Identity;
if (GinNode.ParentIdx!=-1)
{
TMATRIX ThisMtx,ParentMtx;
CNode *ParentNode=&SceneTree[ThisNode.ParentIdx];
ParentMtx=ParentNode->Mtx;
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<GString> const & Strs=T->GetTexNames();
TextureList = Strs;
int NumOfMeshes=MshChunk.size();
for (int j=0; j<NumOfMeshes; j++)
{
CMesh *M = (CMesh*)MshChunk[j];
vector<MeshChunk> const & Mat4Id = M->GetChunk();
for (int i=0; i<Mat4Id.size(); i++)
{
if (Mat4Id[i].MatId>=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; m<MshChunk.size(); m++)
{
CMesh *M = (CMesh*)MshChunk[m];
int CurMod = M->getObj();
CNode *ThisNode=GetNodePtr(GinFile.GetModelName(CurMod));
if (loadPoints( CurMod, PointsChunk,ThisNode) != -1)
{
vector<MeshChunk> const &MeshChunks = M->GetChunk();
for (int mn=0; mn<MeshChunks.size(); mn++)
{
if (loadTris( CurMod, MeshChunks[mn].MeshNum, TrisChunk,ThisNode)!=-1)
{
int MatIdx = addMaterialIdx(MeshChunks[mn].MatId);
for (int i=0; i<MeshChunks[mn].NumFace; i++) ThisNode->TriMaterial.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::vector<CNode>const &KeyAnimTree=KATC->GetTree();
std::vector<CNode>const &AnimTree=NATC->GetTree();
NodeCount=KeyAnimTree.size();
for (Node=0;Node<NodeCount;Node++)
{
LoadAndShrinkAnim(KeyAnimTree[Node],AnimTree[Node],SceneTree[Node]);
}
//-----------------------------------------------------------------------------
// Load Camera(s)
int CamCount=CameraChunk.size();
if (CamCount)
{
for (int Cam=0;Cam<CamCount;Cam++)
{
CCamera *CamC= (CCamera *)CameraChunk[Cam];
Camera.push_back(CamC->GetCam());
}
}
//-----------------------------------------------------------------------------
// Load Skin Weight
if (SkinTreeChunk.size())
{
CSkinTree *ST = (CSkinTree*)SkinTreeChunk[0];
std::vector<CNode> const &SkinTree=ST->GetTree();
NodeCount=SkinTree.size();
for (Node=0;Node<NodeCount;Node++)
{
int WeightCount=SkinTree[Node].Weights.size();
if (WeightCount)
{
SceneTree[Node].Weights.resize(WeightCount);
for (int Weight=0;Weight<WeightCount;Weight++) SceneTree[Node].Weights[Weight]=SkinTree[Node].Weights[Weight];
}
}
}
//-----------------------------------------------------------------------------
// Load User Props - Loaded as Ini File
int PropCount=UserPropChunk.size();
for (int Loop=0;Loop<PropCount;Loop++)
{
CUserProp *UP=(CUserProp*)UserPropChunk[Loop];
if (UP)
{
CNode *ThisNode=GetNodePtr(UP->GetModNum()+1); // Skip SceneRoot);
if (ThisNode)
{
std::vector<char> const & Prop=UP->GetUserProp();
int Size=Prop.size()-1;
if (Size>0)
{
// ThisNode->UserProp.resize(Size);
// for (int c=0;c<Size;c++) ThisNode->UserProp[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<int> 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<PrintTreeSpace;Sp++) printf("| ");
printf("(P=%i I=%i C=%i) %s - T=%i, V=%i A=%i\n",NodeParentIdx,NodeIdx,ChildCount,Node.Name,Node.Tris.size(),Node.Pts.size(),Node.Anim.size());
PrintTreeSpace++;
for (int Child=0;Child<ChildCount;Child++) PrintTreeNode(ChildList[Child],Tree);
PrintTreeSpace--;
*/
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
int CScene::loadPoints( int CurMod, vector<GinChunk const *> &Points ,CNode *ThisNode)
{
for (int f=0; f<Points.size(); f++)
{
CPts4 * T;
T=(CPts4 *)(Points[f]);
if (T->GetModNum() == CurMod)
{
std::vector<TVECTOR> 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;g<Size;g++)
{
/*Abs Pnt*/ ThisNode->Pts[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<GinChunk const *> &Tris,CNode *ThisNode)
{
for (int i=0; i<Tris.size(); i++)
{
CPoly * T;
T=(CPoly *)(Tris[i]);
if (T->GetModNum() == CurMod && T->GetMeshNum() == CurMesh)
{
std::vector<sGinTri> const & TheseTris=T->GetTris();
int Size = TheseTris.size();
ThisNode->TriBase=ThisNode->Tris.size();
for (int j=0; j<Size; j++) ThisNode->Tris.push_back(TheseTris[j]);
return (Size);
}
}
return -1;
}
/*****************************************************************************/
int CScene::loadUV( int CurMod, int CurMesh, vector<GinChunk const *> &UVTris,CNode *ThisNode)
{
for (int i=0; i<UVTris.size(); i++)
{
CUVtri *T;
T = (CUVtri*)UVTris[i];
if (T->GetModNum() == CurMod && T->GetMeshNum() == CurMesh)
{
std::vector<sUVTri> const & TheseTris=T->GetUVTris();
int Size = TheseTris.size();
for (int j=0; j<Size; j++) ThisNode->UVTris.push_back(TheseTris[j]);
return (Size);
}
}
return -1;
}
/*****************************************************************************/
int CScene::loadVCol( int CurMod, int CurMesh, vector<GinChunk const *> &VColTris,CNode *ThisNode)
{
for (int i=0; i<VColTris.size(); i++)
{
CVcol *T;
T = (CVcol*)VColTris[i];
if (T->GetModNum() == CurMod && T->GetMeshNum() == CurMesh)
{
std::vector<sVColTri> const & TheseTris=T->GetVcolTris();
int Size = TheseTris.size();
for (int j=0; j<Size; j++) ThisNode->VColTris.push_back(TheseTris[j]);
return (Size);
}
}
return -1;
}
/*****************************************************************************/
int CScene::addMaterialIdx( int idx )
{
int c = UsedMaterials.size();
for (int i=0; i<c; i++)
{
if (UsedMaterials[i] == idx) return i;
}
UsedMaterials.push_back(idx);
return c;
}
/*****************************************************************************/
static GString GetNameAndExtOnly(char const * Name)
{
GString Rep(Name);
Rep.Filter("/",'\\');
GFName FName(Rep);
Rep=FName.File();
Rep+=".";
Rep+=FName.Ext();
Rep.Lower();
return(Rep);
}
/*****************************************************************************/
void CScene::GetNonSharedTextures(vector<GString> const & SharedTextures,vector<GString> & Dest)
{
for (int f=0;f<AllTexNames.size();f++)
{
bool Found;
Found=false;
GString NameOnly(GetNameAndExtOnly(AllTexNames[f]));
for (int t=0;t<SharedTextures.size() && !Found;t++)
{
GString TexNameOnly(GetNameAndExtOnly(SharedTextures[t]));
Found=TexNameOnly==NameOnly;
}
if (!Found)
{
GFName TexName(AllTexNames[f]);
GFName GinName(FileName);
GinName.File(TexName.File());
GinName.Ext(TexName.Ext());
GString FinalName(GinName.FullName());
FinalName.Lower();
Dest.push_back(FinalName);
}
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
TMATRIX GetWorldMatrix(std::vector<CNode> 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<CNode> 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));
}

780
Utils/Libs/GinLib/gintex.h Normal file
View File

@ -0,0 +1,780 @@
/********************/
/*** Daves GinTex ***/
/********************/
#pragma warning( disable : 4786 )
#ifndef __GINTEX_H__
#define __GINTEX_H__
#include <vector>
#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<Material> 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<Material> 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<MeshChunk> const & GetChunk(void) const {return(Chunk);}
int getObj( void ) const {return Obj;}
protected:
int Obj;
std::vector<MeshChunk> 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<Mod4Chunk> const & GetChunk(void) const {return(Chunk);}
char * GetModelName() {return(Chunk[0].Name);}
protected:
std::vector<Mod4Chunk> 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<GString> const & GetTexNames(void) const {return(Names);}
virtual GinChunk * MakeNew(void) {return(new CTexName);}
virtual void Load(Gifstream & In);
protected:
std::vector<GString> 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<TVECTOR> const & GetPts(void) const {return(Pnts);}
int GetModNum(void) const {return ModNum;}
protected:
int ModNum;
std::vector<TVECTOR> 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<nf; i++)
{
for (int j=0; j<3; j++) Tris[i].p[j] = In.Get32();
for (int h=0; h<3; h++) Tris[i].vis[h] = In.Get32();
}
}
public:
std::vector<sGinTri> const & GetTris(void) const {return(Tris);}
int GetModNum(void) const {return ModNum;}
int GetMeshNum(void) const {return MeshNum;}
protected:
int ModNum,MeshNum;
std::vector<sGinTri> 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<nf; i++)
{
for (int j=0; j<3; j++)
{
float r,g,b;
In.read((char*)&r, 4);
In.read((char*)&g, 4);
In.read((char*)&b, 4);
Tris[i].p[j].r = r;
Tris[i].p[j].g = g;
Tris[i].p[j].b = b;
}
}
}
public:
std::vector<sVColTri> const & GetVcolTris(void) const {return(Tris);}
int GetModNum(void) const {return ModNum;}
int GetMeshNum(void) const {return MeshNum;}
protected:
int ModNum,MeshNum;
std::vector<sVColTri> 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<nf; i++)
{
for (int j=0; j<3; j++)
{
float u,v;
In.read((char*)&u, 4);
In.read((char*)&v, 4);
Tris[i].p[j].u = u;
Tris[i].p[j].v = v;
}
}
}
public:
std::vector<sUVTri> const & GetUVTris(void) const {return(Tris);}
int GetModNum(void) const {return ModNum;}
int GetMeshNum(void) const {return MeshNum;}
protected:
int ModNum,MeshNum;
std::vector<sUVTri> 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<CNode> &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<CNode> &SceneTree,std::vector<int> &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<TVECTOR> const &GetPts() const {return(Pts);}
std::vector<TVECTOR> const &GetRelPts() const {return(RelPts);}
std::vector<sGinTri> const &GetTris() const {return(Tris);}
std::vector<sVColTri> const &GetVColTris() const {return(VColTris);}
std::vector<sUVTri> const &GetUVTris() const {return(UVTris);}
std::vector<int> const &GetTriMaterial() const {return(TriMaterial);}
std::vector<sGinAnim> const &GetAnim() const {return(Anim);}
std::vector<sGinAnim> const &GetKeyAnim() const {return(KeyAnim);}
std::vector<sGinAnim> const &GetShrunkAnim() const {return(ShrunkAnim);}
std::vector<sGinAnim> 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<int> ChildList;
std::vector<int> PruneChildList;
std::vector<sGinWeight> Weights;
std::vector<TVECTOR> Pts;
std::vector<TVECTOR> RelPts;
std::vector<sGinTri> Tris;
std::vector<sVColTri> VColTris;
std::vector<sUVTri> UVTris;
std::vector<int> TriMaterial;
std::vector<sGinAnim> Anim;
std::vector<sGinAnim> KeyAnim;
// Shrunk Anim stuff
int StartFrame,EndFrame;
std::vector<sGinAnim> ShrunkAnim;
std::vector<sGinAnim> 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<CNode> const & GetTree(void) const{return(SceneTree);}
protected:
std::vector<CNode> 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<CNode> const & GetTree(void) const{return(SkinTree);}
protected:
std::vector<CNode> 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<CNode> const & GetTree(void) const{return(AnimTree);}
// int GetFrameCount() {return(FrameCount);}
protected:
// int FrameCount;
std::vector<CNode> 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<CNode> const & GetTree(void) const{return(AnimTree);}
protected:
std::vector<CNode> 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<Size; i++)
{
In.read((char*)&Prop[i],1);
}
Prop[Size]=0;
}
public:
std::vector<char> const & GetUserProp() const {return(Prop);}
int GetModNum(void) const {return ModNum;}
protected:
int ModNum;
std::vector<char> Prop;
};
/*****************************************************************************/
/*** Camera Chunk ************************************************************/
/*****************************************************************************/
struct sCam
{
std::vector<TVECTOR> CamPos;
std::vector<TVECTOR> 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<GinChunk const *> GetVersionChunk() {return(VersionChunk);}
std::vector<GinChunk const *> GetTexNamesChunk() {return(TexNamesChunk);}
std::vector<GinChunk const *> GetMatChunk() {return(MatChunk);}
std::vector<GinChunk const *> GetMod4Chunk() {return(Mod4Chunk);}
std::vector<GinChunk const *> GetMshChunk() {return(MshChunk);}
std::vector<GinChunk const *> GetPointsChunk() {return(PointsChunk);}
std::vector<GinChunk const *> GetTrisChunk() {return(TrisChunk);}
std::vector<GinChunk const *> GetVColTrisChunk() {return(VColTrisChunk);}
std::vector<GinChunk const *> GetUVtrisChunk() {return(UVtrisChunk);}
std::vector<GinChunk const *> GetSceneTreeChunk() {return(SceneTreeChunk);}
std::vector<GinChunk const *> GetAnimTreeChunk() {return(AnimTreeChunk);}
std::vector<GinChunk const *> GetKeyAnimTreeChunk(){return(KeyAnimTreeChunk);}
std::vector<GinChunk const *> GetSkinTreeChunk() {return(SkinTreeChunk);}
std::vector<GinChunk const *> GetUserPropChunk() {return(UserPropChunk);}
std::vector<GinChunk const *> GetCameraChunk() {return(CameraChunk);}
char * GetModelName(int ModelNum)
{
CMod4 *Mod=(CMod4*)Mod4Chunk[ModelNum];
return(Mod->GetModelName());
};
protected:
GinFile MyFile;
std::vector<GinChunk const *> VersionChunk;
std::vector<GinChunk const *> TexNamesChunk;
std::vector<GinChunk const *> MatChunk;
std::vector<GinChunk const *> Mod4Chunk;
std::vector<GinChunk const *> MshChunk;
std::vector<GinChunk const *> PointsChunk;
std::vector<GinChunk const *> TrisChunk;
std::vector<GinChunk const *> VColTrisChunk;
std::vector<GinChunk const *> UVtrisChunk;
std::vector<GinChunk const *> SceneTreeChunk;
std::vector<GinChunk const *> AnimTreeChunk;
std::vector<GinChunk const *> KeyAnimTreeChunk;
std::vector<GinChunk const *> SkinTreeChunk;
std::vector<GinChunk const *> UserPropChunk;
std::vector<GinChunk const *> 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<TreeSize; N++) if (GetNode(N).IsNodeName(Name)) return(GetNodePtr(N));
return(0);
}
CNode *GetNodePtrPrefix(char *Name,int Start=0)
{
int TreeSize=GetSceneTreeSize();
for (int N=Start; N<TreeSize; N++) if (GetNode(N).IsNodePrefix(Name)) return(GetNodePtr(N));
return(0);
}
int GetSceneNodeCount() {return(SceneTree.size());}
int GetSceneTreeSize() {return(SceneTree.size());}
int GetPruneTreeSize() {return(PruneTree.size());}
CNode &GetSceneNode(int Idx) {return(GetNode(Idx));}
CNode &GetPruneNode(int Idx) {return(GetNode(PruneTree[Idx]));}
void PrintSceneTree(int Idx=0)
{
// printf("SceneTree - %i Nodes\n\n",SceneTree.size());
PrintTreeSpace=0;
PrintTreeNode(Idx,0);
}
void PrintPruneTree(int Idx=0)
{
// printf("PruneTree - %i Nodes\n\n",PruneTree.size());
PrintTreeSpace=0;
PrintTreeNode(Idx,1);
}
void PrintTreeNode(int Idx,const int);
void BuildPruneTree(int Idx, int ParentIdx);
bool SetPruneNodes(int Idx);
void ResetSceneTree() {SceneTree.clear();}
void ResetPruneTree()
{
int TreeSize=SceneTree.size();
for (int n=0;n<TreeSize;n++) SceneTree[n].PruneChildList.clear();
}
int CountAllChildren(int Idx) {return(_CountAllChildren(Idx)+1);}
//-----------------
//-----------------
//-----------------
std::vector<GString> const & GetTexNames(void) const {return(AllTexNames);}
std::vector<GString> const & GetTexList(void) const {return(TextureList);}
std::vector<Material> const & GetMaterials(void) const {return(AllMaterials);}
std::vector<int> const & GetUsedMaterialIdx(void) const {return(UsedMaterials);}
std::vector<sCam> const & GetCamera(void) const {return(Camera);}
void GetNonSharedTextures(std::vector<GString> const & SharedTextures,std::vector<GString> & Dest);
protected:
int loadPoints(int CurMod, std::vector<GinChunk const *> &Points,CNode *ThisNode);
int loadTris(int CurMod, int CurMesh, std::vector<GinChunk const *> &Tris,CNode *ThisNode);
int loadUV(int CurMod, int CurMesh, std::vector<GinChunk const *> &UVTris,CNode *ThisNode);
int loadVCol(int CurMod, int CurMesh, std::vector<GinChunk const *> &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<ChildCount;Loop++) NodeCount+=_CountAllChildren(ThisNode.PruneChildList[Loop]);
return(NodeCount+ChildCount);
}
GString FileName;
std::vector<GString> AllTexNames;
std::vector<GString> TextureList;
std::vector<Material> AllMaterials;
std::vector<int> UsedMaterials;
std::vector<CNode> SceneTree;
std::vector<int> PruneTree;
std::vector<sCam> Camera;
int CurTree;
int PrintTreeSpace;
};
/*****************************************************************************/
TMATRIX GetWorldMatrix(std::vector<CNode> const &Tree,int Idx);
TVECTOR GetWorldPos(std::vector<CNode> const &Tree,int Idx);
TVECTOR GetWorldPos(TMATRIX &WorldMtx,TVECTOR &ThisPos);
#endif

View File

@ -0,0 +1,533 @@
/*=========================================================================
EXPORT.CPP
Author:
Created:
Project:
Purpose:
Copyright (c) 1998 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include "mapread.h"
/* Glib
---- */
#include <tquant.h>
/* 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<RepItems.size();f++)
{
_splitpath( RepItems[f].m_texName, NULL, NULL, CompFile, NULL );
if (!strcmp( InFile, CompFile )) return f;
}
if (m_errorOnMissingFile)
GObject::Error(ERR_FATAL,"Missing bmp - %s\n", frame);
return -1;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CMapFile::Parse()
{
int i;
int version;
int x, y;
float lowestY;
TILE_PACKET * t;
MapFile.Seek( 0 );
MapFile.Read( VersionText, 4 );
version = GetVersion( (char *)VersionText );
// READ GLOBAL TILE NAMES
MapFile.Read( &nbTiles );
TileNames = (CFileName *)malloc( nbTiles * sizeof(CFileName) );
for (i=0;i<nbTiles;i++)
{
MapFile.Read( &TileNames[i], sizeof(CFileName) );
}
// READ GLOBAL OBJECT INFO
MapFile.Read( &nbObjects );
Objects = (CObject *)malloc( nbObjects * sizeof(CObject) );
for (i=0;i<nbObjects;i++)
{
MapFile.Read( &Objects[i].Name, sizeof(CFileName) );
if (version < 104)
{
MapFile.Read( &Objects[i].Width );
MapFile.Read( &Objects[i].Height );
MapFile.Read( &Objects[i].Depth );
MapFile.Read( &Objects[i].Mask, (sizeof(bool) * MAX_MASKX * MAX_MASKY) );
}
}
// READ TILE MAP
MapFile.Read( &MapWidth );
MapFile.Read( &MapHeight );
MapFile.Read( &TileSize );
if (TileSize > 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;y<MapHeight;y++)
{
for (x=0;x<MapWidth;x++)
{
MapCTile tile;
int frame = 0;
int angle = 0;
MapFile.Read( &tile, TileSize );
strlwr( tile.FrameName );
for (int l=0;l<strlen(tile.FrameName);l++)
{
if (tile.FrameName[l] == '\\') tile.FrameName[l] = '/';
}
if (tile.frame) frame = FindFrame( tile.FrameName );
else frame = 0;
angle = (int)tile.angle;
angle++;
angle &= 0x3;
if (angle == 2) angle = 0;
else if (angle == 0) angle = 2;
t->frame = 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;y<MapHeight;y++)
{
for (x=0;x<MapWidth;x++)
{
t->height -= (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;i<nbModels;i++)
{
u32 animflag;
u16 angle;
CModel model;
char MyDir[_MAX_DIR];
char MyFile[_MAX_FNAME];
MapFile.Read( &model, ModelSize );
_splitpath( model.MeshName, NULL, MyDir, MyFile, NULL );
angle = (u16)model.AngY;
if (angle == 1) angle = 3;
else if (angle == 3) angle = 1;
animflag = FindFileEquate( MyFile );
animflag &= ~MODEL_FLAGS_MASK;
if (model.m_Animates) animflag |= MODEL_ANIMATE_FLAG;
if (model.m_Busstop) animflag |= MODEL_BUSSTOP_FLAG;
if (model.m_Booth) animflag |= MODEL_BOOTH_FLAG;
if (model.m_OtherAnim) animflag |= MODEL_OTHERANIM_FLAG;
if (model.m_Entrance) animflag |= MODEL_ENTRANCE_FLAG;
m->AnimAndFlags = 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<AnimItems.size();i++)
{
if (!strcmp( AnimItems[i].m_AnimName, name )) return( AnimItems[i].m_Frame );
}
if (AnimHeaderFile)
{
GObject::Error( ERR_WARNING, "Could not find anim %s in anim header %s\n", name, AnimHeaderFile );
}
else
{
GObject::Error( ERR_WARNING, "Could not find anim %s - anim header not loaded\n", name );
}
return (-1);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CMapFile::MakeMapPalette(void)
{
using namespace std;
vector<u8> SourcePal;
vector<u8> 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;f<MapWidth*MapHeight;f++)
{
SourcePal[f*3+0]=Tiles[f].r;
SourcePal[f*3+1]=Tiles[f].g;
SourcePal[f*3+2]=Tiles[f].b;
}
tquant(&SourcePal[0],&TileToPalNum[0],&DestPal[0],NUM_OF_PAL_ENTRIES,MapWidth*MapHeight);
for (int c=0;c<NUM_OF_PAL_ENTRIES;c++)
{
MapPal[c].r=DestPal[c*3+0];
MapPal[c].g=DestPal[c*3+1];
MapPal[c].b=DestPal[c*3+2];
}
}
void CMapFile::WriteMapPalette(FILE * F)
{
int count = NUM_OF_PAL_ENTRIES;
fwrite( &count, sizeof(u32), 1,F);
for (int f=0;f<count;f++)
{
u8 Dummy = 0;
fwrite( &MapPal[f].r, sizeof(u8), 1,F);
fwrite( &MapPal[f].g, sizeof(u8), 1,F);
fwrite( &MapPal[f].b, sizeof(u8), 1,F);
fwrite( &Dummy,sizeof(u8),1,F);
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CMapFile::SetInfoOut( int x, int y, TILE_PACKET * T, OUT_TILE_PACKET * O )
{
O->mType = 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<MapHeight;y++)
{
for (int x=0;x<MapWidth;x++)
{
TILE_PACKET * tile;
OUT_TILE_PACKET out;
tile = &Tiles[x + (y * MapWidth)];
SetInfoOut( x, y, tile, &out );
fwrite( &out, sizeof(OUT_TILE_PACKET), 1, level );
}
}
fwrite( &nbModels, sizeof( int ), 1, level );
for (int i=0;i<nbModels;i++)
{
fwrite( &Models[i], sizeof(MODEL_PACKET), 1, level );
}
fwrite( &nbSpawnPoints, sizeof(int), 1, level );
for (i=0; i<nbSpawnPoints; i++)
{
fwrite( &Spawn[i], sizeof(SPAWNPOS), 1, level);
}
// printf( "WRITTEN %s\n", file );
}
else
{
GObject::Error(ERR_FATAL, "Could not save lvl file - %s", file );
}
}
/*===========================================================================
end */

497
Utils/Libs/GinLib/mapread.h Normal file
View File

@ -0,0 +1,497 @@
/*=========================================================================
EXPORT.H
Author:
Created:
Project:
Purpose:
Copyright (c) 1998 Climax Development Ltd
===========================================================================*/
#pragma warning( disable : 4786 )
#ifndef __EXPORT_H__
#define __EXPORT_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <vector>
#include <algorithm>
/* Glib
---- */
#include <gtypes.h>
#include <misc.hpp>
#include <gstring.hpp>
/* 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<len;i++) ((u8 *)ptr)[i] = Ptr[i];
Ptr += len;
}
protected:
u8 * Buffer;
u8 * Ptr;
};
/*------------------------------------------*/
/* */
/*------------------------------------------*/
class CMapFile
{
public:
CMapFile()
{
m_errorOnMissingFile=true;
AnimHeaderFile=NULL;
}
~CMapFile()
{
}
void Open( const char * map, const char * rep, const char * anim )
{
MapFile.Open( map );
readRepFile( rep, RepItems );
readAnimHeaderFile( anim, AnimItems );
Objects = NULL;
Tiles = NULL;
TileNames = NULL;
Models = NULL;
AnimHeaderFile = anim;
}
void getTexturesUsed(char const * mapFile,std::vector<GString> & textures)
{
m_errorOnMissingFile=false;
MapFile.Open( mapFile );
Objects = NULL;
Tiles = NULL;
TileNames = NULL;
Models = NULL;
Parse();
for (int f=0;f<nbTiles;f++)
{
GString thisTile;
thisTile=TileNames[f].Name;
if (thisTile)
{
if (std::find(textures.begin(),textures.end(),thisTile)==textures.end())
textures.push_back(thisTile);
}
}
Close();
}
void Close()
{
MapFile.Close();
if (Objects) free( Objects );
if (Tiles) free( Tiles );
if (TileNames) free( TileNames );
if (Models) free( Models );
}
void Parse();
void Export( const char * file );
void GetAllTileNames();
int FindFrame( const char * frame );
int FindFileEquate( char * filename );
protected:
int GetVersion( char * version );
void MakeMapPalette(void);
void WriteMapPalette(FILE * F);
void WriteTileHdrs(FILE * F);
u8 GetPalNum(uint x,uint y)
{
if (!((x+y*MapWidth) < TileToPalNum.size()))
GObject::Error(ERR_FATAL,"uh?");
return(TileToPalNum[x+y*MapWidth]);
}
void SetInfoOut( int x, int y, TILE_PACKET * T, OUT_TILE_PACKET * O );
struct Col
{
u8 r,g,b;
};
std::vector<Col> MapPal;
std::vector<u8> TileToPalNum;
const char * AnimHeaderFile;
std::vector<RepItem> RepItems;
std::vector<AnimHeaderItem> 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 */

320
Utils/Libs/GinLib/pak.cpp Normal file
View File

@ -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 <string.h>
#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 */

60
Utils/Libs/GinLib/pak.h Normal file
View File

@ -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 <gtypes.h>
/* 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 */

View File

@ -0,0 +1,251 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <strstream>
/* Glib
---- */
#include <pcre.h>
#include <gobject.hpp>
#include <gfname.hpp>
/* 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<RepItem> & 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<RepItem> items;
readRepFile(name,items);
int numOfItems;
numOfItems=items.size();
for (int f=0;f<numOfItems;f++)
{
RepItem dummyResult;
if (find(items[f].m_texName,dummyResult))
GObject::Error(ERR_FATAL,"%s already defined in rep file database",(char const *)items[f].m_texName);
makeTexNameCompliant(items[f].m_texName);
m_strToInfo[items[f].m_texName]=items[f];
}
m_lastLoadedFile=name;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void RepFile::makeTexNameCompliant(GString & str)
{
str.Lower();
str.Filter("\\",'/');
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void RepFileNoDir::makeTexNameCompliant(GString & str)
{
GFName texFileName(str);
str=texFileName.File();
str.Lower();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool RepFile::find(GString const & str,RepItem & result)
{
GString srchStr;
map<GString,RepItem>::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 */

View File

@ -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 <vector>
#include <map>
/* Glib
---- */
#include <gtypes.h>
#include <gstring.hpp>
/* 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<GString,RepItem> 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<RepItem> & Items);
/*---------------------------------------------------------------------- */
#endif /* __REPREAD_H__ */
/*===========================================================================
end */

View File

@ -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<lineLength;f++)
{
if (line[f] == ';')
line[f]=0;
}
if (strlen(line))
line[strlen(line)-1]=0;
m_lineCount++;
// stripTrailingSpace(line);
}
while (!strlen(line));
return(true);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool ScriptFile::nextLineIsCommand(void)
{
checkIsOpen();
bool retVal;
streampos thisPos;
const int lineLength=DEFAULT_LINE_LENGTH;
char line[lineLength];
int oldLineCount;
oldLineCount=m_lineCount;
retVal=false;
thisPos=m_inStream.tellg();
if (getNextNonBlankLine(line,lineLength))
{
stripTrailingSpace(line);
retVal=isCommand(line);
}
m_inStream.seekg(thisPos);
m_lineCount=oldLineCount;
return(retVal);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
GString ScriptFile::peekNextCommand(void)
{
checkIsOpen();
GString retStr;
if (nextLineIsCommand())
{
const int lineLength=DEFAULT_LINE_LENGTH;
char line[lineLength];
int oldLineCount;
streampos thisPos;
oldLineCount=m_lineCount;
thisPos=m_inStream.tellg();
getNextNonBlankLine(line,lineLength);
stripTrailingSpace(line);
retStr=getCommandString(line);
m_inStream.seekg(thisPos);
m_lineCount=oldLineCount;
}
return(retStr);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void ScriptFile::stripTrailingSpace(char * line)
{
if (strlen(line))
{
bool done=false;
for (int f=strlen(line)-1;f<=0 && !done ;f--)
{
if ((!isspace(line[f])) )
done=true;
else
line[f]=0;
}
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
GString ScriptFile::getCommandString(char * com)
{
char * newStr;
newStr=strdup(com);
newStr[strlen(newStr)-1]=0;
GString retStr(&newStr[1]);
free(newStr);
return(retStr);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool ScriptFile::isCommand(char * line)
{
return ((line[0]=='[') && (line[strlen(line)-1]==']'));
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
GString ScriptFile::getNextLine(void)
{
const int lineLength=DEFAULT_LINE_LENGTH;
char line[lineLength];
getNextNonBlankLine(line,lineLength);
return(line);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool ScriptFile::eof(void)
{
checkIsOpen();
return(m_inStream.eof());
}
/*===========================================================================
end */

View File

@ -0,0 +1,99 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
#pragma warning( disable : 4786 )
#ifndef __SCRIPT_H__
#define __SCRIPT_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <fstream>
/* Glib
---- */
#include <gstring.hpp>
/* 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 */

View File

@ -0,0 +1,203 @@
/*=========================================================================
AllFiles.CPP
Author: Gary
Created: 011200
Project: SpongeBob
Purpose: File cycler stuff
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include <vector>
#include <gtypes.h>
#include <gstring.hpp>
#include <misc.hpp>
#include <gfname.hpp>
#include <pcre.h>
#include <ginio.h>
#include <repread.h>
#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 <gintex.h>
#include <algorithm>
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<GString> NonSharedTextures;
CScene MyFile;
MyFile.Load(FName);
MyFile.GetNonSharedTextures(AllExternalSharedTextures,NonSharedTextures);
vector<GString> NewEntrys;
for (int f=0;f<NonSharedTextures.size();f++)
{
if (find(UniqueTexturesSoFar.begin(),UniqueTexturesSoFar.end(),NonSharedTextures[f]) == UniqueTexturesSoFar.end())
{
NewEntrys.push_back(NonSharedTextures[f]);
UniqueTexturesSoFar.push_back(NonSharedTextures[f]);
}
}
for (f=0;f<NewEntrys.size();f++)
FileCallback(NewEntrys[f],0);
cout<<"Read gin file *"<<FName<<"*"<<endl;
}
else
{
GFName Name(FName);
if (Name.File()[0]=='+')
ThisZeroColZero=true;
else
ThisZeroColZero=ZeroColZero;
if (Name.File()[0]=='!')
m_allocateAs16bit=true;
else
m_allocateAs16bit=false;
if (Name.File()[0] == '@')
{
ThisZeroColZero = true;
m_allocateAs16bit = true;
}
GString TheFile(FName);
TheFile.Lower();
MyInfo.SetInfo(TheFile,CrossHair,ThisZeroColZero,MoveUVs,AllowRotate,ShrinkToFit,m_allocateAs16bit);
cout<<"Add image file "<<TheFile<<endl;
if (ForceOffsets)
MyInfo.SetForceOffsets(XOff,YOff);
AllFileInfos.resize(AllFileInfos.size()+1);
AllFileInfos[AllFileInfos.size()-1]=MyInfo;
}
}
void AllFiles::AddMemFrame(char const * FName,Frame &Frame)
{
FileInfo MyInfo;
bool ThisZeroColZero;
GFName Name(FName);
if (Name.File()[0]=='+')
ThisZeroColZero=true;
else
ThisZeroColZero=ZeroColZero;
if (Name.File()[0]=='!')
m_allocateAs16bit=true;
else
m_allocateAs16bit=false;
if (Name.File()[0] == '@')
{
ThisZeroColZero = true;
m_allocateAs16bit = true;
}
GString TheFile(FName);
TheFile.Lower();
MyInfo.SetInfo(TheFile,CrossHair,ThisZeroColZero,MoveUVs,AllowRotate,ShrinkToFit,m_allocateAs16bit,&Frame);
cout<<"Add MemFrame "<<TheFile<<endl;
if (ForceOffsets)
MyInfo.SetForceOffsets(XOff,YOff);
AllFileInfos.resize(AllFileInfos.size()+1);
AllFileInfos[AllFileInfos.size()-1]=MyInfo;
}
/*----------------------------------------------------------------------
Function: void AllFiles::FileCallback(char const * FName,int FileNum)
---------------------------------------------------------------------- */
void AllFiles::SortOrder()
{
if (!m_noSort)
{
int i,j;
FileInfo MyInfo;
int count = AllFileInfos.size();
for (i=0; i<count; i++)
{
for (j=0; j<count; j++)
{
if (strcmp(AllFileInfos[i].GetFileName(), AllFileInfos[j].GetFileName())<0)
{
MyInfo = AllFileInfos[i];
AllFileInfos[i] = AllFileInfos[j];
AllFileInfos[j] = MyInfo;
}
}
}
}
}
/*----------------------------------------------------------------------
Function: void AllFiles::ReadRepFile(char const * Name)
Purpose: Read in rep file for shared textures
Params: Name of rep file
---------------------------------------------------------------------- */
void AllFiles::ReadRepFile(char const * Name)
{
vector<RepItem> MyItems;
::readRepFile(Name,MyItems);
for (int f=0;f<MyItems.size();f++)
AllExternalSharedTextures.push_back(MyItems[f].m_texName);
cout<<"Read report file "<<Name<<endl;
}
/*===========================================================================
end */

View File

@ -0,0 +1,109 @@
/*=========================================================================
AllFiles.h
Author: Gary
Created: 011200
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ALLFILES_H__
#define __ALLFILES_H__
/*----------------------------------------------------------------------
Includes
-------- */
//#include <vector>
//#include <gtypes.h>
//#include <gstring.hpp>
//#include <misc.hpp>
//#include <gfname.hpp>
//#include <pcre.h>
//#include <ginio.h>
//#include <repread.h>
//#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<GString> UniqueTexturesSoFar;
vector<GString> 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 */

View File

@ -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 */

View File

@ -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

View File

@ -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 <vector>
#include <gtypes.h>
#include <gstring.hpp>
#include <misc.hpp>
#include <gfname.hpp>
#include <pcre.h>
#include <ginio.h>
#include <repread.h>
#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 */

View File

@ -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<u8> & 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<aTPageHeight;y++)
dest[x+y*128]=srcTpData[x+y*WidthInBytes];
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CompressMem(char const * CmdLine,std::vector<u8> & 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 "<<CmdLine<<endl;
system(ComStr);
CompSize=FileSize(CompTmpName);
Body.resize(CompSize);
ifstream In;
In.open(CompTmpName,ios::binary);
if (In)
{
In.read((char *)&Body[0],CompSize);
In.close();
}
else
throw("Can't open compressed out file");
}
else
throw("Can't open uncompressed out file");
remove(TmpName);
remove(CompTmpName);
}
catch (const char * Err)
{
GObject::Error(ERR_FATAL,"%s im CompressMem",Err);
}
}
void VRAMImage::WriteInTpageChunks(ofstream & str)
{
const int TPAGES_IN_ALL =WidthInTpages * HeightInTPages;
vector<u8> tpageData;
tpageData.resize(TPageSizeInBytes);
for (int f=0;f<TPAGES_IN_ALL;f++)
{
getTpData(f,tpageData);
str.write((char*)&tpageData[0],TPageSizeInBytes);
}
}
void VRAMImage::Write(ofstream & Str)
{
if (m_doCompress)
{
printf("Packing TPage\n");
const int TPAGES_IN_ALL =WidthInTpages * HeightInTPages;
const int NUM_OF_WINDOWS = TPAGES_IN_ALL*4;
vector<u8> tpageData;
vector<u8> dataToWrite;
tpageData.resize(TPageSizeInBytes);
dataToWrite.resize(TPageSizeInBytes);
for (int f=0;f<NUM_OF_WINDOWS;f++)
{
int dataWriteSize;
const u8 * srcData;
if ((f&3) == 0)
getTpData(f/4,tpageData);
srcData=&tpageData[(f%4)*128*64];
if (f != 0)
{
vector<u8> 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<u16> OutWords;
PalToPlot.MakePSXPal(OutWords);
int f;
for (f=0;f<OutWords.size();f++)
Addr[f]=OutWords[f];
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::PlotFrame(SprFrame const & FrameToPlot)
{
SprFrame::BDEPTH ThisDepth;
ThisDepth=FrameToPlot.GetBitDepth();
switch(ThisDepth)
{
case SprFrame::BITS_4:
PlotFrame4(FrameToPlot);
break;
case SprFrame::BITS_8:
PlotFrame8(FrameToPlot);
break;
};
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::SaveAs16ColLbm(const char * Name)
{
Palette GazPalette;
GazPalette[0].SetR(0);
GazPalette[0].SetG(0);
GazPalette[0].SetB(255);
int W=WidthInTpages*256;
int H=HeightInPixels;
Frame ThisFr;
for (int f=1;f<15;f++)
{
int Col=f*17;
GazPalette[1+f].SetR(Col);
GazPalette[1+f].SetG(Col);
GazPalette[1+f].SetB(Col);
}
for (int y=0;y<H;y++)
for (int x=0;x<W;x++)
{
if ((x&1))
lbmData[x+y*W]=(VRAMData[ (y*(W/2))+(x/2)]&0xf0) >> 4;
else
lbmData[x+y*W]=VRAMData[(y*(W/2))+(x/2)]&0x0f;
}
ThisFr.SetFrame(lbmData,W,H,GazPalette);
ThisFr.SaveLbm(Name);
cout<<"Written "<<Name<<endl;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::PlotFrame4(SprFrame const & Fr)
{
TPRect Tp=Fr.GetTPRect();
int W=WidthInTpages*256;
W=W/2; /* we're plotting nibbles */
if (!Tp.GetRotate())
{
for (int y=Tp.Y;y<Tp.Y+Tp.H;y++)
for (int x=Tp.X;x<Tp.X+Tp.W;x++)
{
int FrX=x-Tp.X;
int FrY=y-Tp.Y;
u8 ScrNib=Fr.SeeData()[FrY*Tp.W+FrX]&0xf;
u8 * PixAddr=&VRAMData[y*W+x/2];
if ((x&1))
{
*PixAddr&=0x0f;
*PixAddr|=ScrNib<<4;
}
else
{
*PixAddr&=0xf0;
*PixAddr|=ScrNib;
}
}
}
else
{
for (int y=Tp.Y;y<Tp.Y+Tp.H;y++)
for (int x=Tp.X;x<Tp.X+Tp.W;x++)
{
int FrX=x-Tp.X;
int FrY=y-Tp.Y;
u8 ScrNib=Fr.SeeData()[FrX*Tp.H+(Tp.H-FrY-1)]&0xf;
u8 * PixAddr=&VRAMData[y*W+x/2];
if ((x&1))
{
*PixAddr&=0x0f;
*PixAddr|=ScrNib<<4;
}
else
{
*PixAddr&=0xf0;
*PixAddr|=ScrNib;
}
}
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::PlotFrame8(SprFrame const & Fr)
{
const TPRect & Tp=Fr.GetTPRect();
int W=WidthInTpages*256;
W/=2;
u8 * Addr=&VRAMData[Tp.Y*W+Tp.X/2];
if (!Fr.IsRotated())
{
for (int y=0;y<Fr.GetHeight();y++)
for (int x=0;x<Fr.GetWidth();x++)
Addr[y*W+x]=Fr.SeeData()[x+y*Fr.GetWidth()];
}
else
{
for (int y=0;y<Fr.GetWidth();y++)
for (int x=0;x<Fr.GetHeight();x++)
Addr[y*W+x]=Fr.SeeData()[x*Fr.GetWidth()+(Fr.GetWidth()-y-1)];
}
}
/*===========================================================================
end */

View File

@ -0,0 +1,669 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
#include <frame.hpp>
#include <misc.hpp>
/* 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<u8> bitMap;
};
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#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<ncols; i++)
{
pal[i].b = f.get();
pal[i].g = f.get();
pal[i].r = f.get();
if (win_flag)
f.get();
}
}
/* read_1bit_line:
* Support function for reading the 1 bit bitmap file format.
*/
static void read_1bit_line(int length, Gifstream & f, BITMAP *bmp, int line)
{
unsigned char b[32];
unsigned long n;
int i, j, k;
int pix;
for (i=0; i<length; i++)
{
j = i % 32;
if (j == 0)
{
n = f.Get32();
for (k=0; k<32; k++)
{
b[31-k] = n & 1;
n = n >> 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<length; i++)
{
j = i % 8;
if (j == 0)
{
n = f.Get32();
for (k=0; k<4; k++)
{
temp = n & 255;
b[k*2+1] = temp & 15;
temp = temp >> 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<length; i++)
{
j = i % 4;
if (j == 0)
{
n = f.Get32();
for (k=0; k<4; k++)
{
b[k] = n & 255;
n = n >> 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; i<length; i++) {
c.b = f.get();
c.g = f.get();
c.r = f.get();
bmp->line[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;j<count;j++) {
bmp->line(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; j<val; j++) {
val0 = f.get();
bmp->line(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; j<count; j++) {
bmp->line(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<val; j++) {
if ((j%4) == 0) {
val0 = f.Get16();
for (k=0; k<2; k++) {
b[2*k+1] = val0 & 15;
val0 = val0 >> 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<ncol;f++)
{
Colour & col = palObj[f];
col.SetRGB(pal[f].r,pal[f].g,pal[f].b);
}
frm.SetFrame(bmp.getBitMap(),infoheader.biWidth,infoheader.biHeight,palObj);
}
}
/*===========================================================================
end */

View File

@ -0,0 +1,58 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
#ifndef __BMPLOADER_H__
#define __BMPLOADER_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
#include <frame.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
void load_bmp(Frame & frm,char const *filename);
/*---------------------------------------------------------------------- */
#endif /* __BMPLOADER_H__ */
/*===========================================================================
end */

View File

@ -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 "<<Width<<endl;
GObject::Error(ERM_OUTOFMEM);
}
if (!(CountRow=new int[Height]))
{
cout<<"Height is "<<Width<<endl;
GObject::Error(ERM_OUTOFMEM);
}
memset(CountRow,0,sizeof(int)*Height);
memset(CountCol,0,sizeof(int)*Width);
FrmData=Fr.SeeData();
for (int yy=0;yy<Height;yy++)
{
u8 const * ThisRow=&FrmData[yy*Width];
for (int xx=0;xx<Width;xx++)
{
if (ThisRow[xx] == CrossCol)
{
CountRow[yy]++;
CountCol[xx]++;
}
}
}
Col=FindLargestIndex(CountCol,Width);
Row=FindLargestIndex(CountRow,Height);
if ((Col != -1) && (Row != -1))
{
x=Col;
y=Row;
RetVal=true;
}
}
if (CountCol)
delete CountCol;
if (CountRow)
delete CountRow;
return(RetVal);
}
/*----------------------------------------------------------------------
Description:
Returns:
---------------------------------------------------------------------- */
int CROSS_RES::FindLargestIndex(int * CountCol,int Width)
{
int LargestIndex=-1;
int Largest=0;
for (int f=0;f<Width;f++)
{
if (CountCol[f] > Largest)
{
Largest=CountCol[f];
LargestIndex=f;
}
}
return(LargestIndex);
}
/*===========================================================================
end */

View File

@ -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 <gobject.hpp>
#include <frame.hpp>
/*----------------------------------------------------------------------
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 */

View File

@ -0,0 +1,138 @@
/*=========================================================================
GRECT.CPP
Author: Gary Liddon @ Climax
Created:
Project:
Purpose:
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <algorithm>
/* Glib
---- */
#include <frame.hpp>
/* 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 */

View File

@ -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 <vector>
/* Glib
---- */
#include <frame.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
typedef std::vector<Rect> 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 */

359
Utils/Libs/TexGrab/pak.cpp Normal file
View File

@ -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 <string.h>
#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<size && same;f++)
same=p1[f]==p2[f];
return(same);
}
/*----------------------------------------------------------------------
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 (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 */

61
Utils/Libs/TexGrab/pak.h Normal file
View File

@ -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 <gtypes.h>
/* 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 */

File diff suppressed because it is too large Load Diff

573
Utils/Libs/TexGrab/sprset.h Normal file
View File

@ -0,0 +1,573 @@
/*=========================================================================
SPRSET.CPP
Author: Gary Liddon @ Farehame
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
===========================================================================*/
#ifndef __SPRSET_H__
#define __SPRSET_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <vector>
/* Glib
---- */
#include <gobject.hpp>
#include <gstring.hpp>
#include <frame.hpp>
#include <misc.hpp>
/* 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<s.Len(); i++)
{
textout[i]=textin[i];
if (textout[i] == '+') plus = true;
// p++;
// else p++;
}
*/ PlusColZero = plus;
out = textin;
delete textout;
return out;
}
void SetInfo(const char * NewFileName,bool NewCrossHair,bool NewZeroColZero, bool NewMoveUVs,bool NewAllowRotate,bool NewShrinkToFit,bool allocateAs16Bit,Frame *NewMemFrame=0)
{
CrossHair=NewCrossHair;
ZeroColZero=NewZeroColZero;
MoveUVs =NewMoveUVs;
AllowRotate=NewAllowRotate;
SetName(NewFileName);
ShrinkToFit=NewShrinkToFit;
m_allocateAs16Bit=allocateAs16Bit;
MemFrame=NewMemFrame;
/*
if we're allocating on a 16 bit pixel boundary then
we don't want the texture to be rotated
*/
if (allocateAs16Bit)
AllowRotate=false;
}
const char * GetFileName(void) const
{return(FileName);}
const char * GetActualFileName(void) const
{return(ActualFileName);}
void SetName(const char * NewName)
{
if (NewName) strcpy(ActualFileName,NewName);
FileName = CheckForPlus(ActualFileName);
}
bool GetCrossHair(void) const
{return(CrossHair);}
bool GetZeroColZero(void) const
{return(ZeroColZero);}
bool GetPlusColZero(void) const
{return(PlusColZero);}
bool GetMoveUVs(void) const
{return(MoveUVs);}
bool GetAllowRotate(void) const
{return(AllowRotate);}
bool GetForceOffsets(void) const
{
return(ForceOffsets);
}
int GetXOff(void) const
{
return(XOff);
}
int GetYOff(void) const
{
return(YOff);
}
bool getAllocateAs16Bit(void) const
{return(m_allocateAs16Bit);}
char const * GetActualName(void) const
{return(ActualFileName);}
bool GetShrinkToFit(void) const
{return(ShrinkToFit);}
protected:
GString FileName;
char ActualFileName[256];
bool CrossHair;
bool ZeroColZero;
bool PlusColZero;
bool MoveUVs;
bool AllowRotate;
bool ForceOffsets;
bool ShrinkToFit;
bool m_allocateAs16Bit;
int XOff,YOff;
Frame *MemFrame;
};
typedef std::vector<FileInfo> FIVec;
typedef std::vector<FileInfo>::iterator FIVecIt;
typedef std::vector<FileInfo>::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<u16> & 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<SprFrame> SprFrVec;
typedef std::vector<SprFrame>::iterator SprFrIt;
typedef std::vector<SprPal> SprPalVec;
typedef std::vector<SprPal>::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 */

View File

@ -0,0 +1,857 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <algorithm>
#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;f<NumOfTPages;f++)
VecOfPages[f].resize(0);
for (int y=0;y<VRAMHeightPages;y++)
for (int x=0;x<VRAMWidthPages;x++)
AddEmpty((x*Width16)+vX,(y*Height16)+vY,Width16,Height16);
}
/*----------------------------------------------------------------------
Function: bool TryNFit(TPRectList & TpList)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::TryNFit(TPRectList & TpList,TPRect & ThisRect)
{
bool Done=false;
TPRectList::iterator f;
for (f=TpList.begin();f!=TpList.end();f++)
{
TPRect & BlankRect = *f;
if (TryRect(BlankRect,ThisRect))
return(true);
else
{
if (RotateEveryEmpty && CanRotate(ThisRect))
{
ThisRect.SetRotate(!ThisRect.GetRotate());
if (TryRect(BlankRect,ThisRect))
return(true);
else
ThisRect.SetRotate(!ThisRect.GetRotate());
}
}
}
return(false);
}
void VRAM::PosFromTPrect(TPRect & ThisRect,POS_INFO & Pi)
{
TPInfo const * Tpi;
int WorkingWidth;
Tpi=&InfStruct[ThisRect.TypeOfPage];
Pi.XAlign=Tpi->XAlign;
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 (ThisX<MinX)
ThisX=MinX;
if (ThisX>MaxX)
return(false);
if (ThisY<MinY)
ThisY=MinY;
if (ThisY>MaxY)
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 (R1Val<R2Val);
}
};
class Predicate2
{
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 (R1Val>R2Val);
}
};
/*----------------------------------------------------------------------
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.size();f++)
{
if ((RectVec[f].H > 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<RectVec.size();f++)
{
if (!AllocVRAM(RectVec[f]))
{
AllocedEverything=false;
cout<<"Couldn't alloc "<<RectVec[f].W<<","<<RectVec[f].H<<endl;
}
}
return(AllocedEverything);
}
/*----------------------------------------------------------------------
Function: void VRAM::AllocVRAM(TPageType nType,int nW,int nH)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::AllocVRAM(TPRect & OriginalRect)
{
bool Done;
TPRect ThisRect;
ThisRect=OriginalRect;
Done=false;
for (int Page=0;Page<NumOfTPages && !Done;Page++)
{
VecOfPages[Page].sort();
TPRect::SetAllocWH(ThisRect.W,ThisRect.H);
if (!TryNFit(VecOfPages[Page],ThisRect))
{
if (CanRotate(ThisRect))
{
ThisRect.SetRotate(!ThisRect.GetRotate());
VecOfPages[Page].sort();
TPRect::SetAllocWH(ThisRect.W,ThisRect.H);
if (!TryNFit(VecOfPages[Page],ThisRect))
ThisRect.SetRotate(!ThisRect.GetRotate());
else
Done=true;
}
}
else
Done=true;
}
if (Done)
{
OriginalRect=ThisRect;
OriginalRect.SetAlloced(true);
return(true);
}
else
{
OriginalRect.SetAlloced(false);
return(false);
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::CanRotate(TPRect & ThisRect)
{
if (ThisRect.GetDontRotate())
return(false);
switch (ThisRect.TypeOfPage)
{
case TP_PAL:
return(false);
case TP_4:
case TP_8:
case TP_16:
return(true);
case TP_SCREEN:
case TP_NUM_OF_TP_TYPES:
default:
Error(ERR_FATAL,"Not catered for");
return(false);
}
}
/*----------------------------------------------------------------------
Function: void VRAM::AllocVRAM(TPageType nType,int nW,int nH)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAM::RectFromTpRect(Rect & R,TPRect const & ThisRect)
{
R.W=ThisRect.W;
R.H=ThisRect.H;
R.X=ThisRect.X;
R.Y=ThisRect.Y;
}
void VRAM::RemovedFromUnused(TPRect const & ThisRect)
{
RectVec Result;
Rect NewRect;
int f;
RectFromTpRect(NewRect,ThisRect);
int ColidedWith=0;
for ( f=0;f<Unused.size();f++)
{
Rect UnusedRect;
RectFromTpRect(UnusedRect,Unused[f]);
if (UnusedRect.IsColiding(ThisRect) )
{
CutRect(UnusedRect,ThisRect,Result);
ColidedWith++;
}
else
Result.push_back(UnusedRect);
}
Unused.resize(0);
for (f=0;f<NumOfTPages;f++)
VecOfPages[f].resize(0);
for (f=0;f<Result.size();f++)
AddEmpty(Result[f].X,Result[f].Y,Result[f].W,Result[f].H);
}
void VRAM::AddEmpty(int x,int y,int w,int h)
{
Unused.resize(Unused.size()+1);
TPRect & ThisRect=(Unused[Unused.size()-1]);
ThisRect.TypeOfPage=TP_4;
ThisRect.W=w;
ThisRect.H=h;
ThisRect.X=x;
ThisRect.Y=y;
int TpNum=(x/256)+((y/256)*VRAMWidthPages);
VecOfPages[TpNum].insert(VecOfPages[TpNum].end(),ThisRect);
}
void VRAM::AddToUsed(TPRect const & ThisRect)
{
Used.push_back(ThisRect);
}
bool VRAM::InColisionWithUsed(TPRect const & R)
{
for (int f=0;f<Used.size();f++)
{
if (R.IsColiding(Used[f]))
return(true);
}
return(false);
}
/*----------------------------------------------------------------------
Function: bool VRAM::CheckValidAlloc(TPageType nType,int nW,int nH)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::CheckValidAlloc(TPageType nType,int nW,int nH)
{
return(true);
}
/*----------------------------------------------------------------------
Function: int VRAM::GetMaxWidthTp(TPageType nType)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int VRAM::GetMaxWidthTp(TPageType nType)
{
int RetVal;
switch (nType)
{
case TP_4:
RetVal=1;
break;
case TP_8:
RetVal=2;
break;
case TP_16:
RetVal=4;
break;
case TP_SCREEN:
RetVal=256;
break;
default:
RetVal=-1;
Error(ERR_FATAL,"Illegal tpage type");
break;
}
return(RetVal);
}
/*----------------------------------------------------------------------
Function: int VRAM::GetXAlign(TPageType nType)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int VRAM::GetXAlign(TPageType nType)
{
int RetVal;
switch (nType)
{
case TP_4:
RetVal=1;
break;
case TP_8:
RetVal=2;
break;
case TP_16:
RetVal=4;
break;
case TP_PAL:
RetVal=16*4;
break;
case TP_SCREEN:
RetVal=4;
break;
default:
RetVal=-1;
Error(ERR_FATAL,"Illegal tpage type");
break;
}
return(RetVal);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
TPRect & VRAM::NewItem(TPRectVec & TPRects)
{
TPRects.resize(TPRects.size()+1);
return(TPRects[TPRects.size()-1]);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
TPRect::TPRect(void)
{
InitRect();
}
void TPRect::InitRect(void)
{
X=0;
Y=0;
W=0;
H=0;
TypeOfPage=TP_4;
Rotated=false;
Alloced=false;
DontRotate=false;
}
TPRect::TPRect(TPageType nType,int nW,int nH)
{
int WidthMul;
InitRect();
WidthMul=GetWidthMul(nType);
W=nW*WidthMul;
H=nH;
TypeOfPage=nType;
}
int TPRect::GetWidthMul(TPageType nType)
{
int WidthMul;
switch (nType)
{
case TP_4:
WidthMul=1;
break;
case TP_8:
WidthMul=2;
break;
case TP_16:
case TP_SCREEN:
case TP_PAL:
WidthMul=4;
break;
case TP_NUM_OF_TP_TYPES:
default:
Error(ERR_FATAL,"Can't alloc type TP_NUM_OF_TP_TYPES");
break;
}
return (WidthMul);
}
void TPRect::Set(TPageType nType,int nX,int nY,int nW,int nH)
{
TypeOfPage=nType;
X=nX;
Y=nY;
W=nW*GetWidthMul(nType);
H=nH;
}
void TPRect::SetXY(int nX,int nY)
{
X=nX;
Y=nY;
}
u32 TPRect::GetId(void) const
{
int Colis=0;
int PageNum=(X/256)+((Y/256)*16);
if ((X/256) != ((X+W2Alloc-1)/256))
Colis|=1;
if ((Y/256) != ((Y+H2Alloc-1)/256))
Colis|=2;
return ((Colis<<24)|(PageNum<<16)|((Y&0xff)<<8)|(X&0xff));
}
bool TPRect::SetRotate(bool Rot)
{
bool RetBool=Rotated;
if (Rot != RetBool)
{
W/=GetWidthMul(TypeOfPage);
int Temp=W;
W=H;
H=Temp;
W*=GetWidthMul(TypeOfPage);
}
Rotated=Rot;
return(RetBool);
}
void VRAM::getUnusedSpace(TPRectVec & unusedBoxes)
{
int vX=X;
int vY=Y;
const int Width16=256;
const int Height16=256;
for (int y=0;y<VRAMHeightPages;y++)
for (int x=0;x<VRAMWidthPages;x++)
{
TPRect thisRect;
bool foundRect;
foundRect=false;
for (int f=1;f<255 && !foundRect;f++)
{
int boxBaseY;
int boxHeight;
boxBaseY=f;
boxHeight=255-f;
thisRect.X=(x*Width16)+vX;
thisRect.Y=(y*Height16)+vY+boxBaseY;
thisRect.W=Width16;
thisRect.H=boxHeight;
if (!InColisionWithUsed(thisRect))
foundRect=true;
}
if (foundRect)
unusedBoxes.push_back(thisRect);
}
}
int VRAM::GetNumOfUsedPages()
{
int Used=0;
int vX=X;
int vY=Y;
const int Width16=256;
const int Height16=256;
for (int y=0;y<VRAMHeightPages;y++)
for (int x=0;x<VRAMWidthPages;x++)
{
TPRect ThisRect;
ThisRect.X=(x*Width16)+vX;
ThisRect.Y=(y*Height16)+vY;
ThisRect.W=Width16;
ThisRect.H=Height16;
if (InColisionWithUsed(ThisRect))
Used++;
}
return(Used);
}
bool TPRect::IsAlloced(void) const
{
return(Alloced);
}
void TPRect::SetAlloced(bool nAlloced)
{
Alloced=nAlloced;
}
int VRAM::GetNumOfItems()
{
return(Used.size());
}
void TPRect::InitFromFrame(Frame const & Fr)
{
/* !!!!! Make this support other bit widths */
W=Fr.GetWidth();
H=Fr.GetHeight();
if (Fr.GetNumOfCols() <= 16)
TypeOfPage=TP_4;
else if (Fr.GetNumOfCols() <= 256)
TypeOfPage=TP_8;
else
Error(ERR_FATAL,"Only 4 & 8 bit supported right now");
W*=GetWidthMul(TypeOfPage);
}
TPageType TPRect::convertTo16Bit(void)
{
TPageType oldType;
switch (TypeOfPage)
{
case TP_4:
// W=GU_AlignVal(W,4)/4;
break;
case TP_8:
// W=GU_AlignVal(W,2)/2;
break;
default:
Error(ERR_FATAL,"Only 4 & 8 bit supported right now");
break;
}
oldType=TypeOfPage;
TypeOfPage=TP_16;
return(oldType);
}
void TPRect::convertFrom16Bit(TPageType newType)
{
switch (newType)
{
case TP_4:
// W=W*4;
break;
case TP_8:
// W=W*2;
break;
default:
Error(ERR_FATAL,"Only 4 & 8 bit supported right now");
break;
}
TypeOfPage=newType;
}
/*===========================================================================
end */

260
Utils/Libs/TexGrab/tpage.h Normal file
View File

@ -0,0 +1,260 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
#ifndef __TPAGE_HPP__
#define __TPAGE_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <list>
/* Glib
---- */
#include <frame.hpp>
/* 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()<R.GetId());}
void SetWH(int nW,int nH)
{W=nW;H=nH;}
void SetXY(int nX,int nY);
void Set(TPageType nType,int nX,int nY,int nW,int nH);
void SetTpType(TPageType nType) {TypeOfPage=nType;}
bool GetRotate(void) const {return(Rotated);}
bool IsAlloced(void) const;
int GetTpageIn(void) const;
u32 GetId(void) const;
bool GetAlloced(void){return(Alloced);}
static void SetAllocWH(int nW,int nH) {W2Alloc=nW; H2Alloc=nH;}
TPageType convertTo16Bit(void);
void convertFrom16Bit(TPageType newType);
void SetId(int NewId)
{Id=NewId;}
int GetId(void)
{return(Id);}
TPageType TypeOfPage;
void SetDontRotate(bool NewVal=true) {DontRotate=NewVal;}
bool GetDontRotate(void) const {return(DontRotate);}
protected:
int GetWidthMul(TPageType nType);
void InitRect(void);
bool Rotated;
int Id;
void MakeCopy(TPRect const & NewR)
{
W=NewR.W;
H=NewR.H;
X=NewR.X;
Y=NewR.Y;
TypeOfPage=NewR.TypeOfPage;
Rotated=NewR.Rotated;
Id=NewR.Id;
Alloced=NewR.Alloced;
DontRotate=NewR.DontRotate;
}
static int W2Alloc;
static int H2Alloc;
bool Alloced;
bool DontRotate;
};
/* VRAM Alloc handle
----------------- */
typedef int VHND;
typedef std::vector<TPRect> TPRectVec;
/* VRAM
---- */
typedef std::list<TPRect> TPRectList;
typedef std::vector<TPRectList> 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 */

103
Utils/Libs/TexGrab/vimage.h Normal file
View File

@ -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 <gobject.hpp>
#include <fstream>
/* 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<u8> & 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 */