Exemple #1
0
    private void PreProcess(PathError error)
    {
        openList   = new List <PathNode>();
        closedList = new List <PathNode>();

        // Start out of bounds
        if (!pathfinder.pathManagerInstance.IsInBounds(startingCell))
        {
            error.errorType = PathError.PathErrorType.StartOutOfBounds;
            return;
        }
        // Destination out of bounds
        if (!pathfinder.pathManagerInstance.IsInBounds(finalDestination))
        {
            error.errorType = PathError.PathErrorType.DestinationOutOfBounds;
            return;
        }
        // Start not Walkable
        if (!pathfinder.pathManagerInstance.IsCellWalkable(startingCell))
        {
            error.errorType = PathError.PathErrorType.StartNotWalkable;
            return;
        }
        // Destination not Walkable
        if (!pathfinder.pathManagerInstance.IsCellWalkable(startingCell))
        {
            error.errorType = PathError.PathErrorType.DestinationNotWalkable;
            return;
        }
    }
Exemple #2
0
    public Path(int numNodesInPath, Vector3Int[] path, PathError error)
    {
        pathList   = new Vector3Int[numNodesInPath];
        this.error = error;

        for (int i = 0; i < numNodesInPath; ++i)
        {
            this.pathList[i] = path[i];
        }
    }
        protected override void execute()
        {
            TnSServer server = new TnSServer(socket, new TnSProtocol());

            server.OnRequestReceived += (ToAccept request) => {
                if (RequestReceived != null)
                {
                    return(RequestReceived(request));
                }
                return(request);
            };

            server.JobInitialized += (Job job) => {
                JobsList.Receiving.push(job);
                this.job = job;
            };

            try {
                server.transfer();
            } catch (SocketException e) {
                // Trigger the event of conncetion error
                ConnectionError?.Invoke(job);
            } catch (System.IO.IOException e) {
                String sourceName = null;
                //if (job != null) {
                //    job.Status = Job.JobStatus.ConnectionError;

                //    // Trigger the event of Path error
                //    sourceName = job.Task.Info[0].Name;
                //    if (job.Task.Info.Count > 1)
                //        for (int i = 1; i > job.Task.Info.Count; i++)
                //            sourceName += ", " + job.Task.Info[i].Name;
                //}
                PathError?.Invoke(e, job);
            } catch (ObjectDisposedException e) {
                ConnectionError?.Invoke(job);

                // NOTE: 'ObjectDisposedException' and 'SocketException' make the same management as the generale 'Exception'.
                // However they have their own catch because they are very common exceptions in this point of the code, and
                // in this way they are marked and clearely visible.
                // This separation is not neede, but it's really useful to remark this concept.
            } catch (Exception e) {
                ConnectionError?.Invoke(job);
            } finally {
                // Remove the job (if any) from the list
                if (job != null)
                {
                    JobsList.Receiving.remove(job.Id);
                }
                // Close the socket
                socket.Close();
            }
        }
Exemple #4
0
        protected override void execute()
        {
            if (Settings.Instance.Network == null)
            {
                return;
            }
            NetworkInterface nic  = Settings.Instance.Network.Nic;
            IPAddress        addr = null;

            foreach (UnicastIPAddressInformation ip in nic.GetIPProperties().UnicastAddresses)
            {
                if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    addr = ip.Address;
                }
            }
            //IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, Settings.Instance.SERV_ACCEPTING_PORT);
            IPEndPoint localEndPoint = new IPEndPoint(addr, Settings.Instance.SERV_ACCEPTING_PORT);

            listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try {
                listener.Bind(localEndPoint);
                listener.Listen(50);

                while (true)
                {
                    Console.WriteLine("Waiting for a connection...");
                    Socket handler = listener.Accept();

                    ReceptionExecutor receiver = new ReceptionExecutor(handler);
                    receiver.RequestReceived += (ToAccept request) => {
                        if (RequestReceived != null)
                        {
                            return(RequestReceived(request));
                        }
                        return(request);
                    };
                    receiver.ConnectionError += (Job j) => {
                        ConnectionError?.Invoke(j);
                    };
                    receiver.PathError += (System.IO.IOException e, Job job) => {
                        PathError?.Invoke(e, job);
                    };
                    RegisterChild(receiver);
                    receiver.run();
                }
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }
Exemple #5
0
 public Path(PathError error)
 {
     pathList   = new Vector3Int[0];
     this.error = error;
 }
Exemple #6
0
    public Path FindPath()
    {
        PathError error = new PathError();

        PreProcess(error);

        if (error.errorType != PathError.PathErrorType.None)
        {
            return(new Path(error));
        }

        // 1.
        moves = 0;
        PathNode currentNode = new PathNode(moves, startingCell, null, finalDestination);

        closedList.Add(currentNode);
        GenerateNeighbourNodes(currentNode.Moves, currentNode);

        do
        {
            //pathfinder.pathManagerInstance.baseTilemap.SetTile(currentNode.CellPosition, pathfinder.pathManagerInstance.CenterTile);
            //System.Threading.Thread.Sleep(750);

            if (openList.Count == 0)
            {
                error.errorType = PathError.PathErrorType.NoPathAvailable;
                break;
            }

            // Check openlist for best option, best option gets added to the closed list.
            currentNode = ChooseBestOption();
            closedList.Add(currentNode);

            if (currentNode.isDestinationNode)
            {
                break;
            }

            // if this node is being search it must be on the openlist, remove it so we can selcet it as an option again for this search.
            openList.Remove(currentNode);

            // Generate Neighbours which get added to openlist.
            GenerateNeighbourNodes(currentNode.Moves, currentNode);
        } while (true);

        // 2.
        // if a full path can't be found, we will retur a path to the tile with best heuristic from the destination
        // setting currentNode to that tile will cause the loop to start retracing its path from that tile.
        if (error.errorType == PathError.PathErrorType.NoPathAvailable)
        {
            currentNode = GetNodeWithBestHeuristicInList(closedList);
        }

        // 3.
        // We must retrace our steps fronm destination, returniung to each tiles origin until we are back at the startnode
        List <Vector3Int> path = new List <Vector3Int>();

        do
        {
            path.Add(currentNode.CellPosition);
            currentNode = currentNode.OriginNode;

            if (currentNode.isStartingNode)
            {
                break;
            }
        } while (true);

        return(new Path(path.Count, path.ToArray(), error));
    }