This commit is contained in:
parent
74f966d046
commit
8998550cad
26 changed files with 288 additions and 310 deletions
|
@ -19,15 +19,20 @@ public:
|
|||
|
||||
virtual void PreProcess(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);}
|
||||
|
||||
void SetSize(int S) {Size=S;}
|
||||
int GetSize() {return(Size);}
|
||||
int GetType() {return(Type);}
|
||||
int GetSubType() {return(SubType);}
|
||||
protected:
|
||||
int Type;
|
||||
int SubType;
|
||||
int Width;
|
||||
int Height;
|
||||
int Size;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -15,10 +15,8 @@ public:
|
|||
CMkLevelLayer3d(sExpLayerHdr *LayerHdr) : CMkLevelLayerTile(LayerHdr){};
|
||||
|
||||
void PreProcess(CMkLevel *Core);
|
||||
// void Process(CMkLevel *Core);
|
||||
// int Write(FILE *File,const char *LayerName,const char *MapName);
|
||||
protected:
|
||||
// void ProcessVtxList(vector<sVtx> const &In,vector<sVtx> &Out);
|
||||
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -56,7 +56,7 @@ GString Player=Core->GetConfigStr("MISC","PlayerActor");
|
|||
/** 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);
|
||||
sThingHdr Hdr;
|
||||
|
@ -92,6 +92,7 @@ int i,ListSize=ThingList.size();
|
|||
}
|
||||
}
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ const char *GetTypeName() {return("ACTOR");}
|
|||
|
||||
void PreProcess(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);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ static const u8 s_collisionTileRemapTable[17]=
|
|||
0,
|
||||
};
|
||||
|
||||
int CMkLevelLayerCollision::Write(FILE *File,const char *LayerName,const char *MapName)
|
||||
int CMkLevelLayerCollision::Write(CMkLevel *Core,FILE *File,const char *LayerName)
|
||||
{
|
||||
sLayerHdr Hdr;
|
||||
int ThisPos=ftell(File);
|
||||
|
@ -109,29 +109,12 @@ int Height=Map.GetHeight();
|
|||
|
||||
OutElem=s_collisionTileRemapTable[ThisElem.Tile];
|
||||
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);
|
||||
}
|
||||
}
|
||||
PadFile(File);
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
|
||||
virtual void PreProcess(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:
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ void CMkLevelLayerFX::Process(CMkLevel *Core)
|
|||
/** 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);
|
||||
sThingHdr Hdr;
|
||||
|
@ -59,6 +59,7 @@ int i,ListSize=ThingList.size();
|
|||
|
||||
}
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
void PreProcess(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);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ void CMkLevelLayerHazard::Process(CMkLevel *Core)
|
|||
/** 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);
|
||||
sThingHdr Hdr;
|
||||
|
@ -82,6 +82,7 @@ int i,ListSize=ThingList.size();
|
|||
}
|
||||
}
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ const char *GetTypeName() {return("HAZARD");}
|
|||
|
||||
void PreProcess(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;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ void CMkLevelLayerItem::Process(CMkLevel *Core)
|
|||
/** 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);
|
||||
sThingHdr Hdr;
|
||||
|
@ -53,6 +53,7 @@ int i,ListSize=ThingList.size();
|
|||
fwrite(&OutThing,sizeof(sThingItem),1,File);
|
||||
}
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ const char *GetTypeName() {return("ITEM");}
|
|||
|
||||
void PreProcess(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);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ void CMkLevelLayerPlatform::Process(CMkLevel *Core)
|
|||
/** 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);
|
||||
sThingHdr Hdr;
|
||||
|
@ -81,6 +81,7 @@ int i,ListSize=ThingList.size();
|
|||
}
|
||||
}
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ const char *GetTypeName() {return("PLATFORM");}
|
|||
|
||||
void PreProcess(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;
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ CTexGrab &TexGrab=Core->GetTexGrab();
|
|||
/** Write ********************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
int CMkLevelLayerShade::Write(FILE *File,const char *LayerName,const char *MapName)
|
||||
int CMkLevelLayerShade::Write(CMkLevel *Core,FILE *File,const char *LayerName)
|
||||
{
|
||||
sLayerHdr Hdr;
|
||||
int ThisPos=ftell(File);
|
||||
|
@ -147,6 +147,7 @@ int RetPos=ftell(File);
|
|||
fseek(File,RetPos,SEEK_SET);
|
||||
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
|
||||
void PreProcess(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:
|
||||
int WriteTypeList(FILE *File);
|
||||
|
|
|
@ -31,7 +31,7 @@ virtual const char *GetTypeName()=0;
|
|||
|
||||
virtual void PreProcess(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);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "MkLevelLayer.h"
|
||||
#include "MkLevelLayerTile.h"
|
||||
#include "pak.h"
|
||||
|
||||
|
||||
|
||||
|
@ -80,10 +81,9 @@ void CMkLevelLayerTile::Process(CMkLevel *Core)
|
|||
/** 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 ThisPos=ftell(File);
|
||||
int HdrPos=ftell(File);
|
||||
int Width=OutMap.GetWidth();
|
||||
int Height=OutMap.GetHeight();
|
||||
|
||||
|
@ -93,23 +93,129 @@ int Height=OutMap.GetHeight();
|
|||
Hdr.Height=Height;
|
||||
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 X=0; X<Width; X++)
|
||||
{
|
||||
sMkLevelElem &ThisElem=OutMap.Get(X,Y);
|
||||
sTileMapElem OutElem;
|
||||
OutElem.Tile=ThisElem.Elem;
|
||||
// OutElem.LightIdx=0;
|
||||
BuildOutElem(X,Y,&OutElem);
|
||||
|
||||
fwrite(&OutElem,sizeof(sTileMapElem),1,File);
|
||||
}
|
||||
}
|
||||
PadFile(File);
|
||||
|
||||
return(ThisPos);
|
||||
return(Width*Height*sizeof(sTileMapElem));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -22,11 +22,26 @@ public:
|
|||
|
||||
virtual void PreProcess(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:
|
||||
int WriteNormal(CMkLevel *Core,FILE *File);
|
||||
int WritePak(CMkLevel *Core,FILE *File);
|
||||
|
||||
void BuildOutElem(int X,int Y,sTileMapElem *Out);
|
||||
|
||||
CList2d<sExpLayerTile> InMap;
|
||||
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;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ void CMkLevelLayerTrigger::Process(CMkLevel *Core)
|
|||
/** 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);
|
||||
sThingHdr Hdr;
|
||||
|
@ -61,6 +61,7 @@ int i,ListSize=ThingList.size();
|
|||
fwrite(&OutThing,sizeof(sThingTrigger),1,File);
|
||||
}
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ const char *GetTypeName() {return("TRIGGER");}
|
|||
|
||||
void PreProcess(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);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
CMkLevel Level;
|
||||
int TPBase=-1,TPW=-1,TPH=-1;
|
||||
GString IncDir;
|
||||
int PakW=0,PakH=0;
|
||||
|
||||
//***************************************************************************
|
||||
char * CycleCommands(char *String,int Num)
|
||||
|
@ -63,6 +64,17 @@ int Count;
|
|||
case 'q':
|
||||
StripLength=4;
|
||||
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:
|
||||
GObject::Error(ERR_FATAL,"Unknown switch %s",String);
|
||||
break;
|
||||
|
@ -106,7 +118,7 @@ std::vector<GString> const &Files = MyFiles.GetFileInfoVector();
|
|||
if (Files.size()>1) Usage("Too many Levels specified\n");
|
||||
|
||||
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.Process();
|
||||
Level.Write();
|
||||
|
|
|
@ -25,6 +25,33 @@
|
|||
#include "Layers\MkLevelLayerTrigger.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";
|
||||
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
|
||||
GFName Path;
|
||||
|
@ -119,6 +146,9 @@ GFName Path;
|
|||
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].Flags=0;
|
||||
// Setup Pak Info
|
||||
PakW=_PakW;
|
||||
PakH=_PakH;
|
||||
}
|
||||
|
||||
|
||||
|
@ -876,6 +906,9 @@ GString OutFilename=OutName+".Lvl";
|
|||
fclose(File);
|
||||
// Write Info header File
|
||||
WriteIncFile();
|
||||
|
||||
// Write Sizes
|
||||
ReportLayers();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
@ -888,7 +921,7 @@ int i,ListSize;
|
|||
// 2d Tilebank
|
||||
LevelHdr.TileBank2d=(sTile2d*)ftell(File);
|
||||
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++)
|
||||
{
|
||||
sTile2d &OutTile=OutTile2dList[i];
|
||||
|
@ -897,7 +930,7 @@ int i,ListSize;
|
|||
// 3d Tilebank
|
||||
LevelHdr.TileBank3d=(sTile3d*)ftell(File);
|
||||
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++)
|
||||
{
|
||||
sTile3d &OutTile=OutTile3dList[i];
|
||||
|
@ -908,7 +941,7 @@ int i,ListSize;
|
|||
|
||||
// QuadList
|
||||
LevelHdr.QuadList=(sQuad*)WriteQuadList();
|
||||
printf("OT %i -> %i\n",MinOT,MaxOT);
|
||||
// printf("OT %i -> %i\n",MinOT,MaxOT);
|
||||
|
||||
// VtxList
|
||||
LevelHdr.VtxList=(sVtx*)WriteVtxList();
|
||||
|
@ -958,8 +991,8 @@ int ZOfs=+4*Scale;
|
|||
// Write It
|
||||
fwrite(&T,1,sizeof(sTri),File);
|
||||
}
|
||||
printf("Tri %i\n",ListSize);
|
||||
printf("ZMin %i ZMax %i\n",ZMin,ZMax);
|
||||
printf("%i Tris\t(%i Bytes)\n",ListSize,ListSize*sizeof(sTri));
|
||||
// printf("ZMin %i ZMax %i\n",ZMin,ZMax);
|
||||
|
||||
return(ThisPos);
|
||||
|
||||
|
@ -994,7 +1027,7 @@ int i,ListSize=QuadList.size();
|
|||
// Write It
|
||||
fwrite(&Q,1,sizeof(sQuad),File);
|
||||
}
|
||||
printf("Quad %i\n",ListSize);
|
||||
printf("%i Quads\t(%i Bytes)\n",ListSize,ListSize*sizeof(sQuad));
|
||||
return(ThisPos);
|
||||
|
||||
}
|
||||
|
@ -1022,6 +1055,8 @@ int Pos=ftell(File);
|
|||
// printf("%i\n",Out.vz);
|
||||
fwrite(&Out,1,sizeof(sVtx),File);
|
||||
}
|
||||
printf("%i Vtx\t(%i Bytes)\n",ListSize,ListSize*sizeof(sVtx));
|
||||
|
||||
return(Pos);
|
||||
}
|
||||
|
||||
|
@ -1038,54 +1073,60 @@ void CMkLevel::WriteLevel()
|
|||
void CMkLevel::WriteLayers()
|
||||
{
|
||||
// Back (Shade)
|
||||
LevelHdr.BackLayer=WriteLayer(LAYER_TYPE_SHADE,LAYER_SUBTYPE_BACK,0);//"Shade");
|
||||
LevelHdr.BackLayer=WriteLayer(LAYER_TYPE_SHADE,LAYER_SUBTYPE_BACK);
|
||||
// Mid
|
||||
LevelHdr.MidLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_MID,"Mid");
|
||||
LevelHdr.MidLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_MID);
|
||||
// Action
|
||||
LevelHdr.ActionLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION,"Action");
|
||||
LevelHdr.ActionLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION);
|
||||
// Collision
|
||||
LevelHdr.CollisionLayer=WriteLayer(LAYER_TYPE_COLLISION,LAYER_SUBTYPE_NONE,"Collision");
|
||||
LevelHdr.CollisionLayer=WriteLayer(LAYER_TYPE_COLLISION,LAYER_SUBTYPE_NONE);
|
||||
|
||||
// Things
|
||||
LevelHdr.ActorList=WriteThings(LAYER_TYPE_ACTOR,"Actor List");
|
||||
LevelHdr.ItemList=WriteThings(LAYER_TYPE_ITEM,"Item List");
|
||||
LevelHdr.PlatformList=WriteThings(LAYER_TYPE_PLATFORM,"Platform List");
|
||||
LevelHdr.TriggerList=WriteThings(LAYER_TYPE_TRIGGER,"Trigger List");
|
||||
LevelHdr.FXList=WriteThings(LAYER_TYPE_FX,"FX List");
|
||||
LevelHdr.HazardList=WriteThings(LAYER_TYPE_HAZARD,"Hazard List");
|
||||
int ThingStart=ftell(File);
|
||||
LevelHdr.ActorList=WriteThings(LAYER_TYPE_ACTOR);
|
||||
LevelHdr.ItemList=WriteThings(LAYER_TYPE_ITEM);
|
||||
LevelHdr.PlatformList=WriteThings(LAYER_TYPE_PLATFORM);
|
||||
LevelHdr.TriggerList=WriteThings(LAYER_TYPE_TRIGGER);
|
||||
LevelHdr.FXList=WriteThings(LAYER_TYPE_FX);
|
||||
LevelHdr.HazardList=WriteThings(LAYER_TYPE_HAZARD);
|
||||
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);
|
||||
int Ofs;
|
||||
char *LayerName=GetLayerName(Type,SubType);
|
||||
|
||||
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);
|
||||
}
|
||||
Ofs=ThisLayer->Write(File,LayerName,LevelName);
|
||||
Ofs=ThisLayer->Write(this,File,LayerName);
|
||||
|
||||
PadFile(File);
|
||||
return(Ofs);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
int CMkLevel::WriteThings(int Type,const char *LayerName)
|
||||
int CMkLevel::WriteThings(int Type,bool Warn)
|
||||
{
|
||||
CMkLevelLayer *ThisLayer=FindLayer(Type,LAYER_SUBTYPE_NONE);
|
||||
int Ofs;
|
||||
char *LayerName=GetLayerName(Type,LAYER_SUBTYPE_NONE);
|
||||
|
||||
if (!ThisLayer)
|
||||
{
|
||||
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);
|
||||
}
|
||||
Ofs=ThisLayer->Write(File,LayerName,LevelName);
|
||||
Ofs=ThisLayer->Write(this,File,LayerName);
|
||||
// printf("%s %i\n",LayerName,Ofs);
|
||||
PadFile(File);
|
||||
return(Ofs);
|
||||
|
@ -1187,3 +1228,30 @@ int ListSize=InfList.size();
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -194,5 +194,13 @@ SOURCE=.\MkLevel.h
|
|||
|
||||
SOURCE=..\..\tools\Data\bin\MkLevel.ini
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\pak.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\pak.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
|
|
|
@ -86,7 +86,7 @@ public:
|
|||
~CMkLevel();
|
||||
|
||||
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();
|
||||
int AddModel(GString &Filename);
|
||||
|
@ -114,6 +114,8 @@ public:
|
|||
CTexGrab &GetTexGrab() {return(TexGrab);}
|
||||
|
||||
void SetStart(int X,int Y) {LevelHdr.PlayerStartX=X; LevelHdr.PlayerStartY=Y;}
|
||||
|
||||
void GetPakWH(int &W,int &H) {W=PakW; H=PakH;}
|
||||
protected:
|
||||
void BuildModel(CScene &ThisScene,GString &RootPath,int Node);
|
||||
CMkLevelLayer *FindLayer(int Type,int SubType);
|
||||
|
@ -136,8 +138,8 @@ protected:
|
|||
|
||||
void WriteLevel();
|
||||
void WriteLayers();
|
||||
int WriteLayer(int Type,int SubType,const char *LayerName);
|
||||
int WriteThings(int Type,const char *LayerName);
|
||||
int WriteLayer(int Type,int SubType,bool Warn=false);
|
||||
int WriteThings(int Type,bool Warn=false);
|
||||
int WriteModelList();
|
||||
int WriteTriList();
|
||||
int WriteQuadList();
|
||||
|
@ -148,6 +150,9 @@ protected:
|
|||
|
||||
void WriteIncFile();
|
||||
|
||||
void ReportLayers();
|
||||
char *GetLayerName(int Type,int SubType);
|
||||
|
||||
void ExpTri2Face(sExpTri &In,CFace &Out,bool ImportTex=true);
|
||||
|
||||
FILE *File;
|
||||
|
@ -185,6 +190,8 @@ protected:
|
|||
|
||||
CList<sInfItem> InfList;
|
||||
|
||||
int PakW,PakH;
|
||||
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
|
|
Loading…
Add table
Reference in a new issue