]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Add "Fast Render" option to configure culling behaviors
authorishland <ishlandmc@yeah.net>
Sun, 15 Aug 2021 06:27:15 +0000 (14:27 +0800)
committerirtimaled <irtimaled@gmail.com>
Sun, 15 Aug 2021 18:36:02 +0000 (11:36 -0700)
src/main/java/com/irtimaled/bbor/client/ClientRenderer.java
src/main/java/com/irtimaled/bbor/client/RenderCulling.java
src/main/java/com/irtimaled/bbor/client/config/ConfigManager.java
src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java
src/main/java/com/irtimaled/bbor/common/models/AbstractBoundingBox.java
src/main/java/com/irtimaled/bbor/common/models/BoundingBoxCuboid.java
src/main/java/com/irtimaled/bbor/mixin/client/renderer/MixinDebugHud.java
src/main/java/com/irtimaled/bbor/mixin/client/renderer/MixinWorldRenderer.java
src/main/resources/assets/bbor/lang/en_us.json

index 1d517b39834038d9ddcf3ba38561082ffd2ca85c..15aa4931998e6a72d6cf470be12fb239a0d1cd71 100644 (file)
@@ -1,5 +1,6 @@
 package com.irtimaled.bbor.client;
 
+import com.irtimaled.bbor.client.config.ConfigManager;
 import com.irtimaled.bbor.client.interop.ClientInterop;
 import com.irtimaled.bbor.client.interop.TileEntitiesHelper;
 import com.irtimaled.bbor.client.models.Point;
