Update IDhApiRenderProxy.clearRenderDataCache() to also clear cached block colors

This commit is contained in:
James Seibel
2024-07-27 17:36:40 -05:00
parent 56303dd82a
commit 53300a3028
6 changed files with 28 additions and 13 deletions
@@ -26,7 +26,7 @@ import com.seibel.distanthorizons.api.objects.DhApiResult;
* Used to interact with Distant Horizons' rendering system.
*
* @author James Seibel
* @version 2023-10-13
* @version 2024-7-27
* @since API 1.0.0
*/
public interface IDhApiRenderProxy
@@ -39,10 +39,8 @@ public interface IDhApiRenderProxy
* If this is called on a dedicated server it won't do anything and will return {@link DhApiResult#success} = false <Br><Br>
*
* Background: <Br>
* Distant Horizons has two different file formats: Full data and Render data. <Br>
* - Full data files store the block, biome, etc. information and is the result of loading or generating new chunks. <Br>
* - Render data files store LOD colors and are created using the Full data and currently loaded resource packs. <Br>
* This is the data cleared by this method.
* When rendering Distant Horizons bakes each block's color into the geometry that's rendered. <Br>
* This improves rendering speed and VRAM size, but prevents dynamically changing LOD colors. <Br>
*/
DhApiResult<Boolean> clearRenderDataCache();
@@ -258,6 +258,8 @@ public class ClientLevelModule implements Closeable, AbstractDataSourceHandler.I
public void clearRenderCache()
{
this.clientLevel.getClientLevelWrapper().clearBlockColorCache();
ClientRenderState ClientRenderState = this.ClientRenderStateRef.get();
if (ClientRenderState != null && ClientRenderState.quadtree != null)
{
@@ -154,10 +154,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
public IClientLevelWrapper getClientLevelWrapper() { return MC_CLIENT.getWrappedClientLevel(); }
@Override
public void clearRenderCache()
{
clientside.clearRenderCache();
}
public void clearRenderCache() { this.clientside.clearRenderCache(); }
@Override
public IServerLevelWrapper getServerLevelWrapper() { return serverLevelWrapper; }
@@ -151,7 +151,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
}
catch (Exception e)
{
LOGGER.error("Quad Tree tick exception for dimension: " + this.level.getClientLevelWrapper().getDimensionType().getDimensionName() + ", exception: " + e.getMessage(), e);
LOGGER.error("Quad Tree tick exception for dimension: " + this.level.getLevelWrapper().getDimensionType().getDimensionName() + ", exception: " + e.getMessage(), e);
}
finally
{
@@ -515,8 +515,12 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
QuadNode<LodRenderSection> quadNode = nodeIterator.next();
if (quadNode.value != null)
{
quadNode.value.close();
quadNode.value = null;
if (quadNode.value.renderingEnabled)
{
quadNode.value.cancelGpuUpload();
quadNode.value.uploadRenderDataToGpuAsync();
}
}
}
@@ -306,6 +306,20 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
}
/**
* Note: can cause issues with neighboring LOD sections
* if only some (vs all) futures are canceled.
*/
public void cancelGpuUpload()
{
CompletableFuture<Void> future = this.uploadRenderDataToGpuFuture;
if (future != null)
{
future.cancel(true);
}
}
//========================//
// getters and properties //
@@ -33,9 +33,9 @@ public interface IClientLevelWrapper extends ILevelWrapper
IServerLevelWrapper tryGetServerSideWrapper();
int getBlockColor(DhBlockPos pos, IBiomeWrapper biome, IBlockStateWrapper blockState);
/** @return -1 if there was a problem getting the color */
int getDirtBlockColor();
void clearBlockColorCache();
/** Will return null if there was an issue finding the biome. */
@Nullable