Example #1
0
        public ChunkCache(Map map, int cacheRadius)
        {
            this.Map = map;

            this.Radius = cacheRadius;

            this.savedChunkData = new Dictionary<ChunkCoordinate, CacheData>();

            tempChunk = new Chunk(map);

            LoadStartingData();
        }
Example #2
0
 public void GiveBlankChunk(Map map)
 {
     lock (this)
     {
         Chunk = new Chunk(map);
     }
 }
Example #3
0
        /// <summary>
        /// Part of the helper thread method.  Locates the appropriate
        /// piece of CacheData, fills it with good data, then marks it
        /// as prepared.
        /// </summary>
        /// <param name="loadChunkX"></param>
        /// <param name="loadChunkZ"></param>
        private void MakeAndCacheChunk(int loadChunkX, int loadChunkZ)
        {
            CacheData cacheData;

            int oldXMin, oldZMin;

            lock (CacheLock)
            {
                if (HasSavedChunk(loadChunkX, loadChunkZ))
                    return;

                cacheData = this[loadChunkX, loadChunkZ];

                oldXMin = XMin;
                oldZMin = ZMin;
            }

            if (cacheData.Chunk == null)
                cacheData.GiveBlankChunk(Map);

            tempChunk.OverwriteChunkDataWith(loadChunkX, loadChunkZ);

            Chunk swap = tempChunk;
            tempChunk = cacheData.Chunk;
            cacheData.Chunk = swap;

            lock (CacheLock)
            {
                if (oldXMin == XMin && oldZMin == ZMin)
                    cacheData.CleanAndValidate();
            }

            RecalculateNeighborGeometry(loadChunkX, loadChunkZ);
        }
Example #4
0
        private void MakeOcclusionTags(int x, int y, int z,
            out bool includeFrontFace, out bool includeBackFace,
            out bool includeTopFace, out bool includeBottomFace,
            out bool includeLeftFace, out bool includeRightFace,
            Chunk leftChunk, Chunk rightChunk, Chunk forwardChunk, Chunk backwardChunk)
        {
            if (x == 0)
            {
                if (leftChunk != null)
                    includeLeftFace = !BlockHandler.IsFullAndOpaqueToTheRight(leftChunk[GameConstants.CHUNK_X_WIDTH - 1, y, z]);
                else
                    includeLeftFace = true;
            }
            else if (BlockHandler.IsFullAndOpaqueToTheRight(this[x - 1, y, z]))
                includeLeftFace = false;
            else
                includeLeftFace = true;

            if (x + 1 == GameConstants.CHUNK_X_WIDTH)
            {
                if (rightChunk != null)
                    includeRightFace = !BlockHandler.IsFullAndOpaqueToTheLeft(rightChunk[0, y, z]);
                else
                    includeRightFace = true;
            }
            else if (BlockHandler.IsFullAndOpaqueToTheLeft(this[x + 1, y, z]))
                includeRightFace = false;
            else
                includeRightFace = true;

            if (y == 0)
                includeBottomFace = false;
            else if (BlockHandler.IsFullAndOpaqueToTheTop(this[x, y - 1, z]))
                includeBottomFace = false;
            else
                includeBottomFace = true;

            if (y + 1 == GameConstants.CHUNK_Y_HEIGHT)
                includeTopFace = true;
            else if (BlockHandler.IsFullAndOpaqueToTheBottom(this[x, y + 1, z]))
                includeTopFace = false;
            else
                includeTopFace = true;

            if (z == 0)
            {
                if (forwardChunk != null)
                    includeFrontFace = !BlockHandler.IsFullAndOpaqueToTheBack(forwardChunk[x, y, GameConstants.CHUNK_Z_LENGTH - 1]);
                else
                    includeFrontFace = true;
            }
            else if (BlockHandler.IsFullAndOpaqueToTheBack(this[x, y, z - 1]))
                includeFrontFace = false;
            else
                includeFrontFace = true;

            if (z + 1 == GameConstants.CHUNK_Z_LENGTH)
            {
                if (backwardChunk != null)
                    includeBackFace = !BlockHandler.IsFullAndOpaqueToTheFront(backwardChunk[x, y, 0]);
                else
                    includeBackFace = true;
            }
            else if (BlockHandler.IsFullAndOpaqueToTheFront(this[x, y, z + 1]))
                includeBackFace = false;
            else
                includeBackFace = true;
        }
Example #5
0
 private void LoadNeighborChunks(out Chunk leftChunk, out Chunk rightChunk,
     out Chunk forwardChunk, out Chunk backwardChunk)
 {
     leftChunk = Map.GetChunk(chunkX - 1, chunkZ, false, false);
     rightChunk = Map.GetChunk(chunkX + 1, chunkZ, false, false);
     forwardChunk = Map.GetChunk(chunkX, chunkZ - 1, false, false);
     backwardChunk = Map.GetChunk(chunkX, chunkZ + 1, false, false);
 }