Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/helpers/VertexPathfinder.cpp
Show First 20 Lines • Show All 512 Lines • ▼ Show 20 Lines | |||||
WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, CmpPtr<ICmpObstructionManager> cmpObstructionManager) const | WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, CmpPtr<ICmpObstructionManager> cmpObstructionManager) const | ||||
{ | { | ||||
PROFILE2("ComputeShortPath"); | PROFILE2("ComputeShortPath"); | ||||
DebugRenderGoal(cmpObstructionManager->GetSimContext(), request.goal); | DebugRenderGoal(cmpObstructionManager->GetSimContext(), request.goal); | ||||
// Create impassable edges at the max-range boundary, so we can't escape the region | // Create impassable edges at the max-range boundary, so we can't escape the region | ||||
// where we're meant to be searching | // where we're meant to be searching | ||||
fixed rangeXMin = request.x0 - request.range; | fixed rangeXMin = request.x0 - request.range; | ||||
fixed rangeXMax = request.x0 + request.range; | fixed rangeXMax = request.x0 + request.range; | ||||
fixed rangeZMin = request.z0 - request.range; | fixed rangeZMin = request.z0 - request.range; | ||||
fixed rangeZMax = request.z0 + request.range; | fixed rangeZMax = request.z0 + request.range; | ||||
// If useful, move the center of the search-space so that it's slightly towards the goal, | |||||
// as the vertex pathfinder tends to be used to get around entities in front of us. | |||||
CFixedVector2D toGoal = CFixedVector2D(request.goal.x, request.goal.z) - CFixedVector2D(request.x0, request.z0); | |||||
if (toGoal.CompareLength(request.range) >= 0) | |||||
{ | |||||
fixed toGoalLength = toGoal.Length(); | |||||
fixed inv = fixed::FromInt(1) / toGoalLength; | |||||
rangeXMin += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).X; | |||||
rangeXMax += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).X; | |||||
rangeZMin += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).Y; | |||||
rangeZMax += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).Y; | |||||
} | |||||
// Add domain edges | // Add domain edges | ||||
// (Inside-out square, so edges are in reverse from the usual direction.) | // (Inside-out square, so edges are in reverse from the usual direction.) | ||||
m_Edges.emplace_back(Edge{ CFixedVector2D(rangeXMin, rangeZMin), CFixedVector2D(rangeXMin, rangeZMax) }); | m_Edges.emplace_back(Edge{ CFixedVector2D(rangeXMin, rangeZMin), CFixedVector2D(rangeXMin, rangeZMax) }); | ||||
m_Edges.emplace_back(Edge{ CFixedVector2D(rangeXMin, rangeZMax), CFixedVector2D(rangeXMax, rangeZMax) }); | m_Edges.emplace_back(Edge{ CFixedVector2D(rangeXMin, rangeZMax), CFixedVector2D(rangeXMax, rangeZMax) }); | ||||
m_Edges.emplace_back(Edge{ CFixedVector2D(rangeXMax, rangeZMax), CFixedVector2D(rangeXMax, rangeZMin) }); | m_Edges.emplace_back(Edge{ CFixedVector2D(rangeXMax, rangeZMax), CFixedVector2D(rangeXMax, rangeZMin) }); | ||||
m_Edges.emplace_back(Edge{ CFixedVector2D(rangeXMax, rangeZMin), CFixedVector2D(rangeXMin, rangeZMin) }); | m_Edges.emplace_back(Edge{ CFixedVector2D(rangeXMax, rangeZMin), CFixedVector2D(rangeXMin, rangeZMin) }); | ||||
▲ Show 20 Lines • Show All 440 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator