This commit is contained in:
Daveo 2000-11-06 20:24:11 +00:00
parent 17b863e4be
commit 9be320207d
12 changed files with 308 additions and 202 deletions

View file

@ -30,37 +30,25 @@ BOOL Test3dFlag=TRUE;
/*****************************************************************************/ /*****************************************************************************/
CCore::CCore() CCore::CCore()
{ {
/* for (int i=0; i<LAYER_TYPE_MAX; i++) Layers[i]=0;
Layers[LAYER_TYPE_BACK]= new CLayerBack(this);
Layers[LAYER_TYPE_MID]= new CLayerMid(this);
Layers[LAYER_TYPE_ACTION]= new CLayerAction(this);
Layers[LAYER_TYPE_FORE]= new CLayerFore(this);
TileViewFlag=0;
LayerViewFlag=1;
*/
} }
/*****************************************************************************/ /*****************************************************************************/
CCore::~CCore() CCore::~CCore()
{ {
int i; for (int i=0; i<LAYER_TYPE_MAX; i++) if (Layers[i]) delete Layers[i];
for (i=0; i<LAYER_TYPE_MAX; i++) delete Layers[i];
} }
/*****************************************************************************/ /*****************************************************************************/
void CCore::Init(CMapEditView *Wnd) void CCore::NewMap()
{ {
ParentWindow=Wnd;
RenderFlag=TRUE; RenderFlag=TRUE;
UpdateView();
// To be loaded/created // To be loaded/created
Layers[LAYER_TYPE_BACK]= new CLayerBack(this); Layers[LAYER_TYPE_BACK]= new CLayerBack();
Layers[LAYER_TYPE_MID]= new CLayerMid(this); Layers[LAYER_TYPE_MID]= new CLayerMid();
Layers[LAYER_TYPE_ACTION]= new CLayerAction(this); Layers[LAYER_TYPE_ACTION]= new CLayerAction();
Layers[LAYER_TYPE_FORE]= new CLayerFore(this); Layers[LAYER_TYPE_FORE]= new CLayerFore();
TileViewFlag=0; TileViewFlag=0;
LayerViewFlag=1; LayerViewFlag=1;
@ -68,20 +56,27 @@ void CCore::Init(CMapEditView *Wnd)
ActiveLayer=LAYER_TYPE_ACTION; ActiveLayer=LAYER_TYPE_ACTION;
MapCam=Vec(0,0,0); MapCam=Vec(0,0,0);
TileCam=Vec(0,0,0); TileCam=Vec(0,0,0);
TileSet.push_back(CTileSet("c:/temp/3/test.gin",this)); TileBank.AddTileSet("c:/temp/3/test.gin");
}
/*****************************************************************************/
void CCore::OpenMap()
{
} }
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
void CCore::Render() void CCore::Render(CMapEditView *View)
{ {
Vec &ThisCam=GetCam(); Vec &ThisCam=GetCam();
if (TileBank.NeedLoad()) TileBank.LoadTileSets(this);
if (RenderFlag) if (RenderFlag)
{ {
RenderFlag=FALSE; RenderFlag=FALSE;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
if (GetTileView()) if (GetTileView())
{ {
@ -90,52 +85,51 @@ Vec &ThisCam=GetCam();
{ {
for (int i=0;i<LAYER_TYPE_MAX;i++) for (int i=0;i<LAYER_TYPE_MAX;i++)
{ {
Layers[i]->Render(ThisCam,Test3dFlag); Layers[i]->Render(this,ThisCam,Test3dFlag);
} }
} }
Layers[ActiveLayer]->RenderGrid(ThisCam); Layers[ActiveLayer]->RenderGrid(this,ThisCam);
} }
// Calc CursorPos // Calc CursorPos
Layers[ActiveLayer]->FindCursorPos(ThisCam,CurrentMousePos); Layers[ActiveLayer]->FindCursorPos(this,View,ThisCam,CurrentMousePos);
} }
/*****************************************************************************/ /*****************************************************************************/
/*** Control *****************************************************************/ /*** Control *****************************************************************/
/*****************************************************************************/ /*****************************************************************************/
void CCore::LButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag) void CCore::LButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{ {
} }
/*****************************************************************************/ /*****************************************************************************/
void CCore::MButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag) void CCore::MButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{ {
LastMousePos=point; LastMousePos=point;
} }
/*****************************************************************************/ /*****************************************************************************/
void CCore::RButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag) void CCore::RButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{ {
} }
/*****************************************************************************/ /*****************************************************************************/
void CCore::MouseWheel(UINT nFlags, short zDelta, CPoint &pt) void CCore::MouseWheel(CMapEditView *View,UINT nFlags, short zDelta, CPoint &pt)
{ {
if (zDelta>0) if (zDelta>0)
UpdateView(Vec(0,0,1.0f)); UpdateView(View,Vec(0,0,1.0f));
else else
UpdateView(Vec(0,0,-1.0f)); UpdateView(View,Vec(0,0,-1.0f));
} }
/*****************************************************************************/ /*****************************************************************************/
void CCore::MouseMove(UINT nFlags, CPoint &point) void CCore::MouseMove(CMapEditView *View,UINT nFlags, CPoint &point)
{ {
Vec Ofs(0,0,0); Vec Ofs(0,0,0);
Vec &ThisCam=GetCam(); Vec &ThisCam=GetCam();
// check if active doc // check if active doc
if (theApp.GetCurrent()!=ParentWindow->GetDocument()) return; if (theApp.GetCurrent()!=View->GetDocument()) return;
CurrentMousePos=point; CurrentMousePos=point;
@ -145,7 +139,7 @@ Vec &ThisCam=GetCam();
float XS,YS; float XS,YS;
RECT ThisRect; RECT ThisRect;
ParentWindow->GetWindowRect(&ThisRect); View->GetWindowRect(&ThisRect);
XS=ThisCam.z*4;//*Layers[ActiveLayer]->GetLayerZPos(); XS=ThisCam.z*4;//*Layers[ActiveLayer]->GetLayerZPos();
YS=ThisCam.z*4;//*Layers[ActiveLayer]->GetLayerZPos(); YS=ThisCam.z*4;//*Layers[ActiveLayer]->GetLayerZPos();
XS/=((ThisRect.right-ThisRect.left)); XS/=((ThisRect.right-ThisRect.left));
@ -158,17 +152,19 @@ Vec &ThisCam=GetCam();
Ofs.x*=XS; Ofs.x*=XS;
Ofs.y*=YS; Ofs.y*=YS;
UpdateView(Ofs); UpdateView(View,Ofs);
} }
// Mouse has moved, so need to redraw windows, to get CursorPos (And pos render) else
ParentWindow->Invalidate(); { // Mouse still moved, so need to redraw windows, to get CursorPos (And pos render)
View->Invalidate();
}
} }
/*****************************************************************************/ /*****************************************************************************/
/*** Layers ******************************************************************/ /*** Layers ******************************************************************/
/*****************************************************************************/ /*****************************************************************************/
void CCore::UpdateLayerBar(BOOL ViewFlag) void CCore::UpdateLayerBar(CMapEditView *View,BOOL ViewFlag)
{ {
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd(); CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CToolBar *ToolBar=Frm->GetToolBar(); CToolBar *ToolBar=Frm->GetToolBar();
@ -192,31 +188,39 @@ CListBox *Dlg=(CListBox *)LayerBar->GetDlgItem(IDC_LAYERBAR_LIST);
Frm->ShowControlBar(LayerBar, LayerViewFlag, FALSE); Frm->ShowControlBar(LayerBar, LayerViewFlag, FALSE);
} }
/*****************************************************************************/
void CCore::ToggleLayerView(CMapEditView *View)
{
UpdateLayerBar(View,!LayerViewFlag);
}
/*****************************************************************************/ /*****************************************************************************/
void CCore::SetActiveLayer(int i) void CCore::SetActiveLayer(int i)
{ {
UpdateLayerBar(LayerViewFlag); UpdateLayerBar(NULL,LayerViewFlag);
} }
/*****************************************************************************/ /*****************************************************************************/
/*** TileBank ****************************************************************/ /*** TileBank ****************************************************************/
/*****************************************************************************/ /*****************************************************************************/
void CCore::UpdateTileView(BOOL ViewFlag) /*****************************************************************************/
void CCore::UpdateTileView(CMapEditView *View,BOOL ViewFlag)
{ {
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd(); CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CToolBar *ToolBar=Frm->GetToolBar(); CToolBar *ToolBar=Frm->GetToolBar();
TileViewFlag=ViewFlag; TileViewFlag=ViewFlag;
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_TILEPALETTE,TileViewFlag); ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_TILEPALETTE,TileViewFlag);
UpdateView(); UpdateView(View);
} }
/*****************************************************************************/ /*****************************************************************************/
GLint CCore::GetTile(int Bank,int TileNo) void CCore::ToggleTileView(CMapEditView *View)
{ {
return(TileSet[Bank].GetTile(TileNo)); UpdateTileView(View,!TileViewFlag);
} }
/*****************************************************************************/ /*****************************************************************************/
/*** Misc ********************************************************************/ /*** Misc ********************************************************************/
/*****************************************************************************/ /*****************************************************************************/
@ -230,28 +234,21 @@ Vec &CCore::GetCam()
} }
/*****************************************************************************/ /*****************************************************************************/
void CCore::UpdateAll() void CCore::UpdateAll(CMapEditView *View)
{ {
UpdateView(); UpdateView(View);
UpdateLayerBar(LayerViewFlag); UpdateLayerBar(View,LayerViewFlag);
UpdateTileView(TileViewFlag); UpdateTileView(View,TileViewFlag);
} }
/*****************************************************************************/ /*****************************************************************************/
void CCore::Redraw(BOOL f) void CCore::UpdateView(CMapEditView *View,Vec Ofs)
{
RenderFlag=f;
if (RenderFlag)
ParentWindow->Invalidate();
}
/*****************************************************************************/
void CCore::UpdateView(Vec Ofs)
{ {
Vec &ThisCam=GetCam(); Vec &ThisCam=GetCam();
Ofs.y=-Ofs.y; Ofs.y=-Ofs.y;
ThisCam+=Ofs; ThisCam+=Ofs;
if (ThisCam.z>-1) ThisCam.z=-1; if (ThisCam.z>-1) ThisCam.z=-1;
Redraw(); RenderFlag=TRUE;
View->Invalidate();
} }

