Hooked up the stuff with buffer thingy
This commit is contained in:
@@ -2,17 +2,29 @@ package com.seibel.lod.core.objects.a7;
|
||||
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.objects.a7.data.DataHandler;
|
||||
import com.seibel.lod.core.objects.a7.pos.DhBlockPos2D;
|
||||
import com.seibel.lod.core.objects.a7.render.RenderBufferHandler;
|
||||
import com.seibel.lod.core.render.LodRenderProgram;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class DHLevel extends LodQuadTree {
|
||||
private static final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
|
||||
private static final IMinecraftClientWrapper MC = SingletonHandler.get(IMinecraftClientWrapper.class);
|
||||
public final File saveFolder; // Could be null, for no saving
|
||||
public final DataHandler dataHandler; // Could be null, for no saving
|
||||
public DHLevel(File saveFolder) {
|
||||
public final RenderBufferHandler renderBufferHandler;
|
||||
public final ExecutorService dhTickerThread = LodUtil.makeSingleThreadPool("DHLevelTickerThread", 2);
|
||||
private final AtomicBoolean isRunning = new AtomicBoolean(false);
|
||||
public final IWorldWrapper level;
|
||||
|
||||
public DHLevel(File saveFolder, IWorldWrapper level) {
|
||||
super(CONFIG.client().graphics().quality().getLodChunkRenderDistance()*16,
|
||||
MC.getPlayerBlockPos().x,
|
||||
MC.getPlayerBlockPos().z);
|
||||
@@ -22,10 +34,37 @@ public class DHLevel extends LodQuadTree {
|
||||
} else {
|
||||
dataHandler = null;
|
||||
}
|
||||
renderBufferHandler = new RenderBufferHandler(this);
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
// Should be called by server tick thread, or called by render thread but only 20 times per second, or less?
|
||||
public void update() {
|
||||
|
||||
if (!isRunning.getAndSet(true)) {
|
||||
dhTickerThread.submit(() -> {
|
||||
try {
|
||||
tick();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
isRunning.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
super.tick(new DhBlockPos2D(MC.getPlayerBlockPos()));
|
||||
renderBufferHandler.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderDataSource getRenderDataSource() {
|
||||
return dataHandler;
|
||||
}
|
||||
|
||||
public void render(LodRenderProgram renderContext) {
|
||||
renderBufferHandler.render(renderContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class LevelToFileMatcher {
|
||||
|
||||
if (CONFIG.client().multiplayer().getMultiDimensionRequiredSimilarity() == 0) {
|
||||
File saveDir = getLevelFolderWithoutSimilarityMatching();
|
||||
foundLevel = new DHLevel(saveDir);
|
||||
foundLevel = new DHLevel(saveDir, currentWorld);
|
||||
} else {
|
||||
if (determiningWorldFolder.getAndSet(true)) return;
|
||||
//FIXME: Use a thread pool
|
||||
@@ -82,7 +82,7 @@ public class LevelToFileMatcher {
|
||||
// attempt to get the file handler
|
||||
File saveDir = attemptToDetermineSubDimensionFolder();
|
||||
if (saveDir == null) return;
|
||||
foundLevel = new DHLevel(saveDir);
|
||||
foundLevel = new DHLevel(saveDir, currentWorld);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Unable to set the dimension file handler for level [" + currentWorld + "]. Error: ", e);
|
||||
} finally {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.seibel.lod.core.objects.a7.pos;
|
||||
|
||||
import com.seibel.lod.core.objects.DHBlockPos;
|
||||
import com.seibel.lod.core.objects.Pos2D;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
|
||||
@@ -11,6 +12,11 @@ public class DhBlockPos2D {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public DhBlockPos2D(DHBlockPos blockPos) {
|
||||
this.x = blockPos.x;
|
||||
this.z = blockPos.z;
|
||||
}
|
||||
|
||||
public DhBlockPos2D add(DhBlockPos2D other) {
|
||||
return new DhBlockPos2D(x + other.x, z + other.z);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ package com.seibel.lod.core.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.seibel.lod.core.enums.config.ServerFolderNameMode;
|
||||
import com.seibel.lod.core.enums.config.VanillaOverdraw;
|
||||
@@ -446,5 +448,16 @@ public class LodUtil
|
||||
public static void assertTrue(boolean condition) {
|
||||
if (!condition) throw new RuntimeException("Assertion failed");
|
||||
}
|
||||
|
||||
public static ExecutorService makeSingleThreadPool(String name, int relativePriority) {
|
||||
return Executors.newSingleThreadExecutor(new LodThreadFactory(name, Thread.NORM_PRIORITY+relativePriority));
|
||||
}
|
||||
public static ExecutorService makeSingleThreadPool(Class<?> clazz, int relativePriority) {
|
||||
return makeSingleThreadPool(clazz.getSimpleName(), relativePriority);
|
||||
}
|
||||
public static ExecutorService makeSingleThreadPool(String name) {
|
||||
return makeSingleThreadPool(name, 0);
|
||||
}
|
||||
public static ExecutorService makeSingleThreadPool(Class<?> clazz) {
|
||||
return makeSingleThreadPool(clazz.getSimpleName(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user