This commit is contained in:
Daveo 2000-11-07 20:38:19 +00:00
parent 9be320207d
commit 28a8986db5
9 changed files with 44 additions and 225 deletions

View File

@ -17,11 +17,7 @@
#include "Core.h"
#include "Layer.h"
#include "LayerBack.h"
#include "LayerMid.h"
#include "LayerAction.h"
#include "LayerFore.h"
#include "LayerTile.h"
BOOL Test3dFlag=TRUE;
@ -42,13 +38,14 @@ CCore::~CCore()
/*****************************************************************************/
void CCore::NewMap()
{
RenderFlag=TRUE;
// To be loaded/created
Layers[LAYER_TYPE_BACK]= new CLayerBack();
Layers[LAYER_TYPE_MID]= new CLayerMid();
Layers[LAYER_TYPE_ACTION]= new CLayerAction();
Layers[LAYER_TYPE_FORE]= new CLayerFore();
Layers[LAYER_TYPE_BACK]= new CLayerTile("Back", 32, 32, 4.0f, FALSE);
Layers[LAYER_TYPE_MID]= new CLayerTile("Mid", TileLayerDefaultWidth/2.0f, TileLayerDefaultHeight/2.0f, 2.0f, FALSE);
Layers[LAYER_TYPE_ACTION]= new CLayerTile("Action",TileLayerDefaultWidth/1.0f, TileLayerDefaultHeight/1.0f, 1.0f, TRUE);
Layers[LAYER_TYPE_FORE]= new CLayerTile("Fore", TileLayerDefaultWidth/0.5f, TileLayerDefaultHeight/0.5f, 0.5f, FALSE);
TileViewFlag=0;
LayerViewFlag=1;
@ -69,6 +66,7 @@ void CCore::OpenMap()
/*****************************************************************************/
void CCore::Render(CMapEditView *View)
{
Vec &ThisCam=GetCam();
if (TileBank.NeedLoad()) TileBank.LoadTileSets(this);
@ -186,6 +184,8 @@ CListBox *Dlg=(CListBox *)LayerBar->GetDlgItem(IDC_LAYERBAR_LIST);
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_LAYERBAR,LayerViewFlag);
Frm->ShowControlBar(LayerBar, LayerViewFlag, FALSE);
if (View) UpdateView(View);
}
/*****************************************************************************/

View File

@ -8,7 +8,7 @@
#include <Vector>
#include "gl3d.h"
#include "Layer.h"
#include "LayerBack.h"
//#include "LayerTile.h"
#include "TexCache.h"
#include "TileSet.h"
@ -69,7 +69,6 @@ private:
CLayer *Layers[LAYER_TYPE_MAX];
int ActiveLayer;
// std::vector<CTileSet> TileSet;
CTileBank TileBank;
CTexCache TexCache;

View File

