Skip to content

Commit

Permalink
redesigned config screen
Browse files Browse the repository at this point in the history
  • Loading branch information
RogoShum committed May 2, 2024
1 parent 91839f4 commit 3772a62
Show file tree
Hide file tree
Showing 26 changed files with 213 additions and 167 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/rogo/renderingculling/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
Expand All @@ -75,7 +75,7 @@ public static boolean getAsyncChunkRebuild() {
if(!shouldCullChunk())
return false;

if (CullingHandler.needPauseRebuild())
if (CullingStateManager.needPauseRebuild())
return false;

if(ModLoader.hasNvidium())
Expand All @@ -94,7 +94,7 @@ public static void setAsyncChunkRebuild(boolean value) {
if(ModLoader.hasNvidium())
return;

if (CullingHandler.needPauseRebuild())
if (CullingStateManager.needPauseRebuild())
return;

if(!ModLoader.hasSodium())
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
110 changes: 55 additions & 55 deletions src/main/java/rogo/renderingculling/api/CullingRenderEvent.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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(() -> {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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<Entity> 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<BlockEntity> 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();
Expand Down Expand Up @@ -637,8 +641,8 @@ public static void runOnDepthFrame(Consumer<DepthContext> 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()]);
});
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
8 changes: 7 additions & 1 deletion src/main/java/rogo/renderingculling/api/ModLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -159,4 +159,10 @@ public static AABB getObjectAABB(Object o) {

return null;
}

public static void pauseAsync() {
if (ModLoader.hasMod("embeddium")) {
fullChunkUpdateCooldown = 60;
}
}
}
15 changes: 10 additions & 5 deletions src/main/java/rogo/renderingculling/api/data/ChunkCullingMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,14 +16,19 @@ public ChunkCullingMap(int width, int height) {
super(width, height);
}

@Override
protected boolean shouldUpdate() {
return CullingStateManager.continueUpdateChunk();
}

@Override
int configDelayCount() {
return Config.getDepthUpdateDelay();
}

@Override
int bindFrameBufferId() {
return CullingHandler.CHUNK_CULLING_MAP_TARGET.frameBufferId;
return CullingStateManager.CHUNK_CULLING_MAP_TARGET.frameBufferId;
}

public void generateIndex(int renderDistance) {
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 3772a62

Please sign in to comment.