From 0194cffabaf995d0cb51e504cecb75ecef7d2345 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 2 Oct 2021 21:28:52 -0500 Subject: [PATCH] auto indent --- .../java/com/seibel/lod/util/LodUtil.java | 158 +++++++++--------- 1 file changed, 78 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/seibel/lod/util/LodUtil.java b/src/main/java/com/seibel/lod/util/LodUtil.java index 1faa87f61..705774da5 100644 --- a/src/main/java/com/seibel/lod/util/LodUtil.java +++ b/src/main/java/com/seibel/lod/util/LodUtil.java @@ -46,13 +46,13 @@ import net.minecraft.world.server.ServerWorld; * This class holds methods and constants that may be used in multiple places. * * @author James Seibel - * @version 9-7-2021 + * @version 10-2-2021 */ public class LodUtil { private static MinecraftWrapper mc = MinecraftWrapper.INSTANCE; - - + + /** * alpha used when drawing chunks in debug mode */ @@ -60,7 +60,7 @@ public class LodUtil public static final Color COLOR_DEBUG_BLACK = new Color(0, 0, 0, DEBUG_ALPHA); public static final Color COLOR_DEBUG_WHITE = new Color(255, 255, 255, DEBUG_ALPHA); public static final Color COLOR_INVISIBLE = new Color(0, 0, 0, 0); - + /** * a gray-purple color */ @@ -74,14 +74,14 @@ public class LodUtil public static final int NETHERRACK_COLOR_INT = LodUtil.colorToInt(new Color(95, 38, 38)); public static final int WARPED_NYLIUM_COLOR_INT = LodUtil.colorToInt(new Color(34, 94, 85)); public static final int CRIMSON_NYLIUM_COLOR_INT = LodUtil.colorToInt(new Color(126, 27, 27)); - + /** * In order of nearest to farthest:
* Red, Orange, Yellow, Green, Cyan, Blue, Magenta, white, gray, black */ public static final Color DEBUG_DETAIL_LEVEL_COLORS[] = new Color[]{Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.WHITE, Color.GRAY, Color.BLACK}; - - + + /** * 512 blocks wide */ @@ -94,12 +94,12 @@ public class LodUtil * 1 block wide */ public static final byte BLOCK_DETAIL_LEVEL = 0; - - + + public static final byte DETAIL_OPTIONS = 10; - + public static final short MAX_VERTICAL_DATA = 4; - + /** * measured in Blocks
* detail level 9 @@ -115,25 +115,25 @@ public class LodUtil * detail level 0 */ public static final short BLOCK_WIDTH = 1; - - + + /** * number of chunks wide */ public static final int REGION_WIDTH_IN_CHUNKS = 32; - - + + /** * If we ever need to use a heightmap for any reason, use this one. */ public static final Heightmap.Type DEFAULT_HEIGHTMAP = Heightmap.Type.WORLD_SURFACE_WG; - + /** * This regex finds any characters that are invalid for use in a windows * (and by extension mac and linux) file path */ public static final String INVALID_FILE_CHARACTERS_REGEX = "[\\\\\\/:*?\\\"<>|]"; - + /** * 64 MB by default is the maximum amount of memory that * can be directly allocated.

@@ -146,8 +146,8 @@ public class LodUtil * https://stackoverflow.com/questions/50499238/bytebuffer-allocatedirect-and-xmx */ public static final int MAX_ALOCATEABLE_DIRECT_MEMORY = 64 * 1024 * 1024; - - + + /** * Gets the first valid ServerWorld. * @@ -157,15 +157,15 @@ public class LodUtil { if (mc.hasSingleplayerServer()) return null; - + Iterable worlds = mc.getSingleplayerServer().getAllLevels(); - + for (ServerWorld world : worlds) return world; - + return null; } - + /** * Gets the ServerWorld for the relevant dimension. * @@ -176,10 +176,10 @@ public class LodUtil IntegratedServer server = mc.getSingleplayerServer(); if (server == null) return null; - + Iterable worlds = server.getAllLevels(); ServerWorld returnWorld = null; - + for (ServerWorld world : worlds) { if (world.dimensionType() == dimension) @@ -188,10 +188,10 @@ public class LodUtil break; } } - + return returnWorld; } - + /** * Convert a 2D absolute position into a quad tree relative position. */ @@ -199,20 +199,20 @@ public class LodUtil { int relativePosX = Math.floorDiv(x, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)); int relativePosZ = Math.floorDiv(z, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)); - + return new RegionPos(relativePosX, relativePosZ); } - + /** * Convert a 2D absolute position into a quad tree relative position. */ public static int convertLevelPos(int pos, int currectDetailLevel, int targetDetailLevel) { int newPos = Math.floorDiv(pos, (int) Math.pow(2, targetDetailLevel - currectDetailLevel)); - + return newPos; } - + /** * Return whether the given chunk * has any data in it. @@ -220,7 +220,7 @@ public class LodUtil public static boolean chunkHasBlockData(IChunk chunk) { ChunkSection[] blockStorage = chunk.getSections(); - + for (ChunkSection section : blockStorage) { if (section != null && !section.isEmpty()) @@ -228,11 +228,11 @@ public class LodUtil return true; } } - + return false; } - - + + /** * If on single player this will return the name of the user's * world, if in multiplayer it will return the server name, IP, @@ -244,7 +244,7 @@ public class LodUtil { // chop off the dimension ID as it is not needed/wanted String dimId = getDimensionIDFromWorld(world); - + // get the world name int saveIndex = dimId.indexOf("saves") + 1 + "saves".length(); int slashIndex = dimId.indexOf(File.separatorChar, saveIndex); @@ -255,8 +255,8 @@ public class LodUtil return getServerId(); } } - - + + /** * If on single player this will return the name of the user's * world and the dimensional save folder, if in multiplayer @@ -271,53 +271,53 @@ public class LodUtil { // this will return the world save location // and the dimension folder - + ServerWorld serverWorld = LodUtil.getServerWorldFromDimension(world.dimensionType()); if (serverWorld == null) throw new NullPointerException("getDimensionIDFromWorld wasn't able to get the ServerWorld for the dimension " + world.dimensionType().effectsLocation().getPath()); - + ServerChunkProvider provider = serverWorld.getChunkSource(); if (provider == null) throw new NullPointerException("getDimensionIDFromWorld wasn't able to get the ServerChunkProvider for the dimension " + world.dimensionType().effectsLocation().getPath()); - + return provider.dataStorage.dataFolder.toString(); } else { return getServerId() + File.separatorChar + "dim_" + world.dimensionType().effectsLocation().getPath() + File.separatorChar; } } - + /** * returns the server name, IP and game version. */ public static String getServerId() { ServerData server = mc.getCurrentServer(); - + String serverName = server.name.replaceAll(INVALID_FILE_CHARACTERS_REGEX, ""); String serverIp = server.ip.replaceAll(INVALID_FILE_CHARACTERS_REGEX, ""); String serverMcVersion = server.version.getString().replaceAll(INVALID_FILE_CHARACTERS_REGEX, ""); - + String serverId = serverName + ", IP " + serverIp + ", GameVersion " + serverMcVersion; - + return serverId; } - - + + /** * Convert a BlockColors int into a Color object. */ public static Color intToColor(int num) { int filter = 0b11111111; - + int red = (num >> 16) & filter; int green = (num >> 8) & filter; int blue = num & filter; - + return new Color(red, green, blue); } - + /** * Convert a Color into a BlockColors object. */ @@ -325,8 +325,8 @@ public class LodUtil { return color.getRGB(); } - - + + /** * Clamps the given value between the min and max values. * May behave strangely if min > max. @@ -335,7 +335,7 @@ public class LodUtil { return Math.min(max, Math.max(value, min)); } - + /** * Clamps the given value between the min and max values. * May behave strangely if min > max. @@ -344,7 +344,7 @@ public class LodUtil { return Math.min(max, Math.max(value, min)); } - + /** * Clamps the given value between the min and max values. * May behave strangely if min > max. @@ -353,7 +353,7 @@ public class LodUtil { return Math.min(max, Math.max(value, min)); } - + /** * This methods return the number of lods that are going to be rendered in a region in the worst case * @@ -365,7 +365,7 @@ public class LodUtil { int xRegionSign = (int) Math.signum(regionPosX); int zRegionSign = (int) Math.signum(regionPosZ); - + //we first find the center of the circle which is one of the following X position in the center region /* X - X - X @@ -376,8 +376,8 @@ public class LodUtil */ int circleCenterX = 256 + 256 * xRegionSign; int circleCenterZ = 256 + 256 * zRegionSign; - - + + int innerRadius; int outerRadius; int size; @@ -385,19 +385,18 @@ public class LodUtil int minDistance; int maxDistance; long memoryUse = 0; - int number = 0; for (byte detailLevel = BLOCK_DETAIL_LEVEL; detailLevel <= REGION_DETAIL_LEVEL; detailLevel++) { //We find now the inner and outer detail of this area innerRadius = DetailDistanceUtil.getDrawDistanceFromDetail(detailLevel); outerRadius = DetailDistanceUtil.getDrawDistanceFromDetail(detailLevel + 1); - + //we skip if the region does not intersect the two circles. minDistance = LevelPosUtil.minDistance(REGION_DETAIL_LEVEL, regionPosX, regionPosZ, circleCenterX, circleCenterZ); maxDistance = LevelPosUtil.maxDistance(REGION_DETAIL_LEVEL, regionPosX, regionPosZ, circleCenterX, circleCenterZ); if (innerRadius > maxDistance || minDistance > outerRadius) continue; - + //we proceed to count all the position in the region that fall between these two circle size = 1 << (REGION_DETAIL_LEVEL - detailLevel); count = 0; @@ -410,18 +409,17 @@ public class LodUtil count++; } } - + //we multiply the data with the max vertical data of this detail level int maxVerticalData = DetailDistanceUtil.getMaxVerticalData(detailLevel); - - number += count; + count *= maxVerticalData; memoryUse += template.getBufferMemoryForSingleLod(maxVerticalData) * count; } return memoryUse; } - - + + /** * Get a HashSet of all ChunkPos within the normal render distance * that should not be rendered. @@ -430,10 +428,10 @@ public class LodUtil { int chunkRenderDist = mc.getRenderDistance(); ChunkPos centerChunk = new ChunkPos(playerPos); - + // skip chunks that are already going to be rendered by Minecraft HashSet posToSkip = getRenderedChunks(); - + // go through each chunk within the normal view distance for (int x = centerChunk.x - chunkRenderDist; x < centerChunk.x + chunkRenderDist; x++) { @@ -441,11 +439,11 @@ public class LodUtil { if (!lodDim.doesDataExist(LodUtil.CHUNK_DETAIL_LEVEL, x, z)) continue; - + long data = lodDim.getSingleData(LodUtil.CHUNK_DETAIL_LEVEL, x, z); - + short lodAverageHeight = DataPointUtil.getHeight(data); - + if (playerPos.getY() <= lodAverageHeight) { // don't draw Lod's that are taller than the player @@ -454,11 +452,11 @@ public class LodUtil } } } - + return posToSkip; } - - + + /** * This method returns the ChunkPos of all chunks that Minecraft * is going to render this frame.

@@ -470,9 +468,9 @@ public class LodUtil public static HashSet getRenderedChunks() { HashSet loadedPos = new HashSet<>(); - + // Wow those are some long names! - + // go through every RenderInfo to get the compiled chunks WorldRenderer renderer = mc.getLevelRenderer(); for (WorldRenderer.LocalRenderInformationContainer worldrenderer$localrenderinformationcontainer : renderer.renderChunks) @@ -482,15 +480,15 @@ public class LodUtil { // add the ChunkPos for every rendered chunk BlockPos bpos = worldrenderer$localrenderinformationcontainer.chunk.getOrigin(); - + loadedPos.add(new ChunkPos(bpos)); } } - - + + return loadedPos; } - + /** * This method find if a given chunk is a border chunk of the renderable ones * @param vanillaRenderedChunks matrix of the vanilla rendered chunks