Search in sources :

Example 1 with ConverterWorkerThread

use of io.xol.chunkstories.converter.ConverterWorkers.ConverterWorkerThread in project chunkstories by Hugobros3.

the class TaskBuildHeightmap method task.

@Override
protected boolean task(TaskExecutor taskExecutor) {
    ConverterWorkerThread cwt = (ConverterWorkerThread) taskExecutor;
    // We wait on a bunch of stuff to load everytime
    CompoundFence loadRelevantData = new CompoundFence();
    HeightmapImplementation summary = csWorld.getRegionsSummariesHolder().aquireHeightmap(cwt, regionX, regionZ);
    loadRelevantData.add(summary.waitForLoading());
    // Aquires the chunks we want to make the summaries of.
    for (int innerCX = 0; innerCX < 8; innerCX++) for (int innerCZ = 0; innerCZ < 8; innerCZ++) for (int chunkY = 0; chunkY < OfflineWorldConverter.mcWorldHeight / 32; chunkY++) {
        ChunkHolder holder = csWorld.aquireChunkHolder(cwt, regionX * 8 + innerCX, chunkY, regionZ * 8 + innerCZ);
        if (holder != null) {
            loadRelevantData.add(holder.waitForLoading());
            if (cwt.registeredCS_Holders.add(holder))
                cwt.chunksAquired++;
        }
    }
    // Wait until all of that crap loads
    loadRelevantData.traverse();
    // Descend from top
    for (int i = 0; i < 256; i++) for (int j = 0; j < 256; j++) {
        for (int h = OfflineWorldConverter.mcWorldHeight; h > 0; h--) {
            CellData data = csWorld.peekSafely(regionX * 256 + i, h, regionZ * 256 + j);
            if (!data.getVoxel().isAir()) {
                Voxel vox = data.getVoxel();
                if (vox.getDefinition().isSolid() || vox.getDefinition().isLiquid()) {
                    summary.setTopCell(data);
                    break;
                }
            }
        }
    }
    Fence waitForSummarySave = summary.saveSummary();
    // cwt.converter().verbose("Waiting for summary saving...");
    waitForSummarySave.traverse();
    // cwt.converter().verbose("Done.");
    // We don't need the summary anymore
    summary.unregisterUser(cwt);
    return true;
}
Also used : CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) HeightmapImplementation(io.xol.chunkstories.world.summary.HeightmapImplementation) ChunkHolder(io.xol.chunkstories.api.world.chunk.ChunkHolder) Voxel(io.xol.chunkstories.api.voxel.Voxel) ConverterWorkerThread(io.xol.chunkstories.converter.ConverterWorkers.ConverterWorkerThread) Fence(io.xol.chunkstories.api.util.concurrency.Fence) CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) CellData(io.xol.chunkstories.api.world.cell.CellData)

Example 2 with ConverterWorkerThread

use of io.xol.chunkstories.converter.ConverterWorkers.ConverterWorkerThread in project chunkstories by Hugobros3.

the class TaskConvertMcChunk method task.

