This commit is contained in:
Daveo 2001-06-25 15:54:07 +00:00
parent 74f966d046
commit 8998550cad
26 changed files with 288 additions and 310 deletions

View File

@ -19,15 +19,20 @@ public:
virtual void PreProcess(CMkLevel *Core)=0; virtual void PreProcess(CMkLevel *Core)=0;
virtual void Process(CMkLevel *Core)=0; virtual void Process(CMkLevel *Core)=0;
virtual int Write(FILE *File,const char *LayerName,const char *MapName)=0; virtual int Write(CMkLevel *Core,FILE *File,const char *LayerName)=0;
bool IsType(int _Type,int _SubType) {return(Type==_Type && SubType==_SubType);} bool IsType(int _Type,int _SubType) {return(Type==_Type && SubType==_SubType);}
void SetSize(int S) {Size=S;}
int GetSize() {return(Size);}
int GetType() {return(Type);}
int GetSubType() {return(SubType);}
protected: protected:
int Type; int Type;
int SubType; int SubType;
int Width; int Width;
int Height; int Height;
int Size;
}; };

View File

@ -36,234 +36,3 @@ int Height=InMap.GetHeight();
} }
} }
/*****************************************************************************/
/*****************************************************************************/
/*** Process *****************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*
void CMkLevelLayer3d::Process(CMkLevel *Core)
{
int Width=InMap.GetWidth();
int Height=InMap.GetHeight();
int i,ListSize;
TriList.SetTexGrab(Core->GetTexGrab());
//!!! TexGrab.AllowRotate(true);
TexGrab.AllowRotate(false);
//!!! TexGrab.ShrinkToFit(true);
TexGrab.ShrinkToFit(false);
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sExpLayerTile &ThisElem=InMap.Get(X,Y);
sMkLevelElem &OutElem=OutMap.Get(X,Y);
OutElem.Elem=TriList.GetFaceCount();
if (ThisElem.Tile)
{ // Not Blank Tile
sExpTile &InTile=Core->GetTile(ThisElem);
// Build Sorted List
CList<CFace> SortList;
CList<float> ZPosList;
if (InTile.TriCount)
{
for (i=0; i<InTile.TriCount; i++)
{
int ListPos;
CFace &ThisFace=CMkLevel::AllTriList[InTile.TriStart+i];
float ThisZPos;
ThisZPos=ThisFace.vtx[0].z;
if (ThisZPos>ThisFace.vtx[1].z) ThisZPos=ThisFace.vtx[1].z;
if (ThisZPos>ThisFace.vtx[2].z) ThisZPos=ThisFace.vtx[2].z;
ListSize=SortList.size();
for (ListPos=0; ListPos<ListSize; ListPos++)
{
if (ZPosList[ListPos]<ThisZPos) break;
}
SortList.insert(ListPos,ThisFace);
ZPosList.insert(ListPos,ThisZPos);
// Flip 3d tiles
CFace &F=SortList[ListPos];
bool SwapPnt=false;
if (ThisElem.Flags & PC_TILE_FLAG_MIRROR_X)
{
F.vtx[0].x=-F.vtx[0].x;
F.vtx[1].x=-F.vtx[1].x;
F.vtx[2].x=-F.vtx[2].x;
SwapPnt^=1;
}
if (ThisElem.Flags & PC_TILE_FLAG_MIRROR_Y)
{
F.vtx[0].y =1.0-F.vtx[0].y;
F.vtx[1].y =1.0-F.vtx[1].y;
F.vtx[2].y =1.0-F.vtx[2].y;
SwapPnt^=1;
}
if (SwapPnt)
{
Vector3 TmpV=F.vtx[0];
F.vtx[0]=F.vtx[1];
F.vtx[1]=TmpV;
sUV TmpUV=F.uvs[0];
F.uvs[0]=F.uvs[1];
F.uvs[1]=TmpUV;
}
}
}
else
{ // create flat tile
for (int i=0; i<2; i++)
{
FlatFace[i].Mat=OutElem.TexID;
SortList.push_back(FlatFace[i]);
}
}
ListSize=SortList.size();
// Sort out Flipping
for (i=0; i<ListSize; i++)
{
CFace &F=SortList[i];
// Offset Vtx's
for (int p=0; p<3; p++)
{
F.vtx[p].x +=(float)X;
F.vtx[p].y -=(float)Y;
}
F.ID=i;
// printf("%i\n",F.ID);
TriList.AddFace(F);
}
}
}
}
}
*/
/*****************************************************************************/
/*****************************************************************************/
/** Write ********************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*
int CMkLevelLayer3d::Write(FILE *File,const char *LayerName,const char *MapName)
{
int ThisPos=ftell(File);
CMkLevelLayerTile::Write(File,LayerName,MapName);
int Width=OutMap.GetWidth();
int Height=OutMap.GetHeight();
sLayerHdr LayerHdr;
sLayer3d Hdr3d;
vector<sVtx> OutVtxList;
TriList.Process();
ProcessVtxList(TriList.GetVtxList(),OutVtxList);
LayerHdr.Type=Type;
LayerHdr.SubType=SubType;
LayerHdr.Width=Width;
LayerHdr.Height=Height;
fwrite(&LayerHdr,sizeof(sLayerHdr),1,File);
int Pos3d=ftell(File);
fwrite(&Hdr3d,sizeof(sLayer3d),1,File);
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sMkLevelElem &OutElem=OutMap.Get(X,Y);
fwrite(&OutElem.Elem,sizeof(u16),1,File);
}
}
PadFile(File);
Hdr3d.TriCount=TriList.GetFaceCount();
Hdr3d.TriList=TriList.WriteTriList(File)-ThisPos;
Hdr3d.QuadCount=0;
Hdr3d.QuadList=TriList.WriteQuadList(File)-ThisPos;
Hdr3d.VtxCount=OutVtxList.size();
Hdr3d.VtxList=TriList.WriteVtxList(File,OutVtxList)-ThisPos;
printf("T:%i V:%i\t",Hdr3d.TriCount,Hdr3d.VtxCount);
printf("sTri %i\tFT3 %i\n",Hdr3d.TriCount*16,Hdr3d.TriCount*34);
int RetPos=ftell(File);
fseek(File,Pos3d,SEEK_SET);
fwrite(&Hdr3d,sizeof(sLayer3d),1,File);
fseek(File,RetPos,SEEK_SET);
return(ThisPos);
}
*/
/*****************************************************************************/
#if 0
void CMkLevelLayer3d::ProcessVtxList(vector<sVtx> const &InList,vector<sVtx> &OutList)
{
int i,ListSize=InList.size();
//int XMin,XMax,YMin,YMax;
sVtx Ofs;
OutList.resize(ListSize);
if (!ListSize) return;
/*
XMin=XMax=InList[0].vx;
YMin=YMax=InList[0].vy;
// Find Min/Max
for (i=1; i<ListSize; i++)
{
// printf("%i %i %i\n",InList[i].vx,InList[i].vy,InList[i].vz);
if (XMin>InList[i].vx) XMin=InList[i].vx;
if (XMax<InList[i].vx) XMax=InList[i].vx;
if (YMin>InList[i].vy) YMin=InList[i].vy;
if (YMax<InList[i].vy) YMax=InList[i].vy;
}
// Ofs.vx=-32768-XMin;
// Ofs.vy=-32768-YMin;
Ofs.vx=-XMin;
Ofs.vy=-YMin;
*/
Ofs.vx=-0;
Ofs.vy=-0;
Ofs.vz=-4*Scale;
// Adjust Vtx`
for (i=0; i<ListSize;i++)
{
sVtx const &In=InList[i];
sVtx &Out=OutList[i];
Out.vx=+(In.vx+Ofs.vx);
Out.vy=-(In.vy+Ofs.vy);
Out.vz=+(In.vz+Ofs.vz);
// printf("%i %i\n",In.vx,In.vy);
}
/*
XMin=XMax=OutList[0].vx;
YMin=YMax=OutList[0].vy;
// Find Min/Max
for (i=1; i<ListSize; i++)
{
if (XMin>OutList[i].vx) XMin=OutList[i].vx;
if (XMax<OutList[i].vx) XMax=OutList[i].vx;
if (YMin>OutList[i].vy) YMin=OutList[i].vy;
if (YMax<OutList[i].vy) YMax=OutList[i].vy;
}
printf("MinXY %i,%i %i,%i\n",XMin,YMin,XMax,YMax);
*/
}
#endif
/*****************************************************************************/

