/******************/ /*** Layer Tile ***/ /******************/ #include #include #include "MkLevelLayer.h" #include "MkLevelLayerTile.h" #include "pak.h" /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ CMkLevelLayerTile::CMkLevelLayerTile(sExpLayerHdr *LayerHdr) { Type=LayerHdr->Type; SubType=LayerHdr->SubType; Width=LayerHdr->Width; Height=LayerHdr->Height; sExpLayerTile *MapPtr=(sExpLayerTile *)((int)LayerHdr+sizeof(sExpLayerHdr)); InMap.SetSize(Width,Height); for (int Y=0; YTile; ThisTile.Flags=MapPtr->Flags; InMap.Set(X,Y,ThisTile); MapPtr++; } } } /*****************************************************************************/ /*****************************************************************************/ /*** Pre-Process *************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void CMkLevelLayerTile::PreProcess(CMkLevel *Core) { int Width=InMap.GetWidth(); int Height=InMap.GetHeight(); OutMap.SetSize(Width,Height); for (int Y=0; YAddTile2d(InElem); } } } } /*****************************************************************************/ /*****************************************************************************/ /*** Process *****************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void CMkLevelLayerTile::Process(CMkLevel *Core) { } /*****************************************************************************/ /*****************************************************************************/ /** Write ********************************************************************/ /*****************************************************************************/ /*****************************************************************************/ int CMkLevelLayerTile::Write(CMkLevel *Core,FILE *File,const char *LayerName) { int HdrPos=ftell(File); int Width=OutMap.GetWidth(); int Height=OutMap.GetHeight(); Hdr.Type=Type; Hdr.SubType=SubType; Hdr.Width=Width; Hdr.Height=Height; fwrite(&Hdr,sizeof(sLayerHdr),1,File); // printf("%s (%i,%i)= %i\n",LayerName,Width,Height,Width*Height*sizeof(sTileMapElem)); Core->GetPakWH(PakW,PakH); if (PakW && PakH) { int OrigSize=Width*Height*sizeof(sTileMapElem); printf("- PAKing Layer %s (%i,%i).. ",LayerName,Width,Height); int LvlSize=WritePak(Core,File); printf("%i bytes - Saved %i Bytes\n",LvlSize,OrigSize-LvlSize); } else { // printf("- Writing Layer %s (%i,%i).. ",LayerName,Width,Height); int LvlSize=WriteNormal(Core,File); // printf("%i bytes\n",LvlSize); } PadFile(File); // ReWrite Hdr int RetPos=ftell(File); fseek(File,HdrPos,SEEK_SET); fwrite(&Hdr,sizeof(sLayerHdr),1,File); fseek(File,RetPos,SEEK_SET); Size=ftell(File)-HdrPos; return(HdrPos); } /*****************************************************************************/ void CMkLevelLayerTile::BuildOutElem(int X,int Y,sTileMapElem *Out) { sMkLevelElem &In=OutMap.Get(X,Y); Out->Tile=In.Elem; } /*****************************************************************************/ int CMkLevelLayerTile::WriteNormal(CMkLevel *Core,FILE *File) { int Width=OutMap.GetWidth(); int Height=OutMap.GetHeight(); sTileMapElem OutElem; for (int Y=0; Y=PakW*PakH*sizeof(sTileMapElem)) GObject::Error(ERR_WARNING,"BAD PAK: %i>%i\n",PakSize,BufferSize); TotalPak+=PakSize; fwrite(&PakBuffer,PakSize,1,File); } } free(ChunkBuffer); free(PakBuffer); return(TotalPak); } /*****************************************************************************/ int CMkLevelLayerTile::BuildPakChunk(int X,int Y,int &ChunkW,int &ChunkH) { int MapW=OutMap.GetWidth(); int MapH=OutMap.GetHeight(); // Calc Chunk Pos & size X=X*PakW; MapW-=X; ChunkW=__min(MapW,PakW); Y=Y*PakH; MapH-=Y; ChunkH=__min(MapH,PakH); // Build Chunk sTileMapElem *OutPtr=ChunkBuffer; for (int MY=0; MY