📄 3dgamemap.cpp
字号:
//---------------------------------------------------------------------------//
// Gamemap.cpp
//---------------------------------------------------------------------------//
// header ...
#pragma warning(disable:4786)
#include "3DGameMap.h"
#include "TerrainLayer.h"
#include "Interactivelayer.h"
#include "SurfaceLayer.h"
#include "SceneLayer.h"
#include "FloorLayer.h"
#include "SkyLayer.h"
#include "Hero.h"
#include "GamePlayerSet.h"
#include "2DMapPuzzleObj.h"
#include "GameDataSet.h"
#include "3DRole.h"
#include "InfoViewManager.h"
#include "Gamemsg.h"
#include "3DMagicMapItem.h"
#include "3DMapItem.h"
//---------------------------------------------------------------------------//
// gobal ...
CGameMap g_objGameMap;
#ifdef _ANALYSIS_ON
BOOL g_bShowAnalysisInfo = false;
#endif
//---------------------------------------------------------------------------//
CGameMap::CGameMap()
{
m_setMapLayer.clear();
CTerrainLayer* pTerrainLayer = CTerrainLayer::CreateNew();
this->AddLayer(pTerrainLayer);
CFloorLayer * pFloorLayer = CFloorLayer::CreateNew();
this->AddLayer(pFloorLayer);
CSurfaceLayer* pSurfaceLayer = CSurfaceLayer::CreateNew();
this->AddLayer(pSurfaceLayer);
CInteractiveLayer* pInteractiveLayer = CInteractiveLayer::CreateNew();
this->AddLayer(pInteractiveLayer);
CSkyLayer * pSkyLayer = CSkyLayer::CreateNew();
this->AddLayer(pSkyLayer);
//for a*
m_setPath.clear();
m_setCellAStar.clear();
m_setNode.clear();
m_setOpen.clear();
m_nCloseNodeAmount = 0;
m_posView.x = 0;
m_posView.y = 0;
//CMyBitmap::GameCameraCreate();
m_pCellInfo = NULL;
m_nPathMode = _ASTAR_CLOSE;
m_idMap = ID_NONE;
m_idDoc = ID_NONE;
m_bShowMiniMap = true;
m_posViewOffset.x = 0;
m_posViewOffset.y = 0;
m_bShowMapObjInfo = false;
m_dwMapARGB = 0xffffffff;
this->SetScale(_NORMAL_SCALE);
this->CreateRegionData();
m_setIndexLayerInfo.clear();
m_bShowRegionEffect = false;
m_bShowGobalRegionEffect = false;
m_bShowExp = false;
m_dwTimeExpBegin = ::TimeGet();
m_dwShowExp = 0;
m_bShowScreenInfo = false;
m_bBrume = false;
this->CreateRegionEffectInfo();
}
//---------------------------------------------------------------------------//
CGameMap::~CGameMap()
{
m_setIndexLayerInfo.clear();
this->ClearNodeSet();
this->ClearOpenSet();
this->ClearCloseSet();
this->ClearPathSet();
m_objTerrainEffectManager.Destroy();
CMyBitmap::GameCameraDestroy();
this->DestroyRegionData();
this->ClearMapLayer();
this->DestroyCell();
this->ClearRes ();
this->DestroyRegionEffectInfo();
}
//---------------------------------------------------------------------------//
void CGameMap::Reset()
{
m_objMagicEffectManager.Destroy();
m_objItemManager.Destroy();
m_objTerrainObjManager.Destroy();
m_objTerrainEffectManager.Destroy();
this->ClearMapLayer();
this->ClearNodeSet();
this->ClearOpenSet();
this->ClearCloseSet();
this->ClearPathSet();
this->ClearRes ();
CTerrainLayer* pTerrainLayer = CTerrainLayer::CreateNew();
this->AddLayer(pTerrainLayer);
CFloorLayer * pFloorLayer = CFloorLayer::CreateNew();
this->AddLayer(pFloorLayer);
CSurfaceLayer* pSurfaceLayer = CSurfaceLayer::CreateNew();
this->AddLayer(pSurfaceLayer);
CInteractiveLayer* pInteractiveLayer = CInteractiveLayer::CreateNew();
this->AddLayer(pInteractiveLayer);
CSkyLayer * pSkyLayer = CSkyLayer::CreateNew();
this->AddLayer(pSkyLayer);
//for a*
m_setPath.clear();
m_setCellAStar.clear();
m_setNode.clear();
m_setOpen.clear();
m_nCloseNodeAmount = 0;
strcpy(m_szRegionName, "");
m_dwRegionNameChangeBegin = ::TimeGet();
m_setIndexLayerInfo.clear();
this->ClearRes();
m_nCurRegionEffectIndex = -1;
m_dwTimeRegionEffect = 0;
}
//---------------------------------------------------------------------------//
void CGameMap::ClearMapLayer()
{
int nAmount = m_setMapLayer.size();
for(int i = 0; i < nAmount; i++)
{
CMapLayer* pLayer = m_setMapLayer[i];
SAFE_DELETE (pLayer);
}
m_setMapLayer.clear();
}
//---------------------------------------------------------------------------//
void CGameMap::Show(BOOL bMapItemInfo)
{
this->SetShowMapObjInfoFlag(bMapItemInfo);
CMySize sizeScr = {m_nRealScreenWidth, m_nRealScreenHeight};
CMyBitmap::GameCameraBuild(sizeScr);
CMyPos posBgViewport;
this->GetBgViewport(posBgViewport.x, posBgViewport.y);
int nAmount = m_setMapLayer.size();
for(int i = 0; i < nAmount; i++)
{
CMapLayer* pLayer = m_setMapLayer[i];
if(pLayer)
{
pLayer->Show(posBgViewport);
}
}
m_InfoViewManager.Show();
m_InfoViewManager.Clear();
// show mini map
// if (m_bShowMiniMap)
// {
// m_objRadar.Show(m_idDoc);
// }
// g_objHero.ShowArrow(sizeMiniMap.iWidth);
CMyPos posTeam;
posTeam.y = 128;
//g_objHero.ShowTeam(posTeam);
g_objHero.ShowSynWarReport();
this->ShowRegionName();
this->ShowExp();
g_objHero.m_objDiceManager.Show();
this->ShowSnow();
this->ShowBrume();
/* char szDir[64];
sprintf(szDir, "DIR:%d ACTION:%d", g_objHero.GetDir(), g_objHero.GetActionType());
CMyBitmap::ShowString(100, 100, 0x00ffff00, szDir);*/
#ifdef _ARHUN_DEBUG
//this->ShowPath();
//this->ShowCell(false, true, false, false);
#endif
#ifdef _ANALYSIS_ON
if(g_bShowAnalysisInfo)
{
char szTemp[256];
DWORD dwLoadTotal = g_dwBitmapLoadTimeFrame + g_dw3DObjLoadTimeFrame + g_dw3DMotionLoadTimeFrame + g_dw3DTextureLoadTimeFrame + g_dw3DEffectLoadTimeFrame;
static DWORD dwLoadBusy = 0;
if(dwLoadTotal > 30)
{
sprintf(szTemp, "数据加载引发减祯:FrameCost:%u, Total:%u, Bitmap:%u, Phy:%u, Motion%u, Texture:%u, Effect:%u", g_dwFrameInterval, dwLoadTotal, g_dwBitmapLoadTimeFrame, g_dw3DObjLoadTimeFrame, g_dw3DMotionLoadTimeFrame, g_dw3DTextureLoadTimeFrame, g_dw3DEffectLoadTimeFrame);
::LogMsg("//-------------------------------------------------------------------");
::LogMsg(szTemp);
::LogMsg("//-------------------------------------------------------------------");
dwLoadBusy ++;
}
sprintf(szTemp, "数据加载分析:(数据加载耗时超过30毫秒次数%u)", dwLoadBusy);
CMyBitmap::ShowString(10, 80, 0xffff00ff, szTemp);
sprintf(szTemp, "Bitmap加载:数量%u, 总耗时%u, 平均耗时%u, 峰值%u, 祯间峰值%u", g_dwBitmapLoadAmount, g_dwBitmapLoadTime, g_dwBitmapLoadTime/(g_dwBitmapLoadAmount+1), g_dwBitmapLoadTimeMax, g_dwBitmapLoadTimeFrame);
CMyBitmap::ShowString(10, 100, 0xffffff00, szTemp);
sprintf(szTemp, "Phy加载:数量%u, 总耗时%u, 平均耗时%u, 峰值%u, 祯间峰值%u", g_dw3DObjLoadAmount, g_dw3DObjLoadTime, g_dw3DObjLoadTime/(g_dw3DObjLoadAmount+1), g_dw3DObjLoadTimeMax, g_dw3DObjLoadTimeFrame);
CMyBitmap::ShowString(10, 120, 0xffffff00, szTemp);
sprintf(szTemp, "Motion加载:数量%u, 总耗时%u, 平均耗时%u, 峰值%u, 祯间峰值%u", g_dw3DMotionLoadAmount, g_dw3DMotionLoadTime,g_dw3DMotionLoadTime/(g_dw3DMotionLoadAmount+1), g_dw3DMotionLoadTimeMax, g_dw3DMotionLoadTimeFrame);
CMyBitmap::ShowString(10, 140, 0xffffff00, szTemp);
sprintf(szTemp, "Texture加载:数量%u, 总耗时%u, 平均耗时%u, 峰值%u, 祯间峰值%u", g_dw3DTextureLoadAmount, g_dw3DTextureLoadTime, g_dw3DTextureLoadTime/(g_dw3DTextureLoadAmount+1), g_dw3DTextureLoadTimeMax, g_dw3DTextureLoadTimeFrame);
CMyBitmap::ShowString(10, 160, 0xffffff00, szTemp);
sprintf(szTemp, "Effect加载:数量%u, 总耗时%u, 平均耗时%u, 峰值%u, 祯间峰值%u", g_dw3DEffectLoadAmount, g_dw3DEffectLoadTime, g_dw3DEffectLoadTime/(g_dw3DEffectLoadAmount+1), g_dw3DEffectLoadTimeMax, g_dw3DEffectLoadTimeFrame);
CMyBitmap::ShowString(10, 180, 0xffffff00, szTemp);
g_dwBitmapLoadTimeFrame = g_dw3DObjLoadTimeFrame = g_dw3DMotionLoadTimeFrame = g_dw3DTextureLoadTimeFrame = g_dw3DEffectLoadTimeFrame = 0;
CMyBitmap::ShowString(10, 200, 0xffff00ff, "文本搜索分析:");
sprintf(szTemp, "搜索次数%u,搜索行数%u,祯间搜索次数%u,祯间搜索行数%u", g_dwIniGetAmount, g_dwIniSearchLineAmount, g_dwIniGetAmountFrame, g_dwIniSearchLineAmountFrame);
g_dwIniGetAmountFrame = 0;
g_dwIniSearchLineAmountFrame = 0;
CMyBitmap::ShowString(10, 220, 0xffffff00, szTemp);
CMyBitmap::ShowString(10, 240, 0xffff00ff, "GamedataSet分析:");
DWORD dw3DObj, dw3DMotion, dw3DWMotion, dwTexture, dw3DEffect, dwDataAni;
g_objGameDataSet.GetObjAmount(dw3DObj, dw3DMotion, dw3DWMotion, dwTexture, dw3DEffect, dwDataAni);
sprintf(szTemp, "物件数量:3DObj %u, 3DMotion %u, 3DWMotion %u, 3DTexture %u, 3DEffect %u, DataAni %u", dw3DObj, dw3DMotion, dw3DWMotion, dwTexture, dw3DEffect, dwDataAni);
CMyBitmap::ShowString(10, 260, 0xffffff00, szTemp);
sprintf(szTemp, "物件祯搜索数量:3DObj %u, 3DMotion %u, 3DWMotion %u, 3DTexture %u, 3DEffect %u, DataAni %u", g_dw3DObj, g_dw3DMotion, g_dw3DWMotion, g_dwTexture, g_dw3DEffect, g_dwDataAni);
CMyBitmap::ShowString(10, 280, 0xffffff00, szTemp);
g_dw3DObj=0, g_dw3DMotion=0, g_dw3DWMotion=0, g_dwTexture=0, g_dw3DEffect=0, g_dwDataAni=0;
CMyBitmap::ShowString(10, 300, 0xffff00ff, "显示分析:");
if(g_dw3DRoleDrawAmount == 0) g_dw3DRoleDrawAmount = 1;
if(g_dw3DRoleDrawAmountFrame == 0) g_dw3DRoleDrawAmountFrame = 1;
sprintf(szTemp, "3DRole: 总数量%u,总耗时%u,均值%u,祯间数量%u,祯间耗时%u,祯间均值%u,峰值%u", g_dw3DRoleDrawAmount, g_dw3DRoleDrawTime, g_dw3DRoleDrawTime/g_dw3DRoleDrawAmount, g_dw3DRoleDrawAmountFrame, g_dw3DRoleDrawTimeFrame, g_dw3DRoleDrawTimeFrame/g_dw3DRoleDrawAmountFrame, g_dw3DRoleDrawTimeMax);
g_dw3DRoleDrawAmountFrame = g_dw3DRoleDrawTimeFrame = 0;
CMyBitmap::ShowString(10, 320, 0xffffff00, szTemp);
sprintf(szTemp, "Gamemsg显示TimeCost: %u", g_dwTxtMsgTimeCost);
CMyBitmap::ShowString(10, 340, 0xffffff00, szTemp);
g_dwTxtMsgTimeCost = 0;
sprintf(szTemp, "大贴图数量: %u", g_dwBigTexture);
CMyBitmap::ShowString(10, 360, 0xffff00ff, szTemp);
}
#endif
sizeScr.iWidth = _SCR_WIDTH;
sizeScr.iHeight = _SCR_HEIGHT;
CMyBitmap::ClearBuffer(true, false, 0x0);
CMyBitmap::GameCameraBuild(sizeScr);
this->ShowScreenInfo();
}
//---------------------------------------------------------------------------//
void CGameMap::ShowMiniMap(CMySize& sizeMap)
{
const char szAniFile[] = "ani/MiniMap.ani";
char szAniName[256] = "";
sprintf(szAniName, "%u", m_idDoc);
}
//---------------------------------------------------------------------------//
void CGameMap::ProcessManager()
{
m_objTerrainObjManager.Process();
m_objItemManager.Process();
return;
CInteractiveLayer* pLayer = this->GetInteractiveLayer();
if(pLayer)
{
// 判断删除
CMyPos posHero = g_objHero.GetAlignPos();
int nAmount = pLayer->GetObjAmount();
for(int i = nAmount-1; i >= 0; i --)
{
CMapObj * pObj = pLayer->GetObjByIndex(i);
if(pObj && (pObj->GetObjType() == MAP_3DMAGICMAPITEM || pObj->GetObjType() == MAP_3DITEM
|| pObj->GetObjType() == MAP_2DITEM))
{
CMyPos posCell;
pObj->GetPos(posCell);
if(g_objGameMap.Outof9Block(posHero, posCell))
{
pLayer->DelObj(pObj);
}
}
}
}
}
//---------------------------------------------------------------------------//
void CGameMap::Process(void* pInfo)
{
// ToDo
m_objMagicEffectManager.Process();
m_objTerrainEffectManager.Process();
int nAmount = m_setMapLayer.size();
for(int i = 0; i < nAmount; i++)
{
CMapLayer* pLayer = m_setMapLayer[i];
if(pLayer)
pLayer->Process(NULL);
}
m_nRealScreenWidth = _SCR_WIDTH * _NORMAL_SCALE / m_nScale;
m_nRealScreenHeight = _SCR_HEIGHT * _NORMAL_SCALE / m_nScale;
}
//---------------------------------------------------------------------------//
void CGameMap::AddLayer(CMapLayer* pLayer, int nIndex)
{
if(!pLayer)
return;
int nAmount = m_setMapLayer.size();
if((nIndex < 0) || (nIndex >= nAmount))
{
m_setMapLayer.push_back(pLayer);
return;
}
else
{
m_setMapLayer.insert(m_setMapLayer.begin()+nIndex, 1, pLayer);
}
}
//---------------------------------------------------------------------------//
CTerrainLayer* CGameMap::GetTerrainLayer()
{
int nAmount = m_setMapLayer.size();
for(int i = 0; i < nAmount; i++)
{
CMapLayer* pLayer = m_setMapLayer[i];
if(pLayer)
{
if(pLayer->GetType() == CMapLayer::LAYER_TERRAIN)
return (CTerrainLayer*)pLayer;
}
}
return NULL;
}
//---------------------------------------------------------------------------//
CInteractiveLayer* CGameMap::GetInteractiveLayer()
{
int nAmount = m_setMapLayer.size();
for(int i = 0; i < nAmount; i++)
{
CMapLayer* pLayer = m_setMapLayer[i];
if(pLayer)
{
if(pLayer->GetType() == CMapLayer::LAYER_INTERACTIVE)
return (CInteractiveLayer*)pLayer;
}
}
return NULL;
}
CFloorLayer * CGameMap::GetFloorLayer()
{
int nAmount = m_setMapLayer.size();
for(int i = 0; i < nAmount; i++)
{
CMapLayer* pLayer = m_setMapLayer[i];
if(pLayer)
{
if(pLayer->GetType() == CMapLayer::LAYER_FLOOR)
return (CFloorLayer*)pLayer;
}
}
return NULL;
}
CSkyLayer * CGameMap::GetSkyLayer()
{
int nAmount = m_setMapLayer.size();
for(int i = 0; i < nAmount; i++)
{
CMapLayer* pLayer = m_setMapLayer[i];
if(pLayer)
{
if(pLayer->GetType() == CMapLayer::LAYER_SKY)
return (CSkyLayer*)pLayer;
}
}
return NULL;
}
//---------------------------------------------------------------------------//
void CGameMap::World2Cell(int iWorldX,int iWorldY,int& iCellX,int& iCellY)
{
iWorldX -=m_posOrigin.x;
iWorldY -=m_posOrigin.y;
double dWorldX =(double)iWorldX;
double dWorldY =(double)iWorldY;
double dCellWidth =(double)_CELL_WIDTH;
double dCellHeight =(double)_CELL_HEIGHT;
double dTemp0 =(1.0*dWorldX)/(1.0*dCellWidth) + (1.0*dWorldY)/(1.0*dCellHeight);
double dTemp1 =(1.0*dWorldY)/(1.0*dCellHeight) - (1.0*dWorldX)/(1.0*dCellWidth);
iCellX =Double2Int(dTemp0);
iCellY =Double2Int(dTemp1);
}
//---------------------------------------------------------------------------//
void CGameMap::World2Screen(int iWorldX,int iWorldY,int& iScrX,int& iScrY)
{
iScrX =iWorldX-m_posView.x;
iScrY =iWorldY-m_posView.y;
}
//---------------------------------------------------------------------------//
void CGameMap::Cell2World(int iCellX,int iCellY,int& iWorldX,int& iWorldY)
{
iWorldX =_CELL_WIDTH*(iCellX-iCellY)/2+m_posOrigin.x;
iWorldY =_CELL_HEIGHT*(iCellX+iCellY)/2+m_posOrigin.y;
}
//---------------------------------------------------------------------------//
void CGameMap::Cell2Screen(int iCellX,int iCellY,int& iScreenX,int& iScreenY)
{
iScreenX = _CELL_WIDTH*(iCellX-iCellY)/2+m_posOrigin.x-m_posView.x;
iScreenY = _CELL_HEIGHT*(iCellX+iCellY)/2+m_posOrigin.y-m_posView.y;
}
//---------------------------------------------------------------------------//
void CGameMap::Screen2World(int iScrX,int iScrY,int& iWorldX,int& iWorldY)
{
iWorldX = m_posView.x + iScrX;
iWorldY = m_posView.y + iScrY;
}
//---------------------------------------------------------------------------//
void CGameMap::Screen2Cell(int iScrX,int iScrY,int& iCellX,int& iCellY)
{
int iWorldX,iWorldY;
iWorldX =iScrX+m_posView.x;
iWorldY =iScrY+m_posView.y;
World2Cell(iWorldX,iWorldY,iCellX,iCellY);
if(iCellX < 0)
iCellX =0;
else if(iCellX >= this->m_sizeMap.iWidth)
iCellX =this->m_sizeMap.iWidth-1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -