SBSPSS/Utils/MkLevel/Layers/MkLevelLayerShade.cpp

197 lines
5.3 KiB
C++
Raw Normal View History

2001-04-17 18:42:07 +02:00
/*******************/
/*** Layer Shade ***/
/*******************/
#include <DaveLib.h>
#include <List2d.h>
#include "MkLevelLayer.h"
#include "MkLevelLayerShade.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CMkLevelLayerShade::CMkLevelLayerShade(sExpLayerHdr *LayerHdr)
{
2001-04-30 23:49:54 +02:00
int i,ListSize;
2001-04-17 18:42:07 +02:00
int *iPtr;
u8 *Ptr=(u8*)LayerHdr;
Type=LayerHdr->Type;
SubType=LayerHdr->SubType;
Width=LayerHdr->Width;
Height=LayerHdr->Height;
iPtr=(int*)(Ptr+sizeof(sExpLayerHdr));
2001-04-30 23:49:54 +02:00
ShadeHdr.BandCount=*iPtr++;
sRGBCol *RGB=(sRGBCol*)iPtr;
for (i=0; i<LAYER_SHADE_RGB_MAX; i++)
2001-04-17 18:42:07 +02:00
{
2001-04-30 23:49:54 +02:00
ShadeHdr.RGB[i][0]=RGB->R;
ShadeHdr.RGB[i][1]=RGB->G;
ShadeHdr.RGB[i][2]=RGB->B;
RGB++;
2001-04-17 18:42:07 +02:00
}
2001-04-30 23:49:54 +02:00
iPtr=(int*)RGB;
2001-04-17 18:42:07 +02:00
2001-04-30 23:49:54 +02:00
ListSize=*iPtr++;
GfxList.resize(ListSize);
sLayerShadeGfx *GfxPtr=(sLayerShadeGfx*)iPtr;
for (i=0; i<ListSize; i++)
{
2001-05-05 23:18:12 +02:00
sLayerShadeGfx &ThisGfx=GfxList[i];
2001-04-30 23:49:54 +02:00
GfxList[i]=*GfxPtr++;
}
2001-04-17 18:42:07 +02:00
2001-05-05 23:18:12 +02:00
iPtr=(int*)GfxPtr;
2001-04-30 23:49:54 +02:00
ListSize=*iPtr++;
TypeNameList.resize(ListSize);
char *TypePtr=(char*)iPtr;
for (i=0; i<ListSize; i++)
{
TypeNameList[i]=TypePtr;
TypePtr+=strlen(TypePtr)+1;
}
2001-04-17 18:42:07 +02:00
}
/*****************************************************************************/
/*****************************************************************************/
/*** Pre-Process *************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// Build unique tiles, including pre-genned flips, and replace tile idx with new one
void CMkLevelLayerShade::PreProcess(CMkLevel *Core)
{
2001-04-30 23:49:54 +02:00
int i,ListSize=GfxList.size();
int Idx;
GString Path=Core->GetConfigStr("MISC","BackGfxDir");
CTexGrab &TexGrab=Core->GetTexGrab();
2001-04-17 18:42:07 +02:00
2001-04-30 23:49:54 +02:00
for (i=0; i<ListSize; i++)
2001-04-17 18:42:07 +02:00
{
2001-04-30 23:49:54 +02:00
sLayerShadeGfx &ThisGfx=GfxList[i];
sBackGfxList NewType;
NewType.Name=Path+TypeNameList[ThisGfx.Gfx]+".Bmp";
Idx=OutTypeList.Find(NewType);
2001-04-17 18:42:07 +02:00
2001-04-30 23:49:54 +02:00
if (Idx==-1)
2001-04-17 18:42:07 +02:00
{
TexGrab.ZeroColZero(true);
2001-04-30 23:49:54 +02:00
NewType.TexID=TexGrab.AddFile(NewType.Name);
2001-04-17 18:42:07 +02:00
TexGrab.ZeroColZero(false);
2001-04-30 23:49:54 +02:00
Idx=OutTypeList.Add(NewType);
2001-04-17 18:42:07 +02:00
}
2001-04-30 23:49:54 +02:00
ThisGfx.Gfx=Idx;
}
2001-04-17 18:42:07 +02:00
}
/*****************************************************************************/
/*****************************************************************************/
/*** Process *****************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CMkLevelLayerShade::Process(CMkLevel *Core)
{
2001-04-30 23:49:54 +02:00
int i,ListSize=OutTypeList.size();
2001-04-17 18:42:07 +02:00
CTexGrab &TexGrab=Core->GetTexGrab();
//printf("Process Shade Layer\n");
2001-04-30 23:49:54 +02:00
for (i=0; i<ListSize; i++)
2001-04-17 18:42:07 +02:00
{
2001-04-30 23:49:54 +02:00
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;
2001-04-17 18:42:07 +02:00
}
2001-04-30 23:49:54 +02:00
2001-04-17 18:42:07 +02:00
}
/*****************************************************************************/
/*****************************************************************************/
/** 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);
2001-05-05 23:18:12 +02:00
int HdrPos=ftell(File);
fwrite(&ShadeHdr,sizeof(sLayerShadeHdr),1,File);
2001-04-30 23:49:54 +02:00
2001-05-05 23:18:12 +02:00
// Write Gfx Stuff
ShadeHdr.GfxList=(sLayerShadeBackGfx*)(WriteGfxList(File)-ThisPos);
ShadeHdr.TypeList=(sLayerShadeBackGfxType*)(WriteTypeList(File)-ThisPos);
2001-04-17 18:42:07 +02:00
2001-05-05 23:18:12 +02:00
// rewrite header
int RetPos=ftell(File);
fseek(File,HdrPos,SEEK_SET);
2001-04-30 23:49:54 +02:00
fwrite(&ShadeHdr,sizeof(sLayerShadeHdr),1,File);
2001-05-05 23:18:12 +02:00
fseek(File,RetPos,SEEK_SET);
2001-04-17 18:42:07 +02:00
return(ThisPos);
}
/*****************************************************************************/
2001-04-30 23:49:54 +02:00
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();
2001-05-05 23:18:12 +02:00
ShadeHdr.GfxCount=ListSize;
2001-04-30 23:49:54 +02:00
for (i=0; i<ListSize; i++)
{
2001-05-05 23:18:12 +02:00
sLayerShadeGfx &ThisGfx=GfxList[i];
2001-04-30 23:49:54 +02:00
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++)
{
2001-05-05 23:18:12 +02:00
Out.Ofs[p][0]=ThisGfx.Ofs[p].x;
Out.Ofs[p][1]=ThisGfx.Ofs[p].y;
Out.RGB[p][0]=ThisGfx.RGB[p].R;
Out.RGB[p][1]=ThisGfx.RGB[p].G;
Out.RGB[p][2]=ThisGfx.RGB[p].B;
2001-04-30 23:49:54 +02:00
}
2001-05-05 23:18:12 +02:00
fwrite(&Out,sizeof(sLayerShadeBackGfx),1,File);
2001-04-30 23:49:54 +02:00
}
return(Pos);
}