diff --git a/src/main/java/com/seibel/lod/core/api/ApiShared.java b/src/main/java/com/seibel/lod/core/api/ApiShared.java index 794698c58..dbaa288d7 100644 --- a/src/main/java/com/seibel/lod/core/api/ApiShared.java +++ b/src/main/java/com/seibel/lod/core/api/ApiShared.java @@ -19,10 +19,13 @@ package com.seibel.lod.core.api; +import com.seibel.lod.core.ModInfo; import com.seibel.lod.core.builders.bufferBuilding.LodBufferBuilderFactory; import com.seibel.lod.core.builders.lodBuilding.LodBuilder; import com.seibel.lod.core.enums.config.VerticalQuality; import com.seibel.lod.core.objects.lod.LodWorld; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * This stores objects and variables that @@ -34,6 +37,7 @@ import com.seibel.lod.core.objects.lod.LodWorld; public class ApiShared { public ApiShared INSTANCE = new ApiShared(); + public static final Logger LOGGER = LogManager.getLogger(ModInfo.NAME); public static final LodBufferBuilderFactory lodBufferBuilderFactory = new LodBufferBuilderFactory(); public static final LodWorld lodWorld = new LodWorld(); diff --git a/src/main/java/com/seibel/lod/core/api/ClientApi.java b/src/main/java/com/seibel/lod/core/api/ClientApi.java index dcaf6b89e..84d6bfdbf 100644 --- a/src/main/java/com/seibel/lod/core/api/ClientApi.java +++ b/src/main/java/com/seibel/lod/core/api/ClientApi.java @@ -63,7 +63,6 @@ public class ClientApi = Collections.synchronizedList(new LinkedList>()); public static final ClientApi INSTANCE = new ClientApi(); - public static final Logger LOGGER = LogManager.getLogger(ModInfo.NAME); public static LodRenderer renderer = new LodRenderer(ApiShared.lodBufferBuilderFactory); @@ -86,7 +85,7 @@ public class ClientApi if (!ENABLE_LAG_SPIKE_LOGGING) return; timer = System.nanoTime() - timer; if (timer > LAG_SPIKE_THRESOLD_NS) { - ClientApi.LOGGER.info("LagSpikeCatcher: "+source+" took "+Duration.ofNanos(timer)+"!"); + ApiShared.LOGGER.info("LagSpikeCatcher: "+source+" took "+Duration.ofNanos(timer)+"!"); } } } @@ -122,7 +121,7 @@ public class ClientApi public void clientChunkLoadEvent(IChunkWrapper chunk, IWorldWrapper world) { LagSpikeCatcher clientChunkLoad = new LagSpikeCatcher(); - //ClientApi.LOGGER.info("Lod Generating add: "+chunk.getLongChunkPos()); + //ApiShared.LOGGER.info("Lod Generating add: "+chunk.getLongChunkPos()); toBeLoaded.add(chunk.getLongChunkPos()); clientChunkLoad.end("clientChunkLoad"); } @@ -177,7 +176,7 @@ public class ClientApi LagSpikeCatcher updateToBeLoadedChunk = new LagSpikeCatcher(); for (long pos : toBeLoaded) { if (generating.size() >= 8) { - //ClientApi.LOGGER.info("Lod Generating Full! Remining: "+toBeLoaded.size()); + //ApiShared.LOGGER.info("Lod Generating Full! Remining: "+toBeLoaded.size()); break; } IChunkWrapper chunk = world.tryGetChunk(FACTORY.createChunkPos(pos)); @@ -188,10 +187,10 @@ public class ClientApi //if (!chunk.isLightCorrect()) continue; toBeLoaded.remove(pos); generating.add(pos); - //ClientApi.LOGGER.info("Lod Generation trying "+pos+". Remining: " +toBeLoaded.size()); + //ApiShared.LOGGER.info("Lod Generation trying "+pos+". Remining: " +toBeLoaded.size()); ApiShared.lodBuilder.generateLodNodeAsync(chunk, ApiShared.lodWorld, world.getDimensionType(), DistanceGenerationMode.FULL, true, true, () -> { - //ClientApi.LOGGER.info("Lod Generation for "+pos+" done. Remining: " +toBeLoaded.size()); + //ApiShared.LOGGER.info("Lod Generation for "+pos+" done. Remining: " +toBeLoaded.size()); generating.remove(pos); }, () -> { generating.remove(pos); @@ -234,7 +233,7 @@ public class ClientApi ClientApi.renderer.drawLODs(lodDim, mcModelViewMatrix, mcProjectionMatrix, partialTicks, MC.getProfiler()); } catch (RuntimeException e) { rendererDisabledBecauseOfExceptions = true; - ClientApi.LOGGER.error("Renderer thrown an uncaught exception: ",e); + ApiShared.LOGGER.error("Renderer thrown an uncaught exception: ",e); try { MC.sendChatMessage("\u00A74\u00A7l\u00A7uERROR: Distant Horizons" + " renderer has encountered an exception!"); @@ -256,7 +255,7 @@ public class ClientApi } catch (Exception e) { - ClientApi.LOGGER.error("client proxy uncaught exception: ", e); + ApiShared.LOGGER.error("client proxy uncaught exception: ", e); } } diff --git a/src/main/java/com/seibel/lod/core/api/EventApi.java b/src/main/java/com/seibel/lod/core/api/EventApi.java index 753f352ed..1ab6dafbd 100644 --- a/src/main/java/com/seibel/lod/core/api/EventApi.java +++ b/src/main/java/com/seibel/lod/core/api/EventApi.java @@ -116,7 +116,7 @@ public class EventApi { /** This is also called when a new dimension loads */ public void worldLoadEvent(IWorldWrapper world) { if (ENABLE_STACK_DUMP_LOGGING) - ClientApi.LOGGER.info( + ApiShared.LOGGER.info( "WorldLoadEvent called here for " + (world.getWorldType() == WorldType.ClientWorld ? "clientLevel" : "serverLevel"), new RuntimeException()); @@ -143,7 +143,7 @@ public class EventApi { /** This is also called when the user disconnects from a server+ */ public void worldUnloadEvent(IWorldWrapper world) { if (ENABLE_STACK_DUMP_LOGGING) - ClientApi.LOGGER.info( + ApiShared.LOGGER.info( "WorldUnloadEvent called here for " + (world.getWorldType() == WorldType.ClientWorld ? "clientLevel" : "serverLevel"), new RuntimeException()); diff --git a/src/main/java/com/seibel/lod/core/api/ModAccessorApi.java b/src/main/java/com/seibel/lod/core/api/ModAccessorApi.java index adc1ec942..38152dd19 100644 --- a/src/main/java/com/seibel/lod/core/api/ModAccessorApi.java +++ b/src/main/java/com/seibel/lod/core/api/ModAccessorApi.java @@ -39,7 +39,7 @@ public class ModAccessorApi { { throw new IllegalStateException("The singleton [" + interfaceClass.getSimpleName() + "] doesn't implement the interface [" + interfaceClass.getSimpleName() + "]."); } - ClientApi.LOGGER.info("DistantHorizon: Registored mod comatibility accessor for "+modAccessor.getModName()); + ApiShared.LOGGER.info("DistantHorizon: Registored mod comatibility accessor for "+modAccessor.getModName()); singletons.put(interfaceClass, modAccessor); } diff --git a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java index 8dd459aef..43bfc38c8 100644 --- a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java +++ b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java @@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.ReentrantLock; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.builders.lodBuilding.LodBuilder; import com.seibel.lod.core.enums.LodDirection; @@ -86,7 +87,7 @@ public class LodBufferBuilderFactory { return; timer = System.nanoTime() - timer; if (timer > LAG_SPIKE_THRESOLD_NS) { - ClientApi.LOGGER.info("LagSpikeCatcher: " + source + " took " + Duration.ofNanos(timer) + "!"); + ApiShared.LOGGER.info("LagSpikeCatcher: " + source + " took " + Duration.ofNanos(timer) + "!"); } } } @@ -304,7 +305,7 @@ public class LodBufferBuilderFactory { try { uploadBuffers(result.quadBuilder, result.regionPos); } catch (Exception e3) { - ClientApi.LOGGER.error("\"LodNodeBufferBuilder\" was unable to upload buffer: ", e3); + ApiShared.LOGGER.error("\"LodNodeBufferBuilder\" was unable to upload buffer: ", e3); } }, bufferUploadThread); futuresBuffer.add(future); @@ -322,7 +323,7 @@ public class LodBufferBuilderFactory { try { allFutures.get(60, TimeUnit.SECONDS); } catch (TimeoutException te) { - ClientApi.LOGGER.error("LodBufferBuilder timed out: ", te); + ApiShared.LOGGER.error("LodBufferBuilder timed out: ", te); bufferBuilderThreadFactory.dumpAllThreadStacks(); bufferUploadThreadFactory.dumpAllThreadStacks(); bufferBuilderThreads.shutdownNow(); @@ -336,7 +337,7 @@ public class LodBufferBuilderFactory { bufferUploadThread = Executors.newSingleThreadExecutor(bufferUploadThreadFactory); return; } catch (Exception e) { - ClientApi.LOGGER.error("LodBufferBuilder ran into trouble: ", e); + ApiShared.LOGGER.error("LodBufferBuilder ran into trouble: ", e); } long executeEnd = System.currentTimeMillis(); @@ -344,13 +345,13 @@ public class LodBufferBuilderFactory { long buildTime = endTime - startTime; long executeTime = executeEnd - executeStart; if (ENABLE_BUFFER_PERF_LOGGING) - ClientApi.LOGGER.info("Thread Build&Upload(" + nodeToRenderThreads.size() + "/" + ApiShared.LOGGER.info("Thread Build&Upload(" + nodeToRenderThreads.size() + "/" + (lodDim.getWidth() * lodDim.getWidth()) + (fullRegen ? "FULL" : "") + ") time: " + buildTime + " ms" + '\n' + "thread execute time: " + executeTime + " ms"); // mark that the buildable buffers as ready to swap switchVbos = true; } catch (Exception e) { - ClientApi.LOGGER.error("\"LodNodeBufferBuilder.generateLodBuffersAsync\" ran into trouble: ", e); + ApiShared.LOGGER.error("\"LodNodeBufferBuilder.generateLodBuffersAsync\" ran into trouble: ", e); } finally { // regardless of whether we were able to successfully create // the buffers, we are done generating. @@ -579,7 +580,7 @@ public class LodBufferBuilderFactory { private boolean swapBuffers() { bufferLock.lock(); if (ENABLE_BUFFER_SWAP_LOGGING) - ClientApi.LOGGER.debug("Lod Swap Buffers"); + ApiShared.LOGGER.debug("Lod Swap Buffers"); { boolean shouldRegenBuff = true; try { @@ -587,7 +588,7 @@ public class LodBufferBuilderFactory { drawableVbos = buildableVbos; buildableVbos = tmpVbo; - // ClientApi.LOGGER.info("Lod Swapped Buffers: "+drawableVbos.toDetailString()); + // ApiShared.LOGGER.info("Lod Swapped Buffers: "+drawableVbos.toDetailString()); // the vbos have been swapped switchVbos = false; @@ -599,7 +600,7 @@ public class LodBufferBuilderFactory { hideBackBuffer = false; } catch (Exception e) { // this shouldn't normally happen, but just in case it sill prevent deadlock - ClientApi.LOGGER.error("swapBuffers ran into trouble: " + e.getMessage(), e); + ApiShared.LOGGER.error("swapBuffers ran into trouble: " + e.getMessage(), e); } finally { bufferLock.unlock(); } diff --git a/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java b/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java index 427912f06..a9877f4fd 100644 --- a/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java +++ b/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java @@ -22,6 +22,7 @@ package com.seibel.lod.core.builders.lodBuilding; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.enums.LodDirection; import com.seibel.lod.core.enums.config.DistanceGenerationMode; @@ -179,7 +180,7 @@ public class LodBuilder int subZ = i%16; writeVerticalData(data, i*maxVerticalData, maxVerticalData, chunk, config, subX, subZ); //if (DataPointUtil.isVoid(data[i*maxVerticalData])) - // ClientApi.LOGGER.debug("Datapoint is Void: {}, {}", chunk.getMinX()+subX, chunk.getMinZ()+subZ); + // ApiShared.LOGGER.debug("Datapoint is Void: {}, {}", chunk.getMinX()+subX, chunk.getMinZ()+subZ); if (!DataPointUtil.doesItExist(data[i*maxVerticalData])) throw new RuntimeException("writeVerticalData result: Datapoint does not exist at "+ chunk.getMinX()+subX +", "+ chunk.getMinZ()+subZ); if (DataPointUtil.getGenerationMode(data[i*maxVerticalData]) != config.distanceGenerationMode.complexity) @@ -199,7 +200,7 @@ public class LodBuilder return writePartialLodNodeData(lodDim, region, chunk.getChunkPosX(), chunk.getChunkPosZ(), data, config, override); } } catch (RuntimeException e) { - ClientApi.LOGGER.error("LodBuilder encountered an error on building lod for chunk {}: {}", chunk ,e); + ApiShared.LOGGER.error("LodBuilder encountered an error on building lod for chunk {}: {}", chunk ,e); return false; } @@ -212,7 +213,7 @@ public class LodBuilder try { if (region.getMinDetailLevel()!= 0) { if (!LodUtil.checkRamUsage(0.05, 16)) { - ClientApi.LOGGER.debug("LodBuilder: Not enough RAM avalible for loading files to build lods! Returning..."); + ApiShared.LOGGER.debug("LodBuilder: Not enough RAM avalible for loading files to build lods! Returning..."); return false; } @@ -220,7 +221,7 @@ public class LodBuilder if (region!=newRegion) throw new RuntimeException(); } - //ClientApi.LOGGER.info("Generate chunk: {}, {} ({}, {}) at genMode {}", + //ApiShared.LOGGER.info("Generate chunk: {}, {} ({}, {}) at genMode {}", // chunk.getChunkPosX(), chunk.getChunkPosZ(), chunk.getMinX(), chunk.getMinZ(), config.distanceGenerationMode); region.addChunkOfData((byte)0, chunkX*16, chunkZ*16, 16, 16, data, data.length/16/16, override); region.regenerateLodFromArea((byte)0, chunkX*16, chunkZ*16, 16, 16); @@ -268,7 +269,7 @@ public class LodBuilder for (int i=0; i 32768) estimatedSampleNeeded = 32768; if (ENABLE_GENERATOR_STATS_LOGGING) - ClientApi.LOGGER.info("WorldGenerator: Increasing estimatedSampleNeeeded to " + estimatedSampleNeeded); + ApiShared.LOGGER.info("WorldGenerator: Increasing estimatedSampleNeeeded to " + estimatedSampleNeeded); } else if (toGenerate <= 0 && positionGoneThough * 1.5 < posToGenerate.getNumberOfPos()) { // We haven't gone though half of them and it's already enough. @@ -252,13 +253,13 @@ public class BatchGenerator { if (estimatedSampleNeeded < 4) estimatedSampleNeeded = 4; if (ENABLE_GENERATOR_STATS_LOGGING) - ClientApi.LOGGER.info("WorldGenerator: Decreasing estimatedSampleNeeeded to " + estimatedSampleNeeded); + ApiShared.LOGGER.info("WorldGenerator: Decreasing estimatedSampleNeeeded to " + estimatedSampleNeeded); } } public void stop(boolean blocking) { - ClientApi.LOGGER.info("1.18 Experimental Chunk Generator shutting down..."); + ApiShared.LOGGER.info("1.18 Experimental Chunk Generator shutting down..."); generationGroup.stop(blocking); } diff --git a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java index af0ec3190..c95ba396a 100644 --- a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java +++ b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java @@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.builders.lodBuilding.LodBuilder; import com.seibel.lod.core.enums.config.DistanceGenerationMode; @@ -312,7 +313,7 @@ public class LodWorldGenerator { } // catch (Exception e) // { - // ClientApi.LOGGER.error(LodWorldGenerator.class.getSimpleName() + ": ran into + // ApiShared.LOGGER.error(LodWorldGenerator.class.getSimpleName() + ": ran into // an error: " + e.getMessage()); // e.printStackTrace(); // } @@ -338,16 +339,16 @@ public class LodWorldGenerator { public void restartExecutorService() { if (genSubThreads != null && !genSubThreads.isShutdown()) { - ClientApi.LOGGER.info("Blocking until generator sub threads terminated!!"); + ApiShared.LOGGER.info("Blocking until generator sub threads terminated!!"); try { mainGenThread.shutdownNow(); genSubThreads.shutdownNow(); boolean worked = genSubThreads.awaitTermination(30, TimeUnit.SECONDS); if (!worked) - ClientApi.LOGGER.error( + ApiShared.LOGGER.error( "Generator sub threads timed out! May cause crash on game exit due to cleanup failure."); } catch (InterruptedException e) { - ClientApi.LOGGER.error( + ApiShared.LOGGER.error( "Generator sub threads shutdown is interrupted! May cause crash on game exit due to cleanup failure."); e.printStackTrace(); } finally { diff --git a/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java b/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java index d8c85a5c7..25d57dcd0 100644 --- a/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java +++ b/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java @@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; +import com.seibel.lod.core.api.ApiShared; import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; @@ -141,18 +142,18 @@ public class LodDimensionFileHandler subFile.getName().equals("BIOME_ONLY") || subFile.getName().equals("NONE")) { - ClientApi.LOGGER.info("Noticed old save structure files. Starting merge process..."); + ApiShared.LOGGER.info("Noticed old save structure files. Starting merge process..."); LodDimensionOldFileStructureHandler oldFileStructHandler = new LodDimensionOldFileStructureHandler(this); if (mergeOldFileLock.tryLock()) { // I got the lock to merge file. - ClientApi.LOGGER.info("Updating VerticalQuality LOW..."); + ApiShared.LOGGER.info("Updating VerticalQuality LOW..."); oldFileStructHandler.mergeOldFileStructureForVertQuality(VerticalQuality.LOW); - ClientApi.LOGGER.info("Updating VerticalQuality MEDIUM..."); + ApiShared.LOGGER.info("Updating VerticalQuality MEDIUM..."); oldFileStructHandler.mergeOldFileStructureForVertQuality(VerticalQuality.MEDIUM); - ClientApi.LOGGER.info("Updating VerticalQuality HIGH..."); + ApiShared.LOGGER.info("Updating VerticalQuality HIGH..."); oldFileStructHandler.mergeOldFileStructureForVertQuality(VerticalQuality.HIGH); - ClientApi.LOGGER.info("Update completed."); + ApiShared.LOGGER.info("Update completed."); } else { @@ -160,7 +161,7 @@ public class LodDimensionFileHandler mergeOldFileLock.lock(); mergeOldFileLock.unlock(); } - ClientApi.LOGGER.info("Merge process completed."); + ApiShared.LOGGER.info("Merge process completed."); return; } } @@ -229,7 +230,7 @@ public class LodDimensionFileHandler // close the reader and delete the file. inputStream.close(); file.delete(); - ClientApi.LOGGER.info("Outdated LOD region file for region: (" + regionX + "," + regionZ + ")" + ApiShared.LOGGER.info("Outdated LOD region file for region: (" + regionX + "," + regionZ + ")" + " version found: " + fileVersion + ", version requested: " + LOD_SAVE_FILE_VERSION + ". File has been deleted."); @@ -242,7 +243,7 @@ public class LodDimensionFileHandler // close the reader and ignore the file, we don't // want to accidentally delete anything the user may want. inputStream.close(); - ClientApi.LOGGER.info("Newer LOD region file for region: (" + regionX + "," + regionZ + ")" + ApiShared.LOGGER.info("Newer LOD region file for region: (" + regionX + "," + regionZ + ")" + " version found: " + fileVersion + ", version requested: " + LOD_SAVE_FILE_VERSION + " this region will not be written to in order to protect the newer file."); @@ -251,7 +252,7 @@ public class LodDimensionFileHandler } else if (fileVersion < LOD_SAVE_FILE_VERSION) { - ClientApi.LOGGER.debug("Old LOD region file for region: (" + regionX + "," + regionZ + ")" + ApiShared.LOGGER.debug("Old LOD region file for region: (" + regionX + "," + regionZ + ")" + " version found: " + fileVersion + ", version requested: " + LOD_SAVE_FILE_VERSION + ". File will be loaded and updated to new format in next save."); @@ -273,7 +274,7 @@ public class LodDimensionFileHandler } catch (IOException ioEx) { - ClientApi.LOGGER.error("LOD file read error. Unable to read xz compressed file [" + file + "] error [" + ioEx.getMessage() + "]: "); + ApiShared.LOGGER.error("LOD file read error. Unable to read xz compressed file [" + file + "] error [" + ioEx.getMessage() + "]: "); ioEx.printStackTrace(); region.addLevelContainer(new VerticalLevelContainer(tempDetailLevel)); } @@ -292,7 +293,7 @@ public class LodDimensionFileHandler DETAIL_FOLDER_NAME_PREFIX + dataContainer.detailLevel + File.separatorChar + FILE_NAME_PREFIX + "." + posX + "." + posZ + FILE_EXTENSION); if (file.exists()) { - ClientApi.LOGGER.warn("LOD file write warn. Unable to write [" + file + "] because the newer version file already exist! Skipping this position..."); + ApiShared.LOGGER.warn("LOD file write warn. Unable to write [" + file + "] because the newer version file already exist! Skipping this position..."); return; } if (!file.getParentFile().exists()) @@ -300,7 +301,7 @@ public class LodDimensionFileHandler try { file.createNewFile(); } catch (IOException e) { - ClientApi.LOGGER.error("LOD file write error. Unable to create parent directory for [" + file + "] error [" + e.getMessage() + "]: "); + ApiShared.LOGGER.error("LOD file write error. Unable to create parent directory for [" + file + "] error [" + e.getMessage() + "]: "); e.printStackTrace(); return; } @@ -317,7 +318,7 @@ public class LodDimensionFileHandler } catch (IOException e) { - ClientApi.LOGGER.error("LOD file write error. Unable to write to temp file [" + file + "] error [" + e.getMessage() + "]: "); + ApiShared.LOGGER.error("LOD file write error. Unable to write to temp file [" + file + "] error [" + e.getMessage() + "]: "); e.printStackTrace(); } } @@ -346,7 +347,7 @@ public class LodDimensionFileHandler if (r.isWriting.get() != 0) writingRegionCount++; LevelContainer[] container = r.debugGetDataContainers().clone(); if (container == null || container.length != LodUtil.DETAIL_OPTIONS) { - ClientApi.LOGGER.warn("DumpRamUsage encountered an invalid region!"); + ApiShared.LOGGER.warn("DumpRamUsage encountered an invalid region!"); continue; } for (int i = 0; i < LodUtil.DETAIL_OPTIONS; i++) { @@ -387,14 +388,14 @@ public class LodDimensionFileHandler } trySaveRegionsToBeSaved(); if (blockUntilFinished) { - if (ENABLE_SAVE_THREAD_LOGGING) ClientApi.LOGGER.info("Blocking until lod file save finishes!"); + if (ENABLE_SAVE_THREAD_LOGGING) ApiShared.LOGGER.info("Blocking until lod file save finishes!"); try { fileWritingThreadPool.shutdown(); boolean worked = fileWritingThreadPool.awaitTermination(30, TimeUnit.SECONDS); if (!worked) - ClientApi.LOGGER.error("File writing timed out! File data may not be saved correctly and may cause corruptions!!!"); + ApiShared.LOGGER.error("File writing timed out! File data may not be saved correctly and may cause corruptions!!!"); } catch (InterruptedException e) { - ClientApi.LOGGER.error("File writing wait is interrupted! File data may not be saved correctly and may cause corruptions!!!"); + ApiShared.LOGGER.error("File writing wait is interrupted! File data may not be saved correctly and may cause corruptions!!!"); e.printStackTrace(); } finally { fileWritingThreadPool = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName(), Thread.NORM_PRIORITY+1)); @@ -425,7 +426,7 @@ public class LodDimensionFileHandler if (!isStarted) throw new ConcurrentModificationException("WriterMain Triggered but the thead state is not started!?"); if (ENABLE_SAVE_THREAD_LOGGING) - ClientApi.LOGGER.info("Lod File Writer started. To-be-written-regions: "+regionToSave.size()); + ApiShared.LOGGER.info("Lod File Writer started. To-be-written-regions: "+regionToSave.size()); Instant start = Instant.now(); // Note: Since regionToSave is a ConcurrentHashMap, and the .values() return one that support concurrency, // this for loop should be safe and loop until all values are gone. @@ -439,12 +440,12 @@ public class LodDimensionFileHandler r.needSaving = false; Instant i = Instant.now(); if (ENABLE_SAVE_REGION_LOGGING) - ClientApi.LOGGER.info("Lod: Saving Region "+r.getRegionPos()); + ApiShared.LOGGER.info("Lod: Saving Region "+r.getRegionPos()); saveRegionToFile(r); Instant j = Instant.now(); Duration d = Duration.between(i, j); if (ENABLE_SAVE_REGION_LOGGING) - ClientApi.LOGGER.info("Lod: Region "+r.getRegionPos()+" save finish. Took "+d); + ApiShared.LOGGER.info("Lod: Region "+r.getRegionPos()+" save finish. Took "+d); } catch (Exception e) { @@ -456,7 +457,7 @@ public class LodDimensionFileHandler } Instant end = Instant.now(); if (ENABLE_SAVE_THREAD_LOGGING) - ClientApi.LOGGER.info("Lod File Writer completed. Took "+Duration.between(start, end)); + ApiShared.LOGGER.info("Lod File Writer completed. Took "+Duration.between(start, end)); // Use Memory order Release to release any memory changes on setting this boolean // (Corresponding call is the this::saveRegions(...)::...compareAndExchangeAcquire(false, true);) // isFileWritingThreadRunning.setRelease(false); @@ -479,7 +480,7 @@ public class LodDimensionFileHandler // Get the old file File oldFile = getRegionFile(region.regionPosX, region.regionPosZ, detailLevel, region.getVerticalQuality()); if (ENABLE_SAVE_REGION_LOGGING) - ClientApi.LOGGER.debug("saving region [" + region.regionPosX + ", " + region.regionPosZ + "] detail "+detailLevel+" to file."); + ApiShared.LOGGER.debug("saving region [" + region.regionPosX + ", " + region.regionPosZ + "] detail "+detailLevel+" to file."); boolean isFileFullyGened = false; // make sure the file and folder exists @@ -492,7 +493,7 @@ public class LodDimensionFileHandler try { oldFile.createNewFile(); } catch (IOException e) { - ClientApi.LOGGER.error("LOD file write error. Unable to create parent directory for [" + oldFile + "] error [" + e.getMessage() + "]: "); + ApiShared.LOGGER.error("LOD file write error. Unable to create parent directory for [" + oldFile + "] error [" + e.getMessage() + "]: "); e.printStackTrace(); continue; } @@ -514,7 +515,7 @@ public class LodDimensionFileHandler } catch (IOException e) { - ClientApi.LOGGER.warn("LOD file write warning. Unable to read existing file [" + oldFile + "] version. Treating it as latest version. [" + e.getMessage() + "]: "); + ApiShared.LOGGER.warn("LOD file write warning. Unable to read existing file [" + oldFile + "] version. Treating it as latest version. [" + e.getMessage() + "]: "); e.printStackTrace(); } @@ -548,7 +549,7 @@ public class LodDimensionFileHandler // existing file is complete while new one is only partially generate // this can happen is for some reason loading failed // this doesn't fix the bug, but at least protects old data - ClientApi.LOGGER.error("LOD file write error. Attempted to overwrite complete region with incomplete one [" + oldFile + "]"); + ApiShared.LOGGER.error("LOD file write error. Attempted to overwrite complete region with incomplete one [" + oldFile + "]"); try { tempFile.delete(); } catch (SecurityException e) { @@ -559,7 +560,7 @@ public class LodDimensionFileHandler } catch (IOException e) { - ClientApi.LOGGER.error("LOD file write error. Unable to write to temp file [" + tempFile + "] error [" + e.getMessage() + "]: "); + ApiShared.LOGGER.error("LOD file write error. Unable to write to temp file [" + tempFile + "] error [" + e.getMessage() + "]: "); e.printStackTrace(); continue; } @@ -568,7 +569,7 @@ public class LodDimensionFileHandler try { Files.move(tempFile.toPath(), oldFile.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { - ClientApi.LOGGER.error("LOD file write error. Unable to update file [" + oldFile + "] error [" + e.getMessage() + "]: "); + ApiShared.LOGGER.error("LOD file write error. Unable to update file [" + oldFile + "] error [" + e.getMessage() + "]: "); e.printStackTrace(); } } @@ -592,7 +593,7 @@ public class LodDimensionFileHandler try { return dimensionDataSaveFolder.getCanonicalPath() + File.separatorChar; } catch (IOException e) { - ClientApi.LOGGER.warn("Unable to get the base save file path. One possible cause is that" + ApiShared.LOGGER.warn("Unable to get the base save file path. One possible cause is that" + " the process failed to read the current path location due to security configs."); throw new RuntimeException("DistantHorizons Get Save File Path Failure"); } diff --git a/src/main/java/com/seibel/lod/core/handlers/LodDimensionOldFileStructureHandler.java b/src/main/java/com/seibel/lod/core/handlers/LodDimensionOldFileStructureHandler.java index b888e4402..4e284e289 100644 --- a/src/main/java/com/seibel/lod/core/handlers/LodDimensionOldFileStructureHandler.java +++ b/src/main/java/com/seibel/lod/core/handlers/LodDimensionOldFileStructureHandler.java @@ -12,6 +12,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.locks.ReentrantLock; +import com.seibel.lod.core.api.ApiShared; import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; import com.google.common.util.concurrent.ThreadFactoryBuilder; @@ -99,7 +100,7 @@ public class LodDimensionOldFileStructureHandler // the file we are reading is too old. // close the reader and delete the file. inputStream.close(); - ClientApi.LOGGER.info("Outdated LOD region file for region: (" + regionX + "," + regionZ + ")" + ApiShared.LOGGER.info("Outdated LOD region file for region: (" + regionX + "," + regionZ + ")" + " version found: " + fileVersion + ", version requested: " + LOD_SAVE_FILE_VERSION + ". this region file will not be read and merged into the new save structure."); @@ -111,7 +112,7 @@ public class LodDimensionOldFileStructureHandler // close the reader and ignore the file, we don't // want to accidentally delete anything the user may want. inputStream.close(); - ClientApi.LOGGER.info("Unexpected newer LOD region file for region: (" + regionX + "," + regionZ + ")" + ApiShared.LOGGER.info("Unexpected newer LOD region file for region: (" + regionX + "," + regionZ + ")" + " version found: " + fileVersion + ", version requested: " + LOD_SAVE_FILE_VERSION + " this region file will not be read and merged into the new save structure."); @@ -119,7 +120,7 @@ public class LodDimensionOldFileStructureHandler } else if (fileVersion < LOD_SAVE_FILE_VERSION) { - ClientApi.LOGGER.debug("Old LOD region file for region: (" + regionX + "," + regionZ + ")" + ApiShared.LOGGER.debug("Old LOD region file for region: (" + regionX + "," + regionZ + ")" + " version found: " + fileVersion + ", version requested: " + LOD_SAVE_FILE_VERSION + ". this region file be read, updated, and merged into the new save structure."); @@ -134,7 +135,7 @@ public class LodDimensionOldFileStructureHandler } catch (IOException ioEx) { - ClientApi.LOGGER.error("LOD file read error. Unable to read xz compressed file [" + file + "] error [" + ioEx.getMessage() + "]: "); + ApiShared.LOGGER.error("LOD file read error. Unable to read xz compressed file [" + file + "] error [" + ioEx.getMessage() + "]: "); ioEx.printStackTrace(); } } @@ -149,18 +150,18 @@ public class LodDimensionOldFileStructureHandler private void loadAndMergeAndSaveRegion(VerticalQuality verticalQuality, RegionPos regionPos) { - ClientApi.LOGGER.info("Merging region "+regionPos+" at "+verticalQuality+"..."); + ApiShared.LOGGER.info("Merging region "+regionPos+" at "+verticalQuality+"..."); TempLodRegion region = new TempLodRegion(verticalQuality, regionPos); - ClientApi.LOGGER.info("Reading data..."); + ApiShared.LOGGER.info("Reading data..."); loadGenModeToRegion(region, OldDistanceGenerationMode.FULL); loadGenModeToRegion(region, OldDistanceGenerationMode.FEATURES); loadGenModeToRegion(region, OldDistanceGenerationMode.SURFACE); loadGenModeToRegion(region, OldDistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT); loadGenModeToRegion(region, OldDistanceGenerationMode.BIOME_ONLY); loadGenModeToRegion(region, OldDistanceGenerationMode.NONE); - ClientApi.LOGGER.info("Writing data..."); + ApiShared.LOGGER.info("Writing data..."); saveRegion(region); - ClientApi.LOGGER.info("region "+regionPos+" at "+verticalQuality+" merged"); + ApiShared.LOGGER.info("region "+regionPos+" at "+verticalQuality+" merged"); } @@ -245,7 +246,7 @@ public class LodDimensionOldFileStructureHandler try { return dimensionDataSaveFolder.getCanonicalPath() + File.separatorChar; } catch (IOException e) { - ClientApi.LOGGER.warn("Unable to get the base save file path. One possible cause is that" + ApiShared.LOGGER.warn("Unable to get the base save file path. One possible cause is that" + " the process failed to read the current path location due to security configs."); throw new RuntimeException("DistantHorizons Get Save File Path Failure"); } diff --git a/src/main/java/com/seibel/lod/core/objects/PosToRenderContainer.java b/src/main/java/com/seibel/lod/core/objects/PosToRenderContainer.java index 5a42e7212..10b7c30ee 100644 --- a/src/main/java/com/seibel/lod/core/objects/PosToRenderContainer.java +++ b/src/main/java/com/seibel/lod/core/objects/PosToRenderContainer.java @@ -21,6 +21,7 @@ package com.seibel.lod.core.objects; import java.util.Arrays; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.util.LevelPosUtil; import com.seibel.lod.core.util.LodUtil; @@ -60,7 +61,7 @@ public class PosToRenderContainer { // This is might be due to dimensions having a different width // when first loading in - ClientApi.LOGGER.error("Unable to addPosToRender. numberOfPosToRender [" + numberOfPosToRender + "] detailLevel [" + detailLevel + "] Pos [" + posX + "," + posZ + "]"); + ApiShared.LOGGER.error("Unable to addPosToRender. numberOfPosToRender [" + numberOfPosToRender + "] detailLevel [" + detailLevel + "] Pos [" + posX + "," + posZ + "]"); numberOfPosToRender++; // incrementing so we can see how many pos over the limit we would go return; } diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java b/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java index 5f655c680..9a0035ccb 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java @@ -26,6 +26,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.enums.config.DistanceGenerationMode; import com.seibel.lod.core.enums.config.DropoffQuality; @@ -179,11 +180,11 @@ public class LodDimension */ public synchronized void move(RegionPos regionOffset) { - ClientApi.LOGGER.info("LodDim MOVE. Offset: "+regionOffset); + ApiShared.LOGGER.info("LodDim MOVE. Offset: "+regionOffset); saveDirtyRegionsToFile(false); //async add dirty regions to be saved. Pos p = regions.getCenter(); regions.move(p.x+regionOffset.x, p.y+regionOffset.z); - ClientApi.LOGGER.info("LodDim MOVE complete. Offset: "+regionOffset); + ApiShared.LOGGER.info("LodDim MOVE complete. Offset: "+regionOffset); } @@ -285,7 +286,7 @@ public class LodDimension // don't run the tree cutter multiple times // for the same location Runnable thread = () -> { - //ClientApi.LOGGER.info("LodDim cut Region: " + playerPosX + "," + playerPosZ); + //ApiShared.LOGGER.info("LodDim cut Region: " + playerPosX + "," + playerPosZ); totalDirtiedRegions = 0; Pos minPos = regions.getMinInRange(); // go over every region in the dimension @@ -311,7 +312,7 @@ public class LodDimension }); if (totalDirtiedRegions > 8) this.saveDirtyRegionsToFile(false); dirtiedRegionsRoughCount = totalDirtiedRegions; - //ClientApi.LOGGER.info("LodDim cut Region complete: " + playerPosX + "," + playerPosZ); + //ApiShared.LOGGER.info("LodDim cut Region complete: " + playerPosX + "," + playerPosZ); isCutting = false; // See if we need to save and flush some data out. @@ -327,7 +328,7 @@ public class LodDimension // If we have less than 20% or 128MB ram left. Don't expend. if (expandOrLoadPaused) { if (LodUtil.checkRamUsage(0.2, 128)) { - ClientApi.LOGGER.info("Enough ram for expandOrLoadThread. Restarting..."); + ApiShared.LOGGER.info("Enough ram for expandOrLoadThread. Restarting..."); expandOrLoadPaused = false; } } @@ -342,13 +343,13 @@ public class LodDimension // don't run the expander multiple times // for the same location Runnable thread = () -> { - //ClientApi.LOGGER.info("LodDim expend Region: " + playerPosX + "," + playerPosZ); + //ApiShared.LOGGER.info("LodDim expend Region: " + playerPosX + "," + playerPosZ); Pos minPos = regions.getMinInRange(); iterateWithSpiral((int x, int z) -> { if (!expandOrLoadPaused && !LodUtil.checkRamUsage(0.02, 64)) { Runtime.getRuntime().gc(); if (!LodUtil.checkRamUsage(0.2, 128)) { - ClientApi.LOGGER.warn("Not enough ram for expandOrLoadThread. Pausing until Ram is freed..."); + ApiShared.LOGGER.warn("Not enough ram for expandOrLoadThread. Pausing until Ram is freed..."); // We have less than 10% or 64MB ram left. Don't expend. expandOrLoadPaused = true; saveDirtyRegionsToFile(false); @@ -379,7 +380,7 @@ public class LodDimension double deltaRPosZ = debugRPosZ - playerPosZ; double debugDistance = Math.sqrt(deltaRPosX*deltaRPosX + deltaRPosZ*deltaRPosZ); if (minDistance > debugDistance || maxDistance < debugDistance || minDistance > maxDistance) { - ClientApi.LOGGER.error("MinDistance/MaxDistance is WRONG!!! minDist: [{}], maxDist: [{}], centerDist: [{}]\n" + ApiShared.LOGGER.error("MinDistance/MaxDistance is WRONG!!! minDist: [{}], maxDist: [{}], centerDist: [{}]\n" + "At center block pos: {} {}, region pos: {}", minDistance, maxDistance, debugDistance, debugRPosX, debugRPosZ, regionPos); return; @@ -414,7 +415,7 @@ public class LodDimension regenDimensionBuffers = true; } }); - //ClientApi.LOGGER.info("LodDim expend Region complete: " + playerPosX + "," + playerPosZ); + //ApiShared.LOGGER.info("LodDim expend Region complete: " + playerPosX + "," + playerPosZ); isExpanding = false; }; @@ -738,7 +739,7 @@ public class LodDimension if (r.isWriting.get() != 0) writingRegionCount++; LevelContainer[] container = r.debugGetDataContainers().clone(); if (container == null || container.length != LodUtil.DETAIL_OPTIONS) { - ClientApi.LOGGER.warn("DumpRamUsage encountered an invalid region!"); + ApiShared.LOGGER.warn("DumpRamUsage encountered an invalid region!"); continue; } for (int i = 0; i < LodUtil.DETAIL_OPTIONS; i++) { @@ -775,9 +776,9 @@ public class LodDimension try { boolean worked = cutAndExpandThread.awaitTermination(5, TimeUnit.SECONDS); if (!worked) - ClientApi.LOGGER.error("Cut And Expend threads timed out! May cause crash on game exit due to cleanup failure."); + ApiShared.LOGGER.error("Cut And Expend threads timed out! May cause crash on game exit due to cleanup failure."); } catch (InterruptedException e) { - ClientApi.LOGGER.error("Cut And Expend threads shutdown is interrupted! May cause crash on game exit due to cleanup failure: ", e); + ApiShared.LOGGER.error("Cut And Expend threads shutdown is interrupted! May cause crash on game exit due to cleanup failure: ", e); } } diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java b/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java index c7a866896..2009db599 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java @@ -160,13 +160,13 @@ public class LodRegion { throw new RuntimeException("Provided data's verticalSize is different from current storage's verticalSize!"); boolean updated = this.dataContainer[detailLevel].addChunkOfData(data, posX, posZ, widthX, widthZ, override); - //ClientApi.LOGGER.info("addChunkOfData(region:{}, level:{}, x:{}, z:{}, wx:{}, wz:{}, override:{}, updated:{})", + //ApiShared.LOGGER.info("addChunkOfData(region:{}, level:{}, x:{}, z:{}, wx:{}, wz:{}, override:{}, updated:{})", // getRegionPos(), detailLevel, posX, posZ, widthX, widthZ, override, updated); if (updated) { needRegenBuffer = 2; needSaving = true; } else { - /*ClientApi.LOGGER.info("addChunkOfData nothing changed. Datapoint: {}\n Upper Datapoint: {}", + /*ApiShared.LOGGER.info("addChunkOfData nothing changed. Datapoint: {}\n Upper Datapoint: {}", DataPointUtil.toString(this.dataContainer[detailLevel].getSingleData(posX, posZ)), DataPointUtil.toString(this.dataContainer[9].getSingleData(0, 0)) );*/ @@ -445,7 +445,7 @@ public class LodRegion { if (detailLevel >= LodUtil.REGION_DETAIL_LEVEL) return false; int modPosX = LevelPosUtil.getRegionModule(detailLevel, posX); int modPosZ = LevelPosUtil.getRegionModule(detailLevel, posZ); - //ClientApi.LOGGER.info("RegenerateLodFromArea(region:{} level:{}, x:{}, z:{}, wx:{}, wz:{})", + //ApiShared.LOGGER.info("RegenerateLodFromArea(region:{} level:{}, x:{}, z:{}, wx:{}, wz:{})", // getRegionPos(), detailLevel, modPosX, modPosZ, widthX, widthZ); if (detailLevel < minDetailLevel) { byte startLevel = minDetailLevel; @@ -465,7 +465,7 @@ public class LodRegion { widthX = maxPosX-modPosX; widthZ = maxPosZ-modPosZ; detailLevel++; - // ClientApi.LOGGER.info(" - Shink: (level:{}, x:{}, z:{}, wx:{}, wz:{})", detailLevel, modPosX, modPosZ, widthX, widthZ); + // ApiShared.LOGGER.info(" - Shink: (level:{}, x:{}, z:{}, wx:{}, wz:{})", detailLevel, modPosX, modPosZ, widthX, widthZ); chunkUpdate(detailLevel, modPosX, modPosZ, widthX, widthZ); } while (detailLevel < LodUtil.REGION_DETAIL_LEVEL); @@ -480,7 +480,7 @@ public class LodRegion { * TODO make this return whether any value has changed */ private void update(byte detailLevel, int modPosX, int modPosZ) { - //ClientApi.LOGGER.info(" - Update: (level:{}, subLevel:{}, mx:{}, mz:{})", detailLevel, detailLevel-1, modPosX, modPosZ); + //ApiShared.LOGGER.info(" - Update: (level:{}, subLevel:{}, mx:{}, mz:{})", detailLevel, detailLevel-1, modPosX, modPosZ); dataContainer[detailLevel].updateData(dataContainer[detailLevel - 1], modPosX, modPosZ); } private void chunkUpdate(byte detailLevel, int modPosX, int modPosZ, int widthX,int widthZ) { diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LodWorld.java b/src/main/java/com/seibel/lod/core/objects/lod/LodWorld.java index 00dc4e00d..d182473d8 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LodWorld.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LodWorld.java @@ -22,6 +22,7 @@ package com.seibel.lod.core.objects.lod; import java.util.Hashtable; import java.util.Map; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper; @@ -142,7 +143,7 @@ public class LodWorld // TODO we should only print this if lods were actually saved to file // but that requires a LodDimension.hasDirtyRegions() method or something similar - ClientApi.LOGGER.info("Saving LODs"); + ApiShared.LOGGER.info("Saving LODs"); for (IDimensionTypeWrapper key : lodDimensions.keySet()) { lodDimensions.get(key).saveDirtyRegionsToFile(isBlocking); diff --git a/src/main/java/com/seibel/lod/core/objects/opengl/LodQuadBuilder.java b/src/main/java/com/seibel/lod/core/objects/opengl/LodQuadBuilder.java index 3ed74bbf9..a0f44edac 100644 --- a/src/main/java/com/seibel/lod/core/objects/opengl/LodQuadBuilder.java +++ b/src/main/java/com/seibel/lod/core/objects/opengl/LodQuadBuilder.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.enums.LodDirection; import com.seibel.lod.core.enums.LodDirection.Axis; @@ -97,7 +98,7 @@ public class LodQuadBuilder { return false; if (z + w0 > o.z) { - ClientApi.LOGGER.warn("Overlapping quads detected!"); + ApiShared.LOGGER.warn("Overlapping quads detected!"); o.color = ColorUtil.rgbToInt(255, 0, 0); return false; } @@ -116,7 +117,7 @@ public class LodQuadBuilder { return false; if (x + w0 > o.x) { - ClientApi.LOGGER.warn("Overlapping quads detected!"); + ApiShared.LOGGER.warn("Overlapping quads detected!"); o.color = ColorUtil.rgbToInt(255, 0, 0); return false; } @@ -135,7 +136,7 @@ public class LodQuadBuilder { return false; if (x + w0 > o.x) { - ClientApi.LOGGER.warn("Overlapping quads detected!"); + ApiShared.LOGGER.warn("Overlapping quads detected!"); o.color = ColorUtil.rgbToInt(255, 0, 0); return false; } @@ -166,7 +167,7 @@ public class LodQuadBuilder { return false; if (y + w1 > o.y) { - ClientApi.LOGGER.warn("Overlapping quads detected!"); + ApiShared.LOGGER.warn("Overlapping quads detected!"); o.color = ColorUtil.rgbToInt(255, 0, 0); return false; } @@ -184,7 +185,7 @@ public class LodQuadBuilder { return false; if (z + w1 > o.z) { - ClientApi.LOGGER.warn("Overlapping quads detected!"); + ApiShared.LOGGER.warn("Overlapping quads detected!"); o.color = ColorUtil.rgbToInt(255, 0, 0); return false; } @@ -202,7 +203,7 @@ public class LodQuadBuilder { return false; if (y + w1 > o.y) { - ClientApi.LOGGER.warn("Overlapping quads detected!"); + ApiShared.LOGGER.warn("Overlapping quads detected!"); o.color = ColorUtil.rgbToInt(255, 0, 0); return false; } @@ -375,7 +376,7 @@ public class LodQuadBuilder { mergeCount += merggeQuadsPass2(); long postQuadsCount = quads.size(); //if (mergeCount != 0) - //ClientApi.LOGGER.info("Merged {} out of {} quads, to now {} quads.", mergeCount, preQuadsCount, postQuadsCount); + //ApiShared.LOGGER.info("Merged {} out of {} quads, to now {} quads.", mergeCount, preQuadsCount, postQuadsCount); } public Iterator makeVertexBuffers() { diff --git a/src/main/java/com/seibel/lod/core/objects/opengl/LodVertexBuffer.java b/src/main/java/com/seibel/lod/core/objects/opengl/LodVertexBuffer.java index ccb354463..2c4226946 100644 --- a/src/main/java/com/seibel/lod/core/objects/opengl/LodVertexBuffer.java +++ b/src/main/java/com/seibel/lod/core/objects/opengl/LodVertexBuffer.java @@ -21,6 +21,7 @@ package com.seibel.lod.core.objects.opengl; import java.nio.ByteBuffer; +import com.seibel.lod.core.api.ApiShared; import org.lwjgl.opengl.GL32; import org.lwjgl.opengl.GL44; @@ -142,7 +143,7 @@ public class LodVertexBuffer implements AutoCloseable } catch (IllegalArgumentException e) { throw e; } catch (Exception e) { - ClientApi.LOGGER.error("vboUpload failed: ", e); + ApiShared.LOGGER.error("vboUpload failed: ", e); } } @@ -153,9 +154,9 @@ public class LodVertexBuffer implements AutoCloseable if (this.id >= 0) { _destroy(); - if (count==0) ClientApi.LOGGER.info("All LodVerrtexBuffer is freed."); + if (count==0) ApiShared.LOGGER.info("All LodVerrtexBuffer is freed."); } else { - ClientApi.LOGGER.error("LodVertexBuffer double close!"); + ApiShared.LOGGER.error("LodVertexBuffer double close!"); } } diff --git a/src/main/java/com/seibel/lod/core/render/GLProxy.java b/src/main/java/com/seibel/lod/core/render/GLProxy.java index 90f82f8b8..931ae821f 100644 --- a/src/main/java/com/seibel/lod/core/render/GLProxy.java +++ b/src/main/java/com/seibel/lod/core/render/GLProxy.java @@ -27,6 +27,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.seibel.lod.core.api.ApiShared; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL11; @@ -162,9 +163,9 @@ public class GLProxy boolean enableDebugLogging = true; // this must be created on minecraft's render context to work correctly - ClientApi.LOGGER.info("Creating " + GLProxy.class.getSimpleName() + "... If this is the last message you see in the log there must have been a OpenGL error."); + ApiShared.LOGGER.info("Creating " + GLProxy.class.getSimpleName() + "... If this is the last message you see in the log there must have been a OpenGL error."); - ClientApi.LOGGER.info("Lod Render OpenGL version [" + GL11.glGetString(GL11.GL_VERSION) + "]."); + ApiShared.LOGGER.info("Lod Render OpenGL version [" + GL11.glGetString(GL11.GL_VERSION) + "]."); // getting Minecraft's context has to be done on the render thread, // where the GL context is @@ -191,7 +192,7 @@ public class GLProxy "Additional info:\n"+supportedVersionInfo; MC.crashMinecraft(errorMessage, new UnsupportedOperationException("This GPU doesn't support OpenGL 3.2.")); } - ClientApi.LOGGER.info("minecraftGlCapabilities:\n"+getVersionInfo(minecraftGlCapabilities)); + ApiShared.LOGGER.info("minecraftGlCapabilities:\n"+getVersionInfo(minecraftGlCapabilities)); // context creation setup GLFW.glfwDefaultWindowHints(); @@ -206,13 +207,13 @@ public class GLProxy lodBuilderGlContext = GLFW.glfwCreateWindow(64, 48, "LOD Builder Window", 0L, minecraftGlContext); GLFW.glfwMakeContextCurrent(lodBuilderGlContext); lodBuilderGlCapabilities = GL.createCapabilities(); - ClientApi.LOGGER.info("lodBuilderGlCapabilities:\n"+getVersionInfo(lodBuilderGlCapabilities)); + ApiShared.LOGGER.info("lodBuilderGlCapabilities:\n"+getVersionInfo(lodBuilderGlCapabilities)); // create the proxyWorker's context proxyWorkerGlContext = GLFW.glfwCreateWindow(64, 48, "LOD proxy worker Window", 0L, minecraftGlContext); GLFW.glfwMakeContextCurrent(proxyWorkerGlContext); proxyWorkerGlCapabilities = GL.createCapabilities(); - ClientApi.LOGGER.info("proxyWorkerGlCapabilities:\n"+getVersionInfo(lodBuilderGlCapabilities)); + ApiShared.LOGGER.info("proxyWorkerGlCapabilities:\n"+getVersionInfo(lodBuilderGlCapabilities)); // Check if we can use the make-over version of Vertex Attribute, which is available in GL4.3 or after VertexAttributeBufferBindingSupported = minecraftGlCapabilities.glBindVertexBuffer != 0L; // Nullptr @@ -251,7 +252,7 @@ public class GLProxy // display the capabilities if (!bufferStorageSupported) { - ClientApi.LOGGER.warn("This GPU doesn't support Buffer Storage (OpenGL 4.4), falling back to using other methods."); + ApiShared.LOGGER.warn("This GPU doesn't support Buffer Storage (OpenGL 4.4), falling back to using other methods."); } String vendor = GL32.glGetString(GL32.GL_VENDOR).toUpperCase(); // example return: "NVIDIA CORPORATION" @@ -266,7 +267,7 @@ public class GLProxy preferredUploadMethod = GpuUploadMethod.BUFFER_MAPPING; } - ClientApi.LOGGER.info("GPU Vendor [" + vendor + "], Preferred upload method is [" + preferredUploadMethod + "]."); + ApiShared.LOGGER.info("GPU Vendor [" + vendor + "], Preferred upload method is [" + preferredUploadMethod + "]."); setGlContext(GLProxyContext.PROXY_WORKER); File workerLog = new File("OpenGL-Lod-WorkerContext.log"); @@ -292,7 +293,7 @@ public class GLProxy setGlContext(GLProxyContext.MINECRAFT); // GLProxy creation success - ClientApi.LOGGER.info(GLProxy.class.getSimpleName() + " creation successful. OpenGL smiles upon you this day."); + ApiShared.LOGGER.info(GLProxy.class.getSimpleName() + " creation successful. OpenGL smiles upon you this day."); } /** @@ -409,7 +410,7 @@ public class GLProxy } catch (Exception e) { - ClientApi.LOGGER.error(Thread.currentThread().getName() + " ran into a issue: " + e.getMessage()); + ApiShared.LOGGER.error(Thread.currentThread().getName() + " ran into a issue: " + e.getMessage()); e.printStackTrace(); } finally @@ -421,14 +422,14 @@ public class GLProxy public static void ensureAllGLJobCompleted() { if (!hasInstance()) return; - ClientApi.LOGGER.info("Blocking until GL jobs finished!"); + ApiShared.LOGGER.info("Blocking until GL jobs finished!"); try { instance.workerThread.shutdown(); boolean worked = instance.workerThread.awaitTermination(30, TimeUnit.SECONDS); if (!worked) - ClientApi.LOGGER.error("GLWorkerThread shutdown timed out! Game may crash on exit due to cleanup failure!"); + ApiShared.LOGGER.error("GLWorkerThread shutdown timed out! Game may crash on exit due to cleanup failure!"); } catch (InterruptedException e) { - ClientApi.LOGGER.error("GLWorkerThread shutdown is interrupted! Game may crash on exit due to cleanup failure!"); + ApiShared.LOGGER.error("GLWorkerThread shutdown is interrupted! Game may crash on exit due to cleanup failure!"); e.printStackTrace(); } finally { instance.workerThread = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat(GLProxy.class.getSimpleName() + "-Worker-Thread").build()); diff --git a/src/main/java/com/seibel/lod/core/render/LodRenderer.java b/src/main/java/com/seibel/lod/core/render/LodRenderer.java index 5de75f365..83c6ae6f3 100644 --- a/src/main/java/com/seibel/lod/core/render/LodRenderer.java +++ b/src/main/java/com/seibel/lod/core/render/LodRenderer.java @@ -72,7 +72,7 @@ public class LodRenderer if (!ENABLE_DRAW_LAG_SPIKE_LOGGING) return; timer = System.nanoTime() - timer; if (timer> DRAW_LAG_SPIKE_THRESOLD_NS) { //4 ms - ClientApi.LOGGER.info("NOTE: "+source+" took "+Duration.ofNanos(timer)+"!"); + ApiShared.LOGGER.info("NOTE: "+source+" took "+Duration.ofNanos(timer)+"!"); } } @@ -347,7 +347,7 @@ public class LodRenderer } } //if (drawCall==0) - // ClientApi.LOGGER.info("DrawCall Count: "+drawCall+"("+vCount0+")"); + // ApiShared.LOGGER.info("DrawCall Count: "+drawCall+"("+vCount0+")"); //================// // render cleanup // @@ -391,11 +391,11 @@ public class LodRenderer /** Setup all render objects - REQUIRES to be in render thread */ private void setup() { if (isSetupComplete) { - ClientApi.LOGGER.warn("Renderer setup called but it has already completed setup!"); + ApiShared.LOGGER.warn("Renderer setup called but it has already completed setup!"); return; } if (!GLProxy.hasInstance()) { - ClientApi.LOGGER.warn("Renderer setup called but GLProxy has not yet been setup!"); + ApiShared.LOGGER.warn("Renderer setup called but GLProxy has not yet been setup!"); return; } @@ -451,17 +451,17 @@ public class LodRenderer * (Many objects are Native, outside of JVM, and need manual cleanup) */ private void cleanup() { if (!isSetupComplete) { - ClientApi.LOGGER.warn("Renderer cleanup called but Renderer has not completed setup!"); + ApiShared.LOGGER.warn("Renderer cleanup called but Renderer has not completed setup!"); return; } if (!GLProxy.hasInstance()) { - ClientApi.LOGGER.warn("Renderer Cleanup called but the GLProxy has never been inited!"); + ApiShared.LOGGER.warn("Renderer Cleanup called but the GLProxy has never been inited!"); return; } isSetupComplete = false; - ClientApi.LOGGER.info("Renderer Cleanup Started"); + ApiShared.LOGGER.info("Renderer Cleanup Started"); shaderProgram.free(); - ClientApi.LOGGER.info("Renderer Cleanup Complete"); + ApiShared.LOGGER.info("Renderer Cleanup Complete"); } /** Calls the BufferBuilder's destroyBuffers method. */ diff --git a/src/main/java/com/seibel/lod/core/render/objects/Shader.java b/src/main/java/com/seibel/lod/core/render/objects/Shader.java index cf6c91729..f2fe0469e 100644 --- a/src/main/java/com/seibel/lod/core/render/objects/Shader.java +++ b/src/main/java/com/seibel/lod/core/render/objects/Shader.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import com.seibel.lod.core.api.ApiShared; import org.lwjgl.opengl.GL32; import com.seibel.lod.core.api.ClientApi; @@ -50,7 +51,7 @@ public class Shader */ public Shader(int type, String path, boolean absoluteFilePath) { - ClientApi.LOGGER.info("Loading shader at "+path); + ApiShared.LOGGER.info("Loading shader at "+path); // Create an empty shader object id = GL32.glCreateShader(type); StringBuilder source = loadFile(path, absoluteFilePath); @@ -64,7 +65,7 @@ public class Shader free(); // important! throw new RuntimeException(message); } - ClientApi.LOGGER.info("Shader at "+path+" loaded sucessfully."); + ApiShared.LOGGER.info("Shader at "+path+" loaded sucessfully."); } // REMEMBER to always free the resource! diff --git a/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePostGL43.java b/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePostGL43.java index 93cc94fe1..ccd9d033b 100644 --- a/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePostGL43.java +++ b/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePostGL43.java @@ -1,5 +1,6 @@ package com.seibel.lod.core.render.objects; +import com.seibel.lod.core.api.ApiShared; import org.lwjgl.opengl.GL43; import com.seibel.lod.core.api.ClientApi; @@ -63,11 +64,11 @@ public final class VertexAttributePostGL43 extends VertexAttribute { // Requires VertexAttribute binded public void completeAndCheck(int expectedStrideSize) { if (strideSize != expectedStrideSize) { - ClientApi.LOGGER.error("Vertex Attribute calculated stride size " + strideSize + + ApiShared.LOGGER.error("Vertex Attribute calculated stride size " + strideSize + " does not match the provided expected stride size " + expectedStrideSize + "!"); throw new IllegalArgumentException("Vertex Attribute Incorrect Format"); } - ClientApi.LOGGER.info("Vertex Attribute (GL43+) completed. It contains "+numberOfBindingPoints + ApiShared.LOGGER.info("Vertex Attribute (GL43+) completed. It contains "+numberOfBindingPoints +" binding points and a stride size of "+strideSize); } diff --git a/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePreGL43.java b/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePreGL43.java index 02246cb57..6e767a9aa 100644 --- a/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePreGL43.java +++ b/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePreGL43.java @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.TreeMap; import java.util.TreeSet; +import com.seibel.lod.core.api.ApiShared; import org.lwjgl.opengl.GL32; import com.seibel.lod.core.api.ClientApi; @@ -119,31 +120,31 @@ public final class VertexAttributePreGL43 extends VertexAttribute { for (int i = 0; i < pointers.length; i++) { VertexPointer pointer = pointers[i]; if (pointer == null) { - ClientApi.LOGGER.warn("Vertex Attribute index "+i+" is not set! No index should be skipped normally!"); + ApiShared.LOGGER.warn("Vertex Attribute index "+i+" is not set! No index should be skipped normally!"); continue; } pointersOffset[i] = currentOffset; currentOffset += pointer.byteSize; } if (currentOffset != expectedStrideSize) { - ClientApi.LOGGER.error("Vertex Attribute calculated stride size " + currentOffset + + ApiShared.LOGGER.error("Vertex Attribute calculated stride size " + currentOffset + " does not match the provided expected stride size " + expectedStrideSize + "!"); throw new IllegalArgumentException("Vertex Attribute Incorrect Format"); } strideSize = currentOffset; - ClientApi.LOGGER.info("Vertex Attribute (pre GL43) completed."); + ApiShared.LOGGER.info("Vertex Attribute (pre GL43) completed."); // Debug logging - ClientApi.LOGGER.info("Vertex Attribute Debug Data:"); - ClientApi.LOGGER.info("AttributeIndex: ElementCount, glType, normalized, strideSize, offset"); + ApiShared.LOGGER.info("Vertex Attribute Debug Data:"); + ApiShared.LOGGER.info("AttributeIndex: ElementCount, glType, normalized, strideSize, offset"); for (int i=0; i< pointers.length; i++) { VertexPointer pointer = pointers[i]; if (pointer==null) { - ClientApi.LOGGER.warn(i + ": Null!!!!"); + ApiShared.LOGGER.warn(i + ": Null!!!!"); continue; } - ClientApi.LOGGER.info(i + ": "+pointer.elementCount+", "+ + ApiShared.LOGGER.info(i + ": "+pointer.elementCount+", "+ pointer.glType+", "+pointer.normalized+", "+strideSize+", "+pointersOffset[i]); } diff --git a/src/main/java/com/seibel/lod/core/util/DetailDistanceUtil.java b/src/main/java/com/seibel/lod/core/util/DetailDistanceUtil.java index 1be99f937..4eb3d27f3 100644 --- a/src/main/java/com/seibel/lod/core/util/DetailDistanceUtil.java +++ b/src/main/java/com/seibel/lod/core/util/DetailDistanceUtil.java @@ -74,7 +74,7 @@ public class DetailDistanceUtil { double maxDetailDistance = getDrawDistanceFromDetail(maxDetail-1); if (distance > maxDetailDistance) { - //ClientApi.LOGGER.info("DEBUG: Scale as max: {}", distance); + //ApiShared.LOGGER.info("DEBUG: Scale as max: {}", distance); return maxDetail-1; } diff --git a/src/main/java/com/seibel/lod/core/util/LodThreadFactory.java b/src/main/java/com/seibel/lod/core/util/LodThreadFactory.java index 1585351f2..dfd45ffd7 100644 --- a/src/main/java/com/seibel/lod/core/util/LodThreadFactory.java +++ b/src/main/java/com/seibel/lod/core/util/LodThreadFactory.java @@ -23,6 +23,7 @@ import java.lang.ref.WeakReference; import java.util.LinkedList; import java.util.concurrent.ThreadFactory; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; /** @@ -73,7 +74,7 @@ public class LodThreadFactory implements ThreadFactory if (t != null) { StackTraceElement[] stacks = t.getStackTrace(); if (stacks.length != 0) { - ClientApi.LOGGER.info("===========================================\n" + ApiShared.LOGGER.info("===========================================\n" + "Thread: "+t.getName()+"\n"+StackTraceToString(stacks)); } } diff --git a/src/main/java/com/seibel/lod/core/util/SpamReducedLogger.java b/src/main/java/com/seibel/lod/core/util/SpamReducedLogger.java index 2d187ede8..ea6031dd7 100644 --- a/src/main/java/com/seibel/lod/core/util/SpamReducedLogger.java +++ b/src/main/java/com/seibel/lod/core/util/SpamReducedLogger.java @@ -3,6 +3,7 @@ package com.seibel.lod.core.util; import java.lang.ref.WeakReference; import java.util.concurrent.atomic.AtomicInteger; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.api.ClientApi; public class SpamReducedLogger { @@ -19,22 +20,22 @@ public class SpamReducedLogger { public void info(String str, Object... param) { if (sectionLogCount == -1) sectionLogCount = logTries.getAndIncrement(); if (sectionLogCount >= maxLogCount) return; - ClientApi.LOGGER.info(str, param); + ApiShared.LOGGER.info(str, param); } public void debug(String str, Object... param) { if (sectionLogCount == -1) sectionLogCount = logTries.getAndIncrement(); if (sectionLogCount >= maxLogCount) return; - ClientApi.LOGGER.debug(str, param); + ApiShared.LOGGER.debug(str, param); } public void warn(String str, Object... param) { if (sectionLogCount == -1) sectionLogCount = logTries.getAndIncrement(); if (sectionLogCount >= maxLogCount) return; - ClientApi.LOGGER.warn(str, param); + ApiShared.LOGGER.warn(str, param); } public void error(String str, Object... param) { if (sectionLogCount == -1) sectionLogCount = logTries.getAndIncrement(); if (sectionLogCount >= maxLogCount) return; - ClientApi.LOGGER.error(str, param); + ApiShared.LOGGER.error(str, param); } public void incLogTries() { sectionLogCount = -1; @@ -42,18 +43,18 @@ public class SpamReducedLogger { public void infoInc(String str, Object... param) { if (logTries.getAndIncrement() >= maxLogCount) return; - ClientApi.LOGGER.info(str, param); + ApiShared.LOGGER.info(str, param); } public void debugInc(String str, Object... param) { if (logTries.getAndIncrement() >= maxLogCount) return; - ClientApi.LOGGER.debug(str, param); + ApiShared.LOGGER.debug(str, param); } public void warnInc(String str, Object... param) { if (logTries.getAndIncrement() >= maxLogCount) return; - ClientApi.LOGGER.warn(str, param); + ApiShared.LOGGER.warn(str, param); } public void errorInc(String str, Object... param) { if (logTries.getAndIncrement() >= maxLogCount) return; - ClientApi.LOGGER.error(str, param); + ApiShared.LOGGER.error(str, param); } } \ No newline at end of file