Fixes for tasks never finishing

This commit is contained in:
mcrcortex
2024-08-01 15:51:20 +10:00
parent 7f5b84e6e7
commit 9b08c6e5ff
3 changed files with 13 additions and 7 deletions

View File

@@ -1,7 +1,9 @@
package me.cortex.voxy.client.core.model; package me.cortex.voxy.client.core.model;
public class IdNotYetComputedException extends RuntimeException { public class IdNotYetComputedException extends RuntimeException {
public final int id;
public IdNotYetComputedException(int id) { public IdNotYetComputedException(int id) {
super("Id not yet computed: " + id); super("Id not yet computed: " + id);
this.id = id;
} }
} }

View File

@@ -470,7 +470,6 @@ public class RenderDataFactory {
//TODO:FIXME SOMEHOW THIS IS CRITICAL!!!!!!!!!!!!!!!!!! //TODO:FIXME SOMEHOW THIS IS CRITICAL!!!!!!!!!!!!!!!!!!
// so there is one more issue need to be fixed, if water is layered ontop of eachother, the side faces depend on the water state ontop // so there is one more issue need to be fixed, if water is layered ontop of eachother, the side faces depend on the water state ontop
// this has been hackfixed in the model texture bakery but a proper solution that doesnt explode the sides of the water textures needs to be done // this has been hackfixed in the model texture bakery but a proper solution that doesnt explode the sides of the water textures needs to be done
@@ -488,13 +487,13 @@ public class RenderDataFactory {
//Returns true if a face was placed //Returns true if a face was placed
private boolean putFaceIfCan(Mesher2D mesher, int face, int opposingFace, long self, long metadata, int clientModelId, int selfBlockId, long facingState, long facingMetadata, int a, int b) { private boolean putFaceIfCan(Mesher2D mesher, int face, int opposingFace, long self, long metadata, int clientModelId, int selfBlockId, long facingState, long facingMetadata, int a, int b) {
//If face can be occluded and is occluded from the facing block, then dont render the face if (ModelQueries.cullsSame(metadata) && selfBlockId == Mapper.getBlockId(facingState)) {
if (ModelQueries.faceCanBeOccluded(metadata, face) && ModelQueries.faceOccludes(facingMetadata, opposingFace)) { //If we are facing a block, and we are both the same state, dont render that face
return false; return false;
} }
if (ModelQueries.cullsSame(metadata) && selfBlockId == Mapper.getBlockId(facingState)) { //If face can be occluded and is occluded from the facing block, then dont render the face
//If we are facing a block, and we are both the same state, dont render that face if (ModelQueries.faceCanBeOccluded(metadata, face) && ModelQueries.faceOccludes(facingMetadata, opposingFace)) {
return false; return false;
} }

View File

@@ -50,9 +50,10 @@ public class RenderGenerationService {
//NOTE: the biomes are always fully populated/kept up to date //NOTE: the biomes are always fully populated/kept up to date
//Asks the Model system to bake all blocks that currently dont have a model //Asks the Model system to bake all blocks that currently dont have a model
private void computeAndRequestRequiredModels(WorldSection section) { private void computeAndRequestRequiredModels(WorldSection section, int extraId) {
var raw = section.copyData();//TODO: replace with copyDataTo and use a "thread local"/context array to reduce allocation rates var raw = section.copyData();//TODO: replace with copyDataTo and use a "thread local"/context array to reduce allocation rates
IntOpenHashSet seen = new IntOpenHashSet(128); IntOpenHashSet seen = new IntOpenHashSet(128);
seen.add(extraId);
for (long state : raw) { for (long state : raw) {
int block = Mapper.getBlockId(state); int block = Mapper.getBlockId(state);
if (!this.modelBakery.factory.hasModelForBlockId(block)) { if (!this.modelBakery.factory.hasModelForBlockId(block)) {
@@ -85,6 +86,9 @@ public class RenderGenerationService {
try { try {
mesh = factory.generateMesh(section); mesh = factory.generateMesh(section);
} catch (IdNotYetComputedException e) { } catch (IdNotYetComputedException e) {
if (!this.modelBakery.factory.hasModelForBlockId(e.id)) {
this.modelBakery.requestBlockBake(e.id);
}
if (task.hasDoneModelRequest[0]) { if (task.hasDoneModelRequest[0]) {
try { try {
Thread.sleep(10); Thread.sleep(10);
@@ -92,7 +96,8 @@ public class RenderGenerationService {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} else { } else {
this.computeAndRequestRequiredModels(section); //The reason for the extra id parameter is that we explicitly add/check against the exception id due to e.g. requesting accross a chunk boarder wont be captured in the request
this.computeAndRequestRequiredModels(section, e.id);
} }
//We need to reinsert the build task into the queue //We need to reinsert the build task into the queue
//System.err.println("Render task failed to complete due to un-computed client id"); //System.err.println("Render task failed to complete due to un-computed client id");