/**************/ /*** Export ***/ /**************/ #include "stdafx.h" #include #include "LayerTile.h" #include "Map.h" #include "utils.h" #include "Core.h" #include "TexCache.h" #include "TileSet.h" #include "Tile.h" #include "Layer.h" #include "LayerTile.h" #include "Export.h" /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ CExport::CExport(char *Filename) { File=fopen(Filename,"wb"); // Write Dummy File Header fwrite(&FileHdr,sizeof(sExpFileHdr),1,File); // for (int i=0;iGetTileBank(); sExpTile BlankElem={0,0,0,0}; 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; YGetTile(MapElem.Set,MapElem.Tile); sExpLayerTile OutElem; sExpTile OutTile; OutTile.Set=MapElem.Set; OutTile.Tile=MapElem.Tile; OutTile.TriCount=0; OutTile.XOfs=ThisTile.GetTexXOfs(); OutTile.YOfs=ThisTile.GetTexYOfs(); OutElem.Tile=UsedTileList.Add(OutTile); OutElem.Flags=MapElem.Flags; fwrite(&OutElem,sizeof(sExpLayerTile),1,File); } } } /*****************************************************************************/ /*** Collision Layer *********************************************************/ /*****************************************************************************/ void CExport::ExportLayerCollision(CCore *Core,char *LayerName,int SubType,CMap &Map) { sExpLayerHdr LayerHdr; int Width=Map.GetWidth(); int Height=Map.GetHeight(); int ThisFilePos=ftell(File); u8 OutElem; TRACE1("LayerCollision Ofs %i\n",ThisFilePos); LayerOfs.push_back(ThisFilePos); 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; YGetTile(1,0).GetPCTexW(); FileHdr.TileH=Core->GetTile(1,0).GetPCTexH(); // Write Tiles ListSize=UsedTileList.size(); FileHdr.TileCount=ListSize; FileHdr.TileOfs=ftell(File); for (i=0; iGetTile(OutTile.Set,OutTile.Tile); CTileBank &TileBank=Core->GetTileBank(); int RGBW=ThisTile.GetPCTexW(); int RGBH=ThisTile.GetPCTexH(); u8 *RGB=ThisTile.GetPCTexRGB(); GString SetName=TileBank.GetSet(OutTile.Set).GetFilename(); if (ThisTile.IsTile3d()) { ExportTile3d(Core,ThisTile,OutTile); } else { } // 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::ExportTile3d(CCore *Core,CTile &ThisTile,sExpTile &OutTile) { CTexCache &TexCache=Core->GetTexCache(); std::vector &TileTriList=ThisTile.GetTriList(); int TriCount=TileTriList.size(); OutTile.TriStart=TriList.size(); OutTile.TriCount=TriCount; for (int T=0; T