@Override
protected boolean task(TaskExecutor taskExecutor) {
    ConverterWorkerThread cwt = (ConverterWorkerThread) taskExecutor;
    WorldTool csWorld = cwt.world();
    // Is it within our borders ?
    // if (chunkStoriesCurrentChunkX >= 0 && chunkStoriesCurrentChunkX < cwt.size().sizeInChunks * 32 && chunkStoriesCurrentChunkZ >= 0 && chunkStoriesCurrentChunkZ < cwt.size().sizeInChunks * 32)
    {
        // MinecraftChunk minecraftChunk = null;
        try {
            if (minecraftChunk != null) {
                // If it succeed, we first require to load the corresponding chunkstories stuff
                // Ignore the summaries for now
                /*Heightmap summary = csWorld.getRegionsSummariesHolder().aquireRegionSummaryWorldCoordinates(this, chunkStoriesCurrentChunkX, chunkStoriesCurrentChunkZ);
					if(summary != null)
						registeredCS_Summaries.add(summary);*/
                CompoundFence loadRelevantData = new CompoundFence();
                // Then the chunks
                for (int y = 0; y < OfflineWorldConverter.mcWorldHeight; y += 32) {
                    ChunkHolder holder = csWorld.aquireChunkHolderWorldCoordinates(cwt, chunkStoriesCurrentChunkX, y, chunkStoriesCurrentChunkZ);
                    if (holder != null) {
                        loadRelevantData.add(holder.waitForLoading());
                        if (cwt.registeredCS_Holders.add(holder))
                            cwt.chunksAquired++;
                    }
                }
                // Wait for them to actually load
                loadRelevantData.traverse();
                for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) for (int y = 0; y < OfflineWorldConverter.mcWorldHeight; y++) {
                    // Translate each block
                    int mcId = minecraftChunk.getBlockID(x, y, z) & 0xFFF;
                    byte meta = (byte) (minecraftChunk.getBlockMeta(x, y, z) & 0xF);
                    // Ignore air blocks
                    if (mcId != 0) {
                        Mapper mapper = this.mappers.getMapper(mcId, meta);
                        if (mapper == null)
                            continue;
                        if (mapper instanceof NonTrivialMapper) {
                            ((NonTrivialMapper) mapper).output(csWorld, chunkStoriesCurrentChunkX + x, y, chunkStoriesCurrentChunkZ + z, mcId, meta, minecraftRegion, minecraftCurrentChunkXinsideRegion, minecraftCuurrentChunkZinsideRegion, x, y, z);
                        } else {
                            FutureCell future = new FutureCell(csWorld, chunkStoriesCurrentChunkX + x, y, chunkStoriesCurrentChunkZ + z, csWorld.getContent().voxels().air());
                            // Directly set trivial blocks
                            mapper.output(mcId, meta, future);
                            if (!future.getVoxel().isAir())
                                csWorld.pokeSimpleSilently(future);
                        }
                    }
                }
            // Converts external data such as signs
            // SpecialBlocksHandler.processAdditionalStuff(minecraftChunk, csWorld, chunkStoriesCurrentChunkX, 0, chunkStoriesCurrentChunkZ);
            }
        } catch (Exception e) {
            cwt.converter().verbose("Issue with chunk " + minecraftCurrentChunkXinsideRegion + " " + minecraftCuurrentChunkZinsideRegion + " of region " + minecraftRegionX + " " + minecraftRegionZ + ".");
            e.printStackTrace();
        }
    }
    return true;
}
Also used : Mapper(io.xol.chunkstories.api.converter.mappings.Mapper) NonTrivialMapper(io.xol.chunkstories.api.converter.mappings.NonTrivialMapper) FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) WorldTool(io.xol.chunkstories.world.WorldTool) ChunkHolder(io.xol.chunkstories.api.world.chunk.ChunkHolder) ConverterWorkerThread(io.xol.chunkstories.converter.ConverterWorkers.ConverterWorkerThread) NonTrivialMapper(io.xol.chunkstories.api.converter.mappings.NonTrivialMapper)

Aggregations

ChunkHolder (io.xol.chunkstories.api.world.chunk.ChunkHolder)2 ConverterWorkerThread (io.xol.chunkstories.converter.ConverterWorkers.ConverterWorkerThread)2 CompoundFence (io.xol.chunkstories.util.concurrency.CompoundFence)2 Mapper (io.xol.chunkstories.api.converter.mappings.Mapper)1 NonTrivialMapper (io.xol.chunkstories.api.converter.mappings.NonTrivialMapper)1 Fence (io.xol.chunkstories.api.util.concurrency.Fence)1 Voxel (io.xol.chunkstories.api.voxel.Voxel)1 CellData (io.xol.chunkstories.api.world.cell.CellData)1 FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)1 WorldTool (io.xol.chunkstories.world.WorldTool)1 HeightmapImplementation (io.xol.chunkstories.world.summary.HeightmapImplementation)1