public void SetPriorityChunk(PriorityChunk c)
 {
     lock (_priorityCaches)
     {
         c.chunk    = null;
         c.Priority = 0;
         _priorityCaches.Enqueue(c);
     }
 }
Beispiel #2
0
 public void EnGeneratorQueue(PriorityChunk priorityChunk)
 {
     lock (_selfGeneratorQueue)
     {
         if (_selfGeneratorQueue.Count > _selfGeneratorQueue.MaxSize)
         {
             return;
         }
         _selfGeneratorQueue.Enqueue(priorityChunk, priorityChunk.Priority);
     }
 }
 private PriorityChunk DeLoadQueue()
 {
     lock (_selfLoadQueue)
     {
         if (_selfLoadQueue.Count > 0)
         {
             PriorityChunk c = _selfLoadQueue.Dequeue();
             return(c);
         }
         return(null);
     }
 }
 public PriorityChunk GetPriorityChunk(Chunk chunk)
 {
     lock (_priorityCaches)
     {
         if (_priorityCaches.Count > 0)
         {
             PriorityChunk c = _priorityCaches.Dequeue();
             c.chunk = chunk;
             return(c);
         }
         return(new PriorityChunk(chunk));
     }
 }
Beispiel #5
0
 private Chunk DeGeneratorQueue()
 {
     lock (_selfGeneratorQueue)
     {
         if (_selfGeneratorQueue.Count > 0)
         {
             PriorityChunk c     = _selfGeneratorQueue.Dequeue();
             Chunk         chunk = c.chunk;
             _manager.SetPriorityChunk(c);
             return(chunk);
         }
         return(null);
     }
 }
        //单机的持续化工作
        private void SinglePersistanceWorker()
        {
            //单机
            //从本地数据加载
            PriorityChunk loadPriorityChunk = DeLoadQueue();

            if (loadPriorityChunk != null)
            {
                WorldPos pos = loadPriorityChunk.chunk.worldPos;
                if (World.world.GetChunk(pos.x, pos.y, pos.z) == null)
                {
                    return;
                }
                loadPriorityChunk.chunk.InitData();
                if (WorldConfig.Instance.loadInMap)
                {
                    WorldPersistanceManager.Instance.LoadChunk(loadPriorityChunk.chunk);
                }
                //这里进入产生线程
                _manager.generatorWorker.EnGeneratorQueue(loadPriorityChunk);
            }
            //保存到本地数据
            Chunk saveChunk = DeSaveQueue();

            if (saveChunk != null)
            {
                if (saveChunk.isUpdate)
                {
                    if (WorldConfig.Instance.saveBlock)
                    {
                        WorldPersistanceManager.Instance.SaveChunk(saveChunk);
                        saveChunk.isUpdate = false;
                    }
                }
                _manager.EnqueueWaitRemove(saveChunk);
            }
            RefreshChunkArea refreshChunkArea = DeRefreshQueue();

            if (refreshChunkArea != null)
            {
                _manager.generatorWorker.EnRefreshQueue(refreshChunkArea);
            }
        }