Fix some beacon rendering/updating issues
This commit is contained in:
@@ -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<BeaconBeamDTO> beaconBeamList = chunkWrapper.getAllActiveBeacons(nearbyChunkList);
|
||||
dhLevel.setBeaconBeamsForChunk(chunkWrapper.getChunkPos(), beaconBeamList);
|
||||
|
||||
|
||||
dhLevel.updateBeaconBeamsForChunk(chunkWrapper, nearbyChunkList);
|
||||
dhLevel.updateChunkAsync(chunkWrapper, newChunkHash);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -701,6 +701,17 @@ public class Config
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Boolean> disableBeaconDistanceCulling = new ConfigEntry.Builder<Boolean>()
|
||||
.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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<BeaconBeamDTO> newBeamList)
|
||||
public void updateBeaconBeamsForChunk(IChunkWrapper chunkToUpdate, ArrayList<IChunkWrapper> nearbyChunkList)
|
||||
{
|
||||
if (this.beaconRenderHandler != null)
|
||||
{
|
||||
this.beaconRenderHandler.setBeaconBeamsForChunk(chunkPos, newBeamList);
|
||||
List<BeaconBeamDTO> activeBeamList = chunkToUpdate.getAllActiveBeacons(nearbyChunkList);
|
||||
this.beaconRenderHandler.setBeaconBeamsForChunk(chunkToUpdate.getChunkPos(), activeBeamList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<BeaconBeamDTO> beamList);
|
||||
void updateBeaconBeamsForChunk(IChunkWrapper chunkToUpdate, ArrayList<IChunkWrapper> nearbyChunkList);
|
||||
void unloadBeaconBeamsInPos(long pos);
|
||||
|
||||
FullDataSourceProviderV2 getFullDataProvider();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+22
-18
@@ -99,7 +99,7 @@ public class BeaconRenderHandler
|
||||
// level loading/unloading //
|
||||
//=========================//
|
||||
|
||||
public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List<BeaconBeamDTO> newBeamList)
|
||||
public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List<BeaconBeamDTO> 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<DhBlockPos> allPosSet = new HashSet<>();
|
||||
|
||||
// sort new beams
|
||||
HashMap<DhBlockPos, BeaconBeamDTO> newBeamByPos = new HashMap<>(newBeamList.size());
|
||||
for (int i = 0; i < newBeamList.size(); i++)
|
||||
HashMap<DhBlockPos, BeaconBeamDTO> 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)
|
||||
|
||||
+6
-2
@@ -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<DhBlockPos> 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)
|
||||
{
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user