voxelImprovements #5
@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3i;
|
import org.joml.Vector3i;
|
||||||
|
|
||||||
|
import electrosphere.client.terrain.cache.ChunkData;
|
||||||
import electrosphere.client.terrain.cells.DrawCell.DrawCellFace;
|
import electrosphere.client.terrain.cells.DrawCell.DrawCellFace;
|
||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
@ -526,7 +527,7 @@ public class ClientDrawCellManager {
|
|||||||
){
|
){
|
||||||
//client should request chunk data from server for each chunk necessary to create the model
|
//client should request chunk data from server for each chunk necessary to create the model
|
||||||
LoggerInterface.loggerNetworking.DEBUG("(Client) Send Request for terrain at " + posToCheck);
|
LoggerInterface.loggerNetworking.DEBUG("(Client) Send Request for terrain at " + posToCheck);
|
||||||
Globals.clientTerrainManager.requestChunk(posToCheck.x, posToCheck.y, posToCheck.z);
|
Globals.clientTerrainManager.requestChunk(posToCheck.x, posToCheck.y, posToCheck.z, ChunkData.NO_STRIDE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,6 +106,35 @@ public class ClientTerrainManager {
|
|||||||
data
|
data
|
||||||
);
|
);
|
||||||
} break;
|
} break;
|
||||||
|
case SENDREDUCEDCHUNKDATA: {
|
||||||
|
int[][][] values = new int[ChunkData.CHUNK_SIZE][ChunkData.CHUNK_SIZE][ChunkData.CHUNK_SIZE];
|
||||||
|
float[][][] weights = new float[ChunkData.CHUNK_SIZE][ChunkData.CHUNK_SIZE][ChunkData.CHUNK_SIZE];
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(message.getchunkData());
|
||||||
|
FloatBuffer floatBuffer = buffer.asFloatBuffer();
|
||||||
|
for(int x = 0; x < ChunkData.CHUNK_SIZE; x++){
|
||||||
|
for(int y = 0; y < ChunkData.CHUNK_SIZE; y++){
|
||||||
|
for(int z = 0; z < ChunkData.CHUNK_SIZE; z++){
|
||||||
|
weights[x][y][z] = floatBuffer.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IntBuffer intView = buffer.asIntBuffer();
|
||||||
|
intView.position(floatBuffer.position());
|
||||||
|
for(int x = 0; x < ChunkData.CHUNK_SIZE; x++){
|
||||||
|
for(int y = 0; y < ChunkData.CHUNK_SIZE; y++){
|
||||||
|
for(int z = 0; z < ChunkData.CHUNK_SIZE; z++){
|
||||||
|
values[x][y][z] = intView.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ChunkData data = new ChunkData(message.getworldX(), message.getworldY(), message.getworldZ());
|
||||||
|
data.setVoxelType(values);
|
||||||
|
data.setVoxelWeight(weights);
|
||||||
|
terrainCache.addChunkDataToCache(
|
||||||
|
message.getworldX(), message.getworldY(), message.getworldZ(),
|
||||||
|
data
|
||||||
|
);
|
||||||
|
} break;
|
||||||
default:
|
default:
|
||||||
LoggerInterface.loggerEngine.WARNING("ClientTerrainManager: unhandled network message of type" + message.getMessageSubtype());
|
LoggerInterface.loggerEngine.WARNING("ClientTerrainManager: unhandled network message of type" + message.getMessageSubtype());
|
||||||
break;
|
break;
|
||||||
@ -160,13 +189,15 @@ public class ClientTerrainManager {
|
|||||||
* @param worldX the world x coordinate of the chunk
|
* @param worldX the world x coordinate of the chunk
|
||||||
* @param worldY the world y coordinate of the chunk
|
* @param worldY the world y coordinate of the chunk
|
||||||
* @param worldZ the world z coordinate of the chunk
|
* @param worldZ the world z coordinate of the chunk
|
||||||
|
* @param stride The stride of the data
|
||||||
*/
|
*/
|
||||||
public void requestChunk(int worldX, int worldY, int worldZ){
|
public void requestChunk(int worldX, int worldY, int worldZ, int stride){
|
||||||
if(!this.terrainCache.hasRequested(worldX, worldY, worldZ)){
|
if(!this.terrainCache.hasRequested(worldX, worldY, worldZ)){
|
||||||
Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestChunkDataMessage(
|
Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestReducedChunkDataMessage(
|
||||||
worldX,
|
worldX,
|
||||||
worldY,
|
worldY,
|
||||||
worldZ
|
worldZ,
|
||||||
|
stride
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -246,7 +246,7 @@ public class TerrainProtocol implements ServerProtocolTemplate<TerrainMessage> {
|
|||||||
|
|
||||||
// System.out.println("(Server) Send terrain at " + worldX + " " + worldY + " " + worldZ);
|
// System.out.println("(Server) Send terrain at " + worldX + " " + worldY + " " + worldZ);
|
||||||
LoggerInterface.loggerNetworking.DEBUG("(Server) Send terrain at " + worldX + " " + worldY + " " + worldZ);
|
LoggerInterface.loggerNetworking.DEBUG("(Server) Send terrain at " + worldX + " " + worldY + " " + worldZ);
|
||||||
connectionHandler.addMessagetoOutgoingQueue(TerrainMessage.constructsendChunkDataMessage(worldX, worldY, worldZ, buffer.array()));
|
connectionHandler.addMessagetoOutgoingQueue(TerrainMessage.constructSendReducedChunkDataMessage(worldX, worldY, worldZ, stride, buffer.array()));
|
||||||
};
|
};
|
||||||
|
|
||||||
//request chunk
|
//request chunk
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user