0
我用C++开发了一款游戏,并且希望确保一切都正确完成。 使用QHashIterator来检查列表中的哪个项目具有最低值(用于寻路的F-成本)是否是一个很好的解决方案。QHashIterator in C++
从我的代码段:
while(!pathFound){ //do while path is found
QHashIterator<int, PathFinding*> iterator(openList);
PathFinding* parent;
iterator.next();
parent = iterator.value();
while(iterator.hasNext()){ //we take the next tile, and we take the one with the lowest value
iterator.next();
//checking lowest f value
if((iterator.value()->getGcost() + iterator.value()->getHcost()) < (parent->getGcost() + parent->getHcost())){
parent = iterator.value();
}
}
if(!atDestionation(parent,endPoint)){ //here we check if we are at the destionation. if we are we return our pathcost.
clearLists(parent);
filllists(parent,endPoint);
}else{
pathFound = true;
while(parent->hasParent()){
mylist.append(parent);
parent = parent->getParent();
}
pathcost = calculatePathCost(mylist); //we calculate what the pathcost is and return it
}
}
如果没有?有更好的改进吗?
我还发现了一些关于std :: priority_queue的内容。它比QHashIterator更好呢?
这可能不是一个游戏世界的问题,那里不大。但是当游戏世界很大时(比如+ 10000计算),我正在寻找合适的解决方案。任何标记?
这可能是一个stuppid问题,但是你是什么意思的indirections? –
我指的是iterator.value(),假设这个方法是一个指向其他结构的指针,但我想它是Qt API的一部分,所以应该没有问题。 –
你写的stl容器不可能以这种方式使用它。那么我应该删除Qhashiterator?并只使用STL容器? –