Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public VoxyRenderSystem(WorldEngine world, ServiceManager sm) {
world.acquireRef();
Logger.info("Creating Voxy render system");

System.gc();

if (Minecraft.getInstance().options.renderDistance().get()<3) {
String msg = "Voxy: Having a vanilla render distance of 2 can cause rare culling near the edge of your screen issues, please use 3 or more";
Logger.warn(msg);
Expand All @@ -100,8 +98,7 @@ public VoxyRenderSystem(WorldEngine world, ServiceManager sm) {

try {
//wait for opengl to be finished, this should hopefully ensure all memory allocations are free
glFinish();
glFinish();
glFlush();

this.worldIn = world;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import me.cortex.voxy.common.world.WorldEngine;
import me.cortex.voxy.commonImpl.VoxyCommon;
import me.cortex.voxy.commonImpl.WorldIdentifier;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import org.jetbrains.annotations.Nullable;
Expand All @@ -24,13 +25,56 @@ public abstract class MixinLevelRenderer implements IGetVoxyRenderSystem {
@Shadow private @Nullable ClientLevel level;
@Unique private VoxyRenderSystem renderer;

@Unique
private static final long COOLDOWN_MS = 5000L;
@Unique
private volatile long voxy$lastRebuildTime;
@Unique
private volatile boolean voxy$pendingRebuild;

@Override
public VoxyRenderSystem getVoxyRenderSystem() {
return this.renderer;
}

@Inject(method = "allChanged()V", at = @At("RETURN"), order = 900)//We want to inject before sodium
private void reloadVoxyRenderer(CallbackInfo ci) {
long currentTime = System.currentTimeMillis();
long timeSinceLastRebuild = currentTime - this.voxy$lastRebuildTime;

if (timeSinceLastRebuild >= COOLDOWN_MS) {
// Enough time has passed, execute immediately
this.voxy$lastRebuildTime = currentTime;
this.voxy$pendingRebuild = false;
this.executeRebuild();
} else {
// Within cooldown, schedule deferred execution using a simple daemon thread
if (!this.voxy$pendingRebuild) {
this.voxy$pendingRebuild = true;
long delay = COOLDOWN_MS - timeSinceLastRebuild;
Thread delayThread = new Thread(() -> {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
return;
}
if (this.voxy$pendingRebuild) {
this.voxy$pendingRebuild = false;
Minecraft.getInstance().execute(() -> {
this.voxy$lastRebuildTime = System.currentTimeMillis();
this.executeRebuild();
});
}
});
delayThread.setDaemon(true);
delayThread.setName("Voxy-Debounce");
delayThread.start();
}
}
}

@Unique
private void executeRebuild() {
this.shutdownRenderer();
if (this.level != null) {
this.createRenderer();
Expand Down