minor refactoring and style cleanup

This commit is contained in:
James Seibel
2024-09-10 07:24:56 -05:00
parent abe0e284aa
commit 0f27dd79d7
7 changed files with 52 additions and 29 deletions
@@ -90,12 +90,14 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
/**
* stores how far each column has been generated should start with {@link EDhApiWorldGenerationStep#EMPTY}
* @see EDhApiWorldGenerationStep
*
* @see EDhApiWorldGenerationStep
*/
public byte[] columnGenerationSteps;
/**
* stores what world compression was used for each column.
* @see EDhApiWorldCompressionMode
*
* @see EDhApiWorldCompressionMode
*/
public byte[] columnWorldCompressionMode;
@@ -379,7 +381,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
for (int x = 0; x < WIDTH; x += 2)
{
for (int z = 0; z < WIDTH; z += 2)
{
{
int recipientX = (x / 2) + recipientOffsetX;
int recipientZ = (z / 2) + recipientOffsetZ;
int recipientIndex = relativePosToIndex(recipientX, recipientZ);
@@ -612,7 +614,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
int id = determineMostValueInColumnSlice(mergeIds, inputDataSource.mapping);
byte blockLight = (byte) determineAverageValueInColumnSlice(mergeBlockLights);
byte skyLight = (byte) determineAverageValueInColumnSlice(mergeSkyLights);
// if this slice is different then the last one, create a new one
if (id != lastId
// block and sky light might not be necessary
@@ -698,7 +700,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
{
LodUtil.assertTrue(sliceArray.length == 4, "Column Slice should only contain 4 values.");
}
int value0 = sliceArray[0];
int count0 = 0;
int value1 = sliceArray[1];
@@ -719,26 +721,42 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
}
if (value == value0)
{
count0++;
}
else if (value == value1)
{
count1++;
}
else if (value == value2)
{
count2++;
}
else
{
count3++;
}
}
// return the most common occurance
int maxCount = Math.max(count0, Math.max(count1, Math.max(count2, count3)));
if (maxCount == count0)
// if the max count is 1 then we'll just go with the first column
// if the max count is 1 then we'll just go with the first column
{
return value0;
}
else if (maxCount == count1)
{
return value1;
}
else if (maxCount == count2)
{
return value2;
else
}
else
{
return value3;
}
}
private static int determineAverageValueInColumnSlice(int[] sliceArray)
{
@@ -876,8 +894,8 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
{
int index = relativePosToIndex(relX, relZ);
this.dataPoints[index] = longArray;
this.columnGenerationSteps[index] = worldGenStep.value;
this.columnWorldCompressionMode[index] = worldCompressionMode.value;
this.columnGenerationSteps[index] = worldGenStep.value;
this.columnWorldCompressionMode[index] = worldCompressionMode.value;
if (RUN_UPDATE_DEV_VALIDATION)
@@ -942,7 +960,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
// the positions are the same, use the hash as a quick method
// to determine if the data inside is the same.
// Note: this isn't perfect, but should work well enough for our use case.
return other.hashCode() == this.hashCode();
return other.hashCode() == this.hashCode();
}
}
@@ -46,7 +46,7 @@ public abstract class AbstractDataSourceHandler
* The lowest numerical detail level possible.
*
* @see AbstractDataSourceHandler#TOP_SECTION_DETAIL_LEVEL
* */
*/
public static final byte MIN_SECTION_DETAIL_LEVEL = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
@@ -223,7 +223,8 @@ public abstract class AbstractDataSourceHandler
/**
* After this method returns the inputData will be written to file.
* @param updatePos the position to update
*
* @param updatePos the position to update
*/
protected void updateDataSourceAtPos(long updatePos, @NotNull FullDataSourceV2 inputData, boolean lockOnUpdatePos)
{
@@ -289,7 +289,8 @@ public class FullDataSourceProviderV2
}
});
}
catch (RejectedExecutionException ignore) { /* the executor was shut down, it should be back up shortly and able to accept new jobs */ }
catch (RejectedExecutionException ignore)
{ /* the executor was shut down, it should be back up shortly and able to accept new jobs */ }
catch (Exception e)
{
this.parentUpdatingPosSet.remove(parentUpdatePos);
@@ -299,7 +300,10 @@ public class FullDataSourceProviderV2
}
}
catch (InterruptedException ignored) { Thread.currentThread().interrupt(); }
catch (InterruptedException ignored)
{
Thread.currentThread().interrupt();
}
catch (Exception e)
{
LOGGER.error("Unexpected error in the parent update queue thread. Error: " + e.getMessage(), e);
@@ -339,7 +343,7 @@ public class FullDataSourceProviderV2
LOGGER.info("deleting [" + dimensionName + "] - ["+totalDeleteCount+"] unused data sources...");
this.legacyDeletionCount = totalDeleteCount;
ArrayList<String> unusedDataPosList = this.legacyFileHandler.repo.getUnusedDataSourcePositionStringList(50);
while (unusedDataPosList.size() != 0)
{
@@ -368,8 +372,8 @@ public class FullDataSourceProviderV2
}
catch (InterruptedException ignore){}
}
LOGGER.info("Done deleting [" + dimensionName + "] - ["+totalDeleteCount+"] unused data sources.");
}
@@ -553,8 +557,8 @@ public class FullDataSourceProviderV2
* return false; <br>
* } <br>
* </code>
* to the beginning of your override.
* Otherwise, parent retrieval limits will be ignored.
* to the beginning of your override.
* Otherwise, parent retrieval limits will be ignored.
*/
public boolean canQueueRetrieval()
{
@@ -569,13 +573,13 @@ public class FullDataSourceProviderV2
* an empty array if all positions were generated
*/
@Nullable
public LongArrayList getPositionsToRetrieve(Long pos) { return null; }
public LongArrayList getPositionsToRetrieve(Long pos) { return null; }
/**
* Returns how many positions could potentially be generated for this position assuming the position is empty.
* Used when estimating the total number of retrieval requests.
*/
public int getMaxPossibleRetrievalPositionCountForPos(Long pos) { return -1; }
public int getMaxPossibleRetrievalPositionCountForPos(Long pos) { return -1; }
/** @return true if the position was queued, false if not */
public boolean queuePositionForRetrieval(Long genPos) { return false; }
@@ -585,7 +589,7 @@ public class FullDataSourceProviderV2
public void clearRetrievalQueue() { }
/** Can be used to display how many total retrieval requests might be available. */
public void setTotalRetrievalPositionCount(int newCount) { }
public void setTotalRetrievalPositionCount(int newCount) { }
/**
* Returns how many data sources are currently in memory and haven't
@@ -393,6 +393,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
GeneratedFullDataSourceProvider.this.delayedFullDataSourceSaveCache.queueDataSourceForUpdateAndSave(chunkSizedFullDataSource);
};
}
}
private void onDataSourceSave(FullDataSourceV2 fullDataSource)
{
@@ -21,6 +21,7 @@ package com.seibel.distanthorizons.core.generation.tasks;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import javax.annotation.Nullable;
import java.util.function.Consumer;
/**
@@ -32,6 +33,7 @@ public interface IWorldGenTaskTracker
/** Returns true if the task hasn't been garbage collected. */
boolean isMemoryAddressValid();
@Nullable
Consumer<FullDataSourceV2> getChunkDataConsumer();
}
@@ -157,9 +157,9 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
public void clearRenderCache() { this.clientside.clearRenderCache(); }
@Override
public IServerLevelWrapper getServerLevelWrapper() { return serverLevelWrapper; }
public IServerLevelWrapper getServerLevelWrapper() { return this.serverLevelWrapper; }
@Override
public ILevelWrapper getLevelWrapper() { return getServerLevelWrapper(); }
public ILevelWrapper getLevelWrapper() { return this.getServerLevelWrapper(); }
@Override
public FullDataSourceProviderV2 getFullDataProvider() { return this.serverside.fullDataFileHandler; }
@@ -167,7 +167,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
@Override
public AbstractSaveStructure getSaveStructure()
{
return serverside.saveStructure;
return this.serverside.saveStructure;
}
@Override
@@ -156,10 +156,7 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
}
}
private void _clientTick()
{
this.levels.values().forEach(DhClientLevel::clientTick);
}
private void _clientTick() { this.levels.values().forEach(DhClientLevel::clientTick); }
public void clientTick() { this.eventLoop.tick(); }