Compare commits
101 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57c5b2d5fc | |||
| 50c5701836 | |||
| 18e075538d | |||
| b00e8a08e9 | |||
| ac4ab11a74 | |||
| c26631db57 | |||
| 1daa06fff4 | |||
| f3ef6f25f4 | |||
| ec012d9fd6 | |||
| fc90cf3377 | |||
| e1e42d1caf | |||
| 95ce29e355 | |||
| 0fd818b077 | |||
| ba59daf747 | |||
| b7d94c2ed1 | |||
| 7a057a8d53 | |||
| 49c6ab97a9 | |||
| ed0d80b37e | |||
| 9768728c92 | |||
| 0c68544f2f | |||
| b1f154a0ea | |||
| 628c9b071f | |||
| ed39b6181f | |||
| 1d6d712483 | |||
| 73c4f0ffcd | |||
| 48d1005be6 | |||
| e71e8d1966 | |||
| 489b3d3ae1 | |||
| 1b162f10e6 | |||
| 301cce3d11 | |||
| e68d0d5c45 | |||
| 2cf952fb76 | |||
| c7c5ab17bc | |||
| a98955530f | |||
| c63a509f9e | |||
| dac51a9eea | |||
| 8d78a1ad74 | |||
| 7c11bb4258 | |||
| 0d6ec3d836 | |||
| 9449433fe8 | |||
| 2c976c9fb1 | |||
| 90fdfbbe61 | |||
| a8df13fdd2 | |||
| f05eac2637 | |||
| 4ae30b3d47 | |||
| 8abefdcfd5 | |||
| 801a126de0 | |||
| 377d0fbe12 | |||
| 1ecf968668 | |||
| c43b985f4e | |||
| b7fea64925 | |||
| 116d7f4a3f | |||
| 0c36dc03a5 | |||
| c658269eb7 | |||
| defaea86f0 | |||
| f1564cc90b | |||
| 66feb0b9c2 | |||
| 79bfa21115 | |||
| 5588b0d2fa | |||
| e9788acb46 | |||
| 8056a5b8bf | |||
| e0ad956e34 | |||
| 9546f9cbc8 | |||
| 9834b20a9f | |||
| 752008e8ac | |||
| fbe81021c0 | |||
| 882c5399bd | |||
| dbe0461d5f | |||
| d3d166dd02 | |||
| d0dd1f38ff | |||
| 53300a3028 | |||
| 56303dd82a | |||
| 19d8c89bd8 | |||
| adba3e4c15 | |||
| 479ce8093e | |||
| 1ed6c619d9 | |||
| 825f439ffb | |||
| b1b487e63f | |||
| 2763a7ca75 | |||
| b4b1a2a549 | |||
| 5865317394 | |||
| b70c090e94 | |||
| a9f6b924c2 | |||
| 9c25a6450a | |||
| 448982fbaf | |||
| 2ee06c59f1 | |||
| d38711ca4b | |||
| c9b650fb7f | |||
| 3cef8b9a4f | |||
| d9d9f3dad8 | |||
| 44fe1eafb1 | |||
| 36fcc46445 | |||
| 64895ba521 | |||
| 589340f2db | |||
| de7d22766a | |||
| 568ff40df6 | |||
| 17b5ba0ae1 | |||
| 4d4eeacbdd | |||
| 99dc644adf | |||
| f442ab56c0 | |||
| 9147b139c7 |
@@ -180,7 +180,7 @@ public class DhApi
|
|||||||
* This version should be updated whenever non-breaking fixes are added to the Distant Horizons API.
|
* This version should be updated whenever non-breaking fixes are added to the Distant Horizons API.
|
||||||
* @since API 1.0.0
|
* @since API 1.0.0
|
||||||
*/
|
*/
|
||||||
public static int getApiPatchVersion() { return ModInfo.API_PATH_VERSION; }
|
public static int getApiPatchVersion() { return ModInfo.API_PATCH_VERSION; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the mod's semantic version number in the format: Major.Minor.Patch
|
* 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>
|
* CHUNK - Detail Level: 4, width 16 block, <br>
|
||||||
* REGION - Detail Level: 9, width 512 block <br> <br>
|
* REGION - Detail Level: 9, width 512 block <br> <br>
|
||||||
*
|
*
|
||||||
* Detail levels in Distant Horizons represent how large a section (of either LODs or MC chunks)
|
* Detail levels in Distant Horizons represent how large a LOD
|
||||||
* is, with the smallest being 0 (1 block wide). <br>
|
* 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>
|
* 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>
|
* Example for the chunk detail level (4): 2^4 = 16 blocks wide <Br><br>
|
||||||
|
|||||||
+4
-2
@@ -23,13 +23,12 @@ package com.seibel.distanthorizons.api.enums.config;
|
|||||||
* AUTO, <br>
|
* AUTO, <br>
|
||||||
* BUFFER_STORAGE, <br>
|
* BUFFER_STORAGE, <br>
|
||||||
* SUB_DATA, <br>
|
* SUB_DATA, <br>
|
||||||
* BUFFER_MAPPING, <br>
|
|
||||||
* DATA <br>
|
* DATA <br>
|
||||||
*
|
*
|
||||||
* @author Leetom
|
* @author Leetom
|
||||||
* @author James Seibel
|
* @author James Seibel
|
||||||
* @version 2024-4-6
|
* @version 2024-4-6
|
||||||
* @since API 2.0.0
|
* @since API 3.0.0
|
||||||
*/
|
*/
|
||||||
public enum EDhApiGpuUploadMethod
|
public enum EDhApiGpuUploadMethod
|
||||||
{
|
{
|
||||||
@@ -49,7 +48,10 @@ public enum EDhApiGpuUploadMethod
|
|||||||
* May end up storing buffers in System memory. <br>
|
* May end up storing buffers in System memory. <br>
|
||||||
* Fast rending if in GPU memory, slow if in system memory, <br>
|
* Fast rending if in GPU memory, slow if in system memory, <br>
|
||||||
* but won't stutter when uploading.
|
* but won't stutter when uploading.
|
||||||
|
*
|
||||||
|
* @deprecated not currently supported
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
BUFFER_MAPPING(true, false),
|
BUFFER_MAPPING(true, false),
|
||||||
|
|
||||||
/** Fast rendering but may stutter when uploading. */
|
/** Fast rendering but may stutter when uploading. */
|
||||||
|
|||||||
+1
@@ -21,6 +21,7 @@ package com.seibel.distanthorizons.api.enums.rendering;
|
|||||||
* AIR, <br>
|
* AIR, <br>
|
||||||
* ILLUMINATED, <br>
|
* ILLUMINATED, <br>
|
||||||
*
|
*
|
||||||
|
* @author IMS
|
||||||
* @author James Seibel
|
* @author James Seibel
|
||||||
* @since API 3.0.0
|
* @since API 3.0.0
|
||||||
* @version 2024-7-11
|
* @version 2024-7-11
|
||||||
|
|||||||
+6
-1
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.api.interfaces.block;
|
package com.seibel.distanthorizons.api.interfaces.block;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||||
import com.seibel.distanthorizons.api.interfaces.IDhApiUnsafeWrapper;
|
import com.seibel.distanthorizons.api.interfaces.IDhApiUnsafeWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +45,11 @@ public interface IDhApiBlockStateWrapper extends IDhApiUnsafeWrapper
|
|||||||
* @since API 3.0.0
|
* @since API 3.0.0
|
||||||
*/
|
*/
|
||||||
String getSerialString();
|
String getSerialString();
|
||||||
/** @since API 3.0.0 */
|
/**
|
||||||
|
* Returns the byte value representing the {@link EDhApiBlockMaterial} enum.
|
||||||
|
* @see EDhApiBlockMaterial
|
||||||
|
* @since API 3.0.0
|
||||||
|
*/
|
||||||
byte getMaterialId();
|
byte getMaterialId();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ public interface IDhApiConfig
|
|||||||
IDhApiWorldGenerationConfig worldGenerator();
|
IDhApiWorldGenerationConfig worldGenerator();
|
||||||
IDhApiMultiplayerConfig multiplayer();
|
IDhApiMultiplayerConfig multiplayer();
|
||||||
IDhApiMultiThreadingConfig multiThreading();
|
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.
|
// 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
|
//IDhApiLoggingConfig logging(); // TODO implement
|
||||||
IDhApiDebuggingConfig debugging();
|
IDhApiDebuggingConfig debugging();
|
||||||
|
|||||||
-39
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
}
|
|
||||||
+29
-6
@@ -79,11 +79,34 @@ public interface IDhApiWrapperFactory
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
///**
|
/**
|
||||||
// * Specifically designed to be used with the API.
|
* Constructs a {@link IDhApiBiomeWrapper} for use by other DhApi methods.
|
||||||
// *
|
*
|
||||||
// * @throws ClassCastException with instructions on expected objects if the object couldn't be cast
|
* @param resourceLocationString example: "minecraft:plains"
|
||||||
// */
|
*
|
||||||
//IChunkWrapper createChunkWrapper(Object[] objectArray) throws ClassCastException;
|
* @param levelWrapper Expects a {@link IDhApiLevelWrapper} returned by one of DH's {@link DhApi.Delayed#worldProxy} methods. <br>
|
||||||
|
* A custom implementation of {@link IDhApiLevelWrapper} will not be accepted.
|
||||||
|
*
|
||||||
|
* @throws IOException if the resourceLocationString wasn't able to be parsed or converted into a valid {@link IDhApiBiomeWrapper}
|
||||||
|
* @throws ClassCastException if the wrong levelWrapper type was given
|
||||||
|
*
|
||||||
|
* @since API 3.0.0
|
||||||
|
*/
|
||||||
|
IDhApiBiomeWrapper getBiomeWrapper(String resourceLocationString, IDhApiLevelWrapper levelWrapper) throws IOException, ClassCastException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a {@link IDhApiBlockStateWrapper} for use by other DhApi methods.
|
||||||
|
* This returns the default blockstate for the given resource location.
|
||||||
|
*
|
||||||
|
* @param resourceLocationString examples: "minecraft:bedrock", "minecraft:stone", "minecraft:grass_block"
|
||||||
|
* @param levelWrapper Expects a {@link IDhApiBlockStateWrapper} returned by one of DH's {@link DhApi.Delayed#worldProxy} methods. <br>
|
||||||
|
* A custom implementation of {@link IDhApiBlockStateWrapper} will not be accepted.
|
||||||
|
*
|
||||||
|
* @throws IOException if the resourceLocationString wasn't able to be parsed or converted into a valid {@link IDhApiBlockStateWrapper}
|
||||||
|
* @throws ClassCastException if the wrong levelWrapper type was given
|
||||||
|
*
|
||||||
|
* @since API 3.0.0
|
||||||
|
*/
|
||||||
|
IDhApiBlockStateWrapper getDefaultBlockStateWrapper(String resourceLocationString, IDhApiLevelWrapper levelWrapper) throws IOException, ClassCastException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-1
@@ -22,6 +22,8 @@ package com.seibel.distanthorizons.api.interfaces.override.worldGenerator;
|
|||||||
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
|
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
|
||||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
||||||
import com.seibel.distanthorizons.api.interfaces.override.IDhApiOverrideable;
|
import com.seibel.distanthorizons.api.interfaces.override.IDhApiOverrideable;
|
||||||
|
import com.seibel.distanthorizons.api.objects.data.DhApiChunk;
|
||||||
|
import com.seibel.distanthorizons.api.objects.data.DhApiTerrainDataPoint;
|
||||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
@@ -77,13 +79,41 @@ public abstract class AbstractDhApiChunkWorldGenerator implements Closeable, IDh
|
|||||||
}, worldGeneratorThreadPool);
|
}, worldGeneratorThreadPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final CompletableFuture<Void> generateApiChunks(
|
||||||
|
int chunkPosMinX,
|
||||||
|
int chunkPosMinZ,
|
||||||
|
byte granularity,
|
||||||
|
byte targetDataDetail,
|
||||||
|
EDhApiDistantGeneratorMode generatorMode,
|
||||||
|
ExecutorService worldGeneratorThreadPool,
|
||||||
|
Consumer<DhApiChunk> resultConsumer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return CompletableFuture.runAsync(() ->
|
||||||
|
{
|
||||||
|
// TODO what does this mean?
|
||||||
|
int genChunkWidth = BitShiftUtil.powerOfTwo(granularity - 4);
|
||||||
|
|
||||||
|
for (int chunkX = chunkPosMinX; chunkX < chunkPosMinX + genChunkWidth; chunkX++)
|
||||||
|
{
|
||||||
|
for (int chunkZ = chunkPosMinZ; chunkZ < chunkPosMinZ + genChunkWidth; chunkZ++)
|
||||||
|
{
|
||||||
|
DhApiChunk apiChunk = this.generateApiChunk(chunkX, chunkZ, generatorMode);
|
||||||
|
resultConsumer.accept(apiChunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, worldGeneratorThreadPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called to generate terrain over a given area
|
* This method is called to generate terrain over a given area
|
||||||
* from a thread defined by Distant Horizons. <br><br>
|
* from a thread defined by Distant Horizons. <br><br>
|
||||||
*
|
*
|
||||||
* @param chunkPosX the chunk X position in the level (not to be confused with the chunk's BlockPos in the level)
|
* @param chunkPosX the chunk X position in the level (not to be confused with the chunk's BlockPos in the level)
|
||||||
* @param chunkPosZ the chunk Z position in the level (not to be confused with the chunk's BlockPos in the level)
|
* @param chunkPosZ the chunk Z position in the level (not to be confused with the chunk's BlockPos in the level)
|
||||||
* @param generatorMode how far into the world gen pipeline this method run. See {@link EDhApiDistantGeneratorMode} for additional documentation.
|
* @param generatorMode how far into the world gen pipeline this method should run. See {@link EDhApiDistantGeneratorMode} for additional documentation.
|
||||||
*
|
*
|
||||||
* @return See {@link IDhApiWorldGenerator#generateChunks(int, int, byte, byte, EDhApiDistantGeneratorMode, ExecutorService, Consumer) IDhApiWorldGenerator.generateChunks}
|
* @return See {@link IDhApiWorldGenerator#generateChunks(int, int, byte, byte, EDhApiDistantGeneratorMode, ExecutorService, Consumer) IDhApiWorldGenerator.generateChunks}
|
||||||
* for the list of Object's this method should return along with additional documentation.
|
* for the list of Object's this method should return along with additional documentation.
|
||||||
@@ -92,4 +122,21 @@ public abstract class AbstractDhApiChunkWorldGenerator implements Closeable, IDh
|
|||||||
*/
|
*/
|
||||||
public abstract Object[] generateChunk(int chunkPosX, int chunkPosZ, EDhApiDistantGeneratorMode generatorMode);
|
public abstract Object[] generateChunk(int chunkPosX, int chunkPosZ, EDhApiDistantGeneratorMode generatorMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called to generate terrain over a given area
|
||||||
|
* from a thread defined by Distant Horizons. <br><br>
|
||||||
|
*
|
||||||
|
* @param chunkPosX the chunk X position in the level (not to be confused with the chunk's BlockPos in the level)
|
||||||
|
* @param chunkPosZ the chunk Z position in the level (not to be confused with the chunk's BlockPos in the level)
|
||||||
|
* @param generatorMode how far into the world gen pipeline this method should run. See {@link EDhApiDistantGeneratorMode} for additional documentation.
|
||||||
|
*
|
||||||
|
* @return A {@link DhApiChunk} with the generated {@link DhApiTerrainDataPoint} including air blocks.
|
||||||
|
* Note: if air blocks aren't included with the proper lighting, lower detail levels will appear as black/unlit.
|
||||||
|
*
|
||||||
|
* @see IDhApiWorldGenerator#generateApiChunks(int, int, byte, byte, EDhApiDistantGeneratorMode, ExecutorService, Consumer)
|
||||||
|
*
|
||||||
|
* @since API 3.0.0
|
||||||
|
*/
|
||||||
|
public abstract DhApiChunk generateApiChunk(int chunkPosX, int chunkPosZ, EDhApiDistantGeneratorMode generatorMode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-2
@@ -91,10 +91,28 @@ public interface IDhApiWorldGenerator extends Closeable, IDhApiOverrideable
|
|||||||
default byte getMaxGenerationGranularity() { return (byte) (EDhApiDetailLevel.CHUNK.detailLevel + 2); }
|
default byte getMaxGenerationGranularity() { return (byte) (EDhApiDetailLevel.CHUNK.detailLevel + 2); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the generator is unable to accept new generation requests.
|
* 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>
|
||||||
|
*
|
||||||
* @since API 1.0.0
|
* @since API 1.0.0
|
||||||
|
* @deprecated API 3.0.0
|
||||||
*/
|
*/
|
||||||
boolean isBusy();
|
@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; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -154,6 +172,7 @@ public interface IDhApiWorldGenerator extends Closeable, IDhApiOverrideable
|
|||||||
*
|
*
|
||||||
* After the {@link DhApiChunk} has been generated, it should be passed into the
|
* After the {@link DhApiChunk} has been generated, it should be passed into the
|
||||||
* resultConsumer's {@link Consumer#accept(Object)} method.
|
* resultConsumer's {@link Consumer#accept(Object)} method.
|
||||||
|
* Note: if air blocks aren't included in the with the {@link DhApiChunk} with proper lighting, lower detail levels will appear as black/unlit.
|
||||||
*
|
*
|
||||||
* @implNote the default implementation of this method throws an {@link UnsupportedOperationException},
|
* @implNote the default implementation of this method throws an {@link UnsupportedOperationException},
|
||||||
* and must be overridden when {@link #getReturnType()} returns {@link EDhApiWorldGeneratorReturnType#API_CHUNKS}.
|
* and must be overridden when {@link #getReturnType()} returns {@link EDhApiWorldGeneratorReturnType#API_CHUNKS}.
|
||||||
|
|||||||
+3
-5
@@ -26,7 +26,7 @@ import com.seibel.distanthorizons.api.objects.DhApiResult;
|
|||||||
* Used to interact with Distant Horizons' rendering system.
|
* Used to interact with Distant Horizons' rendering system.
|
||||||
*
|
*
|
||||||
* @author James Seibel
|
* @author James Seibel
|
||||||
* @version 2023-10-13
|
* @version 2024-7-27
|
||||||
* @since API 1.0.0
|
* @since API 1.0.0
|
||||||
*/
|
*/
|
||||||
public interface IDhApiRenderProxy
|
public interface IDhApiRenderProxy
|
||||||
@@ -39,10 +39,8 @@ 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>
|
* If this is called on a dedicated server it won't do anything and will return {@link DhApiResult#success} = false <Br><Br>
|
||||||
*
|
*
|
||||||
* Background: <Br>
|
* Background: <Br>
|
||||||
* Distant Horizons has two different file formats: Full data and Render data. <Br>
|
* When rendering Distant Horizons bakes each block's color into the geometry that's rendered. <Br>
|
||||||
* - Full data files store the block, biome, etc. information and is the result of loading or generating new chunks. <Br>
|
* This improves rendering speed and VRAM size, but prevents dynamically changing LOD colors. <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();
|
DhApiResult<Boolean> clearRenderDataCache();
|
||||||
|
|
||||||
|
|||||||
+15
-2
@@ -28,7 +28,7 @@ import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderRegist
|
|||||||
* A level is equivalent to a dimension in vanilla Minecraft.
|
* A level is equivalent to a dimension in vanilla Minecraft.
|
||||||
*
|
*
|
||||||
* @author James Seibel
|
* @author James Seibel
|
||||||
* @version 2022-7-14
|
* @version 2024-7-28
|
||||||
* @since API 1.0.0
|
* @since API 1.0.0
|
||||||
*/
|
*/
|
||||||
public interface IDhApiLevelWrapper extends IDhApiUnsafeWrapper
|
public interface IDhApiLevelWrapper extends IDhApiUnsafeWrapper
|
||||||
@@ -41,7 +41,18 @@ public interface IDhApiLevelWrapper extends IDhApiUnsafeWrapper
|
|||||||
|
|
||||||
boolean hasSkyLight();
|
boolean hasSkyLight();
|
||||||
|
|
||||||
/** Returns the max block height of the level(?) */
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
int getMaxHeight();
|
int getMaxHeight();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +64,8 @@ public interface IDhApiLevelWrapper extends IDhApiUnsafeWrapper
|
|||||||
/**
|
/**
|
||||||
* Will return null if called on the server,
|
* Will return null if called on the server,
|
||||||
* or if called before the renderer has been set up.
|
* or if called before the renderer has been set up.
|
||||||
|
*
|
||||||
|
* @since API 3.0.0
|
||||||
*/
|
*/
|
||||||
IDhApiCustomRenderRegister getRenderRegister();
|
IDhApiCustomRenderRegister getRenderRegister();
|
||||||
|
|
||||||
|
|||||||
@@ -21,15 +21,17 @@ package com.seibel.distanthorizons.api.objects.data;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.api.interfaces.factories.IDhApiWrapperFactory;
|
import com.seibel.distanthorizons.api.interfaces.factories.IDhApiWrapperFactory;
|
||||||
import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains a list of {@link DhApiTerrainDataPoint} representing the blocks in a Minecraft chunk.
|
* Contains a list of {@link DhApiTerrainDataPoint} representing the blocks in a Minecraft chunk.
|
||||||
*
|
*
|
||||||
* @author Builderb0y, James Seibel
|
* @author Builderb0y, James Seibel
|
||||||
* @version 2023-12-21
|
* @version 2024-7-21
|
||||||
* @since API 2.0.0
|
* @since API 2.0.0
|
||||||
*
|
*
|
||||||
* @see IDhApiWrapperFactory
|
* @see IDhApiWrapperFactory
|
||||||
@@ -41,8 +43,8 @@ public class DhApiChunk
|
|||||||
public final int chunkPosX;
|
public final int chunkPosX;
|
||||||
public final int chunkPosZ;
|
public final int chunkPosZ;
|
||||||
|
|
||||||
public final int topYBlockPos;
|
|
||||||
public final int bottomYBlockPos;
|
public final int bottomYBlockPos;
|
||||||
|
public final int topYBlockPos;
|
||||||
|
|
||||||
private final List<List<DhApiTerrainDataPoint>> dataPoints;
|
private final List<List<DhApiTerrainDataPoint>> dataPoints;
|
||||||
|
|
||||||
@@ -52,12 +54,32 @@ public class DhApiChunk
|
|||||||
// constructors //
|
// 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)
|
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)
|
||||||
{
|
{
|
||||||
this.chunkPosX = chunkPosX;
|
this.chunkPosX = chunkPosX;
|
||||||
this.chunkPosZ = chunkPosZ;
|
this.chunkPosZ = chunkPosZ;
|
||||||
this.topYBlockPos = topYBlockPos;
|
|
||||||
this.bottomYBlockPos = bottomYBlockPos;
|
this.bottomYBlockPos = bottomYBlockPos;
|
||||||
|
this.topYBlockPos = topYBlockPos;
|
||||||
|
|
||||||
// populate the array to prevent null pointers
|
// populate the array to prevent null pointers
|
||||||
this.dataPoints = new ArrayList<>(16 * 16); // 256
|
this.dataPoints = new ArrayList<>(16 * 16); // 256
|
||||||
@@ -94,27 +116,34 @@ public class DhApiChunk
|
|||||||
*/
|
*/
|
||||||
public void setDataPoints(int relX, int relZ, List<DhApiTerrainDataPoint> dataPoints) throws IndexOutOfBoundsException, IllegalArgumentException
|
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);
|
throwIfRelativePosOutOfBounds(relX, relZ);
|
||||||
|
|
||||||
// validate the incoming datapoints
|
if (dataPoints == null)
|
||||||
if (dataPoints != null)
|
|
||||||
{
|
{
|
||||||
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
|
// 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.");
|
||||||
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].");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataPoints.set((relZ << 4) | relX, dataPoints);
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// set datapoints //
|
||||||
|
//================//
|
||||||
|
|
||||||
|
List<DhApiTerrainDataPoint> column = this.dataPoints.get(internalArrayIndex);
|
||||||
|
if (column == null)
|
||||||
|
{
|
||||||
|
column = new ArrayList<>();
|
||||||
|
this.dataPoints.set(internalArrayIndex, column);
|
||||||
|
}
|
||||||
|
column.addAll(dataPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+59
-4
@@ -19,14 +19,17 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.api.objects.data;
|
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.IDhApiBiomeWrapper;
|
||||||
import com.seibel.distanthorizons.api.interfaces.block.IDhApiBlockStateWrapper;
|
import com.seibel.distanthorizons.api.interfaces.block.IDhApiBlockStateWrapper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds a single datapoint of terrain data.
|
* Holds a single datapoint of terrain data.
|
||||||
*
|
*
|
||||||
* @author James Seibel
|
* @author James Seibel
|
||||||
* @version 2022-11-13
|
* @version 2024-7-20
|
||||||
* @since API 1.0.0
|
* @since API 1.0.0
|
||||||
*/
|
*/
|
||||||
public class DhApiTerrainDataPoint
|
public class DhApiTerrainDataPoint
|
||||||
@@ -37,27 +40,79 @@ public class DhApiTerrainDataPoint
|
|||||||
* 2 = 4x4 blocks <br>
|
* 2 = 4x4 blocks <br>
|
||||||
* 4 = chunk (16x16 blocks) <br>
|
* 4 = chunk (16x16 blocks) <br>
|
||||||
* 9 = region (512x512 blocks) <br>
|
* 9 = region (512x512 blocks) <br>
|
||||||
|
*
|
||||||
|
* @see EDhApiDetailLevel
|
||||||
*/
|
*/
|
||||||
public final byte detailLevel;
|
public final byte detailLevel;
|
||||||
|
|
||||||
public final int blockLightLevel;
|
public final int blockLightLevel;
|
||||||
public final int skyLightLevel;
|
public final int skyLightLevel;
|
||||||
public final int topYBlockPos;
|
|
||||||
public final int bottomYBlockPos;
|
public final int bottomYBlockPos;
|
||||||
|
public final int topYBlockPos;
|
||||||
|
|
||||||
public final IDhApiBlockStateWrapper blockStateWrapper;
|
public final IDhApiBlockStateWrapper blockStateWrapper;
|
||||||
public final IDhApiBiomeWrapper biomeWrapper;
|
public final IDhApiBiomeWrapper biomeWrapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public DhApiTerrainDataPoint(byte detailLevel, int blockLightLevel, int skyLightLevel, int topYBlockPos, int bottomYBlockPos, IDhApiBlockStateWrapper blockStateWrapper, IDhApiBiomeWrapper biomeWrapper)
|
//==============//
|
||||||
|
// 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
|
||||||
|
)
|
||||||
{
|
{
|
||||||
this.detailLevel = detailLevel;
|
this.detailLevel = detailLevel;
|
||||||
|
|
||||||
this.blockLightLevel = blockLightLevel;
|
this.blockLightLevel = blockLightLevel;
|
||||||
this.skyLightLevel = skyLightLevel;
|
this.skyLightLevel = skyLightLevel;
|
||||||
this.topYBlockPos = topYBlockPos;
|
|
||||||
this.bottomYBlockPos = bottomYBlockPos;
|
this.bottomYBlockPos = bottomYBlockPos;
|
||||||
|
this.topYBlockPos = topYBlockPos;
|
||||||
|
|
||||||
this.blockStateWrapper = blockStateWrapper;
|
this.blockStateWrapper = blockStateWrapper;
|
||||||
this.biomeWrapper = biomeWrapper;
|
this.biomeWrapper = biomeWrapper;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public final class ModInfo
|
|||||||
public static final String NAME = "DistantHorizons";
|
public static final String NAME = "DistantHorizons";
|
||||||
/** Human-readable version of NAME */
|
/** Human-readable version of NAME */
|
||||||
public static final String READABLE_NAME = "Distant Horizons";
|
public static final String READABLE_NAME = "Distant Horizons";
|
||||||
public static final String VERSION = "2.1.3-a-dev";
|
public static final String VERSION = "2.2.1-a";
|
||||||
/** Returns true if the current build is an unstable developer build, false otherwise. */
|
/** Returns true if the current build is an unstable developer build, false otherwise. */
|
||||||
public static boolean IS_DEV_BUILD = VERSION.toLowerCase().contains("dev");
|
public static boolean IS_DEV_BUILD = VERSION.toLowerCase().contains("dev");
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public final class ModInfo
|
|||||||
/** This version should be updated whenever new methods are added to the DH API */
|
/** This version should be updated whenever new methods are added to the DH API */
|
||||||
public static final int API_MINOR_VERSION = 0;
|
public static final int API_MINOR_VERSION = 0;
|
||||||
/** This version should be updated whenever non-breaking fixes are added to the DH API */
|
/** This version should be updated whenever non-breaking fixes are added to the DH API */
|
||||||
public static final int API_PATH_VERSION = 0;
|
public static final int API_PATCH_VERSION = 1;
|
||||||
|
|
||||||
public static final String NETWORKING_RESOURCE_NAMESPACE = "distant_horizons";
|
public static final String NETWORKING_RESOURCE_NAMESPACE = "distant_horizons";
|
||||||
public static final String MULTIVERSE_PLUGIN_NAMESPACE = "world_control";
|
public static final String MULTIVERSE_PLUGIN_NAMESPACE = "world_control";
|
||||||
|
|||||||
+2
-1
@@ -67,10 +67,11 @@ public interface IConfigEntry<T>
|
|||||||
* Checks if the option is valid
|
* Checks if the option is valid
|
||||||
*
|
*
|
||||||
* 0 == valid
|
* 0 == valid
|
||||||
|
* 2 == invalid
|
||||||
* 1 == number too high
|
* 1 == number too high
|
||||||
* -1 == number too low
|
* -1 == number too low
|
||||||
*/
|
*/
|
||||||
byte isValid();
|
byte isValid(); // TODO replace with an enum
|
||||||
/** Checks if a value is valid */
|
/** Checks if a value is valid */
|
||||||
byte isValid(T value);
|
byte isValid(T value);
|
||||||
|
|
||||||
|
|||||||
@@ -19,18 +19,17 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.coreapi.util;
|
package com.seibel.distanthorizons.coreapi.util;
|
||||||
|
|
||||||
import java.text.CharacterIterator;
|
import java.util.ArrayList;
|
||||||
import java.text.StringCharacterIterator;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Miscellaneous string helper functions.
|
* Miscellaneous string helper functions.
|
||||||
*
|
|
||||||
* @author James Seibel
|
|
||||||
* @version 2022-7-19
|
|
||||||
*/
|
*/
|
||||||
public class StringUtil
|
public class StringUtil
|
||||||
{
|
{
|
||||||
|
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the n-th index of the given string. <br> <br>
|
* Returns the n-th index of the given string. <br> <br>
|
||||||
*
|
*
|
||||||
@@ -68,8 +67,6 @@ public class StringUtil
|
|||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
|
||||||
/**
|
/**
|
||||||
* Converts the given byte array into a hex string representation. <br>
|
* Converts the given byte array into a hex string representation. <br>
|
||||||
* source: https://stackoverflow.com/a/9855338
|
* source: https://stackoverflow.com/a/9855338
|
||||||
@@ -87,24 +84,19 @@ public class StringUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Source:
|
* Returns a shortened version of the given string that is no longer than maxLength. <br>
|
||||||
* https://stackoverflow.com/questions/3758606/how-can-i-convert-byte-size-into-a-human-readable-format-in-java#3758880
|
* If null returns the empty string.
|
||||||
*/
|
*/
|
||||||
public static String convertByteCountToHumanReadableSI(long bytes)
|
public static String shortenString(String str, int maxLength)
|
||||||
{
|
{
|
||||||
if (-1000 < bytes && bytes < 1000)
|
if (str == null)
|
||||||
{
|
{
|
||||||
return bytes + " B";
|
return "";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
CharacterIterator ci = new StringCharacterIterator("kMGTPE");
|
|
||||||
while (bytes <= -999_950 || bytes >= 999_950)
|
|
||||||
{
|
{
|
||||||
bytes /= 1000;
|
return str.substring(0, Math.min(str.length(), maxLength));
|
||||||
ci.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.format("%.1f %cB", bytes / 1000.0, ci.current());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
-2
@@ -42,8 +42,6 @@ public class DhApiConfig implements IDhApiConfig
|
|||||||
@Override
|
@Override
|
||||||
public IDhApiMultiThreadingConfig multiThreading() { return DhApiMultiThreadingConfig.INSTANCE; }
|
public IDhApiMultiThreadingConfig multiThreading() { return DhApiMultiThreadingConfig.INSTANCE; }
|
||||||
@Override
|
@Override
|
||||||
public IDhApiGpuBuffersConfig gpuBuffers() { return DhApiGpuBuffersConfig.INSTANCE; }
|
|
||||||
@Override
|
|
||||||
public IDhApiDebuggingConfig debugging() { return DhApiDebuggingConfig.INSTANCE; }
|
public IDhApiDebuggingConfig debugging() { return DhApiDebuggingConfig.INSTANCE; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-39
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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); }
|
|
||||||
|
|
||||||
}
|
|
||||||
+3
-2
@@ -326,9 +326,10 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
|
|||||||
int height = FullDataPointUtil.getHeight(dataPoint);
|
int height = FullDataPointUtil.getHeight(dataPoint);
|
||||||
int topY = bottomY + height;
|
int topY = bottomY + height;
|
||||||
|
|
||||||
return new DhApiTerrainDataPoint(detailLevel,
|
return DhApiTerrainDataPoint.create(
|
||||||
|
detailLevel,
|
||||||
FullDataPointUtil.getBlockLight(dataPoint), FullDataPointUtil.getSkyLight(dataPoint),
|
FullDataPointUtil.getBlockLight(dataPoint), FullDataPointUtil.getSkyLight(dataPoint),
|
||||||
topY, bottomY,
|
bottomY, topY,
|
||||||
blockState, biomeWrapper);
|
blockState, biomeWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.seibel.distanthorizons.api.DhApi;
|
|||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass;
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass;
|
||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
||||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
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.level.IKeyedClientLevelManager;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.render.DhApiRenderProxy;
|
import com.seibel.distanthorizons.core.render.DhApiRenderProxy;
|
||||||
@@ -53,6 +54,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@@ -125,9 +127,28 @@ public class ClientApi
|
|||||||
public synchronized void onClientOnlyConnected()
|
public synchronized void onClientOnlyConnected()
|
||||||
{
|
{
|
||||||
// only continue if the client is connected to a different server
|
// only continue if the client is connected to a different server
|
||||||
if (MC.clientConnectedToDedicatedServer())
|
boolean connectedToServer = MC.clientConnectedToDedicatedServer();
|
||||||
|
boolean connectedToReplay = MC.connectedToReplay();
|
||||||
|
if (connectedToServer || connectedToReplay)
|
||||||
{
|
{
|
||||||
LOGGER.info("Client on ClientOnly mode connecting.");
|
if (connectedToServer)
|
||||||
|
{
|
||||||
|
LOGGER.info("Client on ClientOnly mode connecting.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGGER.info("Replay on ClientServer mode connecting.");
|
||||||
|
|
||||||
|
if (Config.Client.Advanced.Logging.showReplayWarningOnStartup.get())
|
||||||
|
{
|
||||||
|
MC.sendChatMessage("\u00A76" + "Distant Horizons: Replay detected." + "\u00A7r"); // gold color
|
||||||
|
MC.sendChatMessage("DH may behave strangely or have missing functionality.");
|
||||||
|
MC.sendChatMessage("In order to use pre-generated LODs, put your DH database(s) in:");
|
||||||
|
MC.sendChatMessage("\u00A77"+".Minecraft" + File.separator + ClientOnlySaveStructure.SERVER_DATA_FOLDER_NAME + File.separator + ClientOnlySaveStructure.REPLAY_SERVER_FOLDER_NAME + File.separator + "DIMENSION_NAME"+"\u00A7r"); // light gray color
|
||||||
|
MC.sendChatMessage("This can be disabled in DH's config under Advanced -> Logging.");
|
||||||
|
MC.sendChatMessage("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// firing after clientLevelLoadEvent
|
// firing after clientLevelLoadEvent
|
||||||
// TODO if level has prepped to load it should fire level load event
|
// TODO if level has prepped to load it should fire level load event
|
||||||
@@ -476,7 +497,7 @@ public class ClientApi
|
|||||||
{
|
{
|
||||||
// logging //
|
// logging //
|
||||||
|
|
||||||
this.sendChatMessagesNow();
|
this.sendQueuedChatMessages();
|
||||||
|
|
||||||
IProfilerWrapper profiler = MC.getProfiler();
|
IProfilerWrapper profiler = MC.getProfiler();
|
||||||
profiler.pop(); // get out of "terrain"
|
profiler.pop(); // get out of "terrain"
|
||||||
@@ -531,8 +552,17 @@ public class ClientApi
|
|||||||
}
|
}
|
||||||
IDhClientLevel level = dhClientWorld.getOrLoadClientLevel(levelWrapper);
|
IDhClientLevel level = dhClientWorld.getOrLoadClientLevel(levelWrapper);
|
||||||
|
|
||||||
|
|
||||||
if (this.rendererDisabledBecauseOfExceptions)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,9 +613,9 @@ public class ClientApi
|
|||||||
LOGGER.error("Unexpected Renderer error in render pass [" + renderPass + "]. Error: " + e.getMessage(), e);
|
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("\u00A74\u00A7l\u00A7uERROR: Distant Horizons renderer has encountered an exception!");
|
||||||
MC.sendChatMessage("\u00A74Renderer is now disabled to prevent further issues.");
|
MC.sendChatMessage("\u00A74Renderer disabled to try preventing GL state corruption.");
|
||||||
MC.sendChatMessage("\u00A74Please restart your game to re-enable Distant Horizons' LOD rendering.");
|
MC.sendChatMessage("\u00A74Toggle DH rendering via the config UI to re-activate DH rendering.");
|
||||||
MC.sendChatMessage("\u00A74Exception detail: " + e);
|
MC.sendChatMessage("\u00A74Error: " + e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -639,7 +669,7 @@ public class ClientApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendChatMessagesNow()
|
private void sendQueuedChatMessages()
|
||||||
{
|
{
|
||||||
// dev build
|
// dev build
|
||||||
if (ModInfo.IS_DEV_BUILD && !this.configOverrideReminderPrinted && MC.playerExists())
|
if (ModInfo.IS_DEV_BUILD && !this.configOverrideReminderPrinted && MC.playerExists())
|
||||||
@@ -647,10 +677,12 @@ public class ClientApi
|
|||||||
this.configOverrideReminderPrinted = true;
|
this.configOverrideReminderPrinted = true;
|
||||||
|
|
||||||
// remind the user that this is a development build
|
// remind the user that this is a development build
|
||||||
MC.sendChatMessage("\u00A72" + "Distant Horizons: nightly/unstable build, version: [" + ModInfo.VERSION+"]." + "\u00A7r");
|
String message =
|
||||||
MC.sendChatMessage("Issues may occur with this version.");
|
// green text
|
||||||
MC.sendChatMessage("Here be dragons!");
|
"\u00A72" + "Distant Horizons: nightly/unstable build, version: [" + ModInfo.VERSION+"]." + "\u00A7r\n" +
|
||||||
MC.sendChatMessage("");
|
"Issues may occur with this version.\n" +
|
||||||
|
"Here be dragons!\n";
|
||||||
|
MC.sendChatMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// memory
|
// memory
|
||||||
@@ -665,11 +697,13 @@ public class ClientApi
|
|||||||
long maxMemoryInBytes = Runtime.getRuntime().maxMemory();
|
long maxMemoryInBytes = Runtime.getRuntime().maxMemory();
|
||||||
if (maxMemoryInBytes < minimumRecommendedMemoryInBytes)
|
if (maxMemoryInBytes < minimumRecommendedMemoryInBytes)
|
||||||
{
|
{
|
||||||
MC.sendChatMessage("\u00A76" + "Distant Horizons: Low memory detected." + "\u00A7r");
|
String message =
|
||||||
MC.sendChatMessage("Stuttering or low FPS may occur.");
|
// orange text
|
||||||
MC.sendChatMessage("Please increase Minecraft's available memory to 4 gigabytes.");
|
"\u00A76" + "Distant Horizons: Low memory detected." + "\u00A7r \n" +
|
||||||
MC.sendChatMessage("This warning can be disabled in DH's config under Advanced -> Logging.");
|
"Stuttering or low FPS may occur. \n" +
|
||||||
MC.sendChatMessage("");
|
"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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ import com.seibel.distanthorizons.core.generation.DhLightingEngine;
|
|||||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
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.sql.repo.AbstractDhRepo;
|
||||||
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.core.util.TimerUtil;
|
import com.seibel.distanthorizons.core.util.TimerUtil;
|
||||||
import com.seibel.distanthorizons.core.util.objects.Pair;
|
import com.seibel.distanthorizons.core.util.objects.Pair;
|
||||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||||
@@ -43,9 +43,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
|
|
||||||
/** Contains code and variables used by both {@link ClientApi} and {@link ServerApi} */
|
/** Contains code and variables used by both {@link ClientApi} and {@link ServerApi} */
|
||||||
public class SharedApi
|
public class SharedApi
|
||||||
@@ -62,6 +60,7 @@ public class SharedApi
|
|||||||
private static final Timer CHUNK_UPDATE_TIMER = TimerUtil.CreateTimer("ChunkUpdateTimer");
|
private static final Timer CHUNK_UPDATE_TIMER = TimerUtil.CreateTimer("ChunkUpdateTimer");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static AbstractDhWorld currentWorld;
|
private static AbstractDhWorld currentWorld;
|
||||||
private static int lastWorldGenTickDelta = 0;
|
private static int lastWorldGenTickDelta = 0;
|
||||||
private static long lastOverloadedLogMessageMsTime = 0;
|
private static long lastOverloadedLogMessageMsTime = 0;
|
||||||
@@ -139,23 +138,13 @@ public class SharedApi
|
|||||||
public static boolean isChunkAtBlockPosAlreadyUpdating(int blockPosX, int blockPosZ)
|
public static boolean isChunkAtBlockPosAlreadyUpdating(int blockPosX, int blockPosZ)
|
||||||
{ return UPDATING_CHUNK_POS_SET.contains(new DhChunkPos(new DhBlockPos2D(blockPosX, 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 */
|
/** handles both block place and break events */
|
||||||
public void chunkBlockChangedEvent(IChunkWrapper chunk, ILevelWrapper level) { this.applyChunkUpdate(chunk, level, true); }
|
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 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)
|
public void applyChunkUpdate(IChunkWrapper chunkWrapper, ILevelWrapper level, boolean updateNeighborChunks)
|
||||||
{
|
{
|
||||||
@@ -265,7 +254,7 @@ public class SharedApi
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// neighboring chunk
|
// neighboring chunk
|
||||||
DhChunkPos neighbourPos = new DhChunkPos(chunkWrapper.getChunkPos().x + xOffset, chunkWrapper.getChunkPos().z + zOffset);
|
DhChunkPos neighbourPos = new DhChunkPos(chunkWrapper.getChunkPos().getX() + xOffset, chunkWrapper.getChunkPos().getZ() + zOffset);
|
||||||
IChunkWrapper neighbourChunk = dhLevel.getLevelWrapper().tryGetChunk(neighbourPos);
|
IChunkWrapper neighbourChunk = dhLevel.getLevelWrapper().tryGetChunk(neighbourPos);
|
||||||
if (neighbourChunk != null)
|
if (neighbourChunk != null)
|
||||||
{
|
{
|
||||||
@@ -282,36 +271,43 @@ public class SharedApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void bakeChunkLightingAndSendToLevelAsync(IChunkWrapper chunkWrapper, @Nullable ArrayList<IChunkWrapper> neighbourChunkList, IDhLevel dhLevel)
|
/** 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)
|
||||||
{
|
{
|
||||||
// lighting the chunk needs to be done on a separate thread to prevent lagging any of the event threads
|
// lighting the chunk needs to be done on a separate thread to prevent lagging any of the event threads
|
||||||
ThreadPoolExecutor executor = ThreadPoolUtil.getLightPopulatorExecutor();
|
ThreadPoolExecutor executor = ThreadPoolUtil.getChunkToLodBuilderExecutor();
|
||||||
if (executor == null)
|
if (executor == null)
|
||||||
{
|
{
|
||||||
return;
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
executor.execute(() ->
|
return CompletableFuture.runAsync(() ->
|
||||||
{
|
{
|
||||||
//LOGGER.trace(chunkWrapper.getChunkPos() + " " + executor.getActiveCount() + " / " + executor.getQueue().size() + " - " + executor.getCompletedTaskCount());
|
//LOGGER.trace(chunkWrapper.getChunkPos() + " " + executor.getActiveCount() + " / " + executor.getQueue().size() + " - " + executor.getCompletedTaskCount());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
boolean checkChunkHash = !Config.Client.Advanced.LodBuilding.disableUnchangedChunkCheck.get();
|
||||||
|
|
||||||
// check if this chunk has been converted into an LOD already
|
// 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 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();
|
int newChunkHash = chunkWrapper.getBlockBiomeHashCode();
|
||||||
if (oldChunkHash == newChunkHash)
|
if (checkChunkHash)
|
||||||
{
|
{
|
||||||
// if the chunk hashes are the same then we don't need to bother with lighting the chunk
|
if (oldChunkHash == newChunkHash)
|
||||||
// or creating/updating the LODs
|
{
|
||||||
//LOGGER.info("skipping: "+chunkWrapper.getChunkPos()+" "+newChunkHash);
|
// if the chunk hashes are the same then we don't need to bother with lighting the chunk
|
||||||
return;
|
// or creating/updating the LODs
|
||||||
}
|
//LOGGER.info("skipping: "+chunkWrapper.getChunkPos()+" "+newChunkHash);
|
||||||
else
|
return;
|
||||||
{
|
}
|
||||||
//LOGGER.info("g: "+chunkWrapper.getChunkPos()+" "+newChunkHash);
|
else
|
||||||
|
{
|
||||||
|
//LOGGER.info("g: "+chunkWrapper.getChunkPos()+" "+newChunkHash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -328,36 +324,44 @@ public class SharedApi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Save or populate the chunk wrapper's lighting
|
// chunk light baking is disabled since profiling revealed it used
|
||||||
// this is done so we don't have to worry about MC unloading the lighting data for this chunk
|
// roughly the same amount of time as generating the lighting ourselves and
|
||||||
boolean onlyUseDhLighting = Config.Client.Advanced.LodBuilding.onlyUseDhLightingEngine.get();
|
// was much more likely to have issues with corrupt (all black or all bright) chunks
|
||||||
if (!onlyUseDhLighting && chunkWrapper.isLightCorrect())
|
boolean tryUsingMcLightingEngine = false;
|
||||||
|
if (tryUsingMcLightingEngine)
|
||||||
{
|
{
|
||||||
try
|
// 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())
|
||||||
{
|
{
|
||||||
// If MC's lighting engine isn't thread safe this may cause the server thread to lag
|
// If MC's lighting engine isn't thread safe this may cause the server thread to lag
|
||||||
chunkWrapper.bakeDhLightingUsingMcLightingEngine();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalStateException e)
|
|
||||||
|
// something went wrong during the baking process so we have to generate the lighting ourselves
|
||||||
|
if (!chunkLightPopulated)
|
||||||
{
|
{
|
||||||
LOGGER.warn("Chunk light baking error: " + e.getMessage(), e);
|
DhLightingEngine.INSTANCE.lightChunk(chunkWrapper, nearbyChunkList, dhLevel.hasSkyLight() ? LodUtil.MAX_MC_LIGHT : LodUtil.MIN_MC_LIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// generate the chunk's lighting, using neighboring chunks if present
|
DhLightingEngine.INSTANCE.lightChunk(chunkWrapper, nearbyChunkList, dhLevel.hasSkyLight() ? LodUtil.MAX_MC_LIGHT : LodUtil.MIN_MC_LIGHT);
|
||||||
DhLightingEngine.INSTANCE.lightChunk(chunkWrapper, nearbyChunkList, dhLevel.hasSkyLight() ? 15 : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// get this chunk's active beacons
|
dhLevel.updateBeaconBeamsForChunk(chunkWrapper, nearbyChunkList);
|
||||||
List<BeaconBeamDTO> beaconBeamList = chunkWrapper.getAllActiveBeacons(nearbyChunkList);
|
dhLevel.updateChunkAsync(chunkWrapper, newChunkHash);
|
||||||
dhLevel.setBeaconBeamsForChunk(chunkWrapper.getChunkPos(), beaconBeamList);
|
|
||||||
|
|
||||||
|
|
||||||
dhLevel.updateChunkAsync(chunkWrapper);
|
|
||||||
dhLevel.setChunkHash(chunkWrapper.getChunkPos(), newChunkHash);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -382,9 +386,13 @@ public class SharedApi
|
|||||||
UPDATING_CHUNK_POS_SET.remove(chunkWrapper.getChunkPos());
|
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,17 +20,20 @@
|
|||||||
package com.seibel.distanthorizons.core.config;
|
package com.seibel.distanthorizons.core.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.DhApi;
|
||||||
import com.seibel.distanthorizons.api.enums.config.*;
|
import com.seibel.distanthorizons.api.enums.config.*;
|
||||||
import com.seibel.distanthorizons.api.enums.config.quickOptions.*;
|
import com.seibel.distanthorizons.api.enums.config.quickOptions.*;
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.*;
|
import com.seibel.distanthorizons.api.enums.rendering.*;
|
||||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
||||||
import com.seibel.distanthorizons.core.config.eventHandlers.*;
|
import com.seibel.distanthorizons.core.config.eventHandlers.*;
|
||||||
import com.seibel.distanthorizons.core.config.eventHandlers.presets.*;
|
import com.seibel.distanthorizons.core.config.eventHandlers.presets.*;
|
||||||
|
import com.seibel.distanthorizons.core.config.listeners.ConfigChangeListener;
|
||||||
import com.seibel.distanthorizons.core.config.types.*;
|
import com.seibel.distanthorizons.core.config.types.*;
|
||||||
import com.seibel.distanthorizons.core.config.types.enums.*;
|
import com.seibel.distanthorizons.core.config.types.enums.*;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
||||||
@@ -51,7 +54,6 @@ import java.util.List;
|
|||||||
* Otherwise, you will have issues where only some of the config entries will exist when your listener is created.
|
* Otherwise, you will have issues where only some of the config entries will exist when your listener is created.
|
||||||
*
|
*
|
||||||
* @author coolGi
|
* @author coolGi
|
||||||
* @version 2023-7-16
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Config
|
public class Config
|
||||||
@@ -104,6 +106,8 @@ public class Config
|
|||||||
|
|
||||||
public static ConfigLinkedEntry quickEnableWorldGenerator = new ConfigLinkedEntry(Advanced.WorldGenerator.enableDistantGeneration);
|
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>()
|
public static ConfigEntry<Boolean> optionsButton = new ConfigEntry.Builder<Boolean>()
|
||||||
.set(true)
|
.set(true)
|
||||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_FILE)
|
.setAppearance(EConfigEntryAppearance.ONLY_IN_FILE)
|
||||||
@@ -123,7 +127,6 @@ public class Config
|
|||||||
public static ConfigCategory multiplayer = new ConfigCategory.Builder().set(Multiplayer.class).build();
|
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 lodBuilding = new ConfigCategory.Builder().set(LodBuilding.class).build();
|
||||||
public static ConfigCategory multiThreading = new ConfigCategory.Builder().set(MultiThreading.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 autoUpdater = new ConfigCategory.Builder().set(AutoUpdater.class).build();
|
||||||
|
|
||||||
public static ConfigCategory logging = new ConfigCategory.Builder().set(Logging.class).build();
|
public static ConfigCategory logging = new ConfigCategory.Builder().set(Logging.class).build();
|
||||||
@@ -176,6 +179,7 @@ public class Config
|
|||||||
+ "Lowest Quality: " + EDhApiVerticalQuality.HEIGHT_MAP + "\n"
|
+ "Lowest Quality: " + EDhApiVerticalQuality.HEIGHT_MAP + "\n"
|
||||||
+ "Highest Quality: " + EDhApiVerticalQuality.EXTREME)
|
+ "Highest Quality: " + EDhApiVerticalQuality.EXTREME)
|
||||||
.setPerformance(EConfigEntryPerformance.VERY_HIGH)
|
.setPerformance(EConfigEntryPerformance.VERY_HIGH)
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiHorizontalQuality> horizontalQuality = new ConfigEntry.Builder<EDhApiHorizontalQuality>()
|
public static ConfigEntry<EDhApiHorizontalQuality> horizontalQuality = new ConfigEntry.Builder<EDhApiHorizontalQuality>()
|
||||||
@@ -197,6 +201,7 @@ public class Config
|
|||||||
+ EDhApiTransparency.DISABLED + ": LODs will be opaque. \n"
|
+ EDhApiTransparency.DISABLED + ": LODs will be opaque. \n"
|
||||||
+ "")
|
+ "")
|
||||||
.setPerformance(EConfigEntryPerformance.MEDIUM)
|
.setPerformance(EConfigEntryPerformance.MEDIUM)
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiBlocksToAvoid> blocksToIgnore = new ConfigEntry.Builder<EDhApiBlocksToAvoid>()
|
public static ConfigEntry<EDhApiBlocksToAvoid> blocksToIgnore = new ConfigEntry.Builder<EDhApiBlocksToAvoid>()
|
||||||
@@ -208,6 +213,7 @@ 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"
|
+ 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)
|
.setPerformance(EConfigEntryPerformance.NONE)
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<Boolean> tintWithAvoidedBlocks = new ConfigEntry.Builder<Boolean>()
|
public static ConfigEntry<Boolean> tintWithAvoidedBlocks = new ConfigEntry.Builder<Boolean>()
|
||||||
@@ -219,6 +225,7 @@ public class Config
|
|||||||
+ "False: skipped blocks will not change color of surface below them. "
|
+ "False: skipped blocks will not change color of surface below them. "
|
||||||
+ "")
|
+ "")
|
||||||
.setPerformance(EConfigEntryPerformance.NONE)
|
.setPerformance(EConfigEntryPerformance.NONE)
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// TODO fixme
|
// TODO fixme
|
||||||
@@ -584,6 +591,7 @@ public class Config
|
|||||||
+ "0 = black \n"
|
+ "0 = black \n"
|
||||||
+ "1 = normal \n"
|
+ "1 = normal \n"
|
||||||
+ "2 = near white")
|
+ "2 = near white")
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<Double> saturationMultiplier = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI doesnt support floats)
|
public static ConfigEntry<Double> saturationMultiplier = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI doesnt support floats)
|
||||||
@@ -594,6 +602,7 @@ public class Config
|
|||||||
+ "0 = black and white \n"
|
+ "0 = black and white \n"
|
||||||
+ "1 = normal \n"
|
+ "1 = normal \n"
|
||||||
+ "2 = very saturated")
|
+ "2 = very saturated")
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<Boolean> enableCaveCulling = new ConfigEntry.Builder<Boolean>()
|
public static ConfigEntry<Boolean> enableCaveCulling = new ConfigEntry.Builder<Boolean>()
|
||||||
@@ -608,12 +617,15 @@ public class Config
|
|||||||
+ "Additional Info: Currently this cull all faces \n"
|
+ "Additional Info: Currently this cull all faces \n"
|
||||||
+ " with skylight value of 0 in dimensions that \n"
|
+ " with skylight value of 0 in dimensions that \n"
|
||||||
+ " does not have a ceiling.")
|
+ " does not have a ceiling.")
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<Integer> caveCullingHeight = new ConfigEntry.Builder<Integer>()
|
public static ConfigEntry<Integer> caveCullingHeight = new ConfigEntry.Builder<Integer>()
|
||||||
.setMinDefaultMax(-4096, 40, 4096)
|
.setMinDefaultMax(-4096, 60, 4096)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "At what Y value should cave culling start?")
|
+ "At what Y value should cave culling start? \n"
|
||||||
|
+ "Lower this value if you get walls for areas with 0 light.")
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<Integer> earthCurveRatio = new ConfigEntry.Builder<Integer>()
|
public static ConfigEntry<Integer> earthCurveRatio = new ConfigEntry.Builder<Integer>()
|
||||||
@@ -651,6 +663,7 @@ public class Config
|
|||||||
+ EDhApiLodShading.DISABLED + ": All LOD sides will be rendered with the same brightness. \n"
|
+ EDhApiLodShading.DISABLED + ": All LOD sides will be rendered with the same brightness. \n"
|
||||||
+ "")
|
+ "")
|
||||||
.setPerformance(EConfigEntryPerformance.NONE)
|
.setPerformance(EConfigEntryPerformance.NONE)
|
||||||
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<Boolean> disableFrustumCulling = new ConfigEntry.Builder<Boolean>()
|
public static ConfigEntry<Boolean> disableFrustumCulling = new ConfigEntry.Builder<Boolean>()
|
||||||
@@ -685,6 +698,18 @@ public class Config
|
|||||||
+ EDhApiGrassSideRendering.AS_DIRT + ": sides render entirely as dirt. \n"
|
+ EDhApiGrassSideRendering.AS_DIRT + ": sides render entirely as dirt. \n"
|
||||||
+ "")
|
+ "")
|
||||||
.setPerformance(EConfigEntryPerformance.NONE)
|
.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();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -768,8 +793,23 @@ public class Config
|
|||||||
+ "")
|
+ "")
|
||||||
.build();
|
.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>()
|
public static ConfigEntry<Boolean> onlyUseDhLightingEngine = new ConfigEntry.Builder<Boolean>()
|
||||||
.set(false)
|
.set(false)
|
||||||
|
.setAppearance(EConfigEntryAppearance.ONLY_IN_API)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If false LODs will be lit by Minecraft's lighting engine when possible \n"
|
+ "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"
|
+ "and fall back to the DH lighting engine only when necessary. \n"
|
||||||
@@ -843,13 +883,47 @@ public class Config
|
|||||||
+ "")
|
+ "")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
//public static ConfigEntry<Boolean> showMigrationChatWarning = new ConfigEntry.Builder<Boolean>()
|
public static ConfigEntry<String> ignoredRenderBlockCsv = new ConfigEntry.Builder<String>()
|
||||||
// .set(true)
|
.set("minecraft:barrier,minecraft:structure_void,minecraft:light,minecraft:tripwire")
|
||||||
// .comment(""
|
.comment(""
|
||||||
// + "Determines if a message should be displayed in the chat when LOD migration starts. \n"
|
+ "A comma separated list of block resource locations that won't be rendered by DH. \n"
|
||||||
// + "")
|
+ "Note: air is always included in this list. \n"
|
||||||
// .build();
|
+ "")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public static ConfigEntry<String> ignoredRenderCaveBlockCsv = new ConfigEntry.Builder<String>()
|
||||||
|
.set("minecraft:glow_lichen,minecraft:rail,minecraft:water,minecraft:lava,minecraft:bubble_column")
|
||||||
|
.comment(""
|
||||||
|
+ "A comma separated list of block resource locations that shouldn't be rendered \n"
|
||||||
|
+ "if they are in a 0 sky light underground area. \n"
|
||||||
|
+ "Note: air is always included in this list. \n"
|
||||||
|
+ "")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
ignoredRenderBlockCsv.addListener(new ConfigChangeListener<String>(Config.Client.Advanced.LodBuilding.ignoredRenderBlockCsv,
|
||||||
|
(blockCsv) ->
|
||||||
|
{
|
||||||
|
IWrapperFactory wrapperFactory = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
||||||
|
if (wrapperFactory != null)
|
||||||
|
{
|
||||||
|
wrapperFactory.resetRendererIgnoredBlocksSet();
|
||||||
|
DhApi.Delayed.renderProxy.clearRenderDataCache();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
ignoredRenderCaveBlockCsv.addListener(new ConfigChangeListener<String>(Config.Client.Advanced.LodBuilding.ignoredRenderCaveBlockCsv,
|
||||||
|
(blockCsv) ->
|
||||||
|
{
|
||||||
|
IWrapperFactory wrapperFactory = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
||||||
|
if (wrapperFactory != null)
|
||||||
|
{
|
||||||
|
wrapperFactory.resetRendererIgnoredCaveBlocks();
|
||||||
|
DhApi.Delayed.renderProxy.clearRenderDataCache();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Multiplayer
|
public static class Multiplayer
|
||||||
@@ -1023,39 +1097,6 @@ public class Config
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GpuBuffers
|
|
||||||
{
|
|
||||||
public static ConfigEntry<EDhApiGpuUploadMethod> gpuUploadMethod = new ConfigEntry.Builder<EDhApiGpuUploadMethod>()
|
|
||||||
.set(EDhApiGpuUploadMethod.AUTO)
|
|
||||||
.comment(""
|
|
||||||
+ "What method should be used to upload geometry to the GPU? \n"
|
|
||||||
+ "\n"
|
|
||||||
+ EDhApiGpuUploadMethod.AUTO + ": Picks the best option based on the GPU you have. \n"
|
|
||||||
+ "\n"
|
|
||||||
+ 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 class AutoUpdater
|
public static class AutoUpdater
|
||||||
{
|
{
|
||||||
public static ConfigEntry<Boolean> enableAutoUpdater = new ConfigEntry.Builder<Boolean>()
|
public static ConfigEntry<Boolean> enableAutoUpdater = new ConfigEntry.Builder<Boolean>()
|
||||||
@@ -1087,63 +1128,63 @@ public class Config
|
|||||||
// TODO add change all option
|
// TODO add change all option
|
||||||
// TODO default to error chat and info file
|
// TODO default to error chat and info file
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logWorldGenEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logWorldGenEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log information about the world generation process. \n"
|
+ "If enabled, the mod will log information about the world generation process. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logWorldGenPerformance = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logWorldGenPerformance = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log performance about the world generation process. \n"
|
+ "If enabled, the mod will log performance about the world generation process. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logWorldGenLoadEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logWorldGenLoadEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log information about the world generation process. \n"
|
+ "If enabled, the mod will log information about the world generation process. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logLodBuilderEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logLodBuilderEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log information about the LOD generation process. \n"
|
+ "If enabled, the mod will log information about the LOD generation process. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logRendererBufferEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logRendererBufferEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log information about the renderer buffer process. \n"
|
+ "If enabled, the mod will log information about the renderer buffer process. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logRendererGLEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logRendererGLEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log information about the renderer OpenGL process. \n"
|
+ "If enabled, the mod will log information about the renderer OpenGL process. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logFileReadWriteEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logFileReadWriteEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log information about file read/write operations. \n"
|
+ "If enabled, the mod will log information about file read/write operations. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logFileSubDimEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logFileSubDimEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log information about file sub-dimension operations. \n"
|
+ "If enabled, the mod will log information about file sub-dimension operations. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ConfigEntry<EDhApiLoggerMode> logNetworkEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
public static ConfigEntry<EDhApiLoggerMode> logNetworkEvent = new ConfigEntry.Builder<EDhApiLoggerMode>()
|
||||||
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT)
|
.set(EDhApiLoggerMode.LOG_ERROR_TO_CHAT_AND_INFO_TO_FILE)
|
||||||
.comment(""
|
.comment(""
|
||||||
+ "If enabled, the mod will log information about network operations. \n"
|
+ "If enabled, the mod will log information about network operations. \n"
|
||||||
+ "This can be useful for debugging.")
|
+ "This can be useful for debugging.")
|
||||||
@@ -1157,6 +1198,20 @@ public class Config
|
|||||||
+ "memory allocated to run DH well.")
|
+ "memory allocated to run DH well.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
public static ConfigEntry<Boolean> showReplayWarningOnStartup = new ConfigEntry.Builder<Boolean>()
|
||||||
|
.set(true)
|
||||||
|
.comment(""
|
||||||
|
+ "If enabled, a chat message will be displayed when a replay is started \n"
|
||||||
|
+ "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
|
public static class Debugging
|
||||||
@@ -1243,22 +1298,38 @@ public class Config
|
|||||||
public static ConfigEntry<Boolean> columnBuilderDebugEnable = new ConfigEntry.Builder<Boolean>()
|
public static ConfigEntry<Boolean> columnBuilderDebugEnable = new ConfigEntry.Builder<Boolean>()
|
||||||
.set(false)
|
.set(false)
|
||||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||||
.addListener(DebugColumnConfigEventHandler.INSTANCE)
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
public static ConfigEntry<Integer> columnBuilderDebugDetailLevel = new ConfigEntry.Builder<Integer>()
|
public static ConfigEntry<Integer> columnBuilderDebugDetailLevel = new ConfigEntry.Builder<Integer>()
|
||||||
.set((int) DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL)
|
.set((int) DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL)
|
||||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||||
.addListener(DebugColumnConfigEventHandler.INSTANCE)
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
public static ConfigEntry<Integer> columnBuilderDebugXPos = new ConfigEntry.Builder<Integer>()
|
public static ConfigEntry<Integer> columnBuilderDebugXPos = new ConfigEntry.Builder<Integer>()
|
||||||
.set(0)
|
.set(0)
|
||||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||||
.addListener(DebugColumnConfigEventHandler.INSTANCE)
|
.addListener(ReloadLodsConfigEventHandler.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
public static ConfigEntry<Integer> columnBuilderDebugZPos = new ConfigEntry.Builder<Integer>()
|
public static ConfigEntry<Integer> columnBuilderDebugZPos = new ConfigEntry.Builder<Integer>()
|
||||||
.set(0)
|
.set(0)
|
||||||
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
|
||||||
.addListener(DebugColumnConfigEventHandler.INSTANCE)
|
.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)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -23,9 +23,9 @@ import com.seibel.distanthorizons.api.DhApi;
|
|||||||
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderProxy;
|
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderProxy;
|
||||||
import com.seibel.distanthorizons.core.config.listeners.IConfigListener;
|
import com.seibel.distanthorizons.core.config.listeners.IConfigListener;
|
||||||
|
|
||||||
public class DebugColumnConfigEventHandler implements IConfigListener
|
public class ReloadLodsConfigEventHandler implements IConfigListener
|
||||||
{
|
{
|
||||||
public static DebugColumnConfigEventHandler INSTANCE = new DebugColumnConfigEventHandler();
|
public static ReloadLodsConfigEventHandler INSTANCE = new ReloadLodsConfigEventHandler();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigValueSet()
|
public void onConfigValueSet()
|
||||||
+1
-1
@@ -168,7 +168,7 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
|
|||||||
|
|
||||||
if (newPreset != currentPreset)
|
if (newPreset != currentPreset)
|
||||||
{
|
{
|
||||||
this.getPresetConfigEntry().set(this.getCustomPresetEnum());
|
this.getPresetConfigEntry().set(newPreset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,20 +256,38 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
|||||||
public byte isValid(T value, T min, T max)
|
public byte isValid(T value, T min, T max)
|
||||||
{
|
{
|
||||||
if (this.configBase.disableMinMax)
|
if (this.configBase.disableMinMax)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (value == null || this.value == null || value.getClass() != this.value.getClass()) // If the 2 variables aren't the same type then it will be invalid
|
else if (min == null && max == null)
|
||||||
|
{
|
||||||
|
// no validation is needed for this field
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (value == null || this.value == null
|
||||||
|
|| value.getClass() != this.value.getClass())
|
||||||
|
{
|
||||||
|
// If the 2 variables aren't the same type then it will be invalid
|
||||||
return 2;
|
return 2;
|
||||||
if (Number.class.isAssignableFrom(value.getClass()))
|
}
|
||||||
{ // Only check min max if it is a number
|
else if (Number.class.isAssignableFrom(value.getClass()))
|
||||||
|
{
|
||||||
|
// Only check min max if it is a number
|
||||||
if (max != null && NumberUtil.greaterThan((Number) value, (Number) max))
|
if (max != null && NumberUtil.greaterThan((Number) value, (Number) max))
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
if (min != null && NumberUtil.lessThan((Number) value, (Number) min))
|
if (min != null && NumberUtil.lessThan((Number) value, (Number) min))
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This should normally not be called since set() automatically calls this */
|
/** This should normally not be called since set() automatically calls this */
|
||||||
|
|||||||
+2
@@ -62,6 +62,8 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
|
|||||||
|
|
||||||
/** measured in data columns */
|
/** measured in data columns */
|
||||||
public static final int WIDTH = 64;
|
public static final int WIDTH = 64;
|
||||||
|
/** how many chunks wide this datasource is. */
|
||||||
|
public static final int NUMB_OF_CHUNKS_WIDE = WIDTH / LodUtil.CHUNK_WIDTH;
|
||||||
|
|
||||||
public static final byte DATA_FORMAT_VERSION = 1;
|
public static final byte DATA_FORMAT_VERSION = 1;
|
||||||
|
|
||||||
|
|||||||
+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.DataSourcePool;
|
||||||
import com.seibel.distanthorizons.core.file.IDataSource;
|
import com.seibel.distanthorizons.core.file.IDataSource;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
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);
|
EDhApiWorldGenerationStep worldGenStep = inputFullDataSource.getWorldGenStepAtRelativePos(x, z);
|
||||||
if (dataColumn != null && worldGenStep != EDhApiWorldGenerationStep.EMPTY)
|
if (dataColumn != null && worldGenStep != EDhApiWorldGenerationStep.EMPTY)
|
||||||
{
|
{
|
||||||
FullDataToRenderDataTransformer.convertColumnData(
|
FullDataToRenderDataTransformer.updateOrReplaceRenderDataViewColumnWithFullDataColumn(
|
||||||
level, inputFullDataSource.mapping,
|
level, inputFullDataSource.mapping,
|
||||||
minBlockPos.x + x,
|
minBlockPos.x + x,
|
||||||
minBlockPos.z + z,
|
minBlockPos.z + z,
|
||||||
@@ -288,7 +288,7 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
|
|||||||
String SUBDATA_DELIMITER = ",";
|
String SUBDATA_DELIMITER = ",";
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
stringBuilder.append(this.pos);
|
stringBuilder.append(DhSectionPos.toString(this.pos));
|
||||||
stringBuilder.append(LINE_DELIMITER);
|
stringBuilder.append(LINE_DELIMITER);
|
||||||
|
|
||||||
int size = 1;
|
int size = 1;
|
||||||
|
|||||||
+243
-337
@@ -19,29 +19,60 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding;
|
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.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
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.ColorUtil;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
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.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
|
||||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class ColumnBox
|
public class ColumnBox
|
||||||
{
|
{
|
||||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
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(
|
public static void addBoxQuadsToBuilder(
|
||||||
LodQuadBuilder builder,
|
LodQuadBuilder builder, IDhClientLevel clientLevel,
|
||||||
short xSize, short ySize, short zSize,
|
short xSize, short ySize, short zSize,
|
||||||
short x, short minY, short z,
|
short x, short minY, short z,
|
||||||
int color, byte irisBlockMaterialId, byte skyLight, byte blockLight,
|
int color, byte irisBlockMaterialId, byte skyLight, byte blockLight,
|
||||||
long topData, long bottomData, ColumnArrayView[][] adjData)
|
long topData, long bottomData, ColumnArrayView[] adjData, boolean[] isAdjDataSameDetailLevel)
|
||||||
{
|
{
|
||||||
|
//================//
|
||||||
|
// variable setup //
|
||||||
|
//================//
|
||||||
|
|
||||||
short maxX = (short) (x + xSize);
|
short maxX = (short) (x + xSize);
|
||||||
short maxY = (short) (minY + ySize);
|
short maxY = (short) (minY + ySize);
|
||||||
short maxZ = (short) (z + zSize);
|
short maxZ = (short) (z + zSize);
|
||||||
@@ -53,33 +84,24 @@ public class ColumnBox
|
|||||||
boolean isTopTransparent = RenderDataPointUtil.getAlpha(topData) < 255 && LodRenderer.transparencyEnabled;
|
boolean isTopTransparent = RenderDataPointUtil.getAlpha(topData) < 255 && LodRenderer.transparencyEnabled;
|
||||||
boolean isBottomTransparent = RenderDataPointUtil.getAlpha(bottomData) < 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
|
// 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
|
// 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))
|
if (!RenderDataPointUtil.doesDataPointExist(bottomData))
|
||||||
{
|
{
|
||||||
color = ColorUtil.setAlpha(color, 255);
|
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
|
// fake ocean transparency
|
||||||
if (LodRenderer.transparencyEnabled && LodRenderer.fakeOceanFloor)
|
if (LodRenderer.transparencyEnabled && LodRenderer.fakeOceanFloor)
|
||||||
{
|
{
|
||||||
@@ -99,7 +121,9 @@ public class ColumnBox
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// add top and bottom faces if requested //
|
//==========================//
|
||||||
|
// add top and bottom faces //
|
||||||
|
//==========================//
|
||||||
|
|
||||||
boolean skipTop = RenderDataPointUtil.doesDataPointExist(topData) && (RenderDataPointUtil.getYMin(topData) == maxY) && !isTopTransparent;
|
boolean skipTop = RenderDataPointUtil.doesDataPointExist(topData) && (RenderDataPointUtil.getYMin(topData) == maxY) && !isTopTransparent;
|
||||||
if (!skipTop)
|
if (!skipTop)
|
||||||
@@ -114,409 +138,291 @@ public class ColumnBox
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// add North, south, east, and west faces if requested //
|
|
||||||
|
|
||||||
// TODO merge duplicate code
|
//========================================//
|
||||||
//NORTH face vertex creation
|
// add North, south, east, and west faces //
|
||||||
|
//========================================//
|
||||||
|
|
||||||
|
// NORTH face
|
||||||
{
|
{
|
||||||
ColumnArrayView[] adjDataNorth = adjData[EDhDirection.NORTH.ordinal() - 2]; // TODO can we use something other than ordinal-2?
|
ColumnArrayView adjCol = adjData[EDhDirection.NORTH.ordinal() - 2]; // TODO can we use something other than ordinal-2?
|
||||||
int adjOverlapNorth = ColorUtil.INVISIBLE;
|
boolean adjSameDetailLevel = isAdjDataSameDetailLevel[EDhDirection.NORTH.ordinal() - 2];
|
||||||
if (adjDataNorth == null)
|
// if the adjacent column is null that generally means the adjacent area hasn't been generated yet
|
||||||
|
if (adjCol == 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)
|
if (!isTransparent || overVoid)
|
||||||
{
|
{
|
||||||
builder.addQuadAdj(EDhDirection.NORTH, x, minY, z, xSize, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
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
|
else
|
||||||
{
|
{
|
||||||
makeAdjVerticalQuad(builder, adjDataNorth[0], EDhDirection.NORTH, x, minY, z, (short) (xSize / 2), ySize,
|
makeAdjVerticalQuad(builder, adjCol, adjSameDetailLevel, caveCullingMaxY, EDhDirection.NORTH, x, minY, z, xSize, ySize,
|
||||||
color, adjOverlapNorth, irisBlockMaterialId, skyLightTop, blockLight,
|
color, irisBlockMaterialId, 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 vertex creation
|
// SOUTH face
|
||||||
{
|
{
|
||||||
ColumnArrayView[] adjDataSouth = adjData[EDhDirection.SOUTH.ordinal() - 2];
|
ColumnArrayView adjCol = adjData[EDhDirection.SOUTH.ordinal() - 2];
|
||||||
int adjOverlapSouth = ColorUtil.INVISIBLE;
|
boolean adjSameDetailLevel = isAdjDataSameDetailLevel[EDhDirection.SOUTH.ordinal() - 2];
|
||||||
if (adjDataSouth == null)
|
if (adjCol == null)
|
||||||
{
|
{
|
||||||
if (!isTransparent || overVoid)
|
if (!isTransparent || overVoid)
|
||||||
|
{
|
||||||
builder.addQuadAdj(EDhDirection.SOUTH, x, minY, maxZ, xSize, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
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
|
else
|
||||||
{
|
{
|
||||||
makeAdjVerticalQuad(builder, adjDataSouth[0], EDhDirection.SOUTH, x, minY, maxZ, (short) (xSize / 2), ySize,
|
makeAdjVerticalQuad(builder, adjCol, adjSameDetailLevel, caveCullingMaxY, EDhDirection.SOUTH, x, minY, maxZ, xSize, ySize,
|
||||||
color, adjOverlapSouth, irisBlockMaterialId, skyLightTop, blockLight,
|
color, irisBlockMaterialId, 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 vertex creation
|
// WEST face
|
||||||
{
|
{
|
||||||
ColumnArrayView[] adjDataWest = adjData[EDhDirection.WEST.ordinal() - 2];
|
ColumnArrayView adjCol = adjData[EDhDirection.WEST.ordinal() - 2];
|
||||||
int adjOverlapWest = ColorUtil.INVISIBLE;
|
boolean adjSameDetailLevel = isAdjDataSameDetailLevel[EDhDirection.WEST.ordinal() - 2];
|
||||||
if (adjDataWest == null)
|
if (adjCol == null)
|
||||||
{
|
{
|
||||||
if (!isTransparent || overVoid)
|
if (!isTransparent || overVoid)
|
||||||
|
{
|
||||||
builder.addQuadAdj(EDhDirection.WEST, x, minY, z, zSize, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
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
|
else
|
||||||
{
|
{
|
||||||
makeAdjVerticalQuad(builder, adjDataWest[0], EDhDirection.WEST, x, minY, z, (short) (zSize / 2), ySize,
|
makeAdjVerticalQuad(builder, adjCol, adjSameDetailLevel, caveCullingMaxY, EDhDirection.WEST, x, minY, z, zSize, ySize,
|
||||||
color, adjOverlapWest, irisBlockMaterialId, skyLightTop, blockLight,
|
color, irisBlockMaterialId, 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 vertex creation
|
// EAST face
|
||||||
{
|
{
|
||||||
ColumnArrayView[] adjDataEast = adjData[EDhDirection.EAST.ordinal() - 2];
|
ColumnArrayView adjCol = adjData[EDhDirection.EAST.ordinal() - 2];
|
||||||
int adjOverlapEast = ColorUtil.INVISIBLE;
|
boolean adjSameDetailLevel = isAdjDataSameDetailLevel[EDhDirection.EAST.ordinal() - 2];
|
||||||
if (adjData[EDhDirection.EAST.ordinal() - 2] == null)
|
if (adjCol == null)
|
||||||
{
|
{
|
||||||
if (!isTransparent || overVoid)
|
if (!isTransparent || overVoid)
|
||||||
|
{
|
||||||
builder.addQuadAdj(EDhDirection.EAST, maxX, minY, z, zSize, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
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
|
else
|
||||||
{
|
{
|
||||||
makeAdjVerticalQuad(builder, adjDataEast[0], EDhDirection.EAST, maxX, minY, z, (short) (zSize / 2), ySize,
|
makeAdjVerticalQuad(builder, adjCol, adjSameDetailLevel, caveCullingMaxY, EDhDirection.EAST, maxX, minY, z, zSize, ySize,
|
||||||
color, adjOverlapEast, irisBlockMaterialId, skyLightTop, blockLight,
|
color, irisBlockMaterialId, 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(
|
private static void makeAdjVerticalQuad(
|
||||||
LodQuadBuilder builder, ColumnArrayView adjColumnView, EDhDirection direction,
|
LodQuadBuilder builder, @NotNull ColumnArrayView adjColumnView, boolean adjacentIsSameDetailLevel, int caveCullingMaxY, EDhDirection direction,
|
||||||
short x, short yMin, short z, short horizontalWidth, short ySize,
|
short x, short yMin, short z, short horizontalWidth, short ySize,
|
||||||
int color, int debugOverlapColor, byte irisBlockMaterialId, byte skyLightTop, byte blockLight,
|
int color, byte irisBlockMaterialId, byte blockLight)
|
||||||
long topData, long bottomData)
|
|
||||||
{
|
{
|
||||||
|
//==================//
|
||||||
|
// create face with //
|
||||||
|
// no adjacent data //
|
||||||
|
//==================//
|
||||||
|
|
||||||
color = ColorUtil.applyShade(color, MC.getShade(direction));
|
color = ColorUtil.applyShade(color, MC.getShade(direction));
|
||||||
|
|
||||||
if (adjColumnView == null || adjColumnView.size == 0 || RenderDataPointUtil.isVoid(adjColumnView.get(0)))
|
// 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)))
|
||||||
{
|
{
|
||||||
// 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);
|
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, ySize, color, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, blockLight);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int yMax = yMin + ySize;
|
|
||||||
|
|
||||||
int adjIndex;
|
//===========================//
|
||||||
boolean firstFace = true;
|
// Determine face visibility //
|
||||||
boolean inputAboveAdjLods = true;
|
// based on it's neighbors //
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
// there isn't anything under this LOD,
|
// set the initial sky-lights for this face,
|
||||||
// to prevent seeing through the world, make it opaque
|
// if nothing overlaps or overhangs the face should have max sky light
|
||||||
color = ColorUtil.setAlpha(color, 255);
|
Arrays.fill(skyLightAtInputPos, yMin, yMax, LodUtil.MAX_MC_LIGHT);
|
||||||
}
|
|
||||||
|
|
||||||
|
// iterate top down
|
||||||
// Add adjacent faces if this LOD is surrounded by transparent LODs
|
int adjCount = adjColumnView.size();
|
||||||
// (prevents invisible sides underwater)
|
for (int adjIndex = 0; adjIndex < adjCount; adjIndex++)
|
||||||
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 adjBellowPoint = adjColumnView.get(adjIndex-1);
|
long adjPoint = adjColumnView.get(adjIndex);
|
||||||
adjOverVoid = !RenderDataPointUtil.doesDataPointExist(adjBellowPoint);
|
short adjMinY = RenderDataPointUtil.getYMin(adjPoint);
|
||||||
}
|
short adjMaxY = RenderDataPointUtil.getYMax(adjPoint);
|
||||||
boolean adjTransparent = !adjOverVoid && RenderDataPointUtil.getAlpha(adjPoint) < 255 && LodRenderer.transparencyEnabled;
|
|
||||||
|
|
||||||
|
// skip empty adjacent datapoints
|
||||||
// continue if this data point is transparent or the adjacent point is not
|
if (!RenderDataPointUtil.doesDataPointExist(adjPoint)
|
||||||
if (inputTransparent || !adjTransparent) // TODO inputIsTransparent may be unnecessary
|
|| RenderDataPointUtil.isVoid(adjPoint))
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
if (lastAdjWasTransparent && !adjTransparent)
|
|
||||||
{
|
|
||||||
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;
|
continue;
|
||||||
}
|
}
|
||||||
inputAboveAdjLods = false;
|
|
||||||
|
|
||||||
|
// skip this adjacent datapoint if it's above the input datapoint (since it can't affect the input data point)
|
||||||
if (adjYMax < yMin)
|
if (yMax <= adjMinY)
|
||||||
{
|
{
|
||||||
// the adjacent LOD is below the input LOD
|
continue;
|
||||||
|
|
||||||
// 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)
|
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)
|
||||||
{
|
{
|
||||||
// the adjacent LOD's base is at or below the input's base
|
// adj opaque
|
||||||
|
// mark positions adjacent is covering
|
||||||
if (yMax <= adjYMax)
|
byte adjSkyLight = RenderDataPointUtil.getLightSky(adjPoint);
|
||||||
|
for (int i = adjMinY; i < adjMaxY; i++)
|
||||||
{
|
{
|
||||||
// The input face is completely inside the adj's face, don't render it
|
byte skyLightAtPos = skyLightAtInputPos[i];
|
||||||
if (debugOverlapColor != 0)
|
|
||||||
{
|
// if the adjacent is a different detail level, we want to render adjacent opaque
|
||||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, ySize, debugOverlapColor, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, LodUtil.MAX_MC_LIGHT);
|
// 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);
|
||||||
}
|
}
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
// Otherwise: y < _____ height < yMax
|
// adjacent is transparent,
|
||||||
// _______&&: y < depth ______ < yMax
|
// use datapoint below adjacent for lighting
|
||||||
if (debugOverlapColor != 0)
|
byte belowSkyLight = RenderDataPointUtil.getLightSky(adjBelowPoint);
|
||||||
|
for (int i = adjMinY; i < adjMaxY; i++)
|
||||||
{
|
{
|
||||||
builder.addQuadAdj(direction, x, adjYMin, z, horizontalWidth, (short) (adjYMax - adjYMin), debugOverlapColor, irisBlockMaterialId, LodUtil.MAX_MC_LIGHT, LodUtil.MAX_MC_LIGHT);
|
byte skyLightAtPos = skyLightAtInputPos[i];
|
||||||
}
|
skyLightAtInputPos[i] = (byte) Math.min(belowSkyLight, skyLightAtPos);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// set next top as current depth
|
// fill in sky light up to the next DP,
|
||||||
previousAdjDepth = adjYMin;
|
// this is done to handle overhangs
|
||||||
firstFace = false;
|
byte adjSkyLight = RenderDataPointUtil.getLightSky(adjPoint);
|
||||||
nextTopSkyLight = skyLightTop;
|
int adjAboveMinY = RenderDataPointUtil.getYMin(adjAbovePoint);
|
||||||
|
for (int i = adjMaxY; i < adjAboveMinY; i++)
|
||||||
if (adjIndex + 1 < adjColumnView.size() && RenderDataPointUtil.doesDataPointExist(adjColumnView.get(adjIndex + 1)))
|
|
||||||
{
|
{
|
||||||
nextTopSkyLight = RenderDataPointUtil.getLightSky(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastAdjWasTransparent = adjTransparent;
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
|
||||||
|
|
||||||
if (inputAboveAdjLods)
|
|
||||||
{
|
{
|
||||||
// the input LOD is above all adjacent LODs and won't be affected
|
// clean up the array before the next thread uses it
|
||||||
// by them, add the vertical quad using the input's lighting and height
|
// (may be unnecessary since we only work between the yMin-yMax anyway, but is helpful for debugging)
|
||||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, ySize, color, irisBlockMaterialId, skyLightTop, blockLight);
|
Arrays.fill(skyLightAtInputPos, yMin, yMax, SKYLIGHT_EMPTY);
|
||||||
}
|
}
|
||||||
else if (previousAdjDepth != -1)
|
}
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
// We need to finish the last quad.
|
// Don't add transparent vertical faces
|
||||||
builder.addQuadAdj(direction, x, yMin, z, horizontalWidth, (short) (previousAdjDepth - yMin), color, irisBlockMaterialId, nextTopSkyLight, blockLight);
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+204
-113
@@ -19,19 +19,23 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding;
|
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.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.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.render.renderer.LodRenderer;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
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.api.enums.config.EDhApiGpuUploadMethod;
|
||||||
import com.seibel.distanthorizons.core.util.*;
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,18 +53,19 @@ public class ColumnRenderBuffer implements AutoCloseable
|
|||||||
/** number of bytes a single quad takes */
|
/** number of bytes a single quad takes */
|
||||||
public static final int QUADS_BYTE_SIZE = LodUtil.LOD_VERTEX_FORMAT.getByteSize() * 4;
|
public static final int QUADS_BYTE_SIZE = LodUtil.LOD_VERTEX_FORMAT.getByteSize() * 4;
|
||||||
/** how big a single VBO can be in bytes */
|
/** how big a single VBO can be in bytes */
|
||||||
public static final int MAX_VBO_BYTE_SIZE = 1024 * 1024; // 1 MB
|
public static final int MAX_VBO_BYTE_SIZE = 10 * 1024 * 1024; // 10 MB
|
||||||
public static final int MAX_QUADS_PER_BUFFER = MAX_VBO_BYTE_SIZE / QUADS_BYTE_SIZE;
|
public static final int MAX_QUADS_PER_BUFFER = MAX_VBO_BYTE_SIZE / QUADS_BYTE_SIZE;
|
||||||
public static final int FULL_SIZED_BUFFER = MAX_QUADS_PER_BUFFER * QUADS_BYTE_SIZE;
|
public static final int FULL_SIZED_BUFFER = MAX_QUADS_PER_BUFFER * QUADS_BYTE_SIZE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public final DhBlockPos pos;
|
public final DhBlockPos pos;
|
||||||
|
|
||||||
public boolean buffersUploaded = false;
|
public boolean buffersUploaded = false;
|
||||||
|
|
||||||
public SharedVbo.BufferSlice[] opaqueBufferSlices;
|
private GLVertexBuffer[] vbos;
|
||||||
public SharedVbo.BufferSlice[] transparentBufferSlices;
|
private GLVertexBuffer[] vbosTransparent;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -71,12 +76,14 @@ public class ColumnRenderBuffer implements AutoCloseable
|
|||||||
public ColumnRenderBuffer(DhBlockPos pos)
|
public ColumnRenderBuffer(DhBlockPos pos)
|
||||||
{
|
{
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.opaqueBufferSlices = new SharedVbo.BufferSlice[0];
|
this.vbos = new GLVertexBuffer[0];
|
||||||
this.transparentBufferSlices = new SharedVbo.BufferSlice[0];
|
this.vbosTransparent = new GLVertexBuffer[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==================//
|
//==================//
|
||||||
// buffer uploading //
|
// buffer uploading //
|
||||||
//==================//
|
//==================//
|
||||||
@@ -84,7 +91,7 @@ public class ColumnRenderBuffer implements AutoCloseable
|
|||||||
/** Should be run on a DH thread. */
|
/** Should be run on a DH thread. */
|
||||||
public void uploadBuffer(LodQuadBuilder builder, EDhApiGpuUploadMethod gpuUploadMethod) throws InterruptedException
|
public void uploadBuffer(LodQuadBuilder builder, EDhApiGpuUploadMethod gpuUploadMethod) throws InterruptedException
|
||||||
{
|
{
|
||||||
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.");
|
LodUtil.assertTrue(DhApi.isDhThread(), "Buffer uploading needs to be done on a DH thread to prevent locking up any MC threads.");
|
||||||
|
|
||||||
|
|
||||||
// upload on MC's render thread
|
// upload on MC's render thread
|
||||||
@@ -93,7 +100,7 @@ public class ColumnRenderBuffer implements AutoCloseable
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.uploadBuffersUsingUploadMethod(builder, gpuUploadMethod);
|
this.uploadBuffers(builder, gpuUploadMethod);
|
||||||
uploadFuture.complete(null);
|
uploadFuture.complete(null);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
@@ -119,163 +126,231 @@ public class ColumnRenderBuffer implements AutoCloseable
|
|||||||
//LOGGER.warn("Error uploading builder ["+builder+"] synchronously. Error: "+e.getMessage(), e);
|
//LOGGER.warn("Error uploading builder ["+builder+"] synchronously. Error: "+e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void uploadBuffersUsingUploadMethod(LodQuadBuilder builder, EDhApiGpuUploadMethod gpuUploadMethod) throws InterruptedException
|
private void uploadBuffers(LodQuadBuilder builder, EDhApiGpuUploadMethod method) throws InterruptedException
|
||||||
{
|
{
|
||||||
//if (gpuUploadMethod.useEarlyMapping)
|
// uploading mapped buffers used to be done here,
|
||||||
//{
|
// however due to a memory leak and complication with the previous code,
|
||||||
// this.uploadBuffersMapped(builder, gpuUploadMethod);
|
// now we only allow direct uploading.
|
||||||
//}
|
// (There's also insufficient data to state whether mapped buffers are necessary
|
||||||
//else
|
// for DH to upload without stuttering the main thread)
|
||||||
//{
|
|
||||||
this.uploadBuffersDirect(builder);
|
this.vbos = makeAndUploadBuffers(builder, method, this.vbos, builder.makeOpaqueVertexBuffers());
|
||||||
//}
|
this.vbosTransparent = makeAndUploadBuffers(builder, method, this.vbosTransparent, builder.makeTransparentVertexBuffers());
|
||||||
|
|
||||||
this.buffersUploaded = true;
|
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)
|
|
||||||
//{
|
|
||||||
// // opaque vbos //
|
|
||||||
//
|
|
||||||
// this.vbos = ColumnRenderBufferBuilder.resizeBuffer(this.vbos, builder.getCurrentNeededOpaqueVertexBufferCount());
|
|
||||||
// for (int i = 0; i < this.vbos.length; i++)
|
|
||||||
// {
|
|
||||||
// if (this.vbos[i] == null)
|
|
||||||
// {
|
|
||||||
// this.vbos[i] = new GLVertexBuffer(method.useBufferStorage);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// LodQuadBuilder.BufferFiller func = builder.makeOpaqueBufferFiller(method);
|
|
||||||
// for (GLVertexBuffer vbo : this.vbos)
|
|
||||||
// {
|
|
||||||
// func.fill(vbo);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// // 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 void uploadBuffersDirect(LodQuadBuilder builder)
|
|
||||||
{
|
{
|
||||||
int opaqueSliceCount = builder.getCurrentNeededOpaqueVertexBufferCount();
|
try
|
||||||
if (this.opaqueBufferSlices.length != opaqueSliceCount)
|
|
||||||
{
|
{
|
||||||
SharedVbo.OPAQUE.deallocate(this.opaqueBufferSlices);
|
vbos = resizeBuffer(vbos, buffers.size());
|
||||||
this.opaqueBufferSlices = new SharedVbo.BufferSlice[opaqueSliceCount];
|
uploadBuffersDirect(vbos, buffers, method);
|
||||||
}
|
}
|
||||||
uploadBuffersDirect(SharedVbo.OPAQUE, this.opaqueBufferSlices, builder.makeOpaqueVertexBuffers());
|
finally
|
||||||
|
|
||||||
|
|
||||||
int transparentSliceCount = builder.getCurrentNeededTransparentVertexBufferCount();
|
|
||||||
if (this.transparentBufferSlices.length != transparentSliceCount)
|
|
||||||
{
|
{
|
||||||
SharedVbo.TRANSPARENT.deallocate(this.transparentBufferSlices);
|
// all the buffers must be manually freed to prevent memory leaks
|
||||||
this.transparentBufferSlices = new SharedVbo.BufferSlice[transparentSliceCount];
|
if (buffers != null)
|
||||||
|
{
|
||||||
|
for (ByteBuffer buffer : buffers)
|
||||||
|
{
|
||||||
|
MemoryUtil.memFree(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
uploadBuffersDirect(SharedVbo.TRANSPARENT, this.transparentBufferSlices, builder.makeTransparentVertexBuffers());
|
|
||||||
|
// return the array in case it was resized
|
||||||
|
return vbos;
|
||||||
}
|
}
|
||||||
|
private static void uploadBuffersDirect(GLVertexBuffer[] vbos, ArrayList<ByteBuffer> byteBuffers, EDhApiGpuUploadMethod method) throws InterruptedException
|
||||||
private static void uploadBuffersDirect(SharedVbo handler, SharedVbo.BufferSlice[] bufferSlices, Iterator<ByteBuffer> iter)
|
|
||||||
{
|
{
|
||||||
int i = 0;
|
int vboIndex = 0;
|
||||||
while (iter.hasNext())
|
for (int i = 0; i < byteBuffers.size(); i++)
|
||||||
{
|
{
|
||||||
if (i >= bufferSlices.length)
|
if (vboIndex >= vbos.length)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Too many vertex buffers!!");
|
throw new RuntimeException("Too many vertex buffers!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// get or create the buffer
|
|
||||||
if (bufferSlices[i] == null)
|
// get or create the VBO
|
||||||
|
if (vbos[vboIndex] == null)
|
||||||
{
|
{
|
||||||
bufferSlices[i] = handler.allocateSlice();
|
vbos[vboIndex] = new GLVertexBuffer(method.useBufferStorage);
|
||||||
}
|
}
|
||||||
SharedVbo.BufferSlice slice = bufferSlices[i];
|
GLVertexBuffer vbo = vbos[vboIndex];
|
||||||
|
|
||||||
|
|
||||||
ByteBuffer buffer = iter.next();
|
ByteBuffer buffer = byteBuffers.get(i);
|
||||||
|
int size = buffer.limit() - buffer.position();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
handler.updateBuffer(slice, buffer);
|
vbo.bind();
|
||||||
|
vbo.uploadBuffer(buffer, size / LodUtil.LOD_VERTEX_FORMAT.getByteSize(), method, FULL_SIZED_BUFFER);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
bufferSlices[i] = null;
|
vbos[vboIndex] = null;
|
||||||
handler.deallocate(slice);
|
vbo.close();
|
||||||
LOGGER.error("Failed to upload buffer. Error: ["+e.getMessage()+"].", e);
|
LOGGER.error("Failed to upload buffer: ", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
vboIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i < bufferSlices.length)
|
if (vboIndex < vbos.length)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Too few buffer chunks!");
|
throw new RuntimeException("Too few vertex buffers!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//========//
|
//========//
|
||||||
// render //
|
// render //
|
||||||
//========//
|
//========//
|
||||||
|
|
||||||
//public void renderOpaque(LodRenderer renderContext, DhApiRenderParam renderEventParam)
|
/** @return true if something was rendered, false otherwise */
|
||||||
//{
|
public boolean renderOpaque(LodRenderer renderContext, DhApiRenderParam renderEventParam)
|
||||||
// renderContext.setModelViewMatrixOffset(this.pos, renderEventParam);
|
{
|
||||||
// renderContext.drawSharedVbo(SharedVbo.OPAQUE, this.opaqueBufferSlices);
|
boolean hasRendered = false;
|
||||||
//}
|
renderContext.setModelViewMatrixOffset(this.pos, renderEventParam);
|
||||||
//
|
for (GLVertexBuffer vbo : this.vbos)
|
||||||
//public void renderTransparent(LodRenderer renderContext, DhApiRenderParam renderEventParam)
|
{
|
||||||
//{
|
if (vbo == null)
|
||||||
// renderContext.setModelViewMatrixOffset(this.pos, renderEventParam);
|
{
|
||||||
// renderContext.drawSharedVbo(SharedVbo.TRANSPARENT, this.transparentBufferSlices);
|
continue;
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
if (vbo.getVertexCount() == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasRendered = true;
|
||||||
|
renderContext.drawVbo(vbo);
|
||||||
|
//LodRenderer.tickLogger.info("Vertex buffer: {}", vbo);
|
||||||
|
}
|
||||||
|
return hasRendered;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return true if something was rendered, false otherwise */
|
||||||
|
public boolean renderTransparent(LodRenderer renderContext, DhApiRenderParam renderEventParam)
|
||||||
|
{
|
||||||
|
boolean hasRendered = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// can throw an IllegalStateException if the GL program was freed before it should've been
|
||||||
|
renderContext.setModelViewMatrixOffset(this.pos, renderEventParam);
|
||||||
|
|
||||||
|
for (GLVertexBuffer vbo : this.vbosTransparent)
|
||||||
|
{
|
||||||
|
if (vbo == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vbo.getVertexCount() == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasRendered = true;
|
||||||
|
renderContext.drawVbo(vbo);
|
||||||
|
//LodRenderer.tickLogger.info("Vertex buffer: {}", vbo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IllegalStateException e)
|
||||||
|
{
|
||||||
|
LOGGER.error("renderContext program doesn't exist for pos: "+this.pos, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasRendered;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==============//
|
//================//
|
||||||
// misc methods //
|
// helper methods //
|
||||||
//==============//
|
//================//
|
||||||
|
|
||||||
// TODO
|
|
||||||
/** can be used when debugging */
|
|
||||||
public boolean hasNonNullVbos() { return false; } //this.vbos != null || this.vbosTransparent != null; }
|
|
||||||
|
|
||||||
/** can be used when debugging */
|
/** can be used when debugging */
|
||||||
public int bufferSliceCount()
|
public boolean hasNonNullVbos() { return this.vbos != null || this.vbosTransparent != null; }
|
||||||
|
|
||||||
|
/** can be used when debugging */
|
||||||
|
public int vboBufferCount()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (this.opaqueBufferSlices != null)
|
if (this.vbos != null)
|
||||||
{
|
{
|
||||||
count += this.opaqueBufferSlices.length;
|
count += this.vbos.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.transparentBufferSlices != null)
|
if (this.vbosTransparent != null)
|
||||||
{
|
{
|
||||||
count += this.transparentBufferSlices.length;
|
count += this.vbosTransparent.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void debugDumpStats(StatsMap statsMap)
|
||||||
|
{
|
||||||
|
statsMap.incStat("RenderBuffers");
|
||||||
|
statsMap.incStat("SimpleRenderBuffers");
|
||||||
|
for (GLVertexBuffer vertexBuffer : vbos)
|
||||||
|
{
|
||||||
|
if (vertexBuffer != null)
|
||||||
|
{
|
||||||
|
statsMap.incStat("VBOs");
|
||||||
|
if (vertexBuffer.getSize() == FULL_SIZED_BUFFER)
|
||||||
|
{
|
||||||
|
statsMap.incStat("FullsizedVBOs");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vertexBuffer.getSize() == 0)
|
||||||
|
{
|
||||||
|
GLProxy.GL_LOGGER.warn("VBO with size 0");
|
||||||
|
}
|
||||||
|
statsMap.incBytesStat("TotalUsage", vertexBuffer.getSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.
|
* This method is called when object is no longer in use.
|
||||||
* Called either after uploadBuffers() returned false (On buffer Upload
|
* Called either after uploadBuffers() returned false (On buffer Upload
|
||||||
@@ -287,8 +362,24 @@ public class ColumnRenderBuffer implements AutoCloseable
|
|||||||
{
|
{
|
||||||
this.buffersUploaded = false;
|
this.buffersUploaded = false;
|
||||||
|
|
||||||
SharedVbo.OPAQUE.deallocate(this.opaqueBufferSlices);
|
GLProxy.getInstance().queueRunningOnRenderThread(() ->
|
||||||
SharedVbo.TRANSPARENT.deallocate(this.transparentBufferSlices);
|
{
|
||||||
|
for (GLVertexBuffer buffer : this.vbos)
|
||||||
|
{
|
||||||
|
if (buffer != null)
|
||||||
|
{
|
||||||
|
buffer.destroyAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (GLVertexBuffer buffer : this.vbosTransparent)
|
||||||
|
{
|
||||||
|
if (buffer != null)
|
||||||
|
{
|
||||||
|
buffer.destroyAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+313
-127
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding;
|
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.api.enums.rendering.EDhApiDebugRendering;
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
@@ -26,15 +27,16 @@ import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
|||||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
||||||
import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException;
|
import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
||||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
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.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -59,21 +61,21 @@ public class ColumnRenderBufferBuilder
|
|||||||
// vbo building //
|
// vbo building //
|
||||||
//==============//
|
//==============//
|
||||||
|
|
||||||
public static CompletableFuture<ColumnRenderBuffer> buildAndUploadBuffersAsync(
|
public static CompletableFuture<LodQuadBuilder> buildBuffersAsync(
|
||||||
IDhClientLevel clientLevel,
|
IDhClientLevel clientLevel,
|
||||||
ColumnRenderSource renderSource, ColumnRenderSource[] adjData)
|
ColumnRenderSource renderSource, ColumnRenderSource[] adjData, boolean[] isSameDetailLevel
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ThreadPoolExecutor bufferBuilderExecutor = ThreadPoolUtil.getBufferBuilderExecutor();
|
ThreadPoolExecutor bufferBuilderExecutor = ThreadPoolUtil.getBufferBuilderExecutor();
|
||||||
ThreadPoolExecutor bufferUploaderExecutor = ThreadPoolUtil.getBufferUploaderExecutor();
|
if (bufferBuilderExecutor == null || bufferBuilderExecutor.isTerminated())
|
||||||
if ((bufferBuilderExecutor == null || bufferBuilderExecutor.isTerminated()) ||
|
|
||||||
(bufferUploaderExecutor == null || bufferUploaderExecutor.isTerminated()))
|
|
||||||
{
|
{
|
||||||
// one or more of the thread pools has been shut down
|
// one or more of the thread pools has been shut down
|
||||||
CompletableFuture<ColumnRenderBuffer> future = new CompletableFuture<>();
|
CompletableFuture<LodQuadBuilder> future = new CompletableFuture<>();
|
||||||
future.cancel(true);
|
future.cancel(true);
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return CompletableFuture.supplyAsync(() ->
|
return CompletableFuture.supplyAsync(() ->
|
||||||
@@ -81,35 +83,8 @@ public class ColumnRenderBufferBuilder
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
boolean enableTransparency = Config.Client.Advanced.Graphics.Quality.transparency.get().transparencyEnabled;
|
boolean enableTransparency = Config.Client.Advanced.Graphics.Quality.transparency.get().transparencyEnabled;
|
||||||
|
LodQuadBuilder builder = new LodQuadBuilder(enableTransparency, clientLevel.getClientLevelWrapper());
|
||||||
//EVENT_LOGGER.trace("RenderRegion start QuadBuild @ " + renderSource.sectionPos);
|
makeLodRenderData(builder, renderSource, clientLevel, adjData, isSameDetailLevel);
|
||||||
boolean enableSkyLightCulling =
|
|
||||||
Config.Client.Advanced.Graphics.AdvancedGraphics.enableCaveCulling.get()
|
|
||||||
&& (
|
|
||||||
// dimensions with a ceiling will be all caves so we don't want cave culling
|
|
||||||
!clientLevel.getLevelWrapper().hasCeiling()
|
|
||||||
// the end has a lot of overhangs with 0 lighting above the void, which look broken with
|
|
||||||
// the current cave culling logic (this could probably be improved, but just skipping it works best for now)
|
|
||||||
&& !clientLevel.getLevelWrapper().getDimensionType().isTheEnd()
|
|
||||||
// FIXME temporary fix
|
|
||||||
// Cave culling is currently broken for any detail level above 0
|
|
||||||
&& DhSectionPos.getDetailLevel(renderSource.pos) == DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL
|
|
||||||
);
|
|
||||||
|
|
||||||
int skyLightCullingBelow = Config.Client.Advanced.Graphics.AdvancedGraphics.caveCullingHeight.get();
|
|
||||||
// FIXME: Clamp also to the max world height.
|
|
||||||
skyLightCullingBelow = Math.max(skyLightCullingBelow, clientLevel.getMinY());
|
|
||||||
|
|
||||||
|
|
||||||
long builderStartTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
LodQuadBuilder builder = new LodQuadBuilder(enableSkyLightCulling, (short) (skyLightCullingBelow - clientLevel.getMinY()), enableTransparency, clientLevel.getClientLevelWrapper());
|
|
||||||
makeLodRenderData(builder, renderSource, adjData);
|
|
||||||
|
|
||||||
long builderEndTime = System.currentTimeMillis();
|
|
||||||
long buildMs = builderEndTime - builderStartTime;
|
|
||||||
LOGGER.debug("RenderRegion end QuadBuild @ " + renderSource.pos + " took: " + buildMs);
|
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
catch (UncheckedInterruptedException e)
|
catch (UncheckedInterruptedException e)
|
||||||
@@ -118,11 +93,42 @@ public class ColumnRenderBufferBuilder
|
|||||||
}
|
}
|
||||||
catch (Throwable e3)
|
catch (Throwable e3)
|
||||||
{
|
{
|
||||||
LOGGER.error("\"LodNodeBufferBuilder\" was unable to build quads: ", e3);
|
LOGGER.error("LodNodeBufferBuilder was unable to build quads for pos ["+DhSectionPos.toString(renderSource.pos)+"], error: ["+ e3.getMessage()+"].", e3);
|
||||||
throw e3;
|
throw e3;
|
||||||
}
|
}
|
||||||
}, bufferBuilderExecutor)
|
}, bufferBuilderExecutor);
|
||||||
.thenApplyAsync((quadBuilder) ->
|
}
|
||||||
|
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(() ->
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -130,8 +136,15 @@ public class ColumnRenderBufferBuilder
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
buffer.uploadBuffer(quadBuilder, GLProxy.getInstance().getGpuUploadMethod());
|
buffer.uploadBuffer(quadBuilder, GLProxy.getInstance().getGpuUploadMethod());
|
||||||
LodUtil.assertTrue(buffer.buffersUploaded);
|
if (buffer.buffersUploaded)
|
||||||
return buffer;
|
{
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer.close();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -145,35 +158,38 @@ public class ColumnRenderBufferBuilder
|
|||||||
}
|
}
|
||||||
catch (Throwable e3)
|
catch (Throwable e3)
|
||||||
{
|
{
|
||||||
LOGGER.error("LodNodeBufferBuilder was unable to upload buffer: " + e3.getMessage(), e3);
|
LOGGER.error("LodNodeBufferBuilder was unable to upload buffer for pos ["+DhSectionPos.toString(renderSource.pos)+"], error: [" + e3.getMessage() + "].", e3);
|
||||||
throw e3;
|
throw e3;
|
||||||
}
|
}
|
||||||
}, bufferUploaderExecutor);
|
}, bufferUploaderExecutor);
|
||||||
}
|
}
|
||||||
catch (RejectedExecutionException ignore)
|
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
|
// shouldn't happen, but just in case
|
||||||
|
|
||||||
CompletableFuture<ColumnRenderBuffer> future = new CompletableFuture<>();
|
CompletableFuture<ColumnRenderBuffer> future = new CompletableFuture<>();
|
||||||
future.cancel(true);
|
future.cancel(true);
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void makeLodRenderData(LodQuadBuilder quadBuilder, ColumnRenderSource renderSource, ColumnRenderSource[] adjRegions)
|
private static void makeLodRenderData(
|
||||||
|
LodQuadBuilder quadBuilder, ColumnRenderSource renderSource, IDhClientLevel clientLevel,
|
||||||
|
ColumnRenderSource[] adjRegions, boolean[] isSameDetailLevel)
|
||||||
{
|
{
|
||||||
// Variable initialization
|
//=============//
|
||||||
EDhApiDebugRendering debugMode = Config.Client.Advanced.Debugging.debugRendering.get();
|
// debug check //
|
||||||
|
//=============//
|
||||||
|
|
||||||
// can be used to limit which section positions are build and thus, rendered
|
// can be used to limit which section positions are build and thus, rendered
|
||||||
// useful when debugging a specific section
|
// useful when debugging a specific section
|
||||||
boolean enableColumnBufferLimit = Config.Client.Advanced.Debugging.columnBuilderDebugEnable.get();
|
boolean columnBuilderDebugEnabled = Config.Client.Advanced.Debugging.columnBuilderDebugEnable.get();
|
||||||
if (enableColumnBufferLimit)
|
if (columnBuilderDebugEnabled)
|
||||||
{
|
{
|
||||||
if (DhSectionPos.getDetailLevel(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugDetailLevel.get()
|
if (DhSectionPos.getDetailLevel(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugDetailLevel.get()
|
||||||
&& DhSectionPos.getX(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugXPos.get()
|
&& DhSectionPos.getX(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugXPos.get()
|
||||||
&& DhSectionPos.getZ(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugZPos.get())
|
&& DhSectionPos.getZ(renderSource.pos) == Config.Client.Advanced.Debugging.columnBuilderDebugZPos.get())
|
||||||
{
|
{
|
||||||
int test = 0;
|
int breakpoint = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -181,24 +197,22 @@ public class ColumnRenderBufferBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte detailLevel = renderSource.getDataDetailLevel();
|
|
||||||
for (int x = 0; x < ColumnRenderSource.SECTION_SIZE; x++)
|
|
||||||
|
//===================//
|
||||||
|
// build each column //
|
||||||
|
//===================//
|
||||||
|
|
||||||
|
byte thisDetailLevel = renderSource.getDataDetailLevel();
|
||||||
|
for (int relX = 0; relX < ColumnRenderSource.SECTION_SIZE; relX++)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < ColumnRenderSource.SECTION_SIZE; z++)
|
for (int relZ = 0; relZ < ColumnRenderSource.SECTION_SIZE; relZ++)
|
||||||
{
|
{
|
||||||
// TODO make a config for this
|
// stop the builder if requested
|
||||||
// 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();
|
UncheckedInterruptedException.throwIfInterrupted();
|
||||||
|
|
||||||
ColumnArrayView columnRenderData = renderSource.getVerticalDataPointView(x, z);
|
// ignore empty/null columns
|
||||||
|
ColumnArrayView columnRenderData = renderSource.getVerticalDataPointView(relX, relZ);
|
||||||
if (columnRenderData.size() == 0
|
if (columnRenderData.size() == 0
|
||||||
|| !RenderDataPointUtil.doesDataPointExist(columnRenderData.get(0))
|
|| !RenderDataPointUtil.doesDataPointExist(columnRenderData.get(0))
|
||||||
|| RenderDataPointUtil.isVoid(columnRenderData.get(0)))
|
|| RenderDataPointUtil.isVoid(columnRenderData.get(0)))
|
||||||
@@ -206,43 +220,66 @@ public class ColumnRenderBufferBuilder
|
|||||||
continue;
|
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);
|
|
||||||
|
|
||||||
|
|
||||||
// We check every adj block in each direction
|
//=============//
|
||||||
|
// debug limit //
|
||||||
|
//=============//
|
||||||
|
|
||||||
// If the adj block is rendered in the same region and with same detail
|
// can be used to limit the buffer building to a specific relative position.
|
||||||
// and is positioned in a place that is not going to be rendered by vanilla game
|
// useful for debugging a single column
|
||||||
// then we can set this position as adj
|
if (columnBuilderDebugEnabled)
|
||||||
// We avoid cases where the adjPosition is in player chunk while the position is
|
{
|
||||||
// not
|
int wantedX = Config.Client.Advanced.Debugging.columnBuilderDebugXRow.get();
|
||||||
// to always have a wall underwater
|
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];
|
||||||
for (EDhDirection lodDirection : EDhDirection.ADJ_DIRECTIONS)
|
for (EDhDirection lodDirection : EDhDirection.ADJ_DIRECTIONS)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int xAdj = x + lodDirection.getNormal().x;
|
int xAdj = relX + lodDirection.getNormal().x;
|
||||||
int zAdj = z + lodDirection.getNormal().z;
|
int zAdj = relZ + lodDirection.getNormal().z;
|
||||||
boolean isCrossRegionBoundary =
|
boolean isCrossRenderSourceBoundary =
|
||||||
(xAdj < 0 || xAdj >= ColumnRenderSource.SECTION_SIZE) ||
|
(xAdj < 0 || xAdj >= ColumnRenderSource.SECTION_SIZE) ||
|
||||||
(zAdj < 0 || zAdj >= ColumnRenderSource.SECTION_SIZE);
|
(zAdj < 0 || zAdj >= ColumnRenderSource.SECTION_SIZE);
|
||||||
|
|
||||||
ColumnRenderSource adjRenderSource;
|
ColumnRenderSource adjRenderSource;
|
||||||
byte adjDetailLevel;
|
byte adjDetailLevel;
|
||||||
|
|
||||||
//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)
|
//=========================//
|
||||||
|
// get the adjacent render //
|
||||||
|
// source if present //
|
||||||
|
//=========================//
|
||||||
|
|
||||||
|
if (!isCrossRenderSourceBoundary)
|
||||||
{
|
{
|
||||||
//we compute at which detail that position should be rendered
|
// 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
|
||||||
adjRenderSource = adjRegions[lodDirection.ordinal() - 2];
|
adjRenderSource = adjRegions[lodDirection.ordinal() - 2];
|
||||||
if (adjRenderSource == null)
|
if (adjRenderSource == null)
|
||||||
{
|
{
|
||||||
@@ -250,67 +287,70 @@ public class ColumnRenderBufferBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
adjDetailLevel = adjRenderSource.getDataDetailLevel();
|
adjDetailLevel = adjRenderSource.getDataDetailLevel();
|
||||||
if (adjDetailLevel != detailLevel)
|
if (adjDetailLevel == thisDetailLevel)
|
||||||
{
|
|
||||||
//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)
|
if (xAdj < 0)
|
||||||
|
{
|
||||||
xAdj += ColumnRenderSource.SECTION_SIZE;
|
xAdj += ColumnRenderSource.SECTION_SIZE;
|
||||||
|
}
|
||||||
|
if (xAdj >= ColumnRenderSource.SECTION_SIZE)
|
||||||
|
{
|
||||||
|
xAdj -= ColumnRenderSource.SECTION_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
if (zAdj < 0)
|
if (zAdj < 0)
|
||||||
|
{
|
||||||
zAdj += ColumnRenderSource.SECTION_SIZE;
|
zAdj += ColumnRenderSource.SECTION_SIZE;
|
||||||
|
}
|
||||||
if (xAdj >= ColumnRenderSource.SECTION_SIZE)
|
|
||||||
xAdj -= ColumnRenderSource.SECTION_SIZE;
|
|
||||||
|
|
||||||
if (zAdj >= ColumnRenderSource.SECTION_SIZE)
|
if (zAdj >= ColumnRenderSource.SECTION_SIZE)
|
||||||
|
{
|
||||||
zAdj -= ColumnRenderSource.SECTION_SIZE;
|
zAdj -= ColumnRenderSource.SECTION_SIZE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
adjRenderSource = renderSource;
|
|
||||||
adjDetailLevel = detailLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (adjDetailLevel < detailLevel - 1 || adjDetailLevel > detailLevel + 1)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (adjDetailLevel == detailLevel || adjDetailLevel > detailLevel)
|
|
||||||
{
|
//========================//
|
||||||
adjColumnViews[lodDirection.ordinal() - 2] = new ColumnArrayView[1];
|
// get the adjacent views //
|
||||||
adjColumnViews[lodDirection.ordinal() - 2][0] = adjRenderSource.getVerticalDataPointView(xAdj, zAdj);
|
//========================//
|
||||||
}
|
|
||||||
else
|
// the old logic handled additional cases, but they never appeared to fire,
|
||||||
{
|
// so just these two cases should be fine
|
||||||
adjColumnViews[lodDirection.ordinal() - 2] = new ColumnArrayView[2];
|
LodUtil.assertTrue(adjDetailLevel == thisDetailLevel || adjDetailLevel > thisDetailLevel);
|
||||||
adjColumnViews[lodDirection.ordinal() - 2][0] = adjRenderSource.getVerticalDataPointView(xAdj, zAdj);
|
|
||||||
adjColumnViews[lodDirection.ordinal() - 2][1] = adjRenderSource.getVerticalDataPointView(
|
adjColumnViews[lodDirection.ordinal() - 2] = adjRenderSource.getVerticalDataPointView(xAdj, zAdj);
|
||||||
xAdj + (lodDirection.getAxis() == EDhDirection.Axis.X ? 0 : 1),
|
|
||||||
zAdj + (lodDirection.getAxis() == EDhDirection.Axis.Z ? 0 : 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (RuntimeException e)
|
catch (RuntimeException e)
|
||||||
{
|
{
|
||||||
EVENT_LOGGER.warn("Failed to get adj data for [" + detailLevel + ":" + x + "," + z + "] at [" + lodDirection + "], Error: "+e.getMessage(), e);
|
EVENT_LOGGER.warn("Failed to get adj data for relative pos: [" + thisDetailLevel + ":" + relX + "," + relZ + "] at [" + lodDirection + "], Error: "+e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} // for adjacent directions
|
} // for adjacent directions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==========================//
|
||||||
|
// build this render column //
|
||||||
|
//==========================//
|
||||||
|
|
||||||
|
ColumnRenderSource.DebugSourceFlag debugSourceFlag = renderSource.debugGetFlag(relX, relZ);
|
||||||
|
|
||||||
// We render every vertical lod present in this position
|
// We render every vertical lod present in this position
|
||||||
// We only stop when we find a block that is void or non-existing block
|
// We only stop when we find a block that is void or non-existing block
|
||||||
for (int i = 0; i < columnRenderData.size(); i++)
|
for (int i = 0; i < columnRenderData.size(); i++)
|
||||||
{
|
{
|
||||||
// TODO make a config for this
|
|
||||||
// can be uncommented to limit which vertical LOD is generated
|
// can be uncommented to limit which vertical LOD is generated
|
||||||
// if (i != 0)
|
if (Config.Client.Advanced.Debugging.columnBuilderDebugEnable.get())
|
||||||
// {
|
{
|
||||||
// continue;
|
int wantedColumnIndex = Config.Client.Advanced.Debugging.columnBuilderDebugColumnIndex.get();
|
||||||
// }
|
if (wantedColumnIndex >= 0 && i != wantedColumnIndex)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long data = columnRenderData.get(i);
|
long data = columnRenderData.get(i);
|
||||||
// If the data is not render-able (Void or non-existing) we stop since there is
|
// If the data is not render-able (Void or non-existing) we stop since there is
|
||||||
@@ -323,8 +363,12 @@ public class ColumnRenderBufferBuilder
|
|||||||
long topDataPoint = (i - 1) >= 0 ? columnRenderData.get(i - 1) : RenderDataPointUtil.EMPTY_DATA;
|
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;
|
long bottomDataPoint = (i + 1) < columnRenderData.size() ? columnRenderData.get(i + 1) : RenderDataPointUtil.EMPTY_DATA;
|
||||||
|
|
||||||
CubicLodTemplate.addLodToBuffer(data, topDataPoint, bottomDataPoint, adjColumnViews, detailLevel,
|
addLodToBuffer(
|
||||||
x, z, quadBuilder, debugMode, debugSourceFlag);
|
clientLevel,
|
||||||
|
data, topDataPoint, bottomDataPoint,
|
||||||
|
adjColumnViews, isSameDetailLevel,
|
||||||
|
thisDetailLevel, relX, relZ,
|
||||||
|
quadBuilder, debugSourceFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}// for z
|
}// for z
|
||||||
@@ -332,5 +376,147 @@ public class ColumnRenderBufferBuilder
|
|||||||
|
|
||||||
quadBuilder.finalizeData();
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
EDhApiDebugRendering debugging = Config.Client.Advanced.Debugging.debugRendering.get();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-186
@@ -1,186 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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:
|
|
||||||
{
|
|
||||||
|
|
||||||
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, // 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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+124
-413
@@ -38,8 +38,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftCli
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||||
import org.apache.logging.log4j.Logger;
|
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>
|
* Used to create the quads before they are converted to render-able buffers. <br><br>
|
||||||
@@ -51,9 +50,6 @@ public class LodQuadBuilder
|
|||||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||||
|
|
||||||
public final boolean skipQuadsWithZeroSkylight;
|
|
||||||
public final short skyLightCullingBelow;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private final ArrayList<BufferQuad>[] opaqueQuads = (ArrayList<BufferQuad>[]) new ArrayList[6];
|
private final ArrayList<BufferQuad>[] opaqueQuads = (ArrayList<BufferQuad>[]) new ArrayList[6];
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -123,7 +119,7 @@ public class LodQuadBuilder
|
|||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
|
||||||
public LodQuadBuilder(boolean enableSkylightCulling, short skyLightCullingBelow, boolean doTransparency, IClientLevelWrapper clientLevelWrapper)
|
public LodQuadBuilder(boolean doTransparency, IClientLevelWrapper clientLevelWrapper)
|
||||||
{
|
{
|
||||||
this.doTransparency = doTransparency;
|
this.doTransparency = doTransparency;
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
@@ -132,8 +128,6 @@ public class LodQuadBuilder
|
|||||||
this.transparentQuads[i] = new ArrayList<>();
|
this.transparentQuads[i] = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.skipQuadsWithZeroSkylight = enableSkylightCulling;
|
|
||||||
this.skyLightCullingBelow = skyLightCullingBelow;
|
|
||||||
this.clientLevelWrapper = clientLevelWrapper;
|
this.clientLevelWrapper = clientLevelWrapper;
|
||||||
|
|
||||||
this.debugRenderingMode = Config.Client.Advanced.Debugging.debugRendering.get();
|
this.debugRenderingMode = Config.Client.Advanced.Debugging.debugRendering.get();
|
||||||
@@ -157,11 +151,6 @@ public class LodQuadBuilder
|
|||||||
throw new IllegalArgumentException("addQuadAdj() is only for adj direction! Not UP or Down!");
|
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);
|
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()];
|
ArrayList<BufferQuad> quadList = (this.doTransparency && ColorUtil.getAlpha(color) < 255) ? this.transparentQuads[dir.ordinal()] : this.opaqueQuads[dir.ordinal()];
|
||||||
if (!quadList.isEmpty() &&
|
if (!quadList.isEmpty() &&
|
||||||
@@ -180,12 +169,6 @@ public class LodQuadBuilder
|
|||||||
// XZ
|
// 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
|
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);
|
BufferQuad quad = new BufferQuad(x, maxY, z, widthEastWest, widthNorthSouthOrUpDown, color, irisBlockMaterialId, skylight, blocklight, EDhDirection.UP);
|
||||||
boolean isTransparent = (this.doTransparency && ColorUtil.getAlpha(color) < 255);
|
boolean isTransparent = (this.doTransparency && ColorUtil.getAlpha(color) < 255);
|
||||||
ArrayList<BufferQuad> quadList = isTransparent ? this.transparentQuads[EDhDirection.UP.ordinal()] : this.opaqueQuads[EDhDirection.UP.ordinal()];
|
ArrayList<BufferQuad> quadList = isTransparent ? this.transparentQuads[EDhDirection.UP.ordinal()] : this.opaqueQuads[EDhDirection.UP.ordinal()];
|
||||||
@@ -207,15 +190,13 @@ public class LodQuadBuilder
|
|||||||
|
|
||||||
public void addQuadDown(short x, short y, short z, short width, short wz, int color, byte irisBlockMaterialId, byte skylight, byte blocklight)
|
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);
|
BufferQuad quad = new BufferQuad(x, y, z, width, wz, color, irisBlockMaterialId, skylight, blocklight, EDhDirection.DOWN);
|
||||||
ArrayList<BufferQuad> qs = (doTransparency && ColorUtil.getAlpha(color) < 255)
|
ArrayList<BufferQuad> qs = (doTransparency && ColorUtil.getAlpha(color) < 255)
|
||||||
? transparentQuads[EDhDirection.DOWN.ordinal()] : opaqueQuads[EDhDirection.DOWN.ordinal()];
|
? transparentQuads[EDhDirection.DOWN.ordinal()] : opaqueQuads[EDhDirection.DOWN.ordinal()];
|
||||||
if (!qs.isEmpty() &&
|
if (!qs.isEmpty()
|
||||||
(qs.get(qs.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.EastWest)
|
&& (qs.get(qs.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.EastWest)
|
||||||
|| qs.get(qs.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown))
|
|| qs.get(qs.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
premergeCount++;
|
premergeCount++;
|
||||||
return;
|
return;
|
||||||
@@ -225,10 +206,124 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==============//
|
//==============//
|
||||||
// add vertices //
|
// buffer setup //
|
||||||
//==============//
|
//==============//
|
||||||
|
|
||||||
|
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)
|
private void putQuad(ByteBuffer bb, BufferQuad quad)
|
||||||
{
|
{
|
||||||
int[][] quadBase = DIRECTION_VERTEX_IBO_QUAD[quad.direction.ordinal()];
|
int[][] quadBase = DIRECTION_VERTEX_IBO_QUAD[quad.direction.ordinal()];
|
||||||
@@ -286,10 +381,10 @@ public class LodQuadBuilder
|
|||||||
if (quad.direction.getAxis().isHorizontal() || quad.direction == EDhDirection.DOWN)
|
if (quad.direction.getAxis().isHorizontal() || quad.direction == EDhDirection.DOWN)
|
||||||
{
|
{
|
||||||
if (this.grassSideRenderingMode == EDhApiGrassSideRendering.AS_DIRT
|
if (this.grassSideRenderingMode == EDhApiGrassSideRendering.AS_DIRT
|
||||||
// if we want the color to fade, only apply the dirt color to the bottom vertices
|
// 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)
|
|| (this.grassSideRenderingMode == EDhApiGrassSideRendering.FADE_TO_DIRT && quadBase[i][1] == 0)
|
||||||
// always render the bottom as dirt
|
// always render the bottom as dirt
|
||||||
|| quad.direction == EDhDirection.DOWN)
|
|| quad.direction == EDhDirection.DOWN)
|
||||||
{
|
{
|
||||||
// for horizontal and bottom faces of grass blocks, use the dirt color to
|
// for horizontal and bottom faces of grass blocks, use the dirt color to
|
||||||
// prevent green cliff walls
|
// prevent green cliff walls
|
||||||
@@ -311,7 +406,6 @@ public class LodQuadBuilder
|
|||||||
mx, my, mz);
|
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)
|
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;
|
skylight %= 16;
|
||||||
@@ -352,389 +446,6 @@ 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<ByteBuffer>()
|
|
||||||
{
|
|
||||||
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<ByteBuffer>()
|
|
||||||
{
|
|
||||||
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 //
|
// getters //
|
||||||
//=========//
|
//=========//
|
||||||
|
|||||||
-188
@@ -1,188 +0,0 @@
|
|||||||
package com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding;
|
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
|
||||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
|
||||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
|
||||||
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.lwjgl.opengl.GL32;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/** Used to allow multiple {@link ColumnRenderBuffer}'s to be put in a single VBO. */
|
|
||||||
public class SharedVbo
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
|
||||||
|
|
||||||
public static final SharedVbo OPAQUE = new SharedVbo(2_000_000_000L/*1GB*/, 1024 * 1024/*1MB*/);
|
|
||||||
public static final SharedVbo TRANSPARENT = new SharedVbo(2_000_000_000L/*1GB*/, 1024 * 1024/*1MB*/);
|
|
||||||
|
|
||||||
|
|
||||||
public final int vboId;
|
|
||||||
|
|
||||||
|
|
||||||
private final long bufferTotalByteSize;
|
|
||||||
/** the length of a single chunk of this VBO in bytes. */
|
|
||||||
private final int chunkByteSize;
|
|
||||||
|
|
||||||
private final ConcurrentHashMap<Long, BufferSlice> bufferSliceByStartingIndex = new ConcurrentHashMap<>();
|
|
||||||
private long nextMemoryAddress = 0L;
|
|
||||||
private final Queue<BufferSlice> availableSlices = new ArrayDeque<>();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
|
||||||
// constructor //
|
|
||||||
//=============//
|
|
||||||
|
|
||||||
public SharedVbo(long totalSize, int chunkByteSize)
|
|
||||||
{
|
|
||||||
LodUtil.assertTrue(GLProxy.getInstance().runningOnRenderThread(), "Buffer Handler has to be created on the render thread.");
|
|
||||||
|
|
||||||
this.bufferTotalByteSize = totalSize;
|
|
||||||
this.chunkByteSize = chunkByteSize;
|
|
||||||
|
|
||||||
// Generate and bind the VBO
|
|
||||||
this.vboId = GL32.glGenBuffers();
|
|
||||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.vboId);
|
|
||||||
GL32.glBufferData(GL32.GL_ARRAY_BUFFER, this.bufferTotalByteSize, GL32.GL_DYNAMIC_DRAW);
|
|
||||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//============//
|
|
||||||
// allocation //
|
|
||||||
//============//
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public SharedVbo.BufferSlice allocateSlice()
|
|
||||||
{
|
|
||||||
BufferSlice availableSlice = this.availableSlices.poll();
|
|
||||||
if (availableSlice != null)
|
|
||||||
{
|
|
||||||
return availableSlice;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the first free chunk
|
|
||||||
for (long startingIndex = this.nextMemoryAddress; startingIndex < this.bufferTotalByteSize; startingIndex += this.chunkByteSize)
|
|
||||||
{
|
|
||||||
// check if this section is free
|
|
||||||
BufferSlice newSlice = new BufferSlice(startingIndex, this.chunkByteSize);
|
|
||||||
if (this.bufferSliceByStartingIndex.putIfAbsent(startingIndex, newSlice) == null)
|
|
||||||
{
|
|
||||||
this.nextMemoryAddress = startingIndex;
|
|
||||||
return newSlice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null; // No free chunk found
|
|
||||||
}
|
|
||||||
public void deallocate(BufferSlice[] slices)
|
|
||||||
{
|
|
||||||
if (slices != null)
|
|
||||||
{
|
|
||||||
for (BufferSlice slice : slices)
|
|
||||||
{
|
|
||||||
if (slice != null)
|
|
||||||
{
|
|
||||||
this.bufferSliceByStartingIndex.remove(slice.startIndex);
|
|
||||||
this.availableSlices.add(slice);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void deallocate(BufferSlice slice)
|
|
||||||
{
|
|
||||||
if (slice != null)
|
|
||||||
{
|
|
||||||
this.bufferSliceByStartingIndex.remove(slice.startIndex);
|
|
||||||
this.availableSlices.add(slice);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void clear()
|
|
||||||
{
|
|
||||||
this.bufferSliceByStartingIndex.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=================//
|
|
||||||
// buffer handling //
|
|
||||||
//=================//
|
|
||||||
|
|
||||||
public void updateBuffer(BufferSlice chunk, ByteBuffer buffer)
|
|
||||||
{
|
|
||||||
int size = buffer.limit() - buffer.position();
|
|
||||||
if (size > chunk.length)
|
|
||||||
{
|
|
||||||
// if this was fired that means we didn't split up the buffer into the right size
|
|
||||||
// if this isn't stopped the buffer will overwrite an adjacent section and cause incorrect rendering
|
|
||||||
throw new RuntimeException("Programmer error: Uploaded buffer bigger than the allocated area. Allocated: ["+chunk.length+"], buffer: ["+size+"]");
|
|
||||||
}
|
|
||||||
|
|
||||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.vboId);
|
|
||||||
GL32.glBufferSubData(GL32.GL_ARRAY_BUFFER, chunk.startIndex, buffer);
|
|
||||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, 0);
|
|
||||||
chunk.vertexCount = size / LodUtil.LOD_VERTEX_FORMAT.getByteSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void bind() { GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.vboId); }
|
|
||||||
public void unbind() { GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, 0); }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=======//
|
|
||||||
// debug //
|
|
||||||
//=======//
|
|
||||||
|
|
||||||
public String getDebugMenuString()
|
|
||||||
{
|
|
||||||
long maxChunkCount = (this.bufferTotalByteSize / this.chunkByteSize);
|
|
||||||
long chunkCount = 0;
|
|
||||||
long allocatedBytes = 0;
|
|
||||||
|
|
||||||
for (BufferSlice slice : this.bufferSliceByStartingIndex.values())
|
|
||||||
{
|
|
||||||
allocatedBytes += slice.length;
|
|
||||||
chunkCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Slices: ["+F3Screen.NUMBER_FORMAT.format(chunkCount)+"/"+F3Screen.NUMBER_FORMAT.format(maxChunkCount)+"], " +
|
|
||||||
"Mem: ["+StringUtil.convertByteCountToHumanReadableSI(allocatedBytes)+"/"+StringUtil.convertByteCountToHumanReadableSI(this.bufferTotalByteSize)+"]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//================//
|
|
||||||
// helper classes //
|
|
||||||
//================//
|
|
||||||
|
|
||||||
/** represents a single allocated slice of the parent VBO */
|
|
||||||
public static class BufferSlice
|
|
||||||
{
|
|
||||||
public final long startIndex;
|
|
||||||
public final int length;
|
|
||||||
|
|
||||||
public int vertexCount;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
|
||||||
// constructor //
|
|
||||||
//=============//
|
|
||||||
|
|
||||||
public BufferSlice(long startIndex, int length)
|
|
||||||
{
|
|
||||||
this.startIndex = startIndex;
|
|
||||||
this.length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+49
-22
@@ -20,6 +20,7 @@
|
|||||||
package com.seibel.distanthorizons.core.dataObjects.render.columnViews;
|
package com.seibel.distanthorizons.core.dataObjects.render.columnViews;
|
||||||
|
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
||||||
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
|
||||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||||
|
|
||||||
@@ -28,41 +29,60 @@ import java.util.Arrays;
|
|||||||
public final class ColumnArrayView implements IColumnDataView
|
public final class ColumnArrayView implements IColumnDataView
|
||||||
{
|
{
|
||||||
public final LongArrayList data;
|
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;
|
public final int size;
|
||||||
public final int offset; // offset in longs
|
/**
|
||||||
/** can be 0 if this column was created for an empty data source */
|
* Vertical size in data points. <Br>
|
||||||
public final int vertSize; // vertical size in longs
|
* 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 ColumnArrayView(LongArrayList data, int size, int offset, int vertSize)
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
|
||||||
|
public ColumnArrayView(LongArrayList data, int size, int offset, int verticalSize)
|
||||||
{
|
{
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.vertSize = vertSize;
|
this.verticalSize = verticalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=====================//
|
||||||
|
// getters and setters //
|
||||||
|
//=====================//
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long get(int index) { return data.getLong(index + offset); }
|
public long get(int index) { return data.getLong(index + offset); }
|
||||||
|
|
||||||
public void set(int index, long value) { data.set(index + offset, value); }
|
public void set(int index, long value) { data.set(index + offset, value); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() { return size; }
|
public int size() { return size; }
|
||||||
|
@Override
|
||||||
|
public int verticalSize() { return verticalSize; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int verticalSize() { return vertSize; }
|
public int dataCount() { return (this.verticalSize != 0) ? (this.size / this.verticalSize) : 0; } // TODO what does the divide by mean?
|
||||||
|
|
||||||
@Override
|
|
||||||
public int dataCount() { return (this.vertSize != 0) ? (this.size / this.vertSize) : 0; }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ColumnArrayView subView(int dataIndexStart, int dataCount)
|
public ColumnArrayView subView(int dataIndexStart, int dataCount)
|
||||||
{
|
{
|
||||||
return new ColumnArrayView(data, dataCount * vertSize, offset + dataIndexStart * vertSize, vertSize);
|
return new ColumnArrayView(data, dataCount * verticalSize, offset + dataIndexStart * verticalSize, verticalSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fill(long value) { Arrays.fill(data.elements(), offset, offset + size, value); }
|
public void fill(long value) { Arrays.fill(data.elements(), offset, offset + size, value); }
|
||||||
@@ -70,7 +90,7 @@ public final class ColumnArrayView implements IColumnDataView
|
|||||||
public void copyFrom(IColumnDataView source) { copyFrom(source, 0); }
|
public void copyFrom(IColumnDataView source) { copyFrom(source, 0); }
|
||||||
public void copyFrom(IColumnDataView source, int outputDataIndexOffset)
|
public void copyFrom(IColumnDataView source, int outputDataIndexOffset)
|
||||||
{
|
{
|
||||||
if (source.verticalSize() > vertSize)
|
if (source.verticalSize() > verticalSize)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("source verticalSize must be <= self's verticalSize to copy");
|
throw new IllegalArgumentException("source verticalSize must be <= self's verticalSize to copy");
|
||||||
}
|
}
|
||||||
@@ -78,19 +98,19 @@ public final class ColumnArrayView implements IColumnDataView
|
|||||||
{
|
{
|
||||||
throw new IllegalArgumentException("dataIndexStart + source.dataCount() must be <= self.dataCount() to copy");
|
throw new IllegalArgumentException("dataIndexStart + source.dataCount() must be <= self.dataCount() to copy");
|
||||||
}
|
}
|
||||||
else if (source.verticalSize() != vertSize)
|
else if (source.verticalSize() != verticalSize)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < source.dataCount(); i++)
|
for (int i = 0; i < source.dataCount(); i++)
|
||||||
{
|
{
|
||||||
int outputOffset = offset + outputDataIndexOffset * vertSize + i * vertSize;
|
int outputOffset = offset + outputDataIndexOffset * verticalSize + i * verticalSize;
|
||||||
source.subView(i, 1).copyTo(data.elements(), outputOffset, source.verticalSize());
|
source.subView(i, 1).copyTo(data.elements(), outputOffset, source.verticalSize());
|
||||||
Arrays.fill(data.elements(), outputOffset + source.verticalSize(),
|
Arrays.fill(data.elements(), outputOffset + source.verticalSize(),
|
||||||
outputOffset + vertSize, 0);
|
outputOffset + verticalSize, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
source.copyTo(data.elements(), offset + outputDataIndexOffset * vertSize, source.size());
|
source.copyTo(data.elements(), offset + outputDataIndexOffset * verticalSize, source.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,19 +123,19 @@ public final class ColumnArrayView implements IColumnDataView
|
|||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Cannot merge views of different sizes");
|
throw new IllegalArgumentException("Cannot merge views of different sizes");
|
||||||
}
|
}
|
||||||
if (vertSize != source.vertSize)
|
if (verticalSize != source.verticalSize)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Cannot merge views of different vertical sizes");
|
throw new IllegalArgumentException("Cannot merge views of different vertical sizes");
|
||||||
}
|
}
|
||||||
boolean anyChange = false;
|
boolean anyChange = false;
|
||||||
for (int o = 0; o < (source.size() * vertSize); o += vertSize)
|
for (int o = 0; o < (source.size() * verticalSize); o += verticalSize)
|
||||||
{
|
{
|
||||||
if (override)
|
if (override)
|
||||||
{
|
{
|
||||||
if (RenderDataPointUtil.compareDatapointPriority(source.get(o), get(o)) >= 0)
|
if (RenderDataPointUtil.compareDatapointPriority(source.get(o), get(o)) >= 0)
|
||||||
{
|
{
|
||||||
anyChange = true;
|
anyChange = true;
|
||||||
System.arraycopy(source.data, source.offset + o, data, offset + o, vertSize);
|
System.arraycopy(source.data, source.offset + o, data, offset + o, verticalSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -123,7 +143,7 @@ public final class ColumnArrayView implements IColumnDataView
|
|||||||
if (RenderDataPointUtil.compareDatapointPriority(source.get(o), get(o)) > 0)
|
if (RenderDataPointUtil.compareDatapointPriority(source.get(o), get(o)) > 0)
|
||||||
{
|
{
|
||||||
anyChange = true;
|
anyChange = true;
|
||||||
System.arraycopy(source.data, source.offset + o, data, offset + o, vertSize);
|
System.arraycopy(source.data, source.offset + o, data, offset + o, verticalSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +157,7 @@ public final class ColumnArrayView implements IColumnDataView
|
|||||||
throw new IllegalArgumentException("Cannot copy and resize to views with different dataCounts");
|
throw new IllegalArgumentException("Cannot copy and resize to views with different dataCounts");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.vertSize >= source.verticalSize())
|
if (this.verticalSize >= source.verticalSize())
|
||||||
{
|
{
|
||||||
this.copyFrom(source);
|
this.copyFrom(source);
|
||||||
}
|
}
|
||||||
@@ -160,12 +180,18 @@ public final class ColumnArrayView implements IColumnDataView
|
|||||||
RenderDataPointUtil.mergeMultiData(source, this);
|
RenderDataPointUtil.mergeMultiData(source, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// base overrides //
|
||||||
|
//================//
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("S:").append(size);
|
sb.append("S:").append(size);
|
||||||
sb.append(" V:").append(vertSize);
|
sb.append(" V:").append(verticalSize);
|
||||||
sb.append(" O:").append(offset);
|
sb.append(" O:").append(offset);
|
||||||
|
|
||||||
sb.append(" [");
|
sb.append(" [");
|
||||||
@@ -182,6 +208,7 @@ public final class ColumnArrayView implements IColumnDataView
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getDataHash()
|
public int getDataHash()
|
||||||
{
|
{
|
||||||
return arrayHash(data, offset, size);
|
return arrayHash(data, offset, size);
|
||||||
|
|||||||
-253
@@ -1,253 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
+245
-181
@@ -28,7 +28,7 @@ import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArra
|
|||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||||
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
||||||
@@ -38,6 +38,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
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.LongArrayList;
|
||||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -110,33 +111,260 @@ public class FullDataToRenderDataTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
columnSource.markNotEmpty();
|
columnSource.markNotEmpty();
|
||||||
|
int baseX = DhSectionPos.getMinCornerBlockX(pos);
|
||||||
|
int baseZ = DhSectionPos.getMinCornerBlockZ(pos);
|
||||||
|
|
||||||
if (dataDetail == columnSource.getDataDetailLevel())
|
for (int x = 0; x < DhSectionPos.getWidthCountForLowerDetailedSection(pos, dataDetail); x++)
|
||||||
{
|
{
|
||||||
int baseX = DhSectionPos.getMinCornerBlockX(pos);
|
for (int z = 0; z < DhSectionPos.getWidthCountForLowerDetailedSection(pos, dataDetail); z++)
|
||||||
int baseZ = DhSectionPos.getMinCornerBlockZ(pos);
|
|
||||||
|
|
||||||
for (int x = 0; x < DhSectionPos.getWidthCountForLowerDetailedSection(pos, dataDetail); x++)
|
|
||||||
{
|
{
|
||||||
for (int z = 0; z < DhSectionPos.getWidthCountForLowerDetailedSection(pos, dataDetail); z++)
|
throwIfThreadInterrupted();
|
||||||
{
|
|
||||||
throwIfThreadInterrupted();
|
|
||||||
|
|
||||||
ColumnArrayView columnArrayView = columnSource.getVerticalDataPointView(x, z);
|
ColumnArrayView columnArrayView = columnSource.getVerticalDataPointView(x, z);
|
||||||
LongArrayList dataColumn = fullDataSource.get(x, z);
|
LongArrayList dataColumn = fullDataSource.get(x, z);
|
||||||
convertColumnData(level, fullDataSource.mapping, baseX + x, baseZ + z, columnArrayView, dataColumn);
|
|
||||||
}
|
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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
columnSource.fillDebugFlag(0, 0, ColumnRenderSource.SECTION_SIZE, ColumnRenderSource.SECTION_SIZE, ColumnRenderSource.DebugSourceFlag.FULL);
|
columnSource.fillDebugFlag(0, 0, ColumnRenderSource.SECTION_SIZE, ColumnRenderSource.SECTION_SIZE, ColumnRenderSource.DebugSourceFlag.FULL);
|
||||||
|
|
||||||
|
return columnSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Updates the given {@link ColumnArrayView} to match the incoming Full data {@link LongArrayList} */
|
||||||
|
public static void updateOrReplaceRenderDataViewColumnWithFullDataColumn(
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
// Directly use the arrayView since it fits.
|
||||||
|
setRenderColumnView(level, fullDataMapping, blockX, blockZ, columnArrayView, fullDataColumn);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException("To be implemented");
|
// expand the ColumnArrayView to fit the new larger max vertical size
|
||||||
//FIXME: Implement different size creation of renderData
|
ColumnArrayView newColumnArrayView = new ColumnArrayView(new LongArrayList(new long[fullDataLength]), fullDataLength, 0, fullDataLength);
|
||||||
|
setRenderColumnView(level, fullDataMapping, blockX, blockZ, newColumnArrayView, fullDataColumn);
|
||||||
|
columnArrayView.changeVerticalSizeFrom(newColumnArrayView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void setRenderColumnView(
|
||||||
|
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()
|
||||||
|
&& (
|
||||||
|
// dimensions with a ceiling will be all caves so we don't want cave culling
|
||||||
|
!level.getLevelWrapper().hasCeiling()
|
||||||
|
// the end has a lot of overhangs with 0 lighting above the void, which look broken with
|
||||||
|
// the current cave culling logic (this could probably be improved, but just skipping it works best for now)
|
||||||
|
&& !level.getLevelWrapper().getDimensionType().isTheEnd()
|
||||||
|
);
|
||||||
|
|
||||||
|
boolean isColumnVoid = true;
|
||||||
|
|
||||||
|
int colorToApplyToNextBlock = -1;
|
||||||
|
int lastColor = 0;
|
||||||
|
int lastBottom = -10_000;
|
||||||
|
|
||||||
|
int skylightToApplyToNextBlock = -1;
|
||||||
|
int blocklightToApplyToNextBlock = -1;
|
||||||
|
int renderDataIndex = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==================================//
|
||||||
|
// convert full data to render data //
|
||||||
|
//==================================//
|
||||||
|
|
||||||
|
// goes from the top down
|
||||||
|
for (int fullDataIndex = 0; fullDataIndex < fullColumnData.size(); fullDataIndex++)
|
||||||
|
{
|
||||||
|
long fullData = fullColumnData.getLong(fullDataIndex);
|
||||||
|
|
||||||
|
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);
|
||||||
|
block = fullDataMapping.getBlockStateWrapper(id);
|
||||||
|
}
|
||||||
|
catch (IndexOutOfBoundsException e)
|
||||||
|
{
|
||||||
|
if (!brokenPos.contains(fullDataMapping.getPos()))
|
||||||
|
{
|
||||||
|
brokenPos.add(fullDataMapping.getPos());
|
||||||
|
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+"]. " +
|
||||||
|
"Error: ["+e.getMessage()+"]. " +
|
||||||
|
"Further errors for this position won't be logged.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't render broken data
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//====================//
|
||||||
|
// ignored block and //
|
||||||
|
// cave culling check //
|
||||||
|
//====================//
|
||||||
|
|
||||||
|
boolean ignoreBlock = blockStatesToIgnore.contains(block);
|
||||||
|
boolean caveBlock = caveBlockStatesToIgnore.contains(block);
|
||||||
|
if (caveBlock)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
// cave culling can't happen when at the bottom of the world
|
||||||
|
&& (fullDataIndex+1) < 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);
|
||||||
|
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);
|
||||||
|
columnData = RenderDataPointUtil.setYMin(columnData, bottomY);
|
||||||
|
renderColumnData.set(renderDataIndex - 1, columnData);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (ignoreBlock)
|
||||||
|
{
|
||||||
|
// this is a merged block and a cave block, so it should never be rendered
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ignoreBlock)
|
||||||
|
{
|
||||||
|
// this is an ignored block, but shouldn't be merged like a cave block
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=======================//
|
||||||
|
// non-solid block check //
|
||||||
|
//=======================//
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
colorToApplyToNextBlock = ColorUtil.setAlpha(tempColor,255);
|
||||||
|
skylightToApplyToNextBlock = skyLight;
|
||||||
|
blocklightToApplyToNextBlock = blockLight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip this non-colliding block
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int color;
|
||||||
|
if (colorToApplyToNextBlock == -1)
|
||||||
|
{
|
||||||
|
// use this block's color
|
||||||
|
color = level.computeBaseColor(new DhBlockPos(blockX, bottomY + level.getMinY(), blockZ), biome, block);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// use the previous block's color
|
||||||
|
color = colorToApplyToNextBlock;
|
||||||
|
colorToApplyToNextBlock = -1;
|
||||||
|
skyLight = skylightToApplyToNextBlock;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
//replace the previous block with new bottom
|
||||||
|
long columnData = renderColumnData.get(renderDataIndex - 1);
|
||||||
|
columnData = RenderDataPointUtil.setYMin(columnData, bottomY);
|
||||||
|
renderColumnData.set(renderDataIndex - 1, columnData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// add the block
|
||||||
|
isColumnVoid = false;
|
||||||
|
long columnData = RenderDataPointUtil.createDataPoint(bottomY + blockHeight, bottomY, color, skyLight, blockLight, block.getMaterialId());
|
||||||
|
renderColumnData.set(renderDataIndex, columnData);
|
||||||
|
renderDataIndex++;
|
||||||
|
}
|
||||||
|
lastBottom = bottomY;
|
||||||
|
lastColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isColumnVoid)
|
||||||
|
{
|
||||||
|
renderColumnData.set(0, RenderDataPointUtil.EMPTY_DATA);
|
||||||
}
|
}
|
||||||
return columnSource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -158,168 +386,4 @@ public class FullDataToRenderDataTransformer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO what does this mean?
|
|
||||||
private static void iterateAndConvert(
|
|
||||||
IDhClientLevel level, FullDataPointIdMap fullDataMapping,
|
|
||||||
int blockX, int blockZ,
|
|
||||||
ColumnArrayView renderColumnData, LongArrayList fullColumnData)
|
|
||||||
{
|
|
||||||
boolean avoidSolidBlocks = (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());
|
|
||||||
|
|
||||||
boolean isVoid = true;
|
|
||||||
int colorToApplyToNextBlock = -1;
|
|
||||||
int lastColor = 0;
|
|
||||||
int lastBottom = -10000;
|
|
||||||
int skylightToApplyToNextBlock = -1;
|
|
||||||
int blocklightToApplyToNextBlock = -1;
|
|
||||||
int columnOffset = 0;
|
|
||||||
|
|
||||||
// goes from the top down
|
|
||||||
for (int i = 0; i < fullColumnData.size(); i++)
|
|
||||||
{
|
|
||||||
long fullData = fullColumnData.getLong(i);
|
|
||||||
int bottomY = FullDataPointUtil.getBottomY(fullData);
|
|
||||||
int blockHeight = FullDataPointUtil.getHeight(fullData);
|
|
||||||
int id = FullDataPointUtil.getId(fullData);
|
|
||||||
int blockLight = FullDataPointUtil.getBlockLight(fullData);
|
|
||||||
int skyLight = FullDataPointUtil.getSkyLight(fullData);
|
|
||||||
|
|
||||||
// TODO how should corrupted data be handled?
|
|
||||||
// TODO why is the full data corrupted in the first place? FullDataPointUtil hasn't been changed in a long time, could one of the full data point objects be corrupted?
|
|
||||||
// TODO if either of these happen the ID might also be invalid
|
|
||||||
//if (bottomY + blockHeight > 300)
|
|
||||||
//{
|
|
||||||
// // this data point is too tall, it's probably a monolith
|
|
||||||
// int k = 0;
|
|
||||||
// throw new RuntimeException();
|
|
||||||
//}
|
|
||||||
//if (light > 16 || light < 0)
|
|
||||||
//{
|
|
||||||
// // light is out of range
|
|
||||||
// throw new RuntimeException();
|
|
||||||
//}
|
|
||||||
|
|
||||||
IBiomeWrapper biome;
|
|
||||||
IBlockStateWrapper block;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
biome = fullDataMapping.getBiomeWrapper(id);
|
|
||||||
block = fullDataMapping.getBlockStateWrapper(id);
|
|
||||||
}
|
|
||||||
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().getDimensionType().getDimensionName();
|
|
||||||
LOGGER.warn("Unable to get data point with id ["+id+"] " +
|
|
||||||
"(Max possible ID: ["+fullDataMapping.getMaxValidId()+"]) " +
|
|
||||||
"for pos ["+fullDataMapping.getPos()+"] in dimension ["+dimName+"]. " +
|
|
||||||
"Error: ["+e.getMessage()+"]. " +
|
|
||||||
"Further errors for this position won't be logged.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip rendering broken data
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (blockStatesToIgnore.contains(block))
|
|
||||||
{
|
|
||||||
// Don't render: air, barriers, light blocks, etc.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// solid block check
|
|
||||||
if (avoidSolidBlocks && !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);
|
|
||||||
if (ColorUtil.getAlpha(tempColor) == 0)
|
|
||||||
{
|
|
||||||
//make sure to not transfer the color when alpha is 0
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//mare sure to not trnasfer alpha if for some reason grass is semi transparent
|
|
||||||
colorToApplyToNextBlock = ColorUtil.setAlpha(tempColor,255);
|
|
||||||
skylightToApplyToNextBlock = skyLight;
|
|
||||||
blocklightToApplyToNextBlock = blockLight;
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't add this block
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int color;
|
|
||||||
if (colorToApplyToNextBlock == -1)
|
|
||||||
{
|
|
||||||
// use this block's color
|
|
||||||
color = level.computeBaseColor(new DhBlockPos(blockX, bottomY + level.getMinY(), blockZ), biome, block);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// use the previous block's color
|
|
||||||
color = colorToApplyToNextBlock;
|
|
||||||
colorToApplyToNextBlock = -1;
|
|
||||||
skyLight = skylightToApplyToNextBlock;
|
|
||||||
blockLight = blocklightToApplyToNextBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check if they share a top-bottom face and if they have same collor
|
|
||||||
if (color == lastColor && bottomY + blockHeight == lastBottom && columnOffset > 0)
|
|
||||||
{
|
|
||||||
//replace the previus block with new bottom
|
|
||||||
long columnData = renderColumnData.get(columnOffset - 1);
|
|
||||||
columnData = RenderDataPointUtil.setYMin(columnData, bottomY);
|
|
||||||
renderColumnData.set(columnOffset - 1, columnData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// add the block
|
|
||||||
isVoid = false;
|
|
||||||
long columnData = RenderDataPointUtil.createDataPoint(bottomY + blockHeight, bottomY, color, skyLight, blockLight, block.getMaterialId());
|
|
||||||
renderColumnData.set(columnOffset, columnData);
|
|
||||||
columnOffset++;
|
|
||||||
}
|
|
||||||
lastBottom = bottomY;
|
|
||||||
lastColor = color;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (isVoid)
|
|
||||||
{
|
|
||||||
renderColumnData.set(0, RenderDataPointUtil.createVoidDataPoint());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO what does this mean?
|
|
||||||
public static void convertColumnData(IDhClientLevel level, FullDataPointIdMap fullDataMapping, int blockX, int blockZ, ColumnArrayView columnArrayView, LongArrayList fullDataColumn)
|
|
||||||
{
|
|
||||||
if (fullDataColumn == null || fullDataColumn.size() == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dataTotalLength = fullDataColumn.size();
|
|
||||||
if (dataTotalLength > columnArrayView.verticalSize())
|
|
||||||
{
|
|
||||||
ColumnArrayView totalColumnData = new ColumnArrayView(new LongArrayList(new long[dataTotalLength]), dataTotalLength, 0, dataTotalLength);
|
|
||||||
iterateAndConvert(level, fullDataMapping, blockX, blockZ, totalColumnData, fullDataColumn);
|
|
||||||
columnArrayView.changeVerticalSizeFrom(totalColumnData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iterateAndConvert(level, fullDataMapping, blockX, blockZ, columnArrayView, fullDataColumn); //Directly use the arrayView since it fits.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+129
-37
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.dataObjects.transformers;
|
package com.seibel.distanthorizons.core.dataObjects.transformers;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiWorldCompressionMode;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiWorldCompressionMode;
|
||||||
@@ -30,11 +31,12 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
|
|||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPosMutable;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
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.util.objects.DataCorruptedException;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||||
@@ -47,8 +49,6 @@ public class LodDataBuilder
|
|||||||
{
|
{
|
||||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||||
private static final IBlockStateWrapper AIR = SingletonInjector.INSTANCE.get(IWrapperFactory.class).getAirBlockStateWrapper();
|
private static final IBlockStateWrapper AIR = SingletonInjector.INSTANCE.get(IWrapperFactory.class).getAirBlockStateWrapper();
|
||||||
/** how many chunks wide the {@link FullDataSourceV2} is. */
|
|
||||||
private static final int NUMB_OF_CHUNKS_WIDE = FullDataSourceV2.WIDTH / LodUtil.CHUNK_WIDTH;
|
|
||||||
|
|
||||||
private static boolean getTopErrorLogged = false;
|
private static boolean getTopErrorLogged = false;
|
||||||
|
|
||||||
@@ -67,12 +67,8 @@ public class LodDataBuilder
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// get the section position
|
int sectionPosX = getXOrZSectionPosFromChunkPos(chunkWrapper.getChunkPos().getX());
|
||||||
int sectionPosX = chunkWrapper.getChunkPos().x;
|
int sectionPosZ = getXOrZSectionPosFromChunkPos(chunkWrapper.getChunkPos().getZ());
|
||||||
// negative positions start at -1 so the logic there is slightly different
|
|
||||||
sectionPosX = (sectionPosX < 0) ? ((sectionPosX + 1) / NUMB_OF_CHUNKS_WIDE) - 1 : (sectionPosX / NUMB_OF_CHUNKS_WIDE);
|
|
||||||
int sectionPosZ = chunkWrapper.getChunkPos().z;
|
|
||||||
sectionPosZ = (sectionPosZ < 0) ? ((sectionPosZ + 1) / NUMB_OF_CHUNKS_WIDE) - 1 : (sectionPosZ / NUMB_OF_CHUNKS_WIDE);
|
|
||||||
long pos = DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
|
long pos = DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
|
||||||
|
|
||||||
FullDataSourceV2 dataSource = FullDataSourceV2.createEmpty(pos);
|
FullDataSourceV2 dataSource = FullDataSourceV2.createEmpty(pos);
|
||||||
@@ -82,8 +78,8 @@ public class LodDataBuilder
|
|||||||
|
|
||||||
// compute the chunk dataSource offset
|
// compute the chunk dataSource offset
|
||||||
// this offset is used to determine where in the dataSource this chunk's data should go
|
// this offset is used to determine where in the dataSource this chunk's data should go
|
||||||
int chunkOffsetX = chunkWrapper.getChunkPos().x;
|
int chunkOffsetX = chunkWrapper.getChunkPos().getX();
|
||||||
if (chunkWrapper.getChunkPos().x < 0)
|
if (chunkWrapper.getChunkPos().getX() < 0)
|
||||||
{
|
{
|
||||||
// expected offset positions:
|
// expected offset positions:
|
||||||
// chunkPos -> offset
|
// chunkPos -> offset
|
||||||
@@ -98,30 +94,30 @@ public class LodDataBuilder
|
|||||||
// -3 -> 1
|
// -3 -> 1
|
||||||
// -4 -> 0 ---
|
// -4 -> 0 ---
|
||||||
// -5 -> 3
|
// -5 -> 3
|
||||||
chunkOffsetX = ((chunkOffsetX) % NUMB_OF_CHUNKS_WIDE);
|
chunkOffsetX = ((chunkOffsetX) % FullDataSourceV2.NUMB_OF_CHUNKS_WIDE);
|
||||||
if (chunkOffsetX != 0)
|
if (chunkOffsetX != 0)
|
||||||
{
|
{
|
||||||
chunkOffsetX += NUMB_OF_CHUNKS_WIDE;
|
chunkOffsetX += FullDataSourceV2.NUMB_OF_CHUNKS_WIDE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chunkOffsetX %= NUMB_OF_CHUNKS_WIDE;
|
chunkOffsetX %= FullDataSourceV2.NUMB_OF_CHUNKS_WIDE;
|
||||||
}
|
}
|
||||||
chunkOffsetX *= LodUtil.CHUNK_WIDTH;
|
chunkOffsetX *= LodUtil.CHUNK_WIDTH;
|
||||||
|
|
||||||
int chunkOffsetZ = chunkWrapper.getChunkPos().z;
|
int chunkOffsetZ = chunkWrapper.getChunkPos().getZ();
|
||||||
if (chunkWrapper.getChunkPos().z < 0)
|
if (chunkWrapper.getChunkPos().getZ() < 0)
|
||||||
{
|
{
|
||||||
chunkOffsetZ = ((chunkOffsetZ) % NUMB_OF_CHUNKS_WIDE);
|
chunkOffsetZ = ((chunkOffsetZ) % FullDataSourceV2.NUMB_OF_CHUNKS_WIDE);
|
||||||
if (chunkOffsetZ != 0)
|
if (chunkOffsetZ != 0)
|
||||||
{
|
{
|
||||||
chunkOffsetZ += NUMB_OF_CHUNKS_WIDE;
|
chunkOffsetZ += FullDataSourceV2.NUMB_OF_CHUNKS_WIDE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chunkOffsetZ %= NUMB_OF_CHUNKS_WIDE;
|
chunkOffsetZ %= FullDataSourceV2.NUMB_OF_CHUNKS_WIDE;
|
||||||
}
|
}
|
||||||
chunkOffsetZ *= LodUtil.CHUNK_WIDTH;
|
chunkOffsetZ *= LodUtil.CHUNK_WIDTH;
|
||||||
|
|
||||||
@@ -159,8 +155,8 @@ public class LodDataBuilder
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//we are at the height limit. There are no torches here, and sky is not obscured.
|
//we are at the height limit. There are no torches here, and sky is not obscured.
|
||||||
blockLight = 0;
|
blockLight = LodUtil.MIN_MC_LIGHT;
|
||||||
skyLight = 15;
|
skyLight = LodUtil.MAX_MC_LIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -242,7 +238,7 @@ public class LodDataBuilder
|
|||||||
private static boolean blockVisible(IChunkWrapper chunkWrapper, int relBlockX, int blockY, int relBlockZ)
|
private static boolean blockVisible(IChunkWrapper chunkWrapper, int relBlockX, int blockY, int relBlockZ)
|
||||||
{
|
{
|
||||||
DhBlockPos originalBlockPos = new DhBlockPos(relBlockX,blockY,relBlockZ);
|
DhBlockPos originalBlockPos = new DhBlockPos(relBlockX,blockY,relBlockZ);
|
||||||
DhBlockPos testBlockPos = new DhBlockPos(relBlockX,blockY,relBlockZ);
|
final DhBlockPosMutable testBlockPos = new DhBlockPosMutable(relBlockX,blockY,relBlockZ);
|
||||||
|
|
||||||
// up/down
|
// up/down
|
||||||
if (blockInDirectionVisible(chunkWrapper, EDhDirection.UP, originalBlockPos, testBlockPos))
|
if (blockInDirectionVisible(chunkWrapper, EDhDirection.UP, originalBlockPos, testBlockPos))
|
||||||
@@ -277,20 +273,20 @@ public class LodDataBuilder
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private static boolean blockInDirectionVisible(IChunkWrapper chunkWrapper, EDhDirection direction, DhBlockPos originalBlockPos, DhBlockPos testBlockPos)
|
private static boolean blockInDirectionVisible(IChunkWrapper chunkWrapper, EDhDirection direction, DhBlockPos originalBlockPos, DhBlockPosMutable testBlockPos)
|
||||||
{
|
{
|
||||||
originalBlockPos.mutateOffset(direction, testBlockPos);
|
originalBlockPos.mutateOffset(direction, testBlockPos);
|
||||||
|
|
||||||
// if the block is next to the border of a chunk, assume it's visible
|
// if the block is next to the border of a chunk, assume it's visible
|
||||||
if (testBlockPos.x < 0 || testBlockPos.x >= LodUtil.CHUNK_WIDTH)
|
if (testBlockPos.getX() < 0 || testBlockPos.getX() >= LodUtil.CHUNK_WIDTH)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (testBlockPos.z < 0 || testBlockPos.z >= LodUtil.CHUNK_WIDTH)
|
if (testBlockPos.getZ() < 0 || testBlockPos.getZ() >= LodUtil.CHUNK_WIDTH)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (testBlockPos.y < chunkWrapper.getMinBuildHeight() || testBlockPos.y > chunkWrapper.getMaxBuildHeight())
|
if (testBlockPos.getY() < chunkWrapper.getMinBuildHeight() || testBlockPos.getY() > chunkWrapper.getMaxBuildHeight())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -302,14 +298,27 @@ public class LodDataBuilder
|
|||||||
|
|
||||||
|
|
||||||
/** @throws ClassCastException if an API user returns the wrong object type(s) */
|
/** @throws ClassCastException if an API user returns the wrong object type(s) */
|
||||||
public static FullDataSourceV2 createFromApiChunkData(DhApiChunk dataPoints) throws ClassCastException, DataCorruptedException
|
public static FullDataSourceV2 createFromApiChunkData(DhApiChunk apiChunk, boolean runAdditionalValidation) throws ClassCastException, DataCorruptedException, IllegalArgumentException
|
||||||
{
|
{
|
||||||
FullDataSourceV2 accessor = FullDataSourceV2.createEmpty(DhSectionPos.encode(new DhChunkPos(dataPoints.chunkPosX, dataPoints.chunkPosZ)));
|
// get the section position
|
||||||
for (int relZ = 0; relZ < LodUtil.CHUNK_WIDTH; relZ++)
|
int sectionPosX = getXOrZSectionPosFromChunkPos(apiChunk.chunkPosX);
|
||||||
|
int sectionPosZ = getXOrZSectionPosFromChunkPos(apiChunk.chunkPosZ);
|
||||||
|
long pos = DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
|
||||||
|
|
||||||
|
// chunk relative block position in the data source
|
||||||
|
int relSourceBlockX = Math.floorMod(apiChunk.chunkPosX, 4) * LodUtil.CHUNK_WIDTH;
|
||||||
|
int relSourceBlockZ = Math.floorMod(apiChunk.chunkPosZ, 4) * LodUtil.CHUNK_WIDTH;
|
||||||
|
|
||||||
|
FullDataSourceV2 dataSource = FullDataSourceV2.createEmpty(pos);
|
||||||
|
for (int relBlockZ = 0; relBlockZ < LodUtil.CHUNK_WIDTH; relBlockZ++)
|
||||||
{
|
{
|
||||||
for (int relX = 0; relX < LodUtil.CHUNK_WIDTH; relX++)
|
for (int relBlockX = 0; relBlockX < LodUtil.CHUNK_WIDTH; relBlockX++)
|
||||||
{
|
{
|
||||||
List<DhApiTerrainDataPoint> columnDataPoints = dataPoints.getDataPoints(relX, relZ);
|
List<DhApiTerrainDataPoint> columnDataPoints = apiChunk.getDataPoints(relBlockX, relBlockZ);
|
||||||
|
if (runAdditionalValidation)
|
||||||
|
{
|
||||||
|
validateOrThrowDataColumn(columnDataPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// this null check does 2 nice things at the same time:
|
// this null check does 2 nice things at the same time:
|
||||||
@@ -318,12 +327,14 @@ public class LodDataBuilder
|
|||||||
// AND the below loop won't run.
|
// AND the below loop won't run.
|
||||||
int size = (columnDataPoints != null) ? columnDataPoints.size() : 0;
|
int size = (columnDataPoints != null) ? columnDataPoints.size() : 0;
|
||||||
|
|
||||||
|
// TODO make missing air LODs
|
||||||
|
// TODO merge duplicate datapoints
|
||||||
LongArrayList packedDataPoints = new LongArrayList(new long[size]);
|
LongArrayList packedDataPoints = new LongArrayList(new long[size]);
|
||||||
for (int index = 0; index < size; index++)
|
for (int index = 0; index < size; index++)
|
||||||
{
|
{
|
||||||
DhApiTerrainDataPoint dataPoint = columnDataPoints.get(index);
|
DhApiTerrainDataPoint dataPoint = columnDataPoints.get(index);
|
||||||
|
|
||||||
int id = accessor.mapping.addIfNotPresentAndGetId(
|
int id = dataSource.mapping.addIfNotPresentAndGetId(
|
||||||
(IBiomeWrapper) (dataPoint.biomeWrapper),
|
(IBiomeWrapper) (dataPoint.biomeWrapper),
|
||||||
(IBlockStateWrapper) (dataPoint.blockStateWrapper)
|
(IBlockStateWrapper) (dataPoint.blockStateWrapper)
|
||||||
);
|
);
|
||||||
@@ -331,7 +342,7 @@ public class LodDataBuilder
|
|||||||
packedDataPoints.set(index, FullDataPointUtil.encode(
|
packedDataPoints.set(index, FullDataPointUtil.encode(
|
||||||
id,
|
id,
|
||||||
dataPoint.topYBlockPos - dataPoint.bottomYBlockPos,
|
dataPoint.topYBlockPos - dataPoint.bottomYBlockPos,
|
||||||
dataPoint.bottomYBlockPos - dataPoints.topYBlockPos,
|
dataPoint.bottomYBlockPos - apiChunk.bottomYBlockPos,
|
||||||
(byte) (dataPoint.blockLightLevel),
|
(byte) (dataPoint.blockLightLevel),
|
||||||
(byte) (dataPoint.skyLightLevel)
|
(byte) (dataPoint.skyLightLevel)
|
||||||
));
|
));
|
||||||
@@ -339,12 +350,84 @@ public class LodDataBuilder
|
|||||||
|
|
||||||
// TODO add the ability for API users to define a different compression mode
|
// TODO add the ability for API users to define a different compression mode
|
||||||
// or add a "unkown" compression mode
|
// or add a "unkown" compression mode
|
||||||
accessor.setSingleColumn(packedDataPoints, relX, relZ, EDhApiWorldGenerationStep.LIGHT, EDhApiWorldCompressionMode.MERGE_SAME_BLOCKS);
|
dataSource.setSingleColumn(
|
||||||
|
packedDataPoints,
|
||||||
|
relBlockX + relSourceBlockX, relBlockZ + relSourceBlockZ,
|
||||||
|
EDhApiWorldGenerationStep.LIGHT, EDhApiWorldCompressionMode.MERGE_SAME_BLOCKS);
|
||||||
|
dataSource.isEmpty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return dataSource;
|
||||||
return accessor;
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -354,4 +437,13 @@ public class LodDataBuilder
|
|||||||
|
|
||||||
public static boolean canGenerateLodFromChunk(IChunkWrapper chunk) { return chunk != null && chunk.isLightCorrect(); }
|
public static boolean canGenerateLodFromChunk(IChunkWrapper chunk) { return chunk != null && chunk.isLightCorrect(); }
|
||||||
|
|
||||||
|
public static int getXOrZSectionPosFromChunkPos(int chunkXOrZPos)
|
||||||
|
{
|
||||||
|
// get the section position
|
||||||
|
int sectionPos = chunkXOrZPos;
|
||||||
|
// negative positions start at -1 so the logic there is slightly different
|
||||||
|
sectionPos = (sectionPos < 0) ? ((sectionPos + 1) / FullDataSourceV2.NUMB_OF_CHUNKS_WIDE) - 1 : (sectionPos / FullDataSourceV2.NUMB_OF_CHUNKS_WIDE);
|
||||||
|
return sectionPos;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-8
@@ -26,12 +26,12 @@ import com.seibel.distanthorizons.core.config.Config;
|
|||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiServerFolderNameMode;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiServerFolderNameMode;
|
||||||
import com.seibel.distanthorizons.core.level.IServerKeyedClientLevel;
|
import com.seibel.distanthorizons.core.level.IServerKeyedClientLevel;
|
||||||
import com.seibel.distanthorizons.core.util.objects.ParsedIp;
|
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.IMinecraftClientWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
|
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -41,13 +41,17 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class ClientOnlySaveStructure extends AbstractSaveStructure
|
public class ClientOnlySaveStructure extends AbstractSaveStructure
|
||||||
{
|
{
|
||||||
final File folder;
|
public static final String SERVER_DATA_FOLDER_NAME = "Distant_Horizons_server_data";
|
||||||
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
public static final String REPLAY_SERVER_FOLDER_NAME = "REPLAY";
|
||||||
private static final IMinecraftSharedWrapper MC_SHARED = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class);
|
|
||||||
public static final String INVALID_FILE_CHARACTERS_REGEX = "[\\\\/:*?\"<>|]";
|
public static final String INVALID_FILE_CHARACTERS_REGEX = "[\\\\/:*?\"<>|]";
|
||||||
|
|
||||||
SubDimensionLevelMatcher subDimMatcher = null;
|
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||||
final HashMap<ILevelWrapper, File> levelWrapperToFileMap = new HashMap<>();
|
private static final IMinecraftSharedWrapper MC_SHARED = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class);
|
||||||
|
|
||||||
|
|
||||||
|
private SubDimensionLevelMatcher subDimMatcher = null;
|
||||||
|
private final File folder;
|
||||||
|
private final HashMap<ILevelWrapper, File> levelWrapperToFileMap = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -134,7 +138,7 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure
|
|||||||
{
|
{
|
||||||
// use the first existing sub-dimension
|
// use the first existing sub-dimension
|
||||||
String folderName = folders.get(0).getName();
|
String folderName = folders.get(0).getName();
|
||||||
LOGGER.info("Default Sub Dimension set to: [" + LodUtil.shortenString(folderName, 8) + "...]");
|
LOGGER.info("Default Sub Dimension set to: [" + StringUtil.shortenString(folderName, 8) + "...]");
|
||||||
return folders.get(0);
|
return folders.get(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -237,7 +241,7 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure
|
|||||||
private static String getSaveStructureFolderPath()
|
private static String getSaveStructureFolderPath()
|
||||||
{
|
{
|
||||||
String path = MC_SHARED.getInstallationDirectory().getPath() + File.separatorChar
|
String path = MC_SHARED.getInstallationDirectory().getPath() + File.separatorChar
|
||||||
+ "Distant_Horizons_server_data" + File.separatorChar
|
+ SERVER_DATA_FOLDER_NAME + File.separatorChar
|
||||||
+ getServerFolderName();
|
+ getServerFolderName();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -245,6 +249,14 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure
|
|||||||
/** Generated from the server the client is currently connected to. */
|
/** Generated from the server the client is currently connected to. */
|
||||||
private static String getServerFolderName()
|
private static String getServerFolderName()
|
||||||
{
|
{
|
||||||
|
// if connected to a replay we won't have any server info
|
||||||
|
// use the dedicated replay server folder
|
||||||
|
if (MC_CLIENT.connectedToReplay())
|
||||||
|
{
|
||||||
|
return REPLAY_SERVER_FOLDER_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// parse the current server's IP
|
// parse the current server's IP
|
||||||
ParsedIp parsedIp = new ParsedIp(MC_CLIENT.getCurrentServerIp());
|
ParsedIp parsedIp = new ParsedIp(MC_CLIENT.getCurrentServerIp());
|
||||||
String serverIpCleaned = parsedIp.ip.replaceAll(INVALID_FILE_CHARACTERS_REGEX, "");
|
String serverIpCleaned = parsedIp.ip.replaceAll(INVALID_FILE_CHARACTERS_REGEX, "");
|
||||||
|
|||||||
+11
-10
@@ -40,6 +40,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftCli
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
|
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
||||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
@@ -92,7 +93,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
|||||||
if (potentialLevelFolders.size() == 0)
|
if (potentialLevelFolders.size() == 0)
|
||||||
{
|
{
|
||||||
String newId = UUID.randomUUID().toString();
|
String newId = UUID.randomUUID().toString();
|
||||||
LOGGER.info("No potential level files found. Creating a new sub dimension with the ID ["+LodUtil.shortenString(newId, 8)+"]...");
|
LOGGER.info("No potential level files found. Creating a new sub dimension with the ID ["+ StringUtil.shortenString(newId, 8)+"]...");
|
||||||
this.foundLevelFile = this.CreateSubDimFolder(newId);
|
this.foundLevelFile = this.CreateSubDimFolder(newId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,7 +191,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
|||||||
}
|
}
|
||||||
FullDataSourceV2 newChunkSizedFullDataView = FullDataSourceV2.createFromChunk(newlyLoadedChunk);
|
FullDataSourceV2 newChunkSizedFullDataView = FullDataSourceV2.createFromChunk(newlyLoadedChunk);
|
||||||
// convert to a data source for easier comparing
|
// convert to a data source for easier comparing
|
||||||
FullDataSourceV2 newDataSource = FullDataSourceV2.createEmpty(DhSectionPos.encode(this.playerData.playerBlockPos));
|
FullDataSourceV2 newDataSource = FullDataSourceV2.createEmpty(DhSectionPos.encodeContaining(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, this.playerData.playerBlockPos));
|
||||||
newDataSource.update(newChunkSizedFullDataView);
|
newDataSource.update(newChunkSizedFullDataView);
|
||||||
|
|
||||||
|
|
||||||
@@ -201,13 +202,13 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
|||||||
|
|
||||||
// log the start of this attempt
|
// log the start of this attempt
|
||||||
LOGGER.info("Attempting to determine sub-dimension for [" + MC_CLIENT.getWrappedClientLevel().getDimensionType().getDimensionName() + "]");
|
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("Player block pos in dimension: [" + this.playerData.playerBlockPos.getX() + "," + this.playerData.playerBlockPos.getY() + "," + this.playerData.playerBlockPos.getZ() + "]");
|
||||||
LOGGER.info("Potential Sub Dimension folders: [" + this.potentialLevelFolders.size() + "]");
|
LOGGER.info("Potential Sub Dimension folders: [" + this.potentialLevelFolders.size() + "]");
|
||||||
|
|
||||||
SubDimCompare mostSimilarSubDim = null;
|
SubDimCompare mostSimilarSubDim = null;
|
||||||
for (File testLevelFolder : this.potentialLevelFolders)
|
for (File testLevelFolder : this.potentialLevelFolders)
|
||||||
{
|
{
|
||||||
LOGGER.info("Testing level folder: [" + LodUtil.shortenString(testLevelFolder.getName(), 8) + "]");
|
LOGGER.info("Testing level folder: [" + StringUtil.shortenString(testLevelFolder.getName(), 8) + "]");
|
||||||
|
|
||||||
FullDataSourceV2 testFullDataSource = null;
|
FullDataSourceV2 testFullDataSource = null;
|
||||||
try
|
try
|
||||||
@@ -215,7 +216,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
|||||||
// get the data source to compare against
|
// get the data source to compare against
|
||||||
try (IDhLevel tempLevel = new DhClientLevel(new ClientOnlySaveStructure(), this.currentClientLevel, testLevelFolder, false))
|
try (IDhLevel tempLevel = new DhClientLevel(new ClientOnlySaveStructure(), this.currentClientLevel, testLevelFolder, false))
|
||||||
{
|
{
|
||||||
testFullDataSource = tempLevel.getFullDataProvider().getAsync(DhSectionPos.encode(this.playerData.playerBlockPos)).join();
|
testFullDataSource = tempLevel.getFullDataProvider().getAsync(DhSectionPos.encodeContaining(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, this.playerData.playerBlockPos)).join();
|
||||||
if (testFullDataSource == null)
|
if (testFullDataSource == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -314,7 +315,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
|||||||
|
|
||||||
// get the player data for this dimension folder
|
// get the player data for this dimension folder
|
||||||
SubDimensionPlayerData testPlayerData = new SubDimensionPlayerData(testLevelFolder);
|
SubDimensionPlayerData testPlayerData = new SubDimensionPlayerData(testLevelFolder);
|
||||||
LOGGER.info("Last known player pos: [" + testPlayerData.playerBlockPos.x + "," + testPlayerData.playerBlockPos.y + "," + testPlayerData.playerBlockPos.z + "]");
|
LOGGER.info("Last known player pos: [" + testPlayerData.playerBlockPos.getX() + "," + testPlayerData.playerBlockPos.getY() + "," + testPlayerData.playerBlockPos.getZ() + "]");
|
||||||
|
|
||||||
// check if the block positions are close
|
// check if the block positions are close
|
||||||
int playerBlockDist = testPlayerData.playerBlockPos.getManhattanDistance(this.playerData.playerBlockPos);
|
int playerBlockDist = testPlayerData.playerBlockPos.getManhattanDistance(this.playerData.playerBlockPos);
|
||||||
@@ -328,8 +329,8 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String subDimShortName = LodUtil.shortenString(testLevelFolder.getName(), 8); // variables are separated out for easier debugging
|
String subDimShortName = StringUtil.shortenString(testLevelFolder.getName(), 8); // variables are separated out for easier debugging
|
||||||
String equalPercent = LodUtil.shortenString(mostSimilarSubDim.getPercentEqual()+"", 5);
|
String equalPercent = StringUtil.shortenString(mostSimilarSubDim.getPercentEqual()+"", 5);
|
||||||
LOGGER.info("Sub dimension ["+subDimShortName+"...] is current dimension probability: "+equalPercent+" ("+equalDataPoints+"/"+totalDataPointCount+")");
|
LOGGER.info("Sub dimension ["+subDimShortName+"...] is current dimension probability: "+equalPercent+" ("+equalDataPoints+"/"+totalDataPointCount+")");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -359,7 +360,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
|||||||
{
|
{
|
||||||
// we found a sub dim folder that is similar, use it
|
// we found a sub dim folder that is similar, use it
|
||||||
|
|
||||||
LOGGER.info("Sub Dimension set to: [" + LodUtil.shortenString(mostSimilarSubDim.folder.getName(), 8) + "...] with an equality of [" + mostSimilarSubDim.getPercentEqual() + "]");
|
LOGGER.info("Sub Dimension set to: [" + StringUtil.shortenString(mostSimilarSubDim.folder.getName(), 8) + "...] with an equality of [" + mostSimilarSubDim.getPercentEqual() + "]");
|
||||||
return mostSimilarSubDim.folder;
|
return mostSimilarSubDim.folder;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -369,7 +370,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
|
|||||||
String newId = UUID.randomUUID().toString();
|
String newId = UUID.randomUUID().toString();
|
||||||
|
|
||||||
double highestEqualityPercent = mostSimilarSubDim != null ? mostSimilarSubDim.getPercentEqual() : 0;
|
double highestEqualityPercent = mostSimilarSubDim != null ? mostSimilarSubDim.getPercentEqual() : 0;
|
||||||
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) + "...";
|
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) + "...";
|
||||||
LOGGER.info(message);
|
LOGGER.info(message);
|
||||||
|
|
||||||
File folder = this.CreateSubDimFolder(newId);
|
File folder = this.CreateSubDimFolder(newId);
|
||||||
|
|||||||
+5
-5
@@ -22,7 +22,7 @@ package com.seibel.distanthorizons.core.file.subDimMatching;
|
|||||||
|
|
||||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
|
|
||||||
@@ -127,9 +127,9 @@ public class SubDimensionPlayerData
|
|||||||
public void toTomlFile(CommentedFileConfig toml)
|
public void toTomlFile(CommentedFileConfig toml)
|
||||||
{
|
{
|
||||||
// player block pos
|
// player block pos
|
||||||
toml.add(PLAYER_BLOCK_POS_X_PATH, this.playerBlockPos.x);
|
toml.add(PLAYER_BLOCK_POS_X_PATH, this.playerBlockPos.getX());
|
||||||
toml.add(PLAYER_BLOCK_POS_Y_PATH, this.playerBlockPos.y);
|
toml.add(PLAYER_BLOCK_POS_Y_PATH, this.playerBlockPos.getY());
|
||||||
toml.add(PLAYER_BLOCK_POS_Z_PATH, this.playerBlockPos.z);
|
toml.add(PLAYER_BLOCK_POS_Z_PATH, this.playerBlockPos.getZ());
|
||||||
|
|
||||||
toml.save();
|
toml.save();
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ public class SubDimensionPlayerData
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "PlayerBlockPos: [" + this.playerBlockPos.x + "," + this.playerBlockPos.y + "," + this.playerBlockPos.z + "]";
|
return "PlayerBlockPos: [" + this.playerBlockPos.getX() + "," + this.playerBlockPos.getY() + "," + this.playerBlockPos.getZ() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -33,7 +33,7 @@ public class AdjacentChunkHolder
|
|||||||
{
|
{
|
||||||
for (int zOffset = -1; zOffset <= 1; zOffset++)
|
for (int zOffset = -1; zOffset <= 1; zOffset++)
|
||||||
{
|
{
|
||||||
DhChunkPos adjacentPos = new DhChunkPos(centerChunkPos.x + xOffset, centerChunkPos.z + zOffset);
|
DhChunkPos adjacentPos = new DhChunkPos(centerChunkPos.getX() + xOffset, centerChunkPos.getZ() + zOffset);
|
||||||
requestedAdjacentPositions.add(adjacentPos);
|
requestedAdjacentPositions.add(adjacentPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,13 +69,13 @@ public class AdjacentChunkHolder
|
|||||||
DhChunkPos centerPos = this.chunkArray[4].getChunkPos();
|
DhChunkPos centerPos = this.chunkArray[4].getChunkPos();
|
||||||
DhChunkPos offsetPos = centerWrapper.getChunkPos();
|
DhChunkPos offsetPos = centerWrapper.getChunkPos();
|
||||||
|
|
||||||
int offsetX = offsetPos.x - centerPos.x;
|
int offsetX = offsetPos.getX() - centerPos.getX();
|
||||||
if (offsetX < -1 || offsetX > 1)
|
if (offsetX < -1 || offsetX > 1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int offsetZ = offsetPos.z - centerPos.z;
|
int offsetZ = offsetPos.getZ() - centerPos.getZ();
|
||||||
if (offsetZ < -1 || offsetZ > 1)
|
if (offsetZ < -1 || offsetZ > 1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -91,18 +91,18 @@ public class AdjacentChunkHolder
|
|||||||
int chunkZ = BitShiftUtil.divideByPowerOfTwo(blockZ, 4);
|
int chunkZ = BitShiftUtil.divideByPowerOfTwo(blockZ, 4);
|
||||||
IChunkWrapper centerChunk = this.chunkArray[4];
|
IChunkWrapper centerChunk = this.chunkArray[4];
|
||||||
DhChunkPos centerPos = centerChunk.getChunkPos();
|
DhChunkPos centerPos = centerChunk.getChunkPos();
|
||||||
if (centerPos.x == chunkX && centerPos.z == chunkZ)
|
if (centerPos.getX() == chunkX && centerPos.getZ() == chunkZ)
|
||||||
{
|
{
|
||||||
return centerChunk;
|
return centerChunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
int offsetX = chunkX - centerPos.x;
|
int offsetX = chunkX - centerPos.getX();
|
||||||
if (offsetX < -1 || offsetX > 1)
|
if (offsetX < -1 || offsetX > 1)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int offsetZ = chunkZ - centerPos.z;
|
int offsetZ = chunkZ - centerPos.getZ();
|
||||||
if (offsetZ < -1 || offsetZ > 1)
|
if (offsetZ < -1 || offsetZ > 1)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -47,15 +47,6 @@ public class BatchGenerator implements IDhApiWorldGenerator
|
|||||||
private static final IWrapperFactory FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
private static final IWrapperFactory FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
||||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
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 AbstractBatchGenerationEnvironmentWrapper generationEnvironment;
|
||||||
public IDhLevel targetDhLevel;
|
public IDhLevel targetDhLevel;
|
||||||
|
|
||||||
@@ -147,14 +138,6 @@ public class BatchGenerator implements IDhApiWorldGenerator
|
|||||||
@Override
|
@Override
|
||||||
public void preGeneratorTaskStart() { this.generationEnvironment.updateAllFutures(); }
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=========//
|
//=========//
|
||||||
|
|||||||
+156
-37
@@ -21,13 +21,17 @@ package com.seibel.distanthorizons.core.generation;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPosMutable;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
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.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@@ -49,15 +53,28 @@ public class DhLightingEngine
|
|||||||
* Since these objects are always mutated anyway, using a {@link ThreadLocal} will allow us to
|
* 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.
|
* only create as many of these {@link DhBlockPos} as necessary.
|
||||||
*/
|
*/
|
||||||
private static final ThreadLocal<DhBlockPos> PRIMARY_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new DhBlockPos());
|
private static final ThreadLocal<DhBlockPosMutable> PRIMARY_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new DhBlockPosMutable());
|
||||||
private static final ThreadLocal<DhBlockPos> SECONDARY_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new DhBlockPos());
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
|
||||||
private DhLightingEngine() { }
|
private DhLightingEngine() { }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=========//
|
||||||
|
// methods //
|
||||||
|
//=========//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: depending on the implementation of {@link IChunkWrapper#setDhBlockLight(int, int, int, int)} and {@link IChunkWrapper#setDhSkyLight(int, int, int, int)}
|
* 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.
|
* the light values may be stored in the wrapper itself instead of the wrapped chunk object.
|
||||||
@@ -76,12 +93,12 @@ public class DhLightingEngine
|
|||||||
|
|
||||||
|
|
||||||
// try-finally to handle the stableArray resources
|
// try-finally to handle the stableArray resources
|
||||||
StableLightPosStack blockLightPosQueue = null;
|
StableLightPosStack blockLightWorldPosQueue = null;
|
||||||
StableLightPosStack skyLightPosQueue = null;
|
StableLightPosStack skyLightWorldPosQueue = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
blockLightPosQueue = StableLightPosStack.borrowStableLightPosArray();
|
blockLightWorldPosQueue = StableLightPosStack.borrowStableLightPosArray();
|
||||||
skyLightPosQueue = StableLightPosStack.borrowStableLightPosArray();
|
skyLightWorldPosQueue = StableLightPosStack.borrowStableLightPosArray();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -92,7 +109,7 @@ public class DhLightingEngine
|
|||||||
{
|
{
|
||||||
for (int zOffset = -1; zOffset <= 1; zOffset++)
|
for (int zOffset = -1; zOffset <= 1; zOffset++)
|
||||||
{
|
{
|
||||||
DhChunkPos adjacentPos = new DhChunkPos(centerChunkPos.x + xOffset, centerChunkPos.z + zOffset);
|
DhChunkPos adjacentPos = new DhChunkPos(centerChunkPos.getX() + xOffset, centerChunkPos.getZ() + zOffset);
|
||||||
requestedAdjacentPositions.add(adjacentPos);
|
requestedAdjacentPositions.add(adjacentPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,11 +131,14 @@ public class DhLightingEngine
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// get and set the adjacent chunk's initial block lights
|
//==================//
|
||||||
final DhBlockPos relLightBlockPos = PRIMARY_BLOCK_POS_REF.get();
|
// set block lights //
|
||||||
final DhBlockPos relBlockPos = SECONDARY_BLOCK_POS_REF.get();
|
//==================//
|
||||||
|
|
||||||
ArrayList<DhBlockPos> blockLightPosList = chunk.getBlockLightPosList();
|
// get and set the adjacent chunk's initial block lights
|
||||||
|
final DhBlockPosMutable relLightBlockPos = PRIMARY_BLOCK_POS_REF.get();
|
||||||
|
|
||||||
|
ArrayList<DhBlockPos> blockLightPosList = chunk.getWorldBlockLightPosList();
|
||||||
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
|
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);
|
DhBlockPos blockLightPos = blockLightPosList.get(blockLightIndex);
|
||||||
@@ -127,14 +147,18 @@ public class DhLightingEngine
|
|||||||
// get the light
|
// get the light
|
||||||
IBlockStateWrapper blockState = chunk.getBlockState(relLightBlockPos);
|
IBlockStateWrapper blockState = chunk.getBlockState(relLightBlockPos);
|
||||||
int lightValue = blockState.getLightEmission();
|
int lightValue = blockState.getLightEmission();
|
||||||
blockLightPosQueue.push(blockLightPos.x, blockLightPos.y, blockLightPos.z, lightValue);
|
blockLightWorldPosQueue.push(blockLightPos.getX(), blockLightPos.getY(), blockLightPos.getZ(), lightValue);
|
||||||
|
|
||||||
// set the light
|
// set the light
|
||||||
blockLightPos.mutateToChunkRelativePos(relBlockPos);
|
chunk.setDhBlockLight(relLightBlockPos.getX(), relLightBlockPos.getY(), relLightBlockPos.getZ(), lightValue);
|
||||||
chunk.setDhBlockLight(relBlockPos.x, relBlockPos.y, relBlockPos.z, lightValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// set sky lights //
|
||||||
|
//================//
|
||||||
|
|
||||||
// get and set the adjacent chunk's initial skylights,
|
// get and set the adjacent chunk's initial skylights,
|
||||||
// if the dimension has skylights
|
// if the dimension has skylights
|
||||||
if (maxSkyLight > 0)
|
if (maxSkyLight > 0)
|
||||||
@@ -147,7 +171,7 @@ public class DhLightingEngine
|
|||||||
{
|
{
|
||||||
for (int relZ = 0; relZ < LodUtil.CHUNK_WIDTH; relZ++)
|
for (int relZ = 0; relZ < LodUtil.CHUNK_WIDTH; relZ++)
|
||||||
{
|
{
|
||||||
// set each pos' sky light all the way down until a opaque block is hit
|
// set each pos' sky light all the way down until an opaque block is hit
|
||||||
for (int y = maxY; y >= minY; y--)
|
for (int y = maxY; y >= minY; y--)
|
||||||
{
|
{
|
||||||
IBlockStateWrapper block = chunk.getBlockState(relX, y, relZ);
|
IBlockStateWrapper block = chunk.getBlockState(relX, y, relZ);
|
||||||
@@ -160,11 +184,11 @@ public class DhLightingEngine
|
|||||||
|
|
||||||
// add sky light to the queue
|
// add sky light to the queue
|
||||||
DhBlockPos skyLightPos = new DhBlockPos(chunk.getMinBlockX() + relX, y, chunk.getMinBlockZ() + relZ);
|
DhBlockPos skyLightPos = new DhBlockPos(chunk.getMinBlockX() + relX, y, chunk.getMinBlockZ() + relZ);
|
||||||
skyLightPosQueue.push(skyLightPos.x, skyLightPos.y, skyLightPos.z, maxSkyLight);
|
skyLightWorldPosQueue.push(skyLightPos.getX(), skyLightPos.getY(), skyLightPos.getZ(), maxSkyLight);
|
||||||
|
|
||||||
// set the chunk's sky light
|
// set the chunk's sky light
|
||||||
skyLightPos.mutateToChunkRelativePos(relBlockPos);
|
skyLightPos.mutateToChunkRelativePos(relLightBlockPos);
|
||||||
chunk.setDhSkyLight(relBlockPos.x, relBlockPos.y, relBlockPos.z, maxSkyLight);
|
chunk.setDhSkyLight(relLightBlockPos.getX(), relLightBlockPos.getY(), relLightBlockPos.getZ(), maxSkyLight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,14 +204,16 @@ public class DhLightingEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
// block light
|
// block light
|
||||||
this.propagateLightPosList(blockLightPosQueue, adjacentChunkHolder,
|
this.propagateLightPosList(blockLightWorldPosQueue, adjacentChunkHolder,
|
||||||
(neighbourChunk, relBlockPos) -> neighbourChunk.getDhBlockLight(relBlockPos.x, relBlockPos.y, relBlockPos.z),
|
(neighbourChunk, relBlockPos) -> neighbourChunk.getDhBlockLight(relBlockPos.getX(), relBlockPos.getY(), relBlockPos.getZ()),
|
||||||
(neighbourChunk, relBlockPos, newLightValue) -> neighbourChunk.setDhBlockLight(relBlockPos.x, relBlockPos.y, relBlockPos.z, newLightValue));
|
(neighbourChunk, relBlockPos, newLightValue) -> neighbourChunk.setDhBlockLight(relBlockPos.getX(), relBlockPos.getY(), relBlockPos.getZ(), newLightValue),
|
||||||
|
true);
|
||||||
|
|
||||||
// sky light
|
// sky light
|
||||||
this.propagateLightPosList(skyLightPosQueue, adjacentChunkHolder,
|
this.propagateLightPosList(skyLightWorldPosQueue, adjacentChunkHolder,
|
||||||
(neighbourChunk, relBlockPos) -> neighbourChunk.getDhSkyLight(relBlockPos.x, relBlockPos.y, relBlockPos.z),
|
(neighbourChunk, relBlockPos) -> neighbourChunk.getDhSkyLight(relBlockPos.getX(), relBlockPos.getY(), relBlockPos.getZ()),
|
||||||
(neighbourChunk, relBlockPos, newLightValue) -> neighbourChunk.setDhSkyLight(relBlockPos.x, relBlockPos.y, relBlockPos.z, newLightValue));
|
(neighbourChunk, relBlockPos, newLightValue) -> neighbourChunk.setDhSkyLight(relBlockPos.getX(), relBlockPos.getY(), relBlockPos.getZ(), newLightValue),
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -195,8 +221,8 @@ public class DhLightingEngine
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
StableLightPosStack.returnStableLightPosArray(blockLightPosQueue);
|
StableLightPosStack.returnStableLightPosArray(blockLightWorldPosQueue);
|
||||||
StableLightPosStack.returnStableLightPosArray(skyLightPosQueue);
|
StableLightPosStack.returnStableLightPosArray(skyLightWorldPosQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -212,13 +238,14 @@ public class DhLightingEngine
|
|||||||
/** Applies each {@link LightPos} from the queue to the given set of {@link IChunkWrapper}'s. */
|
/** Applies each {@link LightPos} from the queue to the given set of {@link IChunkWrapper}'s. */
|
||||||
private void propagateLightPosList(
|
private void propagateLightPosList(
|
||||||
StableLightPosStack lightPosQueue, AdjacentChunkHolder adjacentChunkHolder,
|
StableLightPosStack lightPosQueue, AdjacentChunkHolder adjacentChunkHolder,
|
||||||
IGetLightFunc getLightFunc, ISetLightFunc setLightFunc)
|
IGetLightFunc getLightFunc, ISetLightFunc setLightFunc,
|
||||||
|
boolean propagatingBlockLights)
|
||||||
{
|
{
|
||||||
// these objects are saved so they can be mutated throughout the method,
|
// these objects are saved so they can be mutated throughout the method,
|
||||||
// this reduces the number of allocations necessary, reducing GC pressure
|
// this reduces the number of allocations necessary, reducing GC pressure
|
||||||
final LightPos lightPos = new LightPos(0, 0, 0, 0);
|
final LightPos lightPos = new LightPos(0, 0, 0, 0);
|
||||||
final DhBlockPos neighbourBlockPos = PRIMARY_BLOCK_POS_REF.get();
|
final DhBlockPosMutable neighbourBlockPos = PRIMARY_BLOCK_POS_REF.get();
|
||||||
final DhBlockPos relNeighbourBlockPos = SECONDARY_BLOCK_POS_REF.get();
|
final DhBlockPosMutable relNeighbourBlockPos = SECONDARY_BLOCK_POS_REF.get();
|
||||||
|
|
||||||
|
|
||||||
// update each light position
|
// update each light position
|
||||||
@@ -239,14 +266,14 @@ public class DhLightingEngine
|
|||||||
|
|
||||||
|
|
||||||
// only continue if the light position is inside one of our chunks
|
// only continue if the light position is inside one of our chunks
|
||||||
IChunkWrapper neighbourChunk = adjacentChunkHolder.getByBlockPos(neighbourBlockPos.x, neighbourBlockPos.z);
|
IChunkWrapper neighbourChunk = adjacentChunkHolder.getByBlockPos(neighbourBlockPos.getX(), neighbourBlockPos.getZ());
|
||||||
if (neighbourChunk == null)
|
if (neighbourChunk == null)
|
||||||
{
|
{
|
||||||
// the light pos is outside our generator's range, ignore it
|
// the light pos is outside our generator's range, ignore it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relNeighbourBlockPos.y < neighbourChunk.getMinNonEmptyHeight() || relNeighbourBlockPos.y > neighbourChunk.getMaxBuildHeight())
|
if (relNeighbourBlockPos.getY() < neighbourChunk.getMinNonEmptyHeight() || relNeighbourBlockPos.getY() > neighbourChunk.getMaxBuildHeight())
|
||||||
{
|
{
|
||||||
// the light pos is outside the chunk's min/max height,
|
// the light pos is outside the chunk's min/max height,
|
||||||
// this can happen if given a chunk that hasn't finished generating
|
// this can happen if given a chunk that hasn't finished generating
|
||||||
@@ -273,16 +300,103 @@ public class DhLightingEngine
|
|||||||
|
|
||||||
// now that light has been propagated to this blockPos
|
// now that light has been propagated to this blockPos
|
||||||
// we need to queue it up so its neighbours can be propagated as well
|
// we need to queue it up so its neighbours can be propagated as well
|
||||||
lightPosQueue.push(neighbourBlockPos.x, neighbourBlockPos.y, neighbourBlockPos.z, targetLevel);
|
lightPosQueue.push(neighbourBlockPos.getX(), neighbourBlockPos.getY(), neighbourBlockPos.getZ(), 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
|
// 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 //
|
// helper classes //
|
||||||
//================//
|
//================//
|
||||||
@@ -293,7 +407,7 @@ public class DhLightingEngine
|
|||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface ISetLightFunc { void setLight(IChunkWrapper chunk, DhBlockPos pos, int lightValue); }
|
interface ISetLightFunc { void setLight(IChunkWrapper chunk, DhBlockPos pos, int lightValue); }
|
||||||
|
|
||||||
private static class LightPos extends DhBlockPos
|
private static class LightPos extends DhBlockPosMutable
|
||||||
{
|
{
|
||||||
public int lightValue;
|
public int lightValue;
|
||||||
|
|
||||||
@@ -303,6 +417,11 @@ public class DhLightingEngine
|
|||||||
this.lightValue = lightValue;
|
this.lightValue = lightValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() { return this.lightValue+" - ["+ this.x +", "+ this.y +", "+ this.z +"]"; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -402,9 +521,9 @@ public class DhLightingEngine
|
|||||||
{
|
{
|
||||||
int subIndex = this.index * INTS_PER_LIGHT_POS;
|
int subIndex = this.index * INTS_PER_LIGHT_POS;
|
||||||
|
|
||||||
pos.x = this.lightPositions.getInt(subIndex);
|
pos.setX(this.lightPositions.getInt(subIndex));
|
||||||
pos.y = this.lightPositions.getInt(subIndex + 1);
|
pos.setY(this.lightPositions.getInt(subIndex + 1));
|
||||||
pos.z = this.lightPositions.getInt(subIndex + 2);
|
pos.setZ(this.lightPositions.getInt(subIndex + 2));
|
||||||
pos.lightValue = this.lightPositions.getInt(subIndex + 3);
|
pos.lightValue = this.lightPositions.getInt(subIndex + 3);
|
||||||
|
|
||||||
this.index--;
|
this.index--;
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ package com.seibel.distanthorizons.core.generation;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.core.generation.tasks.IWorldGenTaskTracker;
|
import com.seibel.distanthorizons.core.generation.tasks.IWorldGenTaskTracker;
|
||||||
import com.seibel.distanthorizons.core.generation.tasks.WorldGenResult;
|
import com.seibel.distanthorizons.core.generation.tasks.WorldGenResult;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.render.LodQuadTree;
|
import com.seibel.distanthorizons.core.render.LodQuadTree;
|
||||||
|
|
||||||
|
|||||||
+38
-12
@@ -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.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.generation.tasks.*;
|
import com.seibel.distanthorizons.core.generation.tasks.*;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
@@ -55,6 +55,16 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||||
private static final IWrapperFactory WRAPPER_FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
|
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;
|
private final IDhApiWorldGenerator generator;
|
||||||
|
|
||||||
/** contains the positions that need to be generated */
|
/** contains the positions that need to be generated */
|
||||||
@@ -78,7 +88,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
// TODO this logic isn't great and can cause a limit to how many threads could be used for world generation,
|
// TODO this logic isn't great and can cause a limit to how many threads could be used for world generation,
|
||||||
// however it won't cause duplicate requests or concurrency issues, so it will be good enough for now.
|
// however it won't cause duplicate requests or concurrency issues, so it will be good enough for now.
|
||||||
// A good long term fix may be to either:
|
// A good long term fix may be to either:
|
||||||
// 1. allow the generator to deal with larger sections (let the generator threads split up larger tasks into smaller one
|
// 1. allow the generator to deal with larger sections (let the generator threads split up larger tasks into smaller ones
|
||||||
// 2. batch requests better. instead of sending 4 individual tasks of detail level N, send 1 task of detail level n+1
|
// 2. batch requests better. instead of sending 4 individual tasks of detail level N, send 1 task of detail level n+1
|
||||||
private final ExecutorService queueingThread = ThreadUtil.makeSingleThreadPool("World Gen Queue");
|
private final ExecutorService queueingThread = ThreadUtil.makeSingleThreadPool("World Gen Queue");
|
||||||
private boolean generationQueueRunning = false;
|
private boolean generationQueueRunning = false;
|
||||||
@@ -206,7 +216,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
|
|
||||||
// queue generation tasks until the generator is full, or there are no more tasks to generate
|
// queue generation tasks until the generator is full, or there are no more tasks to generate
|
||||||
boolean taskStarted = true;
|
boolean taskStarted = true;
|
||||||
while (!this.generator.isBusy() && taskStarted)
|
while (!this.isGeneratorBusy() && taskStarted)
|
||||||
{
|
{
|
||||||
taskStarted = this.startNextWorldGenTask(this.generationTargetPos);
|
taskStarted = this.startNextWorldGenTask(this.generationTargetPos);
|
||||||
if (!taskStarted)
|
if (!taskStarted)
|
||||||
@@ -226,10 +236,26 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOGGER.error("queueing exception: " + e.getMessage(), e);
|
LOGGER.error("queueing exception: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
this.generationQueueRunning = false;
|
this.generationQueueRunning = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
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
|
* @param targetPos the position to center the generation around
|
||||||
@@ -373,7 +399,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
// don't log the shutdown exceptions
|
// don't log the shutdown exceptions
|
||||||
if (!LodUtil.isInterruptOrReject(exception))
|
if (!LodUtil.isInterruptOrReject(exception))
|
||||||
{
|
{
|
||||||
LOGGER.error("Error generating data for section " + taskPos, exception);
|
LOGGER.error("Error generating data for pos: " + DhSectionPos.toString(taskPos), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
newTaskGroup.group.worldGenTasks.forEach(worldGenTask -> worldGenTask.future.complete(WorldGenResult.CreateFail()));
|
newTaskGroup.group.worldGenTasks.forEach(worldGenTask -> worldGenTask.future.complete(WorldGenResult.CreateFail()));
|
||||||
@@ -383,11 +409,11 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
newTaskGroup.group.worldGenTasks.forEach(worldGenTask -> worldGenTask.future.complete(WorldGenResult.CreateSuccess(DhSectionPos.encode(granularity, DhSectionPos.getX(taskPos), DhSectionPos.getZ(taskPos)))));
|
newTaskGroup.group.worldGenTasks.forEach(worldGenTask -> worldGenTask.future.complete(WorldGenResult.CreateSuccess(DhSectionPos.encode(granularity, DhSectionPos.getX(taskPos), DhSectionPos.getZ(taskPos)))));
|
||||||
}
|
}
|
||||||
boolean worked = this.inProgressGenTasksByLodPos.remove(taskPos, newTaskGroup);
|
boolean worked = this.inProgressGenTasksByLodPos.remove(taskPos, newTaskGroup);
|
||||||
LodUtil.assertTrue(worked);
|
LodUtil.assertTrue(worked, "Unable to find in progress generator task with position ["+DhSectionPos.toString(taskPos)+"]");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOGGER.error("Unexpected error completing world gen task: "+taskPos, e);
|
LOGGER.error("Unexpected error completing world gen task at pos: ["+DhSectionPos.toString(taskPos)+"].", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -430,8 +456,8 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
case VANILLA_CHUNKS:
|
case VANILLA_CHUNKS:
|
||||||
{
|
{
|
||||||
return this.generator.generateChunks(
|
return this.generator.generateChunks(
|
||||||
chunkPosMin.x,
|
chunkPosMin.getX(),
|
||||||
chunkPosMin.z,
|
chunkPosMin.getZ(),
|
||||||
granularity,
|
granularity,
|
||||||
targetDataDetail,
|
targetDataDetail,
|
||||||
generatorMode,
|
generatorMode,
|
||||||
@@ -456,8 +482,8 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
case API_CHUNKS:
|
case API_CHUNKS:
|
||||||
{
|
{
|
||||||
return this.generator.generateApiChunks(
|
return this.generator.generateApiChunks(
|
||||||
chunkPosMin.x,
|
chunkPosMin.getX(),
|
||||||
chunkPosMin.z,
|
chunkPosMin.getZ(),
|
||||||
granularity,
|
granularity,
|
||||||
targetDataDetail,
|
targetDataDetail,
|
||||||
generatorMode,
|
generatorMode,
|
||||||
@@ -466,10 +492,10 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FullDataSourceV2 dataSource = LodDataBuilder.createFromApiChunkData(dataPoints);
|
FullDataSourceV2 dataSource = LodDataBuilder.createFromApiChunkData(dataPoints, this.generator.runApiChunkValidation());
|
||||||
chunkDataConsumer.accept(dataSource);
|
chunkDataConsumer.accept(dataSource);
|
||||||
}
|
}
|
||||||
catch (DataCorruptedException e)
|
catch (DataCorruptedException | IllegalArgumentException e)
|
||||||
{
|
{
|
||||||
LOGGER.error("World generator returned a corrupt chunk. Error: [" + e.getMessage() + "]. World generator disabled.", e);
|
LOGGER.error("World generator returned a corrupt chunk. Error: [" + e.getMessage() + "]. World generator disabled.", e);
|
||||||
Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false);
|
Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false);
|
||||||
|
|||||||
@@ -19,28 +19,19 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.level;
|
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.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.fullData.sources.FullDataSourceV2;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.transformers.ChunkToLodBuilder;
|
|
||||||
import com.seibel.distanthorizons.core.file.fullDatafile.DelayedFullDataSourceSaveCache;
|
import com.seibel.distanthorizons.core.file.fullDatafile.DelayedFullDataSourceSaveCache;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
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.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.BeaconRenderHandler;
|
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.CloudRenderHandler;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
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.BeaconBeamDTO;
|
||||||
import com.seibel.distanthorizons.core.sql.dto.ChunkHashDTO;
|
import com.seibel.distanthorizons.core.sql.dto.ChunkHashDTO;
|
||||||
import com.seibel.distanthorizons.core.sql.repo.BeaconBeamRepo;
|
import com.seibel.distanthorizons.core.sql.repo.BeaconBeamRepo;
|
||||||
import com.seibel.distanthorizons.core.sql.repo.ChunkHashRepo;
|
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.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -49,18 +40,14 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public abstract class AbstractDhLevel implements IDhLevel
|
public abstract class AbstractDhLevel implements IDhLevel
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
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 */
|
/** if this is null then the other handler is probably null too, but just in case */
|
||||||
@Nullable
|
@Nullable
|
||||||
public ChunkHashRepo chunkHashRepo;
|
public ChunkHashRepo chunkHashRepo;
|
||||||
@@ -68,9 +55,10 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
@Nullable
|
@Nullable
|
||||||
public BeaconBeamRepo beaconBeamRepo;
|
public BeaconBeamRepo beaconBeamRepo;
|
||||||
|
|
||||||
protected final DelayedFullDataSourceSaveCache delayedFullDataSourceSaveCache = new DelayedFullDataSourceSaveCache(this::onDataSourceSave, 2_000);
|
protected final DelayedFullDataSourceSaveCache delayedFullDataSourceSaveCache = new DelayedFullDataSourceSaveCache(this::onDataSourceSave, 500);
|
||||||
/** contains the {@link DhChunkPos} for each {@link DhSectionPos} that are queued to save via {@link AbstractDhLevel#delayedFullDataSourceSaveCache} */
|
/** 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<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. */
|
/** Will be null if clouds shouldn't be rendered for this level. */
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -83,10 +71,7 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
|
||||||
protected AbstractDhLevel()
|
protected AbstractDhLevel() { }
|
||||||
{
|
|
||||||
this.chunkToLodBuilder = new ChunkToLodBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creating the repos requires access to the level file, which isn't
|
* Creating the repos requires access to the level file, which isn't
|
||||||
@@ -126,11 +111,15 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
GenericObjectRenderer genericRenderer = this.getGenericRenderer();
|
GenericObjectRenderer genericRenderer = this.getGenericRenderer();
|
||||||
if (genericRenderer != null)
|
if (genericRenderer != null)
|
||||||
{
|
{
|
||||||
// only add clouds for certain dimension types
|
// only client levels can render clouds
|
||||||
if (!this.getLevelWrapper().hasCeiling()
|
if (this instanceof IDhClientLevel)
|
||||||
&& !this.getLevelWrapper().getDimensionType().isTheEnd())
|
|
||||||
{
|
{
|
||||||
this.cloudRenderHandler = new CloudRenderHandler(this, genericRenderer);
|
// only add clouds for certain dimension types
|
||||||
|
if (!this.getLevelWrapper().hasCeiling()
|
||||||
|
&& !this.getLevelWrapper().getDimensionType().isTheEnd())
|
||||||
|
{
|
||||||
|
this.cloudRenderHandler = new CloudRenderHandler((IDhClientLevel)this, genericRenderer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -152,7 +141,7 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
public int getUnsavedDataSourceCount() { return this.delayedFullDataSourceSaveCache.getUnsavedCount(); }
|
public int getUnsavedDataSourceCount() { return this.delayedFullDataSourceSaveCache.getUnsavedCount(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateChunkAsync(IChunkWrapper chunkWrapper)
|
public void updateChunkAsync(IChunkWrapper chunkWrapper, int chunkHash)
|
||||||
{
|
{
|
||||||
FullDataSourceV2 dataSource = FullDataSourceV2.createFromChunk(chunkWrapper);
|
FullDataSourceV2 dataSource = FullDataSourceV2.createFromChunk(chunkWrapper);
|
||||||
if (dataSource == null)
|
if (dataSource == null)
|
||||||
@@ -171,6 +160,7 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
chunkPosSet.add(chunkWrapper.getChunkPos());
|
chunkPosSet.add(chunkWrapper.getChunkPos());
|
||||||
return chunkPosSet;
|
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
|
// batch updates to reduce overhead when flying around or breaking/placing a lot of blocks in an area
|
||||||
this.delayedFullDataSourceSaveCache.queueDataSourceForUpdateAndSave(dataSource);
|
this.delayedFullDataSourceSaveCache.queueDataSourceForUpdateAndSave(dataSource);
|
||||||
@@ -185,9 +175,16 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
{
|
{
|
||||||
for (DhChunkPos chunkPos : updatedChunkPosSet)
|
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(
|
ApiEventInjector.INSTANCE.fireAllEvents(
|
||||||
DhApiChunkModifiedEvent.class,
|
DhApiChunkModifiedEvent.class,
|
||||||
new DhApiChunkModifiedEvent.EventParam(this.getLevelWrapper(), chunkPos.x, chunkPos.z));
|
new DhApiChunkModifiedEvent.EventParam(this.getLevelWrapper(), chunkPos.getX(), chunkPos.getZ()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -212,14 +209,6 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
ChunkHashDTO dto = this.chunkHashRepo.getByKey(pos);
|
ChunkHashDTO dto = this.chunkHashRepo.getByKey(pos);
|
||||||
return (dto != null) ? dto.chunkHash : 0;
|
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -228,11 +217,12 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
//=================//
|
//=================//
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List<BeaconBeamDTO> newBeamList)
|
public void updateBeaconBeamsForChunk(IChunkWrapper chunkToUpdate, ArrayList<IChunkWrapper> nearbyChunkList)
|
||||||
{
|
{
|
||||||
if (this.beaconRenderHandler != null)
|
if (this.beaconRenderHandler != null)
|
||||||
{
|
{
|
||||||
this.beaconRenderHandler.setBeaconBeamsForChunk(chunkPos, newBeamList);
|
List<BeaconBeamDTO> activeBeamList = chunkToUpdate.getAllActiveBeacons(nearbyChunkList);
|
||||||
|
this.beaconRenderHandler.setBeaconBeamsForChunk(chunkToUpdate.getChunkPos(), activeBeamList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,8 +252,6 @@ public abstract class AbstractDhLevel implements IDhLevel
|
|||||||
@Override
|
@Override
|
||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
this.chunkToLodBuilder.close();
|
|
||||||
|
|
||||||
if (this.chunkHashRepo != null)
|
if (this.chunkHashRepo != null)
|
||||||
{
|
{
|
||||||
this.chunkHashRepo.close();
|
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.AbstractDataSourceHandler;
|
||||||
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.render.LodQuadTree;
|
import com.seibel.distanthorizons.core.render.LodQuadTree;
|
||||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||||
@@ -258,6 +258,8 @@ public class ClientLevelModule implements Closeable, AbstractDataSourceHandler.I
|
|||||||
|
|
||||||
public void clearRenderCache()
|
public void clearRenderCache()
|
||||||
{
|
{
|
||||||
|
this.clientLevel.getClientLevelWrapper().clearBlockColorCache();
|
||||||
|
|
||||||
ClientRenderState ClientRenderState = this.ClientRenderStateRef.get();
|
ClientRenderState ClientRenderState = this.ClientRenderStateRef.get();
|
||||||
if (ClientRenderState != null && ClientRenderState.quadtree != null)
|
if (ClientRenderState != null && ClientRenderState.quadtree != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV
|
|||||||
import com.seibel.distanthorizons.core.file.fullDatafile.RemoteFullDataSourceProvider;
|
import com.seibel.distanthorizons.core.file.fullDatafile.RemoteFullDataSourceProvider;
|
||||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||||
@@ -86,7 +86,6 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.chunkToLodBuilder.tick();
|
|
||||||
this.clientside.clientTick();
|
this.clientside.clientTick();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -110,7 +109,7 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
|||||||
//================//
|
//================//
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeBaseColor(DhBlockPos pos, IBiomeWrapper biome, IBlockStateWrapper block) { return this.levelWrapper.computeBaseColor(pos, biome, block); }
|
public int computeBaseColor(DhBlockPos pos, IBiomeWrapper biome, IBlockStateWrapper block) { return this.levelWrapper.getBlockColor(pos, biome, block); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IClientLevelWrapper getClientLevelWrapper() { return this.levelWrapper; }
|
public IClientLevelWrapper getClientLevelWrapper() { return this.levelWrapper; }
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
|||||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
||||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||||
@@ -95,7 +95,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
|||||||
{ this.clientside.renderDeferred(renderEventParam, profiler); }
|
{ this.clientside.renderDeferred(renderEventParam, profiler); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serverTick() { this.chunkToLodBuilder.tick(); }
|
public void serverTick() { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doWorldGen()
|
public void doWorldGen()
|
||||||
@@ -146,7 +146,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return clientLevel.computeBaseColor(pos, biome, block);
|
return clientLevel.getBlockColor(pos, biome, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,10 +154,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
|
|||||||
public IClientLevelWrapper getClientLevelWrapper() { return MC_CLIENT.getWrappedClientLevel(); }
|
public IClientLevelWrapper getClientLevelWrapper() { return MC_CLIENT.getWrappedClientLevel(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearRenderCache()
|
public void clearRenderCache() { this.clientside.clearRenderCache(); }
|
||||||
{
|
|
||||||
clientside.clearRenderCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IServerLevelWrapper getServerLevelWrapper() { return serverLevelWrapper; }
|
public IServerLevelWrapper getServerLevelWrapper() { return serverLevelWrapper; }
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ package com.seibel.distanthorizons.core.level;
|
|||||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||||
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
||||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||||
@@ -65,7 +65,7 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
|
|||||||
// methods //
|
// methods //
|
||||||
//=========//
|
//=========//
|
||||||
|
|
||||||
public void serverTick() { this.chunkToLodBuilder.tick(); }
|
public void serverTick() { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> updateDataSourcesAsync(FullDataSourceV2 data) { return this.getFullDataProvider().updateDataSourceAsync(data); }
|
public CompletableFuture<Void> updateDataSourcesAsync(FullDataSourceV2 data) { return this.getFullDataProvider().updateDataSourceAsync(data); }
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
package com.seibel.distanthorizons.core.level;
|
package com.seibel.distanthorizons.core.level;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
|||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
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.chunk.IChunkWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@@ -45,11 +45,10 @@ public interface IDhLevel extends AutoCloseable
|
|||||||
|
|
||||||
/** @return 0 if no hash is known */
|
/** @return 0 if no hash is known */
|
||||||
int getChunkHash(DhChunkPos pos);
|
int getChunkHash(DhChunkPos pos);
|
||||||
void setChunkHash(DhChunkPos pos, int chunkHash);
|
void updateChunkAsync(IChunkWrapper chunk, int newChunkHash);
|
||||||
void updateChunkAsync(IChunkWrapper chunk);
|
|
||||||
|
|
||||||
void loadBeaconBeamsInPos(long pos);
|
void loadBeaconBeamsInPos(long pos);
|
||||||
void setBeaconBeamsForChunk(DhChunkPos chunkPos, List<BeaconBeamDTO> beamList);
|
void updateBeaconBeamsForChunk(IChunkWrapper chunkToUpdate, ArrayList<IChunkWrapper> nearbyChunkList);
|
||||||
void unloadBeaconBeamsInPos(long pos);
|
void unloadBeaconBeamsInPos(long pos);
|
||||||
|
|
||||||
FullDataSourceProviderV2 getFullDataProvider();
|
FullDataSourceProviderV2 getFullDataProvider();
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import com.seibel.distanthorizons.core.file.fullDatafile.GeneratedFullDataSource
|
|||||||
import com.seibel.distanthorizons.core.generation.IFullDataSourceRetrievalQueue;
|
import com.seibel.distanthorizons.core.generation.IFullDataSourceRetrievalQueue;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package com.seibel.distanthorizons.core.logging.f3;
|
package com.seibel.distanthorizons.core.logging.f3;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.SharedVbo;
|
|
||||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||||
@@ -73,6 +72,9 @@ public class F3Screen
|
|||||||
ThreadPoolExecutor worldGenPool = ThreadPoolUtil.getWorldGenExecutor();
|
ThreadPoolExecutor worldGenPool = ThreadPoolUtil.getWorldGenExecutor();
|
||||||
ThreadPoolExecutor fileHandlerPool = ThreadPoolUtil.getFileHandlerExecutor();
|
ThreadPoolExecutor fileHandlerPool = ThreadPoolUtil.getFileHandlerExecutor();
|
||||||
ThreadPoolExecutor updatePool = ThreadPoolUtil.getUpdatePropagatorExecutor();
|
ThreadPoolExecutor updatePool = ThreadPoolUtil.getUpdatePropagatorExecutor();
|
||||||
|
ThreadPoolExecutor lodBuilderPool = ThreadPoolUtil.getChunkToLodBuilderExecutor();
|
||||||
|
ThreadPoolExecutor bufferBuilderPool = ThreadPoolUtil.getBufferBuilderExecutor();
|
||||||
|
ThreadPoolExecutor bufferUploaderPool = ThreadPoolUtil.getBufferUploaderExecutor();
|
||||||
|
|
||||||
AbstractDhWorld world = SharedApi.getAbstractDhWorld();
|
AbstractDhWorld world = SharedApi.getAbstractDhWorld();
|
||||||
Iterable<? extends IDhLevel> levelIterator = world.getAllLoadedLevels();
|
Iterable<? extends IDhLevel> levelIterator = world.getAllLoadedLevels();
|
||||||
@@ -85,6 +87,9 @@ public class F3Screen
|
|||||||
messageList.add(getThreadPoolStatString("World Gen", worldGenPool));//"World Gen Tasks: 40/5304, (in progress: 7)");
|
messageList.add(getThreadPoolStatString("World Gen", worldGenPool));//"World Gen Tasks: 40/5304, (in progress: 7)");
|
||||||
messageList.add(getThreadPoolStatString("File Handler", fileHandlerPool));
|
messageList.add(getThreadPoolStatString("File Handler", fileHandlerPool));
|
||||||
messageList.add(getThreadPoolStatString("Update Propagator", updatePool));
|
messageList.add(getThreadPoolStatString("Update Propagator", updatePool));
|
||||||
|
messageList.add(getThreadPoolStatString("LOD Builder", lodBuilderPool));
|
||||||
|
messageList.add(getThreadPoolStatString("Buffer Builder", bufferBuilderPool));
|
||||||
|
messageList.add(getThreadPoolStatString("Buffer Uploader", bufferUploaderPool));
|
||||||
messageList.add("");
|
messageList.add("");
|
||||||
// chunk updates
|
// chunk updates
|
||||||
messageList.add(SharedApi.INSTANCE.getDebugMenuString());
|
messageList.add(SharedApi.INSTANCE.getDebugMenuString());
|
||||||
@@ -112,11 +117,6 @@ public class F3Screen
|
|||||||
messageList.add(genericRenderer.getVboRenderDebugMenuString());
|
messageList.add(genericRenderer.getVboRenderDebugMenuString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageList.add("");
|
|
||||||
// GPU memory
|
|
||||||
messageList.add("GPU Opaque " + SharedVbo.OPAQUE.getDebugMenuString());
|
|
||||||
messageList.add("GPU Transp " + SharedVbo.TRANSPARENT.getDebugMenuString());
|
|
||||||
messageList.add("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pos;
|
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class DhBlockPos
|
|
||||||
{
|
|
||||||
public static final boolean DO_CHECKS = false;
|
|
||||||
|
|
||||||
// 26 bits wide as that just encompasses the maximum possible value
|
|
||||||
// of +- 30,000,000 blocks in each direction. Yes this packing method
|
|
||||||
// is how Minecraft packs it.
|
|
||||||
|
|
||||||
// NOTE: Remember to ALWAYS check that DHBlockPos packing is EXACTLY
|
|
||||||
// the same as Minecraft's!!!!
|
|
||||||
public static final int PACKED_X_LENGTH = 26;
|
|
||||||
public static final int PACKED_Z_LENGTH = 26;
|
|
||||||
public static final int PACKED_Y_LENGTH = 12;
|
|
||||||
public static final long PACKED_X_MASK = (1L << PACKED_X_LENGTH) - 1L;
|
|
||||||
public static final long PACKED_Y_MASK = (1L << PACKED_Y_LENGTH) - 1L;
|
|
||||||
public static final long PACKED_Z_MASK = (1L << PACKED_Z_LENGTH) - 1L;
|
|
||||||
public static final int PACKED_Y_OFFSET = 0;
|
|
||||||
public static final int PACKED_Z_OFFSET = PACKED_Y_LENGTH;
|
|
||||||
public static final int PACKED_X_OFFSET = PACKED_Y_LENGTH + PACKED_Z_LENGTH;
|
|
||||||
|
|
||||||
/** Useful for methods that need a position passed in but won't actually be used */
|
|
||||||
public static final DhBlockPos ZERO = new DhBlockPos(0, 0, 0);
|
|
||||||
|
|
||||||
|
|
||||||
public int x;
|
|
||||||
public int y;
|
|
||||||
public int z;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public DhBlockPos(int x, int y, int z)
|
|
||||||
{
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
public DhBlockPos()
|
|
||||||
{
|
|
||||||
this(0, 0, 0);
|
|
||||||
}
|
|
||||||
public DhBlockPos(DhBlockPos pos)
|
|
||||||
{
|
|
||||||
this(pos.x, pos.y, pos.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DhBlockPos(DhBlockPos2D pos, int y)
|
|
||||||
{
|
|
||||||
this(pos.x, y, pos.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long asLong(int x, int y, int z)
|
|
||||||
{
|
|
||||||
if (DO_CHECKS)
|
|
||||||
{
|
|
||||||
if ((x & ~PACKED_X_MASK) != 0)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("x is out of range: " + x);
|
|
||||||
}
|
|
||||||
if ((y & ~PACKED_Y_MASK) != 0)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("y is out of range: " + y);
|
|
||||||
}
|
|
||||||
if ((z & ~PACKED_Z_MASK) != 0)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("z is out of range: " + z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ((long) x & PACKED_X_MASK) << PACKED_X_OFFSET |
|
|
||||||
((long) y & PACKED_Y_MASK) << PACKED_Y_OFFSET |
|
|
||||||
((long) z & PACKED_Z_MASK) << PACKED_Z_OFFSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getX(long packed)
|
|
||||||
{ // X is at the top
|
|
||||||
return (int) (packed << (64 - PACKED_X_OFFSET - PACKED_X_LENGTH) >> (64 - PACKED_X_LENGTH));
|
|
||||||
}
|
|
||||||
public static int getY(long packed)
|
|
||||||
{ // Y is at the bottom
|
|
||||||
return (int) (packed << (64 - PACKED_Y_OFFSET - PACKED_Y_LENGTH) >> (64 - PACKED_Y_LENGTH));
|
|
||||||
}
|
|
||||||
public static int getZ(long packed)
|
|
||||||
{ // Z is at the middle
|
|
||||||
return (int) (packed << (64 - PACKED_Z_OFFSET - PACKED_Z_LENGTH) >> (64 - PACKED_Z_LENGTH));
|
|
||||||
}
|
|
||||||
public DhBlockPos(long packed)
|
|
||||||
{
|
|
||||||
this(getX(packed), getY(packed), getZ(packed));
|
|
||||||
}
|
|
||||||
|
|
||||||
public long asLong()
|
|
||||||
{
|
|
||||||
return asLong(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** creates a new {@link DhBlockPos} with the given offset from the current pos. */
|
|
||||||
public DhBlockPos offset(EDhDirection direction) { return this.mutateOffset(direction, null); }
|
|
||||||
/** if not null, mutates "mutablePos" so it matches the current pos after being offset. Otherwise creates a new {@link DhBlockPos}. */
|
|
||||||
public DhBlockPos mutateOffset(EDhDirection direction, @Nullable DhBlockPos mutablePos) { return this.mutateOffset(direction.getNormal().x, direction.getNormal().y, direction.getNormal().z, mutablePos); }
|
|
||||||
|
|
||||||
public DhBlockPos offset(int x, int y, int z) { return this.mutateOffset(x,y,z, null); }
|
|
||||||
public DhBlockPos mutateOffset(int x, int y, int z, @Nullable DhBlockPos mutablePos)
|
|
||||||
{
|
|
||||||
int newX = this.x + x;
|
|
||||||
int newY = this.y + y;
|
|
||||||
int newZ = this.z + z;
|
|
||||||
|
|
||||||
if (mutablePos != null)
|
|
||||||
{
|
|
||||||
mutablePos.x = newX;
|
|
||||||
mutablePos.y = newY;
|
|
||||||
mutablePos.z = newZ;
|
|
||||||
|
|
||||||
return mutablePos;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new DhBlockPos(newX, newY, newZ);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns a new {@link DhBlockPos} limits to a value between 0 and 15 (inclusive) */
|
|
||||||
public DhBlockPos convertToChunkRelativePos() { return this.mutateToChunkRelativePos(null); }
|
|
||||||
/**
|
|
||||||
* Limits the block position to a value between 0 and 15 (inclusive)
|
|
||||||
* If not null, mutates "mutableBlockPos"
|
|
||||||
*/
|
|
||||||
public DhBlockPos mutateToChunkRelativePos(@Nullable DhBlockPos mutableBlockPos)
|
|
||||||
{
|
|
||||||
// move the position into the range -15 and +15
|
|
||||||
int relX = (this.x % LodUtil.CHUNK_WIDTH);
|
|
||||||
// if the position is negative move it into the range 0 and 15
|
|
||||||
relX = (relX < 0) ? (relX + LodUtil.CHUNK_WIDTH) : relX;
|
|
||||||
|
|
||||||
int relZ = (this.z % LodUtil.CHUNK_WIDTH);
|
|
||||||
relZ = (relZ < 0) ? (relZ + LodUtil.CHUNK_WIDTH) : relZ;
|
|
||||||
|
|
||||||
// the y value shouldn't need to be changed
|
|
||||||
|
|
||||||
|
|
||||||
if (mutableBlockPos != null)
|
|
||||||
{
|
|
||||||
mutableBlockPos.x = relX;
|
|
||||||
mutableBlockPos.y = this.y;
|
|
||||||
mutableBlockPos.z = relZ;
|
|
||||||
|
|
||||||
return mutableBlockPos;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new DhBlockPos(relX, this.y, relZ);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can be used to quickly determine the rough distance between two points<Br>
|
|
||||||
* or determine the taxi cab (manhattan) distance between two points. <Br><Br>
|
|
||||||
*
|
|
||||||
* Manhattan distance is equivalent to determining the distance between two street intersections,
|
|
||||||
* where you can only drive along each street, instead of directly to the other point.
|
|
||||||
*/
|
|
||||||
public int getManhattanDistance(DhBlockPos otherPos)
|
|
||||||
{
|
|
||||||
return Math.abs(this.x - otherPos.x) + Math.abs(this.y - otherPos.y) + Math.abs(this.z - otherPos.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
DhBlockPos that = (DhBlockPos) o;
|
|
||||||
return x == that.x && y == that.y && z == that.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Objects.hash(x, y, z);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "DHBlockPos[" +
|
|
||||||
"" + x +
|
|
||||||
", " + y +
|
|
||||||
", " + z +
|
|
||||||
']';
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void _DebugCheckPacker(int x, int y, int z, long expected)
|
|
||||||
{
|
|
||||||
long packed = asLong(x, y, z);
|
|
||||||
if (packed != expected)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Packed values don't match: " + packed + " != " + expected);
|
|
||||||
}
|
|
||||||
DhBlockPos pos = new DhBlockPos(packed);
|
|
||||||
if (pos.x != x || pos.y != y || pos.z != z)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Values after decode don't match: " + pos + " != " + x + ", " + y + ", " + z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -19,12 +19,23 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.pos;
|
package com.seibel.distanthorizons.core.pos;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* immutable <br><br>
|
||||||
|
*
|
||||||
|
* Dev note: if for some reason we want to store these as longs check the old commits. <br>
|
||||||
|
* That logic was removed since it wasn't needed at the time
|
||||||
|
*/
|
||||||
public class DhChunkPos
|
public class DhChunkPos
|
||||||
{
|
{
|
||||||
public final int x; // Low 32 bits
|
private final int x;
|
||||||
public final int z; // High 32 bits
|
public int getX() { return x; }
|
||||||
|
|
||||||
|
private final int z;
|
||||||
|
public int getZ() { return z; }
|
||||||
|
|
||||||
/** cached to improve hashing speed */
|
/** cached to improve hashing speed */
|
||||||
public final int hashCode;
|
public final int hashCode;
|
||||||
@@ -45,15 +56,14 @@ public class DhChunkPos
|
|||||||
}
|
}
|
||||||
public DhChunkPos(DhBlockPos blockPos)
|
public DhChunkPos(DhBlockPos blockPos)
|
||||||
{
|
{
|
||||||
// >> 4 is the Same as div 16
|
// >> 4 is the Same as divide by 16
|
||||||
this(blockPos.x >> 4, blockPos.z >> 4);
|
this(blockPos.getX() >> 4, blockPos.getZ() >> 4);
|
||||||
}
|
}
|
||||||
public DhChunkPos(DhBlockPos2D blockPos)
|
public DhChunkPos(DhBlockPos2D blockPos)
|
||||||
{
|
{
|
||||||
// >> 4 is the Same as div 16
|
// >> 4 is the Same as div 16
|
||||||
this(blockPos.x >> 4, blockPos.z >> 4);
|
this(blockPos.x >> 4, blockPos.z >> 4);
|
||||||
}
|
}
|
||||||
public DhChunkPos(long packed) { this(getXFromPackedLong(packed), getZFromPackedLong(packed)); }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -61,13 +71,8 @@ public class DhChunkPos
|
|||||||
// methods //
|
// methods //
|
||||||
//=========//
|
//=========//
|
||||||
|
|
||||||
public DhBlockPos center() { return new DhBlockPos(8 + this.x << 4, 0, 8 + this.z << 4); }
|
public DhBlockPos centerBlockPos() { return new DhBlockPos(8 + this.x << 4, 0, 8 + this.z << 4); }
|
||||||
public DhBlockPos corner() { return new DhBlockPos(this.x << 4, 0, this.z << 4); }
|
public DhBlockPos minCornerBlockPos() { return new DhBlockPos(this.x << 4, 0, this.z << 4); }
|
||||||
|
|
||||||
public static long toLong(int x, int z) { return ((long) x & 0xFFFFFFFFL) << 32 | (long) z & 0xFFFFFFFFL; }
|
|
||||||
|
|
||||||
private static int getXFromPackedLong(long chunkPos) { return (int) (chunkPos >> 32); }
|
|
||||||
private static int getZFromPackedLong(long chunkPos) { return (int) (chunkPos & 0xFFFFFFFFL); }
|
|
||||||
|
|
||||||
public int getMinBlockX() { return this.x << 4; }
|
public int getMinBlockX() { return this.x << 4; }
|
||||||
public int getMinBlockZ() { return this.z << 4; }
|
public int getMinBlockZ() { return this.z << 4; }
|
||||||
@@ -81,11 +86,10 @@ public class DhChunkPos
|
|||||||
int maxBlockX = minBlockX + LodUtil.CHUNK_WIDTH;
|
int maxBlockX = minBlockX + LodUtil.CHUNK_WIDTH;
|
||||||
int maxBlockZ = minBlockZ + LodUtil.CHUNK_WIDTH;
|
int maxBlockZ = minBlockZ + LodUtil.CHUNK_WIDTH;
|
||||||
|
|
||||||
return minBlockX <= pos.x && pos.x <= maxBlockX
|
return minBlockX <= pos.getX() && pos.getX() < maxBlockX
|
||||||
&& minBlockZ <= pos.z && pos.z <= maxBlockZ;
|
&& minBlockZ <= pos.getZ() && pos.getZ() < maxBlockZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLong() { return toLong(this.x, this.z); }
|
|
||||||
|
|
||||||
|
|
||||||
//================//
|
//================//
|
||||||
@@ -116,39 +120,4 @@ public class DhChunkPos
|
|||||||
@Override
|
@Override
|
||||||
public String toString() { return "C[" + this.x + "," + this.z + "]"; }
|
public String toString() { return "C[" + this.x + "," + this.z + "]"; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=======================//
|
|
||||||
// static helper methods //
|
|
||||||
//=======================//
|
|
||||||
|
|
||||||
public static void _DebugCheckPacker(int x, int z, long expected)
|
|
||||||
{
|
|
||||||
long packed = toLong(x, z);
|
|
||||||
if (packed != expected)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Packed values don't match: " + packed + " != " + expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
DhChunkPos pos = new DhChunkPos(packed);
|
|
||||||
if (pos.x != x || pos.z != z)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Values after decode don't match: " + pos + " != " + x + ", " + z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return true if testPos is within the area defined by the min and max positions. */
|
|
||||||
public static boolean isChunkPosBetween(DhChunkPos minChunkPos, DhChunkPos testPos, DhChunkPos maxChunkPos)
|
|
||||||
{
|
|
||||||
int minChunkX = Math.min(minChunkPos.x, maxChunkPos.x);
|
|
||||||
int minChunkZ = Math.min(minChunkPos.z, maxChunkPos.z);
|
|
||||||
|
|
||||||
int maxChunkX = Math.max(minChunkPos.x, maxChunkPos.x);
|
|
||||||
int maxChunkZ = Math.max(minChunkPos.z, maxChunkPos.z);
|
|
||||||
|
|
||||||
return minChunkX <= testPos.x && testPos.x <= maxChunkX &&
|
|
||||||
minChunkZ <= testPos.z && testPos.z <= maxChunkZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
package com.seibel.distanthorizons.core.pos;
|
package com.seibel.distanthorizons.core.pos;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||||
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -47,6 +48,10 @@ public class DhLodPos implements Comparable<DhLodPos>
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// constructors //
|
||||||
|
//==============//
|
||||||
|
|
||||||
public DhLodPos(byte detailLevel, int x, int z)
|
public DhLodPos(byte detailLevel, int x, int z)
|
||||||
{
|
{
|
||||||
this.detailLevel = detailLevel;
|
this.detailLevel = detailLevel;
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ public class DhLodUnit
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// constructors //
|
||||||
|
//==============//
|
||||||
|
|
||||||
public DhLodUnit(byte detailLevel, int numberOfLodSectionsWide)
|
public DhLodUnit(byte detailLevel, int numberOfLodSectionsWide)
|
||||||
{
|
{
|
||||||
this.detailLevel = detailLevel;
|
this.detailLevel = detailLevel;
|
||||||
@@ -43,6 +47,11 @@ public class DhLodUnit
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=========//
|
||||||
|
// methods //
|
||||||
|
//=========//
|
||||||
|
|
||||||
/** @return the size of this LOD unit in Minecraft blocks */
|
/** @return the size of this LOD unit in Minecraft blocks */
|
||||||
public int toBlockWidth() { return BitShiftUtil.pow(this.numberOfLodSectionsWide, this.detailLevel); }
|
public int toBlockWidth() { return BitShiftUtil.pow(this.numberOfLodSectionsWide, this.detailLevel); }
|
||||||
/** @return the LOD Unit relative to the given block width and detail level */
|
/** @return the LOD Unit relative to the given block width and detail level */
|
||||||
|
|||||||
@@ -19,7 +19,10 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.pos;
|
package com.seibel.distanthorizons.core.pos;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||||
|
|
||||||
@@ -33,11 +36,11 @@ import java.util.function.LongConsumer;
|
|||||||
* For the specifics of how they compare can be viewed in the constants {@link #SECTION_BLOCK_DETAIL_LEVEL},
|
* For the specifics of how they compare can be viewed in the constants {@link #SECTION_BLOCK_DETAIL_LEVEL},
|
||||||
* {@link #SECTION_CHUNK_DETAIL_LEVEL}, and {@link #SECTION_REGION_DETAIL_LEVEL}).<br><br>
|
* {@link #SECTION_CHUNK_DETAIL_LEVEL}, and {@link #SECTION_REGION_DETAIL_LEVEL}).<br><br>
|
||||||
*
|
*
|
||||||
* <strong>Why does the smallest render section represent 2x2 MC chunks (section detail level 6)? </strong> <br>
|
* <strong>Why does the smallest render section represent 4x4 MC chunks (section detail level 6)? </strong> <br>
|
||||||
* A section defines what unit the quad tree works in, because of that we don't want that unit to be too big or too small. <br>
|
* A section defines what unit the quad tree works in, because of that we don't want that unit to be too big or too small. <br>
|
||||||
* <strong>Too small</strong>, and we'll have 1,000s of sections running around, all needing individual files and render buffers.<br>
|
* <strong>Too small</strong>, and we'll have 1,000s of sections running around, all needing individual files and render buffers.<br>
|
||||||
* <strong>Too big</strong>, and the LOD dropoff will be very noticeable.<br>
|
* <strong>Too big</strong>, and the LOD dropoff will be very noticeable.<br>
|
||||||
* With those thoughts in mind we decided on a smallest section size of 32 data points square (IE 2x2 chunks).
|
* With those thoughts in mind we decided on a smallest section size of 64 data points square (IE 4x4 chunks).
|
||||||
*
|
*
|
||||||
* @author Leetom
|
* @author Leetom
|
||||||
*/
|
*/
|
||||||
@@ -101,21 +104,32 @@ public class DhSectionPos
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long encode(DhBlockPos pos) { return encodeBlockPos(pos.x, pos.z); }
|
/** Returns the section pos at the requested detail level containing the given BlockPos */
|
||||||
public static long encode(DhBlockPos2D pos) { return encodeBlockPos(pos.x, pos.z); }
|
public static long encodeContaining(byte outputSectionDetailLevel, DhBlockPos pos)
|
||||||
public static long encodeBlockPos(int blockX, int blockZ)
|
|
||||||
{
|
{
|
||||||
long pos = encode(LodUtil.BLOCK_DETAIL_LEVEL, blockX, blockZ);
|
int sectionPosX = getXOrZSectionPosFromChunkOrBlockPos(pos.getX(), false);
|
||||||
pos = convertToDetailLevel(pos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
|
int sectionPosZ = getXOrZSectionPosFromChunkOrBlockPos(pos.getZ(), false);
|
||||||
return pos;
|
long blockPos = DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
|
||||||
|
return convertToDetailLevel(blockPos, outputSectionDetailLevel);
|
||||||
}
|
}
|
||||||
|
/** Returns the section pos at the requested detail level containing the given ChunkPos */
|
||||||
public static long encode(DhChunkPos pos) { return encodeChunkPos(pos.x, pos.z); }
|
public static long encodeContaining(byte outputSectionDetailLevel, DhChunkPos pos)
|
||||||
public static long encodeChunkPos(int chunkX, int chunkZ)
|
|
||||||
{
|
{
|
||||||
long pos = encode(LodUtil.CHUNK_DETAIL_LEVEL, chunkX, chunkZ);
|
int sectionPosX = getXOrZSectionPosFromChunkOrBlockPos(pos.getX(), true);
|
||||||
pos = convertToDetailLevel(pos, DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
|
int sectionPosZ = getXOrZSectionPosFromChunkOrBlockPos(pos.getZ(), true);
|
||||||
return pos;
|
long blockPos = DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
|
||||||
|
return convertToDetailLevel(blockPos, outputSectionDetailLevel);
|
||||||
|
}
|
||||||
|
private static int getXOrZSectionPosFromChunkOrBlockPos(int chunkXOrZPos, boolean isChunkPos)
|
||||||
|
{
|
||||||
|
int sectionPos = chunkXOrZPos;
|
||||||
|
int fullDataSourceWidth = isChunkPos ? FullDataSourceV2.NUMB_OF_CHUNKS_WIDE : (FullDataSourceV2.NUMB_OF_CHUNKS_WIDE * LodUtil.CHUNK_WIDTH);
|
||||||
|
|
||||||
|
// negative positions start at -1 so the logic there is slightly different
|
||||||
|
sectionPos = (sectionPos < 0)
|
||||||
|
? ((sectionPos + 1) / fullDataSourceWidth) - 1
|
||||||
|
: (sectionPos / fullDataSourceWidth);
|
||||||
|
return sectionPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,15 +23,23 @@ import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/** immutable */
|
||||||
public class Pos2D
|
public class Pos2D
|
||||||
{
|
{
|
||||||
public static final Pos2D ZERO = new Pos2D(0, 0);
|
public static final Pos2D ZERO = new Pos2D(0, 0);
|
||||||
|
|
||||||
public final int x;
|
private final int x;
|
||||||
public final int y;
|
public int getX() { return this.x; }
|
||||||
|
|
||||||
|
private final int y;
|
||||||
|
public int getY() { return this.y; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// constructors //
|
||||||
|
//==============//
|
||||||
|
|
||||||
public Pos2D(int x, int y)
|
public Pos2D(int x, int y)
|
||||||
{
|
{
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@@ -40,6 +48,11 @@ public class Pos2D
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//======//
|
||||||
|
// math //
|
||||||
|
//======//
|
||||||
|
|
||||||
public Pos2D add(Pos2D other) { return new Pos2D(this.x + other.x, this.y + other.y); }
|
public Pos2D add(Pos2D other) { return new Pos2D(this.x + other.x, this.y + other.y); }
|
||||||
public Pos2D subtract(Pos2D other) { return new Pos2D(this.x - other.x, this.y - other.y); }
|
public Pos2D subtract(Pos2D other) { return new Pos2D(this.x - other.x, this.y - other.y); }
|
||||||
public Pos2D subtract(int value) { return new Pos2D(this.x - value, this.y - value); }
|
public Pos2D subtract(int value) { return new Pos2D(this.x - value, this.y - value); }
|
||||||
@@ -72,10 +85,17 @@ public class Pos2D
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// base overrides //
|
||||||
|
//================//
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() { return Objects.hash(this.x, this.y); }
|
public int hashCode() { return Objects.hash(this.x, this.y); }
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() { return "[" + this.x + ", " + this.y + "]"; }
|
public String toString() { return "[" + this.x + ", " + this.y + "]"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object otherObj)
|
public boolean equals(Object otherObj)
|
||||||
{
|
{
|
||||||
if (otherObj == this)
|
if (otherObj == this)
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
/*
|
||||||
|
* 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.pos.blockPos;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* immutable <br><br>
|
||||||
|
*
|
||||||
|
* Dev note: if for some reason we want to store these as longs check the old commits. <br>
|
||||||
|
* That logic was removed since it wasn't needed at the time.
|
||||||
|
*
|
||||||
|
* @see DhBlockPosMutable
|
||||||
|
*/
|
||||||
|
public class DhBlockPos
|
||||||
|
{
|
||||||
|
/** Useful for methods that need a position passed in but won't actually be used */
|
||||||
|
public static final DhBlockPos ZERO = new DhBlockPos(0, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
protected int x;
|
||||||
|
public int getX() { return this.x; }
|
||||||
|
|
||||||
|
protected int y;
|
||||||
|
public int getY() { return this.y; }
|
||||||
|
|
||||||
|
protected int z;
|
||||||
|
public int getZ() { return this.z; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// constructors //
|
||||||
|
//==============//
|
||||||
|
|
||||||
|
public DhBlockPos(int x, int y, int z)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
public DhBlockPos() { this(0, 0, 0); }
|
||||||
|
public DhBlockPos(DhBlockPos pos) { this(pos.x, pos.y, pos.z); }
|
||||||
|
|
||||||
|
public DhBlockPos(DhBlockPos2D pos, int y) { this(pos.x, y, pos.z); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//========//
|
||||||
|
// offset //
|
||||||
|
//========//
|
||||||
|
|
||||||
|
/** creates a new {@link DhBlockPos} with the given offset from the current pos. */
|
||||||
|
public DhBlockPos createOffset(EDhDirection direction) { return this.mutateOrCreateOffset(direction.getNormal().x, direction.getNormal().y, direction.getNormal().z, null); }
|
||||||
|
/** if not null, mutates "mutablePos" so it matches the current pos after being offset. Otherwise creates a new {@link DhBlockPos}. */
|
||||||
|
public void mutateOffset(EDhDirection direction, @NotNull DhBlockPosMutable mutablePos) { this.mutateOrCreateOffset(direction.getNormal().x, direction.getNormal().y, direction.getNormal().z, mutablePos); }
|
||||||
|
|
||||||
|
public DhBlockPos createOffset(int x, int y, int z) { return this.mutateOrCreateOffset(x,y,z, null); }
|
||||||
|
public void mutateOffset(int x, int y, int z, @NotNull DhBlockPosMutable mutablePos) { this.mutateOrCreateOffset(x, y, z, mutablePos); }
|
||||||
|
|
||||||
|
protected DhBlockPos mutateOrCreateOffset(int x, int y, int z, @Nullable DhBlockPosMutable mutablePos)
|
||||||
|
{
|
||||||
|
int newX = this.x + x;
|
||||||
|
int newY = this.y + y;
|
||||||
|
int newZ = this.z + z;
|
||||||
|
|
||||||
|
if (mutablePos != null)
|
||||||
|
{
|
||||||
|
mutablePos.x = newX;
|
||||||
|
mutablePos.y = newY;
|
||||||
|
mutablePos.z = newZ;
|
||||||
|
|
||||||
|
return mutablePos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new DhBlockPos(newX, newY, newZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// chunk relative //
|
||||||
|
//================//
|
||||||
|
|
||||||
|
/** Returns a new {@link DhBlockPos} limited to a value between 0 and 15 (inclusive) */
|
||||||
|
public DhBlockPos createChunkRelativePos() { return this.mutateOrCreateChunkRelativePos(null); }
|
||||||
|
/** Limits the input {@link DhBlockPos} to a value between 0 and 15 (inclusive) */
|
||||||
|
public void mutateToChunkRelativePos(DhBlockPosMutable mutableBlockPos) { this.mutateOrCreateChunkRelativePos(mutableBlockPos); }
|
||||||
|
/**
|
||||||
|
* Limits the block position to a value between 0 and 15 (inclusive)
|
||||||
|
* If not null, mutates "mutableBlockPos"
|
||||||
|
*
|
||||||
|
* @return the mutated or created {@link DhBlockPos}
|
||||||
|
*/
|
||||||
|
protected DhBlockPos mutateOrCreateChunkRelativePos(@Nullable DhBlockPosMutable mutableBlockPos)
|
||||||
|
{
|
||||||
|
int relX = convertWorldPosToChunkRelative(this.x);
|
||||||
|
// the y value shouldn't need to be changed
|
||||||
|
int relZ = convertWorldPosToChunkRelative(this.z);
|
||||||
|
|
||||||
|
|
||||||
|
if (mutableBlockPos != null)
|
||||||
|
{
|
||||||
|
mutableBlockPos.x = relX;
|
||||||
|
mutableBlockPos.y = this.y;
|
||||||
|
mutableBlockPos.z = relZ;
|
||||||
|
|
||||||
|
return mutableBlockPos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new DhBlockPos(relX, this.y, relZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static int convertWorldPosToChunkRelative(int xOrZ)
|
||||||
|
{
|
||||||
|
// move the position into the range -15 and +15
|
||||||
|
int relPos = (xOrZ % LodUtil.CHUNK_WIDTH);
|
||||||
|
// if the position is negative move it into the range 0 and 15
|
||||||
|
relPos = (relPos < 0) ? (relPos + LodUtil.CHUNK_WIDTH) : relPos;
|
||||||
|
return relPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==========//
|
||||||
|
// distance //
|
||||||
|
//==========//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used to quickly determine the rough distance between two points<Br>
|
||||||
|
* or determine the taxi cab (manhattan) distance between two points. <Br><Br>
|
||||||
|
*
|
||||||
|
* Manhattan distance is equivalent to determining the distance between two street intersections,
|
||||||
|
* where you can only drive along each street, instead of directly to the other point.
|
||||||
|
*/
|
||||||
|
public int getManhattanDistance(DhBlockPos otherPos)
|
||||||
|
{ return Math.abs(this.x - otherPos.x) + Math.abs(this.y - otherPos.y) + Math.abs(this.z - otherPos.z); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// base overrides //
|
||||||
|
//================//
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (this == obj)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (obj == null || this.getClass() != obj.getClass())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DhBlockPos that = (DhBlockPos) obj;
|
||||||
|
return this.x == that.x && this.y == that.y && this.z == that.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() { return Objects.hash(this.x, this.y, this.z); }
|
||||||
|
@Override
|
||||||
|
public String toString() { return "DHBlockPos["+ this.x +", "+ this.y +", "+ this.z +"]"; }
|
||||||
|
|
||||||
|
}
|
||||||
+6
-4
@@ -17,10 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.seibel.distanthorizons.core.pos;
|
package com.seibel.distanthorizons.core.pos.blockPos;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.pos.Pos2D;
|
||||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||||
|
|
||||||
|
/** immutable */
|
||||||
public class DhBlockPos2D
|
public class DhBlockPos2D
|
||||||
{
|
{
|
||||||
public static final DhBlockPos2D ZERO = new DhBlockPos2D(0, 0);
|
public static final DhBlockPos2D ZERO = new DhBlockPos2D(0, 0);
|
||||||
@@ -41,11 +43,11 @@ public class DhBlockPos2D
|
|||||||
|
|
||||||
public DhBlockPos2D(DhBlockPos blockPos)
|
public DhBlockPos2D(DhBlockPos blockPos)
|
||||||
{
|
{
|
||||||
this.x = blockPos.x;
|
this.x = blockPos.getX();
|
||||||
this.z = blockPos.z;
|
this.z = blockPos.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DhBlockPos2D fromPos2D(Pos2D pos) { return new DhBlockPos2D(pos.x, pos.y); }
|
public static DhBlockPos2D fromPos2D(Pos2D pos) { return new DhBlockPos2D(pos.getX(), pos.getY()); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.pos.blockPos;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
|
|
||||||
|
public class DhBlockPosMutable extends DhBlockPos
|
||||||
|
{
|
||||||
|
/** Useful for methods that need a position passed in but won't actually be used */
|
||||||
|
public static final DhBlockPosMutable ZERO = new DhBlockPosMutable(0, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
public void setX(int x) { this.x = x; }
|
||||||
|
public void setY(int y) { this.y = y; }
|
||||||
|
public void setZ(int z) { this.z = z; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// constructors //
|
||||||
|
//==============//
|
||||||
|
|
||||||
|
public DhBlockPosMutable(int x, int y, int z) { super(x,y,z); }
|
||||||
|
public DhBlockPosMutable() { super(0, 0, 0); }
|
||||||
|
public DhBlockPosMutable(DhBlockPos pos) { super(pos); }
|
||||||
|
|
||||||
|
public DhBlockPosMutable(DhBlockPos2D pos, int y) { super(pos.x, y, pos.z); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//========//
|
||||||
|
// offset //
|
||||||
|
//========//
|
||||||
|
|
||||||
|
/** @see DhBlockPos#createOffset(EDhDirection) */
|
||||||
|
public DhBlockPosMutable createOffset(EDhDirection direction) { return new DhBlockPosMutable(super.mutateOrCreateOffset(direction.getNormal().x, direction.getNormal().y, direction.getNormal().z, null)); }
|
||||||
|
/** @see DhBlockPos#createOffset(int, int, int) */
|
||||||
|
public DhBlockPosMutable createOffset(int x, int y, int z) { return new DhBlockPosMutable(this.mutateOrCreateOffset(x,y,z, null)); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// chunk relative //
|
||||||
|
//================//
|
||||||
|
|
||||||
|
public DhBlockPosMutable createChunkRelativePos() { return new DhBlockPosMutable(this.mutateOrCreateChunkRelativePos(null)); }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -54,10 +54,6 @@ public class DhFrustumBounds implements IDhApiCullingFrustum
|
|||||||
Vector3f lodMin = new Vector3f(lodBlockPosMinX, this.worldMinY, lodBlockPosMinZ);
|
Vector3f lodMin = new Vector3f(lodBlockPosMinX, this.worldMinY, lodBlockPosMinZ);
|
||||||
Vector3f lodMax = new Vector3f(lodBlockPosMinX + lodBlockWidth, this.worldMaxY, lodBlockPosMinZ + lodBlockWidth);
|
Vector3f lodMax = new Vector3f(lodBlockPosMinX + lodBlockWidth, this.worldMaxY, lodBlockPosMinZ + lodBlockWidth);
|
||||||
|
|
||||||
if (lodMax.x < this.boundsMin.x || lodMin.x > this.boundsMax.x) return false;
|
|
||||||
if (lodMax.z < this.boundsMin.z || lodMin.z > this.boundsMax.z) return false;
|
|
||||||
if (this.worldMaxY < this.boundsMin.y || this.worldMinY > this.boundsMax.y) return false;
|
|
||||||
|
|
||||||
return this.frustum.testAab(lodMin, lodMax);
|
return this.frustum.testAab(lodMin, lodMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,15 +19,13 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.render;
|
package com.seibel.distanthorizons.core.render;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiHorizontalQuality;
|
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.config.listeners.ConfigChangeListener;
|
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
||||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
|
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
|
||||||
@@ -73,7 +71,6 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
*/
|
*/
|
||||||
private final ConcurrentLinkedQueue<Long> sectionsToReload = new ConcurrentLinkedQueue<>();
|
private final ConcurrentLinkedQueue<Long> sectionsToReload = new ConcurrentLinkedQueue<>();
|
||||||
private final IDhClientLevel level; //FIXME: Proper hierarchy to remove this reference!
|
private final IDhClientLevel level; //FIXME: Proper hierarchy to remove this reference!
|
||||||
private final ConfigChangeListener<EDhApiHorizontalQuality> horizontalScaleChangeListener;
|
|
||||||
private final ReentrantLock treeReadWriteLock = new ReentrantLock();
|
private final ReentrantLock treeReadWriteLock = new ReentrantLock();
|
||||||
private final AtomicBoolean fullDataRetrievalQueueRunning = new AtomicBoolean(false);
|
private final AtomicBoolean fullDataRetrievalQueueRunning = new AtomicBoolean(false);
|
||||||
|
|
||||||
@@ -109,8 +106,6 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
this.level = level;
|
this.level = level;
|
||||||
this.fullDataSourceProvider = fullDataSourceProvider;
|
this.fullDataSourceProvider = fullDataSourceProvider;
|
||||||
this.blockRenderDistanceDiameter = viewDiameterInBlocks;
|
this.blockRenderDistanceDiameter = viewDiameterInBlocks;
|
||||||
|
|
||||||
this.horizontalScaleChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.Quality.horizontalQuality, (newHorizontalScale) -> this.onHorizontalQualityChange());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -150,7 +145,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOGGER.error("Quad Tree tick exception for dimension: " + this.level.getClientLevelWrapper().getDimensionType().getDimensionName() + ", exception: " + e.getMessage(), e);
|
LOGGER.error("Quad Tree tick exception for dimension: " + this.level.getLevelWrapper().getDimensionType().getDimensionName() + ", exception: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -191,7 +186,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
LodRenderSection renderSection = this.getValue(pos);
|
LodRenderSection renderSection = this.getValue(pos);
|
||||||
if (renderSection != null && renderSection.renderingEnabled)
|
if (renderSection != null && renderSection.getRenderingEnabled())
|
||||||
{
|
{
|
||||||
renderSection.uploadRenderDataToGpuAsync();
|
renderSection.uploadRenderDataToGpuAsync();
|
||||||
}
|
}
|
||||||
@@ -255,11 +250,12 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
ArrayList<LodRenderSection> nodesNeedingRetrieval,
|
ArrayList<LodRenderSection> nodesNeedingRetrieval,
|
||||||
ArrayList<LodRenderSection> nodesNeedingLoading)
|
ArrayList<LodRenderSection> nodesNeedingLoading)
|
||||||
{
|
{
|
||||||
//===============================//
|
//=====================//
|
||||||
// node and render section setup //
|
// get/create the node //
|
||||||
//===============================//
|
// and render section //
|
||||||
|
//=====================//
|
||||||
|
|
||||||
// make sure the node is created
|
// create the node
|
||||||
if (quadNode == null && this.isSectionPosInBounds(sectionPos)) // the position bounds should only fail when at the edge of the user's render distance
|
if (quadNode == null && this.isSectionPosInBounds(sectionPos)) // the position bounds should only fail when at the edge of the user's render distance
|
||||||
{
|
{
|
||||||
rootNode.setValue(sectionPos, new LodRenderSection(sectionPos, this, this.level, this.fullDataSourceProvider));
|
rootNode.setValue(sectionPos, new LodRenderSection(sectionPos, this, this.level, this.fullDataSourceProvider));
|
||||||
@@ -271,15 +267,12 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the render section is created
|
// make sure the render section is created (shouldn't be necessary, but just in case)
|
||||||
LodRenderSection renderSection = quadNode.value;
|
LodRenderSection renderSection = quadNode.value;
|
||||||
// create a new render section if missing
|
|
||||||
if (renderSection == null)
|
if (renderSection == null)
|
||||||
{
|
{
|
||||||
LodRenderSection newRenderSection = new LodRenderSection(sectionPos, this, this.level, this.fullDataSourceProvider);
|
renderSection = new LodRenderSection(sectionPos, this, this.level, this.fullDataSourceProvider);
|
||||||
rootNode.setValue(sectionPos, newRenderSection);
|
rootNode.setValue(sectionPos, renderSection);
|
||||||
|
|
||||||
renderSection = newRenderSection; // TODO this never seemed to be called, is it necessary?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -292,16 +285,18 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
//byte expectedDetailLevel = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL + 3; // can be used instead of the following logic for testing
|
//byte expectedDetailLevel = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL + 3; // can be used instead of the following logic for testing
|
||||||
byte expectedDetailLevel = this.calculateExpectedDetailLevel(playerPos, sectionPos);
|
byte expectedDetailLevel = this.calculateExpectedDetailLevel(playerPos, sectionPos);
|
||||||
expectedDetailLevel = (byte) Math.min(expectedDetailLevel, this.minRenderDetailLevel);
|
expectedDetailLevel = (byte) Math.min(expectedDetailLevel, this.minRenderDetailLevel);
|
||||||
expectedDetailLevel += DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL;
|
expectedDetailLevel += DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
|
||||||
|
|
||||||
|
|
||||||
if (DhSectionPos.getDetailLevel(sectionPos) > expectedDetailLevel)
|
if (DhSectionPos.getDetailLevel(sectionPos) > expectedDetailLevel)
|
||||||
{
|
{
|
||||||
// section detail level too high //
|
//=======================//
|
||||||
boolean thisPosIsRendering = renderSection.renderingEnabled;
|
// detail level too high //
|
||||||
|
//=======================//
|
||||||
|
|
||||||
|
boolean thisPosIsRendering = renderSection.getRenderingEnabled();
|
||||||
boolean allChildrenSectionsAreLoaded = true;
|
boolean allChildrenSectionsAreLoaded = true;
|
||||||
|
|
||||||
// recursively update all child render sections
|
// recursively update each child render section
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
QuadNode<LodRenderSection> childNode = quadNode.getChildByIndex(i);
|
QuadNode<LodRenderSection> childNode = quadNode.getChildByIndex(i);
|
||||||
@@ -309,6 +304,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
allChildrenSectionsAreLoaded = childSectionLoaded && allChildrenSectionsAreLoaded;
|
allChildrenSectionsAreLoaded = childSectionLoaded && allChildrenSectionsAreLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!allChildrenSectionsAreLoaded)
|
if (!allChildrenSectionsAreLoaded)
|
||||||
{
|
{
|
||||||
// not all child positions are loaded yet, or this section is out of render range
|
// not all child positions are loaded yet, or this section is out of render range
|
||||||
@@ -316,111 +312,90 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (renderSection.renderingEnabled
|
// onRenderingDisabled() needs to be fired before the children are enabled so beacons render correctly
|
||||||
&& Config.Client.Advanced.Debugging.DebugWireframe.showRenderSectionStatus.get())
|
if (renderSection.getRenderingEnabled())
|
||||||
{
|
{
|
||||||
// show that this position has just been disabled
|
renderSection.onRenderingDisabled();
|
||||||
DebugRenderer.makeParticle(
|
|
||||||
new DebugRenderer.BoxParticle(
|
// this position's rendering has been disabled due to children being rendered
|
||||||
new DebugRenderer.Box(renderSection.pos, 128f, 156f, 0.09f, Color.CYAN.darker()),
|
DebugRenderer.makeParticle(new DebugRenderer.BoxParticle(new DebugRenderer.Box(renderSection.pos, 128f, 156f, 0.09f, Color.WHITE), 0.2, 32f));
|
||||||
0.2, 32f
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// all child positions are loaded, disable this section and enable its children.
|
|
||||||
if (renderSection.renderingEnabled)
|
|
||||||
{
|
|
||||||
this.level.unloadBeaconBeamsInPos(renderSection.pos);
|
|
||||||
}
|
|
||||||
renderSection.renderingEnabled = false;
|
|
||||||
|
|
||||||
// walk back down the tree and enable the child sections //TODO there are probably more efficient ways of doing this, but this will work for now
|
// walk back down the tree and enable each child section
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
QuadNode<LodRenderSection> childNode = quadNode.getChildByIndex(i);
|
QuadNode<LodRenderSection> childNode = quadNode.getChildByIndex(i);
|
||||||
boolean childSectionLoaded = this.recursivelyUpdateRenderSectionNode(playerPos, rootNode, childNode, DhSectionPos.getChildByIndex(sectionPos, i), parentSectionIsRendering, nodesNeedingRetrieval, nodesNeedingLoading);
|
this.recursivelyUpdateRenderSectionNode(playerPos, rootNode, childNode, DhSectionPos.getChildByIndex(sectionPos, i), parentSectionIsRendering, nodesNeedingRetrieval, nodesNeedingLoading);
|
||||||
allChildrenSectionsAreLoaded = childSectionLoaded && allChildrenSectionsAreLoaded;
|
|
||||||
}
|
|
||||||
if (!allChildrenSectionsAreLoaded)
|
|
||||||
{
|
|
||||||
// FIXME having world generation enabled in a pre-generated world that doesn't have any DH data can cause this to happen
|
|
||||||
// surprisingly reloadPos() doesn't appear to be the culprit, maybe there is an issue with reloading/changing the full data source?
|
|
||||||
//LOGGER.warn("Potential QuadTree concurrency issue. All child sections should be enabled and ready to render for pos: "+DhSectionPos.toString(sectionPos));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disabling rendering must be done after the children are enabled
|
||||||
|
// otherwise holes may appear in the world, overlaps are less noticeable
|
||||||
|
renderSection.setRenderingEnabled(false);
|
||||||
|
|
||||||
// this section is now being rendered via its children
|
// this section is now being rendered via its children
|
||||||
return allChildrenSectionsAreLoaded;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO this should only equal the expected detail level, the (expectedDetailLevel-1) is a temporary fix to prevent corners from being cut out
|
// TODO this should only equal the expected detail level, the (expectedDetailLevel-1) is a temporary fix to prevent corners from being cut out
|
||||||
else if (DhSectionPos.getDetailLevel(sectionPos) == expectedDetailLevel || DhSectionPos.getDetailLevel(sectionPos) == expectedDetailLevel - 1)
|
else if (DhSectionPos.getDetailLevel(sectionPos) == expectedDetailLevel || DhSectionPos.getDetailLevel(sectionPos) == expectedDetailLevel - 1)
|
||||||
{
|
{
|
||||||
// this is the detail level we want to render //
|
//======================//
|
||||||
|
// desired detail level //
|
||||||
|
//======================//
|
||||||
|
|
||||||
|
|
||||||
/* Can be uncommented to easily debug a single render section. */
|
// prepare this section for rendering
|
||||||
/* Don't forget the disableRendering() at the bottom though. */
|
if (!renderSection.gpuUploadInProgress() && renderSection.renderBuffer == null)
|
||||||
//if (sectionPos.getDetailLevel() == 10
|
|
||||||
// &&
|
|
||||||
// (
|
|
||||||
// sectionPos.getX() == 0 &&
|
|
||||||
// sectionPos.getZ() == -4
|
|
||||||
// ))
|
|
||||||
{
|
{
|
||||||
// prepare this section for rendering
|
nodesNeedingLoading.add(renderSection);
|
||||||
// TODO this should fire for the lowest detail level first to improve loading speed
|
}
|
||||||
if (!renderSection.gpuUploadInProgress() && renderSection.renderBuffer == null)
|
|
||||||
{
|
|
||||||
nodesNeedingLoading.add(renderSection);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config.Client.Advanced.Debugging.DebugWireframe.showQuadTreeRenderStatus.get())
|
// queue world gen if needed
|
||||||
{
|
if (!renderSection.isFullyGenerated())
|
||||||
this.debugRenderSections.add(renderSection);
|
{
|
||||||
}
|
nodesNeedingRetrieval.add(renderSection);
|
||||||
|
}
|
||||||
|
|
||||||
// wait for the parent to disable before enabling this section, so we don't overdraw/overlap render sections
|
// update debug if needed
|
||||||
if (!parentSectionIsRendering && renderSection.canRender())
|
if (Config.Client.Advanced.Debugging.DebugWireframe.showQuadTreeRenderStatus.get())
|
||||||
|
{
|
||||||
|
this.debugRenderSections.add(renderSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// wait for the parent to disable before enabling this section, so we don't have a hole
|
||||||
|
if (!parentSectionIsRendering && renderSection.canRender())
|
||||||
|
{
|
||||||
|
// if rendering is already enabled we don't have to re-enable it
|
||||||
|
if (!renderSection.getRenderingEnabled())
|
||||||
{
|
{
|
||||||
// if rendering is already enabled we don't have to re-enable it
|
renderSection.setRenderingEnabled(true);
|
||||||
if (!renderSection.renderingEnabled)
|
|
||||||
|
// disabling rendering must be done after the parent is enabled
|
||||||
|
// otherwise holes may appear in the world, overlaps are less noticeable
|
||||||
|
quadNode.deleteAllChildren((childRenderSection) ->
|
||||||
{
|
{
|
||||||
renderSection.renderingEnabled = true;
|
if (childRenderSection != null)
|
||||||
this.level.loadBeaconBeamsInPos(renderSection.pos);
|
|
||||||
|
|
||||||
// delete/disable children, all of them will be a lower detail level than requested
|
|
||||||
quadNode.deleteAllChildren((childRenderSection) ->
|
|
||||||
{
|
{
|
||||||
if (childRenderSection != null)
|
if (childRenderSection.getRenderingEnabled())
|
||||||
{
|
{
|
||||||
if (childRenderSection.renderingEnabled)
|
// this position's rendering has been disabled due to a parent rendering
|
||||||
{
|
DebugRenderer.makeParticle(new DebugRenderer.BoxParticle(new DebugRenderer.Box(childRenderSection.pos, 128f, 156f, 0.09f, Color.MAGENTA),0.2, 32f));
|
||||||
// show that this position's rendering has been disabled due to a parent rendering
|
|
||||||
DebugRenderer.makeParticle(
|
|
||||||
new DebugRenderer.BoxParticle(
|
|
||||||
new DebugRenderer.Box(childRenderSection.pos, 128f, 156f, 0.09f, Color.MAGENTA.darker()),
|
|
||||||
0.2, 32f
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
childRenderSection.renderingEnabled = false;
|
|
||||||
childRenderSection.close();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!renderSection.isFullyGenerated())
|
childRenderSection.setRenderingEnabled(false);
|
||||||
{
|
childRenderSection.onRenderingDisabled();
|
||||||
nodesNeedingRetrieval.add(renderSection);
|
childRenderSection.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// onRenderingEnabled() needs to be fired after the children are disabled so beacons render correctly
|
||||||
|
renderSection.onRenderingEnabled();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// renderSection.disableRendering();
|
|
||||||
//}
|
|
||||||
|
|
||||||
return renderSection.canRender();
|
return renderSection.canRender();
|
||||||
}
|
}
|
||||||
@@ -610,12 +585,6 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//==================//
|
|
||||||
// config listeners //
|
|
||||||
//==================//
|
|
||||||
|
|
||||||
private void onHorizontalQualityChange() { this.clearRenderDataCache(); }
|
|
||||||
|
|
||||||
|
|
||||||
//===========//
|
//===========//
|
||||||
// debugging //
|
// debugging //
|
||||||
@@ -646,7 +615,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
}
|
}
|
||||||
else if (renderSection.renderBuffer.hasNonNullVbos())
|
else if (renderSection.renderBuffer.hasNonNullVbos())
|
||||||
{
|
{
|
||||||
if (renderSection.renderBuffer.bufferSliceCount() != 0)
|
if (renderSection.renderBuffer.vboBufferCount() != 0)
|
||||||
{
|
{
|
||||||
color = Color.GREEN;
|
color = Color.GREEN;
|
||||||
}
|
}
|
||||||
@@ -677,8 +646,6 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
|
|||||||
{
|
{
|
||||||
LOGGER.info("Shutting down " + LodQuadTree.class.getSimpleName() + "...");
|
LOGGER.info("Shutting down " + LodQuadTree.class.getSimpleName() + "...");
|
||||||
|
|
||||||
this.horizontalScaleChangeListener.close();
|
|
||||||
|
|
||||||
DebugRenderer.unregister(this, Config.Client.Advanced.Debugging.DebugWireframe.showQuadTreeRenderStatus);
|
DebugRenderer.unregister(this, Config.Client.Advanced.Debugging.DebugWireframe.showQuadTreeRenderStatus);
|
||||||
|
|
||||||
Iterator<QuadNode<LodRenderSection>> nodeIterator = this.nodeIterator();
|
Iterator<QuadNode<LodRenderSection>> nodeIterator = this.nodeIterator();
|
||||||
|
|||||||
@@ -23,17 +23,21 @@ import com.seibel.distanthorizons.core.config.Config;
|
|||||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBufferBuilder;
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBufferBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.transformers.FullDataToRenderDataTransformer;
|
import com.seibel.distanthorizons.core.dataObjects.transformers.FullDataToRenderDataTransformer;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
|
||||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
|
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBuffer;
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBuffer;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
||||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -54,6 +58,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||||
|
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +70,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
private final LodQuadTree quadTree;
|
private final LodQuadTree quadTree;
|
||||||
|
|
||||||
|
|
||||||
public boolean renderingEnabled = false;
|
private boolean renderingEnabled = false;
|
||||||
private boolean canRender = false;
|
private boolean canRender = false;
|
||||||
|
|
||||||
/** this reference is necessary so we can determine what VBO to render */
|
/** this reference is necessary so we can determine what VBO to render */
|
||||||
@@ -76,7 +81,19 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
* Encapsulates everything between pulling data from the database (including neighbors)
|
* Encapsulates everything between pulling data from the database (including neighbors)
|
||||||
* up to the point when geometry data is uploaded to the GPU.
|
* up to the point when geometry data is uploaded to the GPU.
|
||||||
*/
|
*/
|
||||||
private CompletableFuture<Void> uploadRenderDataToGpuFuture = null;
|
private CompletableFuture<Void> buildAndUploadRenderDataToGpuFuture = null;
|
||||||
|
/**
|
||||||
|
* Represents just building the {@link LodQuadBuilder}. <br>
|
||||||
|
* Separate from {@link LodRenderSection#bufferUploadFuture} because they run on
|
||||||
|
* different thread pools and need to be canceled separately.
|
||||||
|
*/
|
||||||
|
private CompletableFuture<LodQuadBuilder> bufferBuildFuture = null;
|
||||||
|
/**
|
||||||
|
* Represents just uploading the {@link LodQuadBuilder} to the GPU. <br>
|
||||||
|
* Separate from {@link LodRenderSection#bufferBuildFuture} because they run on
|
||||||
|
* different thread pools and need to be canceled separately.
|
||||||
|
*/
|
||||||
|
private CompletableFuture<ColumnRenderBuffer> bufferUploadFuture = null;
|
||||||
|
|
||||||
private final ReentrantLock getRenderSourceLock = new ReentrantLock();
|
private final ReentrantLock getRenderSourceLock = new ReentrantLock();
|
||||||
/** Stored as a class variable so we can reuse it's result across multiple LOD loads if necessary */
|
/** Stored as a class variable so we can reuse it's result across multiple LOD loads if necessary */
|
||||||
@@ -110,6 +127,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
// render data loading/uploading //
|
// render data loading/uploading //
|
||||||
//===============================//
|
//===============================//
|
||||||
|
|
||||||
|
// TODO cleanup, there's a lot of nested futures and duplicate error handling here and it's hard to read
|
||||||
public synchronized void uploadRenderDataToGpuAsync()
|
public synchronized void uploadRenderDataToGpuAsync()
|
||||||
{
|
{
|
||||||
if (!GLProxy.hasInstance())
|
if (!GLProxy.hasInstance())
|
||||||
@@ -119,7 +137,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.uploadRenderDataToGpuFuture != null)
|
if (this.buildAndUploadRenderDataToGpuFuture != null)
|
||||||
{
|
{
|
||||||
// don't accidentally queue multiple uploads at the same time
|
// don't accidentally queue multiple uploads at the same time
|
||||||
return;
|
return;
|
||||||
@@ -133,7 +151,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.uploadRenderDataToGpuFuture = CompletableFuture.runAsync(() ->
|
this.buildAndUploadRenderDataToGpuFuture = CompletableFuture.runAsync(() ->
|
||||||
{
|
{
|
||||||
//==================//
|
//==================//
|
||||||
// load render data //
|
// load render data //
|
||||||
@@ -141,15 +159,15 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
|
|
||||||
this.tryDecrementingLoadFutureArray(this.adjacentLoadRefFutures);
|
this.tryDecrementingLoadFutureArray(this.adjacentLoadRefFutures);
|
||||||
|
|
||||||
ReferencedFutureWrapper thisLoadFuture = this.getRenderSourceAsync();
|
ReferencedFutureWrapper thisRenderSourceLoadFuture = this.getRenderSourceAsync();
|
||||||
ReferencedFutureWrapper[] adjLoadRefFutures = this.getNeighborRenderSourcesAsync();
|
ReferencedFutureWrapper[] adjRenderSourceLoadRefFutures = this.getNeighborRenderSourcesAsync();
|
||||||
|
|
||||||
|
|
||||||
// wait for all futures to complete together,
|
// wait for all futures to complete together,
|
||||||
// merging the futures makes loading significantly faster than loading this position then loading its neighbors
|
// merging the futures makes loading significantly faster than loading this position then loading its neighbors
|
||||||
ArrayList<CompletableFuture<ColumnRenderSource>> futureList = new ArrayList<>();
|
ArrayList<CompletableFuture<ColumnRenderSource>> futureList = new ArrayList<>();
|
||||||
futureList.add(thisLoadFuture.future);
|
futureList.add(thisRenderSourceLoadFuture.future);
|
||||||
for (ReferencedFutureWrapper refFuture : adjLoadRefFutures)
|
for (ReferencedFutureWrapper refFuture : adjRenderSourceLoadRefFutures)
|
||||||
{
|
{
|
||||||
futureList.add(refFuture.future);
|
futureList.add(refFuture.future);
|
||||||
}
|
}
|
||||||
@@ -158,72 +176,107 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ColumnRenderSource renderSource = thisLoadFuture.future.get();
|
ColumnRenderSource renderSource = thisRenderSourceLoadFuture.future.get();
|
||||||
if (renderSource == null || renderSource.isEmpty())
|
if (renderSource == null || renderSource.isEmpty())
|
||||||
{
|
{
|
||||||
thisLoadFuture.decrementRefCount();
|
thisRenderSourceLoadFuture.decrementRefCount();
|
||||||
for (ReferencedFutureWrapper futureWrapper : adjLoadRefFutures)
|
for (ReferencedFutureWrapper futureWrapper : adjRenderSourceLoadRefFutures)
|
||||||
{
|
{
|
||||||
futureWrapper.decrementRefCount();
|
futureWrapper.decrementRefCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
// nothing needs to be rendered
|
// nothing needs to be rendered
|
||||||
this.canRender = false;
|
this.canRender = false;
|
||||||
this.uploadRenderDataToGpuFuture = null;
|
this.buildAndUploadRenderDataToGpuFuture = null;
|
||||||
|
this.bufferBuildFuture = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==============================//
|
//=======================//
|
||||||
// build/upload new render data //
|
// build new render data //
|
||||||
//==============================//
|
//=======================//
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ColumnRenderBuffer previousBuffer = this.renderBuffer;
|
ColumnRenderBuffer previousBuffer = this.renderBuffer;
|
||||||
|
|
||||||
ColumnRenderSource[] adjacentRenderSections = new ColumnRenderSource[EDhDirection.ADJ_DIRECTIONS.length];
|
ColumnRenderSource[] adjacentRenderSections = new ColumnRenderSource[EDhDirection.ADJ_DIRECTIONS.length];
|
||||||
|
boolean[] adjIsSameDetailLevel = new boolean[EDhDirection.ADJ_DIRECTIONS.length];
|
||||||
for (int i = 0; i < EDhDirection.ADJ_DIRECTIONS.length; i++)
|
for (int i = 0; i < EDhDirection.ADJ_DIRECTIONS.length; i++)
|
||||||
{
|
{
|
||||||
adjacentRenderSections[i] = adjLoadRefFutures[i].future.getNow(null);
|
adjacentRenderSections[i] = adjRenderSourceLoadRefFutures[i].future.getNow(null);
|
||||||
|
|
||||||
|
// if the adjacent position isn't the same detail level the buffer building logic
|
||||||
|
// will need to be slightly different in order to reduce holes in the LODs
|
||||||
|
EDhDirection direction = EDhDirection.ADJ_DIRECTIONS[i];
|
||||||
|
adjIsSameDetailLevel[direction.ordinal() - 2] = this.isAdjacentPosSameDetailLevel(direction);
|
||||||
}
|
}
|
||||||
ColumnRenderBufferBuilder.buildAndUploadBuffersAsync(this.level, renderSource, adjacentRenderSections).thenAccept((buffer) ->
|
|
||||||
|
if (this.bufferBuildFuture != null)
|
||||||
|
{
|
||||||
|
// shouldn't normally happen, but just in case canceling the previous future
|
||||||
|
// prevents the CPU from working on something that won't be used
|
||||||
|
this.bufferBuildFuture.cancel(true);
|
||||||
|
}
|
||||||
|
this.bufferBuildFuture = ColumnRenderBufferBuilder.buildBuffersAsync(this.level, renderSource, adjacentRenderSections, adjIsSameDetailLevel);
|
||||||
|
this.bufferBuildFuture.thenAccept((lodQuadBuilder) ->
|
||||||
{
|
{
|
||||||
// upload complete, clean up the old data if
|
|
||||||
this.renderBuffer = buffer;
|
|
||||||
this.canRender = true;
|
|
||||||
this.uploadRenderDataToGpuFuture = null;
|
|
||||||
|
|
||||||
|
|
||||||
if (previousBuffer != null)
|
|
||||||
|
//===================================//
|
||||||
|
// upload new render data to the GPU //
|
||||||
|
//===================================//
|
||||||
|
|
||||||
|
if (this.bufferUploadFuture != null)
|
||||||
{
|
{
|
||||||
previousBuffer.close();
|
// shouldn't normally happen, but just in case canceling the previous future
|
||||||
|
// prevents the CPU from working on something that won't be used
|
||||||
|
this.bufferUploadFuture.cancel(true);
|
||||||
}
|
}
|
||||||
|
this.bufferUploadFuture = ColumnRenderBufferBuilder.uploadBuffersAsync(this.level, renderSource, lodQuadBuilder);
|
||||||
|
this.bufferUploadFuture.thenAccept((buffer) ->
|
||||||
|
{
|
||||||
|
// upload complete, clean up the old data if
|
||||||
|
this.renderBuffer = buffer;
|
||||||
|
this.canRender = (buffer != null);
|
||||||
|
this.buildAndUploadRenderDataToGpuFuture = null;
|
||||||
|
this.bufferBuildFuture = null;
|
||||||
|
|
||||||
thisLoadFuture.decrementRefCount();
|
|
||||||
this.tryDecrementingLoadFutureArray(adjLoadRefFutures);
|
if (previousBuffer != null)
|
||||||
this.adjacentLoadRefFutures = null;
|
{
|
||||||
|
previousBuffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
thisRenderSourceLoadFuture.decrementRefCount();
|
||||||
|
this.tryDecrementingLoadFutureArray(adjRenderSourceLoadRefFutures);
|
||||||
|
this.adjacentLoadRefFutures = null;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
thisLoadFuture.decrementRefCount();
|
thisRenderSourceLoadFuture.decrementRefCount();
|
||||||
this.tryDecrementingLoadFutureArray(adjLoadRefFutures);
|
this.tryDecrementingLoadFutureArray(adjRenderSourceLoadRefFutures);
|
||||||
this.adjacentLoadRefFutures = null;
|
this.adjacentLoadRefFutures = null;
|
||||||
|
|
||||||
LOGGER.error("Unexpected error in LodRenderSection loading, Error: "+e.getMessage(), e);
|
LOGGER.error("Unexpected error in LodRenderSection loading, Error: "+e.getMessage(), e);
|
||||||
this.uploadRenderDataToGpuFuture = null;
|
this.buildAndUploadRenderDataToGpuFuture = null;
|
||||||
|
this.bufferBuildFuture = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
thisLoadFuture.decrementRefCount();
|
thisRenderSourceLoadFuture.decrementRefCount();
|
||||||
this.tryDecrementingLoadFutureArray(adjLoadRefFutures);
|
this.tryDecrementingLoadFutureArray(adjRenderSourceLoadRefFutures);
|
||||||
this.adjacentLoadRefFutures = null;
|
this.adjacentLoadRefFutures = null;
|
||||||
|
|
||||||
LOGGER.error("Unexpected error in LodRenderSection loading, Error: "+e.getMessage(), e);
|
LOGGER.error("Unexpected error in LodRenderSection loading, Error: "+e.getMessage(), e);
|
||||||
this.uploadRenderDataToGpuFuture = null;
|
this.buildAndUploadRenderDataToGpuFuture = null;
|
||||||
|
this.bufferBuildFuture = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, executor);
|
}, executor);
|
||||||
@@ -292,7 +345,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOGGER.warn("Unable to get render source " + this.pos + ", error: " + e.getMessage(), e);
|
LOGGER.warn("Unable to get render source " + DhSectionPos.toString(this.pos) + ", error: " + e.getMessage(), e);
|
||||||
this.renderSourceLoadingRefFuture = null;
|
this.renderSourceLoadingRefFuture = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -304,6 +357,32 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
this.getRenderSourceLock.unlock();
|
this.getRenderSourceLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private boolean isAdjacentPosSameDetailLevel(EDhDirection direction)
|
||||||
|
{
|
||||||
|
long adjPos = DhSectionPos.getAdjacentPos(this.pos, direction);
|
||||||
|
byte detailLevel = this.quadTree.calculateExpectedDetailLevel(new DhBlockPos2D(MC.getPlayerBlockPos()), adjPos);
|
||||||
|
detailLevel += DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
|
||||||
|
boolean adjacentIsSameDetailLevel = (detailLevel == DhSectionPos.getDetailLevel(this.pos));
|
||||||
|
return adjacentIsSameDetailLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: can cause issues with neighboring LOD sections
|
||||||
|
* if only some (vs all) futures are canceled.
|
||||||
|
*/
|
||||||
|
public void cancelGpuUpload()
|
||||||
|
{
|
||||||
|
CompletableFuture<Void> future = this.buildAndUploadRenderDataToGpuFuture;
|
||||||
|
this.buildAndUploadRenderDataToGpuFuture = null;
|
||||||
|
this.bufferBuildFuture = null;
|
||||||
|
if (future != null)
|
||||||
|
{
|
||||||
|
// interrupting the future speeds things up, but also causes
|
||||||
|
// some LODs to never load in properly
|
||||||
|
future.cancel(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -313,7 +392,37 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
|
|
||||||
public boolean canRender() { return this.canRender; }
|
public boolean canRender() { return this.canRender; }
|
||||||
|
|
||||||
public boolean gpuUploadInProgress() { return this.uploadRenderDataToGpuFuture != null; }
|
public boolean getRenderingEnabled() { return this.renderingEnabled; }
|
||||||
|
/**
|
||||||
|
* Separate from {@link LodRenderSection#onRenderingEnabled} and {@link LodRenderSection#onRenderingDisabled}
|
||||||
|
* since we need to trigger external changes in disabled -> enabled order
|
||||||
|
* so beacons are removed and then re-added.
|
||||||
|
* However, to prevent holes in the world when disabling sections we need to
|
||||||
|
* enable the new section(s) first before disabling the old one(s).
|
||||||
|
*/
|
||||||
|
public void setRenderingEnabled(boolean enabled) { this.renderingEnabled = enabled;}
|
||||||
|
|
||||||
|
/** @see LodRenderSection#setRenderingEnabled */
|
||||||
|
public void onRenderingEnabled() { this.level.loadBeaconBeamsInPos(this.pos); }
|
||||||
|
/** @see LodRenderSection#setRenderingEnabled */
|
||||||
|
public void onRenderingDisabled()
|
||||||
|
{
|
||||||
|
this.level.unloadBeaconBeamsInPos(this.pos);
|
||||||
|
|
||||||
|
if (Config.Client.Advanced.Debugging.DebugWireframe.showRenderSectionStatus.get())
|
||||||
|
{
|
||||||
|
// show that this position has just been disabled
|
||||||
|
DebugRenderer.makeParticle(
|
||||||
|
new DebugRenderer.BoxParticle(
|
||||||
|
new DebugRenderer.Box(this.pos, 128f, 156f, 0.09f, Color.CYAN.darker()),
|
||||||
|
0.2, 32f
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean gpuUploadInProgress() { return this.buildAndUploadRenderDataToGpuFuture != null; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -394,9 +503,9 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "LodRenderSection{" +
|
return "pos=[" + DhSectionPos.toString(this.pos) + "] " +
|
||||||
"pos=" + this.pos +
|
"enabled=[" + this.renderingEnabled + "] " +
|
||||||
'}';
|
"uploading=[" + this.gpuUploadInProgress() + "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -423,9 +532,18 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
this.renderBuffer.close();
|
this.renderBuffer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.uploadRenderDataToGpuFuture != null)
|
// cancel all in-progress futures since they aren't needed any more
|
||||||
|
if (this.buildAndUploadRenderDataToGpuFuture != null)
|
||||||
{
|
{
|
||||||
this.uploadRenderDataToGpuFuture.cancel(true);
|
this.buildAndUploadRenderDataToGpuFuture.cancel(true);
|
||||||
|
}
|
||||||
|
if (this.bufferBuildFuture != null)
|
||||||
|
{
|
||||||
|
this.bufferBuildFuture.cancel(true);
|
||||||
|
}
|
||||||
|
if (this.bufferUploadFuture != null)
|
||||||
|
{
|
||||||
|
this.bufferUploadFuture.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this render section won't be rendering, we don't need to load any data for it
|
// this render section won't be rendering, we don't need to load any data for it
|
||||||
@@ -460,7 +578,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
|
|||||||
{
|
{
|
||||||
color = Color.green;
|
color = Color.green;
|
||||||
}
|
}
|
||||||
else if (this.uploadRenderDataToGpuFuture != null)
|
else if (this.buildAndUploadRenderDataToGpuFuture != null)
|
||||||
{
|
{
|
||||||
color = Color.yellow;
|
color = Color.yellow;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-16
@@ -25,13 +25,11 @@ import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShadow
|
|||||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBuffer;
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBuffer;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.SharedVbo;
|
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
|
||||||
import com.seibel.distanthorizons.core.pos.DhLodPos;
|
import com.seibel.distanthorizons.core.pos.DhLodPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.pos.Pos2D;
|
import com.seibel.distanthorizons.core.pos.Pos2D;
|
||||||
@@ -50,7 +48,9 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Matrix4fc;
|
import org.joml.Matrix4fc;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Comparator;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,11 +195,11 @@ public class RenderBufferHandler implements AutoCloseable
|
|||||||
int abPosDifference;
|
int abPosDifference;
|
||||||
if (axisDirection.getAxis().equals(EDhDirection.Axis.X))
|
if (axisDirection.getAxis().equals(EDhDirection.Axis.X))
|
||||||
{
|
{
|
||||||
abPosDifference = aPos.x - bPos.x;
|
abPosDifference = aPos.getX() - bPos.getX();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
abPosDifference = aPos.y - bPos.y;
|
abPosDifference = aPos.getY() - bPos.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abPosDifference == 0)
|
if (abPosDifference == 0)
|
||||||
@@ -311,7 +311,7 @@ public class RenderBufferHandler implements AutoCloseable
|
|||||||
}
|
}
|
||||||
|
|
||||||
ColumnRenderBuffer buffer = renderSection.renderBuffer;
|
ColumnRenderBuffer buffer = renderSection.renderBuffer;
|
||||||
if (buffer == null || !renderSection.renderingEnabled)
|
if (buffer == null || !renderSection.getRenderingEnabled())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -348,11 +348,7 @@ public class RenderBufferHandler implements AutoCloseable
|
|||||||
// TODO why can these sometimes be null when teleporting between multiverses
|
// TODO why can these sometimes be null when teleporting between multiverses
|
||||||
if (this.loadedNearToFarBuffers != null)
|
if (this.loadedNearToFarBuffers != null)
|
||||||
{
|
{
|
||||||
renderContext.setModelViewMatrixOffset(DhBlockPos.ZERO, renderEventParam);
|
this.loadedNearToFarBuffers.forEach(loadedBuffer -> loadedBuffer.buffer.renderOpaque(renderContext, renderEventParam));
|
||||||
|
|
||||||
ArrayList<SharedVbo.BufferSlice> sliceList = new ArrayList<>();
|
|
||||||
this.loadedNearToFarBuffers.forEach(loadedBuffer -> sliceList.addAll(Arrays.asList(loadedBuffer.buffer.opaqueBufferSlices)));
|
|
||||||
renderContext.drawSharedVbo(SharedVbo.OPAQUE, sliceList.toArray(new SharedVbo.BufferSlice[0]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void renderTransparent(LodRenderer renderContext, DhApiRenderParam renderEventParam)
|
public void renderTransparent(LodRenderer renderContext, DhApiRenderParam renderEventParam)
|
||||||
@@ -360,11 +356,12 @@ public class RenderBufferHandler implements AutoCloseable
|
|||||||
// TODO why can these sometimes be null when teleporting between multiverses
|
// TODO why can these sometimes be null when teleporting between multiverses
|
||||||
if (this.loadedNearToFarBuffers != null)
|
if (this.loadedNearToFarBuffers != null)
|
||||||
{
|
{
|
||||||
renderContext.setModelViewMatrixOffset(DhBlockPos.ZERO, renderEventParam);
|
ListIterator<LoadedRenderBuffer> iter = this.loadedNearToFarBuffers.listIterator(this.loadedNearToFarBuffers.size());
|
||||||
|
while (iter.hasPrevious())
|
||||||
ArrayList<SharedVbo.BufferSlice> sliceList = new ArrayList<>();
|
{
|
||||||
this.loadedNearToFarBuffers.forEach(loadedBuffer -> sliceList.addAll(Arrays.asList(loadedBuffer.buffer.transparentBufferSlices)));
|
LoadedRenderBuffer loadedBuffer = iter.previous();
|
||||||
renderContext.drawSharedVbo(SharedVbo.TRANSPARENT, sliceList.toArray(new SharedVbo.BufferSlice[0]));
|
loadedBuffer.buffer.renderTransparent(renderContext, renderEventParam);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -193,17 +193,7 @@ public class GLProxy
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EDhApiGpuUploadMethod getGpuUploadMethod()
|
public EDhApiGpuUploadMethod getGpuUploadMethod() { return this.preferredUploadMethod; }
|
||||||
{
|
|
||||||
EDhApiGpuUploadMethod method = Config.Client.Advanced.GpuBuffers.gpuUploadMethod.get();
|
|
||||||
if (!this.bufferStorageSupported && method == EDhApiGpuUploadMethod.BUFFER_STORAGE)
|
|
||||||
{
|
|
||||||
// if buffer storage isn't supported
|
|
||||||
// default to DATA since that is the most compatible
|
|
||||||
method = EDhApiGpuUploadMethod.DATA;
|
|
||||||
}
|
|
||||||
return method == EDhApiGpuUploadMethod.AUTO ? this.preferredUploadMethod : method;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean runningOnRenderThread()
|
public boolean runningOnRenderThread()
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -238,7 +238,7 @@ public class GLBuffer implements AutoCloseable
|
|||||||
// buffer mapping //
|
// buffer mapping //
|
||||||
//================//
|
//================//
|
||||||
|
|
||||||
public ByteBuffer mapBuffer(int targetSize, EDhApiGpuUploadMethod uploadMethod, int maxExpensionSize, int bufferHint, int mapFlags)
|
public ByteBuffer mapBuffer(int targetSize, EDhApiGpuUploadMethod uploadMethod, int maxExpansionSize, int bufferHint, int mapFlags)
|
||||||
{
|
{
|
||||||
LodUtil.assertTrue(targetSize != 0, "MapBuffer targetSize is 0");
|
LodUtil.assertTrue(targetSize != 0, "MapBuffer targetSize is 0");
|
||||||
LodUtil.assertTrue(uploadMethod.useEarlyMapping, "Upload method must be one that use early mappings in order to call mapBuffer");
|
LodUtil.assertTrue(uploadMethod.useEarlyMapping, "Upload method must be one that use early mappings in order to call mapBuffer");
|
||||||
@@ -252,7 +252,7 @@ public class GLBuffer implements AutoCloseable
|
|||||||
if (this.size < targetSize || this.size > targetSize * BUFFER_SHRINK_TRIGGER)
|
if (this.size < targetSize || this.size > targetSize * BUFFER_SHRINK_TRIGGER)
|
||||||
{
|
{
|
||||||
int newSize = (int) (targetSize * BUFFER_EXPANSION_MULTIPLIER);
|
int newSize = (int) (targetSize * BUFFER_EXPANSION_MULTIPLIER);
|
||||||
if (newSize > maxExpensionSize) newSize = maxExpensionSize;
|
if (newSize > maxExpansionSize) newSize = maxExpansionSize;
|
||||||
this.size = newSize;
|
this.size = newSize;
|
||||||
if (this.bufferStorage)
|
if (this.bufferStorage)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -77,9 +77,9 @@ public class GLVertexBuffer extends GLBuffer
|
|||||||
this.vertexCount = vertCount;
|
this.vertexCount = vertCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer mapBuffer(int targetSize, EDhApiGpuUploadMethod uploadMethod, int maxExpensionSize)
|
public ByteBuffer mapBuffer(int targetSize, EDhApiGpuUploadMethod uploadMethod, int maxExpansionSize)
|
||||||
{
|
{
|
||||||
return super.mapBuffer(targetSize, uploadMethod, maxExpensionSize,
|
return super.mapBuffer(targetSize, uploadMethod, maxExpansionSize,
|
||||||
uploadMethod.useBufferStorage ? GL32.GL_MAP_WRITE_BIT :
|
uploadMethod.useBufferStorage ? GL32.GL_MAP_WRITE_BIT :
|
||||||
uploadMethod.useEarlyMapping ? GL32.GL_DYNAMIC_DRAW : GL32.GL_STATIC_DRAW,
|
uploadMethod.useEarlyMapping ? GL32.GL_DYNAMIC_DRAW : GL32.GL_STATIC_DRAW,
|
||||||
GL32.GL_MAP_WRITE_BIT | GL32.GL_MAP_UNSYNCHRONIZED_BIT | GL32.GL_MAP_INVALIDATE_BUFFER_BIT);
|
GL32.GL_MAP_WRITE_BIT | GL32.GL_MAP_UNSYNCHRONIZED_BIT | GL32.GL_MAP_INVALIDATE_BUFFER_BIT);
|
||||||
|
|||||||
+4
-1
@@ -25,6 +25,7 @@ import com.seibel.distanthorizons.core.render.glObject.GLEnums;
|
|||||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -154,7 +155,7 @@ public class QuadElementBuffer extends GLElementBuffer
|
|||||||
LOGGER.info("Quad IBO Resizing from [" + getCapacity() + "] to [" + quadCount + "]" + " with type: " +
|
LOGGER.info("Quad IBO Resizing from [" + getCapacity() + "] to [" + quadCount + "]" + " with type: " +
|
||||||
GLEnums.getString(type));
|
GLEnums.getString(type));
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(indicesCount * GLEnums.getTypeSize(type)).order(ByteOrder.nativeOrder());
|
ByteBuffer buffer = MemoryUtil.memAlloc(indicesCount * GLEnums.getTypeSize(type));
|
||||||
buildBuffer(quadCount, buffer, type);
|
buildBuffer(quadCount, buffer, type);
|
||||||
if (!gl.bufferStorageSupported)
|
if (!gl.bufferStorageSupported)
|
||||||
{
|
{
|
||||||
@@ -169,6 +170,8 @@ public class QuadElementBuffer extends GLElementBuffer
|
|||||||
super.uploadBuffer(buffer, EDhApiGpuUploadMethod.BUFFER_STORAGE,
|
super.uploadBuffer(buffer, EDhApiGpuUploadMethod.BUFFER_STORAGE,
|
||||||
indicesCount * GLEnums.getTypeSize(type), 0);
|
indicesCount * GLEnums.getTypeSize(type), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryUtil.memFree(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
|||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
|
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.pos.DhLodPos;
|
import com.seibel.distanthorizons.core.pos.DhLodPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.GLState;
|
import com.seibel.distanthorizons.core.render.glObject.GLState;
|
||||||
|
|||||||
+23
-52
@@ -25,22 +25,21 @@ import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShader
|
|||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
||||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.SharedVbo;
|
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBuffer;
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBuffer;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
|
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.render.DhApiRenderProxy;
|
import com.seibel.distanthorizons.core.render.DhApiRenderProxy;
|
||||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.GLState;
|
import com.seibel.distanthorizons.core.render.glObject.GLState;
|
||||||
|
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.buffer.QuadElementBuffer;
|
import com.seibel.distanthorizons.core.render.glObject.buffer.QuadElementBuffer;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.texture.*;
|
import com.seibel.distanthorizons.core.render.glObject.texture.*;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.shaders.*;
|
import com.seibel.distanthorizons.core.render.renderer.shaders.*;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||||
@@ -55,13 +54,10 @@ import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
|||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
||||||
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.lwjgl.PointerBuffer;
|
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.nio.IntBuffer;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@@ -305,11 +301,8 @@ public class LodRenderer
|
|||||||
// terrain
|
// terrain
|
||||||
profiler.popPush("LOD Opaque");
|
profiler.popPush("LOD Opaque");
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
|
||||||
|
|
||||||
this.bufferHandler.renderOpaque(this, renderEventParam);
|
this.bufferHandler.renderOpaque(this, renderEventParam);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// custom objects with SSAO
|
// custom objects with SSAO
|
||||||
if (Config.Client.Advanced.Graphics.GenericRendering.enableRendering.get())
|
if (Config.Client.Advanced.Graphics.GenericRendering.enableRendering.get())
|
||||||
{
|
{
|
||||||
@@ -473,7 +466,6 @@ public class LodRenderer
|
|||||||
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
||||||
GL32.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
GL32.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
|
||||||
|
|
||||||
this.bufferHandler.renderTransparent(this, renderEventParam);
|
this.bufferHandler.renderTransparent(this, renderEventParam);
|
||||||
GL32.glDepthMask(true); // Apparently the depth mask state is stored in the FBO, so glState fails to restore it...
|
GL32.glDepthMask(true); // Apparently the depth mask state is stored in the FBO, so glState fails to restore it...
|
||||||
|
|
||||||
@@ -483,7 +475,7 @@ public class LodRenderer
|
|||||||
public void setModelViewMatrixOffset(DhBlockPos pos, DhApiRenderParam renderEventParam) throws IllegalStateException
|
public void setModelViewMatrixOffset(DhBlockPos pos, DhApiRenderParam renderEventParam) throws IllegalStateException
|
||||||
{
|
{
|
||||||
Vec3d cam = MC_RENDER.getCameraExactPosition();
|
Vec3d cam = MC_RENDER.getCameraExactPosition();
|
||||||
Vec3f modelPos = new Vec3f((float) (pos.x - cam.x), (float) (pos.y - cam.y), (float) (pos.z - cam.z));
|
Vec3f modelPos = new Vec3f((float) (pos.getX() - cam.x), (float) (pos.getY() - cam.y), (float) (pos.getZ() - cam.z));
|
||||||
|
|
||||||
|
|
||||||
IDhApiShaderProgram shaderProgram = this.lodRenderProgram;
|
IDhApiShaderProgram shaderProgram = this.lodRenderProgram;
|
||||||
@@ -493,58 +485,37 @@ public class LodRenderer
|
|||||||
shaderProgram = shaderProgramOverride;
|
shaderProgram = shaderProgramOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GL32.glIsProgram(shaderProgram.getId()))
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("No GL program exists with the ID: [" + shaderProgram.getId() + "]. This either means a shader program was freed while it was still in use or was never created.");
|
|
||||||
}
|
|
||||||
|
|
||||||
shaderProgram.bind();
|
shaderProgram.bind();
|
||||||
shaderProgram.setModelOffsetPos(modelPos);
|
shaderProgram.setModelOffsetPos(modelPos);
|
||||||
|
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawSharedVbo(SharedVbo sharedVbo, SharedVbo.BufferSlice[] slices)
|
public void drawVbo(GLVertexBuffer vbo)
|
||||||
{
|
{
|
||||||
IDhApiShaderProgram shaderProgram = this.lodRenderProgram;
|
//// can be uncommented to add additional debug validation to prevent crashes if invalid buffers are being created
|
||||||
IDhApiShaderProgram shaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
|
//// shouldn't be used in production due to the performance hit
|
||||||
if (shaderProgramOverride != null && shaderProgram.overrideThisFrame())
|
//if (GL32.glIsBuffer(vbo.getId()))
|
||||||
{
|
{
|
||||||
shaderProgram = shaderProgramOverride;
|
IDhApiShaderProgram shaderProgram = this.lodRenderProgram;
|
||||||
}
|
IDhApiShaderProgram shaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
|
||||||
|
if (shaderProgramOverride != null && shaderProgram.overrideThisFrame())
|
||||||
|
|
||||||
sharedVbo.bind();
|
|
||||||
shaderProgram.bindVertexBuffer(sharedVbo.vboId);
|
|
||||||
|
|
||||||
IntArrayList countList = new IntArrayList();
|
|
||||||
IntArrayList baseVertexList = new IntArrayList();
|
|
||||||
for (int i = 0; i < slices.length; i++)
|
|
||||||
{
|
|
||||||
SharedVbo.BufferSlice slice = slices[i];
|
|
||||||
if (slice != null && slice.vertexCount != 0)
|
|
||||||
{
|
{
|
||||||
countList.add((slice.vertexCount / 4) * 6); // 4 vertices per quad, 6 indices per quad
|
shaderProgram = shaderProgramOverride;
|
||||||
baseVertexList.add((int)slice.startIndex / LodUtil.LOD_VERTEX_FORMAT.getByteSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vbo.bind();
|
||||||
|
shaderProgram.bindVertexBuffer(vbo.getId());
|
||||||
|
GL32.glDrawElements(GL32.GL_TRIANGLES, (vbo.getVertexCount() / 4) * 6, // TODO what does the 4 and 6 here represent?
|
||||||
|
this.quadIBO.getType(), 0);
|
||||||
|
vbo.unbind();
|
||||||
}
|
}
|
||||||
|
//else
|
||||||
int[] counts = countList.toIntArray();
|
//{
|
||||||
PointerBuffer iboIndicies = PointerBuffer.allocateDirect(counts.length);
|
// // will spam the log if uncommented, but helpful for validation
|
||||||
for (int i = 0; i < counts.length; i++)
|
// //LOGGER.warn("Unable to draw VBO: "+vbo.getId());
|
||||||
{
|
//}
|
||||||
iboIndicies.put(0L);
|
|
||||||
}
|
|
||||||
iboIndicies.rewind();
|
|
||||||
int[] baseVertecies = baseVertexList.toIntArray();
|
|
||||||
|
|
||||||
|
|
||||||
if (counts.length != 0)
|
|
||||||
{
|
|
||||||
GL32.glMultiDrawElementsBaseVertex(GL32.GL_TRIANGLES, counts, this.quadIBO.getType(), iboIndicies, baseVertecies);
|
|
||||||
}
|
|
||||||
|
|
||||||
sharedVbo.unbind();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
|||||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
|
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
|
||||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
|
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
@@ -86,14 +87,14 @@ public class ScreenQuad
|
|||||||
|
|
||||||
private void createBuffer()
|
private void createBuffer()
|
||||||
{
|
{
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(box_vertices.length * Float.BYTES);
|
ByteBuffer buffer = MemoryUtil.memAlloc(box_vertices.length * Float.BYTES);
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
|
||||||
buffer.asFloatBuffer().put(box_vertices);
|
buffer.asFloatBuffer().put(box_vertices);
|
||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
|
|
||||||
this.boxBuffer = new GLVertexBuffer(false);
|
this.boxBuffer = new GLVertexBuffer(false);
|
||||||
this.boxBuffer.bind();
|
this.boxBuffer.bind();
|
||||||
this.boxBuffer.uploadBuffer(buffer, box_vertices.length, EDhApiGpuUploadMethod.DATA, box_vertices.length * Float.BYTES);
|
this.boxBuffer.uploadBuffer(buffer, box_vertices.length, EDhApiGpuUploadMethod.DATA, box_vertices.length * Float.BYTES);
|
||||||
|
MemoryUtil.memFree(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+171
-54
@@ -21,18 +21,20 @@ package com.seibel.distanthorizons.core.render.renderer.generic;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||||
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
|
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
|
||||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
||||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
||||||
import com.seibel.distanthorizons.core.sql.repo.BeaconBeamRepo;
|
import com.seibel.distanthorizons.core.sql.repo.BeaconBeamRepo;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
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.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -42,7 +44,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class BeaconRenderHandler
|
public class BeaconRenderHandler
|
||||||
{
|
{
|
||||||
@@ -51,12 +56,22 @@ public class BeaconRenderHandler
|
|||||||
|
|
||||||
private static final int BEAM_TOP_Y = 6_000;
|
private static final int BEAM_TOP_Y = 6_000;
|
||||||
|
|
||||||
|
/** how often should we check if a beacon should be culled? */
|
||||||
|
private static final int MAX_CULLING_FREQUENCY_IN_MS = 1_000;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** if this is null then the other handler is probably null too, but just in case */
|
/** if this is null then the other handler is probably null too, but just in case */
|
||||||
private final BeaconBeamRepo beaconBeamRepo;
|
private final BeaconBeamRepo beaconBeamRepo;
|
||||||
|
|
||||||
|
private final ReentrantLock updateLock = new ReentrantLock();
|
||||||
|
|
||||||
private final IDhApiRenderableBoxGroup beaconBoxGroup;
|
private final IDhApiRenderableBoxGroup beaconBoxGroup;
|
||||||
private final HashMap<DhBlockPos, AtomicInteger> beaconRefCountByBlockPos = new HashMap<>();
|
private final ArrayList<DhApiRenderableBox> fullBeaconBoxList = new ArrayList<>();
|
||||||
|
private final HashSet<DhBlockPos> beaconBlockPosSet = new HashSet<>();
|
||||||
|
|
||||||
|
private boolean cullingThreadRunning = false;
|
||||||
|
private boolean updateRenderDataNextFrame = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +88,7 @@ public class BeaconRenderHandler
|
|||||||
this.beaconBoxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
|
this.beaconBoxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
|
||||||
this.beaconBoxGroup.setSsaoEnabled(false);
|
this.beaconBoxGroup.setSsaoEnabled(false);
|
||||||
this.beaconBoxGroup.setShading(DhApiRenderableBoxGroupShading.getUnshaded());
|
this.beaconBoxGroup.setShading(DhApiRenderableBoxGroupShading.getUnshaded());
|
||||||
this.beaconBoxGroup.setPreRenderFunc((renderEventParam) -> this.beaconBoxGroup.setActive(Config.Client.Advanced.Graphics.GenericRendering.enableBeaconRendering.get()));
|
this.beaconBoxGroup.setPreRenderFunc(this::beforeRender);
|
||||||
|
|
||||||
renderer.add(this.beaconBoxGroup);
|
renderer.add(this.beaconBoxGroup);
|
||||||
}
|
}
|
||||||
@@ -84,7 +99,7 @@ public class BeaconRenderHandler
|
|||||||
// level loading/unloading //
|
// level loading/unloading //
|
||||||
//=========================//
|
//=========================//
|
||||||
|
|
||||||
public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List<BeaconBeamDTO> newBeamList)
|
public void setBeaconBeamsForChunk(DhChunkPos chunkPos, List<BeaconBeamDTO> activeBeamList)
|
||||||
{
|
{
|
||||||
// synchronized to prevent two threads from updating the same chunk at the same time
|
// synchronized to prevent two threads from updating the same chunk at the same time
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
@@ -92,12 +107,12 @@ public class BeaconRenderHandler
|
|||||||
HashSet<DhBlockPos> allPosSet = new HashSet<>();
|
HashSet<DhBlockPos> allPosSet = new HashSet<>();
|
||||||
|
|
||||||
// sort new beams
|
// sort new beams
|
||||||
HashMap<DhBlockPos, BeaconBeamDTO> newBeamByPos = new HashMap<>(newBeamList.size());
|
HashMap<DhBlockPos, BeaconBeamDTO> activeBeamByPos = new HashMap<>(activeBeamList.size());
|
||||||
for (int i = 0; i < newBeamList.size(); i++)
|
for (int i = 0; i < activeBeamList.size(); i++)
|
||||||
{
|
{
|
||||||
BeaconBeamDTO beam = newBeamList.get(i);
|
BeaconBeamDTO beam = activeBeamList.get(i);
|
||||||
newBeamByPos.put(beam.pos, beam);
|
activeBeamByPos.put(beam.blockPos, beam);
|
||||||
allPosSet.add(beam.pos);
|
allPosSet.add(beam.blockPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get existing beams
|
// get existing beams
|
||||||
@@ -106,8 +121,8 @@ public class BeaconRenderHandler
|
|||||||
for (int i = 0; i < existingBeamList.size(); i++)
|
for (int i = 0; i < existingBeamList.size(); i++)
|
||||||
{
|
{
|
||||||
BeaconBeamDTO beam = existingBeamList.get(i);
|
BeaconBeamDTO beam = existingBeamList.get(i);
|
||||||
existingBeamByPos.put(beam.pos, beam);
|
existingBeamByPos.put(beam.blockPos, beam);
|
||||||
allPosSet.add(beam.pos);
|
allPosSet.add(beam.blockPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,28 +136,28 @@ public class BeaconRenderHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
BeaconBeamDTO existingBeam = existingBeamByPos.get(beaconPos);
|
BeaconBeamDTO existingBeam = existingBeamByPos.get(beaconPos);
|
||||||
BeaconBeamDTO newBeam = newBeamByPos.get(beaconPos);
|
BeaconBeamDTO activeBeam = activeBeamByPos.get(beaconPos);
|
||||||
|
|
||||||
if (existingBeam != null && newBeam != null)
|
if (existingBeam != null && activeBeam != null)
|
||||||
{
|
{
|
||||||
// beam still exists in chunk
|
// beam still exists in chunk
|
||||||
if (!existingBeam.color.equals(newBeam.color))
|
if (!existingBeam.color.equals(activeBeam.color))
|
||||||
{
|
{
|
||||||
// beam colors were changed
|
// beam colors were changed
|
||||||
this.beaconBeamRepo.save(newBeam);
|
this.beaconBeamRepo.save(activeBeam);
|
||||||
this.updateBeaconColor(newBeam);
|
this.updateBeaconColor(activeBeam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (existingBeam == null && newBeam != null)
|
else if (existingBeam == null && activeBeam != null)
|
||||||
{
|
{
|
||||||
// new beam found, add to DB
|
// new beam found, add to DB
|
||||||
this.beaconBeamRepo.save(newBeam);
|
this.beaconBeamRepo.save(activeBeam);
|
||||||
this.startRenderingBeacon(newBeam);
|
this.startRenderingBeacon(activeBeam);
|
||||||
}
|
}
|
||||||
else if (existingBeam != null && newBeam == null)
|
else if (existingBeam != null && activeBeam == null)
|
||||||
{
|
{
|
||||||
// beam no longer exists at position, remove from DB
|
// beam no longer exists at position, remove from DB
|
||||||
this.beaconBeamRepo.deleteWithKey(beaconPos); // TODO broken when updating adjacent chunks
|
this.beaconBeamRepo.deleteWithKey(beaconPos);
|
||||||
this.stopRenderingBeaconAtPos(beaconPos);
|
this.stopRenderingBeaconAtPos(beaconPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +183,7 @@ public class BeaconRenderHandler
|
|||||||
for (int i = 0; i < existingBeamList.size(); i++)
|
for (int i = 0; i < existingBeamList.size(); i++)
|
||||||
{
|
{
|
||||||
BeaconBeamDTO beam = existingBeamList.get(i);
|
BeaconBeamDTO beam = existingBeamList.get(i);
|
||||||
this.stopRenderingBeaconAtPos(beam.pos);
|
this.stopRenderingBeaconAtPos(beam.blockPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,62 +195,164 @@ public class BeaconRenderHandler
|
|||||||
|
|
||||||
private void startRenderingBeacon(BeaconBeamDTO beacon)
|
private void startRenderingBeacon(BeaconBeamDTO beacon)
|
||||||
{
|
{
|
||||||
this.beaconRefCountByBlockPos.compute(beacon.pos, (beamPos, beaconRefCount) ->
|
try
|
||||||
{
|
{
|
||||||
if (beaconRefCount == null) { beaconRefCount = new AtomicInteger(); }
|
this.updateLock.lock();
|
||||||
if (beaconRefCount.getAndIncrement() == 0)
|
|
||||||
|
if (this.beaconBlockPosSet.add(beacon.blockPos))
|
||||||
{
|
{
|
||||||
DhApiRenderableBox beaconBox = new DhApiRenderableBox(
|
DhApiRenderableBox beaconBox = new DhApiRenderableBox(
|
||||||
new DhApiVec3d(beacon.pos.x, beacon.pos.y+1, beacon.pos.z),
|
new DhApiVec3d(beacon.blockPos.getX(), beacon.blockPos.getY() + 1, beacon.blockPos.getZ()),
|
||||||
new DhApiVec3d(beacon.pos.x+1, BEAM_TOP_Y, beacon.pos.z+1),
|
new DhApiVec3d(beacon.blockPos.getX() + 1, BEAM_TOP_Y, beacon.blockPos.getZ() + 1),
|
||||||
beacon.color,
|
beacon.color,
|
||||||
EDhApiBlockMaterial.ILLUMINATED
|
EDhApiBlockMaterial.ILLUMINATED
|
||||||
);
|
);
|
||||||
|
|
||||||
this.beaconBoxGroup.add(beaconBox);
|
this.beaconBoxGroup.add(beaconBox);
|
||||||
|
this.fullBeaconBoxList.add(beaconBox);
|
||||||
this.beaconBoxGroup.triggerBoxChange();
|
this.beaconBoxGroup.triggerBoxChange();
|
||||||
}
|
}
|
||||||
return beaconRefCount;
|
}
|
||||||
});
|
finally
|
||||||
|
{
|
||||||
|
this.updateLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopRenderingBeaconAtPos(DhBlockPos beaconPos)
|
private void stopRenderingBeaconAtPos(DhBlockPos beaconPos)
|
||||||
{
|
{
|
||||||
this.beaconRefCountByBlockPos.compute(beaconPos, (pos, beaconRefCount) ->
|
try
|
||||||
{
|
{
|
||||||
if (beaconRefCount != null
|
this.updateLock.lock();
|
||||||
&& beaconRefCount.decrementAndGet() <= 0)
|
|
||||||
|
if (this.beaconBlockPosSet.remove(beaconPos))
|
||||||
{
|
{
|
||||||
this.beaconBoxGroup.removeIf((box) ->
|
Predicate<DhApiRenderableBox> removePredicate = (DhApiRenderableBox box) ->
|
||||||
box.minPos.x == beaconPos.x
|
{
|
||||||
&& box.minPos.y == beaconPos.y+1 // plus 1 because the beam starts above the beacon
|
return box.minPos.x == beaconPos.getX()
|
||||||
&& box.minPos.z == beaconPos.z
|
&& box.minPos.y == beaconPos.getY() + 1 // plus 1 because the beam starts above the beacon
|
||||||
);
|
&& box.minPos.z == beaconPos.getZ();
|
||||||
|
};
|
||||||
|
this.beaconBoxGroup.removeIf(removePredicate);
|
||||||
|
this.fullBeaconBoxList.removeIf(removePredicate);
|
||||||
|
|
||||||
this.beaconBoxGroup.triggerBoxChange();
|
this.beaconBoxGroup.triggerBoxChange();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
finally
|
||||||
return beaconRefCount;
|
{
|
||||||
}
|
this.updateLock.unlock();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBeaconColor(BeaconBeamDTO newBeam)
|
private void updateBeaconColor(BeaconBeamDTO newBeam)
|
||||||
{
|
{
|
||||||
DhBlockPos pos = newBeam.pos;
|
try
|
||||||
for (int i = 0; i < this.beaconBoxGroup.size(); i++)
|
|
||||||
{
|
{
|
||||||
DhApiRenderableBox box = this.beaconBoxGroup.get(i);
|
this.updateLock.lock();
|
||||||
if (box.minPos.x == pos.x
|
|
||||||
&& box.minPos.y == pos.y+1 // plus 1 because the beam starts above the beacon
|
DhBlockPos pos = newBeam.blockPos;
|
||||||
&& box.minPos.z == pos.z)
|
for (int i = 0; i < this.fullBeaconBoxList.size(); i++)
|
||||||
{
|
{
|
||||||
box.color = newBeam.color;
|
DhApiRenderableBox box = this.fullBeaconBoxList.get(i);
|
||||||
this.beaconBoxGroup.triggerBoxChange();
|
if (box.minPos.x == pos.getX()
|
||||||
break;
|
&& box.minPos.y == pos.getY() + 1 // plus 1 because the beam starts above the beacon
|
||||||
|
&& box.minPos.z == pos.getZ())
|
||||||
|
{
|
||||||
|
box.color = newBeam.color;
|
||||||
|
this.beaconBoxGroup.triggerBoxChange();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.updateLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void beforeRender(DhApiRenderParam renderEventParam)
|
||||||
|
{
|
||||||
|
if (!Config.Client.Advanced.Graphics.AdvancedGraphics.disableBeaconDistanceCulling.get())
|
||||||
|
{
|
||||||
|
// this could be called only when the player moves, but it's an extremely cheap check,
|
||||||
|
// so there isn't much of a reason to bother
|
||||||
|
this.tryUpdateBeaconCullingAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// this must be called on the render thread to prevent concurrency issues
|
||||||
|
if (this.updateRenderDataNextFrame)
|
||||||
|
{
|
||||||
|
this.beaconBoxGroup.triggerBoxChange();
|
||||||
|
this.updateRenderDataNextFrame = false;
|
||||||
|
}
|
||||||
|
this.beaconBoxGroup.setActive(Config.Client.Advanced.Graphics.GenericRendering.enableBeaconRendering.get());
|
||||||
|
}
|
||||||
|
/** does nothing if the culling thread is already running */
|
||||||
|
private void tryUpdateBeaconCullingAsync()
|
||||||
|
{
|
||||||
|
ThreadPoolExecutor executor = ThreadPoolUtil.getBeaconCullingExecutor();
|
||||||
|
if (executor != null
|
||||||
|
&& !this.cullingThreadRunning)
|
||||||
|
{
|
||||||
|
this.cullingThreadRunning = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
executor.execute(() ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(MAX_CULLING_FREQUENCY_IN_MS);
|
||||||
|
}
|
||||||
|
catch (InterruptedException ignore) { }
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// lock to make sure we don't try adding beacons to the arrays while processing them
|
||||||
|
this.updateLock.lock();
|
||||||
|
|
||||||
|
Vec3d cameraPos = MC_RENDER.getCameraExactPosition();
|
||||||
|
double mcRenderDistance = MC_RENDER.getRenderDistance() * LodUtil.CHUNK_WIDTH;
|
||||||
|
|
||||||
|
|
||||||
|
// Clear the existing box group so we can re-populate it.
|
||||||
|
// Since the box group is only used when we trigger an update, clearing it here
|
||||||
|
// and repopulating it is fine.
|
||||||
|
this.beaconBoxGroup.clear();
|
||||||
|
|
||||||
|
// While iterating over every beacon isn't a great way of doing this,
|
||||||
|
// when 940 beacons were tested this only took ~0.9 Milliseconds, so as long as
|
||||||
|
// we aren't freezing the render thread this method of culling works just fine.
|
||||||
|
for (DhApiRenderableBox box : this.fullBeaconBoxList)
|
||||||
|
{
|
||||||
|
// if a beacon is outside the vanilla render distance render it
|
||||||
|
double distance = Vec3d.getHorizontalDistance(cameraPos, box.minPos);
|
||||||
|
if (distance > mcRenderDistance)
|
||||||
|
{
|
||||||
|
this.beaconBoxGroup.add(box);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateRenderDataNextFrame = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LOGGER.error("Unexpected issue while updating beacon culling. Error: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.updateLock.unlock();
|
||||||
|
this.cullingThreadRunning = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (RejectedExecutionException ignore)
|
||||||
|
{ /* If this happens that means everything is already shut down and no culling is necessary */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-31
@@ -21,12 +21,14 @@ package com.seibel.distanthorizons.core.render.renderer.generic;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||||
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
|
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
||||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
||||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
|
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
@@ -48,8 +50,6 @@ public class CloudRenderHandler
|
|||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
|
||||||
private static final String CLOUD_RESOURCE_TEXTURE_PATH = "assets/distanthorizons/textures/clouds.png";
|
private static final String CLOUD_RESOURCE_TEXTURE_PATH = "assets/distanthorizons/textures/clouds.png";
|
||||||
// FIXME transparency sorting makes having transparent clouds impossible
|
|
||||||
private static final Color CLOUD_COLOR = new Color(255,255,255,255);
|
|
||||||
|
|
||||||
private static final boolean DEBUG_BORDER_COLORS = false;
|
private static final boolean DEBUG_BORDER_COLORS = false;
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ public class CloudRenderHandler
|
|||||||
private static final int CLOUD_BOX_THICKNESS = 16;
|
private static final int CLOUD_BOX_THICKNESS = 16;
|
||||||
|
|
||||||
private final IDhApiRenderableBoxGroup[][] boxGroupByOffset = new IDhApiRenderableBoxGroup[3][3];
|
private final IDhApiRenderableBoxGroup[][] boxGroupByOffset = new IDhApiRenderableBoxGroup[3][3];
|
||||||
private final IDhLevel level;
|
private final IDhClientLevel level;
|
||||||
private final GenericObjectRenderer renderer;
|
private final GenericObjectRenderer renderer;
|
||||||
|
|
||||||
private float moveSpeedInBlocksPerSecond = 3.0f;
|
private float moveSpeedInBlocksPerSecond = 3.0f;
|
||||||
@@ -74,7 +74,7 @@ public class CloudRenderHandler
|
|||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
|
||||||
public CloudRenderHandler(IDhLevel level, GenericObjectRenderer renderer)
|
public CloudRenderHandler(IDhClientLevel level, GenericObjectRenderer renderer)
|
||||||
{
|
{
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
@@ -195,16 +195,8 @@ public class CloudRenderHandler
|
|||||||
int maxXBlockPos = endX * CLOUD_BOX_WIDTH;
|
int maxXBlockPos = endX * CLOUD_BOX_WIDTH;
|
||||||
int maxZBlockPos = endZ * CLOUD_BOX_WIDTH;
|
int maxZBlockPos = endZ * CLOUD_BOX_WIDTH;
|
||||||
|
|
||||||
Color color = CLOUD_COLOR;
|
// this color is changed at render time based on the level time
|
||||||
if (DEBUG_BORDER_COLORS)
|
Color color = new Color(255,255,255,255);
|
||||||
{
|
|
||||||
// equals is included so the board is 2 blocks wide, it makes it easier to see
|
|
||||||
if (startX <= 1) { color = Color.RED; }
|
|
||||||
else if (startX >= textureWidth - 2) { color = Color.GREEN; }
|
|
||||||
if (startZ <= 1) { color = Color.BLUE; }
|
|
||||||
else if (endZ >= textureWidth - 2) { color = Color.BLACK; }
|
|
||||||
}
|
|
||||||
|
|
||||||
DhApiRenderableBox box = new DhApiRenderableBox(
|
DhApiRenderableBox box = new DhApiRenderableBox(
|
||||||
new DhApiVec3d(minXBlockPos, 0, minZBlockPos),
|
new DhApiVec3d(minXBlockPos, 0, minZBlockPos),
|
||||||
new DhApiVec3d(maxXBlockPos, CLOUD_BOX_THICKNESS, maxZBlockPos),
|
new DhApiVec3d(maxXBlockPos, CLOUD_BOX_THICKNESS, maxZBlockPos),
|
||||||
@@ -238,13 +230,15 @@ public class CloudRenderHandler
|
|||||||
ModInfo.NAME + ":Clouds",
|
ModInfo.NAME + ":Clouds",
|
||||||
new DhApiVec3d(0, 0, 0), // the offset will be set during rendering
|
new DhApiVec3d(0, 0, 0), // the offset will be set during rendering
|
||||||
boxList);
|
boxList);
|
||||||
boxGroup.setBlockLight(LodUtil.MIN_MC_LIGHT);
|
|
||||||
|
// since cloud colors are set by the level based on the time of day lighting should affect it
|
||||||
|
boxGroup.setBlockLight(LodUtil.MAX_MC_LIGHT);
|
||||||
boxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
|
boxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
|
||||||
boxGroup.setSsaoEnabled(false);
|
boxGroup.setSsaoEnabled(false);
|
||||||
boxGroup.setShading(cloudShading);
|
boxGroup.setShading(cloudShading);
|
||||||
|
|
||||||
CloudParams params = new CloudParams(textureWidth, x, z);
|
CloudParams cloudParams = new CloudParams(textureWidth, x, z);
|
||||||
boxGroup.setPreRenderFunc((renderParam) -> this.preRender(params));
|
boxGroup.setPreRenderFunc((renderParam) -> this.preRender(renderParam, cloudParams));
|
||||||
|
|
||||||
renderer.add(boxGroup);
|
renderer.add(boxGroup);
|
||||||
this.boxGroupByOffset[x+1][z+1] = boxGroup;
|
this.boxGroupByOffset[x+1][z+1] = boxGroup;
|
||||||
@@ -252,9 +246,15 @@ public class CloudRenderHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preRender(CloudParams clouds)
|
private void preRender(DhApiRenderParam renderParam, CloudParams cloudParams)
|
||||||
{
|
{
|
||||||
IDhApiRenderableBoxGroup boxGroup = this.boxGroupByOffset[clouds.instanceOffsetX+1][clouds.instanceOffsetZ+1];
|
IDhApiRenderableBoxGroup boxGroup = this.boxGroupByOffset[cloudParams.instanceOffsetX+1][cloudParams.instanceOffsetZ+1];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//===================//
|
||||||
|
// should we render? //
|
||||||
|
//===================//
|
||||||
|
|
||||||
boolean renderClouds = Config.Client.Advanced.Graphics.GenericRendering.enableCloudRendering.get();
|
boolean renderClouds = Config.Client.Advanced.Graphics.GenericRendering.enableCloudRendering.get();
|
||||||
boxGroup.setActive(renderClouds);
|
boxGroup.setActive(renderClouds);
|
||||||
@@ -275,19 +275,46 @@ public class CloudRenderHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// cloud color //
|
||||||
|
//=============//
|
||||||
|
|
||||||
|
// FIXME transparency sorting makes having transparent clouds impossible
|
||||||
|
// maybe someday we could add the option to cull individual faces? a single bit for each direction should be enough
|
||||||
|
|
||||||
|
// cloud color changes based on the time of day and weather so we need to get it from the level
|
||||||
|
Color cloudColor = this.level.getClientLevelWrapper().getCloudColor(renderParam.partialTicks);
|
||||||
|
if (DEBUG_BORDER_COLORS)
|
||||||
|
{
|
||||||
|
// equals is included so the board is 2 blocks wide, it makes it easier to see
|
||||||
|
if (cloudParams.instanceOffsetX <= 1) { cloudColor = Color.RED; }
|
||||||
|
else if (cloudParams.instanceOffsetX >= cloudParams.textureWidth - 2) { cloudColor = Color.GREEN; }
|
||||||
|
if (cloudParams.instanceOffsetZ <= 1) { cloudColor = Color.BLUE; }
|
||||||
|
else if (cloudParams.instanceOffsetZ >= cloudParams.textureWidth - 2) { cloudColor = Color.BLACK; }
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DhApiRenderableBox box : boxGroup)
|
||||||
|
{
|
||||||
|
box.color = cloudColor;
|
||||||
|
}
|
||||||
|
boxGroup.triggerBoxChange();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//================//
|
//================//
|
||||||
// cloud movement //
|
// cloud movement //
|
||||||
//================//
|
//================//
|
||||||
|
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
float deltaTime = (currentTime - clouds.lastFrameTime) / 1000.0f; // Delta time in seconds
|
float deltaTime = (currentTime - cloudParams.lastFrameTime) / 1000.0f; // Delta time in seconds
|
||||||
clouds.lastFrameTime = currentTime;
|
cloudParams.lastFrameTime = currentTime;
|
||||||
|
|
||||||
float deltaX = this.moveSpeedInBlocksPerSecond * deltaTime;
|
float deltaX = this.moveSpeedInBlocksPerSecond * deltaTime;
|
||||||
// negative delta is to match vanilla's cloud movement
|
// negative delta is to match vanilla's cloud movement
|
||||||
clouds.xOffset -= deltaX;
|
cloudParams.xOffset -= deltaX;
|
||||||
// wrap the cloud around after reaching the edge
|
// wrap the cloud around after reaching the edge
|
||||||
clouds.xOffset %= clouds.widthInBlocks;
|
cloudParams.xOffset %= cloudParams.widthInBlocks;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -299,16 +326,16 @@ public class CloudRenderHandler
|
|||||||
int cameraPosX = (int)MC_RENDER.getCameraExactPosition().x;
|
int cameraPosX = (int)MC_RENDER.getCameraExactPosition().x;
|
||||||
int cameraPosZ = (int)MC_RENDER.getCameraExactPosition().z;
|
int cameraPosZ = (int)MC_RENDER.getCameraExactPosition().z;
|
||||||
// offset the camera position by negative 1 width when below zero to fix off-by-one errors in the negative direction
|
// offset the camera position by negative 1 width when below zero to fix off-by-one errors in the negative direction
|
||||||
if (cameraPosX < 0) { cameraPosX -= clouds.widthInBlocks; }
|
if (cameraPosX < 0) { cameraPosX -= (int)cloudParams.widthInBlocks; }
|
||||||
if (cameraPosZ < 0) { cameraPosZ -= clouds.widthInBlocks; }
|
if (cameraPosZ < 0) { cameraPosZ -= (int)cloudParams.widthInBlocks; }
|
||||||
|
|
||||||
// determine how many cloud instances away from the origin we are
|
// determine how many cloud instances away from the origin we are
|
||||||
int cloudInstanceOffsetX = cameraPosX / (int)clouds.widthInBlocks;
|
int cloudInstanceOffsetX = cameraPosX / (int)cloudParams.widthInBlocks;
|
||||||
int cloudInstanceOffsetZ = cameraPosZ / (int)clouds.widthInBlocks;
|
int cloudInstanceOffsetZ = cameraPosZ / (int)cloudParams.widthInBlocks;
|
||||||
|
|
||||||
// calculate the new offset
|
// calculate the new offset
|
||||||
float xOffset = (cloudInstanceOffsetX * clouds.widthInBlocks);
|
float xOffset = (cloudInstanceOffsetX * cloudParams.widthInBlocks);
|
||||||
float zOffset = (cloudInstanceOffsetZ * clouds.widthInBlocks);
|
float zOffset = (cloudInstanceOffsetZ * cloudParams.widthInBlocks);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -318,9 +345,9 @@ public class CloudRenderHandler
|
|||||||
|
|
||||||
boxGroup.setOriginBlockPos(
|
boxGroup.setOriginBlockPos(
|
||||||
new DhApiVec3d(
|
new DhApiVec3d(
|
||||||
clouds.xOffset + (clouds.instanceOffsetX * clouds.widthInBlocks) + xOffset + clouds.halfWidthInBlocks,
|
cloudParams.xOffset + (cloudParams.instanceOffsetX * cloudParams.widthInBlocks) + xOffset + cloudParams.halfWidthInBlocks,
|
||||||
this.level.getLevelWrapper().getMaxHeight() + 200,
|
this.level.getLevelWrapper().getMaxHeight() + 200,
|
||||||
clouds.zOffset + (clouds.instanceOffsetZ * clouds.widthInBlocks) + zOffset + clouds.halfWidthInBlocks
|
cloudParams.zOffset + (cloudParams.instanceOffsetZ * cloudParams.widthInBlocks) + zOffset + cloudParams.halfWidthInBlocks
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-8
@@ -30,7 +30,9 @@ import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhAp
|
|||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
||||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
||||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
|
import com.seibel.distanthorizons.core.jar.EPlatform;
|
||||||
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
|
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
@@ -42,14 +44,18 @@ import com.seibel.distanthorizons.core.util.LodUtil;
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||||
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModAccessor;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.opengl.ARBInstancedArrays;
|
import org.lwjgl.opengl.ARBInstancedArrays;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
import org.lwjgl.opengl.GL33;
|
import org.lwjgl.opengl.GL33;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -69,6 +75,7 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
|
|||||||
public static final ConfigBasedSpamLogger SPAM_LOGGER = new ConfigBasedSpamLogger(LogManager.getLogger(GenericObjectRenderer.class), () -> EDhApiLoggerMode.LOG_ALL_TO_CHAT, 1);
|
public static final ConfigBasedSpamLogger SPAM_LOGGER = new ConfigBasedSpamLogger(LogManager.getLogger(GenericObjectRenderer.class), () -> EDhApiLoggerMode.LOG_ALL_TO_CHAT, 1);
|
||||||
|
|
||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
private static final ISodiumAccessor SODIUM = ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to troubleshoot the renderer.
|
* Can be used to troubleshoot the renderer.
|
||||||
@@ -171,17 +178,37 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
|
|||||||
}
|
}
|
||||||
this.init = true;
|
this.init = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//===================================//
|
||||||
|
// is instanced rendering available? //
|
||||||
|
//===================================//
|
||||||
|
|
||||||
this.vertexAttribDivisorSupported = GLProxy.getInstance().vertexAttribDivisorSupported;
|
this.vertexAttribDivisorSupported = GLProxy.getInstance().vertexAttribDivisorSupported;
|
||||||
this.instancedArraysSupported = GLProxy.getInstance().instancedArraysSupported;
|
this.instancedArraysSupported = GLProxy.getInstance().instancedArraysSupported;
|
||||||
this.useInstancedRendering = this.vertexAttribDivisorSupported || this.instancedArraysSupported;
|
this.useInstancedRendering = this.vertexAttribDivisorSupported || this.instancedArraysSupported;
|
||||||
if (!this.useInstancedRendering)
|
if (!this.useInstancedRendering)
|
||||||
{
|
{
|
||||||
LOGGER.warn("Instanced rendering not supported by this GPU, falling back to direct rendering. Generic object rendering will be slow.");
|
LOGGER.warn("Instanced rendering not supported by this GPU, falling back to direct rendering. Generic object rendering will be slow and some effects may be disabled.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boolean isMac = (EPlatform.get() == EPlatform.MACOS);
|
||||||
|
if (isMac && SODIUM != null)
|
||||||
|
{
|
||||||
|
this.useInstancedRendering = false;
|
||||||
|
LOGGER.warn("Instanced rendering is broken on Mac when Sodium is present, falling back to direct rendering. Generic object rendering will be slow and some effects may be disabled.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.shaderProgram = new GenericObjectShaderProgram(this.useInstancedRendering);
|
|
||||||
|
|
||||||
|
|
||||||
|
//======================//
|
||||||
|
// startup the renderer //
|
||||||
|
//======================//
|
||||||
|
|
||||||
|
this.shaderProgram = new GenericObjectShaderProgram(this.useInstancedRendering);
|
||||||
|
|
||||||
this.createBuffers();
|
this.createBuffers();
|
||||||
|
|
||||||
if (RENDER_DEBUG_OBJECTS)
|
if (RENDER_DEBUG_OBJECTS)
|
||||||
@@ -192,24 +219,22 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
|
|||||||
private void createBuffers()
|
private void createBuffers()
|
||||||
{
|
{
|
||||||
// box vertices
|
// box vertices
|
||||||
ByteBuffer boxVerticesBuffer = ByteBuffer.allocateDirect(BOX_VERTICES.length * Float.BYTES);
|
ByteBuffer boxVerticesBuffer = MemoryUtil.memAlloc(BOX_VERTICES.length * Float.BYTES);
|
||||||
boxVerticesBuffer.order(ByteOrder.nativeOrder());
|
|
||||||
boxVerticesBuffer.asFloatBuffer().put(BOX_VERTICES);
|
boxVerticesBuffer.asFloatBuffer().put(BOX_VERTICES);
|
||||||
boxVerticesBuffer.rewind();
|
boxVerticesBuffer.rewind();
|
||||||
this.boxVertexBuffer = new GLVertexBuffer(false);
|
this.boxVertexBuffer = new GLVertexBuffer(false);
|
||||||
this.boxVertexBuffer.bind();
|
this.boxVertexBuffer.bind();
|
||||||
this.boxVertexBuffer.uploadBuffer(boxVerticesBuffer, 8, EDhApiGpuUploadMethod.DATA, BOX_VERTICES.length * Float.BYTES);
|
this.boxVertexBuffer.uploadBuffer(boxVerticesBuffer, 8, EDhApiGpuUploadMethod.DATA, BOX_VERTICES.length * Float.BYTES);
|
||||||
|
MemoryUtil.memFree(boxVerticesBuffer);
|
||||||
|
|
||||||
// box vertex indexes
|
// box vertex indexes
|
||||||
ByteBuffer solidIndexBuffer = ByteBuffer.allocateDirect(BOX_INDICES.length * Integer.BYTES);
|
ByteBuffer solidIndexBuffer = MemoryUtil.memAlloc(BOX_INDICES.length * Integer.BYTES);
|
||||||
solidIndexBuffer.order(ByteOrder.nativeOrder());
|
|
||||||
solidIndexBuffer.asIntBuffer().put(BOX_INDICES);
|
solidIndexBuffer.asIntBuffer().put(BOX_INDICES);
|
||||||
solidIndexBuffer.rewind();
|
solidIndexBuffer.rewind();
|
||||||
this.boxIndexBuffer = new GLElementBuffer(false);
|
this.boxIndexBuffer = new GLElementBuffer(false);
|
||||||
this.boxIndexBuffer.uploadBuffer(solidIndexBuffer, EDhApiGpuUploadMethod.DATA, BOX_INDICES.length * Integer.BYTES, GL32.GL_STATIC_DRAW);
|
this.boxIndexBuffer.uploadBuffer(solidIndexBuffer, EDhApiGpuUploadMethod.DATA, BOX_INDICES.length * Integer.BYTES, GL32.GL_STATIC_DRAW);
|
||||||
this.boxIndexBuffer.bind();
|
this.boxIndexBuffer.bind();
|
||||||
|
MemoryUtil.memFree(solidIndexBuffer);
|
||||||
}
|
}
|
||||||
private void addGenericDebugObjects()
|
private void addGenericDebugObjects()
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-1
@@ -215,7 +215,8 @@ public class RenderableBoxGroup
|
|||||||
public Stream<DhApiRenderableBox> stream() { return this.boxList.stream(); }
|
public Stream<DhApiRenderableBox> stream() { return this.boxList.stream(); }
|
||||||
@Override
|
@Override
|
||||||
public Stream<DhApiRenderableBox> parallelStream() { return this.boxList.parallelStream(); }
|
public Stream<DhApiRenderableBox> parallelStream() { return this.boxList.parallelStream(); }
|
||||||
|
@Override
|
||||||
|
public void clear() { this.boxList.clear(); }
|
||||||
|
|
||||||
|
|
||||||
//===================//
|
//===================//
|
||||||
|
|||||||
+6
@@ -94,6 +94,12 @@ public class FogApplyShader extends AbstractShaderRenderer
|
|||||||
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
||||||
GL32.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
GL32.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
// Depth testing must be disabled otherwise this application shader won't apply anything.
|
||||||
|
// setting this isn't necessary in vanilla, but some mods may change this, requiring it to be set manually,
|
||||||
|
// it should be automatically restored after rendering is complete.
|
||||||
|
GL32.glDisable(GL32.GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
|
||||||
// apply the rendered Fog to DH's framebuffer
|
// apply the rendered Fog to DH's framebuffer
|
||||||
GL32.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, FogShader.INSTANCE.frameBuffer);
|
GL32.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, FogShader.INSTANCE.frameBuffer);
|
||||||
GL32.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, LodRenderer.getActiveFramebufferId());
|
GL32.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, LodRenderer.getActiveFramebufferId());
|
||||||
|
|||||||
+5
@@ -167,6 +167,11 @@ public class FogShader extends AbstractShaderRenderer
|
|||||||
GL32.glBindTexture(GL32.GL_TEXTURE_2D, LodRenderer.getActiveDepthTextureId());
|
GL32.glBindTexture(GL32.GL_TEXTURE_2D, LodRenderer.getActiveDepthTextureId());
|
||||||
GL32.glUniform1i(this.uDepthMap, 0);
|
GL32.glUniform1i(this.uDepthMap, 0);
|
||||||
|
|
||||||
|
// this is necessary for MC 1.16 (IE Legacy OpenGL)
|
||||||
|
// otherwise the framebuffer isn't cleared correctly and the fog smears across the screen
|
||||||
|
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
||||||
ScreenQuad.INSTANCE.render();
|
ScreenQuad.INSTANCE.render();
|
||||||
|
|
||||||
state.restore();
|
state.restore();
|
||||||
|
|||||||
+6
@@ -125,6 +125,12 @@ public class SSAOApplyShader extends AbstractShaderRenderer
|
|||||||
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
||||||
GL32.glBlendFuncSeparate(GL32.GL_ZERO, GL32.GL_SRC_ALPHA, GL32.GL_ZERO, GL32.GL_ONE);
|
GL32.glBlendFuncSeparate(GL32.GL_ZERO, GL32.GL_SRC_ALPHA, GL32.GL_ZERO, GL32.GL_ONE);
|
||||||
|
|
||||||
|
// Depth testing must be disabled otherwise this application shader won't apply anything.
|
||||||
|
// setting this isn't necessary in vanilla, but some mods may change this, requiring it to be set manually,
|
||||||
|
// it should be automatically restored after rendering is complete.
|
||||||
|
GL32.glDisable(GL32.GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
|
||||||
// apply the rendered SSAO to the LODs
|
// apply the rendered SSAO to the LODs
|
||||||
GL32.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, SSAOShader.INSTANCE.frameBuffer);
|
GL32.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, SSAOShader.INSTANCE.frameBuffer);
|
||||||
GL32.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, LodRenderer.getActiveFramebufferId());
|
GL32.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, LodRenderer.getActiveFramebufferId());
|
||||||
|
|||||||
+10
-8
@@ -103,17 +103,19 @@ public class SSAOShader extends AbstractShaderRenderer
|
|||||||
this.shader.setUniform(this.gSampleCountUniform,
|
this.shader.setUniform(this.gSampleCountUniform,
|
||||||
Config.Client.Advanced.Graphics.Ssao.sampleCount.get());
|
Config.Client.Advanced.Graphics.Ssao.sampleCount.get());
|
||||||
|
|
||||||
this.shader.setUniform(this.gRadiusUniform,
|
// Implicit Number cast needs to be done to prevent issues with the default value being a int
|
||||||
Config.Client.Advanced.Graphics.Ssao.radius.get().floatValue());
|
Number radius = Config.Client.Advanced.Graphics.Ssao.radius.get();
|
||||||
|
this.shader.setUniform(this.gRadiusUniform, radius.floatValue());
|
||||||
|
|
||||||
this.shader.setUniform(this.gStrengthUniform,
|
|
||||||
Config.Client.Advanced.Graphics.Ssao.strength.get().floatValue());
|
|
||||||
|
|
||||||
this.shader.setUniform(this.gMinLightUniform,
|
Number strength = Config.Client.Advanced.Graphics.Ssao.strength.get();
|
||||||
Config.Client.Advanced.Graphics.Ssao.minLight.get().floatValue());
|
this.shader.setUniform(this.gStrengthUniform, strength.floatValue());
|
||||||
|
|
||||||
this.shader.setUniform(this.gBiasUniform,
|
Number minLight = Config.Client.Advanced.Graphics.Ssao.minLight.get();
|
||||||
Config.Client.Advanced.Graphics.Ssao.bias.get().floatValue());
|
this.shader.setUniform(this.gMinLightUniform, minLight.floatValue());
|
||||||
|
|
||||||
|
Number bias = Config.Client.Advanced.Graphics.Ssao.bias.get();
|
||||||
|
this.shader.setUniform(this.gBiasUniform, bias.floatValue());
|
||||||
|
|
||||||
GL32.glActiveTexture(GL32.GL_TEXTURE0);
|
GL32.glActiveTexture(GL32.GL_TEXTURE0);
|
||||||
GL32.glBindTexture(GL32.GL_TEXTURE_2D, LodRenderer.getActiveDepthTextureId());
|
GL32.glBindTexture(GL32.GL_TEXTURE_2D, LodRenderer.getActiveDepthTextureId());
|
||||||
|
|||||||
@@ -20,15 +20,14 @@
|
|||||||
package com.seibel.distanthorizons.core.sql.dto;
|
package com.seibel.distanthorizons.core.sql.dto;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
/** handles storing {@link FullDataSourceV2}'s in the database. */
|
/** handles storing {@link FullDataSourceV2}'s in the database. */
|
||||||
public class BeaconBeamDTO implements IBaseDTO<DhBlockPos>
|
public class BeaconBeamDTO implements IBaseDTO<DhBlockPos>
|
||||||
{
|
{
|
||||||
public DhBlockPos pos;
|
public DhBlockPos blockPos;
|
||||||
public Color color;
|
public Color color;
|
||||||
|
|
||||||
|
|
||||||
@@ -37,9 +36,9 @@ public class BeaconBeamDTO implements IBaseDTO<DhBlockPos>
|
|||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
|
||||||
public BeaconBeamDTO(DhBlockPos pos, Color color)
|
public BeaconBeamDTO(DhBlockPos blockPos, Color color)
|
||||||
{
|
{
|
||||||
this.pos = pos;
|
this.blockPos = blockPos;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +49,6 @@ public class BeaconBeamDTO implements IBaseDTO<DhBlockPos>
|
|||||||
//===========//
|
//===========//
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DhBlockPos getKey() { return this.pos; }
|
public DhBlockPos getKey() { return this.blockPos; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
package com.seibel.distanthorizons.core.sql.repo;
|
package com.seibel.distanthorizons.core.sql.repo;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
||||||
@@ -60,7 +60,7 @@ public class BeaconBeamRepo extends AbstractDhRepo<DhBlockPos, BeaconBeamDTO>
|
|||||||
public String getTableName() { return "BeaconBeam"; }
|
public String getTableName() { return "BeaconBeam"; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createWhereStatement(DhBlockPos pos) { return "BlockPosX = "+pos.x+" AND BlockPosY = "+pos.y+" AND BlockPosZ = "+pos.z; }
|
public String createWhereStatement(DhBlockPos pos) { return "BlockPosX = "+ pos.getX() +" AND BlockPosY = "+ pos.getY() +" AND BlockPosZ = "+ pos.getZ(); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -100,9 +100,9 @@ public class BeaconBeamRepo extends AbstractDhRepo<DhBlockPos, BeaconBeamDTO>
|
|||||||
PreparedStatement statement = this.createPreparedStatement(sql);
|
PreparedStatement statement = this.createPreparedStatement(sql);
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
statement.setObject(i++, dto.pos.x);
|
statement.setObject(i++, dto.blockPos.getX());
|
||||||
statement.setObject(i++, dto.pos.y);
|
statement.setObject(i++, dto.blockPos.getY());
|
||||||
statement.setObject(i++, dto.pos.z);
|
statement.setObject(i++, dto.blockPos.getZ());
|
||||||
|
|
||||||
statement.setObject(i++, dto.color.getRed());
|
statement.setObject(i++, dto.color.getRed());
|
||||||
statement.setObject(i++, dto.color.getGreen());
|
statement.setObject(i++, dto.color.getGreen());
|
||||||
@@ -132,9 +132,9 @@ public class BeaconBeamRepo extends AbstractDhRepo<DhBlockPos, BeaconBeamDTO>
|
|||||||
|
|
||||||
statement.setObject(i++, System.currentTimeMillis()); // last modified unix time
|
statement.setObject(i++, System.currentTimeMillis()); // last modified unix time
|
||||||
|
|
||||||
statement.setObject(i++, dto.pos.x);
|
statement.setObject(i++, dto.blockPos.getX());
|
||||||
statement.setObject(i++, dto.pos.y);
|
statement.setObject(i++, dto.blockPos.getY());
|
||||||
statement.setObject(i++, dto.pos.z);
|
statement.setObject(i++, dto.blockPos.getZ());
|
||||||
|
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,9 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.sql.repo;
|
package com.seibel.distanthorizons.core.sql.repo;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.sql.dto.ChunkHashDTO;
|
import com.seibel.distanthorizons.core.sql.dto.ChunkHashDTO;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -56,7 +54,7 @@ public class ChunkHashRepo extends AbstractDhRepo<DhChunkPos, ChunkHashDTO>
|
|||||||
public String getTableName() { return "ChunkHash"; }
|
public String getTableName() { return "ChunkHash"; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createWhereStatement(DhChunkPos pos) { return "ChunkPosX = '"+pos.x+"' AND ChunkPosZ = '"+pos.z+"'"; }
|
public String createWhereStatement(DhChunkPos pos) { return "ChunkPosX = '"+ pos.getX() +"' AND ChunkPosZ = '"+ pos.getZ() +"'"; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -93,8 +91,8 @@ public class ChunkHashRepo extends AbstractDhRepo<DhChunkPos, ChunkHashDTO>
|
|||||||
PreparedStatement statement = this.createPreparedStatement(sql);
|
PreparedStatement statement = this.createPreparedStatement(sql);
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
statement.setObject(i++, dto.pos.x);
|
statement.setObject(i++, dto.pos.getX());
|
||||||
statement.setObject(i++, dto.pos.z);
|
statement.setObject(i++, dto.pos.getZ());
|
||||||
|
|
||||||
statement.setObject(i++, dto.chunkHash);
|
statement.setObject(i++, dto.chunkHash);
|
||||||
|
|
||||||
@@ -119,8 +117,8 @@ public class ChunkHashRepo extends AbstractDhRepo<DhChunkPos, ChunkHashDTO>
|
|||||||
statement.setObject(i++, dto.chunkHash);
|
statement.setObject(i++, dto.chunkHash);
|
||||||
statement.setObject(i++, System.currentTimeMillis()); // last modified unix time
|
statement.setObject(i++, System.currentTimeMillis()); // last modified unix time
|
||||||
|
|
||||||
statement.setObject(i++, dto.pos.x);
|
statement.setObject(i++, dto.pos.getX());
|
||||||
statement.setObject(i++, dto.pos.z);
|
statement.setObject(i++, dto.pos.getZ());
|
||||||
|
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package com.seibel.distanthorizons.core.util;
|
package com.seibel.distanthorizons.core.util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
@@ -29,11 +28,8 @@ import java.util.concurrent.RejectedExecutionException;
|
|||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiVanillaOverdraw;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiVanillaOverdraw;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
|
||||||
import com.seibel.distanthorizons.core.pos.Pos2D;
|
|
||||||
import com.seibel.distanthorizons.core.render.vertexFormat.DefaultLodVertexFormats;
|
import com.seibel.distanthorizons.core.render.vertexFormat.DefaultLodVertexFormats;
|
||||||
import com.seibel.distanthorizons.core.render.vertexFormat.LodVertexFormat;
|
import com.seibel.distanthorizons.core.render.vertexFormat.LodVertexFormat;
|
||||||
import com.seibel.distanthorizons.core.util.gridList.EdgeDistanceBooleanGrid;
|
|
||||||
import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException;
|
import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
@@ -44,9 +40,6 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class holds methods and constants that may be used in multiple places.
|
* This class holds methods and constants that may be used in multiple places.
|
||||||
*
|
|
||||||
* @author James Seibel
|
|
||||||
* @version 2022-12-5
|
|
||||||
*/
|
*/
|
||||||
public class LodUtil
|
public class LodUtil
|
||||||
{
|
{
|
||||||
@@ -54,31 +47,7 @@ public class LodUtil
|
|||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||||
|
|
||||||
/**
|
|
||||||
* Vanilla render distances less than or equal to this will not allow partial
|
|
||||||
* overdraw. The VanillaOverdraw will either be ALWAYS or NEVER.
|
|
||||||
*/
|
|
||||||
public static final int MINIMUM_RENDER_DISTANCE_FOR_PARTIAL_OVERDRAW = 4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Vanilla render distances less than or equal to this will cause the overdraw to
|
|
||||||
* run at a smaller fraction of the vanilla render distance.
|
|
||||||
*/
|
|
||||||
public static final int MINIMUM_RENDER_DISTANCE_FOR_FAR_OVERDRAW = 11;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* alpha used when drawing chunks in debug mode
|
|
||||||
*/
|
|
||||||
public static final int DEBUG_ALPHA = 255; // 0 - 25;
|
|
||||||
|
|
||||||
public static final int COLOR_DEBUG_BLACK = ColorUtil.rgbToInt(DEBUG_ALPHA, 0, 0, 0);
|
|
||||||
public static final int COLOR_DEBUG_WHITE = ColorUtil.rgbToInt(DEBUG_ALPHA, 255, 255, 255);
|
|
||||||
public static final int COLOR_INVISIBLE = ColorUtil.rgbToInt(0, 0, 0, 0);
|
|
||||||
|
|
||||||
//FIXME: WE NEED MORE COLORS!!!!
|
|
||||||
/**
|
/**
|
||||||
* In order of nearest to farthest: <br>
|
* In order of nearest to farthest: <br>
|
||||||
* Red, Orange, Yellow, Green, Cyan, Blue, Magenta, white, gray, black
|
* Red, Orange, Yellow, Green, Cyan, Blue, Magenta, white, gray, black
|
||||||
@@ -166,92 +135,9 @@ public class LodUtil
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=========//
|
||||||
/**
|
// methods //
|
||||||
* Gets the ServerWorld for the relevant dimension.
|
//=========//
|
||||||
*
|
|
||||||
* @return null if there is no ServerWorld for the given dimension
|
|
||||||
*/
|
|
||||||
public static ILevelWrapper getServerWorldFromDimension(IDimensionTypeWrapper newDimension)
|
|
||||||
{
|
|
||||||
if (!MC_CLIENT.hasSinglePlayerServer())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
Iterable<ILevelWrapper> worlds = MC_CLIENT.getAllServerWorlds();
|
|
||||||
ILevelWrapper returnWorld = null;
|
|
||||||
|
|
||||||
for (ILevelWrapper world : worlds)
|
|
||||||
{
|
|
||||||
if (world.getDimensionType() == newDimension)
|
|
||||||
{
|
|
||||||
returnWorld = world;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnWorld;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static int computeOverdrawOffset()
|
|
||||||
{
|
|
||||||
int chunkRenderDist = MC_RENDER.getRenderDistance() + 1;
|
|
||||||
EDhApiVanillaOverdraw overdraw = EDhApiVanillaOverdraw.ALWAYS; //Config.Client.Advanced.Graphics.AdvancedGraphics.vanillaOverdraw.get();
|
|
||||||
if (overdraw == EDhApiVanillaOverdraw.ALWAYS) return Integer.MAX_VALUE;
|
|
||||||
|
|
||||||
int offset;
|
|
||||||
if (overdraw == EDhApiVanillaOverdraw.NEVER)
|
|
||||||
{
|
|
||||||
offset = 0; //Config.Client.Advanced.Graphics.AdvancedGraphics.overdrawOffset.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (chunkRenderDist < MINIMUM_RENDER_DISTANCE_FOR_FAR_OVERDRAW)
|
|
||||||
{
|
|
||||||
offset = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
offset = chunkRenderDist / 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chunkRenderDist - offset <= 1)
|
|
||||||
{
|
|
||||||
return Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** not currently used since the new rendering system can't easily toggle single chunks to render */
|
|
||||||
@Deprecated
|
|
||||||
public static EdgeDistanceBooleanGrid readVanillaRenderedChunks()
|
|
||||||
{
|
|
||||||
int offset = computeOverdrawOffset();
|
|
||||||
if (offset == Integer.MAX_VALUE) return null;
|
|
||||||
int renderDist = MC_RENDER.getRenderDistance() + 1;
|
|
||||||
|
|
||||||
Iterator<DhChunkPos> posIter = MC_RENDER.getVanillaRenderedChunks().iterator();
|
|
||||||
|
|
||||||
return new EdgeDistanceBooleanGrid(new Iterator<Pos2D>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean hasNext()
|
|
||||||
{
|
|
||||||
return posIter.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pos2D next()
|
|
||||||
{
|
|
||||||
DhChunkPos pos = posIter.next();
|
|
||||||
return new Pos2D(pos.x, pos.z);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
MC_CLIENT.getPlayerChunkPos().x - renderDist,
|
|
||||||
MC_CLIENT.getPlayerChunkPos().z - renderDist,
|
|
||||||
renderDist * 2 + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the chunk int position for the given double position */
|
/** Returns the chunk int position for the given double position */
|
||||||
public static int getChunkPosFromDouble(double value) { return (int) Math.floor(value / CHUNK_WIDTH); }
|
public static int getChunkPosFromDouble(double value) { return (int) Math.floor(value / CHUNK_WIDTH); }
|
||||||
@@ -275,11 +161,6 @@ public class LodUtil
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkInterrupts() throws InterruptedException
|
|
||||||
{
|
|
||||||
if (Thread.interrupted()) throw new InterruptedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a given string with params using log4j's MessageFormat
|
* Format a given string with params using log4j's MessageFormat
|
||||||
*
|
*
|
||||||
@@ -290,26 +171,7 @@ public class LodUtil
|
|||||||
* Do not use it for deserialization or naming of objects.</b>
|
* Do not use it for deserialization or naming of objects.</b>
|
||||||
* @author leetom
|
* @author leetom
|
||||||
*/
|
*/
|
||||||
public static String formatLog(String str, Object... param)
|
public static String formatLog(String str, Object... param) { return LOGGER.getMessageFactory().newMessage(str, param).getFormattedMessage(); }
|
||||||
{
|
|
||||||
return LOGGER.getMessageFactory().newMessage(str, param).getFormattedMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class AssertFailureException extends RuntimeException
|
public static class AssertFailureException extends RuntimeException
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-3
@@ -829,7 +829,7 @@ public class RenderDataPointReducingList
|
|||||||
int size = view.size();
|
int size = view.size();
|
||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
{
|
{
|
||||||
return RenderDataPointUtil.createVoidDataPoint();
|
return RenderDataPointUtil.EMPTY_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
long highestDataPoint;
|
long highestDataPoint;
|
||||||
@@ -849,7 +849,7 @@ public class RenderDataPointReducingList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//no visible segments, return void.
|
//no visible segments, return void.
|
||||||
return RenderDataPointUtil.createVoidDataPoint();
|
return RenderDataPointUtil.EMPTY_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
//second loop: merge the rest of the segments.
|
//second loop: merge the rest of the segments.
|
||||||
@@ -889,7 +889,7 @@ public class RenderDataPointReducingList
|
|||||||
// so, if we didn't set any data points, add a void data point.
|
// so, if we didn't set any data points, add a void data point.
|
||||||
if (writeIndex == 0)
|
if (writeIndex == 0)
|
||||||
{
|
{
|
||||||
view.set(writeIndex++, RenderDataPointUtil.createVoidDataPoint());
|
view.set(writeIndex++, RenderDataPointUtil.EMPTY_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int size = view.size(); writeIndex < size; writeIndex++)
|
for (int size = view.size(); writeIndex < size; writeIndex++)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.util;
|
package com.seibel.distanthorizons.core.util;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||||
import com.seibel.distanthorizons.core.level.AbstractDhLevel;
|
import com.seibel.distanthorizons.core.level.AbstractDhLevel;
|
||||||
import com.seibel.distanthorizons.core.logging.SpamReducedLogger;
|
import com.seibel.distanthorizons.core.logging.SpamReducedLogger;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
|
||||||
@@ -110,8 +111,6 @@ public class RenderDataPointUtil
|
|||||||
// datapoint manipulation //
|
// datapoint manipulation //
|
||||||
//========================//
|
//========================//
|
||||||
|
|
||||||
public static long createVoidDataPoint() { return EMPTY_DATA; }
|
|
||||||
|
|
||||||
public static long createDataPoint(int height, int depth, int color, int lightSky, int lightBlock, int irisBlockMaterialId)
|
public static long createDataPoint(int height, int depth, int color, int lightSky, int lightBlock, int irisBlockMaterialId)
|
||||||
{
|
{
|
||||||
return createDataPoint(
|
return createDataPoint(
|
||||||
@@ -245,11 +244,11 @@ public class RenderDataPointUtil
|
|||||||
" Y-:" + getYMin(dataPoint) +
|
" Y-:" + getYMin(dataPoint) +
|
||||||
" argb:" + getAlpha(dataPoint) + " " +
|
" argb:" + getAlpha(dataPoint) + " " +
|
||||||
getRed(dataPoint) + " " +
|
getRed(dataPoint) + " " +
|
||||||
getBlue(dataPoint) + " " +
|
getGreen(dataPoint) + " " +
|
||||||
getGreen(dataPoint) +
|
getBlue(dataPoint) +
|
||||||
" BL:" + getLightBlock(dataPoint) +
|
" BL:" + getLightBlock(dataPoint) +
|
||||||
" SL:" + getLightSky(dataPoint) +
|
" SL:" + getLightSky(dataPoint) +
|
||||||
" BID:" + getBlockMaterialId(dataPoint);
|
" MAT:" + getBlockMaterialId(dataPoint) + "["+ EDhApiBlockMaterial.getFromIndex(getBlockMaterialId(dataPoint))+"]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,352 +302,6 @@ public class RenderDataPointUtil
|
|||||||
list.reduce(output.verticalSize());
|
list.reduce(output.verticalSize());
|
||||||
list.copyTo(output);
|
list.copyTo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//old logic left here in case it's ever needed again.
|
|
||||||
/*
|
|
||||||
if (output.dataCount() != 1)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("output must be only reserved for one datapoint!");
|
|
||||||
}
|
|
||||||
|
|
||||||
int inputVerticalSize = sourceData.verticalSize();
|
|
||||||
int outputVerticalSize = output.verticalSize();
|
|
||||||
output.fill(0);
|
|
||||||
|
|
||||||
//dataCount indicate how many position we are merging in one position
|
|
||||||
int dataCount = sourceData.dataCount();
|
|
||||||
|
|
||||||
// We initialize the arrays that are going to be used
|
|
||||||
int heightAndDepthLength = (MAX_WORLD_Y_SIZE / 2 + 16) * 2;
|
|
||||||
short[] heightAndDepth = tLocalHeightAndDepth.get();
|
|
||||||
if (heightAndDepth == null || heightAndDepth.length != heightAndDepthLength)
|
|
||||||
{
|
|
||||||
heightAndDepth = new short[heightAndDepthLength];
|
|
||||||
tLocalHeightAndDepth.set(heightAndDepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte genMode = getGenerationMode(sourceData.get(0));
|
|
||||||
if (genMode == 0)
|
|
||||||
{
|
|
||||||
genMode = 1; // FIXME: Hack to make the version 10 genMode never be 0.
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean allEmpty = true;
|
|
||||||
boolean allVoid = true;
|
|
||||||
boolean limited = false;
|
|
||||||
boolean allDefault;
|
|
||||||
long singleData;
|
|
||||||
|
|
||||||
short yMin;
|
|
||||||
short yMax;
|
|
||||||
int count = 0;
|
|
||||||
int i;
|
|
||||||
int ii;
|
|
||||||
|
|
||||||
int[] indices = tLocalIndices.get();
|
|
||||||
if (indices == null || indices.length != dataCount)
|
|
||||||
{
|
|
||||||
indices = new int[dataCount];
|
|
||||||
tLocalIndices.set(indices);
|
|
||||||
}
|
|
||||||
Arrays.fill(indices, 0);
|
|
||||||
|
|
||||||
boolean[] increaseIndex = tLocalIncreaseIndex.get();
|
|
||||||
if (increaseIndex == null || increaseIndex.length != dataCount)
|
|
||||||
{
|
|
||||||
increaseIndex = new boolean[dataCount];
|
|
||||||
tLocalIncreaseIndex.set(increaseIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean[] indexHandled = tLocalIndexHandled.get();
|
|
||||||
if (indexHandled == null || indexHandled.length != dataCount)
|
|
||||||
{
|
|
||||||
indexHandled = new boolean[dataCount];
|
|
||||||
tLocalIndexHandled.set(indexHandled);
|
|
||||||
}
|
|
||||||
|
|
||||||
long tempData;
|
|
||||||
for (int index = 0; index < dataCount; index++)
|
|
||||||
{
|
|
||||||
tempData = sourceData.get(index * inputVerticalSize);
|
|
||||||
allVoid = allVoid && RenderDataPointUtil.isVoid(tempData);
|
|
||||||
allEmpty = allEmpty && !RenderDataPointUtil.doesDataPointExist(tempData);
|
|
||||||
}
|
|
||||||
|
|
||||||
//We check if there is any data that's not empty or void
|
|
||||||
if (allEmpty)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (allVoid)
|
|
||||||
{
|
|
||||||
output.set(0, createVoidDataPoint(genMode));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//this check is used only to see if we have checked all the values in the array
|
|
||||||
boolean stillHasDataToCheck = true;
|
|
||||||
short prevDepth;
|
|
||||||
|
|
||||||
while (stillHasDataToCheck)
|
|
||||||
{
|
|
||||||
Arrays.fill(indexHandled, false);
|
|
||||||
boolean connected = true;
|
|
||||||
int newHeight = -10000;
|
|
||||||
int newDepth = -10000;
|
|
||||||
int tempYMax;
|
|
||||||
int tempYMin;
|
|
||||||
while (connected)
|
|
||||||
{
|
|
||||||
Arrays.fill(increaseIndex, false);
|
|
||||||
for (int index = 0; index < dataCount; index++)
|
|
||||||
{
|
|
||||||
if (indices[index] < inputVerticalSize)
|
|
||||||
{
|
|
||||||
tempData = sourceData.get(index * inputVerticalSize + indices[index]);
|
|
||||||
if (!RenderDataPointUtil.isVoid(tempData) && RenderDataPointUtil.doesDataPointExist(tempData))
|
|
||||||
{
|
|
||||||
tempYMax = RenderDataPointUtil.getYMax(tempData);
|
|
||||||
tempYMin = RenderDataPointUtil.getYMin(tempData);
|
|
||||||
if (tempYMin >= newHeight)
|
|
||||||
{
|
|
||||||
//First case
|
|
||||||
//the column we are checking is higher than the current column
|
|
||||||
newDepth = tempYMin;
|
|
||||||
newHeight = tempYMax;
|
|
||||||
Arrays.fill(increaseIndex, false);
|
|
||||||
Arrays.fill(indexHandled, false);
|
|
||||||
increaseIndex[index] = true;
|
|
||||||
indexHandled[index] = true;
|
|
||||||
}
|
|
||||||
else if ((tempYMin >= newDepth) && (tempYMax <= newHeight))
|
|
||||||
{
|
|
||||||
//the column we are checking is contained in the current column
|
|
||||||
//we simply increase this index
|
|
||||||
increaseIndex[index] = true;
|
|
||||||
indexHandled[index] = true;
|
|
||||||
}
|
|
||||||
else if (tempYMax > newHeight && tempYMin <= newDepth)
|
|
||||||
{
|
|
||||||
newDepth = tempYMin;
|
|
||||||
newHeight = tempYMax;
|
|
||||||
increaseIndex[index] = true;
|
|
||||||
indexHandled[index] = true;
|
|
||||||
}
|
|
||||||
else if (tempYMax > newDepth && tempYMax <= newHeight)
|
|
||||||
{
|
|
||||||
//the column we are checking touches the current column from the bottom
|
|
||||||
//for this reason we extend what's below
|
|
||||||
|
|
||||||
//We want to avoid to expend this column if it has already been expanded by
|
|
||||||
//this index
|
|
||||||
if (!indexHandled[index])
|
|
||||||
{
|
|
||||||
newDepth = tempYMin;
|
|
||||||
increaseIndex[index] = true;
|
|
||||||
indexHandled[index] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (tempYMin < newHeight && tempYMin > newDepth)
|
|
||||||
{
|
|
||||||
//the column we are checking touches the current column from the top
|
|
||||||
//for this reason we extend the top
|
|
||||||
newHeight = tempYMax;
|
|
||||||
increaseIndex[index] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
indexHandled[index] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//if we added any new data there is a chance that we could add more
|
|
||||||
//for this reason we would continue
|
|
||||||
//if no data is added than the column hasn't changed.
|
|
||||||
//for this reason we can start working on a new column
|
|
||||||
connected = false;
|
|
||||||
for (int index = 0; index < dataCount; index++)
|
|
||||||
{
|
|
||||||
if (increaseIndex[index])
|
|
||||||
{
|
|
||||||
connected = true;
|
|
||||||
indices[index]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Now we add the height and depth data we extracted to the heightAndDepth array
|
|
||||||
if (newDepth != newHeight)
|
|
||||||
{
|
|
||||||
if (count != 0)
|
|
||||||
{
|
|
||||||
prevDepth = heightAndDepth[(count - 1) * 2 + 1];
|
|
||||||
if (newHeight > prevDepth)
|
|
||||||
{
|
|
||||||
newHeight = (short) Math.min(newHeight, prevDepth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
heightAndDepth[count * 2] = (short) newHeight;
|
|
||||||
heightAndDepth[count * 2 + 1] = (short) newDepth;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Here we check the condition that makes the loop continue
|
|
||||||
//We stop the loop only if there is no more data to check
|
|
||||||
stillHasDataToCheck = false;
|
|
||||||
for (int index = 0; index < dataCount; index++)
|
|
||||||
{
|
|
||||||
if (indices[index] < inputVerticalSize)
|
|
||||||
{
|
|
||||||
tempData = sourceData.get(index * inputVerticalSize + indices[index]);
|
|
||||||
stillHasDataToCheck |= !RenderDataPointUtil.isVoid(tempData) && RenderDataPointUtil.doesDataPointExist(tempData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//we limit the vertical portion to maxVerticalData
|
|
||||||
int j = 0;
|
|
||||||
while (count > outputVerticalSize)
|
|
||||||
{
|
|
||||||
limited = true;
|
|
||||||
ii = MAX_WORLD_Y_SIZE;
|
|
||||||
for (i = 0; i < count - 1; i++)
|
|
||||||
{
|
|
||||||
if (heightAndDepth[i * 2 + 1] - heightAndDepth[(i + 1) * 2] <= ii)
|
|
||||||
{
|
|
||||||
ii = heightAndDepth[i * 2 + 1] - heightAndDepth[(i + 1) * 2];
|
|
||||||
j = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
heightAndDepth[j * 2 + 1] = heightAndDepth[(j + 1) * 2 + 1];
|
|
||||||
for (i = j + 1; i < count - 1; i++)
|
|
||||||
{
|
|
||||||
heightAndDepth[i * 2] = heightAndDepth[(i + 1) * 2];
|
|
||||||
heightAndDepth[i * 2 + 1] = heightAndDepth[(i + 1) * 2 + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
//System.arraycopy(heightAndDepth, j + 1, heightAndDepth, j, count - j - 1);
|
|
||||||
count--;
|
|
||||||
}
|
|
||||||
//As standard the vertical lods are ordered from top to bottom
|
|
||||||
|
|
||||||
if (!limited && dataCount == 1) // This mean source vertSize < output vertSize AND both dataCount == 1
|
|
||||||
{
|
|
||||||
sourceData.copyTo(output.data, output.offset, output.vertSize);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
//We want to efficiently memorize indexes
|
|
||||||
int[] dataIndexesCache = tDataIndexCache.get();
|
|
||||||
if (dataIndexesCache == null || dataIndexesCache.length != dataCount)
|
|
||||||
{
|
|
||||||
dataIndexesCache = new int[dataCount];
|
|
||||||
tDataIndexCache.set(dataIndexesCache);
|
|
||||||
}
|
|
||||||
Arrays.fill(dataIndexesCache, 0);
|
|
||||||
|
|
||||||
|
|
||||||
//For each lod height-depth value we have found we now want to generate the rest of the data
|
|
||||||
//by merging all lods at lower level that are contained inside the new ones
|
|
||||||
for (j = 0; j < count; j++)
|
|
||||||
{
|
|
||||||
//We firstly collect height and depth data
|
|
||||||
//this will be added to each realtive long DataPoint
|
|
||||||
yMax = heightAndDepth[j * 2];
|
|
||||||
yMin = heightAndDepth[j * 2 + 1];
|
|
||||||
|
|
||||||
//if both height and depth are at 0 then we finished
|
|
||||||
if ((yMin == 0 && yMax == 0) || j >= heightAndDepth.length / 2)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//We initialize data useful for the merge
|
|
||||||
int numberOfChildren = 0;
|
|
||||||
allEmpty = true;
|
|
||||||
allVoid = true;
|
|
||||||
|
|
||||||
//We initialize all the new values that we are going to put in the dataPoint
|
|
||||||
int tempAlpha = 0;
|
|
||||||
int tempRed = 0;
|
|
||||||
int tempGreen = 0;
|
|
||||||
int tempBlue = 0;
|
|
||||||
int tempLightBlock = 0;
|
|
||||||
int tempLightSky = 0;
|
|
||||||
long data = 0;
|
|
||||||
|
|
||||||
//For each position that we want to merge
|
|
||||||
for (int index = 0; index < dataCount; index++)
|
|
||||||
{
|
|
||||||
//we scan the lods in the position from top to bottom
|
|
||||||
while (dataIndexesCache[index] < inputVerticalSize)
|
|
||||||
{
|
|
||||||
singleData = sourceData.get(index * inputVerticalSize + dataIndexesCache[index]);
|
|
||||||
if (doesDataPointExist(singleData) && !isVoid(singleData))
|
|
||||||
{
|
|
||||||
dataIndexesCache[index]++;
|
|
||||||
if ((yMin <= getYMin(singleData) && getYMin(singleData) < yMax)
|
|
||||||
|| (yMin < getYMax(singleData) && getYMax(singleData) <= yMax))
|
|
||||||
{
|
|
||||||
data = singleData;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!doesDataPointExist(data))
|
|
||||||
{
|
|
||||||
data = createVoidDataPoint(genMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doesDataPointExist(data))
|
|
||||||
{
|
|
||||||
allEmpty = false;
|
|
||||||
if (!isVoid(data))
|
|
||||||
{
|
|
||||||
numberOfChildren++;
|
|
||||||
allVoid = false;
|
|
||||||
tempAlpha = Math.max(getAlpha(data), tempAlpha);
|
|
||||||
tempRed += getRed(data) * getRed(data);
|
|
||||||
tempGreen += getGreen(data) * getGreen(data);
|
|
||||||
tempBlue += getBlue(data) * getBlue(data);
|
|
||||||
tempLightBlock += getLightBlock(data);
|
|
||||||
tempLightSky += getLightSky(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//we have at least 1 child
|
|
||||||
if (dataCount != 1)
|
|
||||||
{
|
|
||||||
tempRed = tempRed / numberOfChildren;
|
|
||||||
tempGreen = tempGreen / numberOfChildren;
|
|
||||||
tempBlue = tempBlue / numberOfChildren;
|
|
||||||
tempLightBlock = tempLightBlock / numberOfChildren;
|
|
||||||
tempLightSky = tempLightSky / numberOfChildren;
|
|
||||||
}
|
|
||||||
|
|
||||||
//data = createDataPoint(tempAlpha, tempRed, tempGreen, tempBlue, height, depth, tempLightSky, tempLightBlock, tempGenMode, allDefault);
|
|
||||||
//if (j > 0 && getColor(data) == getColor(dataPoint[j]))
|
|
||||||
//{
|
|
||||||
// add simplification at the end due to color
|
|
||||||
//}
|
|
||||||
|
|
||||||
output.set(j, createDataPoint(tempAlpha, (int) Math.sqrt(tempRed), (int) Math.sqrt(tempGreen), (int) Math.sqrt(tempBlue), yMax, yMin, tempLightSky, tempLightBlock, genMode));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,15 +23,12 @@ import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
|||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
|
||||||
import com.seibel.distanthorizons.core.world.IDhClientWorld;
|
import com.seibel.distanthorizons.core.world.IDhClientWorld;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,93 +45,6 @@ public class RenderUtil
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=================//
|
|
||||||
// culling methods //
|
|
||||||
//=================//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the given ChunkPos is in the loaded area of the world.
|
|
||||||
*
|
|
||||||
* @param center the center of the loaded world (probably the player's ChunkPos)
|
|
||||||
*/
|
|
||||||
public static boolean isChunkPosInLoadedArea(DhChunkPos pos, DhChunkPos center)
|
|
||||||
{
|
|
||||||
return (pos.x >= center.x - MC_RENDER.getRenderDistance()
|
|
||||||
&& pos.x <= center.x + MC_RENDER.getRenderDistance())
|
|
||||||
&&
|
|
||||||
(pos.z >= center.z - MC_RENDER.getRenderDistance()
|
|
||||||
&& pos.z <= center.z + MC_RENDER.getRenderDistance());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the given coordinate is in the loaded area of the world.
|
|
||||||
*
|
|
||||||
* @param centerCoordinate the center of the loaded world
|
|
||||||
*/
|
|
||||||
public static boolean isCoordinateInLoadedArea(int x, int z, int centerCoordinate)
|
|
||||||
{
|
|
||||||
return (x >= centerCoordinate - MC_RENDER.getRenderDistance()
|
|
||||||
&& x <= centerCoordinate + MC_RENDER.getRenderDistance())
|
|
||||||
&&
|
|
||||||
(z >= centerCoordinate - MC_RENDER.getRenderDistance()
|
|
||||||
&& z <= centerCoordinate + MC_RENDER.getRenderDistance());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the coordinates that are in the center half of the given
|
|
||||||
* 2D matrix, starting at (0,0) and going to (2 * lodRadius, 2 * lodRadius).
|
|
||||||
*/
|
|
||||||
public static boolean isCoordinateInNearFogArea(int i, int j, int lodRadius)
|
|
||||||
{
|
|
||||||
int halfRadius = lodRadius / 2;
|
|
||||||
|
|
||||||
return (i >= lodRadius - halfRadius
|
|
||||||
&& i <= lodRadius + halfRadius)
|
|
||||||
&&
|
|
||||||
(j >= lodRadius - halfRadius
|
|
||||||
&& j <= lodRadius + halfRadius);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if one of the region's 4 corners is in front
|
|
||||||
* of the camera.
|
|
||||||
*/
|
|
||||||
public static boolean isRegionInViewFrustum(DhBlockPos playerBlockPos, Vec3f cameraDir, int vboRegionX, int vboRegionZ)
|
|
||||||
{
|
|
||||||
// convert the vbo position into a direction vector
|
|
||||||
// starting from the player's position
|
|
||||||
Vec3f vboVec = new Vec3f(vboRegionX * LodUtil.REGION_WIDTH, 0, vboRegionZ * LodUtil.REGION_WIDTH);
|
|
||||||
Vec3f playerVec = new Vec3f(playerBlockPos.x, playerBlockPos.y, playerBlockPos.z);
|
|
||||||
|
|
||||||
vboVec.subtract(playerVec);
|
|
||||||
|
|
||||||
// calculate the 4 corners
|
|
||||||
Vec3f vboSeVec = new Vec3f(vboVec.x + LodUtil.REGION_WIDTH, vboVec.y, vboVec.z + LodUtil.REGION_WIDTH);
|
|
||||||
Vec3f vboSwVec = new Vec3f(vboVec.x, vboVec.y, vboVec.z + LodUtil.REGION_WIDTH);
|
|
||||||
Vec3f vboNwVec = new Vec3f(vboVec.x, vboVec.y, vboVec.z);
|
|
||||||
Vec3f vboNeVec = new Vec3f(vboVec.x + LodUtil.REGION_WIDTH, vboVec.y, vboVec.z);
|
|
||||||
|
|
||||||
// if any corner is visible, this region should be rendered
|
|
||||||
return isNormalizedVectorInViewFrustum(vboSeVec, cameraDir) ||
|
|
||||||
isNormalizedVectorInViewFrustum(vboSwVec, cameraDir) ||
|
|
||||||
isNormalizedVectorInViewFrustum(vboNwVec, cameraDir) ||
|
|
||||||
isNormalizedVectorInViewFrustum(vboNeVec, cameraDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Currently takes the dot product of the two vectors,
|
|
||||||
* but in the future could do more complicated frustum culling tests.
|
|
||||||
*/
|
|
||||||
private static boolean isNormalizedVectorInViewFrustum(Vec3f objectVector, Vec3f cameraDir)
|
|
||||||
{
|
|
||||||
// the -0.1 is to offer a slight buffer, so we are
|
|
||||||
// more likely to render LODs and thus, hopefully prevent
|
|
||||||
// flickering or odd disappearances
|
|
||||||
return objectVector.dotProduct(cameraDir) > -0.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=====================//
|
//=====================//
|
||||||
// matrix manipulation //
|
// matrix manipulation //
|
||||||
//=====================//
|
//=====================//
|
||||||
@@ -166,19 +76,6 @@ public class RenderUtil
|
|||||||
return mcModelViewMat.copy();
|
return mcModelViewMat.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* create and return a new combined modelView/projection matrix based on MC's modelView and projection matrices
|
|
||||||
*
|
|
||||||
* @param mcProjMat Minecraft's current projection matrix
|
|
||||||
* @param mcModelViewMat Minecraft's current model view matrix
|
|
||||||
*/
|
|
||||||
public static Mat4f createCombinedModelViewProjectionMatrix(Mat4f mcProjMat, Mat4f mcModelViewMat, float partialTicks)
|
|
||||||
{
|
|
||||||
Mat4f lodProj = createLodProjectionMatrix(mcProjMat, partialTicks);
|
|
||||||
lodProj.multiply(createLodModelViewMatrix(mcModelViewMat));
|
|
||||||
return lodProj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getNearClipPlaneDistanceInBlocks(float partialTicks)
|
public static float getNearClipPlaneDistanceInBlocks(float partialTicks)
|
||||||
{
|
{
|
||||||
int chunkRenderDistance = MC_RENDER.getRenderDistance();
|
int chunkRenderDistance = MC_RENDER.getRenderDistance();
|
||||||
@@ -243,7 +140,7 @@ public class RenderUtil
|
|||||||
{
|
{
|
||||||
// if the player is a significant distance above the work, increase the
|
// if the player is a significant distance above the work, increase the
|
||||||
// near clip plane to fix Z imprecision issues
|
// near clip plane to fix Z imprecision issues
|
||||||
int playerHeight = MC.getPlayerBlockPos().y;
|
int playerHeight = MC.getPlayerBlockPos().getY();
|
||||||
int levelMaxHeight = level.getMaxHeight();
|
int levelMaxHeight = level.getMaxHeight();
|
||||||
if (playerHeight > levelMaxHeight + 1_000)
|
if (playerHeight > levelMaxHeight + 1_000)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -87,11 +87,11 @@ public class ArrayGridList<T> extends ArrayList<T>
|
|||||||
|
|
||||||
public final T get(Pos2D pos)
|
public final T get(Pos2D pos)
|
||||||
{
|
{
|
||||||
return get(pos.x, pos.y);
|
return get(pos.getX(), pos.getY());
|
||||||
}
|
}
|
||||||
public final T set(Pos2D pos, T e)
|
public final T set(Pos2D pos, T e)
|
||||||
{
|
{
|
||||||
return set(pos.x, pos.y, e);
|
return set(pos.getX(), pos.getY(), e);
|
||||||
}
|
}
|
||||||
public T get(int x, int y)
|
public T get(int x, int y)
|
||||||
{
|
{
|
||||||
|
|||||||
-100
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.util.gridList;
|
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.pos.Pos2D;
|
|
||||||
import com.seibel.distanthorizons.core.util.objects.BoolType;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.function.IntPredicate;
|
|
||||||
|
|
||||||
public class EdgeDistanceBooleanGrid extends PosArrayGridList<BoolType>
|
|
||||||
{
|
|
||||||
ArrayGridList<Integer> edgeCache = null;
|
|
||||||
|
|
||||||
public EdgeDistanceBooleanGrid(Iterator<Pos2D> posIter, int offsetX, int offsetY, int gridSize)
|
|
||||||
{
|
|
||||||
super(gridSize, offsetX, offsetY);
|
|
||||||
while (posIter.hasNext())
|
|
||||||
{
|
|
||||||
Pos2D p = posIter.next();
|
|
||||||
this.set(p, BoolType.TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return false if it is indeed updated
|
|
||||||
private static boolean updatePos(ArrayGridList<Integer> grid, int ox, int oy)
|
|
||||||
{
|
|
||||||
if (grid.get(ox, oy) < 0) return true;
|
|
||||||
if (ox == 0 || oy == 0 || ox == grid.gridSize - 1 || oy == grid.gridSize - 1)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int v = grid.get(ox, oy);
|
|
||||||
if (
|
|
||||||
grid.get(ox, oy + 1) < v ||
|
|
||||||
grid.get(ox, oy - 1) < v ||
|
|
||||||
grid.get(ox + 1, oy) < v ||
|
|
||||||
grid.get(ox - 1, oy) < v
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
grid.set(ox, oy, v + 1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//FIXME: This is slow and expensive. Use queue to make this skip recheck done pos
|
|
||||||
private void computeEdgeCache()
|
|
||||||
{
|
|
||||||
if (edgeCache != null) return;
|
|
||||||
|
|
||||||
edgeCache = new ArrayGridList<Integer>(gridSize, (ox, oy) -> {
|
|
||||||
BoolType b = get(ox + getOffsetX(), oy + getOffsetY());
|
|
||||||
return b == null ? -1 : 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
final boolean[] isDone = {false};
|
|
||||||
while (!isDone[0])
|
|
||||||
{
|
|
||||||
isDone[0] = true;
|
|
||||||
edgeCache.forEachPos((ox, oy) -> {
|
|
||||||
isDone[0] &= updatePos(edgeCache, ox, oy);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0 means right on the edge, while 1 means 1 ceil away. Uses Manhattan Distance
|
|
||||||
public <T extends ArrayGridList<BoolType>> void flagAllWithDistance(T list, IntPredicate predicate)
|
|
||||||
{
|
|
||||||
computeEdgeCache();
|
|
||||||
edgeCache.forEachPos((ox, oy) -> {
|
|
||||||
int v = edgeCache.get(ox, oy);
|
|
||||||
if (v < 0 || !predicate.test(v)) return;
|
|
||||||
list.set(ox + getOffsetX(), oy + getOffsetY(), BoolType.TRUE);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
+32
-32
@@ -49,7 +49,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
// constructors //
|
// constructors //
|
||||||
//==============//
|
//==============//
|
||||||
|
|
||||||
public MovableGridRingList(int halfWidth, Pos2D center) { this(halfWidth, center.x, center.y); }
|
public MovableGridRingList(int halfWidth, Pos2D center) { this(halfWidth, center.getX(), center.getY()); }
|
||||||
public MovableGridRingList(int halfWidth, int centerX, int centerY)
|
public MovableGridRingList(int halfWidth, int centerX, int centerY)
|
||||||
{
|
{
|
||||||
super((halfWidth * 2 + 1) * (halfWidth * 2 + 1));
|
super((halfWidth * 2 + 1) * (halfWidth * 2 + 1));
|
||||||
@@ -68,7 +68,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
//=====================//
|
//=====================//
|
||||||
|
|
||||||
/** see {@link MovableGridRingList#get(int, int)} for full documentation */
|
/** see {@link MovableGridRingList#get(int, int)} for full documentation */
|
||||||
public T get(Pos2D pos) { return this.get(pos.x, pos.y); }
|
public T get(Pos2D pos) { return this.get(pos.getX(), pos.getY()); }
|
||||||
/** returns null if x,y is outside the grid */
|
/** returns null if x,y is outside the grid */
|
||||||
public T get(int x, int y)
|
public T get(int x, int y)
|
||||||
{
|
{
|
||||||
@@ -100,7 +100,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
|
|
||||||
|
|
||||||
/** see {@link MovableGridRingList#set(int, int, T)} for full documentation */
|
/** see {@link MovableGridRingList#set(int, int, T)} for full documentation */
|
||||||
public boolean set(Pos2D pos, T item) { return this.set(pos.x, pos.y, item); }
|
public boolean set(Pos2D pos, T item) { return this.set(pos.getX(), pos.getY(), item); }
|
||||||
/** returns false if x,y is outside the grid */
|
/** returns false if x,y is outside the grid */
|
||||||
public boolean set(int x, int y, T item)
|
public boolean set(int x, int y, T item)
|
||||||
{
|
{
|
||||||
@@ -132,7 +132,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** see {@link MovableGridRingList#setChained(int, int, T)} for full documentation */
|
/** see {@link MovableGridRingList#setChained(int, int, T)} for full documentation */
|
||||||
public T setChained(Pos2D pos, T item) { return this.setChained(pos.x, pos.y, item); }
|
public T setChained(Pos2D pos, T item) { return this.setChained(pos.getX(), pos.getY(), item); }
|
||||||
/**
|
/**
|
||||||
* returns null if x,y is outside the grid
|
* returns null if x,y is outside the grid
|
||||||
* Otherwise, returns the new value
|
* Otherwise, returns the new value
|
||||||
@@ -146,7 +146,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
//================//
|
//================//
|
||||||
|
|
||||||
/** see {@link MovableGridRingList#swap(int, int, T)} for full documentation */
|
/** see {@link MovableGridRingList#swap(int, int, T)} for full documentation */
|
||||||
public T swap(Pos2D pos, T item) { return this.swap(pos.x, pos.y, item); }
|
public T swap(Pos2D pos, T item) { return this.swap(pos.getX(), pos.getY(), item); }
|
||||||
/** returns the input item if x,y is outside the grid */
|
/** returns the input item if x,y is outside the grid */
|
||||||
public T swap(int x, int y, T item)
|
public T swap(int x, int y, T item)
|
||||||
{
|
{
|
||||||
@@ -178,7 +178,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
|
|
||||||
|
|
||||||
/** see {@link MovableGridRingList#remove(int, int)} for full documentation */
|
/** see {@link MovableGridRingList#remove(int, int)} for full documentation */
|
||||||
public T remove(Pos2D pos) { return this.remove(pos.x, pos.y); }
|
public T remove(Pos2D pos) { return this.remove(pos.getX(), pos.getY()); }
|
||||||
/** remove and return the item at x,y; returns null if the x,y are outside the grid */
|
/** remove and return the item at x,y; returns null if the x,y are outside the grid */
|
||||||
public T remove(int x, int y) { return this.swap(x, y, null); }
|
public T remove(int x, int y) { return this.swap(x, y, null); }
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
Pos2D cPos = this.minPosRef.get();
|
Pos2D cPos = this.minPosRef.get();
|
||||||
int newMinX = newCenterX - this.halfWidth;
|
int newMinX = newCenterX - this.halfWidth;
|
||||||
int newMinY = newCenterY - this.halfWidth;
|
int newMinY = newCenterY - this.halfWidth;
|
||||||
if (cPos.x == newMinX && cPos.y == newMinY)
|
if (cPos.getX() == newMinX && cPos.getY() == newMinY)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -239,8 +239,8 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
cPos = this.minPosRef.get();
|
cPos = this.minPosRef.get();
|
||||||
int deltaX = newMinX - cPos.x;
|
int deltaX = newMinX - cPos.getX();
|
||||||
int deltaY = newMinY - cPos.y;
|
int deltaY = newMinY - cPos.getY();
|
||||||
if (deltaX == 0 && deltaY == 0)
|
if (deltaX == 0 && deltaY == 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -259,14 +259,14 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
{
|
{
|
||||||
for (int y = 0; y < this.width; y++)
|
for (int y = 0; y < this.width; y++)
|
||||||
{
|
{
|
||||||
Pos2D itemPos = new Pos2D(x + cPos.x, y + cPos.y);
|
Pos2D itemPos = new Pos2D(x + cPos.getX(), y + cPos.getY());
|
||||||
|
|
||||||
if (x - deltaX < 0
|
if (x - deltaX < 0
|
||||||
|| y - deltaY < 0
|
|| y - deltaY < 0
|
||||||
|| x - deltaX >= this.width
|
|| x - deltaX >= this.width
|
||||||
|| y - deltaY >= this.width)
|
|| y - deltaY >= this.width)
|
||||||
{
|
{
|
||||||
T item = this._swapUnsafe(itemPos.x, itemPos.y, null);
|
T item = this._swapUnsafe(itemPos.getX(), itemPos.getY(), null);
|
||||||
if (item != null && removedItemConsumer != null)
|
if (item != null && removedItemConsumer != null)
|
||||||
{
|
{
|
||||||
removedItemConsumer.accept(item);
|
removedItemConsumer.accept(item);
|
||||||
@@ -300,10 +300,10 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
// position getters //
|
// position getters //
|
||||||
//==================//
|
//==================//
|
||||||
|
|
||||||
public Pos2D getCenter() { return new Pos2D(this.minPosRef.get().x + this.halfWidth, this.minPosRef.get().y + this.halfWidth); }
|
public Pos2D getCenter() { return new Pos2D(this.minPosRef.get().getX() + this.halfWidth, this.minPosRef.get().getY() + this.halfWidth); }
|
||||||
|
|
||||||
public Pos2D getMinPosInRange() { return this.minPosRef.get(); }
|
public Pos2D getMinPosInRange() { return this.minPosRef.get(); }
|
||||||
public Pos2D getMaxPosInRange() { return new Pos2D(this.minPosRef.get().x + this.width - 1, this.minPosRef.get().y + this.width - 1); }
|
public Pos2D getMaxPosInRange() { return new Pos2D(this.minPosRef.get().getX() + this.width - 1, this.minPosRef.get().getY() + this.width - 1); }
|
||||||
|
|
||||||
public int getWidth() { return this.width; }
|
public int getWidth() { return this.width; }
|
||||||
public int getHalfWidth() { return this.halfWidth; }
|
public int getHalfWidth() { return this.halfWidth; }
|
||||||
@@ -321,18 +321,18 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
public boolean inRange(int x, int y)
|
public boolean inRange(int x, int y)
|
||||||
{
|
{
|
||||||
Pos2D minPos = this.minPosRef.get();
|
Pos2D minPos = this.minPosRef.get();
|
||||||
return (x >= minPos.x
|
return (x >= minPos.getX()
|
||||||
&& x < minPos.x + this.width
|
&& x < minPos.getX() + this.width
|
||||||
&& y >= minPos.y
|
&& y >= minPos.getY()
|
||||||
&& y < minPos.y + this.width);
|
&& y < minPos.getY() + this.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean _inRangeAcquired(int x, int y, Pos2D min)
|
private boolean _inRangeAcquired(int x, int y, Pos2D min)
|
||||||
{
|
{
|
||||||
return (x >= min.x
|
return (x >= min.getX()
|
||||||
&& x < min.x + this.width
|
&& x < min.getX() + this.width
|
||||||
&& y >= min.y
|
&& y >= min.getY()
|
||||||
&& y < min.y + this.width);
|
&& y < min.getY() + this.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T _getUnsafe(int x, int y) { return super.get(Math.floorMod(x, this.width) + Math.floorMod(y, this.width) * this.width); }
|
private T _getUnsafe(int x, int y) { return super.get(Math.floorMod(x, this.width) + Math.floorMod(y, this.width) * this.width); }
|
||||||
@@ -379,9 +379,9 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Pos2D min = this.minPosRef.get();
|
Pos2D min = this.minPosRef.get();
|
||||||
for (int x = min.x; x < min.x + this.width; x++)
|
for (int x = min.getX(); x < min.getX() + this.width; x++)
|
||||||
{
|
{
|
||||||
for (int y = min.y; y < min.y + this.width; y++)
|
for (int y = min.getY(); y < min.getY() + this.width; y++)
|
||||||
{
|
{
|
||||||
T t = this._getUnsafe(x, y);
|
T t = this._getUnsafe(x, y);
|
||||||
consumer.accept(t, new Pos2D(x, y));
|
consumer.accept(t, new Pos2D(x, y));
|
||||||
@@ -412,7 +412,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
Pos2D min = this.minPosRef.get();
|
Pos2D min = this.minPosRef.get();
|
||||||
for (Pos2D offset : this.ringPositionIteratorArray)
|
for (Pos2D offset : this.ringPositionIteratorArray)
|
||||||
{
|
{
|
||||||
T item = this._getUnsafe(min.x + offset.x, min.y + offset.y);
|
T item = this._getUnsafe(min.getX() + offset.getX(), min.getY() + offset.getY());
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
consumer.accept(item);
|
consumer.accept(item);
|
||||||
@@ -443,9 +443,9 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
Pos2D min = this.minPosRef.get();
|
Pos2D min = this.minPosRef.get();
|
||||||
for (Pos2D offset : this.ringPositionIteratorArray)
|
for (Pos2D offset : this.ringPositionIteratorArray)
|
||||||
{
|
{
|
||||||
LodUtil.assertTrue(this._inRangeAcquired(min.x + offset.x, min.y + offset.y, min));
|
LodUtil.assertTrue(this._inRangeAcquired(min.getX() + offset.getX(), min.getY() + offset.getY(), min));
|
||||||
T item = this._getUnsafe(min.x + offset.x, min.y + offset.y);
|
T item = this._getUnsafe(min.getX() + offset.getX(), min.getY() + offset.getY());
|
||||||
consumer.accept(item, new Pos2D(min.x + offset.x, min.y + offset.y));
|
consumer.accept(item, new Pos2D(min.getX() + offset.getX(), min.getY() + offset.getY()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -479,8 +479,8 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
// sort the positions from nearest to farthest from the world origin
|
// sort the positions from nearest to farthest from the world origin
|
||||||
Arrays.sort(posArray, (a, b) ->
|
Arrays.sort(posArray, (a, b) ->
|
||||||
{
|
{
|
||||||
long disSqrA = (long) a.x * a.x + (long) a.y * a.y;
|
long disSqrA = (long) a.getX() * a.getX() + (long) a.getY() * a.getY();
|
||||||
long disSqrB = (long) b.x * b.x + (long) b.y * b.y;
|
long disSqrB = (long) b.getX() * b.getX() + (long) b.getY() * b.getY();
|
||||||
return Double.compare(disSqrA, disSqrB);
|
return Double.compare(disSqrA, disSqrB);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -490,8 +490,8 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
}
|
}
|
||||||
for (Pos2D pos2D : posArray)
|
for (Pos2D pos2D : posArray)
|
||||||
{
|
{
|
||||||
LodUtil.assertTrue(pos2D.x >= 0 && pos2D.x < this.width);
|
LodUtil.assertTrue(pos2D.getX() >= 0 && pos2D.getX() < this.width);
|
||||||
LodUtil.assertTrue(pos2D.y >= 0 && pos2D.y < this.width);
|
LodUtil.assertTrue(pos2D.getY() >= 0 && pos2D.getY() < this.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ringPositionIteratorArray = posArray;
|
this.ringPositionIteratorArray = posArray;
|
||||||
@@ -508,7 +508,7 @@ public class MovableGridRingList<T> extends ArrayList<T> implements List<T>
|
|||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
Pos2D p = this.minPosRef.get();
|
Pos2D p = this.minPosRef.get();
|
||||||
return this.getClass().getSimpleName() + "[" + (p.x + this.halfWidth) + "," + (p.y + this.halfWidth) + "] " + this.width + "*" + this.width + "[" + this.size() + "]";
|
return this.getClass().getSimpleName() + "[" + (p.getX() + this.halfWidth) + "," + (p.getY() + this.halfWidth) + "] " + this.width + "*" + this.width + "[" + this.size() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toDetailString()
|
public String toDetailString()
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
package com.seibel.distanthorizons.core.util.math;
|
package com.seibel.distanthorizons.core.util.math;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
||||||
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
||||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,7 +135,6 @@ public class Vec3d extends DhApiVec3d
|
|||||||
|
|
||||||
public Vec3d copy() { return new Vec3d(this.x, this.y, this.z); }
|
public Vec3d copy() { return new Vec3d(this.x, this.y, this.z); }
|
||||||
|
|
||||||
// Forge start
|
|
||||||
public Vec3d(double[] values) { this.set(values); }
|
public Vec3d(double[] values) { this.set(values); }
|
||||||
|
|
||||||
public void set(double[] values)
|
public void set(double[] values)
|
||||||
@@ -144,4 +144,31 @@ public class Vec3d extends DhApiVec3d
|
|||||||
this.z = values[2];
|
this.z = values[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double getManhattanDistance(DhApiVec3d a, DhApiVec3d b)
|
||||||
|
{
|
||||||
|
return Math.abs(a.x - b.x)
|
||||||
|
+ Math.abs(a.y - b.y)
|
||||||
|
+ Math.abs(a.z - b.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getDistance(DhApiVec3d a, DhApiVec3d b)
|
||||||
|
{
|
||||||
|
return Math.sqrt(Math.pow(a.x - b.x, 2)
|
||||||
|
+ Math.pow(a.y - b.y, 2)
|
||||||
|
+ Math.pow(a.z - b.z, 2));
|
||||||
|
}
|
||||||
|
/** slightly faster version of {@link Vec3d#getDistance} */
|
||||||
|
public static double getSquaredDistance(DhApiVec3d a, DhApiVec3d b)
|
||||||
|
{
|
||||||
|
return Math.pow(a.x - b.x, 2)
|
||||||
|
+ Math.pow(a.y - b.y, 2)
|
||||||
|
+ Math.pow(a.z - b.z, 2);
|
||||||
|
}
|
||||||
|
/** Gets the distance between points A and B, ignoring Y height. */
|
||||||
|
public static double getHorizontalDistance(DhApiVec3d a, DhApiVec3d b)
|
||||||
|
{
|
||||||
|
return Math.sqrt(Math.pow(a.x - b.x, 2)
|
||||||
|
+ Math.pow(a.z - b.z, 2));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package com.seibel.distanthorizons.core.util.math;
|
package com.seibel.distanthorizons.core.util.math;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
|
||||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package com.seibel.distanthorizons.core.util.objects;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This can be used for easily profiling methods to get the average execution time. <br>
|
||||||
|
* This is a thread safe implementation.
|
||||||
|
*/
|
||||||
|
public class RollingAverage
|
||||||
|
{
|
||||||
|
// properties //
|
||||||
|
|
||||||
|
private final double[] values;
|
||||||
|
private final int size;
|
||||||
|
private int index = 0;
|
||||||
|
private double sum = 0.0;
|
||||||
|
private final Lock arrayLock = new ReentrantLock();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
|
||||||
|
public RollingAverage(int size)
|
||||||
|
{
|
||||||
|
if (size <= 0)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Size must be greater than 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.size = size;
|
||||||
|
this.values = new double[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=======//
|
||||||
|
// input //
|
||||||
|
//=======//
|
||||||
|
|
||||||
|
public void addValue(double value)
|
||||||
|
{
|
||||||
|
this.arrayLock.lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Subtract the oldest value from the sum
|
||||||
|
this.sum -= this.values[this.index];
|
||||||
|
// Update the buffer with the new value
|
||||||
|
this.values[this.index] = value;
|
||||||
|
// Add the new value to the sum
|
||||||
|
this.sum += value;
|
||||||
|
// Move to the next index
|
||||||
|
this.index = (this.index + 1) % this.size;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.arrayLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
this.arrayLock.lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.sum = 0;
|
||||||
|
this.index = 0;
|
||||||
|
Arrays.fill(this.values, 0);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.arrayLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//========//
|
||||||
|
// output //
|
||||||
|
//========//
|
||||||
|
|
||||||
|
/** Gets the current rolling average. */
|
||||||
|
public double getAverage()
|
||||||
|
{
|
||||||
|
this.arrayLock.lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (this.sum / this.size);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.arrayLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** rounded to two decimals*/
|
||||||
|
public String getAverageRoundedString() { return String.format("%.2f", this.getAverage()); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// base overrides //
|
||||||
|
//================//
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() { return "avg: "+this.getAverageRoundedString()+" max count: "+this.size; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -350,6 +350,6 @@ public class QuadNode<T>
|
|||||||
//==============//
|
//==============//
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return "pos: " + this.sectionPos + ", children #: " + this.getTotalChildCount() + ", value: " + this.value; }
|
public String toString() { return "pos: " + DhSectionPos.toString(this.sectionPos) + ", children #: " + this.getTotalChildCount() + ", value: " + this.value; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-4
@@ -20,7 +20,7 @@
|
|||||||
package com.seibel.distanthorizons.core.util.objects.quadTree;
|
package com.seibel.distanthorizons.core.util.objects.quadTree;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.pos.DhLodPos;
|
import com.seibel.distanthorizons.core.pos.DhLodPos;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.pos.Pos2D;
|
import com.seibel.distanthorizons.core.pos.Pos2D;
|
||||||
@@ -31,6 +31,7 @@ import com.seibel.distanthorizons.core.util.gridList.MovableGridRingList;
|
|||||||
import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
|
import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
|
||||||
import it.unimi.dsi.fastutil.longs.LongIterator;
|
import it.unimi.dsi.fastutil.longs.LongIterator;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -85,7 +86,7 @@ public class QuadTree<T>
|
|||||||
Pos2D ringListCenterPos = new Pos2D(
|
Pos2D ringListCenterPos = new Pos2D(
|
||||||
BitShiftUtil.divideByPowerOfTwo(this.centerBlockPos.x, this.treeMinDetailLevel),
|
BitShiftUtil.divideByPowerOfTwo(this.centerBlockPos.x, this.treeMinDetailLevel),
|
||||||
BitShiftUtil.divideByPowerOfTwo(this.centerBlockPos.z, this.treeMinDetailLevel));
|
BitShiftUtil.divideByPowerOfTwo(this.centerBlockPos.z, this.treeMinDetailLevel));
|
||||||
this.topRingList = new MovableGridRingList<>(halfSizeInRootNodes, ringListCenterPos.x, ringListCenterPos.y);
|
this.topRingList = new MovableGridRingList<>(halfSizeInRootNodes, ringListCenterPos.getX(), ringListCenterPos.getY());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +97,10 @@ public class QuadTree<T>
|
|||||||
//=====================//
|
//=====================//
|
||||||
|
|
||||||
/** @return the node at the given section position */
|
/** @return the node at the given section position */
|
||||||
|
@Nullable
|
||||||
public final QuadNode<T> getNode(long pos) throws IndexOutOfBoundsException { return this.getOrSetNode(pos, false, null, true); }
|
public final QuadNode<T> getNode(long pos) throws IndexOutOfBoundsException { return this.getOrSetNode(pos, false, null, true); }
|
||||||
/** @return the value at the given section position */
|
/** @return the value at the given section position */
|
||||||
|
@Nullable
|
||||||
public final T getValue(long pos) throws IndexOutOfBoundsException
|
public final T getValue(long pos) throws IndexOutOfBoundsException
|
||||||
{
|
{
|
||||||
QuadNode<T> node = this.getNode(pos);
|
QuadNode<T> node = this.getNode(pos);
|
||||||
@@ -109,6 +112,7 @@ public class QuadTree<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return the value that was previously in the given position, null if nothing */
|
/** @return the value that was previously in the given position, null if nothing */
|
||||||
|
@Nullable
|
||||||
public final T setValue(long pos, T value) throws IndexOutOfBoundsException
|
public final T setValue(long pos, T value) throws IndexOutOfBoundsException
|
||||||
{
|
{
|
||||||
T previousValue = this.getValue(pos);
|
T previousValue = this.getValue(pos);
|
||||||
@@ -117,6 +121,7 @@ public class QuadTree<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @param runBoundaryChecks should only ever be set to true internally for removing out of bound nodes */
|
/** @param runBoundaryChecks should only ever be set to true internally for removing out of bound nodes */
|
||||||
|
@Nullable
|
||||||
protected final QuadNode<T> getOrSetNode(long pos, boolean setNewValue, T newValue, boolean runBoundaryChecks) throws IndexOutOfBoundsException
|
protected final QuadNode<T> getOrSetNode(long pos, boolean setNewValue, T newValue, boolean runBoundaryChecks) throws IndexOutOfBoundsException
|
||||||
{
|
{
|
||||||
if (runBoundaryChecks && !this.isSectionPosInBounds(pos))
|
if (runBoundaryChecks && !this.isSectionPosInBounds(pos))
|
||||||
@@ -260,7 +265,7 @@ public class QuadTree<T>
|
|||||||
|
|
||||||
|
|
||||||
// remove out of bounds root nodes
|
// remove out of bounds root nodes
|
||||||
this.topRingList.moveTo(expectedCenterPos.x, expectedCenterPos.y, (quadNode) ->
|
this.topRingList.moveTo(expectedCenterPos.getX(), expectedCenterPos.getY(), (quadNode) ->
|
||||||
{
|
{
|
||||||
if (quadNode != null && removedItemConsumer != null)
|
if (quadNode != null && removedItemConsumer != null)
|
||||||
{
|
{
|
||||||
@@ -409,7 +414,7 @@ public class QuadTree<T>
|
|||||||
{
|
{
|
||||||
if (node != null || includeNullNodes)
|
if (node != null || includeNullNodes)
|
||||||
{
|
{
|
||||||
long rootPos = DhSectionPos.encode(QuadTree.this.treeMinDetailLevel, pos2D.x, pos2D.y);
|
long rootPos = DhSectionPos.encode(QuadTree.this.treeMinDetailLevel, pos2D.getX(), pos2D.getY());
|
||||||
if (QuadTree.this.isSectionPosInBounds(rootPos))
|
if (QuadTree.this.isSectionPosInBounds(rootPos))
|
||||||
{
|
{
|
||||||
this.iteratorPosQueue.enqueue(rootPos);
|
this.iteratorPosQueue.enqueue(rootPos);
|
||||||
|
|||||||
+7
-7
@@ -66,6 +66,11 @@ public class ThreadPoolUtil
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static ThreadPoolExecutor getCleanupExecutor() { return cleanupThreadPool; }
|
public static ThreadPoolExecutor getCleanupExecutor() { return cleanupThreadPool; }
|
||||||
|
|
||||||
|
public static final String BEACON_CULLING_THREAD_NAME = "Beacon Culling";
|
||||||
|
private static ThreadPoolExecutor beaconCullingThreadPool;
|
||||||
|
@Nullable
|
||||||
|
public static ThreadPoolExecutor getBeaconCullingExecutor() { return beaconCullingThreadPool; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//======================//
|
//======================//
|
||||||
@@ -76,11 +81,6 @@ public class ThreadPoolUtil
|
|||||||
// and all share an underlying number of threads.
|
// and all share an underlying number of threads.
|
||||||
// WARNING: great care should be used when setting up these threads since deadlock can occur if they are handled poorly.
|
// WARNING: great care should be used when setting up these threads since deadlock can occur if they are handled poorly.
|
||||||
|
|
||||||
public static final DhThreadFactory LIGHT_POPULATOR_THREAD_FACTORY = new DhThreadFactory("LOD Builder - Light Populator", Thread.MIN_PRIORITY);
|
|
||||||
private static ConfigThreadPool lightPopulatorThreadPool;
|
|
||||||
@Nullable
|
|
||||||
public static ThreadPoolExecutor getLightPopulatorExecutor() { return (lightPopulatorThreadPool != null) ? lightPopulatorThreadPool.executor : null; }
|
|
||||||
|
|
||||||
public static final DhThreadFactory CHUNK_TO_LOD_BUILDER_THREAD_FACTORY = new DhThreadFactory("LOD Builder - Chunk to Lod Builder", Thread.MIN_PRIORITY);
|
public static final DhThreadFactory CHUNK_TO_LOD_BUILDER_THREAD_FACTORY = new DhThreadFactory("LOD Builder - Chunk to Lod Builder", Thread.MIN_PRIORITY);
|
||||||
private static ConfigThreadPool chunkToLodBuilderThreadPool;
|
private static ConfigThreadPool chunkToLodBuilderThreadPool;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -114,6 +114,7 @@ public class ThreadPoolUtil
|
|||||||
worldGenThreadPool = new ConfigThreadPool(WORLD_GEN_THREAD_FACTORY, Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads, Config.Client.Advanced.MultiThreading.runTimeRatioForWorldGenerationThreads, null);
|
worldGenThreadPool = new ConfigThreadPool(WORLD_GEN_THREAD_FACTORY, Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads, Config.Client.Advanced.MultiThreading.runTimeRatioForWorldGenerationThreads, null);
|
||||||
bufferUploaderThreadPool = ThreadUtil.makeSingleThreadPool(BUFFER_UPLOADER_THREAD_NAME);
|
bufferUploaderThreadPool = ThreadUtil.makeSingleThreadPool(BUFFER_UPLOADER_THREAD_NAME);
|
||||||
cleanupThreadPool = ThreadUtil.makeSingleThreadPool(CLEANUP_THREAD_NAME);
|
cleanupThreadPool = ThreadUtil.makeSingleThreadPool(CLEANUP_THREAD_NAME);
|
||||||
|
beaconCullingThreadPool = ThreadUtil.makeSingleThreadPool(BEACON_CULLING_THREAD_NAME);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -141,7 +142,6 @@ public class ThreadPoolUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create thread pools
|
// create thread pools
|
||||||
lightPopulatorThreadPool = new ConfigThreadPool(LIGHT_POPULATOR_THREAD_FACTORY, Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads, Config.Client.Advanced.MultiThreading.runTimeRatioForLodBuilderThreads, workerThreadSemaphore);
|
|
||||||
chunkToLodBuilderThreadPool = new ConfigThreadPool(CHUNK_TO_LOD_BUILDER_THREAD_FACTORY, Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads, Config.Client.Advanced.MultiThreading.runTimeRatioForLodBuilderThreads, workerThreadSemaphore);
|
chunkToLodBuilderThreadPool = new ConfigThreadPool(CHUNK_TO_LOD_BUILDER_THREAD_FACTORY, Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads, Config.Client.Advanced.MultiThreading.runTimeRatioForLodBuilderThreads, workerThreadSemaphore);
|
||||||
bufferBuilderThreadPool = new ConfigThreadPool(BUFFER_BUILDER_THREAD_FACTORY, Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads, Config.Client.Advanced.MultiThreading.runTimeRatioForLodBuilderThreads, workerThreadSemaphore);
|
bufferBuilderThreadPool = new ConfigThreadPool(BUFFER_BUILDER_THREAD_FACTORY, Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads, Config.Client.Advanced.MultiThreading.runTimeRatioForLodBuilderThreads, workerThreadSemaphore);
|
||||||
|
|
||||||
@@ -155,10 +155,10 @@ public class ThreadPoolUtil
|
|||||||
worldGenThreadPool.shutdownExecutorService();
|
worldGenThreadPool.shutdownExecutorService();
|
||||||
bufferUploaderThreadPool.shutdown();
|
bufferUploaderThreadPool.shutdown();
|
||||||
cleanupThreadPool.shutdown();
|
cleanupThreadPool.shutdown();
|
||||||
|
beaconCullingThreadPool.shutdown();
|
||||||
|
|
||||||
|
|
||||||
// worker threads
|
// worker threads
|
||||||
ThreadPoolUtil.lightPopulatorThreadPool.shutdownExecutorService();
|
|
||||||
ThreadPoolUtil.chunkToLodBuilderThreadPool.shutdownExecutorService();
|
ThreadPoolUtil.chunkToLodBuilderThreadPool.shutdownExecutorService();
|
||||||
ThreadPoolUtil.bufferBuilderThreadPool.shutdownExecutorService();
|
ThreadPoolUtil.bufferBuilderThreadPool.shutdownExecutorService();
|
||||||
|
|
||||||
|
|||||||
@@ -19,26 +19,18 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.core.world;
|
package com.seibel.distanthorizons.core.world;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
|
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
|
||||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||||
import com.seibel.distanthorizons.core.level.DhClientLevel;
|
import com.seibel.distanthorizons.core.level.DhClientLevel;
|
||||||
import com.seibel.distanthorizons.core.network.NetworkClient;
|
|
||||||
import com.seibel.distanthorizons.core.network.messages.*;
|
|
||||||
import com.seibel.distanthorizons.core.network.messages.PlayerUUIDMessage;
|
|
||||||
import com.seibel.distanthorizons.core.network.messages.RemotePlayerConfigMessage;
|
|
||||||
import com.seibel.distanthorizons.core.network.objects.RemotePlayer;
|
|
||||||
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
||||||
import com.seibel.distanthorizons.core.util.objects.EventLoop;
|
import com.seibel.distanthorizons.core.util.objects.EventLoop;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user