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.
This commit is contained in:
James Seibel
2024-07-30 17:00:59 -05:00
parent f1564cc90b
commit defaea86f0
4 changed files with 1 additions and 205 deletions
@@ -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<DhChunkPos> posIter = MC_RENDER.getVanillaRenderedChunks().iterator();
return new EdgeDistanceBooleanGrid(new Iterator<Pos2D>()
{
@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. <br>
* If null returns the empty string.
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<BoolType>
{
ArrayGridList<Integer> edgeCache = null;
public EdgeDistanceBooleanGrid(Iterator<Pos2D> 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<Integer> 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<Integer>(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 <T extends ArrayGridList<BoolType>> 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);
});
}
}
@@ -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.
* <br>
* If not implemented this calls {@link #getMaximumRenderedChunks()}.
*/
default HashSet<DhChunkPos> 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);
}
/**
* <strong>Doesn't need to be implemented.</strong> <br>
* Returns every chunk position within the vanilla render distance.
*/
default HashSet<DhChunkPos> 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<DhChunkPos> renderedPos = new HashSet<DhChunkPos>();
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);
@@ -25,8 +25,6 @@ import java.util.HashSet;
public interface ISodiumAccessor extends IModAccessor
{
HashSet<DhChunkPos> 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