This commit is contained in:
Daveo 2001-02-06 22:25:39 +00:00
parent d238e6ac10
commit ff8ae0c77b
10 changed files with 177 additions and 125 deletions

View File

@ -817,7 +817,7 @@ CExport Exp(ExportName,LayerCount);
}
Exp.ExportTiles(this);
Exp.ExportTexList(this);
Exp.ExportStrList(this);
}

View File

@ -60,7 +60,8 @@ sExpLayerHdr LayerHdr;
int Width=Map.GetWidth();
int Height=Map.GetHeight();
int ThisFilePos=ftell(File);
sExpMapElem BlankElem={0,0,0};
CTileBank &TileBank=Core->GetTileBank();
sExpTile BlankElem={0,0,0,0};
TRACE1("LayerTile Ofs %i\n",ThisFilePos);
LayerOfs.push_back(ThisFilePos);
@ -78,14 +79,17 @@ sExpMapElem BlankElem={0,0,0};
for (int X=0; X<Width; X++)
{
sMapElem &MapElem=Map.Get(X,Y);
sExpMapElem TileElem;
CTile &ThisTile=Core->GetTile(MapElem.Set,MapElem.Tile);
sExpLayerTile OutElem;
sExpTile OutTile;
TileElem.Tile=MapElem.Tile;
TileElem.Set=MapElem.Set;
TileElem.Flags=MapElem.Flags;
OutTile.Set=MapElem.Set;
OutTile.Tile=MapElem.Tile;
OutTile.TriCount=0;
OutTile.XOfs=ThisTile.GetTexXOfs();
OutTile.YOfs=ThisTile.GetTexYOfs();
OutElem.Tile=UsedTileList.Add(TileElem);
OutElem.Tile=UsedTileList.Add(OutTile);
OutElem.Flags=MapElem.Flags;
fwrite(&OutElem,sizeof(sExpLayerTile),1,File);
}
@ -135,6 +139,9 @@ void CExport::ExportTiles(CCore *Core)
{
int ListSize,i;
FileHdr.TileW=Core->GetTile(1,0).GetPCTexW();
FileHdr.TileH=Core->GetTile(1,0).GetPCTexH();
// Write Tiles
ListSize=UsedTileList.size();
FileHdr.TileCount=ListSize;
@ -142,14 +149,7 @@ int ListSize,i;
for (i=0; i<ListSize; i++)
{
sExpMapElem &ThisElem=UsedTileList[i];
CTile &ThisTile=Core->GetTile(ThisElem.Set,ThisElem.Tile);
sExpTile OutTile;
OutTile.Flags=ThisElem.Flags;
TRACE3("%i %i %i\n",ThisElem.Set,ThisElem.Tile,ThisElem.Flags);
ExportTile(Core,ThisTile,OutTile);
ExportTile(Core,UsedTileList[i]);
}
// Write Tris
@ -158,20 +158,19 @@ int ListSize,i;
FileHdr.TriOfs=ftell(File);
for (i=0; i<ListSize; i++)
{
fwrite(&TriList[i],sizeof(sTriFace),1,File);
fwrite(&TriList[i],sizeof(sExpTri),1,File);
}
TRACE1("TriCount=%i\n",ListSize);
}
/*****************************************************************************/
void CExport::ExportTile(CCore *Core,CTile &ThisTile,sExpTile &OutTile)
void CExport::ExportTile(CCore *Core,sExpTile &OutTile)
{
CTile &ThisTile=Core->GetTile(OutTile.Set,OutTile.Tile);
CTileBank &TileBank=Core->GetTileBank();
int RGBW=ThisTile.GetPCTexW();
int RGBH=ThisTile.GetPCTexH();
u8 *RGB=ThisTile.GetPCTexRGB();
OutTile.W=RGBW;
OutTile.H=RGBH;
GString SetName=TileBank.GetSet(OutTile.Set).GetFilename();
if (ThisTile.IsTile3d())
{
@ -179,40 +178,23 @@ u8 *RGB=ThisTile.GetPCTexRGB();
}
else
{
ExportTile2d(Core,ThisTile,OutTile);
}
// change set name to set mappping
if (OutTile.Set==0)
{
SetName="BLANK";
}
OutTile.Set=SetNames.Add(SetName);
fwrite(&OutTile,sizeof(sExpTile),1,File);
// Write RGB
ASSERT(RGBW==FileHdr.TileW);
ASSERT(RGBH==FileHdr.TileH);
fwrite(RGB,RGBW*RGBH*3,1,File);
}
/*****************************************************************************/
void CExport::ExportTile2d(CCore *Core,CTile &ThisTile,sExpTile &OutTile)
{
CTexCache &TexCache=Core->GetTexCache();
OutTile.TriStart=-1;
OutTile.TriCount=0;
OutTile.XOfs=ThisTile.GetTexXOfs();
OutTile.YOfs=ThisTile.GetTexYOfs();
// Texture
int TexID=ThisTile.GetTexID();
if (TexID==-1) // Blank Tile
{
OutTile.TexId=-1;
}
else
{
sExpTex OutTex;
sTex &ThisTex=TexCache.GetTex(TexID);
OutTex.Filename=ThisTex.Filename;
OutTile.TexId=TexList.Add(OutTex);
}
}
/*****************************************************************************/
void CExport::ExportTile3d(CCore *Core,CTile &ThisTile,sExpTile &OutTile)
{
@ -223,51 +205,84 @@ 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 &InTri=TileTriList[T];
sExpTri OutTri;
GString TexName=TexCache.GetTexName(InTri.Mat);
OutTri.TexID=TexNames.Add(TexName);
for (int p=0; p<3; p++)
{
OutTri.vtx[p]=InTri.vtx[p];
OutTri.uv[p][0]=InTri.uvs[p].u;
OutTri.uv[p][1]=InTri.uvs[p].v;
}
TriList.push_back(OutTri);
}
}
/*
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;
// 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);
// sTex &TriTex=TexCache.GetTex(TileTri.Mat);
// OutTex.Filename=TriTex.Filename;
// OutTri.Mat=TexList.Add(OutTex);
}
TriList.push_back(OutTri);
}
// return(TriCount);
}
*/
/*****************************************************************************/
/*** Textures ****************************************************************/
/*****************************************************************************/
void CExport::ExportTexList(CCore *Core)
void CExport::ExportStrList(CCore *Core)
{
int TexCount=TexList.size();
int ListSize,i;
FileHdr.TexCount=TexCount;
FileHdr.TexOfs=ftell(File);
// Set List
ListSize=SetNames.size();
FileHdr.SetNameCount=ListSize;
FileHdr.SetNameOfs=ftell(File);
for (int i=0; i<TexCount; i++)
for (i=0; i<ListSize; i++)
{
sExpTex &ThisTex=TexList[i];
char TexFilename[256];
MakePathRel2App(ThisTex.Filename,TexFilename);
int Len=strlen(TexFilename);
fwrite(TexFilename,Len+1,1,File);
TRACE2("%i:\t%s\n",i,TexFilename);
const char *Str=SetNames[i];
fwrite(Str,strlen(Str)+1,1,File);
}
// Tex List
ListSize=TexNames.size();
FileHdr.TexNameCount=ListSize;
FileHdr.TexNameOfs=ftell(File);
for (i=0; i<ListSize; i++)
{
const char *Str=TexNames[i];
fwrite(Str,strlen(Str)+1,1,File);
}
}
/*****************************************************************************/

View File

@ -8,8 +8,6 @@
#include "stdafx.h"
#include "mapedit.h"
#include <Vector>
//#include "GinTex.h"
//#include "Tile.h"
#include <List.h>
#include "ExportHdr.h"
@ -31,10 +29,10 @@ public:
void ExportLayerCollision(CCore *Core,char *LayerName,int SubType,CMap &Map);
void ExportTiles(CCore *Core);
void ExportTexList(CCore *Core);
void ExportStrList(CCore *Core);
protected:
void ExportTile(CCore *Core,CTile &ThisTile,sExpTile &OutTile);
void ExportTile(CCore *Core,sExpTile &ThisElem);
void ExportTile3d(CCore *Core,CTile &ThisTile,sExpTile &OutTile);
void ExportTile2d(CCore *Core,CTile &ThisTile,sExpTile &OutTile);
@ -43,14 +41,13 @@ protected:
int LayerCount;
CList<int> LayerOfs;
CList<sTriFace> TriList;
CList<sExpTex> TexList;
CList<sExpTri> TriList;
CList<sExpMapElem> UsedTileList;
CList<GString> SetNames;
CList<GString> TexNames;
// GString Filename;
CList<sExpTile> UsedTileList;
FILE *File;
// int Count;
};

View File

@ -15,26 +15,42 @@
struct sExpFileHdr
{
int TileCount;
// int TileW,TileH;
int TileOfs;
int TileW,TileH;
int TriCount;
int TriOfs;
int TexCount;
int TexOfs;
int SetNameCount;
int SetNameOfs;
int TexNameCount;
int TexNameOfs;
int LayerCount;
// int LayerOfs[n]
};
/*****************************************************************************/
struct sExpTile // 2d 3d
struct sExpTile
{
int TriStart; // -1 n
int TriCount; // -1 n
int XOfs,YOfs; // n -1
int TexId; // n -1
int Flags;
int W,H;
u8 *RGB; // Used in MkLevel
int Set;
int Tile;
int TriStart;
int TriCount;
u16 XOfs,YOfs;
u8 *RGB;
// int TexId; // n -1
// int Flags; // Flip Flags
bool operator==(sExpTile const &v1)
{
return(Set==v1.Set && Tile==v1.Tile);
}
};
/*****************************************************************************/
struct sExpTri
{
int TexID;
Vector3 vtx[3];
float uv[3][2];
};
/*****************************************************************************/
@ -51,33 +67,34 @@ struct sExpLayerHdr
/*****************************************************************************/
struct sExpLayerTile
{
int Tile;
int Flags;
BOOL operator==(sExpLayerTile const &v1) {return (Tile==v1.Tile);}
u16 Tile;
u16 Flags;
// bool operator==(sExpLayerTile const &v1) {return (Tile==v1.Tile);}
};
/*****************************************************************************/
/*
struct sExpTex
{
char *Filename;
BOOL operator==(sExpTex const &v1) {return (!strcmp(Filename,v1.Filename));}
};
*/
/*
struct sExpMapElem
{
int Set;
int Tile;
int Flags;
u16 Set;
u16 Tile;
u16 Flags;
BOOL operator==(sExpMapElem const &v1) // Does Check flags
BOOL operator==(sExpMapElem const &v1)
{
return(Set==v1.Set && Tile==v1.Tile);
// return(Set==v1.Set && Tile==v1.Tile && Flags==v1.Flags);
}
};
*/
/*****************************************************************************/
#endif

View File

@ -158,8 +158,6 @@ Vector3 Ofs;
Ofs.y=-(CursPos.y-(int)ThisCam.y);
ThisCam.x-=(int)ThisCam.x;
ThisCam.y-=(int)ThisCam.y;
TRACE2("-> %f %f\n",Ofs.x,Ofs.y);
if (Is3d && Render3dFlag)
{

View File

@ -14,26 +14,28 @@
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
int CTexCache::GetTexIdx(char *Filename,int Flags)
/*
int CTexCache::GetTexIdx(const char *Filename,int Flags)
{
sTex Tex;
strcpy(Tex.Filename,Filename);
Tex.Filename=Filename;
Tex.Flags=Flags;
return(TexList.Find(Tex));
}
*/
/*****************************************************************************/
// Checks loaded files for dups, assumes all passed RGB is unique
int CTexCache::ProcessTexture(const char *Filename,int Flags,sRGBData *RGBData)
int CTexCache::ProcessTexture(const char *Path,const char *Name,int Flags,sRGBData *RGBData)
{
int ListSize=TexList.size();
sTex NewTex;
sRGBData ThisRGB;
strcpy(NewTex.Filename,Filename);
NewTex.Flags=Flags;
// strcpy(NewTex.Filename,Filename);
NewTex.Path=Path;
NewTex.Name=Name;
NewTex.FullFilename=NewTex.Path+NewTex.Name;
NewTex.Flags=Flags;
if (!RGBData) // Need to load file
@ -43,7 +45,7 @@ sRGBData ThisRGB;
// TRACE1("Loading Texture %s\n",NewTex.Filename);
if (!LoadBMP(NewTex.Filename,ThisRGB))
if (!LoadBMP(NewTex.FullFilename,ThisRGB))
{
exit(-1);
return(ListSize);
@ -81,7 +83,7 @@ int CTexCache::AlignSize(int Size)
/**************************************************************************************/
bool CTexCache::LoadBMP(char *Filename,sRGBData &RGBData)
bool CTexCache::LoadBMP(const char *Filename,sRGBData &RGBData)
{
Frame ThisFrame;
FILE *File;

View File

@ -11,6 +11,7 @@
#include <Vector>
#include "Utils.h"
#include "List.h"
#include <misc.hpp>
struct sRGBData
{
@ -21,14 +22,18 @@ struct sRGBData
struct sTex
{
char Filename[_MAX_PATH];
// char Filename[_MAX_PATH];
GString FullFilename;
GString Path;
GString Name;
GLuint TexID;
int Flags;
int TexWidth,TexHeight;
float dW,dH;
bool Loaded;
bool operator==(sTex const &v1) {return (!strcmp(Filename,v1.Filename) && Flags==v1.Flags);}
// bool operator==(sTex const &v1) {return (!strcmp(Filename,v1.Filename) && Flags==v1.Flags);}
bool operator==(sTex const &v1) {return (FullFilename==v1.FullFilename && Flags==v1.Flags);}
};
const RGBQUAD BlankRGB={255,0,255};
@ -41,12 +46,12 @@ class CTexCache
public:
int GetTexIdx(sTex &Tex) {return(TexList.Find(Tex));}
int GetTexIdx(char *Filename,int Flags);
// int GetTexIdx(const char *Filename,int Flags);
int ProcessTexture(const char *Filename,int Flags,sRGBData *RGBData=0);
int ProcessTexture(const char *Path,const char *Name,int Flags,sRGBData *RGBData=0);
void Purge();
bool LoadBMP(char *Filename,sRGBData &RGBData);
bool LoadBMP(const char *Filename,sRGBData &RGBData);
void FreeBMP(sRGBData &RGBData);
void FixBMP(sRGBData &RGBData);
bool IsSizeOk(int Size);
@ -54,8 +59,8 @@ public:
void LoadTex(sTex &ThisTex,sRGBData *TexData);
sTex &GetTex(int Id) {return(TexList[Id]);}
GString &GetTexName(int Id) {return(TexList[Id].Name);}
GLuint GetTexGLId(int Id) {return(TexList[Id].TexID);}

View File

@ -454,22 +454,29 @@ GString Ext=Filename.Ext();
void CTileSet::Load2d(CCore *Core)
{
CTexCache &TexCache=Core->GetTexCache();
GString FullFilename;
GString ColTest;
GString Path,Name;
ColTest=Filename.File();
ColTest.Append('.');
ColTest+=Filename.Ext();
if (ColTest==ColFName)
{// Collision thing (sigh!)
FullFilename=Filename.FullName();
Path=Filename.Drive();
Path+=Filename.Dir();
Path.Append('\\');
Name=Filename.File();
Name.Append('.');
Name+=Filename.Ext();
}
else
{
MakeFullFilename(Filename.FullName(),FullFilename);
Path=GetWorkingPath();
Name=Filename.FullName();
}
int TexID=TexCache.ProcessTexture(FullFilename,0);
int TexID=TexCache.ProcessTexture(Path,Name,0);
sTex &ThisTex=TexCache.GetTex(TexID);
int Width=ThisTex.TexWidth/16;

View File

@ -266,8 +266,6 @@ GString Path;
Out=Path;
Out+=In;
}
/**************************************************************************************/
@ -278,3 +276,15 @@ GString RootPath=theApp.GetCurrent()->GetPathName();
GFName::makerelative(RootPath,In,Out);
}
/**************************************************************************************/
GString GetWorkingPath()
{
GFName FullPath=theApp.GetCurrent()->GetPathName();
GString Path;
Path=FullPath.Drive();
Path+=FullPath.Dir();
Path.Append('\\');
return(Path);
}

View File

@ -51,5 +51,6 @@ void SetFileExt(char *InName,char *OutName,char *Ext);
void MakeFullFilename(const char *RelName,GString &Out);
void MakePathRel2App(const char* In,char *Out);
GString GetWorkingPath();
#endif