This commit is contained in:
parent
6f7a6252bc
commit
4eef48176b
21 changed files with 1050 additions and 885 deletions
|
@ -27,7 +27,6 @@
|
|||
#include "Export.h"
|
||||
#include "LayerList.h"
|
||||
|
||||
const Vector3 DefaultCamPos(0.0f,0.0f,0.9f);
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -36,12 +35,12 @@ CCore::CCore()
|
|||
{
|
||||
CurrentMousePos=CPoint(0,0);
|
||||
MapCam=DefaultCamPos;
|
||||
TileCam=DefaultCamPos;
|
||||
SpareFlag=false;
|
||||
GridFlag=true;
|
||||
Is3dFlag=true;
|
||||
CurrentView=NULL;
|
||||
CursorPos.x=CursorPos.y=0;
|
||||
CurrentLayer=0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -86,10 +85,10 @@ void CCore::Load(CFile *File)
|
|||
{
|
||||
int Version,i;
|
||||
BOOL F;
|
||||
|
||||
Vector3 DuffVector;
|
||||
File->Read(&Version,sizeof(int));
|
||||
if (Version>100000) Version=1; // Check fix for changing version to int from float
|
||||
|
||||
#ifndef _DEBUG
|
||||
if (Version<FileVersion)
|
||||
{
|
||||
CString mexstr;
|
||||
|
@ -97,13 +96,17 @@ BOOL F;
|
|||
AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
TRACE1("Load Version %i\n",Version);
|
||||
|
||||
File->Read(&MapCam,sizeof(Vector3));
|
||||
if (Version<FileVersion)
|
||||
{
|
||||
File->Read(&MapCamOfs,sizeof(Vector3));
|
||||
File->Read(&TileCam,sizeof(Vector3));
|
||||
File->Read(&TileCamOfs,sizeof(Vector3));
|
||||
File->Read(&DuffVector,sizeof(Vector3));
|
||||
File->Read(&DuffVector,sizeof(Vector3));
|
||||
}
|
||||
|
||||
File->Read(&F,sizeof(BOOL)); SpareFlag=F!=0;
|
||||
File->Read(&F,sizeof(BOOL)); GridFlag=F!=0;
|
||||
|
@ -161,9 +164,6 @@ BOOL F;
|
|||
File->Write(&FileVersion,sizeof(int));
|
||||
|
||||
File->Write(&MapCam,sizeof(Vector3));
|
||||
File->Write(&MapCamOfs,sizeof(Vector3));
|
||||
File->Write(&TileCam,sizeof(Vector3));
|
||||
File->Write(&TileCamOfs,sizeof(Vector3));
|
||||
|
||||
F=SpareFlag; File->Write(&F,sizeof(BOOL));
|
||||
F=GridFlag; File->Write(&F,sizeof(BOOL));
|
||||
|
@ -182,7 +182,12 @@ int LayerCount=Layer.size();
|
|||
Layer[i]->Save(File);
|
||||
}
|
||||
GetTileBank()->Save(File);
|
||||
|
||||
/*
|
||||
CString a=File->GetFilePath();
|
||||
char Txt[256];
|
||||
sprintf(Txt,"%s",a);
|
||||
Export(Txt);
|
||||
*/
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -209,14 +214,14 @@ Vector3 &ThisCam=GetCam();
|
|||
UpdateAll();
|
||||
return;
|
||||
}
|
||||
if (GetTileBank()->NeedLoad()) GetTileBank()->LoadTileSets(this);
|
||||
// if (GetTileBank()->NeedLoad()) GetTileBank()->LoadAllSets(this);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
|
||||
|
||||
if (CurrentLayer!=Layer[ActiveLayer] || CurrentLayer->IsUnique())
|
||||
if (IsSubView() || CurrentLayer->IsUnique())
|
||||
{
|
||||
CurrentLayer->Render(this,ThisCam,Is3dFlag);
|
||||
CurrentLayer->RenderGrid(this,ThisCam,true);
|
||||
if (GridFlag) CurrentLayer->RenderGrid(this,ThisCam,true);
|
||||
CurrentLayer->FindCursorPos(this,GetCam(),CurrentMousePos);
|
||||
}
|
||||
else
|
||||
|
@ -398,7 +403,7 @@ bool RedrawFlag=false;
|
|||
break;
|
||||
|
||||
}
|
||||
/* if (RedrawFlag) */RedrawView();
|
||||
RedrawView();
|
||||
|
||||
}
|
||||
|
||||
|
@ -454,14 +459,12 @@ int LastLayer=ActiveLayer;
|
|||
}
|
||||
else
|
||||
{
|
||||
bool IsCol=Layer[NewLayer]->GetType()==LAYER_TYPE_COLLISION;
|
||||
GetTileBank()->SetCollision(IsCol);
|
||||
ActiveLayer=NewLayer;
|
||||
}
|
||||
|
||||
if (LastLayer!=ActiveLayer || Force)
|
||||
{
|
||||
if (LastLayer<=LayerCount) CurrentLayer->GUIKill(this);
|
||||
if (LastLayer<=LayerCount) Layer[LastLayer]->GUIKill(this);
|
||||
CurrentLayer=Layer[ActiveLayer];
|
||||
CurrentLayer->GUIInit(this);
|
||||
GUIUpdate();
|
||||
|
@ -487,7 +490,6 @@ int Idx=ListSize;
|
|||
Layer.insert(Layer.begin() + Idx,NewLayer);
|
||||
|
||||
if (NewLayer->GetType()==LAYER_TYPE_TILE && NewLayer->GetSubType()==LAYER_SUBTYPE_ACTION) ActionLayer=(CLayerTile*)NewLayer;
|
||||
NewLayer->InitSubView(this);
|
||||
return(Idx);
|
||||
}
|
||||
|
||||
|
@ -511,6 +513,7 @@ int Idx;
|
|||
ASSERT(!"AddLayer - Invalid Layer Type");
|
||||
break;
|
||||
}
|
||||
if (ActionLayer) Layer[Idx]->InitSubView(this);
|
||||
return(Idx);
|
||||
}
|
||||
|
||||
|
@ -549,23 +552,25 @@ int Idx=AddLayer(CLayer::InfoTable[NewLayerId].Type,CLayer::InfoTable[NewLayerI
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CCore::DeleteLayer(int CurrentLayer)
|
||||
void CCore::DeleteLayer(int ThisLayer)
|
||||
{
|
||||
if (Layer[CurrentLayer]->CanDelete())
|
||||
|
||||
if (Layer[ThisLayer]->CanDelete())
|
||||
{
|
||||
Layer[CurrentLayer]->GUIKill(this);
|
||||
delete Layer[CurrentLayer];
|
||||
Layer.erase(Layer.begin() + CurrentLayer);
|
||||
SetLayer(CurrentLayer-1,true);
|
||||
TRACE1("Deleted Layer %i\n",CurrentLayer);
|
||||
// Layer[CurrentLayer]->GUIKill(this);
|
||||
SetLayer(ThisLayer-1,true);
|
||||
delete Layer[ThisLayer];
|
||||
Layer.erase(Layer.begin() + ThisLayer);
|
||||
TRACE1("Deleted Layer %i\n",ThisLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE1("Cant Delete Layer %i\n",CurrentLayer);
|
||||
TRACE1("Cant Delete Layer %i\n",ThisLayer);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
CLayer *CCore::FindSubView(int Type)
|
||||
{
|
||||
int i,ListSize=Layer.size();
|
||||
|
@ -580,7 +585,7 @@ int i,ListSize=Layer.size();
|
|||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/*** Grid ********************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -604,7 +609,7 @@ CLayer *LastLayer=CurrentLayer;
|
|||
LastLayer->GUIKill(this);
|
||||
CurrentLayer->GUIInit(this);
|
||||
GUIUpdate();
|
||||
RedrawView();
|
||||
UpdateView();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -613,9 +618,11 @@ CLayer *LastLayer=CurrentLayer;
|
|||
/*****************************************************************************/
|
||||
Vector3 &CCore::GetCam()
|
||||
{
|
||||
// if (SubViewFlag)
|
||||
// return(TileCam);
|
||||
// else
|
||||
if (IsSubView() || CurrentLayer->IsUnique())
|
||||
{
|
||||
return(CurrentLayer->GetCam());
|
||||
}
|
||||
|
||||
return(MapCam);
|
||||
|
||||
}
|
||||
|
@ -719,6 +726,7 @@ void CCore::RedrawView()
|
|||
/*****************************************************************************/
|
||||
void CCore::UpdateView(Vector3 *Ofs)
|
||||
{
|
||||
if (!CurrentLayer) return;
|
||||
if (Ofs)
|
||||
{
|
||||
Vector3 &ThisCam=GetCam();
|
||||
|
@ -726,8 +734,11 @@ void CCore::UpdateView(Vector3 *Ofs)
|
|||
ThisCam.x+=Ofs->x;
|
||||
ThisCam.y+=Ofs->y;
|
||||
ThisCam.z-=Ofs->z;
|
||||
if (!IsSubView())
|
||||
{
|
||||
if (ThisCam.x<0) ThisCam.x=0;
|
||||
if (ThisCam.y<0) ThisCam.y=0;
|
||||
}
|
||||
if (ThisCam.z<0.1) ThisCam.z=0.1f;
|
||||
}
|
||||
|
||||
|
@ -779,7 +790,6 @@ Vector3 ThisCam=Cam;
|
|||
|
||||
ThisCam=Cam/DivVal;
|
||||
ThisCam.z=Cam.z;
|
||||
|
||||
return(ThisCam);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
#include "Layer.h"
|
||||
#include "LayerTile.h"
|
||||
|
||||
const s32 FileVersion=3;
|
||||
const s32 FileVersion=4;
|
||||
|
||||
#define SCREEN_MAP_WIDTH 30
|
||||
#define SCREEN_MAP_HEIGHT 20
|
||||
|
||||
const Vector3 DefaultCamPos(0.0f,0.0f,0.9f);
|
||||
|
||||
/*****************************************************************************/
|
||||
class CMapEditView;
|
||||
|
||||
|
@ -58,8 +60,8 @@ public:
|
|||
// Subview & TileBank
|
||||
CTileBank *GetTileBank() {return(ActionLayer->GetTileBank());}
|
||||
void ToggleSubView();
|
||||
CLayer *FindSubView(int Type);
|
||||
|
||||
// CLayer *FindSubView(int Type);
|
||||
bool IsSubView() {return(CurrentLayer!=Layer[ActiveLayer]);}
|
||||
// GUI
|
||||
void UpdateParamBar();
|
||||
void GUIAdd(CDialog &Dlg,int ID,bool Visible=true,bool Lock=false);
|
||||
|
@ -117,7 +119,7 @@ private:
|
|||
CMapEditView *CurrentView;
|
||||
CPoint CurrentMousePos,LastMousePos;
|
||||
CPoint CursorPos,LastCursorPos;
|
||||
Vector3 MapCam,TileCam;
|
||||
Vector3 MapCam;
|
||||
Vector3 MapCamOfs,TileCamOfs;
|
||||
Vector3 ScaleVector;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*********************/
|
||||
/*** Tile Stuph ***/
|
||||
/*** Elem Stuph ***/
|
||||
/*********************/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
@ -11,8 +11,7 @@
|
|||
|
||||
#include "Core.h"
|
||||
#include "TexCache.h"
|
||||
//#include "TileSet.h"
|
||||
#include "Tile.h"
|
||||
#include "Elem.h"
|
||||
#include "GinTex.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
@ -36,26 +35,25 @@ const float YFlipMtx[]=
|
|||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
CTile::CTile()
|
||||
CElem::CElem(int Width,int Height)
|
||||
{
|
||||
}
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
CTile::CTile(int Blank,int _Width,int _Height)
|
||||
{
|
||||
Width=_Width;
|
||||
Height=_Height;
|
||||
PCTexID=-1;
|
||||
PCTexRGB=(u8*)malloc(Width*Height*3);
|
||||
memset(PCTexRGB,0,Width*Height*3);
|
||||
Tex2dID=-1;
|
||||
Type=TileType2d;
|
||||
ElemWidth=Width;
|
||||
ElemHeight=Height;
|
||||
UnitWidth=ElemWidth/UnitSize;
|
||||
UnitHeight=ElemHeight/UnitSize;
|
||||
ElemID=-1;
|
||||
ElemRGB=(u8*)malloc(ElemWidth*ElemHeight*3);
|
||||
memset(ElemRGB,0,ElemWidth*ElemHeight*3);
|
||||
|
||||
Type=ElemType2d;
|
||||
TexXOfs=0;
|
||||
TexYOfs=0;
|
||||
CreateBlankTileGfx();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
// 3d tile (From Gin File)
|
||||
CTile::CTile(CCore *Core,const char *Filename,CScene &ThisScene,int Node)
|
||||
// 3d Elem (From Gin File)
|
||||
CElem::CElem(CCore *Core,const char *Filename,CScene &ThisScene,int Node)
|
||||
{
|
||||
CNode &ThisNode=ThisScene.GetNode(Node);
|
||||
CTexCache &TexCache=Core->GetTexCache();
|
||||
|
@ -65,36 +63,50 @@ GFName Path=Filename;
|
|||
SetPath+=Path.Dir();
|
||||
SetPath.Append('\\');
|
||||
|
||||
Type=TileType3d;
|
||||
Type=ElemType3d;
|
||||
TexXOfs=-1;
|
||||
TexYOfs=-1;
|
||||
Build3dTile(TexCache,ThisScene,Node);
|
||||
Build3dElem(TexCache,ThisScene,Node);
|
||||
Calc3dSize();
|
||||
Ofs.x=+0.5f; Ofs.y=0; Ofs.z=+4.0f;
|
||||
Build3dDrawList(TexCache,DrawList[TileType3d]);
|
||||
Build3dDrawList(TexCache,DrawList[ElemType3d]);
|
||||
Create2dTexture(TexCache,Path.File(),Node);
|
||||
Build2dDrawList(TexCache,DrawList[TileType2d]);
|
||||
Build2dDrawList(TexCache,DrawList[ElemType2d]);
|
||||
if (!ValidFlag) CreateInvalidTileGfx();
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
// 2d tile (From Bmp File)
|
||||
CTile::CTile(CCore *Core,const char *Filename,int TexID,int XOfs,int YOfs)
|
||||
// 2d Elem (From Bmp File)
|
||||
CElem::CElem(CCore *Core,const char *Filename,int TexID,int XOfs,int YOfs,int Width,int Height)
|
||||
{
|
||||
CTexCache &TexCache=Core->GetTexCache();
|
||||
GFName Path=Filename;
|
||||
|
||||
Type=TileType2d;
|
||||
ElemWidth=Width;
|
||||
ElemHeight=Height;
|
||||
UnitWidth=ElemWidth/UnitSize;
|
||||
UnitHeight=ElemHeight/UnitSize;
|
||||
|
||||
Type=ElemType2d;
|
||||
TexXOfs=XOfs;
|
||||
TexYOfs=YOfs;
|
||||
|
||||
Build2dTile(Core,Path.File(),TexID);
|
||||
Build2dElem(Core,Path.File(),TexID);
|
||||
Ofs.Zero();
|
||||
Build3dDrawList(TexCache,DrawList[TileType3d]);
|
||||
Build3dDrawList(TexCache,DrawList[ElemType3d]);
|
||||
Create2dTexture(TexCache,Path.File(),TexID);
|
||||
Build2dDrawList(TexCache,DrawList[TileType2d]);
|
||||
Build2dDrawList(TexCache,DrawList[ElemType2d]);
|
||||
if (!ValidFlag) CreateInvalidTileGfx();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTile::Build2dTile(CCore *Core,const char *Filename,int TexID)
|
||||
void CElem::CleanUp()
|
||||
{
|
||||
free(ElemRGB);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElem::Build2dElem(CCore *Core,const char *Filename,int TexID)
|
||||
{
|
||||
const Vector3 P0(0.0f,0.0f,0.0f);
|
||||
const Vector3 P1(1.0f,0.0f,0.0f);
|
||||
|
@ -111,11 +123,10 @@ sTex &ThisTex=TexCache.GetTex(TexID);
|
|||
|
||||
float u0,u1,v0,v1;
|
||||
|
||||
Tex2dID=TexID;
|
||||
u0=(TexXOfs)*ThisTex.dW;
|
||||
u1=u0+ThisTex.dW;
|
||||
|
||||
v0=(((ThisTex.TexHeight/16)-(TexYOfs+1))*ThisTex.dH);
|
||||
v0=(((ThisTex.TexHeight/UnitSize)-(TexYOfs+1))*ThisTex.dH);
|
||||
v1=v0+ThisTex.dH;
|
||||
|
||||
Tri0.Mat=TexID;
|
||||
|
@ -137,7 +148,7 @@ float u0,u1,v0,v1;
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTile::Build3dTile(CTexCache &TexCache,CScene &ThisScene,int Node)
|
||||
void CElem::Build3dElem(CTexCache &TexCache,CScene &ThisScene,int Node)
|
||||
{
|
||||
CNode &ThisNode=ThisScene.GetNode(Node);
|
||||
int ChildCount=ThisNode.GetChildCount();
|
||||
|
@ -170,7 +181,7 @@ int ListSize=TriList.size();
|
|||
ThisName=SetPath+TexList[TexID];
|
||||
TexID=TexCache.ProcessTexture(ThisName,MatList[ThisMat].Flags);
|
||||
}
|
||||
// Sort Rest
|
||||
// Sort Rest of Tri info
|
||||
for (int p=0; p<3; p++)
|
||||
{
|
||||
Tri.vtx[p]=NodeVtxList[ThisTri.p[p]];
|
||||
|
@ -180,29 +191,58 @@ int ListSize=TriList.size();
|
|||
}
|
||||
}
|
||||
|
||||
for (int Child=0; Child<ChildCount; Child++) Build3dTile(TexCache,ThisScene,ThisNode.PruneChildList[Child]);
|
||||
for (int Child=0; Child<ChildCount; Child++) Build3dElem(TexCache,ThisScene,ThisNode.PruneChildList[Child]);
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTile::Build2dDrawList(CTexCache &TexCache,GLint &List)
|
||||
void CElem::Calc3dSize()
|
||||
{
|
||||
int ListSize=TriList.size();
|
||||
float XMin=+9999;
|
||||
float XMax=-9999;
|
||||
float YMin=+9999;
|
||||
float YMax=-9999;
|
||||
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
sTriFace &Tri=TriList[i];
|
||||
for (int p=0; p<3; p++)
|
||||
{
|
||||
if (XMin>Tri.vtx[p].x) XMin=Tri.vtx[p].x;
|
||||
if (XMax<Tri.vtx[p].x) XMax=Tri.vtx[p].x;
|
||||
if (YMin>Tri.vtx[p].y) YMin=Tri.vtx[p].y;
|
||||
if (YMax<Tri.vtx[p].y) YMax=Tri.vtx[p].y;
|
||||
}
|
||||
}
|
||||
UnitWidth=round(XMax-XMin);
|
||||
UnitHeight=round(YMax-YMin);
|
||||
if (UnitWidth<1) UnitWidth=1;
|
||||
if (UnitHeight<1) UnitHeight=1;
|
||||
ElemWidth=UnitWidth*UnitSize;
|
||||
ElemHeight=UnitHeight*UnitSize;
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElem::Build2dDrawList(CTexCache &TexCache,GLint &List)
|
||||
{
|
||||
List=glGenLists(1);
|
||||
glNewList(List,GL_COMPILE);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, TexCache.GetTexGLId(PCTexID));
|
||||
glBindTexture(GL_TEXTURE_2D, TexCache.GetTexGLId(ElemID));
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f(0.0f,0.0f);
|
||||
glVertex3f( 0.0f,0.0f,0.0f);
|
||||
|
||||
glTexCoord2f(1.0f,0.0f);
|
||||
glVertex3f( 1.0f,0.0f,0.0f);
|
||||
glVertex3f( UnitWidth,0.0f,0.0f);
|
||||
|
||||
glTexCoord2f(1.0f,1.0f);
|
||||
glVertex3f( 1.0f,1.0f,0.0f);
|
||||
glVertex3f( UnitWidth,UnitHeight,0.0f);
|
||||
|
||||
glTexCoord2f(0.0f,1.0f);
|
||||
glVertex3f( 0.0f,1.0f,0.0f);
|
||||
glVertex3f( 0.0f,UnitHeight,0.0f);
|
||||
|
||||
glEnd();
|
||||
glEndList();
|
||||
|
@ -211,7 +251,7 @@ void CTile::Build2dDrawList(CTexCache &TexCache,GLint &List)
|
|||
|
||||
/*****************************************************************************/
|
||||
// Build OpenGL display lists, sorted by material (luckily by gin!!)
|
||||
void CTile::Build3dDrawList(CTexCache &TexCache,GLint &List)
|
||||
void CElem::Build3dDrawList(CTexCache &TexCache,GLint &List)
|
||||
{
|
||||
int TriCount=TriList.size();
|
||||
int LastMat=-1,ThisMat;
|
||||
|
@ -247,9 +287,8 @@ int LastMat=-1,ThisMat;
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTile::Render(int Flags,bool Render3d)
|
||||
void CElem::Render(int Flags,bool Render3d)
|
||||
{
|
||||
if (!ValidFlag) return;
|
||||
glPushMatrix();
|
||||
|
||||
if (Flags & PC_TILE_FLAG_MIRROR_X)
|
||||
|
@ -279,23 +318,94 @@ int ColFlags=Flags >> PC_TILE_FLAG_COLLISION_SHIFT;
|
|||
}
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glCallList(DrawList[Render3d]);
|
||||
if (Render3d)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glCallList(DrawList[ElemType3d]);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
else
|
||||
{
|
||||
glCallList(DrawList[ElemType2d]);
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTile::Purge()
|
||||
void CElem::Purge()
|
||||
{
|
||||
glDeleteLists(DrawList[TileType3d],1);
|
||||
glDeleteLists(DrawList[TileType2d],1);
|
||||
for (int i=0; i<ElemTypeMax; i++)
|
||||
glDeleteLists(DrawList[i],1);
|
||||
TriList.clear();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTile::RenderTile4Texture(sRGBData &RGBData)
|
||||
// Only created for the tile browser, should NEVER appear in main view
|
||||
void CElem::CreateBlankTileGfx()
|
||||
{
|
||||
float X0=0;
|
||||
float X1=UnitWidth;
|
||||
float Y0=0;
|
||||
float Y1=UnitHeight;
|
||||
|
||||
Purge();
|
||||
for (int i=0; i<ElemTypeMax; i++)
|
||||
{
|
||||
DrawList[i]=glGenLists(1);
|
||||
glNewList(DrawList[i],GL_COMPILE);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBegin(GL_LINES);
|
||||
glColor4f(1,1,1,1);
|
||||
|
||||
glVertex3f( X0,Y0,0);
|
||||
glVertex3f( X1,Y0,0);
|
||||
|
||||
glVertex3f( X0,Y1,0);
|
||||
glVertex3f( X1,Y1,0);
|
||||
|
||||
glVertex3f( X0,Y0,0);
|
||||
glVertex3f( X0,Y1,0);
|
||||
|
||||
glVertex3f( X1,Y0,0);
|
||||
glVertex3f( X1,Y1,0);
|
||||
glEnd();
|
||||
glEndList();
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElem::CreateInvalidTileGfx()
|
||||
{
|
||||
float X0=0;
|
||||
float X1=UnitWidth;
|
||||
float Y0=0;
|
||||
float Y1=UnitHeight;
|
||||
|
||||
Purge();
|
||||
for (int i=0; i<ElemTypeMax; i++)
|
||||
{
|
||||
DrawList[i]=glGenLists(1);
|
||||
glNewList(DrawList[i],GL_COMPILE);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBegin(GL_LINES);
|
||||
glColor4f(1,1,1,1);
|
||||
|
||||
glVertex3f( X0,Y0,0);
|
||||
glVertex3f( X1,Y1,0);
|
||||
|
||||
glVertex3f( X1,Y0,0);
|
||||
glVertex3f( X0,Y1,0);
|
||||
glEnd();
|
||||
glEndList();
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElem::RenderElem4Texture(sRGBData &RGBData)
|
||||
{
|
||||
|
||||
glClearColor(1,0,1,1 );
|
||||
glPushAttrib(GL_VIEWPORT_BIT);
|
||||
glViewport(0,0,RGBData.Width,RGBData.Height);
|
||||
|
||||
|
@ -315,7 +425,7 @@ void CTile::RenderTile4Texture(sRGBData &RGBData)
|
|||
glColor3f(1,1,1);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glCallList(DrawList[TileType3d]);
|
||||
glCallList(DrawList[ElemType3d]);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
|
@ -325,23 +435,24 @@ void CTile::RenderTile4Texture(sRGBData &RGBData)
|
|||
glPopAttrib();
|
||||
|
||||
glReadPixels(0,0,RGBData.Width,RGBData.Height,GL_RGB, GL_UNSIGNED_BYTE,RGBData.RGB);
|
||||
glClearColor(0,0,0,1 );
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
// ID used to create unique textures within one set :o)
|
||||
void CTile::Create2dTexture(CTexCache &TexCache,const char *Filename,int ID)
|
||||
void CElem::Create2dTexture(CTexCache &TexCache,const char *Filename,int ID)
|
||||
{
|
||||
sRGBData RGBData;
|
||||
|
||||
// PC
|
||||
glClearColor(1,0,1,1 );
|
||||
RGBData.Width=PCTexWidth;
|
||||
RGBData.Height=PCTexHeight;
|
||||
RGBData.RGB=PCTexRGB;
|
||||
RenderTile4Texture(RGBData);
|
||||
PCTexID=TexCache.ProcessTexture("",0,&RGBData);
|
||||
ElemRGB=(u8*)malloc(ElemWidth*ElemHeight*3);
|
||||
|
||||
RGBData.Width=ElemWidth;
|
||||
RGBData.Height=ElemHeight;
|
||||
RGBData.RGB=ElemRGB;
|
||||
RenderElem4Texture(RGBData);
|
||||
ElemID=TexCache.ProcessTexture("",0,&RGBData);
|
||||
ValidFlag=CheckHasData(RGBData);
|
||||
glClearColor(0,0,0,1 );
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (0)
|
||||
|
@ -351,7 +462,7 @@ char TexName[256];
|
|||
static asd=0;
|
||||
sprintf(TexName,"_2dPc_%s_%03d",Filename,asd++);
|
||||
sprintf(Filename,"/x/%s.Tga",TexName);
|
||||
SaveTGA(Filename,PCTexWidth,PCTexHeight,PCTexRGB);
|
||||
SaveTGA(Filename,ElemWidth,ElemHeight,ElemRGB);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -359,7 +470,7 @@ static asd=0;
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CTile::CheckHasData(sRGBData &RGBData)
|
||||
bool CElem::CheckHasData(sRGBData &RGBData)
|
||||
{
|
||||
u8 *Src=RGBData.RGB;
|
||||
int Size=RGBData.Width*RGBData.Height;
|
||||
|
@ -376,6 +487,271 @@ int Size=RGBData.Width*RGBData.Height;
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*** Elem Set ****************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
CElemSet::CElemSet(const char *_Filename,int Idx,int Width,int Height)
|
||||
{
|
||||
GFName FName=_Filename;
|
||||
|
||||
Filename=_Filename;
|
||||
Name=FName.File();
|
||||
|
||||
DefWidth=Width;
|
||||
DefHeight=Height;
|
||||
Loaded=FALSE;
|
||||
SetNumber=Idx;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
CElemSet::~CElemSet()
|
||||
{
|
||||
int ListSize=ElemList.size();
|
||||
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
ElemList[i].CleanUp();
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemSet::Load(CCore *Core)
|
||||
{
|
||||
GFName FName=Filename;
|
||||
GString Ext=FName.Ext();
|
||||
Ext.Upper();
|
||||
|
||||
if (Ext=="GIN")
|
||||
Load3d(Core);
|
||||
else
|
||||
Load2d(Core);
|
||||
Loaded=TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemSet::Load2d(CCore *Core)
|
||||
{
|
||||
CTexCache &TexCache=Core->GetTexCache();
|
||||
int TexID=TexCache.ProcessTexture(Filename,0);
|
||||
sTex &ThisTex=TexCache.GetTex(TexID);
|
||||
int Width=ThisTex.TexWidth/DefWidth;
|
||||
int Height=ThisTex.TexHeight/DefHeight;
|
||||
|
||||
ElemList.push_back(CElem(DefWidth,DefHeight)); // Insert Blank
|
||||
|
||||
for (int Y=0; Y<Height; Y++)
|
||||
{
|
||||
for (int X=0; X<Width; X++)
|
||||
{
|
||||
ElemList.push_back(CElem(Core,Filename,TexID,X,Y,DefWidth,DefHeight));
|
||||
}
|
||||
}
|
||||
ElemBrowserWidth=Width;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemSet::Load3d(CCore *Core)
|
||||
{
|
||||
CScene Scene;
|
||||
|
||||
Scene.Load(Filename);
|
||||
|
||||
CNode &ThisNode=Scene.GetSceneNode(0);
|
||||
int ChildCount=ThisNode.GetPruneChildCount();
|
||||
|
||||
ElemList.push_back(CElem(DefWidth,DefHeight)); // Insert Blank
|
||||
|
||||
for (int Child=0; Child<ChildCount; Child++)
|
||||
{
|
||||
ElemList.push_back(CElem(Core,Filename,Scene,ThisNode.PruneChildList[Child]));
|
||||
}
|
||||
ElemBrowserWidth=DEF_ELEMBROWSWEWIDTH;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemSet::Purge()
|
||||
{
|
||||
int ListSize=ElemList.size();
|
||||
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
ElemList[i].Purge();
|
||||
}
|
||||
ElemList.clear();
|
||||
Loaded=FALSE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
CPoint CElemSet::GetElemPos(int ID)
|
||||
{
|
||||
if (ID==0)
|
||||
return(CPoint(-1,-1));
|
||||
else
|
||||
return(IDToPoint(ID-1,ElemBrowserWidth));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CElemSet::IsValid(int No)
|
||||
{
|
||||
int ListSize=ElemList.size();
|
||||
if (No>ListSize) return(false);
|
||||
return(ElemList[No].IsValid());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*** Elem Bank ***************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
CElemBank::CElemBank()
|
||||
{
|
||||
LoadFlag=FALSE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
CElemBank::~CElemBank()
|
||||
{
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemBank::Load(CFile *File,int Version)
|
||||
{
|
||||
int ListSize;
|
||||
GFName RootPath=File->GetFilePath();
|
||||
GString FilePath;
|
||||
char FixPath[1024];
|
||||
|
||||
FilePath=RootPath.Drive();
|
||||
FilePath+=RootPath.Dir();
|
||||
FilePath.Append('\\');
|
||||
FilePath.Upper();
|
||||
|
||||
File->Read(&ListSize,sizeof(int));
|
||||
|
||||
// New Style rel storage
|
||||
for (int i=0;i<ListSize;i++)
|
||||
{
|
||||
char c=1;
|
||||
GString FullName;//=FilePath;
|
||||
|
||||
while (c)
|
||||
{
|
||||
File->Read(&c,1);
|
||||
FullName.Append(c);
|
||||
}
|
||||
FullName.Upper();
|
||||
GFName::makeabsolute(FilePath,FullName,FixPath);
|
||||
FullName=FixPath;
|
||||
_fullpath( FixPath, FullName, 1024);
|
||||
for (int z=0; z<strlen(FixPath); z++)
|
||||
{// Invalidate any long name short cackness
|
||||
if (FixPath[z]=='~') FixPath[z]='_';
|
||||
}
|
||||
FullName=FixPath;
|
||||
|
||||
CheckFilename(FullName);
|
||||
FullName.Upper();
|
||||
AddSet(FullName);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemBank::Save(CFile *File)
|
||||
{
|
||||
int ListSize=SetList.size();
|
||||
GFName RootPath=File->GetFilePath();
|
||||
GString SavePath;
|
||||
|
||||
SavePath=RootPath.Drive();
|
||||
SavePath+=RootPath.Dir();
|
||||
SavePath.Append('\\');
|
||||
|
||||
SavePath.Upper();
|
||||
|
||||
File->Write(&ListSize,sizeof(int));
|
||||
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
char Filename[256+64];
|
||||
RootPath.makerelative(SavePath,SetList[i].GetFilename(),Filename);
|
||||
File->Write(Filename,strlen(Filename)+1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemBank::AddSet(const char *Filename)
|
||||
{
|
||||
int ListSize=SetList.size();
|
||||
CElemSet NewSet(Filename,ListSize);
|
||||
|
||||
SetList.Add(NewSet);
|
||||
if (SetList.size()!=ListSize) LoadFlag=TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemBank::LoadAllSets(CCore *Core)
|
||||
{
|
||||
int ListSize=SetList.size();
|
||||
|
||||
if (!LoadFlag) return;
|
||||
|
||||
for (int i=0;i<ListSize;i++)
|
||||
{
|
||||
CElemSet &ThisSet=SetList[i];
|
||||
|
||||
if (!ThisSet.IsLoaded()) ThisSet.Load(Core);
|
||||
}
|
||||
LoadFlag=false;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemBank::LoadNewSet(CCore *Core)
|
||||
{
|
||||
char BASED_CODE GinFilter[]= "All Tile Files (*.Gin; *.Bmp)|*.gin;*.Bmp|3d Tile Files (*.Gin)|*.Gin|2d Tile Files (*.Bmp)|*.Bmp|All Files (*.*)|*.*||";
|
||||
CFileDialog Dlg(TRUE,"Gin",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,GinFilter);
|
||||
|
||||
if (Dlg.DoModal()!=IDOK) return;
|
||||
|
||||
char Filename[256];
|
||||
sprintf(Filename,"%s",Dlg.GetPathName());
|
||||
AddSet(Filename);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemBank::ReloadAllSets()
|
||||
{
|
||||
int ListSize=SetList.size();
|
||||
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
SetList[i].Purge();
|
||||
}
|
||||
|
||||
LoadFlag=TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CElemBank::DeleteSet(int Set)
|
||||
{
|
||||
SetList.erase(Set);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
CElem &CElemBank::GetElem(int Set,int Elem)
|
||||
{
|
||||
ASSERT(Set>=0 && Elem>=0);
|
||||
return(SetList[Set].GetElem(Elem));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CElemBank::IsValid(int Set,int Elem)
|
||||
{
|
||||
if (Set<0 || Elem<0) return(false);
|
||||
if (Elem==0) return(true);
|
||||
ASSERT(Set<SetList.size());
|
||||
return(SetList[Set].IsValid(Elem));
|
||||
}
|
||||
|
||||
|
|
|
@ -33,62 +33,135 @@ public:
|
|||
{
|
||||
ElemType2d=0,
|
||||
ElemType3d,
|
||||
ElemTypeMax
|
||||
};
|
||||
enum ElemEnums
|
||||
enum
|
||||
{
|
||||
PCTexWidth =16,
|
||||
PCTexHeight =PCTexWidth,
|
||||
UnitSize=16,
|
||||
};
|
||||
|
||||
// CElem();
|
||||
CElem(int Blank,int Width=PCTexWidth,int Height=PCTexHeight ); // Blank (2d)
|
||||
CElem(CCore *Core,const char *Filename,int TexId,int XOfs,int YOfs); // 2d elem
|
||||
CElem(int Width,int Height); // Blank (2d)
|
||||
CElem(CCore *Core,const char *Filename,int TexId,int XOfs,int YOfs,int Width,int Height); // 2d elem
|
||||
CElem(CCore *Core,const char *Filename,CScene &ThisScene,int Node); // 3d elem
|
||||
|
||||
void CleanUp();
|
||||
void Purge();
|
||||
void Render(int Flags,bool Render3d);
|
||||
|
||||
int GetPCTexW() {return(PCTexWidth);}
|
||||
int GetPCTexH() {return(PCTexHeight);}
|
||||
u8 *GetPCTexRGB() {return(PCTexRGB);}
|
||||
int GetElemWidth() {return(ElemWidth);}
|
||||
int GetElemHeight() {return(ElemHeight);}
|
||||
u8 *GetElemRGB() {return(ElemRGB);}
|
||||
|
||||
bool IsValid() {return(ValidFlag);}
|
||||
|
||||
bool IsElem3d() {return(Type==ElemType3d);}
|
||||
int GetTexXOfs() {return(TexXOfs);}
|
||||
int GetTexYOfs() {return(TexYOfs);}
|
||||
int GetTexID() {return(Tex2dID);}
|
||||
|
||||
void CreateBlankTileGfx();
|
||||
void CreateInvalidTileGfx();
|
||||
|
||||
std::vector<sTriFace> &GetTriList() {return(TriList);}
|
||||
|
||||
protected:
|
||||
void Build3dElem(CTexCache &TexCache,CScene &ThisScene,int Node);
|
||||
void Build2dElem(CCore *Core,const char *Filename,int TexId);
|
||||
// void FixUp();
|
||||
void Build3dDrawList(CTexCache &TexCache,GLint &List);
|
||||
void Build2dDrawList(CTexCache &TexCache,GLint &List);
|
||||
|
||||
void RenderElem4Texture(sRGBData &RGBData);
|
||||
void Create2dTexture(CTexCache &TexCache,const char *Filename,int ID);
|
||||
bool CheckHasData(sRGBData &RGBData);
|
||||
|
||||
void Calc3dSize();
|
||||
GString SetPath;
|
||||
|
||||
std::vector<sTriFace> TriList;
|
||||
|
||||
|
||||
Vector3 Ofs;
|
||||
int Width,Height;
|
||||
|
||||
GLint DrawList[2];
|
||||
GLint DrawList[ElemTypeMax];
|
||||
ElemType Type;
|
||||
bool ValidFlag;
|
||||
int TexXOfs,TexYOfs;
|
||||
int Tex2dID;
|
||||
|
||||
// char PCTexName[256];
|
||||
int PCTexID;
|
||||
u8 *PCTexRGB;
|
||||
int ElemWidth,ElemHeight;
|
||||
float UnitWidth,UnitHeight;
|
||||
int ElemID;
|
||||
u8 *ElemRGB;
|
||||
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
class CElemSet
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
DEF_ELEMWIDTH=16,
|
||||
DEF_ELEMHEIGHT=16,
|
||||
DEF_ELEMBROWSWEWIDTH=8,
|
||||
};
|
||||
|
||||
CElemSet(const char *_Filename,int Idx,int Width=DEF_ELEMWIDTH,int Height=DEF_ELEMHEIGHT);
|
||||
~CElemSet();
|
||||
|
||||
int IsLoaded() {return(Loaded);}
|
||||
int GetCount() {return(ElemList.size());}
|
||||
|
||||
void Load(CCore *Core);
|
||||
|
||||
const char *GetFilename() {return(Filename);}
|
||||
const char *GetName() {return(Name);}
|
||||
int GetBrowserWidth() {return(ElemBrowserWidth);}
|
||||
|
||||
void RenderElem(int Elem,int Flags,bool Render3d) {ElemList[Elem].Render(Flags,Render3d);}
|
||||
CElem &GetElem(int No) {return(ElemList[No]);}
|
||||
void Purge();
|
||||
bool IsValid(int No);
|
||||
|
||||
bool operator==(CElemSet const &v1) {return (Name==v1.Name);}
|
||||
|
||||
private:
|
||||
void Load2d(CCore *Core);
|
||||
void Load3d(CCore *Core);
|
||||
|
||||
CPoint GetElemPos(int ID);
|
||||
|
||||
GString Filename,Name;
|
||||
|
||||
int SetNumber;
|
||||
int DefWidth,DefHeight;
|
||||
CList<CElem> ElemList;
|
||||
bool Loaded;
|
||||
int ElemBrowserWidth;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
class CElemBank
|
||||
{
|
||||
public:
|
||||
CElemBank();
|
||||
~CElemBank();
|
||||
|
||||
void Load(CFile *File,int Version);
|
||||
void Save(CFile *File);
|
||||
|
||||
void AddSet(const char *Filename);
|
||||
void LoadAllSets(CCore *Core);
|
||||
void LoadNewSet(CCore *Core);
|
||||
void ReloadAllSets();
|
||||
void DeleteSet(int Set);
|
||||
int NeedLoad() {return(LoadFlag);}
|
||||
CElem &GetElem(int Set,int Elem);
|
||||
bool IsValid(int Set,int Elem);
|
||||
|
||||
int GetSetCount() {return(SetList.size());}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
CList<CElemSet> SetList;
|
||||
bool LoadFlag;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "Core.h"
|
||||
#include "TexCache.h"
|
||||
#include "TileSet.h"
|
||||
#include "Tile.h"
|
||||
#include "Elem.h"
|
||||
|
||||
#include "Layer.h"
|
||||
#include "LayerTile.h"
|
||||
|
@ -30,6 +30,11 @@ CExport::CExport(char *Filename)
|
|||
// Write Dummy File Header
|
||||
|
||||
fwrite(&FileHdr,sizeof(sExpFileHdr),1,File);
|
||||
|
||||
// Add blank tile
|
||||
|
||||
sExpTile BlankElem={0,0,0,0,0,0,0};
|
||||
AddTile(BlankElem);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -81,8 +86,10 @@ void CExport::ExportTiles(CCore *Core)
|
|||
int ListSize,i;
|
||||
CTileBank *TileBank=Core->GetTileBank();
|
||||
|
||||
FileHdr.TileW=TileBank->GetTile(1,0).GetPCTexW();
|
||||
FileHdr.TileH=TileBank->GetTile(1,0).GetPCTexH();
|
||||
//!! FileHdr.TileW=TileBank->GetTile(0,0).GetElemWidth();
|
||||
//!! FileHdr.TileH=TileBank->GetTile(0,0).GetElemHeight();
|
||||
FileHdr.TileW=16;
|
||||
FileHdr.TileH=16;
|
||||
|
||||
// Write Tiles
|
||||
ListSize=UsedTileList.size();
|
||||
|
@ -108,37 +115,32 @@ CTileBank *TileBank=Core->GetTileBank();
|
|||
void CExport::ExportTile(CCore *Core,sExpTile &OutTile)
|
||||
{
|
||||
CTileBank *TileBank=Core->GetTileBank();
|
||||
CTile &ThisTile=TileBank->GetTile(OutTile.Set,OutTile.Tile);
|
||||
int RGBW=ThisTile.GetPCTexW();
|
||||
int RGBH=ThisTile.GetPCTexH();
|
||||
u8 *RGB=ThisTile.GetPCTexRGB();
|
||||
GString SetName=TileBank->GetSet(OutTile.Set).GetFilename();
|
||||
|
||||
if (ThisTile.IsTile3d())
|
||||
if (OutTile.Set==0 && OutTile.Tile==0)
|
||||
{
|
||||
ExportTile3d(Core,ThisTile,OutTile);
|
||||
char c=0;
|
||||
|
||||
fwrite(&OutTile,sizeof(sExpTile),1,File);
|
||||
fwrite(&c,1,16*16*3,File); // Write RGB
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
// change set name to set mappping
|
||||
if (OutTile.Set==0)
|
||||
{
|
||||
SetName="BLANK";
|
||||
}
|
||||
CElem &ThisTile=TileBank->GetTile(OutTile.Set,OutTile.Tile);
|
||||
GString SetName=TileBank->GetSetFilename(OutTile.Set);
|
||||
|
||||
ASSERT(ThisTile.GetElemWidth()==FileHdr.TileW);
|
||||
ASSERT(ThisTile.GetElemHeight()==FileHdr.TileH);
|
||||
if (ThisTile.IsElem3d()) ExportTile3d(Core,ThisTile,OutTile);
|
||||
OutTile.Set=SetNames.Add(SetName);
|
||||
fwrite(&OutTile,sizeof(sExpTile),1,File);
|
||||
// Write RGB
|
||||
ASSERT(RGBW==FileHdr.TileW);
|
||||
ASSERT(RGBH==FileHdr.TileH);
|
||||
fwrite(RGB,RGBW*RGBH*3,1,File);
|
||||
fwrite(ThisTile.GetElemRGB(),FileHdr.TileW*FileHdr.TileH*3,1,File); // Write RGB
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CExport::ExportTile3d(CCore *Core,CTile &ThisTile,sExpTile &OutTile)
|
||||
void CExport::ExportTile3d(CCore *Core,CElem &ThisTile,sExpTile &OutTile)
|
||||
{
|
||||
CTexCache &TexCache=Core->GetTexCache();
|
||||
std::vector<sTriFace> &TileTriList=ThisTile.GetTriList();
|
||||
|
@ -185,6 +187,7 @@ char RelStr[256];
|
|||
ThisFile.Upper();
|
||||
GFName::makerelative(SavePath,ThisFile,RelStr);
|
||||
fwrite(RelStr,strlen(RelStr)+1,1,File);
|
||||
TRACE2("Set %i:%s\n",i,RelStr);
|
||||
}
|
||||
// Tex List
|
||||
ListSize=TexNames.size();
|
||||
|
@ -197,6 +200,7 @@ char RelStr[256];
|
|||
ThisFile.Upper();
|
||||
GFName::makerelative(SavePath,ThisFile,RelStr);
|
||||
fwrite(RelStr,strlen(RelStr)+1,1,File);
|
||||
TRACE2("Tex %i:%s\n",i,RelStr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ public:
|
|||
|
||||
protected:
|
||||
void ExportTile(CCore *Core,sExpTile &ThisElem);
|
||||
void ExportTile3d(CCore *Core,CTile &ThisTile,sExpTile &OutTile);
|
||||
void ExportTile2d(CCore *Core,CTile &ThisTile,sExpTile &OutTile);
|
||||
void ExportTile3d(CCore *Core,CElem &ThisTile,sExpTile &OutTile);
|
||||
void ExportTile2d(CCore *Core,CElem &ThisTile,sExpTile &OutTile);
|
||||
|
||||
sExpFileHdr FileHdr;
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
#define __EXPORT_STRUCTS_HEADER__
|
||||
|
||||
#include <Vector>
|
||||
//#include "GinTex.h"
|
||||
//#include "Tile.h"
|
||||
|
||||
#include <List.h>
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ int CLayer::InfoTableSize=sizeof(InfoTable)/sizeof(sLayerInfoTable);
|
|||
CLayer::CLayer()
|
||||
{
|
||||
SubView=0;
|
||||
LayerCam=DefaultCamPos;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -78,16 +78,17 @@ virtual void GUIKill(CCore *Core)=0;
|
|||
virtual void GUIUpdate(CCore *Core)=0;
|
||||
virtual void GUIChanged(CCore *Core)=0;
|
||||
|
||||
virtual int GetWidth()=0;
|
||||
virtual int GetHeight()=0;
|
||||
virtual int GetWidth() {return(-1);}
|
||||
virtual int GetHeight() {return(-1);}
|
||||
virtual void CheckLayerSize(int Width,int Height){};
|
||||
virtual bool Resize(int Width,int Height)=0;
|
||||
virtual bool Resize(int Width,int Height) {return(false);}
|
||||
|
||||
virtual void Load(CFile *File,int Version)=0;
|
||||
virtual void Save(CFile *File)=0;
|
||||
|
||||
virtual void Export(CCore *Core,CExport &Exp)=0;
|
||||
|
||||
virtual Vector3 &GetCam() {return(LayerCam);}
|
||||
|
||||
// Functions
|
||||
virtual bool LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag){return(false);}
|
||||
|
@ -103,6 +104,8 @@ protected:
|
|||
bool VisibleFlag;
|
||||
CSelect Selection;
|
||||
CLayer *SubView;
|
||||
Vector3 LayerCam;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#include "Select.h"
|
||||
#include "Export.h"
|
||||
|
||||
// Reserve slot 0 for collision :o)
|
||||
GString ColFName="Collision.bmp";
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -31,6 +34,7 @@ CLayerCollision::CLayerCollision(int _SubType,int Width,int Height)
|
|||
SetDefaultParams();
|
||||
Mode=MouseModePaint;
|
||||
Map.SetSize(Width,Height,TRUE);
|
||||
VisibleFlag=true;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -43,6 +47,32 @@ CLayerCollision::CLayerCollision(CFile *File,int Version)
|
|||
/*****************************************************************************/
|
||||
CLayerCollision::~CLayerCollision()
|
||||
{
|
||||
delete TileBank;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerCollision::InitSubView(CCore *Core)
|
||||
{
|
||||
TileBank=new CTileBank;
|
||||
SubView=TileBank;
|
||||
|
||||
GFName ExePath;
|
||||
GString Filename;
|
||||
|
||||
// Get application path
|
||||
#ifdef _DEBUG
|
||||
ExePath="C:\\Spongebob\\tools\\mapedit\\";
|
||||
#else
|
||||
char ExeFilename[2048];
|
||||
GetModuleFileName(GetModuleHandle(NULL),ExeFilename,2048);
|
||||
ExePath=ExeFilename;
|
||||
ExePath.File(0);
|
||||
ExePath.Ext(0);
|
||||
#endif
|
||||
Filename=ExePath.FullName();
|
||||
Filename+=ColFName;
|
||||
TileBank->AddSet(Filename);
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -81,7 +111,7 @@ void CLayerCollision::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
|
|||
{
|
||||
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
||||
|
||||
CLayerTile::Render(Core,ThisCam,Map,FALSE,0.5f);
|
||||
CLayerTile::Render(Core,ThisCam,Map,false,0.5f);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -162,19 +192,3 @@ int Height=Map.GetHeight();
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
void CLayerCollision::DeleteSet(int Set)
|
||||
{
|
||||
Map.DeleteSet(Set);
|
||||
}
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
void CLayerCollision::RemapSet(int OrigSet,int NewSet)
|
||||
{
|
||||
Map.RemapSet(OrigSet,NewSet);
|
||||
|
||||
}
|
||||
*/
|
|
@ -20,6 +20,7 @@ public:
|
|||
~CLayerCollision();
|
||||
|
||||
int GetType() {return(LAYER_TYPE_COLLISION);}
|
||||
void InitSubView(CCore *Core);
|
||||
|
||||
void Render(CCore *Core,Vector3 &CamPos,bool Is3d);
|
||||
|
||||
|
@ -38,7 +39,7 @@ public:
|
|||
void DeleteSet(int Set);
|
||||
void RemapSet(int OrigSet,int NewSet);
|
||||
protected:
|
||||
|
||||
void InitTileBank();
|
||||
|
||||
CLayerCollisionGUI CollisionGUI;
|
||||
|
||||
|
|
|
@ -110,11 +110,11 @@ void CLayerTile::Save(CFile *File)
|
|||
void CLayerTile::InitSubView(CCore *Core)
|
||||
{
|
||||
// Fix up shared layers
|
||||
if (!SubView)
|
||||
if (SubType!=LAYER_SUBTYPE_ACTION)
|
||||
{
|
||||
SubView=Core->FindSubView(LAYER_SUBVIEW_TILEBANK);
|
||||
TileBank=Core->GetTileBank();
|
||||
SubView=(CLayer*)TileBank;
|
||||
}
|
||||
TileBank=(CTileBank*)SubView;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -154,16 +154,8 @@ void CLayerTile::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
|
|||
{
|
||||
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
||||
|
||||
if (Is3d && Render3dFlag)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
Render(Core,ThisCam,Map,TRUE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
else
|
||||
{
|
||||
Render(Core,ThisCam,Map,FALSE);
|
||||
}
|
||||
Is3d&=Render3dFlag;
|
||||
Render(Core,ThisCam,Map,Is3d);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -211,6 +203,8 @@ int StartY=(int)ThisCam.y;
|
|||
float ShiftX=ThisCam.x - (int)ThisCam.x;
|
||||
float ShiftY=ThisCam.y - (int)ThisCam.y;
|
||||
|
||||
if (TileBank->NeedLoad()) TileBank->LoadAllSets(Core);
|
||||
|
||||
if (StartX<0) StartX=0;
|
||||
if (StartY<0) StartY=0;
|
||||
|
||||
|
@ -251,12 +245,10 @@ int DrawH=ZoomH+8;
|
|||
}
|
||||
|
||||
sMapElem &ThisElem=ThisMap.Get(XPos,YPos);
|
||||
if (ThisElem.Tile && TileBank->IsTileValid(ThisElem.Set,ThisElem.Tile))
|
||||
{ // Render Non Zero Tiles
|
||||
CTile &ThisTile=TileBank->GetTile(ThisElem.Set,ThisElem.Tile);
|
||||
|
||||
if (ThisElem.Tile>0)
|
||||
{ // Render Non Zero and Valid Tiles
|
||||
glColor4f(1,1,1,Alpha); // Set default Color
|
||||
ThisTile.Render(ThisElem.Flags,Render3d);
|
||||
TileBank->RenderTile(ThisElem.Set,ThisElem.Tile,ThisElem.Flags,Render3d);
|
||||
}
|
||||
glTranslatef(1.0f,0,0); // Next X
|
||||
}
|
||||
|
@ -584,6 +576,7 @@ bool Ret=false;
|
|||
case CmdMsg_ActiveBrushLeft:
|
||||
case CmdMsg_ActiveBrushRight:
|
||||
Ret=TileBank->Command(CmdMsg,Core,Param0,Param1);
|
||||
break;
|
||||
default:
|
||||
TRACE3("LayerTile-Unhandled Command %i (%i,%i)\n",CmdMsg,Param0,Param1);
|
||||
}
|
||||
|
@ -634,7 +627,6 @@ bool CLayerTile::MirrorX(CCore *Core)
|
|||
/*****************************************************************************/
|
||||
bool CLayerTile::MirrorY(CCore *Core)
|
||||
{
|
||||
// if (GetType()==LAYER_TYPE_COLLISION) return(false);
|
||||
switch(Mode)
|
||||
{
|
||||
case MouseModePaint:
|
||||
|
@ -714,7 +706,7 @@ CRect Rect=Selection.GetRect();
|
|||
|
||||
bool CLayerTile::Paint(CMap &Blk,CPoint &CursorPos)
|
||||
{
|
||||
if (CursorPos.y==-1 || CursorPos.y==-1) return(FALSE); // Off Map?
|
||||
if (CursorPos.x==-1 || CursorPos.y==-1) return(FALSE); // Off Map?
|
||||
if (!Blk.IsValid()) return(FALSE); // Invalid tile?
|
||||
|
||||
Map.Set(CursorPos.x,CursorPos.y,Blk);
|
||||
|
@ -727,38 +719,45 @@ void CLayerTile::Export(CCore *Core,CExport &Exp)
|
|||
{
|
||||
int Width=Map.GetWidth();
|
||||
int Height=Map.GetHeight();
|
||||
sExpTile BlankElem={0,0,0,0};
|
||||
|
||||
Exp.ExportLayerHeader(LAYER_TYPE_TILE,SubType,Width,Height);
|
||||
|
||||
Exp.AddTile(BlankElem); // Ensure blank tile is present
|
||||
|
||||
for (int Y=0; Y<Height; Y++)
|
||||
{
|
||||
for (int X=0; X<Width; X++)
|
||||
{
|
||||
sMapElem &MapElem=Map.Get(X,Y);
|
||||
CTile &ThisTile=TileBank->GetTile(MapElem.Set,MapElem.Tile);
|
||||
sExpLayerTile OutElem;
|
||||
|
||||
if (MapElem.Set==0 && MapElem.Tile==0)
|
||||
{ // Blank
|
||||
OutElem.Tile=0;
|
||||
OutElem.Flags=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
sExpTile OutTile;
|
||||
CElem &ThisTile=TileBank->GetTile(MapElem.Set,MapElem.Tile);
|
||||
|
||||
OutTile.Set=MapElem.Set;
|
||||
OutTile.Tile=MapElem.Tile;
|
||||
OutTile.TriStart=0;
|
||||
OutTile.TriCount=0;
|
||||
OutTile.XOfs=ThisTile.GetTexXOfs();
|
||||
OutTile.YOfs=ThisTile.GetTexYOfs();
|
||||
|
||||
OutElem.Tile=Exp.AddTile(OutTile);
|
||||
OutElem.Flags=MapElem.Flags;
|
||||
}
|
||||
|
||||
Exp.Write(&OutElem,sizeof(sExpLayerTile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayerTile::DeleteSet(int Set)
|
||||
void CLayerTile::RemoveSet(int Set)
|
||||
{
|
||||
Map.DeleteSet(Set);
|
||||
Map.RemoveSet(Set);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -68,7 +68,7 @@ virtual bool Command(int CmdMsg,CCore *Core,int Param0=0,int Param1=0);
|
|||
|
||||
// Local
|
||||
CTileBank *GetTileBank() {return(TileBank);}
|
||||
void DeleteSet(int Set);
|
||||
void RemoveSet(int Set);
|
||||
void RemapSet(int OrigSet,int NewSet);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -17,7 +17,7 @@ void CMap::Load(CFile *File,int Version)
|
|||
// Version 1
|
||||
int Width;
|
||||
int Height;
|
||||
int VFix=0; // Fix for colliison tileset
|
||||
int VFix=0; // Fix for New tileset shash
|
||||
|
||||
if (Version<2) VFix=1;
|
||||
|
||||
|
@ -33,6 +33,15 @@ int VFix=0; // Fix for colliison tileset
|
|||
sMapElem ThisElem;
|
||||
File->Read(&ThisElem,sizeof(sMapElem));
|
||||
ThisElem.Set+=VFix;
|
||||
if (Version==3)
|
||||
{
|
||||
ThisElem.Set--;
|
||||
if (ThisElem.Set<0)
|
||||
{
|
||||
ThisElem.Set=0;
|
||||
}
|
||||
}
|
||||
|
||||
Set(X,Y,ThisElem,TRUE);
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +321,7 @@ int MinH=min(Height,OldHeight);
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CMap::DeleteSet(int Set)
|
||||
void CMap::RemoveSet(int Set)
|
||||
{
|
||||
int Width=GetWidth();
|
||||
int Height=GetHeight();
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
void Load(CFile *File,int Version);
|
||||
void Save(CFile *File);
|
||||
|
||||
void DeleteSet(int Set);
|
||||
void RemoveSet(int Set);
|
||||
void RemapSet(int Old,int New);
|
||||
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ LINK32=link.exe
|
|||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /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" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\libs\glib" /I "..\libs\maths" /I "..\libs\davelib" /I "..\libs\ginlib" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG" /d "_AFXDLL"
|
||||
|
@ -160,6 +160,14 @@ SOURCE=.\Core.h
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Elem.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Elem.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Map.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -176,14 +184,6 @@ SOURCE=.\TexCache.h
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Tile.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Tile.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TileSet.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
#include "MainFrm.h"
|
||||
#include "LayerTileGui.h"
|
||||
|
||||
// Reserve slot 0 for collision :o)
|
||||
GString ColFName="Collision.bmp";
|
||||
|
||||
/*****************************************************************************/
|
||||
/*** TileBank ****************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -38,31 +35,13 @@ const float TileBrowserY1=1+TileBrowserGap/2;
|
|||
/*****************************************************************************/
|
||||
CTileBank::CTileBank()
|
||||
{
|
||||
GFName ExePath;
|
||||
GString Filename;
|
||||
|
||||
// Get application path
|
||||
#ifdef _DEBUG
|
||||
ExePath="C:\\Spongebob\\tools\\mapedit\\";
|
||||
#else
|
||||
char ExeFilename[2048];
|
||||
GetModuleFileName(GetModuleHandle(NULL),ExeFilename,2048);
|
||||
ExePath=ExeFilename;
|
||||
ExePath.File(0);
|
||||
ExePath.Ext(0);
|
||||
#endif
|
||||
Filename=ExePath.FullName();
|
||||
Filename+=ColFName;
|
||||
|
||||
LoadFlag=FALSE;
|
||||
LoadFlag=false;
|
||||
CurrentSet=0; LastSet=0;
|
||||
for (int i=0; i<MaxBrush; i++) Brush[i].Delete();
|
||||
LastCursorPos=CursorPos=-1;
|
||||
ActiveBrush=0;
|
||||
SelStart=-1;
|
||||
SelEnd=-1;
|
||||
TileSet.push_back(CTileSet(Filename,0));
|
||||
LoadFlag=TRUE;
|
||||
VisibleFlag=true;
|
||||
}
|
||||
|
||||
|
@ -71,22 +50,10 @@ CTileBank::~CTileBank()
|
|||
{
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::SetCollision(bool f)
|
||||
{
|
||||
LastSet=CurrentSet;
|
||||
if (f)
|
||||
{ // Is collision
|
||||
CurrentSet=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentSet=LastSet;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::Load(CFile *File,int Version)
|
||||
{
|
||||
if (Version<FileVersion)
|
||||
{
|
||||
int ListSize;
|
||||
GFName RootPath=File->GetFilePath();
|
||||
|
@ -112,7 +79,7 @@ char FixPath[1024];
|
|||
for (int i=0;i<ListSize;i++)
|
||||
{
|
||||
char c=1;
|
||||
GString FullName;//=FilePath;
|
||||
GString FullName;
|
||||
|
||||
while (c)
|
||||
{
|
||||
|
@ -131,15 +98,28 @@ char FixPath[1024];
|
|||
|
||||
CheckFilename(FullName);
|
||||
FullName.Upper();
|
||||
AddTileSet(FullName);
|
||||
AddSet(FullName);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
File->Read(&LayerCam,sizeof(Vector3));
|
||||
File->Read(&CurrentSet,sizeof(int));
|
||||
File->Read(&ActiveBrush,sizeof(int));
|
||||
Brush[0].Load(File,Version);
|
||||
Brush[1].Load(File,Version);
|
||||
|
||||
CElemBank::Load(File,Version);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::Save(CFile *File)
|
||||
{
|
||||
int ListSize=TileSet.size();
|
||||
int NewListSize=ListSize-1;
|
||||
int ListSize=GetSetCount();
|
||||
GFName RootPath=File->GetFilePath();
|
||||
GString SavePath;
|
||||
|
||||
|
@ -149,55 +129,23 @@ GString SavePath;
|
|||
|
||||
SavePath.Upper();
|
||||
|
||||
File->Write(&NewListSize,sizeof(int));
|
||||
File->Write(&LayerCam,sizeof(Vector3));
|
||||
File->Write(&CurrentSet,sizeof(int));
|
||||
File->Write(&ActiveBrush,sizeof(int));
|
||||
Brush[0].Save(File);
|
||||
Brush[1].Save(File);
|
||||
|
||||
for (int i=1; i<ListSize; i++)
|
||||
{
|
||||
CTileSet &ThisSet=TileSet[i];
|
||||
char Filename[256+64];
|
||||
|
||||
RootPath.makerelative(SavePath,ThisSet.GetFilename(),Filename);
|
||||
File->Write(Filename,strlen(Filename)+1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::AddTileSet(const char *Filename)
|
||||
{
|
||||
int ListSize=TileSet.size();
|
||||
CTileSet NewSet(Filename,ListSize);
|
||||
|
||||
TileSet.Add(NewSet);
|
||||
if (TileSet.size()!=ListSize) LoadFlag=TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::LoadTileSets(CCore *Core)
|
||||
{
|
||||
int ListSize=TileSet.size();
|
||||
|
||||
for (int i=0;i<ListSize;i++)
|
||||
{
|
||||
CTileSet &ThisSet=TileSet[i];
|
||||
|
||||
if (!ThisSet.IsLoaded()) ThisSet.Load(Core);
|
||||
}
|
||||
LoadFlag=FALSE;
|
||||
CElemBank::Save(File);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::DeleteCurrent()
|
||||
{
|
||||
int ListSize=TileSet.size();
|
||||
int ListSize=GetSetCount();
|
||||
// Remap Brushes
|
||||
for (int i=0; i<MaxBrush; i++)
|
||||
{
|
||||
Brush[i].DeleteSet(CurrentSet);
|
||||
Brush[i].RemoveSet(CurrentSet);
|
||||
}
|
||||
for (int Set=CurrentSet; Set<ListSize; Set++)
|
||||
{
|
||||
|
@ -206,65 +154,252 @@ int ListSize=TileSet.size();
|
|||
Brush[i].RemapSet(Set,Set);
|
||||
}
|
||||
}
|
||||
TileSet.erase(CurrentSet);
|
||||
CurrentSet=0;
|
||||
SetList.erase(CurrentSet);
|
||||
if (CurrentSet) CurrentSet--;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::ReloadAll()
|
||||
CPoint CTileBank::GetTilePos(int ID,int Width)
|
||||
{
|
||||
int ListSize=TileSet.size();
|
||||
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
TileSet[i].Purge();
|
||||
}
|
||||
|
||||
LoadFlag=TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
CTile &CTileBank::GetTile(int Bank,int Tile)
|
||||
{
|
||||
ASSERT(Bank>=0 && Tile>=0);
|
||||
return(TileSet[Bank].GetTile(Tile));
|
||||
if (ID==0)
|
||||
return(CPoint(-1,-1));
|
||||
else
|
||||
return(IDToPoint(ID-1,Width));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
|
||||
{
|
||||
if (!TileSet.size()) return; // No tiles, return
|
||||
if (!GetSetCount()) return;
|
||||
CElemSet &ThisSet=SetList[CurrentSet];
|
||||
int ListSize=ThisSet.GetCount();
|
||||
int BrowserWidth=ThisSet.GetBrowserWidth();
|
||||
int TileID=0;
|
||||
sMapElem ThisElem;
|
||||
int SelFlag;
|
||||
float Scale=CamPos.z/(float)BrowserWidth/2.0;
|
||||
|
||||
if (Is3d)
|
||||
ThisElem.Flags=0;
|
||||
ThisElem.Set=CurrentSet;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
while(TileID!=ListSize)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
TileSet[CurrentSet].Render(Core,CamPos,GetLBrush(),GetRBrush(),TRUE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
else
|
||||
CPoint Pos=GetTilePos(TileID,BrowserWidth);
|
||||
float XPos=(float)Pos.x*(1+TileBrowserGap);
|
||||
float YPos=(float)Pos.y*(1+TileBrowserGap);
|
||||
|
||||
glLoadIdentity();
|
||||
glScalef(Scale,Scale,Scale);
|
||||
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
|
||||
|
||||
glColor3f(1,1,1);
|
||||
ThisSet.RenderElem(TileID,0,Is3d);
|
||||
// Selection
|
||||
ThisElem.Tile=TileID;
|
||||
SelFlag=0;
|
||||
|
||||
if (Brush[0].DoesContainTile(ThisElem)) SelFlag|=1;
|
||||
if (Brush[1].DoesContainTile(ThisElem)) SelFlag|=2;
|
||||
|
||||
if (SelFlag)
|
||||
{
|
||||
TileSet[CurrentSet].Render(Core,CamPos,GetLBrush(),GetRBrush(),FALSE);
|
||||
glBegin(GL_QUADS);
|
||||
switch(SelFlag)
|
||||
{
|
||||
case 1: // L
|
||||
glColor4f(1,0,0,0.5);
|
||||
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
|
||||
break;
|
||||
case 2: // R
|
||||
glColor4f(0,0,1,0.5);
|
||||
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
|
||||
break;
|
||||
case 3: // LR
|
||||
glColor4f(1,0,0,0.5);
|
||||
BuildGLQuad(TileBrowserX0,0.5,TileBrowserY0,TileBrowserY1,0.01f);
|
||||
glColor4f(0,0,1,0.5);
|
||||
BuildGLQuad(0.5,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
|
||||
break;
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
TileID++;
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d)
|
||||
{
|
||||
TileSet[CurrentSet].RenderCursor(CamPos,CursorPos,SelStart,SelEnd);
|
||||
if (!GetSetCount()) return;
|
||||
CElemSet &ThisSet=SetList[CurrentSet];
|
||||
int ListSize=ThisSet.GetCount();
|
||||
int BrowserWidth=ThisSet.GetBrowserWidth();
|
||||
CPoint Start,End;
|
||||
int MaxTile=ListSize;
|
||||
float Scale=CamPos.z/(float)BrowserWidth/2.0;
|
||||
|
||||
if (CursorPos<-1 || CursorPos>ListSize) return;
|
||||
if (!ListSize) return;
|
||||
|
||||
|
||||
if (SelStart==-1)
|
||||
{
|
||||
Start=GetTilePos(CursorPos,BrowserWidth);
|
||||
End=Start;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
CPoint S=IDToPoint(SelStart-1,BrowserWidth);
|
||||
CPoint E=IDToPoint(SelEnd-1,BrowserWidth);
|
||||
|
||||
Start=CPoint( min(S.x,E.x), min(S.y,E.y));
|
||||
End=CPoint( max(S.x,E.x), max(S.y,E.y));
|
||||
if (PointToID(End,BrowserWidth)>=MaxTile) return; // Invalid selection
|
||||
}
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
for (int Y=Start.y; Y<=End.y; Y++)
|
||||
{
|
||||
for (int X=Start.x; X<=End.x; X++)
|
||||
{
|
||||
float XPos=(float)X*(1+TileBrowserGap);
|
||||
float YPos=(float)Y*(1+TileBrowserGap);
|
||||
|
||||
glLoadIdentity();
|
||||
glScalef(Scale,Scale,Scale);
|
||||
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
|
||||
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(1,1,0,0.5);
|
||||
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0);
|
||||
glEnd();
|
||||
|
||||
}
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::RenderGrid(CCore *Core,Vector3 &CamPos,bool Active)
|
||||
{
|
||||
TileSet[CurrentSet].RenderGrid(Core,CamPos,Active);
|
||||
if (!GetSetCount()) return;
|
||||
CElemSet &ThisSet=SetList[CurrentSet];
|
||||
int ListSize=ThisSet.GetCount();
|
||||
int BrowserWidth=ThisSet.GetBrowserWidth();
|
||||
int TileID=1; // Dont bother with blank, its sorted
|
||||
float Scale=CamPos.z/(float)BrowserWidth/2.0;
|
||||
|
||||
if (!ListSize) return;
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
while(TileID!=ListSize)
|
||||
{
|
||||
CPoint Pos=GetTilePos(TileID,BrowserWidth);
|
||||
float XPos=(float)Pos.x*(1+TileBrowserGap);
|
||||
float YPos=(float)Pos.y*(1+TileBrowserGap);
|
||||
|
||||
glLoadIdentity();
|
||||
glScalef(Scale,Scale,Scale);
|
||||
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1,1,1);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY0,0);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY1,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY1,0);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX0,TileBrowserY1,0);
|
||||
|
||||
glVertex3f( TileBrowserX1,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY1,0);
|
||||
|
||||
glEnd();
|
||||
|
||||
TileID++;
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos)
|
||||
{
|
||||
if (!TileSet.size()) return; // No tiles, return
|
||||
if (!GetSetCount()) return;
|
||||
CElemSet &ThisSet=SetList[CurrentSet];
|
||||
int ListSize=ThisSet.GetCount();
|
||||
int BrowserWidth=ThisSet.GetBrowserWidth();
|
||||
GLint Viewport[4];
|
||||
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
|
||||
int HitCount;
|
||||
int TileID=0;
|
||||
float Scale=CamPos.z/(float)BrowserWidth/2.0;
|
||||
|
||||
CursorPos=TileSet[CurrentSet].FindCursorPos(Core,CamPos,MousePos);
|
||||
if (!ListSize) return;
|
||||
glGetIntegerv(GL_VIEWPORT, Viewport);
|
||||
glSelectBuffer (SELECT_BUFFER_SIZE, SelectBuffer );
|
||||
glRenderMode (GL_SELECT);
|
||||
|
||||
glInitNames();
|
||||
glPushName(-1);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluPickMatrix( MousePos.x ,(Viewport[3]-MousePos.y),5.0,5.0,Viewport);
|
||||
Core->GetView()->SetupPersMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
while(TileID!=ListSize)
|
||||
{
|
||||
CPoint Pos=GetTilePos(TileID,BrowserWidth);
|
||||
float XPos=(float)Pos.x*(1+TileBrowserGap);
|
||||
float YPos=(float)Pos.y*(1+TileBrowserGap);
|
||||
|
||||
glLoadIdentity();
|
||||
glScalef(Scale,Scale,Scale);
|
||||
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
|
||||
|
||||
glLoadName (TileID);
|
||||
glBegin (GL_QUADS);
|
||||
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0);
|
||||
glEnd();
|
||||
TileID++;
|
||||
}
|
||||
|
||||
HitCount= glRenderMode (GL_RENDER);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
// Process hits
|
||||
|
||||
GLuint *HitPtr=SelectBuffer;
|
||||
|
||||
TileID=-2;
|
||||
if (HitCount) // Just take 1st
|
||||
{
|
||||
TileID=HitPtr[3];
|
||||
}
|
||||
glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert
|
||||
|
||||
CursorPos=TileID;
|
||||
SelEnd=CursorPos;
|
||||
}
|
||||
|
||||
|
@ -307,17 +442,17 @@ bool CTileBank::Command(int CmdMsg,CCore *Core,int Param0,int Param1)
|
|||
switch(CmdMsg)
|
||||
{
|
||||
case CmdMsg_SubViewLoad:
|
||||
LoadSet(Core);
|
||||
LoadNewSet(Core);
|
||||
break;
|
||||
case CmdMsg_SubViewDelete:
|
||||
DeleteSet(Core);
|
||||
break;
|
||||
case CmdMsg_SubViewUpdate:
|
||||
ReloadAll();
|
||||
ReloadAllSets();
|
||||
Core->GetTexCache().Purge();
|
||||
break;
|
||||
case CmdMsg_SubViewSet:
|
||||
CurrentSet=TileBankGUI.m_List.GetCurSel()+1;
|
||||
CurrentSet=TileBankGUI.m_List.GetCurSel();
|
||||
break;
|
||||
case CmdMsg_ActiveBrushLeft:
|
||||
ActiveBrush=LBrush;
|
||||
|
@ -347,19 +482,19 @@ void CTileBank::GUIKill(CCore *Core)
|
|||
/*****************************************************************************/
|
||||
void CTileBank::GUIUpdate(CCore *Core)
|
||||
{
|
||||
int ListSize=TileSet.size();
|
||||
bool IsSubView=true;//Core->IsSubView();
|
||||
int ListSize=GetSetCount();
|
||||
bool IsSubView=true;
|
||||
|
||||
if (TileBankGUI.m_List)
|
||||
{
|
||||
TileBankGUI.m_List.ResetContent();
|
||||
if (ListSize-1)
|
||||
if (ListSize)
|
||||
{
|
||||
for (int i=1; i<ListSize; i++)
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
TileBankGUI.m_List.AddString(TileSet[i].GetName());
|
||||
TileBankGUI.m_List.AddString(GetSetName(i));
|
||||
}
|
||||
TileBankGUI.m_List.SetCurSel(CurrentSet-1);
|
||||
TileBankGUI.m_List.SetCurSel(CurrentSet);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -367,6 +502,7 @@ bool IsSubView=true;//Core->IsSubView();
|
|||
}
|
||||
TileBankGUI.m_List.EnableWindow(IsSubView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -383,6 +519,8 @@ bool CTileBank::Select(int BrushID,bool DownFlag)
|
|||
{
|
||||
if (CursorPos<0) return(FALSE);
|
||||
SelStart=CursorPos;
|
||||
TRACE1("SEL Start %i\n",CursorPos);
|
||||
|
||||
if (CursorPos==0)
|
||||
{
|
||||
SetBrush(GetBrush(BrushID));
|
||||
|
@ -399,7 +537,7 @@ bool CTileBank::Select(int BrushID,bool DownFlag)
|
|||
SetBrush(GetBrush(BrushID));
|
||||
|
||||
SelStart=-1;
|
||||
TRACE0("END SEL\n");
|
||||
TRACE1("END SEL %i\n",CursorPos);
|
||||
}
|
||||
|
||||
return(TRUE);
|
||||
|
@ -408,7 +546,7 @@ bool CTileBank::Select(int BrushID,bool DownFlag)
|
|||
/*****************************************************************************/
|
||||
void CTileBank::SetBrush(CMap &ThisBrush)
|
||||
{
|
||||
int BW=TileSet[CurrentSet].GetTileBrowserWidth();
|
||||
int BW=SetList[CurrentSet].GetBrowserWidth();
|
||||
CPoint S=IDToPoint(SelStart-1,BW);
|
||||
CPoint E=IDToPoint(SelEnd-1,BW);
|
||||
|
||||
|
@ -416,7 +554,7 @@ int Width=abs(E.x-S.x)+1;
|
|||
int Height=abs(E.y-S.y)+1;
|
||||
|
||||
sMapElem ThisElem;
|
||||
int MaxTile=TileSet[CurrentSet].GetTileCount();
|
||||
int MaxTile=SetList[CurrentSet].GetCount();
|
||||
|
||||
// if (PointToID(End,BW)>=MaxTile) SelectCancel(); // Invalid selection
|
||||
|
||||
|
@ -431,14 +569,14 @@ int MaxTile=TileSet[CurrentSet].GetTileCount();
|
|||
for (int X=0; X<Width; X++)
|
||||
{
|
||||
ThisElem.Tile=SelStart+X+(Y*BW);
|
||||
if (!IsTileValid(CurrentSet,ThisElem.Tile))
|
||||
if (!IsValid(CurrentSet,ThisElem.Tile))
|
||||
{
|
||||
TRACE2("Not valid %i %i\n",CurrentSet,ThisElem.Tile);
|
||||
ThisElem.Tile=-1;
|
||||
}
|
||||
ThisBrush.Set(X,Y,ThisElem,TRUE);
|
||||
ThisBrush.Set(X,Y,ThisElem,true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -449,30 +587,6 @@ bool CTileBank::SelectCancel()
|
|||
return(TRUE);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CTileBank::IsTileValid(int Set,int Tile)
|
||||
{
|
||||
if (Set<0 || Tile<0) return(FALSE);
|
||||
if (Tile==0) return(TRUE);
|
||||
ASSERT(Set<TileSet.size());
|
||||
|
||||
return(TileSet[Set].IsTileValid(Tile));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::LoadSet(CCore *Core)
|
||||
{
|
||||
char BASED_CODE GinFilter[]= "All Tile Files (*.Gin; *.Bmp)|*.gin;*.Bmp|3d Tile Files (*.Gin)|*.Gin|2d Tile Files (*.Bmp)|*.Bmp|All Files (*.*)|*.*||";
|
||||
CFileDialog Dlg(TRUE,"Gin",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,GinFilter);
|
||||
|
||||
if (Dlg.DoModal()!=IDOK) return;
|
||||
|
||||
char Filename[256];
|
||||
sprintf(Filename,"%s",Dlg.GetPathName());
|
||||
AddTileSet(Filename);
|
||||
GUIUpdate(Core);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileBank::DeleteSet(CCore *Core)
|
||||
{
|
||||
|
@ -486,7 +600,7 @@ void CTileBank::DeleteSet(CCore *Core)
|
|||
CLayerTile *ThisLayer=(CLayerTile*)Core->GetLayer(i);
|
||||
if (ThisLayer->GetType()==LAYER_TYPE_TILE)
|
||||
{
|
||||
ThisLayer->DeleteSet(CurrentSet);
|
||||
ThisLayer->RemoveSet(CurrentSet);
|
||||
}
|
||||
}
|
||||
DeleteCurrent();
|
||||
|
@ -508,394 +622,3 @@ void CTileBank::DeleteSet(CCore *Core)
|
|||
GUIUpdate(Core);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*** TileSet *****************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
CTileSet::CTileSet(const char *_Filename,int Idx)
|
||||
{
|
||||
GFName FName=_Filename;
|
||||
|
||||
Filename=_Filename;
|
||||
Name=FName.File();
|
||||
|
||||
Loaded=FALSE;
|
||||
SetNumber=Idx;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
CTileSet::~CTileSet()
|
||||
{
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
void CTileSet::Load(CCore *Core)
|
||||
{
|
||||
GFName FName=Filename;
|
||||
GString Ext=FName.Ext();
|
||||
Ext.Upper();
|
||||
|
||||
if (Ext=="GIN")
|
||||
{
|
||||
Load3d(Core);
|
||||
}
|
||||
else
|
||||
{
|
||||
Load2d(Core);
|
||||
}
|
||||
|
||||
Loaded=TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void CTileSet::Load2d(CCore *Core)
|
||||
{
|
||||
CTexCache &TexCache=Core->GetTexCache();
|
||||
GString ColTest;
|
||||
int TexID=TexCache.ProcessTexture(Filename,0);
|
||||
sTex &ThisTex=TexCache.GetTex(TexID);
|
||||
|
||||
int Width=ThisTex.TexWidth/16;
|
||||
int Height=ThisTex.TexHeight/16;
|
||||
|
||||
// TRACE3("Load 2d TileBank %s (%i,%i)\n",Filename.FullName(),Width,Height);
|
||||
|
||||
Tile.push_back(CTile(0)); // Insert Blank
|
||||
|
||||
for (int Y=0; Y<Height; Y++)
|
||||
{
|
||||
for (int X=0; X<Width; X++)
|
||||
{
|
||||
Tile.push_back(CTile(Core,this,TexID,X,Y));
|
||||
}
|
||||
}
|
||||
TileBrowserWidth=Width;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileSet::Load3d(CCore *Core)
|
||||
{
|
||||
CScene Scene;
|
||||
|
||||
Scene.Load(Filename);
|
||||
|
||||
CNode &ThisNode=Scene.GetSceneNode(0);
|
||||
int ChildCount=ThisNode.GetPruneChildCount();
|
||||
|
||||
Tile.push_back(CTile(0)); // Insert Blank
|
||||
|
||||
for (int Child=0; Child<ChildCount; Child++)
|
||||
{
|
||||
Tile.push_back(CTile(Core,this,Scene,ThisNode.PruneChildList[Child]));
|
||||
}
|
||||
TileBrowserWidth=DefTileBrowserWidth;
|
||||
TRACE1("%i\n",Tile.size());
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileSet::Purge()
|
||||
{
|
||||
int ListSize=Tile.size();
|
||||
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
Tile[i].Purge();
|
||||
}
|
||||
Tile.clear();
|
||||
Loaded=FALSE;
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
CPoint CTileSet::GetTilePos(int ID)
|
||||
{
|
||||
if (ID==0)
|
||||
return(CPoint(-1,-1));
|
||||
else
|
||||
return(IDToPoint(ID-1,TileBrowserWidth));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
bool CTileSet::IsTileValid(int No)
|
||||
{
|
||||
// ASSERT(No<Tile.size());
|
||||
if (No>Tile.size()) return(FALSE);
|
||||
return(Tile[No].IsValid());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileSet::Render(CCore *Core,Vector3 &CamPos,CMap &LBrush,CMap &RBrush,bool Render3d)
|
||||
{
|
||||
int ListSize=Tile.size();
|
||||
int TileID=0;
|
||||
sMapElem ThisElem;
|
||||
int SelFlag;
|
||||
bool ValidTile=TRUE;
|
||||
//float Scale=1.0f/(float)TileBrowserWidth/CamPos.z;
|
||||
float Scale=CamPos.z/(float)TileBrowserWidth/2.0;
|
||||
|
||||
ThisElem.Flags=0;
|
||||
ThisElem.Set=SetNumber;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
while(TileID!=ListSize)
|
||||
{
|
||||
CPoint Pos=GetTilePos(TileID);
|
||||
float XPos=(float)Pos.x*(1+TileBrowserGap);
|
||||
float YPos=(float)Pos.y*(1+TileBrowserGap);
|
||||
|
||||
glLoadIdentity();
|
||||
glScalef(Scale,Scale,Scale);
|
||||
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
|
||||
|
||||
ValidTile=IsTileValid(TileID);
|
||||
if (TileID && ValidTile)
|
||||
{
|
||||
glColor3f(1,1,1);
|
||||
Tile[TileID].Render(0,Render3d);
|
||||
}
|
||||
|
||||
// Selection
|
||||
ThisElem.Tile=TileID;
|
||||
SelFlag=0;
|
||||
|
||||
if (LBrush.DoesContainTile(ThisElem)) SelFlag|=1;
|
||||
if (RBrush.DoesContainTile(ThisElem)) SelFlag|=2;
|
||||
|
||||
if (SelFlag)
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
switch(SelFlag)
|
||||
{
|
||||
case 1: // L
|
||||
glColor4f(1,0,0,0.5);
|
||||
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
|
||||
break;
|
||||
case 2: // R
|
||||
glColor4f(0,0,1,0.5);
|
||||
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
|
||||
break;
|
||||
case 3: // LR
|
||||
glColor4f(1,0,0,0.5);
|
||||
BuildGLQuad(TileBrowserX0,0.5,TileBrowserY0,TileBrowserY1,0.01f);
|
||||
glColor4f(0,0,1,0.5);
|
||||
BuildGLQuad(0.5,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
|
||||
break;
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
// Invalid tile?
|
||||
if (!ValidTile)
|
||||
{
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1,1,1);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY1,0);
|
||||
|
||||
glVertex3f( TileBrowserX1,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX0,TileBrowserY1,0);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
// Draw Box around bloody Blank so you can see it
|
||||
if (!TileID)
|
||||
{
|
||||
CPoint Pos=GetTilePos(TileID);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1,1,1);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY0,0);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY1,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY1,0);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX0,TileBrowserY1,0);
|
||||
|
||||
glVertex3f( TileBrowserX1,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY1,0);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
TileID++;
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileSet::RenderCursor(Vector3 &CamPos,int CursorPos,int SelStart,int SelEnd)
|
||||
{
|
||||
int ListSize=Tile.size();
|
||||
CPoint Start,End;
|
||||
int MaxTile=Tile.size();
|
||||
//float Scale=1.0f/(float)TileBrowserWidth/CamPos.z;
|
||||
float Scale=CamPos.z/(float)TileBrowserWidth/2.0;
|
||||
|
||||
if (CursorPos<-1 || CursorPos>ListSize) return;
|
||||
|
||||
if (SelStart==-1)
|
||||
{
|
||||
Start=GetTilePos(CursorPos);
|
||||
End=Start;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
CPoint S=IDToPoint(SelStart-1,TileBrowserWidth);
|
||||
CPoint E=IDToPoint(SelEnd-1,TileBrowserWidth);
|
||||
|
||||
Start=CPoint( min(S.x,E.x), min(S.y,E.y));
|
||||
End=CPoint( max(S.x,E.x), max(S.y,E.y));
|
||||
if (PointToID(End,TileBrowserWidth)>=MaxTile) return; // Invalid selection
|
||||
}
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
for (int Y=Start.y; Y<=End.y; Y++)
|
||||
{
|
||||
for (int X=Start.x; X<=End.x; X++)
|
||||
{
|
||||
float XPos=(float)X*(1+TileBrowserGap);
|
||||
float YPos=(float)Y*(1+TileBrowserGap);
|
||||
|
||||
glLoadIdentity();
|
||||
glScalef(Scale,Scale,Scale);
|
||||
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
|
||||
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(1,1,0,0.5);
|
||||
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0);
|
||||
glEnd();
|
||||
|
||||
}
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CTileSet::RenderGrid(CCore *Core,Vector3 &CamPos,bool Active)
|
||||
{
|
||||
int ListSize=Tile.size();
|
||||
int TileID=1; // Dont bother with blank, its sorted
|
||||
//float Scale=1.0f/(float)TileBrowserWidth/CamPos.z;
|
||||
float Scale=CamPos.z/(float)TileBrowserWidth/2.0;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
while(TileID!=ListSize)
|
||||
{
|
||||
CPoint Pos=GetTilePos(TileID);
|
||||
float XPos=(float)Pos.x*(1+TileBrowserGap);
|
||||
float YPos=(float)Pos.y*(1+TileBrowserGap);
|
||||
|
||||
glLoadIdentity();
|
||||
glScalef(Scale,Scale,Scale);
|
||||
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1,1,1);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY0,0);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY1,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY1,0);
|
||||
|
||||
glVertex3f( TileBrowserX0,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX0,TileBrowserY1,0);
|
||||
|
||||
glVertex3f( TileBrowserX1,TileBrowserY0,0);
|
||||
glVertex3f( TileBrowserX1,TileBrowserY1,0);
|
||||
|
||||
glEnd();
|
||||
|
||||
TileID++;
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int CTileSet::FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos)
|
||||
{
|
||||
int ListSize=Tile.size();
|
||||
GLint Viewport[4];
|
||||
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
|
||||
int HitCount;
|
||||
int TileID=0;
|
||||
//float Scale=1.0f/(float)TileBrowserWidth/CamPos.z;
|
||||
float Scale=CamPos.z/(float)TileBrowserWidth/2.0;
|
||||
|
||||
glGetIntegerv(GL_VIEWPORT, Viewport);
|
||||
glSelectBuffer (SELECT_BUFFER_SIZE, SelectBuffer );
|
||||
glRenderMode (GL_SELECT);
|
||||
|
||||
glInitNames();
|
||||
glPushName(-1);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluPickMatrix( MousePos.x ,(Viewport[3]-MousePos.y),5.0,5.0,Viewport);
|
||||
Core->GetView()->SetupPersMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
while(TileID!=ListSize)
|
||||
{
|
||||
CPoint Pos=GetTilePos(TileID);
|
||||
float XPos=(float)Pos.x*(1+TileBrowserGap);
|
||||
float YPos=(float)Pos.y*(1+TileBrowserGap);
|
||||
|
||||
glLoadIdentity();
|
||||
glScalef(Scale,Scale,Scale);
|
||||
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
|
||||
|
||||
glLoadName (TileID);
|
||||
glBegin (GL_QUADS);
|
||||
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0);
|
||||
glEnd();
|
||||
TileID++;
|
||||
}
|
||||
|
||||
HitCount= glRenderMode (GL_RENDER);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
// Process hits
|
||||
|
||||
GLuint *HitPtr=SelectBuffer;
|
||||
|
||||
TileID=-2;
|
||||
if (HitCount) // Just take 1st
|
||||
{
|
||||
TileID=HitPtr[3];
|
||||
}
|
||||
glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert
|
||||
|
||||
return(TileID);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include "Layer.h"
|
||||
#include "TexCache.h"
|
||||
#include "Tile.h"
|
||||
#include "Elem.h"
|
||||
|
||||
#include "MapEdit.h"
|
||||
#include "LayerTileGui.h"
|
||||
|
@ -27,11 +27,9 @@ DefTileBrowserWidth=8,
|
|||
|
||||
/*****************************************************************************/
|
||||
class CCore;
|
||||
class CTile;
|
||||
|
||||
/*****************************************************************************/
|
||||
class CTileSet;
|
||||
class CTileBank : public CLayer
|
||||
class CTileBank : public CLayer, public CElemBank
|
||||
{
|
||||
public:
|
||||
CTileBank();
|
||||
|
@ -57,11 +55,6 @@ public:
|
|||
void GUIUpdate(CCore *Core);
|
||||
void GUIChanged(CCore *Core);
|
||||
|
||||
int GetWidth(){return(0);}
|
||||
int GetHeight(){return(0);}
|
||||
void CheckLayerSize(int Width,int Height){};
|
||||
bool Resize(int Width,int Height){return(false);}
|
||||
|
||||
void Load(CFile *File,int Version);
|
||||
void Save(CFile *File);
|
||||
|
||||
|
@ -72,30 +65,25 @@ public:
|
|||
bool MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos);
|
||||
bool Command(int CmdMsg,CCore *Core,int Param0=0,int Param1=0);
|
||||
|
||||
// Local
|
||||
void AddTileSet(const char *Filename);
|
||||
int NeedLoad() {return(LoadFlag);}
|
||||
void DeleteCurrent();
|
||||
void ReloadAll();
|
||||
void LoadTileSets(CCore *Core);
|
||||
CTile &GetTile(int Bank,int Tile);
|
||||
// ElemSet Thruput
|
||||
const char *GetSetName(int Set) {return(SetList[Set].GetName());}
|
||||
const char *GetSetFilename(int Set) {return(SetList[Set].GetFilename());}
|
||||
CElem &GetTile(int Set,int Tile) {return(SetList[Set].GetElem(Tile));}
|
||||
void RenderTile(int Set,int Elem,int Flags,bool Is3d) {SetList[Set].RenderElem(Elem,Flags,Is3d);}
|
||||
|
||||
int GetSetCount() {return(TileSet.size());}
|
||||
// Local
|
||||
void DeleteCurrent();
|
||||
|
||||
CMap &GetLBrush() {return(Brush[LBrush]);}
|
||||
CMap &GetRBrush() {return(Brush[RBrush]);}
|
||||
CMap &GetBrush(int i) {return(Brush[i]);}
|
||||
CMap &GetActiveBrush() {return(GetBrush(ActiveBrush));}
|
||||
|
||||
bool IsTileValid(int Set,int Tile);
|
||||
bool CanClose() {return(SelStart==-1);}
|
||||
|
||||
void SetCollision(bool f);
|
||||
CTileSet &GetSet(int Set) {return(TileSet[Set]);}
|
||||
CPoint GetTilePos(int ID,int Width);
|
||||
|
||||
// Functions
|
||||
bool SelectCancel();
|
||||
void LoadSet(CCore *Core);
|
||||
void DeleteSet(CCore *Core);
|
||||
|
||||
|
||||
|
@ -104,7 +92,7 @@ protected:
|
|||
bool Select(int BrushID,bool DownFlag);
|
||||
void SetBrush(CMap &ThisBrush);
|
||||
|
||||
CList<CTileSet> TileSet;
|
||||
//!! CList<CTileSet> TileSet;
|
||||
int CurrentSet,LastSet;
|
||||
CMap Brush[2];
|
||||
int ActiveBrush;
|
||||
|
@ -117,48 +105,5 @@ protected:
|
|||
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
class CTileSet
|
||||
{
|
||||
public:
|
||||
CTileSet(const char *_Filename,int Idx);
|
||||
~CTileSet();
|
||||
|
||||
int IsLoaded() {return(Loaded);}
|
||||
int GetTileCount() {return(Tile.size());}
|
||||
|
||||
void Load(CCore *Core);
|
||||
void Load2d(CCore *Core);
|
||||
void Load3d(CCore *Core);
|
||||
|
||||
const char *GetFilename() {return(Filename);}
|
||||
const char *GetName() {return(Name);}
|
||||
|
||||
CTile &GetTile(int No) {return(Tile[No]);}
|
||||
void Purge();
|
||||
int FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos);
|
||||
void Render(CCore *Core,Vector3 &CamPos,CMap &LBrush,CMap &RBrush,bool Render3d);
|
||||
void RenderCursor(Vector3 &CamPos,int Pos,int Width, int Height);
|
||||
void RenderBrush(Vector3 &CamPos,CMap &LBrush,CMap &RBrush);
|
||||
void RenderGrid(CCore *Core,Vector3 &CamPos,bool Active);
|
||||
int GetTileBrowserWidth() {return(TileBrowserWidth);}
|
||||
bool IsTileValid(int No);
|
||||
|
||||
bool operator==(CTileSet const &v1) {return (Name==v1.Name);}
|
||||
|
||||
// if (IsStrSame((char*)Name,(char*)v1.Name) return(i);
|
||||
|
||||
private:
|
||||
bool Create16x16Tile(sRGBData &Src,u8 *Dst,int XOfs,int YOfs);
|
||||
CPoint GetTilePos(int ID);
|
||||
|
||||
GString Filename,Name;
|
||||
|
||||
int SetNumber;
|
||||
CList<CTile> Tile;
|
||||
bool Loaded;
|
||||
int TileBrowserWidth;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
#endif
|
|
@ -324,3 +324,15 @@ CFileDialog Dlg(true,NULL,Name,OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,Filter);
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int round(float f)
|
||||
{
|
||||
if (f<0)
|
||||
{
|
||||
return (int)(f-0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int)(f+0.5f);
|
||||
}
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -53,6 +53,7 @@ void MakeFullFilename(const char *RelName,GString &Out);
|
|||
void MakePathRel2App(const char* In,char *Out);
|
||||
GString GetWorkingPath();
|
||||
void CheckFilename(GString &Filename);
|
||||
int round(float f) ;
|
||||
|
||||
|
||||
#endif
|
|
@ -129,7 +129,6 @@ vector<GString> const &Files = MyFiles.GetFileInfoVector();
|
|||
for (i=0; i<ListSize; i++)
|
||||
{
|
||||
ActorList[i].ActorWrite();
|
||||
ActorList[i].AnimWrite();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -397,11 +396,15 @@ GString OutName=OutFile+".A3d";
|
|||
// Write TexList
|
||||
FileHdr.TexInfo=(sTexInfo*)WriteTexInfoList();
|
||||
|
||||
printf("S:%i\n",ftell(File));
|
||||
// Write anims
|
||||
AnimWrite();
|
||||
|
||||
// Rewrite Header
|
||||
fseek(File, 0, SEEK_SET);
|
||||
fwrite(&FileHdr,1,sizeof(sActorHdr),File);
|
||||
fclose(File);
|
||||
|
||||
AnimWriteInclude();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
@ -492,7 +495,7 @@ int ListSize=InAnimList.size();
|
|||
AnimList.push_back(ThisAnim);
|
||||
|
||||
ThisBoneCount=ThisAnim.BoneAnim.size();
|
||||
printf("\t(%i Bones, %i Frames)\n",ThisBoneCount,ThisAnim.FrameCount);
|
||||
printf("\t(%i Frames)\n",ThisAnim.FrameCount);
|
||||
|
||||
// Check Skeleton
|
||||
if (BoneCount!=ThisBoneCount)
|
||||
|
@ -557,21 +560,17 @@ int ChildCount=ThisNode.GetPruneChildCount();
|
|||
//***************************************************************************
|
||||
void CMkActor3d::AnimWrite()
|
||||
{
|
||||
GString OutName=OutFile+".Abk";
|
||||
int Anim,AnimCount=AnimList.size();
|
||||
sAnimFileHdr FileHdr;
|
||||
sAnimHdr Hdr;
|
||||
int HdrPos;
|
||||
|
||||
if (!AnimCount) return; // No anims, dont bother
|
||||
File=fopen(OutName,"wb");
|
||||
|
||||
// Write Dummy FileHdr
|
||||
// FileHdr
|
||||
FileHdr.AnimCount=AnimCount;
|
||||
FileHdr.BoneCount=BoneCount;
|
||||
fwrite(&FileHdr,1,sizeof(sAnimFileHdr),File);
|
||||
if (!AnimCount) return; // No anims, dont bother
|
||||
|
||||
// Write Dummy AnimHdrs
|
||||
|
||||
HdrPos=ftell(File);
|
||||
FileHdr.AnimList=(sAnimHdr*)HdrPos;
|
||||
for (Anim=0; Anim<AnimCount; Anim++)
|
||||
{
|
||||
fwrite(&Hdr,1,sizeof(sAnimHdr),File);
|
||||
|
@ -592,12 +591,8 @@ sAnimHdr Hdr;
|
|||
AnimList[Anim].AnimOfs=AnimWriteAnim(AnimList[Anim]);
|
||||
}
|
||||
|
||||
// ReWrite FileHdr
|
||||
fseek(File, 0, SEEK_SET);
|
||||
fwrite(&FileHdr,1,sizeof(sAnimFileHdr),File);
|
||||
|
||||
// Rewrite Dummy AnimHdrs
|
||||
|
||||
fseek(File,HdrPos,SEEK_SET);
|
||||
for (Anim=0; Anim<AnimCount; Anim++)
|
||||
{
|
||||
Hdr.FrameCount=AnimList[Anim].FrameCount;
|
||||
|
@ -606,8 +601,6 @@ sAnimHdr Hdr;
|
|||
fwrite(&Hdr,1,sizeof(sAnimHdr),File);
|
||||
}
|
||||
|
||||
fclose(File);
|
||||
if (!IncludeFile.Empty()) AnimWriteInclude();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
@ -663,6 +656,7 @@ int ListSize=QuatList.size();
|
|||
void CMkActor3d::AnimWriteInclude()
|
||||
{
|
||||
GString Filename=IncFile+"_Anim.h";
|
||||
FILE *File;
|
||||
|
||||
File=fopen(Filename,"wt");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue