コード例 #1
0
        private static void Clean()
        {
            for (int i = 1; i < OpenListLength + 2; i++)
            {
                if (OpenList[i] != null)
                {
                    OpenList[i].Reset();
                }
                OpenList[i] = null;
            }

            for (int i = 0; i < ClosedListLength; i++)
            {
                ClosedList[i].Reset();
                ClosedList[i] = null;
            }

            config = null;

            Nodes      = null;
            ClosedList = null;
            OpenList   = null;

            TilesX = -1;
            TilesY = -1;

            OpenListLength   = 0;
            ClosedListLength = 0;

            currentMap.MakeFree();
            currentMap = null;

            busy = false;
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: Drandik/TankWithEnemies
        public Map(Node[,] nodes, Generator.Config config)
        {
            this.Nodes      = nodes;
            this.config     = config;
            this.OpenListBH = new Node[(nodes.GetLength(0) * nodes.GetLength(1)) + 1];
            this.ClosedList = new Node[nodes.GetLength(0) * nodes.GetLength(1)];

            if (FastPath.DefaultMap == null)
            {
                FastPath.DefaultMap = this;
            }
        }
コード例 #3
0
        private static void Initialise(Map map)
        {
            while (busy)
            {
                ;
            }
            busy = true;

            map.MakeBusy();

            currentMap = map;
            config     = map.GetConfig();

            TilesX = map.TilesX;
            TilesY = map.TilesY;

            Nodes      = map.GetNodeArrayReference();
            OpenList   = map.GetOpenListReference();
            ClosedList = map.GetClosedListReference();

            OpenListLength   = 0;
            ClosedListLength = 0;
        }
コード例 #4
0
ファイル: Generator.cs プロジェクト: Hengle/Fast-Path
        public static void UpdateNodesRuntime(Map map, Int2D Start, Int2D End)
        {
            map.MakeBusy();

            Node[,] nodes = map.GetNodeArrayReference();
            Generator.Config config = map.GetConfig();

            if (End.x < Start.x)
            {
                int startX = Start.x;
                Start.x = End.x;
                End.x   = startX;
            }
            if (End.y < Start.y)
            {
                int startY = Start.y;
                Start.y = End.y;
                End.y   = startY;
            }

            if (Start.x < 0 || Start.y < 0 || End.x > map.TilesX || End.y > map.TilesY)
            {
                throw new System.IndexOutOfRangeException("Node index is out of range");
            }

            for (int i = Start.x; i < End.x; i++)
            {
                for (int j = Start.y; j < End.y; j++)
                {
                    UpdateNode(nodes[i, j], config, false);
                }
            }

            map.MakeFree();

            map.TriggerUpdateEvent();
        }
コード例 #5
0
ファイル: Node.cs プロジェクト: Drandik/TankWithEnemies
        /// <summary>
        /// This calculates the difference in the dept (Z or Y axis) as cost too
        /// </summary>
        public void CalculateFGH(Int2D End, Map map, float aggression, float depthAggression, Generator.Config config)
        {
            const float scale      = 1f;
            float       multiplier = scale * ((aggression < 0f) ? -aggression : aggression);

            Vector parentPos      = Parent.Position;
            int    depthDimension = config.XYGrid ? 2 : 1;
            float  depthDiff      = parentPos[depthDimension] < Position[depthDimension] ? Position[depthDimension] - parentPos[depthDimension] : parentPos[depthDimension] - Position[depthDimension];

            G = Parent != null ? (Parent.G + (Parent.MoveCost * scale * ((Parent.Index.x != Index.x && Parent.Index.y != Index.y) ? 1.414f : 1f))) + (depthAggression * depthDiff)  : 0f;
            H = (Index.x < End.x ? End.x - Index.x : Index.x - End.x) * multiplier + (Index.y < End.y ? End.y - Index.y : Index.y - End.y) * multiplier;
            F = G + H;
        }
コード例 #6
0
 public static Map Generate(Generator.Config config)
 {
     return(config.Build());
 }