예제 #1
0
  @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();
    }
  }
예제 #2
0
  @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);
  }
예제 #3
0
  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();
    }
  }