@@ -116,7 +117,9 @@ public class ClientRenderer {
         RenderHelper.beforeRender();
         TileEntitiesHelper.clearCache();
 
-        for (AbstractBoundingBox key : getBoundingBoxes(dimensionId)) {
+        final List<AbstractBoundingBox> boundingBoxes = getBoundingBoxes(dimensionId);
+        RenderCulling.flushPreRendering();
+        for (AbstractBoundingBox key : boundingBoxes) {
             AbstractRenderer renderer = key.getRenderer();
             if (renderer != null) renderer.render(matrixStack, key);
         }
@@ -124,16 +127,19 @@ public class ClientRenderer {
         RenderQueue.renderDeferred();
 
         RenderHelper.afterRender();
+        RenderCulling.flushRendering();
         matrixStack.pop();
         lastDurationNanos.set(System.nanoTime() - startTime);
     }
 
     public static List<AbstractBoundingBox> getBoundingBoxes(DimensionId dimensionId) {
         List<AbstractBoundingBox> tmp = new LinkedList<>();
+        final boolean doPreCulling = ConfigManager.fastRender.get() >= 2;
         for (IBoundingBoxProvider<?> provider : providers) {
             if (provider.canProvide(dimensionId)) {
                 for (AbstractBoundingBox boundingBox : provider.get(dimensionId)) {
-                    if (boundingBox.isVisibleCulling() && isWithinRenderDistance(boundingBox)) {
+                    if (isWithinRenderDistance(boundingBox)) {
+                        if (doPreCulling && !boundingBox.isVisibleCulling()) continue;
                         tmp.add(boundingBox);
                     }
                 }
index 4a31ecba5eb5d515a2689516a4d6250501951079..cda563677587caa2cecaf84574fe47517939375f 100644 (file)
@@ -1,8 +1,11 @@
 package com.irtimaled.bbor.client;
 
+import com.irtimaled.bbor.client.config.ConfigManager;
 import net.minecraft.client.render.Frustum;
 import net.minecraft.util.math.Box;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
 public class RenderCulling {
@@ -13,12 +16,14 @@ public class RenderCulling {
     private static final AtomicInteger totalCount = new AtomicInteger();
     private static final AtomicInteger culledCountLast = new AtomicInteger();
     private static final AtomicInteger totalCountLast = new AtomicInteger();
+    private static final AtomicInteger preCulledCountLast = new AtomicInteger();
+    private static final AtomicInteger preTotalCountLast = new AtomicInteger();
 
     public static void setFrustum(Frustum frustum) {
         RenderCulling.frustum = frustum;
     }
 
-    public static void flushStats() {
+    public static void flushRendering() {
         synchronized (mutex) {
             culledCountLast.set(culledCount.get());
             totalCountLast.set(totalCount.get());
@@ -27,18 +32,37 @@ public class RenderCulling {
         }
     }
 
-    public static String debugString() {
-        final int culledCountLast;
-        final int totalCountLast;
+    public static void flushPreRendering() {
         synchronized (mutex) {
-            culledCountLast = RenderCulling.culledCountLast.get();
-            totalCountLast = RenderCulling.totalCountLast.get();
+            preCulledCountLast.set(culledCount.get());
+            preTotalCountLast.set(totalCount.get());
+            culledCount.set(0);
+            totalCount.set(0);
         }
-        if (totalCountLast != 0) {
-            return String.format("[BBOR] Rendering culling: %d / %d (%.1f%%)", culledCountLast, totalCountLast, (culledCountLast / (float) totalCountLast) * 100.0);
-        } else {
-            return "[BBOR] Rendering not enabled";
+    }
+
+    public static List<String> debugStrings() {
+        if (!ClientRenderer.getActive()) return List.of("[BBOR] Rendering not enabled");
+        final ArrayList<String> list = new ArrayList<>(2);
+        if (ConfigManager.fastRender.get() >= 2) {
+            final int preCulledCountLast;
+            final int preTotalCountLast;
+            synchronized (mutex) {
+                preCulledCountLast = RenderCulling.preCulledCountLast.get();
+                preTotalCountLast = RenderCulling.preTotalCountLast.get();
+            }
+            list.add(String.format("[BBOR] Pre-culling: %d / %d (%.1f%%)", preCulledCountLast, preTotalCountLast, (preCulledCountLast / (float) preTotalCountLast) * 100.0));
         }
+        if (ConfigManager.fastRender.get() >= 1) {
+            final int culledCountLast;
+            final int totalCountLast;
+            synchronized (mutex) {
+                culledCountLast = RenderCulling.culledCountLast.get();
+                totalCountLast = RenderCulling.totalCountLast.get();
+            }
+            list.add(String.format("[BBOR] Rendering culling: %d / %d (%.1f%%)", culledCountLast, totalCountLast, (culledCountLast / (float) totalCountLast) * 100.0));
+        }
+        return list;
     }
 
     private static boolean cullFrustum(Box box) {
@@ -61,4 +85,8 @@ public class RenderCulling {
         return cullResult;
     }
 
+    public static void incrementCulling() {
+        totalCount.incrementAndGet();
+    }
+
 }
index ceeda1200de481a575b9e19ce920151d9d64065b..7a53b9c4a291eb7b034b66845506287a64a41d3c 100644 (file)
@@ -105,6 +105,8 @@ public class ConfigManager {
 
     public static Setting<HexColor> buttonOnOverlay;
 
+    public static Setting<Integer> fastRender;
+
     public static void loadConfig() {
         configDir = new File(".", "config");
         configDir.mkdirs();
@@ -117,6 +119,7 @@ public class ConfigManager {
         invertBoxColorPlayerInside = setup(config, "general", "invertBoxColorPlayerInside", false, "If set to true the color of any bounding box the player is inside will be inverted.");
         renderSphereAsDots = setup(config, "general", "renderSphereAsDots", false, "If set to true spheres will be rendered as dots.");
         buttonOnOverlay = setup(config, "general", "buttonEnabledOverlay", HexColor.from("#3000ff00"), "The color and alpha of the button overlay when a button is on.");
+        fastRender = setup(config, "general", "fastRender", 2, "Fast render settings. Higher value for faster rendering. ");
 
         drawBeacons = setup(config, "beacons", "drawBeacons", true, "If set to true beacon bounding boxes will be drawn.");
 
index 49e5e6828b228e00d9c2db2298113929bc1d851a..a4b135ae57c7473c086773234b65d5f57ac543a6 100644 (file)
@@ -53,7 +53,11 @@ public class SettingsScreen extends ListScreen {
                             }
                         },
                         width -> new BoolSettingButton(width, I18n.translate("bbor.options.outerBoxOnly"), ConfigManager.outerBoxesOnly),
-                        width -> new BoolSettingButton(width, I18n.translate("bbor.options.fill"), ConfigManager.fill))
+                        width -> new BoolSettingButton(width, I18n.translate("bbor.options.fill"), ConfigManager.fill),
+                        width -> new IntSettingSlider(width, 0, 2, "bbor.options.fastRender", ConfigManager.fastRender)
+                                .addDisplayValue(0, I18n.translate("bbor.options.fastRender.0"))
+                                .addDisplayValue(1, I18n.translate("bbor.options.fastRender.1"))
+                                .addDisplayValue(2, I18n.translate("bbor.options.fastRender.2")))
                 .section(I18n.translate("bbor.features.spawnChunks"),
                         width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.spawnChunks"), BoundingBoxType.WorldSpawn),
                         width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.lazyChunks"), BoundingBoxType.LazySpawnChunks),
index 8074e493a89043bd01823d5a9564cd28742292af..69724b682915e7904dd33264f301ba1ceb5b20c7 100644 (file)
@@ -35,7 +35,7 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
     }
 
     private void renderCuboid0(MatrixStack stack, OffsetBox nudge, Color color, boolean fillOnly, int fillAlpha, boolean mask) {
-        if (!RenderCulling.isVisibleCulling(nudge.toBox())) return;
+        if (ConfigManager.fastRender.get() >= 1 && !RenderCulling.isVisibleCulling(nudge.toBox())) return;
         if (ConfigManager.invertBoxColorPlayerInside.get() &&
                 playerInsideBoundingBox(nudge)) {
             color = new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue());
@@ -97,7 +97,7 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
 //        }
 
         if (cullIfEmpty && startPoint.equals(endPoint)) return;
-        if (!RenderCulling.isVisibleCulling(new OffsetBox(startPoint, endPoint).toBox())) return; // TODO better culling
+        if (ConfigManager.fastRender.get() >= 1 && !RenderCulling.isVisibleCulling(new OffsetBox(startPoint, endPoint).toBox())) return; // TODO better culling
 
         matrixStack.push();
 
@@ -129,7 +129,7 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
     }
 
     private void renderLineSphere(MatrixStack matrixStack, Point center, double radius, Color color) {
-        if (!RenderCulling.isVisibleCulling(new Box(new BlockPos(center.getX(), center.getY(), center.getZ())).expand(radius))) return;
+        if (ConfigManager.fastRender.get() >= 1 && !RenderCulling.isVisibleCulling(new Box(new BlockPos(center.getX(), center.getY(), center.getZ())).expand(radius))) return;
 
         double offset = ((radius - (int) radius) == 0) ? center.getY() - (int) center.getY() : 0;
         int dyStep = radius < 64 ? 1 : MathHelper.floor(radius / 32);
@@ -165,7 +165,7 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
     }
 
     private void renderDotSphere(MatrixStack matrixStack, Point center, double radius, Color color) {
-        if (!RenderCulling.isVisibleCulling(new Box(new BlockPos(center.getX(), center.getY(), center.getZ())).expand(radius))) return;
+        if (ConfigManager.fastRender.get() >= 1 && !RenderCulling.isVisibleCulling(new Box(new BlockPos(center.getX(), center.getY(), center.getZ())).expand(radius))) return;
         matrixStack.push();
 
         for (double phi = 0.0D; phi < TAU; phi += PHI_SEGMENT) {
index 9036fb29a68c0978b52bbb0e3fc31f91e79136da..4b86703f420eef6b6d0ca4819739d014ce5c2f5e 100644 (file)
@@ -1,6 +1,7 @@
 package com.irtimaled.bbor.common.models;
 
 import com.irtimaled.bbor.client.ClientRenderer;
+import com.irtimaled.bbor.client.RenderCulling;
 import com.irtimaled.bbor.client.renderers.AbstractRenderer;
 import com.irtimaled.bbor.common.BoundingBoxType;
 
@@ -35,6 +36,7 @@ public abstract class AbstractBoundingBox {
     }
 
     public boolean isVisibleCulling() {
+        RenderCulling.incrementCulling();
         return true;
     }
 }
index 1cfc458fdf7cdef540b9675d749d7aef74b99f61..7f2906c6559930d7aaba8ba261872ed6e014512f 100644 (file)
@@ -1,6 +1,5 @@
 package com.irtimaled.bbor.common.models;
 
-import com.irtimaled.bbor.client.RenderCulling;
 import com.irtimaled.bbor.client.renderers.AbstractRenderer;
 import com.irtimaled.bbor.client.renderers.CuboidRenderer;
 import com.irtimaled.bbor.common.BoundingBoxType;
@@ -82,8 +81,9 @@ public class BoundingBoxCuboid extends AbstractBoundingBox {
         return RENDERER;
     }
 
-    @Override
-    public boolean isVisibleCulling() {
-        return RenderCulling.isVisibleCulling(minCoords.getX(), minCoords.getY(), minCoords.getZ(), maxCoords.getX(), maxCoords.getY(), maxCoords.getZ());
-    }
+    // TODO
+//    @Override
+//    public boolean isVisibleCulling() {
+//        return RenderCulling.isVisibleCulling(minCoords.getX(), minCoords.getY(), minCoords.getZ(), maxCoords.getX() + 1, maxCoords.getY() + 1, maxCoords.getZ() + 1);
+//    }
 }
index e604e123855fd89263fe86a70f3138e0e8434b65..b1cb122846d3ae3e7efd2020c5511f81e6599232 100644 (file)
@@ -21,7 +21,7 @@ public class MixinDebugHud {
             return;
         }
 
-        cir.getReturnValue().add(RenderCulling.debugString());
+        cir.getReturnValue().addAll(RenderCulling.debugStrings());
         cir.getReturnValue().add(RenderBatch.debugString());
         cir.getReturnValue().add(String.format("[BBOR] Rendering took %.2fms", ClientRenderer.getLastDurationNanos() / 1_000_000.0));
     }
index 0adc75650906dc9c8b60328b8b912aa06e062a7d..9e77b17efc0c9db35b3dda223d370149956eb066 100644 (file)
@@ -30,7 +30,6 @@ public class MixinWorldRenderer {
     private void onRender(MatrixStack matrixStack, float partialTicks, long ignored_2, boolean ignored_3, Camera ignored_4, GameRenderer ignored_5, LightmapTextureManager ignored_6, Matrix4f ignored_7, CallbackInfo ci) {
         Preconditions.checkNotNull(this.client.player);
         RenderCulling.setFrustum(frustum);
-        RenderCulling.flushStats();
         Player.setPosition(partialTicks, this.client.player);
         ClientInterop.render(matrixStack, this.client.player);
     }
index 481c654f73b02701548288de8b11c3718f3c77ef..bdb540389e37f077b54b2060987a96e6a0c3cc3e 100644 (file)
@@ -7,7 +7,11 @@
   "bbor.options.active": "Active",
   "bbor.options.outerBoxOnly": "Outer Box Only",
   "bbor.options.fill": "Fill",
-  "bbor.options.lineWidthModifier": "Line Width Modifier",
+
+  "bbor.options.fastRender": "Fast Render: %s",
+  "bbor.options.fastRender.0": "Off",
+  "bbor.options.fastRender.1": "Medium",
+  "bbor.options.fastRender.2": "High",
 
   "bbor.options.maxY": "Max Y: %s",
   "bbor.options.maxY.activated": "Activated",