Limit path finding max complexity

This commit is contained in:
Eduardo Bart 2013-01-20 14:30:53 -02:00
parent 8c6d5a0f5c
commit 18a37393c5
2 changed files with 8 additions and 5 deletions

View File

@ -540,6 +540,8 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
} }
}; };
const uint MAX_COMPLEXITY = 100000;
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> ret; std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> ret;
std::vector<Otc::Direction>& dirs = std::get<0>(ret); std::vector<Otc::Direction>& dirs = std::get<0>(ret);
Otc::PathFindResult& result = std::get<1>(ret); Otc::PathFindResult& result = std::get<1>(ret);
@ -575,6 +577,11 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
break; break;
} }
if(nodes.size() > MAX_COMPLEXITY) {
result = Otc::PathFindResultTooFar;
break;
}
// path found // path found
if(currentNode->pos == goalPos && (!foundNode || currentNode->cost < foundNode->cost)) if(currentNode->pos == goalPos && (!foundNode || currentNode->cost < foundNode->cost))
foundNode = currentNode; foundNode = currentNode;

View File

@ -714,7 +714,7 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
if(UIWidgetPtr parent = getParent()) if(UIWidgetPtr parent = getParent())
parent->focusPreviousChild(Fw::KeyboardFocusReason); parent->focusPreviousChild(Fw::KeyboardFocusReason);
return true; return true;
} else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyLeft || keyCode == Fw::KeyUp || keyCode == Fw::KeyDown) { } else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyLeft) {
int oldCursorPos = m_cursorPos; int oldCursorPos = m_cursorPos;
@ -722,10 +722,6 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
moveCursorHorizontally(true); moveCursorHorizontally(true);
else if(keyCode == Fw::KeyLeft) // move cursor left else if(keyCode == Fw::KeyLeft) // move cursor left
moveCursorHorizontally(false); moveCursorHorizontally(false);
else if(keyCode == Fw::KeyUp) // move cursor right
moveCursorVertically(true);
else if(keyCode == Fw::KeyDown) // move cursor left
moveCursorVertically(false);
if(m_shiftNavigation) if(m_shiftNavigation)
clearSelection(); clearSelection();