2000-11-24 23:34:20 +01:00
|
|
|
/**************/
|
|
|
|
/*** Export ***/
|
|
|
|
/**************/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <Vector>
|
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
#include "LayerTile.h"
|
|
|
|
#include "Map.h"
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
2000-11-24 23:34:20 +01:00
|
|
|
#include "Core.h"
|
2001-02-01 23:48:22 +01:00
|
|
|
#include "TexCache.h"
|
2000-11-24 23:34:20 +01:00
|
|
|
#include "TileSet.h"
|
2001-03-05 21:49:46 +01:00
|
|
|
#include "Elem.h"
|
2001-02-01 23:48:22 +01:00
|
|
|
|
|
|
|
#include "Layer.h"
|
|
|
|
#include "LayerTile.h"
|
2000-11-24 23:34:20 +01:00
|
|
|
|
|
|
|
#include "Export.h"
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
2001-02-07 22:31:31 +01:00
|
|
|
CExport::CExport(char *Filename)
|
2000-11-24 23:34:20 +01:00
|
|
|
{
|
2001-02-01 23:48:22 +01:00
|
|
|
File=fopen(Filename,"wb");
|
|
|
|
|
|
|
|
// Write Dummy File Header
|
|
|
|
|
|
|
|
fwrite(&FileHdr,sizeof(sExpFileHdr),1,File);
|
2001-03-05 21:49:46 +01:00
|
|
|
|
|
|
|
// Add blank tile
|
|
|
|
|
|
|
|
sExpTile BlankElem={0,0,0,0,0,0,0};
|
|
|
|
AddTile(BlankElem);
|
2000-11-24 23:34:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
CExport::~CExport()
|
|
|
|
{
|
2001-02-07 22:31:31 +01:00
|
|
|
int LayerCount=LayerOfs.size();
|
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
FileHdr.LayerCount=LayerCount;
|
|
|
|
|
|
|
|
for (int i=0;i<LayerCount; i++)
|
|
|
|
{
|
2001-02-07 22:31:31 +01:00
|
|
|
FileHdr.LayerOfs[i]=LayerOfs[i];
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
2001-02-07 22:31:31 +01:00
|
|
|
|
|
|
|
// ReWrite Main Header
|
|
|
|
fseek(File,0,0);
|
|
|
|
fwrite(&FileHdr,sizeof(sExpFileHdr),1,File);
|
2000-11-24 23:34:20 +01:00
|
|
|
fclose(File);
|
|
|
|
}
|
|
|
|
|
2001-04-09 16:25:21 +02:00
|
|
|
/*****************************************************************************/
|
2001-04-23 16:51:44 +02:00
|
|
|
void CExport::PadFile()
|
2001-04-09 16:25:21 +02:00
|
|
|
{
|
|
|
|
int Pad=ftell(File) & 3;
|
|
|
|
|
|
|
|
if (Pad)
|
|
|
|
{
|
|
|
|
fwrite(&Pad,Pad,1,File);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-16 19:23:01 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CExport::Write(void *Addr,int Len)
|
|
|
|
{
|
|
|
|
fwrite(Addr,Len,1,File);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-03-26 23:29:09 +02:00
|
|
|
int CExport::ExportLayerHeader(sLayerDef &LayerDef)//(int Type,int SubType,int Width,int Height)
|
2001-02-16 19:23:01 +01:00
|
|
|
{
|
2001-04-23 16:51:44 +02:00
|
|
|
PadFile();
|
2001-02-16 19:23:01 +01:00
|
|
|
sExpLayerHdr LayerHdr;
|
|
|
|
int ThisFilePos=ftell(File);
|
|
|
|
|
|
|
|
LayerOfs.push_back(ThisFilePos);
|
2001-04-09 16:25:21 +02:00
|
|
|
|
2001-02-16 19:23:01 +01:00
|
|
|
|
2001-03-26 23:29:09 +02:00
|
|
|
LayerHdr.Type=LayerDef.Type;
|
|
|
|
LayerHdr.SubType=LayerDef.SubType;
|
|
|
|
LayerHdr.Width=LayerDef.Width;
|
|
|
|
LayerHdr.Height=LayerDef.Height;
|
2001-02-16 19:23:01 +01:00
|
|
|
fwrite(&LayerHdr,sizeof(sExpLayerHdr),1,File);
|
|
|
|
|
|
|
|
return(ThisFilePos);
|
|
|
|
}
|
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Tiles *******************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CExport::ExportTiles(CCore *Core)
|
|
|
|
{
|
|
|
|
int ListSize,i;
|
2001-03-01 18:28:20 +01:00
|
|
|
CTileBank *TileBank=Core->GetTileBank();
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-03-05 21:49:46 +01:00
|
|
|
//!! FileHdr.TileW=TileBank->GetTile(0,0).GetElemWidth();
|
|
|
|
//!! FileHdr.TileH=TileBank->GetTile(0,0).GetElemHeight();
|
|
|
|
FileHdr.TileW=16;
|
|
|
|
FileHdr.TileH=16;
|
2001-02-06 23:25:39 +01:00
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
// Write Tiles
|
|
|
|
ListSize=UsedTileList.size();
|
|
|
|
FileHdr.TileCount=ListSize;
|
|
|
|
FileHdr.TileOfs=ftell(File);
|
|
|
|
|
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-02-06 23:25:39 +01:00
|
|
|
ExportTile(Core,UsedTileList[i]);
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write Tris
|
|
|
|
ListSize=TriList.size();
|
|
|
|
FileHdr.TriCount=ListSize;
|
|
|
|
FileHdr.TriOfs=ftell(File);
|
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-02-06 23:25:39 +01:00
|
|
|
fwrite(&TriList[i],sizeof(sExpTri),1,File);
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-02-06 23:25:39 +01:00
|
|
|
void CExport::ExportTile(CCore *Core,sExpTile &OutTile)
|
2001-02-01 23:48:22 +01:00
|
|
|
{
|
2001-03-01 18:28:20 +01:00
|
|
|
CTileBank *TileBank=Core->GetTileBank();
|
2001-01-24 23:35:11 +01:00
|
|
|
|
2001-03-05 21:49:46 +01:00
|
|
|
if (OutTile.Set==0 && OutTile.Tile==0)
|
2001-02-01 23:48:22 +01:00
|
|
|
{
|
2001-03-05 21:49:46 +01:00
|
|
|
char c=0;
|
|
|
|
|
|
|
|
fwrite(&OutTile,sizeof(sExpTile),1,File);
|
|
|
|
fwrite(&c,1,16*16*3,File); // Write RGB
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 21:49:58 +01:00
|
|
|
CElem &ThisTile=TileBank->GetElem(OutTile.Set,OutTile.Tile);
|
2001-03-05 21:49:46 +01:00
|
|
|
GString SetName=TileBank->GetSetFilename(OutTile.Set);
|
|
|
|
|
|
|
|
ASSERT(ThisTile.GetElemWidth()==FileHdr.TileW);
|
|
|
|
ASSERT(ThisTile.GetElemHeight()==FileHdr.TileH);
|
2001-04-23 16:51:44 +02:00
|
|
|
if (ThisTile.IsElem3d())
|
|
|
|
{
|
|
|
|
ExportTile3d(Core,ThisTile,OutTile);
|
|
|
|
}
|
2001-03-05 21:49:46 +01:00
|
|
|
OutTile.Set=SetNames.Add(SetName);
|
|
|
|
fwrite(&OutTile,sizeof(sExpTile),1,File);
|
|
|
|
fwrite(ThisTile.GetElemRGB(),FileHdr.TileW*FileHdr.TileH*3,1,File); // Write RGB
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-03-05 21:49:46 +01:00
|
|
|
void CExport::ExportTile3d(CCore *Core,CElem &ThisTile,sExpTile &OutTile)
|
2001-04-23 16:51:44 +02:00
|
|
|
{
|
|
|
|
ExportElem3d(Core,ThisTile,OutTile.TriStart,OutTile.TriCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-05-01 18:54:13 +02:00
|
|
|
void CExport::ExportElem3d(CCore *Core,CElem &ThisElem,int &TriStart,int &TriCount)
|
2001-02-01 23:48:22 +01:00
|
|
|
{
|
2001-02-06 23:25:39 +01:00
|
|
|
CTexCache &TexCache=Core->GetTexCache();
|
2001-05-01 18:54:13 +02:00
|
|
|
std::vector<sTriFace> &ElemTriList=ThisElem.GetTriList();
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-04-23 16:51:44 +02:00
|
|
|
TriStart=TriList.size();
|
2001-05-01 18:54:13 +02:00
|
|
|
TriCount=ElemTriList.size();
|
2001-02-06 23:25:39 +01:00
|
|
|
|
|
|
|
for (int T=0; T<TriCount; T++)
|
2001-02-01 23:48:22 +01:00
|
|
|
{
|
2001-05-01 18:54:13 +02:00
|
|
|
sTriFace &InTri=ElemTriList[T];
|
2001-02-06 23:25:39 +01:00
|
|
|
sExpTri OutTri;
|
2001-02-07 19:46:59 +01:00
|
|
|
GString TexName=TexCache.GetTexFilename(InTri.Mat);
|
2001-02-06 23:25:39 +01:00
|
|
|
OutTri.TexID=TexNames.Add(TexName);
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
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;
|
|
|
|
}
|
2001-05-05 23:18:12 +02:00
|
|
|
OutTri.Flags=InTri.Flags;
|
2001-02-06 23:25:39 +01:00
|
|
|
TriList.push_back(OutTri);
|
|
|
|
}
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-02-06 23:25:39 +01:00
|
|
|
void CExport::ExportStrList(CCore *Core)
|
2001-02-01 23:48:22 +01:00
|
|
|
{
|
2001-02-07 19:46:59 +01:00
|
|
|
int ListSize,i;
|
|
|
|
GString SavePath=GetWorkingPath();
|
|
|
|
char RelStr[256];
|
|
|
|
|
|
|
|
SavePath.Upper();
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
// Set List
|
|
|
|
ListSize=SetNames.size();
|
|
|
|
FileHdr.SetNameCount=ListSize;
|
|
|
|
FileHdr.SetNameOfs=ftell(File);
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
for (i=0; i<ListSize; i++)
|
2001-02-01 23:48:22 +01:00
|
|
|
{
|
2001-02-07 19:46:59 +01:00
|
|
|
GString &ThisFile=SetNames[i];
|
|
|
|
ThisFile.Upper();
|
|
|
|
GFName::makerelative(SavePath,ThisFile,RelStr);
|
|
|
|
fwrite(RelStr,strlen(RelStr)+1,1,File);
|
2001-03-05 21:49:46 +01:00
|
|
|
TRACE2("Set %i:%s\n",i,RelStr);
|
2001-02-06 23:25:39 +01:00
|
|
|
}
|
|
|
|
// Tex List
|
|
|
|
ListSize=TexNames.size();
|
|
|
|
FileHdr.TexNameCount=ListSize;
|
|
|
|
FileHdr.TexNameOfs=ftell(File);
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-02-07 19:46:59 +01:00
|
|
|
GString &ThisFile=TexNames[i];
|
|
|
|
ThisFile.Upper();
|
|
|
|
GFName::makerelative(SavePath,ThisFile,RelStr);
|
|
|
|
fwrite(RelStr,strlen(RelStr)+1,1,File);
|
2001-03-05 21:49:46 +01:00
|
|
|
TRACE2("Tex %i:%s\n",i,RelStr);
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
2001-02-06 23:25:39 +01:00
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|