📄 visioninfo.cpp
字号:
////////////////////////////////////////////////////////////////////////////////// Filename : Vision.cpp// Written By : Reiot// Description : ////////////////////////////////////////////////////////////////////////////////#include "VisionInfo.h"#include "Assert.h"#include "LogClient.h"////////////////////////////////////////////////////////////////////////////////// global variable definition////////////////////////////////////////////////////////////////////////////////VisionInfoManager* g_pVisionInfoManager = NULL;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*VisionInfo::VisionInfo (Sight_t sight , Dir_t dir) throw(){ __BEGIN_TRY m_Sight = sight; m_Dir = dir; // 烙矫 矫具 康开 VisionState temp1[maxVisionWidth][maxVisionHeight]; VisionState temp2[maxVisionWidth][maxVisionHeight]; //-------------------------------------------------------------------------------- // temp1, temp2, m_Rect 甫 葛滴 OUT_OF_SIGHT肺 檬扁拳茄促. //-------------------------------------------------------------------------------- for (int x = 0 ; x < maxVisionWidth ; x ++) { for (int y = 0 ; y < maxVisionHeight ; y ++) { m_Rect[x][y] = temp1[x][y] = temp2[x][y] = OUT_OF_SIGHT; } } // 吝缴痢篮 (10,11)捞 等促.// int cx = maxViewportWidth + 1;// int cy = maxViewportUpperHeight + 1; int cx = maxViewportWidth; int cy = maxViewportUpperHeight; int startx = max(0 , cx - m_Sight); int starty = max(0 , cy - m_Sight); int endx = min(maxVisionWidth - 1 , cx + m_Sight); int endy = min(maxVisionHeight - 1 , cy + m_Sight); //-------------------------------------------------------------------------------- // m_Rect 狼 IN_SIGHT, OUT_OF_SIGHT 康开阑 瘤沥茄促. //-------------------------------------------------------------------------------- for (int x = 1 ; x < maxVisionWidth - 1 ; x ++) { for (int y = 1 ; y < maxVisionHeight - 1 ; y ++) { if (x >= startx && x <= endx && y >= starty && y <= endy) { int dist = abs(cx - x) + abs(cy - y); if (dist <= m_Sight + (m_Sight >> 1)) { m_Rect[x][y] = IN_SIGHT; } } } } //-------------------------------------------------------------------------------- // temp1 = m_Rect << 1 //-------------------------------------------------------------------------------- int dx = 0, dy = 0; switch (m_Dir) { case LEFT : dx--; break; case LEFTDOWN : dx--; dy++; break; case DOWN : dy++; break; case RIGHTDOWN : dx++; dy++; break; case RIGHT : dx++; break; case RIGHTUP : dx++; dy--; break; case UP : dy--; break; case LEFTUP : dx--; dy--; break; } // 矫累苞 场谅钎甫 林狼窍扼. m_Rect 啊 扁霖捞促. for (int x = 1 ; x < maxVisionWidth - 1 ; x ++) { for (int y = 1 ; y < maxVisionHeight - 1 ; y ++) { temp1[x+dx][y+dy] = m_Rect[x][y]; } } //-------------------------------------------------------------------------------- // temp1 = temp1 - m_Rect //-------------------------------------------------------------------------------- for (int x = 0 ; x < maxVisionWidth ; x ++) { for (int y = 0 ; y < maxVisionHeight ; y ++) { if (temp1[x][y] == m_Rect[x][y] == IN_SIGHT) temp1[x][y] = OUT_OF_SIGHT; } } //-------------------------------------------------------------------------------- // temp2 = temp1 >> 1 //-------------------------------------------------------------------------------- for (int x = 1 ; x < maxVisionWidth - 1 ; x ++) { for (int y = 1 ; y < maxVisionHeight - 1 ; y ++) { temp2[x][y] = temp1[x+dx][y+dy]; } } //-------------------------------------------------------------------------------- // m_Rect狼 ON_SIGHT 康开阑 瘤沥茄促. // // IN_SIGHT 康开吝俊辑, 8规氢阑 眉农秦辑 1俺 捞惑狼 OUT_OF_SIGHT 啊 粮犁且 版快 // ON_SIGHT 肺 瘤沥茄促. //-------------------------------------------------------------------------------- for (int x = 1 ; x < maxVisionWidth - 1 ; x ++) { for (int y = 1 ; y < maxVisionHeight - 1 ; y ++) { if (m_Rect[x][y] == IN_SIGHT) { if (m_Rect[ x ][y-1] == OUT_OF_SIGHT || // north m_Rect[x+1][y-1] == OUT_OF_SIGHT || // northeast m_Rect[x+1][ y ] == OUT_OF_SIGHT || // east m_Rect[x+1][y+1] == OUT_OF_SIGHT || // southeast m_Rect[ x ][y+1] == OUT_OF_SIGHT || // south m_Rect[x-1][y+1] == OUT_OF_SIGHT || // southwest m_Rect[x-1][ y ] == OUT_OF_SIGHT || // west m_Rect[x-1][y-1] == OUT_OF_SIGHT) { // northwest m_Rect[x][y] = ON_SIGHT; } } } } //-------------------------------------------------------------------------------- // m_Rect = m_Rect + temp2 //-------------------------------------------------------------------------------- for (int x = 1 ; x < maxVisionWidth - 1 ; x ++) { for (int y = 1 ; y < maxVisionHeight - 1 ; y ++) { if (temp2[x][y] == IN_SIGHT) { Assert(m_Rect[x][y] == ON_SIGHT); m_Rect[x][y] = NEW_SIGHT; } } } if ( sight == 13 ) filelog("VisionInfo.log", "%s", toString().c_str()); __END_CATCH}//--------------------------------------------------------------------------------//// Q(cx,cy)俊 乐绰 农府贸啊 P(x,y)甫 杭 荐 乐绰瘤, 绝绰瘤.. 弊 惑怕蔼阑 府畔窃.//// O(a,b) - Vision Rectangle 狼 吝缴// P(x,y) - 焊绊磊 窍绰 坷宏璃飘狼 困摹// Q(cx,cy) - 焊绰 农府贸狼 困摹//// Q甫 O肺 乞青捞悼茄 傍侥阑 荤侩秦辑, P甫 乞青捞悼茄 谅钎甫 P'(x',y') 捞扼绊 且 锭, //// x' = x + a - cx// y' = y + b - cy//// 啊 等促. 弊矾搁, m_Rect[x'][y']狼 蔼阑 府畔窍搁 等促. (寸楷洒 裹困眉农甫 秦具零)////--------------------------------------------------------------------------------VisionState VisionInfo::getVisionState (ZoneCoord_t cx , ZoneCoord_t cy , ZoneCoord_t x , ZoneCoord_t y) const throw (){ __BEGIN_TRY int px = x + (maxViewportWidth + 1) - cx; int py = y + (maxViewportUpperHeight + 1) - cy; // 乞青捞悼茄 谅钎狼 裹困甫 眉农茄促. if (px >= 0 && px < maxVisionWidth && py >= 0 && py < maxVisionHeight) return m_Rect[px][py]; return OUT_OF_SIGHT; __END_CATCH}//--------------------------------------------------------------------------------// get debug string//--------------------------------------------------------------------------------string VisionInfo::toString () const throw (){ __BEGIN_TRY StringStream msg; msg << "VisionInfo(" << "Sight:" << (int)m_Sight << ",Dir: " << Dir2String[m_Dir] << "\r\n"; for (int y = 0; y < maxVisionHeight ; y++) { for (int x = 0; x < maxVisionWidth ; x++) { switch (m_Rect[x][y]) { case OUT_OF_SIGHT: msg << ". "; break; case IN_SIGHT: msg << "[33m:[m "; break; case ON_SIGHT: msg << "[33m#[m "; break; case NEW_SIGHT: msg << "[32m#[m "; break; } } msg << "\r\n"; } msg << ")"; return msg.toString(); __END_CATCH}*///--------------------------------------------------------------------------------// destructor//--------------------------------------------------------------------------------VisionInfoManager::~VisionInfoManager () throw (){ __BEGIN_TRY/* if (m_pVisionInfos) { for (Sight_t sight = 0 ; sight <= maxSight ; sight ++) { if (m_pVisionInfos[sight]) { for (Dir_t dir = 0 ; dir < DIR_MAX ; dir ++) { SAFE_DELETE(m_pVisionInfos[sight][dir]); } SAFE_DELETE_ARRAY(m_pVisionInfos[sight]); } } SAFE_DELETE_ARRAY(m_pVisionInfos); }*/ __END_CATCH}//--------------------------------------------------------------------------------////--------------------------------------------------------------------------------void VisionInfoManager::init () throw (){ __BEGIN_TRY/* m_pVisionInfos = new VisionInfo ** [ maxSight ]; Assert(m_pVisionInfos != NULL); for (Sight_t sight = 0 ; sight <= maxSight ; sight ++) { m_pVisionInfos[sight] = new VisionInfo* [8]; Assert(m_pVisionInfos[sight] != NULL); for (Dir_t dir = 0 ; dir < DIR_MAX ; dir ++) { m_pVisionInfos[sight][dir] = new VisionInfo(sight,dir); Assert(m_pVisionInfos[sight][dir] != NULL); } } */ __END_CATCH}//--------------------------------------------------------------------------------// get vision info//--------------------------------------------------------------------------------/*VisionInfo* VisionInfoManager::getVisionInfo (Sight_t sight , Dir_t dir) throw (OutOfBoundException){ __BEGIN_TRY if (sight > maxSight) throw OutOfBoundException("sight overflow"); if (dir >= DIR_MAX) throw OutOfBoundException("dir overflow"); return m_pVisionInfos[sight][dir]; __END_CATCH}*///--------------------------------------------------------------------------------// get debug string//--------------------------------------------------------------------------------string VisionInfoManager::toString () const throw (){ __BEGIN_TRY/* StringStream msg; msg << "VisionInfoManager("; for (Sight_t sight = 0 ; sight <= maxSight ; sight ++) { for (Dir_t dir = LEFT ; dir <= LEFTUP ; dir ++) { msg << m_pVisionInfos[sight][dir]->toString(); } } msg << ")"; return msg.toString();*/ __END_CATCH}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -