예제 #1
0
 /*
  * Inform chunks arround the current chunk what their state in the next fixed update is to be.
  * (State is purely a function of proximity to the current occuppied chunk(s))
  */
 private void QueueNextStateForChunks(ChunkIndex currentChunk)
 {
     for (int x = -3; x <= 3; x++)
     {
         for (int y = -3; y <= 3; y++)
         {
             Chunk chunk    = Chunks.GetChunk(currentChunk.Add(x, y));
             int   distance = Mathf.Max(Mathf.Abs(x), Mathf.Abs(y));
             if (distance == 0)
             {
                 chunk.NextState = ChunkState.Occupied;
             }
             else if (distance == 1)
             {
                 chunk.NextState = ChunkState.Live;
             }
             else if (distance == 2)
             {
                 chunk.NextState = ChunkState.SpawningGrounds;
             }
             else if (distance == 3)
             {
                 chunk.NextState = ChunkState.Inactive;
             }
         }
     }
 }
예제 #2
0
        public void FixedUpdate()
        {
            if (!Active)
            {
                return;
            }

            UpdateWorldInitializers();

            ChunkIndex currentChunk = GetChunkIndex(PlayerManager.GetPosition());

            QueueNextStateForChunks(currentChunk);

            LiveChunks.Clear();
            bool allLiveChunksLoaded = true;

            for (int x = -3; x <= 3; x++)
            {
                for (int y = -3; y <= 3; y++)
                {
                    Chunk chunk = Chunks.GetChunk(currentChunk.Add(x, y));

                    TransitionChunkState(chunk);

                    if (chunk.State == ChunkState.Occupied || chunk.State == ChunkState.Live)
                    {
                        LiveChunks.Add(chunk);
                        allLiveChunksLoaded &= chunk.FixedUpdate();
                    }
                }
            }
            if (allLiveChunksLoaded)
            {
                GameManager.Singleton.TakeInput(GameInputType.WorldLoaded);
            }
        }