This commit is contained in:
Daveo 2001-02-07 18:46:59 +00:00
parent 9dd82e90c5
commit c1059872a2
8 changed files with 85 additions and 144 deletions

View File

@ -210,7 +210,7 @@ int TriCount=TileTriList.size();
{ {
sTriFace &InTri=TileTriList[T]; sTriFace &InTri=TileTriList[T];
sExpTri OutTri; sExpTri OutTri;
GString TexName=TexCache.GetTexName(InTri.Mat); GString TexName=TexCache.GetTexFilename(InTri.Mat);
OutTri.TexID=TexNames.Add(TexName); OutTri.TexID=TexNames.Add(TexName);
for (int p=0; p<3; p++) for (int p=0; p<3; p++)
@ -223,44 +223,14 @@ int TriCount=TileTriList.size();
} }
} }
/*
void CExport::ExportTile3d(CCore *Core,CTile &ThisTile,sExpTile &OutTile)
{
CTexCache &TexCache=Core->GetTexCache();
std::vector<sTriFace> &TileTriList=ThisTile.GetTriList();
int TriCount=TileTriList.size();
// OutTile.TriStart=TriList.size();
// OutTile.TriCount=TriCount;
// OutTile.XOfs=-1;
// OutTile.YOfs=-1;
// OutTile.TexId=-1;
for (int T=0; T<TriCount; T++)
{
sTriFace &TileTri=TileTriList[T];
sTriFace OutTri;
// sExpTex OutTex;
for (int p=0; p<3; p++)
{
OutTri=TileTri;
// Texture
// sTex &TriTex=TexCache.GetTex(TileTri.Mat);
// OutTex.Filename=TriTex.Filename;
// OutTri.Mat=TexList.Add(OutTex);
}
TriList.push_back(OutTri);
}
// return(TriCount);
}
*/
/*****************************************************************************/ /*****************************************************************************/
void CExport::ExportStrList(CCore *Core) void CExport::ExportStrList(CCore *Core)
{ {
int ListSize,i; int ListSize,i;
GString SavePath=GetWorkingPath();
char RelStr[256];
SavePath.Upper();
// Set List // Set List
ListSize=SetNames.size(); ListSize=SetNames.size();
@ -269,8 +239,10 @@ int ListSize,i;
for (i=0; i<ListSize; i++) for (i=0; i<ListSize; i++)
{ {
const char *Str=SetNames[i]; GString &ThisFile=SetNames[i];
fwrite(Str,strlen(Str)+1,1,File); ThisFile.Upper();
GFName::makerelative(SavePath,ThisFile,RelStr);
fwrite(RelStr,strlen(RelStr)+1,1,File);
} }
// Tex List // Tex List
ListSize=TexNames.size(); ListSize=TexNames.size();
@ -279,8 +251,10 @@ int ListSize,i;
for (i=0; i<ListSize; i++) for (i=0; i<ListSize; i++)
{ {
const char *Str=TexNames[i]; GString &ThisFile=TexNames[i];
fwrite(Str,strlen(Str)+1,1,File); ThisFile.Upper();
GFName::makerelative(SavePath,ThisFile,RelStr);
fwrite(RelStr,strlen(RelStr)+1,1,File);
} }
} }

View File

