Example #1
0
        /// <summary>
        /// target content will be added or update it's possition if already added
        /// </summary>
        public static void Process(IChunkContent processedContent)
        {
            Bounds2DInt processedContentBounds = PathFinder.ToChunkPosition(processedContent.chunkContentBounds);

            ChunkContentMetaData metaData;

            if (content.TryGetValue(processedContent, out metaData))
            {
                Bounds2DInt currentContentBounds = metaData.lastUpdate;

                if (currentContentBounds == processedContentBounds)
                {
                    return; //nothing to change since it occupy same space
                }
                GetChunkRemoveContent(currentContentBounds, processedContent);
                IncludeBounds(processedContentBounds);
                GetChunkAddContent(processedContentBounds, processedContent);
                content[processedContent] = new ChunkContentMetaData(processedContentBounds);
            }
            else
            {
                if (init == false)
                {
                    beforeInit.Add(processedContent);
                    return;
                }

                IncludeBounds(processedContentBounds);

                GetChunkAddContent(processedContentBounds, processedContent);
                content[processedContent] = new ChunkContentMetaData(processedContentBounds);
            }
        }
Example #2
0
 public static void Clear()
 {
     mapSpace = Bounds2DInt.zero;
     map      = null;
     beforeInit.Clear();
     content.Clear();
     init = false;
 }
Example #3
0
 private static void GetChunkRemoveContent(Bounds2DInt bounds, IChunkContent content)
 {
     for (int x = bounds.minX; x < bounds.maxX + 1; x++)
     {
         for (int z = bounds.minY; z < bounds.maxY + 1; z++)
         {
             GetChunkContent(x, z).Remove(content);
         }
     }
 }
Example #4
0
        private static void IncludeBounds(int startX, int startZ, int endX, int endZ)
        {
            Bounds2DInt boundsPlusOne = new Bounds2DInt(startX, startZ, endX + 1, endZ + 1);

            if (content.Count == 0)
            {
                mapSpace = boundsPlusOne;
                map      = new ChunkContent[boundsPlusOne.sizeX, boundsPlusOne.sizeZ];
            }
            else
            {
                ResizeMap(Bounds2DInt.GetIncluded(mapSpace, boundsPlusOne));
            }
        }
Example #5
0
        private static void ResizeMap(Bounds2DInt newMapSpace)
        {
            if (newMapSpace.minX > mapSpace.minX ||
                newMapSpace.minY > mapSpace.minY ||
                newMapSpace.maxX < mapSpace.maxX ||
                newMapSpace.maxY < mapSpace.maxY)
            {
                throw new ArgumentException(
                          String.Format("Sizes of content map can only be expanded. Old: x {0}, New: x {1}", mapSpace, newMapSpace));
            }

            if (mapSpace == newMapSpace)
            {
                return;
            }

            int offsetX  = mapSpace.minX - newMapSpace.minX;
            int offsetZ  = mapSpace.minY - newMapSpace.minY;
            int newSizeX = newMapSpace.sizeX;
            int newSizeZ = newMapSpace.sizeZ;

            ChunkContent[,] newMap = new ChunkContent[newSizeX, newSizeZ];

            for (int x = 0; x < mapSpace.sizeX; x++)
            {
                for (int z = 0; z < mapSpace.sizeZ; z++)
                {
                    newMap[x + offsetX, z + offsetZ] = map[x, z];
                }
            }

            //Debug.Log("map resized to " + newMapSpace);

            mapSpace = newMapSpace;
            map      = newMap;
        }
Example #6
0
        /// <summary>
        /// target content will be added or update it's possition if already added
        /// </summary>
        public static void Process <T>(List <T> processedContentList) where T : IChunkContent
        {
            //Debug.Log(processedContentList.Count);

            if (processedContentList == null || processedContentList.Count == 0)
            {
                return;
            }

            Bounds2DInt first = PathFinder.ToChunkPosition(processedContentList[0].chunkContentBounds);

            int minX = first.minX,
                minZ = first.minY,
                maxX = first.maxX,
                maxZ = first.maxY;

            Bounds2DInt[] array = new Bounds2DInt[processedContentList.Count];
            array[0] = first;

            for (int i = 1; i < processedContentList.Count; i++)
            {
                Bounds2DInt curRange = PathFinder.ToChunkPosition(processedContentList[i].chunkContentBounds);
                array[i] = curRange;
                if (minX > curRange.minX)
                {
                    minX = curRange.minX;
                }
                if (minZ > curRange.minY)
                {
                    minZ = curRange.minY;
                }
                if (maxX < curRange.maxX)
                {
                    maxX = curRange.maxX;
                }
                if (maxZ < curRange.maxY)
                {
                    maxZ = curRange.maxY;
                }
            }

            IncludeBounds(new Bounds2DInt(minX, minZ, maxX, maxZ));

            for (int i = 0; i < processedContentList.Count; i++)
            {
                Bounds2DInt          processedContentBounds = array[i];
                IChunkContent        processedContent       = processedContentList[i];
                ChunkContentMetaData metaData;
                if (content.TryGetValue(processedContent, out metaData))
                {
                    Bounds2DInt currentContentBounds = metaData.lastUpdate;

                    if (currentContentBounds == processedContentBounds)
                    {
                        return; //nothing to change since it occupy same space
                    }
                    GetChunkRemoveContent(currentContentBounds, processedContent);
                    GetChunkAddContent(processedContentBounds, processedContent);
                    content[processedContent] = new ChunkContentMetaData(processedContentBounds);
                }
                else
                {
                    if (init == false)
                    {
                        beforeInit.Add(processedContent);
                        return;
                    }

                    GetChunkAddContent(processedContentBounds, processedContent);
                    content[processedContent] = new ChunkContentMetaData(processedContentBounds);
                }
            }

            //SceneDebug();
        }
Example #7
0
 public ChunkContentMetaData(Bounds2DInt lastUpdate)
 {
     this.lastUpdate = lastUpdate;
 }
Example #8
0
 private static void IncludeBounds(Bounds2DInt bounds)
 {
     IncludeBounds(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY);
 }