SBSPSS/Utils/MkLevel/Layers/MkLevelLayerShade.cpp
2001-04-30 21:49:54 +00:00

189 lines
5.1 KiB
C++

/*******************/
/*** Layer Shade ***/
/*******************/
#include <DaveLib.h>
#include <List2d.h>
#include "MkLevelLayer.h"
#include "MkLevelLayerShade.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CMkLevelLayerShade::CMkLevelLayerShade(sExpLayerHdr *LayerHdr)
{
int i,ListSize;
int *iPtr;
u8 *Ptr=(u8*)LayerHdr;
Type=LayerHdr->Type;
SubType=LayerHdr->SubType;
Width=LayerHdr->Width;
Height=LayerHdr->Height;
iPtr=(int*)(Ptr+sizeof(sExpLayerHdr));
ShadeHdr.BandCount=*iPtr++;
sRGBCol *RGB=(sRGBCol*)iPtr;
for (i=0; i<LAYER_SHADE_RGB_MAX; i++)
{
ShadeHdr.RGB[i][0]=RGB->R;
ShadeHdr.RGB[i][1]=RGB->G;
ShadeHdr.RGB[i][2]=RGB->B;
RGB++;
}
iPtr=(int*)RGB;
ListSize=*iPtr++;
GfxList.resize(ListSize);
sLayerShadeGfx *GfxPtr=(sLayerShadeGfx*)iPtr;
for (i=0; i<ListSize; i++)
{
GfxList[i]=*GfxPtr++;
}
iPtr=(int*)GfxPtr;
ListSize=*iPtr++;
TypeNameList.resize(ListSize);
char *TypePtr=(char*)iPtr;
for (i=0; i<ListSize; i++)
{
TypeNameList[i]=TypePtr;
TypePtr+=strlen(TypePtr)+1;
}
}
/*****************************************************************************/
/*****************************************************************************/
/*** Pre-Process *************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// Build unique tiles, including pre-genned flips, and replace tile idx with new one
void CMkLevelLayerShade::PreProcess(CMkLevel *Core)
{
int i,ListSize=GfxList.size();
int Idx;
GString Path=Core->GetConfigStr("MISC","BackGfxDir");
CTexGrab &TexGrab=Core->GetTexGrab();
for (i=0; i<ListSize; i++)
{
sLayerShadeGfx &ThisGfx=GfxList[i];
sBackGfxList NewType;
NewType.Name=Path+TypeNameList[ThisGfx.Gfx]+".Bmp";
Idx=OutTypeList.Find(NewType);
if (Idx==-1)
{
TexGrab.ZeroColZero(true);
NewType.TexID=TexGrab.AddFile(NewType.Name);
TexGrab.ZeroColZero(false);
Idx=OutTypeList.Add(NewType);
}
ThisGfx.Gfx=Idx;
}
}
/*****************************************************************************/
/*****************************************************************************/
/*** Process *****************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CMkLevelLayerShade::Process(CMkLevel *Core)
{
int i,ListSize=OutTypeList.size();
CTexGrab &TexGrab=Core->GetTexGrab();
//printf("Process Shade Layer\n");
for (i=0; i<ListSize; i++)
{
sBackGfxList &ThisType=OutTypeList[i];
sTexOutInfo &ThisTex=TexGrab.GetTexInfo()[ThisType.TexID];
ThisType.Out.TPage=ThisTex.Tpage;
ThisType.Out.Clut=ThisTex.Clut;
ThisType.Out.U=ThisTex.u;
ThisType.Out.V=ThisTex.v;
ThisType.Out.W=ThisTex.w;
ThisType.Out.H=ThisTex.h;
// ThisType.TPage|=Trans[i]<<5;
}
}
/*****************************************************************************/
/*****************************************************************************/
/** 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);
// Write Gfx Stuff
ShadeHdr.TypeList=(sLayerShadeBackGfxType*)WriteTypeList(File);
ShadeHdr.GfxList=(sLayerShadeBackGfx*)WriteGfxList(File);
fwrite(&ShadeHdr,sizeof(sLayerShadeHdr),1,File);
PadFile(File);
return(ThisPos);
}
/*****************************************************************************/
int CMkLevelLayerShade::WriteTypeList(FILE *File)
{
int Pos=ftell(File);
int i,ListSize=OutTypeList.size();
for (i=0; i<ListSize; i++)
{
sBackGfxList &ThisType=OutTypeList[i];
fwrite(&ThisType.Out,sizeof(sLayerShadeBackGfxType),1,File);
}
return(Pos);
}
/*****************************************************************************/
int CMkLevelLayerShade::WriteGfxList(FILE *File)
{
int Pos=ftell(File);
int i,ListSize=GfxList.size();
ShadeHdr.GfxCount=GfxList.size();
for (i=0; i<ListSize; i++)
{
sLayerShadeGfx &ThisGfx=GfxList[i];
sLayerShadeBackGfx Out;
Out.Type=ThisGfx.Gfx;
Out.PosX=ThisGfx.Pos.x;
Out.PosY=ThisGfx.Pos.y;
Out.Trans=ThisGfx.TransMode;
for (int p=0; p<4; p++)
{
Out.Ofs[i][0]=ThisGfx.Ofs[i].x;
Out.Ofs[i][1]=ThisGfx.Ofs[i].y;
Out.RGB[i][0]=ThisGfx.RGB[i].R;
Out.RGB[i][1]=ThisGfx.RGB[i].G;
Out.RGB[i][2]=ThisGfx.RGB[i].B;
}
}
return(Pos);
}