View file

@ -23,47 +23,45 @@ public:
CCore(); CCore();
~CCore(); ~CCore();
void Init(CMapEditView *Wnd); void Init();
void Render(); void NewMap();
void OpenMap();
void Render(CMapEditView *View);
// Control // Control
void LButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag); void LButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag);
void MButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag); void MButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag);
void RButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag); void RButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag);
void MouseWheel(UINT nFlags, short zDelta, CPoint &pt); void MouseWheel(CMapEditView *View,UINT nFlags, short zDelta, CPoint &pt);
void MouseMove(UINT nFlags, CPoint &point); void MouseMove(CMapEditView *View,UINT nFlags, CPoint &point);
// TileBank // TileBank
void UpdateTileView(BOOL ViewFlag); void UpdateTileView(CMapEditView *View,BOOL ViewFlag);
BOOL GetTileView() {return(TileViewFlag);} void ToggleTileView(CMapEditView *View);
void ToggleTileView() {UpdateTileView(!TileViewFlag);} BOOL GetTileView() {return(TileViewFlag);}
GLint GetTile(int Bank,int TileNo); CTile GetTile(int Bank,int TileNo) {return(TileBank.GetTile(Bank,TileNo));}
// Layers // Layers
void UpdateLayerBar(BOOL ViewFlag); void UpdateLayerBar(CMapEditView *View,BOOL ViewFlag);
BOOL GetLayerViewFlag() {return(LayerViewFlag);} void ToggleLayerView(CMapEditView *View);
void ToggleLayerView() {UpdateLayerBar(!LayerViewFlag);} BOOL GetLayerViewFlag() {return(LayerViewFlag);}
void SetActiveLayer(int Layer); void SetActiveLayer(int Layer);
int GetActiveLayer() {return(ActiveLayer);} int GetActiveLayer() {return(ActiveLayer);}
CLayer *GetLayer(int i) {return(Layers[i]);} CLayer *GetLayer(int i) {return(Layers[i]);}
// Tex Cache // Tex Cache
CTexCache &GetTexCache() {return(TexCache);} CTexCache &GetTexCache() {return(TexCache);}
// Misc // Misc
void UpdateAll(); void UpdateAll(CMapEditView *View);
void UpdateView(Vec Ofs=Vec(0,0,0)); void UpdateView(CMapEditView *View,Vec Ofs=Vec(0,0,0));
Vec &GetCam();
void SetCursorPos(CPoint &Pos) {CursorPos=Pos;}
CPoint &GetCursorPos() {return(CursorPos);}
CMapEditView *GetParentWindow() {return(ParentWindow);}
void Redraw(BOOL f=TRUE);
Vec &GetCam();
void SetCursorPos(CPoint &Pos) {CursorPos=Pos;}
CPoint &GetCursorPos() {return(CursorPos);}
private: private:
CMapEditView *ParentWindow;
CPoint CurrentMousePos,LastMousePos; CPoint CurrentMousePos,LastMousePos;
CPoint CursorPos,LastCursorPos; CPoint CursorPos,LastCursorPos;
Vec MapCam,TileCam; Vec MapCam,TileCam;
@ -71,14 +69,14 @@ private:
CLayer *Layers[LAYER_TYPE_MAX]; CLayer *Layers[LAYER_TYPE_MAX];
int ActiveLayer; int ActiveLayer;
std::vector<CTileSet> TileSet; // std::vector<CTileSet> TileSet;
CTileBank TileBank;
CTexCache TexCache; CTexCache TexCache;
BOOL RenderFlag; BOOL RenderFlag;
BOOL TileViewFlag; BOOL TileViewFlag;
BOOL LayerViewFlag; BOOL LayerViewFlag;
}; };
/*****************************************************************************/ /*****************************************************************************/

