コード例 #1
0
 protected override void OnDeconstruct()
 {
     if (this.pathfindingInstance != null)
     {
         this.pathfindingInstance.Recycle();
     }
     this.pathfindingInstance = null;
     ComponentsInitializerWorld.UnRegister(PathfindingComponentsInitializer.InitEntity);
 }
コード例 #2
0
        protected override void OnConstruct()
        {
            this.pathfindingInstance = null;

            PathfindingComponentsInitializer.Init(ref this.world.GetStructComponents());
            ComponentsInitializerWorld.Register(PathfindingComponentsInitializer.InitEntity);

            var entity = new Entity("Pathfinding");

            entity.Set(new IsPathfinding());
            this.pathfindingEntity = entity;

            this.AddSystem <SetPathfindingInstanceSystem>();
            this.AddSystem <BuildGraphsSystem>();
            this.AddSystem <PathfindingUpdateSystem>();
        }
コード例 #3
0
 public void SetInstance(ME.ECS.Pathfinding.Pathfinding pathfinding)
 {
     this.pathfindingInstance = pathfinding;
 }
コード例 #4
0
        public Path Run <TMod>(Pathfinding pathfinding, Vector3 from, Vector3 to, Constraint constraint, Graph graph, TMod pathModifier, int threadIndex = 0) where TMod : IPathModifier
        {
            if (threadIndex < 0 || threadIndex > Pathfinding.THREADS_COUNT)
            {
                threadIndex = 0;
            }

            var constraintStart = constraint;

            constraintStart.checkWalkability = true;
            constraintStart.walkable         = true;
            var startNode = graph.GetNearest(from, constraintStart);

            if (startNode == null)
            {
                return(new Path());
            }

            var constraintEnd = constraintStart;

            constraintEnd.checkArea = true;
            constraintEnd.areaMask  = (1 << startNode.area);

            var endNode = graph.GetNearest(to, constraintEnd);

            if (endNode == null)
            {
                return(new Path());
            }

            var visited = PoolList <Node> .Spawn(10);

            System.Diagnostics.Stopwatch swPath = null;
            if (pathfinding.HasLogLevel(LogLevel.Path) == true)
            {
                swPath = System.Diagnostics.Stopwatch.StartNew();
            }
            var nodesPath = this.AstarSearch(graph, visited, startNode, endNode, constraint, threadIndex);

            var statVisited = visited.Count;
            var statLength  = 0;

            var path = new Path();

            path.graph  = graph;
            path.result = PathCompleteState.NotCalculated;

            if (nodesPath == null)
            {
                path.result = PathCompleteState.NotExist;
            }
            else
            {
                statLength = nodesPath.Count;

                path.result = PathCompleteState.Complete;
                path.nodes  = nodesPath;
            }

            for (int i = 0; i < visited.Count; ++i)
            {
                visited[i].Reset(threadIndex);
            }

            PoolList <Node> .Recycle(ref visited);

            System.Diagnostics.Stopwatch swModifier = null;
            if (pathfinding.HasLogLevel(LogLevel.PathMods) == true)
            {
                swModifier = System.Diagnostics.Stopwatch.StartNew();
            }
            if (path.result == PathCompleteState.Complete)
            {
                path = pathModifier.Run(path, constraint);
            }

            if (pathfinding.HasLogLevel(LogLevel.Path) == true)
            {
                Logger.Log(string.Format("Path result {0}, built in {1}ms. Path length: {2} (visited: {3})\nThread Index: {4}", path.result, swPath.ElapsedMilliseconds, statLength, statVisited, threadIndex));
            }

            if (pathfinding.HasLogLevel(LogLevel.PathMods) == true)
            {
                Logger.Log(string.Format("Path Mods: {0}ms", swModifier.ElapsedMilliseconds));
            }

            return(path);
        }