diff options
author | makamys <makamys@outlook.com> | 2022-06-24 09:59:15 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-25 07:27:12 +0200 |
commit | d5d08eb64a91c1a5b74e401037628260cfd8059c (patch) | |
tree | bf28db78fa10f92a28e82639943fe3cc409ee514 /src/main/java | |
parent | 41c8ac491b8e168f871e8d5eec1a13208e272410 (diff) | |
download | Neodymium-d5d08eb64a91c1a5b74e401037628260cfd8059c.tar.gz Neodymium-d5d08eb64a91c1a5b74e401037628260cfd8059c.tar.bz2 Neodymium-d5d08eb64a91c1a5b74e401037628260cfd8059c.zip |
DESTROOOOY
Delete unused LOD stuff. I can always restore it from Git history if I need it
later.
Diffstat (limited to 'src/main/java')
18 files changed, 40 insertions, 1181 deletions
diff --git a/src/main/java/makamys/neodymium/Config.java b/src/main/java/makamys/neodymium/Config.java index 48f46c9..6c72fde 100644 --- a/src/main/java/makamys/neodymium/Config.java +++ b/src/main/java/makamys/neodymium/Config.java @@ -21,10 +21,6 @@ import java.nio.file.Files; import java.nio.file.WatchEvent; import java.nio.file.WatchKey; import java.nio.file.WatchService; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; import org.lwjgl.input.Keyboard; @@ -64,18 +60,6 @@ public class Config { @ConfigBoolean(cat="debug", def=false) public static boolean wireframe; - // Unused LOD stuff - public static int chunkLoadsPerTick = 64; - public static List<Class<?>> blockClassBlacklist = Arrays.asList(); - public static double fogStart = 0.25f; - public static double fogEnd = 1f; - public static double farPlaneDistanceMultiplier = 1; - public static boolean forceVanillaBiomeTemperature = false; - public static boolean hideUnderVanillaChunks = false; - public static boolean disableChunkMeshes = false; - public static boolean disableSimpleMeshes = true; - public static boolean saveMeshes = false; - private static File configFile = new File(Launch.minecraftHome, "config/" + MODID + ".cfg"); private static WatchService watcher; @@ -169,29 +153,6 @@ public class Config { return needReload; } - // Unused - public static void loadConfigLOD(Configuration config) { - chunkLoadsPerTick = config.get("General", "chunkLoadsPerTick", 64).getInt(); - blockClassBlacklist = Arrays.stream(config.get("General", "blockClassBlacklist", "net.minecraft.block.BlockRotatedPillar;biomesoplenty.common.blocks.BlockBOPLog;gregapi.block.multitileentity.MultiTileEntityBlock").getString().split(";")) - .map(className -> { - try { - return Class.forName(className); - } catch (ClassNotFoundException e) { - return null; - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - fogStart = config.get("Fog", "fogStart", "0.4").getDouble(); - fogEnd = config.get("Fog", "fogEnd", "0.8").getDouble(); - farPlaneDistanceMultiplier = config.get("Fog", "farPlaneDistanceMultiplier", "1.0").getDouble(); - forceVanillaBiomeTemperature = config.get("Simple mesh generation", "forceVanillaBiomeTemperature", true).getBoolean(); - hideUnderVanillaChunks = config.getBoolean("hideUnderVanillaChunks", "render", true, ""); - disableChunkMeshes = config.getBoolean("disableChunkMeshes", "render", true, ""); - disableSimpleMeshes = config.getBoolean("disableSimpleMeshes", "render", false, ""); - saveMeshes = config.getBoolean("saveMeshes", "render", false, ""); - } - public static boolean reloadIfChanged(ReloadInfo info) { boolean reloaded = false; if(watcher != null) { diff --git a/src/main/java/makamys/neodymium/MixinConfigPlugin.java b/src/main/java/makamys/neodymium/MixinConfigPlugin.java index a2357d4..38d6304 100644 --- a/src/main/java/makamys/neodymium/MixinConfigPlugin.java +++ b/src/main/java/makamys/neodymium/MixinConfigPlugin.java @@ -9,19 +9,15 @@ import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import makamys.neodymium.util.OFUtil; + public class MixinConfigPlugin implements IMixinConfigPlugin { - private static boolean isOptiFinePresent = MixinConfigPlugin.class.getResource("/optifine/OptiFineTweaker.class") != null; - @Override - public void onLoad(String mixinPackage) { - // TODO Auto-generated method stub - - } + public void onLoad(String mixinPackage) {} @Override public String getRefMapperConfig() { - // TODO Auto-generated method stub return null; } @@ -31,10 +27,7 @@ public class MixinConfigPlugin implements IMixinConfigPlugin { } @Override - public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { - // TODO Auto-generated method stub - - } + public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {} @Override public List<String> getMixins() { @@ -43,7 +36,7 @@ public class MixinConfigPlugin implements IMixinConfigPlugin { "MixinRenderGlobal", "MixinWorldRenderer")); - if (isOptiFinePresent()) { + if (OFUtil.isOptiFinePresent()) { System.out.println("Detected OptiFine"); mixins.add("MixinRenderGlobal_OptiFine"); } @@ -52,19 +45,9 @@ public class MixinConfigPlugin implements IMixinConfigPlugin { } @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - // TODO Auto-generated method stub - - } + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - // TODO Auto-generated method stub - - } - - public static boolean isOptiFinePresent() { - return isOptiFinePresent; - } + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} } diff --git a/src/main/java/makamys/neodymium/Neodymium.java b/src/main/java/makamys/neodymium/Neodymium.java index 4a59426..e8a0c5c 100644 --- a/src/main/java/makamys/neodymium/Neodymium.java +++ b/src/main/java/makamys/neodymium/Neodymium.java @@ -1,16 +1,9 @@ package makamys.neodymium; -import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Objects; -import java.util.stream.Collectors; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.lwjgl.input.Keyboard; - import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; @@ -25,18 +18,16 @@ import cpw.mods.fml.relauncher.SideOnly; import makamys.mclib.core.MCLib; import makamys.mclib.core.MCLibModules; import makamys.neodymium.renderer.NeoRenderer; -import makamys.neodymium.util.SpriteUtil; +import makamys.neodymium.util.OFUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; -import net.minecraftforge.client.event.EntityViewRenderEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.WorldEvent; @Mod(modid = Neodymium.MODID, version = Neodymium.VERSION) @@ -51,8 +42,6 @@ public class Neodymium public static NeoRenderer renderer; - public static boolean fogEventWasPosted; - public static boolean ofFastRender; private static Method ofIsFastRenderMethod; @@ -84,9 +73,6 @@ public class Neodymium private void onPlayerWorldChanged(World newWorld) { if(getRendererWorld() == null && newWorld != null) { Config.reloadConfig(); - if(Config.enabled) { - SpriteUtil.init(); - } } if(renderer != null) { renderer.destroy(); @@ -107,15 +93,6 @@ public class Neodymium } } - @SubscribeEvent - public void onChunkLoad(ChunkEvent.Load event) { - if(!event.world.isRemote) return; - - if(isActive()) { - renderer.onChunkLoad(event); - } - } - public static boolean isActive() { return renderer != null && renderer.hasInited && !renderer.destroyPending; } @@ -142,22 +119,11 @@ public class Neodymium } @SubscribeEvent - public void onServerTick(TickEvent.ServerTickEvent event) { - if(!Config.enabled) return; - - if(event.phase == TickEvent.Phase.START) { - if(isActive()) { - renderer.serverTick(); - } - } - } - - @SubscribeEvent public void onRenderTick(TickEvent.RenderTickEvent event) { if(!Config.enabled) return; if(event.phase == TickEvent.Phase.START) { - if(MixinConfigPlugin.isOptiFinePresent()) { + if(OFUtil.isOptiFinePresent()) { try { if(ofIsFastRenderMethod == null) { ofIsFastRenderMethod = Class.forName("Config").getMethod("isFastRender"); @@ -199,12 +165,6 @@ public class Neodymium } } - - @SubscribeEvent - public void onRenderFog(EntityViewRenderEvent.RenderFogEvent event) { - fogEventWasPosted = true; - } - public static boolean shouldRenderVanillaWorld() { return !isActive() || (isActive() && renderer.renderWorld && !renderer.rendererActive); } diff --git a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java index 997ac67..a45257f 100644 --- a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java +++ b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java @@ -3,46 +3,28 @@ package makamys.neodymium.mixin; import java.util.ArrayList; import java.util.List; -import org.lwjgl.opengl.GL11; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import makamys.neodymium.Config; import makamys.neodymium.Neodymium; import makamys.neodymium.ducks.IWorldRenderer; import makamys.neodymium.renderer.ChunkMesh; import makamys.neodymium.renderer.NeoRenderer; -import makamys.neodymium.renderer.lod.FarChunkCache; -import makamys.neodymium.renderer.lod.FarWorldRenderer; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.ChunkCache; -import net.minecraft.world.World; /** Inserts hooks in WorldRenderer to listen for changes, and to grab the tessellator data right before rendering. */ @Mixin(WorldRenderer.class) abstract class MixinWorldRenderer implements IWorldRenderer { @Shadow - public int posX; - @Shadow - public int posY; - @Shadow - public int posZ; - - @Shadow private boolean isInFrustum; @Shadow public boolean[] skipRenderPass; - @Shadow - private int glRenderList; @Shadow public boolean needsUpdate; @@ -52,22 +34,6 @@ abstract class MixinWorldRenderer implements IWorldRenderer { public List<ChunkMesh> chunkMeshes; - @Redirect(method = "setPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderAABB(Lnet/minecraft/util/AxisAlignedBB;)V")) - private void redirectRenderAABB(AxisAlignedBB p1) { - if(!FarWorldRenderer.class.isInstance(this.getClass())) { - RenderItem.renderAABB(p1); - } - } - - @Redirect(method = "updateRenderer", at = @At(value = "NEW", target = "Lnet/minecraft/world/ChunkCache;")) - private ChunkCache redirectConstructChunkCache(World p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { - if(!FarWorldRenderer.class.isInstance(this.getClass())) { - return new ChunkCache(p1, p2, p3, p4, p5, p6, p7, p8); - } else { - return new FarChunkCache(p1, p2, p3, p4, p5, p6, p7, p8); - } - } - @Inject(method = "updateRenderer", at = @At(value = "HEAD")) private void preUpdateRenderer(CallbackInfo ci) { saveDrawnStatus(); @@ -101,49 +67,13 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Inject(method = "postRenderBlocks", at = @At(value = "HEAD")) private void prePostRenderBlocks(int pass, EntityLivingBase entity, CallbackInfo ci) { - if(insideUpdateRenderer && Neodymium.isActive() && !Config.disableChunkMeshes) { + if(insideUpdateRenderer && Neodymium.isActive()) { if(chunkMeshes != null) { chunkMeshes.add(ChunkMesh.fromTessellator(pass, WorldRenderer.class.cast(this), Tessellator.instance)); } } } - @Redirect(method = "postRenderBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()I")) - private int redirectPostRenderBlocksDraw() { - if(!FarWorldRenderer.class.isInstance(this.getClass())) { - return Tessellator.instance.draw(); - } else { - Tessellator.instance.reset(); - return 0; - } - } - - // There's probably a nicer way to do this - - @Redirect(method = "postRenderBlocks", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glPopMatrix()V")) - private void redirectPostRenderBlocksGL1() { - if(!FarWorldRenderer.class.isInstance(this.getClass())) { - GL11.glPopMatrix(); - } - } - - @Redirect(method = "postRenderBlocks", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glEndList()V")) - private void redirectPostRenderBlocksGL2() { - if(!FarWorldRenderer.class.isInstance(this.getClass())) { - GL11.glEndList(); - } - } - - // XXX this is inconsistent, Forge callbacks are preserved in postRenderBlocks but not preRenderBlocks - - @Inject(method = "preRenderBlocks", at = @At(value = "HEAD")) - private void preRenderBlocksInjector(CallbackInfo ci) { - if(FarWorldRenderer.class.isInstance(this.getClass())) { - Tessellator.instance.setTranslation((double)(-this.posX), (double)(-this.posY), (double)(-this.posZ)); - ci.cancel(); - } - } - @Inject(method = "setDontDraw", at = @At(value = "HEAD")) private void preSetDontDraw(CallbackInfo ci) { if(Neodymium.isActive()) { diff --git a/src/main/java/makamys/neodymium/mixin/unused/lod/MixinChunkCache.java b/src/main/java/makamys/neodymium/mixin/unused/lod/MixinChunkCache.java deleted file mode 100644 index 98dce9d..0000000 --- a/src/main/java/makamys/neodymium/mixin/unused/lod/MixinChunkCache.java +++ /dev/null @@ -1,29 +0,0 @@ -package makamys.neodymium.mixin.unused.lod; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import makamys.neodymium.Neodymium; -import makamys.neodymium.renderer.lod.FarChunkCache; -import net.minecraft.world.ChunkCache; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; - -/** Unused remnant from LODMod. Handles reusage of Chunks when a LOD chunk becomes loaded. */ -@Mixin(ChunkCache.class) -abstract class MixinChunkCache { - - @Redirect(method = "<init>*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getChunkFromChunkCoords(II)Lnet/minecraft/world/chunk/Chunk;")) - private Chunk redirectGetChunkFromChunkCoords(World world, int p1, int p2) { - Chunk chunk = world.getChunkFromChunkCoords(p1, p2); - if(Neodymium.isActive() && FarChunkCache.class.isInstance(this.getClass()) && chunk.isEmpty()) { - Chunk myChunk = Neodymium.renderer.getChunkFromChunkCoords(p1, p2); - if(myChunk != null) { - chunk = myChunk; - } - } - return chunk; - } - -} diff --git a/src/main/java/makamys/neodymium/mixin/unused/lod/MixinEntityRenderer.java b/src/main/java/makamys/neodymium/mixin/unused/lod/MixinEntityRenderer.java deleted file mode 100644 index 7ddade1..0000000 --- a/src/main/java/makamys/neodymium/mixin/unused/lod/MixinEntityRenderer.java +++ /dev/null @@ -1,32 +0,0 @@ -package makamys.neodymium.mixin.unused.lod; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import makamys.neodymium.Neodymium; -import net.minecraft.client.renderer.EntityRenderer; - -/** Unused remnant from LODMod. Handles changing fog distance. */ -@Mixin(EntityRenderer.class) -abstract class MixinEntityRenderer { - - @Shadow - private float farPlaneDistance; - - @Inject(method = "setupCameraTransform", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F", shift = At.Shift.AFTER, ordinal = 1)) - private void onConstructed(CallbackInfo ci) { - if(Neodymium.isActive()) { - farPlaneDistance *= Neodymium.renderer.getFarPlaneDistanceMultiplier(); - } - } - - @Inject(method = "setupFog", at = @At(value = "RETURN")) - private void afterSetupFog(int mode, float alpha, CallbackInfo ci) { - if(Neodymium.isActive()) { - Neodymium.renderer.afterSetupFog(mode, alpha, farPlaneDistance); - } - } -} diff --git a/src/main/java/makamys/neodymium/mixin/unused/lod/MixinRenderBlocks.java b/src/main/java/makamys/neodymium/mixin/unused/lod/MixinRenderBlocks.java deleted file mode 100644 index 0af9799..0000000 --- a/src/main/java/makamys/neodymium/mixin/unused/lod/MixinRenderBlocks.java +++ /dev/null @@ -1,25 +0,0 @@ -package makamys.neodymium.mixin.unused.lod; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import makamys.neodymium.Neodymium; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.world.IBlockAccess; - -/** Unused remnant from LODMod. Disables a wall being drawn on the edges of chunks facing unloaded chunks. */ -@Mixin(RenderBlocks.class) -abstract class MixinRenderBlocks { - - @Redirect(method = "renderBlockLiquid", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;shouldSideBeRendered(Lnet/minecraft/world/IBlockAccess;IIII)Z")) - public boolean shouldSideBeRendered(Block block, IBlockAccess ba, int x, int y, int z, int w) { - if(Neodymium.isActive()) { - return Neodymium.renderer.shouldSideBeRendered(block, ba, x, y, z, w); - } else { - return block.shouldSideBeRendered(ba, x, y, z, w); - } - } - -} diff --git a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java index c1616f2..47c082e 100644 --- a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java +++ b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java @@ -1,35 +1,24 @@ package makamys.neodymium.renderer; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.FloatBuffer; import java.nio.IntBuffer; -import java.nio.ShortBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; - import org.lwjgl.BufferUtils; import makamys.neodymium.Config; -import makamys.neodymium.MixinConfigPlugin; import makamys.neodymium.Neodymium; import makamys.neodymium.ducks.IWorldRenderer; import makamys.neodymium.util.BufferWriter; +import makamys.neodymium.util.OFUtil; import makamys.neodymium.util.RecyclingList; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagByteArray; import net.minecraft.tileentity.TileEntity; /** A mesh for a 16x16x16 region of the world. */ @@ -39,9 +28,6 @@ public class ChunkMesh extends Mesh { private int[] subMeshStart = new int[NORMAL_ORDER.length]; - // TODO move this somewhere else - List<String> nameList = (List<String>) ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).mapUploadedSprites.keySet().stream().collect(Collectors.toList()); - public static int usedRAM = 0; public static int instances = 0; @@ -76,9 +62,6 @@ public class ChunkMesh extends Mesh { instances++; } - private static int totalOriginalQuadCount = 0; - private static int totalSimplifiedQuadCount = 0; - public static ChunkMesh fromTessellator(int pass, WorldRenderer wr, Tessellator t) { if(t.vertexCount % 4 != 0) { System.out.println("Error: Vertex count is not a multiple of 4"); @@ -89,7 +72,7 @@ public class ChunkMesh extends Mesh { int yOffset = wr.posY; int zOffset = wr.posZ; - boolean fr = MixinConfigPlugin.isOptiFinePresent() && Neodymium.ofFastRender; + boolean fr = OFUtil.isOptiFinePresent() && Neodymium.ofFastRender; int tessellatorXOffset = fr ? 0 : xOffset; int tessellatorYOffset = fr ? 0 : yOffset; int tessellatorZOffset = fr ? 0 : zOffset; @@ -134,10 +117,6 @@ public class ChunkMesh extends Mesh { int quadCount = countValidQuads(quads); - totalOriginalQuadCount += quads.size(); - totalSimplifiedQuadCount += quadCount; - //System.out.println("simplified quads " + totalOriginalQuadCount + " -> " + totalSimplifiedQuadCount + " (ratio: " + ((float)totalSimplifiedQuadCount / (float)totalOriginalQuadCount) + ") totalMergeCountByPlane: " + Arrays.toString(totalMergeCountByPlane)); - if(quadCount > 0) { return new ChunkMesh( (int)(xOffset / 16), (int)(yOffset / 16), (int)(zOffset / 16), @@ -248,69 +227,10 @@ public class ChunkMesh extends Mesh { destroy(); } - public void update() { - } - - // Java is weird. - public static short readShortAt(DataInputStream in, int offset) { - try { - in.reset(); - in.skip(offset); - return in.readShort(); - } catch(IOException e) { - return -1; - } - } - - public static short readShortAt(byte[] data, int offset) { - return (short)(Byte.toUnsignedInt(data[offset]) << 8 | Byte.toUnsignedInt(data[offset + 1])); - } - - public static int readIntAt(DataInputStream in, int offset) { - try { - in.reset(); - in.skip(offset); - return in.readInt(); - } catch(IOException e) { - return -1; - } - } - - public static int readIntAt(byte[] data, int offset) { - return (int)(Byte.toUnsignedLong(data[offset]) << 24 | Byte.toUnsignedLong(data[offset + 1]) << 16 | Byte.toUnsignedLong(data[offset + 2]) << 8 | Byte.toUnsignedLong(data[offset + 3])); - } - public int getStride() { return MeshQuad.getStride(); } - static void saveChunks(List<Integer> coords) { - System.out.println("saving " + (coords.size() / 3) + " cchunks"); - for(int i = 0; i < coords.size(); i += 3) { - if(i % 300 == 0) { - System.out.println((i / 3) + " / " + (coords.size() / 3)); - } - int theX = coords.get(i); - int theY = coords.get(i + 1); - int theZ = coords.get(i + 2); - - WorldRenderer wr = new WorldRenderer(Minecraft.getMinecraft().theWorld, new ArrayList<TileEntity>(), theX * 16, theY * 16, theZ * 16, 100000); - /* - if (this.occlusionEnabled) - { - this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4].glOcclusionQuery = this.glOcclusionQueryBase.get(var3); - }*/ - - wr.isWaitingOnOcclusionQuery = false; - wr.isVisible = true; - wr.isInFrustum = true; - wr.chunkIndex = 0; - wr.markDirty(); - wr.updateRenderer(Minecraft.getMinecraft().thePlayer); - } - //Tessellator.endSave(); - } - static List<ChunkMesh> getChunkMesh(int theX, int theY, int theZ) { WorldRenderer wr = new WorldRenderer(Minecraft.getMinecraft().theWorld, new ArrayList<TileEntity>(), theX * 16, theY * 16, theZ * 16, 100000); diff --git a/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java b/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java index 882b0c6..cb08c43 100644 --- a/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java +++ b/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java @@ -85,27 +85,6 @@ public class GPUMemoryManager { glBindBuffer(GL_ARRAY_BUFFER, 0); } - private int malloc(int size) { - int nextBase = 0; - if(!sentMeshes.isEmpty()) { - if(nextMesh < sentMeshes.size() - 1) { - Mesh next = sentMeshes.get(nextMesh); - Mesh nextnext = sentMeshes.get(nextMesh + 1); - if(nextnext.offset - next.getEnd() >= size) { - return next.getEnd(); - } - } - - nextBase = sentMeshes.get(sentMeshes.size() - 1).getEnd(); - } - - if(nextBase + size >= bufferSize) { - return -1; - } else { - return nextBase; - } - } - private int end() { return (sentMeshes.isEmpty() ? 0 : sentMeshes.get(sentMeshes.size() - 1).getEnd()); } diff --git a/src/main/java/makamys/neodymium/renderer/MeshQuad.java b/src/main/java/makamys/neodymium/renderer/MeshQuad.java index 1d2c196..71daf1a 100644 --- a/src/main/java/makamys/neodymium/renderer/MeshQuad.java +++ b/src/main/java/makamys/neodymium/renderer/MeshQuad.java @@ -66,21 +66,6 @@ public class MeshQuad { private static Vector3f vectorB = new Vector3f(); private static Vector3f vectorC = new Vector3f(); - private int minPositive(int a, int b) { - if(a == -1) { - return b; - } else { - return a < b ? a : b; - } - } - private int maxPositive(int a, int b) { - if(a == -1) { - return b; - } else { - return a > b ? a : b; - } - } - private void read(int[] rawBuffer, int offset, int offsetX, int offsetY, int offsetZ) { for(int vi = 0; vi < 4; vi++) { int i = offset + vi * 8; @@ -146,10 +131,6 @@ public class MeshQuad { mergeReference = null; } - public MeshQuad() { - - } - public void writeToBuffer(BufferWriter out) throws IOException { for(int vertexI = 0; vertexI < 4; vertexI++) { int vi = vertexI; diff --git a/src/main/java/makamys/neodymium/renderer/NeoChunk.java b/src/main/java/makamys/neodymium/renderer/NeoChunk.java index e7c3cab..b5e544b 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoChunk.java +++ b/src/main/java/makamys/neodymium/renderer/NeoChunk.java @@ -2,10 +2,8 @@ package makamys.neodymium.renderer; import java.util.List; -import makamys.neodymium.Config; import makamys.neodymium.Neodymium; import net.minecraft.entity.Entity; -import net.minecraft.world.chunk.Chunk; /** A container for the meshes that compose a chunk (16x256x16 region). It keeps track of which meshes should be made visible and which ones should not. */ public class NeoChunk { @@ -18,7 +16,6 @@ public class NeoChunk { boolean discardedMesh; NeoRegion region; - SimpleChunkMesh[] simpleMeshes = new SimpleChunkMesh[2]; ChunkMesh[] chunkMeshes = new ChunkMesh[32]; public boolean[] isSectionVisible = new boolean[16]; @@ -30,25 +27,7 @@ public class NeoChunk { this.z = z; this.region = region; } - /* - public LODChunk(NBTTagCompound nbt, List<String> spriteList) { - this.x = nbt.getInteger("x"); - this.z = nbt.getInteger("z"); - - loadChunkMeshesNBT(nbt.getCompoundTag("chunkMeshes"), spriteList); - } - private void loadChunkMeshesNBT(NBTTagCompound chunkMeshesCompound, List<String> spriteList) { - for(Object o : chunkMeshesCompound.func_150296_c()) { - String key = (String)o; - int keyInt = Integer.parseInt(key); - - byte[] data = chunkMeshesCompound.getByteArray(key); - - chunkMeshes[keyInt] = new ChunkMesh(x, keyInt / 2, z, new ChunkMesh.Flags(true, true, true, false), data.length / (2 + 4 * (3 + 2 + 2 + 4)), data, spriteList, keyInt % 2); - } - } - */ @Override public String toString() { return "LODChunk(" + x + ", " + z + ")"; @@ -64,9 +43,7 @@ public class NeoChunk { if(chunkMeshes[cy * 2 + i] != null) { if(newChunkMesh != null) { // ??? why is this needed? - if(newChunkMesh != null) { - newChunkMesh.pass = i; - } + newChunkMesh.pass = i; } renderer.removeMesh(chunkMeshes[cy * 2 + i]); @@ -81,23 +58,6 @@ public class NeoChunk { discardedMesh = false; } - // nice copypasta - public void putSimpleMeshes(List<SimpleChunkMesh> newSimpleMeshes) { - for(int i = 0; i < 2; i++) { - SimpleChunkMesh newSimpleMesh = newSimpleMeshes.size() > i ? newSimpleMeshes.get(i) : null; - if(simpleMeshes[i] != null) { - if(newSimpleMesh != null) { - newSimpleMesh.pass = i; - } - - renderer.setMeshVisible(simpleMeshes[i], false); - simpleMeshes[i].destroy(); - } - simpleMeshes[i] = newSimpleMesh; - } - Neodymium.renderer.lodChunkChanged(this); - } - public boolean hasChunkMeshes() { for(ChunkMesh cm : chunkMeshes) { if(cm != null) { @@ -107,19 +67,8 @@ public class NeoChunk { return false; } - public void tick(Entity player) { - if(Config.disableSimpleMeshes) { - setLOD(2); - } else { - double distSq = distSq(player); - if(Config.disableSimpleMeshes || distSq < Math.pow((Neodymium.renderer.renderRange / 2) * 16, 2)) { - setLOD(2); - } else if(distSq < Math.pow((Neodymium.renderer.renderRange) * 16, 2)) { - setLOD(1); - } else { - setLOD(0); - } - } + public void tick() { + setLOD(2); } public void setLOD(int lod) { @@ -140,35 +89,8 @@ public class NeoChunk { } } } - /* - public NBTTagCompound saveToNBT(NBTTagCompound oldNbt, List<String> oldStringTable) { - NBTTagCompound nbt = new NBTTagCompound(); - nbt.setInteger("x", x); - nbt.setInteger("z", z); - - NBTTagCompound chunkMeshesCompound = oldNbt == null ? new NBTTagCompound() : oldNbt.getCompoundTag("chunkMeshes"); - if(!discardedMesh) { - for(int i = 0; i < chunkMeshes.length; i++) { - if(chunkMeshes[i] != null) { - chunkMeshesCompound.setTag(String.valueOf(i), chunkMeshes[i].nbtData); - } - } - } else if(oldNbt != null && discardedMesh && lod == 2) { - loadChunkMeshesNBT(chunkMeshesCompound, oldStringTable); - Neodymium.renderer.lodChunkChanged(this); - } - nbt.setTag("chunkMeshes", chunkMeshesCompound); - dirty = false; - return nbt; - } - */ + public void destroy() { - for(SimpleChunkMesh scm: simpleMeshes) { - if(scm != null) { - scm.destroy(); - region.meshes--; - } - } for(ChunkMesh cm: chunkMeshes) { if(cm != null) { cm.destroy(); @@ -178,12 +100,6 @@ public class NeoChunk { Neodymium.renderer.setVisible(this, false); } - public void receiveChunk(Chunk chunk) { - if(!Config.disableSimpleMeshes) { - putSimpleMeshes(SimpleChunkMesh.generateSimpleMeshes(chunk)); - } - } - public boolean isFullyVisible() { if(!visible) return false; for(boolean b : isSectionVisible) { @@ -195,11 +111,6 @@ public class NeoChunk { } public boolean isEmpty() { - for(SimpleChunkMesh scm: simpleMeshes) { - if(scm != null) { - return false; - } - } for(ChunkMesh cm: chunkMeshes) { if(cm != null) { return false; diff --git a/src/main/java/makamys/neodymium/renderer/NeoRegion.java b/src/main/java/makamys/neodymium/renderer/NeoRegion.java index 40aaf7d..2e4570b 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRegion.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRegion.java @@ -3,7 +3,6 @@ package makamys.neodymium.renderer; import java.nio.file.Path; import net.minecraft.entity.Entity; -import net.minecraft.world.chunk.Chunk; public class NeoRegion { @@ -25,96 +24,11 @@ public class NeoRegion { } } } - /* - public LODRegion(int regionX, int regionZ, NBTTagCompound nbt) { - this.regionX = regionX; - this.regionZ = regionZ; - - NBTTagList list = nbt.getTagList("chunks", NBT.TAG_COMPOUND); - List<String> stringTable = Arrays.asList(nbt.getString("stringTable").split("\\n")); - - int idx = 0; - for(int i = 0; i < 32; i++) { - for(int j = 0; j < 32; j++) { - data[i][j] = new LODChunk(list.getCompoundTagAt(idx++), stringTable); - if(data[i][j].hasChunkMeshes()) { - Neodymium.renderer.setVisible(data[i][j], true); - } - } - } - } - */ + public static NeoRegion load(Path saveDir, int regionX, int regionZ) { - /*if(!(.disableChunkMeshes || !.saveMeshes)) { - File saveFile = getSavePath(saveDir, regionX, regionZ).toFile(); - if(saveFile.exists()) { - try { - NBTTagCompound nbt = CompressedStreamTools.readCompressed(new FileInputStream(saveFile)); - return new LODRegion(regionX, regionZ, nbt); - } catch (Exception e) { - e.printStackTrace(); - } - } - }*/ return new NeoRegion(regionX, regionZ); } - /* - private static Path getSavePath(Path saveDir, int regionX, int regionZ) { - return saveDir.resolve("lod").resolve(regionX + "," + regionZ + ".lod"); - } - public void save(Path saveDir) { - if(.disableChunkMeshes || !.saveMeshes) return; - - try { - File saveFile = getSavePath(saveDir, regionX, regionZ).toFile(); - saveFile.getParentFile().mkdirs(); - - NBTTagCompound oldNbt = null; - NBTTagList oldList = null; - List<String> oldStringTable = null; - if(saveFile.exists()) { - oldNbt = CompressedStreamTools.readCompressed(new FileInputStream(saveFile)); - oldList = oldNbt.getTagList("chunks", NBT.TAG_COMPOUND);; - oldStringTable = Arrays.asList(oldNbt.getString("stringTable").split("\\n")); - } - - NBTTagCompound nbt = new NBTTagCompound(); - nbt.setByte("V", (byte)0); - nbt.setString("stringTable", String.join("\n", (List<String>) ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).mapUploadedSprites.keySet().stream().collect(Collectors.toList()))); - - NBTTagList list = new NBTTagList(); - - int idx = 0; - for(int i = 0; i < 32; i++) { - for(int j = 0; j < 32; j++) { - list.appendTag(data[i][j].saveToNBT(oldNbt == null ? null : oldList.getCompoundTagAt(idx++), - oldNbt == null? null : oldStringTable)); - } - } - nbt.setTag("chunks", list); - - new Thread( - new Runnable() { - - @Override - public void run() { - try { - CompressedStreamTools.writeCompressed(nbt, new FileOutputStream(saveFile)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - }).start(); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - */ public NeoChunk getChunkAbsolute(int chunkXAbs, int chunkZAbs) { return getChunk(chunkXAbs - regionX * 32, chunkZAbs - regionZ * 32); } @@ -127,23 +41,12 @@ public class NeoRegion { } } - public NeoChunk putChunk(Chunk chunk) { - int relX = chunk.xPosition - regionX * 32; - int relZ = chunk.zPosition - regionZ * 32; - - if(relX >= 0 && relX < 32 && relZ >= 0 && relZ < 32) { - data[relX][relZ].receiveChunk(chunk); - return data[relX][relZ]; - } - return null; - } - - public void tick(Entity player) { + public void tick() { for(int i = 0; i < 32; i++) { for(int j = 0; j < 32; j++) { NeoChunk chunk = data[i][j]; if(chunk != null) { - chunk.tick(player); + chunk.tick(); } } } @@ -156,7 +59,6 @@ public class NeoRegion { } public void destroy(Path saveDir) { - //save(saveDir); for(int i = 0; i < 32; i++) { for(int j = 0; j < 32; j++) { NeoChunk chunk = data[i][j]; diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index 240ec49..73a3be2 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -11,7 +11,6 @@ import java.nio.IntBuffer; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -39,16 +38,12 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.ChunkProviderServer; import net.minecraftforge.event.world.ChunkEvent; /** The main renderer class. */ @@ -61,7 +56,6 @@ public class NeoRenderer { public boolean reloadPending; private static boolean[] wasDown = new boolean[256]; - private int renderQuads = 0; public boolean renderWorld; public boolean rendererActive; @@ -79,20 +73,10 @@ public class NeoRenderer { List<Chunk> myChunks = new ArrayList<Chunk>(); List<NeoChunk> pendingLODChunks = new ArrayList<>(); - private boolean hasServerInited = false; private Map<ChunkCoordIntPair, NeoRegion> loadedRegionsMap = new HashMap<>(); public World world; - // TODO make these packets to make this work on dedicated servers - Queue<Chunk> farChunks = new ConcurrentLinkedQueue<>(); - - List<ChunkCoordIntPair> serverChunkLoadQueue = new ArrayList<>(); - - private double lastSortX = Double.NaN; - private double lastSortY = Double.NaN; - private double lastSortZ = Double.NaN; - private double interpX; private double interpY; private double interpZ; @@ -100,18 +84,9 @@ public class NeoRenderer { int interpYDiv; int interpZDiv; - private long lastGCTime = -1; - private long lastSaveTime = -1; - private long gcInterval = 10 * 1000; - private long saveInterval = 60 * 1000; - private int renderedMeshes, renderedQuads; private int frameCount; - public int renderRange = 48; // unused LOD thing.. - - private boolean freezeMeshes; - public NeoRenderer(World world){ this.world = world; if(shouldRenderInWorld(world)) { @@ -125,8 +100,6 @@ public class NeoRenderer { public void preRenderSortedRenderers(int renderPass, double alpha, WorldRenderer[] sortedWorldRenderers) { if(renderPass != 0) return; - Neodymium.fogEventWasPosted = false; - renderedMeshes = 0; renderedQuads = 0; @@ -140,11 +113,6 @@ public class NeoRenderer { if(mem.getCoherenceRate() < 0.95f || frameCount % 4 == 0) { mem.runGC(false); } - lastGCTime = System.currentTimeMillis(); - if(lastSaveTime == -1 || (System.currentTimeMillis() - lastSaveTime) > saveInterval && Config.saveMeshes) { - onSave(); - lastSaveTime = System.currentTimeMillis(); - } if(rendererActive && renderWorld) { Entity rve = Minecraft.getMinecraft().renderViewEntity; @@ -221,86 +189,22 @@ public class NeoRenderer { } } - private boolean isNormalMeshVisible(Mesh mesh) { - switch(mesh.normal) { - case POSITIVE_X: - return interpXDiv >= ((mesh.x + 0)); - case NEGATIVE_X: - return interpXDiv < ((mesh.x + 1)); - case POSITIVE_Y: - return interpYDiv >= ((mesh.y + 0)); - case NEGATIVE_Y: - return interpYDiv < ((mesh.y + 1)); - case POSITIVE_Z: - return interpZDiv >= ((mesh.z + 0)); - case NEGATIVE_Z: - return interpZDiv < ((mesh.z + 1)); - default: - return true; - } - } - private void mainLoop() { - /*while(!farChunks.isEmpty()) { - NeoChunk lodChunk = receiveFarChunk(farChunks.remove()); - sendChunkToGPU(lodChunk); - }*/ - if(Minecraft.getMinecraft().playerController.netClientHandler.doneLoadingTerrain) { - Entity player = Minecraft.getMinecraft().renderViewEntity; - - List<ChunkCoordIntPair> newServerChunkLoadQueue = new ArrayList<>(); - - if(Double.isNaN(lastSortX) || getLastSortDistanceSq(player) > 16 * 16) { - /*int centerX = (int)Math.floor(player.posX / 16.0); - int centerZ = (int)Math.floor(player.posZ / 16.0); + for(Iterator<Entry<ChunkCoordIntPair, NeoRegion>> it = loadedRegionsMap.entrySet().iterator(); it.hasNext();) { + Entry<ChunkCoordIntPair, NeoRegion> kv = it.next(); + NeoRegion v = kv.getValue(); - for(int x = -renderRange; x <= renderRange; x++) { - for(int z = -renderRange; z <= renderRange; z++) { - if(x * x + z * z < renderRange * renderRange) { - int chunkX = centerX + x; - int chunkZ = centerZ + z; - - if(getLODChunk(chunkX, chunkZ).needsChunk) { - newServerChunkLoadQueue.add(new ChunkCoordIntPair(chunkX, chunkZ)); - getLODChunk(chunkX, chunkZ).needsChunk = false; - } - } - } - } - Collections.sort(newServerChunkLoadQueue, new ChunkCoordDistanceComparator(player.posX, player.posY, player.posZ)); - addToServerChunkLoadQueue(newServerChunkLoadQueue); - - lastSortX = player.posX; - lastSortY = player.posY; - lastSortZ = player.posZ;*/ - for(Iterator<Entry<ChunkCoordIntPair, NeoRegion>> it = loadedRegionsMap.entrySet().iterator(); it.hasNext();) { - Entry<ChunkCoordIntPair, NeoRegion> kv = it.next(); - NeoRegion v = kv.getValue(); - - if(v.shouldDelete()) { - v.destroy(getSaveDir()); - it.remove(); - } else { - v.tick(player); - } + if(v.shouldDelete()) { + v.destroy(getSaveDir()); + it.remove(); + } else { + v.tick(); } } } } - public float getFarPlaneDistanceMultiplier() { - return (float)Config.farPlaneDistanceMultiplier; - } - - public void afterSetupFog(int mode, float alpha, float farPlaneDistance) { - EntityLivingBase entity = Minecraft.getMinecraft().renderViewEntity; - if(Neodymium.fogEventWasPosted && !Minecraft.getMinecraft().theWorld.provider.doesXZShowFog((int)entity.posX, (int)entity.posZ)) { - GL11.glFogf(GL11.GL_FOG_START, mode < 0 ? 0 : farPlaneDistance * (float)Config.fogStart); - GL11.glFogf(GL11.GL_FOG_END, mode < 0 ? farPlaneDistance/4 : farPlaneDistance * (float)Config.fogEnd); - } - } - private void handleKeyboard() { if(Config.debugPrefix == 0 || (Config.debugPrefix != -1 && Keyboard.isKeyDown(Config.debugPrefix))) { if(Keyboard.isKeyDown(Keyboard.KEY_F) && !wasDown[Keyboard.KEY_F]) { @@ -314,11 +218,6 @@ public class NeoRenderer { } if(Keyboard.isKeyDown(Keyboard.KEY_M) && !wasDown[Keyboard.KEY_M]) { showMemoryDebugger = !showMemoryDebugger; - //LODChunk chunk = getLODChunk(9, -18); - //setMeshVisible(chunk.chunkMeshes[7], false, true); - //freezeMeshes = false; - //chunk.chunkMeshes[7].quadCount = 256; - //setMeshVisible(chunk.chunkMeshes[7], true, true); } if(Keyboard.isKeyDown(Keyboard.KEY_P) && !wasDown[Keyboard.KEY_P]) { Util.dumpTexture(); @@ -440,8 +339,6 @@ public class NeoRenderer { } public boolean init() { - Map<String, TextureAtlasSprite> uploadedSprites = ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).mapUploadedSprites; - reloadShader(); VAO = glGenVertexArrays(); @@ -546,15 +443,11 @@ public class NeoRenderer { } public void destroy() { - onSave(); - glDeleteProgram(shaderPrograms[0]); glDeleteProgram(shaderPrograms[1]); glDeleteVertexArrays(VAO); mem.destroy(); - SimpleChunkMesh.instances = 0; - SimpleChunkMesh.usedRAM = 0; ChunkMesh.instances = 0; ChunkMesh.usedRAM = 0; } @@ -578,8 +471,6 @@ public class NeoRenderer { } public void onWorldRendererPost(WorldRenderer wr) { - if(Config.disableChunkMeshes) return; - int x = Math.floorDiv(wr.posX, 16); int y = Math.floorDiv(wr.posY, 16); int z = Math.floorDiv(wr.posZ, 16); @@ -591,38 +482,10 @@ public class NeoRenderer { } } - private double getLastSortDistanceSq(Entity player) { - return Math.pow(lastSortX - player.posX, 2) + Math.pow(lastSortZ - player.posZ, 2); - } - - private synchronized void addToServerChunkLoadQueue(List<ChunkCoordIntPair> coords) { - serverChunkLoadQueue.addAll(coords); - } - - private NeoChunk receiveFarChunk(Chunk chunk) { - NeoRegion region = getRegionContaining(chunk.xPosition, chunk.zPosition); - return region.putChunk(chunk); - } - private NeoChunk getLODChunk(int chunkX, int chunkZ) { return getRegionContaining(chunkX, chunkZ).getChunkAbsolute(chunkX, chunkZ); } - public void onStopServer() { - - } - - public synchronized void serverTick() { - int chunkLoadsRemaining = Config.chunkLoadsPerTick; - while(!serverChunkLoadQueue.isEmpty() && chunkLoadsRemaining-- > 0) { - ChunkCoordIntPair coords = serverChunkLoadQueue.remove(0); - ChunkProviderServer chunkProviderServer = Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(world.provider.dimensionId).theChunkProviderServer; - Chunk chunk = chunkProviderServer.currentChunkProvider.provideChunk(coords.chunkXPos, coords.chunkZPos); - SimpleChunkMesh.prepareFarChunkOnServer(chunk); - farChunks.add(chunk); - } - } - private NeoRegion getRegionContaining(int chunkX, int chunkZ) { ChunkCoordIntPair key = new ChunkCoordIntPair(Math.floorDiv(chunkX , 32), Math.floorDiv(chunkZ, 32)); NeoRegion region = loadedRegionsMap.get(key); @@ -633,13 +496,6 @@ public class NeoRenderer { return region; } - private void sendChunkToGPU(NeoChunk lodChunk) { - Entity player = Minecraft.getMinecraft().renderViewEntity; - - lodChunk.tick(player); - setVisible(lodChunk, true, true); - } - public void setVisible(NeoChunk chunk, boolean visible) { setVisible(chunk, visible, false); } @@ -652,20 +508,7 @@ public class NeoRenderer { } public void lodChunkChanged(NeoChunk lodChunk) { - int newLOD = (!lodChunk.hasChunkMeshes() && lodChunk.lod == 2) ? (Config.disableSimpleMeshes ? 0 : 1) : lodChunk.lod; - for(SimpleChunkMesh sm : lodChunk.simpleMeshes) { - if(sm != null) { - if(lodChunk.isFullyVisible() && newLOD == 1) { - if(!sm.visible) { - setMeshVisible(sm, true); - } - } else { - if(sm.visible) { - setMeshVisible(sm, false); - } - } - } - } + int newLOD = lodChunk.hasChunkMeshes() ? 2 : 0; for(int y = 0; y < 16; y++) { for(int pass = 0; pass < 2; pass++) { ChunkMesh cm = lodChunk.chunkMeshes[y * 2 + pass]; @@ -685,11 +528,7 @@ public class NeoRenderer { } protected void setMeshVisible(Mesh mesh, boolean visible) { - setMeshVisible(mesh, visible, false); - } - - protected void setMeshVisible(Mesh mesh, boolean visible, boolean force) { - if((!force && freezeMeshes) || mesh == null) return; + if(mesh == null) return; if(mesh.visible != visible) { mesh.visible = visible; @@ -734,25 +573,12 @@ public class NeoRenderer { )); text.addAll(mem.getDebugText()); text.addAll(Arrays.asList( - //"Simple meshes: " + SimpleChunkMesh.instances + " (" + SimpleChunkMesh.usedRAM / 1024 / 1024 + "MB)", "Meshes: " + ChunkMesh.instances + " (" + ChunkMesh.usedRAM / 1024 / 1024 + "MB)", - //"Total RAM used: " + ((SimpleChunkMesh.usedRAM + ChunkMesh.usedRAM) / 1024 / 1024) + " MB", "Rendered: " + renderedMeshes + " (" + renderedQuads / 1000 + "KQ)" )); return text; } - public void onSave() { - //System.out.println("Saving LOD regions..."); - //long t0 = System.currentTimeMillis(); - //loadedRegionsMap.forEach((k, v) -> v.save(getSaveDir())); - //System.out.println("Finished saving LOD regions in " + ((System.currentTimeMillis() - t0) / 1000.0) + "s"); - } - - public void onChunkLoad(ChunkEvent.Load event) { - farChunks.add(event.getChunk()); - } - private Path getSaveDir(){ return Minecraft.getMinecraft().mcDataDir.toPath().resolve("neodymium").resolve(Minecraft.getMinecraft().getIntegratedServer().getFolderName()); } diff --git a/src/main/java/makamys/neodymium/renderer/SimpleChunkMesh.java b/src/main/java/makamys/neodymium/renderer/SimpleChunkMesh.java deleted file mode 100644 index 0c21fe8..0000000 --- a/src/main/java/makamys/neodymium/renderer/SimpleChunkMesh.java +++ /dev/null @@ -1,336 +0,0 @@ -package makamys.neodymium.renderer; - -import java.nio.FloatBuffer; -import java.util.Arrays; -import java.util.List; - -import org.lwjgl.BufferUtils; - -import makamys.neodymium.Config; -import makamys.neodymium.util.MCUtil; -import net.minecraft.block.Block; -import net.minecraft.block.BlockGrass; -import net.minecraft.block.BlockLeaves; -import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; -import net.minecraft.init.Blocks; -import net.minecraft.util.IIcon; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.chunk.Chunk; - -public class SimpleChunkMesh extends Mesh { - - private FloatBuffer vertices; - - public static int usedRAM; - public static int instances; - public static int divisions = 4; - - private static boolean isSolid(Block block) { - return block.isBlockNormalCube() && block.isOpaqueCube() && block.renderAsNormalBlock(); - } - - private static boolean isBad(Block block) { - for(Class clazz : Config.blockClassBlacklist) { - if(clazz.isInstance(block)) { - return true; - } - } - return false; - } - - public static List<SimpleChunkMesh> generateSimpleMeshes(Chunk target){ - SimpleChunkMesh pass1 = new SimpleChunkMesh(target.xPosition, target.zPosition, divisions * divisions * 25, 0); - SimpleChunkMesh pass2 = new SimpleChunkMesh(target.xPosition, target.zPosition, divisions * divisions * 25, 1); - - SimpleChunkMeshBuilder builder = new SimpleChunkMeshBuilder(); - - for(int divX = 0; divX < divisions; divX++) { - for(int divZ = 0; divZ < divisions; divZ++) { - IIcon icon = null; - int color = 0xFFFFFFFF; - int size = 16 / divisions; - int y = 255; - boolean foundWater = false; - - int xOff = divX * size; - int zOff = divZ * size; - - int biomeId = target.getBiomeArray()[xOff << 4 | zOff] & 255; - if(biomeId == 255) { - System.out.println("Missing biome data for chunk " + target.xPosition + ", " + target.zPosition); - } - BiomeGenBase biome = BiomeGenBase.getBiome(biomeId) == null ? BiomeGenBase.plains : BiomeGenBase.getBiome(biomeId); - - for(y = 255; y > 0; y--) { - Block block = target.getBlock(xOff, y, zOff); - - int worldX = target.xPosition * 16 + divX * size; - int worldY = y; - int worldZ = target.zPosition * 16 + divZ * size; - - if(!foundWater && block.getMaterial() == Material.water) { - foundWater = true; - int meta = target.getBlockMetadata(xOff, y, zOff); - IIcon waterIcon = block.getIcon(1, meta); - - int waterColor = biome.getWaterColorMultiplier(); - waterColor |= 0xFF000000; - pass2.addFaceYPos(worldX, worldY, worldZ, size, size, waterIcon, waterColor, 1); - } - - if(isSolid(block) && isBad(block)) { - for(int dx = -1; dx <= 1; dx++) { - for(int dz = -1; dz <= 1; dz++) { - int newX = xOff + dx; - int newZ = zOff + dz; - if(newX >= 0 && newX < 16 && newZ >= 0 && newZ < 16) { - Block newBlock = target.getBlock(newX, y, newZ); - if(!isBad(newBlock)) { - xOff += dx; - zOff += dz; - worldX += dx; - worldZ += dz; - block = newBlock; - } - } - } - } - } - if(isSolid(block)) { - - float brightnessMult = foundWater ? 0.2f : 1f; - int meta = target.getBlockMetadata(xOff, y, zOff); - icon = block.getIcon(1, meta); - - if(block instanceof BlockGrass) { - color = biome.getBiomeGrassColor(worldX, y, worldZ); - } else if(block instanceof BlockLeaves) { - color = biome.getBiomeFoliageColor(worldX, y, worldZ); - } else { - color = block.colorMultiplier(Minecraft.getMinecraft().theWorld, worldX, y, worldZ); - } - color = (0xFF << 24) | ((color >> 16 & 0xFF) << 0) | ((color >> 8 & 0xFF) << 8) | ((color >> 0 & 0xFF) << 16); - - if((Config.forceVanillaBiomeTemperature ? MCUtil.getBiomeTemperatureVanilla(biome, worldX, y, worldZ) - : biome.getFloatTemperature(worldX, y, worldZ)) < 0.15f) { - - builder.addCube(divX, divZ, worldY + 0.2f, 1f, Blocks.snow_layer.getIcon(1, 0), 0xFFFFFFFF, brightnessMult); - builder.addCube(divX, divZ, worldY - 0.8f, -1, icon, color, brightnessMult); - } else { - builder.addCube(divX, divZ, worldY, -1, icon, color, brightnessMult); - } - - - break; - } - } - } - } - - builder.render(pass1, target.xPosition, target.zPosition); - - pass1.finish(); - pass2.finish(); - - return Arrays.asList(new SimpleChunkMesh[] {pass1.quadCount != 0 ? pass1 : null, pass2.quadCount != 0 ? pass2 : null}); - } - - private static class SimpleChunkMeshBuilder { - int maxIconsPerColumn = 2; - float[][][] heights = new float[divisions][divisions][maxIconsPerColumn]; - float[][][] depths = new float[divisions][divisions][maxIconsPerColumn]; - IIcon[][][] icons = new IIcon[divisions][divisions][maxIconsPerColumn]; - int[][][] colors = new int[divisions][divisions][maxIconsPerColumn]; - float[][][] brightnessMults = new float[divisions][divisions][maxIconsPerColumn]; - - public void addCube(int x, int z, float height, float depth, IIcon icon, int color, float brightnessMult) { - IIcon[] iconz = icons[x][z]; - int i = iconz[0] == null ? 0 : 1; - if(iconz[0] != null && iconz[1] != null) { - throw new IllegalStateException("Too many icons in column"); - } - - heights[x][z][i] = height; - depths[x][z][i] = depth; - icons[x][z][i] = icon; - colors[x][z][i] = color; - brightnessMults[x][z][i] = brightnessMult; - } - - public void render(SimpleChunkMesh mesh, int chunkX, int chunkZ) { - float size = 16 / divisions; - - for(int x = 0; x < divisions; x++) { - for(int z = 0; z < divisions; z++) { - float worldX = chunkX * 16 + x * size; - float worldZ = chunkZ * 16 + z * size; - for(int i = 0; i < maxIconsPerColumn; i++) { - IIcon icon = icons[x][z][i]; - if(icon != null) { - float height = heights[x][z][i]; - float depthValue = depths[x][z][i]; - float depth = depthValue == -1 ? height : depthValue; - int color = colors[x][z][i]; - float brightnessMult = brightnessMults[x][z][i]; - - if(i == 0) { - mesh.addFaceYPos(worldX, height, worldZ, size, size, icon, color, brightnessMult); - } - float heightX0 = x > 0 ? heights[x - 1][z][0] : 0; - if(heightX0 < height) { - mesh.addFaceX2(worldX, height, worldZ, Math.min(depth, height - heightX0), size, icon, color, brightnessMult); - } - - float heightX1 = x < divisions - 1 ? heights[x + 1][z][0] : 0; - if(heightX1 < height) { - mesh.addFaceX1(worldX + size, height, worldZ, Math.min(depth, height - heightX1), size, icon, color, brightnessMult); - } - - float heightZ0 = z > 0 ? heights[x][z - 1][0] : 0; - if(heightZ0 < height) { - mesh.addFaceZ1(worldX, height, worldZ, size, Math.min(depth, height - heightZ0), icon, color, brightnessMult); - } - - float heightZ1 = z < divisions - 1 ? heights[x][z + 1][0] : 0; - if(heightZ1 < height) { - mesh.addFaceZ2(worldX, height, worldZ + size, size, Math.min(depth, height - heightZ1), icon, color, brightnessMult); - } - } - } - } - } - } - } - - public SimpleChunkMesh(int x, int z, int maxQuads, int pass) { - this.x = x; - this.y = 64; - this.z = z; - this.pass = pass; - - buffer = BufferUtils.createByteBuffer(4 * 6 * 7 * maxQuads); - vertices = buffer.asFloatBuffer(); - } - - public void finish() { - vertices.flip(); - buffer.limit(vertices.limit() * 4); - - // may want to shrink the buffers to actual size to not waste memory - - usedRAM += buffer.limit(); - instances++; - } - - private void addCube(float x, float y, float z, float sizeX, float sizeZ, float sizeY, IIcon icon, int color, float brightnessMult) { - addFaceYPos(x, y, z, sizeX, sizeZ, icon, color, brightnessMult); - addFaceZ1(x, y, z, sizeX, sizeY, icon, color, brightnessMult); - addFaceZ2(x, y, z + sizeZ, sizeX, sizeY, icon, color, brightnessMult); - addFaceX1(x + sizeX, y, z, sizeX, sizeY, icon, color, brightnessMult); - addFaceX2(x, y, z, sizeX, sizeY, icon, color, brightnessMult); - } - - private void addFaceZ1(float x, float y, float z, float sizeX, float sizeY, IIcon icon, int color, float brightnessMult) { - addFace( - x + 0, y - sizeY, z + 0, - x + 0, y + 0, z + 0, - x + sizeX, y + 0, z + 0, - x + sizeX, y - sizeY, z + 0, - icon, color, (int)(200 * brightnessMult) - ); - } - - private void addFaceZ2(float x, float y, float z, float sizeX, float sizeY, IIcon icon, int color, float brightnessMult) { - addFace( - x + sizeX, y - sizeY, z, - x + sizeX, y + 0, z, - x + 0, y + 0, z, - x + 0, y - sizeY, z, - icon, color, (int)(200 * brightnessMult) - ); - } - - private void addFaceX1(float x, float y, float z, float sizeY, float sizeZ, IIcon icon, int color, float brightnessMult) { - addFace( - x, y - sizeY, z + 0, - x, y + 0, z + 0, - x, y + 0, z + sizeZ, - x, y - sizeY, z + sizeZ, - icon, color, (int)(160 * brightnessMult) - ); - } - - private void addFaceX2(float x, float y, float z, float sizeY, float sizeZ, IIcon icon, int color, float brightnessMult) { - addFace( - x + 0, y - sizeY, z + sizeZ, - x + 0, y + 0, z + sizeZ, - x + 0, y + 0, z + 0, - x + 0, y - sizeY, z + 0, - icon, color, (int)(160 * brightnessMult) - ); - } - - private void addFaceYPos(float x, float y, float z, float sizeX, float sizeZ, IIcon icon, int color, float brightnessMult) { - addFace( - x + 0, y + 0, z + 0, - x + 0, y + 0, z + sizeZ, - x + sizeX, y + 0, z + sizeZ, - x + sizeX, y + 0, z + 0, - icon, color, (int)(240 * brightnessMult) - ); - } - - private void addFace(float p1x, float p1y, float p1z, - float p2x, float p2y, float p2z, - float p3x, float p3y, float p3z, - float p4x, float p4y, float p4z, - IIcon icon, int color, int brightness) { - int off = vertices.position() * 4; - vertices.put(new float[] { - p1x, p1y, p1z, icon.getMinU(), icon.getMaxV(), 0, 0, - p2x, p2y, p2z, icon.getMinU(), icon.getMinV(), 0, 0, - p4x, p4y, p4z, icon.getMaxU(), icon.getMaxV(), 0, 0, - p2x, p2y, p2z, icon.getMinU(), icon.getMinV(), 0, 0, - p3x, p3y, p3z, icon.getMaxU(), icon.getMinV(), 0, 0, - p4x, p4y, p4z, icon.getMaxU(), icon.getMaxV(), 0, 0 - }); - buffer.putInt(off + 0 * getStride() + 6 * 4, color); - buffer.putShort(off + 0 * getStride() + 5 * 4 + 2, (short)brightness); - buffer.putInt(off + 1 * getStride() + 6 * 4, color); - buffer.putShort(off + 1 * getStride() + 5 * 4 + 2, (short)brightness); - buffer.putInt(off + 2 * getStride() + 6 * 4, color); - buffer.putShort(off + 2 * getStride() + 5 * 4 + 2, (short)brightness); - buffer.putInt(off + 3 * getStride() + 6 * 4, color); - buffer.putShort(off + 3 * getStride() + 5 * 4 + 2, (short)brightness); - buffer.putInt(off + 4 * getStride() + 6 * 4, color); - buffer.putShort(off + 4 * getStride() + 5 * 4 + 2, (short)brightness); - buffer.putInt(off + 5 * getStride() + 6 * 4, color); - buffer.putShort(off + 5 * getStride() + 5 * 4 + 2, (short)brightness); - - quadCount++; - } - - public int getStride() { - return (3 * 4 + 8 + 4 + 4); - } - - public void destroy() { - usedRAM -= buffer.limit(); - instances--; - } - - public static void prepareFarChunkOnServer(Chunk chunk) { - for(int divX = 0; divX < divisions; divX++) { - for(int divZ = 0; divZ < divisions; divZ++) { - int size = 16 / divisions; - - int xOff = divX * size; - int zOff = divZ * size; - - chunk.getBiomeGenForWorldCoords(xOff, zOff, chunk.worldObj.getWorldChunkManager()); - } - } - } - -} diff --git a/src/main/java/makamys/neodymium/renderer/lod/FarChunkCache.java b/src/main/java/makamys/neodymium/renderer/lod/FarChunkCache.java deleted file mode 100644 index 603a7de..0000000 --- a/src/main/java/makamys/neodymium/renderer/lod/FarChunkCache.java +++ /dev/null @@ -1,13 +0,0 @@ -package makamys.neodymium.renderer.lod; - -import net.minecraft.world.ChunkCache; -import net.minecraft.world.World; - -/** Unused remnant from LODMod. */ -public class FarChunkCache extends ChunkCache { - - public FarChunkCache(World p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { - super(p1, p2, p3, p4, p5, p6, p7, p8); - } - -} diff --git a/src/main/java/makamys/neodymium/renderer/lod/FarWorldRenderer.java b/src/main/java/makamys/neodymium/renderer/lod/FarWorldRenderer.java deleted file mode 100644 index 6428d9c..0000000 --- a/src/main/java/makamys/neodymium/renderer/lod/FarWorldRenderer.java +++ /dev/null @@ -1,15 +0,0 @@ -package makamys.neodymium.renderer.lod; - -import java.util.List; - -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.world.World; - -/** Unused remnant from LODMod. */ -public class FarWorldRenderer extends WorldRenderer { - - public FarWorldRenderer(World p1, List p2, int p3, int p4, int p5, int p6) { - super(p1, p2, p3, p4, p5, p6); - } - -} diff --git a/src/main/java/makamys/neodymium/util/OFUtil.java b/src/main/java/makamys/neodymium/util/OFUtil.java new file mode 100644 index 0000000..a26177f --- /dev/null +++ b/src/main/java/makamys/neodymium/util/OFUtil.java @@ -0,0 +1,11 @@ +package makamys.neodymium.util; + +import makamys.neodymium.MixinConfigPlugin; + +public class OFUtil { + private static boolean isOptiFinePresent = MixinConfigPlugin.class.getResource("/optifine/OptiFineTweaker.class") != null; + + public static boolean isOptiFinePresent() { + return isOptiFinePresent; + } +} diff --git a/src/main/java/makamys/neodymium/util/SpriteUtil.java b/src/main/java/makamys/neodymium/util/SpriteUtil.java deleted file mode 100644 index 4219802..0000000 --- a/src/main/java/makamys/neodymium/util/SpriteUtil.java +++ /dev/null @@ -1,55 +0,0 @@ -package makamys.neodymium.util; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.world.ChunkCoordIntPair; - -public class SpriteUtil { - - private static int[] spriteIndexMap; - public static List<TextureAtlasSprite> sprites; - - private static Map<Long, Integer> uv2spriteIndex = new HashMap<>(); - - private static int findSpriteIndexForUV(float u, float v) { - Map<String, TextureAtlasSprite> uploadedSprites = ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).mapUploadedSprites; - - int spriteIndex = 0; - for(TextureAtlasSprite tas : uploadedSprites.values()) { - if(tas.getMinU() <= u && u <= tas.getMaxU() && tas.getMinV() <= v && v <= tas.getMaxV()) { - break; - } - spriteIndex++; - } - return spriteIndex; - } - - public static int getSpriteIndexForUV(float u, float v){ - long key = ChunkCoordIntPair.chunkXZ2Int((int)(u * Integer.MAX_VALUE), (int)(v * Integer.MAX_VALUE)); - int index = uv2spriteIndex.getOrDefault(key, -1); - if(index == -1) { - index = findSpriteIndexForUV(u, v); - uv2spriteIndex.put(key, index); - } - return index; - } - - public static TextureAtlasSprite getSprite(int i){ - if(i >= 0 && i < sprites.size()) { - return sprites.get(i); - } else { - return null; - } - } - - public static void init() { - Map<String, TextureAtlasSprite> uploadedSprites = ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).mapUploadedSprites; - sprites = uploadedSprites.values().stream().collect(Collectors.toList()); - } -} |