Fix up multiple errors and init issues everywhere
This commit is contained in:
@@ -29,6 +29,7 @@ import com.seibel.lod.core.logging.ConfigBasedSpamLogger;
|
||||
import com.seibel.lod.core.logging.SpamReducedLogger;
|
||||
import com.seibel.lod.core.objects.a7.DHLevel;
|
||||
import com.seibel.lod.core.objects.a7.DHWorld;
|
||||
import com.seibel.lod.core.objects.a7.Server;
|
||||
import com.seibel.lod.core.objects.math.Mat4f;
|
||||
import com.seibel.lod.core.render.GLProxy;
|
||||
import com.seibel.lod.core.render.RenderSystemTest;
|
||||
@@ -112,6 +113,16 @@ public class ClientApi
|
||||
prefix += ":\u00A7r ";
|
||||
if (MC != null) MC.sendChatMessage(prefix + str);
|
||||
}
|
||||
|
||||
public void clientServerConnected() {
|
||||
SharedApi.currentServer = new Server(false);
|
||||
SharedApi.currentWorld = new DHWorld();
|
||||
}
|
||||
public void clientServerDisconnected() {
|
||||
SharedApi.currentWorld.close();
|
||||
SharedApi.currentWorld = null;
|
||||
SharedApi.currentServer = null;
|
||||
}
|
||||
|
||||
public void clientChunkLoadEvent(IChunkWrapper chunk, IWorldWrapper world)
|
||||
{
|
||||
@@ -124,14 +135,13 @@ public class ClientApi
|
||||
|
||||
public void clientLevelUnloadEvent(IWorldWrapper world)
|
||||
{
|
||||
if (SharedApi.currentServer != null) return;
|
||||
if (SharedApi.currentWorld != null) {
|
||||
SharedApi.currentWorld.unloadLevel(world);
|
||||
}
|
||||
}
|
||||
public void clientLevelLoadEvent(IWorldWrapper world)
|
||||
{
|
||||
if (SharedApi.currentServer != null) return;
|
||||
//TODO: Maybe make DHLevel init no longer depend on needing player entity in single player
|
||||
if (SharedApi.currentWorld != null) {
|
||||
SharedApi.currentWorld.getOrLoadLevel(world);
|
||||
}
|
||||
@@ -257,12 +267,11 @@ public class ClientApi
|
||||
private void applyDeveloperConfigOverrides()
|
||||
{
|
||||
// remind the user that the config override is active
|
||||
if (!configOverrideReminderPrinted)
|
||||
if (!configOverrideReminderPrinted && MC.playerExists())
|
||||
{
|
||||
MC.sendChatMessage(ModInfo.READABLE_NAME + " experimental build " + ModInfo.VERSION);
|
||||
MC.sendChatMessage("You are running an unsupported version of the mod!");
|
||||
MC.sendChatMessage("Here be dragons!");
|
||||
|
||||
configOverrideReminderPrinted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,19 +67,22 @@ public class ServerApi
|
||||
|
||||
//TODO: rename to serverLoadEvent
|
||||
public void serverWorldLoadEvent() {
|
||||
Server server = new Server();
|
||||
SharedApi.currentServer = server;
|
||||
SharedApi.currentServer = new Server(!SharedApi.inDedicatedEnvironment);
|
||||
SharedApi.currentWorld = new DHWorld();
|
||||
//TODO: Setup the network handler
|
||||
}
|
||||
|
||||
//TODO: rename to serverUnloadEvent
|
||||
public void serverWorldUnloadEvent() {
|
||||
//TODO: Close the network handler
|
||||
SharedApi.currentWorld.close();
|
||||
SharedApi.currentWorld = null;
|
||||
SharedApi.currentServer = null;
|
||||
}
|
||||
|
||||
public void serverLevelLoadEvent(IWorldWrapper world) {
|
||||
//TODO: Maybe make DHLevel init no longer depend on needing player entity in single player
|
||||
if (SharedApi.currentServer.isSinglePlayer) return;
|
||||
SharedApi.currentWorld.getOrLoadLevel(world);
|
||||
}
|
||||
public void serverLevelUnloadEvent(IWorldWrapper world) {
|
||||
|
||||
@@ -14,7 +14,5 @@ public class SharedApi {
|
||||
public static Server currentServer;
|
||||
public static IMinecraftSharedWrapper MC;
|
||||
public static Logger LOGGER = DhLoggerBuilder.getLogger("DH Events");
|
||||
|
||||
public static boolean inDedicatedEnvironment;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.seibel.lod.core.objects.a7;
|
||||
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.objects.a7.io.DHFolderHandler;
|
||||
import com.seibel.lod.core.objects.a7.io.LevelToFileMatcher;
|
||||
import com.seibel.lod.core.util.DetailDistanceUtil;
|
||||
import com.seibel.lod.core.util.EventLoop;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
@@ -15,12 +17,13 @@ import java.util.Iterator;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public class DHWorld implements Closeable {
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger("DHWorld");
|
||||
|
||||
private final File saveDir;
|
||||
private final HashMap<IWorldWrapper, DHLevel> levels;
|
||||
private LevelToFileMatcher levelToFileMatcher = null;
|
||||
|
||||
public ExecutorService dhTickerThread = LodUtil.makeSingleThreadPool("DHTickerThread", 2);
|
||||
|
||||
public EventLoop eventLoop = new EventLoop(dhTickerThread, this::tick);
|
||||
|
||||
public DHWorld() {
|
||||
@@ -32,6 +35,7 @@ public class DHWorld implements Closeable {
|
||||
public DHLevel getOrLoadLevel(IWorldWrapper wrapper) {
|
||||
if (!levels.containsKey(wrapper)) {
|
||||
if (levelToFileMatcher == null || levelToFileMatcher.getTargetWorld() != wrapper) {
|
||||
LOGGER.info("Loading level for world " + wrapper.getDimensionType().getDimensionName());
|
||||
levelToFileMatcher = new LevelToFileMatcher(this, saveDir, wrapper);
|
||||
}
|
||||
DHLevel level = levelToFileMatcher.tryGetLevel();
|
||||
@@ -51,6 +55,7 @@ public class DHWorld implements Closeable {
|
||||
|
||||
public void unloadLevel(IWorldWrapper wrapper) {
|
||||
if (levels.containsKey(wrapper)) {
|
||||
LOGGER.info("Unloading level for world " + wrapper.getDimensionType().getDimensionName());
|
||||
levels.get(wrapper).close();
|
||||
levels.remove(wrapper);
|
||||
}
|
||||
@@ -84,6 +89,7 @@ public class DHWorld implements Closeable {
|
||||
public void close() {
|
||||
eventLoop.halt();
|
||||
for (DHLevel level : levels.values()) {
|
||||
LOGGER.info("Unloading level for world " + level.level.getDimensionType().getDimensionName());
|
||||
level.close();
|
||||
}
|
||||
levels.clear();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.seibel.lod.core.objects.a7;
|
||||
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.objects.a7.datatype.column.ColumnDatatype;
|
||||
import com.seibel.lod.core.objects.a7.datatype.full.FullDatatype;
|
||||
import com.seibel.lod.core.objects.a7.pos.DhBlockPos2D;
|
||||
@@ -9,6 +10,7 @@ import com.seibel.lod.core.objects.a7.render.RenderDataSourceLoader;
|
||||
import com.seibel.lod.core.util.DetailDistanceUtil;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.util.gridList.MovableGridRingList;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -41,7 +43,10 @@ public abstract class LodQuadTree {
|
||||
|
||||
static final ArrayList<RenderDataSourceLoader> layerLoaderConfig = new ArrayList<>();
|
||||
|
||||
static final Logger LOGGER = DhLoggerBuilder.getLogger("LodQuadTree");
|
||||
|
||||
public static void registerLayerLoader(RenderDataSourceLoader loader, byte sectionLevel) {
|
||||
LOGGER.info("Registering loader for section level " + sectionLevel + " for " + loader.getClass().getSimpleName());
|
||||
while (layerLoaderConfig.size() <= sectionLevel) {
|
||||
layerLoaderConfig.add(null);
|
||||
}
|
||||
@@ -51,7 +56,6 @@ public abstract class LodQuadTree {
|
||||
}
|
||||
|
||||
// static {
|
||||
// //TODO: Make this dynamic
|
||||
// Collections.addAll(layerLoaderConfig,
|
||||
// null,
|
||||
// null, //1
|
||||
@@ -106,9 +110,12 @@ public abstract class LodQuadTree {
|
||||
* @param initialPlayerZ player z coordinate
|
||||
*/
|
||||
public LodQuadTree(int viewDistance, int initialPlayerX, int initialPlayerZ) {
|
||||
ColumnDatatype.REGISTER(); //FIXME: This is a hack to make sure the datatype is registered
|
||||
|
||||
assertContainerTypeConfigCorrect();
|
||||
this.viewDistance = viewDistance;
|
||||
|
||||
//FIXME: Rework this mess of code!
|
||||
{ // Calculate the max section detail
|
||||
byte maxDetailLevel = getMaxDetailInRange(viewDistance * Math.sqrt(2));
|
||||
RenderDataSourceLoader finalEntry = null;
|
||||
@@ -122,9 +129,11 @@ public abstract class LodQuadTree {
|
||||
}
|
||||
if (finalEntry == null) throw new RuntimeException("No container type found!");
|
||||
if (topSectionLevel == layerLoaderConfig.size())
|
||||
topSectionLevel = (byte) (maxDetailLevel - finalEntry.detailOffset);
|
||||
topSectionLevel = (byte) (maxDetailLevel + finalEntry.detailOffset);
|
||||
numbersOfSectionLevels = (byte) (topSectionLevel + 1);
|
||||
startingSectionLevel = firstLevel;
|
||||
LOGGER.info("MaxLevel: " + maxDetailLevel + ", StartingLevel: " + startingSectionLevel + ", NumberOfLevels: " + numbersOfSectionLevels
|
||||
+ ", TopSectionLevel: " + topSectionLevel + ", FinalEntry: " + finalEntry);
|
||||
sectionDetailLayers = new SectionDetailLayer[numbersOfSectionLevels - startingSectionLevel];
|
||||
ringLists = new MovableGridRingList[numbersOfSectionLevels - startingSectionLevel];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
package com.seibel.lod.core.objects.a7;
|
||||
|
||||
public class Server {
|
||||
public final boolean isSinglePlayer;
|
||||
|
||||
public Server(boolean isSinglePlayer) {
|
||||
this.isSinglePlayer = isSinglePlayer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,9 +232,14 @@ public class ColumnDatatype implements RenderDataSource, IColumnDatatype {
|
||||
return (long) dataContainer.length * Long.BYTES;
|
||||
}
|
||||
|
||||
public static final ColumnRenderLoader COLUMN_LAYER_LOADER = new ColumnRenderLoader();
|
||||
static {
|
||||
public static ColumnRenderLoader COLUMN_LAYER_LOADER;
|
||||
|
||||
private static boolean hasRendered = false;
|
||||
public static void REGISTER() { //FIXME: THIS IS A MESS
|
||||
if (hasRendered) return;
|
||||
COLUMN_LAYER_LOADER = new ColumnRenderLoader();
|
||||
LodQuadTree.registerLayerLoader(COLUMN_LAYER_LOADER, (byte) 7); // 7 or above
|
||||
hasRendered = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -313,4 +318,6 @@ public class ColumnDatatype implements RenderDataSource, IColumnDatatype {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class LevelToFileMatcher {
|
||||
private void tick() {
|
||||
// prevent multiple threads running at the same time
|
||||
|
||||
if (CONFIG.client().multiplayer().getMultiDimensionRequiredSimilarity() == 0) {
|
||||
if (CONFIG.client().multiplayer().getMultiDimensionRequiredSimilarity() == 0 || MC.hasSinglePlayerServer()) {
|
||||
File saveDir = getLevelFolderWithoutSimilarityMatching();
|
||||
foundLevel = new DHLevel(dhWorld, saveDir, currentWorld);
|
||||
} else {
|
||||
|
||||
@@ -263,6 +263,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T> {
|
||||
}
|
||||
|
||||
// TODO: Use MutablePos2D in the future
|
||||
// Will pass in null entries
|
||||
public void forEachPos(BiConsumer<? super T, Pos2D> d) {
|
||||
moveLock.readLock().lock();
|
||||
try {
|
||||
@@ -280,6 +281,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T> {
|
||||
}
|
||||
|
||||
// TODO: Use MutablePos2D in the future
|
||||
// Will skip null entries
|
||||
public void forEachOrdered(Consumer<? super T> d) {
|
||||
if (ringIteratorList == null) buildRingIteratorList();
|
||||
moveLock.readLock().lock();
|
||||
@@ -287,7 +289,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T> {
|
||||
Pos2D min = pos.get();
|
||||
for (Pos2D offset : ringIteratorList) {
|
||||
T t = _getUnsafe(min.x + offset.x, min.y + offset.y);
|
||||
d.accept(t);
|
||||
if (t != null) d.accept(t);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -296,6 +298,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T> {
|
||||
}
|
||||
|
||||
// TODO: Use MutablePos2D in the future
|
||||
// Will pass in null entries
|
||||
public void forEachPosOrdered(BiConsumer<? super T, Pos2D> d) {
|
||||
if (ringIteratorList == null) buildRingIteratorList();
|
||||
moveLock.readLock().lock();
|
||||
|
||||
Reference in New Issue
Block a user