// DXIsoMap.cpp: implementation of the CDXIsoMap class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DXIsoMap.h"
#include "DDDevice.h"
#include "DDDIBSurface.h"
#include "PackFile.h"
#include "IsoType.h"
//#include "stdafx.h"
//#include "Isotest.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
const CHAR CDXIsoMap::m_CellFigue[16][32] =
{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
{1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2},
{1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2},
{1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2},
{1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2},
{1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4},
{3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4},
{3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}
};
const int CDXIsoMap::m_nCellWidth = 32;
const int CDXIsoMap::m_nCellHeight = 16;
const int CDXIsoMap::m_nCellWidthShift = 5;
const int CDXIsoMap::m_nCellHeightShift = 4;
const BYTE CDXIsoMap::m_CellIdxFlg = 0x10;
const BYTE CDXIsoMap::m_CellRmrFlg = 0X20;
const BYTE CDXIsoMap::m_CellNpcFlg = 0x40;
const BYTE CDXIsoMap::m_CellLnkFlg = 0x80;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDXIsoMap::CDXIsoMap()
{
m_bAutoDelete = false;
m_pMapData = NULL;
m_nPosX = 0;
m_nPosY = 0;
m_nPosTX = 0;
m_nPosTY = 0;
m_nOffX = 0;
m_nOffY = 0;
m_pPassValues = NULL;
m_pTiles = NULL;
}
CDXIsoMap::~CDXIsoMap()
{
if (m_pPassValues != NULL)
{
delete []m_pPassValues;
m_pPassValues = NULL;
}
if (m_pMapData != NULL)
{
delete []m_pMapData;
m_pMapData = NULL;
}
if (m_bAutoDelete == true)
{
if (m_pTiles != NULL)
{
delete m_pTiles;
}
}
m_pTiles = NULL;
}
bool CDXIsoMap::Create(CDDSurface* pTiles,
LPCTSTR lpszFileName,
CPackFileManager* pPackFileManager/* = NULL*/)
{
ASSERT(pTiles != NULL);
ASSERT(lpszFileName != NULL);
int nCellColumns;
int nCellRows;
CELL* pMapData = NULL;
if (pPackFileManager != NULL) // use CPackFile
{
CPackFile packFile;
if (packFile.Open(pPackFileManager, lpszFileName) == false)
return false;
packFile.Read(&nCellColumns, sizeof(int));
packFile.Read(&nCellRows, sizeof(int));
int nSize = nCellColumns * nCellRows;
pMapData = new CELL[nSize];
ASSERT(pMapData != NULL);
packFile.Read(pMapData, sizeof(CELL) * nSize);
}
else
{
HANDLE fh = ::CreateFile(lpszFileName, GENERIC_READ,
FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (fh == INVALID_HANDLE_VALUE)
return false;
DWORD dwRead;
::ReadFile(fh, &nCellColumns, sizeof(int), &dwRead, NULL);
::ReadFile(fh, &nCellRows, sizeof(int), &dwRead, NULL);
int nSize = nCellColumns * nCellRows;
pMapData = new CELL[nSize];
ASSERT(pMapData != NULL);
::ReadFile(fh, pMapData, sizeof(CELL) * nSize, &dwRead, NULL);
::CloseHandle(fh);
}
return Create(pTiles,
nCellColumns, nCellRows,
pMapData);
}
bool CDXIsoMap::Save(LPCTSTR lpszFileName)
{
HANDLE fh = ::CreateFile(lpszFileName, GENERIC_WRITE,
0, (LPSECURITY_ATTRIBUTES)NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if (fh == INVALID_HANDLE_VALUE)
return false;
DWORD dwWriteBytes;
::WriteFile(fh, &m_nColumns, sizeof(int), &dwWriteBytes, NULL);
::WriteFile(fh, &m_nRows, sizeof(int), &dwWriteBytes, NULL);
::WriteFile(fh, m_pMapData, sizeof(int) * m_nColumns * m_nRows, &dwWriteBytes, NULL);
::CloseHandle(fh);
return true;
}
bool CDXIsoMap::Create(CDDSurface* pTiles,
int nCellColumns, int nCellRows,
CELL* pMapData)
{
m_pTiles = pTiles;
m_nPosX = m_nCellWidth >> 1;
m_nPosY = m_nCellHeight >> 1;
m_nColumns = nCellColumns;
m_nRows = nCellRows;
m_nTotalWidth = m_nColumns << (m_nCellWidthShift - 1);
m_nTotalHeight = m_nRows << m_nCellHeightShift;
ASSERT(m_pMapData == NULL);
m_pMapData = pMapData;
m_nSrcSurfaceCellRows = (m_pTiles->GetWidth() / m_nCellWidth);
return true;
}
bool CDXIsoMap::Create(CDDSurface* pTiles,
int nCellColumns, int nCellRows, int nFill)
{
int nSize = nCellColumns * nCellRows;
CELL* pMapData = new CELL[nSize];
ASSERT(pMapData != NULL);
for (int i = 0; i < nSize; ++ i)
{
pMapData[i].base.index = (BYTE)nFill;
if (nFill & 0X100)
pMapData[i].base.flag = m_CellIdxFlg;
else pMapData[i].base.flag = 0;
pMapData[i].fringe.index = 0;
pMapData[i].fringe.flag = 0;
}
return Create(pTiles,
nCellColumns, nCellRows,
pMapData);
}
// 在屏幕的(nDestX, nDestY)位置画图块
// IN:
// nDestX
// nDestY: 屏幕坐标
void CDXIsoMap::BltTile(CDDSurface* pDestSurface,
int nDestX, int nDestY, CELL* pCell)
{
RECT drc, drc0;
drc.left = nDestX;
drc.top = nDestY;
drc.right = nDestX + m_nCellWidth;
drc.bottom = nDestY + m_nCellHeight;
if (IntersectRect(&drc0, &drc, &m_rcDest))
{
int nOffY = drc0.top - drc.top;
int nOffX = drc0.left - drc.left;
int nW = drc0.right - drc0.left;
int nH = drc0.bottom - drc0.top;
int nTileIndex = pCell->base.index;
if (pCell->base.flag & m_CellIdxFlg)
nTileIndex += 0x100;
int x1, y1;
RECT src;
if (nTileIndex)
{
x1 = (nTileIndex % m_nSrcSurfaceCellRows) << m_nCellWidthShift;
y1 = (nTileIndex / m_nSrcSurfaceCellRows) << m_nCellHeightShift;
src.top = y1 + nOffY;
src.left = x1 + nOffX;
src.bottom = src.top + nH;
src.right = src.left + nW;
m_pTiles->Draw(pDestSurface, drc0.left, drc0.top, &src);
}
nTileIndex = pCell->fringe.index;
if (pCell->fringe.flag & m_CellIdxFlg)
nTileIndex += 0x100;
if (nTileIndex)
{
x1 = (nTileIndex % m_nSrcSurfaceCellRows) << m_nCellWidthShift;
y1 = (nTileIndex / m_nSrcSurfaceCellRows) << m_nCellHeightShift;
src.top = y1 + nOffY;
src.left = x1 + nOffX;
src.bottom = src.top + nH;
src.right = src.left + nW;
m_pTiles->Draw(pDestSurface, drc0.left, drc0.top, &src);
}
}
}
void CDXIsoMap::SetViewRect(LPRECT lprcView)
{
ASSERT(lprcView != NULL);
m_rcDest.top = lprcView->top;
m_rcDest.left = lprcView->left;
m_rcDest.bottom = lprcView->bottom;
m_rcDest.right = lprcView->right;
}
void CDXIsoMap::Draw(CDDSurface* pDestSurface, LPRECT lprcDest)
{
if (lprcDest != NULL)
{
m_rcDest.top = lprcDest->top;
m_rcDest.left = lprcDest->left;
m_rcDest.bottom = lprcDest->bottom;
m_rcDest.right = lprcDest->right;
}
int nHalfW = m_nCellWidth >> 1;
int nHalfH = m_nCellHeight >> 1;
int nOffsetX;
int nOffsetY;
if (m_nPosTX & 1)
{
nOffsetX = (m_nPosX-nHalfW) & (m_nCellWidth-1);
nOffsetY = (m_nPosY-nHalfH) & (m_nCellHeight-1);
}
else
{
nOffsetX = m_nPosX & (m_nCellWidth-1);
nOffsetY = m_nPosY & (m_nCellHeight-1);
}
nOffsetX = -nOffsetX;
nOffsetY = -nOffsetY;
int nOffTx, nOffTy;
if (m_nPosTX & 1)
{
nOffTx = m_nPosTX - 1;
nOffTy = m_nPosTY;
nOffsetX = nOffsetX - nHalfW;
nOffsetY = nOffsetY - nHalfH;
}
else
{
nOffTx = m_nPosTX - 2;
nOff
GZM888888
- 粉丝: 526
- 资源: 3066
最新资源
- 指针扫描和内存遍历二合一工具
- 基于JavaScript的在线考试系统(编号:65965158)(1).zip
- 五相电机双闭环矢量控制模型-采用邻近四矢量SVPWM-MATLAB-Simulink仿真模型包括: (1)原理说明文档(重要):包括扇区判断、矢量作用时间计算、矢量作用顺序及切时间计算、PWM波的生成
- Linux下的cursor安装包
- springboot-教务管理系统(编号:62528147).zip
- 3dmmods_倾城系列月白_by_白嫖萌新.zip
- SVPWM+死区补偿(基于电流极性)+高频注入法辨识PMSM的dq轴电感(离线辨识)-simulink
- 微信跑腿小程序的设计与实现
- 基于 Java 实现的上位机通讯程序,可与单片机进行数据交换
- screentshot-2024.12.22-20.45.35.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