Exemplo n.º 1
0
 public ChunkDataContext(IChunkData _parent, IVoxelModel _model, int _count, bool _async)
 {
     parent    = _parent;
     model     = _model;
     faceCount = _count;
     async     = _async;
 }
Exemplo n.º 2
0
        private bool TryGetRemovalNode(Vector3Int localPosition, IChunkData chunkData, ChunkNeighbourhood neighbourhood, out RemovalNode node)
        {
            var chunkId = chunkData.ChunkID;

            AdjustForBounds(ref localPosition, ref chunkId, chunkDimensions);
            if (chunkId.Equals(chunkData.ChunkID))
            {
                node = new RemovalNode()
                {
                    localPosition = localPosition,
                    chunkData     = chunkData,
                    lv            = chunkData.GetLight(localPosition)
                };
                return(true);
            }
            else if (ChunkWritable(chunkId, neighbourhood))
            {
                var newChunkData = neighbourhood.GetChunkData(chunkId);
                node = new RemovalNode()
                {
                    localPosition = localPosition,
                    chunkData     = newChunkData,
                    lv            = newChunkData.GetLight(localPosition)
                };
                return(true);
            }
            //Otherwise, this position is not valid
            node = default;
            return(false);
        }
        public bool TryGetStoredDataForChunk(Vector3Int chunkID, out IChunkData storedData)
        {
            if (SaveUtils.DoSave)
            {
                Profiler.BeginSample("LoadingSavedChunkData");
                if (serialiser.TryLoad(chunkID.ToString(), out var data))
                {
                    storedData = InitialiseChunkDataFromSaved((ChunkSaveData)data, chunkID);
                    storedData.FullyGenerated = false;//This prevents saving it again if nothing changes.
                    return(true);
                }
                Profiler.EndSample();
            }
            else
            {
                if (ModifiedChunkData.TryGetValue(chunkID, out var data))
                {
                    storedData = data;
                    return(true);
                }
            }

            storedData = null;
            return(false);
        }
 //Add or replace modified data for the given chunk
 public void StoreModifiedChunkData(Vector3Int chunkID, IChunkData data)
 {
     if (SaveUtils.DoSave)
     {
         //Save to file
         serialiser.Save(data.GetSaveData(), data.ChunkID.ToString());
     }
     else
     {
         //Store in RAM
         ModifiedChunkData[chunkID] = data;
     }
 }
Exemplo n.º 5
0
        public void OnChunksGeneratedSunlightTriple(int[] order)
        {
            Vector3Int[] ids = new Vector3Int[] {
                Vector3Int.zero,
                Vector3Int.down,
                Vector3Int.down * 2
            };

            IChunkData[] chunkDatas = new IChunkData[]
            {
                GetMockChunkData(ids[0]),
                GetMockChunkData(ids[1]),
                GetMockChunkData(ids[2]),
            };

            //Ground level is at 0, so the lower chunk will at first think it has no sunlight
            heightMapYValue = 0;

            foreach (var index in order)
            {
                RunLightingGeneration(ids[index]);
                lightManager.Update();
            }

            //var bottomNeigh = new ChunkNeighbourhood(lowChunkData, GetMockChunkData);
            //Debug.Log("TopSlice");
            //PrintSlice(bottomNeigh, 15,false);
            //Debug.Log("BottomSlice");
            //PrintSlice(bottomNeigh, 0, false);

            var expectedLv = new LightValue()
            {
                Sun = maxIntensity, Dynamic = 0
            };

            for (int z = 0; z < chunkDimensions.z; z++)
            {
                for (int y = 0; y < chunkDimensions.y; y++)
                {
                    for (int x = 0; x < chunkDimensions.x; x++)
                    {
                        for (int i = 0; i < ids.Length; i++)
                        {
                            Assert.AreEqual(expectedLv, chunkDatas[i].GetLight(x, y, z),
                                            $"Light value not as expected for position {x},{y},{z} in chunk {i}");
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private bool TryGetPropagateNode(Vector3Int localPosition, IChunkData chunkData, ChunkNeighbourhood neighbourhood, out PropagationNode node)
        {
            Profiler.BeginSample("TryGetPropagateNode");
            var chunkId = chunkData.ChunkID;

            Profiler.BeginSample("AdjustForBounds");
            AdjustForBounds(ref localPosition, ref chunkId, chunkDimensions);
            Profiler.EndSample();
            if (chunkId.Equals(chunkData.ChunkID))
            {
                node = new PropagationNode()
                {
                    localPosition = localPosition,
                    chunkData     = chunkData,
                    worldPos      = chunkManager.ChunkToWorldPosition(chunkId).ToInt() + localPosition
                };
                Profiler.EndSample();
                return(true);
            }
            else
            {
                Profiler.BeginSample("ChunkWritable");
                var writable = ChunkWritable(chunkId, neighbourhood);
                Profiler.EndSample();
                if (writable)
                {
                    node = new PropagationNode()
                    {
                        localPosition = localPosition,
                        chunkData     = neighbourhood.GetChunkData(chunkId),
                        worldPos      = chunkManager.ChunkToWorldPosition(chunkId).ToInt() + localPosition
                    };
                    Profiler.EndSample();
                    return(true);
                }
            }
            //Otherwise, this position is not valid
            node = default;
            Profiler.EndSample();
            return(false);
        }
Exemplo n.º 7
0
        public ChunkNeighbourhood(Vector3Int center, Func <Vector3Int, IChunkData> getData)
        {
            Profiler.BeginSample("CreateChunkNeighbourhood");
            data = new Dictionary <Vector3Int, IChunkData>();

            this.center  = getData(center);
            this.getData = getData;

            //Func<Vector3Int, IEnumerable<Vector3Int>> neighbourIdGenerator = Utils.Helpers.GetNeighboursDirectOnly;

            //if (includeDiagonals)
            //{
            //    neighbourIdGenerator = Utils.Helpers.GetNeighboursIncludingDiagonal;
            //}

            //this.center = getData(center);

            //foreach (var item in neighbourIdGenerator(center))
            //{
            //    data.Add(item, getData(item));
            //}
            Profiler.EndSample();
        }
Exemplo n.º 8
0
 public bool TryGetStoredDataForChunk(Vector3Int chunkID, out IChunkData storedData)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 public void StoreModifiedChunkData(Vector3Int chunkID, IChunkData data)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public Mesh CreateMesh(IChunkData chunk)
 {
     return(new Mesh());
 }
Exemplo n.º 11
0
 public void addData(IChunkData data)
 {
     dataList.Add(data);
 }
Exemplo n.º 12
0
 public ChunkNeighbourhood(IChunkData center, Func <Vector3Int, IChunkData> getData)
 {
     data         = new Dictionary <Vector3Int, IChunkData>();
     this.center  = center;
     this.getData = getData;
 }
Exemplo n.º 13
0
 internal CompressedChunkHeader(IChunkData chunkData)
 {
     IsCompressed        = chunkData is CompressedChunkData;
     CompressedChunkSize = (ushort)(chunkData.Size + 2);
 }
Exemplo n.º 14
0
 public RestrictedChunkData(IChunkData realData, bool allowModifyVoxels = false, bool allowModifyLight = false)
 {
     this.realData          = realData;
     this.allowModifyVoxels = allowModifyVoxels;
     this.allowModifyLight  = allowModifyLight;
 }