Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f767215ff0 | |||
| ef87a4e595 | |||
| 1e4fb66e9a | |||
| fef87df09b |
+1
-1
@@ -537,7 +537,7 @@ ij_groovy_wrap_chain_calls_after_dot = false
|
||||
ij_groovy_wrap_long_lines = false
|
||||
|
||||
[{*.har,*.json,*.png.mcmeta,mcmod.info,pack.mcmeta}]
|
||||
indent_size = 2
|
||||
indent_size = 4
|
||||
ij_json_array_wrapping = split_into_lines
|
||||
ij_json_keep_blank_lines_in_code = 0
|
||||
ij_json_keep_indents_on_empty_lines = false
|
||||
|
||||
@@ -61,15 +61,14 @@ public class DhApi
|
||||
* Note: Don't use this string in your code. It may change and is only for reference.
|
||||
*/
|
||||
public static final String READ_ME =
|
||||
"If you don't see Javadocs something is wrong. \n" +
|
||||
"If you are only using the full DH Mod in your build script, you won't have access to our javadocs and could potentially call into unsafe code. \n" +
|
||||
"\n" +
|
||||
"Please use the API jar in your build script as a compile time dependency " +
|
||||
"and the full DH jar as a runtime dependency. \n" +
|
||||
"\n" +
|
||||
"Please refer to the example API project or the DH Developer Wiki for additional information " +
|
||||
"and suggested setup. \n" + // DH Dev note: no links were included to prevent link rot.
|
||||
"";
|
||||
"""
|
||||
If you don't see Javadocs something is wrong.
|
||||
If you are only using the full DH Mod in your build script, you won't have access to our javadocs and could potentially call into unsafe code.
|
||||
|
||||
Please use the API jar in your build script as a compile time dependency and the full DH jar as a runtime dependency.
|
||||
|
||||
Please refer to the example API project or the DH Developer Wiki for additional information and suggested setup.
|
||||
"""; // DH Dev note: no links were included to prevent link rot.
|
||||
public static String readMe() { return READ_ME; }
|
||||
|
||||
/**
|
||||
@@ -180,7 +179,7 @@ public class DhApi
|
||||
* This version should be updated whenever non-breaking fixes are added to the Distant Horizons API.
|
||||
* @since API 1.0.0
|
||||
*/
|
||||
public static int getApiPatchVersion() { return ModInfo.API_PATCH_VERSION; }
|
||||
public static int getApiPatchVersion() { return ModInfo.API_PATH_VERSION; }
|
||||
|
||||
/**
|
||||
* Returns the mod's semantic version number in the format: Major.Minor.Patch
|
||||
|
||||
@@ -24,7 +24,7 @@ package com.seibel.distanthorizons.api.enums;
|
||||
* CHUNK - Detail Level: 4, width 16 block, <br>
|
||||
* REGION - Detail Level: 9, width 512 block <br> <br>
|
||||
*
|
||||
* Detail levels in Distant Horizons represent how large a LOD
|
||||
* Detail levels in Distant Horizons represent how large a section (of either LODs or MC chunks)
|
||||
* is, with the smallest being 0 (1 block wide). <br>
|
||||
* The width of a detail level can be calculated by putting the detail level to the power of 2. <br>
|
||||
* Example for the chunk detail level (4): 2^4 = 16 blocks wide <Br><br>
|
||||
|
||||
+2
-4
@@ -23,12 +23,13 @@ package com.seibel.distanthorizons.api.enums.config;
|
||||
* AUTO, <br>
|
||||
* BUFFER_STORAGE, <br>
|
||||
* SUB_DATA, <br>
|
||||
* BUFFER_MAPPING, <br>
|
||||
* DATA <br>
|
||||
*
|
||||
* @author Leetom
|
||||
* @author James Seibel
|
||||
* @version 2024-4-6
|
||||
* @since API 3.0.0
|
||||
* @since API 2.0.0
|
||||
*/
|
||||
public enum EDhApiGpuUploadMethod
|
||||
{
|
||||
@@ -48,10 +49,7 @@ public enum EDhApiGpuUploadMethod
|
||||
* May end up storing buffers in System memory. <br>
|
||||
* Fast rending if in GPU memory, slow if in system memory, <br>
|
||||
* but won't stutter when uploading.
|
||||
*
|
||||
* @deprecated not currently supported
|
||||
*/
|
||||
@Deprecated
|
||||
BUFFER_MAPPING(true, false),
|
||||
|
||||
/** Fast rendering but may stutter when uploading. */
|
||||
|
||||
-1
@@ -21,7 +21,6 @@ package com.seibel.distanthorizons.api.enums.rendering;
|
||||
* AIR, <br>
|
||||
* ILLUMINATED, <br>
|
||||
*
|
||||
* @author IMS
|
||||
* @author James Seibel
|
||||
* @since API 3.0.0
|
||||
* @version 2024-7-11
|
||||
|
||||
+13
-24
@@ -56,34 +56,23 @@ public enum EDhApiDebugRendering
|
||||
|
||||
public static EDhApiDebugRendering next(EDhApiDebugRendering type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OFF:
|
||||
return SHOW_DETAIL;
|
||||
case SHOW_DETAIL:
|
||||
return SHOW_BLOCK_MATERIAL;
|
||||
case SHOW_BLOCK_MATERIAL:
|
||||
return SHOW_OVERLAPPING_QUADS;
|
||||
case SHOW_OVERLAPPING_QUADS:
|
||||
return SHOW_RENDER_SOURCE_FLAG;
|
||||
default:
|
||||
return OFF;
|
||||
}
|
||||
return switch (type) {
|
||||
case OFF -> SHOW_DETAIL;
|
||||
case SHOW_DETAIL -> SHOW_BLOCK_MATERIAL;
|
||||
case SHOW_BLOCK_MATERIAL -> SHOW_OVERLAPPING_QUADS;
|
||||
case SHOW_OVERLAPPING_QUADS -> SHOW_RENDER_SOURCE_FLAG;
|
||||
default -> OFF;
|
||||
};
|
||||
}
|
||||
|
||||
public static EDhApiDebugRendering previous(EDhApiDebugRendering type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OFF:
|
||||
return SHOW_RENDER_SOURCE_FLAG;
|
||||
case SHOW_RENDER_SOURCE_FLAG:
|
||||
return SHOW_OVERLAPPING_QUADS;
|
||||
case SHOW_OVERLAPPING_QUADS:
|
||||
return SHOW_DETAIL;
|
||||
default:
|
||||
return OFF;
|
||||
}
|
||||
return switch (type) {
|
||||
case OFF -> SHOW_RENDER_SOURCE_FLAG;
|
||||
case SHOW_RENDER_SOURCE_FLAG -> SHOW_OVERLAPPING_QUADS;
|
||||
case SHOW_OVERLAPPING_QUADS -> SHOW_DETAIL;
|
||||
default -> OFF;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-18
@@ -42,29 +42,21 @@ public enum EDhApiRendererMode
|
||||
/** Used by the config GUI to cycle through the available rendering options */
|
||||
public static EDhApiRendererMode next(EDhApiRendererMode type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DEFAULT:
|
||||
return DEBUG;
|
||||
case DEBUG:
|
||||
return DISABLED;
|
||||
default:
|
||||
return DEFAULT;
|
||||
}
|
||||
return switch (type) {
|
||||
case DEFAULT -> DEBUG;
|
||||
case DEBUG -> DISABLED;
|
||||
default -> DEFAULT;
|
||||
};
|
||||
}
|
||||
|
||||
/** Used by the config GUI to cycle through the available rendering options */
|
||||
public static EDhApiRendererMode previous(EDhApiRendererMode type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DEFAULT:
|
||||
return DISABLED;
|
||||
case DEBUG:
|
||||
return DEFAULT;
|
||||
default:
|
||||
return DEBUG;
|
||||
}
|
||||
return switch (type) {
|
||||
case DEFAULT -> DISABLED;
|
||||
case DEBUG -> DEFAULT;
|
||||
default -> DEBUG;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-6
@@ -19,7 +19,6 @@
|
||||
|
||||
package com.seibel.distanthorizons.api.interfaces.block;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||
import com.seibel.distanthorizons.api.interfaces.IDhApiUnsafeWrapper;
|
||||
|
||||
/**
|
||||
@@ -45,11 +44,7 @@ public interface IDhApiBlockStateWrapper extends IDhApiUnsafeWrapper
|
||||
* @since API 3.0.0
|
||||
*/
|
||||
String getSerialString();
|
||||
/**
|
||||
* Returns the byte value representing the {@link EDhApiBlockMaterial} enum.
|
||||
* @see EDhApiBlockMaterial
|
||||
* @since API 3.0.0
|
||||
*/
|
||||
/** @since API 3.0.0 */
|
||||
byte getMaterialId();
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public interface IDhApiConfig
|
||||
IDhApiWorldGenerationConfig worldGenerator();
|
||||
IDhApiMultiplayerConfig multiplayer();
|
||||
IDhApiMultiThreadingConfig multiThreading();
|
||||
IDhApiGpuBuffersConfig gpuBuffers();
|
||||
// note: DON'T add the Auto Updater to this API. We only want the user's to have the ability to control when things are downloaded to their machines.
|
||||
//IDhApiLoggingConfig logging(); // TODO implement
|
||||
IDhApiDebuggingConfig debugging();
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.api.interfaces.config.client;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
||||
import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigGroup;
|
||||
import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue;
|
||||
|
||||
/**
|
||||
* Distant Horizons' OpenGL buffer configuration.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2023-6-14
|
||||
* @since API 1.0.0
|
||||
*/
|
||||
public interface IDhApiGpuBuffersConfig extends IDhApiConfigGroup
|
||||
{
|
||||
|
||||
/** Defines how geometry data is uploaded to the GPU. */
|
||||
IDhApiConfigValue<EDhApiGpuUploadMethod> gpuUploadMethod();
|
||||
|
||||
/**
|
||||
* Defines how long we should wait after uploading one
|
||||
* Megabyte of geometry data to the GPU before uploading
|
||||
* the next Megabyte of data. <br>
|
||||
* This can be set to a non-zero number to reduce stuttering caused by
|
||||
* uploading buffers to the GPU.
|
||||
*/
|
||||
IDhApiConfigValue<Integer> gpuUploadPerMegabyteInMilliseconds();
|
||||
|
||||
}
|
||||
+2
-20
@@ -91,28 +91,10 @@ public interface IDhApiWorldGenerator extends Closeable, IDhApiOverrideable
|
||||
default byte getMaxGenerationGranularity() { return (byte) (EDhApiDetailLevel.CHUNK.detailLevel + 2); }
|
||||
|
||||
/**
|
||||
* Starting in API 3.0.0 DH now handles future queuing/management internally. <br><br>
|
||||
*
|
||||
* Previous description: <br>
|
||||
* true if the generator is unable to accept new generation requests. <br>
|
||||
*
|
||||
* @return true if the generator is unable to accept new generation requests.
|
||||
* @since API 1.0.0
|
||||
* @deprecated API 3.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean isBusy() { return false; }
|
||||
|
||||
/**
|
||||
* Only used if {@link #getReturnType()} returns {@link EDhApiWorldGeneratorReturnType#API_CHUNKS}. <Br>
|
||||
* If true DH will run additional validation on the {@link DhApiChunk}'s returned. <Br>
|
||||
* This should be disabled during release but should be enabled during development to help spot issues with your data format.
|
||||
*
|
||||
* @see #getReturnType()
|
||||
* @see DhApiChunk
|
||||
* @see EDhApiWorldGeneratorReturnType#API_CHUNKS
|
||||
* @since API 3.0.0
|
||||
*/
|
||||
default boolean runApiChunkValidation() { return true; }
|
||||
boolean isBusy();
|
||||
|
||||
|
||||
|
||||
|
||||
+5
-3
@@ -26,7 +26,7 @@ import com.seibel.distanthorizons.api.objects.DhApiResult;
|
||||
* Used to interact with Distant Horizons' rendering system.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2024-7-27
|
||||
* @version 2023-10-13
|
||||
* @since API 1.0.0
|
||||
*/
|
||||
public interface IDhApiRenderProxy
|
||||
@@ -39,8 +39,10 @@ public interface IDhApiRenderProxy
|
||||
* If this is called on a dedicated server it won't do anything and will return {@link DhApiResult#success} = false <Br><Br>
|
||||
*
|
||||
* Background: <Br>
|
||||
* When rendering Distant Horizons bakes each block's color into the geometry that's rendered. <Br>
|
||||
* This improves rendering speed and VRAM size, but prevents dynamically changing LOD colors. <Br>
|
||||
* Distant Horizons has two different file formats: Full data and Render data. <Br>
|
||||
* - Full data files store the block, biome, etc. information and is the result of loading or generating new chunks. <Br>
|
||||
* - Render data files store LOD colors and are created using the Full data and currently loaded resource packs. <Br>
|
||||
* This is the data cleared by this method.
|
||||
*/
|
||||
DhApiResult<Boolean> clearRenderDataCache();
|
||||
|
||||
|
||||
+2
@@ -28,6 +28,8 @@ import com.seibel.distanthorizons.api.interfaces.IDhApiUnsafeWrapper;
|
||||
*/
|
||||
public interface IDhApiDimensionTypeWrapper extends IDhApiUnsafeWrapper
|
||||
{
|
||||
String getDimensionName();
|
||||
|
||||
boolean hasCeiling();
|
||||
|
||||
boolean hasSkyLight();
|
||||
|
||||
+2
-17
@@ -28,33 +28,20 @@ import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderRegist
|
||||
* A level is equivalent to a dimension in vanilla Minecraft.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2024-7-28
|
||||
* @version 2022-7-14
|
||||
* @since API 1.0.0
|
||||
*/
|
||||
public interface IDhApiLevelWrapper extends IDhApiUnsafeWrapper
|
||||
{
|
||||
IDhApiDimensionTypeWrapper getDimensionType();
|
||||
|
||||
String getDimensionName();
|
||||
|
||||
EDhApiLevelType getLevelType();
|
||||
|
||||
boolean hasCeiling();
|
||||
|
||||
boolean hasSkyLight();
|
||||
|
||||
/**
|
||||
* Deprecated, use {@link IDhApiLevelWrapper#getMaxHeight} instead. <br>
|
||||
* Returns the max block height of the level.
|
||||
*
|
||||
* @see IDhApiLevelWrapper#getMaxHeight
|
||||
*/
|
||||
@Deprecated
|
||||
default int getHeight() { return this.getMaxHeight(); }
|
||||
/**
|
||||
* Returns the max block height of the level
|
||||
* @since API 3.0.0
|
||||
*/
|
||||
/** Returns the max block height of the level(?) */
|
||||
int getMaxHeight();
|
||||
|
||||
/**
|
||||
@@ -66,8 +53,6 @@ public interface IDhApiLevelWrapper extends IDhApiUnsafeWrapper
|
||||
/**
|
||||
* Will return null if called on the server,
|
||||
* or if called before the renderer has been set up.
|
||||
*
|
||||
* @since API 3.0.0
|
||||
*/
|
||||
IDhApiCustomRenderRegister getRenderRegister();
|
||||
|
||||
|
||||
@@ -59,12 +59,12 @@ public class DhApiResult<T>
|
||||
|
||||
|
||||
public static <Pt> DhApiResult<Pt> createSuccess() { return new DhApiResult<>(true, ""); }
|
||||
public static <Pt> DhApiResult<Pt> createSuccess(Pt payload) { return new DhApiResult<Pt>(true, "", payload); }
|
||||
public static <Pt> DhApiResult<Pt> createSuccess(Pt payload) { return new DhApiResult<>(true, "", payload); }
|
||||
// There is no createSuccess(String message) method because it would be too easy to confuse with createSuccess(Pt payload) when returning null
|
||||
public static <Pt> DhApiResult<Pt> createSuccess(String message, Pt payload) { return new DhApiResult<Pt>(true, message, payload); }
|
||||
public static <Pt> DhApiResult<Pt> createSuccess(String message, Pt payload) { return new DhApiResult<>(true, message, payload); }
|
||||
|
||||
// there is no createFail() since all fail results should give a reason for their failure
|
||||
public static <Pt> DhApiResult<Pt> createFail(String message) { return new DhApiResult<>(false, message); }
|
||||
public static <Pt> DhApiResult<Pt> createFail(String message, Pt payload) { return new DhApiResult<Pt>(false, message, payload); }
|
||||
public static <Pt> DhApiResult<Pt> createFail(String message, Pt payload) { return new DhApiResult<>(false, message, payload); }
|
||||
|
||||
}
|
||||
|
||||
@@ -21,10 +21,8 @@ package com.seibel.distanthorizons.api.objects.data;
|
||||
|
||||
import com.seibel.distanthorizons.api.interfaces.factories.IDhApiWrapperFactory;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -54,27 +52,7 @@ public class DhApiChunk
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
/**
|
||||
* Deprecated due to the topYBlockPos and bottomYBlockPos variables being put in the wrong order.
|
||||
* They should have been in bottom -> top order.
|
||||
*
|
||||
* @see DhApiChunk#create(int, int, int, int)
|
||||
*/
|
||||
@Deprecated
|
||||
public DhApiChunk(int chunkPosX, int chunkPosZ, int topYBlockPos, int bottomYBlockPos)
|
||||
{ this(chunkPosX, chunkPosZ, bottomYBlockPos, topYBlockPos, false); }
|
||||
|
||||
/**
|
||||
* @since API 3.0.0
|
||||
*/
|
||||
public static DhApiChunk create(int chunkPosX, int chunkPosZ, int bottomYBlockPos, int topYBlockPos)
|
||||
{ return new DhApiChunk(chunkPosX, chunkPosZ, bottomYBlockPos, topYBlockPos, false); }
|
||||
|
||||
/**
|
||||
* Only visible to internal DH methods
|
||||
* @param ignoredParameter is only present to differentiate the two constructors and isn't actually used
|
||||
*/
|
||||
private DhApiChunk(int chunkPosX, int chunkPosZ, int bottomYBlockPos, int topYBlockPos, boolean ignoredParameter)
|
||||
public DhApiChunk(int chunkPosX, int chunkPosZ, int bottomYBlockPos, int topYBlockPos)
|
||||
{
|
||||
this.chunkPosX = chunkPosX;
|
||||
this.chunkPosZ = chunkPosZ;
|
||||
@@ -116,34 +94,27 @@ public class DhApiChunk
|
||||
*/
|
||||
public void setDataPoints(int relX, int relZ, List<DhApiTerrainDataPoint> dataPoints) throws IndexOutOfBoundsException, IllegalArgumentException
|
||||
{
|
||||
//==================//
|
||||
// basic validation //
|
||||
//==================//
|
||||
|
||||
// heavier validation is done in the world generator if requested
|
||||
|
||||
int internalArrayIndex = (relZ << 4) | relX;
|
||||
throwIfRelativePosOutOfBounds(relX, relZ);
|
||||
|
||||
if (dataPoints == null)
|
||||
// validate the incoming datapoints
|
||||
if (dataPoints != null)
|
||||
{
|
||||
// we don't allow null columns
|
||||
throw new IllegalArgumentException("Null columns aren't allowed. If you want to remove all data from a column please clear the list or pass in an empty list.");
|
||||
for (int i = 0; i < dataPoints.size(); i++) // standard for-loop used instead of an enhanced for-loop to slightly reduce GC overhead due to iterator allocation
|
||||
{
|
||||
DhApiTerrainDataPoint dataPoint = dataPoints.get(i);
|
||||
if (dataPoint == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Null DhApiTerrainDataPoints are not allowed. If you want to represent empty terrain, please use AIR.");
|
||||
}
|
||||
|
||||
if (dataPoint.detailLevel != 0)
|
||||
{
|
||||
throw new IllegalArgumentException("DhApiTerrainDataPoints has the wrong detail level ["+dataPoint.detailLevel+"], all data points must be block sized; IE their detail level must be [0].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// set datapoints //
|
||||
//================//
|
||||
|
||||
List<DhApiTerrainDataPoint> column = this.dataPoints.get(internalArrayIndex);
|
||||
if (column == null)
|
||||
{
|
||||
column = new ArrayList<>();
|
||||
this.dataPoints.set(internalArrayIndex, column);
|
||||
}
|
||||
column.addAll(dataPoints);
|
||||
this.dataPoints.set((relZ << 4) | relX, dataPoints);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-56
@@ -19,12 +19,9 @@
|
||||
|
||||
package com.seibel.distanthorizons.api.objects.data;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
|
||||
import com.seibel.distanthorizons.api.interfaces.block.IDhApiBiomeWrapper;
|
||||
import com.seibel.distanthorizons.api.interfaces.block.IDhApiBlockStateWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Holds a single datapoint of terrain data.
|
||||
*
|
||||
@@ -40,8 +37,6 @@ public class DhApiTerrainDataPoint
|
||||
* 2 = 4x4 blocks <br>
|
||||
* 4 = chunk (16x16 blocks) <br>
|
||||
* 9 = region (512x512 blocks) <br>
|
||||
*
|
||||
* @see EDhApiDetailLevel
|
||||
*/
|
||||
public final byte detailLevel;
|
||||
|
||||
@@ -55,57 +50,7 @@ public class DhApiTerrainDataPoint
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
/**
|
||||
* Deprecated due to the topYBlockPos and bottomYBlockPos variables being put in the wrong order.
|
||||
* They should have been in bottom -> top order.
|
||||
*
|
||||
* @see DhApiTerrainDataPoint#create(byte, int, int, int, int, IDhApiBlockStateWrapper, IDhApiBiomeWrapper)
|
||||
*/
|
||||
@Deprecated
|
||||
public DhApiTerrainDataPoint(
|
||||
byte detailLevel,
|
||||
int blockLightLevel, int skyLightLevel,
|
||||
int topYBlockPos, int bottomYBlockPos,
|
||||
IDhApiBlockStateWrapper blockStateWrapper, IDhApiBiomeWrapper biomeWrapper)
|
||||
{
|
||||
this(detailLevel, blockLightLevel, skyLightLevel,
|
||||
bottomYBlockPos, topYBlockPos,
|
||||
blockStateWrapper, biomeWrapper,
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since API 3.0.0
|
||||
*/
|
||||
public static DhApiTerrainDataPoint create(
|
||||
byte detailLevel,
|
||||
int blockLightLevel, int skyLightLevel,
|
||||
int bottomYBlockPos, int topYBlockPos,
|
||||
IDhApiBlockStateWrapper blockStateWrapper, IDhApiBiomeWrapper biomeWrapper
|
||||
)
|
||||
{
|
||||
return new DhApiTerrainDataPoint(
|
||||
detailLevel, blockLightLevel, skyLightLevel,
|
||||
bottomYBlockPos, topYBlockPos,
|
||||
blockStateWrapper, biomeWrapper,
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only visible to internal DH methods
|
||||
* @param ignoredParameter is only present to differentiate the two constructors and isn't actually used
|
||||
*/
|
||||
private DhApiTerrainDataPoint(
|
||||
byte detailLevel,
|
||||
int blockLightLevel, int skyLightLevel,
|
||||
int bottomYBlockPos, int topYBlockPos,
|
||||
IDhApiBlockStateWrapper blockStateWrapper, IDhApiBiomeWrapper biomeWrapper,
|
||||
boolean ignoredParameter
|
||||
)
|
||||
public DhApiTerrainDataPoint(byte detailLevel, int blockLightLevel, int skyLightLevel, int bottomYBlockPos, int topYBlockPos, IDhApiBlockStateWrapper blockStateWrapper, IDhApiBiomeWrapper biomeWrapper)
|
||||
{
|
||||
this.detailLevel = detailLevel;
|
||||
|
||||
|
||||
+1
-2
@@ -163,9 +163,8 @@ public class ApiEventInjector extends DependencyInjector<IDhApiEvent> implements
|
||||
DhApiEventParam<T> eventParam = createEventParamWrapper(event, input);
|
||||
event.fireEvent(eventParam);
|
||||
|
||||
if (eventParam instanceof DhApiCancelableEventParam)
|
||||
if (eventParam instanceof DhApiCancelableEventParam<T> cancelableEventParam)
|
||||
{
|
||||
DhApiCancelableEventParam<T> cancelableEventParam = (DhApiCancelableEventParam<T>) eventParam;
|
||||
cancelEvent |= cancelableEventParam.isEventCanceled();
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -87,7 +87,7 @@ public class DependencyInjector<BindableType extends IBindable> implements IDepe
|
||||
// make sure the hashSet has an array to hold the dependency
|
||||
if (!this.dependencies.containsKey(dependencyInterface))
|
||||
{
|
||||
this.dependencies.put(dependencyInterface, new ArrayList<BindableType>());
|
||||
this.dependencies.put(dependencyInterface, new ArrayList<>());
|
||||
}
|
||||
|
||||
// add the dependency
|
||||
@@ -134,7 +134,7 @@ public class DependencyInjector<BindableType extends IBindable> implements IDepe
|
||||
@Override
|
||||
public <T extends BindableType> T get(Class<T> interfaceClass) throws ClassCastException
|
||||
{
|
||||
return (T) this.getInternalLogic(interfaceClass, false).get(0);
|
||||
return (T) this.getInternalLogic(interfaceClass, false).getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,7 +146,7 @@ public class DependencyInjector<BindableType extends IBindable> implements IDepe
|
||||
@Override
|
||||
public <T extends BindableType> T get(Class<T> interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException
|
||||
{
|
||||
return (T) this.getInternalLogic(interfaceClass, allowIncompleteDependencies).get(0);
|
||||
return (T) this.getInternalLogic(interfaceClass, allowIncompleteDependencies).getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +175,7 @@ public class DependencyInjector<BindableType extends IBindable> implements IDepe
|
||||
|
||||
|
||||
// return an empty list to prevent null pointers
|
||||
ArrayList<T> emptyList = new ArrayList<T>();
|
||||
ArrayList<T> emptyList = new ArrayList<>();
|
||||
emptyList.add(null);
|
||||
return emptyList;
|
||||
}
|
||||
|
||||
+2
-2
@@ -64,14 +64,14 @@ public class OverridePriorityListContainer implements IBindable
|
||||
else
|
||||
{
|
||||
// last item should have the highest priority
|
||||
return this.overridePairList.get(this.overridePairList.size() - 1).override;
|
||||
return this.overridePairList.getLast().override;
|
||||
}
|
||||
}
|
||||
public IDhApiOverrideable getOverrideWithHighestPriority()
|
||||
{
|
||||
if (this.overridePairList.size() != 0)
|
||||
{
|
||||
return this.overridePairList.get(0).override;
|
||||
return this.overridePairList.getFirst().override;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -26,22 +26,15 @@ package com.seibel.distanthorizons.coreapi;
|
||||
public final class ModInfo
|
||||
{
|
||||
public static final String ID = "distanthorizons";
|
||||
|
||||
public static final String RESOURCE_NAMESPACE = "distant_horizons";
|
||||
public static final String DEDICATED_SERVER_INITIAL_PATH = "dedicated_server_initial";
|
||||
|
||||
// region Protocol versions
|
||||
// Incremented every time any packets are added, changed or removed, with a few exceptions.
|
||||
public static final int PROTOCOL_VERSION = 3;
|
||||
public static final String WRAPPER_PACKET_PATH = "message";
|
||||
// endregion
|
||||
|
||||
|
||||
/** The internal protocol version used for networking */
|
||||
public static final int PROTOCOL_VERSION = 1;
|
||||
/** The protocol version used for multiverse networking */
|
||||
public static final int MULTIVERSE_PLUGIN_PROTOCOL_VERSION = 1;
|
||||
/** The internal mod name */
|
||||
public static final String NAME = "DistantHorizons";
|
||||
/** Human-readable version of NAME */
|
||||
public static final String READABLE_NAME = "Distant Horizons";
|
||||
public static final String VERSION = "2.2.2-a-dev";
|
||||
public static final String VERSION = "2.1.3-a-dev";
|
||||
/** Returns true if the current build is an unstable developer build, false otherwise. */
|
||||
public static boolean IS_DEV_BUILD = VERSION.toLowerCase().contains("dev");
|
||||
|
||||
@@ -50,7 +43,10 @@ public final class ModInfo
|
||||
/** This version should be updated whenever new methods are added to the DH API */
|
||||
public static final int API_MINOR_VERSION = 0;
|
||||
/** This version should be updated whenever non-breaking fixes are added to the DH API */
|
||||
public static final int API_PATCH_VERSION = 1;
|
||||
public static final int API_PATH_VERSION = 0;
|
||||
|
||||
public static final String NETWORKING_RESOURCE_NAMESPACE = "distant_horizons";
|
||||
public static final String MULTIVERSE_PLUGIN_NAMESPACE = "world_control";
|
||||
|
||||
/** All DH owned threads should start with this string to allow for easier debugging and profiling. */
|
||||
public static final String THREAD_NAME_PREFIX = "DH-";
|
||||
|
||||
@@ -24,12 +24,12 @@ import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Miscellaneous string helper functions.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-7-19
|
||||
*/
|
||||
public class StringUtil
|
||||
{
|
||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the n-th index of the given string. <br> <br>
|
||||
*
|
||||
@@ -67,6 +67,8 @@ public class StringUtil
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||
/**
|
||||
* Converts the given byte array into a hex string representation. <br>
|
||||
* source: https://stackoverflow.com/a/9855338
|
||||
@@ -83,20 +85,4 @@ public class StringUtil
|
||||
return new String(hexChars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a shortened version of the given string that is no longer than maxLength. <br>
|
||||
* If null returns the empty string.
|
||||
*/
|
||||
public static String shortenString(String str, int maxLength)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return str.substring(0, Math.min(str.length(), maxLength));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-12
@@ -10,7 +10,7 @@ application {
|
||||
}
|
||||
|
||||
configurations {
|
||||
shadowedArtifact // Used by DH to specify that we want to implement the shadowed core JAR file instead of the regular JAR file
|
||||
downgradedArtifact // Used by DH to specify that we want to implement the shadowed core JAR file instead of the regular JAR file
|
||||
shade
|
||||
implementation.extendsFrom shade
|
||||
}
|
||||
@@ -39,9 +39,7 @@ dependencies { // All of these dependencies are in Vanilla Minecraft, but we nee
|
||||
runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-tinyfd::$lwjglNatives"
|
||||
|
||||
// FIXME for some reason this line doesn't actually shade in the library
|
||||
// shade "it.unimi.dsi:fastutil:${rootProject.fastutil_version}" // Add our own fastutil version
|
||||
implementation "org.joml:joml:${rootProject.joml_version}"
|
||||
|
||||
|
||||
// Some other dependencies
|
||||
@@ -49,15 +47,8 @@ dependencies { // All of these dependencies are in Vanilla Minecraft, but we nee
|
||||
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
||||
implementation("com.google.common:google-collect:0.5")
|
||||
implementation("com.google.guava:guava:31.1-jre")
|
||||
|
||||
}
|
||||
|
||||
artifacts {
|
||||
shadowedArtifact shadowJar // Setup the configuration shadowedArtifact to be the shadowJar
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
def librariesLocation = "DistantHorizons.libraries"
|
||||
// relocate "it.unimi.dsi.fastutil", "${librariesLocation}.unimi.dsi.fastutil"
|
||||
mergeServiceFiles()
|
||||
downgradedArtifact shadeDowngradedApi // Setup the configuration downgradedArtifact to be the `shadeDowngradedApi` which downgrades the core to a specified Java version
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericRenderObjectFactory;
|
||||
import com.seibel.distanthorizons.core.sql.DatabaseUpdater;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.core.world.DhApiWorldProxy;
|
||||
import com.seibel.distanthorizons.core.api.external.methods.config.DhApiConfig;
|
||||
@@ -78,18 +77,16 @@ public class Initializer
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class) != null)
|
||||
|
||||
// attempt to setup Swing so we can display dialogs (popup windows)
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
// attempt to setup Swing so we can display dialogs (popup windows)
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
LOGGER.warn("Java.awt.headless is false. This means Distant Horizons can't display error and info dialog windows.");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("Java.awt.headless set to true. Distant Horizons can correctly display error and info dialog windows.");
|
||||
}
|
||||
LOGGER.warn("Java.awt.headless is false. This means Distant Horizons can't display error and info dialog windows.");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("Java.awt.headless set to true. Distant Horizons can correctly display error and info dialog windows.");
|
||||
}
|
||||
|
||||
// link Core's config to the API
|
||||
|
||||
Vendored
+2
@@ -42,6 +42,8 @@ public class DhApiConfig implements IDhApiConfig
|
||||
@Override
|
||||
public IDhApiMultiThreadingConfig multiThreading() { return DhApiMultiThreadingConfig.INSTANCE; }
|
||||
@Override
|
||||
public IDhApiGpuBuffersConfig gpuBuffers() { return DhApiGpuBuffersConfig.INSTANCE; }
|
||||
@Override
|
||||
public IDhApiDebuggingConfig debugging() { return DhApiDebuggingConfig.INSTANCE; }
|
||||
|
||||
}
|
||||
|
||||
+7
-7
@@ -35,30 +35,30 @@ public class DhApiAmbientOcclusionConfig implements IDhApiAmbientOcclusionConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> enabled()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.Ssao.enabled); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.enabled); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> sampleCount()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.Graphics.Ssao.sampleCount); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.sampleCount); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> radius()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Ssao.radius); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.radius); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> strength()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Ssao.strength); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.strength); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> bias()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Ssao.bias); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.bias); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> minLight()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Ssao.minLight); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.minLight); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> blurRadius()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.Graphics.Ssao.blurRadius); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.blurRadius); }
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -34,18 +34,18 @@ public class DhApiDebuggingConfig implements IDhApiDebuggingConfig
|
||||
|
||||
|
||||
public IDhApiConfigValue<EDhApiDebugRendering> debugRendering()
|
||||
{ return new DhApiConfigValue<EDhApiDebugRendering, EDhApiDebugRendering>(Config.Client.Advanced.Debugging.debugRendering); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.debugRendering); }
|
||||
|
||||
public IDhApiConfigValue<Boolean> debugKeybindings()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Debugging.enableDebugKeybindings); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.enableDebugKeybindings); }
|
||||
|
||||
public IDhApiConfigValue<Boolean> renderWireframe()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Debugging.renderWireframe); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.renderWireframe); }
|
||||
|
||||
public IDhApiConfigValue<Boolean> lodOnlyMode()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Debugging.lodOnlyMode); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.lodOnlyMode); }
|
||||
|
||||
public IDhApiConfigValue<Boolean> debugWireframeRendering()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Debugging.DebugWireframe.enableRendering); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.DebugWireframe.enableRendering); }
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -35,26 +35,26 @@ public class DhApiFarFogConfig implements IDhApiFarFogConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> farFogStartDistance()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogStart); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogStart); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> farFogEndDistance()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogEnd); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogEnd); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> farFogMinThickness()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogMin); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogMin); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> farFogMaxThickness()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogMax); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogMax); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiFogFalloff> farFogFalloff()
|
||||
{ return new DhApiConfigValue<EDhApiFogFalloff, EDhApiFogFalloff>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogFalloff); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogFalloff); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> farFogDensity()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogDensity); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogDensity); }
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -35,12 +35,12 @@ public class DhApiGenericRenderingConfig implements IDhApiGenericRenderingConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> renderingEnabled()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.GenericRendering.enableRendering); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.GenericRendering.enableRendering); }
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> beaconRenderingEnabled()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.GenericRendering.enableBeaconRendering); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.GenericRendering.enableBeaconRendering); }
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> cloudRenderingEnabled()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.GenericRendering.enableCloudRendering); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.GenericRendering.enableCloudRendering); }
|
||||
|
||||
}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.core.api.external.methods.config.client;
|
||||
|
||||
import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue;
|
||||
import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiGpuBuffersConfig;
|
||||
import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
||||
|
||||
public class DhApiGpuBuffersConfig implements IDhApiGpuBuffersConfig
|
||||
{
|
||||
public static DhApiGpuBuffersConfig INSTANCE = new DhApiGpuBuffersConfig();
|
||||
|
||||
private DhApiGpuBuffersConfig() { }
|
||||
|
||||
|
||||
|
||||
public IDhApiConfigValue<EDhApiGpuUploadMethod> gpuUploadMethod()
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.GpuBuffers.gpuUploadMethod); }
|
||||
|
||||
public IDhApiConfigValue<Integer> gpuUploadPerMegabyteInMilliseconds()
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.GpuBuffers.gpuUploadPerMegabyteInMilliseconds); }
|
||||
|
||||
}
|
||||
+20
-20
@@ -56,15 +56,15 @@ public class DhApiGraphicsConfig implements IDhApiGraphicsConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> chunkRenderDistance()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> renderingEnabled()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.quickEnableRendering); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.quickEnableRendering); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiRendererMode> renderingMode()
|
||||
{ return new DhApiConfigValue<EDhApiRendererMode, EDhApiRendererMode>(Config.Client.Advanced.Debugging.rendererMode); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.rendererMode); }
|
||||
|
||||
|
||||
|
||||
@@ -74,27 +74,27 @@ public class DhApiGraphicsConfig implements IDhApiGraphicsConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiMaxHorizontalResolution> maxHorizontalResolution()
|
||||
{ return new DhApiConfigValue<EDhApiMaxHorizontalResolution, EDhApiMaxHorizontalResolution>(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiVerticalQuality> verticalQuality()
|
||||
{ return new DhApiConfigValue<EDhApiVerticalQuality, EDhApiVerticalQuality>(Config.Client.Advanced.Graphics.Quality.verticalQuality); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.verticalQuality); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiHorizontalQuality> horizontalQuality()
|
||||
{ return new DhApiConfigValue<EDhApiHorizontalQuality, EDhApiHorizontalQuality>(Config.Client.Advanced.Graphics.Quality.horizontalQuality); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.horizontalQuality); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiTransparency> transparency()
|
||||
{ return new DhApiConfigValue<EDhApiTransparency, EDhApiTransparency>(Config.Client.Advanced.Graphics.Quality.transparency); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.transparency); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiBlocksToAvoid> blocksToAvoid()
|
||||
{ return new DhApiConfigValue<EDhApiBlocksToAvoid, EDhApiBlocksToAvoid>(Config.Client.Advanced.Graphics.Quality.blocksToIgnore); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.blocksToIgnore); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> tintWithAvoidedBlocks()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.Quality.tintWithAvoidedBlocks); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.tintWithAvoidedBlocks); }
|
||||
|
||||
// TODO re-implement
|
||||
// @Override
|
||||
@@ -109,47 +109,47 @@ public class DhApiGraphicsConfig implements IDhApiGraphicsConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> overdrawPreventionRadius()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.AdvancedGraphics.overdrawPrevention); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.overdrawPrevention); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> brightnessMultiplier()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.AdvancedGraphics.brightnessMultiplier); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.brightnessMultiplier); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> saturationMultiplier()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.AdvancedGraphics.saturationMultiplier); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.saturationMultiplier); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> caveCullingEnabled()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.AdvancedGraphics.enableCaveCulling); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.enableCaveCulling); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> caveCullingHeight()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.Graphics.AdvancedGraphics.caveCullingHeight); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.caveCullingHeight); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> earthCurvatureRatio()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.Graphics.AdvancedGraphics.earthCurveRatio); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.earthCurveRatio); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> lodOnlyMode()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Debugging.lodOnlyMode); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.lodOnlyMode); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> lodBias()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.AdvancedGraphics.lodBias); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.lodBias); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiLodShading> lodShading()
|
||||
{ return new DhApiConfigValue<EDhApiLodShading, EDhApiLodShading>(Config.Client.Advanced.Graphics.AdvancedGraphics.lodShading); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.lodShading); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> disableFrustumCulling()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> disableShadowFrustumCulling()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableShadowPassFrustumCulling); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableShadowPassFrustumCulling); }
|
||||
|
||||
|
||||
|
||||
|
||||
+9
-9
@@ -37,38 +37,38 @@ public class DhApiHeightFogConfig implements IDhApiHeightFogConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiHeightFogMixMode> heightFogMixMode()
|
||||
{ return new DhApiConfigValue<EDhApiHeightFogMixMode, EDhApiHeightFogMixMode>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMixMode); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMixMode); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiHeightFogMode> heightFogMode()
|
||||
{ return new DhApiConfigValue<EDhApiHeightFogMode, EDhApiHeightFogMode>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMode); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMode); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> heightFogBaseHeight()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogBaseHeight); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogBaseHeight); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> heightFogStartingHeightPercent()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogStart); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogStart); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> heightFogEndingHeightPercent()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogEnd); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogEnd); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> heightFogMinThickness()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMin); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMin); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> heightFogMaxThickness()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMax); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMax); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<EDhApiFogFalloff> heightFogFalloff()
|
||||
{ return new DhApiConfigValue<EDhApiFogFalloff, EDhApiFogFalloff>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogFalloff); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogFalloff); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> heightFogDensity()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogDensity); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogDensity); }
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,14 +34,14 @@ public class DhApiMultiThreadingConfig implements IDhApiMultiThreadingConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> worldGeneratorThreads()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> fileHandlerThreads()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.MultiThreading.numberOfFileHandlerThreads); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.MultiThreading.numberOfFileHandlerThreads); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> lodBuilderThreads()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads); }
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,9 +34,9 @@ public class DhApiMultiplayerConfig implements IDhApiMultiplayerConfig
|
||||
|
||||
|
||||
public IDhApiConfigValue<EDhApiServerFolderNameMode> folderSavingMode()
|
||||
{ return new DhApiConfigValue<EDhApiServerFolderNameMode, EDhApiServerFolderNameMode>(Config.Client.Advanced.Multiplayer.serverFolderNameMode); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Multiplayer.serverFolderNameMode); }
|
||||
|
||||
public IDhApiConfigValue<Double> multiverseSimilarityRequirement()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Multiplayer.multiverseSimilarityRequiredPercent); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Multiplayer.multiverseSimilarityRequiredPercent); }
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -34,18 +34,18 @@ public class DhApiNoiseTextureConfig implements IDhApiNoiseTextureConfig
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Boolean> noiseEnabled()
|
||||
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseEnabled); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseEnabled); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> noiseSteps()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseSteps); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseSteps); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Double> noiseIntensity()
|
||||
{ return new DhApiConfigValue<Double, Double>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseIntensity); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseIntensity); }
|
||||
|
||||
@Override
|
||||
public IDhApiConfigValue<Integer> noiseDropoff()
|
||||
{ return new DhApiConfigValue<Integer, Integer>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseDropoff); }
|
||||
{ return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseDropoff); }
|
||||
|
||||
}
|
||||
|
||||
+4
-7
@@ -187,22 +187,20 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
|
||||
return DhApiResult.createFail("Unable to get terrain data before the world has loaded.");
|
||||
}
|
||||
|
||||
if (!(levelWrapper instanceof ILevelWrapper))
|
||||
if (!(levelWrapper instanceof ILevelWrapper coreLevelWrapper))
|
||||
{
|
||||
// custom level wrappers aren't supported,
|
||||
// the API user must get a level wrapper from our code somewhere
|
||||
return DhApiResult.createFail("Unsupported [" + IDhApiLevelWrapper.class.getSimpleName() + "] implementation, only the core class [" + IDhLevel.class.getSimpleName() + "] is a valid parameter.");
|
||||
}
|
||||
ILevelWrapper coreLevelWrapper = (ILevelWrapper) levelWrapper;
|
||||
|
||||
|
||||
if (!(apiDataCache instanceof DhApiTerrainDataCache))
|
||||
if (!(apiDataCache instanceof DhApiTerrainDataCache dataCache))
|
||||
{
|
||||
// custom level wrappers aren't supported,
|
||||
// the API user must get a level wrapper from our code somewhere
|
||||
return DhApiResult.createFail("Unsupported [" + IDhApiTerrainDataCache.class.getSimpleName() + "] implementation, only the core class [" + DhApiTerrainDataCache.class.getSimpleName() + "] is a valid parameter.");
|
||||
}
|
||||
DhApiTerrainDataCache dataCache = (DhApiTerrainDataCache) apiDataCache;
|
||||
|
||||
|
||||
IDhLevel level = currentWorld.getLevel(coreLevelWrapper);
|
||||
@@ -326,10 +324,9 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
|
||||
int height = FullDataPointUtil.getHeight(dataPoint);
|
||||
int topY = bottomY + height;
|
||||
|
||||
return DhApiTerrainDataPoint.create(
|
||||
detailLevel,
|
||||
return new DhApiTerrainDataPoint(detailLevel,
|
||||
FullDataPointUtil.getBlockLight(dataPoint), FullDataPointUtil.getSkyLight(dataPoint),
|
||||
bottomY, topY,
|
||||
topY, bottomY,
|
||||
blockState, biomeWrapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,20 +24,18 @@ import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
|
||||
import com.seibel.distanthorizons.core.level.IKeyedClientLevelManager;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.render.DhApiRenderProxy;
|
||||
import com.seibel.distanthorizons.core.util.TimerUtil;
|
||||
import com.seibel.distanthorizons.core.util.objects.Pair;
|
||||
import com.seibel.distanthorizons.core.world.*;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.session.Session;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiDebugRendering;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiRendererMode;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.level.IServerKeyedClientLevel;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
|
||||
import com.seibel.distanthorizons.core.logging.SpamReducedLogger;
|
||||
@@ -45,21 +43,21 @@ import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import com.seibel.distanthorizons.core.render.renderer.TestRenderer;
|
||||
import com.seibel.distanthorizons.core.util.RenderUtil;
|
||||
import com.seibel.distanthorizons.core.world.AbstractDhWorld;
|
||||
import com.seibel.distanthorizons.core.world.DhClientServerWorld;
|
||||
import com.seibel.distanthorizons.core.world.DhClientWorld;
|
||||
import com.seibel.distanthorizons.core.world.IDhClientWorld;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -78,6 +76,8 @@ public class ClientApi
|
||||
public static final TestRenderer TEST_RENDERER = new TestRenderer();
|
||||
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||
private static final IKeyedClientLevelManager KEYED_CLIENT_LEVEL_MANAGER = SingletonInjector.INSTANCE.get(IKeyedClientLevelManager.class);
|
||||
|
||||
public static final long SPAM_LOGGER_FLUSH_NS = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS);
|
||||
|
||||
@@ -90,11 +90,10 @@ public class ClientApi
|
||||
|
||||
private long lastFlushNanoTime = 0;
|
||||
|
||||
private final ClientPluginChannelApi pluginChannelApi = new ClientPluginChannelApi(this::clientLevelLoadEvent, this::clientLevelUnloadEvent);
|
||||
private boolean isServerCommunicationEnabled = false;
|
||||
|
||||
// Delay loading the first level to give server some time to respond with level to actually load
|
||||
private Timer firstLevelLoadTimer;
|
||||
private static final long FIRST_LEVEL_LOAD_DELAY = 1000;
|
||||
/** set to true if any unexpected responses are received from the server */
|
||||
private boolean serverNetworkingIsMalformed = false;
|
||||
|
||||
/** Holds any levels that were loaded before the {@link ClientApi#onClientOnlyConnected} was fired. */
|
||||
public final HashSet<IClientLevelWrapper> waitingClientLevels = new HashSet<>();
|
||||
@@ -153,11 +152,8 @@ public class ClientApi
|
||||
|
||||
// firing after clientLevelLoadEvent
|
||||
// TODO if level has prepped to load it should fire level load event
|
||||
DhClientWorld world = new DhClientWorld();
|
||||
SharedApi.setDhWorld(world);
|
||||
SharedApi.setDhWorld(new DhClientWorld());
|
||||
|
||||
this.pluginChannelApi.onJoin(world.networkState.getSession());
|
||||
world.networkState.sendConfigMessage();
|
||||
|
||||
LOGGER.info("Loading [" + this.waitingClientLevels.size() + "] waiting client level wrappers.");
|
||||
for (IClientLevelWrapper level : this.waitingClientLevels)
|
||||
@@ -172,12 +168,6 @@ public class ClientApi
|
||||
/** Synchronized to prevent a rare issue where multiple disconnect events are triggered on top of each other. */
|
||||
public synchronized void onClientOnlyDisconnected()
|
||||
{
|
||||
if (this.firstLevelLoadTimer != null)
|
||||
{
|
||||
this.firstLevelLoadTimer.cancel();
|
||||
this.firstLevelLoadTimer = null;
|
||||
}
|
||||
|
||||
AbstractDhWorld world = SharedApi.getAbstractDhWorld();
|
||||
if (world != null)
|
||||
{
|
||||
@@ -187,7 +177,11 @@ public class ClientApi
|
||||
SharedApi.setDhWorld(null);
|
||||
}
|
||||
|
||||
this.pluginChannelApi.reset();
|
||||
// clear the previous server's information
|
||||
this.isServerCommunicationEnabled = false;
|
||||
this.serverNetworkingIsMalformed = false;
|
||||
KEYED_CLIENT_LEVEL_MANAGER.setUseOverrideWrapper(false);
|
||||
KEYED_CLIENT_LEVEL_MANAGER.setServerKeyedLevel(null);
|
||||
|
||||
// remove any waiting items
|
||||
this.waitingChunkByClientLevelAndPos.clear();
|
||||
@@ -200,21 +194,16 @@ public class ClientApi
|
||||
// level events //
|
||||
//==============//
|
||||
|
||||
public void clientLevelUnloadEvent(IClientLevelWrapper level)
|
||||
{
|
||||
this.clientLevelUnloadEvent(level, false);
|
||||
}
|
||||
|
||||
public void clientLevelUnloadEvent(IClientLevelWrapper level, boolean respawn)
|
||||
public void clientLevelUnloadEvent(@Nullable IClientLevelWrapper level)
|
||||
{
|
||||
try
|
||||
{
|
||||
LOGGER.info("Unloading client level [" + level + "]-["+level.getDimensionName()+"].");
|
||||
|
||||
if (level instanceof IServerKeyedClientLevel && !respawn)
|
||||
if (level == null)
|
||||
{
|
||||
this.pluginChannelApi.onClientLevelUnload();
|
||||
// can happen on certain multiverse servers
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Unloading client level [" + level + "]-["+level.getDimensionType().getDimensionName()+"].");
|
||||
|
||||
AbstractDhWorld world = SharedApi.getAbstractDhWorld();
|
||||
if (world != null)
|
||||
@@ -234,42 +223,30 @@ public class ClientApi
|
||||
}
|
||||
}
|
||||
|
||||
public void clientLevelLoadEvent(IClientLevelWrapper level)
|
||||
public void clientLevelLoadEvent(@Nullable IClientLevelWrapper level) { this.clientLevelLoadEvent(level, false); }
|
||||
public void multiverseClientLevelLoadEvent(@Nullable IClientLevelWrapper level) { this.clientLevelLoadEvent(level, true); }
|
||||
private void clientLevelLoadEvent(@Nullable IClientLevelWrapper level, boolean isServerCommunication)
|
||||
{
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
{
|
||||
if (this.firstLevelLoadTimer == null)
|
||||
{
|
||||
this.firstLevelLoadTimer = TimerUtil.CreateTimer("FirstLevelLoadTimer");
|
||||
this.firstLevelLoadTimer.schedule(new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
ClientApi.this.clientLevelLoadEvent(level);
|
||||
}
|
||||
}, FIRST_LEVEL_LOAD_DELAY);
|
||||
return;
|
||||
}
|
||||
this.firstLevelLoadTimer.cancel();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
LOGGER.info("Loading client level [" + level + "]-["+level.getDimensionName()+"].");
|
||||
if (this.isServerCommunicationEnabled && !isServerCommunication)
|
||||
{
|
||||
LOGGER.info("Server supports communication, deferring loading.");
|
||||
return;
|
||||
}
|
||||
if (level == null)
|
||||
{
|
||||
// can happen on certain multiverse servers
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
LOGGER.info("Loading " + (isServerCommunication ? "Multiverse" : "") + " client level [" + level + "]-["+level.getDimensionType().getDimensionName()+"].");
|
||||
|
||||
AbstractDhWorld world = SharedApi.getAbstractDhWorld();
|
||||
if (world != null)
|
||||
{
|
||||
if (!this.pluginChannelApi.allowLevelLoading(level))
|
||||
{
|
||||
LOGGER.info("Levels in this connection are managed by the server, skipping auto-load.");
|
||||
|
||||
// Instead of attempting to load themselves, send config and wait for level key.
|
||||
((DhClientWorld) world).networkState.sendConfigMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
world.getOrLoadLevel(level);
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelLoadEvent.class, new DhApiLevelLoadEvent.EventParam(level));
|
||||
|
||||
@@ -286,7 +263,6 @@ public class ClientApi
|
||||
LOGGER.error("Unexpected error in ClientApi.clientLevelLoadEvent(), error: "+e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadWaitingChunksForLevel(IClientLevelWrapper level)
|
||||
{
|
||||
HashSet<Pair<IClientLevelWrapper, DhChunkPos>> keysToRemove = new HashSet<>();
|
||||
@@ -380,14 +356,123 @@ public class ClientApi
|
||||
// networking //
|
||||
//============//
|
||||
|
||||
public void pluginMessageReceived(@NotNull NetworkMessage message)
|
||||
{
|
||||
Session session = this.pluginChannelApi.session;
|
||||
if (session != null)
|
||||
{
|
||||
session.tryHandleMessage(message);
|
||||
}
|
||||
}
|
||||
// /** @param byteBuf is Netty's {@link ByteBuffer} wrapper. */
|
||||
// public void serverMessageReceived(ByteBuf byteBuf)
|
||||
// {
|
||||
// if (!Config.Client.Advanced.Multiplayer.enableMultiverseNetworking.get())
|
||||
// {
|
||||
// // multiverse networking disabled, ignore anything sent from the server
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// // either value can be set to true to debug the received byte stream
|
||||
// boolean stopAndDisplayInputAsByteArray = false;
|
||||
// boolean stopAndDisplayInputAsString = false;
|
||||
// if (stopAndDisplayInputAsByteArray || stopAndDisplayInputAsString)
|
||||
// {
|
||||
// String messageString = "";
|
||||
// if (stopAndDisplayInputAsByteArray)
|
||||
// {
|
||||
// int byteCount = byteBuf.readableBytes();
|
||||
// byte[] arr = new byte[byteCount];
|
||||
// StringBuilder stringBuilder = new StringBuilder("Server message received: [");
|
||||
// for (int i = 0; i < byteCount; i++)
|
||||
// {
|
||||
// arr[i] = byteBuf.readByte();
|
||||
// stringBuilder.append(arr[i]);
|
||||
// }
|
||||
// stringBuilder.append("]");
|
||||
//
|
||||
// messageString = stringBuilder.toString();
|
||||
// }
|
||||
// else if (stopAndDisplayInputAsString)
|
||||
// {
|
||||
// messageString = byteBuf.toString(StandardCharsets.UTF_8);
|
||||
// }
|
||||
//
|
||||
// // this is logged as an error so it is easier to see in an Intellij log
|
||||
// LOGGER.error(messageString);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// // It is important to ensure malicious server input is ignored.
|
||||
// if (this.serverNetworkingIsMalformed)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // check that the incoming message is within the expected size
|
||||
// short commandLength = byteBuf.readShort();
|
||||
// if (commandLength < 1 || commandLength > 32)
|
||||
// {
|
||||
// LOGGER.error("Server command length ["+commandLength+"] outside the expected range of 1 to 32 (inclusive).");
|
||||
// ClientApi.INSTANCE.serverNetworkingIsMalformed = true;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // parse the command
|
||||
// String eventType;
|
||||
// try
|
||||
// {
|
||||
// eventType = byteBuf.readCharSequence(commandLength, StandardCharsets.UTF_8).toString();
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// LOGGER.error("Server sent un-parsable command. Error: "+e.getMessage());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// switch (eventType)
|
||||
// {
|
||||
// case "ServerCommsEnabled":
|
||||
// LOGGER.info("Server supports DH multiverse protocol.");
|
||||
// ClientApi.INSTANCE.isServerCommunicationEnabled = true;
|
||||
// KEYED_CLIENT_LEVEL_MANAGER.setUseOverrideWrapper(true);
|
||||
// MC.executeOnRenderThread(() ->
|
||||
// {
|
||||
// // Unload the current world, since it may be wrong.
|
||||
// // A followup WorldChanged event should be received from the server soon after this.
|
||||
// LOGGER.info("Unloading current client level so the server can define the correct multiverse level.");
|
||||
// this.clientLevelUnloadEvent((IClientLevelWrapper) MC.getWrappedClientWorld());
|
||||
// });
|
||||
// break;
|
||||
//
|
||||
// case "LevelChanged":
|
||||
// short levelKeyLength = byteBuf.readShort();
|
||||
// if (levelKeyLength < 1 || levelKeyLength > 128) // TODO 128 should be put into a constant somewhere
|
||||
// {
|
||||
// LOGGER.error("Server [LevelChanged] command length ["+commandLength+"] outside the expected range of 1 to 128 (inclusive).");
|
||||
// this.serverNetworkingIsMalformed = true;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// String levelKey = byteBuf.readCharSequence(levelKeyLength, StandardCharsets.UTF_8).toString();
|
||||
// if (!levelKey.matches("[a-zA-Z0-9_]+"))
|
||||
// {
|
||||
// LOGGER.error("Server sent invalid world key name, and is being ignored.");
|
||||
// this.isServerCommunicationEnabled = false;
|
||||
// this.serverNetworkingIsMalformed = true;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// LOGGER.info("Server level change event received, changing the level to ["+levelKey+"].");
|
||||
// MC.executeOnRenderThread(() -> {
|
||||
// if (MC.getWrappedClientWorld() != null)
|
||||
// {
|
||||
// this.clientLevelUnloadEvent((IClientLevelWrapper) MC.getWrappedClientWorld());
|
||||
// }
|
||||
// IServerKeyedClientLevel clientLevel = KEYED_CLIENT_LEVEL_MANAGER.getServerKeyedLevel(MC.getWrappedClientWorld(), levelKey);
|
||||
// KEYED_CLIENT_LEVEL_MANAGER.setServerKeyedLevel(clientLevel);
|
||||
// this.multiverseClientLevelLoadEvent(clientLevel);
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@@ -412,7 +497,7 @@ public class ClientApi
|
||||
{
|
||||
// logging //
|
||||
|
||||
this.sendQueuedChatMessages();
|
||||
this.sendChatMessagesNow();
|
||||
|
||||
IProfilerWrapper profiler = MC.getProfiler();
|
||||
profiler.pop(); // get out of "terrain"
|
||||
@@ -465,24 +550,10 @@ public class ClientApi
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IDhClientLevel level = (IDhClientLevel) dhClientWorld.getLevel(levelWrapper);
|
||||
if (level == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IDhClientLevel level = dhClientWorld.getOrLoadClientLevel(levelWrapper);
|
||||
|
||||
if (this.rendererDisabledBecauseOfExceptions)
|
||||
{
|
||||
// re-enable rendering if the user toggles DH rendering
|
||||
if (!Config.Client.quickEnableRendering.get())
|
||||
{
|
||||
LOGGER.info("DH Renderer re-enabled after exception. Some rendering issues may occur. Please reboot Minecraft if you see any rendering issues.");
|
||||
this.rendererDisabledBecauseOfExceptions = false;
|
||||
Config.Client.quickEnableRendering.set(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -533,9 +604,9 @@ public class ClientApi
|
||||
LOGGER.error("Unexpected Renderer error in render pass [" + renderPass + "]. Error: " + e.getMessage(), e);
|
||||
|
||||
MC.sendChatMessage("\u00A74\u00A7l\u00A7uERROR: Distant Horizons renderer has encountered an exception!");
|
||||
MC.sendChatMessage("\u00A74Renderer disabled to try preventing GL state corruption.");
|
||||
MC.sendChatMessage("\u00A74Toggle DH rendering via the config UI to re-activate DH rendering.");
|
||||
MC.sendChatMessage("\u00A74Error: " + e);
|
||||
MC.sendChatMessage("\u00A74Renderer is now disabled to prevent further issues.");
|
||||
MC.sendChatMessage("\u00A74Please restart your game to re-enable Distant Horizons' LOD rendering.");
|
||||
MC.sendChatMessage("\u00A74Exception detail: " + e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -589,7 +660,7 @@ public class ClientApi
|
||||
}
|
||||
}
|
||||
|
||||
private void sendQueuedChatMessages()
|
||||
private void sendChatMessagesNow()
|
||||
{
|
||||
// dev build
|
||||
if (ModInfo.IS_DEV_BUILD && !this.configOverrideReminderPrinted && MC.playerExists())
|
||||
@@ -597,12 +668,10 @@ public class ClientApi
|
||||
this.configOverrideReminderPrinted = true;
|
||||
|
||||
// remind the user that this is a development build
|
||||
String message =
|
||||
// green text
|
||||
"\u00A72" + "Distant Horizons: nightly/unstable build, version: [" + ModInfo.VERSION+"]." + "\u00A7r\n" +
|
||||
"Issues may occur with this version.\n" +
|
||||
"Here be dragons!\n";
|
||||
MC.sendChatMessage(message);
|
||||
MC.sendChatMessage("\u00A72" + "Distant Horizons: nightly/unstable build, version: [" + ModInfo.VERSION+"]." + "\u00A7r");
|
||||
MC.sendChatMessage("Issues may occur with this version.");
|
||||
MC.sendChatMessage("Here be dragons!");
|
||||
MC.sendChatMessage("");
|
||||
}
|
||||
|
||||
// memory
|
||||
@@ -617,13 +686,11 @@ public class ClientApi
|
||||
long maxMemoryInBytes = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemoryInBytes < minimumRecommendedMemoryInBytes)
|
||||
{
|
||||
String message =
|
||||
// orange text
|
||||
"\u00A76" + "Distant Horizons: Low memory detected." + "\u00A7r \n" +
|
||||
"Stuttering or low FPS may occur. \n" +
|
||||
"Please increase Minecraft's available memory to 4 gigabytes. \n" +
|
||||
"This warning can be disabled in DH's config under Advanced -> Logging. \n";
|
||||
MC.sendChatMessage(message);
|
||||
MC.sendChatMessage("\u00A76" + "Distant Horizons: Low memory detected." + "\u00A7r");
|
||||
MC.sendChatMessage("Stuttering or low FPS may occur.");
|
||||
MC.sendChatMessage("Please increase Minecraft's available memory to 4 gigabytes.");
|
||||
MC.sendChatMessage("This warning can be disabled in DH's config under Advanced -> Logging.");
|
||||
MC.sendChatMessage("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-116
@@ -1,116 +0,0 @@
|
||||
package com.seibel.distanthorizons.core.api.internal;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.level.IKeyedClientLevelManager;
|
||||
import com.seibel.distanthorizons.core.level.IServerKeyedClientLevel;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.network.event.internal.CloseEvent;
|
||||
import com.seibel.distanthorizons.core.network.messages.base.CurrentLevelKeyMessage;
|
||||
import com.seibel.distanthorizons.core.network.session.Session;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* This class is used to manage the level keys.
|
||||
*/
|
||||
public class ClientPluginChannelApi
|
||||
{
|
||||
private static final ConfigBasedLogger LOGGER = new ConfigBasedLogger(LogManager.getLogger(),
|
||||
() -> Config.Client.Advanced.Logging.logNetworkEvent.get());
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
private static final IKeyedClientLevelManager KEYED_CLIENT_LEVEL_MANAGER = SingletonInjector.INSTANCE.get(IKeyedClientLevelManager.class);
|
||||
|
||||
private final Consumer<IServerKeyedClientLevel> levelLoadHandler;
|
||||
private final Consumer<IClientLevelWrapper> levelUnloadHandler;
|
||||
|
||||
@Nullable
|
||||
public Session session;
|
||||
|
||||
|
||||
public boolean allowLevelLoading(IClientLevelWrapper level)
|
||||
{
|
||||
return (KEYED_CLIENT_LEVEL_MANAGER.isEnabled() && level instanceof IServerKeyedClientLevel)
|
||||
|| !KEYED_CLIENT_LEVEL_MANAGER.isEnabled();
|
||||
}
|
||||
|
||||
|
||||
public ClientPluginChannelApi(Consumer<IServerKeyedClientLevel> levelLoadHandler, Consumer<IClientLevelWrapper> levelUnloadHandler)
|
||||
{
|
||||
this.levelLoadHandler = levelLoadHandler;
|
||||
this.levelUnloadHandler = levelUnloadHandler;
|
||||
}
|
||||
|
||||
public void onJoin(@NonNull Session session)
|
||||
{
|
||||
Objects.requireNonNull(session);
|
||||
this.session = session;
|
||||
session.registerHandler(CurrentLevelKeyMessage.class, this::onCurrentLevelKeyMessage);
|
||||
session.registerHandler(CloseEvent.class, this::onClose);
|
||||
}
|
||||
|
||||
private void onCurrentLevelKeyMessage(CurrentLevelKeyMessage msg)
|
||||
{
|
||||
// prefix@namespace:path
|
||||
// 1-50 characters in total, all parts except namespace can be omitted
|
||||
if (!msg.levelKey.matches("^(?=.{1,50}$)([a-zA-Z0-9-_]+@)?[a-zA-Z0-9-_]+(:[a-zA-Z0-9-_]+)?$"))
|
||||
{
|
||||
throw new IllegalArgumentException("Server sent invalid level key.");
|
||||
}
|
||||
|
||||
LOGGER.info("Server level key received: " + msg.levelKey);
|
||||
|
||||
MC.executeOnRenderThread(() -> {
|
||||
IClientLevelWrapper clientLevel = MC.getWrappedClientLevel(true);
|
||||
IServerKeyedClientLevel existingKeyedClientLevel = KEYED_CLIENT_LEVEL_MANAGER.getServerKeyedLevel();
|
||||
|
||||
if (existingKeyedClientLevel != null)
|
||||
{
|
||||
if (!existingKeyedClientLevel.getServerLevelKey().equals(msg.levelKey))
|
||||
{
|
||||
LOGGER.info("Unloading previous level with key: " + existingKeyedClientLevel.getServerLevelKey());
|
||||
this.levelUnloadHandler.accept(existingKeyedClientLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("Level key matches the previous level key, ignoring the message.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("Unloading non-keyed level: " + clientLevel.getDimensionName());
|
||||
this.levelUnloadHandler.accept(clientLevel);
|
||||
}
|
||||
|
||||
if (existingKeyedClientLevel == null || !existingKeyedClientLevel.getServerLevelKey().equals(msg.levelKey))
|
||||
{
|
||||
LOGGER.info("Loading level with key: " + msg.levelKey);
|
||||
IServerKeyedClientLevel keyedLevel = KEYED_CLIENT_LEVEL_MANAGER.setServerKeyedLevel(clientLevel, msg.levelKey);
|
||||
this.levelLoadHandler.accept(keyedLevel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onClientLevelUnload()
|
||||
{
|
||||
KEYED_CLIENT_LEVEL_MANAGER.clearServerKeyedLevel();
|
||||
}
|
||||
|
||||
private void onClose(CloseEvent event)
|
||||
{
|
||||
this.reset();
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
this.session = null;
|
||||
KEYED_CLIENT_LEVEL_MANAGER.disable();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,9 +21,13 @@ package com.seibel.distanthorizons.core.api.internal;
|
||||
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiLevelLoadEvent;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiLevelUnloadEvent;
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.generation.DhLightingEngine;
|
||||
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.world.AbstractDhWorld;
|
||||
import com.seibel.distanthorizons.core.world.DhClientServerWorld;
|
||||
import com.seibel.distanthorizons.core.world.DhServerWorld;
|
||||
@@ -33,7 +37,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This holds the methods that should be called by the host mod loader (Fabric,
|
||||
@@ -151,7 +154,7 @@ public class ServerApi
|
||||
IDhServerWorld serverWorld = SharedApi.getIDhServerWorld();
|
||||
if (serverWorld instanceof DhServerWorld) // TODO add support for DhClientServerWorld's (lan worlds) as well
|
||||
{
|
||||
LOGGER.info("Creating state for player: " + player.getName());
|
||||
LOGGER.debug("Waiting for player to connect: " + player.getUUID());
|
||||
((DhServerWorld) serverWorld).addPlayer(player);
|
||||
}
|
||||
}
|
||||
@@ -160,27 +163,9 @@ public class ServerApi
|
||||
IDhServerWorld serverWorld = SharedApi.getIDhServerWorld();
|
||||
if (serverWorld instanceof DhServerWorld) // TODO add support for DhClientServerWorld's (lan worlds) as well
|
||||
{
|
||||
LOGGER.info("Destroying state for player: " + player.getName());
|
||||
LOGGER.debug("Removing player from connect wait list: " + player.getUUID());
|
||||
((DhServerWorld) serverWorld).removePlayer(player);
|
||||
}
|
||||
}
|
||||
public void serverPlayerLevelChangeEvent(IServerPlayerWrapper player, IServerLevelWrapper origin, IServerLevelWrapper dest)
|
||||
{
|
||||
IDhServerWorld serverWorld = SharedApi.getIDhServerWorld();
|
||||
if (serverWorld instanceof DhServerWorld) // TODO add support for DhClientServerWorld's (lan worlds) as well
|
||||
{
|
||||
LOGGER.info("Player changed level: " + player.getName());
|
||||
((DhServerWorld) serverWorld).changePlayerLevel(player, origin, dest);
|
||||
}
|
||||
}
|
||||
|
||||
public void pluginMessageReceived(IServerPlayerWrapper player, @NotNull NetworkMessage message)
|
||||
{
|
||||
IDhServerWorld serverWorld = SharedApi.getIDhServerWorld();
|
||||
if (serverWorld instanceof DhServerWorld) // TODO add support for DhClientServerWorld's (lan worlds) as well
|
||||
{
|
||||
((DhServerWorld) serverWorld).remotePlayerConnectionHandler.handlePluginMessage(player, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,11 +26,11 @@ import com.seibel.distanthorizons.core.generation.DhLightingEngine;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
||||
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
||||
import com.seibel.distanthorizons.core.sql.repo.AbstractDhRepo;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.TimerUtil;
|
||||
import com.seibel.distanthorizons.core.util.objects.Pair;
|
||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||
@@ -43,7 +43,9 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/** Contains code and variables used by both {@link ClientApi} and {@link ServerApi} */
|
||||
public class SharedApi
|
||||
@@ -60,7 +62,6 @@ public class SharedApi
|
||||
private static final Timer CHUNK_UPDATE_TIMER = TimerUtil.CreateTimer("ChunkUpdateTimer");
|
||||
|
||||
|
||||
|
||||
private static AbstractDhWorld currentWorld;
|
||||
private static int lastWorldGenTickDelta = 0;
|
||||
private static long lastOverloadedLogMessageMsTime = 0;
|
||||
@@ -84,7 +85,6 @@ public class SharedApi
|
||||
|
||||
public static void setDhWorld(AbstractDhWorld newWorld)
|
||||
{
|
||||
AbstractDhWorld prevWorld = currentWorld;
|
||||
currentWorld = newWorld;
|
||||
|
||||
// starting and stopping the DataRenderTransformer is necessary to prevent attempting to
|
||||
@@ -96,16 +96,12 @@ public class SharedApi
|
||||
else
|
||||
{
|
||||
ThreadPoolUtil.shutdownThreadPools();
|
||||
|
||||
if (prevWorld != null && prevWorld.environment != EWorldEnvironment.Server_Only)
|
||||
{
|
||||
DebugRenderer.clearRenderables();
|
||||
MC_RENDER.clearTargetFrameBuffer();
|
||||
// shouldn't be necessary, but if we missed closing one of the connections this should make sure they're all closed
|
||||
DebugRenderer.clearRenderables();
|
||||
MC_RENDER.clearTargetFrameBuffer();
|
||||
// shouldn't be necessary, but if we missed closing one of the connections this should make sure they're all closed
|
||||
AbstractDhRepo.closeAllConnections();
|
||||
// needs to be closed on world shutdown to clear out un-processed chunks
|
||||
UPDATING_CHUNK_POS_SET.clear();
|
||||
}
|
||||
UPDATING_CHUNK_POS_SET.clear();
|
||||
|
||||
// recommend that the garbage collector cleans up any objects from the old world and thread pools
|
||||
System.gc();
|
||||
@@ -143,13 +139,23 @@ public class SharedApi
|
||||
public static boolean isChunkAtBlockPosAlreadyUpdating(int blockPosX, int blockPosZ)
|
||||
{ return UPDATING_CHUNK_POS_SET.contains(new DhChunkPos(new DhBlockPos2D(blockPosX, blockPosZ))); }
|
||||
|
||||
public static boolean isChunkAtChunkPosAlreadyUpdating(int chunkPosX, int chunkPosZ)
|
||||
{ return UPDATING_CHUNK_POS_SET.contains(new DhChunkPos(chunkPosX, chunkPosZ)); }
|
||||
|
||||
|
||||
/** handles both block place and break events */
|
||||
public void chunkBlockChangedEvent(IChunkWrapper chunk, ILevelWrapper level) { this.applyChunkUpdate(chunk, level, true); }
|
||||
|
||||
public void chunkLoadEvent(IChunkWrapper chunk, ILevelWrapper level) { this.applyChunkUpdate(chunk, level, false); }
|
||||
public void chunkUnloadEvent(IChunkWrapper chunk, ILevelWrapper level)
|
||||
{
|
||||
// temporarily disabled since this was originally incorrectly designated as "chunkSaveEvent"
|
||||
// but didn't actually fire on chunk save
|
||||
// and generally this is unnecessary and drastically reduces LOD building performance
|
||||
// when traveling around the world
|
||||
if (false)
|
||||
{
|
||||
this.applyChunkUpdate(chunk, level, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void applyChunkUpdate(IChunkWrapper chunkWrapper, ILevelWrapper level, boolean updateNeighborChunks)
|
||||
{
|
||||
@@ -166,11 +172,10 @@ public class SharedApi
|
||||
AbstractDhWorld dhWorld = SharedApi.getAbstractDhWorld();
|
||||
if (dhWorld == null)
|
||||
{
|
||||
if (level instanceof IClientLevelWrapper)
|
||||
if (level instanceof IClientLevelWrapper clientLevel)
|
||||
{
|
||||
// If the client world isn't loaded yet, keep track of which chunks were loaded so we can use them later.
|
||||
// This may happen if the client world and client level load events happen out of order
|
||||
IClientLevelWrapper clientLevel = (IClientLevelWrapper) level;
|
||||
ClientApi.INSTANCE.waitingChunkByClientLevelAndPos.replace(new Pair<>(clientLevel, chunkWrapper.getChunkPos()), chunkWrapper);
|
||||
}
|
||||
|
||||
@@ -181,10 +186,9 @@ public class SharedApi
|
||||
IDhLevel dhLevel = dhWorld.getLevel(level);
|
||||
if (dhLevel == null)
|
||||
{
|
||||
if (level instanceof IClientLevelWrapper)
|
||||
if (level instanceof IClientLevelWrapper clientLevel)
|
||||
{
|
||||
// the client level isn't loaded yet
|
||||
IClientLevelWrapper clientLevel = (IClientLevelWrapper) level;
|
||||
ClientApi.INSTANCE.waitingChunkByClientLevelAndPos.replace(new Pair<>(clientLevel, chunkWrapper.getChunkPos()), chunkWrapper);
|
||||
}
|
||||
|
||||
@@ -259,7 +263,7 @@ public class SharedApi
|
||||
else
|
||||
{
|
||||
// neighboring chunk
|
||||
DhChunkPos neighbourPos = new DhChunkPos(chunkWrapper.getChunkPos().getX() + xOffset, chunkWrapper.getChunkPos().getZ() + zOffset);
|
||||
DhChunkPos neighbourPos = new DhChunkPos(chunkWrapper.getChunkPos().x + xOffset, chunkWrapper.getChunkPos().z + zOffset);
|
||||
IChunkWrapper neighbourChunk = dhLevel.getLevelWrapper().tryGetChunk(neighbourPos);
|
||||
if (neighbourChunk != null)
|
||||
{
|
||||
@@ -276,43 +280,36 @@ public class SharedApi
|
||||
}
|
||||
}
|
||||
}
|
||||
/** returning a {@link CompletableFuture} isn't necessary, but allows Intellij to properly show the full stack trace when debugging. */
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
private static CompletableFuture<Void> bakeChunkLightingAndSendToLevelAsync(IChunkWrapper chunkWrapper, @Nullable ArrayList<IChunkWrapper> neighbourChunkList, IDhLevel dhLevel)
|
||||
private static void bakeChunkLightingAndSendToLevelAsync(IChunkWrapper chunkWrapper, @Nullable ArrayList<IChunkWrapper> neighbourChunkList, IDhLevel dhLevel)
|
||||
{
|
||||
// lighting the chunk needs to be done on a separate thread to prevent lagging any of the event threads
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getChunkToLodBuilderExecutor();
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getLightPopulatorExecutor();
|
||||
if (executor == null)
|
||||
{
|
||||
return CompletableFuture.completedFuture(null);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return CompletableFuture.runAsync(() ->
|
||||
executor.execute(() ->
|
||||
{
|
||||
//LOGGER.trace(chunkWrapper.getChunkPos() + " " + executor.getActiveCount() + " / " + executor.getQueue().size() + " - " + executor.getCompletedTaskCount());
|
||||
|
||||
try
|
||||
{
|
||||
boolean checkChunkHash = !Config.Client.Advanced.LodBuilding.disableUnchangedChunkCheck.get();
|
||||
|
||||
// check if this chunk has been converted into an LOD already
|
||||
int oldChunkHash = dhLevel.getChunkHash(chunkWrapper.getChunkPos()); // shouldn't happen on the render thread since it may take a few moments to run
|
||||
int newChunkHash = chunkWrapper.getBlockBiomeHashCode();
|
||||
if (checkChunkHash)
|
||||
if (oldChunkHash == newChunkHash)
|
||||
{
|
||||
if (oldChunkHash == newChunkHash)
|
||||
{
|
||||
// if the chunk hashes are the same then we don't need to bother with lighting the chunk
|
||||
// or creating/updating the LODs
|
||||
//LOGGER.info("skipping: "+chunkWrapper.getChunkPos()+" "+newChunkHash);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//LOGGER.info("g: "+chunkWrapper.getChunkPos()+" "+newChunkHash);
|
||||
}
|
||||
// if the chunk hashes are the same then we don't need to bother with lighting the chunk
|
||||
// or creating/updating the LODs
|
||||
//LOGGER.info("skipping: "+chunkWrapper.getChunkPos()+" "+newChunkHash);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//LOGGER.info("g: "+chunkWrapper.getChunkPos()+" "+newChunkHash);
|
||||
}
|
||||
|
||||
|
||||
@@ -329,44 +326,36 @@ public class SharedApi
|
||||
}
|
||||
|
||||
|
||||
// chunk light baking is disabled since profiling revealed it used
|
||||
// roughly the same amount of time as generating the lighting ourselves and
|
||||
// was much more likely to have issues with corrupt (all black or all bright) chunks
|
||||
boolean tryUsingMcLightingEngine = false;
|
||||
if (tryUsingMcLightingEngine)
|
||||
// Save or populate the chunk wrapper's lighting
|
||||
// this is done so we don't have to worry about MC unloading the lighting data for this chunk
|
||||
boolean onlyUseDhLighting = Config.Client.Advanced.LodBuilding.onlyUseDhLightingEngine.get();
|
||||
if (!onlyUseDhLighting && chunkWrapper.isLightCorrect())
|
||||
{
|
||||
// Save or populate the chunk wrapper's lighting
|
||||
// this is done so we don't have to worry about MC unloading the lighting data for this chunk
|
||||
boolean chunkLightPopulated = false;
|
||||
boolean onlyUseDhLighting = Config.Client.Advanced.LodBuilding.onlyUseDhLightingEngine.get();
|
||||
if (!onlyUseDhLighting && chunkWrapper.isLightCorrect())
|
||||
try
|
||||
{
|
||||
// If MC's lighting engine isn't thread safe this may cause the server thread to lag
|
||||
chunkLightPopulated = chunkWrapper.bakeDhLightingUsingMcLightingEngine(dhLevel.getLevelWrapper());
|
||||
if (!chunkLightPopulated)
|
||||
{
|
||||
// clear any existing data to prevent partial or corrupt lighting
|
||||
// when re-generating it
|
||||
chunkWrapper.clearDhBlockLighting();
|
||||
chunkWrapper.clearDhSkyLighting();
|
||||
}
|
||||
chunkWrapper.bakeDhLightingUsingMcLightingEngine();
|
||||
}
|
||||
|
||||
// something went wrong during the baking process so we have to generate the lighting ourselves
|
||||
if (!chunkLightPopulated)
|
||||
catch (IllegalStateException e)
|
||||
{
|
||||
DhLightingEngine.INSTANCE.lightChunk(chunkWrapper, nearbyChunkList, dhLevel.hasSkyLight() ? LodUtil.MAX_MC_LIGHT : LodUtil.MIN_MC_LIGHT);
|
||||
LOGGER.warn("Chunk light baking error: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DhLightingEngine.INSTANCE.lightChunk(chunkWrapper, nearbyChunkList, dhLevel.hasSkyLight() ? LodUtil.MAX_MC_LIGHT : LodUtil.MIN_MC_LIGHT);
|
||||
// generate the chunk's lighting, using neighboring chunks if present
|
||||
DhLightingEngine.INSTANCE.lightChunk(chunkWrapper, nearbyChunkList, dhLevel.hasSkyLight() ? 15 : 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
dhLevel.updateBeaconBeamsForChunk(chunkWrapper, nearbyChunkList);
|
||||
dhLevel.updateChunkAsync(chunkWrapper, newChunkHash);
|
||||
// get this chunk's active beacons
|
||||
List<BeaconBeamDTO> beaconBeamList = chunkWrapper.getAllActiveBeacons(nearbyChunkList);
|
||||
dhLevel.setBeaconBeamsForChunk(chunkWrapper.getChunkPos(), beaconBeamList);
|
||||
|
||||
|
||||
dhLevel.updateChunkAsync(chunkWrapper);
|
||||
dhLevel.setChunkHash(chunkWrapper.getChunkPos(), newChunkHash);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -391,13 +380,9 @@ public class SharedApi
|
||||
UPDATING_CHUNK_POS_SET.remove(chunkWrapper.getChunkPos());
|
||||
}
|
||||
}
|
||||
}, executor);
|
||||
}
|
||||
catch (RejectedExecutionException ignore)
|
||||
{
|
||||
// the executor was shut down, it should be back up shortly and able to accept new jobs
|
||||
return CompletableFuture.completedFuture(null);
|
||||
});
|
||||
}
|
||||
catch (RejectedExecutionException ignore) { /* the executor was shut down, it should be back up shortly and able to accept new jobs */ }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package com.seibel.distanthorizons.core.config;
|
||||
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.seibel.distanthorizons.api.DhApi;
|
||||
import com.seibel.distanthorizons.api.enums.config.*;
|
||||
import com.seibel.distanthorizons.api.enums.config.quickOptions.*;
|
||||
@@ -44,7 +43,6 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
|
||||
/**
|
||||
@@ -56,6 +54,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
* Otherwise, you will have issues where only some of the config entries will exist when your listener is created.
|
||||
*
|
||||
* @author coolGi
|
||||
* @version 2023-7-16
|
||||
*/
|
||||
|
||||
public class Config
|
||||
@@ -108,8 +107,6 @@ public class Config
|
||||
|
||||
public static ConfigLinkedEntry quickEnableWorldGenerator = new ConfigLinkedEntry(Advanced.WorldGenerator.enableDistantGeneration);
|
||||
|
||||
public static ConfigLinkedEntry quickLodCloudRendering = new ConfigLinkedEntry(Advanced.Graphics.GenericRendering.enableCloudRendering);
|
||||
|
||||
public static ConfigEntry<Boolean> optionsButton = new ConfigEntry.Builder<Boolean>()
|
||||
.set(true)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_FILE)
|
||||
@@ -129,6 +126,7 @@ public class Config
|
||||
public static ConfigCategory multiplayer = new ConfigCategory.Builder().set(Multiplayer.class).build();
|
||||
public static ConfigCategory lodBuilding = new ConfigCategory.Builder().set(LodBuilding.class).build();
|
||||
public static ConfigCategory multiThreading = new ConfigCategory.Builder().set(MultiThreading.class).build();
|
||||
public static ConfigCategory buffers = new ConfigCategory.Builder().set(GpuBuffers.class).build();
|
||||
public static ConfigCategory autoUpdater = new ConfigCategory.Builder().set(AutoUpdater.class).build();
|
||||
|
||||
public static ConfigCategory logging = new ConfigCategory.Builder().set(Logging.class).build();
|
||||
@@ -165,17 +163,8 @@ public class Config
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Integer> lodChunkRenderDistanceRadius = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("renderDistanceRadius")
|
||||
.setMinDefaultMax(32, 128, 4096)
|
||||
.comment("" +
|
||||
"The radius of the mod's render distance. (measured in chunks)\n" +
|
||||
"On server changes the distance players will receive real-time updates for, if enabled." +
|
||||
"\n" +
|
||||
"Note for servers:\n" +
|
||||
"This setting does not prevent players from generating farther out.\n" +
|
||||
"If you want to limit performance impact, change rate limits\n" +
|
||||
"and thread count/runtime ratio settings instead.\n" +
|
||||
"It also does not affect the visuals on clients.")
|
||||
.comment("The radius of the mod's render distance. (measured in chunks)")
|
||||
.setPerformance(EConfigEntryPerformance.HIGH)
|
||||
.build();
|
||||
|
||||
@@ -190,7 +179,6 @@ public class Config
|
||||
+ "Lowest Quality: " + EDhApiVerticalQuality.HEIGHT_MAP + "\n"
|
||||
+ "Highest Quality: " + EDhApiVerticalQuality.EXTREME)
|
||||
.setPerformance(EConfigEntryPerformance.VERY_HIGH)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiHorizontalQuality> horizontalQuality = new ConfigEntry.Builder<EDhApiHorizontalQuality>()
|
||||
@@ -212,7 +200,6 @@ public class Config
|
||||
+ EDhApiTransparency.DISABLED + ": LODs will be opaque. \n"
|
||||
+ "")
|
||||
.setPerformance(EConfigEntryPerformance.MEDIUM)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiBlocksToAvoid> blocksToIgnore = new ConfigEntry.Builder<EDhApiBlocksToAvoid>()
|
||||
@@ -224,7 +211,6 @@ public class Config
|
||||
+ EDhApiBlocksToAvoid.NON_COLLIDING + ": Only represent solid blocks in the LODs (tall grass, torches, etc. won't count for a LOD's height) \n"
|
||||
+ "")
|
||||
.setPerformance(EConfigEntryPerformance.NONE)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Boolean> tintWithAvoidedBlocks = new ConfigEntry.Builder<Boolean>()
|
||||
@@ -236,7 +222,6 @@ public class Config
|
||||
+ "False: skipped blocks will not change color of surface below them. "
|
||||
+ "")
|
||||
.setPerformance(EConfigEntryPerformance.NONE)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
// TODO fixme
|
||||
@@ -602,7 +587,6 @@ public class Config
|
||||
+ "0 = black \n"
|
||||
+ "1 = normal \n"
|
||||
+ "2 = near white")
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Double> saturationMultiplier = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI doesnt support floats)
|
||||
@@ -613,7 +597,6 @@ public class Config
|
||||
+ "0 = black and white \n"
|
||||
+ "1 = normal \n"
|
||||
+ "2 = very saturated")
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Boolean> enableCaveCulling = new ConfigEntry.Builder<Boolean>()
|
||||
@@ -628,15 +611,14 @@ public class Config
|
||||
+ "Additional Info: Currently this cull all faces \n"
|
||||
+ " with skylight value of 0 in dimensions that \n"
|
||||
+ " does not have a ceiling.")
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
@Deprecated
|
||||
public static ConfigEntry<Integer> caveCullingHeight = new ConfigEntry.Builder<Integer>()
|
||||
.setMinDefaultMax(-4096, 60, 4096)
|
||||
.setMinDefaultMax(-4096, 40, 4096)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_API)
|
||||
.comment(""
|
||||
+ "At what Y value should cave culling start? \n"
|
||||
+ "Lower this value if you get walls for areas with 0 light.")
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
+ "At what Y value should cave culling start?")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Integer> earthCurveRatio = new ConfigEntry.Builder<Integer>()
|
||||
@@ -674,7 +656,6 @@ public class Config
|
||||
+ EDhApiLodShading.DISABLED + ": All LOD sides will be rendered with the same brightness. \n"
|
||||
+ "")
|
||||
.setPerformance(EConfigEntryPerformance.NONE)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Boolean> disableFrustumCulling = new ConfigEntry.Builder<Boolean>()
|
||||
@@ -709,18 +690,6 @@ public class Config
|
||||
+ EDhApiGrassSideRendering.AS_DIRT + ": sides render entirely as dirt. \n"
|
||||
+ "")
|
||||
.setPerformance(EConfigEntryPerformance.NONE)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Boolean> disableBeaconDistanceCulling = new ConfigEntry.Builder<Boolean>()
|
||||
.set(false)
|
||||
.comment(""
|
||||
+ "If true all beacons near the camera won't be drawn to prevent vanilla overdraw. \n"
|
||||
+ "If false all beacons will be rendered. \n"
|
||||
+ "\n"
|
||||
+ "Generally this should be left as false. It's main purpose is for debugging\n"
|
||||
+ "beacon updating/rendering.\n"
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
}
|
||||
@@ -730,15 +699,16 @@ public class Config
|
||||
public static class WorldGenerator
|
||||
{
|
||||
public static ConfigEntry<Boolean> enableDistantGeneration = new ConfigEntry.Builder<Boolean>()
|
||||
.setServersideShortName("enableDistantGeneration")
|
||||
.set(true)
|
||||
.comment(""
|
||||
+ " Should Distant Horizons slowly generate LODs \n"
|
||||
+ " outside the vanilla render distance?")
|
||||
+ " outside the vanilla render distance?\n"
|
||||
+ "\n"
|
||||
+ " Note: when on a server, distant generation isn't supported \n"
|
||||
+ " and will always be disabled.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiDistantGeneratorMode> distantGeneratorMode = new ConfigEntry.Builder<EDhApiDistantGeneratorMode>()
|
||||
.setServersideShortName("distantGeneratorMode")
|
||||
.set(EDhApiDistantGeneratorMode.FEATURES)
|
||||
.comment(""
|
||||
+ "How detailed should LODs be generated outside the vanilla render distance? \n"
|
||||
@@ -780,7 +750,6 @@ public class Config
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Integer> worldGenerationTimeoutLengthInSeconds = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("worldGenerationTimeout")
|
||||
.setMinDefaultMax(5, 60 * 3, 60 * 10/*10 minutes*/ )
|
||||
.comment(""
|
||||
+ "How long should a world generator thread run for before timing out? \n"
|
||||
@@ -794,7 +763,6 @@ public class Config
|
||||
public static class LodBuilding
|
||||
{
|
||||
public static ConfigEntry<Integer> minTimeBetweenChunkUpdatesInSeconds = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("minTimeBetweenChunkUpdates")
|
||||
.setMinDefaultMax(0, 1, 60)
|
||||
.comment(""
|
||||
+ "Determines how long must pass between LOD chunk updates before another. \n"
|
||||
@@ -805,23 +773,8 @@ public class Config
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Boolean> disableUnchangedChunkCheck = new ConfigEntry.Builder<Boolean>()
|
||||
.set(false)
|
||||
.comment(""
|
||||
+ "Normally DH will attempt to skip creating LODs for chunks it's already seen\n"
|
||||
+ "and that haven't changed.\n"
|
||||
+ "\n"
|
||||
+ "However sometimes that logic incorrecly prevents LODs from being updated.\n"
|
||||
+ "Disabling this check may fix issues where LODs aren't updated after\n"
|
||||
+ "blocks have been changed.\n"
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
/** Currently we always use the DH lighting engine because there's a high likelyhood of MC returning incorrect lighting otherwise */
|
||||
@Deprecated
|
||||
public static ConfigEntry<Boolean> onlyUseDhLightingEngine = new ConfigEntry.Builder<Boolean>()
|
||||
.set(false)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_API)
|
||||
.comment(""
|
||||
+ "If false LODs will be lit by Minecraft's lighting engine when possible \n"
|
||||
+ "and fall back to the DH lighting engine only when necessary. \n"
|
||||
@@ -856,7 +809,7 @@ public class Config
|
||||
+ "unaffected until it needs to be re-written to the database.\n"
|
||||
+ "\n"
|
||||
+ EDhApiDataCompressionMode.UNCOMPRESSED + " \n"
|
||||
+ "Should only be used for testing, is worse in every way vs [" + EDhApiDataCompressionMode.LZ4 + "].\n"
|
||||
+ "Should only be used for testing, is worse in every way vs ["+EDhApiDataCompressionMode.LZ4+"].\n"
|
||||
+ "Expected Compression Ratio: 1.0\n"
|
||||
+ "Estimated average DTO read speed: 1.64 milliseconds\n"
|
||||
+ "Estimated average DTO write speed: 12.44 milliseconds\n"
|
||||
@@ -914,7 +867,7 @@ public class Config
|
||||
|
||||
static
|
||||
{
|
||||
ignoredRenderBlockCsv.addListener(new ConfigChangeListener<String>(Config.Client.Advanced.LodBuilding.ignoredRenderBlockCsv,
|
||||
ignoredRenderBlockCsv.addListener(new ConfigChangeListener<>(Config.Client.Advanced.LodBuilding.ignoredRenderBlockCsv,
|
||||
(blockCsv) ->
|
||||
{
|
||||
IWrapperFactory wrapperFactory = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
||||
@@ -925,7 +878,7 @@ public class Config
|
||||
}
|
||||
}));
|
||||
|
||||
ignoredRenderCaveBlockCsv.addListener(new ConfigChangeListener<String>(Config.Client.Advanced.LodBuilding.ignoredRenderCaveBlockCsv,
|
||||
ignoredRenderCaveBlockCsv.addListener(new ConfigChangeListener<>(Config.Client.Advanced.LodBuilding.ignoredRenderCaveBlockCsv,
|
||||
(blockCsv) ->
|
||||
{
|
||||
IWrapperFactory wrapperFactory = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
||||
@@ -978,7 +931,7 @@ public class Config
|
||||
.build();
|
||||
|
||||
// not currently implemented
|
||||
public static ConfigEntry<Boolean> enableMultiverseNetworking = new ConfigEntry.Builder<Boolean>()
|
||||
private static ConfigEntry<Boolean> enableMultiverseNetworking = new ConfigEntry.Builder<Boolean>()
|
||||
.set(true)
|
||||
.comment(""
|
||||
+ "If true Distant Horizons will attempt to communicate with the connected \n"
|
||||
@@ -986,137 +939,59 @@ public class Config
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
public static ConfigCategory serverNetworking = new ConfigCategory.Builder().set(ServerNetworking.class).build();
|
||||
|
||||
public static class ServerNetworking
|
||||
{
|
||||
public static ConfigUIComment generalSectionNote = new ConfigUIComment();
|
||||
public static ConfigEntry<Boolean> enableServerNetworking = new ConfigEntry.Builder<Boolean>()
|
||||
.setServersideShortName("enableServerNetworking")
|
||||
.set(true)
|
||||
.comment(""
|
||||
+ "WARNING!\n"
|
||||
+ "Server-client networking is not yet fully implemented!\n"
|
||||
+ "Both the server and client must be running the server-side fork with this option enabled\n"
|
||||
+ "for Distant Horizons data to be transceived.\n"
|
||||
+ "\n"
|
||||
+ "If true, the server and client will attempt to communicate to transceive Distant Horizons data.\n"
|
||||
+ "This allows for further distant generation and LOD updates on all clients.\n"
|
||||
+ "\n"
|
||||
+ "This should only be used on trusted servers with trusted players!\n"
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
public static ConfigEntry<Boolean> sendLevelKeys = new ConfigEntry.Builder<Boolean>()
|
||||
.setServersideShortName("sendLevelKeys")
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_FILE)
|
||||
.set(true)
|
||||
.comment(""
|
||||
+ "Makes the server send level keys for each world.\n"
|
||||
+ "Disable this if you use alternative ways to send level keys.\n"
|
||||
+ "")
|
||||
.build();
|
||||
public static ConfigEntry<String> levelKeyPrefix = new ConfigEntry.Builder<String>()
|
||||
.setServersideShortName("levelKeyPrefix")
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_FILE)
|
||||
.set(
|
||||
Suppliers.compose(wrapper -> !wrapper.isDedicatedServer() || wrapper.isWorldInitialized(), () -> SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class)).get()
|
||||
? ""
|
||||
: "server" + ThreadLocalRandom.current().nextInt(1, 1000)
|
||||
)
|
||||
.comment(""
|
||||
+ "Prefix of the level keys sent to the clients.\n"
|
||||
+ "Should be set to a unique value for each backend server behind a proxy,\n"
|
||||
+ "or empty if you don't use a proxy.\n"
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
|
||||
public static ConfigUIComment generationSectionNote = new ConfigUIComment();
|
||||
public static ConfigEntry<Integer> generationRequestRateLimit = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("generationRequestRateLimit")
|
||||
.setMinDefaultMax(1, 20, 100)
|
||||
.comment(""
|
||||
+ "How many LOD generation requests per second should a client send? \n"
|
||||
+ "Also limits the amount of player's requests allowed to stay in the server's queue."
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
|
||||
public static ConfigUIComment realTimeUpdatesSectionNote = new ConfigUIComment();
|
||||
public static ConfigEntry<Boolean> enableRealTimeUpdates = new ConfigEntry.Builder<Boolean>()
|
||||
.setServersideShortName("enableRealTimeUpdates")
|
||||
.set(false)
|
||||
.comment(""
|
||||
+ "If true, the client will receive real-time LOD updates for chunks outside the client's render distance."
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
|
||||
public static ConfigUIComment syncOnLoginSectionNote = new ConfigUIComment();
|
||||
public static ConfigEntry<Boolean> synchronizeOnLogin = new ConfigEntry.Builder<Boolean>()
|
||||
.setServersideShortName("synchronizeOnLogin")
|
||||
.set(false)
|
||||
.comment(""
|
||||
+ "If true, clients will receive updated LODs on join if any changes occurred since last join."
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Integer> syncOnLoginRateLimit = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("syncOnLoginRateLimit")
|
||||
.setMinDefaultMax(1, 50, 100)
|
||||
.comment(""
|
||||
+ "How many LOD sync requests per second should a client send? \n"
|
||||
+ "Also limits the amount of player's requests allowed to stay in the server's queue."
|
||||
+ "")
|
||||
.build();
|
||||
}
|
||||
// not currently implemented
|
||||
private static ConfigEntry<Boolean> enableServerNetworking = new ConfigEntry.Builder<Boolean>()
|
||||
.set(false)
|
||||
.comment(""
|
||||
+ "Attention: this is only for developers and hasn't been implemented.\n"
|
||||
+ "\n"
|
||||
+ "If true Distant Horizons will attempt to communicate with the connected \n"
|
||||
+ "server in order to load LODs outside your vanilla render distance. \n"
|
||||
+ "\n"
|
||||
+ "Note: This requires DH to be installed on the server in order to function. \n"
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public static class MultiThreading
|
||||
{
|
||||
public static final String THREAD_NOTE = ""
|
||||
+ "Multi-threading Note:\n"
|
||||
+ "If the total thread count in Distant Horizon's config is more threads than your CPU has cores,\n"
|
||||
+ "CPU performance may suffer if Distant Horizons has a lot to load or generate.\n"
|
||||
+ "Multi-threading Note: \n"
|
||||
+ "If the total thread count in Distant Horizon's config is more threads than your CPU has cores, \n"
|
||||
+ "CPU performance may suffer if Distant Horizons has a lot to load or generate. \n"
|
||||
+ "This can be an issue when first loading into a world, when flying, and/or when generating new terrain.";
|
||||
|
||||
public static final String THREAD_RUN_TIME_RATIO_NOTE = ""
|
||||
+ "If this value is less than 1.0, it will be treated as a percentage\n"
|
||||
+ "of time each thread can run before going idle.\n"
|
||||
+ "If this value is less than 1.0, it will be treated as a percentage \n"
|
||||
+ "of time each thread can run before going idle. \n"
|
||||
+ "\n"
|
||||
+ "This can be used to reduce CPU usage if the thread count\n"
|
||||
+ "is already set to 1 for the given option, or more finely\n"
|
||||
+ "This can be used to reduce CPU usage if the thread count \n"
|
||||
+ "is already set to 1 for the given option, or more finely \n"
|
||||
+ "tune CPU performance.";
|
||||
|
||||
|
||||
public static final ConfigEntry<Integer> numberOfWorldGenerationThreads = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("numberOfWorldGenerationThreads")
|
||||
.setMinDefaultMax(1,
|
||||
ThreadPresetConfigEventHandler.getWorldGenDefaultThreadCount(),
|
||||
Runtime.getRuntime().availableProcessors())
|
||||
.comment(""
|
||||
+ "How many threads should be used when generating LOD\n"
|
||||
+ "chunks outside the normal render distance?\n"
|
||||
+ "How many threads should be used when generating LOD \n"
|
||||
+ "chunks outside the normal render distance? \n"
|
||||
+ "\n"
|
||||
+ "If you experience stuttering when generating distant LODs,\n"
|
||||
+ "decrease this number.\n"
|
||||
+ "If you want to increase LOD\n"
|
||||
+ "generation speed, increase this number.\n"
|
||||
+ "If you experience stuttering when generating distant LODs, \n"
|
||||
+ "decrease this number. \n"
|
||||
+ "If you want to increase LOD \n"
|
||||
+ "generation speed, increase this number. \n"
|
||||
+ "\n"
|
||||
+ THREAD_NOTE)
|
||||
.build();
|
||||
public static final ConfigEntry<Double> runTimeRatioForWorldGenerationThreads = new ConfigEntry.Builder<Double>()
|
||||
.setServersideShortName("runTimeRatioForWorldGenerationThreads")
|
||||
.setMinDefaultMax(0.01, ThreadPresetConfigEventHandler.getWorldGenDefaultRunTimeRatio(), 1.0)
|
||||
.comment(THREAD_RUN_TIME_RATIO_NOTE)
|
||||
.build();
|
||||
|
||||
public static final ConfigEntry<Integer> numberOfFileHandlerThreads = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("numberOfFileHandlerThreads")
|
||||
.setMinDefaultMax(1,
|
||||
ThreadPresetConfigEventHandler.getFileHandlerDefaultThreadCount(),
|
||||
Runtime.getRuntime().availableProcessors())
|
||||
@@ -1130,7 +1005,6 @@ public class Config
|
||||
+ THREAD_NOTE)
|
||||
.build();
|
||||
public static final ConfigEntry<Double> runTimeRatioForFileHandlerThreads = new ConfigEntry.Builder<Double>()
|
||||
.setServersideShortName("runTimeRatioForFileHandlerThreads")
|
||||
.setMinDefaultMax(0.01, ThreadPresetConfigEventHandler.getFileHandlerDefaultRunTimeRatio(), 1.0)
|
||||
.comment(THREAD_RUN_TIME_RATIO_NOTE)
|
||||
.build();
|
||||
@@ -1161,7 +1035,6 @@ public class Config
|
||||
.build();
|
||||
|
||||
public static final ConfigEntry<Integer> numberOfLodBuilderThreads = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("numberOfLodBuilderThreads")
|
||||
.setMinDefaultMax(1,
|
||||
ThreadPresetConfigEventHandler.getLodBuilderDefaultThreadCount(),
|
||||
Runtime.getRuntime().availableProcessors())
|
||||
@@ -1174,12 +1047,10 @@ public class Config
|
||||
+ THREAD_NOTE)
|
||||
.build();
|
||||
public static final ConfigEntry<Double> runTimeRatioForLodBuilderThreads = new ConfigEntry.Builder<Double>()
|
||||
.setServersideShortName("runTimeRatioForLodBuilderThreads")
|
||||
.setMinDefaultMax(0.01, ThreadPresetConfigEventHandler.getLodBuilderDefaultRunTimeRatio(), 1.0)
|
||||
.comment(THREAD_RUN_TIME_RATIO_NOTE)
|
||||
.build();
|
||||
public static final ConfigEntry<Boolean> enableLodBuilderThreadLimiting = new ConfigEntry.Builder<Boolean>()
|
||||
.setServersideShortName("enableLodBuilderThreadLimiting")
|
||||
.set(true)
|
||||
.comment(""
|
||||
+ "Should only be disabled if deadlock occurs and LODs refuse to update. \n"
|
||||
@@ -1189,24 +1060,53 @@ public class Config
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
public static final ConfigEntry<Integer> numberOfNetworkCompressionThreads = new ConfigEntry.Builder<Integer>()
|
||||
.setServersideShortName("numberOfNetworkCompressionThreads")
|
||||
.setMinDefaultMax(1,
|
||||
ThreadPresetConfigEventHandler.getNetworkCompressionDefaultThreadCount(),
|
||||
Runtime.getRuntime().availableProcessors())
|
||||
}
|
||||
|
||||
public static class GpuBuffers
|
||||
{
|
||||
public static ConfigEntry<EDhApiGpuUploadMethod> gpuUploadMethod = new ConfigEntry.Builder<EDhApiGpuUploadMethod>()
|
||||
.set(EDhApiGpuUploadMethod.AUTO)
|
||||
.comment(""
|
||||
+ "How many threads should be used when building LODs? \n"
|
||||
+ "What method should be used to upload geometry to the GPU? \n"
|
||||
+ "\n"
|
||||
+ "These threads run when terrain is generated, when\n"
|
||||
+ "certain graphics settings are changed, and when moving around the world. \n"
|
||||
+ EDhApiGpuUploadMethod.AUTO + ": Picks the best option based on the GPU you have. \n"
|
||||
+ "\n"
|
||||
+ THREAD_NOTE)
|
||||
+ EDhApiGpuUploadMethod.BUFFER_STORAGE + ": Default if OpenGL 4.5 is supported. \n"
|
||||
+ " Fast rendering, no stuttering. \n"
|
||||
+ "\n"
|
||||
+ EDhApiGpuUploadMethod.SUB_DATA + ": Backup option for NVIDIA. \n"
|
||||
+ " Fast rendering but may stutter when uploading. \n"
|
||||
+ "\n"
|
||||
+ EDhApiGpuUploadMethod.BUFFER_MAPPING + ": Slow rendering but won't stutter when uploading. \n"
|
||||
+ " Generally the best option for integrated GPUs. \n"
|
||||
+ " Default option for AMD/Intel if OpenGL 4.5 isn't supported. \n"
|
||||
+ " May end up storing buffers in System memory. \n"
|
||||
+ " Fast rendering if in GPU memory, slow if in system memory, \n"
|
||||
+ " but won't stutter when uploading. \n"
|
||||
+ "\n"
|
||||
+ EDhApiGpuUploadMethod.DATA + ": Fast rendering but will stutter when uploading. \n"
|
||||
+ " Backup option for AMD/Intel. \n"
|
||||
+ " Fast rendering but may stutter when uploading. \n"
|
||||
+ "\n"
|
||||
+ "If you don't see any difference when changing these settings, \n"
|
||||
+ "or the world looks corrupted: restart your game."
|
||||
+ "")
|
||||
.build();
|
||||
public static final ConfigEntry<Double> runTimeRatioForNetworkCompressionThreads = new ConfigEntry.Builder<Double>()
|
||||
.setServersideShortName("runTimeRatioForNetworkCompressionThreads")
|
||||
.setMinDefaultMax(0.01, ThreadPresetConfigEventHandler.getNetworkCompressionDefaultRunTimeRatio(), 1.0)
|
||||
.comment(THREAD_RUN_TIME_RATIO_NOTE)
|
||||
|
||||
public static ConfigEntry<Integer> gpuUploadPerMegabyteInMilliseconds = new ConfigEntry.Builder<Integer>()
|
||||
.setMinDefaultMax(0, 0, 50)
|
||||
.comment(""
|
||||
+ "How long should a buffer wait per Megabyte of data uploaded? \n"
|
||||
+ "Helpful resource for frame times: https://fpstoms.com \n"
|
||||
+ "\n"
|
||||
+ "Longer times may reduce stuttering but will make LODs \n"
|
||||
+ "transition and load slower. Change this to [0] for no timeout. \n"
|
||||
+ "\n"
|
||||
+ "NOTE:\n"
|
||||
+ "Before changing this config, try changing the \"GPU Upload method\" first. \n"
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public static class AutoUpdater
|
||||
@@ -1240,70 +1140,63 @@ public class Config
|
||||
// TODO add change all option
|
||||
// TODO default to error chat and info file
|
||||
public static ConfigEntry<EDhApiLoggerMode> logWorldGenEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.setServersideShortName("logWorldGenEvent")
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log information about the world generation process. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiLoggerMode> logWorldGenPerformance = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.setServersideShortName("logWorldGenPerformance")
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log performance about the world generation process. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiLoggerMode> logWorldGenLoadEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.setServersideShortName("logWorldGenPerformance")
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log information about the world generation process. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiLoggerMode> logLodBuilderEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.setServersideShortName("logLodBuilderEvent")
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log information about the LOD generation process. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiLoggerMode> logRendererBufferEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log information about the renderer buffer process. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiLoggerMode> logRendererGLEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log information about the renderer OpenGL process. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiLoggerMode> logFileReadWriteEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.setServersideShortName("logFileReadWriteEvent")
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log information about file read/write operations. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiLoggerMode> logFileSubDimEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.setServersideShortName("logFileSubDimEvent")
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log information about file sub-dimension operations. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<EDhApiLoggerMode> logNetworkEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||
.setServersideShortName("logNetworkEvent")
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
||||
.comment(""
|
||||
+ "If enabled, the mod will log information about network operations. \n"
|
||||
+ "This can be useful for debugging.")
|
||||
@@ -1324,13 +1217,6 @@ public class Config
|
||||
+ "giving some basic information about how DH will function.")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Boolean> showModCompatibilityWarningsOnStartup = new ConfigEntry.Builder<Boolean>()
|
||||
.set(true)
|
||||
.comment(""
|
||||
+ "If enabled, a chat message will be displayed when a potentially problematic \n"
|
||||
+ "mod is installed alongside DH.")
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public static class Debugging
|
||||
@@ -1417,38 +1303,22 @@ public class Config
|
||||
public static ConfigEntry<Boolean> columnBuilderDebugEnable = new ConfigEntry.Builder<Boolean>()
|
||||
.set(false)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.addListener(DebugColumnConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
public static ConfigEntry<Integer> columnBuilderDebugDetailLevel = new ConfigEntry.Builder<Integer>()
|
||||
.set((int) DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.addListener(DebugColumnConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
public static ConfigEntry<Integer> columnBuilderDebugXPos = new ConfigEntry.Builder<Integer>()
|
||||
.set(0)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.addListener(DebugColumnConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
public static ConfigEntry<Integer> columnBuilderDebugZPos = new ConfigEntry.Builder<Integer>()
|
||||
.set(0)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Integer> columnBuilderDebugXRow = new ConfigEntry.Builder<Integer>()
|
||||
.set(-1)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
public static ConfigEntry<Integer> columnBuilderDebugZRow = new ConfigEntry.Builder<Integer>()
|
||||
.set(-1)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
public static ConfigEntry<Integer> columnBuilderDebugColumnIndex = new ConfigEntry.Builder<Integer>()
|
||||
.set(-1)
|
||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||
.addListener(DebugColumnConfigEventHandler.INSTANCE)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -1554,8 +1424,8 @@ public class Config
|
||||
"Can be changed if you experience crashing when loading into a world.\n" +
|
||||
"\n" +
|
||||
"Defines the OpenGL context type Distant Horizon's will create. \n" +
|
||||
"Generally this should be left as [" + EDhApiGlProfileMode.CORE + "] unless there is an issue with your GPU driver. \n" +
|
||||
"Possible values: [" + StringUtil.join("],[", EDhApiGlProfileMode.values()) + "] \n" +
|
||||
"Generally this should be left as ["+ EDhApiGlProfileMode.CORE+"] unless there is an issue with your GPU driver. \n" +
|
||||
"Possible values: ["+ StringUtil.join("],[", EDhApiGlProfileMode.values())+"] \n" +
|
||||
"")
|
||||
.build();
|
||||
public static ConfigEntry<Boolean> enableGlForwardCompatibilityMode = new ConfigEntry.Builder<Boolean>()
|
||||
@@ -1627,27 +1497,25 @@ public class Config
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<List<String>> listTest = new ConfigEntry.Builder<List<String>>()
|
||||
.set(new ArrayList<String>(Arrays.asList("option 1", "option 2", "option 3")))
|
||||
.set(new ArrayList<>(Arrays.asList("option 1", "option 2", "option 3")))
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Map<String, String>> mapTest = new ConfigEntry.Builder<Map<String, String>>()
|
||||
.set(new HashMap<String, String>())
|
||||
.set(new HashMap<>())
|
||||
.build();
|
||||
|
||||
public static ConfigUIButton uiButtonTest = new ConfigUIButton(() ->
|
||||
{
|
||||
new Thread(() ->
|
||||
{
|
||||
if (!GraphicsEnvironment.isHeadless())
|
||||
new Thread(() ->
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("button pressed!");
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("button pressed!");
|
||||
}
|
||||
}));
|
||||
|
||||
public static ConfigCategory categoryTest = new ConfigCategory.Builder().set(CategoryTest.class).build();
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class ConfigBase
|
||||
* <br> Map<String, T>
|
||||
* <br> HashMap<String, T>
|
||||
*/
|
||||
public static final List<Class<?>> acceptableInputs = new ArrayList<Class<?>>()
|
||||
public static final List<Class<?>> acceptableInputs = new ArrayList<>()
|
||||
{{
|
||||
add(Boolean.class);
|
||||
add(Byte.class);
|
||||
@@ -149,7 +149,7 @@ public class ConfigBase
|
||||
LOGGER.warn(exception);
|
||||
}
|
||||
|
||||
AbstractConfigType<?, ?> entry = entries.get(entries.size() - 1);
|
||||
AbstractConfigType<?, ?> entry = entries.getLast();
|
||||
entry.category = category;
|
||||
entry.name = field.getName();
|
||||
entry.configBase = this;
|
||||
@@ -160,7 +160,7 @@ public class ConfigBase
|
||||
{
|
||||
LOGGER.error("Invalid variable type at [" + (category.isEmpty() ? "" : category + ".") + field.getName() + "].");
|
||||
LOGGER.error("Type [" + entry.getType() + "] is not one of these types [" + acceptableInputs.toString() + "]");
|
||||
entries.remove(entries.size() - 1); // Delete the entry if it is invalid so the game can still run
|
||||
entries.removeLast(); // Delete the entry if it is invalid so the game can still run
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.Map;
|
||||
public class NumberUtil
|
||||
{
|
||||
// Is there no better way of doing this?
|
||||
public static Map<Class<?>, Number> minValues = new HashMap<Class<?>, Number>()
|
||||
public static Map<Class<?>, Number> minValues = new HashMap<>()
|
||||
{{
|
||||
put(Byte.class, Byte.MIN_VALUE);
|
||||
put(Short.class, Short.MIN_VALUE);
|
||||
@@ -41,7 +41,7 @@ public class NumberUtil
|
||||
put(Double.class, Double.MIN_VALUE);
|
||||
put(Float.class, Float.MIN_VALUE);
|
||||
}};
|
||||
public static Map<Class<?>, Number> maxValues = new HashMap<Class<?>, Number>()
|
||||
public static Map<Class<?>, Number> maxValues = new HashMap<>()
|
||||
{{
|
||||
put(Byte.class, Byte.MAX_VALUE);
|
||||
put(Short.class, Short.MAX_VALUE);
|
||||
|
||||
+2
-2
@@ -23,9 +23,9 @@ import com.seibel.distanthorizons.api.DhApi;
|
||||
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderProxy;
|
||||
import com.seibel.distanthorizons.core.config.listeners.IConfigListener;
|
||||
|
||||
public class ReloadLodsConfigEventHandler implements IConfigListener
|
||||
public class DebugColumnConfigEventHandler implements IConfigListener
|
||||
{
|
||||
public static ReloadLodsConfigEventHandler INSTANCE = new ReloadLodsConfigEventHandler();
|
||||
public static DebugColumnConfigEventHandler INSTANCE = new DebugColumnConfigEventHandler();
|
||||
|
||||
@Override
|
||||
public void onConfigValueSet()
|
||||
+2
-2
@@ -35,8 +35,8 @@ public class QuickRenderToggleConfigEventHandler
|
||||
/** private since we only ever need one handler at a time */
|
||||
private QuickRenderToggleConfigEventHandler()
|
||||
{
|
||||
this.quickRenderChangeListener = new ConfigChangeListener<>(Config.Client.quickEnableRendering, (val) -> { Config.Client.Advanced.Debugging.rendererMode.set(Config.Client.quickEnableRendering.get() ? EDhApiRendererMode.DEFAULT : EDhApiRendererMode.DISABLED); });
|
||||
this.rendererModeChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Debugging.rendererMode, (val) -> { Config.Client.quickEnableRendering.set(Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED); });
|
||||
this.quickRenderChangeListener = new ConfigChangeListener<>(Config.Client.quickEnableRendering, (val) -> Config.Client.Advanced.Debugging.rendererMode.set(Config.Client.quickEnableRendering.get() ? EDhApiRendererMode.DEFAULT : EDhApiRendererMode.DISABLED));
|
||||
this.rendererModeChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Debugging.rendererMode, (val) -> Config.Client.quickEnableRendering.set(Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class ResetConfigEventHandler
|
||||
/** private since we only ever need one handler at a time */
|
||||
private ResetConfigEventHandler()
|
||||
{
|
||||
this.configChangeListener = new ConfigChangeListener<>(Config.Client.ResetConfirmation.resetAllSettings, (resetSettings) -> { doStuff(resetSettings); });
|
||||
this.configChangeListener = new ConfigChangeListener<>(Config.Client.ResetConfirmation.resetAllSettings, this::doStuff);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -57,9 +57,7 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
|
||||
|
||||
public AbstractPresetConfigEventHandler()
|
||||
{
|
||||
if (configGui != null) {
|
||||
configGui.addOnScreenChangeListener(this::onConfigUiClosed);
|
||||
}
|
||||
configGui.addOnScreenChangeListener(this::onConfigUiClosed);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +168,7 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
|
||||
|
||||
if (newPreset != currentPreset)
|
||||
{
|
||||
this.getPresetConfigEntry().set(newPreset);
|
||||
this.getPresetConfigEntry().set(this.getCustomPresetEnum());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +216,7 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
|
||||
possiblePrestList.add(this.getCustomPresetEnum());
|
||||
}
|
||||
|
||||
return possiblePrestList.get(0);
|
||||
return possiblePrestList.getFirst();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-6
@@ -41,7 +41,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE
|
||||
|
||||
|
||||
private final ConfigEntryWithPresetOptions<EDhApiQualityPreset, EDhApiMaxHorizontalResolution> drawResolution = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution,
|
||||
new HashMap<EDhApiQualityPreset, EDhApiMaxHorizontalResolution>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiQualityPreset.MINIMUM, EDhApiMaxHorizontalResolution.TWO_BLOCKS);
|
||||
this.put(EDhApiQualityPreset.LOW, EDhApiMaxHorizontalResolution.BLOCK);
|
||||
@@ -50,7 +50,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE
|
||||
this.put(EDhApiQualityPreset.EXTREME, EDhApiMaxHorizontalResolution.BLOCK);
|
||||
}});
|
||||
private final ConfigEntryWithPresetOptions<EDhApiQualityPreset, EDhApiVerticalQuality> verticalQuality = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.verticalQuality,
|
||||
new HashMap<EDhApiQualityPreset, EDhApiVerticalQuality>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiQualityPreset.MINIMUM, EDhApiVerticalQuality.HEIGHT_MAP);
|
||||
this.put(EDhApiQualityPreset.LOW, EDhApiVerticalQuality.LOW);
|
||||
@@ -59,7 +59,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE
|
||||
this.put(EDhApiQualityPreset.EXTREME, EDhApiVerticalQuality.EXTREME);
|
||||
}});
|
||||
private final ConfigEntryWithPresetOptions<EDhApiQualityPreset, EDhApiHorizontalQuality> horizontalQuality = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.horizontalQuality,
|
||||
new HashMap<EDhApiQualityPreset, EDhApiHorizontalQuality>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiQualityPreset.MINIMUM, EDhApiHorizontalQuality.LOWEST);
|
||||
this.put(EDhApiQualityPreset.LOW, EDhApiHorizontalQuality.LOW);
|
||||
@@ -68,7 +68,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE
|
||||
this.put(EDhApiQualityPreset.EXTREME, EDhApiHorizontalQuality.EXTREME);
|
||||
}});
|
||||
private final ConfigEntryWithPresetOptions<EDhApiQualityPreset, EDhApiTransparency> transparency = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.transparency,
|
||||
new HashMap<EDhApiQualityPreset, EDhApiTransparency>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiQualityPreset.MINIMUM, EDhApiTransparency.DISABLED);
|
||||
this.put(EDhApiQualityPreset.LOW, EDhApiTransparency.DISABLED); // should be fake if/when fake is fixed
|
||||
@@ -77,7 +77,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE
|
||||
this.put(EDhApiQualityPreset.EXTREME, EDhApiTransparency.COMPLETE);
|
||||
}});
|
||||
private final ConfigEntryWithPresetOptions<EDhApiQualityPreset, Boolean> ssaoEnabled = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Ssao.enabled,
|
||||
new HashMap<EDhApiQualityPreset, Boolean>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiQualityPreset.MINIMUM, false);
|
||||
this.put(EDhApiQualityPreset.LOW, false);
|
||||
@@ -106,7 +106,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE
|
||||
for (ConfigEntryWithPresetOptions<EDhApiQualityPreset, ?> config : this.configList)
|
||||
{
|
||||
// ignore try-using, the listener should only ever be added once and should never be removed
|
||||
new ConfigChangeListener<>(config.configEntry, (val) -> { this.onConfigValueChanged(); });
|
||||
new ConfigChangeListener<>(config.configEntry, (val) -> this.onConfigValueChanged());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-35
@@ -32,7 +32,6 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHandler<EDhApiThreadPreset>
|
||||
{
|
||||
public static final ThreadPresetConfigEventHandler INSTANCE = new ThreadPresetConfigEventHandler();
|
||||
@@ -43,7 +42,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
|
||||
public static int getWorldGenDefaultThreadCount() { return getThreadCountByPercent(0.1); }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Integer> worldGenThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads,
|
||||
new HashMap<EDhApiThreadPreset, Integer>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getWorldGenDefaultThreadCount());
|
||||
@@ -53,7 +52,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
}});
|
||||
public static double getWorldGenDefaultRunTimeRatio() { return 0.5; }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Double> worldGenRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForWorldGenerationThreads,
|
||||
new HashMap<EDhApiThreadPreset, Double>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.1);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getWorldGenDefaultRunTimeRatio());
|
||||
@@ -65,7 +64,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
|
||||
public static int getFileHandlerDefaultThreadCount() { return getThreadCountByPercent(0.1); }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Integer> fileHandlerThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfFileHandlerThreads,
|
||||
new HashMap<EDhApiThreadPreset, Integer>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getFileHandlerDefaultThreadCount());
|
||||
@@ -75,7 +74,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
}});
|
||||
public static double getFileHandlerDefaultRunTimeRatio() { return 0.5; }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Double> fileHandlerRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForFileHandlerThreads,
|
||||
new HashMap<EDhApiThreadPreset, Double>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.25);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getFileHandlerDefaultRunTimeRatio());
|
||||
@@ -87,7 +86,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
|
||||
public static int getUpdatePropagatorDefaultThreadCount() { return getThreadCountByPercent(0.10); }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Integer> UpdatePropagatorThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfUpdatePropagatorThreads,
|
||||
new HashMap<EDhApiThreadPreset, Integer>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getUpdatePropagatorDefaultThreadCount());
|
||||
@@ -97,7 +96,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
}});
|
||||
public static double getUpdatePropagatorDefaultRunTimeRatio() { return 0.25; }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Double> UpdatePropagatorRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForUpdatePropagatorThreads,
|
||||
new HashMap<EDhApiThreadPreset, Double>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.1);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getUpdatePropagatorDefaultRunTimeRatio());
|
||||
@@ -109,7 +108,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
|
||||
public static int getLodBuilderDefaultThreadCount() { return getThreadCountByPercent(0.1); }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Integer> lodBuilderThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads,
|
||||
new HashMap<EDhApiThreadPreset, Integer>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getLodBuilderDefaultThreadCount());
|
||||
@@ -119,7 +118,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
}});
|
||||
public static double getLodBuilderDefaultRunTimeRatio() { return 0.25; }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Double> lodBuilderRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForLodBuilderThreads,
|
||||
new HashMap<EDhApiThreadPreset, Double>()
|
||||
new HashMap<>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.1);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getLodBuilderDefaultRunTimeRatio());
|
||||
@@ -129,28 +128,6 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
}});
|
||||
|
||||
|
||||
public static int getNetworkCompressionDefaultThreadCount() { return getThreadCountByPercent(0.3); }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Integer> networkCompressionThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfNetworkCompressionThreads,
|
||||
new HashMap<EDhApiThreadPreset, Integer>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getNetworkCompressionDefaultThreadCount());
|
||||
this.put(EDhApiThreadPreset.BALANCED, getThreadCountByPercent(0.4));
|
||||
this.put(EDhApiThreadPreset.AGGRESSIVE, getThreadCountByPercent(0.6));
|
||||
this.put(EDhApiThreadPreset.I_PAID_FOR_THE_WHOLE_CPU, getThreadCountByPercent(0.8));
|
||||
}});
|
||||
public static double getNetworkCompressionDefaultRunTimeRatio() { return 0.5; }
|
||||
private final ConfigEntryWithPresetOptions<EDhApiThreadPreset, Double> networkCompressionRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForNetworkCompressionThreads,
|
||||
new HashMap<EDhApiThreadPreset, Double>()
|
||||
{{
|
||||
this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.25);
|
||||
this.put(EDhApiThreadPreset.LOW_IMPACT, getNetworkCompressionDefaultRunTimeRatio());
|
||||
this.put(EDhApiThreadPreset.BALANCED, 0.75);
|
||||
this.put(EDhApiThreadPreset.AGGRESSIVE, 1.0);
|
||||
this.put(EDhApiThreadPreset.I_PAID_FOR_THE_WHOLE_CPU, 1.0);
|
||||
}});
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// constructors //
|
||||
@@ -172,14 +149,11 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan
|
||||
this.configList.add(this.lodBuilderThreadCount);
|
||||
this.configList.add(this.lodBuilderRunTime);
|
||||
|
||||
this.configList.add(this.networkCompressionThreadCount);
|
||||
this.configList.add(this.networkCompressionRunTime);
|
||||
|
||||
|
||||
for (ConfigEntryWithPresetOptions<EDhApiThreadPreset, ?> config : this.configList)
|
||||
{
|
||||
// ignore try-using, the listeners should only ever be added once and should never be removed
|
||||
new ConfigChangeListener<>(config.configEntry, (val) -> { this.onConfigValueChanged(); });
|
||||
new ConfigChangeListener<>(config.configEntry, (val) -> this.onConfigValueChanged());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.seibel.distanthorizons.core.config.ConfigBase;
|
||||
import com.seibel.distanthorizons.core.config.types.AbstractConfigType;
|
||||
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -192,8 +191,6 @@ public class ConfigFileHandling
|
||||
public void saveEntry(ConfigEntry<?> entry, CommentedFileConfig workConfig)
|
||||
{
|
||||
if (!entry.getAppearance().showInFile) return;
|
||||
if (SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class).isDedicatedServer() && entry.getServersideShortName() == null)
|
||||
return;
|
||||
if (entry.getTrueValue() == null)
|
||||
throw new IllegalArgumentException("Entry [" + entry.getNameWCategory() + "] is null, this may be a problem with [" + configBase.modName + "]. Please contact the authors");
|
||||
|
||||
@@ -268,9 +265,6 @@ public class ConfigFileHandling
|
||||
)
|
||||
return;
|
||||
|
||||
if (SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class).isDedicatedServer() && entry.getServersideShortName() == null)
|
||||
return;
|
||||
|
||||
String comment = entry.getComment().replaceAll("\n", "\n ").trim();
|
||||
// the new line makes it easier to read and separate configs
|
||||
// the space makes sure the first word of a comment isn't directly in line with the "#"
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ import java.util.Map;
|
||||
public class ConfigTypeConverters
|
||||
{
|
||||
// Once you've made a converter add it to here where the first value is the type you want to convert and the 2nd value is the converter
|
||||
public static final Map<Class<?>, ConverterBase> convertObjects = new HashMap<Class<?>, ConverterBase>()
|
||||
public static final Map<Class<?>, ConverterBase> convertObjects = new HashMap<>()
|
||||
{{
|
||||
this.put(Short.class, new ShortConverter());
|
||||
this.put(Long.class, new LongConverter());
|
||||
|
||||
+15
-20
@@ -73,33 +73,28 @@ public final class EmbeddedFrameUtil
|
||||
|
||||
private static String getEmbeddedFrameImpl()
|
||||
{
|
||||
switch (EPlatform.get())
|
||||
return switch (EPlatform.get())
|
||||
{
|
||||
case LINUX:
|
||||
return "sun.awt.X11.XEmbeddedFrame";
|
||||
case WINDOWS:
|
||||
return "sun.awt.windows.WEmbeddedFrame";
|
||||
case MACOS:
|
||||
return "sun.lwawt.macosx.CViewEmbeddedFrame";
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
case LINUX -> "sun.awt.X11.XEmbeddedFrame";
|
||||
case WINDOWS -> "sun.awt.windows.WEmbeddedFrame";
|
||||
case MACOS -> "sun.lwawt.macosx.CViewEmbeddedFrame";
|
||||
default -> throw new IllegalStateException();
|
||||
};
|
||||
}
|
||||
|
||||
private static long getEmbeddedFrameHandle(long window)
|
||||
{
|
||||
switch (EPlatform.get())
|
||||
return switch (EPlatform.get())
|
||||
{
|
||||
case LINUX:
|
||||
return glfwGetX11Window(window);
|
||||
case WINDOWS:
|
||||
return glfwGetWin32Window(window);
|
||||
case MACOS:
|
||||
case LINUX -> glfwGetX11Window(window);
|
||||
case WINDOWS -> glfwGetWin32Window(window);
|
||||
case MACOS ->
|
||||
{
|
||||
long objc_msgSend = ObjCRuntime.getLibrary().getFunctionAddress("objc_msgSend");
|
||||
return invokePPP(glfwGetCocoaWindow(window), sel_getUid("contentView"), objc_msgSend);
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
yield invokePPP(glfwGetCocoaWindow(window), sel_getUid("contentView"), objc_msgSend);
|
||||
}
|
||||
default -> throw new IllegalStateException();
|
||||
};
|
||||
}
|
||||
|
||||
public static Frame embeddedFrameCreate(long window)
|
||||
|
||||
@@ -44,7 +44,6 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
private T min;
|
||||
private T max;
|
||||
private final ArrayList<IConfigListener> listenerList;
|
||||
private final String serversideShortName;
|
||||
|
||||
// API control //
|
||||
/**
|
||||
@@ -58,14 +57,13 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
|
||||
|
||||
/** Creates the entry */
|
||||
private ConfigEntry(EConfigEntryAppearance appearance, T value, String comment, T min, T max, String serversideShortName, boolean allowApiOverride, EConfigEntryPerformance performance, ArrayList<IConfigListener> listenerList)
|
||||
private ConfigEntry(EConfigEntryAppearance appearance, T value, String comment, T min, T max, boolean allowApiOverride, EConfigEntryPerformance performance, ArrayList<IConfigListener> listenerList)
|
||||
{
|
||||
super(appearance, value);
|
||||
|
||||
this.comment = comment;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.serversideShortName = serversideShortName;
|
||||
this.allowApiOverride = allowApiOverride;
|
||||
this.performance = performance;
|
||||
this.listenerList = listenerList;
|
||||
@@ -181,8 +179,6 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
if (validness == 1) this.value = (T) NumberUtil.getMaximum(this.value.getClass());
|
||||
}
|
||||
|
||||
public String getServersideShortName() { return this.serversideShortName; }
|
||||
|
||||
@Override
|
||||
public String getComment() { return this.comment; }
|
||||
@Override
|
||||
@@ -319,7 +315,6 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
private String tmpComment = null;
|
||||
private T tmpMin = null;
|
||||
private T tmpMax = null;
|
||||
protected String tmpServersideShortName = null;
|
||||
private boolean tmpUseApiOverwrite = true;
|
||||
private EConfigEntryPerformance tmpPerformance = EConfigEntryPerformance.DONT_SHOW;
|
||||
protected ArrayList<IConfigListener> tmpIConfigListener = new ArrayList<>();
|
||||
@@ -357,12 +352,6 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> setServersideShortName(String name)
|
||||
{
|
||||
this.tmpServersideShortName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> setUseApiOverwrite(boolean newUseApiOverwrite)
|
||||
{
|
||||
this.tmpUseApiOverwrite = newUseApiOverwrite;
|
||||
@@ -405,7 +394,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
|
||||
public ConfigEntry<T> build()
|
||||
{
|
||||
return new ConfigEntry<>(this.tmpAppearance, this.tmpValue, this.tmpComment, this.tmpMin, this.tmpMax, this.tmpServersideShortName, this.tmpUseApiOverwrite, this.tmpPerformance, this.tmpIConfigListener);
|
||||
return new ConfigEntry<>(this.tmpAppearance, this.tmpValue, this.tmpComment, this.tmpMin, this.tmpMax, this.tmpUseApiOverwrite, this.tmpPerformance, this.tmpIConfigListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -516,10 +516,9 @@ public class FullDataPointIdMap
|
||||
if (otherObj == this)
|
||||
return true;
|
||||
|
||||
if (!(otherObj instanceof Entry))
|
||||
if (!(otherObj instanceof Entry other))
|
||||
return false;
|
||||
|
||||
Entry other = (Entry) otherObj;
|
||||
return other.biome.getSerialString().equals(this.biome.getSerialString())
|
||||
&& other.blockState.getSerialString().equals(this.blockState.getSerialString());
|
||||
}
|
||||
|
||||
+20
-39
@@ -90,13 +90,11 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
|
||||
/**
|
||||
* stores how far each column has been generated should start with {@link EDhApiWorldGenerationStep#EMPTY}
|
||||
*
|
||||
* @see EDhApiWorldGenerationStep
|
||||
*/
|
||||
public byte[] columnGenerationSteps;
|
||||
/**
|
||||
* stores what world compression was used for each column.
|
||||
*
|
||||
* @see EDhApiWorldCompressionMode
|
||||
*/
|
||||
public byte[] columnWorldCompressionMode;
|
||||
@@ -153,9 +151,9 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
if (FullDataSourceV1.WIDTH != WIDTH)
|
||||
{
|
||||
throw new UnsupportedOperationException(
|
||||
"Unable to convert [" + FullDataSourceV1.class.getSimpleName() + "] into [" + FullDataSourceV2.class.getSimpleName() + "]. " +
|
||||
"Data sources have different data point widths and no converter is present. " +
|
||||
"input width [" + FullDataSourceV1.WIDTH + "], recipient width [" + WIDTH + "].");
|
||||
"Unable to convert ["+FullDataSourceV1.class.getSimpleName()+"] into ["+FullDataSourceV2.class.getSimpleName()+"]. " +
|
||||
"Data sources have different data point widths and no converter is present. " +
|
||||
"input width ["+ FullDataSourceV1.WIDTH+"], recipient width ["+WIDTH+"].");
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +256,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
// and would lead to edge cases that don't necessarily need to be supported
|
||||
// (IE what do you do when the input is smaller than a single datapoint in the receiving data source?)
|
||||
// instead it's better to just percolate the updates up
|
||||
throw new UnsupportedOperationException("Unsupported data source update. Expected input detail level of [" + thisDetailLevel + "] or [" + (thisDetailLevel + 1) + "], received detail level [" + inputDetailLevel + "].");
|
||||
throw new UnsupportedOperationException("Unsupported data source update. Expected input detail level of ["+thisDetailLevel+"] or ["+(thisDetailLevel+1)+"], received detail level ["+inputDetailLevel+"].");
|
||||
}
|
||||
|
||||
// determine if this data source should be applied to its parent
|
||||
@@ -296,7 +294,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
byte inputGenState = inputDataSource.columnGenerationSteps[index];
|
||||
|
||||
if (inputGenState != EDhApiWorldGenerationStep.EMPTY.value
|
||||
&& thisGenState <= inputGenState)
|
||||
&& thisGenState <= inputGenState)
|
||||
{
|
||||
// check if the data changed
|
||||
if (this.dataPoints[index] == null)
|
||||
@@ -494,7 +492,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
// special numbers:
|
||||
// -2 = the column's height hasn't been determined yet
|
||||
// -1 = we've reached the end of the column
|
||||
int[] currentDatapointIndex = new int[]{-2, -2, -2, -2};
|
||||
int[] currentDatapointIndex = new int[] { -2, -2, -2, -2 };
|
||||
|
||||
int lastId = 0;
|
||||
byte lastBlockLight = 0;
|
||||
@@ -514,10 +512,10 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
{
|
||||
// if each column has reached the end of their data, nothing more needs to be done
|
||||
if (currentDatapointIndex[0] == -1
|
||||
&& currentDatapointIndex[1] == -1
|
||||
&& currentDatapointIndex[2] == -1
|
||||
&& currentDatapointIndex[3] == -1
|
||||
)
|
||||
&& currentDatapointIndex[1] == -1
|
||||
&& currentDatapointIndex[2] == -1
|
||||
&& currentDatapointIndex[3] == -1
|
||||
)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -617,9 +615,9 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
|
||||
// if this slice is different then the last one, create a new one
|
||||
if (id != lastId
|
||||
// block and sky light might not be necessary
|
||||
|| blockLight != lastBlockLight
|
||||
|| skyLight != lastSkyLight)
|
||||
// block and sky light might not be necessary
|
||||
|| blockLight != lastBlockLight
|
||||
|| skyLight != lastSkyLight)
|
||||
{
|
||||
if (height != 0)
|
||||
{
|
||||
@@ -721,42 +719,26 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
}
|
||||
|
||||
if (value == value0)
|
||||
{
|
||||
count0++;
|
||||
}
|
||||
else if (value == value1)
|
||||
{
|
||||
count1++;
|
||||
}
|
||||
else if (value == value2)
|
||||
{
|
||||
count2++;
|
||||
}
|
||||
else
|
||||
{
|
||||
count3++;
|
||||
}
|
||||
}
|
||||
|
||||
// return the most common occurance
|
||||
int maxCount = Math.max(count0, Math.max(count1, Math.max(count2, count3)));
|
||||
if (maxCount == count0)
|
||||
// if the max count is 1 then we'll just go with the first column
|
||||
{
|
||||
// if the max count is 1 then we'll just go with the first column
|
||||
return value0;
|
||||
}
|
||||
else if (maxCount == count1)
|
||||
{
|
||||
return value1;
|
||||
}
|
||||
else if (maxCount == count2)
|
||||
{
|
||||
return value2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return value3;
|
||||
}
|
||||
}
|
||||
private static int determineAverageValueInColumnSlice(int[] sliceArray)
|
||||
{
|
||||
@@ -789,9 +771,9 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
public static int relativePosToIndex(int relX, int relZ) throws IndexOutOfBoundsException
|
||||
{
|
||||
if (relX < 0 || relZ < 0 ||
|
||||
relX > WIDTH || relZ > WIDTH)
|
||||
relX > WIDTH || relZ > WIDTH)
|
||||
{
|
||||
throw new IndexOutOfBoundsException("Relative data source positions must be between [0] and [" + WIDTH + "] (inclusive) the relative pos: [" + relX + "," + relZ + "] is outside of those boundaries.");
|
||||
throw new IndexOutOfBoundsException("Relative data source positions must be between [0] and ["+WIDTH+"] (inclusive) the relative pos: ["+relX+","+relZ+"] is outside of those boundaries.");
|
||||
}
|
||||
|
||||
return (relX * WIDTH) + relZ;
|
||||
@@ -836,7 +818,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
// reverse the array so index 0 is the highest,
|
||||
// this is necessary for later logic
|
||||
// source: https://stackoverflow.com/questions/2137755/how-do-i-reverse-an-int-array-in-java
|
||||
for (int i = 0; i < dataColumn.size() / 2; i++)
|
||||
for(int i = 0; i < dataColumn.size() / 2; i++)
|
||||
{
|
||||
long temp = dataColumn.getLong(i);
|
||||
dataColumn.set(i, dataColumn.getLong(dataColumn.size() - i - 1));
|
||||
@@ -894,8 +876,8 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
{
|
||||
int index = relativePosToIndex(relX, relZ);
|
||||
this.dataPoints[index] = longArray;
|
||||
this.columnGenerationSteps[index] = worldGenStep.value;
|
||||
this.columnWorldCompressionMode[index] = worldCompressionMode.value;
|
||||
this.columnGenerationSteps[index] = worldGenStep.value;
|
||||
this.columnWorldCompressionMode[index] = worldCompressionMode.value;
|
||||
|
||||
|
||||
if (RUN_UPDATE_DEV_VALIDATION)
|
||||
@@ -945,11 +927,10 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (!(obj instanceof FullDataSourceV2))
|
||||
if (!(obj instanceof FullDataSourceV2 other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
FullDataSourceV2 other = (FullDataSourceV2) obj;
|
||||
|
||||
if (other.pos != this.pos)
|
||||
{
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ import com.seibel.distanthorizons.core.dataObjects.transformers.FullDataToRender
|
||||
import com.seibel.distanthorizons.core.file.DataSourcePool;
|
||||
import com.seibel.distanthorizons.core.file.IDataSource;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
||||
@@ -182,7 +182,7 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
|
||||
EDhApiWorldGenerationStep worldGenStep = inputFullDataSource.getWorldGenStepAtRelativePos(x, z);
|
||||
if (dataColumn != null && worldGenStep != EDhApiWorldGenerationStep.EMPTY)
|
||||
{
|
||||
FullDataToRenderDataTransformer.updateOrReplaceRenderDataViewColumnWithFullDataColumn(
|
||||
FullDataToRenderDataTransformer.updateRenderDataViewWithFullDataColumn(
|
||||
level, inputFullDataSource.mapping,
|
||||
minBlockPos.x + x,
|
||||
minBlockPos.z + z,
|
||||
@@ -288,7 +288,7 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
|
||||
String SUBDATA_DELIMITER = ",";
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append(DhSectionPos.toString(this.pos));
|
||||
stringBuilder.append(this.pos);
|
||||
stringBuilder.append(LINE_DELIMITER);
|
||||
|
||||
int size = 1;
|
||||
|
||||
+12
-22
@@ -99,33 +99,23 @@ public final class BufferQuad
|
||||
|
||||
if (compareDirection == BufferMergeDirectionEnum.EastWest)
|
||||
{
|
||||
switch (this.direction.getAxis())
|
||||
return switch (this.direction.getAxis())
|
||||
{
|
||||
case X:
|
||||
return threeDimensionalCompare(this.x, this.y, this.z, quad.x, quad.y, quad.z);
|
||||
case Y:
|
||||
return threeDimensionalCompare(this.y, this.z, this.x, quad.y, quad.z, quad.x);
|
||||
case Z:
|
||||
return threeDimensionalCompare(this.z, this.y, this.x, quad.z, quad.y, quad.x);
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid Axis enum: " + this.direction.getAxis());
|
||||
}
|
||||
case X -> threeDimensionalCompare(this.x, this.y, this.z, quad.x, quad.y, quad.z);
|
||||
case Y -> threeDimensionalCompare(this.y, this.z, this.x, quad.y, quad.z, quad.x);
|
||||
case Z -> threeDimensionalCompare(this.z, this.y, this.x, quad.z, quad.y, quad.x);
|
||||
default -> throw new IllegalArgumentException("Invalid Axis enum: " + this.direction.getAxis());
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (this.direction.getAxis())
|
||||
return switch (this.direction.getAxis())
|
||||
{
|
||||
case X:
|
||||
return threeDimensionalCompare(this.x, this.z, this.y, quad.x, quad.z, quad.y);
|
||||
case Y:
|
||||
return threeDimensionalCompare(this.y, this.x, this.z, quad.y, quad.x, quad.z);
|
||||
case Z:
|
||||
return threeDimensionalCompare(this.z, this.x, this.y, quad.z, quad.x, quad.y);
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid Axis enum: " + this.direction.getAxis());
|
||||
}
|
||||
case X -> threeDimensionalCompare(this.x, this.z, this.y, quad.x, quad.z, quad.y);
|
||||
case Y -> threeDimensionalCompare(this.y, this.x, this.z, quad.y, quad.x, quad.z);
|
||||
case Z -> threeDimensionalCompare(this.z, this.x, this.y, quad.z, quad.x, quad.y);
|
||||
default -> throw new IllegalArgumentException("Invalid Axis enum: " + this.direction.getAxis());
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
+347
-253
@@ -19,60 +19,29 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
||||
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
|
||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ColumnBox
|
||||
{
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
|
||||
/**
|
||||
* if the skylight has this value that means
|
||||
* no data is expected
|
||||
*/
|
||||
private static final byte SKYLIGHT_EMPTY = -1;
|
||||
/**
|
||||
* if the skylight has this value that means
|
||||
* that block position is covered/occuled by an adjacent block/column.
|
||||
*/
|
||||
private static final byte SKYLIGHT_COVERED = -2;
|
||||
|
||||
private static final ThreadLocal<byte[]> THREAD_LOCAL_SKY_LIGHT_ARRAY = ThreadLocal.withInitial(() ->
|
||||
{
|
||||
byte[] array = new byte[RenderDataPointUtil.MAX_WORLD_Y_SIZE];
|
||||
Arrays.fill(array, SKYLIGHT_EMPTY);
|
||||
return array;
|
||||
});
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// builder //
|
||||
//=========//
|
||||
|
||||
public static void addBoxQuadsToBuilder(
|
||||
LodQuadBuilder builder, IDhClientLevel clientLevel,
|
||||
LodQuadBuilder builder,
|
||||
short xSize, short ySize, short zSize,
|
||||
short x, short minY, short z,
|
||||
int color, byte irisBlockMaterialId, byte skyLight, byte blockLight,
|
||||
long topData, long bottomData, ColumnArrayView[] adjData, boolean[] isAdjDataSameDetailLevel)
|
||||
long topData, long bottomData, ColumnArrayView[][] adjData)
|
||||
{
|
||||
//================//
|
||||
// variable setup //
|
||||
//================//
|
||||
|
||||
short maxX = (short) (x + xSize);
|
||||
short maxY = (short) (minY + ySize);
|
||||
short maxZ = (short) (z + zSize);
|
||||
@@ -84,24 +53,33 @@ public class ColumnBox
|
||||
boolean isTopTransparent = RenderDataPointUtil.getAlpha(topData) < 255 && LodRenderer.transparencyEnabled;
|
||||
boolean isBottomTransparent = RenderDataPointUtil.getAlpha(bottomData) < 255 && LodRenderer.transparencyEnabled;
|
||||
|
||||
// defaulting to a value far below what we can normally render means we
|
||||
// don't need to have an additional "is cave culling enabled" check
|
||||
int caveCullingMaxY = Integer.MIN_VALUE;
|
||||
if (Config.Client.Advanced.Graphics.AdvancedGraphics.enableCaveCulling.get())
|
||||
{
|
||||
caveCullingMaxY = Config.Client.Advanced.Graphics.AdvancedGraphics.caveCullingHeight.get() - clientLevel.getMinY();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if there isn't any data below this LOD, make this LOD's color opaque to prevent seeing void through transparent blocks
|
||||
// Note: this LOD should still be considered transparent for this method's checks, otherwise rendering bugs may occur
|
||||
// FIXME this transparency change should be applied before this point since this could affect other areas
|
||||
// This may also be better than handling the LOD as transparent, but that is TBD
|
||||
if (!RenderDataPointUtil.doesDataPointExist(bottomData))
|
||||
{
|
||||
color = ColorUtil.setAlpha(color, 255);
|
||||
}
|
||||
|
||||
|
||||
// cave culling prevention
|
||||
// prevents certain faces from being culled underground that should be allowed
|
||||
if (builder.skipQuadsWithZeroSkylight
|
||||
&& 0 == skyLight
|
||||
&& builder.skyLightCullingBelow > maxY
|
||||
&& (
|
||||
(RenderDataPointUtil.getAlpha(topData) < 255 && RenderDataPointUtil.getYMax(topData) >= builder.skyLightCullingBelow)
|
||||
|| (RenderDataPointUtil.getYMin(topData) >= builder.skyLightCullingBelow)
|
||||
|| !RenderDataPointUtil.doesDataPointExist(topData)
|
||||
)
|
||||
)
|
||||
{
|
||||
maxY = builder.skyLightCullingBelow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// fake ocean transparency
|
||||
if (LodRenderer.transparencyEnabled && LodRenderer.fakeOceanFloor)
|
||||
{
|
||||
@@ -121,9 +99,7 @@ public class ColumnBox
|
||||
|
||||
|
||||
|
||||
//==========================//
|
||||
// add top and bottom faces //
|
||||
//==========================//
|
||||
// add top and bottom faces if requested //
|
||||
|
||||
boolean skipTop = RenderDataPointUtil.doesDataPointExist(topData) && (RenderDataPointUtil.getYMin(topData) == maxY) && !isTopTransparent;
|
||||
if (!skipTop)
|
||||
@@ -138,291 +114,409 @@ public class ColumnBox
|
||||
}
|
||||
|
||||
|
||||
// add North, south, east, and west faces if requested //
|
||||
|
||||
//========================================//
|
||||
// add North, south, east, and west faces //
|
||||
//========================================//
|
||||
|
||||
// NORTH face
|
||||
// TODO merge duplicate code
|
||||
//NORTH face vertex creation
|
||||
{
|
||||
ColumnArrayView adjCol = adjData[EDhDirection.NORTH.ordinal() - 2]; // TODO can we use something other than ordinal-2?
|
||||
boolean adjSameDetailLevel = isAdjDataSameDetailLevel[EDhDirection.NORTH.ordinal() - 2];
|
||||
// if the adjacent column is null that generally means the adjacent area hasn't been generated yet
|
||||
if (adjCol == null)
|
||||
ColumnArrayView[] adjDataNorth = adjData[EDhDirection.NORTH.ordinal() - 2]; // TODO can we use something other than ordinal-2?
|
||||
int adjOverlapNorth = ColorUtil.INVISIBLE;
|
||||
if (adjDataNorth == null)
|
||||
{
|
||||
// Add an adjacent face if this is opaque face or transparent over the void.
|
||||
// add an adjacent face if this is opaque face or transparent over the void
|
||||
if (!isTransparent || overVoid)
|
||||
{
|
||||
builder.addQuadAdj(EDhDirection.NORTH, x, minY, z, xSize, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
||||
}
|
||||
}
|
||||
else if (adjDataNorth.length == 1)
|
||||
{
|
||||
makeAdjVerticalQuad(builder, adjDataNorth[0], EDhDirection.NORTH, x, minY, z, xSize, ySize,
|
||||
color, adjOverlapNorth, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
}
|
||||
else
|
||||
{
|
||||
makeAdjVerticalQuad(builder, adjCol, adjSameDetailLevel, caveCullingMaxY, EDhDirection.NORTH, x, minY, z, xSize, ySize,
|
||||
color, irisBlockMaterialId, blockLight);
|
||||
makeAdjVerticalQuad(builder, adjDataNorth[0], EDhDirection.NORTH, x, minY, z, (short) (xSize / 2), ySize,
|
||||
color, adjOverlapNorth, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
makeAdjVerticalQuad(builder, adjDataNorth[1], EDhDirection.NORTH, (short) (x + xSize / 2), minY, z, (short) (xSize / 2), ySize,
|
||||
color, adjOverlapNorth, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
}
|
||||
}
|
||||
|
||||
// SOUTH face
|
||||
//SOUTH face vertex creation
|
||||
{
|
||||
ColumnArrayView adjCol = adjData[EDhDirection.SOUTH.ordinal() - 2];
|
||||
boolean adjSameDetailLevel = isAdjDataSameDetailLevel[EDhDirection.SOUTH.ordinal() - 2];
|
||||
if (adjCol == null)
|
||||
ColumnArrayView[] adjDataSouth = adjData[EDhDirection.SOUTH.ordinal() - 2];
|
||||
int adjOverlapSouth = ColorUtil.INVISIBLE;
|
||||
if (adjDataSouth == null)
|
||||
{
|
||||
if (!isTransparent || overVoid)
|
||||
{
|
||||
builder.addQuadAdj(EDhDirection.SOUTH, x, minY, maxZ, xSize, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
||||
}
|
||||
}
|
||||
else if (adjDataSouth.length == 1)
|
||||
{
|
||||
makeAdjVerticalQuad(builder, adjDataSouth[0], EDhDirection.SOUTH, x, minY, maxZ, xSize, ySize,
|
||||
color, adjOverlapSouth, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
}
|
||||
else
|
||||
{
|
||||
makeAdjVerticalQuad(builder, adjCol, adjSameDetailLevel, caveCullingMaxY, EDhDirection.SOUTH, x, minY, maxZ, xSize, ySize,
|
||||
color, irisBlockMaterialId, blockLight);
|
||||
makeAdjVerticalQuad(builder, adjDataSouth[0], EDhDirection.SOUTH, x, minY, maxZ, (short) (xSize / 2), ySize,
|
||||
color, adjOverlapSouth, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
|
||||
makeAdjVerticalQuad(builder, adjDataSouth[1], EDhDirection.SOUTH, (short) (x + xSize / 2), minY, maxZ, (short) (xSize / 2), ySize,
|
||||
color, adjOverlapSouth, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
}
|
||||
}
|
||||
|
||||
// WEST face
|
||||
//WEST face vertex creation
|
||||
{
|
||||
ColumnArrayView adjCol = adjData[EDhDirection.WEST.ordinal() - 2];
|
||||
boolean adjSameDetailLevel = isAdjDataSameDetailLevel[EDhDirection.WEST.ordinal() - 2];
|
||||
if (adjCol == null)
|
||||
ColumnArrayView[] adjDataWest = adjData[EDhDirection.WEST.ordinal() - 2];
|
||||
int adjOverlapWest = ColorUtil.INVISIBLE;
|
||||
if (adjDataWest == null)
|
||||
{
|
||||
if (!isTransparent || overVoid)
|
||||
{
|
||||
builder.addQuadAdj(EDhDirection.WEST, x, minY, z, zSize, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
||||
}
|
||||
}
|
||||
else if (adjDataWest.length == 1)
|
||||
{
|
||||
makeAdjVerticalQuad(builder, adjDataWest[0], EDhDirection.WEST, x, minY, z, zSize, ySize,
|
||||
color, adjOverlapWest, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
}
|
||||
else
|
||||
{
|
||||
makeAdjVerticalQuad(builder, adjCol, adjSameDetailLevel, caveCullingMaxY, EDhDirection.WEST, x, minY, z, zSize, ySize,
|
||||
color, irisBlockMaterialId, blockLight);
|
||||
makeAdjVerticalQuad(builder, adjDataWest[0], EDhDirection.WEST, x, minY, z, (short) (zSize / 2), ySize,
|
||||
color, adjOverlapWest, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
makeAdjVerticalQuad(builder, adjDataWest[1], EDhDirection.WEST, x, minY, (short) (z + zSize / 2), (short) (zSize / 2), ySize,
|
||||
color, adjOverlapWest, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
}
|
||||
}
|
||||
|
||||
// EAST face
|
||||
//EAST face vertex creation
|
||||
{
|
||||
ColumnArrayView adjCol = adjData[EDhDirection.EAST.ordinal() - 2];
|
||||
boolean adjSameDetailLevel = isAdjDataSameDetailLevel[EDhDirection.EAST.ordinal() - 2];
|
||||
if (adjCol == null)
|
||||
ColumnArrayView[] adjDataEast = adjData[EDhDirection.EAST.ordinal() - 2];
|
||||
int adjOverlapEast = ColorUtil.INVISIBLE;
|
||||
if (adjData[EDhDirection.EAST.ordinal() - 2] == null)
|
||||
{
|
||||
if (!isTransparent || overVoid)
|
||||
{
|
||||
builder.addQuadAdj(EDhDirection.EAST, maxX, minY, z, zSize, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
||||
}
|
||||
}
|
||||
else if (adjDataEast.length == 1)
|
||||
{
|
||||
makeAdjVerticalQuad(builder, adjDataEast[0], EDhDirection.EAST, maxX, minY, z, zSize, ySize,
|
||||
color, adjOverlapEast, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
}
|
||||
else
|
||||
{
|
||||
makeAdjVerticalQuad(builder, adjCol, adjSameDetailLevel, caveCullingMaxY, EDhDirection.EAST, maxX, minY, z, zSize, ySize,
|
||||
color, irisBlockMaterialId, blockLight);
|
||||
makeAdjVerticalQuad(builder, adjDataEast[0], EDhDirection.EAST, maxX, minY, z, (short) (zSize / 2), ySize,
|
||||
color, adjOverlapEast, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
makeAdjVerticalQuad(builder, adjDataEast[1], EDhDirection.EAST, maxX, minY, (short) (z + zSize / 2), (short) (zSize / 2), ySize,
|
||||
color, adjOverlapEast, irisBlockMaterialId, skyLightTop, blockLight,
|
||||
topData, bottomData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the overlap color can be used to see faces that shouldn't be rendered
|
||||
private static void makeAdjVerticalQuad(
|
||||
LodQuadBuilder builder, @NotNull ColumnArrayView adjColumnView, boolean adjacentIsSameDetailLevel, int caveCullingMaxY, EDhDirection direction,
|
||||
LodQuadBuilder builder, ColumnArrayView adjColumnView, EDhDirection direction,
|
||||
short x, short yMin, short z, short horizontalWidth, short ySize,
|
||||
int color, byte irisBlockMaterialId, byte blockLight)
|
||||
int color, int debugOverlapColor, byte irisBlockMaterialId, byte skyLightTop, byte blockLight,
|
||||
long topData, long bottomData)
|
||||
{
|
||||
//==================//
|
||||
// create face with //
|
||||
// no adjacent data //
|
||||
//==================//
|
||||
|
||||
color = ColorUtil.applyShade(color, MC.getShade(direction));
|
||||
|
||||
// if there isn't any data adjacent to this LOD,
|
||||
// just add the full vertical quad
|
||||
if (adjColumnView.size == 0 || RenderDataPointUtil.isVoid(adjColumnView.get(0)))
|
||||
if (adjColumnView == null || adjColumnView.size == 0 || RenderDataPointUtil.isVoid(adjColumnView.get(0)))
|
||||
{
|
||||
|
||||
// there isn't any data adjacent to this LOD, add the vertical quad
|
||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int yMax = yMin + ySize;
|
||||
|
||||
//===========================//
|
||||
// Determine face visibility //
|
||||
// based on it's neighbors //
|
||||
//===========================//
|
||||
int adjIndex;
|
||||
boolean firstFace = true;
|
||||
boolean inputAboveAdjLods = true;
|
||||
short previousAdjDepth = -1;
|
||||
byte nextTopSkyLight = skyLightTop;
|
||||
boolean inputTransparent = ColorUtil.getAlpha(color) < 255 && LodRenderer.transparencyEnabled;
|
||||
boolean lastAdjWasTransparent = false;
|
||||
|
||||
short yMax = (short) (yMin + ySize); // min is inclusive, max is exclusive
|
||||
byte[] skyLightAtInputPos = THREAD_LOCAL_SKY_LIGHT_ARRAY.get();
|
||||
|
||||
try
|
||||
|
||||
if (!RenderDataPointUtil.doesDataPointExist(bottomData))
|
||||
{
|
||||
// set the initial sky-lights for this face,
|
||||
// if nothing overlaps or overhangs the face should have max sky light
|
||||
Arrays.fill(skyLightAtInputPos, yMin, yMax, LodUtil.MAX_MC_LIGHT);
|
||||
// there isn't anything under this LOD,
|
||||
// to prevent seeing through the world, make it opaque
|
||||
color = ColorUtil.setAlpha(color, 255);
|
||||
}
|
||||
|
||||
// iterate top down
|
||||
int adjCount = adjColumnView.size();
|
||||
for (int adjIndex = 0; adjIndex < adjCount; adjIndex++)
|
||||
|
||||
// Add adjacent faces if this LOD is surrounded by transparent LODs
|
||||
// (prevents invisible sides underwater)
|
||||
int adjCount = adjColumnView.size();
|
||||
for (adjIndex = 0; // iterates top down
|
||||
adjIndex < adjCount
|
||||
&& RenderDataPointUtil.doesDataPointExist(adjColumnView.get(adjIndex))
|
||||
&& !RenderDataPointUtil.isVoid(adjColumnView.get(adjIndex));
|
||||
adjIndex++)
|
||||
{
|
||||
long adjPoint = adjColumnView.get(adjIndex);
|
||||
|
||||
// if the adjacent data point is over the void
|
||||
// don't consider it as transparent
|
||||
// FIXME this transparency change should be applied before this point since this could affect other areas
|
||||
boolean adjOverVoid = false;
|
||||
if (adjIndex > 0)
|
||||
{
|
||||
long adjPoint = adjColumnView.get(adjIndex);
|
||||
short adjMinY = RenderDataPointUtil.getYMin(adjPoint);
|
||||
short adjMaxY = RenderDataPointUtil.getYMax(adjPoint);
|
||||
long adjBellowPoint = adjColumnView.get(adjIndex-1);
|
||||
adjOverVoid = !RenderDataPointUtil.doesDataPointExist(adjBellowPoint);
|
||||
}
|
||||
boolean adjTransparent = !adjOverVoid && RenderDataPointUtil.getAlpha(adjPoint) < 255 && LodRenderer.transparencyEnabled;
|
||||
|
||||
// skip empty adjacent datapoints
|
||||
if (!RenderDataPointUtil.doesDataPointExist(adjPoint)
|
||||
|| RenderDataPointUtil.isVoid(adjPoint))
|
||||
|
||||
// continue if this data point is transparent or the adjacent point is not
|
||||
if (inputTransparent || !adjTransparent) // TODO inputIsTransparent may be unnecessary
|
||||
{
|
||||
short adjYMin = RenderDataPointUtil.getYMin(adjPoint);
|
||||
short adjYMax = RenderDataPointUtil.getYMax(adjPoint);
|
||||
|
||||
|
||||
// if fake transparency is enabled, allow for 1 block of transparency,
|
||||
// everything under that should be opaque
|
||||
if (LodRenderer.transparencyEnabled && LodRenderer.fakeOceanFloor)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip this adjacent datapoint if it's above the input datapoint (since it can't affect the input data point)
|
||||
if (yMax <= adjMinY)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
long adjAbovePoint = (adjIndex != 0) ? adjColumnView.get(adjIndex - 1) : RenderDataPointUtil.EMPTY_DATA;
|
||||
long adjBelowPoint = (adjIndex + 1 < adjCount) ? adjColumnView.get(adjIndex + 1) : RenderDataPointUtil.EMPTY_DATA;
|
||||
|
||||
// if the adjacent data point is over the void
|
||||
// don't consider it as transparent
|
||||
boolean adjOverVoid = !RenderDataPointUtil.doesDataPointExist(adjBelowPoint);
|
||||
boolean adjTransparent = !adjOverVoid && RenderDataPointUtil.getAlpha(adjPoint) < 255 && LodRenderer.transparencyEnabled;
|
||||
|
||||
|
||||
|
||||
//=================================//
|
||||
// set sky light based on adjacent //
|
||||
//=================================//
|
||||
|
||||
// set light based on overlapping adjacent
|
||||
if (!adjTransparent)
|
||||
{
|
||||
// adj opaque
|
||||
// mark positions adjacent is covering
|
||||
byte adjSkyLight = RenderDataPointUtil.getLightSky(adjPoint);
|
||||
for (int i = adjMinY; i < adjMaxY; i++)
|
||||
if (lastAdjWasTransparent && !adjTransparent)
|
||||
{
|
||||
byte skyLightAtPos = skyLightAtInputPos[i];
|
||||
|
||||
// if the adjacent is a different detail level, we want to render adjacent opaque
|
||||
// faces to try and reduce the chance of holes on detail level borders
|
||||
boolean adjacentCoversThis =
|
||||
// if the adjacent is the same detail level, no special handling is necessary
|
||||
!adjacentIsSameDetailLevel
|
||||
// if the adjacent face is underground we probably don't need it
|
||||
&& RenderDataPointUtil.getYMax(adjPoint) >= caveCullingMaxY
|
||||
// check if this face is on a border
|
||||
&&
|
||||
(
|
||||
(x == 0 && direction == EDhDirection.WEST)
|
||||
|| (z == 0 && direction == EDhDirection.NORTH)
|
||||
// TODO why does 256 represent a border? aren't LODs only 64 datapoints wide?
|
||||
|| (x == 256 && direction == EDhDirection.EAST)
|
||||
|| (z == 256 && direction == EDhDirection.SOUTH)
|
||||
);
|
||||
|
||||
byte newSkyLightAtPos = adjacentCoversThis ? adjSkyLight : SKYLIGHT_COVERED;
|
||||
skyLightAtInputPos[i] = (byte) Math.min(newSkyLightAtPos, skyLightAtPos);
|
||||
adjYMax = (short) (RenderDataPointUtil.getYMax(adjColumnView.get(adjIndex - 1)) - 1);
|
||||
}
|
||||
else if (adjTransparent && (adjIndex + 1) < adjCount)
|
||||
{
|
||||
if (RenderDataPointUtil.getAlpha(adjColumnView.get(adjIndex + 1)) == 255)
|
||||
{
|
||||
adjYMin = (short) (adjYMax - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (yMax <= adjYMin)
|
||||
{
|
||||
// the adjacent LOD is above the input LOD and won't affect its rendering,
|
||||
// skip to the next adjacent
|
||||
continue;
|
||||
}
|
||||
inputAboveAdjLods = false;
|
||||
|
||||
|
||||
if (adjYMax < yMin)
|
||||
{
|
||||
// the adjacent LOD is below the input LOD
|
||||
|
||||
// getting the skylight is more complicated
|
||||
// since LODs can be adjacent to water, which changes how skylight works
|
||||
byte skyLight;
|
||||
if (adjIndex == 0)
|
||||
{
|
||||
// this adj LOD is at the highest position,
|
||||
// its sky lighting won't be affected by anything above it
|
||||
skyLight = RenderDataPointUtil.getLightSky(adjPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO improve the comments here, this is a bit confusing
|
||||
long aboveAdjPoint = adjColumnView.get(adjIndex - 1);
|
||||
if (RenderDataPointUtil.getAlpha(aboveAdjPoint) != 255)
|
||||
{
|
||||
// above adjacent LOD is transparent...
|
||||
|
||||
boolean inputMaxHigherThanAboveAdj = yMax > RenderDataPointUtil.getYMax(aboveAdjPoint);
|
||||
if (inputMaxHigherThanAboveAdj)
|
||||
{
|
||||
// ...and higher than the input yMax,
|
||||
// use its sky light
|
||||
skyLight = RenderDataPointUtil.getLightSky(aboveAdjPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ...and at or below the input yMax,
|
||||
skyLight = RenderDataPointUtil.getLightSky(adjPoint);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// LOD above adjacent is opaque, use the adj LOD's skylight
|
||||
skyLight = RenderDataPointUtil.getLightSky(adjPoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (firstFace)
|
||||
{
|
||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, ySize, color, irisBlockMaterialId, skyLight, blockLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now: adjMaxHeight < y < previousAdjDepth < yMax
|
||||
if (previousAdjDepth == -1)
|
||||
{
|
||||
// TODO why is this an error?
|
||||
throw new RuntimeException("Loop error");
|
||||
}
|
||||
|
||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, (short) (previousAdjDepth - yMin), color, irisBlockMaterialId, skyLight, blockLight);
|
||||
|
||||
previousAdjDepth = -1;
|
||||
}
|
||||
|
||||
|
||||
// TODO why break here?
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (adjYMin <= yMin)
|
||||
{
|
||||
// the adjacent LOD's base is at or below the input's base
|
||||
|
||||
if (yMax <= adjYMax)
|
||||
{
|
||||
// The input face is completely inside the adj's face, don't render it
|
||||
if (debugOverlapColor != 0)
|
||||
{
|
||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, ySize, debugOverlapColor, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, LodUtil.MAX_MC_LIGHT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// the adj data intersects the lower part of the input data, don't render below the intersection
|
||||
|
||||
if (adjYMax > yMin && debugOverlapColor != 0)
|
||||
{
|
||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, (short) (adjYMax - yMin), debugOverlapColor, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, LodUtil.MAX_MC_LIGHT);
|
||||
}
|
||||
|
||||
// if this is the only face, use the yMax and break,
|
||||
// if there was another face finish the last one and then break
|
||||
if (firstFace)
|
||||
{
|
||||
builder.addQuadAdj(direction, x, adjYMax, z, horizontalWidth, (short) (yMax - adjYMax), color, irisBlockMaterialId,
|
||||
RenderDataPointUtil.getLightSky(adjPoint), blockLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now: depth <= y <= height <= previousAdjDepth < yMax
|
||||
if (previousAdjDepth == -1)
|
||||
{
|
||||
// TODO why is this an error?
|
||||
throw new RuntimeException("Loop error");
|
||||
}
|
||||
|
||||
if (previousAdjDepth > adjYMax)
|
||||
{
|
||||
builder.addQuadAdj(direction, x, adjYMax, z, horizontalWidth, (short) (previousAdjDepth - adjYMax), color, irisBlockMaterialId,
|
||||
RenderDataPointUtil.getLightSky(adjPoint), blockLight);
|
||||
}
|
||||
previousAdjDepth = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// we don't need to check any other adjacent LODs
|
||||
// since this one completely covers the input
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// In here always true: y < adjYMin < yMax
|
||||
// _________________&&: y < ________ (height and yMax)
|
||||
|
||||
if (adjYMax >= yMax)
|
||||
{
|
||||
// Basically: y _______ < yMax <= height
|
||||
// _______&&: y < depth < yMax
|
||||
// the adj data intersects the higher part of the current data
|
||||
if (debugOverlapColor != 0)
|
||||
{
|
||||
builder.addQuadAdj(direction, x, adjYMin, z, horizontalWidth, (short) (yMax - adjYMin), debugOverlapColor, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, LodUtil.MAX_MC_LIGHT);
|
||||
}
|
||||
|
||||
// we start the creation of a new face
|
||||
}
|
||||
else
|
||||
{
|
||||
// adjacent is transparent,
|
||||
// use datapoint below adjacent for lighting
|
||||
byte belowSkyLight = RenderDataPointUtil.getLightSky(adjBelowPoint);
|
||||
for (int i = adjMinY; i < adjMaxY; i++)
|
||||
// Otherwise: y < _____ height < yMax
|
||||
// _______&&: y < depth ______ < yMax
|
||||
if (debugOverlapColor != 0)
|
||||
{
|
||||
byte skyLightAtPos = skyLightAtInputPos[i];
|
||||
skyLightAtInputPos[i] = (byte) Math.min(belowSkyLight, skyLightAtPos);
|
||||
builder.addQuadAdj(direction, x, adjYMin, z, horizontalWidth, (short) (adjYMax - adjYMin), debugOverlapColor, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, LodUtil.MAX_MC_LIGHT);
|
||||
}
|
||||
|
||||
if (firstFace)
|
||||
{
|
||||
builder.addQuadAdj(direction, x, adjYMax, z, horizontalWidth, (short) (yMax - adjYMax), color, irisBlockMaterialId,
|
||||
RenderDataPointUtil.getLightSky(adjPoint), blockLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now: y < depth < height <= previousAdjDepth < yMax
|
||||
if (previousAdjDepth == -1)
|
||||
throw new RuntimeException("Loop error");
|
||||
if (previousAdjDepth > adjYMax)
|
||||
{
|
||||
if (irisBlockMaterialId == EDhApiBlockMaterial.GRASS.index)
|
||||
{
|
||||
// this LOD is underneath another, grass will never show here
|
||||
irisBlockMaterialId = EDhApiBlockMaterial.DIRT.index;
|
||||
}
|
||||
|
||||
builder.addQuadAdj(direction, x, adjYMax, z, horizontalWidth, (short) (previousAdjDepth - adjYMax), color, irisBlockMaterialId,
|
||||
RenderDataPointUtil.getLightSky(adjPoint), blockLight);
|
||||
}
|
||||
previousAdjDepth = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// fill in sky light up to the next DP,
|
||||
// this is done to handle overhangs
|
||||
byte adjSkyLight = RenderDataPointUtil.getLightSky(adjPoint);
|
||||
int adjAboveMinY = RenderDataPointUtil.getYMin(adjAbovePoint);
|
||||
for (int i = adjMaxY; i < adjAboveMinY; i++)
|
||||
// set next top as current depth
|
||||
previousAdjDepth = adjYMin;
|
||||
firstFace = false;
|
||||
nextTopSkyLight = skyLightTop;
|
||||
|
||||
if (adjIndex + 1 < adjColumnView.size() && RenderDataPointUtil.doesDataPointExist(adjColumnView.get(adjIndex + 1)))
|
||||
{
|
||||
byte skyLightAtPos = skyLightAtInputPos[i];
|
||||
skyLightAtInputPos[i] = (byte) Math.min(adjSkyLight, skyLightAtPos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================//
|
||||
// create vertical faces //
|
||||
//=======================//
|
||||
|
||||
boolean inputTransparent = ColorUtil.getAlpha(color) < 255 && LodRenderer.transparencyEnabled;
|
||||
byte lastSkyLight = skyLightAtInputPos[yMin];
|
||||
int quadBottomY = yMin;
|
||||
int quadTopY = -1;
|
||||
|
||||
// walk up the sky lights and create a new face
|
||||
// whenever the light changes to different valid value
|
||||
for (int i = yMin; i < yMax; i++)
|
||||
{
|
||||
byte skyLight = skyLightAtInputPos[i];
|
||||
if (skyLight != lastSkyLight)
|
||||
{
|
||||
// the sky light changed, create the in-progress face
|
||||
tryAddVerticalFaceWithSkyLightToBuilder(
|
||||
builder, direction,
|
||||
x, z, horizontalWidth,
|
||||
color, irisBlockMaterialId, blockLight,
|
||||
lastSkyLight, inputTransparent, quadTopY, quadBottomY
|
||||
);
|
||||
|
||||
lastSkyLight = skyLight;
|
||||
quadBottomY = i;
|
||||
nextTopSkyLight = RenderDataPointUtil.getLightSky(adjColumnView.get(adjIndex + 1));
|
||||
}
|
||||
|
||||
quadTopY = (i + 1);
|
||||
}
|
||||
|
||||
// add the in-progress face if present
|
||||
if (quadTopY != -1)
|
||||
{
|
||||
tryAddVerticalFaceWithSkyLightToBuilder(
|
||||
builder, direction,
|
||||
x, z, horizontalWidth,
|
||||
color, irisBlockMaterialId, blockLight,
|
||||
lastSkyLight, inputTransparent, quadTopY, quadBottomY
|
||||
);
|
||||
lastAdjWasTransparent = adjTransparent;
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
|
||||
|
||||
if (inputAboveAdjLods)
|
||||
{
|
||||
// clean up the array before the next thread uses it
|
||||
// (may be unnecessary since we only work between the yMin-yMax anyway, but is helpful for debugging)
|
||||
Arrays.fill(skyLightAtInputPos, yMin, yMax, SKYLIGHT_EMPTY);
|
||||
// the input LOD is above all adjacent LODs and won't be affected
|
||||
// by them, add the vertical quad using the input's lighting and height
|
||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, ySize, color, irisBlockMaterialId, skyLightTop, blockLight);
|
||||
}
|
||||
else if (previousAdjDepth != -1)
|
||||
{
|
||||
// We need to finish the last quad.
|
||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, (short) (previousAdjDepth - yMin), color, irisBlockMaterialId, nextTopSkyLight, blockLight);
|
||||
}
|
||||
}
|
||||
private static void tryAddVerticalFaceWithSkyLightToBuilder(
|
||||
LodQuadBuilder builder, EDhDirection direction,
|
||||
short x, short z, short horizontalWidth,
|
||||
int color, byte irisBlockMaterialId, byte blockLight,
|
||||
byte lastSkyLight, boolean inputTransparent, int quadTopY, int quadBottomY
|
||||
)
|
||||
{
|
||||
// invalid positions will have a negative skylight
|
||||
if (lastSkyLight >= 0)
|
||||
{
|
||||
// Don't add transparent vertical faces
|
||||
// unless the adjacent position is empty.
|
||||
// This is done to prevent walls between water blocks in the ocean.
|
||||
if (!inputTransparent
|
||||
|| (lastSkyLight == LodUtil.MAX_MC_LIGHT))
|
||||
{
|
||||
// don't add negative/empty height faces
|
||||
short height = (short) (quadTopY - quadBottomY);
|
||||
if (height > 0)
|
||||
{
|
||||
builder.addQuadAdj(direction, x, (short) quadBottomY, z, horizontalWidth, height, color, irisBlockMaterialId, lastSkyLight, blockLight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+83
-68
@@ -19,23 +19,23 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding;
|
||||
|
||||
import com.seibel.distanthorizons.api.DhApi;
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
||||
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.objects.StatsMap;
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
||||
import com.seibel.distanthorizons.core.util.*;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ public class ColumnRenderBuffer implements AutoCloseable
|
||||
/** Should be run on a DH thread. */
|
||||
public void uploadBuffer(LodQuadBuilder builder, EDhApiGpuUploadMethod gpuUploadMethod) throws InterruptedException
|
||||
{
|
||||
LodUtil.assertTrue(DhApi.isDhThread(), "Buffer uploading needs to be done on a DH thread to prevent locking up any MC threads.");
|
||||
LodUtil.assertTrue(Thread.currentThread().getName().startsWith(ThreadUtil.THREAD_NAME_PREFIX), "Buffer uploading needs to be done on a DH thread to prevent locking up any MC threads.");
|
||||
|
||||
|
||||
// upload on MC's render thread
|
||||
@@ -100,7 +100,7 @@ public class ColumnRenderBuffer implements AutoCloseable
|
||||
{
|
||||
try
|
||||
{
|
||||
this.uploadBuffers(builder, gpuUploadMethod);
|
||||
this.uploadBuffersUsingUploadMethod(builder, gpuUploadMethod);
|
||||
uploadFuture.complete(null);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
@@ -126,46 +126,72 @@ public class ColumnRenderBuffer implements AutoCloseable
|
||||
//LOGGER.warn("Error uploading builder ["+builder+"] synchronously. Error: "+e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
private void uploadBuffers(LodQuadBuilder builder, EDhApiGpuUploadMethod method) throws InterruptedException
|
||||
private void uploadBuffersUsingUploadMethod(LodQuadBuilder builder, EDhApiGpuUploadMethod gpuUploadMethod) throws InterruptedException
|
||||
{
|
||||
// uploading mapped buffers used to be done here,
|
||||
// however due to a memory leak and complication with the previous code,
|
||||
// now we only allow direct uploading.
|
||||
// (There's also insufficient data to state whether mapped buffers are necessary
|
||||
// for DH to upload without stuttering the main thread)
|
||||
|
||||
this.vbos = makeAndUploadBuffers(builder, method, this.vbos, builder.makeOpaqueVertexBuffers());
|
||||
this.vbosTransparent = makeAndUploadBuffers(builder, method, this.vbosTransparent, builder.makeTransparentVertexBuffers());
|
||||
if (gpuUploadMethod.useEarlyMapping)
|
||||
{
|
||||
this.uploadBuffersMapped(builder, gpuUploadMethod);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.uploadBuffersDirect(builder, gpuUploadMethod);
|
||||
}
|
||||
|
||||
this.buffersUploaded = true;
|
||||
}
|
||||
/** This resizes and returns the vbo array if necessary based on the amount of data needed for this area. */
|
||||
private static GLVertexBuffer[] makeAndUploadBuffers(LodQuadBuilder builder, EDhApiGpuUploadMethod method, GLVertexBuffer[] vbos, ArrayList<ByteBuffer> buffers) throws InterruptedException
|
||||
|
||||
|
||||
|
||||
private void uploadBuffersMapped(LodQuadBuilder builder, EDhApiGpuUploadMethod method)
|
||||
{
|
||||
try
|
||||
// opaque vbos //
|
||||
|
||||
this.vbos = ColumnRenderBufferBuilder.resizeBuffer(this.vbos, builder.getCurrentNeededOpaqueVertexBufferCount());
|
||||
for (int i = 0; i < this.vbos.length; i++)
|
||||
{
|
||||
vbos = resizeBuffer(vbos, buffers.size());
|
||||
uploadBuffersDirect(vbos, buffers, method);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// all the buffers must be manually freed to prevent memory leaks
|
||||
if (buffers != null)
|
||||
if (this.vbos[i] == null)
|
||||
{
|
||||
for (ByteBuffer buffer : buffers)
|
||||
{
|
||||
MemoryUtil.memFree(buffer);
|
||||
}
|
||||
this.vbos[i] = new GLVertexBuffer(method.useBufferStorage);
|
||||
}
|
||||
}
|
||||
LodQuadBuilder.BufferFiller func = builder.makeOpaqueBufferFiller(method);
|
||||
for (GLVertexBuffer vbo : this.vbos)
|
||||
{
|
||||
func.fill(vbo);
|
||||
}
|
||||
|
||||
// return the array in case it was resized
|
||||
return vbos;
|
||||
|
||||
// transparent vbos //
|
||||
|
||||
this.vbosTransparent = ColumnRenderBufferBuilder.resizeBuffer(this.vbosTransparent, builder.getCurrentNeededTransparentVertexBufferCount());
|
||||
for (int i = 0; i < this.vbosTransparent.length; i++)
|
||||
{
|
||||
if (this.vbosTransparent[i] == null)
|
||||
{
|
||||
this.vbosTransparent[i] = new GLVertexBuffer(method.useBufferStorage);
|
||||
}
|
||||
}
|
||||
LodQuadBuilder.BufferFiller transparentFillerFunc = builder.makeTransparentBufferFiller(method);
|
||||
for (GLVertexBuffer vbo : this.vbosTransparent)
|
||||
{
|
||||
transparentFillerFunc.fill(vbo);
|
||||
}
|
||||
}
|
||||
private static void uploadBuffersDirect(GLVertexBuffer[] vbos, ArrayList<ByteBuffer> byteBuffers, EDhApiGpuUploadMethod method) throws InterruptedException
|
||||
|
||||
private void uploadBuffersDirect(LodQuadBuilder builder, EDhApiGpuUploadMethod method) throws InterruptedException
|
||||
{
|
||||
this.vbos = ColumnRenderBufferBuilder.resizeBuffer(this.vbos, builder.getCurrentNeededOpaqueVertexBufferCount());
|
||||
uploadBuffersDirect(this.vbos, builder.makeOpaqueVertexBuffers(), method);
|
||||
|
||||
this.vbosTransparent = ColumnRenderBufferBuilder.resizeBuffer(this.vbosTransparent, builder.getCurrentNeededTransparentVertexBufferCount());
|
||||
uploadBuffersDirect(this.vbosTransparent, builder.makeTransparentVertexBuffers(), method);
|
||||
}
|
||||
private static void uploadBuffersDirect(GLVertexBuffer[] vbos, Iterator<ByteBuffer> iter, EDhApiGpuUploadMethod method) throws InterruptedException
|
||||
{
|
||||
long remainingMS = 0;
|
||||
long MBPerMS = Config.Client.Advanced.GpuBuffers.gpuUploadPerMegabyteInMilliseconds.get();
|
||||
int vboIndex = 0;
|
||||
for (int i = 0; i < byteBuffers.size(); i++)
|
||||
while (iter.hasNext())
|
||||
{
|
||||
if (vboIndex >= vbos.length)
|
||||
{
|
||||
@@ -181,13 +207,13 @@ public class ColumnRenderBuffer implements AutoCloseable
|
||||
GLVertexBuffer vbo = vbos[vboIndex];
|
||||
|
||||
|
||||
ByteBuffer buffer = byteBuffers.get(i);
|
||||
int size = buffer.limit() - buffer.position();
|
||||
ByteBuffer bb = iter.next();
|
||||
int size = bb.limit() - bb.position();
|
||||
|
||||
try
|
||||
{
|
||||
vbo.bind();
|
||||
vbo.uploadBuffer(buffer, size / LodUtil.LOD_VERTEX_FORMAT.getByteSize(), method, FULL_SIZED_BUFFER);
|
||||
vbo.uploadBuffer(bb, size / LodUtil.LOD_VERTEX_FORMAT.getByteSize(), method, FULL_SIZED_BUFFER);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -196,6 +222,24 @@ public class ColumnRenderBuffer implements AutoCloseable
|
||||
LOGGER.error("Failed to upload buffer: ", e);
|
||||
}
|
||||
|
||||
|
||||
if (MBPerMS > 0)
|
||||
{
|
||||
// upload buffers over an extended period of time
|
||||
// to hopefully prevent stuttering.
|
||||
remainingMS += size * MBPerMS;
|
||||
if (remainingMS >= TimeUnit.NANOSECONDS.convert(1000 / 60, TimeUnit.MILLISECONDS))
|
||||
{
|
||||
if (remainingMS > MAX_BUFFER_UPLOAD_TIMEOUT_NANOSECONDS)
|
||||
{
|
||||
remainingMS = MAX_BUFFER_UPLOAD_TIMEOUT_NANOSECONDS;
|
||||
}
|
||||
|
||||
Thread.sleep(remainingMS / 1000000, (int) (remainingMS % 1000000));
|
||||
remainingMS = 0;
|
||||
}
|
||||
}
|
||||
|
||||
vboIndex++;
|
||||
}
|
||||
|
||||
@@ -274,9 +318,9 @@ public class ColumnRenderBuffer implements AutoCloseable
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// helper methods //
|
||||
//================//
|
||||
//==============//
|
||||
// misc methods //
|
||||
//==============//
|
||||
|
||||
/** can be used when debugging */
|
||||
public boolean hasNonNullVbos() { return this.vbos != null || this.vbosTransparent != null; }
|
||||
@@ -322,35 +366,6 @@ public class ColumnRenderBuffer implements AutoCloseable
|
||||
}
|
||||
}
|
||||
|
||||
public static GLVertexBuffer[] resizeBuffer(GLVertexBuffer[] vbos, int newSize)
|
||||
{
|
||||
if (vbos.length == newSize)
|
||||
{
|
||||
return vbos;
|
||||
}
|
||||
|
||||
GLVertexBuffer[] newVbos = new GLVertexBuffer[newSize];
|
||||
System.arraycopy(vbos, 0, newVbos, 0, Math.min(vbos.length, newSize));
|
||||
if (newSize < vbos.length)
|
||||
{
|
||||
for (int i = newSize; i < vbos.length; i++)
|
||||
{
|
||||
if (vbos[i] != null)
|
||||
{
|
||||
vbos[i].close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return newVbos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// base overrides //
|
||||
//================//
|
||||
|
||||
/**
|
||||
* This method is called when object is no longer in use.
|
||||
* Called either after uploadBuffers() returned false (On buffer Upload
|
||||
|
||||
+124
-301
@@ -19,7 +19,6 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiDebugRendering;
|
||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
@@ -27,16 +26,15 @@ import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
||||
import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException;
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -61,21 +59,21 @@ public class ColumnRenderBufferBuilder
|
||||
// vbo building //
|
||||
//==============//
|
||||
|
||||
public static CompletableFuture<LodQuadBuilder> buildBuffersAsync(
|
||||
public static CompletableFuture<ColumnRenderBuffer> buildAndUploadBuffersAsync(
|
||||
IDhClientLevel clientLevel,
|
||||
ColumnRenderSource renderSource, ColumnRenderSource[] adjData, boolean[] isSameDetailLevel
|
||||
)
|
||||
ColumnRenderSource renderSource, ColumnRenderSource[] adjData)
|
||||
{
|
||||
ThreadPoolExecutor bufferBuilderExecutor = ThreadPoolUtil.getBufferBuilderExecutor();
|
||||
if (bufferBuilderExecutor == null || bufferBuilderExecutor.isTerminated())
|
||||
ThreadPoolExecutor bufferUploaderExecutor = ThreadPoolUtil.getBufferUploaderExecutor();
|
||||
if ((bufferBuilderExecutor == null || bufferBuilderExecutor.isTerminated()) ||
|
||||
(bufferUploaderExecutor == null || bufferUploaderExecutor.isTerminated()))
|
||||
{
|
||||
// one or more of the thread pools has been shut down
|
||||
CompletableFuture<LodQuadBuilder> future = new CompletableFuture<>();
|
||||
CompletableFuture<ColumnRenderBuffer> future = new CompletableFuture<>();
|
||||
future.cancel(true);
|
||||
return future;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
@@ -83,8 +81,16 @@ public class ColumnRenderBufferBuilder
|
||||
try
|
||||
{
|
||||
boolean enableTransparency = Config.Client.Advanced.Graphics.Quality.transparency.get().transparencyEnabled;
|
||||
|
||||
long builderStartTime = System.currentTimeMillis();
|
||||
|
||||
LodQuadBuilder builder = new LodQuadBuilder(enableTransparency, clientLevel.getClientLevelWrapper());
|
||||
makeLodRenderData(builder, renderSource, clientLevel, adjData, isSameDetailLevel);
|
||||
makeLodRenderData(builder, renderSource, adjData);
|
||||
|
||||
long builderEndTime = System.currentTimeMillis();
|
||||
long buildMs = builderEndTime - builderStartTime;
|
||||
//LOGGER.debug("RenderRegion end QuadBuild @ " + renderSource.pos + " took: " + buildMs);
|
||||
|
||||
return builder;
|
||||
}
|
||||
catch (UncheckedInterruptedException e)
|
||||
@@ -93,42 +99,11 @@ public class ColumnRenderBufferBuilder
|
||||
}
|
||||
catch (Throwable e3)
|
||||
{
|
||||
LOGGER.error("LodNodeBufferBuilder was unable to build quads for pos ["+DhSectionPos.toString(renderSource.pos)+"], error: ["+ e3.getMessage()+"].", e3);
|
||||
LOGGER.error("\"LodNodeBufferBuilder\" was unable to build quads: ", e3);
|
||||
throw e3;
|
||||
}
|
||||
}, bufferBuilderExecutor);
|
||||
}
|
||||
catch (RejectedExecutionException ignore)
|
||||
{
|
||||
// the thread pool was probably shut down because it's size is being changed, just wait a sec and it should be back
|
||||
|
||||
CompletableFuture<LodQuadBuilder> future = new CompletableFuture<>();
|
||||
future.cancel(true);
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
||||
/** @link adjData should be null for adjacent sections that cross detail level boundaries */
|
||||
public static CompletableFuture<ColumnRenderBuffer> uploadBuffersAsync(
|
||||
IDhClientLevel clientLevel,
|
||||
ColumnRenderSource renderSource,
|
||||
LodQuadBuilder quadBuilder
|
||||
)
|
||||
{
|
||||
// TODO put into a single future/thread so it can be easily canceled
|
||||
ThreadPoolExecutor bufferUploaderExecutor = ThreadPoolUtil.getBufferUploaderExecutor();
|
||||
if (bufferUploaderExecutor == null || bufferUploaderExecutor.isTerminated())
|
||||
{
|
||||
// one or more of the thread pools has been shut down
|
||||
CompletableFuture<ColumnRenderBuffer> future = new CompletableFuture<>();
|
||||
future.cancel(true);
|
||||
return future;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
}, bufferBuilderExecutor)
|
||||
.thenApplyAsync((quadBuilder) ->
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -136,15 +111,8 @@ public class ColumnRenderBufferBuilder
|
||||
try
|
||||
{
|
||||
buffer.uploadBuffer(quadBuilder, GLProxy.getInstance().getGpuUploadMethod());
|
||||
if (buffer.buffersUploaded)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.close();
|
||||
return null;
|
||||
}
|
||||
LodUtil.assertTrue(buffer.buffersUploaded);
|
||||
return buffer;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -158,38 +126,35 @@ public class ColumnRenderBufferBuilder
|
||||
}
|
||||
catch (Throwable e3)
|
||||
{
|
||||
LOGGER.error("LodNodeBufferBuilder was unable to upload buffer for pos ["+DhSectionPos.toString(renderSource.pos)+"], error: [" + e3.getMessage() + "].", e3);
|
||||
LOGGER.error("LodNodeBufferBuilder was unable to upload buffer: " + e3.getMessage(), e3);
|
||||
throw e3;
|
||||
}
|
||||
}, bufferUploaderExecutor);
|
||||
}
|
||||
catch (RejectedExecutionException ignore)
|
||||
{
|
||||
// shouldn't happen, but just in case
|
||||
// the thread pool was probably shut down because it's size is being changed, just wait a sec and it should be back
|
||||
|
||||
CompletableFuture<ColumnRenderBuffer> future = new CompletableFuture<>();
|
||||
future.cancel(true);
|
||||
return future;
|
||||
}
|
||||
}
|
||||
private static void makeLodRenderData(
|
||||
LodQuadBuilder quadBuilder, ColumnRenderSource renderSource, IDhClientLevel clientLevel,
|
||||
ColumnRenderSource[] adjRegions, boolean[] isSameDetailLevel)
|
||||
private static void makeLodRenderData(LodQuadBuilder quadBuilder, ColumnRenderSource renderSource, ColumnRenderSource[] adjRegions)
|
||||
{
|
||||
//=============//
|
||||
// debug check //
|
||||
//=============//
|
||||
// Variable initialization
|
||||
EDhApiDebugRendering debugMode = Config.Client.Advanced.Debugging.debugRendering.get();
|
||||
|
||||
// can be used to limit which section positions are build and thus, rendered
|
||||
// useful when debugging a specific section
|
||||
boolean columnBuilderDebugEnabled = Config.Client.Advanced.Debugging.columnBuilderDebugEnable.get();
|
||||
if (columnBuilderDebugEnabled)
|
||||
boolean enableColumnBufferLimit = Config.Client.Advanced.Debugging.columnBuilderDebugEnable.get();
|
||||
if (enableColumnBufferLimit)
|
||||
{
|
||||
if (DhSectionPos.getDetailLevel(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugDetailLevel.get()
|
||||
&& DhSectionPos.getX(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugXPos.get()
|
||||
&& DhSectionPos.getZ(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugZPos.get())
|
||||
{
|
||||
int breakpoint = 0;
|
||||
int test = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -197,22 +162,24 @@ public class ColumnRenderBufferBuilder
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===================//
|
||||
// build each column //
|
||||
//===================//
|
||||
|
||||
byte thisDetailLevel = renderSource.getDataDetailLevel();
|
||||
for (int relX = 0; relX < ColumnRenderSource.SECTION_SIZE; relX++)
|
||||
byte detailLevel = renderSource.getDataDetailLevel();
|
||||
for (int x = 0; x < ColumnRenderSource.SECTION_SIZE; x++)
|
||||
{
|
||||
for (int relZ = 0; relZ < ColumnRenderSource.SECTION_SIZE; relZ++)
|
||||
for (int z = 0; z < ColumnRenderSource.SECTION_SIZE; z++)
|
||||
{
|
||||
// stop the builder if requested
|
||||
// TODO make a config for this
|
||||
// can be uncommented to limit the buffer building to a specific
|
||||
// relative position in this section.
|
||||
// useful for debugging a single column's rendering
|
||||
// if (x != 0 || (z != 0 && z != 1))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
|
||||
UncheckedInterruptedException.throwIfInterrupted();
|
||||
|
||||
// ignore empty/null columns
|
||||
ColumnArrayView columnRenderData = renderSource.getVerticalDataPointView(relX, relZ);
|
||||
ColumnArrayView columnRenderData = renderSource.getVerticalDataPointView(x, z);
|
||||
if (columnRenderData.size() == 0
|
||||
|| !RenderDataPointUtil.doesDataPointExist(columnRenderData.get(0))
|
||||
|| RenderDataPointUtil.isVoid(columnRenderData.get(0)))
|
||||
@@ -220,66 +187,43 @@ public class ColumnRenderBufferBuilder
|
||||
continue;
|
||||
}
|
||||
|
||||
ColumnRenderSource.DebugSourceFlag debugSourceFlag = renderSource.debugGetFlag(x, z);
|
||||
|
||||
ColumnArrayView[][] adjColumnViews = new ColumnArrayView[4][];
|
||||
// We extract the adj data in the four cardinal direction
|
||||
|
||||
// we first reset the adjShadeDisabled. This is used to disable the shade on the
|
||||
// border when we have transparent block like water or glass
|
||||
// to avoid having a "darker border" underground
|
||||
// Arrays.fill(adjShadeDisabled, false);
|
||||
|
||||
|
||||
//=============//
|
||||
// debug limit //
|
||||
//=============//
|
||||
// We check every adj block in each direction
|
||||
|
||||
// can be used to limit the buffer building to a specific relative position.
|
||||
// useful for debugging a single column
|
||||
if (columnBuilderDebugEnabled)
|
||||
{
|
||||
int wantedX = Config.Client.Advanced.Debugging.columnBuilderDebugXRow.get();
|
||||
if (wantedX >= 0 && relX != wantedX)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int wantedZ = Config.Client.Advanced.Debugging.columnBuilderDebugZRow.get();
|
||||
if (wantedZ >= 0 && relZ != wantedZ)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================//
|
||||
// get adjacent render data columns //
|
||||
//==================================//
|
||||
|
||||
ColumnArrayView[] adjColumnViews = new ColumnArrayView[EDhDirection.ADJ_DIRECTIONS.length];
|
||||
// If the adj block is rendered in the same region and with same detail
|
||||
// and is positioned in a place that is not going to be rendered by vanilla game
|
||||
// then we can set this position as adj
|
||||
// We avoid cases where the adjPosition is in player chunk while the position is
|
||||
// not
|
||||
// to always have a wall underwater
|
||||
for (EDhDirection lodDirection : EDhDirection.ADJ_DIRECTIONS)
|
||||
{
|
||||
try
|
||||
{
|
||||
int xAdj = relX + lodDirection.getNormal().x;
|
||||
int zAdj = relZ + lodDirection.getNormal().z;
|
||||
boolean isCrossRenderSourceBoundary =
|
||||
int xAdj = x + lodDirection.getNormal().x;
|
||||
int zAdj = z + lodDirection.getNormal().z;
|
||||
boolean isCrossRegionBoundary =
|
||||
(xAdj < 0 || xAdj >= ColumnRenderSource.SECTION_SIZE) ||
|
||||
(zAdj < 0 || zAdj >= ColumnRenderSource.SECTION_SIZE);
|
||||
(zAdj < 0 || zAdj >= ColumnRenderSource.SECTION_SIZE);
|
||||
|
||||
ColumnRenderSource adjRenderSource;
|
||||
byte adjDetailLevel;
|
||||
|
||||
|
||||
|
||||
//=========================//
|
||||
// get the adjacent render //
|
||||
// source if present //
|
||||
//=========================//
|
||||
|
||||
if (!isCrossRenderSourceBoundary)
|
||||
//we check if the detail of the adjPos is equal to the correct one (region border fix)
|
||||
//or if the detail is wrong by 1 value (region+circle border fix)
|
||||
if (isCrossRegionBoundary)
|
||||
{
|
||||
// the adjacent position is inside this same render source
|
||||
adjRenderSource = renderSource;
|
||||
adjDetailLevel = thisDetailLevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the adjacent position is outside this render source
|
||||
|
||||
// skip empty sections
|
||||
//we compute at which detail that position should be rendered
|
||||
adjRenderSource = adjRegions[lodDirection.ordinal() - 2];
|
||||
if (adjRenderSource == null)
|
||||
{
|
||||
@@ -287,70 +231,67 @@ public class ColumnRenderBufferBuilder
|
||||
}
|
||||
|
||||
adjDetailLevel = adjRenderSource.getDataDetailLevel();
|
||||
if (adjDetailLevel == thisDetailLevel)
|
||||
if (adjDetailLevel != detailLevel)
|
||||
{
|
||||
//TODO: Implement this
|
||||
}
|
||||
else
|
||||
{
|
||||
// if the adjacent position is outside this render source,
|
||||
// wrap the position around so it's inside the adjacent source
|
||||
|
||||
if (xAdj < 0)
|
||||
{
|
||||
xAdj += ColumnRenderSource.SECTION_SIZE;
|
||||
}
|
||||
if (xAdj >= ColumnRenderSource.SECTION_SIZE)
|
||||
{
|
||||
xAdj -= ColumnRenderSource.SECTION_SIZE;
|
||||
}
|
||||
|
||||
if (zAdj < 0)
|
||||
{
|
||||
zAdj += ColumnRenderSource.SECTION_SIZE;
|
||||
}
|
||||
|
||||
if (xAdj >= ColumnRenderSource.SECTION_SIZE)
|
||||
xAdj -= ColumnRenderSource.SECTION_SIZE;
|
||||
|
||||
if (zAdj >= ColumnRenderSource.SECTION_SIZE)
|
||||
{
|
||||
zAdj -= ColumnRenderSource.SECTION_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
adjRenderSource = renderSource;
|
||||
adjDetailLevel = detailLevel;
|
||||
}
|
||||
|
||||
if (adjDetailLevel < detailLevel - 1 || adjDetailLevel > detailLevel + 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
//========================//
|
||||
// get the adjacent views //
|
||||
//========================//
|
||||
|
||||
// the old logic handled additional cases, but they never appeared to fire,
|
||||
// so just these two cases should be fine
|
||||
LodUtil.assertTrue(adjDetailLevel == thisDetailLevel || adjDetailLevel > thisDetailLevel);
|
||||
|
||||
adjColumnViews[lodDirection.ordinal() - 2] = adjRenderSource.getVerticalDataPointView(xAdj, zAdj);
|
||||
if (adjDetailLevel == detailLevel || adjDetailLevel > detailLevel)
|
||||
{
|
||||
adjColumnViews[lodDirection.ordinal() - 2] = new ColumnArrayView[1];
|
||||
adjColumnViews[lodDirection.ordinal() - 2][0] = adjRenderSource.getVerticalDataPointView(xAdj, zAdj);
|
||||
}
|
||||
else
|
||||
{
|
||||
adjColumnViews[lodDirection.ordinal() - 2] = new ColumnArrayView[2];
|
||||
adjColumnViews[lodDirection.ordinal() - 2][0] = adjRenderSource.getVerticalDataPointView(xAdj, zAdj);
|
||||
adjColumnViews[lodDirection.ordinal() - 2][1] = adjRenderSource.getVerticalDataPointView(
|
||||
xAdj + (lodDirection.getAxis() == EDhDirection.Axis.X ? 0 : 1),
|
||||
zAdj + (lodDirection.getAxis() == EDhDirection.Axis.Z ? 0 : 1));
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
EVENT_LOGGER.warn("Failed to get adj data for relative pos: [" + thisDetailLevel + ":" + relX + "," + relZ + "] at [" + lodDirection + "], Error: "+e.getMessage(), e);
|
||||
EVENT_LOGGER.warn("Failed to get adj data for [" + detailLevel + ":" + x + "," + z + "] at [" + lodDirection + "], Error: "+e.getMessage(), e);
|
||||
}
|
||||
} // for adjacent directions
|
||||
|
||||
|
||||
|
||||
//==========================//
|
||||
// build this render column //
|
||||
//==========================//
|
||||
|
||||
ColumnRenderSource.DebugSourceFlag debugSourceFlag = renderSource.debugGetFlag(relX, relZ);
|
||||
|
||||
// We render every vertical lod present in this position
|
||||
// We only stop when we find a block that is void or non-existing block
|
||||
for (int i = 0; i < columnRenderData.size(); i++)
|
||||
{
|
||||
// TODO make a config for this
|
||||
// can be uncommented to limit which vertical LOD is generated
|
||||
if (Config.Client.Advanced.Debugging.columnBuilderDebugEnable.get())
|
||||
{
|
||||
int wantedColumnIndex = Config.Client.Advanced.Debugging.columnBuilderDebugColumnIndex.get();
|
||||
if (wantedColumnIndex >= 0 && i != wantedColumnIndex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// if (i != 0)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
long data = columnRenderData.get(i);
|
||||
// If the data is not render-able (Void or non-existing) we stop since there is
|
||||
@@ -363,12 +304,8 @@ public class ColumnRenderBufferBuilder
|
||||
long topDataPoint = (i - 1) >= 0 ? columnRenderData.get(i - 1) : RenderDataPointUtil.EMPTY_DATA;
|
||||
long bottomDataPoint = (i + 1) < columnRenderData.size() ? columnRenderData.get(i + 1) : RenderDataPointUtil.EMPTY_DATA;
|
||||
|
||||
addLodToBuffer(
|
||||
clientLevel,
|
||||
data, topDataPoint, bottomDataPoint,
|
||||
adjColumnViews, isSameDetailLevel,
|
||||
thisDetailLevel, relX, relZ,
|
||||
quadBuilder, debugSourceFlag);
|
||||
CubicLodTemplate.addLodToBuffer(data, topDataPoint, bottomDataPoint, adjColumnViews, detailLevel,
|
||||
x, z, quadBuilder, debugMode, debugSourceFlag);
|
||||
}
|
||||
|
||||
}// for z
|
||||
@@ -376,147 +313,33 @@ public class ColumnRenderBufferBuilder
|
||||
|
||||
quadBuilder.finalizeData();
|
||||
}
|
||||
private static void addLodToBuffer(
|
||||
IDhClientLevel clientLevel,
|
||||
long data, long topData, long bottomData,
|
||||
ColumnArrayView[] adjColumnViews, boolean[] isSameDetailLevel,
|
||||
byte detailLevel, int renderSourceOffsetPosX, int renderSourceOffsetPosZ,
|
||||
LodQuadBuilder quadBuilder, ColumnRenderSource.DebugSourceFlag debugSource)
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// vbo interaction //
|
||||
//=================//
|
||||
|
||||
public static GLVertexBuffer[] resizeBuffer(GLVertexBuffer[] vbos, int newSize)
|
||||
{
|
||||
long sectionPos = DhSectionPos.encode(detailLevel, renderSourceOffsetPosX, renderSourceOffsetPosZ);
|
||||
|
||||
short width = (short) BitShiftUtil.powerOfTwo(detailLevel);
|
||||
short x = (short) DhSectionPos.getMinCornerBlockX(sectionPos);
|
||||
short yMin = RenderDataPointUtil.getYMin(data);
|
||||
short z = (short) DhSectionPos.getMinCornerBlockZ(sectionPos);
|
||||
short ySize = (short) (RenderDataPointUtil.getYMax(data) - yMin);
|
||||
|
||||
if (ySize == 0)
|
||||
if (vbos.length == newSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (ySize < 0)
|
||||
{
|
||||
throw new IllegalArgumentException("Negative y size for the data! Data: [" + RenderDataPointUtil.toString(data) + "].");
|
||||
return vbos;
|
||||
}
|
||||
|
||||
byte blockMaterialId = RenderDataPointUtil.getBlockMaterialId(data);
|
||||
|
||||
|
||||
|
||||
int color;
|
||||
boolean fullBright = false;
|
||||
EDhApiDebugRendering debugging = Config.Client.Advanced.Debugging.debugRendering.get();
|
||||
switch (debugging)
|
||||
GLVertexBuffer[] newVbos = new GLVertexBuffer[newSize];
|
||||
System.arraycopy(vbos, 0, newVbos, 0, Math.min(vbos.length, newSize));
|
||||
if (newSize < vbos.length)
|
||||
{
|
||||
case OFF:
|
||||
for (int i = newSize; i < vbos.length; i++)
|
||||
{
|
||||
float saturationMultiplier = Config.Client.Advanced.Graphics.AdvancedGraphics.saturationMultiplier.get().floatValue();
|
||||
float brightnessMultiplier = Config.Client.Advanced.Graphics.AdvancedGraphics.brightnessMultiplier.get().floatValue();
|
||||
if (saturationMultiplier == 1.0 && brightnessMultiplier == 1.0)
|
||||
if (vbos[i] != null)
|
||||
{
|
||||
color = RenderDataPointUtil.getColor(data);
|
||||
vbos[i].close();
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] ahsv = ColorUtil.argbToAhsv(RenderDataPointUtil.getColor(data));
|
||||
color = ColorUtil.ahsvToArgb(ahsv[0], ahsv[1], ahsv[2] * saturationMultiplier, ahsv[3] * brightnessMultiplier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SHOW_DETAIL:
|
||||
{
|
||||
color = LodUtil.DEBUG_DETAIL_LEVEL_COLORS[detailLevel];
|
||||
fullBright = true;
|
||||
break;
|
||||
}
|
||||
case SHOW_BLOCK_MATERIAL:
|
||||
{
|
||||
|
||||
switch (EDhApiBlockMaterial.getFromIndex(blockMaterialId))
|
||||
{
|
||||
case UNKNOWN:
|
||||
case AIR: // shouldn't normally be rendered, but just in case
|
||||
color = ColorUtil.HOT_PINK;
|
||||
break;
|
||||
|
||||
case LEAVES:
|
||||
color = ColorUtil.DARK_GREEN;
|
||||
break;
|
||||
case STONE:
|
||||
color = ColorUtil.GRAY;
|
||||
break;
|
||||
case WOOD:
|
||||
color = ColorUtil.BROWN;
|
||||
break;
|
||||
case METAL:
|
||||
color = ColorUtil.DARK_GRAY;
|
||||
break;
|
||||
case DIRT:
|
||||
color = ColorUtil.LIGHT_BROWN;
|
||||
break;
|
||||
case LAVA:
|
||||
color = ColorUtil.ORANGE;
|
||||
break;
|
||||
case DEEPSLATE:
|
||||
color = ColorUtil.BLACK;
|
||||
break;
|
||||
case SNOW:
|
||||
color = ColorUtil.WHITE;
|
||||
break;
|
||||
case SAND:
|
||||
color = ColorUtil.TAN;
|
||||
break;
|
||||
case TERRACOTTA:
|
||||
color = ColorUtil.DARK_ORANGE;
|
||||
break;
|
||||
case NETHER_STONE:
|
||||
color = ColorUtil.DARK_RED;
|
||||
break;
|
||||
case WATER:
|
||||
color = ColorUtil.BLUE;
|
||||
break;
|
||||
case GRASS:
|
||||
color = ColorUtil.GREEN;
|
||||
break;
|
||||
case ILLUMINATED:
|
||||
color = ColorUtil.YELLOW;
|
||||
break;
|
||||
|
||||
default:
|
||||
// undefined color
|
||||
color = ColorUtil.CYAN;
|
||||
break;
|
||||
}
|
||||
|
||||
fullBright = true;
|
||||
break;
|
||||
}
|
||||
case SHOW_OVERLAPPING_QUADS:
|
||||
{
|
||||
color = ColorUtil.WHITE;
|
||||
fullBright = true;
|
||||
break;
|
||||
}
|
||||
case SHOW_RENDER_SOURCE_FLAG:
|
||||
{
|
||||
color = debugSource == null ? ColorUtil.RED : debugSource.color;
|
||||
fullBright = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown debug mode: " + debugging);
|
||||
}
|
||||
|
||||
ColumnBox.addBoxQuadsToBuilder(
|
||||
quadBuilder, clientLevel,
|
||||
width, ySize, width,
|
||||
x, yMin, z,
|
||||
color,
|
||||
blockMaterialId,
|
||||
RenderDataPointUtil.getLightSky(data),
|
||||
fullBright ? 15 : RenderDataPointUtil.getLightBlock(data),
|
||||
topData, bottomData, adjColumnViews, isSameDetailLevel);
|
||||
return newVbos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
||||
import com.seibel.distanthorizons.core.pos.DhLodPos;
|
||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiDebugRendering;
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||
|
||||
/**
|
||||
* Builds LODs as rectangular prisms.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-1-2
|
||||
*/
|
||||
public class CubicLodTemplate
|
||||
{
|
||||
|
||||
public static void addLodToBuffer(
|
||||
long data, long topData, long bottomData, ColumnArrayView[][] adjColumnViews,
|
||||
byte detailLevel, int offsetPosX, int offsetOosZ, LodQuadBuilder quadBuilder,
|
||||
EDhApiDebugRendering debugging, ColumnRenderSource.DebugSourceFlag debugSource)
|
||||
{
|
||||
DhLodPos blockOffsetPos = new DhLodPos(detailLevel, offsetPosX, offsetOosZ).convertToDetailLevel(LodUtil.BLOCK_DETAIL_LEVEL);
|
||||
|
||||
short width = (short) BitShiftUtil.powerOfTwo(detailLevel);
|
||||
short x = (short) blockOffsetPos.x;
|
||||
short yMin = RenderDataPointUtil.getYMin(data);
|
||||
short z = (short) (short) blockOffsetPos.z;
|
||||
short ySize = (short) (RenderDataPointUtil.getYMax(data) - yMin);
|
||||
|
||||
if (ySize == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (ySize < 0)
|
||||
{
|
||||
throw new IllegalArgumentException("Negative y size for the data! Data: " + RenderDataPointUtil.toString(data));
|
||||
}
|
||||
|
||||
byte blockMaterialId = RenderDataPointUtil.getBlockMaterialId(data);
|
||||
|
||||
|
||||
|
||||
int color;
|
||||
boolean fullBright = false;
|
||||
switch (debugging)
|
||||
{
|
||||
case OFF:
|
||||
{
|
||||
float saturationMultiplier = Config.Client.Advanced.Graphics.AdvancedGraphics.saturationMultiplier.get().floatValue();
|
||||
float brightnessMultiplier = Config.Client.Advanced.Graphics.AdvancedGraphics.brightnessMultiplier.get().floatValue();
|
||||
if (saturationMultiplier == 1.0 && brightnessMultiplier == 1.0)
|
||||
{
|
||||
color = RenderDataPointUtil.getColor(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] ahsv = ColorUtil.argbToAhsv(RenderDataPointUtil.getColor(data));
|
||||
color = ColorUtil.ahsvToArgb(ahsv[0], ahsv[1], ahsv[2] * saturationMultiplier, ahsv[3] * brightnessMultiplier);
|
||||
//ApiShared.LOGGER.info("Raw color:[{}], AHSV:{}, Out color:[{}]",
|
||||
// ColorUtil.toString(DataPointUtil.getColor(data)),
|
||||
// ahsv, ColorUtil.toString(color));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SHOW_DETAIL:
|
||||
{
|
||||
color = LodUtil.DEBUG_DETAIL_LEVEL_COLORS[detailLevel];
|
||||
fullBright = true;
|
||||
break;
|
||||
}
|
||||
case SHOW_BLOCK_MATERIAL:
|
||||
{
|
||||
|
||||
color = switch (EDhApiBlockMaterial.getFromIndex(blockMaterialId))
|
||||
{
|
||||
case UNKNOWN, AIR -> // shouldn't normally be rendered, but just in case
|
||||
ColorUtil.HOT_PINK;
|
||||
case LEAVES -> ColorUtil.DARK_GREEN;
|
||||
case STONE -> ColorUtil.GRAY;
|
||||
case WOOD -> ColorUtil.BROWN;
|
||||
case METAL -> ColorUtil.DARK_GRAY;
|
||||
case DIRT -> ColorUtil.LIGHT_BROWN;
|
||||
case LAVA -> ColorUtil.ORANGE;
|
||||
case DEEPSLATE -> ColorUtil.BLACK;
|
||||
case SNOW -> ColorUtil.WHITE;
|
||||
case SAND -> ColorUtil.TAN;
|
||||
case TERRACOTTA -> ColorUtil.DARK_ORANGE;
|
||||
case NETHER_STONE -> ColorUtil.DARK_RED;
|
||||
case WATER -> ColorUtil.BLUE;
|
||||
case GRASS -> ColorUtil.GREEN;
|
||||
case ILLUMINATED -> ColorUtil.YELLOW;
|
||||
default ->
|
||||
// undefined color
|
||||
ColorUtil.CYAN;
|
||||
};
|
||||
|
||||
fullBright = true;
|
||||
break;
|
||||
}
|
||||
case SHOW_OVERLAPPING_QUADS:
|
||||
{
|
||||
color = ColorUtil.WHITE;
|
||||
fullBright = true;
|
||||
break;
|
||||
}
|
||||
case SHOW_RENDER_SOURCE_FLAG:
|
||||
{
|
||||
color = debugSource == null ? ColorUtil.RED : debugSource.color;
|
||||
fullBright = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown debug mode: " + debugging);
|
||||
}
|
||||
|
||||
ColumnBox.addBoxQuadsToBuilder(
|
||||
quadBuilder, // buffer
|
||||
width, ySize, width, // setWidth
|
||||
x, yMin, z, // setOffset
|
||||
color, // setColor
|
||||
blockMaterialId, // irisBlockMaterialId
|
||||
RenderDataPointUtil.getLightSky(data), // setSkyLights
|
||||
fullBright ? 15 : RenderDataPointUtil.getLightBlock(data), // setBlockLights
|
||||
topData, bottomData, adjColumnViews); // setAdjData
|
||||
}
|
||||
|
||||
}
|
||||
+419
-128
@@ -38,7 +38,8 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftCli
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
//TODO: Recheck this class for refactoring
|
||||
|
||||
/**
|
||||
* Used to create the quads before they are converted to render-able buffers. <br><br>
|
||||
@@ -50,6 +51,11 @@ public class LodQuadBuilder
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
|
||||
@Deprecated
|
||||
public final boolean skipQuadsWithZeroSkylight;
|
||||
@Deprecated
|
||||
public final short skyLightCullingBelow;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final ArrayList<BufferQuad>[] opaqueQuads = (ArrayList<BufferQuad>[]) new ArrayList[6];
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -128,6 +134,8 @@ public class LodQuadBuilder
|
||||
this.transparentQuads[i] = new ArrayList<>();
|
||||
}
|
||||
|
||||
this.skipQuadsWithZeroSkylight = false;
|
||||
this.skyLightCullingBelow = 0;
|
||||
this.clientLevelWrapper = clientLevelWrapper;
|
||||
|
||||
this.debugRenderingMode = Config.Client.Advanced.Debugging.debugRendering.get();
|
||||
@@ -151,12 +159,17 @@ public class LodQuadBuilder
|
||||
throw new IllegalArgumentException("addQuadAdj() is only for adj direction! Not UP or Down!");
|
||||
}
|
||||
|
||||
if (this.skipQuadsWithZeroSkylight && skyLight == 0 && y + widthNorthSouthOrUpDown < this.skyLightCullingBelow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BufferQuad quad = new BufferQuad(x, y, z, widthEastWest, widthNorthSouthOrUpDown, color, irisBlockMaterialId, skyLight, blockLight, dir);
|
||||
ArrayList<BufferQuad> quadList = (this.doTransparency && ColorUtil.getAlpha(color) < 255) ? this.transparentQuads[dir.ordinal()] : this.opaqueQuads[dir.ordinal()];
|
||||
if (!quadList.isEmpty() &&
|
||||
(
|
||||
quadList.get(quadList.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.EastWest)
|
||||
|| quadList.get(quadList.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown))
|
||||
quadList.getLast().tryMerge(quad, BufferMergeDirectionEnum.EastWest)
|
||||
|| quadList.getLast().tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown))
|
||||
)
|
||||
{
|
||||
this.premergeCount++;
|
||||
@@ -169,6 +182,12 @@ public class LodQuadBuilder
|
||||
// XZ
|
||||
public void addQuadUp(short x, short maxY, short z, short widthEastWest, short widthNorthSouthOrUpDown, int color, byte irisBlockMaterialId, byte skylight, byte blocklight) // TODO argument names are wrong
|
||||
{
|
||||
// cave culling
|
||||
if (this.skipQuadsWithZeroSkylight && skylight == 0 && maxY < this.skyLightCullingBelow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BufferQuad quad = new BufferQuad(x, maxY, z, widthEastWest, widthNorthSouthOrUpDown, color, irisBlockMaterialId, skylight, blocklight, EDhDirection.UP);
|
||||
boolean isTransparent = (this.doTransparency && ColorUtil.getAlpha(color) < 255);
|
||||
ArrayList<BufferQuad> quadList = isTransparent ? this.transparentQuads[EDhDirection.UP.ordinal()] : this.opaqueQuads[EDhDirection.UP.ordinal()];
|
||||
@@ -177,8 +196,8 @@ public class LodQuadBuilder
|
||||
// attempt to merge this quad with adjacent ones
|
||||
if (!quadList.isEmpty() &&
|
||||
(
|
||||
quadList.get(quadList.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.EastWest)
|
||||
|| quadList.get(quadList.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown))
|
||||
quadList.getLast().tryMerge(quad, BufferMergeDirectionEnum.EastWest)
|
||||
|| quadList.getLast().tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown))
|
||||
)
|
||||
{
|
||||
this.premergeCount++;
|
||||
@@ -190,13 +209,15 @@ public class LodQuadBuilder
|
||||
|
||||
public void addQuadDown(short x, short y, short z, short width, short wz, int color, byte irisBlockMaterialId, byte skylight, byte blocklight)
|
||||
{
|
||||
if (skipQuadsWithZeroSkylight && skylight == 0 && y < skyLightCullingBelow)
|
||||
return;
|
||||
BufferQuad quad = new BufferQuad(x, y, z, width, wz, color, irisBlockMaterialId, skylight, blocklight, EDhDirection.DOWN);
|
||||
ArrayList<BufferQuad> qs = (doTransparency && ColorUtil.getAlpha(color) < 255)
|
||||
? transparentQuads[EDhDirection.DOWN.ordinal()] : opaqueQuads[EDhDirection.DOWN.ordinal()];
|
||||
if (!qs.isEmpty()
|
||||
&& (qs.get(qs.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.EastWest)
|
||||
|| qs.get(qs.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown))
|
||||
)
|
||||
if (!qs.isEmpty() &&
|
||||
(qs.getLast().tryMerge(quad, BufferMergeDirectionEnum.EastWest)
|
||||
|| qs.getLast().tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown))
|
||||
)
|
||||
{
|
||||
premergeCount++;
|
||||
return;
|
||||
@@ -206,124 +227,10 @@ public class LodQuadBuilder
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// data finalizing //
|
||||
//=================//
|
||||
|
||||
/** runs any final data cleanup, merging, etc. */
|
||||
public void finalizeData() { this.mergeQuads(); }
|
||||
|
||||
/** Uses Greedy meshing to merge this builder's Quads. */
|
||||
public void mergeQuads()
|
||||
{
|
||||
long mergeCount = 0; // can be used for debugging
|
||||
long preQuadsCount = this.getCurrentOpaqueQuadsCount() + this.getCurrentTransparentQuadsCount();
|
||||
if (preQuadsCount <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int directionIndex = 0; directionIndex < 6; directionIndex++)
|
||||
{
|
||||
mergeCount += mergeQuadsInternal(this.opaqueQuads, directionIndex, BufferMergeDirectionEnum.EastWest);
|
||||
if (this.doTransparency)
|
||||
{
|
||||
mergeCount += mergeQuadsInternal(this.transparentQuads, directionIndex, BufferMergeDirectionEnum.EastWest);
|
||||
}
|
||||
|
||||
|
||||
// only run the second merge if the face is the top or bottom
|
||||
if (directionIndex == EDhDirection.UP.ordinal() || directionIndex == EDhDirection.DOWN.ordinal())
|
||||
{
|
||||
mergeCount += mergeQuadsInternal(this.opaqueQuads, directionIndex, BufferMergeDirectionEnum.NorthSouthOrUpDown);
|
||||
if (this.doTransparency)
|
||||
{
|
||||
mergeCount += mergeQuadsInternal(this.transparentQuads, directionIndex, BufferMergeDirectionEnum.NorthSouthOrUpDown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//long postQuadsCount = this.getCurrentOpaqueQuadsCount() + this.getCurrentTransparentQuadsCount();
|
||||
//LOGGER.trace("Merged "+mergeCount+"/"+preQuadsCount+"("+(mergeCount / (double) preQuadsCount)+") quads");
|
||||
}
|
||||
|
||||
/** Merges all of this builder's quads for the given directionIndex (up, down, left, etc.) in the given direction */
|
||||
private static long mergeQuadsInternal(ArrayList<BufferQuad>[] list, int directionIndex, BufferMergeDirectionEnum mergeDirection)
|
||||
{
|
||||
if (list[directionIndex].size() <= 1)
|
||||
return 0;
|
||||
|
||||
list[directionIndex].sort((objOne, objTwo) -> objOne.compare(objTwo, mergeDirection));
|
||||
|
||||
long mergeCount = 0;
|
||||
ListIterator<BufferQuad> iter = list[directionIndex].listIterator();
|
||||
BufferQuad currentQuad = iter.next();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
BufferQuad nextQuad = iter.next();
|
||||
|
||||
if (currentQuad.tryMerge(nextQuad, mergeDirection))
|
||||
{
|
||||
// merge successful, attempt to merge the next quad
|
||||
mergeCount++;
|
||||
iter.set(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
// merge fail, move on to the next quad
|
||||
currentQuad = nextQuad;
|
||||
}
|
||||
}
|
||||
list[directionIndex].removeIf(Objects::isNull);
|
||||
return mergeCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// buffer setup //
|
||||
// add vertices //
|
||||
//==============//
|
||||
|
||||
public ArrayList<ByteBuffer> makeOpaqueVertexBuffers() { return this.makeVertexBuffers(this.opaqueQuads); }
|
||||
public ArrayList<ByteBuffer> makeTransparentVertexBuffers() { return this.makeVertexBuffers(this.transparentQuads); }
|
||||
private ArrayList<ByteBuffer> makeVertexBuffers(ArrayList<BufferQuad>[] quadList)
|
||||
{
|
||||
ArrayList<ByteBuffer> byteBufferList = new ArrayList<>(3);
|
||||
|
||||
ByteBuffer buffer = null;
|
||||
for (int directionIndex = 0; directionIndex < 6; directionIndex++)
|
||||
{
|
||||
// ignore empty directions
|
||||
if (quadList[directionIndex].isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// put all the quads in this direction into the buffer
|
||||
for (int quadIndex = 0; quadIndex < quadList[directionIndex].size(); quadIndex++)
|
||||
{
|
||||
// if this is the first iteration or the buffer is full,
|
||||
// create a new buffer
|
||||
if (buffer == null || !buffer.hasRemaining())
|
||||
{
|
||||
buffer = MemoryUtil.memAlloc(ColumnRenderBuffer.FULL_SIZED_BUFFER);
|
||||
byteBufferList.add(buffer);
|
||||
}
|
||||
|
||||
this.putQuad(buffer, quadList[directionIndex].get(quadIndex));
|
||||
}
|
||||
}
|
||||
|
||||
// rewind all the buffers so they can be read from
|
||||
for (int i = 0; i < byteBufferList.size(); i++)
|
||||
{
|
||||
buffer = byteBufferList.get(i);
|
||||
buffer.limit(buffer.position());
|
||||
buffer.rewind();
|
||||
}
|
||||
|
||||
return byteBufferList;
|
||||
}
|
||||
private void putQuad(ByteBuffer bb, BufferQuad quad)
|
||||
{
|
||||
int[][] quadBase = DIRECTION_VERTEX_IBO_QUAD[quad.direction.ordinal()];
|
||||
@@ -381,10 +288,10 @@ public class LodQuadBuilder
|
||||
if (quad.direction.getAxis().isHorizontal() || quad.direction == EDhDirection.DOWN)
|
||||
{
|
||||
if (this.grassSideRenderingMode == EDhApiGrassSideRendering.AS_DIRT
|
||||
// if we want the color to fade, only apply the dirt color to the bottom vertices
|
||||
|| (this.grassSideRenderingMode == EDhApiGrassSideRendering.FADE_TO_DIRT && quadBase[i][1] == 0)
|
||||
// always render the bottom as dirt
|
||||
|| quad.direction == EDhDirection.DOWN)
|
||||
// if we want the color to fade, only apply the dirt color to the bottom vertices
|
||||
|| (this.grassSideRenderingMode == EDhApiGrassSideRendering.FADE_TO_DIRT && quadBase[i][1] == 0)
|
||||
// always render the bottom as dirt
|
||||
|| quad.direction == EDhDirection.DOWN)
|
||||
{
|
||||
// for horizontal and bottom faces of grass blocks, use the dirt color to
|
||||
// prevent green cliff walls
|
||||
@@ -406,6 +313,7 @@ public class LodQuadBuilder
|
||||
mx, my, mz);
|
||||
}
|
||||
}
|
||||
|
||||
private void putVertex(ByteBuffer bb, short x, short y, short z, int color, byte normalIndex, byte irisBlockMaterialId, byte skylight, byte blocklight, int mx, int my, int mz)
|
||||
{
|
||||
skylight %= 16;
|
||||
@@ -446,6 +354,389 @@ public class LodQuadBuilder
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// data finalizing //
|
||||
//=================//
|
||||
|
||||
/** runs any final data cleanup, merging, etc. */
|
||||
public void finalizeData() { this.mergeQuads(); }
|
||||
|
||||
/** Uses Greedy meshing to merge this builder's Quads. */
|
||||
public void mergeQuads()
|
||||
{
|
||||
long mergeCount = 0;
|
||||
long preQuadsCount = this.getCurrentOpaqueQuadsCount() + this.getCurrentTransparentQuadsCount();
|
||||
if (preQuadsCount <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int directionIndex = 0; directionIndex < 6; directionIndex++)
|
||||
{
|
||||
mergeCount += mergeQuadsInternal(this.opaqueQuads, directionIndex, BufferMergeDirectionEnum.EastWest);
|
||||
if (this.doTransparency)
|
||||
{
|
||||
mergeCount += mergeQuadsInternal(this.transparentQuads, directionIndex, BufferMergeDirectionEnum.EastWest);
|
||||
}
|
||||
|
||||
|
||||
// only run the second merge if the face is the top or bottom
|
||||
if (directionIndex == EDhDirection.UP.ordinal() || directionIndex == EDhDirection.DOWN.ordinal())
|
||||
{
|
||||
mergeCount += mergeQuadsInternal(this.opaqueQuads, directionIndex, BufferMergeDirectionEnum.NorthSouthOrUpDown);
|
||||
if (this.doTransparency)
|
||||
{
|
||||
mergeCount += mergeQuadsInternal(this.transparentQuads, directionIndex, BufferMergeDirectionEnum.NorthSouthOrUpDown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long postQuadsCount = this.getCurrentOpaqueQuadsCount() + this.getCurrentTransparentQuadsCount();
|
||||
LOGGER.debug("Merged "+mergeCount+"/"+preQuadsCount+"("+(mergeCount / (double) preQuadsCount)+") quads");
|
||||
}
|
||||
|
||||
/** Merges all of this builder's quads for the given directionIndex (up, down, left, etc.) in the given direction */
|
||||
private static long mergeQuadsInternal(ArrayList<BufferQuad>[] list, int directionIndex, BufferMergeDirectionEnum mergeDirection)
|
||||
{
|
||||
if (list[directionIndex].size() <= 1)
|
||||
return 0;
|
||||
|
||||
list[directionIndex].sort((objOne, objTwo) -> objOne.compare(objTwo, mergeDirection));
|
||||
|
||||
long mergeCount = 0;
|
||||
ListIterator<BufferQuad> iter = list[directionIndex].listIterator();
|
||||
BufferQuad currentQuad = iter.next();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
BufferQuad nextQuad = iter.next();
|
||||
|
||||
if (currentQuad.tryMerge(nextQuad, mergeDirection))
|
||||
{
|
||||
// merge successful, attempt to merge the next quad
|
||||
mergeCount++;
|
||||
iter.set(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
// merge fail, move on to the next quad
|
||||
currentQuad = nextQuad;
|
||||
}
|
||||
}
|
||||
list[directionIndex].removeIf(Objects::isNull);
|
||||
return mergeCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// buffer setup //
|
||||
//==============//
|
||||
|
||||
public Iterator<ByteBuffer> makeOpaqueVertexBuffers()
|
||||
{
|
||||
return new Iterator<>()
|
||||
{
|
||||
final ByteBuffer bb = ByteBuffer.allocateDirect(ColumnRenderBuffer.FULL_SIZED_BUFFER)
|
||||
.order(ByteOrder.nativeOrder());
|
||||
int dir = skipEmpty(0);
|
||||
int quad = 0;
|
||||
|
||||
private int skipEmpty(int d)
|
||||
{
|
||||
while (d < 6 && opaqueQuads[d].isEmpty())
|
||||
{
|
||||
d++;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return dir < 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer next()
|
||||
{
|
||||
if (dir >= 6)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
bb.clear();
|
||||
bb.limit(ColumnRenderBuffer.FULL_SIZED_BUFFER);
|
||||
while (bb.hasRemaining() && dir < 6)
|
||||
{
|
||||
writeData();
|
||||
}
|
||||
bb.limit(bb.position());
|
||||
bb.rewind();
|
||||
return bb;
|
||||
}
|
||||
|
||||
private void writeData()
|
||||
{
|
||||
int i = quad;
|
||||
for (; i < opaqueQuads[dir].size(); i++)
|
||||
{
|
||||
if (!bb.hasRemaining())
|
||||
{
|
||||
break;
|
||||
}
|
||||
putQuad(bb, opaqueQuads[dir].get(i));
|
||||
}
|
||||
|
||||
if (i >= opaqueQuads[dir].size())
|
||||
{
|
||||
quad = 0;
|
||||
dir++;
|
||||
dir = skipEmpty(dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
quad = i;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Iterator<ByteBuffer> makeTransparentVertexBuffers()
|
||||
{
|
||||
return new Iterator<>()
|
||||
{
|
||||
final ByteBuffer bb = ByteBuffer.allocateDirect(ColumnRenderBuffer.FULL_SIZED_BUFFER)
|
||||
.order(ByteOrder.nativeOrder());
|
||||
int directionIndex = this.skipEmptyDirectionIndices(0);
|
||||
int quad = 0;
|
||||
|
||||
private int skipEmptyDirectionIndices(int directionIndex)
|
||||
{
|
||||
while (directionIndex < 6 &&
|
||||
(LodQuadBuilder.this.transparentQuads[directionIndex] == null
|
||||
|| LodQuadBuilder.this.transparentQuads[directionIndex].isEmpty()))
|
||||
{
|
||||
directionIndex++;
|
||||
}
|
||||
|
||||
return directionIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() { return this.directionIndex < 6; }
|
||||
|
||||
@Override
|
||||
public ByteBuffer next()
|
||||
{
|
||||
if (this.directionIndex >= 6)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
this.bb.clear();
|
||||
this.bb.limit(ColumnRenderBuffer.FULL_SIZED_BUFFER);
|
||||
while (this.bb.hasRemaining() && this.directionIndex < 6)
|
||||
{
|
||||
this.writeData();
|
||||
}
|
||||
this.bb.limit(this.bb.position());
|
||||
this.bb.rewind();
|
||||
return this.bb;
|
||||
}
|
||||
|
||||
private void writeData()
|
||||
{
|
||||
int i = this.quad;
|
||||
for (; i < LodQuadBuilder.this.transparentQuads[this.directionIndex].size(); i++)
|
||||
{
|
||||
if (!this.bb.hasRemaining())
|
||||
{
|
||||
break;
|
||||
}
|
||||
putQuad(this.bb, LodQuadBuilder.this.transparentQuads[this.directionIndex].get(i));
|
||||
}
|
||||
|
||||
if (i >= LodQuadBuilder.this.transparentQuads[this.directionIndex].size())
|
||||
{
|
||||
this.quad = 0;
|
||||
this.directionIndex++;
|
||||
this.directionIndex = this.skipEmptyDirectionIndices(this.directionIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.quad = i;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
public interface BufferFiller
|
||||
{
|
||||
/** If true: more data needs to be filled */
|
||||
boolean fill(GLVertexBuffer vbo);
|
||||
|
||||
}
|
||||
|
||||
public BufferFiller makeOpaqueBufferFiller(EDhApiGpuUploadMethod method)
|
||||
{
|
||||
return new BufferFiller()
|
||||
{
|
||||
int dir = 0;
|
||||
int quad = 0;
|
||||
|
||||
public boolean fill(GLVertexBuffer vbo)
|
||||
{
|
||||
if (dir >= 6)
|
||||
{
|
||||
vbo.setVertexCount(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
int numOfQuads = _countRemainingQuads();
|
||||
if (numOfQuads > ColumnRenderBuffer.MAX_QUADS_PER_BUFFER)
|
||||
numOfQuads = ColumnRenderBuffer.MAX_QUADS_PER_BUFFER;
|
||||
if (numOfQuads == 0)
|
||||
{
|
||||
vbo.setVertexCount(0);
|
||||
return false;
|
||||
}
|
||||
ByteBuffer bb = vbo.mapBuffer(numOfQuads * ColumnRenderBuffer.QUADS_BYTE_SIZE, method,
|
||||
ColumnRenderBuffer.FULL_SIZED_BUFFER);
|
||||
if (bb == null)
|
||||
throw new NullPointerException("mapBuffer returned null");
|
||||
bb.clear();
|
||||
bb.limit(numOfQuads * ColumnRenderBuffer.QUADS_BYTE_SIZE);
|
||||
while (bb.hasRemaining() && dir < 6)
|
||||
{
|
||||
writeData(bb);
|
||||
}
|
||||
bb.rewind();
|
||||
vbo.unmapBuffer();
|
||||
vbo.setVertexCount(numOfQuads * 4);
|
||||
return dir < 6;
|
||||
}
|
||||
|
||||
private int _countRemainingQuads()
|
||||
{
|
||||
int a = opaqueQuads[dir].size() - quad;
|
||||
for (int i = dir + 1; i < opaqueQuads.length; i++)
|
||||
{
|
||||
a += opaqueQuads[i].size();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private void writeData(ByteBuffer bb)
|
||||
{
|
||||
int startQ = quad;
|
||||
|
||||
int i = startQ;
|
||||
for (i = startQ; i < opaqueQuads[dir].size(); i++)
|
||||
{
|
||||
if (!bb.hasRemaining())
|
||||
{
|
||||
break;
|
||||
}
|
||||
putQuad(bb, opaqueQuads[dir].get(i));
|
||||
}
|
||||
|
||||
if (i >= opaqueQuads[dir].size())
|
||||
{
|
||||
quad = 0;
|
||||
dir++;
|
||||
while (dir < 6 && opaqueQuads[dir].isEmpty())
|
||||
{
|
||||
dir++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
quad = i;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public BufferFiller makeTransparentBufferFiller(EDhApiGpuUploadMethod method)
|
||||
{
|
||||
return new BufferFiller()
|
||||
{
|
||||
int dir = 0;
|
||||
int quad = 0;
|
||||
|
||||
public boolean fill(GLVertexBuffer vbo)
|
||||
{
|
||||
if (dir >= 6)
|
||||
{
|
||||
vbo.setVertexCount(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
int numOfQuads = _countRemainingQuads();
|
||||
if (numOfQuads > ColumnRenderBuffer.MAX_QUADS_PER_BUFFER)
|
||||
numOfQuads = ColumnRenderBuffer.MAX_QUADS_PER_BUFFER;
|
||||
if (numOfQuads == 0)
|
||||
{
|
||||
vbo.setVertexCount(0);
|
||||
return false;
|
||||
}
|
||||
ByteBuffer bb = vbo.mapBuffer(numOfQuads * ColumnRenderBuffer.QUADS_BYTE_SIZE, method,
|
||||
ColumnRenderBuffer.FULL_SIZED_BUFFER);
|
||||
if (bb == null)
|
||||
throw new NullPointerException("mapBuffer returned null");
|
||||
bb.clear();
|
||||
bb.limit(numOfQuads * ColumnRenderBuffer.QUADS_BYTE_SIZE);
|
||||
while (bb.hasRemaining() && dir < 6)
|
||||
{
|
||||
writeData(bb);
|
||||
}
|
||||
bb.rewind();
|
||||
vbo.unmapBuffer();
|
||||
vbo.setVertexCount(numOfQuads * 4);
|
||||
return dir < 6;
|
||||
}
|
||||
|
||||
private int _countRemainingQuads()
|
||||
{
|
||||
int a = transparentQuads[dir].size() - quad;
|
||||
for (int i = dir + 1; i < transparentQuads.length; i++)
|
||||
{
|
||||
a += transparentQuads[i].size();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private void writeData(ByteBuffer bb)
|
||||
{
|
||||
int startQ = quad;
|
||||
|
||||
int i = startQ;
|
||||
for (i = startQ; i < transparentQuads[dir].size(); i++)
|
||||
{
|
||||
if (!bb.hasRemaining())
|
||||
{
|
||||
break;
|
||||
}
|
||||
putQuad(bb, transparentQuads[dir].get(i));
|
||||
}
|
||||
|
||||
if (i >= transparentQuads[dir].size())
|
||||
{
|
||||
quad = 0;
|
||||
dir++;
|
||||
while (dir < 6 && transparentQuads[dir].isEmpty())
|
||||
{
|
||||
dir++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
quad = i;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// getters //
|
||||
//=========//
|
||||
|
||||
+23
-50
@@ -20,7 +20,6 @@
|
||||
package com.seibel.distanthorizons.core.dataObjects.render.columnViews;
|
||||
|
||||
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
||||
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
|
||||
@@ -29,60 +28,41 @@ import java.util.Arrays;
|
||||
public final class ColumnArrayView implements IColumnDataView
|
||||
{
|
||||
public final LongArrayList data;
|
||||
|
||||
/**
|
||||
* How many data points are currently being represented by this view. <br>
|
||||
* Will be equal to or less than {@link ColumnArrayView#verticalSize}.
|
||||
*/
|
||||
public final int size;
|
||||
/**
|
||||
* Vertical size in data points. <Br>
|
||||
* Can be 0 if this column was created for an empty data source.
|
||||
*/
|
||||
public final int verticalSize;
|
||||
|
||||
/**
|
||||
* Where the relative starting index is in the {@link ColumnArrayView#data} array
|
||||
* if this view is representing part of a {@link ColumnRenderSource}.
|
||||
*/
|
||||
public final int offset;
|
||||
public final int offset; // offset in longs
|
||||
/** can be 0 if this column was created for an empty data source */
|
||||
public final int vertSize; // vertical size in longs
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
public ColumnArrayView(LongArrayList data, int size, int offset, int verticalSize)
|
||||
public ColumnArrayView(LongArrayList data, int size, int offset, int vertSize)
|
||||
{
|
||||
this.data = data;
|
||||
this.size = size;
|
||||
this.offset = offset;
|
||||
this.verticalSize = verticalSize;
|
||||
this.vertSize = vertSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=====================//
|
||||
// getters and setters //
|
||||
//=====================//
|
||||
|
||||
@Override
|
||||
public long get(int index) { return data.getLong(index + offset); }
|
||||
|
||||
public void set(int index, long value) { data.set(index + offset, value); }
|
||||
|
||||
@Override
|
||||
public int size() { return size; }
|
||||
@Override
|
||||
public int verticalSize() { return verticalSize; }
|
||||
|
||||
@Override
|
||||
public int dataCount() { return (this.verticalSize != 0) ? (this.size / this.verticalSize) : 0; } // TODO what does the divide by mean?
|
||||
public int verticalSize() { return vertSize; }
|
||||
|
||||
@Override
|
||||
public int dataCount() { return (this.vertSize != 0) ? (this.size / this.vertSize) : 0; }
|
||||
|
||||
@Override
|
||||
public ColumnArrayView subView(int dataIndexStart, int dataCount)
|
||||
{
|
||||
return new ColumnArrayView(data, dataCount * verticalSize, offset + dataIndexStart * verticalSize, verticalSize);
|
||||
return new ColumnArrayView(data, dataCount * vertSize, offset + dataIndexStart * vertSize, vertSize);
|
||||
}
|
||||
|
||||
public void fill(long value) { Arrays.fill(data.elements(), offset, offset + size, value); }
|
||||
@@ -90,7 +70,7 @@ public final class ColumnArrayView implements IColumnDataView
|
||||
public void copyFrom(IColumnDataView source) { copyFrom(source, 0); }
|
||||
public void copyFrom(IColumnDataView source, int outputDataIndexOffset)
|
||||
{
|
||||
if (source.verticalSize() > verticalSize)
|
||||
if (source.verticalSize() > vertSize)
|
||||
{
|
||||
throw new IllegalArgumentException("source verticalSize must be <= self's verticalSize to copy");
|
||||
}
|
||||
@@ -98,19 +78,19 @@ public final class ColumnArrayView implements IColumnDataView
|
||||
{
|
||||
throw new IllegalArgumentException("dataIndexStart + source.dataCount() must be <= self.dataCount() to copy");
|
||||
}
|
||||
else if (source.verticalSize() != verticalSize)
|
||||
else if (source.verticalSize() != vertSize)
|
||||
{
|
||||
for (int i = 0; i < source.dataCount(); i++)
|
||||
{
|
||||
int outputOffset = offset + outputDataIndexOffset * verticalSize + i * verticalSize;
|
||||
int outputOffset = offset + outputDataIndexOffset * vertSize + i * vertSize;
|
||||
source.subView(i, 1).copyTo(data.elements(), outputOffset, source.verticalSize());
|
||||
Arrays.fill(data.elements(), outputOffset + source.verticalSize(),
|
||||
outputOffset + verticalSize, 0);
|
||||
outputOffset + vertSize, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
source.copyTo(data.elements(), offset + outputDataIndexOffset * verticalSize, source.size());
|
||||
source.copyTo(data.elements(), offset + outputDataIndexOffset * vertSize, source.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,19 +103,19 @@ public final class ColumnArrayView implements IColumnDataView
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot merge views of different sizes");
|
||||
}
|
||||
if (verticalSize != source.verticalSize)
|
||||
if (vertSize != source.vertSize)
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot merge views of different vertical sizes");
|
||||
}
|
||||
boolean anyChange = false;
|
||||
for (int o = 0; o < (source.size() * verticalSize); o += verticalSize)
|
||||
for (int o = 0; o < (source.size() * vertSize); o += vertSize)
|
||||
{
|
||||
if (override)
|
||||
{
|
||||
if (RenderDataPointUtil.compareDatapointPriority(source.get(o), get(o)) >= 0)
|
||||
{
|
||||
anyChange = true;
|
||||
System.arraycopy(source.data, source.offset + o, data, offset + o, verticalSize);
|
||||
System.arraycopy(source.data, source.offset + o, data, offset + o, vertSize);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -143,7 +123,7 @@ public final class ColumnArrayView implements IColumnDataView
|
||||
if (RenderDataPointUtil.compareDatapointPriority(source.get(o), get(o)) > 0)
|
||||
{
|
||||
anyChange = true;
|
||||
System.arraycopy(source.data, source.offset + o, data, offset + o, verticalSize);
|
||||
System.arraycopy(source.data, source.offset + o, data, offset + o, vertSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +137,7 @@ public final class ColumnArrayView implements IColumnDataView
|
||||
throw new IllegalArgumentException("Cannot copy and resize to views with different dataCounts");
|
||||
}
|
||||
|
||||
if (this.verticalSize >= source.verticalSize())
|
||||
if (this.vertSize >= source.verticalSize())
|
||||
{
|
||||
this.copyFrom(source);
|
||||
}
|
||||
@@ -180,18 +160,12 @@ public final class ColumnArrayView implements IColumnDataView
|
||||
RenderDataPointUtil.mergeMultiData(source, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// base overrides //
|
||||
//================//
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("S:").append(size);
|
||||
sb.append(" V:").append(verticalSize);
|
||||
sb.append(" V:").append(vertSize);
|
||||
sb.append(" O:").append(offset);
|
||||
|
||||
sb.append(" [");
|
||||
@@ -208,7 +182,6 @@ public final class ColumnArrayView implements IColumnDataView
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public int getDataHash()
|
||||
{
|
||||
return arrayHash(data, offset, size);
|
||||
@@ -226,7 +199,7 @@ public final class ColumnArrayView implements IColumnDataView
|
||||
for (int i = offset; i < end; i++)
|
||||
{
|
||||
long element = a.getLong(i);
|
||||
int elementHash = (int) (element ^ (element >>> 32));
|
||||
int elementHash = Long.hashCode(element);
|
||||
result = 31 * result + elementHash;
|
||||
}
|
||||
return result;
|
||||
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.core.dataObjects.transformers;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
public class ChunkToLodBuilder implements AutoCloseable
|
||||
{
|
||||
public static final ConfigBasedLogger LOGGER = new ConfigBasedLogger(LogManager.getLogger(), () -> Config.Client.Advanced.Logging.logLodBuilderEvent.get());
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
|
||||
public static final long MAX_TICK_TIME_NS = 1000000000L / 20L;
|
||||
|
||||
private final ConcurrentHashMap<DhChunkPos, IChunkWrapper> concurrentChunkToBuildByChunkPos = new ConcurrentHashMap<>();
|
||||
private final ConcurrentLinkedDeque<Task> concurrentTaskToBuildList = new ConcurrentLinkedDeque<>();
|
||||
private final AtomicInteger runningCount = new AtomicInteger(0);
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
public ChunkToLodBuilder() { }
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// data generation //
|
||||
//=================//
|
||||
|
||||
public CompletableFuture<FullDataSourceV2> tryGenerateData(IChunkWrapper chunkWrapper)
|
||||
{
|
||||
if (chunkWrapper == null)
|
||||
{
|
||||
throw new NullPointerException("ChunkWrapper cannot be null!");
|
||||
}
|
||||
|
||||
IChunkWrapper oldChunk = this.concurrentChunkToBuildByChunkPos.put(chunkWrapper.getChunkPos(), chunkWrapper); // an Exchange operation
|
||||
// If there's old chunk, that means we just replaced an unprocessed old request on generating data on this pos.
|
||||
// if so, we can just return null to signal this, as the old request's future will instead be the proper one
|
||||
// that will return the latest generated data.
|
||||
if (oldChunk != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Otherwise, it means we're the first to do so. Let's submit our task to this entry.
|
||||
CompletableFuture<FullDataSourceV2> future = new CompletableFuture<>();
|
||||
this.concurrentTaskToBuildList.addLast(new Task(chunkWrapper.getChunkPos(), future));
|
||||
return future;
|
||||
}
|
||||
|
||||
// TODO why on tick?
|
||||
public void tick()
|
||||
{
|
||||
int threadCount = ThreadPoolUtil.getWorkerThreadCount();
|
||||
if (this.runningCount.get() >= threadCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (this.concurrentTaskToBuildList.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (MC == null || !MC.playerExists())
|
||||
{
|
||||
// TODO handle server side properly
|
||||
|
||||
// MC hasn't finished loading (or is currently unloaded)
|
||||
|
||||
// can be uncommented if tasks aren't being cleared correctly
|
||||
//this.clearCurrentTasks();
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadPoolExecutor lodBuilderExecutor = ThreadPoolUtil.getChunkToLodBuilderExecutor();
|
||||
if (lodBuilderExecutor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < threadCount; i++)
|
||||
{
|
||||
this.runningCount.incrementAndGet();
|
||||
try
|
||||
{
|
||||
CompletableFuture.runAsync(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
this.tickThreadTask();
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.runningCount.decrementAndGet();
|
||||
}
|
||||
}, lodBuilderExecutor);
|
||||
}
|
||||
catch (RejectedExecutionException ignore) { /* the thread pool was probably shut down because it's size is being changed, just wait a sec and it should be back */ }
|
||||
}
|
||||
}
|
||||
private void tickThreadTask()
|
||||
{
|
||||
long time = System.nanoTime();
|
||||
int count = 0;
|
||||
boolean allDone = false;
|
||||
while (true)
|
||||
{
|
||||
// run until we either run out of time, or all tasks are complete
|
||||
if (System.nanoTime() - time > MAX_TICK_TIME_NS && !this.concurrentTaskToBuildList.isEmpty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Task task = this.concurrentTaskToBuildList.pollFirst();
|
||||
if (task == null)
|
||||
{
|
||||
allDone = true;
|
||||
break;
|
||||
}
|
||||
|
||||
count++;
|
||||
IChunkWrapper latestChunk = this.concurrentChunkToBuildByChunkPos.remove(task.chunkPos); // Basically an Exchange operation
|
||||
if (latestChunk == null)
|
||||
{
|
||||
LOGGER.error("Somehow Task at " + task.chunkPos + " has latestChunk as null. Skipping task.");
|
||||
task.future.complete(null);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (LodDataBuilder.canGenerateLodFromChunk(latestChunk))
|
||||
{
|
||||
FullDataSourceV2 dataSource = LodDataBuilder.createGeneratedDataSource(latestChunk);
|
||||
if (dataSource != null)
|
||||
{
|
||||
task.future.complete(dataSource);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (task.generationAttemptExpirationTimeMs < System.currentTimeMillis())
|
||||
{
|
||||
// this task won't be re-queued
|
||||
//LOGGER.trace("removed chunk "+task.chunkPos);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOGGER.error("Error while processing Task at " + task.chunkPos, ex);
|
||||
}
|
||||
|
||||
// Failed to build due to chunk not meeting requirement,
|
||||
// re-add it to the queue so it can be tested next time
|
||||
IChunkWrapper casChunk = this.concurrentChunkToBuildByChunkPos.putIfAbsent(task.chunkPos, latestChunk); // CAS operation with expected=null
|
||||
if (casChunk == null || latestChunk.isStillValid()) // That means CAS have been successful
|
||||
{
|
||||
this.concurrentTaskToBuildList.addLast(task); // Then add back the same old task.
|
||||
}
|
||||
else // Else, it means someone managed to sneak in a new gen request in this pos. Then lets drop this old task.
|
||||
{
|
||||
task.future.complete(null);
|
||||
}
|
||||
|
||||
count--;
|
||||
}
|
||||
|
||||
long time2 = System.nanoTime();
|
||||
if (!allDone)
|
||||
{
|
||||
//LOGGER.info("Completed {} tasks in {} in this tick", count, Duration.ofNanos(time2 - time));
|
||||
}
|
||||
else if (count > 0)
|
||||
{
|
||||
//LOGGER.info("Completed all {} tasks in {}", count, Duration.ofNanos(time2 - time));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* should be called whenever changing levels/worlds
|
||||
* to prevent trying to generate LODs for chunk(s) that are no longer loaded
|
||||
* (which can cause exceptions)
|
||||
*/
|
||||
public void clearCurrentTasks()
|
||||
{
|
||||
this.concurrentTaskToBuildList.clear();
|
||||
this.concurrentChunkToBuildByChunkPos.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// base methods //
|
||||
//==============//
|
||||
|
||||
@Override
|
||||
public void close() { this.clearCurrentTasks(); }
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// helper classes //
|
||||
//================//
|
||||
|
||||
private static class Task
|
||||
{
|
||||
public final DhChunkPos chunkPos;
|
||||
public final CompletableFuture<FullDataSourceV2> future;
|
||||
/** This is tracked so impossible tasks can be removed from the queue */
|
||||
public long generationAttemptExpirationTimeMs = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
|
||||
|
||||
Task(DhChunkPos chunkPos, CompletableFuture<FullDataSourceV2> future)
|
||||
{
|
||||
this.chunkPos = chunkPos;
|
||||
this.future = future;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+43
-70
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.core.dataObjects.transformers;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiBlocksToAvoid;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||
@@ -28,7 +29,7 @@ import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArra
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
||||
@@ -38,7 +39,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -122,12 +122,7 @@ public class FullDataToRenderDataTransformer
|
||||
|
||||
ColumnArrayView columnArrayView = columnSource.getVerticalDataPointView(x, z);
|
||||
LongArrayList dataColumn = fullDataSource.get(x, z);
|
||||
|
||||
updateOrReplaceRenderDataViewColumnWithFullDataColumn(
|
||||
level, fullDataSource.mapping,
|
||||
// bitshift is to account for LODs with a detail level greater than 0 so the block pos is correct
|
||||
baseX + BitShiftUtil.pow(x,dataDetail), baseZ + BitShiftUtil.pow(z,dataDetail),
|
||||
columnArrayView, dataColumn);
|
||||
updateRenderDataViewWithFullDataColumn(level, fullDataSource.mapping, baseX + x, baseZ + z, columnArrayView, dataColumn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,48 +132,40 @@ public class FullDataToRenderDataTransformer
|
||||
}
|
||||
|
||||
/** Updates the given {@link ColumnArrayView} to match the incoming Full data {@link LongArrayList} */
|
||||
public static void updateOrReplaceRenderDataViewColumnWithFullDataColumn(
|
||||
public static void updateRenderDataViewWithFullDataColumn(
|
||||
IDhClientLevel level,
|
||||
FullDataPointIdMap fullDataMapping, int blockX, int blockZ,
|
||||
ColumnArrayView columnArrayView,
|
||||
LongArrayList fullDataColumn)
|
||||
{
|
||||
// we can't do anything if the full data is missing or empty
|
||||
if (fullDataColumn == null || fullDataColumn.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int fullDataLength = fullDataColumn.size();
|
||||
if (fullDataLength <= columnArrayView.verticalSize())
|
||||
int dataTotalLength = fullDataColumn.size();
|
||||
if (dataTotalLength > columnArrayView.verticalSize())
|
||||
{
|
||||
// Directly use the arrayView since it fits.
|
||||
setRenderColumnView(level, fullDataMapping, blockX, blockZ, columnArrayView, fullDataColumn);
|
||||
ColumnArrayView totalColumnData = new ColumnArrayView(new LongArrayList(new long[dataTotalLength]), dataTotalLength, 0, dataTotalLength);
|
||||
iterateAndConvert(level, fullDataMapping, blockX, blockZ, totalColumnData, fullDataColumn);
|
||||
columnArrayView.changeVerticalSizeFrom(totalColumnData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// expand the ColumnArrayView to fit the new larger max vertical size
|
||||
ColumnArrayView newColumnArrayView = new ColumnArrayView(new LongArrayList(new long[fullDataLength]), fullDataLength, 0, fullDataLength);
|
||||
setRenderColumnView(level, fullDataMapping, blockX, blockZ, newColumnArrayView, fullDataColumn);
|
||||
columnArrayView.changeVerticalSizeFrom(newColumnArrayView);
|
||||
iterateAndConvert(level, fullDataMapping, blockX, blockZ, columnArrayView, fullDataColumn); //Directly use the arrayView since it fits.
|
||||
}
|
||||
}
|
||||
private static void setRenderColumnView(
|
||||
private static void iterateAndConvert(
|
||||
IDhClientLevel level, FullDataPointIdMap fullDataMapping,
|
||||
int blockX, int blockZ,
|
||||
ColumnArrayView renderColumnData, LongArrayList fullColumnData)
|
||||
{
|
||||
//===============//
|
||||
// config values //
|
||||
//===============//
|
||||
|
||||
boolean ignoreNonCollidingBlocks = (Config.Client.Advanced.Graphics.Quality.blocksToIgnore.get() == EDhApiBlocksToAvoid.NON_COLLIDING);
|
||||
boolean colorBelowWithAvoidedBlocks = Config.Client.Advanced.Graphics.Quality.tintWithAvoidedBlocks.get();
|
||||
|
||||
HashSet<IBlockStateWrapper> blockStatesToIgnore = WRAPPER_FACTORY.getRendererIgnoredBlocks(level.getLevelWrapper());
|
||||
HashSet<IBlockStateWrapper> caveBlockStatesToIgnore = WRAPPER_FACTORY.getRendererIgnoredCaveBlocks(level.getLevelWrapper());
|
||||
|
||||
int caveCullingMaxY = Config.Client.Advanced.Graphics.AdvancedGraphics.caveCullingHeight.get() - level.getMinY();
|
||||
boolean caveCullingEnabled =
|
||||
Config.Client.Advanced.Graphics.AdvancedGraphics.enableCaveCulling.get()
|
||||
&& (
|
||||
@@ -189,36 +176,30 @@ public class FullDataToRenderDataTransformer
|
||||
&& !level.getLevelWrapper().getDimensionType().isTheEnd()
|
||||
);
|
||||
|
||||
boolean isColumnVoid = true;
|
||||
boolean isVoid = true;
|
||||
|
||||
int colorToApplyToNextBlock = -1;
|
||||
int lastColor = 0;
|
||||
int lastBottom = -10_000;
|
||||
int lastBottom = -10000;
|
||||
|
||||
int skylightToApplyToNextBlock = -1;
|
||||
int blocklightToApplyToNextBlock = -1;
|
||||
int renderDataIndex = 0;
|
||||
int columnOffset = 0;
|
||||
|
||||
IBiomeWrapper biome = null;
|
||||
IBlockStateWrapper block = null;
|
||||
|
||||
|
||||
//==================================//
|
||||
// convert full data to render data //
|
||||
//==================================//
|
||||
|
||||
// goes from the top down
|
||||
for (int fullDataIndex = 0; fullDataIndex < fullColumnData.size(); fullDataIndex++)
|
||||
for (int i = 0; i < fullColumnData.size(); i++)
|
||||
{
|
||||
long fullData = fullColumnData.getLong(fullDataIndex);
|
||||
|
||||
long fullData = fullColumnData.getLong(i);
|
||||
int bottomY = FullDataPointUtil.getBottomY(fullData);
|
||||
int blockHeight = FullDataPointUtil.getHeight(fullData);
|
||||
int topY = bottomY + blockHeight;
|
||||
int id = FullDataPointUtil.getId(fullData);
|
||||
int blockLight = FullDataPointUtil.getBlockLight(fullData);
|
||||
int skyLight = FullDataPointUtil.getSkyLight(fullData);
|
||||
|
||||
IBiomeWrapper biome;
|
||||
IBlockStateWrapper block;
|
||||
try
|
||||
{
|
||||
biome = fullDataMapping.getBiomeWrapper(id);
|
||||
@@ -226,10 +207,11 @@ public class FullDataToRenderDataTransformer
|
||||
}
|
||||
catch (IndexOutOfBoundsException e)
|
||||
{
|
||||
// FIXME sometimes the data map has a length of 0
|
||||
if (!brokenPos.contains(fullDataMapping.getPos()))
|
||||
{
|
||||
brokenPos.add(fullDataMapping.getPos());
|
||||
String dimName = level.getLevelWrapper().getDimensionName();
|
||||
String dimName = level.getLevelWrapper().getDimensionType().getDimensionName();
|
||||
LOGGER.warn("Unable to get data point with id ["+id+"] " +
|
||||
"(Max possible ID: ["+fullDataMapping.getMaxValidId()+"]) " +
|
||||
"for pos ["+fullDataMapping.getPos()+"] in dimension ["+dimName+"]. " +
|
||||
@@ -237,12 +219,11 @@ public class FullDataToRenderDataTransformer
|
||||
"Further errors for this position won't be logged.");
|
||||
}
|
||||
|
||||
// don't render broken data
|
||||
// skip rendering broken data
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//====================//
|
||||
// ignored block and //
|
||||
// cave culling check //
|
||||
@@ -255,25 +236,23 @@ public class FullDataToRenderDataTransformer
|
||||
if (caveCullingEnabled
|
||||
// assume this data point is underground if it has no sky-light
|
||||
&& skyLight == LodUtil.MIN_MC_LIGHT
|
||||
// ignore caves above a certain height to prevent floating islands from having walls underneath them
|
||||
&& topY < caveCullingMaxY
|
||||
// cave culling shouldn't happen when at the top of the world
|
||||
&& renderDataIndex != 0 && fullDataIndex != 0
|
||||
&& columnOffset != 0
|
||||
// cave culling can't happen when at the bottom of the world
|
||||
&& (fullDataIndex+1) < fullColumnData.size())
|
||||
&& columnOffset != fullColumnData.size())
|
||||
{
|
||||
// we need to get the next sky/block lights because
|
||||
// the air block here will always have a light of 0/0 due to only the top of the LOD's light being saved.
|
||||
long nextFullData = fullColumnData.getLong(fullDataIndex+1);
|
||||
long nextFullData = fullColumnData.getLong(i+1);
|
||||
int nextSkyLight = FullDataPointUtil.getSkyLight(nextFullData);
|
||||
|
||||
if (nextSkyLight == LodUtil.MIN_MC_LIGHT
|
||||
&& ColorUtil.getAlpha(lastColor) == 255)
|
||||
{
|
||||
// replace the previous block with new bottom
|
||||
long columnData = renderColumnData.get(renderDataIndex - 1);
|
||||
long columnData = renderColumnData.get(columnOffset - 1);
|
||||
columnData = RenderDataPointUtil.setYMin(columnData, bottomY);
|
||||
renderColumnData.set(renderDataIndex - 1, columnData);
|
||||
renderColumnData.set(columnOffset - 1, columnData);
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -293,28 +272,27 @@ public class FullDataToRenderDataTransformer
|
||||
}
|
||||
|
||||
|
||||
//===================//
|
||||
// solid block check //
|
||||
//===================//
|
||||
|
||||
//=======================//
|
||||
// non-solid block check //
|
||||
//=======================//
|
||||
|
||||
if (ignoreNonCollidingBlocks
|
||||
&& !block.isSolid() && !block.isLiquid() && block.getOpacity() != LodUtil.BLOCK_FULLY_OPAQUE)
|
||||
if (ignoreNonCollidingBlocks && !block.isSolid() && !block.isLiquid() && block.getOpacity() != LodUtil.BLOCK_FULLY_OPAQUE)
|
||||
{
|
||||
if (colorBelowWithAvoidedBlocks)
|
||||
{
|
||||
int tempColor = level.computeBaseColor(new DhBlockPos(blockX, bottomY + level.getMinY(), blockZ), biome, block);
|
||||
// don't transfer the color when alpha is 0
|
||||
// this prevents issues if grass is transparent
|
||||
if (ColorUtil.getAlpha(tempColor) != 0)
|
||||
{
|
||||
// don't transfer alpha if for some reason grass is semi transparent
|
||||
colorToApplyToNextBlock = ColorUtil.setAlpha(tempColor,255);
|
||||
|
||||
skylightToApplyToNextBlock = skyLight;
|
||||
blocklightToApplyToNextBlock = blockLight;
|
||||
}
|
||||
}
|
||||
|
||||
// skip this non-colliding block
|
||||
// don't add this block
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -334,36 +312,31 @@ public class FullDataToRenderDataTransformer
|
||||
blockLight = blocklightToApplyToNextBlock;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================//
|
||||
// merge same-colored adjacent //
|
||||
//=============================//
|
||||
|
||||
// check if they share a top-bottom face and if they have same color
|
||||
if (color == lastColor && bottomY + blockHeight == lastBottom && renderDataIndex > 0)
|
||||
//check if they share a top-bottom face and if they have same color
|
||||
if (color == lastColor && bottomY + blockHeight == lastBottom && columnOffset > 0)
|
||||
{
|
||||
//replace the previous block with new bottom
|
||||
long columnData = renderColumnData.get(renderDataIndex - 1);
|
||||
long columnData = renderColumnData.get(columnOffset - 1);
|
||||
columnData = RenderDataPointUtil.setYMin(columnData, bottomY);
|
||||
renderColumnData.set(renderDataIndex - 1, columnData);
|
||||
renderColumnData.set(columnOffset - 1, columnData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the block
|
||||
isColumnVoid = false;
|
||||
isVoid = false;
|
||||
long columnData = RenderDataPointUtil.createDataPoint(bottomY + blockHeight, bottomY, color, skyLight, blockLight, block.getMaterialId());
|
||||
renderColumnData.set(renderDataIndex, columnData);
|
||||
renderDataIndex++;
|
||||
renderColumnData.set(columnOffset, columnData);
|
||||
columnOffset++;
|
||||
}
|
||||
lastBottom = bottomY;
|
||||
lastColor = color;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (isColumnVoid)
|
||||
if (isVoid)
|
||||
{
|
||||
renderColumnData.set(0, RenderDataPointUtil.EMPTY_DATA);
|
||||
renderColumnData.set(0, RenderDataPointUtil.createVoidDataPoint());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-93
@@ -19,7 +19,6 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.dataObjects.transformers;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiWorldCompressionMode;
|
||||
@@ -31,12 +30,10 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPosMutable;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
||||
import com.seibel.distanthorizons.core.util.objects.DataCorruptedException;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
@@ -67,8 +64,8 @@ public class LodDataBuilder
|
||||
|
||||
|
||||
|
||||
int sectionPosX = getXOrZSectionPosFromChunkPos(chunkWrapper.getChunkPos().getX());
|
||||
int sectionPosZ = getXOrZSectionPosFromChunkPos(chunkWrapper.getChunkPos().getZ());
|
||||
int sectionPosX = getXOrZSectionPosFromChunkPos(chunkWrapper.getChunkPos().x);
|
||||
int sectionPosZ = getXOrZSectionPosFromChunkPos(chunkWrapper.getChunkPos().z);
|
||||
long pos = DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
|
||||
|
||||
FullDataSourceV2 dataSource = FullDataSourceV2.createEmpty(pos);
|
||||
@@ -78,8 +75,8 @@ public class LodDataBuilder
|
||||
|
||||
// compute the chunk dataSource offset
|
||||
// this offset is used to determine where in the dataSource this chunk's data should go
|
||||
int chunkOffsetX = chunkWrapper.getChunkPos().getX();
|
||||
if (chunkWrapper.getChunkPos().getX() < 0)
|
||||
int chunkOffsetX = chunkWrapper.getChunkPos().x;
|
||||
if (chunkWrapper.getChunkPos().x < 0)
|
||||
{
|
||||
// expected offset positions:
|
||||
// chunkPos -> offset
|
||||
@@ -106,8 +103,8 @@ public class LodDataBuilder
|
||||
}
|
||||
chunkOffsetX *= LodUtil.CHUNK_WIDTH;
|
||||
|
||||
int chunkOffsetZ = chunkWrapper.getChunkPos().getZ();
|
||||
if (chunkWrapper.getChunkPos().getZ() < 0)
|
||||
int chunkOffsetZ = chunkWrapper.getChunkPos().z;
|
||||
if (chunkWrapper.getChunkPos().z < 0)
|
||||
{
|
||||
chunkOffsetZ = ((chunkOffsetZ) % FullDataSourceV2.NUMB_OF_CHUNKS_WIDE);
|
||||
if (chunkOffsetZ != 0)
|
||||
@@ -155,8 +152,8 @@ public class LodDataBuilder
|
||||
else
|
||||
{
|
||||
//we are at the height limit. There are no torches here, and sky is not obscured.
|
||||
blockLight = LodUtil.MIN_MC_LIGHT;
|
||||
skyLight = LodUtil.MAX_MC_LIGHT;
|
||||
blockLight = 0;
|
||||
skyLight = 15;
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +235,7 @@ public class LodDataBuilder
|
||||
private static boolean blockVisible(IChunkWrapper chunkWrapper, int relBlockX, int blockY, int relBlockZ)
|
||||
{
|
||||
DhBlockPos originalBlockPos = new DhBlockPos(relBlockX,blockY,relBlockZ);
|
||||
final DhBlockPosMutable testBlockPos = new DhBlockPosMutable(relBlockX,blockY,relBlockZ);
|
||||
DhBlockPos testBlockPos = new DhBlockPos(relBlockX,blockY,relBlockZ);
|
||||
|
||||
// up/down
|
||||
if (blockInDirectionVisible(chunkWrapper, EDhDirection.UP, originalBlockPos, testBlockPos))
|
||||
@@ -273,20 +270,20 @@ public class LodDataBuilder
|
||||
|
||||
return false;
|
||||
}
|
||||
private static boolean blockInDirectionVisible(IChunkWrapper chunkWrapper, EDhDirection direction, DhBlockPos originalBlockPos, DhBlockPosMutable testBlockPos)
|
||||
private static boolean blockInDirectionVisible(IChunkWrapper chunkWrapper, EDhDirection direction, DhBlockPos originalBlockPos, DhBlockPos testBlockPos)
|
||||
{
|
||||
originalBlockPos.mutateOffset(direction, testBlockPos);
|
||||
|
||||
// if the block is next to the border of a chunk, assume it's visible
|
||||
if (testBlockPos.getX() < 0 || testBlockPos.getX() >= LodUtil.CHUNK_WIDTH)
|
||||
if (testBlockPos.x < 0 || testBlockPos.x >= LodUtil.CHUNK_WIDTH)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (testBlockPos.getZ() < 0 || testBlockPos.getZ() >= LodUtil.CHUNK_WIDTH)
|
||||
if (testBlockPos.z < 0 || testBlockPos.z >= LodUtil.CHUNK_WIDTH)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (testBlockPos.getY() < chunkWrapper.getMinBuildHeight() || testBlockPos.getY() > chunkWrapper.getMaxBuildHeight())
|
||||
if (testBlockPos.y < chunkWrapper.getMinBuildHeight() || testBlockPos.y > chunkWrapper.getMaxBuildHeight())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -298,7 +295,7 @@ public class LodDataBuilder
|
||||
|
||||
|
||||
/** @throws ClassCastException if an API user returns the wrong object type(s) */
|
||||
public static FullDataSourceV2 createFromApiChunkData(DhApiChunk apiChunk, boolean runAdditionalValidation) throws ClassCastException, DataCorruptedException, IllegalArgumentException
|
||||
public static FullDataSourceV2 createFromApiChunkData(DhApiChunk apiChunk) throws ClassCastException, DataCorruptedException
|
||||
{
|
||||
// get the section position
|
||||
int sectionPosX = getXOrZSectionPosFromChunkPos(apiChunk.chunkPosX);
|
||||
@@ -315,10 +312,6 @@ public class LodDataBuilder
|
||||
for (int relBlockX = 0; relBlockX < LodUtil.CHUNK_WIDTH; relBlockX++)
|
||||
{
|
||||
List<DhApiTerrainDataPoint> columnDataPoints = apiChunk.getDataPoints(relBlockX, relBlockZ);
|
||||
if (runAdditionalValidation)
|
||||
{
|
||||
validateOrThrowDataColumn(columnDataPoints);
|
||||
}
|
||||
|
||||
|
||||
// this null check does 2 nice things at the same time:
|
||||
@@ -327,8 +320,6 @@ public class LodDataBuilder
|
||||
// AND the below loop won't run.
|
||||
int size = (columnDataPoints != null) ? columnDataPoints.size() : 0;
|
||||
|
||||
// TODO make missing air LODs
|
||||
// TODO merge duplicate datapoints
|
||||
LongArrayList packedDataPoints = new LongArrayList(new long[size]);
|
||||
for (int index = 0; index < size; index++)
|
||||
{
|
||||
@@ -359,75 +350,6 @@ public class LodDataBuilder
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
private static void validateOrThrowDataColumn(List<DhApiTerrainDataPoint> dataPoints) throws IllegalArgumentException
|
||||
{
|
||||
// order doesn't need to be checked if there is 0 or 1 items
|
||||
if (dataPoints.size() > 1)
|
||||
{
|
||||
// DH expects datapoints to be in a top-down order
|
||||
DhApiTerrainDataPoint first = dataPoints.get(0);
|
||||
DhApiTerrainDataPoint last = dataPoints.get(dataPoints.size() - 1);
|
||||
if (first.bottomYBlockPos < last.bottomYBlockPos)
|
||||
{
|
||||
// flip the array if it's in bottom-up order
|
||||
Collections.reverse(dataPoints);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// check that each datapoint is valid
|
||||
int lastBottomYPos = Integer.MIN_VALUE;
|
||||
for (int i = 0; i < dataPoints.size(); i++) // standard for-loop used instead of an enhanced for-loop to slightly reduce GC overhead due to iterator allocation
|
||||
{
|
||||
DhApiTerrainDataPoint dataPoint = dataPoints.get(i);
|
||||
|
||||
if (dataPoint == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Datapoint: ["+i+"] is null DhApiTerrainDataPoints are not allowed. If you want to represent empty terrain, please use AIR.");
|
||||
}
|
||||
|
||||
if (dataPoint.detailLevel != 0)
|
||||
{
|
||||
throw new IllegalArgumentException("Datapoint: ["+i+"] has the wrong detail level ["+dataPoint.detailLevel+"], all data points must be block sized; IE their detail level must be [0].");
|
||||
}
|
||||
|
||||
|
||||
|
||||
int bottomYPos = dataPoint.bottomYBlockPos;
|
||||
int topYPos = dataPoint.topYBlockPos;
|
||||
int height = (dataPoint.topYBlockPos - dataPoint.bottomYBlockPos);
|
||||
|
||||
// is the datapoint right side up?
|
||||
if (bottomYPos > topYPos)
|
||||
{
|
||||
throw new IllegalArgumentException("Datapoint: ["+i+"] is upside down. Top Pos: ["+topYPos+"], bottom pos: ["+bottomYPos+"].");
|
||||
}
|
||||
// valid height?
|
||||
if (height <= 0 || height >= RenderDataPointUtil.MAX_WORLD_Y_SIZE)
|
||||
{
|
||||
throw new IllegalArgumentException("Datapoint: ["+i+"] has invalid height. Height must be in the range [1 - "+RenderDataPointUtil.MAX_WORLD_Y_SIZE+"] (inclusive).");
|
||||
}
|
||||
|
||||
// is this datapoint overlapping the last one?
|
||||
if (lastBottomYPos > topYPos)
|
||||
{
|
||||
throw new IllegalArgumentException("DhApiTerrainDataPoint ["+i+"] is overlapping with the last datapoint, this top Y: ["+topYPos+"], lastBottomYPos: ["+lastBottomYPos+"].");
|
||||
}
|
||||
// is there a gap between the last datapoint?
|
||||
if (topYPos != lastBottomYPos
|
||||
&& lastBottomYPos != Integer.MIN_VALUE)
|
||||
{
|
||||
throw new IllegalArgumentException("DhApiTerrainDataPoint ["+i+"] has a gap between it and index ["+(i-1)+"]. Empty spaces should be filled by air, otherwise DH's downsampling won't calculate lighting correctly.");
|
||||
}
|
||||
|
||||
|
||||
lastBottomYPos = bottomYPos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -98,9 +98,7 @@ public enum EDhDirection
|
||||
private static final EDhDirection[] VALUES = values();
|
||||
|
||||
private static final Map<String, EDhDirection> BY_NAME = Arrays.stream(VALUES).collect(Collectors.toMap(EDhDirection::getName, (p_199787_0_) ->
|
||||
{
|
||||
return p_199787_0_;
|
||||
}));
|
||||
p_199787_0_));
|
||||
|
||||
// private static final LodDirection[] BY_3D_DATA = Arrays.stream(VALUES).sorted(Comparator.comparingInt((p_199790_0_) ->
|
||||
// {
|
||||
@@ -247,36 +245,26 @@ public enum EDhDirection
|
||||
|
||||
public EDhDirection getClockWise()
|
||||
{
|
||||
switch (this)
|
||||
return switch (this)
|
||||
{
|
||||
case NORTH:
|
||||
return EAST;
|
||||
case SOUTH:
|
||||
return WEST;
|
||||
case WEST:
|
||||
return NORTH;
|
||||
case EAST:
|
||||
return SOUTH;
|
||||
default:
|
||||
throw new IllegalStateException("Unable to get Y-rotated facing of " + this);
|
||||
}
|
||||
case NORTH -> EAST;
|
||||
case SOUTH -> WEST;
|
||||
case WEST -> NORTH;
|
||||
case EAST -> SOUTH;
|
||||
default -> throw new IllegalStateException("Unable to get Y-rotated facing of " + this);
|
||||
};
|
||||
}
|
||||
|
||||
public EDhDirection getCounterClockWise()
|
||||
{
|
||||
switch (this)
|
||||
return switch (this)
|
||||
{
|
||||
case NORTH:
|
||||
return WEST;
|
||||
case SOUTH:
|
||||
return EAST;
|
||||
case WEST:
|
||||
return SOUTH;
|
||||
case EAST:
|
||||
return NORTH;
|
||||
default:
|
||||
throw new IllegalStateException("Unable to get CCW facing of " + this);
|
||||
}
|
||||
case NORTH -> WEST;
|
||||
case SOUTH -> EAST;
|
||||
case WEST -> SOUTH;
|
||||
case EAST -> NORTH;
|
||||
default -> throw new IllegalStateException("Unable to get CCW facing of " + this);
|
||||
};
|
||||
}
|
||||
|
||||
public String getName()
|
||||
@@ -317,16 +305,11 @@ public enum EDhDirection
|
||||
|
||||
public static EDhDirection fromAxisAndDirection(EDhDirection.Axis p_211699_0_, EDhDirection.AxisDirection p_211699_1_)
|
||||
{
|
||||
switch (p_211699_0_)
|
||||
{
|
||||
case X:
|
||||
return p_211699_1_ == EDhDirection.AxisDirection.POSITIVE ? EAST : WEST;
|
||||
case Y:
|
||||
return p_211699_1_ == EDhDirection.AxisDirection.POSITIVE ? UP : DOWN;
|
||||
case Z:
|
||||
default:
|
||||
return p_211699_1_ == EDhDirection.AxisDirection.POSITIVE ? SOUTH : NORTH;
|
||||
}
|
||||
return switch (p_211699_0_) {
|
||||
case X -> p_211699_1_ == AxisDirection.POSITIVE ? EAST : WEST;
|
||||
case Y -> p_211699_1_ == AxisDirection.POSITIVE ? UP : DOWN;
|
||||
default -> p_211699_1_ == AxisDirection.POSITIVE ? SOUTH : NORTH;
|
||||
};
|
||||
}
|
||||
|
||||
// public float toYRot()
|
||||
@@ -436,9 +419,7 @@ public enum EDhDirection
|
||||
private static final EDhDirection.Axis[] VALUES = values();
|
||||
|
||||
private static final Map<String, EDhDirection.Axis> BY_NAME = Arrays.stream(VALUES).collect(Collectors.toMap(EDhDirection.Axis::getName, (p_199785_0_) ->
|
||||
{
|
||||
return p_199785_0_;
|
||||
}));
|
||||
p_199785_0_));
|
||||
private final String name;
|
||||
|
||||
Axis(String name)
|
||||
|
||||
+3
-4
@@ -46,7 +46,7 @@ public abstract class AbstractDataSourceHandler
|
||||
* The lowest numerical detail level possible.
|
||||
*
|
||||
* @see AbstractDataSourceHandler#TOP_SECTION_DETAIL_LEVEL
|
||||
*/
|
||||
* */
|
||||
public static final byte MIN_SECTION_DETAIL_LEVEL = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ public abstract class AbstractDataSourceHandler
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Unexpected error in async data source update, error: " + e.getMessage(), e);
|
||||
LOGGER.error("Unexpected error in async data source update, error: "+e.getMessage(), e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -223,7 +223,6 @@ public abstract class AbstractDataSourceHandler
|
||||
|
||||
/**
|
||||
* After this method returns the inputData will be written to file.
|
||||
*
|
||||
* @param updatePos the position to update
|
||||
*/
|
||||
protected void updateDataSourceAtPos(long updatePos, @NotNull FullDataSourceV2 inputData, boolean lockOnUpdatePos)
|
||||
@@ -269,7 +268,7 @@ public abstract class AbstractDataSourceHandler
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Error updating pos [" + updatePos + "], error: "+e.getMessage(), e);
|
||||
LOGGER.error("Error updating pos ["+updatePos+"], error: "+e.getMessage(), e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
+67
-142
@@ -21,7 +21,6 @@ package com.seibel.distanthorizons.core.file.fullDatafile;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||
@@ -38,7 +37,6 @@ import com.seibel.distanthorizons.core.sql.repo.FullDataSourceV2Repo;
|
||||
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
||||
import com.seibel.distanthorizons.core.util.objects.DataCorruptedException;
|
||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||
import com.seibel.distanthorizons.core.world.EWorldEnvironment;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -47,14 +45,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Handles reading/writing {@link FullDataSourceV2}
|
||||
@@ -110,7 +105,6 @@ public class FullDataSourceProviderV2
|
||||
* This isn't in {@link AbstractDataSourceHandler} since we don't need parent updating logic
|
||||
* for render data, only full data.
|
||||
*/
|
||||
@Nullable
|
||||
private final ThreadPoolExecutor updateQueueProcessor;
|
||||
|
||||
|
||||
@@ -127,21 +121,14 @@ public class FullDataSourceProviderV2
|
||||
|
||||
DebugRenderer.register(this, Config.Client.Advanced.Debugging.DebugWireframe.showFullDataUpdateStatus);
|
||||
|
||||
String dimensionName = level.getLevelWrapper().getDimensionName();
|
||||
String dimensionName = level.getLevelWrapper().getDimensionType().getDimensionName();
|
||||
|
||||
// start migrating any legacy data sources present in the background
|
||||
this.migrationThreadPool = ThreadUtil.makeRateLimitedThreadPool(1, MIGRATION_THREAD_NAME_PREFIX + "[" + dimensionName + "]", Config.Client.Advanced.MultiThreading.runTimeRatioForUpdatePropagatorThreads.get(), Thread.MIN_PRIORITY, (Semaphore) null);
|
||||
this.migrationThreadPool = ThreadUtil.makeRateLimitedThreadPool(1, MIGRATION_THREAD_NAME_PREFIX +"["+dimensionName+"]", Config.Client.Advanced.MultiThreading.runTimeRatioForUpdatePropagatorThreads.get(), Thread.MIN_PRIORITY, (Semaphore)null);
|
||||
this.migrationThreadPool.execute(this::convertLegacyDataSources);
|
||||
|
||||
if (SharedApi.getEnvironment() != EWorldEnvironment.Server_Only)
|
||||
{
|
||||
this.updateQueueProcessor = ThreadUtil.makeSingleThreadPool("Parent Update Queue [" + dimensionName + "]");
|
||||
this.updateQueueProcessor.execute(this::runUpdateQueue);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.updateQueueProcessor = null;
|
||||
}
|
||||
this.updateQueueProcessor = ThreadUtil.makeSingleThreadPool("Parent Update Queue ["+dimensionName+"]");
|
||||
this.updateQueueProcessor.execute(this::runUpdateQueue);
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +163,7 @@ public class FullDataSourceProviderV2
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.warn("Unable to create DTO, error: " + e.getMessage(), e);
|
||||
LOGGER.warn("Unable to create DTO, error: "+e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -188,58 +175,6 @@ public class FullDataSourceProviderV2
|
||||
@Override
|
||||
protected FullDataSourceV2 makeEmptyDataSource(long pos) { return FullDataSourceV2.DATA_SOURCE_POOL.getPooledSource(pos, true); }
|
||||
|
||||
@Nullable
|
||||
public Long getTimestampForPos(long pos)
|
||||
{
|
||||
try
|
||||
{
|
||||
PreparedStatement preparedStatement = this.repo.createPreparedStatement(
|
||||
"SELECT LastModifiedUnixDateTime " +
|
||||
"FROM " + this.repo.getTableName() + " " +
|
||||
"WHERE DetailLevel = ? " +
|
||||
"AND PosX = ? " +
|
||||
"AND PosZ = ?;"
|
||||
);
|
||||
preparedStatement.setInt(1, DhSectionPos.getDetailLevel(pos) - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
|
||||
preparedStatement.setInt(2, DhSectionPos.getX(pos));
|
||||
preparedStatement.setInt(3, DhSectionPos.getZ(pos));
|
||||
|
||||
List<Map<String, Object>> row = this.repo.query(preparedStatement);
|
||||
return !row.isEmpty() ? (Long) row.get(0).get("LastModifiedUnixDateTime") : null;
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public Map<Long, Long> getTimestampsForRange(byte detailLevel, int startPosX, int startPosZ, int endPosX, int endPosZ)
|
||||
{
|
||||
try
|
||||
{
|
||||
PreparedStatement preparedStatement = this.repo.createPreparedStatement(
|
||||
"SELECT PosX, PosZ, LastModifiedUnixDateTime " +
|
||||
"FROM " + this.repo.getTableName() + " " +
|
||||
"WHERE DetailLevel = ? " +
|
||||
"AND PosX BETWEEN ? AND ? " +
|
||||
"AND PosZ BETWEEN ? AND ?;"
|
||||
);
|
||||
preparedStatement.setInt(1, detailLevel - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
|
||||
preparedStatement.setInt(2, startPosX);
|
||||
preparedStatement.setInt(3, endPosX);
|
||||
preparedStatement.setInt(4, startPosZ);
|
||||
preparedStatement.setInt(5, endPosZ);
|
||||
|
||||
return this.repo.query(preparedStatement).stream().collect(Collectors.toMap(
|
||||
row -> DhSectionPos.encode(detailLevel, (int) row.get("PosX"), (int) row.get("PosZ")),
|
||||
row -> (long) row.get("LastModifiedUnixDateTime"))
|
||||
);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
@@ -264,7 +199,7 @@ public class FullDataSourceProviderV2
|
||||
|
||||
// queue parent updates
|
||||
if (executor.getQueue().size() < MAX_UPDATE_TASK_COUNT
|
||||
&& this.parentUpdatingPosSet.size() < MAX_UPDATE_TASK_COUNT)
|
||||
&& this.parentUpdatingPosSet.size() < MAX_UPDATE_TASK_COUNT)
|
||||
{
|
||||
// get the positions that need to be applied to their parents
|
||||
LongArrayList parentUpdatePosList = this.repo.getPositionsToUpdate(MAX_UPDATE_TASK_COUNT);
|
||||
@@ -289,7 +224,7 @@ public class FullDataSourceProviderV2
|
||||
{
|
||||
// stop if there are already a bunch of updates queued
|
||||
if (this.parentUpdatingPosSet.size() > MAX_UPDATE_TASK_COUNT
|
||||
|| !this.parentUpdatingPosSet.add(parentUpdatePos))
|
||||
|| !this.parentUpdatingPosSet.add(parentUpdatePos))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -354,8 +289,7 @@ public class FullDataSourceProviderV2
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (RejectedExecutionException ignore)
|
||||
{ /* the executor was shut down, it should be back up shortly and able to accept new jobs */ }
|
||||
catch (RejectedExecutionException ignore) { /* the executor was shut down, it should be back up shortly and able to accept new jobs */ }
|
||||
catch (Exception e)
|
||||
{
|
||||
this.parentUpdatingPosSet.remove(parentUpdatePos);
|
||||
@@ -365,17 +299,14 @@ public class FullDataSourceProviderV2
|
||||
}
|
||||
|
||||
}
|
||||
catch (InterruptedException ignored)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
catch (InterruptedException ignored) { Thread.currentThread().interrupt(); }
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Unexpected error in the parent update queue thread. Error: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("Update thread [" + Thread.currentThread().getName() + "] terminated.");
|
||||
LOGGER.info("Update thread ["+Thread.currentThread().getName()+"] terminated.");
|
||||
}
|
||||
|
||||
|
||||
@@ -386,8 +317,8 @@ public class FullDataSourceProviderV2
|
||||
|
||||
private void convertLegacyDataSources()
|
||||
{
|
||||
String dimensionName = this.level.getLevelWrapper().getDimensionName();
|
||||
LOGGER.info("Attempting to migrate data sources for: [" + dimensionName + "]-[" + this.saveDir + "]...");
|
||||
String dimensionName = this.level.getLevelWrapper().getDimensionType().getDimensionName();
|
||||
LOGGER.info("Attempting to migrate data sources for: ["+dimensionName+"]-["+this.saveDir+"]...");
|
||||
|
||||
|
||||
|
||||
@@ -406,7 +337,7 @@ public class FullDataSourceProviderV2
|
||||
this.showMigrationStartMessage();
|
||||
|
||||
|
||||
LOGGER.info("deleting [" + dimensionName + "] - [" + totalDeleteCount + "] unused data sources...");
|
||||
LOGGER.info("deleting [" + dimensionName + "] - ["+totalDeleteCount+"] unused data sources...");
|
||||
this.legacyDeletionCount = totalDeleteCount;
|
||||
|
||||
ArrayList<String> unusedDataPosList = this.legacyFileHandler.repo.getUnusedDataSourcePositionStringList(50);
|
||||
@@ -424,7 +355,7 @@ public class FullDataSourceProviderV2
|
||||
|
||||
long endStart = System.currentTimeMillis();
|
||||
long deleteTime = endStart - startTime;
|
||||
LOGGER.info("Deleting [" + dimensionName + "] - [" + unusedCount + "/" + totalDeleteCount + "] in [" + deleteTime + "]ms ...");
|
||||
LOGGER.info("Deleting [" + dimensionName + "] - [" + unusedCount + "/" + totalDeleteCount + "] in ["+deleteTime+"]ms ...");
|
||||
|
||||
|
||||
// a slight delay is added to prevent accidentally locking the database when deleting a lot of rows
|
||||
@@ -435,12 +366,10 @@ public class FullDataSourceProviderV2
|
||||
// and weak computers wait no time at all
|
||||
Thread.sleep(deleteTime / 2);
|
||||
}
|
||||
catch (InterruptedException ignore)
|
||||
{
|
||||
}
|
||||
catch (InterruptedException ignore){}
|
||||
}
|
||||
|
||||
LOGGER.info("Done deleting [" + dimensionName + "] - [" + totalDeleteCount + "] unused data sources.");
|
||||
LOGGER.info("Done deleting [" + dimensionName + "] - ["+totalDeleteCount+"] unused data sources.");
|
||||
}
|
||||
|
||||
|
||||
@@ -451,7 +380,7 @@ public class FullDataSourceProviderV2
|
||||
|
||||
long totalMigrationCount = this.legacyFileHandler.getDataSourceMigrationCount();
|
||||
this.migrationCount = totalMigrationCount;
|
||||
LOGGER.info("Found [" + totalMigrationCount + "] data sources that need migration.");
|
||||
LOGGER.info("Found ["+totalMigrationCount+"] data sources that need migration.");
|
||||
|
||||
ArrayList<FullDataSourceV1> legacyDataSourceList = this.legacyFileHandler.getDataSourcesToMigrate(MIGRATION_BATCH_COUNT);
|
||||
if (!legacyDataSourceList.isEmpty())
|
||||
@@ -491,40 +420,40 @@ public class FullDataSourceProviderV2
|
||||
{
|
||||
newDataSource.close();
|
||||
}
|
||||
catch (Exception ignore)
|
||||
{
|
||||
}
|
||||
});
|
||||
catch (Exception ignore)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Long migrationPos = legacyDataSource.getPos();
|
||||
LOGGER.warn("Unexpected issue migrating data source at pos " + migrationPos + ". Error: " + e.getMessage(), e);
|
||||
this.legacyFileHandler.markMigrationFailed(migrationPos);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Long migrationPos = legacyDataSource.getPos();
|
||||
LOGGER.warn("Unexpected issue migrating data source at pos " + migrationPos + ". Error: " + e.getMessage(), e);
|
||||
this.legacyFileHandler.markMigrationFailed(migrationPos);
|
||||
// wait for each thread to finish updating
|
||||
CompletableFuture<Void> combinedFutures = CompletableFuture.allOf(updateFutureList.toArray(new CompletableFuture[0]));
|
||||
combinedFutures.get(MIGRATION_MAX_UPDATE_TIMEOUT_IN_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
catch (InterruptedException | TimeoutException e)
|
||||
{
|
||||
LOGGER.warn("Migration update timed out after [" + MIGRATION_MAX_UPDATE_TIMEOUT_IN_MS + "] milliseconds. Migration will re-try the same positions again in a moment..", e);
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
LOGGER.warn("Migration update failed. Migration will re-try the same positions again. Error:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
legacyDataSourceList = this.legacyFileHandler.getDataSourcesToMigrate(MIGRATION_BATCH_COUNT);
|
||||
|
||||
try
|
||||
{
|
||||
// wait for each thread to finish updating
|
||||
CompletableFuture<Void> combinedFutures = CompletableFuture.allOf(updateFutureList.toArray(new CompletableFuture[0]));
|
||||
combinedFutures.get(MIGRATION_MAX_UPDATE_TIMEOUT_IN_MS, TimeUnit.MILLISECONDS);
|
||||
progressCount += legacyDataSourceList.size();
|
||||
this.migrationCount -= legacyDataSourceList.size();
|
||||
}
|
||||
catch (InterruptedException | TimeoutException e)
|
||||
{
|
||||
LOGGER.warn("Migration update timed out after [" + MIGRATION_MAX_UPDATE_TIMEOUT_IN_MS + "] milliseconds. Migration will re-try the same positions again in a moment..", e);
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
LOGGER.warn("Migration update failed. Migration will re-try the same positions again. Error:" + e.getMessage(), e);
|
||||
}
|
||||
|
||||
legacyDataSourceList = this.legacyFileHandler.getDataSourcesToMigrate(MIGRATION_BATCH_COUNT);
|
||||
|
||||
progressCount += legacyDataSourceList.size();
|
||||
this.migrationCount -= legacyDataSourceList.size();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -534,16 +463,16 @@ public class FullDataSourceProviderV2
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (this.migrationThreadRunning.get())
|
||||
{
|
||||
LOGGER.info("migration complete for: [" + dimensionName + "]-[" + this.saveDir + "].");
|
||||
this.showMigrationEndMessage(true);
|
||||
this.migrationCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("migration stopped for: [" + dimensionName + "]-[" + this.saveDir + "].");
|
||||
this.showMigrationEndMessage(false);
|
||||
if (this.migrationThreadRunning.get())
|
||||
{
|
||||
LOGGER.info("migration complete for: ["+dimensionName+"]-["+this.saveDir+"].");
|
||||
this.showMigrationEndMessage(true);
|
||||
this.migrationCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("migration stopped for: ["+dimensionName+"]-["+this.saveDir+"].");
|
||||
this.showMigrationEndMessage(false);
|
||||
this.migrationStoppedWithError = true;
|
||||
}
|
||||
}
|
||||
@@ -569,7 +498,7 @@ public class FullDataSourceProviderV2
|
||||
}
|
||||
this.migrationStartMessageQueued = true;
|
||||
|
||||
String dimName = this.level.getLevelWrapper().getDimensionName();
|
||||
String dimName = this.level.getLevelWrapper().getDimensionType().getDimensionName();
|
||||
ClientApi.INSTANCE.showChatMessageNextFrame(
|
||||
"Old Distant Horizons data is being migrated for ["+dimName+"]. \n" +
|
||||
"While migrating LODs may load slowly \n" +
|
||||
@@ -580,7 +509,7 @@ public class FullDataSourceProviderV2
|
||||
|
||||
private void showMigrationEndMessage(boolean success)
|
||||
{
|
||||
String dimName = this.level.getLevelWrapper().getDimensionName();
|
||||
String dimName = this.level.getLevelWrapper().getDimensionType().getDimensionName();
|
||||
|
||||
if (success)
|
||||
{
|
||||
@@ -621,11 +550,11 @@ public class FullDataSourceProviderV2
|
||||
* <code>
|
||||
* if (!super.canQueueRetrieval()) <br>
|
||||
* { <br>
|
||||
* return false; <br>
|
||||
* return false; <br>
|
||||
* } <br>
|
||||
* </code>
|
||||
* to the beginning of your override.
|
||||
* Otherwise, parent retrieval limits will be ignored.
|
||||
* to the beginning of your override.
|
||||
* Otherwise, parent retrieval limits will be ignored.
|
||||
*/
|
||||
public boolean canQueueRetrieval()
|
||||
{
|
||||
@@ -640,12 +569,12 @@ public class FullDataSourceProviderV2
|
||||
* an empty array if all positions were generated
|
||||
*/
|
||||
@Nullable
|
||||
public LongArrayList getPositionsToRetrieve(Long pos) { return null; }
|
||||
public LongArrayList getPositionsToRetrieve(Long pos) { return null; }
|
||||
/**
|
||||
* Returns how many positions could potentially be generated for this position assuming the position is empty.
|
||||
* Used when estimating the total number of retrieval requests.
|
||||
*/
|
||||
public int getMaxPossibleRetrievalPositionCountForPos(Long pos) { return -1; }
|
||||
public int getMaxPossibleRetrievalPositionCountForPos(Long pos) { return -1; }
|
||||
|
||||
/** @return true if the position was queued, false if not */
|
||||
public boolean queuePositionForRetrieval(Long genPos) { return false; }
|
||||
@@ -656,7 +585,7 @@ public class FullDataSourceProviderV2
|
||||
public void clearRetrievalQueue() { }
|
||||
|
||||
/** Can be used to display how many total retrieval requests might be available. */
|
||||
public void setTotalRetrievalPositionCount(int newCount) { }
|
||||
public void setTotalRetrievalPositionCount(int newCount) { }
|
||||
|
||||
/**
|
||||
* Returns how many data sources are currently in memory and haven't
|
||||
@@ -665,7 +594,6 @@ public class FullDataSourceProviderV2
|
||||
*/
|
||||
public int getUnsavedDataSourceCount() { return -1; }
|
||||
|
||||
public boolean fileExists(long pos) { return this.repo.getDataSizeInBytes(pos) > 0; }
|
||||
|
||||
|
||||
//===========//
|
||||
@@ -676,22 +604,19 @@ public class FullDataSourceProviderV2
|
||||
public void debugRender(DebugRenderer renderer)
|
||||
{
|
||||
this.lockedPosSet
|
||||
.forEach((pos) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 74f, 0.15f, Color.PINK)); });
|
||||
.forEach((pos) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 74f, 0.15f, Color.PINK)));
|
||||
|
||||
this.queuedUpdateCountsByPos
|
||||
.forEach((pos, updateCountRef) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f + (updateCountRef.get() * 16f), 0.20f, Color.WHITE)); });
|
||||
.forEach((pos, updateCountRef) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f + (updateCountRef.get() * 16f), 0.20f, Color.WHITE)));
|
||||
this.parentUpdatingPosSet
|
||||
.forEach((pos) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f, 0.20f, Color.MAGENTA)); });
|
||||
.forEach((pos) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f, 0.20f, Color.MAGENTA)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
super.close();
|
||||
if (this.updateQueueProcessor != null)
|
||||
{
|
||||
this.updateQueueProcessor.shutdownNow();
|
||||
}
|
||||
this.updateQueueProcessor.shutdownNow();
|
||||
|
||||
this.legacyFileHandler.close();
|
||||
|
||||
|
||||
+6
-36
@@ -36,15 +36,12 @@ import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 implements IDebugRenderable
|
||||
{
|
||||
@@ -73,7 +70,6 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
//=============//
|
||||
|
||||
public GeneratedFullDataSourceProvider(IDhLevel level, AbstractSaveStructure saveStructure) { super(level, saveStructure); }
|
||||
public GeneratedFullDataSourceProvider(IDhLevel level, AbstractSaveStructure saveStructure, @Nullable File saveDirOverride) { super(level, saveStructure, saveDirOverride); }
|
||||
|
||||
|
||||
|
||||
@@ -97,7 +93,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
// don't log shutdown exceptions
|
||||
if (!(exception instanceof CancellationException || exception.getCause() instanceof CancellationException))
|
||||
{
|
||||
LOGGER.error("Uncaught Gen Task Exception at [" + genTaskResult.pos + "], error: [" + exception.getMessage() + "].", exception);
|
||||
LOGGER.error("Uncaught Gen Task Exception at [" + genTaskResult.pos + "], error: ["+ exception.getMessage() + "].", exception);
|
||||
}
|
||||
}
|
||||
else if (genTaskResult.success)
|
||||
@@ -115,7 +111,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
// if the generation task was split up into smaller positions, add the on-complete event to them
|
||||
for (CompletableFuture<WorldGenResult> siblingFuture : genTaskResult.childFutures)
|
||||
{
|
||||
siblingFuture.whenComplete((siblingGenTaskResult, siblingEx) -> this.onWorldGenTaskComplete(siblingGenTaskResult, siblingEx));
|
||||
siblingFuture.whenComplete(this::onWorldGenTaskComplete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +139,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
{
|
||||
boolean oldQueueExists = this.worldGenQueueRef.compareAndSet(null, newWorldGenQueue);
|
||||
LodUtil.assertTrue(oldQueueExists, "previous world gen queue is still here!");
|
||||
LOGGER.info("Set world gen queue for level [" + this.level.getLevelWrapper().getDimensionName() + "].");
|
||||
LOGGER.info("Set world gen queue for level ["+this.level+"].");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,7 +215,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
|
||||
GenTask genTask = new GenTask(genPos);
|
||||
CompletableFuture<WorldGenResult> worldGenFuture = worldGenQueue.submitGenTask(genPos, (byte) (DhSectionPos.getDetailLevel(genPos) - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL), genTask);
|
||||
worldGenFuture.whenComplete((genTaskResult, ex) -> this.onWorldGenTaskComplete(genTaskResult, ex));
|
||||
worldGenFuture.whenComplete(this::onWorldGenTaskComplete);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -241,12 +237,6 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
public int getUnsavedDataSourceCount() { return this.delayedFullDataSourceSaveCache.getUnsavedCount(); }
|
||||
|
||||
|
||||
public boolean isFullyGenerated(byte[] columnGenerationSteps)
|
||||
{
|
||||
return IntStream.range(0, columnGenerationSteps.length)
|
||||
.noneMatch(i -> columnGenerationSteps[i] == EDhApiWorldGenerationStep.EMPTY.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongArrayList getPositionsToRetrieve(Long pos)
|
||||
{
|
||||
@@ -360,22 +350,6 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
return BitShiftUtil.powerOfTwo(detailLevelDiff);
|
||||
}
|
||||
|
||||
public Map<Long, Integer> getLoadStates(Iterable<Long> posList)
|
||||
{
|
||||
HashMap<Long, Integer> map = new HashMap<>();
|
||||
for (long pos : posList)
|
||||
{
|
||||
map.put(pos,
|
||||
// Loaded
|
||||
this.delayedFullDataSourceSaveCache.dataSourceByPosition.containsKey(pos) ? 3
|
||||
// Unloaded, but exists
|
||||
: this.fileExists(pos) ? 2
|
||||
// Not generated
|
||||
: 1);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======//
|
||||
@@ -388,7 +362,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
super.debugRender(renderer);
|
||||
|
||||
this.delayedFullDataSourceSaveCache.dataSourceByPosition
|
||||
.forEach((pos, dataSource) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f, 0.20f, Color.green.darker())); });
|
||||
.forEach((pos, dataSource) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f, 0.20f, Color.green.darker())));
|
||||
}
|
||||
|
||||
|
||||
@@ -413,12 +387,8 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
|
||||
@Override
|
||||
public Consumer<FullDataSourceV2> getChunkDataConsumer()
|
||||
{
|
||||
return (chunkSizedFullDataSource) ->
|
||||
{
|
||||
GeneratedFullDataSourceProvider.this.delayedFullDataSourceSaveCache.queueDataSourceForUpdateAndSave(chunkSizedFullDataSource);
|
||||
};
|
||||
return GeneratedFullDataSourceProvider.this.delayedFullDataSourceSaveCache::queueDataSourceForUpdateAndSave;
|
||||
}
|
||||
|
||||
}
|
||||
private void onDataSourceSave(FullDataSourceV2 fullDataSource)
|
||||
{ GeneratedFullDataSourceProvider.this.updateDataSourceAsync(fullDataSource); }
|
||||
|
||||
+3
-55
@@ -19,67 +19,15 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.file.fullDatafile;
|
||||
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.multiplayer.client.SyncOnLoginRequestQueue;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvider
|
||||
public class RemoteFullDataSourceProvider extends FullDataSourceProviderV2
|
||||
{
|
||||
@Nullable
|
||||
private final SyncOnLoginRequestQueue syncOnLoginRequestQueue;
|
||||
private final Set<Long> finishedTaskPositions = ConcurrentHashMap.newKeySet();
|
||||
|
||||
public RemoteFullDataSourceProvider(IDhLevel level, AbstractSaveStructure saveStructure, @Nullable File saveDirOverride, @Nullable SyncOnLoginRequestQueue syncOnLoginRequestQueue)
|
||||
{
|
||||
super(level, saveStructure, saveDirOverride);
|
||||
this.syncOnLoginRequestQueue = syncOnLoginRequestQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FullDataSourceV2 get(long pos)
|
||||
{
|
||||
FullDataSourceV2 fullDataSource = super.get(pos);
|
||||
if (fullDataSource == null || this.syncOnLoginRequestQueue == null)
|
||||
{
|
||||
return fullDataSource;
|
||||
}
|
||||
|
||||
int posToMinimumDetailScale = (DhSectionPos.getDetailLevel(pos) - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL + 1);
|
||||
Map<Long, Long> timestamps = this.getTimestampsForRange(
|
||||
DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL,
|
||||
DhSectionPos.getX(pos) * posToMinimumDetailScale,
|
||||
DhSectionPos.getZ(pos) * posToMinimumDetailScale,
|
||||
(DhSectionPos.getX(pos) + 1) * posToMinimumDetailScale - 1,
|
||||
(DhSectionPos.getZ(pos) + 1) * posToMinimumDetailScale - 1
|
||||
);
|
||||
for (Map.Entry<Long, Long> entry : timestamps.entrySet())
|
||||
{
|
||||
if (this.finishedTaskPositions.add(entry.getKey()))
|
||||
{
|
||||
this.syncOnLoginRequestQueue.submitRequest(entry.getKey(), entry.getValue(), this.delayedFullDataSourceSaveCache::queueDataSourceForUpdateAndSave);
|
||||
}
|
||||
}
|
||||
|
||||
return fullDataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
if (this.syncOnLoginRequestQueue != null)
|
||||
{
|
||||
this.syncOnLoginRequestQueue.close();
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
public RemoteFullDataSourceProvider(IDhLevel level, AbstractSaveStructure saveStructure) { super(level, saveStructure); }
|
||||
public RemoteFullDataSourceProvider(IDhLevel level, AbstractSaveStructure saveStructure, @Nullable File saveDirOverride) { super(level, saveStructure, saveDirOverride); }
|
||||
|
||||
}
|
||||
+23
-38
@@ -26,12 +26,12 @@ import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiServerFolderNameMode;
|
||||
import com.seibel.distanthorizons.core.level.IServerKeyedClientLevel;
|
||||
import com.seibel.distanthorizons.core.util.objects.ParsedIp;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -85,26 +85,24 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure
|
||||
return this.levelWrapperToFileMap.computeIfAbsent(levelWrapper, (newLevelWrapper) ->
|
||||
{
|
||||
// Use the server provided key if one was provided
|
||||
if (newLevelWrapper instanceof IServerKeyedClientLevel)
|
||||
if (newLevelWrapper instanceof IServerKeyedClientLevel keyedClientLevel)
|
||||
{
|
||||
IServerKeyedClientLevel keyedClientLevel = (IServerKeyedClientLevel) newLevelWrapper;
|
||||
LOGGER.info("Loading level " + newLevelWrapper.getDimensionName() + " with key: " + keyedClientLevel.getServerLevelKey());
|
||||
LOGGER.info("Loading level " + newLevelWrapper.getDimensionType().getDimensionName() + " with key: " + keyedClientLevel.getServerLevelKey());
|
||||
// This world was identified by the server directly, so we can know for sure which folder to use.
|
||||
return new File(getSaveStructureFolderPath() + File.separatorChar + keyedClientLevel.getServerLevelKey().replaceAll(":", "@@"));
|
||||
return new File(getSaveStructureFolderPath() + File.separatorChar + keyedClientLevel.getServerLevelKey());
|
||||
}
|
||||
|
||||
|
||||
// use multiverse matching if enabled and in multiplayer (the server should already know where the player is)
|
||||
if (newLevelWrapper instanceof IClientLevelWrapper && Config.Client.Advanced.Multiplayer.multiverseSimilarityRequiredPercent.get() != 0)
|
||||
if (newLevelWrapper instanceof IClientLevelWrapper newClientLevelWrapper && Config.Client.Advanced.Multiplayer.multiverseSimilarityRequiredPercent.get() != 0)
|
||||
{
|
||||
IClientLevelWrapper newClientLevelWrapper = (IClientLevelWrapper) newLevelWrapper;
|
||||
|
||||
// create the matcher if one doesn't exist
|
||||
if (this.subDimMatcher == null || !this.subDimMatcher.isFindingLevel(newClientLevelWrapper))
|
||||
{
|
||||
LOGGER.info("Loading level " + newClientLevelWrapper.getDimensionName());
|
||||
LOGGER.info("Loading level " + newClientLevelWrapper.getDimensionType().getDimensionName());
|
||||
|
||||
List<File> levelFolders = this.getDhDataFoldersForDimension(newClientLevelWrapper);
|
||||
List<File> levelFolders = this.getDhDataFoldersForDimension(newClientLevelWrapper.getDimensionType());
|
||||
this.subDimMatcher = new SubDimensionLevelMatcher(newClientLevelWrapper, this.folder, levelFolders);
|
||||
}
|
||||
|
||||
@@ -133,23 +131,23 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure
|
||||
|
||||
private File getLevelFolderWithoutSimilarityMatching(ILevelWrapper level)
|
||||
{
|
||||
List<File> folders = this.getDhDataFoldersForDimension(level);
|
||||
if (!folders.isEmpty() && folders.get(0) != null)
|
||||
List<File> folders = this.getDhDataFoldersForDimension(level.getDimensionType());
|
||||
if (!folders.isEmpty() && folders.getFirst() != null)
|
||||
{
|
||||
// use the first existing sub-dimension
|
||||
String folderName = folders.get(0).getName();
|
||||
LOGGER.info("Default Sub Dimension set to: [" + StringUtil.shortenString(folderName, 8) + "...]");
|
||||
return folders.get(0);
|
||||
String folderName = folders.getFirst().getName();
|
||||
LOGGER.info("Default Sub Dimension set to: [" + LodUtil.shortenString(folderName, 8) + "...]");
|
||||
return folders.getFirst();
|
||||
}
|
||||
else
|
||||
{
|
||||
// no valid sub dimension was found, create a new one
|
||||
LOGGER.info("Default Sub Dimension not found. Creating: [" + level.getDimensionName() + "]");
|
||||
return new File(this.folder, level.getDimensionName().replaceAll(":", "@@"));
|
||||
LOGGER.info("Default Sub Dimension not found. Creating: [" + level.getDimensionType().getDimensionName() + "]");
|
||||
return new File(this.folder, level.getDimensionType().getDimensionName());
|
||||
}
|
||||
}
|
||||
|
||||
public List<File> getDhDataFoldersForDimension(ILevelWrapper level)
|
||||
public List<File> getDhDataFoldersForDimension(IDimensionTypeWrapper dimensionType)
|
||||
{
|
||||
File[] folders = this.folder.listFiles();
|
||||
if (folders == null)
|
||||
@@ -158,7 +156,7 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure
|
||||
}
|
||||
|
||||
// filter by dimension name
|
||||
String expectedDimName = level.getDimensionName();
|
||||
String expectedDimName = dimensionType.getDimensionName();
|
||||
ArrayList<File> possibleDimFolders = new ArrayList<>();
|
||||
for (File dimFolder : folders)
|
||||
{
|
||||
@@ -270,27 +268,14 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure
|
||||
|
||||
|
||||
// generate the folder name
|
||||
String folderName;
|
||||
switch (folderNameMode)
|
||||
String folderName = switch (folderNameMode)
|
||||
{
|
||||
default:
|
||||
case NAME_ONLY:
|
||||
folderName = serverName;
|
||||
break;
|
||||
case IP_ONLY:
|
||||
folderName = serverIpCleaned;
|
||||
break;
|
||||
|
||||
case NAME_IP:
|
||||
folderName = serverName + ", IP " + serverIpCleaned;
|
||||
break;
|
||||
case NAME_IP_PORT:
|
||||
folderName = serverName + ", IP " + serverIpCleaned + (serverPortCleaned.length() != 0 ? ("-" + serverPortCleaned) : "");
|
||||
break;
|
||||
case NAME_IP_PORT_MC_VERSION:
|
||||
folderName = serverName + ", IP " + serverIpCleaned + (serverPortCleaned.length() != 0 ? ("-" + serverPortCleaned) : "") + ", GameVersion " + serverMcVersion;
|
||||
break;
|
||||
}
|
||||
default -> serverName;
|
||||
case IP_ONLY -> serverIpCleaned;
|
||||
case NAME_IP -> serverName + ", IP " + serverIpCleaned;
|
||||
case NAME_IP_PORT -> serverName + ", IP " + serverIpCleaned + (serverPortCleaned.length() != 0 ? ("-" + serverPortCleaned) : "");
|
||||
case NAME_IP_PORT_MC_VERSION -> serverName + ", IP " + serverIpCleaned + (serverPortCleaned.length() != 0 ? ("-" + serverPortCleaned) : "") + ", GameVersion " + serverMcVersion;
|
||||
};
|
||||
|
||||
// PercentEscaper makes the characters all part of the standard alphameric character set
|
||||
// This fixes some issues when the server is named something in other languages
|
||||
|
||||
+11
-12
@@ -40,7 +40,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftCli
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
@@ -93,7 +92,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
||||
if (potentialLevelFolders.size() == 0)
|
||||
{
|
||||
String newId = UUID.randomUUID().toString();
|
||||
LOGGER.info("No potential level files found. Creating a new sub dimension with the ID ["+ StringUtil.shortenString(newId, 8)+"]...");
|
||||
LOGGER.info("No potential level files found. Creating a new sub dimension with the ID ["+LodUtil.shortenString(newId, 8)+"]...");
|
||||
this.foundLevelFile = this.CreateSubDimFolder(newId);
|
||||
}
|
||||
}
|
||||
@@ -201,20 +200,20 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
||||
//================================//
|
||||
|
||||
// log the start of this attempt
|
||||
LOGGER.info("Attempting to determine sub-dimension for [" + MC_CLIENT.getWrappedClientLevel().getDimensionName() + "]");
|
||||
LOGGER.info("Player block pos in dimension: [" + this.playerData.playerBlockPos.getX() + "," + this.playerData.playerBlockPos.getY() + "," + this.playerData.playerBlockPos.getZ() + "]");
|
||||
LOGGER.info("Attempting to determine sub-dimension for [" + MC_CLIENT.getWrappedClientLevel().getDimensionType().getDimensionName() + "]");
|
||||
LOGGER.info("Player block pos in dimension: [" + this.playerData.playerBlockPos.x + "," + this.playerData.playerBlockPos.y + "," + this.playerData.playerBlockPos.z + "]");
|
||||
LOGGER.info("Potential Sub Dimension folders: [" + this.potentialLevelFolders.size() + "]");
|
||||
|
||||
SubDimCompare mostSimilarSubDim = null;
|
||||
for (File testLevelFolder : this.potentialLevelFolders)
|
||||
{
|
||||
LOGGER.info("Testing level folder: [" + StringUtil.shortenString(testLevelFolder.getName(), 8) + "]");
|
||||
LOGGER.info("Testing level folder: [" + LodUtil.shortenString(testLevelFolder.getName(), 8) + "]");
|
||||
|
||||
FullDataSourceV2 testFullDataSource = null;
|
||||
try
|
||||
{
|
||||
// get the data source to compare against
|
||||
try (IDhLevel tempLevel = new DhClientLevel(new ClientOnlySaveStructure(), this.currentClientLevel, testLevelFolder, false, null))
|
||||
try (IDhLevel tempLevel = new DhClientLevel(new ClientOnlySaveStructure(), this.currentClientLevel, testLevelFolder, false))
|
||||
{
|
||||
testFullDataSource = tempLevel.getFullDataProvider().getAsync(DhSectionPos.encodeContaining(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, this.playerData.playerBlockPos)).join();
|
||||
if (testFullDataSource == null)
|
||||
@@ -315,7 +314,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
||||
|
||||
// get the player data for this dimension folder
|
||||
SubDimensionPlayerData testPlayerData = new SubDimensionPlayerData(testLevelFolder);
|
||||
LOGGER.info("Last known player pos: [" + testPlayerData.playerBlockPos.getX() + "," + testPlayerData.playerBlockPos.getY() + "," + testPlayerData.playerBlockPos.getZ() + "]");
|
||||
LOGGER.info("Last known player pos: [" + testPlayerData.playerBlockPos.x + "," + testPlayerData.playerBlockPos.y + "," + testPlayerData.playerBlockPos.z + "]");
|
||||
|
||||
// check if the block positions are close
|
||||
int playerBlockDist = testPlayerData.playerBlockPos.getManhattanDistance(this.playerData.playerBlockPos);
|
||||
@@ -329,8 +328,8 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
||||
}
|
||||
|
||||
|
||||
String subDimShortName = StringUtil.shortenString(testLevelFolder.getName(), 8); // variables are separated out for easier debugging
|
||||
String equalPercent = StringUtil.shortenString(mostSimilarSubDim.getPercentEqual()+"", 5);
|
||||
String subDimShortName = LodUtil.shortenString(testLevelFolder.getName(), 8); // variables are separated out for easier debugging
|
||||
String equalPercent = LodUtil.shortenString(mostSimilarSubDim.getPercentEqual()+"", 5);
|
||||
LOGGER.info("Sub dimension ["+subDimShortName+"...] is current dimension probability: "+equalPercent+" ("+equalDataPoints+"/"+totalDataPointCount+")");
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -360,7 +359,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
||||
{
|
||||
// we found a sub dim folder that is similar, use it
|
||||
|
||||
LOGGER.info("Sub Dimension set to: [" + StringUtil.shortenString(mostSimilarSubDim.folder.getName(), 8) + "...] with an equality of [" + mostSimilarSubDim.getPercentEqual() + "]");
|
||||
LOGGER.info("Sub Dimension set to: [" + LodUtil.shortenString(mostSimilarSubDim.folder.getName(), 8) + "...] with an equality of [" + mostSimilarSubDim.getPercentEqual() + "]");
|
||||
return mostSimilarSubDim.folder;
|
||||
}
|
||||
else
|
||||
@@ -370,7 +369,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
||||
String newId = UUID.randomUUID().toString();
|
||||
|
||||
double highestEqualityPercent = mostSimilarSubDim != null ? mostSimilarSubDim.getPercentEqual() : 0;
|
||||
String message = "No suitable sub dimension found. The highest equality was [" + StringUtil.shortenString(highestEqualityPercent + "", 5) + "]. Creating a new sub dimension with ID: " + StringUtil.shortenString(newId, 8) + "...";
|
||||
String message = "No suitable sub dimension found. The highest equality was [" + LodUtil.shortenString(highestEqualityPercent + "", 5) + "]. Creating a new sub dimension with ID: " + LodUtil.shortenString(newId, 8) + "...";
|
||||
LOGGER.info(message);
|
||||
|
||||
File folder = this.CreateSubDimFolder(newId);
|
||||
@@ -380,7 +379,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
||||
}
|
||||
|
||||
|
||||
private File CreateSubDimFolder(String subDimId) { return new File(this.levelsFolder.getPath() + File.separatorChar + this.currentClientLevel.getDimensionName(), subDimId); }
|
||||
private File CreateSubDimFolder(String subDimId) { return new File(this.levelsFolder.getPath() + File.separatorChar + this.currentClientLevel.getDimensionType().getDimensionName(), subDimId); }
|
||||
|
||||
@Override
|
||||
public void close() { this.matcherThread.shutdownNow(); }
|
||||
|
||||
+5
-5
@@ -22,7 +22,7 @@ package com.seibel.distanthorizons.core.file.subDimMatching;
|
||||
|
||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
|
||||
@@ -127,9 +127,9 @@ public class SubDimensionPlayerData
|
||||
public void toTomlFile(CommentedFileConfig toml)
|
||||
{
|
||||
// player block pos
|
||||
toml.add(PLAYER_BLOCK_POS_X_PATH, this.playerBlockPos.getX());
|
||||
toml.add(PLAYER_BLOCK_POS_Y_PATH, this.playerBlockPos.getY());
|
||||
toml.add(PLAYER_BLOCK_POS_Z_PATH, this.playerBlockPos.getZ());
|
||||
toml.add(PLAYER_BLOCK_POS_X_PATH, this.playerBlockPos.x);
|
||||
toml.add(PLAYER_BLOCK_POS_Y_PATH, this.playerBlockPos.y);
|
||||
toml.add(PLAYER_BLOCK_POS_Z_PATH, this.playerBlockPos.z);
|
||||
|
||||
toml.save();
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class SubDimensionPlayerData
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "PlayerBlockPos: [" + this.playerBlockPos.getX() + "," + this.playerBlockPos.getY() + "," + this.playerBlockPos.getZ() + "]";
|
||||
return "PlayerBlockPos: [" + this.playerBlockPos.x + "," + this.playerBlockPos.y + "," + this.playerBlockPos.z + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -33,7 +33,7 @@ public class AdjacentChunkHolder
|
||||
{
|
||||
for (int zOffset = -1; zOffset <= 1; zOffset++)
|
||||
{
|
||||
DhChunkPos adjacentPos = new DhChunkPos(centerChunkPos.getX() + xOffset, centerChunkPos.getZ() + zOffset);
|
||||
DhChunkPos adjacentPos = new DhChunkPos(centerChunkPos.x + xOffset, centerChunkPos.z + zOffset);
|
||||
requestedAdjacentPositions.add(adjacentPos);
|
||||
}
|
||||
}
|
||||
@@ -69,13 +69,13 @@ public class AdjacentChunkHolder
|
||||
DhChunkPos centerPos = this.chunkArray[4].getChunkPos();
|
||||
DhChunkPos offsetPos = centerWrapper.getChunkPos();
|
||||
|
||||
int offsetX = offsetPos.getX() - centerPos.getX();
|
||||
int offsetX = offsetPos.x - centerPos.x;
|
||||
if (offsetX < -1 || offsetX > 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int offsetZ = offsetPos.getZ() - centerPos.getZ();
|
||||
int offsetZ = offsetPos.z - centerPos.z;
|
||||
if (offsetZ < -1 || offsetZ > 1)
|
||||
{
|
||||
return;
|
||||
@@ -91,18 +91,18 @@ public class AdjacentChunkHolder
|
||||
int chunkZ = BitShiftUtil.divideByPowerOfTwo(blockZ, 4);
|
||||
IChunkWrapper centerChunk = this.chunkArray[4];
|
||||
DhChunkPos centerPos = centerChunk.getChunkPos();
|
||||
if (centerPos.getX() == chunkX && centerPos.getZ() == chunkZ)
|
||||
if (centerPos.x == chunkX && centerPos.z == chunkZ)
|
||||
{
|
||||
return centerChunk;
|
||||
}
|
||||
|
||||
int offsetX = chunkX - centerPos.getX();
|
||||
int offsetX = chunkX - centerPos.x;
|
||||
if (offsetX < -1 || offsetX > 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int offsetZ = chunkZ - centerPos.getZ();
|
||||
int offsetZ = chunkZ - centerPos.z;
|
||||
if (offsetZ < -1 || offsetZ > 1)
|
||||
{
|
||||
return null;
|
||||
|
||||
@@ -47,6 +47,15 @@ public class BatchGenerator implements IDhApiWorldGenerator
|
||||
private static final IWrapperFactory FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
/**
|
||||
* Defines how many tasks can be queued per thread. <br><br>
|
||||
*
|
||||
* TODO the multiplier here should change dynamically based on how fast the generator is vs the queuing thread,
|
||||
* if this is too high it may cause issues when moving,
|
||||
* but if it is too low the generator threads won't have enough tasks to work on
|
||||
*/
|
||||
private static final int MAX_QUEUED_TASKS_PER_THREAD = 3;
|
||||
|
||||
public AbstractBatchGenerationEnvironmentWrapper generationEnvironment;
|
||||
public IDhLevel targetDhLevel;
|
||||
|
||||
@@ -100,23 +109,17 @@ public class BatchGenerator implements IDhApiWorldGenerator
|
||||
int chunkPosMinX, int chunkPosMinZ, byte granularity, byte targetDataDetail, EDhApiDistantGeneratorMode generatorMode,
|
||||
ExecutorService worldGeneratorThreadPool, Consumer<Object[]> resultConsumer)
|
||||
{
|
||||
EDhApiWorldGenerationStep targetStep = null;
|
||||
switch (generatorMode)
|
||||
EDhApiWorldGenerationStep targetStep = switch (generatorMode)
|
||||
{
|
||||
case PRE_EXISTING_ONLY: // Only load in existing chunks. Note: this requires the biome generation step in order for biomes to be properly initialized.
|
||||
//case BIOME_ONLY: // No blocks. Require fake height in LodBuilder
|
||||
targetStep = EDhApiWorldGenerationStep.BIOMES;
|
||||
break;
|
||||
case PRE_EXISTING_ONLY -> // Only load in existing chunks. Note: this requires the biome generation step in order for biomes to be properly initialized.
|
||||
//case BIOME_ONLY: // No blocks. Require fake height in LodBuilder
|
||||
EDhApiWorldGenerationStep.BIOMES;
|
||||
//case BIOME_ONLY_SIMULATE_HEIGHT:
|
||||
// targetStep = EDhApiWorldGenerationStep.NOISE; // Stone only. Requires a fake surface
|
||||
// break;
|
||||
case SURFACE:
|
||||
targetStep = EDhApiWorldGenerationStep.SURFACE;
|
||||
break;
|
||||
case FEATURES:
|
||||
targetStep = EDhApiWorldGenerationStep.FEATURES;
|
||||
break;
|
||||
}
|
||||
case SURFACE -> EDhApiWorldGenerationStep.SURFACE;
|
||||
case FEATURES -> EDhApiWorldGenerationStep.FEATURES;
|
||||
};
|
||||
|
||||
int genChunkSize = BitShiftUtil.powerOfTwo(granularity - 4); // minus 4 is equal to dividing by 16 to convert to chunk scale
|
||||
|
||||
@@ -138,6 +141,14 @@ public class BatchGenerator implements IDhApiWorldGenerator
|
||||
@Override
|
||||
public void preGeneratorTaskStart() { this.generationEnvironment.updateAllFutures(); }
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
int worldGenThreadCount = Math.max(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads.get(), 1);
|
||||
int maxWorldGenTaskCount = worldGenThreadCount * MAX_QUEUED_TASKS_PER_THREAD;
|
||||
return this.generationEnvironment.getEventCount() > maxWorldGenTaskCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
|
||||
+36
-155
@@ -21,17 +21,13 @@ package com.seibel.distanthorizons.core.generation;
|
||||
|
||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPosMutable;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@@ -53,28 +49,15 @@ public class DhLightingEngine
|
||||
* Since these objects are always mutated anyway, using a {@link ThreadLocal} will allow us to
|
||||
* only create as many of these {@link DhBlockPos} as necessary.
|
||||
*/
|
||||
private static final ThreadLocal<DhBlockPosMutable> PRIMARY_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new DhBlockPosMutable());
|
||||
private static final ThreadLocal<DhBlockPosMutable> SECONDARY_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new DhBlockPosMutable());
|
||||
|
||||
/** if enabled will render each block light value when the lighting engine is run */
|
||||
private static final boolean RENDER_BLOCK_LIGHT_WIREFRAME = false;
|
||||
/** if enabled will render each sky light value when the lighting engine is run */
|
||||
private static final boolean RENDER_SKY_LIGHT_WIREFRAME = false;
|
||||
private static final ThreadLocal<DhBlockPos> PRIMARY_BLOCK_POS_REF = ThreadLocal.withInitial(DhBlockPos::new);
|
||||
private static final ThreadLocal<DhBlockPos> SECONDARY_BLOCK_POS_REF = ThreadLocal.withInitial(DhBlockPos::new);
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
private DhLightingEngine() { }
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// methods //
|
||||
//=========//
|
||||
|
||||
/**
|
||||
* Note: depending on the implementation of {@link IChunkWrapper#setDhBlockLight(int, int, int, int)} and {@link IChunkWrapper#setDhSkyLight(int, int, int, int)}
|
||||
* the light values may be stored in the wrapper itself instead of the wrapped chunk object.
|
||||
@@ -93,12 +76,12 @@ public class DhLightingEngine
|
||||
|
||||
|
||||
// try-finally to handle the stableArray resources
|
||||
StableLightPosStack blockLightWorldPosQueue = null;
|
||||
StableLightPosStack skyLightWorldPosQueue = null;
|
||||
StableLightPosStack blockLightPosQueue = null;
|
||||
StableLightPosStack skyLightPosQueue = null;
|
||||
try
|
||||
{
|
||||
blockLightWorldPosQueue = StableLightPosStack.borrowStableLightPosArray();
|
||||
skyLightWorldPosQueue = StableLightPosStack.borrowStableLightPosArray();
|
||||
blockLightPosQueue = StableLightPosStack.borrowStableLightPosArray();
|
||||
skyLightPosQueue = StableLightPosStack.borrowStableLightPosArray();
|
||||
|
||||
|
||||
|
||||
@@ -109,7 +92,7 @@ public class DhLightingEngine
|
||||
{
|
||||
for (int zOffset = -1; zOffset <= 1; zOffset++)
|
||||
{
|
||||
DhChunkPos adjacentPos = new DhChunkPos(centerChunkPos.getX() + xOffset, centerChunkPos.getZ() + zOffset);
|
||||
DhChunkPos adjacentPos = new DhChunkPos(centerChunkPos.x + xOffset, centerChunkPos.z + zOffset);
|
||||
requestedAdjacentPositions.add(adjacentPos);
|
||||
}
|
||||
}
|
||||
@@ -131,14 +114,11 @@ public class DhLightingEngine
|
||||
|
||||
|
||||
|
||||
//==================//
|
||||
// set block lights //
|
||||
//==================//
|
||||
|
||||
// get and set the adjacent chunk's initial block lights
|
||||
final DhBlockPosMutable relLightBlockPos = PRIMARY_BLOCK_POS_REF.get();
|
||||
final DhBlockPos relLightBlockPos = PRIMARY_BLOCK_POS_REF.get();
|
||||
final DhBlockPos relBlockPos = SECONDARY_BLOCK_POS_REF.get();
|
||||
|
||||
ArrayList<DhBlockPos> blockLightPosList = chunk.getWorldBlockLightPosList();
|
||||
ArrayList<DhBlockPos> blockLightPosList = chunk.getBlockLightPosList();
|
||||
for (int blockLightIndex = 0; blockLightIndex < blockLightPosList.size(); blockLightIndex++) // using iterators in high traffic areas can cause GC issues due to allocating a bunch of iterators, use an indexed for-loop instead
|
||||
{
|
||||
DhBlockPos blockLightPos = blockLightPosList.get(blockLightIndex);
|
||||
@@ -147,18 +127,14 @@ public class DhLightingEngine
|
||||
// get the light
|
||||
IBlockStateWrapper blockState = chunk.getBlockState(relLightBlockPos);
|
||||
int lightValue = blockState.getLightEmission();
|
||||
blockLightWorldPosQueue.push(blockLightPos.getX(), blockLightPos.getY(), blockLightPos.getZ(), lightValue);
|
||||
blockLightPosQueue.push(blockLightPos.x, blockLightPos.y, blockLightPos.z, lightValue);
|
||||
|
||||
// set the light
|
||||
chunk.setDhBlockLight(relLightBlockPos.getX(), relLightBlockPos.getY(), relLightBlockPos.getZ(), lightValue);
|
||||
blockLightPos.mutateToChunkRelativePos(relBlockPos);
|
||||
chunk.setDhBlockLight(relBlockPos.x, relBlockPos.y, relBlockPos.z, lightValue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// set sky lights //
|
||||
//================//
|
||||
|
||||
// get and set the adjacent chunk's initial skylights,
|
||||
// if the dimension has skylights
|
||||
if (maxSkyLight > 0)
|
||||
@@ -171,7 +147,7 @@ public class DhLightingEngine
|
||||
{
|
||||
for (int relZ = 0; relZ < LodUtil.CHUNK_WIDTH; relZ++)
|
||||
{
|
||||
// set each pos' sky light all the way down until an opaque block is hit
|
||||
// set each pos' sky light all the way down until a opaque block is hit
|
||||
for (int y = maxY; y >= minY; y--)
|
||||
{
|
||||
IBlockStateWrapper block = chunk.getBlockState(relX, y, relZ);
|
||||
@@ -184,11 +160,11 @@ public class DhLightingEngine
|
||||
|
||||
// add sky light to the queue
|
||||
DhBlockPos skyLightPos = new DhBlockPos(chunk.getMinBlockX() + relX, y, chunk.getMinBlockZ() + relZ);
|
||||
skyLightWorldPosQueue.push(skyLightPos.getX(), skyLightPos.getY(), skyLightPos.getZ(), maxSkyLight);
|
||||
skyLightPosQueue.push(skyLightPos.x, skyLightPos.y, skyLightPos.z, maxSkyLight);
|
||||
|
||||
// set the chunk's sky light
|
||||
skyLightPos.mutateToChunkRelativePos(relLightBlockPos);
|
||||
chunk.setDhSkyLight(relLightBlockPos.getX(), relLightBlockPos.getY(), relLightBlockPos.getZ(), maxSkyLight);
|
||||
skyLightPos.mutateToChunkRelativePos(relBlockPos);
|
||||
chunk.setDhSkyLight(relBlockPos.x, relBlockPos.y, relBlockPos.z, maxSkyLight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,16 +180,14 @@ public class DhLightingEngine
|
||||
}
|
||||
|
||||
// block light
|
||||
this.propagateLightPosList(blockLightWorldPosQueue, adjacentChunkHolder,
|
||||
(neighbourChunk, relBlockPos) -> neighbourChunk.getDhBlockLight(relBlockPos.getX(), relBlockPos.getY(), relBlockPos.getZ()),
|
||||
(neighbourChunk, relBlockPos, newLightValue) -> neighbourChunk.setDhBlockLight(relBlockPos.getX(), relBlockPos.getY(), relBlockPos.getZ(), newLightValue),
|
||||
true);
|
||||
this.propagateLightPosList(blockLightPosQueue, adjacentChunkHolder,
|
||||
(neighbourChunk, relBlockPos) -> neighbourChunk.getDhBlockLight(relBlockPos.x, relBlockPos.y, relBlockPos.z),
|
||||
(neighbourChunk, relBlockPos, newLightValue) -> neighbourChunk.setDhBlockLight(relBlockPos.x, relBlockPos.y, relBlockPos.z, newLightValue));
|
||||
|
||||
// sky light
|
||||
this.propagateLightPosList(skyLightWorldPosQueue, adjacentChunkHolder,
|
||||
(neighbourChunk, relBlockPos) -> neighbourChunk.getDhSkyLight(relBlockPos.getX(), relBlockPos.getY(), relBlockPos.getZ()),
|
||||
(neighbourChunk, relBlockPos, newLightValue) -> neighbourChunk.setDhSkyLight(relBlockPos.getX(), relBlockPos.getY(), relBlockPos.getZ(), newLightValue),
|
||||
false);
|
||||
this.propagateLightPosList(skyLightPosQueue, adjacentChunkHolder,
|
||||
(neighbourChunk, relBlockPos) -> neighbourChunk.getDhSkyLight(relBlockPos.x, relBlockPos.y, relBlockPos.z),
|
||||
(neighbourChunk, relBlockPos, newLightValue) -> neighbourChunk.setDhSkyLight(relBlockPos.x, relBlockPos.y, relBlockPos.z, newLightValue));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -221,8 +195,8 @@ public class DhLightingEngine
|
||||
}
|
||||
finally
|
||||
{
|
||||
StableLightPosStack.returnStableLightPosArray(blockLightWorldPosQueue);
|
||||
StableLightPosStack.returnStableLightPosArray(skyLightWorldPosQueue);
|
||||
StableLightPosStack.returnStableLightPosArray(blockLightPosQueue);
|
||||
StableLightPosStack.returnStableLightPosArray(skyLightPosQueue);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,14 +212,13 @@ public class DhLightingEngine
|
||||
/** Applies each {@link LightPos} from the queue to the given set of {@link IChunkWrapper}'s. */
|
||||
private void propagateLightPosList(
|
||||
StableLightPosStack lightPosQueue, AdjacentChunkHolder adjacentChunkHolder,
|
||||
IGetLightFunc getLightFunc, ISetLightFunc setLightFunc,
|
||||
boolean propagatingBlockLights)
|
||||
IGetLightFunc getLightFunc, ISetLightFunc setLightFunc)
|
||||
{
|
||||
// these objects are saved so they can be mutated throughout the method,
|
||||
// this reduces the number of allocations necessary, reducing GC pressure
|
||||
final LightPos lightPos = new LightPos(0, 0, 0, 0);
|
||||
final DhBlockPosMutable neighbourBlockPos = PRIMARY_BLOCK_POS_REF.get();
|
||||
final DhBlockPosMutable relNeighbourBlockPos = SECONDARY_BLOCK_POS_REF.get();
|
||||
final DhBlockPos neighbourBlockPos = PRIMARY_BLOCK_POS_REF.get();
|
||||
final DhBlockPos relNeighbourBlockPos = SECONDARY_BLOCK_POS_REF.get();
|
||||
|
||||
|
||||
// update each light position
|
||||
@@ -266,14 +239,14 @@ public class DhLightingEngine
|
||||
|
||||
|
||||
// only continue if the light position is inside one of our chunks
|
||||
IChunkWrapper neighbourChunk = adjacentChunkHolder.getByBlockPos(neighbourBlockPos.getX(), neighbourBlockPos.getZ());
|
||||
IChunkWrapper neighbourChunk = adjacentChunkHolder.getByBlockPos(neighbourBlockPos.x, neighbourBlockPos.z);
|
||||
if (neighbourChunk == null)
|
||||
{
|
||||
// the light pos is outside our generator's range, ignore it
|
||||
continue;
|
||||
}
|
||||
|
||||
if (relNeighbourBlockPos.getY() < neighbourChunk.getMinNonEmptyHeight() || relNeighbourBlockPos.getY() > neighbourChunk.getMaxBuildHeight())
|
||||
if (relNeighbourBlockPos.y < neighbourChunk.getMinNonEmptyHeight() || relNeighbourBlockPos.y > neighbourChunk.getMaxBuildHeight())
|
||||
{
|
||||
// the light pos is outside the chunk's min/max height,
|
||||
// this can happen if given a chunk that hasn't finished generating
|
||||
@@ -300,103 +273,16 @@ public class DhLightingEngine
|
||||
|
||||
// now that light has been propagated to this blockPos
|
||||
// we need to queue it up so its neighbours can be propagated as well
|
||||
lightPosQueue.push(neighbourBlockPos.getX(), neighbourBlockPos.getY(), neighbourBlockPos.getZ(), targetLevel);
|
||||
lightPosQueue.push(neighbourBlockPos.x, neighbourBlockPos.y, neighbourBlockPos.z, targetLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// can be enable if troubleshooting lighting issues
|
||||
if (RENDER_BLOCK_LIGHT_WIREFRAME && propagatingBlockLights)
|
||||
{
|
||||
RenderDhLightValuesAsWireframe(adjacentChunkHolder, true);
|
||||
}
|
||||
else if (RENDER_SKY_LIGHT_WIREFRAME && !propagatingBlockLights)
|
||||
{
|
||||
RenderDhLightValuesAsWireframe(adjacentChunkHolder, false);
|
||||
}
|
||||
|
||||
|
||||
// propagation complete
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// debugging //
|
||||
//===========//
|
||||
|
||||
/** Draw a wireframe representing each block's light value */
|
||||
private static void RenderDhLightValuesAsWireframe(AdjacentChunkHolder adjacentChunkHolder, boolean renderBlockLights)
|
||||
{
|
||||
for (IChunkWrapper chunk : adjacentChunkHolder.chunkArray)
|
||||
{
|
||||
if (chunk == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int chunkMinX = chunk.getMinBlockX();
|
||||
int chunkMinZ = chunk.getMinBlockZ();
|
||||
|
||||
int minY = chunk.getMinNonEmptyHeight();
|
||||
int maxY = chunk.getMaxNonEmptyHeight();
|
||||
|
||||
// check each position's light
|
||||
for (int x = 0; x < LodUtil.CHUNK_WIDTH; x++)
|
||||
{
|
||||
for (int z = 0; z < LodUtil.CHUNK_WIDTH; z++)
|
||||
{
|
||||
for (int y = minY; y < maxY; y++)
|
||||
{
|
||||
int lightValue = renderBlockLights? chunk.getDhBlockLight(x, y, z) : chunk.getDhSkyLight(x, y, z);
|
||||
if (lightValue != LodUtil.MIN_MC_LIGHT)
|
||||
{
|
||||
// hotter colors for more intense light
|
||||
Color color;
|
||||
if (lightValue >= 14)
|
||||
{
|
||||
color = Color.WHITE;
|
||||
}
|
||||
else if (lightValue >= 10)
|
||||
{
|
||||
color = Color.PINK;
|
||||
}
|
||||
else if (lightValue >= 6)
|
||||
{
|
||||
color = Color.YELLOW;
|
||||
}
|
||||
else if (lightValue >= 4)
|
||||
{
|
||||
color = Color.ORANGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = Color.RED;
|
||||
}
|
||||
|
||||
|
||||
// a color can be set to null if you only want to troubleshoot up to a certain light level
|
||||
if (color != null)
|
||||
{
|
||||
DebugRenderer.makeParticle(
|
||||
new DebugRenderer.BoxParticle(
|
||||
new DebugRenderer.Box(DhSectionPos.encode((byte) 0, chunkMinX + x, chunkMinZ + z), y, y + 1, 0.2f, color),
|
||||
10.0, 0f
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// helper classes //
|
||||
//================//
|
||||
@@ -407,7 +293,7 @@ public class DhLightingEngine
|
||||
@FunctionalInterface
|
||||
interface ISetLightFunc { void setLight(IChunkWrapper chunk, DhBlockPos pos, int lightValue); }
|
||||
|
||||
private static class LightPos extends DhBlockPosMutable
|
||||
private static class LightPos extends DhBlockPos
|
||||
{
|
||||
public int lightValue;
|
||||
|
||||
@@ -417,11 +303,6 @@ public class DhLightingEngine
|
||||
this.lightValue = lightValue;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() { return this.lightValue+" - ["+ this.x +", "+ this.y +", "+ this.z +"]"; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -521,9 +402,9 @@ public class DhLightingEngine
|
||||
{
|
||||
int subIndex = this.index * INTS_PER_LIGHT_POS;
|
||||
|
||||
pos.setX(this.lightPositions.getInt(subIndex));
|
||||
pos.setY(this.lightPositions.getInt(subIndex + 1));
|
||||
pos.setZ(this.lightPositions.getInt(subIndex + 2));
|
||||
pos.x = this.lightPositions.getInt(subIndex);
|
||||
pos.y = this.lightPositions.getInt(subIndex + 1);
|
||||
pos.z = this.lightPositions.getInt(subIndex + 2);
|
||||
pos.lightValue = this.lightPositions.getInt(subIndex + 3);
|
||||
|
||||
this.index--;
|
||||
|
||||
+1
-4
@@ -21,12 +21,11 @@ package com.seibel.distanthorizons.core.generation;
|
||||
|
||||
import com.seibel.distanthorizons.core.generation.tasks.IWorldGenTaskTracker;
|
||||
import com.seibel.distanthorizons.core.generation.tasks.WorldGenResult;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.render.LodQuadTree;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
@@ -106,7 +105,5 @@ public interface IFullDataSourceRetrievalQueue extends Closeable
|
||||
int getEstimatedTotalTaskCount();
|
||||
void setEstimatedTotalTaskCount(int newEstimate);
|
||||
|
||||
void addDebugMenuStringsToList(List<String> messageList);
|
||||
|
||||
|
||||
}
|
||||
+17
-49
@@ -27,7 +27,7 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.generation.tasks.*;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
@@ -47,7 +47,6 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -56,16 +55,6 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
private static final IWrapperFactory WRAPPER_FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
||||
|
||||
/**
|
||||
* Defines how many tasks can be queued per thread. <br><br>
|
||||
*
|
||||
* TODO the multiplier here should change dynamically based on how fast the generator is vs the queuing thread,
|
||||
* if this is too high it may cause issues when moving,
|
||||
* but if it is too low the generator threads won't have enough tasks to work on
|
||||
*/
|
||||
private static final int MAX_QUEUED_TASKS_PER_THREAD = 3;
|
||||
|
||||
|
||||
private final IDhApiWorldGenerator generator;
|
||||
|
||||
/** contains the positions that need to be generated */
|
||||
@@ -217,7 +206,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
|
||||
// queue generation tasks until the generator is full, or there are no more tasks to generate
|
||||
boolean taskStarted = true;
|
||||
while (!this.isGeneratorBusy() && taskStarted)
|
||||
while (!this.generator.isBusy() && taskStarted)
|
||||
{
|
||||
taskStarted = this.startNextWorldGenTask(this.generationTargetPos);
|
||||
if (!taskStarted)
|
||||
@@ -244,19 +233,6 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
}
|
||||
});
|
||||
}
|
||||
public boolean isGeneratorBusy()
|
||||
{
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getWorldGenExecutor();
|
||||
if (executor == null)
|
||||
{
|
||||
// shouldn't happen, but just in case, don't queue more tasks
|
||||
return true;
|
||||
}
|
||||
|
||||
int worldGenThreadCount = Math.max(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads.get(), 1);
|
||||
int maxWorldGenTaskCount = worldGenThreadCount * MAX_QUEUED_TASKS_PER_THREAD;
|
||||
return executor.getQueue().size() > maxWorldGenTaskCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param targetPos the position to center the generation around
|
||||
@@ -452,13 +428,11 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
{
|
||||
EDhApiDistantGeneratorMode generatorMode = Config.Client.Advanced.WorldGenerator.distantGeneratorMode.get();
|
||||
EDhApiWorldGeneratorReturnType returnType = this.generator.getReturnType();
|
||||
switch (returnType)
|
||||
return switch (returnType)
|
||||
{
|
||||
case VANILLA_CHUNKS:
|
||||
{
|
||||
return this.generator.generateChunks(
|
||||
chunkPosMin.getX(),
|
||||
chunkPosMin.getZ(),
|
||||
case VANILLA_CHUNKS -> this.generator.generateChunks(
|
||||
chunkPosMin.x,
|
||||
chunkPosMin.z,
|
||||
granularity,
|
||||
targetDataDetail,
|
||||
generatorMode,
|
||||
@@ -478,13 +452,10 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
case API_CHUNKS:
|
||||
{
|
||||
return this.generator.generateApiChunks(
|
||||
chunkPosMin.getX(),
|
||||
chunkPosMin.getZ(),
|
||||
);
|
||||
case API_CHUNKS -> this.generator.generateApiChunks(
|
||||
chunkPosMin.x,
|
||||
chunkPosMin.z,
|
||||
granularity,
|
||||
targetDataDetail,
|
||||
generatorMode,
|
||||
@@ -493,10 +464,10 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
{
|
||||
try
|
||||
{
|
||||
FullDataSourceV2 dataSource = LodDataBuilder.createFromApiChunkData(dataPoints, this.generator.runApiChunkValidation());
|
||||
FullDataSourceV2 dataSource = LodDataBuilder.createFromApiChunkData(dataPoints);
|
||||
chunkDataConsumer.accept(dataSource);
|
||||
}
|
||||
catch (DataCorruptedException | IllegalArgumentException e)
|
||||
catch (DataCorruptedException e)
|
||||
{
|
||||
LOGGER.error("World generator returned a corrupt chunk. Error: [" + e.getMessage() + "]. World generator disabled.", e);
|
||||
Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false);
|
||||
@@ -507,14 +478,13 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
default:
|
||||
);
|
||||
default ->
|
||||
{
|
||||
Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false);
|
||||
throw new AssertFailureException("Unknown return type: " + returnType);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -536,8 +506,6 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
@Override
|
||||
public void setEstimatedTotalTaskCount(int newEstimate) { this.estimatedTotalTaskCount = newEstimate; }
|
||||
|
||||
public void addDebugMenuStringsToList(List<String> messageList) { }
|
||||
|
||||
|
||||
|
||||
//==========//
|
||||
@@ -642,8 +610,8 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
||||
@Override
|
||||
public void debugRender(DebugRenderer renderer)
|
||||
{
|
||||
this.waitingTasks.keySet().forEach((pos) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.blue)); });
|
||||
this.inProgressGenTasksByLodPos.forEach((pos, t) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.red)); });
|
||||
this.waitingTasks.keySet().forEach((pos) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.blue)));
|
||||
this.inProgressGenTasksByLodPos.forEach((pos, t) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.red)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
package com.seibel.distanthorizons.core.generation;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.generation.tasks.IWorldGenTaskTracker;
|
||||
import com.seibel.distanthorizons.core.generation.tasks.WorldGenResult;
|
||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.multiplayer.client.AbstractFullDataRequestQueue;
|
||||
import com.seibel.distanthorizons.core.multiplayer.client.ClientNetworkState;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class WorldRemoteGenerationQueue extends AbstractFullDataRequestQueue implements IFullDataSourceRetrievalQueue, IDebugRenderable
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
private int estimatedTotalTaskCount;
|
||||
|
||||
|
||||
@Override
|
||||
protected int getRequestRateLimit() { return this.networkState.config.getGenerationRequestRateLimit(); }
|
||||
|
||||
@Override
|
||||
protected String getQueueName() { return "World Remote Generation Queue"; }
|
||||
|
||||
|
||||
public WorldRemoteGenerationQueue(ClientNetworkState networkState, IDhClientLevel level)
|
||||
{
|
||||
super(networkState, level, false, Config.Client.Advanced.Debugging.DebugWireframe.showWorldGenQueue);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte lowestDataDetail()
|
||||
{
|
||||
return LodUtil.BLOCK_DETAIL_LEVEL;
|
||||
}
|
||||
@Override
|
||||
public byte highestDataDetail()
|
||||
{
|
||||
return LodUtil.BLOCK_DETAIL_LEVEL;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<WorldGenResult> submitGenTask(long sectionPos, byte requiredDataDetail, IWorldGenTaskTracker tracker)
|
||||
{
|
||||
return super.submitRequest(sectionPos, tracker.getChunkDataConsumer())
|
||||
.thenApply(result -> result
|
||||
? WorldGenResult.CreateSuccess(sectionPos)
|
||||
: WorldGenResult.CreateFail());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAndSetTargetPos(DhBlockPos2D targetPos)
|
||||
{
|
||||
super.tick(targetPos);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getEstimatedTotalTaskCount() { return this.estimatedTotalTaskCount; }
|
||||
@Override
|
||||
public void setEstimatedTotalTaskCount(int newEstimate) { this.estimatedTotalTaskCount = newEstimate; }
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> startClosing(boolean cancelCurrentGeneration, boolean alsoInterruptRunning)
|
||||
{
|
||||
return super.startClosing(alsoInterruptRunning);
|
||||
}
|
||||
}
|
||||
-2
@@ -21,7 +21,6 @@ package com.seibel.distanthorizons.core.generation.tasks;
|
||||
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@@ -33,7 +32,6 @@ public interface IWorldGenTaskTracker
|
||||
/** Returns true if the task hasn't been garbage collected. */
|
||||
boolean isMemoryAddressValid();
|
||||
|
||||
@Nullable
|
||||
Consumer<FullDataSourceV2> getChunkDataConsumer();
|
||||
|
||||
}
|
||||
|
||||
@@ -40,20 +40,14 @@ public class DarkModeDetector
|
||||
|
||||
public static boolean isDarkMode()
|
||||
{
|
||||
switch (EPlatform.get())
|
||||
return switch (EPlatform.get())
|
||||
{
|
||||
case WINDOWS:
|
||||
return isWindowsDarkMode();
|
||||
case MACOS:
|
||||
return isMacOsDarkMode();
|
||||
case LINUX:
|
||||
// Most Unix(-like) distros also use a lot of the same things as Linux (like desktop environments and window managers)
|
||||
case BSD:
|
||||
case UNIX:
|
||||
return checkLinuxDark();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case WINDOWS -> isWindowsDarkMode();
|
||||
case MACOS -> isMacOsDarkMode();
|
||||
// Most Unix(-like) distros also use a lot of the same things as Linux (like desktop environments and window managers)
|
||||
case LINUX, BSD, UNIX -> checkLinuxDark();
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
// Needs checking as I dont use Mac
|
||||
|
||||
@@ -131,7 +131,7 @@ public class JarMain
|
||||
|
||||
|
||||
// Selected download
|
||||
AtomicReference<String> downloadID = new AtomicReference<String>("");
|
||||
AtomicReference<String> downloadID = new AtomicReference<>("");
|
||||
|
||||
|
||||
// This is for the panel to show the update description
|
||||
|
||||
@@ -175,17 +175,12 @@ public class JarUtils
|
||||
@Deprecated
|
||||
public static OperatingSystem getOperatingSystem()
|
||||
{ // Get the os and turn it into that enum
|
||||
switch (EPlatform.get())
|
||||
{
|
||||
case WINDOWS:
|
||||
return OperatingSystem.WINDOWS;
|
||||
case LINUX:
|
||||
return OperatingSystem.LINUX;
|
||||
case MACOS:
|
||||
return OperatingSystem.MACOS;
|
||||
default:
|
||||
return OperatingSystem.NONE;
|
||||
}
|
||||
return switch (EPlatform.get()) {
|
||||
case WINDOWS -> OperatingSystem.WINDOWS;
|
||||
case LINUX -> OperatingSystem.LINUX;
|
||||
case MACOS -> OperatingSystem.MACOS;
|
||||
default -> OperatingSystem.NONE;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class BaseJFrame extends JFrame
|
||||
final BufferedReader br = new BufferedReader(isr)
|
||||
)
|
||||
{
|
||||
List<Object> col = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(br.lines().toArray())));
|
||||
List<Object> col = List.of(br.lines().toArray());
|
||||
for (Object obj : col)
|
||||
{
|
||||
langsToChoose.add(((String) obj).replaceAll("\\.json", ""));
|
||||
@@ -101,7 +101,7 @@ public class BaseJFrame extends JFrame
|
||||
}
|
||||
|
||||
// Creates the box
|
||||
JComboBox<String> languageBox = new JComboBox(new DefaultComboBoxModel(langsToChoose.toArray()));
|
||||
JComboBox<String> languageBox = new JComboBox<>(new DefaultComboBoxModel(langsToChoose.toArray()));
|
||||
languageBox.setSelectedIndex(langsToChoose.indexOf(Locale.getDefault().toString().toLowerCase()));
|
||||
languageBox.addActionListener(e -> {
|
||||
Locale.setDefault(Locale.forLanguageTag(languageBox.getSelectedItem().toString())); // Change lang on update
|
||||
|
||||
@@ -133,7 +133,7 @@ public class GitlabGetter
|
||||
public static void main(String[] args) {
|
||||
GitlabGetter gitlabGetter = new GitlabGetter();
|
||||
|
||||
System.out.println(gitlabGetter.getDownloads(gitlabGetter.projectPipelines.get(0).get("id")));
|
||||
System.out.println(gitlabGetter.getDownloads(gitlabGetter.projectPipelines.getFirst().get("id")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-7
@@ -72,8 +72,8 @@ public class ModrinthGetter
|
||||
downloadUrl.put(workingID,
|
||||
new URL(
|
||||
((Config)
|
||||
((ArrayList) currentRelease.get("files"))
|
||||
.get(0))
|
||||
((ArrayList<?>) currentRelease.get("files"))
|
||||
.getFirst())
|
||||
.get("url")
|
||||
.toString()
|
||||
));
|
||||
@@ -112,7 +112,7 @@ public class ModrinthGetter
|
||||
{
|
||||
try
|
||||
{
|
||||
return mcVerToReleaseID.get(mcVer).get(0);
|
||||
return mcVerToReleaseID.get(mcVer).getFirst();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -121,17 +121,17 @@ public class ModrinthGetter
|
||||
}
|
||||
public static String getLatestNameForVersion(String mcVer)
|
||||
{
|
||||
return releaseNames.get(mcVerToReleaseID.get(mcVer).get(0));
|
||||
return releaseNames.get(mcVerToReleaseID.get(mcVer).getFirst());
|
||||
}
|
||||
public static URL getLatestDownloadForVersion(String mcVer)
|
||||
{
|
||||
return downloadUrl.get(mcVerToReleaseID.get(mcVer).get(0));
|
||||
return downloadUrl.get(mcVerToReleaseID.get(mcVer).getFirst());
|
||||
}
|
||||
public static String getLatestShaForVersion(String mcVer)
|
||||
{
|
||||
return (((ArrayList<Config>) idToJson.get(
|
||||
mcVerToReleaseID.get(mcVer).get(0)
|
||||
).get("files")).get(0).get("hashes.sha1")
|
||||
mcVerToReleaseID.get(mcVer).getFirst()
|
||||
).get("files")).getFirst().get("hashes.sha1")
|
||||
.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ public class SelfUpdater
|
||||
{
|
||||
if (GitlabGetter.INSTANCE.projectPipelines.size() == 0)
|
||||
return false;
|
||||
com.electronwill.nightconfig.core.Config pipeline = GitlabGetter.INSTANCE.projectPipelines.get(0);
|
||||
com.electronwill.nightconfig.core.Config pipeline = GitlabGetter.INSTANCE.projectPipelines.getFirst();
|
||||
|
||||
if (!pipeline.get("ref").equals(ModJarInfo.Git_Branch))
|
||||
{
|
||||
@@ -186,16 +186,13 @@ public class SelfUpdater
|
||||
}
|
||||
public static boolean updateMod(String minecraftVersion, File file)
|
||||
{
|
||||
boolean returnValue = false;
|
||||
switch (Config.Client.Advanced.AutoUpdater.updateBranch.get())
|
||||
boolean returnValue = switch (Config.Client.Advanced.AutoUpdater.updateBranch.get())
|
||||
{
|
||||
case STABLE:
|
||||
returnValue = updateStableMod(minecraftVersion, file);
|
||||
break;
|
||||
case NIGHTLY:
|
||||
returnValue = updateNightlyMod(minecraftVersion, file);
|
||||
break;
|
||||
case STABLE -> updateStableMod(minecraftVersion, file);
|
||||
case NIGHTLY -> updateNightlyMod(minecraftVersion, file);
|
||||
default -> false;
|
||||
};
|
||||
;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@@ -253,7 +250,7 @@ public class SelfUpdater
|
||||
|
||||
File mergedZip = file.getParentFile().toPath().resolve("merged.zip").toFile();
|
||||
|
||||
WebDownloader.downloadAsFile(GitlabGetter.INSTANCE.getDownloads(GitlabGetter.INSTANCE.projectPipelines.get(0).get("id")).get(minecraftVersion), mergedZip);
|
||||
WebDownloader.downloadAsFile(GitlabGetter.INSTANCE.getDownloads(GitlabGetter.INSTANCE.projectPipelines.getFirst().get("id")).get(minecraftVersion), mergedZip);
|
||||
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(mergedZip));
|
||||
ZipEntry zipEntry = zis.getNextEntry();
|
||||
@@ -301,7 +298,7 @@ public class SelfUpdater
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warn("Failed to update " + ModInfo.READABLE_NAME + " to version " + GitlabGetter.INSTANCE.projectPipelines.get(0).get("sha"));
|
||||
LOGGER.warn("Failed to update " + ModInfo.READABLE_NAME + " to version " + GitlabGetter.INSTANCE.projectPipelines.getFirst().get("sha"));
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,19 +19,28 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.level;
|
||||
|
||||
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiChunkModifiedEvent;
|
||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||
import com.seibel.distanthorizons.core.dataObjects.transformers.ChunkToLodBuilder;
|
||||
import com.seibel.distanthorizons.core.file.fullDatafile.DelayedFullDataSourceSaveCache;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.BeaconRenderHandler;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.CloudRenderHandler;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericRenderObjectFactory;
|
||||
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
||||
import com.seibel.distanthorizons.core.sql.dto.ChunkHashDTO;
|
||||
import com.seibel.distanthorizons.core.sql.repo.BeaconBeamRepo;
|
||||
import com.seibel.distanthorizons.core.sql.repo.ChunkHashRepo;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -40,14 +49,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class AbstractDhLevel implements IDhLevel
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
public final ChunkToLodBuilder chunkToLodBuilder;
|
||||
|
||||
/** if this is null then the other handler is probably null too, but just in case */
|
||||
@Nullable
|
||||
public ChunkHashRepo chunkHashRepo;
|
||||
@@ -55,10 +68,9 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
@Nullable
|
||||
public BeaconBeamRepo beaconBeamRepo;
|
||||
|
||||
protected final DelayedFullDataSourceSaveCache delayedFullDataSourceSaveCache = new DelayedFullDataSourceSaveCache(this::onDataSourceSave, 500);
|
||||
protected final DelayedFullDataSourceSaveCache delayedFullDataSourceSaveCache = new DelayedFullDataSourceSaveCache(this::onDataSourceSave, 2_000);
|
||||
/** contains the {@link DhChunkPos} for each {@link DhSectionPos} that are queued to save via {@link AbstractDhLevel#delayedFullDataSourceSaveCache} */
|
||||
protected final ConcurrentHashMap<Long, HashSet<DhChunkPos>> updatedChunkPosSetBySectionPos = new ConcurrentHashMap<>();
|
||||
protected final ConcurrentHashMap<DhChunkPos, Integer> updatedChunkHashesByChunkPos = new ConcurrentHashMap<>();
|
||||
|
||||
/** Will be null if clouds shouldn't be rendered for this level. */
|
||||
@Nullable
|
||||
@@ -71,7 +83,10 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
protected AbstractDhLevel() { }
|
||||
protected AbstractDhLevel()
|
||||
{
|
||||
this.chunkToLodBuilder = new ChunkToLodBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating the repos requires access to the level file, which isn't
|
||||
@@ -111,15 +126,11 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
GenericObjectRenderer genericRenderer = this.getGenericRenderer();
|
||||
if (genericRenderer != null)
|
||||
{
|
||||
// only client levels can render clouds
|
||||
if (this instanceof IDhClientLevel)
|
||||
// only add clouds for certain dimension types
|
||||
if (!this.getLevelWrapper().hasCeiling()
|
||||
&& !this.getLevelWrapper().getDimensionType().isTheEnd())
|
||||
{
|
||||
// only add clouds for certain dimension types
|
||||
if (!this.getLevelWrapper().hasCeiling()
|
||||
&& !this.getLevelWrapper().getDimensionType().isTheEnd())
|
||||
{
|
||||
this.cloudRenderHandler = new CloudRenderHandler((IDhClientLevel)this, genericRenderer);
|
||||
}
|
||||
this.cloudRenderHandler = new CloudRenderHandler(this, genericRenderer);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +152,7 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
public int getUnsavedDataSourceCount() { return this.delayedFullDataSourceSaveCache.getUnsavedCount(); }
|
||||
|
||||
@Override
|
||||
public void updateChunkAsync(IChunkWrapper chunkWrapper, int chunkHash)
|
||||
public void updateChunkAsync(IChunkWrapper chunkWrapper)
|
||||
{
|
||||
FullDataSourceV2 dataSource = FullDataSourceV2.createFromChunk(chunkWrapper);
|
||||
if (dataSource == null)
|
||||
@@ -160,7 +171,6 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
chunkPosSet.add(chunkWrapper.getChunkPos());
|
||||
return chunkPosSet;
|
||||
});
|
||||
this.updatedChunkHashesByChunkPos.put(chunkWrapper.getChunkPos(), chunkHash);
|
||||
|
||||
// batch updates to reduce overhead when flying around or breaking/placing a lot of blocks in an area
|
||||
this.delayedFullDataSourceSaveCache.queueDataSourceForUpdateAndSave(dataSource);
|
||||
@@ -175,16 +185,9 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
{
|
||||
for (DhChunkPos chunkPos : updatedChunkPosSet)
|
||||
{
|
||||
// save after the data source has been updated to prevent saving the hash without the associated datasource
|
||||
Integer chunkHash = this.updatedChunkHashesByChunkPos.remove(chunkPos);
|
||||
if (this.chunkHashRepo != null && chunkHash != null)
|
||||
{
|
||||
this.chunkHashRepo.save(new ChunkHashDTO(chunkPos, chunkHash));
|
||||
}
|
||||
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(
|
||||
DhApiChunkModifiedEvent.class,
|
||||
new DhApiChunkModifiedEvent.EventParam(this.getLevelWrapper(), chunkPos.getX(), chunkPos.getZ()));
|
||||
new DhApiChunkModifiedEvent.EventParam(this.getLevelWrapper(), chunkPos.x, chunkPos.z));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -209,6 +212,14 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
ChunkHashDTO dto = this.chunkHashRepo.getByKey(pos);
|
||||
return (dto != null) ? dto.chunkHash : 0;
|
||||
}
|
||||
@Override
|
||||
public void setChunkHash(DhChunkPos pos, int chunkHash)
|
||||
{
|
||||
if (this.chunkHashRepo != null)
|
||||
{
|
||||
this.chunkHashRepo.save(new ChunkHashDTO(pos, chunkHash));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -217,12 +228,11 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
//=================//
|
||||
|
||||
@Override
|
||||
public void updateBeaconBeamsForChunk(IChunkWrapper chunkToUpdate, ArrayList<IChunkWrapper> nearbyChunkList)
|
||||
public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List<BeaconBeamDTO> newBeamList)
|
||||
{
|
||||
if (this.beaconRenderHandler != null)
|
||||
{
|
||||
List<BeaconBeamDTO> activeBeamList = chunkToUpdate.getAllActiveBeacons(nearbyChunkList);
|
||||
this.beaconRenderHandler.setBeaconBeamsForChunk(chunkToUpdate.getChunkPos(), activeBeamList);
|
||||
this.beaconRenderHandler.setBeaconBeamsForChunk(chunkPos, newBeamList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,6 +262,8 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
this.chunkToLodBuilder.close();
|
||||
|
||||
if (this.chunkHashRepo != null)
|
||||
{
|
||||
this.chunkHashRepo.close();
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.file.AbstractDataSourceHandler;
|
||||
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.render.LodQuadTree;
|
||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||
@@ -258,8 +258,6 @@ public class ClientLevelModule implements Closeable, AbstractDataSourceHandler.I
|
||||
|
||||
public void clearRenderCache()
|
||||
{
|
||||
this.clientLevel.getClientLevelWrapper().clearBlockColorCache();
|
||||
|
||||
ClientRenderState ClientRenderState = this.ClientRenderStateRef.get();
|
||||
if (ClientRenderState != null && ClientRenderState.quadtree != null)
|
||||
{
|
||||
|
||||
@@ -20,27 +20,15 @@
|
||||
package com.seibel.distanthorizons.core.level;
|
||||
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.distanthorizons.core.config.AppliedConfigState;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
||||
import com.seibel.distanthorizons.core.file.fullDatafile.RemoteFullDataSourceProvider;
|
||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||
import com.seibel.distanthorizons.core.generation.WorldRemoteGenerationQueue;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.multiplayer.client.ClientNetworkState;
|
||||
import com.seibel.distanthorizons.core.multiplayer.client.SyncOnLoginRequestQueue;
|
||||
import com.seibel.distanthorizons.core.network.event.ScopedNetworkEventSource;
|
||||
import com.seibel.distanthorizons.core.network.messages.fullData.FullDataPartialUpdateMessage;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
||||
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
@@ -48,8 +36,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -58,66 +44,25 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
|
||||
private static class WorldGenState extends WorldGenModule.AbstractWorldGenState
|
||||
{
|
||||
WorldGenState(IDhClientLevel level, ClientNetworkState networkState)
|
||||
{
|
||||
this.worldGenerationQueue = new WorldRemoteGenerationQueue(networkState, level);
|
||||
}
|
||||
}
|
||||
|
||||
public final ClientLevelModule clientside;
|
||||
public final IClientLevelWrapper levelWrapper;
|
||||
public final AbstractSaveStructure saveStructure;
|
||||
public final RemoteFullDataSourceProvider dataFileHandler;
|
||||
|
||||
@CheckForNull
|
||||
private final ClientNetworkState networkState;
|
||||
@Nullable
|
||||
private final ScopedNetworkEventSource eventSource;
|
||||
|
||||
public final WorldGenModule worldGenModule;
|
||||
public final AppliedConfigState<Boolean> worldGeneratorEnabledConfig;
|
||||
|
||||
@Nullable
|
||||
private final SyncOnLoginRequestQueue syncOnLoginRequestQueue;
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
public DhClientLevel(AbstractSaveStructure saveStructure, IClientLevelWrapper clientLevelWrapper, @Nullable ClientNetworkState networkState) { this(saveStructure, clientLevelWrapper, null, true, networkState); }
|
||||
public DhClientLevel(AbstractSaveStructure saveStructure, IClientLevelWrapper clientLevelWrapper, @Nullable File fullDataSaveDirOverride, boolean enableRendering, @Nullable ClientNetworkState networkState)
|
||||
public DhClientLevel(AbstractSaveStructure saveStructure, IClientLevelWrapper clientLevelWrapper) { this(saveStructure, clientLevelWrapper, null, true); }
|
||||
public DhClientLevel(AbstractSaveStructure saveStructure, IClientLevelWrapper clientLevelWrapper, @Nullable File fullDataSaveDirOverride, boolean enableRendering)
|
||||
{
|
||||
if (saveStructure.getFullDataFolder(clientLevelWrapper).mkdirs())
|
||||
{
|
||||
LOGGER.warn("unable to create data folder.");
|
||||
}
|
||||
this.levelWrapper = clientLevelWrapper;
|
||||
this.levelWrapper.setParentLevel(this);
|
||||
this.saveStructure = saveStructure;
|
||||
|
||||
this.networkState = networkState;
|
||||
if (networkState != null)
|
||||
{
|
||||
this.eventSource = new ScopedNetworkEventSource(networkState.getSession());
|
||||
this.syncOnLoginRequestQueue = new SyncOnLoginRequestQueue(this, networkState);
|
||||
this.registerNetworkHandlers();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.eventSource = null;
|
||||
this.syncOnLoginRequestQueue = null;
|
||||
}
|
||||
|
||||
this.dataFileHandler = new RemoteFullDataSourceProvider(this, saveStructure, fullDataSaveDirOverride, this.syncOnLoginRequestQueue);
|
||||
this.worldGeneratorEnabledConfig = new AppliedConfigState<>(Config.Client.Advanced.WorldGenerator.enableDistantGeneration);
|
||||
this.worldGenModule = new WorldGenModule(this);
|
||||
|
||||
this.dataFileHandler = new RemoteFullDataSourceProvider(this, saveStructure, fullDataSaveDirOverride);
|
||||
this.clientside = new ClientLevelModule(this);
|
||||
|
||||
this.createAndSetSupportingRepos(this.dataFileHandler.repo.databaseFile);
|
||||
@@ -130,30 +75,7 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
}
|
||||
}
|
||||
|
||||
private void registerNetworkHandlers()
|
||||
{
|
||||
assert this.eventSource != null;
|
||||
assert this.networkState != null;
|
||||
|
||||
this.eventSource.registerHandler(FullDataPartialUpdateMessage.class, msg ->
|
||||
{
|
||||
try
|
||||
{
|
||||
FullDataSourceV2DTO dataSourceDto = this.networkState.decodeDataSourceAndReleaseBuffer(msg.payload);
|
||||
|
||||
if (!msg.isSameLevelAs(this.levelWrapper))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateDataSourcesAsync(dataSourceDto.createPooledDataSource(this.levelWrapper));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Error while updating full data source", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//==============//
|
||||
// tick methods //
|
||||
@@ -164,12 +86,8 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
{
|
||||
try
|
||||
{
|
||||
this.chunkToLodBuilder.tick();
|
||||
this.clientside.clientTick();
|
||||
|
||||
if (this.syncOnLoginRequestQueue != null)
|
||||
{
|
||||
this.syncOnLoginRequestQueue.tick(new DhBlockPos2D(MC_CLIENT.getPlayerBlockPos()));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -177,50 +95,6 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWorldGen()
|
||||
{
|
||||
ClientNetworkState networkState = this.networkState;
|
||||
|
||||
boolean isClientUsable = false, isAllowedDimension = false;
|
||||
if (networkState != null)
|
||||
{
|
||||
isClientUsable = networkState.isReady();
|
||||
isAllowedDimension = MC_CLIENT.getWrappedClientLevel() == this.levelWrapper;
|
||||
}
|
||||
|
||||
boolean shouldDoWorldGen = isClientUsable
|
||||
&& networkState.config.isDistantGenerationEnabled()
|
||||
&& isAllowedDimension
|
||||
&& this.clientside.isRendering();
|
||||
|
||||
boolean isWorldGenRunning = this.worldGenModule.isWorldGenRunning();
|
||||
if (shouldDoWorldGen && !isWorldGenRunning)
|
||||
{
|
||||
// start world gen
|
||||
this.worldGenModule.startWorldGen(this.dataFileHandler, new WorldGenState(this, networkState));
|
||||
|
||||
// populate the queue based on the current rendering tree
|
||||
ClientLevelModule.ClientRenderState renderState = this.clientside.ClientRenderStateRef.get();
|
||||
renderState.quadtree.leafNodeIterator().forEachRemaining(node -> {
|
||||
this.dataFileHandler.getAsync(node.sectionPos);
|
||||
});
|
||||
}
|
||||
else if (!shouldDoWorldGen && isWorldGenRunning)
|
||||
{
|
||||
// stop world gen
|
||||
this.worldGenModule.stopWorldGen(this.dataFileHandler);
|
||||
}
|
||||
|
||||
if (this.worldGenModule.isWorldGenRunning())
|
||||
{
|
||||
this.worldGenModule.worldGenTick(
|
||||
new DhBlockPos2D(MC_CLIENT.getPlayerBlockPos())
|
||||
.scale(MC_CLIENT.getWrappedClientLevel().getDimensionType().getTeleportationScale(this.getLevelWrapper().getDimensionType()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DhApiRenderParam renderEventParam, IProfilerWrapper profiler)
|
||||
{ this.clientside.render(renderEventParam, profiler); }
|
||||
@@ -236,16 +110,13 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
//================//
|
||||
|
||||
@Override
|
||||
public int computeBaseColor(DhBlockPos pos, IBiomeWrapper biome, IBlockStateWrapper block) { return this.levelWrapper.getBlockColor(pos, biome, block); }
|
||||
public int computeBaseColor(DhBlockPos pos, IBiomeWrapper biome, IBlockStateWrapper block) { return this.levelWrapper.computeBaseColor(pos, biome, block); }
|
||||
|
||||
@Override
|
||||
public IClientLevelWrapper getClientLevelWrapper() { return this.levelWrapper; }
|
||||
|
||||
@Override
|
||||
public void clearRenderCache()
|
||||
{
|
||||
this.clientside.clearRenderCache();
|
||||
}
|
||||
public void clearRenderCache() { this.clientside.clearRenderCache(); }
|
||||
|
||||
@Override
|
||||
public ILevelWrapper getLevelWrapper() { return this.levelWrapper; }
|
||||
@@ -259,7 +130,7 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
@Override
|
||||
public void addDebugMenuStringsToList(List<String> messageList)
|
||||
{
|
||||
String dimName = this.levelWrapper.getDimensionName();
|
||||
String dimName = this.levelWrapper.getDimensionType().getDimensionName();
|
||||
boolean rendering = this.clientside.isRendering();
|
||||
messageList.add("["+dimName+"] rendering: "+(rendering ? "yes" : "no"));
|
||||
|
||||
@@ -282,33 +153,11 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
{
|
||||
messageList.add(" Migration Failed");
|
||||
}
|
||||
|
||||
|
||||
// world gen
|
||||
this.worldGenModule.addDebugMenuStringsToList(messageList);
|
||||
if (this.syncOnLoginRequestQueue != null)
|
||||
{
|
||||
assert this.networkState != null;
|
||||
if (this.networkState.config.getSynchronizeOnLogin())
|
||||
{
|
||||
this.syncOnLoginRequestQueue.addDebugMenuStringsToList(messageList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
if (this.worldGenModule != null)
|
||||
{
|
||||
this.worldGenModule.close();
|
||||
}
|
||||
|
||||
if (this.eventSource != null)
|
||||
{
|
||||
this.eventSource.close();
|
||||
}
|
||||
|
||||
this.levelWrapper.setParentLevel(null);
|
||||
this.clientside.close();
|
||||
super.close();
|
||||
@@ -335,16 +184,4 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
return (renderState != null) ? renderState.renderBufferHandler : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldGenTaskComplete(long pos)
|
||||
{
|
||||
DebugRenderer.makeParticle(
|
||||
new DebugRenderer.BoxParticle(
|
||||
new DebugRenderer.Box(pos, 128f, 156f, 0.09f, Color.red.darker()),
|
||||
0.2, 32f
|
||||
)
|
||||
);
|
||||
|
||||
this.clientside.reloadPos(pos);
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@ import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
@@ -95,7 +95,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
||||
{ this.clientside.renderDeferred(renderEventParam, profiler); }
|
||||
|
||||
@Override
|
||||
public void serverTick() { }
|
||||
public void serverTick() { this.chunkToLodBuilder.tick(); }
|
||||
|
||||
@Override
|
||||
public void doWorldGen()
|
||||
@@ -146,7 +146,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
||||
}
|
||||
else
|
||||
{
|
||||
return clientLevel.getBlockColor(pos, biome, block);
|
||||
return clientLevel.computeBaseColor(pos, biome, block);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,14 +154,15 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
||||
public IClientLevelWrapper getClientLevelWrapper() { return MC_CLIENT.getWrappedClientLevel(); }
|
||||
|
||||
@Override
|
||||
public void clearRenderCache() {
|
||||
this.clientside.clearRenderCache();
|
||||
public void clearRenderCache()
|
||||
{
|
||||
clientside.clearRenderCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IServerLevelWrapper getServerLevelWrapper() { return this.serverLevelWrapper; }
|
||||
public IServerLevelWrapper getServerLevelWrapper() { return serverLevelWrapper; }
|
||||
@Override
|
||||
public ILevelWrapper getLevelWrapper() { return this.getServerLevelWrapper(); }
|
||||
public ILevelWrapper getLevelWrapper() { return getServerLevelWrapper(); }
|
||||
|
||||
@Override
|
||||
public FullDataSourceProviderV2 getFullDataProvider() { return this.serverside.fullDataFileHandler; }
|
||||
@@ -169,7 +170,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
||||
@Override
|
||||
public AbstractSaveStructure getSaveStructure()
|
||||
{
|
||||
return this.serverside.saveStructure;
|
||||
return serverside.saveStructure;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,7 +192,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
||||
public void addDebugMenuStringsToList(List<String> messageList)
|
||||
{
|
||||
// header
|
||||
String dimName = this.serverLevelWrapper.getDimensionName();
|
||||
String dimName = this.serverLevelWrapper.getDimensionType().getDimensionName();
|
||||
boolean rendering = this.clientside.isRendering();
|
||||
messageList.add("["+dimName+"] rendering: "+(rendering ? "yes" : "no"));
|
||||
|
||||
@@ -218,7 +219,12 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
||||
|
||||
|
||||
// world gen
|
||||
this.serverside.worldGenModule.addDebugMenuStringsToList(messageList);
|
||||
WorldGenModule worldGenState = this.serverside.worldGenModule;
|
||||
String worldGenDisplayString = worldGenState.getDebugMenuString();
|
||||
if (worldGenDisplayString != null)
|
||||
{
|
||||
messageList.add(worldGenDisplayString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,73 +19,33 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.level;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.multiplayer.server.RemotePlayerConnectionHandler;
|
||||
import com.seibel.distanthorizons.core.multiplayer.server.ServerPlayerState;
|
||||
import com.seibel.distanthorizons.core.network.exceptions.InvalidLevelException;
|
||||
import com.seibel.distanthorizons.core.network.exceptions.RequestRejectedException;
|
||||
import com.seibel.distanthorizons.core.network.messages.ILevelRelatedMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.TrackableMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.fullData.FullDataPartialUpdateMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.fullData.FullDataPayload;
|
||||
import com.seibel.distanthorizons.core.network.messages.fullData.FullDataSourceRequestMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.fullData.FullDataSourceResponseMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.requests.CancelMessage;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
private static final ConfigBasedLogger NETWORK_LOGGER = new ConfigBasedLogger(LogManager.getLogger(),
|
||||
() -> Config.Client.Advanced.Logging.logNetworkEvent.get());
|
||||
|
||||
public static final int FULL_DATA_CHUNK_SIZE = 1048000; // 576 bytes left for other contents
|
||||
|
||||
public final ServerLevelModule serverside;
|
||||
private final IServerLevelWrapper serverLevelWrapper;
|
||||
|
||||
private final RemotePlayerConnectionHandler remotePlayerConnectionHandler;
|
||||
|
||||
/**
|
||||
* This queue is used for ensuring fair generation speed for each player. <br>
|
||||
* Every tick the first player gets used for centering generation, and then is immediately moved into the back of the queue. <br>
|
||||
* TODO only add players that actually have something to generate
|
||||
*/
|
||||
private final ConcurrentLinkedQueue<IServerPlayerWrapper> worldGenPlayerCenteringQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private final ConcurrentMap<Long, DataSourceRequestGroup> requestGroupsByPos = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Long, DataSourceRequestGroup> requestGroupsByFutureId = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
public DhServerLevel(AbstractSaveStructure saveStructure, IServerLevelWrapper serverLevelWrapper, RemotePlayerConnectionHandler remotePlayerConnectionHandler)
|
||||
public DhServerLevel(AbstractSaveStructure saveStructure, IServerLevelWrapper serverLevelWrapper)
|
||||
{
|
||||
if (saveStructure.getFullDataFolder(serverLevelWrapper).mkdirs())
|
||||
{
|
||||
@@ -97,363 +57,74 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
|
||||
this.runRepoReliantSetup();
|
||||
|
||||
LOGGER.info("Started DHLevel for {} with saves at {}", serverLevelWrapper, saveStructure);
|
||||
|
||||
this.remotePlayerConnectionHandler = remotePlayerConnectionHandler;
|
||||
}
|
||||
|
||||
public void registerNetworkHandlers(ServerPlayerState serverPlayerState)
|
||||
{
|
||||
serverPlayerState.session.registerHandler(FullDataSourceRequestMessage.class, this.currentLevelOnly(msg ->
|
||||
{
|
||||
ServerPlayerState.RateLimiterSet rateLimiterSet = serverPlayerState.getRateLimiterSet(this);
|
||||
|
||||
if (msg.clientTimestamp == null)
|
||||
{
|
||||
// Normal generation
|
||||
|
||||
if (!serverPlayerState.config.isDistantGenerationEnabled())
|
||||
{
|
||||
msg.sendResponse(new RequestRejectedException("Operation is disabled from config."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rateLimiterSet.generationRequestRateLimiter.tryAcquire(msg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
DataSourceRequestGroup requestGroup = this.requestGroupsByPos.computeIfAbsent(msg.sectionPos, pos ->
|
||||
{
|
||||
DataSourceRequestGroup newGroup = new DataSourceRequestGroup();
|
||||
this.tryFulfillDataSourceRequestGroup(newGroup, pos);
|
||||
NETWORK_LOGGER.debug("[{}] Created request group for pos {}", this.serverLevelWrapper.getDimensionName(), pos);
|
||||
return newGroup;
|
||||
});
|
||||
|
||||
// If this fails, loop until either permit is acquired or group is removed to create another one
|
||||
if (!requestGroup.requestAddSemaphore.tryAcquire())
|
||||
{
|
||||
Thread.yield();
|
||||
continue;
|
||||
}
|
||||
|
||||
this.requestGroupsByFutureId.put(msg.futureId, requestGroup);
|
||||
requestGroup.requestMessages.put(msg.futureId, msg);
|
||||
requestGroup.requestAddSemaphore.release();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sync only
|
||||
|
||||
if (!serverPlayerState.config.getSynchronizeOnLogin())
|
||||
{
|
||||
msg.sendResponse(new RequestRejectedException("Operation is disabled from config."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rateLimiterSet.syncOnLoginRateLimiter.tryAcquire(msg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Long serverTimestamp = this.serverside.fullDataFileHandler.getTimestampForPos(msg.sectionPos);
|
||||
if (serverTimestamp == null || serverTimestamp <= msg.clientTimestamp)
|
||||
{
|
||||
rateLimiterSet.syncOnLoginRateLimiter.release();
|
||||
msg.sendResponse(new FullDataSourceResponseMessage(null));
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getNetworkCompressionExecutor();
|
||||
if (executor == null)
|
||||
{
|
||||
LOGGER.warn("Unable to send FullDataSourceResponseMessage - getNetworkCompressionExecutor() is null");
|
||||
return;
|
||||
}
|
||||
this.serverside.fullDataFileHandler.getAsync(msg.sectionPos).thenAcceptAsync(fullDataSource ->
|
||||
{
|
||||
rateLimiterSet.syncOnLoginRateLimiter.release();
|
||||
|
||||
FullDataPayload payload = new FullDataPayload(fullDataSource);
|
||||
payload.acceptInChunkMessages(FULL_DATA_CHUNK_SIZE, msg.getSession()::sendMessage);
|
||||
msg.sendResponse(new FullDataSourceResponseMessage(payload));
|
||||
}, executor);
|
||||
}
|
||||
}));
|
||||
|
||||
serverPlayerState.session.registerHandler(CancelMessage.class, msg ->
|
||||
{
|
||||
DataSourceRequestGroup requestGroup = this.requestGroupsByFutureId.remove(msg.futureId);
|
||||
if (requestGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If this fails, group is being removed and completing cancellation is not necessary
|
||||
if (requestGroup.requestRemoveSemaphore.tryAcquire())
|
||||
{
|
||||
// Prevent adding requests in case the group will be removed by this cancellation
|
||||
requestGroup.requestAddSemaphore.acquireUninterruptibly(Short.MAX_VALUE);
|
||||
requestGroup.requestRemoveSemaphore.release();
|
||||
|
||||
serverPlayerState.getRateLimiterSet(this).generationRequestRateLimiter.release();
|
||||
|
||||
FullDataSourceRequestMessage requestMessage = requestGroup.requestMessages.remove(msg.futureId);
|
||||
if (requestGroup.requestMessages.isEmpty())
|
||||
{
|
||||
NETWORK_LOGGER.debug("[{}] Cancelled request group {}", this.serverLevelWrapper.getDimensionName(), requestMessage.sectionPos);
|
||||
this.requestGroupsByPos.remove(requestMessage.sectionPos);
|
||||
this.serverside.fullDataFileHandler.removeRetrievalRequestIf(pos -> pos == requestMessage.sectionPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
requestGroup.requestAddSemaphore.release(Short.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public <T extends NetworkMessage> Consumer<T> currentLevelOnly(Consumer<T> next)
|
||||
{
|
||||
return msg ->
|
||||
{
|
||||
LodUtil.assertTrue(msg instanceof ILevelRelatedMessage, MessageFormat.format("Received message does not implement {0}: {1}", ILevelRelatedMessage.class.getSimpleName(), msg.getClass().getSimpleName()));
|
||||
|
||||
// Handle only in requested dimension
|
||||
if (!((ILevelRelatedMessage) msg).isSameLevelAs(this.getServerLevelWrapper()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If player is not in this dimension and handling multiple dimensions at once is not allowed
|
||||
assert msg.getSession().serverPlayer != null;
|
||||
if (msg.getSession().serverPlayer.getLevel() != this.getLevelWrapper())
|
||||
{
|
||||
// If the message can be replied to - reply with error, otherwise just ignore
|
||||
if (msg instanceof TrackableMessage)
|
||||
{
|
||||
((TrackableMessage) msg).sendResponse(new InvalidLevelException(MessageFormat.format(
|
||||
"Generation not allowed. Requested dimension: {0}, player dimension: {1}, handler dimension: {2}",
|
||||
((ILevelRelatedMessage) msg).getLevelName(),
|
||||
msg.getSession().serverPlayer.getLevel().getDimensionName(),
|
||||
this.getLevelWrapper().getDimensionName()
|
||||
)));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
next.accept(msg);
|
||||
};
|
||||
}
|
||||
|
||||
//=========//
|
||||
// methods //
|
||||
//=========//
|
||||
|
||||
public void addPlayer(IServerPlayerWrapper serverPlayer)
|
||||
{
|
||||
this.worldGenPlayerCenteringQueue.add(serverPlayer);
|
||||
}
|
||||
public void removePlayer(IServerPlayerWrapper serverPlayer)
|
||||
{
|
||||
this.worldGenPlayerCenteringQueue.remove(serverPlayer);
|
||||
}
|
||||
public void serverTick() { this.chunkToLodBuilder.tick(); }
|
||||
|
||||
@Override
|
||||
public void serverTick()
|
||||
{
|
||||
// Send finished data source requests
|
||||
for (Map.Entry<Long, DataSourceRequestGroup> entry : this.requestGroupsByPos.entrySet())
|
||||
{
|
||||
DataSourceRequestGroup requestGroup = entry.getValue();
|
||||
|
||||
if (requestGroup.fullDataSource == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
NETWORK_LOGGER.debug("[{}] Fulfilled request group {}", this.serverLevelWrapper.getDimensionName(), entry.getKey());
|
||||
|
||||
// Make this group unavailable for adding into
|
||||
this.requestGroupsByPos.remove(entry.getKey());
|
||||
requestGroup.requestRemoveSemaphore.acquireUninterruptibly(Short.MAX_VALUE);
|
||||
requestGroup.requestAddSemaphore.acquireUninterruptibly(Short.MAX_VALUE);
|
||||
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getNetworkCompressionExecutor();
|
||||
if (executor == null)
|
||||
{
|
||||
LOGGER.warn("Unable to send FullDataSourceResponseMessage - getNetworkCompressionExecutor() is null");
|
||||
continue;
|
||||
}
|
||||
CompletableFuture.runAsync(() ->
|
||||
{
|
||||
FullDataPayload payload = new FullDataPayload(requestGroup.fullDataSource);
|
||||
for (FullDataSourceRequestMessage msg : requestGroup.requestMessages.values())
|
||||
{
|
||||
this.requestGroupsByFutureId.remove(msg.futureId);
|
||||
|
||||
ServerPlayerState serverPlayerState = this.remotePlayerConnectionHandler.getConnectedPlayer(msg.serverPlayer());
|
||||
if (serverPlayerState == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
serverPlayerState.getRateLimiterSet(this).generationRequestRateLimiter.release();
|
||||
payload.acceptInChunkMessages(FULL_DATA_CHUNK_SIZE, msg.getSession()::sendMessage);
|
||||
msg.sendResponse(new FullDataSourceResponseMessage(payload));
|
||||
}
|
||||
}, executor);
|
||||
}
|
||||
}
|
||||
public CompletableFuture<Void> updateDataSourcesAsync(FullDataSourceV2 data) { return this.getFullDataProvider().updateDataSourceAsync(data); }
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> updateDataSourcesAsync(FullDataSourceV2 data)
|
||||
{
|
||||
if (!Config.Client.Advanced.Multiplayer.ServerNetworking.enableRealTimeUpdates.get())
|
||||
{
|
||||
return this.getFullDataProvider().updateDataSourceAsync(data);
|
||||
}
|
||||
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getNetworkCompressionExecutor();
|
||||
if (executor == null)
|
||||
{
|
||||
LOGGER.warn("Unable to send FullDataPartialUpdateMessage - getNetworkCompressionExecutor() is null");
|
||||
return this.getFullDataProvider().updateDataSourceAsync(data);
|
||||
}
|
||||
CompletableFuture.runAsync(() ->
|
||||
{
|
||||
FullDataPayload payload = new FullDataPayload(data);
|
||||
for (ServerPlayerState serverPlayerState : this.remotePlayerConnectionHandler.getConnectedPlayers())
|
||||
{
|
||||
if (serverPlayerState.serverPlayer().getLevel() != this.serverLevelWrapper)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!serverPlayerState.config.isRealTimeUpdatesEnabled())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Vec3d playerPosition = serverPlayerState.serverPlayer().getPosition();
|
||||
int distanceFromPlayer = DhSectionPos.getManhattanBlockDistance(data.getPos(), new DhBlockPos2D((int) playerPosition.x, (int) playerPosition.z)) / 16;
|
||||
if (distanceFromPlayer >= serverPlayerState.serverPlayer().getViewDistance() &&
|
||||
distanceFromPlayer <= serverPlayerState.config.getRenderDistanceRadius())
|
||||
{
|
||||
payload.acceptInChunkMessages(FULL_DATA_CHUNK_SIZE, serverPlayerState.session::sendMessage);
|
||||
serverPlayerState.session.sendMessage(new FullDataPartialUpdateMessage(this.serverLevelWrapper, payload));
|
||||
}
|
||||
}
|
||||
}, executor);
|
||||
|
||||
|
||||
return this.getFullDataProvider().updateDataSourceAsync(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinY()
|
||||
{
|
||||
return this.getLevelWrapper().getMinHeight();
|
||||
}
|
||||
public int getMinY() { return getLevelWrapper().getMinHeight(); }
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
super.close();
|
||||
this.serverside.close();
|
||||
LOGGER.info("Closed DHLevel for {}", this.getLevelWrapper());
|
||||
serverside.close();
|
||||
LOGGER.info("Closed DHLevel for {}", getLevelWrapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWorldGen()
|
||||
{
|
||||
boolean shouldDoWorldGen = true; //todo;
|
||||
boolean isWorldGenRunning = this.serverside.worldGenModule.isWorldGenRunning();
|
||||
boolean isWorldGenRunning = serverside.worldGenModule.isWorldGenRunning();
|
||||
if (shouldDoWorldGen && !isWorldGenRunning)
|
||||
{
|
||||
// start world gen
|
||||
this.serverside.worldGenModule.startWorldGen(this.serverside.fullDataFileHandler, new ServerLevelModule.WorldGenState(this));
|
||||
serverside.worldGenModule.startWorldGen(serverside.fullDataFileHandler, new ServerLevelModule.WorldGenState(this));
|
||||
}
|
||||
else if (!shouldDoWorldGen && isWorldGenRunning)
|
||||
{
|
||||
// stop world gen
|
||||
this.serverside.worldGenModule.stopWorldGen(this.serverside.fullDataFileHandler);
|
||||
serverside.worldGenModule.stopWorldGen(serverside.fullDataFileHandler);
|
||||
}
|
||||
|
||||
if (this.serverside.worldGenModule.isWorldGenRunning())
|
||||
if (serverside.worldGenModule.isWorldGenRunning())
|
||||
{
|
||||
IServerPlayerWrapper firstPlayer = this.worldGenPlayerCenteringQueue.peek();
|
||||
if (firstPlayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Put first player in back before removing from front, so it can be removed by other thread without blocking
|
||||
// - if it gets removed, remove() below will remove the item we just put instead
|
||||
this.worldGenPlayerCenteringQueue.add(firstPlayer);
|
||||
this.worldGenPlayerCenteringQueue.remove(firstPlayer);
|
||||
|
||||
Vec3d position = firstPlayer.getPosition();
|
||||
this.serverside.worldGenModule.worldGenTick(new DhBlockPos2D((int) position.x, (int) position.z));
|
||||
serverside.worldGenModule.worldGenTick(new DhBlockPos2D(0, 0)); // todo;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IServerLevelWrapper getServerLevelWrapper()
|
||||
{
|
||||
return this.serverLevelWrapper;
|
||||
}
|
||||
public IServerLevelWrapper getServerLevelWrapper() { return serverLevelWrapper; }
|
||||
|
||||
@Override
|
||||
public ILevelWrapper getLevelWrapper()
|
||||
{
|
||||
return this.getServerLevelWrapper();
|
||||
}
|
||||
public ILevelWrapper getLevelWrapper() { return getServerLevelWrapper(); }
|
||||
|
||||
@Override
|
||||
public FullDataSourceProviderV2 getFullDataProvider()
|
||||
{
|
||||
return this.serverside.fullDataFileHandler;
|
||||
}
|
||||
public FullDataSourceProviderV2 getFullDataProvider() { return this.serverside.fullDataFileHandler; }
|
||||
|
||||
@Override
|
||||
public AbstractSaveStructure getSaveStructure()
|
||||
{
|
||||
return this.serverside.saveStructure;
|
||||
return serverside.saveStructure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight() { return this.serverLevelWrapper.hasSkyLight(); }
|
||||
|
||||
private void tryFulfillDataSourceRequestGroup(DataSourceRequestGroup requestGroup, long pos)
|
||||
{
|
||||
this.serverside.fullDataFileHandler.getAsync(pos).thenAccept(fullDataSource -> {
|
||||
if (this.serverside.fullDataFileHandler.isFullyGenerated(fullDataSource.columnGenerationSteps))
|
||||
{
|
||||
requestGroup.fullDataSource = fullDataSource;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.serverside.fullDataFileHandler.queuePositionForRetrieval(pos);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldGenTaskComplete(long pos)
|
||||
{
|
||||
DataSourceRequestGroup requestGroup = this.requestGroupsByPos.get(pos);
|
||||
if (requestGroup != null)
|
||||
{
|
||||
this.tryFulfillDataSourceRequestGroup(requestGroup, pos);
|
||||
}
|
||||
//TODO: Send packet to client
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -477,21 +148,8 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
|
||||
@Override
|
||||
public void addDebugMenuStringsToList(List<String> messageList)
|
||||
{
|
||||
String dimName = this.serverLevelWrapper.getDimensionName();
|
||||
String dimName = this.serverLevelWrapper.getDimensionType().getDimensionName();
|
||||
messageList.add("["+dimName+"]");
|
||||
}
|
||||
|
||||
private static class DataSourceRequestGroup
|
||||
{
|
||||
public final ConcurrentMap<Long, FullDataSourceRequestMessage> requestMessages = new ConcurrentHashMap<>();
|
||||
|
||||
@CheckForNull
|
||||
public FullDataSourceV2 fullDataSource;
|
||||
|
||||
// Maybe there's a better way to do synchronization, but this should suffice
|
||||
// Why not something like ReentrantReadWriteLock: locks should not be bound to threads
|
||||
public final Semaphore requestAddSemaphore = new Semaphore(Short.MAX_VALUE, true);
|
||||
public final Semaphore requestRemoveSemaphore = new Semaphore(Short.MAX_VALUE, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,13 +20,13 @@
|
||||
package com.seibel.distanthorizons.core.level;
|
||||
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
|
||||
public interface IDhClientLevel extends IDhWorldGenLevel
|
||||
public interface IDhClientLevel extends IDhLevel
|
||||
{
|
||||
void clientTick();
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -45,10 +45,11 @@ public interface IDhLevel extends AutoCloseable
|
||||
|
||||
/** @return 0 if no hash is known */
|
||||
int getChunkHash(DhChunkPos pos);
|
||||
void updateChunkAsync(IChunkWrapper chunk, int newChunkHash);
|
||||
void setChunkHash(DhChunkPos pos, int chunkHash);
|
||||
void updateChunkAsync(IChunkWrapper chunk);
|
||||
|
||||
void loadBeaconBeamsInPos(long pos);
|
||||
void updateBeaconBeamsForChunk(IChunkWrapper chunkToUpdate, ArrayList<IChunkWrapper> nearbyChunkList);
|
||||
void setBeaconBeamsForChunk(DhChunkPos chunkPos, List<BeaconBeamDTO> beamList);
|
||||
void unloadBeaconBeamsInPos(long pos);
|
||||
|
||||
FullDataSourceProviderV2 getFullDataProvider();
|
||||
|
||||
+9
-6
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.level;
|
||||
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
|
||||
|
||||
/**
|
||||
@@ -28,12 +28,15 @@ import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindab
|
||||
*/
|
||||
public interface IKeyedClientLevelManager extends IBindable
|
||||
{
|
||||
IServerKeyedClientLevel getServerKeyedLevel();
|
||||
/** Called when a client level is wrapped by a ServerEnhancedClientLevel, for integration into mod internals. */
|
||||
IServerKeyedClientLevel setServerKeyedLevel(IClientLevelWrapper clientLevel, String levelKey);
|
||||
void clearServerKeyedLevel();
|
||||
void setServerKeyedLevel(IServerKeyedClientLevel clientLevel);
|
||||
IServerKeyedClientLevel getOverrideWrapper();
|
||||
|
||||
boolean isEnabled();
|
||||
void disable();
|
||||
/** Returns a new instance of a ServerEnhancedClientLevel. */
|
||||
IServerKeyedClientLevel getServerKeyedLevel(ILevelWrapper level, String serverLevelKey);
|
||||
|
||||
/** Sets the LOD engine to use the override wrapper, if the server has communication enabled. */
|
||||
void setUseOverrideWrapper(boolean useOverrideWrapper);
|
||||
boolean getUseOverrideWrapper();
|
||||
|
||||
}
|
||||
|
||||
@@ -23,11 +23,10 @@ import com.seibel.distanthorizons.core.file.fullDatafile.GeneratedFullDataSource
|
||||
import com.seibel.distanthorizons.core.generation.IFullDataSourceRetrievalQueue;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -138,21 +137,20 @@ public class WorldGenModule implements Closeable
|
||||
|
||||
public boolean isWorldGenRunning() { return this.worldGenStateRef.get() != null; }
|
||||
|
||||
public void addDebugMenuStringsToList(List<String> messageList)
|
||||
public String getDebugMenuString()
|
||||
{
|
||||
AbstractWorldGenState worldGenState = this.worldGenStateRef.get();
|
||||
if (worldGenState == null)
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
String waitingCountStr = F3Screen.NUMBER_FORMAT.format(worldGenState.worldGenerationQueue.getWaitingTaskCount());
|
||||
String inProgressCountStr = F3Screen.NUMBER_FORMAT.format(worldGenState.worldGenerationQueue.getInProgressTaskCount());
|
||||
String totalCountEstimateStr = F3Screen.NUMBER_FORMAT.format(worldGenState.worldGenerationQueue.getEstimatedTotalTaskCount());
|
||||
messageList.add("World Gen Tasks: "+waitingCountStr+"/"+totalCountEstimateStr+" (in progress: "+inProgressCountStr+")");
|
||||
|
||||
worldGenState.worldGenerationQueue.addDebugMenuStringsToList(messageList);
|
||||
return "World Gen Tasks: "+waitingCountStr+"/"+totalCountEstimateStr+" (in progress: "+inProgressCountStr+")";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ConfigBasedLogger
|
||||
|
||||
|
||||
public static final List<WeakReference<ConfigBasedLogger>> loggers
|
||||
= Collections.synchronizedList(new LinkedList<WeakReference<ConfigBasedLogger>>());
|
||||
= Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
public static synchronized void updateAll()
|
||||
{
|
||||
@@ -101,7 +101,7 @@ public class ConfigBasedLogger
|
||||
else
|
||||
logger.log(logLevel, msgStr);
|
||||
}
|
||||
if (MC != null && mode.levelForChat.isLessSpecificThan(level))
|
||||
if (mode.levelForChat.isLessSpecificThan(level))
|
||||
{
|
||||
if (param.length > 0 && param[param.length - 1] instanceof Throwable)
|
||||
MC.logToChat(level, msgStr + "\n" +
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class ConfigBasedSpamLogger
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
|
||||
public static final List<WeakReference<ConfigBasedSpamLogger>> loggers
|
||||
= Collections.synchronizedList(new LinkedList<WeakReference<ConfigBasedSpamLogger>>());
|
||||
= Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
public static synchronized void updateAll(boolean flush)
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ public class SpamReducedLogger
|
||||
private static final Logger LOGGER = LogManager.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
|
||||
|
||||
public static final List<WeakReference<SpamReducedLogger>> loggers
|
||||
= Collections.synchronizedList(new LinkedList<WeakReference<SpamReducedLogger>>());
|
||||
= Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
public static synchronized void flushAll()
|
||||
{
|
||||
@@ -53,7 +53,7 @@ public class SpamReducedLogger
|
||||
public SpamReducedLogger(int maxLogPerSec)
|
||||
{
|
||||
maxLogCount = maxLogPerSec;
|
||||
loggers.add(new WeakReference<SpamReducedLogger>(this));
|
||||
loggers.add(new WeakReference<>(this));
|
||||
}
|
||||
|
||||
public void reset()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user