/// <summary> Constructor. </summary> /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception> /// <param name="worldGrid"> The world grid which should provide the grid data to be watched. </param> /// <param name="numUnitsWide"> How many units wide the area that should be watched. </param> /// <param name="numUnitsHigh"> How many units high the area that should be watched. </param> public WorldGridSlice(WorldGrid worldGrid, int numUnitsWide, int numUnitsHigh) { if (worldGrid == null) { throw new ArgumentNullException("worldGrid"); } // we always need to be odd isn't that a statement of life) if (numUnitsWide % 2 != 1) { numUnitsWide = numUnitsWide + 1; } if (numUnitsHigh % 2 != 1) { numUnitsHigh = numUnitsHigh + 1; } // let's make sure we always have valid values numUnitsWide = Math.Max(numUnitsWide, 5); numUnitsHigh = Math.Max(numUnitsHigh, 5); _worldGrid = worldGrid; _visibleGridItems = new Array2D <SliceUnitData <T> >(numUnitsWide, numUnitsHigh); // these are used for converting an array index back into a world coordinate _numUnitsWideHalfThreshold = (_visibleGridItems.Width - 1) / 2; _numUnitsHighHalfThreshold = (_visibleGridItems.Height - 1) / 2; }
/// <summary> Default constructor. </summary> public ViewableChunks(WorldGrid worldGrid, int xRadius, int yRadius) { _world = worldGrid; _xRadius = xRadius; _yRadius = yRadius; NumberOfChunksWide = _xRadius * 2 + 1; NumberOfChunksHigh = _yRadius * 2 + 1; VisibleChunks = new Array2D <Chunk>(NumberOfChunksWide, NumberOfChunksHigh); }