View File

@ -15,10 +15,8 @@ public:
CMkLevelLayer3d(sExpLayerHdr *LayerHdr) : CMkLevelLayerTile(LayerHdr){}; CMkLevelLayer3d(sExpLayerHdr *LayerHdr) : CMkLevelLayerTile(LayerHdr){};
void PreProcess(CMkLevel *Core); void PreProcess(CMkLevel *Core);
// void Process(CMkLevel *Core);
// int Write(FILE *File,const char *LayerName,const char *MapName);
protected: protected:
// void ProcessVtxList(vector<sVtx> const &In,vector<sVtx> &Out);
}; };
/*****************************************************************************/ /*****************************************************************************/

View File

@ -56,7 +56,7 @@ GString Player=Core->GetConfigStr("MISC","PlayerActor");
/** Write ********************************************************************/ /** Write ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerActor::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerActor::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
int ThisPos=ftell(File); int ThisPos=ftell(File);
sThingHdr Hdr; sThingHdr Hdr;
@ -92,6 +92,7 @@ int i,ListSize=ThingList.size();
} }
} }
Size=ftell(File)-ThisPos;
return(ThisPos); return(ThisPos);
} }

View File

@ -17,7 +17,7 @@ const char *GetTypeName() {return("ACTOR");}
void PreProcess(CMkLevel *Core); void PreProcess(CMkLevel *Core);
void Process(CMkLevel *Core); void Process(CMkLevel *Core);
int Write(FILE *File,const char *LayerName,const char *MapName); int Write(CMkLevel *Core,FILE *File,const char *LayerName);
}; };

View File

@ -87,7 +87,7 @@ static const u8 s_collisionTileRemapTable[17]=
0, 0,
}; };
int CMkLevelLayerCollision::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerCollision::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
sLayerHdr Hdr; sLayerHdr Hdr;
int ThisPos=ftell(File); int ThisPos=ftell(File);
@ -109,29 +109,12 @@ int Height=Map.GetHeight();
OutElem=s_collisionTileRemapTable[ThisElem.Tile]; OutElem=s_collisionTileRemapTable[ThisElem.Tile];
OutElem|=ThisElem.Flags<<COLLISION_TYPE_FLAG_SHIFT; OutElem|=ThisElem.Flags<<COLLISION_TYPE_FLAG_SHIFT;
/*
OutElem=0;
if (ThisElem.Tile || ThisElem.Flags)
{
int FF=ThisElem.Tile & 1;
int T=(ThisElem.Tile>>1)+1;
OutElem=((T-1)*4)+1;
OutElem+=FF;
OutElem|=ThisElem.Flags<<COLLISION_TYPE_FLAG_SHIFT;
}
*/
/* if (ThisElem.Tile>(u16)COLLISION_MASK)
{
printf("COLLISION OVERFLOW %s: %i,%i=(%i,%i)!!\n",MapName,X,Y,ThisElem.Tile,ThisElem.Flags);
}
*/
fwrite(&OutElem,sizeof(u8),1,File); fwrite(&OutElem,sizeof(u8),1,File);
} }
} }
PadFile(File); PadFile(File);
Size=ftell(File)-ThisPos;
return(ThisPos); return(ThisPos);
} }

View File

@ -16,7 +16,7 @@ public:
virtual void PreProcess(CMkLevel *Core); virtual void PreProcess(CMkLevel *Core);
virtual void Process(CMkLevel *Core); virtual void Process(CMkLevel *Core);
virtual int Write(FILE *File,const char *LayerName,const char *MapName); virtual int Write(CMkLevel *Core,FILE *File,const char *LayerName);
protected: protected:

View File

@ -35,7 +35,7 @@ void CMkLevelLayerFX::Process(CMkLevel *Core)
/** Write ********************************************************************/ /** Write ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerFX::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerFX::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
int ThisPos=ftell(File); int ThisPos=ftell(File);
sThingHdr Hdr; sThingHdr Hdr;
@ -59,6 +59,7 @@ int i,ListSize=ThingList.size();
} }
Size=ftell(File)-ThisPos;
return(ThisPos); return(ThisPos);
} }

View File

@ -17,7 +17,7 @@ public:
void PreProcess(CMkLevel *Core); void PreProcess(CMkLevel *Core);
void Process(CMkLevel *Core); void Process(CMkLevel *Core);
int Write(FILE *File,const char *LayerName,const char *MapName); int Write(CMkLevel *Core,FILE *File,const char *LayerName);
}; };

View File

@ -45,7 +45,7 @@ void CMkLevelLayerHazard::Process(CMkLevel *Core)
/** Write ********************************************************************/ /** Write ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerHazard::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerHazard::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
int ThisPos=ftell(File); int ThisPos=ftell(File);
sThingHdr Hdr; sThingHdr Hdr;
@ -82,6 +82,7 @@ int i,ListSize=ThingList.size();
} }
} }
Size=ftell(File)-ThisPos;
return(ThisPos); return(ThisPos);
} }

View File

@ -17,7 +17,7 @@ const char *GetTypeName() {return("HAZARD");}
void PreProcess(CMkLevel *Core); void PreProcess(CMkLevel *Core);
void Process(CMkLevel *Core); void Process(CMkLevel *Core);
int Write(FILE *File,const char *LayerName,const char *MapName); int Write(CMkLevel *Core,FILE *File,const char *LayerName);
CList<int> RemapTable; CList<int> RemapTable;

View File

@ -33,7 +33,7 @@ void CMkLevelLayerItem::Process(CMkLevel *Core)
/** Write ********************************************************************/ /** Write ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerItem::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerItem::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
int ThisPos=ftell(File); int ThisPos=ftell(File);
sThingHdr Hdr; sThingHdr Hdr;
@ -53,6 +53,7 @@ int i,ListSize=ThingList.size();
fwrite(&OutThing,sizeof(sThingItem),1,File); fwrite(&OutThing,sizeof(sThingItem),1,File);
} }
Size=ftell(File)-ThisPos;
return(ThisPos); return(ThisPos);
} }

View File

@ -17,7 +17,7 @@ const char *GetTypeName() {return("ITEM");}
void PreProcess(CMkLevel *Core); void PreProcess(CMkLevel *Core);
void Process(CMkLevel *Core); void Process(CMkLevel *Core);
int Write(FILE *File,const char *LayerName,const char *MapName); int Write(CMkLevel *Core,FILE *File,const char *LayerName);
}; };

View File

@ -44,7 +44,7 @@ void CMkLevelLayerPlatform::Process(CMkLevel *Core)
/** Write ********************************************************************/ /** Write ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerPlatform::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerPlatform::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
int ThisPos=ftell(File); int ThisPos=ftell(File);
sThingHdr Hdr; sThingHdr Hdr;
@ -81,6 +81,7 @@ int i,ListSize=ThingList.size();
} }
} }
Size=ftell(File)-ThisPos;
return(ThisPos); return(ThisPos);
} }

View File

@ -17,7 +17,7 @@ const char *GetTypeName() {return("PLATFORM");}
void PreProcess(CMkLevel *Core); void PreProcess(CMkLevel *Core);
void Process(CMkLevel *Core); void Process(CMkLevel *Core);
int Write(FILE *File,const char *LayerName,const char *MapName); int Write(CMkLevel *Core,FILE *File,const char *LayerName);
CList<int> RemapTable; CList<int> RemapTable;

View File

@ -121,7 +121,7 @@ CTexGrab &TexGrab=Core->GetTexGrab();
/** Write ********************************************************************/ /** Write ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerShade::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerShade::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
sLayerHdr Hdr; sLayerHdr Hdr;
int ThisPos=ftell(File); int ThisPos=ftell(File);
@ -147,6 +147,7 @@ int RetPos=ftell(File);
fseek(File,RetPos,SEEK_SET); fseek(File,RetPos,SEEK_SET);
Size=ftell(File)-ThisPos;
return(ThisPos); return(ThisPos);
} }

View File

@ -26,7 +26,7 @@ public:
void PreProcess(CMkLevel *Core); void PreProcess(CMkLevel *Core);
void Process(CMkLevel *Core); void Process(CMkLevel *Core);
int Write(FILE *File,const char *LayerName,const char *MapName); int Write(CMkLevel *Core,FILE *File,const char *LayerName);
protected: protected:
int WriteTypeList(FILE *File); int WriteTypeList(FILE *File);

View File

@ -31,7 +31,7 @@ virtual const char *GetTypeName()=0;
virtual void PreProcess(CMkLevel *Core)=0; virtual void PreProcess(CMkLevel *Core)=0;
virtual void Process(CMkLevel *Core)=0; virtual void Process(CMkLevel *Core)=0;
virtual int Write(FILE *File,const char *LayerName,const char *MapName)=0; virtual int Write(CMkLevel *Core,FILE *File,const char *LayerName)=0;
int CountThing(CMkLevel *Core,const char *Name); int CountThing(CMkLevel *Core,const char *Name);
protected: protected:

View File

@ -7,6 +7,7 @@
#include "MkLevelLayer.h" #include "MkLevelLayer.h"
#include "MkLevelLayerTile.h" #include "MkLevelLayerTile.h"
#include "pak.h"
@ -80,10 +81,9 @@ void CMkLevelLayerTile::Process(CMkLevel *Core)
/** Write ********************************************************************/ /** Write ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerTile::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerTile::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
sLayerHdr Hdr; int HdrPos=ftell(File);
int ThisPos=ftell(File);
int Width=OutMap.GetWidth(); int Width=OutMap.GetWidth();
int Height=OutMap.GetHeight(); int Height=OutMap.GetHeight();
@ -93,23 +93,129 @@ int Height=OutMap.GetHeight();
Hdr.Height=Height; Hdr.Height=Height;
fwrite(&Hdr,sizeof(sLayerHdr),1,File); fwrite(&Hdr,sizeof(sLayerHdr),1,File);
printf("%s (%i,%i)= %i\n",LayerName,Width,Height,Width*Height*sizeof(sTileMapElem)); // 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<Height; Y++) for (int Y=0; Y<Height; Y++)
{ {
for (int X=0; X<Width; X++) for (int X=0; X<Width; X++)
{ {
sMkLevelElem &ThisElem=OutMap.Get(X,Y); BuildOutElem(X,Y,&OutElem);
sTileMapElem OutElem;
OutElem.Tile=ThisElem.Elem;
// OutElem.LightIdx=0;
fwrite(&OutElem,sizeof(sTileMapElem),1,File); fwrite(&OutElem,sizeof(sTileMapElem),1,File);
} }
} }
PadFile(File); return(Width*Height*sizeof(sTileMapElem));
return(ThisPos);
} }
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerTile::WritePak(CMkLevel *Core,FILE *File)
{
int MapW=OutMap.GetWidth();
int MapH=OutMap.GetHeight();
int ChunkW=(MapW/PakW)+1;
int ChunkH=(MapH/PakH)+1;
int BufferSize=PakW*PakH*sizeof(sTileMapElem);
int TotalPak=0;
ChunkBuffer=(sTileMapElem*)malloc(BufferSize);
PakBuffer=(u8*)malloc(BufferSize*8); // Allow for bad pak
for (int ChunkY=0; ChunkY<ChunkH; ChunkY++)
{
for (int ChunkX=0; ChunkX<ChunkW; ChunkX++)
{
// Create Chunk
int ThisChunkW,ThisChunkH,ThisChunkSize;
int PakSize;
ThisChunkSize=BuildPakChunk(ChunkX,ChunkY,ThisChunkW,ThisChunkH);
PakSize=PakChunk(ThisChunkSize);
// if (PakSize>=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<ChunkH; MY++)
{
for (int MX=0; MX<ChunkW; MX++)
{
BuildOutElem(X+MX,Y+MY,OutPtr++);
}
}
return(ChunkW*ChunkH*sizeof(sTileMapElem));
}
/*****************************************************************************/
int CMkLevelLayerTile::PakChunk(int ChunkSize)
{
int PakSize=PAK_doPak(PakBuffer,(u8*)ChunkBuffer,ChunkSize);
return(PakSize);
}

