Improve naming/documentation for LodRenderSource/Provider

This commit is contained in:
James Seibel
2023-02-04 22:16:30 -06:00
parent d5a8e1eb1b
commit c94cf2a6ec
6 changed files with 54 additions and 34 deletions
@@ -11,6 +11,12 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicReference;
/**
* This represents LOD data that is stored in system memory <br>
* Example: {@link com.seibel.lod.core.datatype.column.ColumnRenderSource ColumnRenderSource} <br><br>
*
* These are created via {@link com.seibel.lod.core.file.renderfile.ILodRenderSourceProvider ILodRenderSourceProvider}'s
*/
public interface ILodRenderSource
{
DhSectionPos getSectionPos();
@@ -8,7 +8,13 @@ import java.io.File;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public interface IRenderSourceProvider extends AutoCloseable
/**
* This represents LOD data that is stored in long term storage (IE LOD files stored on the hard drive) <br>
* Example: {@link RenderFileHandler RenderFileHandler} <br><br>
*
* This is used to create {@link ILodRenderSource}'s
*/
public interface ILodRenderSourceProvider extends AutoCloseable
{
CompletableFuture<ILodRenderSource> read(DhSectionPos pos);
void addScannedFile(Collection<File> detectedFiles);
@@ -26,7 +26,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
public class RenderFileHandler implements IRenderSourceProvider
public class RenderFileHandler implements ILodRenderSourceProvider
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
@@ -4,7 +4,7 @@ import com.seibel.lod.core.datatype.column.ColumnRenderSource;
import com.seibel.lod.core.level.IDhClientLevel;
import com.seibel.lod.core.pos.DhBlockPos2D;
import com.seibel.lod.core.pos.DhSectionPos;
import com.seibel.lod.core.file.renderfile.IRenderSourceProvider;
import com.seibel.lod.core.file.renderfile.ILodRenderSourceProvider;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.pos.Pos2D;
import com.seibel.lod.core.util.BitShiftUtil;
@@ -48,7 +48,7 @@ public class LodQuadTree implements AutoCloseable
public final byte numbersOfSectionDetailLevels;
private final MovableGridRingList<LodRenderSection>[] renderSectionRingLists;
public final int blockViewDistance;
private final IRenderSourceProvider renderSourceProvider;
private final ILodRenderSourceProvider renderSourceProvider;
private final IDhClientLevel level; //FIXME: Proper hierarchy to remove this reference!
@@ -63,7 +63,7 @@ public class LodQuadTree implements AutoCloseable
public LodQuadTree(
IDhClientLevel level, int viewDistance,
int initialPlayerX, int initialPlayerZ,
IRenderSourceProvider provider)
ILodRenderSourceProvider provider)
{
DetailDistanceUtil.updateSettings(); //TODO: Move this to somewhere else
this.level = level;
@@ -5,7 +5,7 @@ import com.seibel.lod.core.config.Config;
import com.seibel.lod.core.level.IDhClientLevel;
import com.seibel.lod.core.pos.DhSectionPos;
import com.seibel.lod.core.datatype.ILodRenderSource;
import com.seibel.lod.core.file.renderfile.IRenderSourceProvider;
import com.seibel.lod.core.file.renderfile.ILodRenderSourceProvider;
import java.util.concurrent.CompletableFuture;
@@ -25,8 +25,8 @@ public class LodRenderSection
private boolean isRenderEnabled = false;
// TODO: Should I provide a way to change the render source?
private ILodRenderSource lodRenderSource;
private IRenderSourceProvider renderSourceProvider = null; // TODO: rename these two interfaces to make it more obvious what each one does
private ILodRenderSource renderSource;
private ILodRenderSourceProvider renderSourceProvider = null;
private EVerticalQuality previousVerticalQualitySetting = null;
@@ -60,11 +60,11 @@ public class LodRenderSection
}
if (this.lodRenderSource != null)
if (this.renderSource != null)
{
this.lodRenderSource.disableRender();
this.lodRenderSource.dispose();
this.lodRenderSource = null;
this.renderSource.disableRender();
this.renderSource.dispose();
this.renderSource = null;
}
if (this.loadFuture != null)
{
@@ -77,16 +77,16 @@ public class LodRenderSection
//
//
//
//==============//
// LOD provider //
//==============//
public void load(IRenderSourceProvider renderDataProvider)
public void load(ILodRenderSourceProvider renderDataProvider)
{
this.renderSourceProvider = renderDataProvider;
this.previousVerticalQualitySetting = Config.Client.Graphics.Quality.verticalQuality.get();
}
public void reload(IRenderSourceProvider renderDataProvider)
public void reload(ILodRenderSourceProvider renderDataProvider)
{
if (this.loadFuture != null)
{
@@ -94,10 +94,10 @@ public class LodRenderSection
this.loadFuture = null;
}
if (this.lodRenderSource != null)
if (this.renderSource != null)
{
this.lodRenderSource.dispose();
this.lodRenderSource = null;
this.renderSource.dispose();
this.renderSource = null;
}
this.loadFuture = renderDataProvider.read(this.pos);
@@ -106,32 +106,34 @@ public class LodRenderSection
//================//
// update methods //
//================//
public void tick(LodQuadTree quadTree, IDhClientLevel level)
{
if (this.loadFuture != null && this.loadFuture.isDone())
{
this.lodRenderSource = this.loadFuture.join();
this.renderSource = this.loadFuture.join();
this.loadFuture = null;
if (this.isRenderEnabled)
{
this.lodRenderSource.enableRender(level, quadTree);
this.renderSource.enableRender(level, quadTree);
}
}
if (this.lodRenderSource != null)
if (this.renderSource != null)
{
this.renderSourceProvider.refreshRenderSource(this.lodRenderSource);
this.renderSourceProvider.refreshRenderSource(this.renderSource);
}
}
public void dispose()
{
if (this.lodRenderSource != null)
if (this.renderSource != null)
{
this.lodRenderSource.dispose();
this.renderSource.dispose();
}
else if (this.loadFuture != null)
{
@@ -141,7 +143,11 @@ public class LodRenderSection
public boolean canRender() { return this.isLoaded() && this.isRenderEnabled && this.lodRenderSource != null; }
//========================//
// getters and properties //
//========================//
public boolean canRender() { return this.isLoaded() && this.isRenderEnabled && this.renderSource != null; }
public boolean isLoaded() { return this.renderSourceProvider != null; }
public boolean isLoading() { return false; }
@@ -149,19 +155,21 @@ public class LodRenderSection
//FIXME: Used by RenderBufferHandler
public int FIXME_BYPASS_DONT_USE_getChildCount() { return this.childCount; }
public boolean isOutdated() { return this.previousVerticalQualitySetting != Config.Client.Graphics.Quality.verticalQuality.get() || (this.lodRenderSource != null && !this.lodRenderSource.isValid()); }
public boolean isOutdated() { return this.previousVerticalQualitySetting != Config.Client.Graphics.Quality.verticalQuality.get() || (this.renderSource != null && !this.renderSource.isValid()); }
public ILodRenderSource getRenderSource() { return this.lodRenderSource; }
public ILodRenderSource getRenderSource() { return this.renderSource; }
//==============//
// base methods //
//==============//
public String toString() {
return "LodRenderSection{" +
"pos=" + this.pos +
", childCount=" + this.childCount +
", lodRenderSource=" + this.lodRenderSource +
", lodRenderSource=" + this.renderSource +
", loadFuture=" + this.loadFuture +
", isRenderEnabled=" + this.isRenderEnabled +
'}';
@@ -1,7 +1,7 @@
package com.seibel.lod.core.util;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.file.renderfile.IRenderSourceProvider;
import com.seibel.lod.core.file.renderfile.ILodRenderSourceProvider;
import com.seibel.lod.core.file.structure.AbstractSaveStructure;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
@@ -20,7 +20,7 @@ public class FileScanUtil {
public static final String LOD_FILE_POSTFIX = ".lod";
public static void scanFile(AbstractSaveStructure save, ILevelWrapper level,
@Nullable IDataSourceProvider dataSource,
@Nullable IRenderSourceProvider renderSource) {
@Nullable ILodRenderSourceProvider renderSource) {
if (dataSource != null) {
try (Stream<Path> pathStream = Files.walk(save.getDataFolder(level).toPath(), MAX_SCAN_DEPTH)) {
dataSource.addScannedFile(pathStream.filter(