void gatherBlockPositionsForDeactivate(Chunk chunk) {
   try {
     deactivateBlocksQueue.put(createBatchBlockEventMappings(chunk));
   } catch (InterruptedException e) {
     logger.error("Failed to queue deactivation of blocks for {}", chunk.getPosition());
   }
 }
  @Override
  public void purgeWorld() {
    ChunkMonitor.fireChunkProviderDisposed(this);
    pipeline.shutdown();
    unloadRequestTaskMaster.shutdown(new ChunkUnloadRequest(), true);
    lightMerger.shutdown();

    for (Chunk chunk : nearCache.values()) {
      if (chunk.isReady()) {
        worldEntity.send(new BeforeChunkUnload(chunk.getPosition()));
        storageManager.deactivateChunk(chunk);
        chunk.dispose();
      }
    }
    nearCache.clear();
    readyChunks.clear();
    sortedReadyChunks.clear();
    storageManager.deleteWorld();
    preparingChunks.clear();
    worldEntity.send(new PurgeWorldEvent());

    pipeline = new ChunkGenerationPipeline(new ChunkTaskRelevanceComparator());
    unloadRequestTaskMaster = TaskMaster.createFIFOTaskMaster("Chunk-Unloader", 8);
    lightMerger = new LightMerger<>(this);
    lightMerger.restart();
    ChunkMonitor.fireChunkProviderInitialized(this);

    for (ChunkRelevanceRegion chunkRelevanceRegion : regions.values()) {
      for (Vector3i pos : chunkRelevanceRegion.getCurrentRegion()) {
        createOrLoadChunk(pos);
      }
      chunkRelevanceRegion.setUpToDate();
    }
  }
 private void updateAdjacentChunksReadyFieldOfAdjChunks(Chunk chunkInCenter) {
   Vector3i centerChunkPos = chunkInCenter.getPosition();
   for (Side side : Side.values()) {
     Vector3i adjChunkPos = side.getAdjacentPos(centerChunkPos);
     Chunk adjChunk = nearCache.get(adjChunkPos);
     if (adjChunk != null) {
       updateAdjacentChunksReadyFieldOf(adjChunk);
     }
   }
 }
  @Override
  public void deactivateChunk(Chunk chunk) {
    Collection<EntityRef> entitiesOfChunk = getEntitiesOfChunk(chunk);
    ChunkImpl chunkImpl = (ChunkImpl) chunk; // storage manager only works with ChunkImpl
    unloadedAndUnsavedChunkMap.put(
        chunk.getPosition(),
        new CompressedChunkBuilder(getEntityManager(), chunkImpl, entitiesOfChunk, true));

    entitiesOfChunk.forEach(this::deactivateOrDestroyEntityRecursive);
  }
Esempio n. 5
0
 private static synchronized ChunkMonitorEntry registerChunk(Chunk chunk) {
   Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null");
   final Vector3i pos = chunk.getPosition();
   ChunkMonitorEntry entry = CHUNKS.get(pos);
   if (entry == null) {
     entry = new ChunkMonitorEntry(pos);
     CHUNKS.put(pos, entry);
   }
   entry.addChunk(chunk);
   return entry;
 }
 private boolean areAdjacentChunksReady(Chunk chunk) {
   Vector3i centerChunkPos = chunk.getPosition();
   for (Side side : Side.values()) {
     Vector3i adjChunkPos = side.getAdjacentPos(centerChunkPos);
     Chunk adjChunk = nearCache.get(adjChunkPos);
     boolean adjChunkReady = (adjChunk != null && adjChunk.isReady());
     if (!adjChunkReady) {
       return false;
     }
   }
   return true;
 }
  private boolean unloadChunkInternal(Vector3i pos) {
    Chunk chunk = nearCache.get(pos);
    if (chunk.isLocked()) {
      return false;
    }

    chunk.lock();
    try {
      if (!chunk.isReady()) {
        // Chunk hasn't been finished or changed, so just drop it.
        Iterator<ReadyChunkInfo> infoIterator = sortedReadyChunks.iterator();
        while (infoIterator.hasNext()) {
          ReadyChunkInfo next = infoIterator.next();
          if (next.getPos().equals(chunk.getPosition())) {
            infoIterator.remove();
            break;
          }
        }
        return true;
      }
      worldEntity.send(new BeforeChunkUnload(pos));
      for (ChunkRelevanceRegion region : regions.values()) {
        region.chunkUnloaded(pos);
      }
      storageManager.deactivateChunk(chunk);
      chunk.dispose();
      updateAdjacentChunksReadyFieldOfAdjChunks(chunk);

      try {
        unloadRequestTaskMaster.put(new ChunkUnloadRequest(chunk, this));
      } catch (InterruptedException e) {
        logger.error("Failed to enqueue unload request for {}", chunk.getPosition(), e);
      }

      return true;
    } finally {
      chunk.unlock();
    }
  }
  @Override
  public void dispose() {
    shutdown();

    for (Chunk chunk : nearCache.values()) {
      unloadChunkInternal(chunk.getPosition());
      chunk.dispose();
    }
    nearCache.clear();
    /*
     * The chunk monitor needs to clear chunk references, so it's important
     * that no new chunk get created
     */
    ChunkMonitor.fireChunkProviderDisposed(this);
  }
Esempio n. 9
0
 public static void fireChunkDeflated(Chunk chunk, int oldSize, int newSize) {
   Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null");
   post(new ChunkMonitorEvent.Deflated(chunk.getPosition(), oldSize, newSize));
 }
Esempio n. 10
0
 public static void fireChunkRevived(Chunk chunk) {
   Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null");
   post(new ChunkMonitorEvent.Revived(chunk.getPosition()));
 }