View File

@ -22,11 +22,26 @@ public:
virtual void PreProcess(CMkLevel *Core); virtual void PreProcess(CMkLevel *Core);
virtual void Process(CMkLevel *Core); virtual void Process(CMkLevel *Core);
virtual int Write(FILE *File,const char *LayerName,const char *MapName); virtual int Write(CMkLevel *Core,FILE *File,const char *LayerName);
protected: protected:
int WriteNormal(CMkLevel *Core,FILE *File);
int WritePak(CMkLevel *Core,FILE *File);
void BuildOutElem(int X,int Y,sTileMapElem *Out);
CList2d<sExpLayerTile> InMap; CList2d<sExpLayerTile> InMap;
CList2d<sMkLevelElem> OutMap; CList2d<sMkLevelElem> OutMap;
sLayerHdr Hdr;
// Pak Stuff
int BuildPakChunk(int X,int Y,int &PakW,int &PakH);
int PakChunk(int ChunkSize);
int PakW,PakH;
sTileMapElem *ChunkBuffer;
u8 *PakBuffer;
}; };

View File

@ -35,7 +35,7 @@ void CMkLevelLayerTrigger::Process(CMkLevel *Core)
/** Write ********************************************************************/ /** Write ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CMkLevelLayerTrigger::Write(FILE *File,const char *LayerName,const char *MapName) int CMkLevelLayerTrigger::Write(CMkLevel *Core,FILE *File,const char *LayerName)
{ {
int ThisPos=ftell(File); int ThisPos=ftell(File);
sThingHdr Hdr; sThingHdr Hdr;
@ -61,6 +61,7 @@ int i,ListSize=ThingList.size();
fwrite(&OutThing,sizeof(sThingTrigger),1,File); fwrite(&OutThing,sizeof(sThingTrigger),1,File);
} }
Size=ftell(File)-ThisPos;
return(ThisPos); return(ThisPos);
} }

View File

@ -17,7 +17,7 @@ const char *GetTypeName() {return("TRIGGER");}
void PreProcess(CMkLevel *Core); void PreProcess(CMkLevel *Core);
void Process(CMkLevel *Core); void Process(CMkLevel *Core);
int Write(FILE *File,const char *LayerName,const char *MapName); int Write(CMkLevel *Core,FILE *File,const char *LayerName);
}; };

View File

@ -14,6 +14,7 @@
CMkLevel Level; CMkLevel Level;
int TPBase=-1,TPW=-1,TPH=-1; int TPBase=-1,TPW=-1,TPH=-1;
GString IncDir; GString IncDir;
int PakW=0,PakH=0;
//*************************************************************************** //***************************************************************************
char * CycleCommands(char *String,int Num) char * CycleCommands(char *String,int Num)
@ -63,6 +64,17 @@ int Count;
case 'q': case 'q':
StripLength=4; StripLength=4;
break; break;
case 'p':
TpStr= CheckFileString(String);
TextPtr=Text;
strcpy(TextPtr,TpStr);
Count=ZeroAndCountCommas(TextPtr);
if (Count!=1)
GObject::Error(ERR_FATAL,"Problem with option %s\n",String);
PakW=atol(TextPtr);
TextPtr+=strlen(TextPtr)+1;
PakH=atol(TextPtr);
break;
default: default:
GObject::Error(ERR_FATAL,"Unknown switch %s",String); GObject::Error(ERR_FATAL,"Unknown switch %s",String);
break; break;
@ -106,7 +118,7 @@ std::vector<GString> const &Files = MyFiles.GetFileInfoVector();
if (Files.size()>1) Usage("Too many Levels specified\n"); if (Files.size()>1) Usage("Too many Levels specified\n");
Level.SetAppDir(argv[0]); Level.SetAppDir(argv[0]);
Level.Init(Files[0],OutStr,IncDir,TPBase,TPW,TPH); Level.Init(Files[0],OutStr,IncDir,TPBase,TPW,TPH,PakW,PakH);
Level.Load(); Level.Load();
Level.Process(); Level.Process();
Level.Write(); Level.Write();

View File

@ -25,6 +25,33 @@
#include "Layers\MkLevelLayerTrigger.h" #include "Layers\MkLevelLayerTrigger.h"
#include "Layers\MkLevelLayerHazard.h" #include "Layers\MkLevelLayerHazard.h"
//***************************************************************************
struct sLayerNameTable
{
int Type,SubType;
char *Name;
};
sLayerNameTable LayerNameTable[]=
{
{LAYER_TYPE_SHADE,LAYER_SUBTYPE_BACK,"Shade"},
{LAYER_TYPE_TILE,LAYER_SUBTYPE_MID,"Mid"},
{LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION,"Action"},
{LAYER_TYPE_COLLISION,LAYER_SUBTYPE_NONE,"Collision"},
{LAYER_TYPE_ACTOR,LAYER_SUBTYPE_NONE,"Actor List"},
{LAYER_TYPE_ITEM,LAYER_SUBTYPE_NONE,"Item List"},
{LAYER_TYPE_PLATFORM,LAYER_SUBTYPE_NONE,"Platform List"},
{LAYER_TYPE_TRIGGER,LAYER_SUBTYPE_NONE,"Trigger List"},
{LAYER_TYPE_FX,LAYER_SUBTYPE_NONE,"FX List"},
{LAYER_TYPE_HAZARD,LAYER_SUBTYPE_NONE,"Hazard List"},
};
#define LayerNameTableSize sizeof(LayerNameTable)/sizeof(sLayerNameTable)
//***************************************************************************
int TSize,QSize,VSize;
int Tile2dSize,Tile3dSize;
//*************************************************************************** //***************************************************************************
const GString ConfigFilename="MkLevel.ini"; const GString ConfigFilename="MkLevel.ini";
sExpLayerTile BlankTile2d={-1,-1}; sExpLayerTile BlankTile2d={-1,-1};
@ -61,7 +88,7 @@ GFName Path=AppPath;
} }
//*************************************************************************** //***************************************************************************
void CMkLevel::Init(const char *Filename,const char *OutFilename,const char *IncDir,int TPBase,int TPW,int TPH) void CMkLevel::Init(const char *Filename,const char *OutFilename,const char *IncDir,int TPBase,int TPW,int TPH,int _PakW,int _PakH)
{ {
// Setup filenames and paths // Setup filenames and paths
GFName Path; GFName Path;
@ -119,6 +146,9 @@ GFName Path;
FlatFace[1].uv[1][0]=1; FlatFace[1].uv[1][1]=1; FlatFace[1].uv[1][0]=1; FlatFace[1].uv[1][1]=1;
FlatFace[1].uv[2][0]=0; FlatFace[1].uv[2][1]=1; FlatFace[1].uv[2][0]=0; FlatFace[1].uv[2][1]=1;
FlatFace[1].Flags=0; FlatFace[1].Flags=0;
// Setup Pak Info
PakW=_PakW;
PakH=_PakH;
} }
@ -876,6 +906,9 @@ GString OutFilename=OutName+".Lvl";
fclose(File); fclose(File);
// Write Info header File // Write Info header File
WriteIncFile(); WriteIncFile();
// Write Sizes
ReportLayers();
} }
//*************************************************************************** //***************************************************************************
@ -888,7 +921,7 @@ int i,ListSize;
// 2d Tilebank // 2d Tilebank
LevelHdr.TileBank2d=(sTile2d*)ftell(File); LevelHdr.TileBank2d=(sTile2d*)ftell(File);
ListSize=OutTile2dList.size(); ListSize=OutTile2dList.size();
printf("%i 2d tiles\n",ListSize); printf("%i 2d tiles\t(%i Bytes)\n",ListSize,ListSize*sizeof(sTile2d));
for (i=0; i<ListSize; i++) for (i=0; i<ListSize; i++)
{ {
sTile2d &OutTile=OutTile2dList[i]; sTile2d &OutTile=OutTile2dList[i];
@ -897,7 +930,7 @@ int i,ListSize;
// 3d Tilebank // 3d Tilebank
LevelHdr.TileBank3d=(sTile3d*)ftell(File); LevelHdr.TileBank3d=(sTile3d*)ftell(File);
ListSize=OutTile3dList.size(); ListSize=OutTile3dList.size();
printf("%i 3d tiles\n",ListSize); printf("%i 3d tiles\t(%i Bytes)\n",ListSize,ListSize*sizeof(sTile3d));
for (i=0; i<ListSize; i++) for (i=0; i<ListSize; i++)
{ {
sTile3d &OutTile=OutTile3dList[i]; sTile3d &OutTile=OutTile3dList[i];
@ -908,7 +941,7 @@ int i,ListSize;
// QuadList // QuadList
LevelHdr.QuadList=(sQuad*)WriteQuadList(); LevelHdr.QuadList=(sQuad*)WriteQuadList();
printf("OT %i -> %i\n",MinOT,MaxOT); // printf("OT %i -> %i\n",MinOT,MaxOT);
// VtxList // VtxList
LevelHdr.VtxList=(sVtx*)WriteVtxList(); LevelHdr.VtxList=(sVtx*)WriteVtxList();
@ -958,8 +991,8 @@ int ZOfs=+4*Scale;
// Write It // Write It
fwrite(&T,1,sizeof(sTri),File); fwrite(&T,1,sizeof(sTri),File);
} }
printf("Tri %i\n",ListSize); printf("%i Tris\t(%i Bytes)\n",ListSize,ListSize*sizeof(sTri));
printf("ZMin %i ZMax %i\n",ZMin,ZMax); // printf("ZMin %i ZMax %i\n",ZMin,ZMax);
return(ThisPos); return(ThisPos);
@ -994,7 +1027,7 @@ int i,ListSize=QuadList.size();
// Write It // Write It
fwrite(&Q,1,sizeof(sQuad),File); fwrite(&Q,1,sizeof(sQuad),File);
} }
printf("Quad %i\n",ListSize); printf("%i Quads\t(%i Bytes)\n",ListSize,ListSize*sizeof(sQuad));
return(ThisPos); return(ThisPos);
} }
@ -1022,6 +1055,8 @@ int Pos=ftell(File);
// printf("%i\n",Out.vz); // printf("%i\n",Out.vz);
fwrite(&Out,1,sizeof(sVtx),File); fwrite(&Out,1,sizeof(sVtx),File);
} }
printf("%i Vtx\t(%i Bytes)\n",ListSize,ListSize*sizeof(sVtx));
return(Pos); return(Pos);
} }
@ -1038,54 +1073,60 @@ void CMkLevel::WriteLevel()
void CMkLevel::WriteLayers() void CMkLevel::WriteLayers()
{ {
// Back (Shade) // Back (Shade)
LevelHdr.BackLayer=WriteLayer(LAYER_TYPE_SHADE,LAYER_SUBTYPE_BACK,0);//"Shade"); LevelHdr.BackLayer=WriteLayer(LAYER_TYPE_SHADE,LAYER_SUBTYPE_BACK);
// Mid // Mid
LevelHdr.MidLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_MID,"Mid"); LevelHdr.MidLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_MID);
// Action // Action
LevelHdr.ActionLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION,"Action"); LevelHdr.ActionLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION);
// Collision // Collision
LevelHdr.CollisionLayer=WriteLayer(LAYER_TYPE_COLLISION,LAYER_SUBTYPE_NONE,"Collision"); LevelHdr.CollisionLayer=WriteLayer(LAYER_TYPE_COLLISION,LAYER_SUBTYPE_NONE);
// Things // Things
LevelHdr.ActorList=WriteThings(LAYER_TYPE_ACTOR,"Actor List"); int ThingStart=ftell(File);
LevelHdr.ItemList=WriteThings(LAYER_TYPE_ITEM,"Item List"); LevelHdr.ActorList=WriteThings(LAYER_TYPE_ACTOR);
LevelHdr.PlatformList=WriteThings(LAYER_TYPE_PLATFORM,"Platform List"); LevelHdr.ItemList=WriteThings(LAYER_TYPE_ITEM);
LevelHdr.TriggerList=WriteThings(LAYER_TYPE_TRIGGER,"Trigger List"); LevelHdr.PlatformList=WriteThings(LAYER_TYPE_PLATFORM);
LevelHdr.FXList=WriteThings(LAYER_TYPE_FX,"FX List"); LevelHdr.TriggerList=WriteThings(LAYER_TYPE_TRIGGER);
LevelHdr.HazardList=WriteThings(LAYER_TYPE_HAZARD,"Hazard List"); LevelHdr.FXList=WriteThings(LAYER_TYPE_FX);
LevelHdr.HazardList=WriteThings(LAYER_TYPE_HAZARD);
LevelHdr.ModelList=(sModel*)WriteModelList(); LevelHdr.ModelList=(sModel*)WriteModelList();
printf("Things =\t(%i Bytes)\n",ftell(File)-ThingStart);
} }
//*************************************************************************** //***************************************************************************
int CMkLevel::WriteLayer(int Type,int SubType,const char *LayerName) int CMkLevel::WriteLayer(int Type,int SubType,bool Warn)
{ {
CMkLevelLayer *ThisLayer=FindLayer(Type,SubType); CMkLevelLayer *ThisLayer=FindLayer(Type,SubType);
int Ofs; int Ofs;
char *LayerName=GetLayerName(Type,SubType);
if (!ThisLayer) if (!ThisLayer)
{ {
if (LayerName) GObject::Error(ERR_WARNING,"No %s Layer Found in %s!!\n",LayerName,LevelName); if (Warn) GObject::Error(ERR_WARNING,"No %s Layer Found in %s!!\n",LayerName,LevelName);
return(0); return(0);
} }
Ofs=ThisLayer->Write(File,LayerName,LevelName); Ofs=ThisLayer->Write(this,File,LayerName);
PadFile(File); PadFile(File);
return(Ofs); return(Ofs);
} }
//*************************************************************************** //***************************************************************************
int CMkLevel::WriteThings(int Type,const char *LayerName) int CMkLevel::WriteThings(int Type,bool Warn)
{ {
CMkLevelLayer *ThisLayer=FindLayer(Type,LAYER_SUBTYPE_NONE); CMkLevelLayer *ThisLayer=FindLayer(Type,LAYER_SUBTYPE_NONE);
int Ofs; int Ofs;
char *LayerName=GetLayerName(Type,LAYER_SUBTYPE_NONE);
if (!ThisLayer) if (!ThisLayer)
{ {
GFName Name=InFilename; GFName Name=InFilename;
if (LayerName) GObject::Error(ERR_WARNING,"No %s Layer Found in %s!!\n",LayerName,Name.File()); if (Warn) GObject::Error(ERR_WARNING,"No %s Layer Found in %s!!\n",LayerName,Name.File());
return(0); return(0);
} }
Ofs=ThisLayer->Write(File,LayerName,LevelName); Ofs=ThisLayer->Write(this,File,LayerName);
// printf("%s %i\n",LayerName,Ofs); // printf("%s %i\n",LayerName,Ofs);
PadFile(File); PadFile(File);
return(Ofs); return(Ofs);
@ -1187,3 +1228,30 @@ int ListSize=InfList.size();
fclose(File); fclose(File);
} }
//***************************************************************************
//***************************************************************************
//***************************************************************************
void CMkLevel::ReportLayers()
{
int i,ListSize=LayerList.size();
for (i=0; i<ListSize; i++)
{
CMkLevelLayer *ThisLayer=LayerList[i];
char *LayerName=GetLayerName(ThisLayer->GetType(),ThisLayer->GetSubType());
printf("Layer %s= %i bytes\n",LayerName,ThisLayer->GetSize());
}
}
//***************************************************************************
char *CMkLevel::GetLayerName(int Type,int SubType)
{
for (int i=0; i<LayerNameTableSize; i++)
{
if (LayerNameTable[i].Type==Type && LayerNameTable[i].SubType==SubType) return(LayerNameTable[i].Name);
}
return(0);
}

View File

@ -194,5 +194,13 @@ SOURCE=.\MkLevel.h
SOURCE=..\..\tools\Data\bin\MkLevel.ini SOURCE=..\..\tools\Data\bin\MkLevel.ini
# End Source File # End Source File
# Begin Source File
SOURCE=.\pak.cpp
# End Source File
# Begin Source File
SOURCE=.\pak.h
# End Source File
# End Target # End Target
# End Project # End Project

View File

@ -86,7 +86,7 @@ public:
~CMkLevel(); ~CMkLevel();
void SetAppDir(const char *Path); void SetAppDir(const char *Path);
void Init(const char *InFilename,const char *OutFilename,const char *IncDir,int TPBase,int TPW,int TPH); void Init(const char *InFilename,const char *OutFilename,const char *IncDir,int TPBase,int TPW,int TPH,int PakW,int PakH);
void LoadModels(); void LoadModels();
int AddModel(GString &Filename); int AddModel(GString &Filename);
@ -114,6 +114,8 @@ public:
CTexGrab &GetTexGrab() {return(TexGrab);} CTexGrab &GetTexGrab() {return(TexGrab);}
void SetStart(int X,int Y) {LevelHdr.PlayerStartX=X; LevelHdr.PlayerStartY=Y;} void SetStart(int X,int Y) {LevelHdr.PlayerStartX=X; LevelHdr.PlayerStartY=Y;}
void GetPakWH(int &W,int &H) {W=PakW; H=PakH;}
protected: protected:
void BuildModel(CScene &ThisScene,GString &RootPath,int Node); void BuildModel(CScene &ThisScene,GString &RootPath,int Node);
CMkLevelLayer *FindLayer(int Type,int SubType); CMkLevelLayer *FindLayer(int Type,int SubType);
@ -136,8 +138,8 @@ protected:
void WriteLevel(); void WriteLevel();
void WriteLayers(); void WriteLayers();
int WriteLayer(int Type,int SubType,const char *LayerName); int WriteLayer(int Type,int SubType,bool Warn=false);
int WriteThings(int Type,const char *LayerName); int WriteThings(int Type,bool Warn=false);
int WriteModelList(); int WriteModelList();
int WriteTriList(); int WriteTriList();
int WriteQuadList(); int WriteQuadList();
@ -148,6 +150,9 @@ protected:
void WriteIncFile(); void WriteIncFile();
void ReportLayers();
char *GetLayerName(int Type,int SubType);
void ExpTri2Face(sExpTri &In,CFace &Out,bool ImportTex=true); void ExpTri2Face(sExpTri &In,CFace &Out,bool ImportTex=true);
FILE *File; FILE *File;
@ -185,6 +190,8 @@ protected:
CList<sInfItem> InfList; CList<sInfItem> InfList;
int PakW,PakH;
}; };
//*************************************************************************** //***************************************************************************