Skip to content

Commit

Permalink
add async rebuild chunk feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RogoShum committed May 2, 2024
1 parent 3947e25 commit c1a8d60
Show file tree
Hide file tree
Showing 43 changed files with 776 additions and 533 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.15.9
fiber_version = 0.23.0-SNAPSHOT

# Mod Properties
mod_version=0.5.4
mod_version=0.5.8
maven_group=rogo.renderingculling
archives_base_name=BruteForceRenderingCulling-fabric-1.18.2

Expand Down
51 changes: 25 additions & 26 deletions src/main/java/rogo/renderingculling/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import io.github.fablabsmc.fablabs.api.fiber.v1.tree.ConfigBranch;
import io.github.fablabsmc.fablabs.api.fiber.v1.tree.ConfigTree;
import io.github.fablabsmc.fablabs.api.fiber.v1.tree.PropertyMirror;
import net.minecraft.network.chat.Component;

import java.io.*;
import java.nio.file.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -25,7 +27,7 @@ public class Config {
private static final PropertyMirror<List<String>> BLOCK_ENTITY_SKIP = PropertyMirror.create(ConfigTypes.makeList(ConfigTypes.STRING));

public static double getSampling() {
if(unload())
if (unload())
return 0.5;

return SAMPLING.getValue();
Expand All @@ -37,7 +39,7 @@ public static void setSampling(double value) {
}

public static boolean getCullEntity() {
if(unload() || !CullingHandler.gl33())
if (unload() || !CullingStateManager.gl33())
return false;
return CULL_ENTITY.getValue();
}
Expand All @@ -48,7 +50,7 @@ public static void setCullEntity(boolean value) {
}

public static boolean getCullChunk() {
if(unload())
if (unload())
return false;
return CULL_CHUNK.getValue();
}
Expand All @@ -57,7 +59,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 @@ -69,51 +71,47 @@ public static void setCullChunk(boolean value) {
}

public static boolean getAsyncChunkRebuild() {
if (true)
return false;
if (unload())
return false;

if(!shouldCullChunk())
if (!shouldCullChunk())
return false;

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

if(ModLoader.hasNvidium())
if (ModLoader.hasNvidium())
return false;

if(!ModLoader.hasSodium())
if (!ModLoader.hasSodium())
return false;

return ASYNC.getValue();
}

public static void setAsyncChunkRebuild(boolean value) {
if (true)
return;
if(!shouldCullChunk())
if (!shouldCullChunk())
return;

if(ModLoader.hasNvidium())
if (ModLoader.hasNvidium())
return;

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

if(!ModLoader.hasSodium())
if (!ModLoader.hasSodium())
return;

ASYNC.setValue(value);
save();
}

public static int getShaderDynamicDelay() {
return CullingHandler.enabledShader() ? 1 : 0;
return CullingStateManager.enabledShader() ? 1 : 0;
}

public static int getDepthUpdateDelay() {
if(unload())
if (unload())
return 1;
return UPDATE_DELAY.getValue() <= 9 ? UPDATE_DELAY.getValue() + getShaderDynamicDelay() : UPDATE_DELAY.getValue();
}
Expand All @@ -124,13 +122,13 @@ public static void setDepthUpdateDelay(int value) {
}

public static List<String> getEntitiesSkip() {
if(unload())
if (unload())
return ImmutableList.of();
return ENTITY_SKIP.getValue();
}

public static List<String> getBlockEntitiesSkip() {
if(unload())
if (unload())
return ImmutableList.of();
return BLOCK_ENTITY_SKIP.getValue();
}
Expand All @@ -148,7 +146,7 @@ private static String getTranslatedItem(String s) {
}

public static void save() {
if(CONTEXT != null) {
if (CONTEXT != null) {
try (OutputStream s = new BufferedOutputStream(Files.newOutputStream(CONTEXT.path, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING))) {
FiberSerialization.serialize(CONTEXT.config, s, CONTEXT.serializer);
} catch (IOException ignored) {
Expand Down Expand Up @@ -188,14 +186,14 @@ private static void init() {
}

public static void loadConfig() {
if(!configLoaded) {
if (!configLoaded) {
Config.init();
try {
Files.createDirectory(Paths.get("config"));
} 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 All @@ -217,5 +215,6 @@ private static void setupConfig(ConfigContext context) {
}
}

public record ConfigContext(ConfigTree config, Path path, JanksonValueSerializer serializer){}
public record ConfigContext(ConfigTree config, Path path, JanksonValueSerializer serializer) {
}
}
Loading

0 comments on commit c1a8d60

Please sign in to comment.