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;
}
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();
}
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;
}
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;
}
Aggregations