From f3ef6f25f474937babcb798a361e9fec93320d84 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 1 Sep 2024 16:36:37 -0500 Subject: [PATCH] Fix some beacon rendering/updating issues --- .../core/api/internal/SharedApi.java | 9 +---- .../distanthorizons/core/config/Config.java | 11 +++++ .../core/level/AbstractDhLevel.java | 6 ++- .../distanthorizons/core/level/IDhLevel.java | 4 +- .../distanthorizons/core/pos/DhChunkPos.java | 4 +- .../renderer/generic/BeaconRenderHandler.java | 40 ++++++++++--------- .../chunk/IChunkWrapper.java | 8 +++- .../assets/distanthorizons/lang/en_us.json | 6 ++- 8 files changed, 53 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java index 11148c1ef..24d13a52a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java @@ -29,7 +29,6 @@ import com.seibel.distanthorizons.core.logging.f3.F3Screen; import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D; import com.seibel.distanthorizons.core.pos.DhChunkPos; import com.seibel.distanthorizons.core.render.renderer.DebugRenderer; -import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO; import com.seibel.distanthorizons.core.sql.repo.AbstractDhRepo; import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.util.TimerUtil; @@ -361,13 +360,7 @@ public class SharedApi - - - // get this chunk's active beacons - List beaconBeamList = chunkWrapper.getAllActiveBeacons(nearbyChunkList); - dhLevel.setBeaconBeamsForChunk(chunkWrapper.getChunkPos(), beaconBeamList); - - + dhLevel.updateBeaconBeamsForChunk(chunkWrapper, nearbyChunkList); dhLevel.updateChunkAsync(chunkWrapper, newChunkHash); } catch (Exception e) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index 94c2ed8d5..084b66d5b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -701,6 +701,17 @@ public class Config .addListener(ReloadLodsConfigEventHandler.INSTANCE) .build(); + public static ConfigEntry disableBeaconDistanceCulling = new ConfigEntry.Builder() + .set(false) + .comment("" + + "If true all beacons near the camera won't be drawn to prevent vanilla overdraw. \n" + + "If false all beacons will be rendered. \n" + + "\n" + + "Generally this should be left as false. It's main purpose is for debugging\n" + + "beacon updating/rendering.\n" + + "") + .build(); + } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/AbstractDhLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/AbstractDhLevel.java index 12baec1d0..064158e57 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/AbstractDhLevel.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/AbstractDhLevel.java @@ -39,6 +39,7 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.sql.SQLException; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -216,11 +217,12 @@ public abstract class AbstractDhLevel implements IDhLevel //=================// @Override - public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List newBeamList) + public void updateBeaconBeamsForChunk(IChunkWrapper chunkToUpdate, ArrayList nearbyChunkList) { if (this.beaconRenderHandler != null) { - this.beaconRenderHandler.setBeaconBeamsForChunk(chunkPos, newBeamList); + List activeBeamList = chunkToUpdate.getAllActiveBeacons(nearbyChunkList); + this.beaconRenderHandler.setBeaconBeamsForChunk(chunkToUpdate.getChunkPos(), activeBeamList); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/IDhLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/IDhLevel.java index cc73cf8fe..a56aafc44 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/IDhLevel.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/IDhLevel.java @@ -25,11 +25,11 @@ import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure; import com.seibel.distanthorizons.core.pos.DhChunkPos; import com.seibel.distanthorizons.core.render.RenderBufferHandler; import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer; -import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO; import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -48,7 +48,7 @@ public interface IDhLevel extends AutoCloseable void updateChunkAsync(IChunkWrapper chunk, int newChunkHash); void loadBeaconBeamsInPos(long pos); - void setBeaconBeamsForChunk(DhChunkPos chunkPos, List beamList); + void updateBeaconBeamsForChunk(IChunkWrapper chunkToUpdate, ArrayList nearbyChunkList); void unloadBeaconBeamsInPos(long pos); FullDataSourceProviderV2 getFullDataProvider(); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/pos/DhChunkPos.java b/core/src/main/java/com/seibel/distanthorizons/core/pos/DhChunkPos.java index e7eb36806..7af15a626 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/pos/DhChunkPos.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/pos/DhChunkPos.java @@ -86,8 +86,8 @@ public class DhChunkPos int maxBlockX = minBlockX + LodUtil.CHUNK_WIDTH; int maxBlockZ = minBlockZ + LodUtil.CHUNK_WIDTH; - return minBlockX <= pos.getX() && pos.getX() <= maxBlockX - && minBlockZ <= pos.getZ() && pos.getZ() <= maxBlockZ; + return minBlockX <= pos.getX() && pos.getX() < maxBlockX + && minBlockZ <= pos.getZ() && pos.getZ() < maxBlockZ; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java index 1ea603a3a..b9b93e014 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java @@ -99,7 +99,7 @@ public class BeaconRenderHandler // level loading/unloading // //=========================// - public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List newBeamList) + public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List activeBeamList) { // synchronized to prevent two threads from updating the same chunk at the same time synchronized (this) @@ -107,11 +107,11 @@ public class BeaconRenderHandler HashSet allPosSet = new HashSet<>(); // sort new beams - HashMap newBeamByPos = new HashMap<>(newBeamList.size()); - for (int i = 0; i < newBeamList.size(); i++) + HashMap activeBeamByPos = new HashMap<>(activeBeamList.size()); + for (int i = 0; i < activeBeamList.size(); i++) { - BeaconBeamDTO beam = newBeamList.get(i); - newBeamByPos.put(beam.blockPos, beam); + BeaconBeamDTO beam = activeBeamList.get(i); + activeBeamByPos.put(beam.blockPos, beam); allPosSet.add(beam.blockPos); } @@ -136,28 +136,28 @@ public class BeaconRenderHandler } BeaconBeamDTO existingBeam = existingBeamByPos.get(beaconPos); - BeaconBeamDTO newBeam = newBeamByPos.get(beaconPos); + BeaconBeamDTO activeBeam = activeBeamByPos.get(beaconPos); - if (existingBeam != null && newBeam != null) + if (existingBeam != null && activeBeam != null) { // beam still exists in chunk - if (!existingBeam.color.equals(newBeam.color)) + if (!existingBeam.color.equals(activeBeam.color)) { // beam colors were changed - this.beaconBeamRepo.save(newBeam); - this.updateBeaconColor(newBeam); + this.beaconBeamRepo.save(activeBeam); + this.updateBeaconColor(activeBeam); } } - else if (existingBeam == null && newBeam != null) + else if (existingBeam == null && activeBeam != null) { // new beam found, add to DB - this.beaconBeamRepo.save(newBeam); - this.startRenderingBeacon(newBeam); + this.beaconBeamRepo.save(activeBeam); + this.startRenderingBeacon(activeBeam); } - else if (existingBeam != null && newBeam == null) + else if (existingBeam != null && activeBeam == null) { // beam no longer exists at position, remove from DB - this.beaconBeamRepo.deleteWithKey(beaconPos); // TODO broken when updating adjacent chunks + this.beaconBeamRepo.deleteWithKey(beaconPos); this.stopRenderingBeaconAtPos(beaconPos); } @@ -274,9 +274,13 @@ public class BeaconRenderHandler private void beforeRender(DhApiRenderParam renderEventParam) { - // this could be called only when the player moves, but it's an extremely cheap check, - // so there isn't much of a reason to bother - this.tryUpdateBeaconCullingAsync(); + if (!Config.Client.Advanced.Graphics.AdvancedGraphics.disableBeaconDistanceCulling.get()) + { + // this could be called only when the player moves, but it's an extremely cheap check, + // so there isn't much of a reason to bother + this.tryUpdateBeaconCullingAsync(); + } + // this must be called on the render thread to prevent concurrency issues if (this.updateRenderDataNextFrame) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/chunk/IChunkWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/chunk/IChunkWrapper.java index 56cc08a78..3bcc287eb 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/chunk/IChunkWrapper.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/chunk/IChunkWrapper.java @@ -347,7 +347,8 @@ public interface IChunkWrapper extends IBindable AdjacentChunkHolder adjacentChunkHolder = new AdjacentChunkHolder(this, neighbourChunkList); - // since beacons emit light we can check only the positions that are emitting light + // find the beacon block positions, + // since beacons emit light we only need to check the positions that emit light final DhBlockPosMutable relPos = new DhBlockPosMutable(); ArrayList blockPosList = this.getWorldBlockLightPosList(); for (int i = 0; i < blockPosList.size(); i++) @@ -359,9 +360,11 @@ public interface IChunkWrapper extends IBindable IBlockStateWrapper block = this.getBlockState(relPos); if (block.isBeaconBlock()) { + // check if this beacon is active and if so what color it should be Color beaconColor = getBeaconColor(pos, adjacentChunkHolder); if (beaconColor != null) { + // beacon is active BeaconBeamDTO beam = new BeaconBeamDTO(blockPosList.get(i), beaconColor); beaconBeamList.add(beam); } @@ -390,7 +393,8 @@ public interface IChunkWrapper extends IBindable baseRelPos.setX(beaconRelPos.getX() + x); baseRelPos.setZ(beaconRelPos.getZ() + z); baseRelPos.mutateToChunkRelativePos(baseRelPos); - + + // if no chunk is loaded assume the beacon is complete in that direction IChunkWrapper chunk = chunkHolder.getByBlockPos(beaconPos.getX() + x, beaconPos.getZ() + z); if (chunk != null) { diff --git a/core/src/main/resources/assets/distanthorizons/lang/en_us.json b/core/src/main/resources/assets/distanthorizons/lang/en_us.json index 3cb3facb1..bded71d0a 100644 --- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json +++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json @@ -308,7 +308,11 @@ "distanthorizons.config.client.advanced.graphics.advancedGraphics.grassSideRendering": "Grass Side Rendering", "distanthorizons.config.client.advanced.graphics.advancedGraphics.grassSideRendering.@tooltip": - "How should the sides and bottom of grass block LODs render?", + "How should the sides and bottom of grass block LODs render?", + "distanthorizons.config.client.advanced.graphics.advancedGraphics.disableBeaconDistanceCulling": + "Disable Beacon Distance Culling", + "distanthorizons.config.client.advanced.graphics.advancedGraphics.disableBeaconDistanceCulling.@tooltip": + "If true all beacons near the camera won't be drawn to prevent vanilla overdraw. \nIf false all beacons will be rendered.", "distanthorizons.config.client.advanced.graphics.genericRendering":