Search in sources :

Example 6 with CompoundFence

use of io.xol.chunkstories.util.concurrency.CompoundFence in project chunkstories by Hugobros3.

the class WorldImplementation method saveEverything.

@Override
public Fence saveEverything() {
    CompoundFence ioOperationsFence = new CompoundFence();
    logger.info("Saving all parts of world " + worldInfo.getName());
    ioOperationsFence.add(regions.saveAll());
    ioOperationsFence.add(getRegionsSummariesHolder().saveAllLoadedSummaries());
    if (worldInfoMaster != null)
        this.worldInfoMaster.save();
    this.internalData.setLong("entities-ids-counter", entitiesUUIDGenerator.get());
    this.internalData.setLong("worldTime", worldTime);
    this.internalData.setLong("worldTimeInternal", worldTicksCounter);
    this.internalData.setFloat("overcastFactor", overcastFactor);
    this.internalData.save();
    if (masterContentTranslator != null)
        this.masterContentTranslator.save(new File(this.getFolderPath() + "/content_mappings.dat"));
    return ioOperationsFence;
}
Also used : CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) SerializedEntityFile(io.xol.chunkstories.entity.SerializedEntityFile) OldStyleConfigFile(io.xol.chunkstories.util.config.OldStyleConfigFile) File(java.io.File)

Example 7 with CompoundFence

use of io.xol.chunkstories.util.concurrency.CompoundFence in project chunkstories by Hugobros3.

the class MultithreadedOfflineWorldConverter method stepOneCopyWorldData.

