This commit is contained in:
Daveo 2001-04-17 16:42:07 +00:00
parent c582c425f8
commit 3149023193
25 changed files with 2648 additions and 0 deletions

View file

@ -0,0 +1,35 @@
/******************/
/*** Layer Core ***/
/******************/
#ifndef __MKLEVEL_LAYER_HEADER__
#define __MKLEVEL_LAYER_HEADER__
#include <Vector>
#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

View file

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

View file

@ -0,0 +1,28 @@
/****************/
/*** Layer 3d ***/
/****************/
#ifndef __MKLEVEL_LAYER_3D__HEADER__
#define __MKLEVEL_LAYER_3D__HEADER__
#include "MkLevelLayerTile.h"
#include <List2d.h>
/*****************************************************************************/
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<sVtx> const &In,vector<sVtx> &Out);
// CFaceStore TriList;
};
/*****************************************************************************/
#endif

View file

@ -0,0 +1,95 @@
/*******************/
/*** Layer Actor ***/
/*******************/
#include <Davelib.h>
#include <List2d.h>
#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; i<ListSize && NotFound; i++)
{
sMkLevelLayerThing &ThisThing=ThingList[i];
if (ThisThing.Name==Player)
{
Core->SetStart(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<ListSize; i++)
{
sMkLevelLayerThing &ThisThing=ThingList[i];
int p,PointCount=ThisThing.XY.size();
sThingActor OutThing;
OutThing.Type=ThisThing.Type;
OutThing.Health=ThisThing.Data.Health;
OutThing.AttackStrength=ThisThing.Data.AttackStrength;
OutThing.Speed=ThisThing.Data.Speed;
OutThing.TurnRate=ThisThing.Data.TurnRate;
OutThing.Flags=ThisThing.Data.CollisionFlag;
OutThing.PointCount=PointCount;
fwrite(&OutThing,sizeof(sThingActor),1,File);
for (p=0;p<PointCount;p++)
{
sThingPoint Pnt;
Pnt.X=ThisThing.XY[p].x;
Pnt.Y=ThisThing.XY[p].y;
fwrite(&Pnt,sizeof(sThingPoint),1,File);
}
}
return(ThisPos);
}
/*****************************************************************************/

View file

@ -0,0 +1,25 @@
/*******************/
/*** Layer Actor ***/
/*******************/
#ifndef __MKLEVEL_LAYER_ACTOR_HEADER__
#define __MKLEVEL_LAYER_ACTOR_HEADER__
#include "MkLevelLayerThing.h"
#include <List2d.h>
/*****************************************************************************/
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

View file

@ -0,0 +1,95 @@
/***********************/
/*** Layer Collision ***/
/***********************/
#include <DaveLib.h>
#include <List2d.h>
#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<Height; Y++)
{
for (int X=0; X<Width; X++)
{
Map.Set(X,Y,*MapPtr++);
}
}
}
/*****************************************************************************/
/*****************************************************************************/
/*** Pre-Process *************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CMkLevelLayerCollision::PreProcess(CMkLevel *Core)
{
//printf("PreProcess Collision Layer\n");
}
/*****************************************************************************/
/*****************************************************************************/
/*** Process *****************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CMkLevelLayerCollision::Process(CMkLevel *Core)
{
//printf("Process Collision Layer\n");
}
/*****************************************************************************/
/*****************************************************************************/
/** Write ********************************************************************/
/*****************************************************************************/
/*****************************************************************************/
int CMkLevelLayerCollision::Write(FILE *File,const char *LayerName,const char *MapName)
{
sLayerHdr Hdr;
int ThisPos=ftell(File);
int Width=Map.GetWidth();
int Height=Map.GetHeight();
Hdr.Type=Type;
Hdr.SubType=SubType;
Hdr.Width=Width;
Hdr.Height=Height;
fwrite(&Hdr,sizeof(sLayerHdr),1,File);
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sExpColTile &ThisElem=Map.Get(X,Y);
u8 OutElem;
OutElem=ThisElem.Flags<<COLLISION_TYPE_FLAG_SHIFT;
OutElem|=ThisElem.Tile;
if (ThisElem.Tile>(u16)COLLISION_MASK)
{
printf("COLLISION OVERFLOW %s: %i,%i=(%i,%i)!!\n",MapName,X,Y,ThisElem.Tile,ThisElem.Flags);
}
fwrite(&OutElem,sizeof(u8),1,File);
}
}
PadFile(File);
return(ThisPos);
}
/*****************************************************************************/

View file

@ -0,0 +1,27 @@
/***********************/
/*** Layer Collision ***/
/***********************/
#ifndef __MKLEVEL_LAYER_COLLISION_HEADER__
#define __MKLEVEL_LAYER_COLLISION_HEADER__
#include "MkLevelLayer.h"
#include <List2d.h>
/*****************************************************************************/
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<sExpColTile> Map;
};
/*****************************************************************************/
#endif

View file

