//----------------------------------------------------------------------------- public void Execute() { BurstQueue queue = new BurstQueue(FloodQueue); for (int index = 0; index < NumGoals; ++index) { var tileIndex = GridUtilties.Grid2Index(Settings, Goals[index]); if (DistanceMap[tileIndex] < TileSystem.k_ObstacleFloat) { DistanceMap[tileIndex] = 0; queue.Enqueue(tileIndex); } } // Search! while (queue.Length > 0) { var index = queue.Dequeue(); var newDistance = DistanceMap[index] + 1; var grid = GridUtilties.Index2Grid(Settings, index); for (GridUtilties.Direction dir = GridUtilties.Direction.N; dir <= GridUtilties.Direction.W; ++dir) { var neighborGrid = grid + Offsets[(int)dir]; var neighborIndex = GridUtilties.Grid2Index(Settings, neighborGrid); if (neighborIndex != -1 && DistanceMap[neighborIndex] < TileSystem.k_ObstacleFloat && newDistance < DistanceMap[neighborIndex]) { DistanceMap[neighborIndex] = newDistance; queue.Enqueue(neighborIndex); } } } }
//----------------------------------------------------------------------------- public void Execute(int index) { int2 gridPos = GridUtilties.Index2Grid(Settings, index); float weight = DistanceMap[index]; Flowfield[index] = new float3(0); for (GridUtilties.Direction dir = 0; dir < GridUtilties.Direction.MAX; ++dir) { int2 dirOffset = Offsets[(int)dir]; int neigborIdx = GridUtilties.Grid2Index(Settings, gridPos + dirOffset); if (neigborIdx == -1) { continue; } float neighborWeight = DistanceMap[neigborIdx]; if (weight <= neighborWeight) { continue; } weight = neighborWeight; float3 direction = new float3(dirOffset.x, 0, dirOffset.y); Flowfield[index] = math.normalize(direction); } }