Exemple #1
0
    public MapColliderInfo(int width, int height)
    {
        if (width <= 0 || height <= 0)
        {
            return;
        }

        MapWidth  = width;
        MapHeight = height;

        CostField        = new byte[height, width];
        IntegrationField = new float[height, width];
        IntegrateInfos   = new IntegrateFlag[height, width];
        FlowField        = new FlowFieldDir[height, width];
    }
Exemple #2
0
    private static void MoveDiagonal(FastPriorityQueue <PathNode> openList, MapColliderInfo map, int2 start, int2 dir, float cost)
    {
        if (dir.x == 0 || dir.y == 0)
        {
            return;
        }

        while (!MapColliderUtils.UnReachable(map, start.x, start.y))
        {
            IntegrateFlag integrateFlag = map.IntegrateInfos[start.x, start.y];

            if (integrateFlag.HasFlag(IntegrateFlag.Visited))
            {
                if (map.IntegrationField[start.x, start.y] > cost)
                {
                    map.IntegrationField[start.x, start.y] = cost;
                }
                else
                {
                    return;
                }
            }
            else
            {
                map.IntegrateInfos[start.x, start.y]  |= IntegrateFlag.Visited;
                map.IntegrationField[start.x, start.y] = cost;
            }

            MoveCardinal(openList, map, start, new int2(dir.x, 0), cost);
            MoveCardinal(openList, map, start, new int2(0, dir.y), cost);

            if (!MapColliderUtils.UnReachable(map, start + new int2(dir.x, 0)) ||
                !MapColliderUtils.UnReachable(map, start + new int2(0, dir.y)))
            {
                start += dir;
                cost  += 1.5f;
            }
            else
            {
                return;
            }
        }
    }
Exemple #3
0
    private static void MoveCardinal(FastPriorityQueue <PathNode> openList, MapColliderInfo map, int2 start, int2 dir, float cost)
    {
        start += dir;
        cost  += 1;

        while (!MapColliderUtils.UnReachable(map, start.x, start.y))
        {
            IntegrateFlag integrateFlag = map.IntegrateInfos[start.x, start.y];

            if (integrateFlag.HasFlag(IntegrateFlag.Visited))
            {
                if (map.IntegrationField[start.x, start.y] > cost)
                {
                    map.IntegrationField[start.x, start.y] = cost;
                }
                else
                {
                    return;
                }
            }

            int2 newdir = IsJumpPoint(map, start, dir);
            if (newdir.x != 0 || newdir.y != 0)
            {
                if (integrateFlag.HasFlag(IntegrateFlag.Visited))
                {
                    map.IntegrateInfos[start.x, start.y] &= ~IntegrateFlag.Visited;
                }
                map.IntegrationField[start.x, start.y] = math.min(map.IntegrationField[start.x, start.y], cost);
                openList.Enqueue(new PathNode(start, newdir), cost);
                return;
            }
            else
            {
                map.IntegrateInfos[start.x, start.y]  |= IntegrateFlag.Visited;
                map.IntegrationField[start.x, start.y] = cost;
                start += dir;
                cost  += 1;
            }
        }
    }