示例#1
0
 private IEnumerator InitializeCoroutine()
 {
     do
     {
         var chunkKey = WorldDataChunk.GetKey(Position);
         if (ChunkCache.IsChunkGenerated(chunkKey))
         {
             previousPositionChunkKey = chunkKey;
             //WorldManager.Instance.ChunkIsReady = true; IsReady
             break;
         }
         yield return(null);
     } while (true);
 }
示例#2
0
        internal static IList <string> GetChunkKeysInRadius(string chunkKeyAtOrigin, int radius)
        {
            var chunkAtOrigin = ChunkCache.GetGeneratedChunk(chunkKeyAtOrigin);
            var result        = new List <string>();

            for (var zCircle = -radius; zCircle <= radius; zCircle++)
            {
                for (var xCircle = -radius; xCircle <= radius; xCircle++)
                {
                    if (xCircle * xCircle + zCircle * zCircle < radius * radius)
                    {
                        result.Add(WorldDataChunk.GetKey(chunkAtOrigin.X + xCircle, chunkAtOrigin.Z + zCircle));
                    }
                }
            }

            return(result);
        }
示例#3
0
        public static void Update(Vector3 worldPosition, int radius)
        {
            var chunkAtOrigin = ChunkCache.GetGeneratedChunk(worldPosition);

            int chunkAtOriginX;
            int chunkAtOriginZ;

            if (chunkAtOrigin == null)
            {
                chunkAtOriginX = 0;
                chunkAtOriginZ = 0;
            }
            else
            {
                chunkAtOriginX = chunkAtOrigin.X;
                chunkAtOriginZ = chunkAtOrigin.Z;
            }

            var rSquared = radius * radius;

            for (var deltaZ = -radius; deltaZ <= radius; ++deltaZ)
            {
                var zSquared = rSquared - (deltaZ * deltaZ);

                for (var deltaX = -radius; deltaX <= radius; ++deltaX)
                {
                    var chunkX         = chunkAtOriginX + deltaX;
                    var chunkZ         = chunkAtOriginZ + deltaZ;
                    var existingChunk  = ChunkCache.GetGeneratedChunk(chunkX, chunkZ);
                    var isInsideRadius = deltaX * deltaX < zSquared;

                    if (isInsideRadius)
                    {
                        if (existingChunk == null)
                        {
                            if (ChunkCanBeAdded(chunkX, chunkZ))
                            {
                                AddNewChunk(new WorldDataChunk(chunkX, chunkZ));
                            }
                        }
                        else
                        {
                            // already there... nothing to do
                        }
                    }
                    else
                    {
                        if (existingChunk == null)
                        {
                            // not there anyways... nothing to do
                        }
                        else
                        {
                            if (ChunkCanBeRemoved(chunkX, chunkZ))
                            {
                                RemoveChunk(chunkX, chunkZ);
                            }
                        }
                    }
                }
            }
        }
示例#4
0
 public static Vector3 GetTerrainSurfaceWorldCoordinates(float x, float z)
 {
     return(new Vector3(x, ChunkCache.GetElevation(x, z), z));
 }
示例#5
0
 public static Vector3 GetTerrainSurfaceWorldCoordinates(Vector3 vector)
 {
     return(new Vector3(vector.x, ChunkCache.GetElevation(vector.x, vector.z), vector.z));
 }
示例#6
0
 internal WorldDataChunk GetGeneratedNeighbor(int deltaX, int deltaZ)
 {
     return(ChunkCache.GetGeneratedChunk(X + deltaX, Z + deltaZ));
 }