From defaea86f0fd6f83a0b8bf1257a52795917791ba Mon Sep 17 00:00:00 2001 From: James Seibel Date: Tue, 30 Jul 2024 17:00:59 -0500 Subject: [PATCH] Remove unused sodium and McRenderWrapper methods Removed methods were originally used to cull LODs if MC had loaded chunks, however this turned out to be more trouble than it was worth and caused more problems than it solved. --- .../distanthorizons/core/util/LodUtil.java | 39 +------ .../gridList/EdgeDistanceBooleanGrid.java | 100 ------------------ .../minecraft/IMinecraftRenderWrapper.java | 65 ------------ .../modAccessor/ISodiumAccessor.java | 2 - 4 files changed, 1 insertion(+), 205 deletions(-) delete mode 100644 core/src/main/java/com/seibel/distanthorizons/core/util/gridList/EdgeDistanceBooleanGrid.java diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java index ad9de0b90..8c652ebda 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java @@ -29,11 +29,8 @@ import java.util.concurrent.RejectedExecutionException; import com.seibel.distanthorizons.api.enums.config.EDhApiVanillaOverdraw; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; -import com.seibel.distanthorizons.core.pos.DhChunkPos; -import com.seibel.distanthorizons.core.pos.Pos2D; import com.seibel.distanthorizons.core.render.vertexFormat.DefaultLodVertexFormats; import com.seibel.distanthorizons.core.render.vertexFormat.LodVertexFormat; -import com.seibel.distanthorizons.core.util.gridList.EdgeDistanceBooleanGrid; import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException; import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper; @@ -223,36 +220,6 @@ public class LodUtil return offset; } - /** not currently used since the new rendering system can't easily toggle single chunks to render */ - @Deprecated - public static EdgeDistanceBooleanGrid readVanillaRenderedChunks() - { - int offset = computeOverdrawOffset(); - if (offset == Integer.MAX_VALUE) return null; - int renderDist = MC_RENDER.getRenderDistance() + 1; - - Iterator posIter = MC_RENDER.getVanillaRenderedChunks().iterator(); - - return new EdgeDistanceBooleanGrid(new Iterator() - { - @Override - public boolean hasNext() - { - return posIter.hasNext(); - } - - @Override - public Pos2D next() - { - DhChunkPos pos = posIter.next(); - return new Pos2D(pos.x, pos.z); - } - }, - MC_CLIENT.getPlayerChunkPos().x - renderDist, - MC_CLIENT.getPlayerChunkPos().z - renderDist, - renderDist * 2 + 1); - } - /** Returns the chunk int position for the given double position */ public static int getChunkPosFromDouble(double value) { return (int) Math.floor(value / CHUNK_WIDTH); } /** Returns the float position inside the chunk for the given double position */ @@ -275,11 +242,6 @@ public class LodUtil return true; } - public static void checkInterrupts() throws InterruptedException - { - if (Thread.interrupted()) throw new InterruptedException(); - } - /** * Format a given string with params using log4j's MessageFormat * @@ -295,6 +257,7 @@ public class LodUtil return LOGGER.getMessageFactory().newMessage(str, param).getFormattedMessage(); } + // TODO move /** * Returns a shortened version of the given string that is no longer than maxLength.
* If null returns the empty string. diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/gridList/EdgeDistanceBooleanGrid.java b/core/src/main/java/com/seibel/distanthorizons/core/util/gridList/EdgeDistanceBooleanGrid.java deleted file mode 100644 index c6f3dbcd5..000000000 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/gridList/EdgeDistanceBooleanGrid.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This file is part of the Distant Horizons mod - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2023 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.core.util.gridList; - -import com.seibel.distanthorizons.core.pos.Pos2D; -import com.seibel.distanthorizons.core.util.objects.BoolType; - -import java.util.Iterator; -import java.util.function.IntPredicate; - -public class EdgeDistanceBooleanGrid extends PosArrayGridList -{ - ArrayGridList edgeCache = null; - - public EdgeDistanceBooleanGrid(Iterator posIter, int offsetX, int offsetY, int gridSize) - { - super(gridSize, offsetX, offsetY); - while (posIter.hasNext()) - { - Pos2D p = posIter.next(); - this.set(p, BoolType.TRUE); - } - } - - // Return false if it is indeed updated - private static boolean updatePos(ArrayGridList grid, int ox, int oy) - { - if (grid.get(ox, oy) < 0) return true; - if (ox == 0 || oy == 0 || ox == grid.gridSize - 1 || oy == grid.gridSize - 1) - { - return true; - } - - int v = grid.get(ox, oy); - if ( - grid.get(ox, oy + 1) < v || - grid.get(ox, oy - 1) < v || - grid.get(ox + 1, oy) < v || - grid.get(ox - 1, oy) < v - ) - { - return true; - } - else - { - grid.set(ox, oy, v + 1); - return false; - } - } - - //FIXME: This is slow and expensive. Use queue to make this skip recheck done pos - private void computeEdgeCache() - { - if (edgeCache != null) return; - - edgeCache = new ArrayGridList(gridSize, (ox, oy) -> { - BoolType b = get(ox + getOffsetX(), oy + getOffsetY()); - return b == null ? -1 : 0; - }); - - final boolean[] isDone = {false}; - while (!isDone[0]) - { - isDone[0] = true; - edgeCache.forEachPos((ox, oy) -> { - isDone[0] &= updatePos(edgeCache, ox, oy); - }); - } - } - - // 0 means right on the edge, while 1 means 1 ceil away. Uses Manhattan Distance - public > void flagAllWithDistance(T list, IntPredicate predicate) - { - computeEdgeCache(); - edgeCache.forEachPos((ox, oy) -> { - int v = edgeCache.get(ox, oy); - if (v < 0 || !predicate.test(v)) return; - list.set(ox + getOffsetX(), oy + getOffsetY(), BoolType.TRUE); - }); - } - - -} diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper.java index 2fc860772..538f8cc0f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper.java @@ -48,18 +48,10 @@ public interface IMinecraftRenderWrapper extends IBindable { Vec3f getLookAtVector(); - DhBlockPos getCameraBlockPosition(); - boolean playerHasBlindingEffect(); Vec3d getCameraExactPosition(); - Mat4f getWorldViewMatrix(); - - Mat4f getDefaultProjectionMatrix(float partialTicks); - - double getGamma(); - Color getFogColor(float partialTicks); default Color getSpecialFogColor(float partialTicks) { return getFogColor(partialTicks); } @@ -90,63 +82,6 @@ public interface IMinecraftRenderWrapper extends IBindable */ void clearTargetFrameBuffer(); - /** - * This method returns the ChunkPos of all chunks that Minecraft - * is going to render this frame. - *
- * If not implemented this calls {@link #getMaximumRenderedChunks()}. - */ - default HashSet getVanillaRenderedChunks() - { - // FIXME: Is this actually required? Does it make a differance if it exists or not? - ISodiumAccessor sodium = ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class); - return sodium == null ? getMaximumRenderedChunks() : sodium.getNormalRenderedChunks(); - } - - static boolean correctedCheckRadius(int dx, int dz, int radius2Mul4) - { - dx = dx * 2;// + (dx < 0 ? -1 : 1); - dz = dz * 2;// + (dz < 0 ? -1 : 1); - return (dx * dx + dz * dz <= radius2Mul4); - } - - /** - * Doesn't need to be implemented.
- * Returns every chunk position within the vanilla render distance. - */ - default HashSet getMaximumRenderedChunks() - { - IMinecraftClientWrapper mcWrapper = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); - IWrapperFactory factory = SingletonInjector.INSTANCE.get(IWrapperFactory.class); - IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class); - IMinecraftClientWrapper minecraft = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); - ILevelWrapper clientWorld = minecraft.getWrappedClientLevel(); - - int chunkDist = this.getRenderDistance() + 1; // For some reason having '+1' is actually closer to real value - - DhChunkPos centerChunkPos = mcWrapper.getPlayerChunkPos(); - int centerChunkX = centerChunkPos.x; - int centerChunkZ = centerChunkPos.z; - int chunkDist2Mul4 = chunkDist * chunkDist * 4; - - // add every position within render distance - HashSet renderedPos = new HashSet(); - for (int deltaChunkX = -chunkDist; deltaChunkX <= chunkDist; deltaChunkX++) - { - for (int deltaChunkZ = -chunkDist; deltaChunkZ <= chunkDist; deltaChunkZ++) - { - if (!versionConstants.isVanillaRenderedChunkSquare() && - !correctedCheckRadius(deltaChunkX, deltaChunkZ, chunkDist2Mul4)) - { - continue; - } - if (!clientWorld.hasChunkLoaded(centerChunkX + deltaChunkX, centerChunkZ + deltaChunkZ)) continue; - renderedPos.add(new DhChunkPos(centerChunkX + deltaChunkX, centerChunkZ + deltaChunkZ)); - } - } - return renderedPos; - } - /** Can return null if the given level hasn't had a light map assigned to it */ @Nullable ILightMapWrapper getLightmapWrapper(ILevelWrapper level); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/modAccessor/ISodiumAccessor.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/modAccessor/ISodiumAccessor.java index 82ca5efc0..c7eda6885 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/modAccessor/ISodiumAccessor.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/modAccessor/ISodiumAccessor.java @@ -25,8 +25,6 @@ import java.util.HashSet; public interface ISodiumAccessor extends IModAccessor { - HashSet getNormalRenderedChunks(); - /** A temporary overwrite for a config in sodium 0.5 to fix their terrain from showing, will be removed once a proper fix is added */ void setFogOcclusion(boolean b); // FIXME