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;
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);
}
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);
}
}
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 {
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());
}
}
- 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) {
return cullResult;
}
+ public static void incrementCulling() {
+ totalCount.incrementAndGet();
+ }
+
}
public static Setting<HexColor> buttonOnOverlay;
+ public static Setting<Integer> fastRender;
+
public static void loadConfig() {
configDir = new File(".", "config");
configDir.mkdirs();
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.");
}
},
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),
}
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());
// }
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();
}
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);
}
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) {
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;
}
public boolean isVisibleCulling() {
+ RenderCulling.incrementCulling();
return true;
}
}
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;
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);
+// }
}
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));
}
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);
}
"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",