@ -8,181 +8,27 @@
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include "GLEnabledView.h"
//#include "GLEnabledView.h"
#include "MapEditDoc.h"
#include "MapEditView.h"
//#include "MapEditDoc.h"
//#include "MapEditView.h"
#include "Core.h"
#include "Layer.h"
#include "Utils.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CLayer::CLayer()
char *CLayer::GetName()
{
return(Name);
}
/*****************************************************************************/
CLayer::~CLayer()
void CLayer::SetName(char *_Name)
{
}
/*****************************************************************************/
void CLayer::Render(CCore *Core,Vec &MapPos,BOOL Is3d)
{
Render2d(Core,MapPos);
}
/*****************************************************************************/
void CLayer::Render2d(CCore *Core,Vec &MapPos)
{
float XYDiv=GetLayerZPosDiv();
return;
int Width=Map.GetWidth();
int Height=Map.GetHeight();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(MapPos.x/XYDiv,MapPos.y/XYDiv,MapPos.z);
glBegin(GL_QUADS);
BuildGLQuad(-1,Width+1,-1,0,0); // Bottom
BuildGLQuad(-1,Width+1,Height+1,Height,0); // Top
BuildGLQuad(-1,0,Height,0,0); // Left
BuildGLQuad(Width,Width+1,Height,0,0); // Right
glEnd();
}
/*****************************************************************************/
void CLayer::Render3d(CCore *Core,Vec &MapPos)
{
float XYDiv=GetLayerZPosDiv();
int MapW=Map.GetWidth();
int MapH=Map.GetHeight();
float StartX=MapPos.x/XYDiv;
float StartY=MapPos.y/XYDiv;
CTexCache &TexCache=Core->GetTexCache();
glMatrixMode(GL_MODELVIEW);
for (int YLoop=0; YLoop<MapH; YLoop++)
{
for (int XLoop=0; XLoop<MapW; XLoop++)
{
sMapElem &ThisElem=Map.GetTile(XLoop,YLoop);
CTile &ThisTile=Core->GetTile(ThisElem.Bank,ThisElem.Tile);
glLoadIdentity(); // Slow way, but good to go for the mo
glTranslatef(StartX+XLoop,StartY-YLoop,MapPos.z);
ThisTile.Render();
}
}
}
/*****************************************************************************/
void CLayer::RenderGrid(CCore *Core,Vec &MapPos)
{
float XYDiv=GetLayerZPosDiv();
int MapW=Map.GetWidth();
int MapH=Map.GetHeight();
float StartX=MapPos.x/XYDiv;
float StartY=MapPos.y/XYDiv;
float OverVal=0.5;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(StartX,StartY,MapPos.z);
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glNormal3f( 1,1,1);
glColor3ub(255,255,255);
for (int YLoop=0; YLoop<MapH+1; YLoop++)
{
glVertex3f( 0-OverVal, -YLoop+1, 0);
glVertex3f( MapW+OverVal, -YLoop+1, 0);
}
for (int XLoop=0; XLoop<MapW+1; XLoop++)
{
glVertex3f( XLoop, 0+1+OverVal, 0);
glVertex3f( XLoop, -MapH+1-OverVal, 0);
}
glEnd();
glEnable(GL_TEXTURE_2D);
}
/*****************************************************************************/
void CLayer::FindCursorPos(CCore *Core,CMapEditView *View,Vec &MapPos,CPoint &MousePos)
{
GLint Viewport[4];
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
int HitCount;
int TileID=0;
CPoint &CursorPos=Core->GetCursorPos();
float XYDiv=GetLayerZPosDiv();
int MapW=Map.GetWidth();
int MapH=Map.GetHeight();
float StartX=MapPos.x/XYDiv;
float StartY=MapPos.y/XYDiv;
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);
View->SetupPersMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(StartX,StartY,MapPos.z);
for (int YLoop=0; YLoop<MapH; YLoop++)
{
for (int XLoop=0; XLoop<MapW; XLoop++)
{
glLoadName (TileID);
glBegin (GL_QUADS);
BuildGLQuad(XLoop,XLoop+1,-YLoop,-YLoop+1,0);
glEnd();
TileID++;
}
}
HitCount= glRenderMode (GL_RENDER);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
CursorPos.x=CursorPos.y=-1;
// Process hits
GLuint *HitPtr=SelectBuffer;
if (HitCount) // Just take 1st
{
int HitID=HitPtr[3];
CursorPos.x=HitID%MapW;
CursorPos.y=HitID/MapW;
}
glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert
sprintf(Name,"%s",_Name);
}
/*****************************************************************************/

View File

@ -29,30 +29,27 @@ enum LAYER_TYPE
/*****************************************************************************/
class CCore;
class CMap;
class CMapEditView;
class CLayer
{
public:
CLayer();
~CLayer();
CLayer(){};
virtual ~CLayer(){};
// Virtual
virtual void Init()=0;
virtual char *GetName()=0;
virtual void Render(CCore *Core,Vec &MapPos,BOOL Is3d);
virtual void Render2d(CCore *Core,Vec &MapPos);
virtual void Render3d(CCore *Core,Vec &MapPos);
virtual void RenderGrid(CCore *Core,Vec &MapPos);
virtual char *GetName();
virtual void SetName(char *_Name);
virtual float GetLayerZPosDiv()=0;
virtual BOOL CanRender3d()=0;
virtual float GetLayerZPosDiv() {return(ZPosDiv);}
virtual void FindCursorPos(CCore *Core,CMapEditView *View,Vec &MapPos,CPoint &MousePos);
virtual void Render(CCore *Core,Vec &MapPos,BOOL Is3d)=0;
virtual void RenderGrid(CCore *Core,Vec &MapPos)=0;
virtual void FindCursorPos(CCore *Core,CMapEditView *View,Vec &MapPos,CPoint &MousePos)=0;
protected:
CMap Map;
char Name[256];
BOOL Render3dFlag;
float ZPosDiv;
};

