Esempio n. 1
0
 public Cell(CoordPair p)
 {
     grid_x   = p.x_coord / MapConst.MAX_NUMBER_OF_CELLS;
     grid_y   = p.y_coord / MapConst.MAX_NUMBER_OF_CELLS;
     cell_x   = p.x_coord % MapConst.MAX_NUMBER_OF_CELLS;
     cell_y   = p.y_coord % MapConst.MAX_NUMBER_OF_CELLS;
     nocreate = false;
     //reserved = 0;
 }
Esempio n. 2
0
        public Cell(float x, float y)
        {
            CoordPair p = GridDefines.ComputeCellCoord(x, y);

            grid_x   = p.x_coord / MapConst.MAX_NUMBER_OF_CELLS;
            grid_y   = p.y_coord / MapConst.MAX_NUMBER_OF_CELLS;
            cell_x   = p.x_coord % MapConst.MAX_NUMBER_OF_CELLS;
            cell_y   = p.y_coord % MapConst.MAX_NUMBER_OF_CELLS;
            nocreate = false;
            //reserved = 0;
        }
Esempio n. 3
0
        void VisitCircle <T>(Visitor <T> visitor, Map map, CoordPair begin_cell, CoordPair end_cell) where T : Notifier
        {
            //here is an algorithm for 'filling' circum-squared octagon
            uint x_shift = (uint)Math.Ceiling((end_cell.x_coord - begin_cell.x_coord) * 0.3f - 0.5f);
            //lets calculate x_start/x_end coords for central strip...
            uint x_start = begin_cell.x_coord + x_shift;
            uint x_end   = end_cell.x_coord - x_shift;

            //visit central strip with constant width...
            for (uint x = x_start; x <= x_end; ++x)
            {
                for (uint y = begin_cell.y_coord; y <= end_cell.y_coord; ++y)
                {
                    CellCoord cellCoord = new CellCoord(x, y);
                    Cell      r_zone    = new Cell(cellCoord);
                    r_zone.nocreate = this.nocreate;
                    map.Visit(r_zone, visitor);
                }
            }

            //if x_shift == 0 then we have too small cell area, which were already
            //visited at previous step, so just return from procedure...
            if (x_shift == 0)
            {
                return;
            }

            uint y_start = end_cell.y_coord;
            uint y_end   = begin_cell.y_coord;

            //now we are visiting borders of an octagon...
            for (uint step = 1; step <= (x_start - begin_cell.x_coord); ++step)
            {
                //each step reduces strip height by 2 cells...
                y_end   += 1;
                y_start -= 1;
                for (uint y = y_start; y >= y_end; --y)
                {
                    //we visit cells symmetrically from both sides, heading from center to sides and from up to bottom
                    //e.g. filling 2 trapezoids after filling central cell strip...
                    CellCoord cellCoord_left = new CellCoord(x_start - step, y);
                    Cell      r_zone_left    = new Cell(cellCoord_left);
                    r_zone_left.nocreate = this.nocreate;
                    map.Visit(r_zone_left, visitor);

                    //right trapezoid cell visit
                    CellCoord cellCoord_right = new CellCoord(x_end + step, y);
                    Cell      r_zone_right    = new Cell(cellCoord_right);
                    r_zone_right.nocreate = this.nocreate;
                    map.Visit(r_zone_right, visitor);
                }
            }
        }
Esempio n. 4
0
        public CellArea(float x, float y, float radius)
        {
            if (radius <= 0.0f)
            {
                CoordPair center = GridDefines.ComputeCellCoord(x, y).normalize();
                low_bound  = center;
                high_bound = center;
                return;
            }
            CoordPair centerX = GridDefines.ComputeCellCoord(x - radius, y - radius).normalize();
            CoordPair centerY = GridDefines.ComputeCellCoord(x + radius, y + radius).normalize();

            low_bound  = centerX;
            high_bound = centerY;
        }
Esempio n. 5
0
 void ResizeBorders(CoordPair begin_cell, CoordPair end_cell)
 {
     begin_cell = low_bound;
     end_cell   = high_bound;
 }
Esempio n. 6
0
        public void Visit <T>(CoordPair standing_cell, Visitor <T> visitor, Map map, float radius, float x_off, float y_off) where T : Notifier
        {
            if (!standing_cell.IsCoordValid())
            {
                return;
            }

            //no jokes here... Actually placing ASSERT() here was good idea, but
            //we had some problems with DynamicObjects, which pass radius = 0.0f (DB issue?)
            //maybe it is better to just return when radius <= 0.0f?
            if (radius <= 0.0f)
            {
                map.Visit(this, visitor);
                return;
            }
            //lets limit the upper value for search radius
            if (radius > MapConst.SizeOfGrids)
            {
                radius = MapConst.SizeOfGrids;
            }

            //lets calculate object coord offsets from cell borders.
            CellArea area = new CellArea(x_off, y_off, radius);

            //if radius fits inside standing cell
            if (area == null)
            {
                map.Visit(this, visitor);
                return;
            }

            //visit all cells, found in CalculateCellArea()
            //if radius is known to reach cell area more than 4x4 then we should call optimized VisitCircle
            //currently this technique works with MAX_NUMBER_OF_CELLS 16 and higher, with lower values
            //there are nothing to optimize because SIZE_OF_GRID_CELL is too big...
            if ((area.high_bound.x_coord > (area.low_bound.x_coord + 4)) && (area.high_bound.y_coord > (area.low_bound.y_coord + 4)))
            {
                VisitCircle(visitor, map, area.low_bound, area.high_bound);
                return;
            }

            //ALWAYS visit standing cell first!!! Since we deal with small radiuses
            //it is very essential to call visitor for standing cell firstly...
            map.Visit(this, visitor);

            // loop the cell range
            for (uint x = area.low_bound.x_coord; x <= area.high_bound.x_coord; ++x)
            {
                for (uint y = area.low_bound.y_coord; y <= area.high_bound.y_coord; ++y)
                {
                    CellCoord cellCoord = new CellCoord(x, y);
                    //lets skip standing cell since we already visited it
                    if (cellCoord != standing_cell)
                    {
                        Cell r_zone = new Cell(cellCoord);
                        r_zone.nocreate = this.nocreate;
                        map.Visit(r_zone, visitor);
                    }
                }
            }
        }
Esempio n. 7
0
 public CoordPair(CoordPair obj)
 {
     Limit   = obj.Limit;
     x_coord = obj.x_coord;
     y_coord = obj.y_coord;
 }