diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 873598be..5f05c255 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1986,6 +1986,7 @@ Performance improvements - Foliage cell quits earlier - Behavior tree addition/subtraction from scene optimization - Reduce bones on LOD human model + - Shallow clone on physics cell creation Increase human move speed LOD components re-attach physics diff --git a/src/main/java/electrosphere/client/block/BlockChunkData.java b/src/main/java/electrosphere/client/block/BlockChunkData.java index 9d7a9fe6..6bbe0268 100644 --- a/src/main/java/electrosphere/client/block/BlockChunkData.java +++ b/src/main/java/electrosphere/client/block/BlockChunkData.java @@ -86,38 +86,38 @@ public class BlockChunkData implements BlockMeshgenData { /** * The type of block at a given position */ - short[] type; + private short[] type; /** * Metadata about a block * first 4 bits are the rotation of the block) */ - short[] metadata; + private short[] metadata; /** * If this block chunk is homogenously a single value, it will be the value of this short. Otherwise is */ - short homogenousValue = NOT_HOMOGENOUS; + private short homogenousValue = NOT_HOMOGENOUS; /** * The level of detail of the block data */ - int lod; + private int lod; /** * The x coordinate of the world position of the chunk */ - int worldX; + private int worldX; /** * The y coordinate of the world position of the chunk */ - int worldY; + private int worldY; /** * The z coordinate of the world position of the chunk */ - int worldZ; + private int worldZ; /** * Constructor @@ -152,6 +152,27 @@ public class BlockChunkData implements BlockMeshgenData { this.setMetadata(BlockChunkPool.getShort()); } + /** + * Clones a block chunk data + * @param other The data to clone + * @return The cloned data + */ + public static BlockChunkData cloneShallow(BlockChunkData other){ + BlockChunkData rVal = new BlockChunkData(); + if(other.type != null){ + rVal.type = other.type; + } + if(other.metadata != null){ + rVal.metadata = other.metadata; + } + rVal.homogenousValue = other.homogenousValue; + rVal.lod = other.lod; + rVal.worldX = other.worldX; + rVal.worldY = other.worldY; + rVal.worldZ = other.worldZ; + return rVal; + } + /** * Gets the type data for the chunk * @return The type data diff --git a/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java b/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java index c06d1151..370ea370 100644 --- a/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java +++ b/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java @@ -384,7 +384,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager //the server will not be able to synchronize it properly. ServerEntityUtils.initiallyPositionEntity(parent,blockEntity,realPos); ServerEntityUtils.initiallyPositionEntity(parent,terrainEntity,realPos); - PhysicsDataCell cell = PhysicsDataCell.createPhysicsCell(worldPos, terrainEntity, blockEntity); + PhysicsDataCell cell = PhysicsDataCell.createPhysicsCell(terrainEntity, blockEntity); cell.setTerrainChunk(terrainChunk); cell.setBlockChunk(blockChunkData); cell.generatePhysics(); @@ -819,7 +819,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager ServerEntityUtils.initiallyPositionEntity(realm,blockEntity,realPos); ServerEntityUtils.initiallyPositionEntity(realm,terrainEntity,realPos); - PhysicsDataCell targetCell = PhysicsDataCell.createPhysicsCell(worldPos, terrainEntity, blockEntity); + PhysicsDataCell targetCell = PhysicsDataCell.createPhysicsCell(terrainEntity, blockEntity); if(cell == null){ posPhysicsMap.put(key, targetCell); } else { diff --git a/src/main/java/electrosphere/server/datacell/physics/PhysicsDataCell.java b/src/main/java/electrosphere/server/datacell/physics/PhysicsDataCell.java index d5d3432c..0b5ff53f 100644 --- a/src/main/java/electrosphere/server/datacell/physics/PhysicsDataCell.java +++ b/src/main/java/electrosphere/server/datacell/physics/PhysicsDataCell.java @@ -14,26 +14,19 @@ import electrosphere.renderer.meshgen.BlockMeshgen.BlockMeshData; import electrosphere.server.datacell.Realm; import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; -import org.joml.Vector3i; -import org.ode4j.ode.DBody; - /** * An entity which contains physics for terrain for a given chunk on the server */ public class PhysicsDataCell { - Vector3i worldPos; - Entity physicsEntity; Entity blockPhysicsEntity; ServerTerrainChunk terrainChunk; BlockChunkData blockChunk; - DBody physicsObject; - - float[][][] weights = new float[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE]; - int[][][] types = new int[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE]; + float[][][] weights; + int[][][] types; /** * The terrain vertex data @@ -52,7 +45,6 @@ public class PhysicsDataCell { * @return The cell */ public static PhysicsDataCell createPhysicsCell( - Vector3i worldPos, Entity physicsEntity, Entity blockPhysicsEntity @@ -60,7 +52,6 @@ public class PhysicsDataCell { PhysicsDataCell rVal = new PhysicsDataCell(); rVal.physicsEntity = physicsEntity; rVal.blockPhysicsEntity = blockPhysicsEntity; - rVal.worldPos = worldPos; return rVal; } @@ -123,6 +114,8 @@ public class PhysicsDataCell { //fill in data // //main chunk + this.weights = new float[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE]; + this.types = new int[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE]; for(int x = 0; x < ChunkData.CHUNK_DATA_SIZE; x++){ for(int y = 0; y < ChunkData.CHUNK_DATA_SIZE; y++){ for(int z = 0; z < ChunkData.CHUNK_DATA_SIZE; z++){ @@ -257,7 +250,7 @@ public class PhysicsDataCell { * @param blockChunk The block chunk data */ public void setBlockChunk(BlockChunkData blockChunk) { - this.blockChunk = blockChunk; + this.blockChunk = BlockChunkData.cloneShallow(blockChunk); } /**