void InitializeGraph()
 {
     //initialize neighbors using predefined dixtionary
     foreach (Node node in graph)
     {
         node.neighbors = new List<Neighbor>();
         foreach (KeyValuePair<Service.DataFormat, List<Service.DataFormat>> neighbor in node.distanceDict)
         {
             Neighbor newNeightbor = new Neighbor();
             foreach (Node graphNode in graph)
             {
                 if (graphNode.name == neighbor.Key)
                 {
                     newNeightbor.node = graphNode;
                     newNeightbor.distance = neighbor.Value.Count;
                     node.neighbors.Add(newNeightbor);
                     break;
                 }
             }
         }
     }
     for (var i = 0; i < graph.Count(); i++)
     {
         TransverNode(graph[i]);
     }
 }
Ejemplo n.º 2
0
 public void adjustAdorns( Neighbor sourceNeighbor )
  {
     Neighbor tarGetNeighbor =
             (Neighbor)adjacentNeighbors[adjacentNeighbors.Count - 1];
     tarGetNeighbor.weight = sourceNeighbor.weight;
     original( sourceNeighbor );
 }
    void Awake() {
        GameObject[] all_points = GameObject.FindGameObjectsWithTag("Waypoint");
        Vector3 this_point = transform.position;
        float range = 50f;
        announced = false;
        neighbors = new List<Neighbor>();
        N_view = new List<GameObject>();
        foreach (GameObject point in all_points) {
            if (point == this.gameObject)
                continue;
            Vector3 to_point = point.transform.position - transform.position;
            // Vector3.Normalize(to_point);
            RaycastHit Hit;
            Debug.DrawRay(this_point, to_point);
            if (Physics.Raycast(this_point, to_point, out Hit, range, waypoints_and_walls))
                if (Hit.collider.gameObject == point) {
                    Neighbor current_neighbor = new Neighbor(point, Hit.distance);

                    if (Physics.Raycast(transform.position + transform.up, to_point, out Hit, to_point.magnitude, waypoints_and_walls))
                        continue;
                    
                    neighbors.Add(current_neighbor);

                }

        }
        foreach (Neighbor neighbor in neighbors) {
            N_view.Add(neighbor.point);
        }
    }
 // Update is called once per frame
 void Update() {
     if (!dead) {
         if (!waiting && !start)
             cease_exist();
         if (announced == false && start == false) {
             neighbors.RemoveAll(x => x.point == null);
             foreach (Neighbor neighbor in neighbors) {
                 Neighbor me = new Neighbor(this.gameObject, neighbor.distance);
                 neighbor.point.GetComponent<PatrolPoint>().neighbors.Add(me);
                 neighbor.point.GetComponent<PatrolPoint>().neighbors.Reverse();
             }
             announced = true;
         }
     }
 }
Ejemplo n.º 5
0
    public void AddEdge( Vertex start,  Neighbor theNeighbor )
    {
        original( start,theNeighbor );

        // At this point the edges are Added.
        // If there is an adorn like weight it has to be Added to
        // the neighbor already present there
        if ( isDirected==false )
          {
            // It has to Add ONLY the weight object to the neighbor
            Vertex end = theNeighbor.neighbor;
            end.AddWeight( end,theNeighbor.weight );

        } // of else
    }
Ejemplo n.º 6
0
        public Cell GetNeighbor(Cell cell, Neighbor neighbor)
        {
            if (cell == null)
            {
                throw new ArgumentException("Cell cannot be null", "cell");
            }

            var cellIndex = Cells.IndexOf(cell);

            var row    = Convert.ToInt32(Math.Floor((double)cellIndex / ColumnCount));
            var column = cellIndex - row * ColumnCount;

            switch (neighbor)
            {
            case Neighbor.NorthWest:
                row    -= 1;
                column -= 1;
                break;

            case Neighbor.North:
                row -= 1;
                break;

            case Neighbor.NorthEast:
                row    -= 1;
                column += 1;
                break;

            case Neighbor.East:
                column += 1;
                break;

            case Neighbor.SouthEast:
                row    += 1;
                column += 1;
                break;

            case Neighbor.South:
                row += 1;
                break;

            case Neighbor.SouthWest:
                row    += 1;
                column -= 1;
                break;

            case Neighbor.West:
                column -= 1;
                break;

            default:
                throw new ArgumentOutOfRangeException("neighbor");
            }

            if (row < 0 || row >= RowCount)
            {
                return(null);
            }
            if (column < 0 || column >= ColumnCount)
            {
                return(null);
            }

            return(GetCell(row, column));
        }
Ejemplo n.º 7
0
 /** Sets the appropriate neighbor for this TerrainRenderable.  Neighbors are necessary
  * to know when to bridge between LODs.
  */
 public void SetNeighbor(Neighbor n, Tile t)
 {
     neighbors[(int)n] = t;
 }
Ejemplo n.º 8
0
 public static EdgeIfc TransformNeighborToEdge(Neighbor val)
 {
     return val.edge;
 }
Ejemplo n.º 9
0
    private static void Main(string[] args)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for FEM2D_SAMPLE.
    //
    //  Discussion:
    //
    //    FEM2D_SAMPLE reads files defining a 2D FEM representation of data,
    //    and a set of sample points, and writes out a file containing the
    //    value of the finite element function at the sample points.
    //
    //  Usage:
    //
    //    fem2d_sample fem_prefix sample_prefix
    //
    //    where 'fem_prefix' is the common prefix for the FEM files:
    //
    //    * fem_prefix_nodes.txt,    the node coordinates.
    //    * fem_prefix_elements.txt, the nodes that make up each element;
    //    * fem_prefix_values.txt,   the values defined at each node.
    //
    //    and 'sample_prefix' is the common prefix for the SAMPLE files.
    //    (the node file is input, and the values file is created by the program.)
    //
    //    * sample_prefix_nodes.txt,  the node coordinates where samples are desired.
    //    * sample_prefix_values.txt, the values computed at each sample node.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 June 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int[]  fem_element_neighbor;
        string fem_prefix;
        string sample_prefix;

        Console.WriteLine("");
        Console.WriteLine("FEM2D_SAMPLE");
        Console.WriteLine("");
        Console.WriteLine("  Read files defining an FEM function of 2 arguments.");
        Console.WriteLine("  Read a file of sample arguments.");
        Console.WriteLine("  Write a file of function values at the arguments.");
        //
        //  Get the number of command line arguments.
        //
        try
        {
            fem_prefix = args[0];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("Enter the FEM file prefix:");
            fem_prefix = Console.ReadLine();
        }

        try
        {
            sample_prefix = args[1];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("Enter the sample file prefix:");
            sample_prefix = Console.ReadLine();
        }

        //
        //  Create the filenames.
        //
        string fem_node_filename    = fem_prefix + "_nodes.txt";
        string fem_element_filename = fem_prefix + "_elements.txt";
        string fem_value_filename   = fem_prefix + "_values.txt";

        string sample_node_filename  = sample_prefix + "_nodes.txt";
        string sample_value_filename = sample_prefix + "_values.txt";
        //
        //  Read the FEM data.
        //
        TableHeader h            = typeMethods.r8mat_header_read(fem_node_filename);
        int         fem_node_dim = h.m;
        int         fem_node_num = h.n;

        double[] fem_node_xy = typeMethods.r8mat_data_read(fem_node_filename, fem_node_dim, fem_node_num);

        Console.WriteLine("");
        Console.WriteLine("  The FEM node dimension is        " + fem_node_dim + "");
        Console.WriteLine("  The FEM node number is           " + fem_node_num + "");

        if (fem_node_dim != 2)
        {
            Console.WriteLine("");
            Console.WriteLine("FEM2D_SAMPLE - Fatal error!");
            Console.WriteLine("  Spatial dimension of the nodes is not 2.");
            return;
        }

        h = typeMethods.i4mat_header_read(fem_element_filename);
        int fem_element_order = h.m;
        int fem_element_num   = h.n;

        int[] fem_element_node = typeMethods.i4mat_data_read(fem_element_filename, fem_element_order,
                                                             fem_element_num);

        Console.WriteLine("  The FEM element order is         " + fem_element_order + "");
        Console.WriteLine("  The FEM element number is        " + fem_element_num + "");

        h = typeMethods.r8mat_header_read(fem_value_filename);
        int fem_value_dim = h.m;
        int fem_value_num = h.n;

        Console.WriteLine("  The FEM value order is           " + fem_value_dim + "");
        Console.WriteLine("  the FEM value number is          " + fem_value_num + "");

        if (fem_value_num != fem_node_num)
        {
            Console.WriteLine("");
            Console.WriteLine("FEM2D_SAMPLE - Fatal error!");
            Console.WriteLine("  Number of values and nodes differ.");
            return;
        }

        double[] fem_value = typeMethods.r8mat_data_read(fem_value_filename, fem_value_dim, fem_value_num);
        switch (fem_element_order)
        {
        //
        //  Create the element neighbor array.
        //
        case 3:
            fem_element_neighbor = Neighbor.triangulation_order3_neighbor_triangles(
                fem_element_num, fem_element_node);
            break;

        case 6:
            fem_element_neighbor = Neighbor.triangulation_order6_neighbor_triangles(
                fem_element_num, fem_element_node);
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("FEM2D_SAMPLE - Fatal error!");
            Console.WriteLine("  The element order must be 3 or 6.");
            Console.WriteLine("  But this data has element order = " + fem_element_order + "");
            return;
        }

        Console.WriteLine("  The element neighbor array has been computed.");
        //
        //  Read the SAMPLE node data.
        //
        h = typeMethods.r8mat_header_read(sample_node_filename);
        int sample_node_dim = h.m;
        int sample_node_num = h.n;

        double[] sample_node_xy = typeMethods.r8mat_data_read(sample_node_filename, sample_node_dim,
                                                              sample_node_num);

        Console.WriteLine("");
        Console.WriteLine("  Sample node spatial dimension is " + sample_node_dim + "");
        Console.WriteLine("  Sample node number is            " + sample_node_num + "");

        if (sample_node_dim != 2)
        {
            Console.WriteLine("");
            Console.WriteLine("FEM2D_SAMPLE - Fatal error!");
            Console.WriteLine("  Spatial dimension of the sample nodes is not 2.");
            return;
        }

        //
        //  Compute the SAMPLE values.
        //
        int sample_value_dim = fem_value_dim;
        int sample_value_num = sample_node_num;

        double[] sample_value = FEM_2D_Evaluate.fem2d_evaluate(fem_node_num, fem_node_xy, fem_element_order,
                                                               fem_element_num, fem_element_node, fem_element_neighbor, fem_value_dim,
                                                               fem_value, sample_node_num, sample_node_xy);
        //
        //  Write the sample values.
        //
        typeMethods.r8mat_write(sample_value_filename, sample_value_dim, sample_value_num,
                                sample_value);

        Console.WriteLine("");
        Console.WriteLine("  Interpolated FEM data written to \"" + sample_value_filename + "\"");

        Console.WriteLine("");
        Console.WriteLine("FEM2D_SAMPLE");
        Console.WriteLine("  Normal end of execution.");

        Console.WriteLine("");
    }
Ejemplo n.º 10
0
 //Aggiunge un vicino al nodo
 public void addNeighbor(Neighbor neighbor)
 {
     neighbors.Add(neighbor);
 }
Ejemplo n.º 11
0
 public static Vertex TransformNeighborToEnd(Neighbor val)
 {
     // should be a Lambda Method in C# 3.0
     return val.end;
 }
Ejemplo n.º 12
0
 /** Returns the neighbor TerrainRenderable.
 */
 public Renderable GetNeighbor( Neighbor n )
 {
     return neighbors[ (int)n ];
 }
Ejemplo n.º 13
0
		public TerrainZoneRenderable GetNeighbor( Neighbor neighbor )
		{
			return this.mNeighbors[ (int)neighbor ];
		}
Ejemplo n.º 14
0
 public Neighbor Get(Neighbor data)
 {
     return(String.IsNullOrEmpty(data.Id) ? _neighborDal.GetWithGeometry(data) : _neighborDal.GetWithId(data));
 }
Ejemplo n.º 15
0
 public Vertex TransformToNeighbor(Neighbor val)
 {
     return val.neighbor;
 }
Ejemplo n.º 16
0
 public static EdgeIfc CastNeighborToEdgeIfc(Neighbor val)
 {
     return val; //implicit upcast
 }
Ejemplo n.º 17
0
    public void SetVoxelOnNeighbor(Neighbor neighbor, int x, int y, int z, int newVoxel)
    {
        Debug.Log("Setting Voxel On Neighbor");

        if(voxelComplex!=null){
            Vector3 newPosition = Vector3.zero;

            switch (neighbor){
            case Neighbor.Right:
                newPosition.x = Width*transform.localScale.x;
                break;
            case Neighbor.Left:
                newPosition.x-=Width*transform.localScale.x;
                break;
            case Neighbor.Front:
                newPosition.z-=Depth*transform.localScale.z;
                break;
            case Neighbor.Back:
                newPosition.z+=Depth*transform.localScale.z;
                break;
            case Neighbor.Top:
                newPosition.y+=Height*transform.localScale.y;
                break;
            case Neighbor.Bottom:
                newPosition.y-=Height*transform.localScale.y;
                break;

            }

            var neighbor_maybe = (VoxelStructure)voxelComplex.GetVoxelStructureAtPosition(transform.position+newPosition);
            if(neighbor_maybe==null){

                var newGo = new GameObject();
                var newStructure = newGo.AddComponent<VoxelStructure>();
                newStructure.voxelComplex = voxelComplex;
                newStructure.transform.parent = voxelComplex.transform;

                newStructure.Width = Width;
                newStructure.Height = Height;
                newStructure.Depth = Depth;

                newStructure.pallette = pallette;
                //
                newStructure.transform.localScale = transform.localScale;
                newStructure.transform.position = transform.position + newPosition;
                newStructure.SetVoxel(x,y,z,newVoxel);
                newStructure.Draw();

            }else{
                neighbor_maybe.SetVoxel(x,y,z,newVoxel);
                neighbor_maybe.Draw();
            }

        }
    }
Ejemplo n.º 18
0
 /** Sets the appropriate neighbor for this TerrainRenderable.  Neighbors are necessary
 to know when to bridge between LODs.
 */
 public void SetNeighbor( Neighbor n, Renderable t )
 {
     neighbors[(int) n ] = t;
 }
Ejemplo n.º 19
0
        private int PickTile(Neighbor neighbors)
        {
            // Top Right
            if (Matches(neighbors, Neighbor.Right | Neighbor.BottomRight | Neighbor.Bottom, Neighbor.TopRight | Neighbor.BottomLeft))
            {
                return(183);
            }

            if (Matches(neighbors, Neighbor.Left | Neighbor.Right | AllBottom, Neighbor.TopLeft | Neighbor.TopRight))
            {
                return(184);
            }

            if (Matches(neighbors, Neighbor.Left | Neighbor.BottomLeft | Neighbor.Bottom, Neighbor.TopLeft | Neighbor.BottomRight))
            {
                return(185);
            }

            if (Matches(neighbors, Neighbor.Top | Neighbor.FarTop | Neighbor.Bottom | AllRight, Neighbor.TopLeft | Neighbor.BottomLeft))
            {
                return(233);
            }

            if (Matches(neighbors, Neighbor.Top | Neighbor.Bottom | AllRight, Neighbor.TopLeft | Neighbor.BottomLeft))
            {
                return(208);
            }

            if (Matches(neighbors, Neighbor.Top | Neighbor.FarTop | Neighbor.Bottom | AllLeft, Neighbor.TopRight | Neighbor.BottomRight))
            {
                return(235);
            }

            if (Matches(neighbors, Neighbor.Top | Neighbor.Bottom | AllLeft, Neighbor.TopRight | Neighbor.BottomRight))
            {
                return(210);
            }

            if (Matches(neighbors, AllTop | Neighbor.Right))
            {
                return(212);
            }

            if (Matches(neighbors, Neighbor.Top | Neighbor.TopRight | Neighbor.Right, Neighbor.BottomRight | Neighbor.TopLeft))
            {
                return(258);
            }

            if (Matches(neighbors, AllTop | Neighbor.Left))
            {
                return(213);
            }

            if (Matches(neighbors, Neighbor.Top | Neighbor.TopLeft | Neighbor.Left, Neighbor.BottomLeft | Neighbor.TopRight))
            {
                return(260);
            }

            if (Matches(neighbors, AllTop | Neighbor.Left | Neighbor.Right, Neighbor.BottomLeft | Neighbor.BottomRight))
            {
                return(259);
            }

            if (Matches(neighbors, Neighbor.Top | AllRight | Neighbor.Bottom))
            {
                return(237);
            }

            if (Matches(neighbors, Neighbor.Top | AllLeft | Neighbor.Bottom))
            {
                return(238);
            }

            if (Matches(neighbors, Neighbor.Top | Neighbor.TopRight | Neighbor.Right | Neighbor.Left | Neighbor.BottomLeft | Neighbor.Bottom, Neighbor.BottomRight))
            {
                return(283);
            }

            if (Matches(neighbors, Neighbor.Top | Neighbor.Right | Neighbor.TopLeft | Neighbor.Left | Neighbor.Bottom | Neighbor.BottomRight, Neighbor.BottomLeft))
            {
                return(284);
            }

            if (Matches(neighbors, AllTop | Neighbor.Left | AllRight | Neighbor.Bottom))
            {
                return(308);
            }

            if (Matches(neighbors, AllTop | AllLeft | Neighbor.Right | Neighbor.Bottom))
            {
                return(309);
            }

            return(-1);
        }
Ejemplo n.º 20
0
 public virtual void AddEdge( Neighbor n )
 {
     adjacentNeighbors.Add(n);
 }
Ejemplo n.º 21
0
 public TCell this[Neighbor neighbor]
 {
     get => neighbors[neighbor];
Ejemplo n.º 22
0
 // Adds an edge without weights if Weighted layer is not present
 public void AddEdge( Vertex start,   Neighbor theNeighbor ) 
 {
     start.AddEdge( theNeighbor );
     Vertex end = theNeighbor.neighbor;
     end.AddEdge( new  Neighbor( start ) );
 }
Ejemplo n.º 23
0
		unsafe public int StitchEdge( Neighbor neighbor, int hiLOD, int loLOD, bool omitFirstTri, bool omitLastTri, BufferBase ppIdx )
Ejemplo n.º 24
0
 public void AddNeighbor(Neighbor n)
 {
     neighbors.Add(n);
 }
Ejemplo n.º 25
0
 /** Returns the neighbor TerrainRenderable.
 */
 public Tile GetNeighbor( Neighbor n )
 {
     return neighbors[ (int)n ];
 }
Ejemplo n.º 26
0
 public static Vertex TransformNeighborToEnd(Neighbor val)
 {
     // should be a Lambda Method in C# 3.0
     return(val.end);
 }
Ejemplo n.º 27
0
        //public IndexData GetIndex( int LOD)
        //{
        //}
        /** Utility method to generate stitching indexes on the edge of a tile
        @param neighbor The neighbor direction to stitch
        @param hiLOD The LOD of this tile
        @param loLOD The LOD of the neighbor
        @param omitFirstTri Whether the first tri of the stitch (always clockwise
        relative to the centre of this tile) is to be omitted because an
        adjoining edge is also being stitched
        @param omitLastTri Whether the last tri of the stitch (always clockwise
        relative to the centre of this tile) is to be omitted because an
        adjoining edge is also being stitched
        @param pIdx Pointer to a pointer to the index buffer to push the results
        into (this pointer will be updated)
        @returns The number of indexes added
        */
        public long StitchEdge(Neighbor neighbor, long hiLOD, long loLOD, bool omitFirstTri, bool omitLastTri, IntPtr Idx, ref long pos)
        {
            Debug.Assert( loLOD > hiLOD );
            /*
            Now do the stitching; we can stitch from any level to any level.
            The stitch pattern is like this for each pair of vertices in the lower LOD
            (excuse the poor ascii art):

            lower LOD
            *-----------*
            |\  \ 3 /  /|
            |1\2 \ / 4/5|
            *--*--*--*--*
            higher LOD

            The algorithm is, for each pair of lower LOD vertices:
            1. Iterate over the higher LOD vertices, generating tris connected to the
            first lower LOD vertex, up to and including 1/2 the span of the lower LOD
            over the higher LOD (tris 1-2). Skip the first tri if it is on the edge
            of the tile and that edge is to be stitched itself.
            2. Generate a single tri for the middle using the 2 lower LOD vertices and
            the middle vertex of the higher LOD (tri 3).
            3. Iterate over the higher LOD vertices from 1/2 the span of the lower LOD
            to the end, generating tris connected to the second lower LOD vertex
            (tris 4-5). Skip the last tri if it is on the edge of a tile and that
            edge is to be stitched itself.

            The same algorithm works for all edges of the patch; stitching is done
            clockwise so that the origin and steps used change, but the general
            approach does not.
            */

            // Work out the steps ie how to increment indexes
            // Step from one vertex to another in the high detail version
            int step = 1 << (int)hiLOD;
            // Step from one vertex to another in the low detail version
            int superstep = 1 << (int)loLOD;
            // Step half way between low detail steps
            int halfsuperstep = superstep >> 1;

            // Work out the starting points and sign of increments
            // We always work the strip clockwise
            int startx = 0, starty = 0, endx = 0, rowstep = 0;
            bool horizontal = false;
            switch(neighbor)
            {
                case Neighbor.North:
                    startx = starty = 0;
                    endx =  (int)this.tileSize - 1;
                    rowstep = step;
                    horizontal = true;
                    break;
                case Neighbor.South:
                    // invert x AND y direction, helps to keep same winding
                    startx = starty = (int)this.tileSize - 1;
                    endx = 0;
                    rowstep = -step;
                    step = -step;
                    superstep = -superstep;
                    halfsuperstep = -halfsuperstep;
                    horizontal = true;
                    break;
                case Neighbor.East:
                    startx = 0;
                    endx = (int)this.tileSize - 1;
                    starty = (int)this.tileSize - 1;
                    rowstep = -step;
                    horizontal = false;
                    break;
                case Neighbor.West:
                    startx = (int)this.tileSize  - 1;
                    endx = 0;
                    starty = 0;
                    rowstep = step;
                    step = -step;
                    superstep = -superstep;
                    halfsuperstep = -halfsuperstep;
                    horizontal = false;
                    break;
                default:
                    break;
            };

            long numStitches = 0;

            unsafe
            {
                ushort* pIdx = (ushort *)Idx.ToPointer();
                for ( int j = startx; j != endx; j += superstep )
                {
                    int k;
                    for (k = 0; k != halfsuperstep; k += step)
                    {
                        int jk = j + k;
                        //skip the first bit of the corner?
                        if ( j != startx || k != 0 || !omitFirstTri )
                        {
                            if (horizontal)
                            {
                                pIdx[pos++] = index( j , starty );						numStitches++;
                                pIdx[pos++] = index( jk, starty + rowstep );			numStitches++;
                                pIdx[pos++] = index( jk + step, starty + rowstep );		numStitches++;
                            }
                            else
                            {
                                pIdx[pos++] = index( starty, j );						numStitches++;
                                pIdx[pos++] = index( starty + rowstep, jk );			numStitches++;
                                pIdx[pos++] = index( starty + rowstep, jk + step);		numStitches++;
                            }
                        }
                    }

                    // Middle tri
                    if (horizontal)
                    {
                        pIdx[pos++] = index( j, starty );								numStitches++;
                        pIdx[pos++] = index( j + halfsuperstep, starty + rowstep);		numStitches++;
                        pIdx[pos++] = index( j + superstep, starty );					numStitches++;
                    }
                    else
                    {
                        pIdx[pos++] = index( starty, j );								numStitches++;
                        pIdx[pos++] = index( starty + rowstep, j + halfsuperstep );		numStitches++;
                        pIdx[pos++] = index( starty, j + superstep );					numStitches++;
                    }

                    for (k = halfsuperstep; k != superstep; k += step)
                    {
                        int jk = j + k;
                        if ( j != endx - superstep || k != superstep - step || !omitLastTri )
                        {
                            if (horizontal)
                            {
                                pIdx[pos++] = index( j + superstep, starty );			numStitches++;
                                pIdx[pos++] = index( jk, starty + rowstep );			numStitches++;
                                pIdx[pos++] = index( jk + step, starty + rowstep );		numStitches++;
                            }
                            else
                            {
                                pIdx[pos++] = index( starty, j + superstep );			numStitches++;
                                pIdx[pos++] = index( starty + rowstep, jk );			numStitches++;
                                pIdx[pos++] = index( starty + rowstep, jk + step );		numStitches++;
                            }
                        }
                    }
                }
            }

            return numStitches;
        }
Ejemplo n.º 28
0
 public static EdgeIfc TransformNeighborToEdge(Neighbor val)
 {
     // should be a Lambda Method in C# 3.0
     return(val.edge);
 }
Ejemplo n.º 29
0
 // Adds an edge without weights if Weighted layer is not present
 //    public virtual void AddAnEdge( Vertex start,  Vertex end, int weight )
 //    {
 //    AddEdge( start, new  Neighbor( end ) );
 //    }
 // Adds an edge without weights if Weighted layer is not present
 public virtual EdgeIfc AddEdge( Vertex start,  Vertex end )
 {
     Neighbor e = new Neighbor( end );
     AddEdge( start, e );
     return e;
 }
Ejemplo n.º 30
0
 public override void Add(Neighbor data)
 {
     collection.InsertOne(data);
 }
Ejemplo n.º 31
0
    public void FindNeighbors()
    {
        List <Neighbor> temp = new List <Neighbor>();

        //go through current neighbors and keep the ones that are preset
        for (int i = 0; i < neighbors.Length; i++)
        {
            if (neighbors[i].preset)
            {
                temp.Add(neighbors[i]);
            }
        }

        //raycast in each direction to find neighbors
        RaycastHit hit;
        Neighbor   newNeigh;
        Waypoint   newWaypoint;

        if (Physics.Raycast(transform.position, Vector3.forward, out hit, 100))
        {
            newWaypoint = hit.collider.gameObject.GetComponent <Waypoint>();
            if (newWaypoint)
            {
                newNeigh = new Neighbor(hit.collider.gameObject.GetComponent <Waypoint>(), false);
                if (!temp.Contains(newNeigh))
                {
                    temp.Add(newNeigh);
                }
            }
        }
        if (Physics.Raycast(transform.position, Vector3.right, out hit, 100))
        {
            newWaypoint = hit.collider.gameObject.GetComponent <Waypoint>();
            if (newWaypoint)
            {
                newNeigh = new Neighbor(hit.collider.gameObject.GetComponent <Waypoint>(), false);
                if (!temp.Contains(newNeigh))
                {
                    temp.Add(newNeigh);
                }
            }
        }
        if (Physics.Raycast(transform.position, Vector3.back, out hit, 100))
        {
            newWaypoint = hit.collider.gameObject.GetComponent <Waypoint>();
            if (newWaypoint)
            {
                newNeigh = new Neighbor(hit.collider.gameObject.GetComponent <Waypoint>(), false);
                if (!temp.Contains(newNeigh))
                {
                    temp.Add(newNeigh);
                }
            }
        }
        if (Physics.Raycast(transform.position, Vector3.left, out hit, 100))
        {
            newWaypoint = hit.collider.gameObject.GetComponent <Waypoint>();
            if (newWaypoint)
            {
                newNeigh = new Neighbor(hit.collider.gameObject.GetComponent <Waypoint>(), false);
                if (!temp.Contains(newNeigh))
                {
                    temp.Add(newNeigh);
                }
            }
        }

        //set new neighbors
        neighbors = temp.ToArray();
    }
Ejemplo n.º 32
0
 public override void Delete(Neighbor data)
 {
     collection.DeleteOne(d => d.Id == data.Id);
 }
Ejemplo n.º 33
0
		public TerrainRenderable GetNeighbor( Neighbor n )
		{
			return this.neighbors[ (int)n ];
		}
Ejemplo n.º 34
0
 public override Neighbor GetWithId(Neighbor data)
 {
     return(collection.Find(d => d.Id == data.Id).FirstOrDefault());
 }
Ejemplo n.º 35
0
 public static Vertex TransformNeighborToEnd(Neighbor val)
 {
     return val.end;
 }
Ejemplo n.º 36
0
 public override Neighbor GetWithGeometry(Neighbor data)
 {
     return(collection.Find(d => d.Geometry.Coordinates == data.Geometry.Coordinates).FirstOrDefault());
 }
Ejemplo n.º 37
0
 /** Returns the neighbor TerrainRenderable.
  */
 public Tile GetNeighbor(Neighbor n)
 {
     return(neighbors[(int)n]);
 }
Ejemplo n.º 38
0
        public override Neighbor GetIntersects(Neighbor neighbor)
        {
            BsonDocument query = BsonDocument.Parse("{ '$and': [{'geometry': {'$geoIntersects': {'$geometry':" + neighbor.Geometry.ToBsonDocument() + "}}}, {'_id': {'$not': {'$eq': '" + neighbor.Id + "'}}}]}");

            return(collection.Find(query).FirstOrDefault());
        }
Ejemplo n.º 39
0
        private Neighbor GetNeighbors(GameLocation location, int x, int y, Vector2?ignore = null)
        {
            Neighbor result = Neighbor.None;

            // Top
            if (HasTile(location, x, y - 1, ignore))
            {
                result |= Neighbor.Top;

                // Far Top
                if (HasTile(location, x, y - 2, ignore))
                {
                    result |= Neighbor.FarTop;
                }
            }

            // Left
            if (HasTile(location, x - 1, y, ignore))
            {
                result |= Neighbor.Left;

                // Far Left
                if (HasTile(location, x - 2, y, ignore))
                {
                    result |= Neighbor.FarLeft;
                }
            }

            // Right
            if (HasTile(location, x + 1, y, ignore))
            {
                result |= Neighbor.Right;

                // Far Right
                if (HasTile(location, x + 2, y, ignore))
                {
                    result |= Neighbor.FarRight;
                }
            }

            // Bottom
            if (HasTile(location, x, y + 1, ignore))
            {
                result |= Neighbor.Bottom;

                // Far Bottom
                if (HasTile(location, x, y + 2, ignore))
                {
                    result |= Neighbor.FarBottom;
                }
            }

            // Top Left
            if ((result & (Neighbor.Top | Neighbor.Left)) != 0)
            {
                if (HasTile(location, x - 1, y - 1, ignore))
                {
                    result |= Neighbor.TopLeft;
                }
            }

            // Top Right
            if ((result & (Neighbor.Top | Neighbor.Right)) != 0)
            {
                if (HasTile(location, x + 1, y - 1, ignore))
                {
                    result |= Neighbor.TopRight;
                }
            }

            // Bottom Left
            if ((result & (Neighbor.Bottom | Neighbor.Left)) != 0)
            {
                if (HasTile(location, x - 1, y + 1, ignore))
                {
                    result |= Neighbor.BottomLeft;

                    // Far Bottom Left
                    if (HasTile(location, x - 1, y + 2, ignore))
                    {
                        result |= Neighbor.FarBottomLeft;
                    }
                }
            }

            // Bottom Right
            if ((result & (Neighbor.Bottom | Neighbor.Right)) != 0)
            {
                if (HasTile(location, x + 1, y + 1, ignore))
                {
                    result |= Neighbor.BottomRight;

                    // Far Bottom Right
                    if (HasTile(location, x + 1, y + 2, ignore))
                    {
                        result |= Neighbor.FarBottomRight;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 40
0
 public Vertex(string name, Neighbor neighbors)
 {
     this.Name          = name;
     this.AdjacencyList = neighbors;
 }
Ejemplo n.º 41
0
        public override void draw(SpriteBatch b, Vector2 tileLocation)
        {
            Texture2D tex = ModEntry.instance.OutsideTexture.Value;

            if (tex == null)             // || Sprite < 0)
            {
                return;
            }

            int x = (int)tileLocation.X;
            int y = (int)tileLocation.Y;

            Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * Game1.tileSize, y * Game1.tileSize));

            Neighbor neighbors = GetNeighbors(currentLocation, x, y);
            int      sprite    = PickTile(neighbors);

            // Draw Above

            if (sprite >= 0)
            {
                b.Draw(
                    tex,
                    local,
                    Game1.getSourceRectForStandardTileSheet(tex, sprite, 16, 16),
                    Color.White,
                    0f,
                    Vector2.Zero,
                    4f,
                    SpriteEffects.None,
                    (float)((y * 64.0 + 2.0 + x / 10000.0) / 20000.0)
                    );
            }

            string  label = ((short)neighbors).ToString();
            Vector2 size  = Game1.tinyFont.MeasureString(label);

            if (Game1.oldKBState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F3))
            {
                Utility.drawTextWithShadow(
                    b,
                    label,
                    Game1.tinyFont,
                    local + new Vector2((64 - size.X) / 2, (64 - size.Y) / 2),
                    Color.Black,
                    layerDepth: 1f
                    );
            }

            /*b.DrawString(
             *      Game1.smallFont,
             *      label,
             *      local + new Vector2(32,32),
             *      Color.White,
             *      0f,
             *      size / 2,
             *      1f,
             *      SpriteEffects.None,
             *      1f
             * );*/
        }
 public TerrainRenderable GetNeighbor(Neighbor n)
 {
     return(neighbors[(int)n]);
 }
Ejemplo n.º 43
0
 public Neighbor GetIntersects(Neighbor neighbor)
 {
     return(_neighborDal.GetIntersects(neighbor));
 }
 public void SetNeighbor(Neighbor n, TerrainRenderable t)
 {
     neighbors[(int)n] = t;
 }
Ejemplo n.º 45
0
 protected override void OnCreate()
 {
     RequireSingletonForUpdate <MapSettings>();
     _cmdBufferSystem = World.GetExistingSystem <EndInitializationEntityCommandBufferSystem>();
     _neighbors       = Neighbor.FullNeighborhood(Allocator.Persistent);
 }
Ejemplo n.º 46
0
    public void HasDetected(GameObject other)
    {
        if (!initialized)
        {
            return;
        }

        int colliderId = other.GetInstanceID();

        // if the object that collided is not the gameObject to which this script is attached
        if (colliderId != gameObject.GetInstanceID())
        {
            // if the object that collided is an agent
            if (other.layer.Equals(agentsLayer))
            {
                NeighbourAgents            otherNeighborhood = other.GetComponent("NeighbourAgents") as NeighbourAgents;
                Dictionary <int, Neighbor> otherNeighbors    = otherNeighborhood.neighbors;

                // if the agent has not the current agent as a neighbor
                if (!otherNeighbors.ContainsKey(gameObject.GetInstanceID()))
                {
                    // if the agent is not already a possible neighbor
                    if (!neighbors.ContainsKey(colliderId))
                    {
                        // Add the object that collided to the possible neighbors
                        Neighbor neighborAgent = new Neighbor();
                        neighborAgent.triggers   = 1;
                        neighborAgent.planning   = null;
                        neighborAgent.gameObject = other;
                        neighbors.Add(colliderId, neighborAgent);

                        //Debug.Log(colliderId + " is a possible neighbor of " + gameObject.GetInstanceID());
                    }
                    else                     // if it is already a possible neighbor
                    {
                        neighbors.Remove(colliderId);


                        Neighbor neighborAgent = new Neighbor();
                        // Increase the number of triggers
                        neighborAgent.triggers = 2;
                        if (!ADAFootstepTest.ADA_PLANNER_IN_USE)
                        {
                            neighborAgent.planning           = other.GetComponent("FootstepPlanningTest") as Planner;
                            neighborAgent.animationInterface = other.GetComponent(animationInterfaceComponentName) as AnimationInterface;
                        }
                        else
                        {
                            neighborAgent.planning           = other.GetComponent("ADAFootstepTest") as Planner;
                            neighborAgent.animationInterface = other.GetComponent(animationInterfaceComponentName) as AnimationInterface;
                        }
                        neighborAgent.gameObject = other;
                        neighbors.Add(colliderId, neighborAgent);

                        // MUBBASIR -- WE WENT FROM 1 TO 2 -- WE SHOULD REPLAN
                        observable.notifyObservers(Event.NEIGBHOR_AGENTS_CHANGED, null);

                        newNeighbor = true;

                        // If it has triggered the two triggers it will be considered as a neighbor by the domain
                        //Debug.Log(colliderId + " is neighbor of " + gameObject.GetInstanceID());
                    }
                }
            }
        }
    }
Ejemplo n.º 47
0
		public int StitchEdge( Neighbor neighbor, int hiLOD, int loLOD, bool omitFirstTri, bool omitLastTri, BufferBase ppIdx )
#endif
		{
			Debug.Assert( loLOD > hiLOD, "TerrainZoneRenderable.StitchEdge" );
			/*
			Now do the stitching; we can stitch from any level to any level.
			The stitch pattern is like this for each pair of vertices in the lower LOD
			(excuse the poor ascii art):

			lower LOD
			*-----------*
			|\  \ 3 /  /|
			|1\2 \ / 4/5|
			*--*--*--*--*
			higher LOD

			The algorithm is, for each pair of lower LOD vertices:
			1. Iterate over the higher LOD vertices, generating tris connected to the
			first lower LOD vertex, up to and including 1/2 the span of the lower LOD
			over the higher LOD (tris 1-2). Skip the first tri if it is on the edge
			of the tile and that edge is to be stitched itself.
			2. Generate a single tri for the middle using the 2 lower LOD vertices and
			the middle vertex of the higher LOD (tri 3).
			3. Iterate over the higher LOD vertices from 1/2 the span of the lower LOD
			to the end, generating tris connected to the second lower LOD vertex
			(tris 4-5). Skip the last tri if it is on the edge of a tile and that
			edge is to be stitched itself.

			The same algorithm works for all edges of the patch; stitching is done
			clockwise so that the origin and steps used change, but the general
			approach does not.
			*/

			// Get pointer to be updated
			var pIdx = ppIdx.ToUShortPointer();
			var idx = 0;

			// Work out the steps ie how to increment indexes
			// Step from one vertex to another in the high detail version
			var step = 1 << hiLOD;
			// Step from one vertex to another in the low detail version
			var superstep = 1 << loLOD;
			// Step half way between low detail steps
			var halfsuperstep = superstep >> 1;

			// Work out the starting points and sign of increments
			// We always work the strip clockwise
			int startx, starty, endx, rowstep;
			startx = starty = endx = rowstep = 0;
			var horizontal = false;
			switch ( neighbor )
			{
				case Neighbor.NORTH:
					startx = starty = 0;
					endx = this.mOptions.tileSize - 1;
					rowstep = step;
					horizontal = true;
					break;
				case Neighbor.SOUTH:
					// invert x AND y direction, helps to keep same winding
					startx = starty = this.mOptions.tileSize - 1;
					endx = 0;
					rowstep = -step;
					step = -step;
					superstep = -superstep;
					halfsuperstep = -halfsuperstep;
					horizontal = true;
					break;
				case Neighbor.EAST:
					startx = 0;
					endx = this.mOptions.tileSize - 1;
					starty = this.mOptions.tileSize - 1;
					rowstep = -step;
					horizontal = false;
					break;
				case Neighbor.WEST:
					startx = this.mOptions.tileSize - 1;
					endx = 0;
					starty = 0;
					rowstep = step;
					step = -step;
					superstep = -superstep;
					halfsuperstep = -halfsuperstep;
					horizontal = false;
					break;
			}

			var numIndexes = 0;

			for ( var j = startx; j != endx; j += superstep )
			{
				int k;
				for ( k = 0; k != halfsuperstep; k += step )
				{
					var jk = j + k;
					//skip the first bit of the corner?
					if ( j != startx || k != 0 || !omitFirstTri )
					{
						if ( horizontal )
						{
							pIdx[ idx++ ] = Index( jk, starty + rowstep );
							numIndexes++; // original order: 2
							pIdx[ idx++ ] = Index( jk + step, starty + rowstep );
							numIndexes++; // original order: 3
							pIdx[ idx++ ] = Index( j, starty );
							numIndexes++; // original order: 1
						}
						else
						{
							pIdx[ idx++ ] = Index( starty + rowstep, jk );
							numIndexes++; // original order: 2
							pIdx[ idx++ ] = Index( starty + rowstep, jk + step );
							numIndexes++; // original order: 3
							pIdx[ idx++ ] = Index( starty, j );
							numIndexes++; // original order: 1
						}
					}
				}

				// Middle tri
				if ( horizontal )
				{
					pIdx[ idx++ ] = Index( j + halfsuperstep, starty + rowstep );
					numIndexes++; // original order: 2
					pIdx[ idx++ ] = Index( j + superstep, starty );
					numIndexes++; // original order: 3
					pIdx[ idx++ ] = Index( j, starty );
					numIndexes++; // original order: 1
				}
				else
				{
					pIdx[ idx++ ] = Index( starty + rowstep, j + halfsuperstep );
					numIndexes++; // original order: 2
					pIdx[ idx++ ] = Index( starty, j + superstep );
					numIndexes++; // original order: 3
					pIdx[ idx++ ] = Index( starty, j );
					numIndexes++; // original order: 1
				}

				for ( k = halfsuperstep; k != superstep; k += step )
				{
					var jk = j + k;
					if ( j != endx - superstep || k != superstep - step || !omitLastTri )
					{
						if ( horizontal )
						{
							pIdx[ idx++ ] = Index( jk, starty + rowstep );
							numIndexes++; // original order: 2
							pIdx[ idx++ ] = Index( jk + step, starty + rowstep );
							numIndexes++; // original order: 3
							pIdx[ idx++ ] = Index( j + superstep, starty );
							numIndexes++; // original order: 1
						}
						else
						{
							pIdx[ idx++ ] = Index( starty + rowstep, jk );
							numIndexes++; // original order: 2
							pIdx[ idx++ ] = Index( starty + rowstep, jk + step );
							numIndexes++; // original order: 3
							pIdx[ idx++ ] = Index( starty, j + superstep );
							numIndexes++; // original order: 1
						}
					}
				}
			}

			ppIdx.Ptr += idx*sizeof ( ushort );

			return numIndexes;
		}
Ejemplo n.º 48
0
 private bool CanMoveTo(Neighbor neighbor) => (neighbor.Door & Keys) == neighbor.Door;
Ejemplo n.º 49
0
		public void SetNeighbor( Neighbor n, TerrainZoneRenderable t )
		{
			this.mNeighbors[ (int)n ] = t;
		}
Ejemplo n.º 50
0
        public ExtractResult Extract()
        {
            var last = route.Last.Value;
            var star = TryGetStar(last);

            if (star == null)
            {
                // Case 1
                var wpt = FindWpt(last);

                var neighbor  = new Neighbor("DCT", wpt.Distance(rwyWpt));
                var node1     = new RouteNode(wpt, neighbor);
                var node2     = new RouteNode(rwyWpt, null);
                var destRoute = new Route(node1, node2);

                return(new ExtractResult(route.ToRouteString(), destRoute));
            }

            // Remove STAR from RouteString.
            route.RemoveLast();

            // Case 2, 3
            var starFirstWpt = star.First();

            if (starFirstWpt.ID != route.Last.Value)
            {
                throw new ArgumentException($"{route.Last.Value} is not the"
                                            + $" first waypoint of the STAR {last}.");
            }

            if (wptList.FindByWaypoint(starFirstWpt) == -1)
            {
                // Case 3

                route.RemoveLast();
                // Now the last item of route is the last enroute waypoint.

                var    lastEnrouteWpt = FindWpt(route.Last.Value);
                var    firstStarWpt   = star.First();
                double distance1      = lastEnrouteWpt.Distance(firstStarWpt);

                var neighbor1 = new Neighbor("DCT", distance1);
                var node1     = new RouteNode(lastEnrouteWpt, neighbor1);

                double distance2 = star.TotalDistance();
                var    innerWpts = star.WithoutFirstAndLast();

                var neighbor2 = new Neighbor(
                    last, distance2, innerWpts, InnerWaypointsType.Terminal);
                var node2 = new RouteNode(firstStarWpt, neighbor2);

                var node3     = new RouteNode(rwyWpt, null);
                var destRoute = new Route(node1, node2, node3);

                return(new ExtractResult(route.ToRouteString(), destRoute));
            }
            else
            {
                // Case 2
                var    firstStarWpt = star.First();
                double distance     = star.TotalDistance();
                var    innerWpts    = star.WithoutFirstAndLast();

                var neighbor = new Neighbor(
                    last, distance, innerWpts, InnerWaypointsType.Terminal);
                var node1 = new RouteNode(firstStarWpt, neighbor);

                var node2     = new RouteNode(rwyWpt, null);
                var destRoute = new Route(node1, node2);

                return(new ExtractResult(route.ToRouteString(), destRoute));
            }
        }
Ejemplo n.º 51
0
 /** Sets the appropriate neighbor for this TerrainRenderable.  Neighbors are necessary
 to know when to bridge between LODs.
 */
 public void SetNeighbor( Neighbor n, Tile t )
 {
     neighbors[(int) n ] = t;
 }
 private void Initialized(Neighbor neighbor)
 {
     neighbor.Initialize(ironBellyTestSetting);
 }
Ejemplo n.º 53
0
 public virtual void adjustAdorns( Neighbor sourceNeighbor )
 {
 }
        /*CAUTION: Any change in the advanced heartbeat structure should be accounted for in variables
         * NetManagerGlobal.AdvHeartbeatFixedSize and NetManagerGlobal.EachNeighborInfoSize
         */
        private static void Send_AdvancedHeartbeat(object state)
        {
            ushort[] neighbors = MACBase.NeighborListArray();
            _neighborInfoManagerPipe.MACBase.MACNeighborList(neighbors);

            // Find the number of neighbors
            byte num_nbrs = 0;

            for (int i = 0; i < neighbors.Length; i++)
            {
                if (neighbors[i] == 0) // At the end
                {
                    break;
                }
                num_nbrs++;
            }

            if (num_nbrs == 0)
            {
                return;
            }

            _numBeat++;

            ushort[] valid_nbrs;
            byte[]   nbrStatus;
            ushort[] numSamplesRec;
            ushort[] numSyncSent;
            byte[]   avgRSSI;
            byte[]   ewrnp;
            byte[]   isAvailableForUpperLayers;

            // TODO: Make this if-else more compact
            if (num_nbrs <= NetManagerGlobal.MaxNeighborsPerHeartbeat) // Send all information
            {
                valid_nbrs                = new ushort[num_nbrs];
                nbrStatus                 = new byte[num_nbrs];
                numSamplesRec             = new ushort[num_nbrs];
                numSyncSent               = new ushort[num_nbrs];
                avgRSSI                   = new byte[num_nbrs];
                ewrnp                     = new byte[num_nbrs];
                isAvailableForUpperLayers = new byte[num_nbrs];

                // Initialize ewrnp array with maxEtx
                for (int i = 0; i < ewrnp.Length; i++)
                {
                    ewrnp[i] = RoutingGlobal.MaxEtx;
                }

                for (int i = 0; i < num_nbrs; i++)
                {
                    var      nbr_name = neighbors[i];
                    Neighbor nbr      = _neighborInfoManagerPipe.NeighborStatus(nbr_name);

                    valid_nbrs[i]    = nbr_name;
                    nbrStatus[i]     = (byte)nbr.NeighborStatus;
                    numSamplesRec[i] = nbr.NumOfTimeSamplesRecorded;
                    numSyncSent[i]   = nbr.NumTimeSyncMessagesSent;
                    avgRSSI[i]       = (byte)((nbr.ReceiveLink.AverageRSSI + nbr.SendLink.AverageRSSI)); // * 0.5;

                    int index = CandidateTable.findIndex(nbr_name);
                    if (RoutingGlobal.Parent == nbr_name)
                    {
                        ewrnp[i] = RoutingGlobal.GetPathEWRNP();
                    }
                    else if (index < byte.MaxValue)
                    {
                        ewrnp[i] = (byte)CandidateTable._candidateList[index].GetPathEWRNP();
                    }

                    isAvailableForUpperLayers[i] = nbr.IsAvailableForUpperLayers ? (byte)1 : (byte)0;
                }
            }
            else // Starting with the current head pointer, use neighbor list as a circular array to send out info for NetManagerGlobal.MaxNeighborsPerHeartbeat consecutive neighbors
            {
                valid_nbrs                = new ushort[NetManagerGlobal.MaxNeighborsPerHeartbeat];
                nbrStatus                 = new byte[NetManagerGlobal.MaxNeighborsPerHeartbeat];
                numSamplesRec             = new ushort[NetManagerGlobal.MaxNeighborsPerHeartbeat];
                numSyncSent               = new ushort[NetManagerGlobal.MaxNeighborsPerHeartbeat];
                avgRSSI                   = new byte[NetManagerGlobal.MaxNeighborsPerHeartbeat];
                ewrnp                     = new byte[NetManagerGlobal.MaxNeighborsPerHeartbeat];
                isAvailableForUpperLayers = new byte[NetManagerGlobal.MaxNeighborsPerHeartbeat];

                // Initialize ewrnp array with maxEtx
                for (int i = 0; i < ewrnp.Length; i++)
                {
                    ewrnp[i] = RoutingGlobal.MaxEtx;
                }

                for (int i = 0; i < NetManagerGlobal.MaxNeighborsPerHeartbeat; i++)
                {
                    // If current head pointer has a higher index than number of neighbors (owing to loss), restart at index 0; otherwise, start at current head pointer
                    circ_headptr = (circ_headptr < num_nbrs) ? (byte)(circ_headptr % num_nbrs) : (byte)0;
                    var      nbr_name = neighbors[circ_headptr];
                    Neighbor nbr      = _neighborInfoManagerPipe.NeighborStatus(nbr_name);

                    valid_nbrs[i]    = nbr_name;
                    nbrStatus[i]     = (byte)nbr.NeighborStatus;
                    numSamplesRec[i] = nbr.NumOfTimeSamplesRecorded;
                    numSyncSent[i]   = nbr.NumTimeSyncMessagesSent;
                    avgRSSI[i]       = (byte)((nbr.ReceiveLink.AverageRSSI + nbr.SendLink.AverageRSSI)); // * 0.5;

                    int index = CandidateTable.findIndex(nbr_name);
                    if (RoutingGlobal.Parent == nbr_name)
                    {
                        ewrnp[i] = RoutingGlobal.GetPathEWRNP();
                    }
                    else if (index < byte.MaxValue)
                    {
                        ewrnp[i] = (byte)CandidateTable._candidateList[index].GetPathEWRNP();
                    }

                    isAvailableForUpperLayers[i] = nbr.IsAvailableForUpperLayers ? (byte)1 : (byte)0;

                    circ_headptr = (byte)((circ_headptr + 1) % num_nbrs);
                }

                // Adjust circular buffer head pointer at the end
                circ_headptr = (byte)((circ_headptr + 1) % num_nbrs);
            }

#if DBG_DIAGNOSTIC
            SystemGlobal.PrintNumericVals("Neighbor names: ", valid_nbrs);
            SystemGlobal.PrintNumericVals("Neighbor status: ", nbrStatus);
            SystemGlobal.PrintNumericVals("Avg RSSI: ", avgRSSI);
            SystemGlobal.PrintNumericVals("Routing EWRNP: ", ewrnp);
            SystemGlobal.PrintNumericVals("# samples rcvd: ", numSamplesRec);
            SystemGlobal.PrintNumericVals("# timesync sent: ", numSyncSent);
            SystemGlobal.PrintNumericVals("Available for upper layers: ", isAvailableForUpperLayers);
            Debug.Print("Parent: " + RoutingGlobal.Parent);
            Debug.Print("");
#endif

            var size = NetManagerGlobal.MoteMessages.Compose.Heartbeat(NetManagerGlobal.MsgBytes, _neighborInfoManagerPipe.MACRadioObj.RadioAddress, (ushort)_numBeat, SystemGlobal.NodeType, RoutingGlobal.Parent, (byte)RoutingGlobal.GetPathEWRNP(), valid_nbrs, nbrStatus, numSamplesRec, numSyncSent, avgRSSI, ewrnp, isAvailableForUpperLayers, RoutingGlobal.Infinity);
            //var size = NetManagerGlobal.MoteMessages.Compose.Heartbeat(NetManagerGlobal.MsgBytes, _neighborInfoManagerPipe.MACRadioObj.RadioAddress, (ushort)_numBeat, SystemGlobal.NodeType, RoutingGlobal.Parent, (byte)RoutingGlobal.BestEtx, neighbors, nbrStatus, avgRSSI, ewrnp);
#if !DBG_LOGIC
            Debug.Print("NeighborInfo#" + _numBeat + " size: " + size);
#endif

            #region Uncomment when not using scheduler
            // If in a reset, do not forward TODO: Change this to "spray"
            if (RoutingGlobal._color == Color.Red)
            {
#if DBG_VERBOSE
                Debug.Print("\tIn a Reset wave... not forwarded");
#endif
                return;
            }

            // If parent is available, pass it on
            if (RoutingGlobal.IsParent)
            {
                var status = RoutingGlobal.SendToParent(_neighborInfoManagerPipe, NetManagerGlobal.MsgBytes, size);
                if (status != 999)
                {
                    RoutingGlobal.UpdateNumTriesInCurrentWindow_Parent(1);
#if !DBG_LOGIC
                    Debug.Print("Updated numTriesInCurrentWindow for Parent " + RoutingGlobal.Parent + "; new value = " + RoutingGlobal.GetNumTriesInCurrentWindow_Parent());
#endif
                    if (!_sentPacketSizes.Contains(status))
                    {
                        _sentPacketSizes.Add(status, size);
                    }
                }
                else //Retry once
                {
#if !DBG_LOGIC
                    Debug.Print("Retrying packet");
#endif
                    RoutingGlobal.CleanseCandidateTable(_neighborInfoManagerPipe);
                    Candidate tmpBest = CandidateTable.GetBestCandidate(false);
                    NetManagerGlobal.TempParent = tmpBest.GetMacID();
                    status = NetManagerGlobal.SendToTempParent(_neighborInfoManagerPipe, NetManagerGlobal.MsgBytes, size);
                    if (status != 999)
                    {
                        tmpBest.UpdateNumTriesInCurrentWindow(1);
#if !DBG_LOGIC
                        Debug.Print("Updated numTriesInCurrentWindow for TempParent " + NetManagerGlobal.TempParent + "; new value = " + tmpBest.GetNumTriesInCurrentWindow());
#endif
                        if (!_sentPacketSizes.Contains(status))
                        {
                            _sentPacketSizes.Add(status, size);
                        }
                    }
                }
            }
            #endregion
        }
Ejemplo n.º 55
0
 public static EdgeIfc TransformNeighborToEdge(Neighbor val)
 {
     // should be a Lambda Method in C# 3.0
     return val.edge;
 }
Ejemplo n.º 56
0
    public void CheckNeighbors()
    {
        myTemp             = false;
        transform.position = new Vector3(transform.position.x, 0.5f, transform.position.z);

        int x = Mathf.FloorToInt(transform.position.x);
        int z = Mathf.FloorToInt(transform.position.z);

        if (myPathManager.GetPortals.Count != 0)
        {
            for (int i = 0; i < myPathManager.GetPortals.Count; i++)
            {
                if (x - 1 >= 0)
                {
                    if (myPathManager.GetPathTileMap[x - 1, z] != null)
                    {
                        //Debug.Log("Last placed tile pos: " + myPathManager.GetLastPlacedTile.transform.position, myPathManager.GetLastPlacedTile.gameObject);

                        //Debug.Log("Found Normal Tile");
                        if (myPathManager.GetPathTileMap[x - 1, z] == myPathManager.GetLastPlacedTile)
                        {
                            myPathTileNeighbors             = myPathManager.GetLastPlacedTile;
                            myPathManager.GetLastPlacedTile = this;
                            myNeigbor = Neighbor.left;
                            CheckOldNeighborLeft();
                        }
                        if (myPathManager.GetPathTileMap[x - 1, z] == myPathManager.GetPortals[i].myStartTile)
                        {
                            //Debug.Log("Found Start Tile");
                            myPathTileNeighbors             = myPathManager.GetPortals[i].myStartTile;
                            myPathManager.GetLastPlacedTile = this;
                            myNeigbor = Neighbor.left;
                            CheckOldNeighborLeft();
                        }
                    }
                }
                if (x + 1 < WorldController.Instance.GetWorldWidth)
                {
                    if (myPathManager.GetPathTileMap[x + 1, z] != null)
                    {
                        //Debug.Log("Last placed tile pos: " + myPathManager.GetLastPlacedTile.transform.position, myPathManager.GetLastPlacedTile.gameObject) ;
                        if (myPathManager.GetPathTileMap[x + 1, z] == myPathManager.GetLastPlacedTile)
                        {
                            myPathTileNeighbors             = myPathManager.GetLastPlacedTile;
                            myPathManager.GetLastPlacedTile = this;
                            myNeigbor = Neighbor.right;
                            CheckOldNeighborRight();
                        }
                        if (myPathManager.GetPathTileMap[x + 1, z] == myPathManager.GetPortals[i].myStartTile)
                        {
                            //Debug.Log("Found Start Tile");

                            myPathTileNeighbors             = myPathManager.GetPortals[i].myStartTile;
                            myPathManager.GetLastPlacedTile = this;
                            myNeigbor = Neighbor.right;
                            CheckOldNeighborRight();
                        }
                    }
                }
                if (z - 1 >= 0)
                {
                    if (myPathManager.GetPathTileMap[x, z - 1] != null)
                    {
                        //Debug.Log("Last placed tile pos: " + myPathManager.GetLastPlacedTile.transform.position, myPathManager.GetLastPlacedTile.gameObject);

                        if (myPathManager.GetPathTileMap[x, z - 1] == myPathManager.GetLastPlacedTile)
                        {
                            myPathTileNeighbors             = myPathManager.GetLastPlacedTile;
                            myPathManager.GetLastPlacedTile = this;
                            myNeigbor = Neighbor.down;
                            CheckOldNeighborDown();
                        }
                        if (myPathManager.GetPathTileMap[x, z - 1] == myPathManager.GetPortals[i].myStartTile)
                        {
                            //Debug.Log("Found Start Tile");

                            myPathTileNeighbors             = myPathManager.GetPortals[i].myStartTile;
                            myPathManager.GetLastPlacedTile = this;
                            myNeigbor = Neighbor.down;
                            CheckOldNeighborDown();
                        }
                    }
                }
                if (z + 1 < WorldController.Instance.GetWorldDepth)
                {
                    if (myPathManager.GetPathTileMap[x, z + 1] != null)
                    {
                        //Debug.Log("Last placed tile pos: " + myPathManager.GetLastPlacedTile.transform.position, myPathManager.GetLastPlacedTile.gameObject);

                        //Debug.Log("Found Normal Tile");
                        if (myPathManager.GetPathTileMap[x, z + 1] == myPathManager.GetLastPlacedTile)
                        {
                            myPathTileNeighbors             = myPathManager.GetLastPlacedTile;
                            myPathManager.GetLastPlacedTile = this;
                            myNeigbor = Neighbor.up;
                            CheckOldNeighborUp();
                        }
                        if (myPathManager.GetPathTileMap[x, z + 1] == myPathManager.GetPortals[i].myStartTile)
                        {
                            myPathTileNeighbors             = myPathManager.GetPortals[i].myStartTile;
                            myPathManager.GetLastPlacedTile = this;
                            myNeigbor = Neighbor.up;
                            CheckOldNeighborUp();
                        }
                    }
                }
            }
        }
        else
        {
            if (x - 1 >= 0)
            {
                if (myPathManager.GetPathTileMap[x - 1, z] != null)
                {
                    if (myPathManager.GetPathTileMap[x - 1, z] == myPathManager.GetLastPlacedTile)
                    {
                        myPathTileNeighbors = myPathManager.GetLastPlacedTile;
                        myNeigbor           = Neighbor.left;
                        CheckOldNeighborLeft();
                        myPathManager.GetLastPlacedTile = this;
                    }
                    //if (myPathManager.GetPathTileMap[x - 1, z] == myPathManager.GetPortals[i].myStartTile)
                    //{
                    //    Debug.Log("Found Start Tile");
                    //    myPathTileNeighbors = myPathManager.GetPortals[i].myStartTile;
                    //    myNeigbor = Neighbor.left;
                    //    CheckOldNeighborLeft();
                    //    myPathManager.GetLastPlacedTile = this;
                    //}
                }
            }
            if (x + 1 < WorldController.Instance.GetWorldWidth)
            {
                if (myPathManager.GetPathTileMap[x + 1, z] != null)
                {
                    if (myPathManager.GetPathTileMap[x + 1, z] == myPathManager.GetLastPlacedTile)
                    {
                        myPathTileNeighbors = myPathManager.GetLastPlacedTile;
                        myNeigbor           = Neighbor.right;
                        CheckOldNeighborRight();
                        myPathManager.GetLastPlacedTile = this;
                    }
                    //if (myPathManager.GetPathTileMap[x + 1, z] == myPathManager.GetPortals[i].myStartTile)
                    //{
                    //    Debug.Log("Found Start Tile");

                    //    myPathTileNeighbors = myPathManager.GetPortals[i].myStartTile;
                    //    myNeigbor = Neighbor.right;
                    //    CheckOldNeighborRight();
                    //    myPathManager.GetLastPlacedTile = this;
                    //}
                }
            }
            if (z - 1 >= 0)
            {
                if (myPathManager.GetPathTileMap[x, z - 1] != null)
                {
                    if (myPathManager.GetPathTileMap[x, z - 1] == myPathManager.GetLastPlacedTile)
                    {
                        myPathTileNeighbors = myPathManager.GetLastPlacedTile;
                        myNeigbor           = Neighbor.down;
                        CheckOldNeighborDown();

                        myPathManager.GetLastPlacedTile = this;
                    }
                    //if (myPathManager.GetPathTileMap[x, z - 1] == myPathManager.GetPortals[i].myStartTile)
                    //{
                    //    Debug.Log("Found Start Tile");

                    //    myPathTileNeighbors = myPathManager.GetPortals[i].myStartTile;
                    //    myNeigbor = Neighbor.down;
                    //    CheckOldNeighborDown();
                    //    myPathManager.GetLastPlacedTile = this;
                    //}
                }
            }
            if (z + 1 < WorldController.Instance.GetWorldDepth)
            {
                if (myPathManager.GetPathTileMap[x, z + 1] != null)
                {
                    if (myPathManager.GetPathTileMap[x, z + 1] == myPathManager.GetLastPlacedTile)
                    {
                        myPathTileNeighbors = myPathManager.GetLastPlacedTile;
                        myNeigbor           = Neighbor.up;
                        CheckOldNeighborUp();
                        myPathManager.GetLastPlacedTile = this;
                    }
                    //if (myPathManager.GetPathTileMap[x, z + 1] == myPathManager.GetPortals[i].myStartTile)
                    //{
                    //    myPathTileNeighbors = myPathManager.GetPortals[i].myStartTile;
                    //    myNeigbor = Neighbor.up;
                    //    CheckOldNeighborUp();
                    //    myPathManager.GetLastPlacedTile = this;
                    //}
                }
            }
        }
        myPlacementEffect.Play();
        AudioManager.ourInstance.PlayEffect(AudioManager.EEffects.PLACE);
    }
Ejemplo n.º 57
0
 public void AddNeighbor( Neighbor n )
 {
     neighbors.Add( n );
 }
Ejemplo n.º 58
0
        private void AddEdge(IDictionary <string, IDictionary <string, int> > edgesToCheck, Neighbor neighbor, string nodeId)
        {
            if (!edgesToCheck.TryGetValue(neighbor.NodeId, out IDictionary <string, int> edges))
            {
                edges = new Dictionary <string, int>();
                edgesToCheck.Add(neighbor.NodeId, edges);
            }

            edges.Add(nodeId, neighbor.Cost);
        }
Ejemplo n.º 59
0
 public virtual void AddEdge( Vertex start,  Neighbor theNeighbor )
 {
     start.AddEdge( theNeighbor );
 }
Ejemplo n.º 60
0
    public void HasDetected(GameObject other)
    {
        if (!initialized)
            return;

        int colliderId = other.GetInstanceID();

        // if the object that collided is not the gameObject to which this script is attached
        if ( colliderId != gameObject.GetInstanceID())
        {
            // if the object that collided is an agent
            if ( other.layer.Equals(agentsLayer) )
            {
                NeighbourAgents otherNeighborhood = other.GetComponent("NeighbourAgents") as NeighbourAgents;
                Dictionary<int,Neighbor> otherNeighbors = otherNeighborhood.neighbors;

                // if the agent has not the current agent as a neighbor
                if ( !otherNeighbors.ContainsKey(gameObject.GetInstanceID()))
                {

                    // if the agent is not already a possible neighbor
                    if (!neighbors.ContainsKey(colliderId))
                    {
                        // Add the object that collided to the possible neighbors
                        Neighbor neighborAgent = new Neighbor();
                        neighborAgent.triggers = 1;
                        neighborAgent.planning = null;
                        neighborAgent.gameObject = other;
                        neighbors.Add(colliderId, neighborAgent);

                        //Debug.Log(colliderId + " is a possible neighbor of " + gameObject.GetInstanceID());

                    }
                    else // if it is already a possible neighbor
                    {
                        neighbors.Remove(colliderId);

                        Neighbor neighborAgent = new Neighbor();
                        // Increase the number of triggers
                        neighborAgent.triggers = 2;
                        if (!ADAFootstepTest.ADA_PLANNER_IN_USE)
                        {
                            neighborAgent.planning = other.GetComponent("FootstepPlanningTest") as Planner;
                            neighborAgent.animationInterface = other.GetComponent(animationInterfaceComponentName) as AnimationInterface;
                        }
                        else
                        {
                            neighborAgent.planning = other.GetComponent("ADAFootstepTest") as Planner;
                            neighborAgent.animationInterface = other.GetComponent(animationInterfaceComponentName) as AnimationInterface;
                        }
                        neighborAgent.gameObject = other;
                        neighbors.Add(colliderId,neighborAgent);

                        // MUBBASIR -- WE WENT FROM 1 TO 2 -- WE SHOULD REPLAN
                        observable.notifyObservers(Event.NEIGBHOR_AGENTS_CHANGED, null);

                        newNeighbor = true;

                        // If it has triggered the two triggers it will be considered as a neighbor by the domain
                        //Debug.Log(colliderId + " is neighbor of " + gameObject.GetInstanceID());
                    }
                }
            }
        }
    }