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 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;
};

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){};
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);
};
/*****************************************************************************/

View file

@ -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);
}

View file

@ -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);
};

View file

@ -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);
}

View file

@ -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:

View file

@ -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);
}

View file

@ -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);
};

View file

@ -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);
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
};

View file

@ -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);
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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);

View 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:

View file

@ -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);
}

View file

@ -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;
};

View file

@ -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);
}

View file

@ -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);
};