homogenous value fixes
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-11-11 17:07:30 -05:00
parent c2aacdd2ae
commit d06d5d4506
9 changed files with 136 additions and 111 deletions

View File

@ -997,10 +997,9 @@ Potential physics destruction fix
Join propagation further up tree Join propagation further up tree
Lower client cache size (to fight memory stalling) Lower client cache size (to fight memory stalling)
Manual free button on memory debug window Manual free button on memory debug window
Passing chunk data between nodes
Fix homogenous value propagating from chunk gen to client cache
passing chunk data between nodes Fix homogenous value joining on client
storing min lod of children at every level of tree

View File

@ -22,6 +22,11 @@ public class ChunkData {
*/ */
public static final int NOT_HOMOGENOUS = -1; public static final int NOT_HOMOGENOUS = -1;
/**
* The weight of a cell in a homogenous chunk
*/
public static final float HOMOGENOUS_WEIGHT = 1.0f;
/** /**
* The size of the chunk data stored on the client * The size of the chunk data stored on the client
*/ */

View File

@ -320,7 +320,9 @@ public class ClientDrawCellManager {
} }
} }
if(isHomogenous){ if(isHomogenous){
this.join(node); WorldOctTreeNode<DrawCell> newNode = this.join(node);
newNode.getData().setHasGenerated(true);
newNode.getData().setHomogenous(true);
} }
if((this.chunkTree.getMaxLevel() - node.getLevel()) < minLeafLod){ if((this.chunkTree.getMaxLevel() - node.getLevel()) < minLeafLod){
evaluationMap.put(node,true); evaluationMap.put(node,true);
@ -391,7 +393,7 @@ public class ClientDrawCellManager {
return return
node.canSplit() && node.canSplit() &&
(node.getLevel() != this.chunkTree.getMaxLevel()) && (node.getLevel() != this.chunkTree.getMaxLevel()) &&
(!node.getData().hasGenerated() || !node.getData().isHomogenous()) && !node.getData().isHomogenous() &&
(node.getParent() != null || node == this.chunkTree.getRoot()) && (node.getParent() != null || node == this.chunkTree.getRoot()) &&
( (
( (
@ -614,7 +616,7 @@ public class ClientDrawCellManager {
* Joins a parent node * Joins a parent node
* @param node The parent node * @param node The parent node
*/ */
private void join(WorldOctTreeNode<DrawCell> node){ private WorldOctTreeNode<DrawCell> join(WorldOctTreeNode<DrawCell> node){
Globals.profiler.beginCpuSample("ClientDrawCellManager.join"); Globals.profiler.beginCpuSample("ClientDrawCellManager.join");
//perform op //perform op
WorldOctTreeNode<DrawCell> newLeaf = chunkTree.join(node, DrawCell.generateTerrainCell(node.getMinBound(),node.getData().lod)); WorldOctTreeNode<DrawCell> newLeaf = chunkTree.join(node, DrawCell.generateTerrainCell(node.getMinBound(),node.getData().lod));
@ -628,6 +630,7 @@ public class ClientDrawCellManager {
evaluationMap.put(newLeaf,true); evaluationMap.put(newLeaf,true);
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
return newLeaf;
} }
/** /**

View File

@ -66,7 +66,7 @@ public class DrawCell {
/** /**
* Tracks whether this draw cell is flagged as homogenous from the server or not * Tracks whether this draw cell is flagged as homogenous from the server or not
*/ */
boolean homogenous = true; boolean homogenous = false;
/** /**
* Number of failed generation attempts * Number of failed generation attempts
@ -251,17 +251,17 @@ public class DrawCell {
} }
if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){ if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){
this.homogenous = false; this.homogenous = false;
faceWeights[x][y] = currentChunk.getWeight(
0,
localCoord1,
localCoord2
);
faceTypes[x][y] = currentChunk.getType(
0,
localCoord1,
localCoord2
);
} }
faceWeights[x][y] = currentChunk.getWeight(
0,
localCoord1,
localCoord2
);
faceTypes[x][y] = currentChunk.getType(
0,
localCoord1,
localCoord2
);
} break; } break;
case X_NEGATIVE: { case X_NEGATIVE: {
ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint( ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint(
@ -277,17 +277,17 @@ public class DrawCell {
} }
if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){ if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){
this.homogenous = false; this.homogenous = false;
faceWeights[x][y] = currentChunk.getWeight(
0,
localCoord1,
localCoord2
);
faceTypes[x][y] = currentChunk.getType(
0,
localCoord1,
localCoord2
);
} }
faceWeights[x][y] = currentChunk.getWeight(
0,
localCoord1,
localCoord2
);
faceTypes[x][y] = currentChunk.getType(
0,
localCoord1,
localCoord2
);
} break; } break;
case Y_POSITIVE: { case Y_POSITIVE: {
ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint( ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint(
@ -303,17 +303,17 @@ public class DrawCell {
} }
if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){ if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){
this.homogenous = false; this.homogenous = false;
faceWeights[x][y] = currentChunk.getWeight(
localCoord1,
0,
localCoord2
);
faceTypes[x][y] = currentChunk.getType(
localCoord1,
0,
localCoord2
);
} }
faceWeights[x][y] = currentChunk.getWeight(
localCoord1,
0,
localCoord2
);
faceTypes[x][y] = currentChunk.getType(
localCoord1,
0,
localCoord2
);
} break; } break;
case Y_NEGATIVE: { case Y_NEGATIVE: {
ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint( ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint(
@ -329,17 +329,17 @@ public class DrawCell {
} }
if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){ if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){
this.homogenous = false; this.homogenous = false;
faceWeights[x][y] = currentChunk.getWeight(
localCoord1,
0,
localCoord2
);
faceTypes[x][y] = currentChunk.getType(
localCoord1,
0,
localCoord2
);
} }
faceWeights[x][y] = currentChunk.getWeight(
localCoord1,
0,
localCoord2
);
faceTypes[x][y] = currentChunk.getType(
localCoord1,
0,
localCoord2
);
} break; } break;
case Z_POSITIVE: { case Z_POSITIVE: {
ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint( ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint(
@ -355,17 +355,17 @@ public class DrawCell {
} }
if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){ if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){
this.homogenous = false; this.homogenous = false;
faceWeights[x][y] = currentChunk.getWeight(
localCoord1,
localCoord2,
0
);
faceTypes[x][y] = currentChunk.getType(
localCoord1,
localCoord2,
0
);
} }
faceWeights[x][y] = currentChunk.getWeight(
localCoord1,
localCoord2,
0
);
faceTypes[x][y] = currentChunk.getType(
localCoord1,
localCoord2,
0
);
} break; } break;
case Z_NEGATIVE: { case Z_NEGATIVE: {
ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint( ChunkData currentChunk = Globals.clientTerrainManager.getChunkDataAtWorldPoint(
@ -381,17 +381,17 @@ public class DrawCell {
} }
if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){ if(currentChunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){
this.homogenous = false; this.homogenous = false;
faceWeights[x][y] = currentChunk.getWeight(
localCoord1,
localCoord2,
0
);
faceTypes[x][y] = currentChunk.getType(
localCoord1,
localCoord2,
0
);
} }
faceWeights[x][y] = currentChunk.getWeight(
localCoord1,
localCoord2,
0
);
faceTypes[x][y] = currentChunk.getType(
localCoord1,
localCoord2,
0
);
} break; } break;
} }
// Vector3i sampleChunkWorldPos = new Vector3i( // Vector3i sampleChunkWorldPos = new Vector3i(
@ -473,6 +473,14 @@ public class DrawCell {
this.hasGenerated = hasGenerated; this.hasGenerated = hasGenerated;
} }
/**
* Sets whether this draw cell is homogenous or not
* @param hasGenerated true if is homogenous, false otherwise
*/
public void setHomogenous(boolean homogenous) {
this.homogenous = homogenous;
}
/** /**
* Gets whether this draw cell will generate polygons or not * Gets whether this draw cell will generate polygons or not
* @return true if it has polygons, false otherwise * @return true if it has polygons, false otherwise

View File

@ -123,36 +123,38 @@ public class ClientTerrainManager {
); );
} break; } break;
case SENDREDUCEDCHUNKDATA: { case SENDREDUCEDCHUNKDATA: {
int[][][] values = new int[ChunkData.CHUNK_DATA_SIZE][ChunkData.CHUNK_DATA_SIZE][ChunkData.CHUNK_DATA_SIZE]; ChunkData data = new ChunkData(message.getworldX(), message.getworldY(), message.getworldZ(), message.getchunkResolution(), message.gethomogenousValue());
float[][][] weights = new float[ChunkData.CHUNK_DATA_SIZE][ChunkData.CHUNK_DATA_SIZE][ChunkData.CHUNK_DATA_SIZE]; if(message.gethomogenousValue() == ChunkData.NOT_HOMOGENOUS){
ByteBuffer buffer = ByteBuffer.wrap(message.getchunkData()); int[][][] values = new int[ChunkData.CHUNK_DATA_SIZE][ChunkData.CHUNK_DATA_SIZE][ChunkData.CHUNK_DATA_SIZE];
FloatBuffer floatBuffer = buffer.asFloatBuffer(); float[][][] weights = new float[ChunkData.CHUNK_DATA_SIZE][ChunkData.CHUNK_DATA_SIZE][ChunkData.CHUNK_DATA_SIZE];
for(int x = 0; x < ChunkData.CHUNK_DATA_SIZE; x++){ ByteBuffer buffer = ByteBuffer.wrap(message.getchunkData());
for(int y = 0; y < ChunkData.CHUNK_DATA_SIZE; y++){ FloatBuffer floatBuffer = buffer.asFloatBuffer();
for(int z = 0; z < ChunkData.CHUNK_DATA_SIZE; z++){ for(int x = 0; x < ChunkData.CHUNK_DATA_SIZE; x++){
weights[x][y][z] = floatBuffer.get(); for(int y = 0; y < ChunkData.CHUNK_DATA_SIZE; y++){
} for(int z = 0; z < ChunkData.CHUNK_DATA_SIZE; z++){
} weights[x][y][z] = floatBuffer.get();
}
IntBuffer intView = buffer.asIntBuffer();
intView.position(floatBuffer.position());
int firstType = -1;
boolean homogenous = true;
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++){
values[x][y][z] = intView.get();
if(firstType == -1){
firstType = values[x][y][z];
} else if(homogenous && firstType == values[x][y][z]){
homogenous = false;
} }
} }
} }
IntBuffer intView = buffer.asIntBuffer();
intView.position(floatBuffer.position());
int firstType = -1;
boolean homogenous = true;
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++){
values[x][y][z] = intView.get();
if(firstType == -1){
firstType = values[x][y][z];
} else if(homogenous && firstType == values[x][y][z]){
homogenous = false;
}
}
}
}
data.setVoxelType(values);
data.setVoxelWeight(weights);
} }
ChunkData data = new ChunkData(message.getworldX(), message.getworldY(), message.getworldZ(), message.getchunkResolution(),homogenous ? firstType : ChunkData.NOT_HOMOGENOUS);
data.setVoxelType(values);
data.setVoxelWeight(weights);
terrainCache.addChunkDataToCache( terrainCache.addChunkDataToCache(
message.getworldX(), message.getworldY(), message.getworldZ(), message.getworldX(), message.getworldY(), message.getworldZ(),
data data

View File

@ -45,7 +45,7 @@ public class TerrainChunk {
Entity rVal = EntityCreationUtils.createClientSpatialEntity(); Entity rVal = EntityCreationUtils.createClientSpatialEntity();
if(hasPolygons){ if(hasPolygons && chunkData.terrainGrid != null && chunkData.textureGrid != null){
generationService.submit(() -> { generationService.submit(() -> {
TerrainChunkData data; TerrainChunkData data;
try { try {

View File

@ -222,31 +222,38 @@ public class TerrainProtocol implements ServerProtocolTemplate<TerrainMessage> {
int yWidth = chunk.getWeights()[0].length; int yWidth = chunk.getWeights()[0].length;
int zWidth = chunk.getWeights()[0][0].length; int zWidth = chunk.getWeights()[0][0].length;
ByteBuffer buffer = ByteBuffer.allocate(xWidth*yWidth*zWidth*(4+4)); byte[] toSend = null;
FloatBuffer floatView = buffer.asFloatBuffer();
for(int x = 0; x < xWidth; x++){ if(chunk.getHomogenousValue() == ChunkData.NOT_HOMOGENOUS){
for(int y = 0; y < yWidth; y++){ ByteBuffer buffer = ByteBuffer.allocate(xWidth*yWidth*zWidth*(4+4));
for(int z = 0; z < zWidth; z++){ FloatBuffer floatView = buffer.asFloatBuffer();
floatView.put(chunk.getWeights()[x][y][z]);
for(int x = 0; x < xWidth; x++){
for(int y = 0; y < yWidth; y++){
for(int z = 0; z < zWidth; z++){
floatView.put(chunk.getWeights()[x][y][z]);
}
} }
} }
}
IntBuffer intView = buffer.asIntBuffer(); IntBuffer intView = buffer.asIntBuffer();
intView.position(floatView.position()); intView.position(floatView.position());
for(int x = 0; x < xWidth; x++){ for(int x = 0; x < xWidth; x++){
for(int y = 0; y < yWidth; y++){ for(int y = 0; y < yWidth; y++){
for(int z = 0; z < zWidth; z++){ for(int z = 0; z < zWidth; z++){
intView.put(chunk.getValues()[x][y][z]); intView.put(chunk.getValues()[x][y][z]);
}
} }
} }
toSend = buffer.array();
} else {
toSend = new byte[]{ 0 };
} }
// 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.constructSendReducedChunkDataMessage(worldX, worldY, worldZ, stride, chunk.getHomogenousValue(), buffer.array())); connectionHandler.addMessagetoOutgoingQueue(TerrainMessage.constructSendReducedChunkDataMessage(worldX, worldY, worldZ, stride, chunk.getHomogenousValue(), toSend));
}; };
//request chunk //request chunk

View File

@ -96,7 +96,7 @@ public class TestGenerationChunkGenerator implements ChunkGenerator {
float[][][] weights = new float[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];; float[][][] weights = new float[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];;
int[][][] values = new int[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE]; int[][][] values = new int[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];
int firstType = -1; int firstType = -2;
boolean homogenous = true; boolean homogenous = true;
try { try {
//actual generation algo //actual generation algo
@ -182,7 +182,7 @@ public class TestGenerationChunkGenerator implements ChunkGenerator {
weights[x][y][z] = voxel.weight; weights[x][y][z] = voxel.weight;
values[x][y][z] = voxel.type; values[x][y][z] = voxel.type;
} }
if(firstType == -1){ if(firstType == -2){
firstType = values[x][y][z]; firstType = values[x][y][z];
} else if(homogenous && firstType != values[x][y][z]){ } else if(homogenous && firstType != values[x][y][z]){
homogenous = false; homogenous = false;

View File

@ -75,6 +75,7 @@ public class ServerTerrainChunk {
this.worldX = worldX; this.worldX = worldX;
this.worldY = worldY; this.worldY = worldY;
this.worldZ = worldZ; this.worldZ = worldZ;
this.homogenousValue = homogenousValue;
this.weights = weights; this.weights = weights;
this.values = values; this.values = values;
} }