@ -0,0 +1,65 @@
/****************/
/*** Layer FX ***/
/****************/
#include <Davelib.h>
#include <List2d.h>
#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<ListSize; i++)
{
sMkLevelLayerThing &ThisThing=ThingList[i];
sThingFX OutThing;
OutThing.Type=ThisThing.Type;
OutThing.Speed=ThisThing.Data.Speed;
OutThing.Pos.X=ThisThing.XY[0].x;
OutThing.Pos.Y=ThisThing.XY[0].y;
OutThing.Size.X=ThisThing.Data.Width;
OutThing.Size.Y=ThisThing.Data.Height;
fwrite(&OutThing,sizeof(sThingFX),1,File);
}
return(ThisPos);
}
/*****************************************************************************/

View file

@ -0,0 +1,25 @@
/****************/
/*** Layer FX ***/
/***************/
#ifndef __MKLEVEL_LAYER_FX_HEADER__
#define __MKLEVEL_LAYER_FX_HEADER__
#include "MkLevelLayerThing.h"
#include <List2d.h>
/*****************************************************************************/
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

View file

@ -0,0 +1,59 @@
/******************/
/*** Layer Item ***/
/******************/
#include <Davelib.h>
#include <List2d.h>
//#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<ListSize; i++)
{
sMkLevelLayerThing &ThisThing=ThingList[i];
sThingItem OutThing;
OutThing.Type=ThisThing.Type;
OutThing.Pos.X=ThisThing.XY[0].x;
OutThing.Pos.Y=ThisThing.XY[0].y;
fwrite(&OutThing,sizeof(sThingItem),1,File);
}
return(ThisPos);
}
/*****************************************************************************/

View file

@ -0,0 +1,25 @@
/******************/
/*** Layer Item ***/
/******************/
#ifndef __MKLEVEL_LAYER_ITEM_HEADER__
#define __MKLEVEL_LAYER_ITEM_HEADER__
#include "MkLevelLayerThing.h"
#include <List2d.h>
/*****************************************************************************/
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

View file

@ -0,0 +1,71 @@
/**********************/
/*** Layer Platform ***/
/**********************/
#include <Davelib.h>
#include <List2d.h>
//#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<ListSize; i++)
{
sMkLevelLayerThing &ThisThing=ThingList[i];
int p,PointCount=ThisThing.XY.size();
sThingPlatform OutThing;
OutThing.Type=ThisThing.Type;
OutThing.Speed=ThisThing.Data.Speed;
OutThing.TurnRate=ThisThing.Data.TurnRate;
OutThing.Flags=ThisThing.Data.CollisionFlag;
OutThing.PointCount=PointCount;
fwrite(&OutThing,sizeof(sThingPlatform),1,File);
for (p=0;p<PointCount;p++)
{
sThingPoint Pnt;
Pnt.X=ThisThing.XY[p].x;
Pnt.Y=ThisThing.XY[p].y;
fwrite(&Pnt,sizeof(sThingPoint),1,File);
}
}
return(ThisPos);
}
/*****************************************************************************/

View file

@ -0,0 +1,25 @@
/**********************/
/*** Layer Platform ***/
/**********************/
#ifndef __MKLEVEL_LAYER_PLATFORM_HEADER__
#define __MKLEVEL_LAYER_PLATFORM_HEADER__
#include "MkLevelLayerThing.h"
#include <List2d.h>
/*****************************************************************************/
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

View file

@ -0,0 +1,162 @@
/*******************/
/*** Layer Shade ***/
/*******************/
#include <DaveLib.h>
#include <List2d.h>
#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; i<LAYER_SHADE_RGB_MAX; i++)
{
List[i].Pos=*iPtr++;
RGB=(u8*)(iPtr);
List[i].RGB[0]=RGB[0];
List[i].RGB[1]=RGB[1];
List[i].RGB[2]=RGB[2];
iPtr+=4/sizeof(int);
}
Trans[0]=*iPtr++;
Flags[0]=*iPtr++;
Trans[1]=*iPtr++;
Flags[1]=*iPtr++;
// Load back gfx
char *c=(char*)iPtr;
BackGfx[0]=c;
c+=strlen(c)+1;
BackGfx[1]=c;
}
/*****************************************************************************/
/*****************************************************************************/
/*** Pre-Process *************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// Build unique tiles, including pre-genned flips, and replace tile idx with new one
void CMkLevelLayerShade::PreProcess(CMkLevel *Core)
{
GString Path=Core->GetConfigStr("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<Count; i++)
{
Data.Data[i].Ofs=List[i].Pos;
Data.Data[i].RGB[0]=List[i].RGB[0];
Data.Data[i].RGB[1]=List[i].RGB[1];
Data.Data[i].RGB[2]=List[i].RGB[2];
}
fwrite(&Data,sizeof(sLayerShadeHdr),1,File);
PadFile(File);
return(ThisPos);
}
/*****************************************************************************/

View file