@ -6,6 +6,7 @@
#include <gl\gl.h> #include <gl\gl.h>
#include <gl\glu.h> #include <gl\glu.h>
#include <frame.hpp> #include <frame.hpp>
#include <gfname.hpp>
#include <Vector> #include <Vector>
#include "TexCache.h" #include "TexCache.h"
@ -25,17 +26,15 @@ sTex Tex;
*/ */
/*****************************************************************************/ /*****************************************************************************/
// Checks loaded files for dups, assumes all passed RGB is unique // Checks loaded files for dups, assumes all passed RGB is unique
int CTexCache::ProcessTexture(const char *Path,const char *Name,int Flags,sRGBData *RGBData) int CTexCache::ProcessTexture(const char *Filename,int Flags,sRGBData *RGBData)
{ {
int ListSize=TexList.size(); int ListSize=TexList.size();
sTex NewTex; sTex NewTex;
sRGBData ThisRGB; sRGBData ThisRGB;
GFName FName=Filename;
// strcpy(NewTex.Filename,Filename); NewTex.Name=FName.File();
NewTex.Path=Path; NewTex.Filename=Filename;
NewTex.Name=Name;
NewTex.FullFilename=NewTex.Path+NewTex.Name;
NewTex.Flags=Flags; NewTex.Flags=Flags;
if (!RGBData) // Need to load file if (!RGBData) // Need to load file
@ -45,7 +44,7 @@ sRGBData ThisRGB;
// TRACE1("Loading Texture %s\n",NewTex.Filename); // TRACE1("Loading Texture %s\n",NewTex.Filename);
if (!LoadBMP(NewTex.FullFilename,ThisRGB)) if (!LoadBMP(NewTex.Filename,ThisRGB))
{ {
exit(-1); exit(-1);
return(ListSize); return(ListSize);

View File

@ -22,9 +22,7 @@ struct sRGBData
struct sTex struct sTex
{ {
// char Filename[_MAX_PATH]; GString Filename;
GString FullFilename;
GString Path;
GString Name; GString Name;
GLuint TexID; GLuint TexID;
int Flags; int Flags;
@ -32,8 +30,7 @@ struct sTex
float dW,dH; float dW,dH;
bool Loaded; bool Loaded;
// bool operator==(sTex const &v1) {return (!strcmp(Filename,v1.Filename) && Flags==v1.Flags);} bool operator==(sTex const &v1) {return (Filename==v1.Filename && Flags==v1.Flags);}
bool operator==(sTex const &v1) {return (FullFilename==v1.FullFilename && Flags==v1.Flags);}
}; };
const RGBQUAD BlankRGB={255,0,255}; const RGBQUAD BlankRGB={255,0,255};
@ -46,9 +43,8 @@ class CTexCache
public: public:
int GetTexIdx(sTex &Tex) {return(TexList.Find(Tex));} int GetTexIdx(sTex &Tex) {return(TexList.Find(Tex));}
// int GetTexIdx(const char *Filename,int Flags);
int ProcessTexture(const char *Path,const char *Name,int Flags,sRGBData *RGBData=0); int ProcessTexture(const char *Name,int Flags,sRGBData *RGBData=0);
void Purge(); void Purge();
bool LoadBMP(const char *Filename,sRGBData &RGBData); bool LoadBMP(const char *Filename,sRGBData &RGBData);
@ -60,6 +56,7 @@ public:
void LoadTex(sTex &ThisTex,sRGBData *TexData); void LoadTex(sTex &ThisTex,sRGBData *TexData);
sTex &GetTex(int Id) {return(TexList[Id]);} sTex &GetTex(int Id) {return(TexList[Id]);}
GString &GetTexFilename(int Id) {return(TexList[Id].Filename);}
GString &GetTexName(int Id) {return(TexList[Id].Name);} GString &GetTexName(int Id) {return(TexList[Id].Name);}
GLuint GetTexGLId(int Id) {return(TexList[Id].TexID);} GLuint GetTexGLId(int Id) {return(TexList[Id].TexID);}

View File

@ -43,7 +43,7 @@ GString Filename;
// Get application path // Get application path
#ifdef _DEBUG #ifdef _DEBUG
ExePath="C:/Spongebob/tools/mapedit/"; ExePath="C:\\Spongebob\\tools\\mapedit\\";
#else #else
char ExeFilename[2048]; char ExeFilename[2048];
GetModuleFileName(GetModuleHandle(NULL),ExeFilename,2048); GetModuleFileName(GetModuleHandle(NULL),ExeFilename,2048);
@ -84,29 +84,14 @@ void CTileBank::SetCollision(bool f)
} }
} }
/*****************************************************************************/
char *FixName(const char *In)
{
char *Ptr=(char*)In;
while (*Ptr)
{
if (Ptr[0]=='T' &&
Ptr[1]=='I' &&
Ptr[2]=='L' &&
Ptr[3]=='E') return(Ptr);
Ptr++;
}
return(Ptr);
}
/*****************************************************************************/
void CTileBank::Load(CFile *File,int Version) void CTileBank::Load(CFile *File,int Version)
{ {
int ListSize; int ListSize;
GFName RootPath=File->GetFilePath(); GFName RootPath=File->GetFilePath();
GString FilePath; GString FilePath;
FilePath=RootPath.Drive(); FilePath=RootPath.Drive();
FilePath+=RootPath.Dir(); FilePath+=RootPath.Dir();
FilePath.Append('\\'); FilePath.Append('\\');
@ -124,22 +109,17 @@ GString FilePath;
// New Style rel storage // New Style rel storage
for (int i=0;i<ListSize;i++) for (int i=0;i<ListSize;i++)
{ {
char c=1;//,FullName[256+64]; char c=1;
GString RelName; GString FullName=FilePath;
int Len=0;
while (c) while (c)
{ {
File->Read(&c,1); File->Read(&c,1);
RelName.Append(c); FullName.Append(c);
} }
// RelName.Upper(); FullName.Upper();
CheckFilename(FullName);
{ // Dodgy arse artist fix AddTileSet(FullName);
// RelName=FixName(RelName);
}
// RootPath.makeabsolute(FilePath,RelName,FullName);
AddTileSet(RelName);
} }
} }
@ -148,12 +128,14 @@ void CTileBank::Save(CFile *File)
{ {
int ListSize=TileSet.size(); int ListSize=TileSet.size();
int NewListSize=ListSize-1; int NewListSize=ListSize-1;
GString FilePath;
GFName RootPath=File->GetFilePath(); GFName RootPath=File->GetFilePath();
GString SavePath;
FilePath=RootPath.Drive(); SavePath=RootPath.Drive();
FilePath+=RootPath.Dir(); SavePath+=RootPath.Dir();
FilePath.Append('\\'); SavePath.Append('\\');
SavePath.Upper();
File->Write(&NewListSize,sizeof(int)); File->Write(&NewListSize,sizeof(int));
File->Write(&CurrentSet,sizeof(int)); File->Write(&CurrentSet,sizeof(int));
@ -166,8 +148,7 @@ GFName RootPath=File->GetFilePath();
CTileSet &ThisSet=TileSet[i]; CTileSet &ThisSet=TileSet[i];
char Filename[256+64]; char Filename[256+64];
RootPath.makerelative(SavePath,ThisSet.GetFilename(),Filename);
RootPath.makerelative(FilePath,ThisSet.GetFilename(),Filename);
File->Write(Filename,strlen(Filename)+1); File->Write(Filename,strlen(Filename)+1);
} }
@ -397,15 +378,6 @@ BOOL CTileBank::IsTileValid(int Set,int Tile)
return(TileSet[Set].IsTileValid(Tile)); return(TileSet[Set].IsTileValid(Tile));
} }
/*****************************************************************************/
/*
BOOL CTileBank::IsTileValidGB(int Set,int Tile)
{
if (Set<0 || Tile<0) return(FALSE);
return(TileSet[Set].IsTileValidGB(Tile));
}
*/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*** TileSet *****************************************************************/ /*** TileSet *****************************************************************/
@ -413,10 +385,10 @@ BOOL CTileBank::IsTileValidGB(int Set,int Tile)
/*****************************************************************************/ /*****************************************************************************/
CTileSet::CTileSet(const char *_Filename,int Idx) CTileSet::CTileSet(const char *_Filename,int Idx)
{ {
if (_Filename) GFName FName=_Filename;
{
Filename=_Filename; Filename=_Filename;
} Name=FName.File();
Loaded=FALSE; Loaded=FALSE;
SetNumber=Idx; SetNumber=Idx;
@ -434,7 +406,8 @@ CTileSet::~CTileSet()
/*****************************************************************************/ /*****************************************************************************/
void CTileSet::Load(CCore *Core) void CTileSet::Load(CCore *Core)
{ {
GString Ext=Filename.Ext(); GFName FName=Filename;
GString Ext=FName.Ext();
Ext.Upper(); Ext.Upper();
if (Ext=="GIN") if (Ext=="GIN")
@ -455,28 +428,7 @@ void CTileSet::Load2d(CCore *Core)
{ {
CTexCache &TexCache=Core->GetTexCache(); CTexCache &TexCache=Core->GetTexCache();
GString ColTest; GString ColTest;
GString Path,Name; int TexID=TexCache.ProcessTexture(Filename,0);
ColTest=Filename.File();
ColTest.Append('.');
ColTest+=Filename.Ext();
if (ColTest==ColFName)
{// Collision thing (sigh!)
Path=Filename.Drive();
Path+=Filename.Dir();
Path.Append('\\');
Name=Filename.File();
Name.Append('.');
Name+=Filename.Ext();
}
else
{
Path=GetWorkingPath();
Name=Filename.FullName();
}
int TexID=TexCache.ProcessTexture(Path,Name,0);
sTex &ThisTex=TexCache.GetTex(TexID); sTex &ThisTex=TexCache.GetTex(TexID);
int Width=ThisTex.TexWidth/16; int Width=ThisTex.TexWidth/16;
@ -500,11 +452,8 @@ int Height=ThisTex.TexHeight/16;
void CTileSet::Load3d(CCore *Core) void CTileSet::Load3d(CCore *Core)
{ {
CScene Scene; CScene Scene;
GString FullFilename;
MakeFullFilename(Filename.FullName(),FullFilename); Scene.Load(Filename);
Scene.Load(FullFilename);
CNode &ThisNode=Scene.GetSceneNode(0); CNode &ThisNode=Scene.GetSceneNode(0);
int ChildCount=ThisNode.GetPruneChildCount(); int ChildCount=ThisNode.GetPruneChildCount();
@ -551,16 +500,6 @@ BOOL CTileSet::IsTileValid(int No)
{return(Tile[No].IsValid());} {return(Tile[No].IsValid());}
} }
/*****************************************************************************/
/*
BOOL CTileSet::IsTileValidGB(int No)
{
// ASSERT(No<Tile.size());
if (No>Tile.size()) return(FALSE);
return(Tile[No].IsValidGB());
}
*/
/*****************************************************************************/ /*****************************************************************************/
void CTileSet::Render(CCore *Core,Vector3 &CamPos,CMap &LBrush,CMap &RBrush,BOOL Render3d) void CTileSet::Render(CCore *Core,Vector3 &CamPos,CMap &LBrush,CMap &RBrush,BOOL Render3d)
{ {

View File

@ -115,8 +115,8 @@ public:
// const char *GetExt() {return(Filename.Ext());} // const char *GetExt() {return(Filename.Ext());}
// const char *GetFilename() {return(Filename.FullName());} // const char *GetFilename() {return(Filename.FullName());}
const char *GetFilename() {return(Filename.FullName());} const char *GetFilename() {return(Filename);}
const char *GetName() {return(Filename.File());} const char *GetName() {return(Name);}
CTile &GetTile(int No) {return(Tile[No]);} CTile &GetTile(int No) {return(Tile[No]);}
void Purge(); void Purge();
@ -134,7 +134,7 @@ private:
BOOL Create16x16Tile(sRGBData &Src,u8 *Dst,int XOfs,int YOfs); BOOL Create16x16Tile(sRGBData &Src,u8 *Dst,int XOfs,int YOfs);
CPoint GetTilePos(int ID); CPoint GetTilePos(int ID);
GFName Filename; GString Filename,Name;
int SetNumber; int SetNumber;
CList<CTile> Tile; CList<CTile> Tile;

View File

@ -288,3 +288,35 @@ GString Path;
return(Path); return(Path);
} }
/*****************************************************************************/
void CheckFilename(GString &Filename)
{
FILE *File;
CString mexstr;
GFName FName=Filename;
GString Name;
// Check File exists
File=fopen(Filename,"r");
if (File)
{
fclose(File);
return;
}
Name=FName.File();
Name.Append('.');
Name+=FName.Ext();
mexstr.Format("%s Not Found.\n\nPlease Locate\n", Filename);
AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION);
char BASED_CODE Filter[]= "All Files (*.*)|*.*||";
CFileDialog Dlg(true,NULL,Name,OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,Filter);
if (Dlg.DoModal()!=IDOK) return;
Filename=Dlg.GetPathName();
}

View File

@ -37,7 +37,6 @@ void DbgMsg(const char * pszFmt,...);
void BuildGLBox(float XMin,float XMax,float YMin,float YMax,float ZMin,float ZMax); void BuildGLBox(float XMin,float XMax,float YMin,float YMax,float ZMin,float ZMax);
void BuildGLBoxNoNormals(float XMin,float XMax,float YMin,float YMax,float ZMin,float ZMax); void BuildGLBoxNoNormals(float XMin,float XMax,float YMin,float YMax,float ZMin,float ZMax);
void BuildGLQuad(float XMin,float XMax,float YMin,float YMax,float Z); void BuildGLQuad(float XMin,float XMax,float YMin,float YMax,float Z);
int LoadGLTexture(char *FileName, GLuint &Text,int &Width,int &Height);
CPoint IDToPoint(int ID,int Width); CPoint IDToPoint(int ID,int Width);
int PointToID(CPoint &Pnt,int Width); int PointToID(CPoint &Pnt,int Width);
@ -52,5 +51,6 @@ void SetFileExt(char *InName,char *OutName,char *Ext);
void MakeFullFilename(const char *RelName,GString &Out); void MakeFullFilename(const char *RelName,GString &Out);
void MakePathRel2App(const char* In,char *Out); void MakePathRel2App(const char* In,char *Out);
GString GetWorkingPath(); GString GetWorkingPath();
void CheckFilename(GString &Filename);
#endif #endif

Binary file not shown.