protected void stepOneCopyWorldData(MinecraftWorld mcWorld, WorldImplementation csWorld, int minecraftOffsetX, int minecraftOffsetZ) {
    verbose("Entering step one: converting raw block data");
    // Prepares the loops
    WorldSize size = csWorld.getWorldInfo().getSize();
    int mcRegionStartX = MinecraftWorld.blockToRegionCoordinates(minecraftOffsetX);
    int mcRegionStartZ = MinecraftWorld.blockToRegionCoordinates(minecraftOffsetZ);
    int mcRegionEndX = MinecraftWorld.blockToRegionCoordinates(minecraftOffsetX + size.sizeInChunks * 32);
    int mcRegionEndZ = MinecraftWorld.blockToRegionCoordinates(minecraftOffsetZ + size.sizeInChunks * 32);
    int minecraftChunksImported = 0;
    long minecraftChunksToImport = ((long) (size.sizeInChunks * 32) * (long) (size.sizeInChunks * 32)) / (16 * 16);
    // System.out.println(size + " " + size.sizeInChunks + " " + minecraftChunksToImport);
    double completion = 0.0;
    long lastPercentageShow = System.currentTimeMillis();
    try {
        // We do this minecraft region per minecraft region.
        for (int minecraftRegionX = mcRegionStartX; minecraftRegionX < mcRegionEndX; minecraftRegionX++) {
            for (int minecraftRegionZ = mcRegionStartZ; minecraftRegionZ < mcRegionEndZ; minecraftRegionZ++) {
                // Load the culprit (There isn't any fancy world management, the getRegion()
                // actually loads the entire region file)
                MinecraftRegion minecraftRegion = mcWorld.getRegion(minecraftRegionX, minecraftRegionZ);
                CompoundFence waitForTheBoys = new CompoundFence();
                // TODO Good candidate for task-ifying
                for (int minecraftCurrentChunkXinsideRegion = 0; minecraftCurrentChunkXinsideRegion < 32; minecraftCurrentChunkXinsideRegion++) {
                    for (int minecraftCuurrentChunkZinsideRegion = 0; minecraftCuurrentChunkZinsideRegion < 32; minecraftCuurrentChunkZinsideRegion++) {
                        // Map minecraft chunk-space to chunk stories's
                        int chunkStoriesCurrentChunkX = (minecraftCurrentChunkXinsideRegion + minecraftRegionX * 32) * 16 - minecraftOffsetX;
                        int chunkStoriesCurrentChunkZ = (minecraftCuurrentChunkZinsideRegion + minecraftRegionZ * 32) * 16 - minecraftOffsetZ;
                        // Is it within our borders ?
                        if (chunkStoriesCurrentChunkX >= 0 && chunkStoriesCurrentChunkX < csWorld.getWorldInfo().getSize().sizeInChunks * 32 && chunkStoriesCurrentChunkZ >= 0 && chunkStoriesCurrentChunkZ < csWorld.getWorldInfo().getSize().sizeInChunks * 32) {
                            if (minecraftRegion != null) {
                                MinecraftChunk minecraftChunk = minecraftRegion.getChunk(minecraftCurrentChunkXinsideRegion, minecraftCuurrentChunkZinsideRegion);
                                TaskConvertMcChunk task = new TaskConvertMcChunk(minecraftRegion, minecraftChunk, chunkStoriesCurrentChunkX, chunkStoriesCurrentChunkZ, minecraftCurrentChunkXinsideRegion, minecraftCuurrentChunkZinsideRegion, minecraftRegionX, minecraftRegionZ, mappers);
                                workers.scheduleTask(task);
                                waitForTheBoys.add(task);
                            }
                        }
                    }
                }
                // System.out.println("Waiting on "+waitForTheBoys.size() + " async tasks...");
                // This code is mysoginistic, hang it
                waitForTheBoys.traverse();
                workers.dropAll();
                csWorld.unloadUselessData().traverse();
                // Close region
                if (minecraftRegion != null)
                    minecraftRegion.close();
                System.gc();
                // Display progress
                minecraftChunksImported += 32 * 32;
                if (Math.floor(((double) minecraftChunksImported / (double) minecraftChunksToImport) * 100) > completion) {
                    completion = Math.floor(((double) minecraftChunksImported / (double) minecraftChunksToImport) * 100);
                    if (completion >= 100.0 || (System.currentTimeMillis() - lastPercentageShow > 5000)) {
                        verbose(completion + "% ... (" + csWorld.getRegionsHolder().countChunks() + " chunks loaded ) using " + Runtime.getRuntime().freeMemory() / 1024 / 1024 + "/" + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "Mb ");
                        lastPercentageShow = System.currentTimeMillis();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    csWorld.unloadUselessData();
}
Also used : CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) MinecraftRegion(io.xol.enklume.MinecraftRegion) MinecraftChunk(io.xol.enklume.MinecraftChunk) WorldSize(io.xol.chunkstories.api.world.WorldInfo.WorldSize) IOException(java.io.IOException)

Example 8 with CompoundFence

use of io.xol.chunkstories.util.concurrency.CompoundFence in project chunkstories by Hugobros3.

the class HashMapWorldRegionsHolder method unloadsUselessData.

public Fence unloadsUselessData() {
    // We might want to wait for a few things
    CompoundFence compoundFence = new CompoundFence();
    // Prevents unloading a region whilst one of it's chunk holders is being aquired
    noConcurrentRegionCreationDestruction.acquireUninterruptibly();
    // Iterates over loaded regions and unloads unused ones
    Iterator<RegionImplementation> regionsIterator = this.getLoadedRegions();
    while (regionsIterator.hasNext()) {
        RegionImplementation region = regionsIterator.next();
        // Processes users, remove null ones
        region.unloadsUnusedChunks();
        // If no users have registered for any chunks
        if (region.isUnused() && region.canBeUnloaded()) {
            // This is the only way to ensure all entities end up in a single region file and we don't have uuid conflicts
            if (world instanceof WorldMaster)
                compoundFence.add(region.unloadAndSave());
            else
                // Immediate
                region.unload();
        }
    }
    noConcurrentRegionCreationDestruction.release();
    return compoundFence;
}
Also used : CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 9 with CompoundFence

use of io.xol.chunkstories.util.concurrency.CompoundFence in project chunkstories by Hugobros3.

the class HashMapWorldRegionsHolder method saveAll.

public Fence saveAll() {
    CompoundFence allRegionsFences = new CompoundFence();
    Iterator<RegionImplementation> i = regions.values().iterator();
    Region region;
    while (i.hasNext()) {
        region = i.next();
        if (region != null) {
            allRegionsFences.add(region.save());
        }
    }
    return allRegionsFences;
}
Also used : CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) Region(io.xol.chunkstories.api.world.region.Region)

Aggregations

CompoundFence (io.xol.chunkstories.util.concurrency.CompoundFence)9 ChunkHolder (io.xol.chunkstories.api.world.chunk.ChunkHolder)4 WorldSize (io.xol.chunkstories.api.world.WorldInfo.WorldSize)3 Fence (io.xol.chunkstories.api.util.concurrency.Fence)2 Heightmap (io.xol.chunkstories.api.world.heightmap.Heightmap)2 ConverterWorkerThread (io.xol.chunkstories.converter.ConverterWorkers.ConverterWorkerThread)2 Mapper (io.xol.chunkstories.api.converter.mappings.Mapper)1 NonTrivialMapper (io.xol.chunkstories.api.converter.mappings.NonTrivialMapper)1 Voxel (io.xol.chunkstories.api.voxel.Voxel)1 Task (io.xol.chunkstories.api.workers.Task)1 TaskExecutor (io.xol.chunkstories.api.workers.TaskExecutor)1 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)1 WorldUser (io.xol.chunkstories.api.world.WorldUser)1 CellData (io.xol.chunkstories.api.world.cell.CellData)1 FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)1 Region (io.xol.chunkstories.api.world.region.Region)1 SerializedEntityFile (io.xol.chunkstories.entity.SerializedEntityFile)1 SimpleFence (io.xol.chunkstories.util.concurrency.SimpleFence)1 OldStyleConfigFile (io.xol.chunkstories.util.config.OldStyleConfigFile)1 WorldTool (io.xol.chunkstories.world.WorldTool)1