diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 75875815..9b3ba556 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1882,6 +1882,8 @@ Macro data is injected into voxel chunk generators Close macro objects injected into voxel chunk gen instead of all data Fix spline3d mat storing calculations when getting positions Roads applied to terrain voxel gen +Support lack of macro data for chunk gens +Support multichunk select all blocks diff --git a/src/main/java/electrosphere/client/block/ClientBlockSelection.java b/src/main/java/electrosphere/client/block/ClientBlockSelection.java index 2272aa2d..e39e9618 100644 --- a/src/main/java/electrosphere/client/block/ClientBlockSelection.java +++ b/src/main/java/electrosphere/client/block/ClientBlockSelection.java @@ -13,6 +13,7 @@ import electrosphere.client.interact.select.AreaSelection.AreaSelectionType; import electrosphere.client.scene.ClientWorldData; import electrosphere.data.block.fab.BlockFab; import electrosphere.engine.Globals; +import electrosphere.server.datacell.ServerWorldData; import electrosphere.util.math.HashUtils; /** @@ -96,38 +97,42 @@ public class ClientBlockSelection { */ public static BlockFab convertSelectionToFab(){ AreaSelection selection = Globals.cursorState.getAreaSelection(); - Vector3i startChunk = Globals.clientState.clientWorldData.convertRealToWorldSpace(selection.getRectStart()); - Vector3i endChunk = Globals.clientState.clientWorldData.convertRealToWorldSpace(selection.getRectEnd()); - if(!startChunk.equals(endChunk)){ - throw new Error("Unsupported case! Selected are coverts multiple chunks.. " + startChunk + " " + endChunk); - } - Vector3i blockStart = ClientWorldData.convertRealToLocalBlockSpace(selection.getRectStart()); - Vector3i blockEnd = ClientWorldData.convertRealToLocalBlockSpace(selection.getRectEnd()); - BlockChunkData chunk = Globals.clientState.clientBlockManager.getChunkDataAtWorldPoint(startChunk, 0); - if(chunk == null){ - throw new Error("Failed to grab chunk at " + startChunk); - } + //get dims + int dimX = (int)((selection.getRectEnd().x - selection.getRectStart().x) * BlockChunkData.BLOCKS_PER_UNIT_DISTANCE); + int dimY = (int)((selection.getRectEnd().y - selection.getRectStart().y) * BlockChunkData.BLOCKS_PER_UNIT_DISTANCE); + int dimZ = (int)((selection.getRectEnd().z - selection.getRectStart().z) * BlockChunkData.BLOCKS_PER_UNIT_DISTANCE); - int blockCount = (blockEnd.x - blockStart.x) * (blockEnd.y - blockStart.y) * (blockEnd.z - blockStart.z); + Vector3d posCurr = new Vector3d(); + Vector3i chunkPos = null; + Vector3i blockPos = null; + + int blockCount = dimX * dimY * dimZ; short[] types = new short[blockCount]; short[] metadata = new short[blockCount]; int i = 0; - for(int x = blockStart.x; x < blockEnd.x; x++){ - for(int y = blockStart.y; y < blockEnd.y; y++){ - for(int z = blockStart.z; z < blockEnd.z; z++){ - types[i] = chunk.getType(x, y, z); - metadata[i] = chunk.getMetadata(x, y, z); + for(int x = 0; x < dimX; x++){ + for(int y = 0; y < dimY; y++){ + for(int z = 0; z < dimZ; z++){ + posCurr.set(selection.getRectStart()).add( + x * BlockChunkData.BLOCK_SIZE_MULTIPLIER, + y * BlockChunkData.BLOCK_SIZE_MULTIPLIER, + z * BlockChunkData.BLOCK_SIZE_MULTIPLIER + ); + chunkPos = ServerWorldData.convertRealToChunkSpace(posCurr); + BlockChunkData chunk = Globals.clientState.clientBlockManager.getChunkDataAtWorldPoint(chunkPos, 0); + if(chunk == null){ + throw new Error("Failed to grab chunk at " + chunkPos); + } + blockPos = ServerWorldData.convertRealToLocalBlockSpace(posCurr); + types[i] = chunk.getType(blockPos.x, blockPos.y, blockPos.z); + metadata[i] = chunk.getMetadata(blockPos.x, blockPos.y, blockPos.z); i++; } } } - Vector3i dimensions = new Vector3i( - (blockEnd.x - blockStart.x), - (blockEnd.y - blockStart.y), - (blockEnd.z - blockStart.z) - ); + Vector3i dimensions = new Vector3i(dimX, dimY, dimZ); BlockFab fab = BlockFab.create(dimensions, types, metadata); return fab; diff --git a/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java b/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java index 4d5dae0f..3920e6fa 100644 --- a/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java +++ b/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java @@ -217,7 +217,7 @@ public class ProceduralChunkGenerator implements ChunkGenerator { values[x][y][z] = voxel.type; } //apply macro data - if(this.applyMacroData(macroData, realX, realY, realZ, voxel)){ + if(macroData != null && this.applyMacroData(macroData, realX, realY, realZ, voxel)){ weights[x][y][z] = voxel.weight; values[x][y][z] = voxel.type; } diff --git a/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java b/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java index b27ecdec..8ebb51ce 100644 --- a/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java +++ b/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java @@ -306,7 +306,10 @@ public class ServerTerrainManager { } //generate if it does not exist if(returnedChunk == null){ - List objects = this.macroData.getNearbyObjects(ServerWorldData.convertChunkToRealSpace(worldX, worldY, worldZ)); + List objects = null; + if(macroData != null){ + objects = this.macroData.getNearbyObjects(ServerWorldData.convertChunkToRealSpace(worldX, worldY, worldZ)); + } returnedChunk = chunkGenerator.generateChunk(objects, worldX, worldY, worldZ, ChunkData.NO_STRIDE); } this.chunkCache.add(worldX, worldY, worldZ, ChunkData.NO_STRIDE, returnedChunk); @@ -354,7 +357,10 @@ public class ServerTerrainManager { */ public void getChunkAsync(int worldX, int worldY, int worldZ, int stride, Consumer onLoad){ Globals.profiler.beginAggregateCpuSample("ServerTerrainManager.getChunkAsync"); - List objects = this.macroData.getNearbyObjects(ServerWorldData.convertChunkToRealSpace(worldX, worldY, worldZ)); + List objects = null; + if(this.macroData != null){ + objects = this.macroData.getNearbyObjects(ServerWorldData.convertChunkToRealSpace(worldX, worldY, worldZ)); + } chunkExecutorService.submit(new ChunkGenerationThread(objects, chunkDiskMap, chunkCache, chunkGenerator, worldX, worldY, worldZ, stride, onLoad)); Globals.profiler.endCpuSample(); }