From 31490231932cb3d4dc0a63d983f6f22b55461d9a Mon Sep 17 00:00:00 2001 From: Daveo Date: Tue, 17 Apr 2001 16:42:07 +0000 Subject: [PATCH] --- Utils/MkLevel/Layers/MkLevelLayer.h | 35 + Utils/MkLevel/Layers/MkLevelLayer3d.cpp | 267 ++++++ Utils/MkLevel/Layers/MkLevelLayer3d.h | 28 + Utils/MkLevel/Layers/MkLevelLayerActor.cpp | 95 +++ Utils/MkLevel/Layers/MkLevelLayerActor.h | 25 + .../MkLevel/Layers/MkLevelLayerCollision.cpp | 95 +++ Utils/MkLevel/Layers/MkLevelLayerCollision.h | 27 + Utils/MkLevel/Layers/MkLevelLayerFX.cpp | 65 ++ Utils/MkLevel/Layers/MkLevelLayerFX.h | 25 + Utils/MkLevel/Layers/MkLevelLayerItem.cpp | 59 ++ Utils/MkLevel/Layers/MkLevelLayerItem.h | 25 + Utils/MkLevel/Layers/MkLevelLayerPlatform.cpp | 71 ++ Utils/MkLevel/Layers/MkLevelLayerPlatform.h | 25 + Utils/MkLevel/Layers/MkLevelLayerShade.cpp | 162 ++++ Utils/MkLevel/Layers/MkLevelLayerShade.h | 51 ++ Utils/MkLevel/Layers/MkLevelLayerThing.cpp | 87 ++ Utils/MkLevel/Layers/MkLevelLayerThing.h | 46 + Utils/MkLevel/Layers/MkLevelLayerTile.cpp | 112 +++ Utils/MkLevel/Layers/MkLevelLayerTile.h | 34 + Utils/MkLevel/Layers/MkLevelLayerTrigger.cpp | 63 ++ Utils/MkLevel/Layers/MkLevelLayerTrigger.h | 25 + Utils/MkLevel/Main.cpp | 107 +++ Utils/MkLevel/MkLevel.cpp | 801 ++++++++++++++++++ Utils/MkLevel/MkLevel.dsp | 190 +++++ Utils/MkLevel/MkLevel.h | 128 +++ 25 files changed, 2648 insertions(+) create mode 100644 Utils/MkLevel/Layers/MkLevelLayer.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayer3d.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayer3d.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerActor.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerActor.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerCollision.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerCollision.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerFX.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerFX.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerItem.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerItem.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerPlatform.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerPlatform.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerShade.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerShade.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerThing.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerThing.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerTile.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerTile.h create mode 100644 Utils/MkLevel/Layers/MkLevelLayerTrigger.cpp create mode 100644 Utils/MkLevel/Layers/MkLevelLayerTrigger.h create mode 100644 Utils/MkLevel/Main.cpp create mode 100644 Utils/MkLevel/MkLevel.cpp create mode 100644 Utils/MkLevel/MkLevel.dsp create mode 100644 Utils/MkLevel/MkLevel.h diff --git a/Utils/MkLevel/Layers/MkLevelLayer.h b/Utils/MkLevel/Layers/MkLevelLayer.h new file mode 100644 index 000000000..42a7d998e --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayer.h @@ -0,0 +1,35 @@ +/******************/ +/*** Layer Core ***/ +/******************/ + +#ifndef __MKLEVEL_LAYER_HEADER__ +#define __MKLEVEL_LAYER_HEADER__ + +#include + +#include "..\MkLevel.h" +#include "..\..\MapEdit\LayerDef.h" +#include "..\..\mapedit\ExportHdr.h" + + +/*****************************************************************************/ +class CMkLevelLayer +{ +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; + + bool IsType(int _Type,int _SubType) {return(Type==_Type && SubType==_SubType);} + +protected: + int Type; + int SubType; + int Width; + int Height; +}; + + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayer3d.cpp b/Utils/MkLevel/Layers/MkLevelLayer3d.cpp new file mode 100644 index 000000000..da7370c12 --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayer3d.cpp @@ -0,0 +1,267 @@ +/****************/ +/*** Layer 3d ***/ +/****************/ + +#include +#include + +#include "..\MkLevel.h" +#include "MkLevelLayer3d.h" + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Pre-Process *************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayer3d::PreProcess(CMkLevel *Core) +{ +int Width=InMap.GetWidth(); +int Height=InMap.GetHeight(); + + OutMap.SetSize(Width,Height); + + for (int Y=0; YAddTile3d(InElem); + } + } + } +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** 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; YGetTile(ThisElem); +// Build Sorted List + CList SortList; + CList ZPosList; + if (InTile.TriCount) + { + for (i=0; iThisFace.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 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 const &InList,vector &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; iInList[i].vx) XMin=InList[i].vx; + if (XMaxInList[i].vy) YMin=InList[i].vy; + if (YMaxOutList[i].vx) XMin=OutList[i].vx; + if (XMaxOutList[i].vy) YMin=OutList[i].vy; + if (YMax + +/*****************************************************************************/ +class CMkLevelLayer3d : public CMkLevelLayerTile +{ +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 const &In,vector &Out); + +// CFaceStore TriList; + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerActor.cpp b/Utils/MkLevel/Layers/MkLevelLayerActor.cpp new file mode 100644 index 000000000..a82da5999 --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerActor.cpp @@ -0,0 +1,95 @@ +/*******************/ +/*** Layer Actor ***/ +/*******************/ + +#include +#include + +#include "..\MkLevel.h" +#include "MkLevelLayerActor.h" + + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Pre-Process *************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerActor::PreProcess(CMkLevel *Core) +{ +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Process *****************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerActor::Process(CMkLevel *Core) +{ +int i,ListSize; +bool NotFound; + +// Extract Player Start +GString Player=Core->GetConfigStr("MISC","PlayerActor"); + NotFound=true; + ListSize=ThingList.size(); + for (i=0; iSetStart(ThisThing.XY[0].x,ThisThing.XY[0].y); + NotFound=false; + ThingList.erase(i); + } + } + if (NotFound) + { + GObject::Error(ERR_FATAL,"No Start Point defined"); + } + + ProcessList(); + printf("%i actors\n",ThingList.size()); +} + +/*****************************************************************************/ +/*****************************************************************************/ +/** Write ********************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +int CMkLevelLayerActor::Write(FILE *File,const char *LayerName,const char *MapName) +{ +int ThisPos=ftell(File); +sThingHdr Hdr; +int i,ListSize=ThingList.size(); + + Hdr.Count=ListSize; + fwrite(&Hdr,sizeof(sThingHdr),1,File); + + for (i=0; i + +/*****************************************************************************/ +class CMkLevelLayerActor : public CMkLevelLayerThing +{ +public: + CMkLevelLayerActor(sExpLayerHdr *LayerHdr) : CMkLevelLayerThing(LayerHdr){}; +const char *GetTypeName() {return("ACTOR");} + + void PreProcess(CMkLevel *Core); + void Process(CMkLevel *Core); + int Write(FILE *File,const char *LayerName,const char *MapName); + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerCollision.cpp b/Utils/MkLevel/Layers/MkLevelLayerCollision.cpp new file mode 100644 index 000000000..a2d5f76af --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerCollision.cpp @@ -0,0 +1,95 @@ +/***********************/ +/*** Layer Collision ***/ +/***********************/ + +#include +#include + +#include "MkLevelLayer.h" +#include "MkLevelLayerCollision.h" + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +CMkLevelLayerCollision::CMkLevelLayerCollision(sExpLayerHdr *LayerHdr) +{ + Type=LayerHdr->Type; + SubType=LayerHdr->SubType; + Width=LayerHdr->Width; + Height=LayerHdr->Height; + +sExpColTile *MapPtr=(sExpColTile*)((int)LayerHdr+sizeof(sExpLayerHdr)); + + Map.SetSize(Width,Height); + + for (int Y=0; Y(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); + + return(ThisPos); +} + +/*****************************************************************************/ diff --git a/Utils/MkLevel/Layers/MkLevelLayerCollision.h b/Utils/MkLevel/Layers/MkLevelLayerCollision.h new file mode 100644 index 000000000..9ead2c873 --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerCollision.h @@ -0,0 +1,27 @@ +/***********************/ +/*** Layer Collision ***/ +/***********************/ + +#ifndef __MKLEVEL_LAYER_COLLISION_HEADER__ +#define __MKLEVEL_LAYER_COLLISION_HEADER__ + +#include "MkLevelLayer.h" +#include + +/*****************************************************************************/ +class CMkLevelLayerCollision: public CMkLevelLayer +{ +public: + CMkLevelLayerCollision(sExpLayerHdr *LayerHdr); + +virtual void PreProcess(CMkLevel *Core); +virtual void Process(CMkLevel *Core); +virtual int Write(FILE *File,const char *LayerName,const char *MapName); + +protected: + + CList2d Map; +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerFX.cpp b/Utils/MkLevel/Layers/MkLevelLayerFX.cpp new file mode 100644 index 000000000..2726eae42 --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerFX.cpp @@ -0,0 +1,65 @@ +/****************/ +/*** Layer FX ***/ +/****************/ + +#include +#include + +#include "..\MkLevel.h" +#include "MkLevelLayerFX.h" + + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Pre-Process *************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerFX::PreProcess(CMkLevel *Core) +{ + //printf("Pre-Process FX Layer ()\n"); +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Process *****************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerFX::Process(CMkLevel *Core) +{ + ProcessList(); + printf("%i FX\n",ThingList.size()); +} + +/*****************************************************************************/ +/*****************************************************************************/ +/** Write ********************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +int CMkLevelLayerFX::Write(FILE *File,const char *LayerName,const char *MapName) +{ +int ThisPos=ftell(File); +sThingHdr Hdr; +int i,ListSize=ThingList.size(); + + Hdr.Count=ListSize; + fwrite(&Hdr,sizeof(sThingHdr),1,File); + + for (i=0; i + +/*****************************************************************************/ +class CMkLevelLayerFX : public CMkLevelLayerThing +{ +public: + CMkLevelLayerFX(sExpLayerHdr *LayerHdr) : CMkLevelLayerThing(LayerHdr){}; + const char *GetTypeName() {return("FX");} + + void PreProcess(CMkLevel *Core); + void Process(CMkLevel *Core); + int Write(FILE *File,const char *LayerName,const char *MapName); + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerItem.cpp b/Utils/MkLevel/Layers/MkLevelLayerItem.cpp new file mode 100644 index 000000000..4b705482e --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerItem.cpp @@ -0,0 +1,59 @@ +/******************/ +/*** Layer Item ***/ +/******************/ + +#include +#include + +//#include "MkLevel.h" +#include "MkLevelLayerItem.h" + + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Pre-Process *************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerItem::PreProcess(CMkLevel *Core) +{ +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Process *****************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerItem::Process(CMkLevel *Core) +{ + ProcessList(); +} + +/*****************************************************************************/ +/*****************************************************************************/ +/** Write ********************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +int CMkLevelLayerItem::Write(FILE *File,const char *LayerName,const char *MapName) +{ +int ThisPos=ftell(File); +sThingHdr Hdr; +int i,ListSize=ThingList.size(); + + Hdr.Count=ListSize; + fwrite(&Hdr,sizeof(sThingHdr),1,File); + + for (i=0; i + +/*****************************************************************************/ +class CMkLevelLayerItem : public CMkLevelLayerThing +{ +public: + CMkLevelLayerItem(sExpLayerHdr *LayerHdr) : CMkLevelLayerThing(LayerHdr){}; +const char *GetTypeName() {return("ITEM");} + + void PreProcess(CMkLevel *Core); + void Process(CMkLevel *Core); + int Write(FILE *File,const char *LayerName,const char *MapName); + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerPlatform.cpp b/Utils/MkLevel/Layers/MkLevelLayerPlatform.cpp new file mode 100644 index 000000000..e00794012 --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerPlatform.cpp @@ -0,0 +1,71 @@ +/**********************/ +/*** Layer Platform ***/ +/**********************/ + +#include +#include + +//#include "MkLevel.h" +#include "MkLevelLayerPlatform.h" + + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Pre-Process *************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerPlatform::PreProcess(CMkLevel *Core) +{ +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Process *****************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerPlatform::Process(CMkLevel *Core) +{ + ProcessList(); + printf("%i Platforms\n",ThingList.size()); +} + +/*****************************************************************************/ +/*****************************************************************************/ +/** Write ********************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +int CMkLevelLayerPlatform::Write(FILE *File,const char *LayerName,const char *MapName) +{ +int ThisPos=ftell(File); +sThingHdr Hdr; +int i,ListSize=ThingList.size(); + + Hdr.Count=ListSize; + fwrite(&Hdr,sizeof(sThingHdr),1,File); + + for (i=0; i + +/*****************************************************************************/ +class CMkLevelLayerPlatform : public CMkLevelLayerThing +{ +public: + CMkLevelLayerPlatform(sExpLayerHdr *LayerHdr) : CMkLevelLayerThing(LayerHdr){}; +const char *GetTypeName() {return("PLATFORM");} + + void PreProcess(CMkLevel *Core); + void Process(CMkLevel *Core); + int Write(FILE *File,const char *LayerName,const char *MapName); + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerShade.cpp b/Utils/MkLevel/Layers/MkLevelLayerShade.cpp new file mode 100644 index 000000000..c850e5314 --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerShade.cpp @@ -0,0 +1,162 @@ +/*******************/ +/*** Layer Shade ***/ +/*******************/ + +#include +#include + +#include "MkLevelLayer.h" +#include "MkLevelLayerShade.h" + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +CMkLevelLayerShade::CMkLevelLayerShade(sExpLayerHdr *LayerHdr) +{ +int *iPtr; +u8 *Ptr=(u8*)LayerHdr; +u8 *RGB; + + Type=LayerHdr->Type; + SubType=LayerHdr->SubType; + Width=LayerHdr->Width; + Height=LayerHdr->Height; + + iPtr=(int*)(Ptr+sizeof(sExpLayerHdr)); + + Count=*iPtr++; + List.resize(LAYER_SHADE_RGB_MAX); + for (int i=0; iGetConfigStr("MISC","BackGfxDir"); + + for (int i=0; i<2; i++) + { + if (!BackGfx[i].Empty()) + { + TexID[i]=AddBackGfx(Core,Path+BackGfx[i]+".Bmp"); + } + else + { + TexID[i]=-1; + } + } +} + +/*****************************************************************************/ +int CMkLevelLayerShade::AddBackGfx(CMkLevel *Core,const char *Filename) +{ +sBackGfxList NewGfx; +CTexGrab &TexGrab=Core->GetTexGrab(); + + NewGfx.Name=Filename; + NewGfx.TexID=-1; + +int Idx=BackGfxList.Add(NewGfx); + + if (BackGfxList[Idx].TexID==-1) + { + TexGrab.ZeroColZero(true); + BackGfxList[Idx].TexID=TexGrab.AddFile(BackGfxList[Idx].Name); + TexGrab.ZeroColZero(false); + } + + return(BackGfxList[Idx].TexID); + +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Process *****************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerShade::Process(CMkLevel *Core) +{ +CTexGrab &TexGrab=Core->GetTexGrab(); + + //printf("Process Shade Layer\n"); + for (int i=0; i<2; i++) + { + sLayerShadeGfx &ThisGfx=Data.BackGfx[i]; + if (TexID[i]==-1) + { + ThisGfx.TPage=0; + } + else + { + sTexOutInfo &ThisTex=TexGrab.GetTexInfo()[TexID[i]]; + ThisGfx.TPage=ThisTex.Tpage; + ThisGfx.Clut=ThisTex.Clut; + ThisGfx.U=ThisTex.u; + ThisGfx.V=ThisTex.v; + ThisGfx.W=ThisTex.w; + ThisGfx.H=ThisTex.h; + ThisGfx.TPage|=Trans[i]<<5; + ThisGfx.Flags=Flags[i]; + } + + } +} + +/*****************************************************************************/ +/*****************************************************************************/ +/** Write ********************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +int CMkLevelLayerShade::Write(FILE *File,const char *LayerName,const char *MapName) +{ +sLayerHdr Hdr; +int ThisPos=ftell(File); + + Hdr.Type=Type; + Hdr.SubType=SubType; + Hdr.Width=Width; + Hdr.Height=Height; + fwrite(&Hdr,sizeof(sLayerHdr),1,File); + + Data.Count=Count; + for (int i=0; i + +/*****************************************************************************/ +struct SMkLayerShadeRGB +{ + int Pos; + u8 RGB[3]; +}; + +/*****************************************************************************/ +struct sBackGfxList +{ + GString Name; + int TexID; + +bool operator ==(sBackGfxList const &v1) {return(Name==v1.Name);} +}; + +/*****************************************************************************/ +class CMkLevelLayerShade : public CMkLevelLayer +{ +public: + CMkLevelLayerShade(sExpLayerHdr *LayerHdr); + + void PreProcess(CMkLevel *Core); + void Process(CMkLevel *Core); + int Write(FILE *File,const char *LayerName,const char *MapName); + int AddBackGfx(CMkLevel *Core,const char *Filename); + +protected: + int Count; + vector List; + GString BackGfx[2]; + int Flags[2]; + int Trans[2]; + + CList BackGfxList; + int TexID[2]; + sLayerShadeHdr Data; +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerThing.cpp b/Utils/MkLevel/Layers/MkLevelLayerThing.cpp new file mode 100644 index 000000000..f6bcd5388 --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerThing.cpp @@ -0,0 +1,87 @@ +/*******************/ +/*** Layer Thing ***/ +/*******************/ + +#include +//#include + +#include "..\MkLevel.h" +#include "MkLevelLayer.h" +#include "MkLevelLayerThing.h" + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +CMkLevelLayerThing::CMkLevelLayerThing(sExpLayerHdr *LayerHdr) +{ +u8 *Ptr=(u8*)LayerHdr; + + Type=LayerHdr->Type; + SubType=LayerHdr->SubType; + Width=LayerHdr->Width; + Height=LayerHdr->Height; + +int *iPtr=(int*)(Ptr+sizeof(sExpLayerHdr)); + +int i,ListSize=*iPtr++; + ThingList.resize(ListSize); + Ptr=(u8*)iPtr; + for (i=0; i XY; + sLayerThingData Data; +}; + +/*****************************************************************************/ +class CMkLevelLayerThing : public CMkLevelLayer +{ +public: + CMkLevelLayerThing(sExpLayerHdr *LayerHdr); +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; + +protected: + u8 *LoadThing(sMkLevelLayerThing &ThisThing,u8 *Ptr); + void LoadThingNames(char *Ptr); + void ProcessList(); + + CList ThingList; + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerTile.cpp b/Utils/MkLevel/Layers/MkLevelLayerTile.cpp new file mode 100644 index 000000000..7028e207e --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerTile.cpp @@ -0,0 +1,112 @@ +/******************/ +/*** Layer Tile ***/ +/******************/ + +#include +#include + +#include "MkLevelLayer.h" +#include "MkLevelLayerTile.h" + + + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +CMkLevelLayerTile::CMkLevelLayerTile(sExpLayerHdr *LayerHdr) +{ + Type=LayerHdr->Type; + SubType=LayerHdr->SubType; + Width=LayerHdr->Width; + Height=LayerHdr->Height; + +sExpLayerTile *MapPtr=(sExpLayerTile *)((int)LayerHdr+sizeof(sExpLayerHdr)); + + InMap.SetSize(Width,Height); + + for (int Y=0; YTile; + ThisTile.Flags=MapPtr->Flags; + InMap.Set(X,Y,ThisTile); + MapPtr++; + } + } +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Pre-Process *************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerTile::PreProcess(CMkLevel *Core) +{ +int Width=InMap.GetWidth(); +int Height=InMap.GetHeight(); + + OutMap.SetSize(Width,Height); + + for (int Y=0; YAddTile2d(InElem); + } + } + } +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Process *****************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerTile::Process(CMkLevel *Core) +{ +} + +/*****************************************************************************/ +/*****************************************************************************/ +/** Write ********************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +int CMkLevelLayerTile::Write(FILE *File,const char *LayerName,const char *MapName) +{ +sLayerHdr Hdr; +int ThisPos=ftell(File); +int Width=OutMap.GetWidth(); +int Height=OutMap.GetHeight(); + + Hdr.Type=Type; + Hdr.SubType=SubType; + Hdr.Width=Width; + Hdr.Height=Height; + fwrite(&Hdr,sizeof(sLayerHdr),1,File); + + for (int Y=0; Y + +struct sMkLevelElem +{ + u16 Elem; + int TexID; +}; + +/*****************************************************************************/ +class CMkLevelLayerTile : public CMkLevelLayer +{ +public: + CMkLevelLayerTile(sExpLayerHdr *LayerHdr); + +virtual void PreProcess(CMkLevel *Core); +virtual void Process(CMkLevel *Core); +virtual int Write(FILE *File,const char *LayerName,const char *MapName); + +protected: + CList2d InMap; + CList2d OutMap; + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Layers/MkLevelLayerTrigger.cpp b/Utils/MkLevel/Layers/MkLevelLayerTrigger.cpp new file mode 100644 index 000000000..da84ca726 --- /dev/null +++ b/Utils/MkLevel/Layers/MkLevelLayerTrigger.cpp @@ -0,0 +1,63 @@ +/*********************/ +/*** Layer Trigger ***/ +/*********************/ + +#include +#include + +//#include "MkLevel.h" +#include "MkLevelLayerTrigger.h" + + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Pre-Process *************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerTrigger::PreProcess(CMkLevel *Core) +{ +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*** Process *****************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CMkLevelLayerTrigger::Process(CMkLevel *Core) +{ + ProcessList(); + printf("%i Trigger\n",ThingList.size()); + +} + +/*****************************************************************************/ +/*****************************************************************************/ +/** Write ********************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +int CMkLevelLayerTrigger::Write(FILE *File,const char *LayerName,const char *MapName) +{ +int ThisPos=ftell(File); +sThingHdr Hdr; +int i,ListSize=ThingList.size(); + + Hdr.Count=ListSize; + fwrite(&Hdr,sizeof(sThingHdr),1,File); + + for (i=0; i + +/*****************************************************************************/ +class CMkLevelLayerTrigger : public CMkLevelLayerThing +{ +public: + CMkLevelLayerTrigger(sExpLayerHdr *LayerHdr) : CMkLevelLayerThing(LayerHdr){}; +const char *GetTypeName() {return("TRIGGER");} + + void PreProcess(CMkLevel *Core); + void Process(CMkLevel *Core); + int Write(FILE *File,const char *LayerName,const char *MapName); + +}; + +/*****************************************************************************/ +#endif diff --git a/Utils/MkLevel/Main.cpp b/Utils/MkLevel/Main.cpp new file mode 100644 index 000000000..c7c86f900 --- /dev/null +++ b/Utils/MkLevel/Main.cpp @@ -0,0 +1,107 @@ +/*******************************/ +/*** SpongeBob Level Creator ***/ +/*******************************/ + +#include "stdio.h" +#include +#include +#include +#include + +#include "MkLevel.h" + +//*************************************************************************** +CMkLevel Level; +int TPBase=-1,TPW=-1,TPH=-1; + +//*************************************************************************** +char * CycleCommands(char *String,int Num) +{ +char Text[256],*TextPtr; +int Count; + + if (String[0]=='-' || String[0]=='/') + { + GString TpStr; + TpStr= String; + TpStr.Upper(); + switch (String[1]) + {// Switches + case 'o': + OutStr = CheckFileString(String); + break; + case 'd': + DebugOn =true; + break; + case 's': + TpStr= CheckFileString(String); + Scale=atof(TpStr); + break; + case 't': + TpStr= CheckFileString(String); + TextPtr=Text; + strcpy(TextPtr,TpStr); + Count=ZeroAndCountCommas(TextPtr); + if (Count!=2) + GObject::Error(ERR_FATAL,"Problem with option %s\n",String); + TPBase=atol(TextPtr); + TextPtr+=strlen(TextPtr)+1; + TPW=atol(TextPtr); + TextPtr+=strlen(TextPtr)+1; + TPH=atol(TextPtr); + break; + case 'q': + StripLength=4; + break; + default: + GObject::Error(ERR_FATAL,"Unknown switch %s",String); + break; + } + } + else + { + GString UpperName(String); + UpperName.Upper(); + MyFiles.AddFile(UpperName); + } + + return(String); +} + +//*************************************************************************** + +void Usage(char *ErrStr) +{ + printf("\nMkLevel: by Dave\n"); + printf("Usage: MkLevel [ .. ] [ switches.. ]\n"); + printf("Switches:\n"); + printf(" -o:[FILE] Set output File (AND Dir)\n"); + printf(" -s:nn Set Scaling value\n"); + printf(" -t:p,w,h Set TPage No,Width,Height\n"); +// printf(" -c: Set Chapter Name\n"); +// printf(" -l: Set Level Name\n"); + printf(" -d: Enable Debug output\n"); +// printf(" -q: Enable Quadding\n"); + GObject::Error(ERR_FATAL,ErrStr); +} + +//*************************************************************************** + +int main(int argc, char *argv[]) +{ + CommandLine(argc,argv,CycleCommands); + +std::vector const &Files = MyFiles.GetFileInfoVector(); + + if (Files.size()==0) Usage("No Levels specified\n"); + if (Files.size()>1) Usage("Too many Levels specified\n"); + + Level.Init(Files[0],OutStr,TPBase,TPW,TPH); + Level.Load(); + Level.Process(); + Level.Write(); + return 0; +} + + + diff --git a/Utils/MkLevel/MkLevel.cpp b/Utils/MkLevel/MkLevel.cpp new file mode 100644 index 000000000..4eae5aa67 --- /dev/null +++ b/Utils/MkLevel/MkLevel.cpp @@ -0,0 +1,801 @@ +/*********************/ +/*** MkLevel Class ***/ +/*********************/ + +#include "stdio.h" +#include +#include +#include +#include +#include +#include + +#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" + +//*************************************************************************** +GString ConfigFilename="MkLevel"; +sExpLayerTile BlankTile={-1,-1}; + +//*************************************************************************** +CMkLevel::CMkLevel() +{ + memset(&LvlHdr,0,sizeof(sLvlHdr)); + Tile2dList.Add(BlankTile); +} + +//*************************************************************************** +CMkLevel::~CMkLevel() +{ +} + +//*************************************************************************** +void CMkLevel::Init(const char *Filename,const char *OutDir,int TPBase,int TPW,int TPH) +{ +// Setup filenames and paths +GFName Path=Filename; + + InFilename=Filename; + LevelName=Path.File(); + Path.File(""); + Path.Ext(""); + InPath=Path.FullName(); + OutPath=OutDir; OutPath.Append('\\'); + OutName=OutPath+LevelName; + +// Load ini file +#ifdef _DEBUG + ConfigFilename="\\spongebob\\tools\\data\\bin\\mklevel.ini"; +#endif + Config.LoadAndImport(ConfigFilename); + +// 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(true); + TexGrab.AllowRotate(false); + //!!! TexGrab.ShrinkToFit(true); + TexGrab.ShrinkToFit(false); + +// Setup TriList + OutTriList.SetTexGrab(TexGrab); + +// 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; + FlatFace[0].uvs[0].u=1; FlatFace[0].uvs[0].v=1; + FlatFace[0].uvs[1].u=0; FlatFace[0].uvs[1].v=0; + FlatFace[0].uvs[2].u=1; FlatFace[0].uvs[2].v=0; + + 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; + FlatFace[1].uvs[0].u=0; FlatFace[1].uvs[0].v=0; + FlatFace[1].uvs[1].u=1; FlatFace[1].uvs[1].v=1; + FlatFace[1].uvs[2].u=0; FlatFace[1].uvs[2].v=1; + +} + +//*************************************************************************** +//*** 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 &List,char *TexPtr,int Count) +{ +char FullName[256]; +GString FilePath; + + for (int i=0; iTileW; + 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); + +// Load Tiles +u8 *TilePtr=(u8*) &ByteHdr[FileHdr->TileOfs]; + + InTileList.resize(FileHdr->TileCount); + for (i=0; iTileCount; i++) + { + sExpTile *ThisTilePtr=(sExpTile*)TilePtr; + sExpTile &InTile=InTileList[i]; + + InTile=*ThisTilePtr; + InTile.RGB=(u8*)malloc(RGBSize); + memcpy(InTile.RGB,TilePtr+sizeof(sExpTile),RGBSize); + TilePtr+=RGBSize+sizeof(sExpTile); + } + +// Load Tris +sExpTri *TriPtr=(sExpTri*) &ByteHdr[FileHdr->TriOfs]; + InTriList.resize(FileHdr->TriCount); + for (i=0; iTriCount; i++) + { + InTriList[i]=TriPtr[i]; + } + +// Load 2d bitmaps + ListSize=InSetNameList.size(); + BmpList.resize(ListSize); + for (i=0; iLayerCount; 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; + default: + GObject::Error(ERR_FATAL,"Unknown Layer Type\n"); + } + } +} + +//*************************************************************************** +//*** Process *************************************************************** +//*************************************************************************** +void CMkLevel::Process() +{ + printf("PreProcess Layers\n"); + PreProcessLayers(); + printf("Process Tilebank\n"); + ProcessTileBanks(); + printf("Process Layers\n"); + ProcessLayers(); + OutTriList.Process(); +} + +//*************************************************************************** +void CMkLevel::PreProcessLayers() +{ +int LayerCount=LayerList.size(); + + for (int i=0; iPreProcess(this); + } +} + +//*************************************************************************** +void CMkLevel::ProcessLayers() +{ +int LayerCount=LayerList.size(); + + for (int i=0; iProcess(this); + } +} + +//*************************************************************************** +void CMkLevel::ProcessTileBanks() +{ + PreProcessTileBank2d(); + PreProcessTileBank3d(); + TexGrab.Process(); + ProcessTileBank2d(); + ProcessTileBank3d(); +} + +//*************************************************************************** +void CMkLevel::PreProcessTileBank2d() +{ +int i,ListSize=Tile2dList.size(); + + Tile2dList[0].Tile=-1; +// Extract Tex data from list + for (i=1; i &TexInfo=TexGrab.GetTexInfo(); + + OutTile2dList.resize(ListSize); + for (i=1; iIsType(Type,SubType)) return(LayerList[i]); + } + return(0); +} + +//*************************************************************************** +int CMkLevel::Create3dTile(sExpLayerTile &InTile) +{ +sExpTile &SrcTile=InTileList[InTile.Tile]; +CFace F; +int i,ListSize; +CList SortList; +CList ZPosList; + + if (SrcTile.TriCount) + { + for (i=0; iThisTri.vtx[1].z) ThisZPos=ThisTri.vtx[1].z; + if (ThisZPos>ThisTri.vtx[2].z) ThisZPos=ThisTri.vtx[2].z; + + ListSize=SortList.size(); + for (ListPos=0; ListPos=0 && InTex.SetBmpW) + { + printf("AARGH!!! %s(%i) wants X=%i,tile is only %i Wide\n",Name,InTex.Set,InTex.XOfs*16,BmpW); + InTex.XOfs=0; + } + if (InTex.YOfs*16>BmpH) + { + printf("AARGH!!! %s(%i) wants Y=%i,tile is only %i High\n",Name,InTex.Set,InTex.YOfs*16,BmpH); + InTex.YOfs=0; + } + + MakeTexName(InTex,TexName); + + ThisRect.X=InTex.XOfs*16; + ThisRect.Y=InTex.YOfs*16; + ThisRect.W=16; + ThisRect.H=16; + + ThisFrame.Grab(InFrame,ThisRect); + + if (InTex.Flags& PC_TILE_FLAG_MIRROR_X) ThisFrame.FlipX(); + if (InTex.Flags & PC_TILE_FLAG_MIRROR_Y) ThisFrame.FlipY(); + + InTex.TexID=TexGrab.AddMemFrame(TexName,ThisFrame); + +#ifdef _DEBUG + if (0) + { + if (!ThisFrame.IsBlank()) + { + char DbgName[256]; + sprintf(DbgName,"/x/%s.lbm",TexName); + ThisFrame.SaveLbm(DbgName); + } + } +#endif + return(InTex.TexID); +} + +//*************************************************************************** +void CMkLevel::MakeTexName(sMkLevelTex &InTex,GString &OutStr) +{ +char NewName[256]; +GString Name=GFName(InSetNameList[InTex.Set]).File(); + + sprintf(NewName,"%s_%02d_%02d_%01d_",Name,InTex.XOfs,InTex.YOfs,InTex.Flags&PC_TILE_FLAG_MIRROR_XY); + OutStr=NewName; +} + +//*************************************************************************** +int CMkLevel::FindRGBMatch(sMkLevelTex &ThisTex) +{ +int i,ListSize=Tex2dList.size(); +int Size=TileW*TileH; +u8 *RGBPtr=ThisTex.RGB; + +// Create Checksum for this tile + ThisTex.RChk=0; + ThisTex.GChk=0; + ThisTex.BChk=0; + for (i=0; i &TriList=OutTriList.GetOutTriList(); +vector const &VtxList=OutTriList.GetVtxList(); +int ThisPos=ftell(File); +int i,ListSize=TriList.size(); +int MaxOT=0; + for (i=0;i63) OtOfs=63; +// Write It + fwrite(&T,1,sizeof(sTri),File); + } + printf("MAXOT = %i\n",MaxOT); + + return(ThisPos); + +} + +//*************************************************************************** +//*** Write ***************************************************************** +//*************************************************************************** +void CMkLevel::WriteLevel() +{ +GString OutFilename=OutName+".Lvl"; + + File=fopen(OutFilename,"wb"); + + fwrite(&LvlHdr,1,sizeof(sLvlHdr),File); + + WriteLayers(); + +// rewrite header + fseek(File,0,SEEK_SET); + fwrite(&LvlHdr,1,sizeof(sLvlHdr),File); + + fclose(File); +} + +//*************************************************************************** +void CMkLevel::WriteLayers() +{ +// Back (Shade) + LvlHdr.BackLayer=WriteLayer(LAYER_TYPE_SHADE,LAYER_SUBTYPE_BACK,0);//"Shade"); +// Mid + LvlHdr.MidLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_MID,"Mid"); +// Action + LvlHdr.ActionLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION,"Action"); +// Fore +// LvlHdr.ForeLayer=WriteLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_FORE,"Fore"); +// Collision + LvlHdr.CollisionLayer=WriteLayer(LAYER_TYPE_COLLISION,LAYER_SUBTYPE_NONE,"Collision"); + +// Things + LvlHdr.ActorList=WriteThings(LAYER_TYPE_ACTOR,"Actor List"); + LvlHdr.ItemList=WriteThings(LAYER_TYPE_ITEM,"Item List"); + LvlHdr.PlatformList=WriteThings(LAYER_TYPE_PLATFORM,"Platform List"); + LvlHdr.TriggerList=WriteThings(LAYER_TYPE_TRIGGER,"FX List"); + LvlHdr.FXList=WriteThings(LAYER_TYPE_FX,"FX List"); +} + +//*************************************************************************** +int CMkLevel::WriteLayer(int Type,int SubType,const char *LayerName) +{ +CMkLevelLayer *ThisLayer=FindLayer(Type,SubType); +int Ofs; + + if (!ThisLayer) + { + if (LayerName) GObject::Error(ERR_WARNING,"No %s Layer Found in %s!!\n",LayerName,LevelName); + return(0); + } + Ofs=ThisLayer->Write(File,LayerName,LevelName); + + PadFile(File); + return(Ofs); +} + +//*************************************************************************** +int CMkLevel::WriteThings(int Type,const char *LayerName) +{ +CMkLevelLayer *ThisLayer=FindLayer(Type,LAYER_SUBTYPE_NONE); +int Ofs; + + if (!ThisLayer) + { + GFName Name=InFilename; + if (LayerName) GObject::Error(ERR_WARNING,"No %s Layer Found in %s!!\n",LayerName,Name.File()); + return(0); + } + Ofs=ThisLayer->Write(File,LayerName,LevelName); + PadFile(File); + return(Ofs); +} diff --git a/Utils/MkLevel/MkLevel.dsp b/Utils/MkLevel/MkLevel.dsp new file mode 100644 index 000000000..4774620af --- /dev/null +++ b/Utils/MkLevel/MkLevel.dsp @@ -0,0 +1,190 @@ +# Microsoft Developer Studio Project File - Name="MkLevel" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=MkLevel - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "MkLevel.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "MkLevel.mak" CFG="MkLevel - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "MkLevel - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "MkLevel - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName ""$/Utils/MkLevel", JTGAAAAA" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "MkLevel - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /G6 /MD /W3 /GX /O2 /I "..\libs\glib" /I "..\libs\maths" /I "..\libs\davelib" /I "..\libs\ginlib" /I "..\libs\texgrab" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib glib.lib ginlib.lib texgrab.lib maths.lib /nologo /subsystem:console /machine:I386 /out:"..\..\tools\data\bin\MkLevel.exe" /libpath:"..\libs\psxlib\release" /libpath:"..\libs\ginlib\release" /libpath:"..\libs\glib\release" /libpath:"..\libs\davelib\release" /libpath:"..\libs\texgrab\release" /libpath:"..\libs\maths\release" + +!ELSEIF "$(CFG)" == "MkLevel - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /Gi /GX /ZI /Od /I "..\libs\glib" /I "..\libs\maths" /I "..\libs\davelib" /I "..\libs\ginlib" /I "..\libs\psxlib" /I "..\libs\texgrab" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fr /YX /FD /GZ /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib glib.lib ginlib.lib texgrab.lib maths.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\libs\ginlib\debug" /libpath:"..\libs\glib\debug" /libpath:"..\libs\davelib\debug" /libpath:"..\libs\texgrab\debug" /libpath:"..\libs\maths\debug" + +!ENDIF + +# Begin Target + +# Name "MkLevel - Win32 Release" +# Name "MkLevel - Win32 Debug" +# Begin Group "Layers" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\Layers\MkLevelLayer.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayer3d.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayer3d.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerActor.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerActor.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerCollision.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerCollision.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerFX.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerFX.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerItem.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerItem.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerPlatform.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerPlatform.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerShade.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerShade.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerThing.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerThing.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerTile.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerTile.h +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerTrigger.cpp +# End Source File +# Begin Source File + +SOURCE=.\Layers\MkLevelLayerTrigger.h +# End Source File +# End Group +# Begin Source File + +SOURCE=.\Main.cpp +# End Source File +# Begin Source File + +SOURCE=.\MkLevel.cpp +# End Source File +# Begin Source File + +SOURCE=.\MkLevel.h +# End Source File +# Begin Source File + +SOURCE=..\..\tools\Data\bin\MkLevel.ini +# End Source File +# End Target +# End Project diff --git a/Utils/MkLevel/MkLevel.h b/Utils/MkLevel/MkLevel.h new file mode 100644 index 000000000..23848feb4 --- /dev/null +++ b/Utils/MkLevel/MkLevel.h @@ -0,0 +1,128 @@ +/*************************/ +/*** Base Level Holder ***/ +/*************************/ + +#ifndef __MKLEVEL_HEADER__ +#define __MKLEVEL_HEADER__ + +#include +#include +#include +#include "IniClass.h" + +// Map Editor header files +#include "..\mapedit\LayerDef.h" +#include "..\mapedit\ExportHdr.h" + +using namespace std; + +//*************************************************************************** +struct sMkLevelTex +{ + int Set; + int XOfs,YOfs; + u8 *RGB; + int Flags; + int RChk,GChk,BChk; + int TexID; + +bool operator ==(sMkLevelTex const &v1) + { + if (Set!=v1.Set) return(false); + if (XOfs!=v1.XOfs) return(false); + if (YOfs!=v1.YOfs) return(false); + if (Flags!=v1.Flags) return(false); + return(true); + } +}; + +//*************************************************************************** +class CMkLevelLayer; +class CMkLevel +{ +public: + CMkLevel(); + ~CMkLevel(); + + void Init(const char *InFilename,const char *OutPath,int TPBase,int TPW,int TPH); + + void Load(); + + void Process(); + int AddTile3d(sExpLayerTile &Tile) {return(Tile3dList.Add(Tile));} + int AddTile2d(sExpLayerTile &Tile) {return(Tile2dList.Add(Tile));} + + void Write(); + + int Create2dTex(sExpLayerTile &ThisTile); + int Create3dTile(sExpLayerTile &ThisTile); + int FindRGBMatch(sMkLevelTex &ThisTex); + bool IsRGBSame(const sMkLevelTex &Tile0,const sMkLevelTex &Tile1); + void MakeTexName(sMkLevelTex &InTex,GString &OutStr); + int BuildTileTex(sMkLevelTex &InTex); + + char *GetConfigStr(const char *Grp,const char *Key) {return(Config.GetStr(Grp,Key));} + CTexGrab &GetTexGrab() {return(TexGrab);} + + void SetStart(int X,int Y) {LvlHdr.PlayerStartX=X; LvlHdr.PlayerStartY=Y;} +protected: + CMkLevelLayer *FindLayer(int Type,int SubType); + void LoadStrList(CList &List,char *TexPtr,int Count); + + void LoadTiles(sExpFileHdr *FileHdr); + void LoadLayers(sExpFileHdr *FileHdr); + void LoadLayer(sExpLayerHdr *LayerHdr); + + void PreProcessLayers(); + void ProcessTileBanks(); + void PreProcessTileBank2d(); + void ProcessTileBank2d(); + void PreProcessTileBank3d(); + void ProcessTileBank3d(); + void ProcessLayers(); + void SetUpTileUV(sTile2d &Out, sTexOutInfo &Info); + + void WriteLevel(); + void WriteLayers(); + int WriteLayer(int Type,int SubType,const char *LayerName); + int WriteThings(int Type,const char *LayerName); + int WriteTriList(); + int WriteQuadList(); + void WriteTileBank(); + + void BuildTiles(); + + FILE *File; + GString InFilename,InPath,LevelName; + GString OutPath,OutName; + + int TileW,TileH; + CIni Config; + + CList InTriList; + CList InTileList; + CList InSetNameList; + CList InTexNameList; + CList UsedSetNameList; + CList UsedTexNameList; + + CFaceStore OutTriList; + CList OutTile2dList; + CList OutTile3dList; + + CList Tile2dList; + CList Tile3dList; + CList Tex2dList; + CTexGrab TexGrab; + CList BmpList; + + vector LayerList; + + sLvlHdr LvlHdr; + sTileBankHdr TileBankHdr; + CFace FlatFace[2]; + +}; + +//*************************************************************************** +#endif