fix recursive delete in cell managers
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-11-29 17:16:29 -05:00
parent aa34ea4db6
commit 2c967a2141
6 changed files with 28 additions and 55 deletions

View File

@ -1176,6 +1176,8 @@ Work on diagnosing data cell misalignment with entities
Fix gridded data cell manager loops iterating incorrectly
Implement multi-biome sampling for surface heightmap
Nearest biome sampling for content generation
Fix recursive delete not actually recursing
Add floor voxel type
# TODO

View File

@ -198,7 +198,7 @@ public class ClientBlockCellManager {
});
//do deletions
this.twoLayerDestroy(node);
this.recursivelyDestroy(node);
//update neighbors
this.conditionalUpdateAdjacentNodes(container, container.getChildren().get(0).getLevel());
@ -609,29 +609,14 @@ public class ClientBlockCellManager {
private void recursivelyDestroy(WorldOctTreeNode<BlockDrawCell> node){
if(node.getChildren().size() > 0){
for(WorldOctTreeNode<BlockDrawCell> child : node.getChildren()){
child.getData().destroy();
this.recursivelyDestroy(child);
}
// node.getChildren().forEach(child -> recursivelyDestroy(child));
}
if(node.getData() != null){
node.getData().destroy();
}
}
/**
* Destroys two layers of nodes
* @param node The top node
*/
private void twoLayerDestroy(WorldOctTreeNode<BlockDrawCell> node){
if(!node.getData().hasGenerated()){
for(WorldOctTreeNode<BlockDrawCell> child : node.getChildren()){
child.getData().destroy();
}
} else {
node.getData().destroy();
}
}
/**
* Checks if the cell manager made an update last frame or not
* @return true if an update occurred, false otherwise

View File

@ -228,7 +228,7 @@ public class ClientDrawCellManager {
});
//do deletions
this.twoLayerDestroy(node);
this.recursivelyDestroy(node);
//update neighbors
this.conditionalUpdateAdjacentNodes(container, container.getChildren().get(0).getLevel());
@ -280,6 +280,9 @@ public class ClientDrawCellManager {
}
} else {
if(this.shouldJoin(playerPos, node, distCache)) {
if(node.getMinBound().x == 192 && node.getMinBound().y == 0 && node.getMinBound().z == 192){
System.out.println("Joining target node");
}
this.join(node);
updated = true;
} else {
@ -615,6 +618,7 @@ public class ClientDrawCellManager {
DrawCell newLeafCell = DrawCell.generateTerrainCell(node.getMinBound(),node.getData().lod);
WorldOctTreeNode<DrawCell> newLeaf = chunkTree.join(node, newLeafCell);
newLeaf.getData().transferChunkData(node.getData());
newLeaf.getData().setHasGenerated(false);
//update neighbors
this.conditionalUpdateAdjacentNodes(newLeaf, newLeaf.getLevel());
@ -741,27 +745,10 @@ public class ClientDrawCellManager {
private void recursivelyDestroy(WorldOctTreeNode<DrawCell> node){
if(node.getChildren().size() > 0){
for(WorldOctTreeNode<DrawCell> child : node.getChildren()){
child.getData().destroy();
this.recursivelyDestroy(child);
}
// node.getChildren().forEach(child -> recursivelyDestroy(child));
}
if(node.getData() != null){
node.getData().destroy();
}
}
/**
* Destroys two layers of nodes
* @param node The top node
*/
private void twoLayerDestroy(WorldOctTreeNode<DrawCell> node){
if(!node.getData().hasGenerated()){
for(WorldOctTreeNode<DrawCell> child : node.getChildren()){
child.getData().destroy();
}
} else {
node.getData().destroy();
}
node.getData().destroy();
}
/**

View File

@ -231,13 +231,14 @@ public class DrawCell {
*/
public void destroy(){
if(modelEntity != null){
Entity target = this.modelEntity;
Globals.clientScene.registerBehaviorTree(new BehaviorTree(){
int framesSimulated = 0;
public void simulate(float deltaTime) {
if(framesSimulated < FRAMES_TO_WAIT_BEFORE_DESTRUCTION){
framesSimulated++;
} else {
ClientEntityUtils.destroyEntity(modelEntity);
ClientEntityUtils.destroyEntity(target);
Globals.clientScene.deregisterBehaviorTree(this);
}
}

View File

@ -234,7 +234,7 @@ public class FoliageCellManager {
});
//do deletions
this.twoLayerDestroy(node);
this.recursivelyDestroy(node);
//update neighbors
this.conditionalUpdateAdjacentNodes(container, container.getChildren().get(0).getLevel());
@ -666,29 +666,14 @@ public class FoliageCellManager {
private void recursivelyDestroy(WorldOctTreeNode<FoliageCell> node){
if(node.getChildren().size() > 0){
for(WorldOctTreeNode<FoliageCell> child : node.getChildren()){
child.getData().destroy();
this.recursivelyDestroy(child);
}
// node.getChildren().forEach(child -> recursivelyDestroy(child));
}
if(node.getData() != null){
node.getData().destroy();
}
}
/**
* Destroys two layers of nodes
* @param node The top node
*/
private void twoLayerDestroy(WorldOctTreeNode<FoliageCell> node){
if(!node.getData().hasGenerated()){
for(WorldOctTreeNode<FoliageCell> child : node.getChildren()){
child.getData().destroy();
}
} else {
node.getData().destroy();
}
}
/**
* Checks if the cell manager made an update last frame or not
* @return true if an update occurred, false otherwise

View File

@ -16,6 +16,11 @@ public class NoiseVoxelGen implements VoxelGenerator {
*/
public static final int SURFACE_VOXEL_WIDTH = 2;
/**
* The voxel type for the floor of the world
*/
public static final int FLOOR_VOXEL_TYPE = 6;
/**
* The tag for the noise function that generates
*/
@ -49,6 +54,14 @@ public class NoiseVoxelGen implements VoxelGenerator {
int stride, double surfaceHeight, double surfaceGradient,
BiomeData surfaceBiome, GenerationContext generationContext
) {
//floor handling
if(realY < 1){
voxel.weight = 1.0f;
voxel.type = FLOOR_VOXEL_TYPE;
return;
}
double strideMultiplier = Math.pow(2,stride);
double heightDiff = realY - surfaceHeight;
double sample = 1.0;//this.sampler.getValue(0, realX, realY, realZ);