void CMap::Input(Vec2I position) { Vec2I end_pos(position.x / GRID_WIDTH, position.y / GRID_HEIGHT); DEBUG_TRACE("start:%d,%d\tend:%d,%d\n", m_pos.x, m_pos.y, end_pos.x, end_pos.y); if (! IsFree(end_pos)) return; QWORD start_time = GetTimer()->GetTime(); if (m_Astar.FindPath(m_pos, end_pos)) { QWORD end_time = GetTimer()->GetTime(); DEBUG_TRACE("find path time:%f\n", GetTimer()->GetTimeMillisec(end_time - start_time)); m_findPath.clear(); std::vector<Vec2I>& vec = m_Astar.GetPath(); m_findPath.reserve(vec.size()); for (int i = 0; i < vec.size(); ++i) { Vec2I pt = vec[i]; m_findPath.push_back(Grid2CenterPt(pt)); } m_pos = end_pos; m_rect.SetRect(m_pos.x * GRID_WIDTH, m_pos.y * GRID_HEIGHT, (m_pos.x + 1) * GRID_WIDTH, (m_pos.y + 1) * GRID_HEIGHT); } }
int main(int argc,char** argv) { CGameMap gamemap; gamemap.Init(); GameMap* game_map = gamemap.GetGameMap(); CAStar star; star.Init(0,244); std::list<lihj_uint16> pathlist; bool bok = star.BeginStar(game_map); if (bok) { //star.PrintCloseList(); star.GetPath(pathlist); } //std::list<lihj_uint16>::iterator iter = pathlist.begin(); for (lihj_uint16 y = 0; y < game_map->uint16_highth; y ++ ) { for (lihj_uint16 x = 0; x < game_map->uint16_width; x ++) { lihj_uint16 cell_index = x + y * game_map->uint16_width; path_node node; bool inopenlist = star.InOpenList(cell_index,node); bool incloselist = inopenlist || star.InCloseList(cell_index,node); if (inopenlist || incloselist) { bool bfind = false; for (std::list<lihj_uint16>::const_iterator iter = pathlist.begin(); iter != pathlist.end(); ++ iter) { if ((*iter) == cell_index) { bfind = true; break; } } if (bfind) { LogInfo("[%04u %04u]",cell_index,node.insert_counter); } else if(inopenlist) { LogDebug("[%04u %04u]",cell_index,node.insert_counter); } else { LogFatal("[%04u %04u]",cell_index,node.insert_counter); } } else { if (game_map->mapcell[cell_index].uint8_type == 2) { LogDebug1("[%04u %04u]",cell_index ,0); } else { LogError("[%04u %04u]",cell_index ,0); } } } LogDebug("\n"); } star.EndStar(); gamemap.Uninit(); system("pause"); return 0; }