View file

@ -21,7 +21,7 @@
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
CLayer::CLayer(CCore *_Core) CLayer::CLayer()
{ {
} }
@ -31,23 +31,13 @@ CLayer::~CLayer()
} }
/*****************************************************************************/ /*****************************************************************************/
void CLayer::InitLayer(CCore *_Core) void CLayer::Render(CCore *Core,Vec &MapPos,BOOL Is3d)
{ {
int Width=Map.GetWidth(); Render2d(Core,MapPos);
int Height=Map.GetHeight();
Core=_Core;
TRACE3("%i x %i = %i\t",Width,Height,Width*Height);
} }
/*****************************************************************************/ /*****************************************************************************/
void CLayer::Render(Vec &MapPos,BOOL Is3d) void CLayer::Render2d(CCore *Core,Vec &MapPos)
{
Render2d(MapPos);
}
/*****************************************************************************/
void CLayer::Render2d(Vec &MapPos)
{ {
float XYDiv=GetLayerZPosDiv(); float XYDiv=GetLayerZPosDiv();
return; return;
@ -69,13 +59,14 @@ int Height=Map.GetHeight();
} }
/*****************************************************************************/ /*****************************************************************************/
void CLayer::Render3d(Vec &MapPos) void CLayer::Render3d(CCore *Core,Vec &MapPos)
{ {
float XYDiv=GetLayerZPosDiv(); float XYDiv=GetLayerZPosDiv();
int MapW=Map.GetWidth(); int MapW=Map.GetWidth();
int MapH=Map.GetHeight(); int MapH=Map.GetHeight();
float StartX=MapPos.x/XYDiv; float StartX=MapPos.x/XYDiv;
float StartY=MapPos.y/XYDiv; float StartY=MapPos.y/XYDiv;
CTexCache &TexCache=Core->GetTexCache();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
@ -83,18 +74,19 @@ float StartY=MapPos.y/XYDiv;
{ {
for (int XLoop=0; XLoop<MapW; XLoop++) for (int XLoop=0; XLoop<MapW; XLoop++)
{ {
sMapElem &ThisTile=Map.GetTile(XLoop,YLoop); sMapElem &ThisElem=Map.GetTile(XLoop,YLoop);
CTile &ThisTile=Core->GetTile(ThisElem.Bank,ThisElem.Tile);
glLoadIdentity(); // Slow way, but good to go for the mo glLoadIdentity(); // Slow way, but good to go for the mo
glTranslatef(StartX+XLoop,StartY-YLoop,MapPos.z); glTranslatef(StartX+XLoop,StartY-YLoop,MapPos.z);
glCallList(Core->GetTile(ThisTile.Bank,ThisTile.Tile)); ThisTile.Render();
} }
} }
} }
/*****************************************************************************/ /*****************************************************************************/
void CLayer::RenderGrid(Vec &MapPos) void CLayer::RenderGrid(CCore *Core,Vec &MapPos)
{ {
float XYDiv=GetLayerZPosDiv(); float XYDiv=GetLayerZPosDiv();
int MapW=Map.GetWidth(); int MapW=Map.GetWidth();
@ -129,7 +121,7 @@ float OverVal=0.5;
} }
/*****************************************************************************/ /*****************************************************************************/
void CLayer::FindCursorPos(Vec &MapPos,CPoint &MousePos) void CLayer::FindCursorPos(CCore *Core,CMapEditView *View,Vec &MapPos,CPoint &MousePos)
{ {
GLint Viewport[4]; GLint Viewport[4];
GLuint SelectBuffer[SELECT_BUFFER_SIZE]; GLuint SelectBuffer[SELECT_BUFFER_SIZE];
@ -154,7 +146,7 @@ float StartY=MapPos.y/XYDiv;
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
gluPickMatrix( MousePos.x ,(Viewport[3]-MousePos.y),5.0,5.0,Viewport); gluPickMatrix( MousePos.x ,(Viewport[3]-MousePos.y),5.0,5.0,Viewport);
Core->GetParentWindow()->SetupPersMatrix(); View->SetupPersMatrix();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();

View file

@ -30,31 +30,27 @@ enum LAYER_TYPE
/*****************************************************************************/ /*****************************************************************************/
class CCore; class CCore;
class CMap; class CMap;
class CMapEditView;
class CLayer class CLayer
{ {
public: public:
CLayer(){ASSERT(1);} CLayer();
CLayer(CCore *_Core);
~CLayer(); ~CLayer();
void InitLayer(CCore *_Core);
// Virtual // Virtual
virtual void Init()=0; virtual void Init()=0;
virtual char *GetName()=0; virtual char *GetName()=0;
virtual void Render(Vec &MapPos,BOOL Is3d); virtual void Render(CCore *Core,Vec &MapPos,BOOL Is3d);
virtual void Render2d(Vec &MapPos); virtual void Render2d(CCore *Core,Vec &MapPos);
virtual void Render3d(Vec &MapPos); virtual void Render3d(CCore *Core,Vec &MapPos);
virtual void RenderGrid(Vec &MapPos); virtual void RenderGrid(CCore *Core,Vec &MapPos);
virtual float GetLayerZPosDiv()=0; virtual float GetLayerZPosDiv()=0;
virtual BOOL CanRender3d()=0; virtual BOOL CanRender3d()=0;
virtual void FindCursorPos(Vec &MapPos,CPoint &MousePos); virtual void FindCursorPos(CCore *Core,CMapEditView *View,Vec &MapPos,CPoint &MousePos);
protected: protected:
CCore *Core;
CMap Map; CMap Map;
}; };

View file

@ -2,7 +2,7 @@
[General Info] [General Info]
Version=1 Version=1
LastClass=CMapEditDoc LastClass=CMapEditView
LastTemplate=CFrameWnd LastTemplate=CFrameWnd
NewFileInclude1=#include "stdafx.h" NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "mapedit.h" NewFileInclude2=#include "mapedit.h"
@ -84,7 +84,7 @@ Type=0
BaseClass=CGLEnabledView BaseClass=CGLEnabledView
HeaderFile=MapEditView.h HeaderFile=MapEditView.h
ImplementationFile=MapEditView.cpp ImplementationFile=MapEditView.cpp
LastObject=CMapEditView LastObject=ID_TOOLBAR_LAYERBAR
Filter=C Filter=C
VirtualFilter=VWC VirtualFilter=VWC

View file

@ -95,8 +95,8 @@ BOOL CMapEditApp::InitInstance()
// Parse command line for standard shell commands, DDE, file open // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo; CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo); ParseCommandLine(cmdInfo);
// Prevent creating new doc on startup (should still open cmd line file tho // Prevent creating new doc on startup (should still open cmd line file tho)
if (cmdInfo.m_nShellCommand==CCommandLineInfo::FileNew) cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing; // if (cmdInfo.m_nShellCommand==CCommandLineInfo::FileNew) cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;
// Dispatch commands specified on the command line // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo)) return FALSE; if (!ProcessShellCommand(cmdInfo)) return FALSE;

View file

@ -19,6 +19,7 @@ IMPLEMENT_DYNCREATE(CMapEditDoc, CDocument)
BEGIN_MESSAGE_MAP(CMapEditDoc, CDocument) BEGIN_MESSAGE_MAP(CMapEditDoc, CDocument)
//{{AFX_MSG_MAP(CMapEditDoc) //{{AFX_MSG_MAP(CMapEditDoc)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSORXY, OnStatusCursorXY)
//}}AFX_MSG_MAP //}}AFX_MSG_MAP
END_MESSAGE_MAP() END_MESSAGE_MAP()
@ -35,12 +36,9 @@ CMapEditDoc::~CMapEditDoc()
BOOL CMapEditDoc::OnNewDocument() BOOL CMapEditDoc::OnNewDocument()
{ {
if (!CDocument::OnNewDocument()) if (!CDocument::OnNewDocument()) return FALSE;
return FALSE;
TRACE0("New Doc\n"); TRACE0("New Doc\n");
Core.NewMap();
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE; return TRUE;
} }
@ -52,20 +50,18 @@ BOOL CMapEditDoc::OnOpenDocument(LPCTSTR lpszPathName)
TRACE1("Load Doc %s\n",lpszPathName); TRACE1("Load Doc %s\n",lpszPathName);
// TODO: Add your specialized creation code here
return TRUE; return TRUE;
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// CMapEditDoc serialization // CMapEditDoc serialization
void CMapEditDoc::Serialize(CArchive& ar) void CMapEditDoc::Serialize(CArchive& ar)
{ {
if (ar.IsStoring()) if (ar.IsStoring())
{ {
// TODO: add storing code here // TODO: add storing code here
} }
else else
{ {
@ -87,3 +83,83 @@ void CMapEditDoc::Dump(CDumpContext& dc) const
CDocument::Dump(dc); CDocument::Dump(dc);
} }
#endif //_DEBUG #endif //_DEBUG
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
void CMapEditDoc::UpdateView(CMapEditView *View)
{
Core.UpdateView(View);
}
/*********************************************************************************/
void CMapEditDoc::Render(CMapEditView *View)
{
Core.Render(View);
}
/*********************************************************************************/
void CMapEditDoc::UpdateAll(CMapEditView *View)
{
Core.UpdateAll(View);
}
/*********************************************************************************/
void CMapEditDoc::OnStatusCursorXY(CCmdUI *pCmdUI)
{
CPoint &XY=Core.GetCursorPos();
CString XYStr;
pCmdUI->Enable();
if (XY.x!=-1 && XY.y!=-1)
XYStr.Format( "%d\t%d", XY.x,XY.y);
pCmdUI->SetText(XYStr);
}
/*********************************************************************************/
/*********************************************************************************/
/*** Windows Message Handlers ****************************************************/
/*********************************************************************************/
/*********************************************************************************/
void CMapEditDoc::LButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{
Core.LButtonControl(View,nFlags,point,DownFlag);
}
/*********************************************************************************/
void CMapEditDoc::MButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{
Core.MButtonControl(View,nFlags,point,DownFlag);
}
/*********************************************************************************/
void CMapEditDoc::RButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{
Core.RButtonControl(View,nFlags,point,DownFlag);
}
/*********************************************************************************/
void CMapEditDoc::MouseWheel(CMapEditView *View,UINT nFlags, short zDelta, CPoint &point)
{
Core.MouseWheel(View,nFlags,zDelta,point);
}
/*********************************************************************************/
void CMapEditDoc::MouseMove(CMapEditView *View,UINT nFlags, CPoint &point)
{
Core.MouseMove(View,nFlags,point);
}
/*********************************************************************************/
void CMapEditDoc::ToggleLayerView(CMapEditView *View)
{
Core.ToggleLayerView(View);
}
/*********************************************************************************/
void CMapEditDoc::ToggleTileView(CMapEditView *View)
{
Core.ToggleTileView(View);
}

View file

@ -19,6 +19,19 @@ protected: // create from serialization only
// Attributes // Attributes
public: public:
// void SetupPersMatrix(float _m_dAspectRatio);
void UpdateView(CMapEditView *View);
void Render(CMapEditView *View);
void UpdateAll(CMapEditView *View);
// Windows Messages Thru Point
void LButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag);
void MButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag);
void RButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag);
void MouseWheel(CMapEditView *View,UINT nFlags, short zDelta, CPoint &pt);
void MouseMove(CMapEditView *View,UINT nFlags, CPoint &point);
void ToggleLayerView(CMapEditView *View);
void ToggleTileView(CMapEditView *View);
// Operations // Operations
public: public:
@ -28,8 +41,8 @@ public:
//{{AFX_VIRTUAL(CMapEditDoc) //{{AFX_VIRTUAL(CMapEditDoc)
public: public:
virtual BOOL OnNewDocument(); virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName); virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL //}}AFX_VIRTUAL
// Implementation // Implementation
@ -41,11 +54,11 @@ public:
#endif #endif
protected: protected:
CCore Core;
// Generated message map functions // Generated message map functions
protected: protected:
//{{AFX_MSG(CMapEditDoc) //{{AFX_MSG(CMapEditDoc)
afx_msg void OnStatusCursorXY(CCmdUI *pCmdUI);
//}}AFX_MSG //}}AFX_MSG
DECLARE_MESSAGE_MAP() DECLARE_MESSAGE_MAP()

View file

@ -37,7 +37,6 @@ BEGIN_MESSAGE_MAP(CMapEditView, CGLEnabledView)
ON_WM_MOUSEMOVE() ON_WM_MOUSEMOVE()
ON_COMMAND(ID_TOOLBAR_LAYERBAR, OnToolbarLayerbar) ON_COMMAND(ID_TOOLBAR_LAYERBAR, OnToolbarLayerbar)
ON_COMMAND(ID_TOOLBAR_TILEPALETTE, OnToolbarTilepalette) ON_COMMAND(ID_TOOLBAR_TILEPALETTE, OnToolbarTilepalette)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSORXY, OnStatusCursorXY)
//}}AFX_MSG_MAP //}}AFX_MSG_MAP
END_MESSAGE_MAP() END_MESSAGE_MAP()
@ -46,9 +45,6 @@ END_MESSAGE_MAP()
CMapEditView::CMapEditView() CMapEditView::CMapEditView()
{ {
//CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
//CDialogBar *LayerBar=Frm->GetLayerBar();
} }
CMapEditView::~CMapEditView() CMapEditView::~CMapEditView()
@ -76,16 +72,14 @@ void CMapEditView::OnCreateGL()
glEnable(GL_LIGHTING); // Enable Lighting glEnable(GL_LIGHTING); // Enable Lighting
glEnable(GL_COLOR_MATERIAL); // Enable Material Coloring glEnable(GL_COLOR_MATERIAL); // Enable Material Coloring
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
Core.Init(this);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
void CMapEditView::OnDrawGL() void CMapEditView::OnDrawGL()
{ {
Core.Render(); GetDocument()->Render(this);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -99,17 +93,17 @@ void CMapEditView::OnSizeGL(int cx, int cy)
SetupPersMatrix(); SetupPersMatrix();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPopMatrix(); glPopMatrix();
Core.Redraw(); GetDocument()->UpdateView(this);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
void CMapEditView::SetupPersMatrix() void CMapEditView::SetupPersMatrix()
{ {
gluPerspective(40.0,m_dAspectRatio,0.1f, 100.0f); gluPerspective(40.0,m_dAspectRatio,0.1f, 100.0f);
glTranslatef(0.0f,0.0f,-4.f); glTranslatef(0.0f,0.0f,-4.f);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// CMapEditView diagnostics // CMapEditView diagnostics
@ -139,41 +133,19 @@ void CMapEditView::OnSetFocus(CWnd* pOldWnd)
CMapEditDoc *CurDoc=GetDocument(); CMapEditDoc *CurDoc=GetDocument();
CGLEnabledView::OnSetFocus(pOldWnd); CGLEnabledView::OnSetFocus(pOldWnd);
theApp.SetCurrent(CurDoc); theApp.SetCurrent(CurDoc);
UpdateAll(); CurDoc->UpdateAll(this);
} }
/*********************************************************************************/ /*********************************************************************************/
/*********************************************************************************/ /*********************************************************************************/
/*********************************************************************************/ /*********************************************************************************/
void CMapEditView::UpdateAll() void CMapEditView::OnLButtonDown(UINT nFlags, CPoint point) {GetDocument()->LButtonControl(this,nFlags,point,TRUE);}
{ void CMapEditView::OnLButtonUp(UINT nFlags, CPoint point) {GetDocument()->LButtonControl(this,nFlags,point,FALSE);}
Core.UpdateAll(); void CMapEditView::OnMButtonDown(UINT nFlags, CPoint point) {GetDocument()->MButtonControl(this,nFlags,point,TRUE);}
} void CMapEditView::OnMButtonUp(UINT nFlags, CPoint point) {GetDocument()->MButtonControl(this,nFlags,point,FALSE);}
BOOL CMapEditView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) {GetDocument()->MouseWheel(this,nFlags,zDelta,pt) ;return(0);}
/*********************************************************************************/ void CMapEditView::OnRButtonDown(UINT nFlags, CPoint point) {GetDocument()->RButtonControl(this,nFlags,point,TRUE);}
void CMapEditView::OnStatusCursorXY(CCmdUI *pCmdUI) void CMapEditView::OnRButtonUp(UINT nFlags, CPoint point) {GetDocument()->RButtonControl(this,nFlags,point,FALSE);}
{ void CMapEditView::OnMouseMove(UINT nFlags, CPoint point) {GetDocument()->MouseMove(this,nFlags, point);}
CPoint &XY=Core.GetCursorPos(); void CMapEditView::OnToolbarLayerbar() {GetDocument()->ToggleLayerView(this);}
CString XYStr; void CMapEditView::OnToolbarTilepalette() {GetDocument()->ToggleTileView(this);}
pCmdUI->Enable();
if (XY.x!=-1 && XY.y!=-1)
XYStr.Format( "%d\t%d", XY.x,XY.y);
pCmdUI->SetText(XYStr);
}
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
void CMapEditView::OnLButtonDown(UINT nFlags, CPoint point) {Core.LButtonControl(nFlags,point,TRUE);}
void CMapEditView::OnLButtonUp(UINT nFlags, CPoint point) {Core.LButtonControl(nFlags,point,FALSE);}
void CMapEditView::OnMButtonDown(UINT nFlags, CPoint point) {Core.MButtonControl(nFlags,point,TRUE);}
void CMapEditView::OnMButtonUp(UINT nFlags, CPoint point) {Core.MButtonControl(nFlags,point,FALSE);}
BOOL CMapEditView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) {Core.MouseWheel(nFlags,zDelta,pt) ;return(0);}
void CMapEditView::OnRButtonDown(UINT nFlags, CPoint point) {Core.RButtonControl(nFlags,point,TRUE);}
void CMapEditView::OnRButtonUp(UINT nFlags, CPoint point) {Core.RButtonControl(nFlags,point,FALSE);}
void CMapEditView::OnMouseMove(UINT nFlags, CPoint point) {Core.MouseMove(nFlags, point);}
void CMapEditView::OnToolbarLayerbar() {Core.ToggleLayerView();}
void CMapEditView::OnToolbarTilepalette() {Core.ToggleTileView();}

View file

@ -39,11 +39,9 @@ public:
virtual void AssertValid() const; virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const; virtual void Dump(CDumpContext& dc) const;
#endif #endif
void UpdateAll();
protected: protected:
void VideoMode(ColorsNumber &c,ZAccuracy &z,BOOL &dbuf); void VideoMode(ColorsNumber &c,ZAccuracy &z,BOOL &dbuf);
CCore Core;
// Generated message map functions // Generated message map functions
protected: protected:
@ -59,7 +57,6 @@ protected:
afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnToolbarLayerbar(); afx_msg void OnToolbarLayerbar();
afx_msg void OnToolbarTilepalette(); afx_msg void OnToolbarTilepalette();
afx_msg void OnStatusCursorXY(CCmdUI *pCmdUI);
//}}AFX_MSG //}}AFX_MSG
DECLARE_MESSAGE_MAP() DECLARE_MESSAGE_MAP()
}; };

View file

@ -9,6 +9,7 @@
#include <gl\glut.h> #include <gl\glut.h>
#include <Vector> #include <Vector>
#include "Core.h"
#include "TileSet.h" #include "TileSet.h"
#include "GinTex.h" #include "GinTex.h"
#include "utils.h" #include "utils.h"
@ -16,19 +17,63 @@
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*** TileBank ****************************************************************/
/*****************************************************************************/ /*****************************************************************************/
CTileSet::CTileSet(char *_Filename,CCore *Core) /*****************************************************************************/
CTileBank::CTileBank()
{
LoadFlag=FALSE;
}
/*****************************************************************************/
CTileBank::~CTileBank()
{
}
/*****************************************************************************/
void CTileBank::AddTileSet(char *Filename)
{
TileSet.push_back(CTileSet(Filename));
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;
}
/*****************************************************************************/
CTile &CTileBank::GetTile(int Bank,int Tile)
{
return(TileSet[Bank].GetTile(Tile));
}
/*****************************************************************************/
/*****************************************************************************/
/*** TileSet *****************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CTileSet::CTileSet(char *_Filename)
{ {
char Drive[_MAX_DRIVE]; char Drive[_MAX_DRIVE];
char Dir[_MAX_DIR]; char Dir[_MAX_DIR];
char Fname[_MAX_FNAME]; char Fname[_MAX_FNAME];
char Ext[_MAX_EXT]; char Ext[_MAX_EXT];
sprintf(FullName,"%s",_Filename);
_splitpath(_Filename,Drive,Dir,Fname,Ext); _splitpath(_Filename,Drive,Dir,Fname,Ext);
sprintf(Path,"%s%s",Drive,Dir); sprintf(Path,"%s%s",Drive,Dir);
sprintf(Filename,"%s%s",Fname,Ext); sprintf(Filename,"%s%s",Fname,Ext);
Loaded=FALSE;
Load(Core,_Filename);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -41,11 +86,11 @@ CTileSet::~CTileSet()
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
int CTileSet::Load(CCore *Core,char *_Filename) void CTileSet::Load(CCore *Core)
{ {
CScene Scene; CScene Scene;
Scene.Load(_Filename); Scene.Load(FullName);
CNode &ThisNode=Scene.GetSceneNode(0); CNode &ThisNode=Scene.GetSceneNode(0);
int ChildCount=ThisNode.GetPruneChildCount(); int ChildCount=ThisNode.GetPruneChildCount();
@ -57,7 +102,7 @@ int ChildCount=ThisNode.GetPruneChildCount();
Tile.push_back(NewTile); Tile.push_back(NewTile);
} }
Loaded=TRUE;
return(1);
} }
/*****************************************************************************/

View file

@ -14,28 +14,48 @@
#include "TexCache.h" #include "TexCache.h"
#include "Tile.h" #include "Tile.h"
//#include "GinTex.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
class CCore; class CCore;
class CTile;
/*****************************************************************************/
class CTileBank
{
public:
CTileBank();
~CTileBank();
void AddTileSet(char *Filename);
int NeedLoad() {return(LoadFlag);}
void LoadTileSets(CCore *Core);
CTile &GetTile(int Bank,int Tile);
private:
std::vector<CTileSet> TileSet;
BOOL LoadFlag;
};
/*****************************************************************************/
class CTileSet class CTileSet
{ {
public: public:
CTileSet(char *_Filename,CCore *Core); CTileSet(char *_Filename);
~CTileSet(); ~CTileSet();
int Load(CCore *Core,char *_Filename); int IsLoaded() {return(Loaded);}
void Load(CCore *Core);
char *GetPath() {return(Path);} char *GetPath() {return(Path);}
char *GetFilename() {return(Filename);} char *GetFilename() {return(Filename);}
GLint GetTile(int No) {return(Tile[No].GetTile());} CTile &GetTile(int No) {return(Tile[No]);}
private: private:
char Path[256]; char FullName[256],Path[256],Filename[256];
char Filename[256];
std::vector<CTile> Tile; std::vector<CTile> Tile;
BOOL Loaded;
}; };