/// <summary>
 /// Serialize a chunk.
 /// </summary>
 /// <param name="chunk">The chunk to serialize.</param>
 /// <param name="chunkIndex">The chunk index.</param>
 public void SerialiseChunk(Chunk chunk, Position chunkIndex)
 {
     // NOTE: This should occur in a seperate thread, since terrain serialization isn't high priority.
     // However, care should be taken to consider the situation when a terrain is being serialized in another thread
     // and then a new deserialization request comes in for that chunk. In this case the deserialization thread
     // should block
 }
        /// <summary>
        /// Handles the on-touch behaviour for the component.
        /// </summary>
        /// <param name="hitPoint">The point at which the component was touched in world coordinates.</param>
        public override void ProcessTouch(Vector3 hitPoint)
        {
            var position = new Position((int)Math.Floor(hitPoint.x), (int)Math.Floor(hitPoint.y));
            var offset = new Vector2(Math.Abs(hitPoint.x - position.X), Math.Abs(hitPoint.y - position.Y));

            // Dig at the touched point
            this.cTerrain.Mutator.Dig(position, offset);
        }
        /// <summary>
        /// Attempt to deserialise a chunk.
        /// </summary>
        /// <param name="chunkIndex">The chunk index.</param>
        /// <param name="chunk">The deserialised chunk.</param>
        /// <returns>True if chunk was deserialised; False if a serialization file does not exist for chunk.</returns>
        public bool TryDeserialiseChunk(Position chunkIndex, out Chunk chunk)
        {
            string chunkFile;
            if (!this.chunkFiles.TryGetValue(chunkIndex, out chunkFile))
            {
                // A chunk file doesn't exist for the given chunk
                chunk = null;
                return false;
            }

            // TODO: Deserialize the file
            throw new NotImplementedException("Chunk deserialization is not yet implemented.");
        }
示例#4
0
        /// <summary>
        /// Run a test for the marching cubes algorithm.
        /// </summary>
        private static void TestMarchingCubes()
        {
            var terrain = new VoxelTerrain();
            var chunkIndex = new Position(0, 0);
            var noiseGenerator = new NoiseGenerator(1, 16, 0.001f, 0.25f);
            var voxelGenerator = new ChunkVoxelGenerator(noiseGenerator, 0, 50);

            // Load the chunk
            var chunkLoader = new ChunkLoader(voxelGenerator);
            chunkLoader.LoadChunk(terrain, chunkIndex);

            // Generate the mesh
            var meshGenerator = new MarchingCubesGenerator(terrain, 7);
            meshGenerator.UpdateChunk(chunkIndex);
        }
 /// <summary>
 /// Gets the chunk component with the given index.
 /// </summary>
 /// <param name="chunkIndex">The chunk index.</param>
 /// <returns>The chunk component; Null if it does not exist.</returns>
 private ChunkComponent GetChunkComponent(Position chunkIndex)
 {
     Transform chunkTransform = this.transform.FindChild(TerrainLoaderComponent.GetChunkLabel(chunkIndex));
     return chunkTransform != null ? chunkTransform.GetComponent<ChunkComponent>() : null;
 }
 /// <summary>
 /// Check if the chunk at the given index exists and if so update the dictionary to indicate that the chunk's
 /// border needs to be regenerated.
 /// </summary>
 /// <param name="chunkIndex">The chunk index.</param>
 /// <param name="neighbour">The border.</param>
 /// <param name="borders">The chunk borders that need to have their mesh re-generated.</param>
 private void CheckNeighbour(
     Position chunkIndex,
     ChunkNeighbour neighbour,
     Dictionary<Position, ChunkNeighbour> borders)
 {
     if (this.cTerrain.Terrain.Chunks.ContainsKey(chunkIndex))
     {
         if (borders.ContainsKey(chunkIndex))
         {
             borders[chunkIndex] |= neighbour;
         }
         else
         {
             borders.Add(chunkIndex, neighbour);
         }
     }
 }
 /// <summary>
 /// Gets the label for the given chunk index.
 /// </summary>
 /// <param name="chunkIndex">The chunk index.</param>
 /// <returns>The chunk label.</returns>
 private static string GetChunkLabel(Position chunkIndex)
 {
     return string.Format("Chunk[{0},{1}]", chunkIndex.X, chunkIndex.Y);
 }