Пример #1
0
        public static void Calculate(IntVector2 viewerLocation, int visionRange, Grid2D<bool> visibilityMap, IntSize2 mapSize,
			Func<IntVector2, bool> blockerDelegate)
        {
            visibilityMap.Clear();

            if (blockerDelegate(viewerLocation) == true)
                return;

            for (int y = -visionRange; y <= visionRange; ++y)
            {
                for (int x = -visionRange; x <= visionRange; ++x)
                {
                    var dst = viewerLocation + new IntVector2(x, y);

                    if (mapSize.Contains(dst) == false)
                    {
                        visibilityMap[x, y] = false;
                        continue;
                    }

                    bool vis = FindLos(viewerLocation, dst, blockerDelegate);
                    visibilityMap[x, y] = vis;
                }
            }
        }
Пример #2
0
        public void Resize_NewCellsHaveDefaultValue()
        {
            var startWidth  = 10;
            var startHeight = 10;
            var defaultVal  = 5;
            var grid        = new Grid2D <int>(startWidth, startHeight, defaultVal);

            grid.Clear(10);

            grid.Resize(20, 20);

            for (var x = 0; x < grid.Width; x++)
            {
                for (var y = 0; y < grid.Height; y++)
                {
                    if (x >= startWidth || y >= startHeight)
                    {
                        Assert.AreEqual(defaultVal, grid[x, y], "({0},{1})", x, y);
                    }
                    else
                    {
                        Assert.AreEqual(10, grid[x, y], "({0},{1})", x, y);
                    }
                }
            }
        }
Пример #3
0
        public void Clear_Default_AllCleared()
        {
            var grid = new Grid2D <int>(100, 50, 33);

            grid.Clear(1);

            grid.Clear();

            for (var x = 0; x < grid.Width; x++)
            {
                for (var y = 0; y < grid.Height; y++)
                {
                    Assert.AreEqual(33, grid[x, y], "({0},{1})", x, y);
                }
            }
        }
Пример #4
0
		public static void Calculate(IntVector2 viewerLocation, int visionRange, Grid2D<bool> visibilityMap, IntSize2 mapSize,
			Func<IntVector2, bool> blockerDelegate)
		{
			visibilityMap.Clear();

			if (blockerDelegate(viewerLocation) == true)
				return;

			visibilityMap[0, 0] = true;

			SCRData data = new SCRData()
			{
				ViewerLocation = viewerLocation,
				VisionRange = visionRange,
				VisionRangeSquared = (visionRange + 1) * (visionRange + 1),	// +1 to get a bit bigger view area
				VisibilityMap = visibilityMap,
				MapSize = mapSize,
				BlockerDelegate = blockerDelegate,
			};

			for (int octant = 0; octant < 8; ++octant)
				Calculate(ref data, 1, octant, 0.0, 1.0, 1);
		}
Пример #5
0
        public static void Calculate(IntVector2 viewerLocation, int visionRange, Grid2D<bool> visibilityMap, IntSize2 mapSize,
			Func<IntVector2, bool> blockerDelegate)
        {
            visibilityMap.Clear();

            if (blockerDelegate(viewerLocation) == true)
                return;

            var g = new IntGrid2(new IntVector2(), mapSize);
            g = g.Offset(-viewerLocation.X, -viewerLocation.Y);
            var vr = new IntVector2(visionRange, visionRange);
            g = g.Intersect(new IntGrid2(vr, -vr));

            int visionRangeSquared = (visionRange + 1) * (visionRange + 1);	// +1 to get a bit bigger view area

            foreach (var dst in g.Range())
            {
                if (dst.X * dst.X + dst.Y * dst.Y > visionRangeSquared)
                    continue;

                bool vis = FindLos(viewerLocation, dst, blockerDelegate);
                visibilityMap[dst] = vis;
            }
        }