@ -0,0 +1,51 @@
/*******************/
/*** Layer Shade ***/
/*******************/
#ifndef __MKLEVEL_LAYER_SHADE_HEADER__
#define __MKLEVEL_LAYER_SHADE_HEADER__
#include "MkLevelLayer.h"
#include <List2d.h>
/*****************************************************************************/
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<SMkLayerShadeRGB> List;
GString BackGfx[2];
int Flags[2];
int Trans[2];
CList<sBackGfxList> BackGfxList;
int TexID[2];
sLayerShadeHdr Data;
};
/*****************************************************************************/
#endif

View file

@ -0,0 +1,87 @@
/*******************/
/*** Layer Thing ***/
/*******************/
#include <DaveLib.h>
//#include <List2d.h>
#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<ListSize; i++)
{
Ptr=LoadThing(ThingList[i],Ptr);
}
LoadThingNames((char*)Ptr);
}
/*****************************************************************************/
u8 *CMkLevelLayerThing::LoadThing(sMkLevelLayerThing &ThisThing,u8 *Ptr)
{
int i,ListSize;
sLayerThingData *DPtr=(sLayerThingData*)Ptr;
ThisThing.Data=*DPtr++;
int *iPtr=(int*)DPtr;
ListSize=ThisThing.Data.WaypointCount;
ThisThing.XY.resize(ListSize);
for (i=0; i<ListSize; i++)
{
ThisThing.XY[i].x=*iPtr++;
ThisThing.XY[i].y=*iPtr++;
}
return((u8*)iPtr);
}
/*****************************************************************************/
void CMkLevelLayerThing::LoadThingNames(char *Ptr)
{
int i,ListSize=ThingList.size();
for (i=0; i<ListSize; i++)
{
sMkLevelLayerThing &ThisThing=ThingList[i];
ThisThing.Name=Ptr;
Ptr+=strlen(Ptr)+1;
}
}
/*****************************************************************************/
void CMkLevelLayerThing::ProcessList()
{
/*
int i,ListSize=ThingList.size();
for (i=0; i<ListSize; i++)
{
sMkLevelLayerThing &ThisThing=ThingList[i];
bool Found=CMkLevel::Config.GetInt(GetTypeName(),ThisThing.Name,ThisThing.Type);
if (!Found)
GObject::Error(ERR_FATAL,"%s not found in list\n",ThisThing.Name);
}
*/
}

View file

@ -0,0 +1,46 @@
/*******************/
/*** Layer Thing ***/
/*******************/
#ifndef __MKLEVEL_LAYER_THING_HEADER__
#define __MKLEVEL_LAYER_THING_HEADER__
#include "MkLevelLayer.h"
struct sPoint
{
int x;
int y;
inline operator=(sPoint const &Src) {x=Src.x;y=Src.y;}
};
struct sMkLevelLayerThing
{
GString Name;
int Type;
vector<sPoint> 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<sMkLevelLayerThing> ThingList;
};
/*****************************************************************************/
#endif

View file

@ -0,0 +1,112 @@
/******************/
/*** Layer Tile ***/
/******************/
#include <DaveLib.h>
#include <List2d.h>
#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; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sExpLayerTile ThisTile;
ThisTile.Tile=MapPtr->Tile;
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; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sExpLayerTile &InElem=InMap.Get(X,Y);
sMkLevelElem &OutElem=OutMap.Get(X,Y);
OutElem.Elem=0;
if (InElem.Tile)
{ // Dont process blanks
OutElem.Elem=Core->AddTile2d(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<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sMkLevelElem &ThisElem=OutMap.Get(X,Y);
ASSERT(Hdr.SubType!=LAYER_SUBTYPE_ACTION);
fwrite(&ThisElem.Elem,sizeof(u16),1,File);
}
}
PadFile(File);
return(ThisPos);
}
/*****************************************************************************/

View file

@ -0,0 +1,34 @@
/******************/
/*** Layer Tile ***/
/******************/
#ifndef __MKLEVEL_LAYER_TILE_HEADER__
#define __MKLEVEL_LAYER_TILE_HEADER__
#include "MkLevelLayer.h"
#include <List2d.h>
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<sExpLayerTile> InMap;
CList2d<sMkLevelElem> OutMap;
};
/*****************************************************************************/
#endif

View file

@ -0,0 +1,63 @@
/*********************/
/*** Layer Trigger ***/
/*********************/
#include <Davelib.h>
#include <List2d.h>
//#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<ListSize; i++)
{
sMkLevelLayerThing &ThisThing=ThingList[i];
sThingTrigger OutThing;
OutThing.Type=ThisThing.Type;
OutThing.Pos.X=ThisThing.XY[0].x;
OutThing.Pos.Y=ThisThing.XY[0].y;
OutThing.Width=ThisThing.Data.Width;
OutThing.Height=ThisThing.Data.Height;
fwrite(&OutThing,sizeof(sThingTrigger),1,File);
}
return(ThisPos);
}
/*****************************************************************************/

View file

@ -0,0 +1,25 @@
/*********************/
/*** Layer Trigger ***/
/*********************/
#ifndef __MKLEVEL_LAYER_TRIGGER_HEADER__
#define __MKLEVEL_LAYER_TRIGGER_HEADER__
#include "MkLevelLayerThing.h"
#include <List2d.h>
/*****************************************************************************/
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