2001-04-17 18:42:07 +02:00
|
|
|
/*********************/
|
|
|
|
/*** MkLevel Class ***/
|
|
|
|
/*********************/
|
|
|
|
|
|
|
|
#include "stdio.h"
|
|
|
|
#include <misc.hpp>
|
|
|
|
#include <GFName.hpp>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <iostream.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <DaveLib.h>
|
|
|
|
|
|
|
|
#include "MkLevel.h"
|
|
|
|
#include "Layers\MkLevelLayer.h"
|
|
|
|
|
|
|
|
#include "Layers\MkLevelLayerTile.h"
|
|
|
|
#include "Layers\MkLevelLayer3d.h"
|
|
|
|
#include "Layers\MkLevelLayerShade.h"
|
|
|
|
#include "Layers\MkLevelLayerCollision.h"
|
|
|
|
|
|
|
|
#include "Layers\MkLevelLayerActor.h"
|
|
|
|
#include "Layers\MkLevelLayerItem.h"
|
|
|
|
#include "Layers\MkLevelLayerPlatform.h"
|
|
|
|
#include "Layers\MkLevelLayerFX.h"
|
|
|
|
#include "Layers\MkLevelLayerTrigger.h"
|
2001-04-30 23:49:54 +02:00
|
|
|
#include "Layers\MkLevelLayerHazard.h"
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-06-25 17:54:07 +02:00
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
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;
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
2001-04-19 17:12:21 +02:00
|
|
|
const GString ConfigFilename="MkLevel.ini";
|
2001-06-27 18:45:56 +02:00
|
|
|
sExpLayerTile BlankTile={0,0};
|
|
|
|
//sExpLayerTile BlankTile2d={-1,-1};
|
|
|
|
//sExpLayerTile BlankTile3d={0,0};
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
Vector3 DefVtxTable[8]=
|
|
|
|
{
|
|
|
|
Vector3(+0.5f,+1.0f,-4.0f),
|
|
|
|
Vector3(-0.5f,+1.0f,-4.0f),
|
|
|
|
Vector3(+0.5f, 0.0f,-4.0f),
|
|
|
|
Vector3(-0.5f, 0.0f,-4.0f),
|
|
|
|
|
|
|
|
Vector3(+0.5f,+1.0f,+4.0f),
|
|
|
|
Vector3(-0.5f,+1.0f,+4.0f),
|
|
|
|
Vector3(+0.5f, 0.0f,+4.0f),
|
|
|
|
Vector3(-0.5f, 0.0f,+4.0f),
|
|
|
|
};
|
|
|
|
#define DefVtxTableSize sizeof(DefVtxTable)/sizeof(Vector3)
|
|
|
|
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
|
|
|
CMkLevel::CMkLevel()
|
|
|
|
{
|
2001-04-19 17:12:21 +02:00
|
|
|
memset(&LevelHdr,0,sizeof(sLevelHdr));
|
2001-06-27 18:45:56 +02:00
|
|
|
// Add Blanks
|
|
|
|
AddTile2d(BlankTile);
|
|
|
|
AddTile3d(BlankTile);
|
|
|
|
OutElem3d.resize(1);
|
2001-06-28 19:48:30 +02:00
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
CMkLevel::~CMkLevel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-04-19 17:12:21 +02:00
|
|
|
void CMkLevel::SetAppDir(const char *AppPath)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
AppDir="\\spongebob\\tools\\data\\bin\\";
|
|
|
|
#else
|
|
|
|
GFName Path=AppPath;
|
|
|
|
|
|
|
|
Path.File("");
|
|
|
|
Path.Ext("");
|
|
|
|
AppDir=Path.FullName();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-28 19:48:30 +02:00
|
|
|
void CMkLevel::Init(const char *Filename,const char *OutFilename,const char *IncDir,int TPBase,int TPW,int TPH,int _PakW,int _PakH,bool _LocalGeom)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
|
|
|
// Setup filenames and paths
|
2001-04-19 17:12:21 +02:00
|
|
|
GFName Path;
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
InFilename=Filename;
|
2001-04-19 17:12:21 +02:00
|
|
|
Path=Filename;
|
2001-04-17 18:42:07 +02:00
|
|
|
LevelName=Path.File();
|
|
|
|
Path.File("");
|
|
|
|
Path.Ext("");
|
|
|
|
InPath=Path.FullName();
|
2001-04-19 17:12:21 +02:00
|
|
|
Path=OutFilename;
|
|
|
|
Path.Ext("");
|
2001-05-23 18:03:10 +02:00
|
|
|
LevelFullName=Path.File();
|
|
|
|
LevelFullName.Upper();
|
2001-04-19 17:12:21 +02:00
|
|
|
OutName=Path.FullName();
|
2001-05-23 18:03:10 +02:00
|
|
|
OutIncName=IncDir;
|
|
|
|
OutIncName+=Path.File();
|
|
|
|
OutIncName+="_INF.h";
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
// Load ini file
|
2001-04-19 17:12:21 +02:00
|
|
|
Config.LoadAndImport(GString(AppDir+ConfigFilename));
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
// Setup Texgrab
|
|
|
|
if (TPBase==-1 || TPW==-1 || TPH==-1)
|
|
|
|
GObject::Error(ERR_FATAL,"TPage not set\n");
|
|
|
|
|
|
|
|
TexGrab.SetTPage(TPBase,TPW,TPH);
|
|
|
|
TexGrab.SetOutFile(GString(OutName+".Tex"));
|
|
|
|
TexGrab.SetDebug(DebugOn);
|
|
|
|
TexGrab.SetDebugOut(GString(OutName+".Lbm"));
|
|
|
|
TexGrab.NoSort();
|
|
|
|
TexGrab.AnimatedHeadersOnly(true);
|
|
|
|
TexGrab.DontOutputBoxes(true);
|
|
|
|
TexGrab.AllowRotate(false);
|
|
|
|
TexGrab.ShrinkToFit(false);
|
|
|
|
|
|
|
|
// Set up other stuph
|
|
|
|
|
|
|
|
FlatFace[0].vtx[0].x=+0.5f; FlatFace[0].vtx[0].y=+1.0f; FlatFace[0].vtx[0].z=-4.0f;
|
|
|
|
FlatFace[0].vtx[1].x=-0.5f; FlatFace[0].vtx[1].y= 0.0f; FlatFace[0].vtx[1].z=-4.0f;
|
|
|
|
FlatFace[0].vtx[2].x=+0.5f; FlatFace[0].vtx[2].y= 0.0f; FlatFace[0].vtx[2].z=-4.0f;
|
2001-04-19 17:12:21 +02:00
|
|
|
FlatFace[0].uv[0][0]=1; FlatFace[0].uv[0][1]=1;
|
|
|
|
FlatFace[0].uv[1][0]=0; FlatFace[0].uv[1][1]=0;
|
|
|
|
FlatFace[0].uv[2][0]=1; FlatFace[0].uv[2][1]=0;
|
2001-05-05 23:18:12 +02:00
|
|
|
FlatFace[0].Flags=0;
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
FlatFace[1].vtx[0].x=-0.5f; FlatFace[1].vtx[0].y= 0.0f; FlatFace[1].vtx[0].z=-4.0f;
|
|
|
|
FlatFace[1].vtx[1].x=+0.5f; FlatFace[1].vtx[1].y=+1.0f; FlatFace[1].vtx[1].z=-4.0f;
|
|
|
|
FlatFace[1].vtx[2].x=-0.5f; FlatFace[1].vtx[2].y=+1.0f; FlatFace[1].vtx[2].z=-4.0f;
|
2001-04-19 17:12:21 +02:00
|
|
|
FlatFace[1].uv[0][0]=0; FlatFace[1].uv[0][1]=0;
|
|
|
|
FlatFace[1].uv[1][0]=1; FlatFace[1].uv[1][1]=1;
|
|
|
|
FlatFace[1].uv[2][0]=0; FlatFace[1].uv[2][1]=1;
|
2001-05-05 23:18:12 +02:00
|
|
|
FlatFace[1].Flags=0;
|
2001-06-28 19:48:30 +02:00
|
|
|
|
|
|
|
// Setup Extra Info
|
2001-06-25 17:54:07 +02:00
|
|
|
PakW=_PakW;
|
|
|
|
PakH=_PakH;
|
2001-06-28 19:48:30 +02:00
|
|
|
LocalGeom=_LocalGeom;
|
|
|
|
AddDefVtx(OutVtxList);
|
2001-04-27 18:16:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-28 19:48:30 +02:00
|
|
|
void CMkLevel::AddDefVtx(vector<sVtx> &VtxList)
|
2001-04-27 18:16:23 +02:00
|
|
|
{
|
2001-06-28 19:48:30 +02:00
|
|
|
CFaceStore F;
|
|
|
|
for (int i=0; i<DefVtxTableSize; i++)
|
|
|
|
{
|
|
|
|
F.AddVtx(VtxList,DefVtxTable[i]);
|
|
|
|
}
|
2001-04-27 18:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-04-30 23:49:54 +02:00
|
|
|
int CMkLevel::AddModel(const char *Name,int TriStart,int TriCount)
|
2001-04-27 18:16:23 +02:00
|
|
|
{
|
|
|
|
sMkLevelModel ThisModel;
|
2001-06-28 19:48:30 +02:00
|
|
|
int ModelID;
|
2001-04-27 18:16:23 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
ThisModel.Name=Name;
|
|
|
|
ThisModel.TriStart=TriStart;
|
|
|
|
ThisModel.TriCount=TriCount;
|
2001-04-27 18:16:23 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
ModelID=ModelList.Add(ThisModel);
|
|
|
|
return(ModelID);
|
|
|
|
}
|
2001-04-27 18:16:23 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::PreProcessModels()
|
|
|
|
{
|
|
|
|
int i,ListSize=ModelList.size();
|
2001-04-27 18:16:23 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
sMkLevelModel &ThisModel=ModelList[i];
|
|
|
|
ThisModel.ElemID=Create3dElem(ThisModel.TriCount,ThisModel.TriStart,false); // always all models as global for the moment
|
|
|
|
}
|
2001-04-27 18:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::ProcessModels()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
|
|
|
//*** Load ******************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::Load()
|
|
|
|
{
|
|
|
|
FILE *File;
|
|
|
|
sExpFileHdr *FileHdr;
|
|
|
|
int Size;
|
|
|
|
|
|
|
|
printf("Load %s\n",LevelName);
|
|
|
|
|
|
|
|
File=fopen(InFilename,"rb");
|
|
|
|
if (!File)
|
|
|
|
GObject::Error(ERR_FATAL,"%s Not found\n",InFilename);
|
|
|
|
// Calc File Size
|
|
|
|
fseek(File,0,SEEK_END);
|
|
|
|
Size=ftell(File);
|
|
|
|
fseek(File,0,SEEK_SET);
|
|
|
|
FileHdr=(sExpFileHdr*)malloc(Size);
|
|
|
|
// Load It
|
|
|
|
fread(FileHdr,Size,1,File);
|
|
|
|
fclose(File);
|
|
|
|
|
|
|
|
LoadTiles(FileHdr);
|
|
|
|
LoadLayers(FileHdr);
|
|
|
|
|
|
|
|
free(FileHdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::LoadStrList(CList<GString> &List,char *TexPtr,int Count)
|
|
|
|
{
|
2001-04-23 16:51:44 +02:00
|
|
|
char FullName[1024];
|
2001-04-17 18:42:07 +02:00
|
|
|
GString FilePath;
|
|
|
|
|
|
|
|
for (int i=0; i<Count; i++)
|
|
|
|
{
|
2001-04-19 17:12:21 +02:00
|
|
|
GString InName=InPath;
|
|
|
|
InName+=TexPtr;
|
2001-05-09 23:56:48 +02:00
|
|
|
_fullpath( FullName, InName, 1024);
|
2001-04-17 18:42:07 +02:00
|
|
|
List.push_back(GString(FullName));
|
|
|
|
TexPtr+=strlen(TexPtr)+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::LoadTiles(sExpFileHdr *FileHdr)
|
|
|
|
{
|
|
|
|
u8 *ByteHdr=(u8*)FileHdr;
|
|
|
|
int i,ListSize;
|
|
|
|
int RGBSize;
|
|
|
|
|
|
|
|
TileW=FileHdr->TileW;
|
|
|
|
TileH=FileHdr->TileH;
|
|
|
|
RGBSize=TileW*TileH*3;
|
|
|
|
|
|
|
|
// Load SetNames
|
|
|
|
LoadStrList(InSetNameList,(char*) &ByteHdr[FileHdr->SetNameOfs],FileHdr->SetNameCount);
|
|
|
|
// Load TexNames
|
|
|
|
LoadStrList(InTexNameList,(char*) &ByteHdr[FileHdr->TexNameOfs],FileHdr->TexNameCount);
|
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
// Load Tris
|
|
|
|
sExpTri *TriPtr=(sExpTri*) &ByteHdr[FileHdr->TriOfs];
|
|
|
|
InTriList.resize(FileHdr->TriCount);
|
|
|
|
for (i=0; i<FileHdr->TriCount; i++)
|
|
|
|
{
|
|
|
|
InTriList[i]=TriPtr[i];
|
|
|
|
}
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
// Load Tiles
|
|
|
|
u8 *TilePtr=(u8*) &ByteHdr[FileHdr->TileOfs];
|
|
|
|
InTileList.resize(FileHdr->TileCount);
|
|
|
|
for (i=0; i<FileHdr->TileCount; i++)
|
|
|
|
{
|
|
|
|
sExpTile *ThisTilePtr=(sExpTile*)TilePtr;
|
|
|
|
sExpTile &InTile=InTileList[i];
|
|
|
|
|
|
|
|
InTile=*ThisTilePtr;
|
2001-05-05 23:18:12 +02:00
|
|
|
// Skip RGB Image, not needed (and too buggy)
|
2001-05-02 20:40:41 +02:00
|
|
|
// InTile.RGB=(u8*)malloc(RGBSize);
|
|
|
|
// memcpy(InTile.RGB,TilePtr+sizeof(sExpTile),RGBSize);
|
|
|
|
InTile.RGB=0;
|
2001-04-17 18:42:07 +02:00
|
|
|
TilePtr+=RGBSize+sizeof(sExpTile);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load 2d bitmaps
|
|
|
|
ListSize=InSetNameList.size();
|
|
|
|
BmpList.resize(ListSize);
|
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
GString Ext=GFName(InSetNameList[i]).Ext();
|
|
|
|
if (Ext=="BMP")
|
|
|
|
{
|
2001-04-19 17:12:21 +02:00
|
|
|
BmpList[i].LoadBMP(InSetNameList[i]);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::LoadLayers(sExpFileHdr *FileHdr)
|
|
|
|
{
|
|
|
|
u8 *ByteHdr=(u8*)FileHdr;
|
|
|
|
|
|
|
|
for (int i=0; i<FileHdr->LayerCount; i++)
|
|
|
|
{
|
|
|
|
sExpLayerHdr *LayerHdr=(sExpLayerHdr *)&ByteHdr[FileHdr->LayerOfs[i]];
|
|
|
|
|
|
|
|
switch(LayerHdr->Type)
|
|
|
|
{
|
|
|
|
case LAYER_TYPE_TILE:
|
|
|
|
switch (LayerHdr->SubType)
|
|
|
|
{
|
|
|
|
case LAYER_SUBTYPE_ACTION:
|
|
|
|
LayerList.push_back(new CMkLevelLayer3d(LayerHdr));
|
|
|
|
break;
|
|
|
|
case LAYER_SUBTYPE_MID:
|
|
|
|
LayerList.push_back(new CMkLevelLayerTile(LayerHdr));
|
|
|
|
break;
|
|
|
|
case LAYER_SUBTYPE_BACK:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LAYER_TYPE_COLLISION:
|
|
|
|
LayerList.push_back(new CMkLevelLayerCollision(LayerHdr));
|
|
|
|
break;
|
|
|
|
case LAYER_TYPE_SHADE:
|
|
|
|
LayerList.push_back(new CMkLevelLayerShade(LayerHdr));
|
|
|
|
break;
|
|
|
|
case LAYER_TYPE_ACTOR:
|
|
|
|
LayerList.push_back(new CMkLevelLayerActor(LayerHdr));
|
|
|
|
break;
|
|
|
|
case LAYER_TYPE_ITEM:
|
|
|
|
LayerList.push_back(new CMkLevelLayerItem(LayerHdr));
|
|
|
|
break;
|
|
|
|
case LAYER_TYPE_PLATFORM:
|
|
|
|
LayerList.push_back(new CMkLevelLayerPlatform(LayerHdr));
|
|
|
|
break;
|
|
|
|
case LAYER_TYPE_TRIGGER:
|
|
|
|
LayerList.push_back(new CMkLevelLayerTrigger(LayerHdr));
|
|
|
|
break;
|
|
|
|
case LAYER_TYPE_FX:
|
|
|
|
LayerList.push_back(new CMkLevelLayerFX(LayerHdr));
|
|
|
|
break;
|
2001-04-30 23:49:54 +02:00
|
|
|
case LAYER_TYPE_HAZARD:
|
|
|
|
LayerList.push_back(new CMkLevelLayerHazard(LayerHdr));
|
|
|
|
break;
|
2001-04-17 18:42:07 +02:00
|
|
|
default:
|
|
|
|
GObject::Error(ERR_FATAL,"Unknown Layer Type\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-23 16:51:44 +02:00
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
|
|
|
//*** Process ***************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::Process()
|
|
|
|
{
|
|
|
|
printf("PreProcess Layers\n");
|
|
|
|
PreProcessLayers();
|
2001-06-28 19:48:30 +02:00
|
|
|
printf("PreProcess ElemBanks\n");
|
|
|
|
PreProcessElemBank2d();
|
|
|
|
PreProcessElemBank3d();
|
|
|
|
printf("PreProcess Models\n");
|
|
|
|
PreProcessModels();
|
|
|
|
printf("Process Textures\n");
|
|
|
|
TexGrab.Process();
|
2001-06-27 18:45:56 +02:00
|
|
|
printf("Process ElemBanks\n");
|
2001-06-28 19:48:30 +02:00
|
|
|
ProcessElemBank2d();
|
|
|
|
ProcessElemBank3d();
|
2001-04-17 18:42:07 +02:00
|
|
|
printf("Process Layers\n");
|
|
|
|
ProcessLayers();
|
2001-06-28 19:48:30 +02:00
|
|
|
printf("Process Models\n");
|
|
|
|
ProcessModels();
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::PreProcessLayers()
|
|
|
|
{
|
|
|
|
int LayerCount=LayerList.size();
|
|
|
|
|
|
|
|
for (int i=0; i<LayerCount; i++)
|
|
|
|
{
|
|
|
|
LayerList[i]->PreProcess(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::ProcessLayers()
|
|
|
|
{
|
|
|
|
int LayerCount=LayerList.size();
|
|
|
|
|
|
|
|
for (int i=0; i<LayerCount; i++)
|
|
|
|
{
|
|
|
|
LayerList[i]->Process(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-27 18:45:56 +02:00
|
|
|
int CMkLevel::AddTile2d(sExpLayerTile &InTile)
|
|
|
|
{
|
|
|
|
sUsedTile2d ThisTile;
|
|
|
|
|
|
|
|
ThisTile.Tile=InTile.Tile;
|
|
|
|
ThisTile.Flags=InTile.Flags;
|
|
|
|
|
|
|
|
return(UsedTile2dList.Add(ThisTile));
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
int CMkLevel::AddTile3d(sExpLayerTile &InTile)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
sUsedTile3d ThisTile;
|
|
|
|
|
|
|
|
ThisTile.Tile=InTile.Tile;
|
|
|
|
ThisTile.Flags=InTile.Flags;
|
|
|
|
int TileID=UsedTile3dList.Add(ThisTile);
|
|
|
|
int TileIdx=(TileID<<2) | (InTile.Flags & PC_TILE_FLAG_MIRROR_XY);
|
|
|
|
return(TileIdx);
|
|
|
|
}
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
2001-06-27 18:45:56 +02:00
|
|
|
void CMkLevel::PreProcessElemBank2d()
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
int i,ListSize=UsedTile2dList.size();
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
// Extract Tex data from list
|
|
|
|
for (i=1; i<ListSize; i++)
|
|
|
|
{ // Skip blank
|
2001-06-27 18:45:56 +02:00
|
|
|
sUsedTile2d &ThisTile=UsedTile2dList[i];
|
|
|
|
ThisTile.TexID=Create2dTile(ThisTile.Tile,ThisTile.Flags);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-27 18:45:56 +02:00
|
|
|
void CMkLevel::ProcessElemBank2d()
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
int i,ListSize=UsedTile2dList.size();
|
2001-04-17 18:42:07 +02:00
|
|
|
vector<sTexOutInfo> &TexInfo=TexGrab.GetTexInfo();
|
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
OutElem2d.resize(ListSize);
|
2001-04-17 18:42:07 +02:00
|
|
|
for (i=1; i<ListSize; i++)
|
|
|
|
{ // Skip blank
|
2001-06-27 18:45:56 +02:00
|
|
|
sUsedTile2d &InTile=UsedTile2dList[i];
|
|
|
|
sElem2d &OutElem=OutElem2d[i];
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
SetUpTileUV(OutElem,TexInfo[InTile.TexID]);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-27 18:45:56 +02:00
|
|
|
void CMkLevel::PreProcessElemBank3d()
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
int i,ListSize=UsedTile3dList.size();
|
2001-04-19 17:12:21 +02:00
|
|
|
|
|
|
|
for (i=1; i<ListSize; i++)
|
|
|
|
{ // Skip Blank
|
2001-06-27 18:45:56 +02:00
|
|
|
sUsedTile3d &ThisTile=UsedTile3dList[i];
|
|
|
|
ThisTile.Tile=Create3dTile(ThisTile.Tile,ThisTile.Flags);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-28 19:48:30 +02:00
|
|
|
int MaxElemTri=0,MaxElemQuad=0;
|
2001-06-27 18:45:56 +02:00
|
|
|
void CMkLevel::ProcessElemBank3d()
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-06-28 19:48:30 +02:00
|
|
|
//int i,ListSize=UsedTile3dList.size(); <--- UsedTile3dList is tiles only!!
|
|
|
|
int i,ListSize=OutElem3d.size();
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-06-28 19:48:30 +02:00
|
|
|
ProcessElem3d(OutElem3d[i]);
|
|
|
|
}
|
|
|
|
printf("Max Elem Tri =%i\tMax Elem Quad =%i\n",MaxElemTri,MaxElemQuad);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::ProcessElem3d(sOutElem3d &ThisElem)
|
|
|
|
{
|
|
|
|
CFaceStore &ThisList=ThisElem.FaceStore;
|
2001-06-27 18:45:56 +02:00
|
|
|
|
|
|
|
ThisList.setMaxStripLength(StripLength);
|
|
|
|
ThisElem.Elem3d.TriStart=OutTriList.size();
|
|
|
|
ThisElem.Elem3d.QuadStart=OutQuadList.size();
|
2001-06-28 19:48:30 +02:00
|
|
|
if (!ThisElem.LocalGeom)
|
|
|
|
{ // Global Geom
|
|
|
|
ThisList.Process(OutTriList,OutQuadList,OutVtxList);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Local Geom
|
|
|
|
AddDefVtx(ThisElem.LocalVtxList);
|
|
|
|
ThisList.Process(OutTriList,OutQuadList,ThisElem.LocalVtxList);
|
|
|
|
int v,VtxListSize=ThisElem.LocalVtxList.size();
|
|
|
|
for (v=0; v<VtxListSize; v++)
|
|
|
|
{
|
|
|
|
u16 Idx=CFaceStore::AddVtx(OutVtxList,ThisElem.LocalVtxList[v]);
|
|
|
|
ThisElem.LocalVtxIdxList.push_back(Idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
ThisElem.Elem3d.TriCount=ThisList.GetTriFaceCount();
|
|
|
|
ThisElem.Elem3d.QuadCount=ThisList.GetQuadFaceCount();
|
|
|
|
if (MaxElemTri<ThisElem.Elem3d.TriCount) MaxElemTri=ThisElem.Elem3d.TriCount;
|
|
|
|
if (MaxElemQuad<ThisElem.Elem3d.QuadCount) MaxElemQuad=ThisElem.Elem3d.QuadCount;
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-27 18:45:56 +02:00
|
|
|
void CMkLevel::SetUpTileUV(sElem2d &Out, sTexOutInfo &Info)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
|
|
|
int W = Info.w-1;
|
|
|
|
int H = Info.h-1;
|
|
|
|
float Inx0, Iny0;
|
|
|
|
u8 Outx0, Outy0;
|
|
|
|
|
|
|
|
// Allow for upside textures now :oP
|
|
|
|
Inx0=0;
|
|
|
|
Iny0=1-0;
|
|
|
|
|
|
|
|
if (Info.Rotated)
|
|
|
|
{
|
|
|
|
GObject::Error(ERR_FATAL,"Rotated Texure, cant cope!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Outx0 = Info.u + round(Inx0 * W);
|
|
|
|
Outy0 = (Info.v + H) - round(Iny0 * H);
|
|
|
|
|
|
|
|
Out.u0=Outx0; Out.v0=Outy0;
|
|
|
|
Out.TPage=Info.Tpage;
|
|
|
|
Out.Clut=Info.Clut;
|
|
|
|
}
|
|
|
|
|
2001-04-23 16:51:44 +02:00
|
|
|
//***************************************************************************
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
|
|
|
//***************************************************************************
|
2001-04-23 16:51:44 +02:00
|
|
|
void CMkLevel::ExpTri2Face(sExpTri &ThisTri,CFace &F,bool ImportTex)
|
|
|
|
{
|
|
|
|
if (ImportTex)
|
|
|
|
{
|
|
|
|
F.TexName=InTexNameList[ThisTri.TexID];
|
|
|
|
F.Mat=-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
F.Mat=ThisTri.TexID;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int p=0; p<3; p++)
|
|
|
|
{
|
|
|
|
F.vtx[p]=ThisTri.vtx[p];
|
|
|
|
F.vtx[p].y=F.vtx[p].y;
|
|
|
|
F.uvs[p].u=ThisTri.uv[p][0];
|
|
|
|
F.uvs[p].v=ThisTri.uv[p][1];
|
|
|
|
}
|
2001-05-02 20:40:41 +02:00
|
|
|
|
2001-04-23 16:51:44 +02:00
|
|
|
|
|
|
|
}
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
|
|
|
CMkLevelLayer *CMkLevel::FindLayer(int Type,int SubType)
|
|
|
|
{
|
|
|
|
int ListSize=LayerList.size();
|
|
|
|
|
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
if (LayerList[i]->IsType(Type,SubType)) return(LayerList[i]);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-27 18:45:56 +02:00
|
|
|
int CMkLevel::Create3dTile(int Tile,int Flags)
|
|
|
|
{
|
2001-06-28 19:48:30 +02:00
|
|
|
sExpTile &SrcTile=InTileList[Tile];
|
|
|
|
int ElemID;
|
|
|
|
if (SrcTile.TriCount)
|
|
|
|
{
|
|
|
|
ElemID=Create3dElem(SrcTile.TriCount,SrcTile.TriStart,LocalGeom);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ElemID=Create2dElem(Tile,LocalGeom);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(ElemID);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
int CMkLevel::Create3dElem(int TriCount,int TriStart,bool Local)
|
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
CFace F;
|
2001-06-28 19:48:30 +02:00
|
|
|
int i,ListSize;
|
2001-06-27 18:45:56 +02:00
|
|
|
CList<sExpTri> SortList;
|
|
|
|
CList<float> ZPosList;
|
2001-06-28 19:48:30 +02:00
|
|
|
int ElemID=OutElem3d.size();
|
|
|
|
OutElem3d.resize(ElemID+1);
|
2001-06-27 18:45:56 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
sOutElem3d &ThisElem=OutElem3d[ElemID];
|
|
|
|
CFaceStore &FaceList=ThisElem.FaceStore;
|
|
|
|
FaceList.SetTexGrab(TexGrab);
|
|
|
|
ThisElem.LocalGeom=Local;
|
|
|
|
|
|
|
|
for (i=0; i<TriCount; i++)
|
2001-06-27 18:45:56 +02:00
|
|
|
{
|
2001-06-28 19:48:30 +02:00
|
|
|
int ListPos;
|
|
|
|
sExpTri &ThisTri=InTriList[TriStart+i];
|
|
|
|
float ThisZPos;
|
2001-06-27 18:45:56 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
ThisZPos=ThisTri.vtx[0].z;
|
|
|
|
if (ThisZPos<ThisTri.vtx[1].z) ThisZPos=ThisTri.vtx[1].z;
|
|
|
|
if (ThisZPos<ThisTri.vtx[2].z) ThisZPos=ThisTri.vtx[2].z;
|
2001-06-27 18:45:56 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
ListSize=SortList.size();
|
|
|
|
for (ListPos=0; ListPos<ListSize; ListPos++)
|
|
|
|
{
|
|
|
|
if (ZPosList[ListPos]>ThisZPos) break;
|
2001-06-27 18:45:56 +02:00
|
|
|
}
|
2001-06-28 19:48:30 +02:00
|
|
|
SortList.insert(ListPos,ThisTri);
|
|
|
|
ZPosList.insert(ListPos,ThisZPos);
|
2001-06-27 18:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add sorted list to main list
|
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
for (i=0; i<TriCount; i++)
|
2001-06-27 18:45:56 +02:00
|
|
|
{
|
|
|
|
sExpTri &ThisTri=SortList[i];
|
|
|
|
CFace F;
|
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
F.TexName=InTexNameList[ThisTri.TexID];
|
|
|
|
F.Mat=-1;
|
|
|
|
|
|
|
|
for (int p=0; p<3; p++)
|
2001-06-27 18:45:56 +02:00
|
|
|
{
|
2001-06-28 19:48:30 +02:00
|
|
|
F.vtx[p]=ThisTri.vtx[p];
|
|
|
|
F.uvs[p].u=ThisTri.uv[p][0];
|
|
|
|
F.uvs[p].v=ThisTri.uv[p][1];
|
2001-06-27 18:45:56 +02:00
|
|
|
}
|
2001-06-28 19:48:30 +02:00
|
|
|
FaceList.SetTPageFlag(F,ThisTri.Flags);
|
|
|
|
FaceList.AddFace(F,true);
|
|
|
|
}
|
|
|
|
return(ElemID);
|
|
|
|
}
|
2001-06-27 18:45:56 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
//***************************************************************************
|
|
|
|
int CMkLevel::Create2dElem(int Tile,bool Local)
|
|
|
|
{
|
|
|
|
CFace F;
|
|
|
|
int i;
|
|
|
|
int TexID=Create2dTile(Tile,0);
|
|
|
|
int ElemID=OutElem3d.size();
|
|
|
|
OutElem3d.resize(ElemID+1);
|
|
|
|
|
|
|
|
sOutElem3d &ThisElem=OutElem3d[ElemID];
|
|
|
|
CFaceStore &FaceList=ThisElem.FaceStore;
|
|
|
|
FaceList.SetTexGrab(TexGrab);
|
|
|
|
ThisElem.LocalGeom=Local;
|
|
|
|
|
|
|
|
for (i=0; i<2; i++)
|
|
|
|
{
|
|
|
|
sExpTri &ThisTri=FlatFace[i];
|
|
|
|
CFace F;
|
|
|
|
|
|
|
|
F.Mat=TexID;
|
|
|
|
|
|
|
|
for (int p=0; p<3; p++)
|
2001-06-27 18:45:56 +02:00
|
|
|
{
|
|
|
|
F.vtx[p]=ThisTri.vtx[p];
|
|
|
|
F.uvs[p].u=ThisTri.uv[p][0];
|
|
|
|
F.uvs[p].v=ThisTri.uv[p][1];
|
|
|
|
}
|
2001-06-28 19:48:30 +02:00
|
|
|
FaceList.SetTPageFlag(F,0);
|
2001-06-27 18:45:56 +02:00
|
|
|
FaceList.AddFace(F,true);
|
|
|
|
}
|
2001-06-28 19:48:30 +02:00
|
|
|
return(ElemID);
|
2001-06-27 18:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
int CMkLevel::Create3dTile(int Tile,int Flags)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
sExpTile &SrcTile=InTileList[Tile];
|
2001-04-17 18:42:07 +02:00
|
|
|
CFace F;
|
2001-04-19 17:12:21 +02:00
|
|
|
int i,ListSize,p;
|
2001-04-17 18:42:07 +02:00
|
|
|
CList<sExpTri> SortList;
|
|
|
|
CList<float> ZPosList;
|
2001-06-27 18:45:56 +02:00
|
|
|
sTileBank3d ThisTile;
|
|
|
|
int TileID=OutTileBank3d.size();
|
|
|
|
CFaceStore FaceStore;
|
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
|
|
|
|
ThisTile.TriStart=OutFaceList.GetFaceCount();
|
|
|
|
ThisTile.QuadCount=0;
|
|
|
|
ThisTile.QuadStart=0;
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
if (SrcTile.TriCount)
|
|
|
|
{
|
2001-04-19 17:12:21 +02:00
|
|
|
ThisTile.TriCount=SrcTile.TriCount;
|
2001-04-17 18:42:07 +02:00
|
|
|
for (i=0; i<SrcTile.TriCount; i++)
|
|
|
|
{
|
|
|
|
int ListPos;
|
2001-05-05 23:18:12 +02:00
|
|
|
sExpTri &ThisTri=InTriList[SrcTile.TriStart+i];
|
2001-04-17 18:42:07 +02:00
|
|
|
float ThisZPos;
|
|
|
|
|
|
|
|
ThisZPos=ThisTri.vtx[0].z;
|
2001-04-23 16:51:44 +02:00
|
|
|
if (ThisZPos<ThisTri.vtx[1].z) ThisZPos=ThisTri.vtx[1].z;
|
|
|
|
if (ThisZPos<ThisTri.vtx[2].z) ThisZPos=ThisTri.vtx[2].z;
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
ListSize=SortList.size();
|
|
|
|
for (ListPos=0; ListPos<ListSize; ListPos++)
|
|
|
|
{
|
2001-04-23 16:51:44 +02:00
|
|
|
if (ZPosList[ListPos]>ThisZPos) break;
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
2001-04-19 17:12:21 +02:00
|
|
|
SortList.insert(ListPos,ThisTri);
|
|
|
|
ZPosList.insert(ListPos,ThisZPos);
|
|
|
|
}
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
}
|
|
|
|
else
|
2001-06-27 18:45:56 +02:00
|
|
|
{
|
|
|
|
int TexID=Create2dTile(Tile,0);
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
ThisTile.TriCount=2;
|
2001-05-05 23:18:12 +02:00
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
for (int i=0; i<2; i++)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-05-05 23:18:12 +02:00
|
|
|
FlatFace[i].Flags=0;
|
2001-04-19 17:12:21 +02:00
|
|
|
FlatFace[i].TexID=TexID;
|
|
|
|
SortList.push_back(FlatFace[i]);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
2001-04-19 17:12:21 +02:00
|
|
|
}
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
// Add sorted list to main list
|
2001-04-19 17:12:21 +02:00
|
|
|
ListSize=SortList.size();
|
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
sExpTri &ThisTri=SortList[i];
|
|
|
|
CFace F;
|
|
|
|
bool SwapPnt=false;
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
if (SrcTile.TriCount)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
|
|
|
F.TexName=InTexNameList[ThisTri.TexID];
|
|
|
|
F.Mat=-1;
|
2001-04-19 17:12:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
F.Mat=ThisTri.TexID;
|
|
|
|
}
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
for (p=0; p<3; p++)
|
|
|
|
{
|
|
|
|
F.vtx[p]=ThisTri.vtx[p];
|
2001-04-23 16:51:44 +02:00
|
|
|
F.vtx[p].y=F.vtx[p].y;
|
2001-04-19 17:12:21 +02:00
|
|
|
F.uvs[p].u=ThisTri.uv[p][0];
|
|
|
|
F.uvs[p].v=ThisTri.uv[p][1];
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
2001-04-19 17:12:21 +02:00
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
if (Flags & PC_TILE_FLAG_MIRROR_X)
|
2001-04-19 17:12:21 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
if (Flags & PC_TILE_FLAG_MIRROR_Y)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-04-19 17:12:21 +02:00
|
|
|
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;
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
2001-04-23 16:51:44 +02:00
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
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;
|
|
|
|
}
|
2001-06-27 18:45:56 +02:00
|
|
|
|
2001-05-02 20:40:41 +02:00
|
|
|
OutFaceList.SetTPageFlag(F,ThisTri.Flags);
|
2001-04-19 17:12:21 +02:00
|
|
|
OutFaceList.AddFace(F,true);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
OutTileBank3d.push_back(ThisTile);
|
2001-04-19 17:12:21 +02:00
|
|
|
return(TileID);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
*/
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
2001-06-27 18:45:56 +02:00
|
|
|
int CMkLevel::Create2dTile(int Tile,int Flags)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-04-23 16:51:44 +02:00
|
|
|
sExpTile &SrcTile=InTileList[Tile];
|
2001-05-05 23:18:12 +02:00
|
|
|
sMkLevelTex InTex;
|
|
|
|
int Idx;
|
2001-06-27 18:45:56 +02:00
|
|
|
|
2001-05-05 23:18:12 +02:00
|
|
|
InTex.Tile=Tile;
|
|
|
|
InTex.Flags=Flags;
|
|
|
|
|
|
|
|
Idx=Tex2dList.Find(InTex);
|
|
|
|
|
|
|
|
if (Idx!=-1)
|
|
|
|
{
|
|
|
|
return(Tex2dList[Idx].TexID);
|
|
|
|
}
|
2001-05-02 20:40:41 +02:00
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
// Must be new, add it
|
2001-05-05 23:18:12 +02:00
|
|
|
InTex.TexID=BuildTileTex(SrcTile,Flags);
|
|
|
|
Tex2dList.push_back(InTex);
|
|
|
|
return(InTex.TexID);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-05-02 20:40:41 +02:00
|
|
|
int CMkLevel::BuildTileTex(sExpTile &SrcTile,int Flags)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-05-02 20:40:41 +02:00
|
|
|
Frame &InFrame=BmpList[SrcTile.Set];
|
2001-04-17 18:42:07 +02:00
|
|
|
Frame ThisFrame;
|
|
|
|
Rect ThisRect;
|
2001-05-02 20:40:41 +02:00
|
|
|
GString Name=GFName(InSetNameList[SrcTile.Set]).File();
|
2001-04-17 18:42:07 +02:00
|
|
|
GString TexName;
|
|
|
|
int BmpW=InFrame.GetWidth();
|
|
|
|
int BmpH=InFrame.GetHeight();
|
2001-05-02 20:40:41 +02:00
|
|
|
int TexID;
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-05-02 20:40:41 +02:00
|
|
|
if (SrcTile.XOfs*16>BmpW)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-05-02 20:40:41 +02:00
|
|
|
printf("AARGH!!! %s(%i) wants X=%i,tile is only %i Wide\n",Name,SrcTile.Set,SrcTile.XOfs*16,BmpW);
|
|
|
|
SrcTile.XOfs=0;
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
2001-05-02 20:40:41 +02:00
|
|
|
if (SrcTile.YOfs*16>BmpH)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-05-02 20:40:41 +02:00
|
|
|
printf("AARGH!!! %s(%i) wants Y=%i,tile is only %i High\n",Name,SrcTile.Set,SrcTile.YOfs*16,BmpH);
|
|
|
|
SrcTile.YOfs=0;
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
2001-05-02 20:40:41 +02:00
|
|
|
MakeTexName(SrcTile,Flags,TexName);
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-05-02 20:40:41 +02:00
|
|
|
ThisRect.X=SrcTile.XOfs*16;
|
|
|
|
ThisRect.Y=SrcTile.YOfs*16;
|
2001-04-17 18:42:07 +02:00
|
|
|
ThisRect.W=16;
|
|
|
|
ThisRect.H=16;
|
|
|
|
|
|
|
|
ThisFrame.Grab(InFrame,ThisRect);
|
|
|
|
|
2001-05-02 20:40:41 +02:00
|
|
|
if (Flags& PC_TILE_FLAG_MIRROR_X) ThisFrame.FlipX();
|
|
|
|
if (Flags & PC_TILE_FLAG_MIRROR_Y) ThisFrame.FlipY();
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-05-02 20:40:41 +02:00
|
|
|
TexID=TexGrab.AddMemFrame(TexName,ThisFrame);
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
if (!ThisFrame.IsBlank())
|
|
|
|
{
|
|
|
|
char DbgName[256];
|
|
|
|
sprintf(DbgName,"/x/%s.lbm",TexName);
|
|
|
|
ThisFrame.SaveLbm(DbgName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2001-05-02 20:40:41 +02:00
|
|
|
return(TexID);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-05-02 20:40:41 +02:00
|
|
|
void CMkLevel::MakeTexName(sExpTile &SrcTile,int Flags,GString &OutStr)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
|
|
|
char NewName[256];
|
2001-05-02 20:40:41 +02:00
|
|
|
GString Name=GFName(InSetNameList[SrcTile.Set]).File();
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-05-02 20:40:41 +02:00
|
|
|
sprintf(NewName,"%s_%02d_%02d_%01d_",Name,SrcTile.XOfs,SrcTile.YOfs,Flags&PC_TILE_FLAG_MIRROR_XY);
|
2001-04-17 18:42:07 +02:00
|
|
|
OutStr=NewName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//*** Write *****************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::Write()
|
|
|
|
{
|
2001-04-19 17:12:21 +02:00
|
|
|
GString OutFilename=OutName+".Lvl";
|
|
|
|
|
|
|
|
File=fopen(OutFilename,"wb");
|
|
|
|
|
|
|
|
fwrite(&LevelHdr,1,sizeof(sLevelHdr),File);
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
WriteLevel();
|
2001-06-27 18:45:56 +02:00
|
|
|
WriteElemBanks();
|
2001-04-19 17:12:21 +02:00
|
|
|
|
|
|
|
// rewrite header
|
|
|
|
fseek(File,0,SEEK_SET);
|
|
|
|
fwrite(&LevelHdr,1,sizeof(sLevelHdr),File);
|
|
|
|
|
|
|
|
fclose(File);
|
2001-05-23 18:03:10 +02:00
|
|
|
// Write Info header File
|
|
|
|
WriteIncFile();
|
2001-06-25 17:54:07 +02:00
|
|
|
|
|
|
|
// Write Sizes
|
|
|
|
ReportLayers();
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-04-19 17:12:21 +02:00
|
|
|
int MinOT=123456,MaxOT=0;
|
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
void CMkLevel::WriteElemBanks()
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
|
|
|
int i,ListSize;
|
|
|
|
|
2001-06-27 18:45:56 +02:00
|
|
|
// 2d Elem
|
|
|
|
LevelHdr.ElemBank2d=(sElem2d*)ftell(File);
|
|
|
|
ListSize=OutElem2d.size();
|
|
|
|
printf("%i 2d Elems\t(%i Bytes)\n",ListSize,ListSize*sizeof(sElem2d));
|
2001-04-17 18:42:07 +02:00
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
sElem2d &OutElem=OutElem2d[i];
|
|
|
|
fwrite(&OutElem,1,sizeof(sElem2d),File);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
2001-06-27 18:45:56 +02:00
|
|
|
// 3d Elem
|
|
|
|
|
|
|
|
LevelHdr.ElemBank3d=(sElem3d*)ftell(File);
|
|
|
|
ListSize=OutElem3d.size();
|
|
|
|
printf("%i 3d Elems\t(%i Bytes)\n",ListSize,ListSize*sizeof(sElem3d));
|
2001-04-17 18:42:07 +02:00
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
sElem3d &OutElem=OutElem3d[i].Elem3d;
|
|
|
|
fwrite(&OutElem,1,sizeof(sElem3d),File);
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
// TriList
|
2001-04-19 17:12:21 +02:00
|
|
|
LevelHdr.TriList=(sTri*)WriteTriList();
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
// QuadList
|
2001-04-19 17:12:21 +02:00
|
|
|
LevelHdr.QuadList=(sQuad*)WriteQuadList();
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
// VtxList
|
2001-04-19 17:12:21 +02:00
|
|
|
LevelHdr.VtxList=(sVtx*)WriteVtxList();
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-27 18:45:56 +02:00
|
|
|
int ZMin=9999,ZMax=0;
|
2001-06-28 19:48:30 +02:00
|
|
|
int SnapCount[8]={0,0,0,0,0,0,0,0};
|
2001-04-17 18:42:07 +02:00
|
|
|
int CMkLevel::WriteTriList()
|
|
|
|
{
|
|
|
|
int ThisPos=ftell(File);
|
2001-06-27 18:45:56 +02:00
|
|
|
int i,ListSize=OutTriList.size();
|
2001-05-02 20:40:41 +02:00
|
|
|
int ZOfs=+4*Scale;
|
2001-04-19 17:12:21 +02:00
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
for (i=0;i<ListSize;i++)
|
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
sTri &T=OutTriList[i];
|
2001-04-17 18:42:07 +02:00
|
|
|
int OtOfs=0;
|
2001-05-02 20:40:41 +02:00
|
|
|
int Z[3];
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
// Calc OtOfs
|
2001-06-27 18:45:56 +02:00
|
|
|
Z[0]=OutVtxList[T.P0].vz+ZOfs;
|
|
|
|
Z[1]=OutVtxList[T.P1].vz+ZOfs;
|
|
|
|
Z[2]=OutVtxList[T.P2].vz+ZOfs;
|
2001-06-28 19:48:30 +02:00
|
|
|
|
|
|
|
if (T.P0<8) SnapCount[T.P0]++;
|
|
|
|
if (T.P1<8) SnapCount[T.P1]++;
|
|
|
|
if (T.P2<8) SnapCount[T.P2]++;
|
2001-04-17 18:42:07 +02:00
|
|
|
for (int p=0; p<3; p++)
|
|
|
|
{
|
2001-05-02 20:40:41 +02:00
|
|
|
if (ZMin>Z[p]) ZMin=Z[p];
|
|
|
|
if (ZMax<Z[p]) ZMax=Z[p];
|
|
|
|
OtOfs+=Z[p]*Z[p];
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
2001-05-02 20:40:41 +02:00
|
|
|
OtOfs=(int)sqrt(OtOfs/3);
|
|
|
|
|
|
|
|
OtOfs/=8;
|
2001-04-19 17:12:21 +02:00
|
|
|
if (MinOT>OtOfs) MinOT=OtOfs;
|
2001-04-17 18:42:07 +02:00
|
|
|
if (MaxOT<OtOfs) MaxOT=OtOfs;
|
2001-04-19 17:12:21 +02:00
|
|
|
if (OtOfs>15) OtOfs=15;
|
2001-05-02 20:40:41 +02:00
|
|
|
if (OtOfs<0) OtOfs=0;
|
|
|
|
|
|
|
|
T.OTOfs=OtOfs;
|
2001-04-17 18:42:07 +02:00
|
|
|
// Write It
|
|
|
|
fwrite(&T,1,sizeof(sTri),File);
|
|
|
|
}
|
2001-06-25 17:54:07 +02:00
|
|
|
printf("%i Tris\t(%i Bytes)\n",ListSize,ListSize*sizeof(sTri));
|
2001-06-28 19:48:30 +02:00
|
|
|
// printf("\n"); for (i=0; i<8;i++) printf("Snapped Vtx %i=%i \n",i,SnapCount[i]); printf("\n");
|
2001-04-17 18:42:07 +02:00
|
|
|
return(ThisPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-04-19 17:12:21 +02:00
|
|
|
int CMkLevel::WriteQuadList()
|
|
|
|
{
|
|
|
|
int ThisPos=ftell(File);
|
2001-06-27 18:45:56 +02:00
|
|
|
int i,ListSize=OutQuadList.size();
|
|
|
|
int ZOfs=+4*Scale;
|
2001-04-19 17:12:21 +02:00
|
|
|
|
|
|
|
for (i=0;i<ListSize;i++)
|
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
sQuad &Q=OutQuadList[i];
|
2001-04-19 17:12:21 +02:00
|
|
|
int OtOfs=0;
|
2001-06-27 18:45:56 +02:00
|
|
|
int Z[4];
|
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
// Calc OtOfs
|
2001-06-27 18:45:56 +02:00
|
|
|
Z[0]=OutVtxList[Q.P0].vz+ZOfs;
|
|
|
|
Z[1]=OutVtxList[Q.P1].vz+ZOfs;
|
|
|
|
Z[2]=OutVtxList[Q.P2].vz+ZOfs;
|
|
|
|
Z[3]=OutVtxList[Q.P3].vz+ZOfs;
|
2001-04-19 17:12:21 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
if (Q.P0<8) SnapCount[Q.P0]++;
|
|
|
|
if (Q.P1<8) SnapCount[Q.P1]++;
|
|
|
|
if (Q.P2<8) SnapCount[Q.P2]++;
|
|
|
|
if (Q.P3<8) SnapCount[Q.P3]++;
|
2001-04-19 17:12:21 +02:00
|
|
|
for (int p=0; p<4; p++)
|
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
if (ZMin>Z[p]) ZMin=Z[p];
|
|
|
|
if (ZMax<Z[p]) ZMax=Z[p];
|
|
|
|
OtOfs+=Z[p]*Z[p];
|
2001-04-19 17:12:21 +02:00
|
|
|
}
|
2001-06-27 18:45:56 +02:00
|
|
|
OtOfs=(int)sqrt(OtOfs/4);
|
|
|
|
|
|
|
|
OtOfs/=8;
|
2001-04-19 17:12:21 +02:00
|
|
|
if (MinOT>OtOfs) MinOT=OtOfs;
|
|
|
|
if (MaxOT<OtOfs) MaxOT=OtOfs;
|
2001-06-27 18:45:56 +02:00
|
|
|
if (OtOfs>15) OtOfs=15;
|
|
|
|
if (OtOfs<0) OtOfs=0;
|
|
|
|
|
|
|
|
Q.OTOfs=OtOfs;
|
2001-04-19 17:12:21 +02:00
|
|
|
// Write It
|
|
|
|
fwrite(&Q,1,sizeof(sQuad),File);
|
|
|
|
}
|
2001-06-25 17:54:07 +02:00
|
|
|
printf("%i Quads\t(%i Bytes)\n",ListSize,ListSize*sizeof(sQuad));
|
2001-06-28 19:48:30 +02:00
|
|
|
// printf("\n"); for (i=0; i<8;i++) printf("Snapped Vtx %i=%i \n",i,SnapCount[i]); printf("\n");
|
2001-04-19 17:12:21 +02:00
|
|
|
return(ThisPos);
|
|
|
|
}
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
//***************************************************************************
|
2001-06-28 19:48:30 +02:00
|
|
|
sVtx Min={+100,+100,+100};
|
|
|
|
sVtx Max={-100,-100,-100};
|
2001-04-19 17:12:21 +02:00
|
|
|
int CMkLevel::WriteVtxList()
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
int i,ListSize=OutVtxList.size();
|
2001-04-19 17:12:21 +02:00
|
|
|
int Pos=ftell(File);
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-06-27 18:45:56 +02:00
|
|
|
sVtx const &In=OutVtxList[i];
|
2001-04-19 17:12:21 +02:00
|
|
|
sVtx Out;
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-04-23 16:51:44 +02:00
|
|
|
Out.vx=+In.vx;
|
2001-06-27 18:45:56 +02:00
|
|
|
Out.vy=-In.vy+(Scale/2); // Offset it so the origin is centre centre
|
2001-04-23 16:51:44 +02:00
|
|
|
Out.vz=+In.vz;
|
2001-06-28 19:48:30 +02:00
|
|
|
Min.vx=__min(Min.vx,Out.vx);
|
|
|
|
Min.vy=__min(Min.vy,Out.vy);
|
|
|
|
Min.vz=__min(Min.vz,Out.vz);
|
|
|
|
Max.vx=__max(Max.vx,Out.vx);
|
|
|
|
Max.vy=__max(Max.vy,Out.vy);
|
|
|
|
Max.vz=__max(Max.vz,Out.vz);
|
2001-04-19 17:12:21 +02:00
|
|
|
fwrite(&Out,1,sizeof(sVtx),File);
|
2001-06-28 19:48:30 +02:00
|
|
|
// if (abs(Out.vz)==400) printf("%i %i %i\n",Out.vx,Out.vy,Out.vz);
|
2001-04-19 17:12:21 +02:00
|
|
|
}
|
2001-06-25 17:54:07 +02:00
|
|
|
printf("%i Vtx\t(%i Bytes)\n",ListSize,ListSize*sizeof(sVtx));
|
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
printf("Min %i %i %i\n",Min.vx,Min.vy,Min.vz);
|
|
|
|
printf("Max %i %i %i\n",Max.vx,Max.vy,Max.vz);
|
|
|
|
|
2001-04-19 17:12:21 +02:00
|
|
|
return(Pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//*** Write *****************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::WriteLevel()
|
|
|
|
{
|
|
|
|
WriteLayers();
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::WriteLayers()
|
|
|
|
{
|
|
|
|
// Back (Shade)
|
2001-06-25 17:54:07 +02:00
|
|
|
LevelHdr.BackLayer=WriteLayer(LAYER_TYPE_SHADE,LAYER_SUBTYPE_BACK);
|
2001-04-17 18:42:07 +02:00
|
|
|
// Mid
|
2001-06-25 17:54:07 +02:00
|
|
|
LevelHdr.MidLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_MID);
|
2001-04-17 18:42:07 +02:00
|
|
|
// Action
|
2001-06-25 17:54:07 +02:00
|
|
|
LevelHdr.ActionLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION);
|
2001-04-17 18:42:07 +02:00
|
|
|
// Collision
|
2001-06-25 17:54:07 +02:00
|
|
|
LevelHdr.CollisionLayer=WriteLayer(LAYER_TYPE_COLLISION,LAYER_SUBTYPE_NONE);
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
// Things
|
2001-06-25 17:54:07 +02:00
|
|
|
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);
|
2001-06-28 19:48:30 +02:00
|
|
|
LevelHdr.ModelList=(sModel*)WriteModelList();
|
2001-06-25 17:54:07 +02:00
|
|
|
printf("Things =\t(%i Bytes)\n",ftell(File)-ThingStart);
|
|
|
|
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-25 17:54:07 +02:00
|
|
|
int CMkLevel::WriteLayer(int Type,int SubType,bool Warn)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
|
|
|
CMkLevelLayer *ThisLayer=FindLayer(Type,SubType);
|
|
|
|
int Ofs;
|
2001-06-25 17:54:07 +02:00
|
|
|
char *LayerName=GetLayerName(Type,SubType);
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
if (!ThisLayer)
|
|
|
|
{
|
2001-06-25 17:54:07 +02:00
|
|
|
if (Warn) GObject::Error(ERR_WARNING,"No %s Layer Found in %s!!\n",LayerName,LevelName);
|
2001-04-17 18:42:07 +02:00
|
|
|
return(0);
|
|
|
|
}
|
2001-06-25 17:54:07 +02:00
|
|
|
Ofs=ThisLayer->Write(this,File,LayerName);
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
PadFile(File);
|
|
|
|
return(Ofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-06-25 17:54:07 +02:00
|
|
|
int CMkLevel::WriteThings(int Type,bool Warn)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
|
|
|
CMkLevelLayer *ThisLayer=FindLayer(Type,LAYER_SUBTYPE_NONE);
|
|
|
|
int Ofs;
|
2001-06-25 17:54:07 +02:00
|
|
|
char *LayerName=GetLayerName(Type,LAYER_SUBTYPE_NONE);
|
2001-04-17 18:42:07 +02:00
|
|
|
|
|
|
|
if (!ThisLayer)
|
|
|
|
{
|
|
|
|
GFName Name=InFilename;
|
2001-06-25 17:54:07 +02:00
|
|
|
if (Warn) GObject::Error(ERR_WARNING,"No %s Layer Found in %s!!\n",LayerName,Name.File());
|
2001-04-17 18:42:07 +02:00
|
|
|
return(0);
|
|
|
|
}
|
2001-06-25 17:54:07 +02:00
|
|
|
Ofs=ThisLayer->Write(this,File,LayerName);
|
2001-04-19 17:12:21 +02:00
|
|
|
// printf("%s %i\n",LayerName,Ofs);
|
2001-04-17 18:42:07 +02:00
|
|
|
PadFile(File);
|
|
|
|
return(Ofs);
|
|
|
|
}
|
2001-04-23 16:51:44 +02:00
|
|
|
|
|
|
|
//***************************************************************************
|
2001-04-27 18:16:23 +02:00
|
|
|
int CMkLevel::WriteModelList()
|
2001-04-23 16:51:44 +02:00
|
|
|
{
|
2001-04-27 18:16:23 +02:00
|
|
|
int i,ListSize=ModelList.size();
|
2001-04-23 16:51:44 +02:00
|
|
|
int Ofs=ftell(File);
|
|
|
|
|
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
sModel Out;
|
2001-04-27 18:16:23 +02:00
|
|
|
sMkLevelModel &ThisModel=ModelList[i];
|
2001-06-28 19:48:30 +02:00
|
|
|
sOutElem3d &ThisElem=OutElem3d[ThisModel.ElemID];
|
|
|
|
sBBox &ElemBBox=ThisElem.FaceStore.GetBBox();
|
|
|
|
Out.ElemID=ThisModel.ElemID;
|
|
|
|
Out.BBox=ElemBBox;
|
2001-04-23 16:51:44 +02:00
|
|
|
|
2001-06-28 19:48:30 +02:00
|
|
|
printf("Writing Model %s (%i) (%i %i) (BBox %i,%i->%i,%i)\n",ThisModel.Name,Out.ElemID,ThisElem.Elem3d.TriCount,ThisElem.Elem3d.QuadCount,Out.BBox.XMin,Out.BBox.YMin,Out.BBox.XMax,Out.BBox.YMax);
|
2001-04-23 16:51:44 +02:00
|
|
|
fwrite(&Out,1,sizeof(sModel),File);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(Ofs);
|
|
|
|
}
|
2001-05-05 23:18:12 +02:00
|
|
|
|
|
|
|
//***************************************************************************
|
2001-05-23 18:03:10 +02:00
|
|
|
//*** Inf File **************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::AddInfItem(const char *Name,int Val)
|
|
|
|
{
|
|
|
|
sInfItem Item;
|
2001-05-30 19:02:54 +02:00
|
|
|
GString ReplaceBadFileChars(GString s); // Dodgy extern from TexGrab Lib!
|
|
|
|
Item.Name=ReplaceBadFileChars(Name);
|
2001-05-23 18:03:10 +02:00
|
|
|
Item.Name.Upper();
|
|
|
|
Item.Val=Val;
|
|
|
|
|
|
|
|
InfList.Add(Item);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkLevel::WriteIncFile()
|
|
|
|
{
|
|
|
|
GString DefStr;
|
|
|
|
|
|
|
|
DefStr=LevelFullName+"_INF";
|
|
|
|
File=fopen(OutIncName,"wt");
|
|
|
|
|
|
|
|
fprintf(File,"// %s Info Header\n",LevelFullName);
|
|
|
|
fprintf(File,"\n");
|
|
|
|
fprintf(File,"#ifndef\t__%s_INF_HEADER__\n",LevelFullName);
|
|
|
|
fprintf(File,"#define\t__%s_INF_HEADER__\n",LevelFullName);
|
|
|
|
fprintf(File,"\n");
|
|
|
|
fprintf(File,"\n");
|
|
|
|
fprintf(File,"enum\t%s\n",DefStr);
|
|
|
|
fprintf(File,"{\n");
|
|
|
|
|
|
|
|
int ListSize=InfList.size();
|
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
sInfItem &ThisItem=InfList[i];
|
|
|
|
|
|
|
|
fprintf(File,"\t%s_%s\t\t=%i,\n",DefStr,ThisItem.Name,ThisItem.Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(File,"};\n");
|
|
|
|
fprintf(File,"\n");
|
|
|
|
fprintf(File,"#endif\n");
|
|
|
|
|
|
|
|
fclose(File);
|
|
|
|
}
|
2001-06-25 17:54:07 +02:00
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
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);
|
|
|
|
}
|