]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/client/RenderCulling.java
Add "Fast Render" option to configure culling behaviors
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / RenderCulling.java
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();
+    }
+
 }