diff --git a/gradle.properties b/gradle.properties index a0f72b8..fabcd97 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10 loader_version=0.15.9 # Mod Properties -mod_version=0.5.7 +mod_version=0.5.8 maven_group=rogo.renderingculling archives_base_name=BruteForceRenderingCulling-fabric-1.20.1 diff --git a/src/main/java/rogo/renderingculling/api/Config.java b/src/main/java/rogo/renderingculling/api/Config.java index 2e18357..2abdd76 100644 --- a/src/main/java/rogo/renderingculling/api/Config.java +++ b/src/main/java/rogo/renderingculling/api/Config.java @@ -28,16 +28,16 @@ public static double getSampling() { if(unload()) return 0.5; - return SAMPLING.getValue(); + return Math.max(SAMPLING.getValue(), 0.05); } public static void setSampling(double value) { - SAMPLING.setValue(value); + SAMPLING.setValue(Math.max(0.05, value)); save(); } public static boolean getCullEntity() { - if(unload() || !CullingHandler.gl33()) + if(unload() || !CullingStateManager.gl33()) return false; return CULL_ENTITY.getValue(); } @@ -57,7 +57,7 @@ public static boolean shouldCullChunk() { if (unload()) return false; - if (CullingHandler.CHUNK_CULLING_MAP == null || !CullingHandler.CHUNK_CULLING_MAP.isDone()) + if (CullingStateManager.CHUNK_CULLING_MAP == null || !CullingStateManager.CHUNK_CULLING_MAP.isDone()) return false; return getCullChunk(); @@ -75,7 +75,7 @@ public static boolean getAsyncChunkRebuild() { if(!shouldCullChunk()) return false; - if (CullingHandler.needPauseRebuild()) + if (CullingStateManager.needPauseRebuild()) return false; if(ModLoader.hasNvidium()) @@ -94,7 +94,7 @@ public static void setAsyncChunkRebuild(boolean value) { if(ModLoader.hasNvidium()) return; - if (CullingHandler.needPauseRebuild()) + if (CullingStateManager.needPauseRebuild()) return; if(!ModLoader.hasSodium()) @@ -105,7 +105,7 @@ public static void setAsyncChunkRebuild(boolean value) { } public static int getShaderDynamicDelay() { - return CullingHandler.enabledShader() ? 1 : 0; + return CullingStateManager.enabledShader() ? 1 : 0; } public static int getDepthUpdateDelay() { @@ -160,7 +160,7 @@ private static void init() { blockList.add("minecraft:beacon"); BRANCH = ConfigTree.builder() - .beginValue(getTranslatedItem("brute_force_rendering_culling.sampler"), ConfigTypes.DOUBLE.withValidRange(0.0, 1.0, 0.01), 0.05) + .beginValue(getTranslatedItem("brute_force_rendering_culling.sampler"), ConfigTypes.DOUBLE.withValidRange(0.0, 1.0, 0.01), 0.2) .finishValue(SAMPLING::mirror) .beginValue(getTranslatedItem("brute_force_rendering_culling.culling_map_update_delay"), ConfigTypes.INTEGER, 1) @@ -191,7 +191,7 @@ public static void loadConfig() { } catch (IOException ignored) { } JanksonValueSerializer serializer = new JanksonValueSerializer(false); - CONTEXT = new ConfigContext(BRANCH, Paths.get("config", CullingHandler.MOD_ID + ".json"), serializer); + CONTEXT = new ConfigContext(BRANCH, Paths.get("config", CullingStateManager.MOD_ID + ".json"), serializer); setupConfig(CONTEXT); configLoaded = true; } diff --git a/src/main/java/rogo/renderingculling/api/CullingRenderEvent.java b/src/main/java/rogo/renderingculling/api/CullingRenderEvent.java index b0af8cb..89a1fdc 100644 --- a/src/main/java/rogo/renderingculling/api/CullingRenderEvent.java +++ b/src/main/java/rogo/renderingculling/api/CullingRenderEvent.java @@ -41,7 +41,7 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { return; } - if (CullingHandler.DEBUG > 0) { + if (CullingStateManager.DEBUG > 0) { Minecraft minecraft = Minecraft.getInstance(); int width = minecraft.getWindow().getGuiScaledWidth() / 2; int height = 20; @@ -49,12 +49,12 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { List monitorTexts = new ArrayList<>(); - if (CullingHandler.fps == 0) { - CullingHandler.fps++; + if (CullingStateManager.fps == 0) { + CullingStateManager.fps++; } - if (CullingHandler.cullingInitCount == 0) { - CullingHandler.cullingInitCount++; + if (CullingStateManager.cullingInitCount == 0) { + CullingStateManager.cullingInitCount++; } int index = Minecraft.getInstance().fpsString.indexOf("fps"); @@ -72,34 +72,34 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { + (Config.getCullChunk() ? Component.translatable("brute_force_rendering_culling.enable").getString() : Component.translatable("brute_force_rendering_culling.disable").getString()); addString(monitorTexts, cull_chunk); - if (CullingHandler.DEBUG > 1) { + if (CullingStateManager.DEBUG > 1) { String Sampler = Component.translatable("brute_force_rendering_culling.sampler").getString() + ": " + String.valueOf((Float.parseFloat(String.format("%.0f", Config.getSampling() * 100.0D))) + "%"); addString(monitorTexts, Sampler); if (Config.getCullEntity()) { - String blockCullingTime = Component.translatable("brute_force_rendering_culling.block_culling_time").getString() + ": " + (CullingHandler.blockCullingTime / 1000 / CullingHandler.fps) + " μs"; + String blockCullingTime = Component.translatable("brute_force_rendering_culling.block_culling_time").getString() + ": " + (CullingStateManager.blockCullingTime / 1000 / CullingStateManager.fps) + " μs"; addString(monitorTexts, blockCullingTime); - String blockCulling = Component.translatable("brute_force_rendering_culling.block_culling").getString() + ": " + CullingHandler.blockCulling + " / " + CullingHandler.blockCount; + String blockCulling = Component.translatable("brute_force_rendering_culling.block_culling").getString() + ": " + CullingStateManager.blockCulling + " / " + CullingStateManager.blockCount; addString(monitorTexts, blockCulling); - String entityCullingTime = Component.translatable("brute_force_rendering_culling.entity_culling_time").getString() + ": " + (CullingHandler.entityCullingTime / 1000 / CullingHandler.fps) + " μs"; + String entityCullingTime = Component.translatable("brute_force_rendering_culling.entity_culling_time").getString() + ": " + (CullingStateManager.entityCullingTime / 1000 / CullingStateManager.fps) + " μs"; addString(monitorTexts, entityCullingTime); - String entityCulling = Component.translatable("brute_force_rendering_culling.entity_culling").getString() + ": " + CullingHandler.entityCulling + " / " + CullingHandler.entityCount; + String entityCulling = Component.translatable("brute_force_rendering_culling.entity_culling").getString() + ": " + CullingStateManager.entityCulling + " / " + CullingStateManager.entityCount; addString(monitorTexts, entityCulling); - String initTime = Component.translatable("brute_force_rendering_culling.entity_culling_init").getString() + ": " + (CullingHandler.entityCullingInitTime / 1000 / CullingHandler.cullingInitCount) + " μs"; + String initTime = Component.translatable("brute_force_rendering_culling.entity_culling_init").getString() + ": " + (CullingStateManager.entityCullingInitTime / 1000 / CullingStateManager.cullingInitCount) + " μs"; addString(monitorTexts, initTime); } if (Config.getCullChunk()) { - if (CullingHandler.CHUNK_CULLING_MAP != null) { - String chunkCullingCount = Component.translatable("brute_force_rendering_culling.chunk_update_count").getString() + ": " + CullingHandler.CHUNK_CULLING_MAP.lastQueueUpdateCount; + if (CullingStateManager.CHUNK_CULLING_MAP != null) { + String chunkCullingCount = Component.translatable("brute_force_rendering_culling.chunk_update_count").getString() + ": " + CullingStateManager.CHUNK_CULLING_MAP.lastQueueUpdateCount; addString(monitorTexts, chunkCullingCount); } - String cullingInitTime = Component.translatable("brute_force_rendering_culling.chunk_culling_init").getString() + ": " + (CullingHandler.chunkCullingInitTime / CullingHandler.cullingInitCount / CullingHandler.fps) + " ns"; + String cullingInitTime = Component.translatable("brute_force_rendering_culling.chunk_culling_init").getString() + ": " + (CullingStateManager.chunkCullingInitTime / CullingStateManager.cullingInitCount / CullingStateManager.fps) + " ns"; addString(monitorTexts, cullingInitTime); } } @@ -127,7 +127,7 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { .color(bgColor, bgColor, bgColor, bgAlpha) .uv(u(right - 1), v(top - 1)).endVertex(); RenderSystem.setShaderTexture(0, Minecraft.getInstance().getMainRenderTarget().getColorTextureId()); - CullingHandler.useShader(CullingHandler.REMOVE_COLOR_SHADER); + CullingStateManager.useShader(CullingStateManager.REMOVE_COLOR_SHADER); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 0.1f); RenderSystem.disableBlend(); RenderSystem.getModelViewStack().pushPose(); @@ -150,7 +150,7 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { RenderSystem.disableBlend(); renderText(guiGraphics, monitorTexts, width, top); - if (!CullingHandler.checkTexture) + if (!CullingStateManager.checkTexture) return; Tesselator tessellator = Tesselator.getInstance(); @@ -160,7 +160,7 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { RenderSystem.enableBlend(); RenderSystem.depthMask(false); RenderSystem.defaultBlendFunc(); - for (int i = 0; i < CullingHandler.DEPTH_BUFFER_TARGET.length; ++i) { + for (int i = 0; i < CullingStateManager.DEPTH_BUFFER_TARGET.length; ++i) { int scaledHeight = (int) (minecraft.getWindow().getGuiScaledHeight() * windowScale * screenScale); int scaledWidth = (int) (minecraft.getWindow().getGuiScaledWidth() * windowScale * screenScale); int offsetHeight = (int) ((1 - screenScale) * 2 * minecraft.getWindow().getGuiScaledHeight() * windowScale); @@ -169,7 +169,7 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { bufferbuilder.vertex(scaledWidth, minecraft.getWindow().getGuiScaledHeight() - offsetHeight, 0.0D).uv(1, 0.0F).color(255, 255, 255, 255).endVertex(); bufferbuilder.vertex(scaledWidth, minecraft.getWindow().getGuiScaledHeight() - scaledHeight - offsetHeight, 0.0D).uv(1, 1).color(255, 255, 255, 255).endVertex(); bufferbuilder.vertex(0.0D, minecraft.getWindow().getGuiScaledHeight() - scaledHeight - offsetHeight, 0.0D).uv(0.0F, 1).color(255, 255, 255, 255).endVertex(); - RenderSystem.setShaderTexture(0, CullingHandler.DEPTH_TEXTURE[i]); + RenderSystem.setShaderTexture(0, CullingStateManager.DEPTH_TEXTURE[i]); tessellator.end(); screenScale *= 0.5f; } @@ -181,7 +181,7 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { bufferbuilder.vertex((double) minecraft.getWindow().getGuiScaledWidth(), height, 0.0D).uv(1, 0.0F).color(255, 255, 255, 255).endVertex(); bufferbuilder.vertex((double) minecraft.getWindow().getGuiScaledWidth(), 0, 0.0D).uv(1, 1).color(255, 255, 255, 255).endVertex(); bufferbuilder.vertex(minecraft.getWindow().getGuiScaledWidth() - height, 0, 0.0D).uv(0.0F, 1).color(255, 255, 255, 255).endVertex(); - RenderSystem.setShaderTexture(0, CullingHandler.ENTITY_CULLING_MAP_TARGET.getColorTextureId()); + RenderSystem.setShaderTexture(0, CullingStateManager.ENTITY_CULLING_MAP_TARGET.getColorTextureId()); tessellator.end(); } @@ -192,7 +192,7 @@ public void onOverlayRender(GuiGraphics guiGraphics, float tickDelta) { bufferbuilder.vertex((double) minecraft.getWindow().getGuiScaledWidth(), height * 2, 0.0D).uv(1, 0.0F).color(255, 255, 255, 255).endVertex(); bufferbuilder.vertex((double) minecraft.getWindow().getGuiScaledWidth(), height, 0.0D).uv(1, 1).color(255, 255, 255, 255).endVertex(); bufferbuilder.vertex(minecraft.getWindow().getGuiScaledWidth() - height, height, 0.0D).uv(0.0F, 1).color(255, 255, 255, 255).endVertex(); - RenderSystem.setShaderTexture(0, CullingHandler.CHUNK_CULLING_MAP_TARGET.getColorTextureId()); + RenderSystem.setShaderTexture(0, CullingStateManager.CHUNK_CULLING_MAP_TARGET.getColorTextureId()); tessellator.end(); } RenderSystem.depthMask(true); @@ -213,37 +213,37 @@ public void renderText(GuiGraphics guiGraphics, List list, int width, in } protected static void updateCullingMap() { - if (!CullingHandler.anyCulling()) + if (!CullingStateManager.anyCulling()) return; Tesselator tessellator = Tesselator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuilder(); - if (CullingHandler.checkCulling) + if (CullingStateManager.checkCulling) return; - if (Config.getCullEntity() && CullingHandler.ENTITY_CULLING_MAP != null && CullingHandler.ENTITY_CULLING_MAP.needTransferData()) { - CullingHandler.ENTITY_CULLING_MAP_TARGET.clear(Minecraft.ON_OSX); - CullingHandler.ENTITY_CULLING_MAP_TARGET.bindWrite(false); - CullingHandler.callDepthTexture(); - CullingHandler.ENTITY_CULLING_MAP.getEntityTable().addEntityAttribute(ENTITY_CULLING_INSTANCE_RENDERER::addInstanceAttrib); - ENTITY_CULLING_INSTANCE_RENDERER.drawWithShader(CullingHandler.INSTANCED_ENTITY_CULLING_SHADER); + if (Config.getCullEntity() && CullingStateManager.ENTITY_CULLING_MAP != null && CullingStateManager.ENTITY_CULLING_MAP.needTransferData()) { + CullingStateManager.ENTITY_CULLING_MAP_TARGET.clear(Minecraft.ON_OSX); + CullingStateManager.ENTITY_CULLING_MAP_TARGET.bindWrite(false); + CullingStateManager.callDepthTexture(); + CullingStateManager.ENTITY_CULLING_MAP.getEntityTable().addEntityAttribute(ENTITY_CULLING_INSTANCE_RENDERER::addInstanceAttrib); + ENTITY_CULLING_INSTANCE_RENDERER.drawWithShader(CullingStateManager.INSTANCED_ENTITY_CULLING_SHADER); } - if (Config.getCullChunk() && CullingHandler.CHUNK_CULLING_MAP != null && CullingHandler.CHUNK_CULLING_MAP.needTransferData()) { - CullingHandler.useShader(CullingHandler.CHUNK_CULLING_SHADER); - CullingHandler.CHUNK_CULLING_MAP_TARGET.clear(Minecraft.ON_OSX); - CullingHandler.CHUNK_CULLING_MAP_TARGET.bindWrite(false); + if (Config.getCullChunk() && CullingStateManager.CHUNK_CULLING_MAP != null && CullingStateManager.CHUNK_CULLING_MAP.needTransferData()) { + CullingStateManager.useShader(CullingStateManager.CHUNK_CULLING_SHADER); + CullingStateManager.CHUNK_CULLING_MAP_TARGET.clear(Minecraft.ON_OSX); + CullingStateManager.CHUNK_CULLING_MAP_TARGET.bindWrite(false); bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); bufferbuilder.vertex(-1.0f, -1.0f, 0.0f).endVertex(); bufferbuilder.vertex(1.0f, -1.0f, 0.0f).endVertex(); bufferbuilder.vertex(1.0f, 1.0f, 0.0f).endVertex(); bufferbuilder.vertex(-1.0f, 1.0f, 0.0f).endVertex(); - CullingHandler.callDepthTexture(); + CullingStateManager.callDepthTexture(); tessellator.end(); } - CullingHandler.bindMainFrameTarget(); + CullingStateManager.bindMainFrameTarget(); } public static void setUniform(ShaderInstance shader) { @@ -261,23 +261,23 @@ public static void setUniform(ShaderInstance shader) { if (shaderInstance.getBoxScale() != null) { shaderInstance.getBoxScale().set(8.0f); } - if (shaderInstance.getFrustumPos() != null && CullingHandler.FRUSTUM != null) { + if (shaderInstance.getFrustumPos() != null && CullingStateManager.FRUSTUM != null) { Vec3 pos = new Vec3( - ((AccessorFrustum) CullingHandler.FRUSTUM).camX(), - ((AccessorFrustum) CullingHandler.FRUSTUM).camY(), - ((AccessorFrustum) CullingHandler.FRUSTUM).camZ()); + ((AccessorFrustum) CullingStateManager.FRUSTUM).camX(), + ((AccessorFrustum) CullingStateManager.FRUSTUM).camY(), + ((AccessorFrustum) CullingStateManager.FRUSTUM).camZ()); float[] array = new float[]{(float) pos.x, (float) pos.y, (float) pos.z}; shaderInstance.getFrustumPos().set(array); } if (shaderInstance.getCullingViewMat() != null) { - shaderInstance.getCullingViewMat().set(CullingHandler.VIEW_MATRIX); + shaderInstance.getCullingViewMat().set(CullingStateManager.VIEW_MATRIX); } if (shaderInstance.getCullingProjMat() != null) { - shaderInstance.getCullingProjMat().set(CullingHandler.PROJECTION_MATRIX); + shaderInstance.getCullingProjMat().set(CullingStateManager.PROJECTION_MATRIX); } if(shaderInstance.getCullingFrustum() != null) { - Vector4f[] frustumData = ModLoader.getFrustumPlanes(((AccessorFrustum) CullingHandler.FRUSTUM).frustumIntersection()); + Vector4f[] frustumData = ModLoader.getFrustumPlanes(((AccessorFrustum) CullingStateManager.FRUSTUM).frustumIntersection()); List data = new ArrayList<>(); for (Vector4f frustumDatum : frustumData) { data.add(frustumDatum.x()); @@ -293,8 +293,8 @@ public static void setUniform(ShaderInstance shader) { } if (shaderInstance.getRenderDistance() != null) { float distance = Minecraft.getInstance().options.getEffectiveRenderDistance(); - if (shader == CullingHandler.COPY_DEPTH_SHADER) { - if (CullingHandler.DEPTH_INDEX > 0) + if (shader == CullingStateManager.COPY_DEPTH_SHADER) { + if (CullingStateManager.DEPTH_INDEX > 0) distance = 2; else distance = 0; @@ -303,30 +303,30 @@ public static void setUniform(ShaderInstance shader) { shaderInstance.getRenderDistance().set(distance); } if (shaderInstance.getDepthSize() != null) { - float[] array = new float[CullingHandler.DEPTH_SIZE * 2]; - if (shader == CullingHandler.COPY_DEPTH_SHADER) { - array[0] = (float) CullingHandler.DEPTH_BUFFER_TARGET[CullingHandler.DEPTH_INDEX].width; - array[1] = (float) CullingHandler.DEPTH_BUFFER_TARGET[CullingHandler.DEPTH_INDEX].height; + float[] array = new float[CullingStateManager.DEPTH_SIZE * 2]; + if (shader == CullingStateManager.COPY_DEPTH_SHADER) { + array[0] = (float) CullingStateManager.DEPTH_BUFFER_TARGET[CullingStateManager.DEPTH_INDEX].width; + array[1] = (float) CullingStateManager.DEPTH_BUFFER_TARGET[CullingStateManager.DEPTH_INDEX].height; } else { - for (int i = 0; i < CullingHandler.DEPTH_SIZE; ++i) { + for (int i = 0; i < CullingStateManager.DEPTH_SIZE; ++i) { int arrayIdx = i * 2; - array[arrayIdx] = (float) CullingHandler.DEPTH_BUFFER_TARGET[i].width; - array[arrayIdx + 1] = (float) CullingHandler.DEPTH_BUFFER_TARGET[i].height; + array[arrayIdx] = (float) CullingStateManager.DEPTH_BUFFER_TARGET[i].width; + array[arrayIdx + 1] = (float) CullingStateManager.DEPTH_BUFFER_TARGET[i].height; } } shaderInstance.getDepthSize().set(array); } - if (shader == CullingHandler.COPY_DEPTH_SHADER && CullingHandler.DEPTH_INDEX > 0 && shader.SCREEN_SIZE != null) { - shader.SCREEN_SIZE.set((float) CullingHandler.DEPTH_BUFFER_TARGET[CullingHandler.DEPTH_INDEX - 1].width, (float) CullingHandler.DEPTH_BUFFER_TARGET[CullingHandler.DEPTH_INDEX - 1].height); + if (shader == CullingStateManager.COPY_DEPTH_SHADER && CullingStateManager.DEPTH_INDEX > 0 && shader.SCREEN_SIZE != null) { + shader.SCREEN_SIZE.set((float) CullingStateManager.DEPTH_BUFFER_TARGET[CullingStateManager.DEPTH_INDEX - 1].width, (float) CullingStateManager.DEPTH_BUFFER_TARGET[CullingStateManager.DEPTH_INDEX - 1].height); } if (shaderInstance.getCullingSize() != null) { - shaderInstance.getCullingSize().set((float) CullingHandler.CHUNK_CULLING_MAP_TARGET.width, (float) CullingHandler.CHUNK_CULLING_MAP_TARGET.height); + shaderInstance.getCullingSize().set((float) CullingStateManager.CHUNK_CULLING_MAP_TARGET.width, (float) CullingStateManager.CHUNK_CULLING_MAP_TARGET.height); } if (shaderInstance.getEntityCullingSize() != null) { - shaderInstance.getEntityCullingSize().set((float) CullingHandler.ENTITY_CULLING_MAP_TARGET.width, (float) CullingHandler.ENTITY_CULLING_MAP_TARGET.height); + shaderInstance.getEntityCullingSize().set((float) CullingStateManager.ENTITY_CULLING_MAP_TARGET.width, (float) CullingStateManager.ENTITY_CULLING_MAP_TARGET.height); } if (shaderInstance.getLevelHeightOffset() != null) { - shaderInstance.getLevelHeightOffset().set(CullingHandler.LEVEL_SECTION_RANGE); + shaderInstance.getLevelHeightOffset().set(CullingStateManager.LEVEL_SECTION_RANGE); } if (shaderInstance.getLevelMinSection() != null && Minecraft.getInstance().level != null) { int min = Minecraft.getInstance().level.getMinSection(); diff --git a/src/main/java/rogo/renderingculling/api/CullingHandler.java b/src/main/java/rogo/renderingculling/api/CullingStateManager.java similarity index 89% rename from src/main/java/rogo/renderingculling/api/CullingHandler.java rename to src/main/java/rogo/renderingculling/api/CullingStateManager.java index 0dad808..e97e3b5 100644 --- a/src/main/java/rogo/renderingculling/api/CullingHandler.java +++ b/src/main/java/rogo/renderingculling/api/CullingStateManager.java @@ -45,7 +45,7 @@ import static org.lwjgl.opengl.GL11.GL_TEXTURE; import static org.lwjgl.opengl.GL30.*; -public class CullingHandler { +public class CullingStateManager { public static final String MOD_ID = "brute_force_rendering_culling"; public static final Logger LOGGER = LogUtils.getLogger(); public static EntityCullingMap ENTITY_CULLING_MAP = null; @@ -103,7 +103,7 @@ public class CullingHandler { public static boolean checkCulling = false; public static boolean checkTexture = false; private static boolean usingShader = false; - private static int fullChunkUpdateCooldown = 0; + protected static int fullChunkUpdateCooldown = 0; private static String shaderName = ""; public static int LEVEL_SECTION_RANGE; public static int LEVEL_POS_RANGE; @@ -114,6 +114,8 @@ public class CullingHandler { private static int frame; private static int lastVisibleUpdatedFrame; public static volatile boolean useOcclusionCulling = true; + private static int continueUpdateCount; + private static boolean lastUpdate; static { RenderSystem.recordRenderCall(() -> { @@ -218,7 +220,7 @@ public static boolean shouldRenderChunk(IRenderSectionVisibility section, boolea public static boolean shouldSkipBlockEntity(BlockEntity blockEntity, AABB aabb, BlockPos pos) { blockCount++; - + //for valkyrien skies if (CAMERA.getPosition().distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) > Minecraft.getInstance().options.getEffectiveRenderDistance() * Minecraft.getInstance().options.getEffectiveRenderDistance() * 2) { @@ -312,9 +314,7 @@ public static void onProfilerPopPush(String s) { switch (s) { case "beforeRunTick" -> { if (((AccessorLevelRender) Minecraft.getInstance().levelRenderer).getNeedsFullRenderChunkUpdate() && Minecraft.getInstance().level != null) { - if (ModLoader.hasMod("embeddium")) { - fullChunkUpdateCooldown = 60; - } + ModLoader.pauseAsync(); LEVEL_SECTION_RANGE = Minecraft.getInstance().level.getMaxSection() - Minecraft.getInstance().level.getMinSection(); LEVEL_MIN_SECTION_ABS = Math.abs(Minecraft.getInstance().level.getMinSection()); @@ -335,9 +335,9 @@ public static void onProfilerPopPush(String s) { } else { frustum = levelFrustum.getCullingFrustum(); } - CullingHandler.FRUSTUM = new Frustum(frustum).offsetToFullyIncludeCameraCube(32); - if (CullingHandler.CHUNK_CULLING_MAP != null) { - CullingHandler.CHUNK_CULLING_MAP.updateCamera(); + CullingStateManager.FRUSTUM = new Frustum(frustum).offsetToFullyIncludeCameraCube(32); + if (CullingStateManager.CHUNK_CULLING_MAP != null) { + CullingStateManager.CHUNK_CULLING_MAP.updateCamera(); } checkShader(); } @@ -373,6 +373,10 @@ public static void onProfilerPush(String s) { fullChunkUpdateCooldown--; } + if (anyNextTick() && continueUpdateCount > 0) { + continueUpdateCount--; + } + if (isNextLoop()) { visibleBlock.tick(clientTickCount, 1); visibleEntity.tick(clientTickCount, 1); @@ -395,9 +399,9 @@ public static void onProfilerPush(String s) { entityCullingInitTime = preEntityCullingInitTime; preEntityCullingInitTime = 0; - if (CullingHandler.CHUNK_CULLING_MAP != null) { - CullingHandler.CHUNK_CULLING_MAP.lastQueueUpdateCount = CullingHandler.CHUNK_CULLING_MAP.queueUpdateCount; - CullingHandler.CHUNK_CULLING_MAP.queueUpdateCount = 0; + if (CullingStateManager.CHUNK_CULLING_MAP != null) { + CullingStateManager.CHUNK_CULLING_MAP.lastQueueUpdateCount = CullingStateManager.CHUNK_CULLING_MAP.queueUpdateCount; + CullingStateManager.CHUNK_CULLING_MAP.queueUpdateCount = 0; } if (preChunkCullingTime != 0) { @@ -446,7 +450,7 @@ public static void checkShader() { if (SHADER_LOADER.enabledShader() && OptiFine != null) { String shaderPack = ""; try { - Field field = CullingHandler.OptiFine.getDeclaredField("currentShaderName"); + Field field = CullingStateManager.OptiFine.getDeclaredField("currentShaderName"); field.setAccessible(true); shaderPack = (String) field.get(null); } catch (NoSuchFieldException | IllegalAccessException e) { @@ -465,9 +469,9 @@ public static void checkShader() { } public static void updateDepthMap() { - CullingHandler.PROJECTION_MATRIX = new Matrix4f(RenderSystem.getProjectionMatrix()); - if (anyCulling() && !checkCulling && anyNeedTransfer()) { - float sampling = (float) (double) Config.getSampling(); + CullingStateManager.PROJECTION_MATRIX = new Matrix4f(RenderSystem.getProjectionMatrix()); + if (anyCulling() && !checkCulling && anyNeedTransfer() && continueUpdateDepth()) { + float sampling = (float) Config.getSampling(); Window window = Minecraft.getInstance().getWindow(); int width = window.getWidth(); int height = window.getHeight(); @@ -504,7 +508,7 @@ public static void updateDepthMap() { MAIN_DEPTH_TEXTURE = depthTexture; runOnDepthFrame((depthContext) -> { - useShader(CullingHandler.COPY_DEPTH_SHADER); + useShader(CullingStateManager.COPY_DEPTH_SHADER); depthContext.frame().clear(Minecraft.ON_OSX); depthContext.frame().bindWrite(false); Tesselator tesselator = Tesselator.getInstance(); @@ -570,11 +574,11 @@ public static void updateMapData() { } } - int tableCapacity = CullingHandler.ENTITY_CULLING_MAP.getEntityTable().size() / 64; + int tableCapacity = CullingStateManager.ENTITY_CULLING_MAP.getEntityTable().size() / 64; tableCapacity = tableCapacity * 64 + 64; int cullingSize = (int) Math.sqrt(tableCapacity) + 1; - if (CullingHandler.ENTITY_CULLING_MAP_TARGET.width != cullingSize || CullingHandler.ENTITY_CULLING_MAP_TARGET.height != cullingSize) { - CullingHandler.ENTITY_CULLING_MAP_TARGET.resize(cullingSize, cullingSize, Minecraft.ON_OSX); + if (CullingStateManager.ENTITY_CULLING_MAP_TARGET.width != cullingSize || CullingStateManager.ENTITY_CULLING_MAP_TARGET.height != cullingSize) { + CullingStateManager.ENTITY_CULLING_MAP_TARGET.resize(cullingSize, cullingSize, Minecraft.ON_OSX); if (ENTITY_CULLING_MAP != null) { EntityCullingMap temp = ENTITY_CULLING_MAP; ENTITY_CULLING_MAP = new EntityCullingMap(ENTITY_CULLING_MAP_TARGET.width, ENTITY_CULLING_MAP_TARGET.height); @@ -588,18 +592,18 @@ public static void updateMapData() { preEntityCullingInitTime += System.nanoTime() - time; if (Minecraft.getInstance().level != null) { - CullingHandler.ENTITY_CULLING_MAP.getEntityTable().tick(clientTickCount); + CullingStateManager.ENTITY_CULLING_MAP.getEntityTable().tick(clientTickCount); Iterable entities = Minecraft.getInstance().level.entitiesForRendering(); - entities.forEach(entity -> CullingHandler.ENTITY_CULLING_MAP.getEntityTable().addObject(entity)); + entities.forEach(entity -> CullingStateManager.ENTITY_CULLING_MAP.getEntityTable().addObject(entity)); for (Object levelrenderer$renderchunkinfo : ((IEntitiesForRender) Minecraft.getInstance().levelRenderer).renderChunksInFrustum()) { List list = ((IRenderChunkInfo) levelrenderer$renderchunkinfo).getRenderChunk().getCompiledChunk().getRenderableBlockEntities(); - list.forEach(entity -> CullingHandler.ENTITY_CULLING_MAP.getEntityTable().addObject(entity)); + list.forEach(entity -> CullingStateManager.ENTITY_CULLING_MAP.getEntityTable().addObject(entity)); } - CullingHandler.ENTITY_CULLING_MAP.getEntityTable().addAllTemp(); + CullingStateManager.ENTITY_CULLING_MAP.getEntityTable().addAllTemp(); } - CullingHandler.ENTITY_CULLING_MAP.getEntityTable().addEntityAttribute(CullingRenderEvent.ENTITY_CULLING_INSTANCE_RENDERER::addInstanceAttrib); + CullingStateManager.ENTITY_CULLING_MAP.getEntityTable().addEntityAttribute(CullingRenderEvent.ENTITY_CULLING_INSTANCE_RENDERER::addInstanceAttrib); } fps = ((AccessorMinecraft) Minecraft.getInstance()).getFps(); @@ -637,8 +641,8 @@ public static void runOnDepthFrame(Consumer consumer) { } public static void callDepthTexture() { - CullingHandler.runOnDepthFrame((depthContext) -> { - RenderSystem.setShaderTexture(depthContext.index(), CullingHandler.DEPTH_TEXTURE[depthContext.index()]); + CullingStateManager.runOnDepthFrame((depthContext) -> { + RenderSystem.setShaderTexture(depthContext.index(), CullingStateManager.DEPTH_TEXTURE[depthContext.index()]); }); } @@ -671,8 +675,8 @@ public static boolean anyCulling() { } public static boolean anyNeedTransfer() { - return (CullingHandler.ENTITY_CULLING_MAP != null && CullingHandler.ENTITY_CULLING_MAP.needTransferData()) || - (CullingHandler.CHUNK_CULLING_MAP != null && CullingHandler.CHUNK_CULLING_MAP.needTransferData()); + return (CullingStateManager.ENTITY_CULLING_MAP != null && CullingStateManager.ENTITY_CULLING_MAP.needTransferData()) || + (CullingStateManager.CHUNK_CULLING_MAP != null && CullingStateManager.CHUNK_CULLING_MAP.needTransferData()); } private static int gl33 = -1; @@ -695,4 +699,24 @@ public static int mapChunkY(double posY) { return (int) Math.floor(mappingRatio * LEVEL_SECTION_RANGE); } + + public static void updating() { + continueUpdateCount = 10; + lastUpdate = true; + } + + public static boolean continueUpdateChunk() { + if (continueUpdateCount > 0) { + return true; + } else if (lastUpdate) { + lastUpdate = false; + return true; + } + + return false; + } + + public static boolean continueUpdateDepth() { + return continueUpdateCount > 0; + } } diff --git a/src/main/java/rogo/renderingculling/api/ModLoader.java b/src/main/java/rogo/renderingculling/api/ModLoader.java index bcfdbe8..0d3377a 100644 --- a/src/main/java/rogo/renderingculling/api/ModLoader.java +++ b/src/main/java/rogo/renderingculling/api/ModLoader.java @@ -30,7 +30,7 @@ import java.util.function.Supplier; import static java.lang.Thread.MAX_PRIORITY; -import static rogo.renderingculling.api.CullingHandler.*; +import static rogo.renderingculling.api.CullingStateManager.*; public class ModLoader implements ModInitializer { @@ -159,4 +159,10 @@ public static AABB getObjectAABB(Object o) { return null; } + + public static void pauseAsync() { + if (ModLoader.hasMod("embeddium")) { + fullChunkUpdateCooldown = 60; + } + } } diff --git a/src/main/java/rogo/renderingculling/api/data/ChunkCullingMap.java b/src/main/java/rogo/renderingculling/api/data/ChunkCullingMap.java index b635b75..35e9a9b 100644 --- a/src/main/java/rogo/renderingculling/api/data/ChunkCullingMap.java +++ b/src/main/java/rogo/renderingculling/api/data/ChunkCullingMap.java @@ -2,7 +2,7 @@ import net.minecraft.world.phys.Vec3; import rogo.renderingculling.api.Config; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; public class ChunkCullingMap extends CullingMap { private int renderDistance = 0; @@ -16,6 +16,11 @@ public ChunkCullingMap(int width, int height) { super(width, height); } + @Override + protected boolean shouldUpdate() { + return CullingStateManager.continueUpdateChunk(); + } + @Override int configDelayCount() { return Config.getDepthUpdateDelay(); @@ -23,7 +28,7 @@ int configDelayCount() { @Override int bindFrameBufferId() { - return CullingHandler.CHUNK_CULLING_MAP_TARGET.frameBufferId; + return CullingStateManager.CHUNK_CULLING_MAP_TARGET.frameBufferId; } public void generateIndex(int renderDistance) { @@ -32,17 +37,17 @@ public void generateIndex(int renderDistance) { } public void updateCamera() { - Vec3 camera = CullingHandler.CAMERA.getPosition(); + Vec3 camera = CullingStateManager.CAMERA.getPosition(); cameraX = (int) camera.x >> 4; cameraZ = (int) camera.z >> 4; } public boolean isChunkOffsetCameraVisible(int x, int y, int z, boolean checkForChunk) { - return isChunkVisible((x >> 4) - cameraX, CullingHandler.mapChunkY(y), (z >> 4) - cameraZ, checkForChunk); + return isChunkVisible((x >> 4) - cameraX, CullingStateManager.mapChunkY(y), (z >> 4) - cameraZ, checkForChunk); } public boolean isChunkVisible(int posX, int posY, int posZ, boolean checkForChunk) { - int index = 1 + (((posX + renderDistance) * spacePartitionSize * CullingHandler.LEVEL_SECTION_RANGE + (posZ + renderDistance) * CullingHandler.LEVEL_SECTION_RANGE + posY) << 2); + int index = 1 + (((posX + renderDistance) * spacePartitionSize * CullingStateManager.LEVEL_SECTION_RANGE + (posZ + renderDistance) * CullingStateManager.LEVEL_SECTION_RANGE + posY) << 2); if (index > 0 && index < cullingBuffer.limit()) { return (cullingBuffer.get(index) & 0xFF) > (checkForChunk ? 0 : 127); } diff --git a/src/main/java/rogo/renderingculling/api/data/CullingMap.java b/src/main/java/rogo/renderingculling/api/data/CullingMap.java index e755c4a..840436c 100644 --- a/src/main/java/rogo/renderingculling/api/data/CullingMap.java +++ b/src/main/java/rogo/renderingculling/api/data/CullingMap.java @@ -5,7 +5,7 @@ import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL31; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import java.nio.ByteBuffer; @@ -29,7 +29,7 @@ public CullingMap(int width, int height) { GL15.glBindBuffer(GL31.GL_PIXEL_PACK_BUFFER, pboId); GL15.glBufferData(GL31.GL_PIXEL_PACK_BUFFER, (long) width * height * 4 * Float.BYTES, GL15.GL_DYNAMIC_READ); GL15.glBindBuffer(GL31.GL_PIXEL_PACK_BUFFER, 0); - CullingHandler.bindMainFrameTarget(); + CullingStateManager.bindMainFrameTarget(); } public boolean needTransferData() { @@ -46,9 +46,9 @@ public void transferData() { GL15.glBindBuffer(GL31.GL_PIXEL_PACK_BUFFER, pboId); GL11.glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, 0); GL15.glBindBuffer(GL31.GL_PIXEL_PACK_BUFFER, 0); - CullingHandler.bindMainFrameTarget(); + CullingStateManager.bindMainFrameTarget(); delayCount = configDelayCount() + dynamicDelayCount(); - } else { + } else if (shouldUpdate()) { delayCount--; } if (delayCount <= 0) { @@ -56,6 +56,8 @@ public void transferData() { } } + protected abstract boolean shouldUpdate(); + public void readData() { GL15.glBindBuffer(GL31.GL_PIXEL_PACK_BUFFER, pboId); GL15.glGetBufferSubData(GL31.GL_PIXEL_PACK_BUFFER, 0, cullingBuffer); @@ -66,8 +68,8 @@ public void readData() { abstract int configDelayCount(); public int dynamicDelayCount() { - if (CullingHandler.fps > 100) { - return CullingHandler.fps / 100; + if (CullingStateManager.fps > 100) { + return CullingStateManager.fps / 100; } return 0; diff --git a/src/main/java/rogo/renderingculling/api/data/EntityCullingMap.java b/src/main/java/rogo/renderingculling/api/data/EntityCullingMap.java index 629d571..bd8e6b0 100644 --- a/src/main/java/rogo/renderingculling/api/data/EntityCullingMap.java +++ b/src/main/java/rogo/renderingculling/api/data/EntityCullingMap.java @@ -5,7 +5,7 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import rogo.renderingculling.api.Config; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.ModLoader; import rogo.renderingculling.util.LifeTimer; @@ -20,6 +20,11 @@ public EntityCullingMap(int width, int height) { super(width, height); } + @Override + protected boolean shouldUpdate() { + return true; + } + @Override int configDelayCount() { return Config.getDepthUpdateDelay(); @@ -27,19 +32,19 @@ int configDelayCount() { @Override int bindFrameBufferId() { - return CullingHandler.ENTITY_CULLING_MAP_TARGET.frameBufferId; + return CullingStateManager.ENTITY_CULLING_MAP_TARGET.frameBufferId; } public boolean isObjectVisible(Object o) { int idx = entityMap.getIndex(o); idx = 1 + idx * 4; if (entityMap.tempObjectTimer.contains(o)) - entityMap.addTemp(o, CullingHandler.clientTickCount); + entityMap.addTemp(o, CullingStateManager.clientTickCount); if (idx > -1 && idx < cullingBuffer.limit()) { return (cullingBuffer.get(idx) & 0xFF) > 0; } else { - entityMap.addTemp(o, CullingHandler.clientTickCount); + entityMap.addTemp(o, CullingStateManager.clientTickCount); } return true; } diff --git a/src/main/java/rogo/renderingculling/gui/ConfigScreen.java b/src/main/java/rogo/renderingculling/gui/ConfigScreen.java index 3ea3d55..fd847ce 100644 --- a/src/main/java/rogo/renderingculling/gui/ConfigScreen.java +++ b/src/main/java/rogo/renderingculling/gui/ConfigScreen.java @@ -16,7 +16,7 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; import rogo.renderingculling.api.Config; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.ModLoader; import java.util.List; @@ -59,7 +59,7 @@ public void renderBackground(GuiGraphics guiGraphics) { float bgColor = 1.0f; float bgAlpha = 0.3f; RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 0.1f); - CullingHandler.useShader(CullingHandler.REMOVE_COLOR_SHADER); + CullingStateManager.useShader(CullingStateManager.REMOVE_COLOR_SHADER); BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder(); bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX); bufferbuilder.vertex(right - 1, bottom + 1, 0.0D) @@ -130,10 +130,10 @@ protected void init() { } if (player.getName().getString().equals("Dev")) { - addConfigButton(() -> CullingHandler.checkCulling, (b) -> CullingHandler.checkCulling = b, () -> Component.literal("Debug")) + addConfigButton(() -> CullingStateManager.checkCulling, (b) -> CullingStateManager.checkCulling = b, () -> Component.literal("Debug")) .setDetailMessage(() -> Component.translatable("brute_force_rendering_culling.detail.debug")); - addConfigButton(() -> CullingHandler.checkTexture, (b) -> CullingHandler.checkTexture = b, () -> Component.literal("Check Texture")) + addConfigButton(() -> CullingStateManager.checkTexture, (b) -> CullingStateManager.checkTexture = b, () -> Component.literal("Check Texture")) .setDetailMessage(() -> Component.translatable("brute_force_rendering_culling.detail.check_texture")); } @@ -172,7 +172,7 @@ protected void init() { .setDetailMessage(() -> Component.translatable("brute_force_rendering_culling.detail.cull_chunk")); addConfigButton(Config::getCullEntity, Config::setCullEntity, () -> Component.translatable("brute_force_rendering_culling.cull_entity")) .setDetailMessage(() -> { - if (CullingHandler.gl33()) { + if (CullingStateManager.gl33()) { return Component.translatable("brute_force_rendering_culling.detail.cull_entity"); } else { return Component.translatable("brute_force_rendering_culling.detail.gl33"); @@ -273,7 +273,7 @@ private void renderButtonDetails(GuiGraphics guiGraphics, Component details) { int top = 2; float bgColor = 0.0f; - float bgAlpha = 0.6f; + float bgAlpha = 0.7f; RenderSystem.setShader(GameRenderer::getPositionColorShader); BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder(); diff --git a/src/main/java/rogo/renderingculling/gui/NeatButton.java b/src/main/java/rogo/renderingculling/gui/NeatButton.java index 7b577c9..d18b137 100644 --- a/src/main/java/rogo/renderingculling/gui/NeatButton.java +++ b/src/main/java/rogo/renderingculling/gui/NeatButton.java @@ -48,7 +48,6 @@ public void renderWidget(GuiGraphics guiGraphics, int p_93747_, int p_93748_, fl Font font = minecraft.font; boolean display = getter.get(); int j = display && enable.get() ? 16777215 : 10526880; - guiGraphics.drawCenteredString(font, display ? Component.literal("■") : Component.literal("□"), this.getX() + this.width / 2 - ((this.width - 20) / 2), this.getY() + (this.height - 8) / 2, j | Mth.ceil(this.alpha * 255.0F) << 24); if (display != cache) { cache = display; @@ -78,6 +77,7 @@ public void renderWidget(GuiGraphics guiGraphics, int p_93747_, int p_93748_, fl bufferbuilder.vertex(this.getX() - 1, this.getY() - 1, 0.0D).color(color, color, color, 1.0f).endVertex(); BufferUploader.drawWithShader(bufferbuilder.end()); guiGraphics.drawCenteredString(font, this.getMessage(), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, j | Mth.ceil(this.alpha * 255.0F) << 24); + guiGraphics.drawCenteredString(font, display ? Component.literal("■") : Component.literal("□"), this.getX() + this.width / 2 - ((this.width - 20) / 2), this.getY() + (this.height - 8) / 2, j | Mth.ceil(this.alpha * 255.0F) << 24); RenderSystem.disableBlend(); RenderSystem.defaultBlendFunc(); } diff --git a/src/main/java/rogo/renderingculling/mixin/MixinBlockEntityRender.java b/src/main/java/rogo/renderingculling/mixin/MixinBlockEntityRender.java index c51a924..b1fefd2 100644 --- a/src/main/java/rogo/renderingculling/mixin/MixinBlockEntityRender.java +++ b/src/main/java/rogo/renderingculling/mixin/MixinBlockEntityRender.java @@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; @Mixin(BlockEntityRenderDispatcher.class) public class MixinBlockEntityRender { @@ -19,7 +19,7 @@ public class MixinBlockEntityRender { public void onShouldRender(E p_112268_, float p_112269_, PoseStack p_112270_, MultiBufferSource p_112271_, CallbackInfo ci) { AABB aabb = new AABB(p_112268_.getBlockPos()); aabb.inflate(Vec3.atCenterOf(p_112268_.getBlockPos()).distanceTo(Minecraft.getInstance().gameRenderer.getMainCamera().getPosition()) * 0.03125); - if(CullingHandler.shouldSkipBlockEntity(p_112268_, aabb, p_112268_.getBlockPos())) + if(CullingStateManager.shouldSkipBlockEntity(p_112268_, aabb, p_112268_.getBlockPos())) ci.cancel(); } } diff --git a/src/main/java/rogo/renderingculling/mixin/MixinEntityRender.java b/src/main/java/rogo/renderingculling/mixin/MixinEntityRender.java index 1aeafff..68331db 100644 --- a/src/main/java/rogo/renderingculling/mixin/MixinEntityRender.java +++ b/src/main/java/rogo/renderingculling/mixin/MixinEntityRender.java @@ -7,13 +7,13 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; @Mixin(EntityRenderDispatcher.class) public class MixinEntityRender { @Inject(method = "shouldRender", at = @At("RETURN"), cancellable = true) public void onShouldRender(E p_114398_, Frustum p_114399_, double p_114400_, double p_114401_, double p_114402_, CallbackInfoReturnable cir) { - if (cir.getReturnValue() && !p_114398_.noCulling && CullingHandler.shouldSkipEntity(p_114398_)) { + if (cir.getReturnValue() && !p_114398_.noCulling && CullingStateManager.shouldSkipEntity(p_114398_)) { cir.setReturnValue(false); } } diff --git a/src/main/java/rogo/renderingculling/mixin/MixinFrustum.java b/src/main/java/rogo/renderingculling/mixin/MixinFrustum.java index b3ac891..c993c9e 100644 --- a/src/main/java/rogo/renderingculling/mixin/MixinFrustum.java +++ b/src/main/java/rogo/renderingculling/mixin/MixinFrustum.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import rogo.renderingculling.api.Config; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.util.DummySection; @Mixin(Frustum.class) @@ -15,7 +15,7 @@ public abstract class MixinFrustum { @Inject(method = "isVisible", at = @At(value = "RETURN"), cancellable = true) public void afterVisible(AABB aabb, CallbackInfoReturnable cir) { - if (CullingHandler.applyFrustum && Config.shouldCullChunk() && cir.getReturnValue() && !CullingHandler.shouldRenderChunk(new DummySection(aabb), true)) + if (CullingStateManager.applyFrustum && Config.shouldCullChunk() && cir.getReturnValue() && !CullingStateManager.shouldRenderChunk(new DummySection(aabb), true)) cir.setReturnValue(false); } } diff --git a/src/main/java/rogo/renderingculling/mixin/MixinGameRenderer.java b/src/main/java/rogo/renderingculling/mixin/MixinGameRenderer.java index 3c9e008..e112261 100644 --- a/src/main/java/rogo/renderingculling/mixin/MixinGameRenderer.java +++ b/src/main/java/rogo/renderingculling/mixin/MixinGameRenderer.java @@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; @Mixin(GameRenderer.class) public abstract class MixinGameRenderer { @@ -20,6 +20,6 @@ public abstract class MixinGameRenderer { @Inject(method = "renderLevel", at = @At(value = "HEAD")) public void afterRunTick(float p_109090_, long p_109091_, PoseStack p_109092_, CallbackInfo ci) { - CullingHandler.FOV = this.getFov(this.getMainCamera(), p_109090_, true); + CullingStateManager.FOV = this.getFov(this.getMainCamera(), p_109090_, true); } } diff --git a/src/main/java/rogo/renderingculling/mixin/MixinInactiveProfiler.java b/src/main/java/rogo/renderingculling/mixin/MixinInactiveProfiler.java index b24a707..ef55ff1 100644 --- a/src/main/java/rogo/renderingculling/mixin/MixinInactiveProfiler.java +++ b/src/main/java/rogo/renderingculling/mixin/MixinInactiveProfiler.java @@ -5,18 +5,18 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; @Mixin(InactiveProfiler.class) public class MixinInactiveProfiler { @Inject(method = "popPush(Ljava/lang/String;)V", at = @At(value = "HEAD")) public void onPopPush(String p_18395_, CallbackInfo ci) { - CullingHandler.onProfilerPopPush(p_18395_); + CullingStateManager.onProfilerPopPush(p_18395_); } @Inject(method = "push(Ljava/lang/String;)V", at = @At(value = "HEAD")) public void onPush(String p_18395_, CallbackInfo ci) { - CullingHandler.onProfilerPush(p_18395_); + CullingStateManager.onProfilerPush(p_18395_); } } diff --git a/src/main/java/rogo/renderingculling/mixin/MixinLevelRender.java b/src/main/java/rogo/renderingculling/mixin/MixinLevelRender.java index 41b1717..9ecc0e7 100644 --- a/src/main/java/rogo/renderingculling/mixin/MixinLevelRender.java +++ b/src/main/java/rogo/renderingculling/mixin/MixinLevelRender.java @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.impl.IEntitiesForRender; import rogo.renderingculling.util.VanillaAsyncUtil; @@ -50,17 +50,18 @@ public void onSetupRenderHead(Camera p_194339_, Frustum p_194340_, boolean p_194 @Inject(method = "applyFrustum", at = @At(value = "HEAD")) public void onApplyFrustumHead(Frustum p_194355_, CallbackInfo ci) { - CullingHandler.applyFrustum = true; + CullingStateManager.applyFrustum = true; + CullingStateManager.updating(); } @Inject(method = "applyFrustum", at = @At(value = "RETURN")) public void onApplyFrustumReturn(Frustum p_194355_, CallbackInfo ci) { - CullingHandler.applyFrustum = false; + CullingStateManager.applyFrustum = false; } @Inject(method = "prepareCullFrustum", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/culling/Frustum;(Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V")) public void onPrepareCullFrustum(PoseStack p_172962_, Vec3 p_172963_, Matrix4f p_172964_, CallbackInfo ci) { - CullingHandler.PROJECTION_MATRIX = new Matrix4f(p_172964_); + CullingStateManager.PROJECTION_MATRIX = new Matrix4f(p_172964_); } @Override diff --git a/src/main/java/rogo/renderingculling/mixin/MixinMinecraft.java b/src/main/java/rogo/renderingculling/mixin/MixinMinecraft.java index f42a712..f28acd6 100644 --- a/src/main/java/rogo/renderingculling/mixin/MixinMinecraft.java +++ b/src/main/java/rogo/renderingculling/mixin/MixinMinecraft.java @@ -6,22 +6,22 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; @Mixin(Minecraft.class) public class MixinMinecraft { @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GameRenderer;render(FJZ)V", shift = At.Shift.AFTER)) public void afterRunTick(boolean p_91384_, CallbackInfo ci) { - CullingHandler.onProfilerPopPush("afterRunTick"); + CullingStateManager.onProfilerPopPush("afterRunTick"); } @Inject(method = "runTick", at = @At(value = "HEAD")) public void beforeRunTick(boolean p_91384_, CallbackInfo ci) { - CullingHandler.onProfilerPopPush("beforeRunTick"); + CullingStateManager.onProfilerPopPush("beforeRunTick"); } @Inject(method = "setLevel", at = @At(value = "HEAD")) public void onJoinWorld(ClientLevel world, CallbackInfo ci) { - CullingHandler.onWorldUnload(world); + CullingStateManager.onWorldUnload(world); } } diff --git a/src/main/java/rogo/renderingculling/mixin/MixinShaderInstance.java b/src/main/java/rogo/renderingculling/mixin/MixinShaderInstance.java index de6b46f..5248ee8 100644 --- a/src/main/java/rogo/renderingculling/mixin/MixinShaderInstance.java +++ b/src/main/java/rogo/renderingculling/mixin/MixinShaderInstance.java @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.CullingRenderEvent; import rogo.renderingculling.api.ModLoader; import rogo.renderingculling.api.impl.ICullingShader; @@ -175,7 +175,7 @@ public Uniform getBoxScale() { @Inject(at = @At("TAIL"), method = "apply") public void onApply(CallbackInfo ci) { - if (CullingHandler.updatingDepth) + if (CullingStateManager.updatingDepth) ProgramManager.glUseProgram(this.programId); } diff --git a/src/main/java/rogo/renderingculling/mixin/fabric/MixinKeyboardHandler.java b/src/main/java/rogo/renderingculling/mixin/fabric/MixinKeyboardHandler.java index 83d2346..0dd1ef9 100644 --- a/src/main/java/rogo/renderingculling/mixin/fabric/MixinKeyboardHandler.java +++ b/src/main/java/rogo/renderingculling/mixin/fabric/MixinKeyboardHandler.java @@ -2,14 +2,12 @@ import net.minecraft.client.KeyboardHandler; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.culling.Frustum; import net.minecraft.world.entity.Entity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; @Mixin(KeyboardHandler.class) public class MixinKeyboardHandler { @@ -17,7 +15,7 @@ public class MixinKeyboardHandler { @Inject(method = "keyPress", at= @At(value = "RETURN")) void onKeyPress(long l, int i, int j, int k, int m, CallbackInfo ci) { if (l == Minecraft.getInstance().getWindow().getWindow()) { - CullingHandler.onProfilerPush("onKeyboardInput"); + CullingStateManager.onProfilerPush("onKeyboardInput"); } } } diff --git a/src/main/java/rogo/renderingculling/mixin/sodium/MixinOcclusionCuller.java b/src/main/java/rogo/renderingculling/mixin/sodium/MixinOcclusionCuller.java index cbdfa15..31ef227 100644 --- a/src/main/java/rogo/renderingculling/mixin/sodium/MixinOcclusionCuller.java +++ b/src/main/java/rogo/renderingculling/mixin/sodium/MixinOcclusionCuller.java @@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import rogo.renderingculling.api.Config; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.impl.IRenderSectionVisibility; @Mixin(OcclusionCuller.class) @@ -18,7 +18,7 @@ public abstract class MixinOcclusionCuller { @Inject(method = "isSectionVisible", at = @At(value = "RETURN"), remap = false, cancellable = true) private static void onIsSectionVisible(RenderSection section, Viewport viewport, float maxDistance, CallbackInfoReturnable cir) { - if (Config.shouldCullChunk() && cir.getReturnValue() && !CullingHandler.shouldRenderChunk((IRenderSectionVisibility) section, true)) + if (Config.shouldCullChunk() && cir.getReturnValue() && !CullingStateManager.shouldRenderChunk((IRenderSectionVisibility) section, true)) cir.setReturnValue(false); } diff --git a/src/main/java/rogo/renderingculling/mixin/sodium/MixinRenderSectionManager.java b/src/main/java/rogo/renderingculling/mixin/sodium/MixinRenderSectionManager.java index 55c20e1..3bba97f 100644 --- a/src/main/java/rogo/renderingculling/mixin/sodium/MixinRenderSectionManager.java +++ b/src/main/java/rogo/renderingculling/mixin/sodium/MixinRenderSectionManager.java @@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import rogo.renderingculling.api.Config; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.impl.IRenderSectionVisibility; import rogo.renderingculling.util.SodiumSectionAsyncUtil; @@ -41,13 +41,18 @@ private void init(ClientLevel world, int renderDistance, CommandList commandList @Inject(method = "isSectionVisible", at = @At(value = "RETURN"), remap = false, locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) private void onIsSectionVisible(int x, int y, int z, CallbackInfoReturnable cir, RenderSection section) { if (Config.shouldCullChunk()) - cir.setReturnValue(CullingHandler.shouldRenderChunk((IRenderSectionVisibility) section, false)); + cir.setReturnValue(CullingStateManager.shouldRenderChunk((IRenderSectionVisibility) section, false)); + } + + @Inject(method = "update", at = @At(value = "HEAD"), remap = false) + private void onUpdate(Camera camera, Viewport viewport, int frame, boolean spectator, CallbackInfo ci) { + CullingStateManager.updating(); } @ModifyVariable(name = "visitor", method = "createTerrainRenderList", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/occlusion/OcclusionCuller;findVisible(Lme/jellysquid/mods/sodium/client/render/chunk/occlusion/OcclusionCuller$Visitor;Lme/jellysquid/mods/sodium/client/render/viewport/Viewport;FZI)V", shift = At.Shift.BEFORE), remap = false) private VisibleChunkCollector onCreateTerrainRenderList(VisibleChunkCollector value) { if (Config.getAsyncChunkRebuild()) { - VisibleChunkCollector collector = CullingHandler.renderingIris() ? SodiumSectionAsyncUtil.getShadowCollector() : SodiumSectionAsyncUtil.getChunkCollector(); + VisibleChunkCollector collector = CullingStateManager.renderingIris() ? SodiumSectionAsyncUtil.getShadowCollector() : SodiumSectionAsyncUtil.getChunkCollector(); return collector == null ? value : collector; } return value; @@ -56,7 +61,7 @@ private VisibleChunkCollector onCreateTerrainRenderList(VisibleChunkCollector va @Inject(method = "updateChunks", at = @At(value = "HEAD"), remap = false) private void onCreateTerrainRenderList(boolean updateImmediately, CallbackInfo ci) { if (Config.getAsyncChunkRebuild()) { - VisibleChunkCollector collector = CullingHandler.renderingIris() ? SodiumSectionAsyncUtil.getShadowCollector() : SodiumSectionAsyncUtil.getChunkCollector(); + VisibleChunkCollector collector = CullingStateManager.renderingIris() ? SodiumSectionAsyncUtil.getShadowCollector() : SodiumSectionAsyncUtil.getChunkCollector(); if(collector != null) this.renderLists = collector.createRenderLists(); } diff --git a/src/main/java/rogo/renderingculling/util/OcclusionCullerThread.java b/src/main/java/rogo/renderingculling/util/OcclusionCullerThread.java index e2ea69f..329e40d 100644 --- a/src/main/java/rogo/renderingculling/util/OcclusionCullerThread.java +++ b/src/main/java/rogo/renderingculling/util/OcclusionCullerThread.java @@ -2,7 +2,7 @@ import net.minecraft.client.Minecraft; import rogo.renderingculling.api.Config; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.ModLoader; public class OcclusionCullerThread extends Thread { @@ -30,7 +30,7 @@ public static void shouldUpdate() { public void run() { while (!finished) { try { - if (CullingHandler.CHUNK_CULLING_MAP != null && CullingHandler.CHUNK_CULLING_MAP.isDone()) { + if (CullingStateManager.CHUNK_CULLING_MAP != null && CullingStateManager.CHUNK_CULLING_MAP.isDone()) { if (Config.getAsyncChunkRebuild()) { if (ModLoader.hasSodium()) { SodiumSectionAsyncUtil.asyncSearchRebuildSection(); diff --git a/src/main/java/rogo/renderingculling/util/OptiFineLoaderImpl.java b/src/main/java/rogo/renderingculling/util/OptiFineLoaderImpl.java index d9c4c10..55b1989 100644 --- a/src/main/java/rogo/renderingculling/util/OptiFineLoaderImpl.java +++ b/src/main/java/rogo/renderingculling/util/OptiFineLoaderImpl.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.Minecraft; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import java.lang.reflect.Field; @@ -12,7 +12,7 @@ public class OptiFineLoaderImpl implements ShaderLoader { @Override public int getFrameBufferID() { try { - Field f = CullingHandler.OptiFine.getDeclaredField("dfb"); + Field f = CullingStateManager.OptiFine.getDeclaredField("dfb"); f.setAccessible(true); Object dfb = f.get(null); Field buffer = dfb.getClass().getDeclaredField("glFramebuffer"); @@ -28,7 +28,7 @@ public int getFrameBufferID() { @Override public boolean renderingShaderPass() { try { - Field field = CullingHandler.OptiFine.getDeclaredField("shaderPackLoaded"); + Field field = CullingStateManager.OptiFine.getDeclaredField("shaderPackLoaded"); field.setAccessible(true); return (Boolean) field.get(null); } catch (NoSuchFieldException | IllegalAccessException e) { @@ -48,7 +48,7 @@ public void bindDefaultFrameBuffer() { try { glState = Class.forName("net.optifine.shaders.GlState"); } catch (ClassNotFoundException e) { - CullingHandler.LOGGER.debug("GlState Not Found"); + CullingStateManager.LOGGER.debug("GlState Not Found"); } } try { diff --git a/src/main/java/rogo/renderingculling/util/SodiumSectionAsyncUtil.java b/src/main/java/rogo/renderingculling/util/SodiumSectionAsyncUtil.java index 9c5fc88..4b81040 100644 --- a/src/main/java/rogo/renderingculling/util/SodiumSectionAsyncUtil.java +++ b/src/main/java/rogo/renderingculling/util/SodiumSectionAsyncUtil.java @@ -9,7 +9,7 @@ import me.jellysquid.mods.sodium.client.render.chunk.region.RenderRegion; import me.jellysquid.mods.sodium.client.render.viewport.Viewport; import net.minecraft.world.level.Level; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.impl.ICollectorAccessor; import java.util.ArrayDeque; @@ -39,13 +39,13 @@ public static void fromSectionManager(Long2ReferenceMap sections, public static void asyncSearchRebuildSection() { shouldUpdate.acquireUninterruptibly(); - if (CullingHandler.enabledShader() && shadowViewport != null) { + if (CullingStateManager.enabledShader() && shadowViewport != null) { frame++; - CullingHandler.useOcclusionCulling = false; + CullingStateManager.useOcclusionCulling = false; AsynchronousChunkCollector shadowCollector = new AsynchronousChunkCollector(frame); occlusionCuller.findVisible(shadowCollector, shadowViewport, shadowSearchDistance, shadowUseOcclusionCulling, frame); SodiumSectionAsyncUtil.shadowCollector = shadowCollector; - CullingHandler.useOcclusionCulling = true; + CullingStateManager.useOcclusionCulling = true; } if (viewport != null) { @@ -54,8 +54,8 @@ public static void asyncSearchRebuildSection() { occlusionCuller.findVisible(collector, viewport, searchDistance, useOcclusionCulling, frame); SodiumSectionAsyncUtil.collector = collector; - if(CullingHandler.CHUNK_CULLING_MAP != null) - CullingHandler.CHUNK_CULLING_MAP.queueUpdateCount++; + if(CullingStateManager.CHUNK_CULLING_MAP != null) + CullingStateManager.CHUNK_CULLING_MAP.queueUpdateCount++; Map> rebuildList = SodiumSectionAsyncUtil.collector.getRebuildLists(); for(ArrayDeque arrayDeque : rebuildList.values()) { if (!arrayDeque.isEmpty()) { @@ -67,7 +67,7 @@ public static void asyncSearchRebuildSection() { } public static void update(Viewport viewport, float searchDistance, boolean useOcclusionCulling) { - if (CullingHandler.renderingShader()) { + if (CullingStateManager.renderingShader()) { SodiumSectionAsyncUtil.shadowViewport = viewport; SodiumSectionAsyncUtil.shadowSearchDistance = searchDistance; SodiumSectionAsyncUtil.shadowUseOcclusionCulling = useOcclusionCulling; @@ -126,7 +126,7 @@ public void visit(RenderSection section, boolean visible) { @Override public Map> getRebuildLists() { - if(CullingHandler.needPauseRebuild()) { + if(CullingStateManager.needPauseRebuild()) { return syncRebuildLists; } super.getRebuildLists().forEach(((chunkUpdateType, renderSections) -> { diff --git a/src/main/java/rogo/renderingculling/util/VanillaAsyncUtil.java b/src/main/java/rogo/renderingculling/util/VanillaAsyncUtil.java index 1c23e81..8e139a7 100644 --- a/src/main/java/rogo/renderingculling/util/VanillaAsyncUtil.java +++ b/src/main/java/rogo/renderingculling/util/VanillaAsyncUtil.java @@ -8,7 +8,7 @@ import net.minecraft.core.SectionPos; import org.jetbrains.annotations.NotNull; import rogo.renderingculling.api.Config; -import rogo.renderingculling.api.CullingHandler; +import rogo.renderingculling.api.CullingStateManager; import rogo.renderingculling.api.impl.IEntitiesForRender; import rogo.renderingculling.api.impl.IRenderChunkInfo; import rogo.renderingculling.api.impl.IRenderSectionVisibility; @@ -40,7 +40,7 @@ public static void asyncSearchRebuildSection() { while (!queue.isEmpty()) { LevelRenderer.RenderChunkInfo last = queue.poll(); ChunkRenderDispatcher.RenderChunk lastRenderChunk = ((IRenderChunkInfo) last).getRenderChunk(); - if (originChunk != last && (!CullingHandler.FRUSTUM.isVisible(lastRenderChunk.getBoundingBox()) || !CullingHandler.shouldRenderChunk((IRenderSectionVisibility) lastRenderChunk, true))) { + if (originChunk != last && (!CullingStateManager.FRUSTUM.isVisible(lastRenderChunk.getBoundingBox()) || !CullingStateManager.shouldRenderChunk((IRenderSectionVisibility) lastRenderChunk, true))) { continue; } @@ -61,8 +61,8 @@ public static void asyncSearchRebuildSection() { } } } - if(CullingHandler.CHUNK_CULLING_MAP != null) - CullingHandler.CHUNK_CULLING_MAP.queueUpdateCount++; + if(CullingStateManager.CHUNK_CULLING_MAP != null) + CullingStateManager.CHUNK_CULLING_MAP.queueUpdateCount++; storage = renderChunkStorage; } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d986f0f..bdb1401 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "brute_force_rendering_culling", - "version": "0.5.5", + "version": "0.5.8", "name": "Brute force Rendering Culling", "description": "", "authors": [