Exemplo n.º 1
0
  private void createOrLoadChunk(Vector3i chunkPos) {
    Chunk chunk = nearCache.get(chunkPos);
    if (chunk == null && !preparingChunks.contains(chunkPos)) {
      preparingChunks.add(chunkPos);
      pipeline.doTask(
          new AbstractChunkTask(chunkPos) {
            @Override
            public String getName() {
              return "Create or Load Chunk";
            }

            @Override
            public void run() {
              ChunkStore chunkStore = storageManager.loadChunkStore(getPosition());
              Chunk chunk;
              if (chunkStore == null) {
                chunk = new ChunkImpl(getPosition());
                generator.createChunk(chunk);
              } else {
                chunk = chunkStore.getChunk();
              }

              InternalLightProcessor.generateInternalLighting(chunk);
              chunk.deflate();
              readyChunks.offer(
                  new ReadyChunkInfo(chunk, createBatchBlockEventMappings(chunk), chunkStore));
            }
          });
    }
  }
Exemplo n.º 2
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();
    }
  }
Exemplo n.º 3
0
 @Override
 public void shutdown() {
   pipeline.shutdown();
   unloadRequestTaskMaster.shutdown(new ChunkUnloadRequest(), true);
   lightMerger.shutdown();
 }
Exemplo n.º 4
0
 public void restart() {
   pipeline.restart();
   unloadRequestTaskMaster.restart();
   lightMerger.restart();
 }