View File

@ -2,8 +2,8 @@
[General Info]
Version=1
LastClass=CMapEditView
LastTemplate=CFrameWnd
LastClass=CAboutDlg
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "mapedit.h"
LastPage=0
@ -20,10 +20,10 @@ Class8=CMapEditView
ResourceCount=6
Resource1=IDR_MAPEDITYPE (English (U.S.))
Resource2=IDR_MAINFRAME (English (U.S.))
Resource2=IDD_ABOUTBOX (English (U.S.))
Resource3=IDD_LAYERBAR1 (English (U.S.))
Resource4=IDD_LAYERBAR (English (U.S.))
Resource5=IDD_ABOUTBOX (English (U.S.))
Resource5=IDR_MAINFRAME (English (U.S.))
Resource6=IDD_TILEBAR (English (U.S.))
[CLS:CChildFrame]
@ -84,7 +84,7 @@ Type=0
BaseClass=CGLEnabledView
HeaderFile=MapEditView.h
ImplementationFile=MapEditView.cpp
LastObject=ID_TOOLBAR_LAYERBAR
LastObject=ID_NEWMAP_OK
Filter=C
VirtualFilter=VWC

View File

@ -102,35 +102,11 @@ SOURCE=.\Layer.h
# End Source File
# Begin Source File
SOURCE=.\LayerAction.cpp
SOURCE=.\LayerTile.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerAction.h
# End Source File
# Begin Source File
SOURCE=.\LayerBack.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerBack.h
# End Source File
# Begin Source File
SOURCE=.\LayerFore.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerFore.h
# End Source File
# Begin Source File
SOURCE=.\LayerMid.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerMid.h
SOURCE=.\LayerTile.h
# End Source File
# End Group
# Begin Source File

View File

@ -69,10 +69,9 @@ char Dir[_MAX_DIR];
char Fname[_MAX_FNAME];
char Ext[_MAX_EXT];
sprintf(FullName,"%s",_Filename);
_splitpath(_Filename,Drive,Dir,Fname,Ext);
sprintf(Path,"%s%s",Drive,Dir);
sprintf(Filename,"%s%s",Fname,Ext);
sprintf(Name,"%s",Fname);
Loaded=FALSE;
}
@ -89,8 +88,10 @@ CTileSet::~CTileSet()
void CTileSet::Load(CCore *Core)
{
CScene Scene;
char Filename[256+64];
Scene.Load(FullName);
sprintf(Filename,"%s%s.%s",Path,Name,"Gin");
Scene.Load(Filename);
CNode &ThisNode=Scene.GetSceneNode(0);
int ChildCount=ThisNode.GetPruneChildCount();

View File

@ -48,12 +48,12 @@ public:
int IsLoaded() {return(Loaded);}
void Load(CCore *Core);
char *GetPath() {return(Path);}
char *GetFilename() {return(Filename);}
char *GetName() {return(Name);}
CTile &GetTile(int No) {return(Tile[No]);}
private:
char FullName[256],Path[256],Filename[256];
char Path[256],Name[256];
std::vector<CTile> Tile;
BOOL Loaded;

View File

@ -23,9 +23,9 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 141
#define _APS_NEXT_RESOURCE_VALUE 142
#define _APS_NEXT_COMMAND_VALUE 32775
#define _APS_NEXT_CONTROL_VALUE 1015
#define _APS_NEXT_CONTROL_VALUE 1018
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif