本文整理汇总了C++中Dijkstra::Execute方法的典型用法代码示例。如果您正苦于以下问题:C++ Dijkstra::Execute方法的具体用法?C++ Dijkstra::Execute怎么用?C++ Dijkstra::Execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dijkstra
的用法示例。
在下文中一共展示了Dijkstra::Execute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool TiledMapLayer::init()
{
if (Layer::init()) {
auto map = TMXTiledMap::create("tiledmap/TestMap.tmx");
map->setAnchorPoint(Vec2(0.0f, 0.0f));
map->setPosition(0, 0);
this->addChild(map);
auto mapLayer = map->getLayer("layer1");
Size maxSize = mapLayer->getLayerSize();
CCLOG("maplayer maxwidth %f maxheight %f" , maxSize.width,maxSize.height);
mapGraph = new GridMap((int)maxSize.width,(int)maxSize.height);
for (int row = 0; row < maxSize.width; row++) {
for (int col = 0; col < maxSize.height; col++) {
int gid = mapLayer->getTileGIDAt(Vec2(row,col));
printf(" %d",gid);
if (gid == 10) {
mapGraph->setGridVertexType(row, col, vertex_vertex);
}
}
printf("\n");
}
Dijkstra dij;
dij.Execute(*mapGraph, 10, 39 * ID_PARA + 13);
Vertex * vertex = mapGraph->getVertex(39, 13);
// AStar dij;
// dij.Execute(*mapGraph, 10, 39 * ID_PARA + 13);
// Vertex * vertex = mapGraph->getVertex(39, 13);
printf("path tree length %lld \n", dij.pathTree.size());
// for (auto it = dij.pathTree.find(vertex) , end = dij.pathTree.end(); it->second != 0&& it != end ; it= dij.pathTree.find(it->second)) {
// mapLayer->setTileGID(31, Vec2(vertex->getX(), vertex->getY()));
// vertex = it->second;
// }
auto end = dij.pathTree.end();
while (vertex != nullptr) {
mapLayer->setTileGID(31, Vec2(vertex->getX(), vertex->getY()));
auto it = dij.pathTree.find(vertex);
if (it != end && it->second != nullptr) {
vertex = it->second;
}else{
vertex = nullptr;
}
}
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(TiledMapLayer::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(TiledMapLayer::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(TiledMapLayer::onTouchEnded, this);
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}
return false;
}