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-02-01 23:48:22 +01:00
|
|
|
#include "Tile.h"
|
|
|
|
|
|
|
|
#include "Layer.h"
|
|
|
|
#include "LayerTile.h"
|
2000-11-24 23:34:20 +01:00
|
|
|
|
|
|
|
#include "Export.h"
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
2001-02-01 23:48:22 +01:00
|
|
|
CExport::CExport(char *Filename,int _LayerCount)
|
2000-11-24 23:34:20 +01:00
|
|
|
{
|
2001-02-01 23:48:22 +01:00
|
|
|
LayerCount=_LayerCount;
|
|
|
|
File=fopen(Filename,"wb");
|
|
|
|
|
|
|
|
// Write Dummy File Header
|
|
|
|
|
|
|
|
fwrite(&FileHdr,sizeof(sExpFileHdr),1,File);
|
|
|
|
for (int i=0;i<LayerCount; i++) fwrite(&LayerCount,sizeof(int),1,File);
|
2000-11-24 23:34:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
CExport::~CExport()
|
|
|
|
{
|
2001-02-01 23:48:22 +01:00
|
|
|
ASSERT(LayerCount==LayerOfs.size());
|
|
|
|
FileHdr.LayerCount=LayerCount;
|
|
|
|
// ReWrite Main Header
|
|
|
|
fseek(File,0,0);
|
|
|
|
fwrite(&FileHdr,sizeof(sExpFileHdr),1,File);
|
|
|
|
|
|
|
|
for (int i=0;i<LayerCount; i++)
|
|
|
|
{
|
|
|
|
TRACE1("LayerOfs %i\n",LayerOfs[i]);
|
|
|
|
fwrite(&LayerOfs[i],sizeof(int),1,File);
|
|
|
|
}
|
2000-11-24 23:34:20 +01:00
|
|
|
fclose(File);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-02-01 23:48:22 +01:00
|
|
|
/*** Tile Map ****************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CExport::ExportLayerTile(CCore *Core,char *LayerName,int SubType,CMap &Map)
|
|
|
|
{
|
|
|
|
sExpLayerHdr LayerHdr;
|
|
|
|
int Width=Map.GetWidth();
|
|
|
|
int Height=Map.GetHeight();
|
|
|
|
int ThisFilePos=ftell(File);
|
2001-02-06 23:25:39 +01:00
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
|
|
|
sExpTile BlankElem={0,0,0,0};
|
2001-02-01 23:48:22 +01:00
|
|
|
|
|
|
|
TRACE1("LayerTile Ofs %i\n",ThisFilePos);
|
|
|
|
LayerOfs.push_back(ThisFilePos);
|
|
|
|
|
|
|
|
LayerHdr.Type=LAYER_TYPE_TILE;
|
|
|
|
LayerHdr.SubType=SubType;
|
|
|
|
LayerHdr.Width=Map.GetWidth();
|
|
|
|
LayerHdr.Height=Map.GetHeight();
|
|
|
|
fwrite(&LayerHdr,sizeof(sExpLayerHdr),1,File);
|
|
|
|
|
|
|
|
UsedTileList.Add(BlankElem); // Ensure blank tile is present
|
|
|
|
|
|
|
|
for (int Y=0; Y<Height; Y++)
|
|
|
|
{
|
|
|
|
for (int X=0; X<Width; X++)
|
|
|
|
{
|
|
|
|
sMapElem &MapElem=Map.Get(X,Y);
|
2001-02-06 23:25:39 +01:00
|
|
|
CTile &ThisTile=Core->GetTile(MapElem.Set,MapElem.Tile);
|
2001-02-02 20:18:13 +01:00
|
|
|
sExpLayerTile OutElem;
|
2001-02-06 23:25:39 +01:00
|
|
|
sExpTile OutTile;
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
OutTile.Set=MapElem.Set;
|
|
|
|
OutTile.Tile=MapElem.Tile;
|
|
|
|
OutTile.TriCount=0;
|
|
|
|
OutTile.XOfs=ThisTile.GetTexXOfs();
|
|
|
|
OutTile.YOfs=ThisTile.GetTexYOfs();
|
2001-02-02 20:18:13 +01:00
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
OutElem.Tile=UsedTileList.Add(OutTile);
|
2001-02-01 23:48:22 +01:00
|
|
|
OutElem.Flags=MapElem.Flags;
|
|
|
|
fwrite(&OutElem,sizeof(sExpLayerTile),1,File);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Collision Layer *********************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CExport::ExportLayerCollision(CCore *Core,char *LayerName,int SubType,CMap &Map)
|
2001-01-24 23:35:11 +01:00
|
|
|
{
|
2001-02-01 23:48:22 +01:00
|
|
|
sExpLayerHdr LayerHdr;
|
|
|
|
int Width=Map.GetWidth();
|
|
|
|
int Height=Map.GetHeight();
|
|
|
|
int ThisFilePos=ftell(File);
|
|
|
|
u8 OutElem;
|
2001-01-24 23:35:11 +01:00
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
TRACE1("LayerCollision Ofs %i\n",ThisFilePos);
|
|
|
|
LayerOfs.push_back(ThisFilePos);
|
2001-01-24 23:35:11 +01:00
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
LayerHdr.Type=LAYER_TYPE_COLLISION;
|
|
|
|
LayerHdr.SubType=SubType;
|
|
|
|
LayerHdr.Width=Map.GetWidth();
|
|
|
|
LayerHdr.Height=Map.GetHeight();
|
|
|
|
fwrite(&LayerHdr,sizeof(sExpLayerHdr),1,File);
|
|
|
|
|
|
|
|
for (int Y=0; Y<Height; Y++)
|
2001-01-24 23:35:11 +01:00
|
|
|
{
|
2001-02-01 23:48:22 +01:00
|
|
|
for (int X=0; X<Width; X++)
|
2001-01-24 23:35:11 +01:00
|
|
|
{
|
2001-02-01 23:48:22 +01:00
|
|
|
sMapElem &MapElem=Map.Get(X,Y);
|
|
|
|
OutElem=0;
|
|
|
|
if (MapElem.Tile)
|
|
|
|
{
|
|
|
|
OutElem=((MapElem.Tile-1)*4)+1;
|
|
|
|
OutElem+=MapElem.Flags & TILE_FLAG_MIRROR_XY;
|
|
|
|
}
|
|
|
|
fwrite(&OutElem,sizeof(u8),1,File);
|
2001-01-24 23:35:11 +01:00
|
|
|
}
|
|
|
|
}
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Tiles *******************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CExport::ExportTiles(CCore *Core)
|
|
|
|
{
|
|
|
|
int ListSize,i;
|
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
FileHdr.TileW=Core->GetTile(1,0).GetPCTexW();
|
|
|
|
FileHdr.TileH=Core->GetTile(1,0).GetPCTexH();
|
|
|
|
|
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-02-06 23:25:39 +01:00
|
|
|
CTile &ThisTile=Core->GetTile(OutTile.Set,OutTile.Tile);
|
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
2001-02-01 23:48:22 +01:00
|
|
|
int RGBW=ThisTile.GetPCTexW();
|
|
|
|
int RGBH=ThisTile.GetPCTexH();
|
|
|
|
u8 *RGB=ThisTile.GetPCTexRGB();
|
2001-02-06 23:25:39 +01:00
|
|
|
GString SetName=TileBank.GetSet(OutTile.Set).GetFilename();
|
2001-01-24 23:35:11 +01:00
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
if (ThisTile.IsTile3d())
|
|
|
|
{
|
|
|
|
ExportTile3d(Core,ThisTile,OutTile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
// change set name to set mappping
|
|
|
|
if (OutTile.Set==0)
|
|
|
|
{
|
|
|
|
SetName="BLANK";
|
|
|
|
}
|
|
|
|
|
|
|
|
OutTile.Set=SetNames.Add(SetName);
|
2001-02-01 23:48:22 +01:00
|
|
|
fwrite(&OutTile,sizeof(sExpTile),1,File);
|
2001-02-06 23:25:39 +01:00
|
|
|
// Write RGB
|
|
|
|
ASSERT(RGBW==FileHdr.TileW);
|
|
|
|
ASSERT(RGBH==FileHdr.TileH);
|
2001-02-01 23:48:22 +01:00
|
|
|
fwrite(RGB,RGBW*RGBH*3,1,File);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-02-06 23:25:39 +01:00
|
|
|
void CExport::ExportTile3d(CCore *Core,CTile &ThisTile,sExpTile &OutTile)
|
2001-02-01 23:48:22 +01:00
|
|
|
{
|
2001-02-06 23:25:39 +01:00
|
|
|
CTexCache &TexCache=Core->GetTexCache();
|
|
|
|
std::vector<sTriFace> &TileTriList=ThisTile.GetTriList();
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
int TriCount=TileTriList.size();
|
|
|
|
|
|
|
|
OutTile.TriStart=TriList.size();
|
|
|
|
OutTile.TriCount=TriCount;
|
|
|
|
|
|
|
|
for (int T=0; T<TriCount; T++)
|
2001-02-01 23:48:22 +01:00
|
|
|
{
|
2001-02-06 23:25:39 +01:00
|
|
|
sTriFace &InTri=TileTriList[T];
|
|
|
|
sExpTri OutTri;
|
|
|
|
GString TexName=TexCache.GetTexName(InTri.Mat);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
TriList.push_back(OutTri);
|
|
|
|
}
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
/*
|
2001-02-01 23:48:22 +01:00
|
|
|
void CExport::ExportTile3d(CCore *Core,CTile &ThisTile,sExpTile &OutTile)
|
|
|
|
{
|
|
|
|
CTexCache &TexCache=Core->GetTexCache();
|
|
|
|
std::vector<sTriFace> &TileTriList=ThisTile.GetTriList();
|
|
|
|
|
|
|
|
int TriCount=TileTriList.size();
|
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
// OutTile.TriStart=TriList.size();
|
|
|
|
// OutTile.TriCount=TriCount;
|
|
|
|
// OutTile.XOfs=-1;
|
|
|
|
// OutTile.YOfs=-1;
|
|
|
|
// OutTile.TexId=-1;
|
2001-02-01 23:48:22 +01:00
|
|
|
|
|
|
|
for (int T=0; T<TriCount; T++)
|
|
|
|
{
|
|
|
|
sTriFace &TileTri=TileTriList[T];
|
|
|
|
sTriFace OutTri;
|
2001-02-06 23:25:39 +01:00
|
|
|
// sExpTex OutTex;
|
2001-02-01 23:48:22 +01:00
|
|
|
|
|
|
|
for (int p=0; p<3; p++)
|
|
|
|
{
|
|
|
|
OutTri=TileTri;
|
|
|
|
// Texture
|
2001-02-06 23:25:39 +01:00
|
|
|
// sTex &TriTex=TexCache.GetTex(TileTri.Mat);
|
|
|
|
// OutTex.Filename=TriTex.Filename;
|
|
|
|
// OutTri.Mat=TexList.Add(OutTex);
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
TriList.push_back(OutTri);
|
|
|
|
}
|
|
|
|
// return(TriCount);
|
|
|
|
|
2001-02-06 23:25:39 +01:00
|
|
|
}
|
|
|
|
*/
|
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-06 23:25:39 +01:00
|
|
|
int ListSize,i;
|
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-06 23:25:39 +01:00
|
|
|
const char *Str=SetNames[i];
|
|
|
|
fwrite(Str,strlen(Str)+1,1,File);
|
|
|
|
}
|
|
|
|
// 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++)
|
|
|
|
{
|
|
|
|
const char *Str=TexNames[i];
|
|
|
|
fwrite(Str,strlen(Str)+1,1,File);
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
2001-02-06 23:25:39 +01:00
|
|
|
|
2001-02-01 23:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|