Beispiel #1
0
        public void SetMaxSize(IntSize2 size)
        {
            int len = size.Width * size.Height;

            if (len == this.Grid.Length)
            {
                return;
            }

            this.Grid    = new T[size.Width * size.Height];
            this.Invalid = true;
        }
Beispiel #2
0
        void Scale(IntSize2 oldSize, IntSize2 newSize)
        {
            if (newSize.Width <= oldSize.Width && newSize.Height <= oldSize.Height)
            {
                var xdiff = oldSize.Width - newSize.Width;
                var ydiff = oldSize.Height - newSize.Height;

                xdiff /= 2;
                ydiff /= 2;

                var grid = this.Grid;

                for (int y = 0; y < newSize.Height; ++y)
                {
                    Array.Copy(grid, (y + ydiff) * oldSize.Width + xdiff,
                               grid, y * newSize.Width + 0, newSize.Width);
                }
            }
            else if (newSize.Width >= oldSize.Width && newSize.Height >= oldSize.Height)
            {
                var xdiff = oldSize.Width - newSize.Width;
                var ydiff = oldSize.Height - newSize.Height;

                xdiff /= -2;
                ydiff /= -2;

                var grid = this.Grid;

                for (int y = oldSize.Height - 1; y >= 0; --y)
                {
                    Array.Copy(grid, y * oldSize.Width + 0,
                               grid, (y + ydiff) * newSize.Width + xdiff, oldSize.Width);
                }

                // clear top rows
                Array.Clear(grid, 0, ydiff * newSize.Width);

                // clear bottom rows
                Array.Clear(grid, (newSize.Height - ydiff) * newSize.Width, ydiff * newSize.Width);

                // clear the edges
                for (int y = ydiff; y < newSize.Height - ydiff; ++y)
                {
                    Array.Clear(grid, y * newSize.Width, xdiff);
                    Array.Clear(grid, y * newSize.Width + newSize.Width - xdiff, xdiff);
                }
            }
            else
            {
                this.Invalid = true;
            }
        }
Beispiel #3
0
        public void SetSize(IntSize2 size)
        {
            if (this.Size == size)
            {
                return;
            }

            var oldSize = this.Size;

            int len = size.Width * size.Height;

            if (len > this.Grid.Length)
            {
                throw new Exception();
            }

            this.Size = size;

            Scale(oldSize, size);
        }
Beispiel #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);
            }
        }
Beispiel #5
0
 public IntGrid2Z(IntVector2 point, IntSize2 size, int z)
     : this(point.X, point.Y, size.Width, size.Height, z)
 {
 }
Beispiel #6
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;
                }
            }
        }
Beispiel #7
0
 public ArrayGrid2D(IntSize2 size)
     : this(size.Width, size.Height)
 {
 }
Beispiel #8
0
 public IntGrid2(IntVector2 point, IntSize2 size)
     : this(point.X, point.Y, size.Width, size.Height)
 {
 }
Beispiel #9
0
 public IntSize3(IntSize2 size, int depth)
 {
     m_width  = size.Width;
     m_height = size.Height;
     m_depth  = depth;
 }
Beispiel #10
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;
            }
        }