Remove IRenderSource
There was only ColumnRenderSource and several pieces of logic required there to only be ColumnRenderSource, so it didn't make sense to keep the interface.
This commit is contained in:
+8
-8
@@ -11,7 +11,7 @@ import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Abstract for loading and creating {@link IRenderSource} objects
|
||||
* Abstract for loading and creating {@link ColumnRenderSource} objects
|
||||
* from {@link RenderMetaDataFile}'s and {@link IFullDataSource}'s. <br><Br>
|
||||
*
|
||||
* Also holds all {@link AbstractRenderSourceLoader}'s
|
||||
@@ -19,8 +19,8 @@ import java.util.*;
|
||||
*/
|
||||
public abstract class AbstractRenderSourceLoader
|
||||
{
|
||||
public static final HashMultimap<Class<? extends IRenderSource>, AbstractRenderSourceLoader> LOADER_BY_SOURCE_TYPE = HashMultimap.create();
|
||||
public static final HashMap<Long, Class<? extends IRenderSource>> SOURCE_TYPE_BY_METADATA_VERSION = new HashMap<>();
|
||||
public static final HashMultimap<Class<? extends ColumnRenderSource>, AbstractRenderSourceLoader> LOADER_BY_SOURCE_TYPE = HashMultimap.create();
|
||||
public static final HashMap<Long, Class<? extends ColumnRenderSource>> SOURCE_TYPE_BY_METADATA_VERSION = new HashMap<>();
|
||||
|
||||
public static AbstractRenderSourceLoader getLoader(long renderTypeId, byte loaderVersion)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ public abstract class AbstractRenderSourceLoader
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static AbstractRenderSourceLoader getLoader(Class<? extends IRenderSource> clazz, byte loaderVersion)
|
||||
public static AbstractRenderSourceLoader getLoader(Class<? extends ColumnRenderSource> clazz, byte loaderVersion)
|
||||
{
|
||||
return LOADER_BY_SOURCE_TYPE.get(clazz).stream()
|
||||
.filter(l -> Arrays.binarySearch(l.loaderSupportedRenderDataVersions, loaderVersion) >= 0)
|
||||
@@ -38,7 +38,7 @@ public abstract class AbstractRenderSourceLoader
|
||||
|
||||
|
||||
|
||||
public final Class<? extends IRenderSource> renderSourceClass;
|
||||
public final Class<? extends ColumnRenderSource> renderSourceClass;
|
||||
public final long renderTypeId;
|
||||
public final byte[] loaderSupportedRenderDataVersions;
|
||||
public final byte detailOffset;
|
||||
@@ -51,7 +51,7 @@ public abstract class AbstractRenderSourceLoader
|
||||
*
|
||||
* @throws IllegalArgumentException if another render source already exists for the given renderTypeId or supported render data versions
|
||||
*/
|
||||
public AbstractRenderSourceLoader(Class<? extends IRenderSource> renderSourceClass, long renderTypeId, byte[] loaderSupportedRenderDataVersions, byte detailOffset) throws IllegalArgumentException
|
||||
public AbstractRenderSourceLoader(Class<? extends ColumnRenderSource> renderSourceClass, long renderTypeId, byte[] loaderSupportedRenderDataVersions, byte detailOffset) throws IllegalArgumentException
|
||||
{
|
||||
this.renderTypeId = renderTypeId;
|
||||
this.loaderSupportedRenderDataVersions = loaderSupportedRenderDataVersions;
|
||||
@@ -100,8 +100,8 @@ public abstract class AbstractRenderSourceLoader
|
||||
* @throws IOException if the file uses a unsupported data version
|
||||
* or there was an issue reading the file
|
||||
*/
|
||||
public abstract IRenderSource loadRenderSource(RenderMetaDataFile renderFile, InputStream data, IDhLevel level) throws IOException;
|
||||
public abstract ColumnRenderSource loadRenderSource(RenderMetaDataFile renderFile, InputStream data, IDhLevel level) throws IOException;
|
||||
/** Should not return null */
|
||||
public abstract IRenderSource createRenderSource(IFullDataSource dataSource, IDhClientLevel level);
|
||||
public abstract ColumnRenderSource createRenderSource(IFullDataSource dataSource, IDhClientLevel level);
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ColumnRenderLoader extends AbstractRenderSourceLoader
|
||||
|
||||
|
||||
@Override
|
||||
public IRenderSource loadRenderSource(RenderMetaDataFile dataFile, InputStream inputStream, IDhLevel level) throws IOException
|
||||
public ColumnRenderSource loadRenderSource(RenderMetaDataFile dataFile, InputStream inputStream, IDhLevel level) throws IOException
|
||||
{
|
||||
DataInputStream inputDataStream = new DataInputStream(inputStream); // DO NOT CLOSE
|
||||
int dataFileVersion = dataFile.metaData.loaderVersion;
|
||||
@@ -60,7 +60,7 @@ public class ColumnRenderLoader extends AbstractRenderSourceLoader
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRenderSource createRenderSource(IFullDataSource dataSource, IDhClientLevel level)
|
||||
public ColumnRenderSource createRenderSource(IFullDataSource dataSource, IDhClientLevel level)
|
||||
{
|
||||
if (dataSource instanceof FullDataSource) // TODO replace with Java 7 method
|
||||
{
|
||||
@@ -70,6 +70,7 @@ public class ColumnRenderLoader extends AbstractRenderSourceLoader
|
||||
{
|
||||
return FullToColumnTransformer.transformIncompleteDataToColumnData(level, (IIncompleteFullDataSource) dataSource);
|
||||
}
|
||||
|
||||
LodUtil.assertNotReach();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
* @author Leetom
|
||||
* @version 2022-2-7
|
||||
*/
|
||||
public class ColumnRenderSource implements IRenderSource, IColumnDatatype
|
||||
public class ColumnRenderSource implements IColumnDatatype
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
@@ -76,7 +76,11 @@ public class ColumnRenderSource implements IRenderSource, IColumnDatatype
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
public static ColumnRenderSource createEmptyRenderSource(DhSectionPos sectionPos) { return new ColumnRenderSource(sectionPos, 0, 0); }
|
||||
/**
|
||||
* Creates an empty ColumnRenderSource.
|
||||
*
|
||||
@@ -239,23 +243,20 @@ public class ColumnRenderSource implements IRenderSource, IColumnDatatype
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFromRenderSource(IRenderSource source)
|
||||
/** Overrides any data that has not been written directly using write(). Skips empty source dataPoints. */
|
||||
public void updateFromRenderSource(ColumnRenderSource renderSource)
|
||||
{
|
||||
// TODO if we can only write this one type of data isn't it dangerous to have it in the interface?
|
||||
LodUtil.assertTrue(source instanceof ColumnRenderSource);
|
||||
ColumnRenderSource src = (ColumnRenderSource) source;
|
||||
|
||||
// validate we are writing for the same location
|
||||
LodUtil.assertTrue(src.sectionPos.equals(this.sectionPos));
|
||||
LodUtil.assertTrue(renderSource.sectionPos.equals(this.sectionPos));
|
||||
|
||||
// change the vertical size if necessary (this can happen if the vertical quality was changed in the config)
|
||||
this.clearAndChangeVerticalSize(src.verticalDataCount);
|
||||
this.clearAndChangeVerticalSize(renderSource.verticalDataCount);
|
||||
// validate both objects have the same number of dataPoints
|
||||
LodUtil.assertTrue(src.verticalDataCount == this.verticalDataCount);
|
||||
LodUtil.assertTrue(renderSource.verticalDataCount == this.verticalDataCount);
|
||||
|
||||
|
||||
if (src.isEmpty)
|
||||
if (renderSource.isEmpty)
|
||||
{
|
||||
// the source is empty, don't attempt to update anything
|
||||
return;
|
||||
@@ -268,7 +269,7 @@ public class ColumnRenderSource implements IRenderSource, IColumnDatatype
|
||||
for (int i = 0; i < this.dataContainer.length; i += this.verticalDataCount)
|
||||
{
|
||||
int thisGenMode = ColumnFormat.getGenerationMode(this.dataContainer[i]);
|
||||
int srcGenMode = ColumnFormat.getGenerationMode(src.dataContainer[i]);
|
||||
int srcGenMode = ColumnFormat.getGenerationMode(renderSource.dataContainer[i]);
|
||||
|
||||
if (srcGenMode == 0)
|
||||
{
|
||||
@@ -280,10 +281,10 @@ public class ColumnRenderSource implements IRenderSource, IColumnDatatype
|
||||
if (thisGenMode <= srcGenMode)
|
||||
{
|
||||
ColumnArrayView thisColumnArrayView = new ColumnArrayView(this.dataContainer, this.verticalDataCount, i, this.verticalDataCount);
|
||||
ColumnArrayView srcColumnArrayView = new ColumnArrayView(src.dataContainer, src.verticalDataCount, i, src.verticalDataCount);
|
||||
ColumnArrayView srcColumnArrayView = new ColumnArrayView(renderSource.dataContainer, renderSource.verticalDataCount, i, renderSource.verticalDataCount);
|
||||
thisColumnArrayView.copyFrom(srcColumnArrayView);
|
||||
|
||||
this.debugSourceFlags[i / this.verticalDataCount] = src.debugSourceFlags[i / this.verticalDataCount];
|
||||
this.debugSourceFlags[i / this.verticalDataCount] = renderSource.debugSourceFlags[i / this.verticalDataCount];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,7 +303,6 @@ public class ColumnRenderSource implements IRenderSource, IColumnDatatype
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastWrite(ChunkSizedFullDataSource chunkData, IDhClientLevel level) { FullToColumnTransformer.writeFullDataChunkToColumnData(this, level, chunkData); }
|
||||
|
||||
|
||||
@@ -369,20 +369,22 @@ public class ColumnRenderSource implements IRenderSource, IColumnDatatype
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableRender(IDhClientLevel level, LodQuadTree quadTree)
|
||||
{
|
||||
this.level = level;
|
||||
//this.tryBuildBuffer(level, quadTree); // FIXME why was this commented out?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableRender() { this.cancelBuildBuffer(); }
|
||||
|
||||
@Override
|
||||
public void dispose() { this.cancelBuildBuffer(); }
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Try and swap in new render buffer for this section. Note that before this call, there should be no other
|
||||
* places storing or referencing the render buffer.
|
||||
* @param renderBufferToSwap The slot for swapping in the new buffer.
|
||||
* @return True if the swap was successful. False if swap is not needed or if it is in progress.
|
||||
*/
|
||||
public boolean trySwapRenderBufferAsync(LodQuadTree quadTree, AtomicReference<AbstractRenderBuffer> renderBufferToSwap)
|
||||
{
|
||||
// prevent swapping the buffer to quickly
|
||||
@@ -433,20 +435,17 @@ public class ColumnRenderSource implements IRenderSource, IColumnDatatype
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveRender(IDhClientLevel level, RenderMetaDataFile file, OutputStream dataStream) throws IOException
|
||||
{
|
||||
DataOutputStream dos = new DataOutputStream(dataStream); // DO NOT CLOSE
|
||||
this.writeData(dos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getRenderVersion() { return LATEST_VERSION; }
|
||||
|
||||
@Override
|
||||
/** Whether this object is still valid. If not, a new one should be created. */
|
||||
public boolean isValid() { return true; }
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() { return this.isEmpty; }
|
||||
public void markNotEmpty() { this.isEmpty = false; }
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.seibel.lod.core.datatype.render;
|
||||
|
||||
import com.seibel.lod.core.datatype.full.sources.ChunkSizedFullDataSource;
|
||||
import com.seibel.lod.core.level.IDhClientLevel;
|
||||
import com.seibel.lod.core.pos.DhSectionPos;
|
||||
import com.seibel.lod.core.render.LodQuadTree;
|
||||
import com.seibel.lod.core.render.AbstractRenderBuffer;
|
||||
import com.seibel.lod.core.file.renderfile.RenderMetaDataFile;
|
||||
|
||||
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 ColumnRenderSource ColumnRenderSource} <br><br>
|
||||
*
|
||||
* These are created via {@link com.seibel.lod.core.file.renderfile.ILodRenderSourceProvider ILodRenderSourceProvider}'s
|
||||
*/
|
||||
public interface IRenderSource
|
||||
{
|
||||
DhSectionPos getSectionPos();
|
||||
|
||||
byte getDataDetail();
|
||||
|
||||
void enableRender(IDhClientLevel level, LodQuadTree quadTree);
|
||||
|
||||
void disableRender();
|
||||
|
||||
void dispose(); // notify the container that the parent lodSection is now disposed (can be in loaded or unloaded state)
|
||||
|
||||
|
||||
/**
|
||||
* Try and swap in new render buffer for this section. Note that before this call, there should be no other
|
||||
* places storing or referencing the render buffer.
|
||||
* @param referenceSlot The slot for swapping in the new buffer.
|
||||
* @return True if the swap was successful. False if swap is not needed or if it is in progress.
|
||||
*/
|
||||
boolean trySwapRenderBufferAsync(LodQuadTree quadTree, AtomicReference<AbstractRenderBuffer> referenceSlot);
|
||||
|
||||
void saveRender(IDhClientLevel level, RenderMetaDataFile file, OutputStream dataStream) throws IOException;
|
||||
|
||||
byte getRenderVersion();
|
||||
|
||||
/** Whether this object is still valid. If not, a new one should be created. */
|
||||
boolean isValid();
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
void fastWrite(ChunkSizedFullDataSource chunkData, IDhClientLevel level);
|
||||
|
||||
/** Overrides any data that has not been written directly using write(). Skips empty source dataPoints. */
|
||||
void updateFromRenderSource(IRenderSource source);
|
||||
|
||||
}
|
||||
+3
-4
@@ -1,7 +1,6 @@
|
||||
package com.seibel.lod.core.datatype.transform;
|
||||
|
||||
import com.seibel.lod.core.datatype.full.IFullDataSource;
|
||||
import com.seibel.lod.core.datatype.render.IRenderSource;
|
||||
import com.seibel.lod.core.datatype.render.ColumnRenderLoader;
|
||||
import com.seibel.lod.core.datatype.render.ColumnRenderSource;
|
||||
import com.seibel.lod.core.level.IDhClientLevel;
|
||||
@@ -16,17 +15,17 @@ public class DataRenderTransformer
|
||||
public static final ExecutorService TRANSFORMER_THREADS
|
||||
= LodUtil.makeThreadPool(4, "Data/Render Transformer");
|
||||
|
||||
public static CompletableFuture<IRenderSource> transformDataSource(IFullDataSource data, IDhClientLevel level)
|
||||
public static CompletableFuture<ColumnRenderSource> transformDataSource(IFullDataSource data, IDhClientLevel level)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() -> transform(data, level), TRANSFORMER_THREADS);
|
||||
}
|
||||
|
||||
public static CompletableFuture<IRenderSource> asyncTransformDataSource(CompletableFuture<IFullDataSource> data, IDhClientLevel level)
|
||||
public static CompletableFuture<ColumnRenderSource> asyncTransformDataSource(CompletableFuture<IFullDataSource> data, IDhClientLevel level)
|
||||
{
|
||||
return data.thenApplyAsync((d) -> transform(d, level), TRANSFORMER_THREADS);
|
||||
}
|
||||
|
||||
private static IRenderSource transform(IFullDataSource dataSource, IDhClientLevel level)
|
||||
private static ColumnRenderSource transform(IFullDataSource dataSource, IDhClientLevel level)
|
||||
{
|
||||
if (dataSource == null)
|
||||
{
|
||||
|
||||
+2
-2
@@ -1,7 +1,6 @@
|
||||
package com.seibel.lod.core.datatype.transform;
|
||||
|
||||
import com.seibel.lod.core.datatype.full.IIncompleteFullDataSource;
|
||||
import com.seibel.lod.core.datatype.render.IRenderSource;
|
||||
import com.seibel.lod.core.datatype.column.accessor.ColumnFormat;
|
||||
import com.seibel.lod.core.datatype.render.ColumnRenderSource;
|
||||
import com.seibel.lod.core.datatype.column.accessor.ColumnArrayView;
|
||||
@@ -68,7 +67,8 @@ public class FullToColumnTransformer {
|
||||
return columnSource;
|
||||
}
|
||||
|
||||
public static IRenderSource transformIncompleteDataToColumnData(IDhClientLevel level, IIncompleteFullDataSource data) {
|
||||
public static ColumnRenderSource transformIncompleteDataToColumnData(IDhClientLevel level, IIncompleteFullDataSource data)
|
||||
{
|
||||
final DhSectionPos pos = data.getSectionPos();
|
||||
final byte dataDetail = data.getDataDetail();
|
||||
final int vertSize = Config.Client.Graphics.Quality.verticalQuality.get().calculateMaxVerticalData(data.getDataDetail());
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.core.file.renderfile;
|
||||
|
||||
import com.seibel.lod.core.datatype.render.IRenderSource;
|
||||
import com.seibel.lod.core.datatype.render.ColumnRenderSource;
|
||||
import com.seibel.lod.core.datatype.full.sources.ChunkSizedFullDataSource;
|
||||
import com.seibel.lod.core.pos.DhSectionPos;
|
||||
|
||||
@@ -12,17 +12,17 @@ import java.util.concurrent.CompletableFuture;
|
||||
* 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 IRenderSource}'s
|
||||
* This is used to create {@link ColumnRenderSource}'s
|
||||
*/
|
||||
public interface ILodRenderSourceProvider extends AutoCloseable
|
||||
{
|
||||
CompletableFuture<IRenderSource> read(DhSectionPos pos);
|
||||
CompletableFuture<ColumnRenderSource> read(DhSectionPos pos);
|
||||
void addScannedFile(Collection<File> detectedFiles);
|
||||
void write(DhSectionPos sectionPos, ChunkSizedFullDataSource chunkData);
|
||||
CompletableFuture<Void> flushAndSave();
|
||||
|
||||
/** Returns true if the data was refreshed, false otherwise */
|
||||
boolean refreshRenderSource(IRenderSource source);
|
||||
boolean refreshRenderSource(ColumnRenderSource source);
|
||||
|
||||
/** Deletes any data stored in the render cache so it can be re-created */
|
||||
void deleteRenderCache();
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.seibel.lod.core.file.renderfile;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.seibel.lod.core.datatype.full.IFullDataSource;
|
||||
import com.seibel.lod.core.datatype.PlaceHolderRenderSource;
|
||||
import com.seibel.lod.core.datatype.render.IRenderSource;
|
||||
import com.seibel.lod.core.datatype.render.AbstractRenderSourceLoader;
|
||||
import com.seibel.lod.core.datatype.render.ColumnRenderSource;
|
||||
import com.seibel.lod.core.datatype.full.sources.ChunkSizedFullDataSource;
|
||||
@@ -171,7 +169,7 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
|
||||
/** This call is concurrent. I.e. it supports multiple threads calling this method at the same time. */
|
||||
@Override
|
||||
public CompletableFuture<IRenderSource> read(DhSectionPos pos)
|
||||
public CompletableFuture<ColumnRenderSource> read(DhSectionPos pos)
|
||||
{
|
||||
RenderMetaDataFile metaFile = this.filesBySectionPos.get(pos);
|
||||
if (metaFile == null)
|
||||
@@ -212,7 +210,7 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
LOGGER.error("Uncaught error on "+pos+":", exception);
|
||||
}
|
||||
|
||||
return (renderSource != null) ? renderSource : new PlaceHolderRenderSource(pos);
|
||||
return (renderSource != null) ? renderSource : ColumnRenderSource.createEmptyRenderSource(pos);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -272,7 +270,7 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
|
||||
public File computeRenderFilePath(DhSectionPos pos) { return new File(this.saveDir, pos.serialize() + RENDER_FILE_EXTENSION);}
|
||||
|
||||
public CompletableFuture<IRenderSource> onCreateRenderFile(RenderMetaDataFile file)
|
||||
public CompletableFuture<ColumnRenderSource> onCreateRenderFile(RenderMetaDataFile file)
|
||||
{
|
||||
final int vertSize = Config.Client.Graphics.Quality.verticalQuality.get()
|
||||
.calculateMaxVerticalData((byte) (file.pos.sectionDetailLevel - ColumnRenderSource.SECTION_SIZE_OFFSET));
|
||||
@@ -281,14 +279,14 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
new ColumnRenderSource(file.pos, vertSize, this.level.getMinY()));
|
||||
}
|
||||
|
||||
private void updateCache(IRenderSource renderSource, RenderMetaDataFile file)
|
||||
private void updateCache(ColumnRenderSource renderSource, RenderMetaDataFile file)
|
||||
{
|
||||
if (this.cacheUpdateLockBySectionPos.putIfAbsent(file.pos, new Object()) != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final WeakReference<IRenderSource> renderSourceReference = new WeakReference<>(renderSource); // TODO why is this a week reference?
|
||||
final WeakReference<ColumnRenderSource> renderSourceReference = new WeakReference<>(renderSource); // TODO why is this a week reference?
|
||||
CompletableFuture<IFullDataSource> fullDataSourceFuture = this.fullDataSourceProvider.read(renderSource.getSectionPos());
|
||||
fullDataSourceFuture = fullDataSourceFuture.thenApply((dataSource) ->
|
||||
{
|
||||
@@ -319,7 +317,7 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
).thenRun(() -> this.cacheUpdateLockBySectionPos.remove(file.pos));
|
||||
}
|
||||
|
||||
public IRenderSource onRenderFileLoaded(IRenderSource renderSource, RenderMetaDataFile file)
|
||||
public ColumnRenderSource onRenderFileLoaded(ColumnRenderSource renderSource, RenderMetaDataFile file)
|
||||
{
|
||||
// if (!this.fullDataSourceProvider.isCacheVersionValid(file.pos, file.metaData.dataVersion.get()))
|
||||
// {
|
||||
@@ -329,8 +327,8 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
return renderSource;
|
||||
}
|
||||
|
||||
private void write(IRenderSource currentRenderSource, RenderMetaDataFile file,
|
||||
IRenderSource newRenderSource)
|
||||
private void write(ColumnRenderSource currentRenderSource, RenderMetaDataFile file,
|
||||
ColumnRenderSource newRenderSource)
|
||||
{
|
||||
if (currentRenderSource == null || newRenderSource == null)
|
||||
{
|
||||
@@ -348,7 +346,7 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
file.save(currentRenderSource, this.level);
|
||||
}
|
||||
|
||||
public void onReadRenderSourceFromCache(RenderMetaDataFile file, IRenderSource data)
|
||||
public void onReadRenderSourceFromCache(RenderMetaDataFile file, ColumnRenderSource data)
|
||||
{
|
||||
// if (!this.fullDataSourceProvider.isCacheVersionValid(file.pos, file.metaData.dataVersion.get()))
|
||||
// {
|
||||
@@ -356,10 +354,10 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
// }
|
||||
}
|
||||
|
||||
public boolean refreshRenderSource(IRenderSource source)
|
||||
public boolean refreshRenderSource(ColumnRenderSource renderSource)
|
||||
{
|
||||
RenderMetaDataFile file = this.filesBySectionPos.get(source.getSectionPos());
|
||||
if (source instanceof PlaceHolderRenderSource)
|
||||
RenderMetaDataFile file = this.filesBySectionPos.get(renderSource.getSectionPos());
|
||||
if (renderSource.isEmpty())
|
||||
{
|
||||
if (file == null || file.metaData == null)
|
||||
{
|
||||
@@ -371,7 +369,7 @@ public class RenderFileHandler implements ILodRenderSourceProvider
|
||||
LodUtil.assertTrue(file.metaData != null);
|
||||
// if (!this.fullDataSourceProvider.isCacheVersionValid(file.pos, file.metaData.dataVersion.get()))
|
||||
// {
|
||||
this.updateCache(source, file);
|
||||
this.updateCache(renderSource, file);
|
||||
return true;
|
||||
// }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.core.file.renderfile;
|
||||
|
||||
import com.seibel.lod.core.datatype.render.IRenderSource;
|
||||
import com.seibel.lod.core.datatype.render.ColumnRenderSource;
|
||||
import com.seibel.lod.core.datatype.render.AbstractRenderSourceLoader;
|
||||
import com.seibel.lod.core.datatype.full.sources.ChunkSizedFullDataSource;
|
||||
import com.seibel.lod.core.file.metaData.MetaData;
|
||||
@@ -25,7 +25,7 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
public AbstractRenderSourceLoader loader;
|
||||
public Class<? extends IRenderSource> dataType;
|
||||
public Class<? extends ColumnRenderSource> dataType;
|
||||
|
||||
// The '?' type should either be:
|
||||
// SoftReference<LodRenderSource>, or - File that may still be loaded
|
||||
@@ -91,7 +91,7 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
DhLodPos chunkPos = new DhLodPos((byte) (chunkData.dataDetail + 4), chunkData.x, chunkData.z);
|
||||
LodUtil.assertTrue(this.pos.getSectionBBoxPos().overlaps(chunkPos), "Chunk pos {} doesn't overlap with section {}", chunkPos, pos);
|
||||
|
||||
CompletableFuture<IRenderSource> source = this._readCached(this.data.get());
|
||||
CompletableFuture<ColumnRenderSource> source = this._readCached(this.data.get());
|
||||
if (source == null)
|
||||
{
|
||||
return;
|
||||
@@ -107,7 +107,7 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
return CompletableFuture.completedFuture(null); // No need to save if the file doesn't exist.
|
||||
}
|
||||
|
||||
CompletableFuture<IRenderSource> source = this._readCached(this.data.get());
|
||||
CompletableFuture<ColumnRenderSource> source = this._readCached(this.data.get());
|
||||
if (source == null)
|
||||
{
|
||||
return CompletableFuture.completedFuture(null); // If there is no cached data, there is no need to save.
|
||||
@@ -118,7 +118,7 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
|
||||
// Suppress casting of CompletableFuture<?> to CompletableFuture<LodRenderSource>
|
||||
@SuppressWarnings("unchecked")
|
||||
private CompletableFuture<IRenderSource> _readCached(Object obj)
|
||||
private CompletableFuture<ColumnRenderSource> _readCached(Object obj)
|
||||
{
|
||||
// Has file cached in RAM and not freed yet.
|
||||
if ((obj instanceof SoftReference<?>))
|
||||
@@ -126,9 +126,8 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
Object inner = ((SoftReference<?>) obj).get();
|
||||
if (inner != null)
|
||||
{
|
||||
LodUtil.assertTrue(inner instanceof IRenderSource);
|
||||
fileHandler.onReadRenderSourceFromCache(this, (IRenderSource) inner);
|
||||
return CompletableFuture.completedFuture((IRenderSource) inner);
|
||||
fileHandler.onReadRenderSourceFromCache(this, (ColumnRenderSource) inner);
|
||||
return CompletableFuture.completedFuture((ColumnRenderSource) inner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,18 +135,18 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
// Someone is already trying to complete it. so just return the obj.
|
||||
if ((obj instanceof CompletableFuture<?>))
|
||||
{
|
||||
return (CompletableFuture<IRenderSource>) obj;
|
||||
return (CompletableFuture<ColumnRenderSource>) obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cause: Generic Type runtime casting cannot safety check it.
|
||||
// However, the Union type ensures the 'data' should only contain the listed type.
|
||||
public CompletableFuture<IRenderSource> loadOrGetCached(Executor fileReaderThreads, IDhLevel level)
|
||||
public CompletableFuture<ColumnRenderSource> loadOrGetCached(Executor fileReaderThreads, IDhLevel level)
|
||||
{
|
||||
Object obj = this.data.get();
|
||||
|
||||
CompletableFuture<IRenderSource> cached = this._readCached(obj);
|
||||
CompletableFuture<ColumnRenderSource> cached = this._readCached(obj);
|
||||
if (cached != null)
|
||||
{
|
||||
return cached;
|
||||
@@ -156,7 +155,7 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
// Create an empty and non-completed future.
|
||||
// Note: I do this before actually filling in the future so that I can ensure only
|
||||
// one task is submitted to the thread pool.
|
||||
CompletableFuture<IRenderSource> loadRenderSourceFuture = new CompletableFuture<>();
|
||||
CompletableFuture<ColumnRenderSource> loadRenderSourceFuture = new CompletableFuture<>();
|
||||
|
||||
// Would use faster and non-nesting Compare and exchange. But java 8 doesn't have it! :(
|
||||
boolean worked = this.data.compareAndSet(obj, loadRenderSourceFuture);
|
||||
@@ -204,7 +203,7 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
}
|
||||
|
||||
// Load the file.
|
||||
IRenderSource renderSource;
|
||||
ColumnRenderSource renderSource;
|
||||
try (FileInputStream fio = this.getDataContent())
|
||||
{
|
||||
renderSource = this.loader.loadRenderSource(this, fio, level);
|
||||
@@ -235,11 +234,11 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
return loadRenderSourceFuture;
|
||||
}
|
||||
|
||||
private static MetaData makeMetaData(IRenderSource data)
|
||||
private static MetaData makeMetaData(ColumnRenderSource renderSource)
|
||||
{
|
||||
AbstractRenderSourceLoader loader = AbstractRenderSourceLoader.getLoader(data.getClass(), data.getRenderVersion());
|
||||
return new MetaData(data.getSectionPos(), -1,
|
||||
data.getDataDetail(), loader == null ? 0 : loader.renderTypeId, data.getRenderVersion());
|
||||
AbstractRenderSourceLoader loader = AbstractRenderSourceLoader.getLoader(renderSource.getClass(), renderSource.getRenderVersion());
|
||||
return new MetaData(renderSource.getSectionPos(), -1,
|
||||
renderSource.getDataDetail(), loader == null ? 0 : loader.renderTypeId, renderSource.getRenderVersion());
|
||||
}
|
||||
|
||||
private FileInputStream getDataContent() throws IOException
|
||||
@@ -262,9 +261,9 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
return fin;
|
||||
}
|
||||
|
||||
public void save(IRenderSource data, IDhClientLevel level)
|
||||
public void save(ColumnRenderSource renderSource, IDhClientLevel level)
|
||||
{
|
||||
if (data.isEmpty())
|
||||
if (renderSource.isEmpty())
|
||||
{
|
||||
if (this.path.exists())
|
||||
{
|
||||
@@ -280,7 +279,7 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
|
||||
//LOGGER.info("Saving updated render file v[{}] at sect {}", this.metaData.dataVersion.get(), this.pos);
|
||||
try
|
||||
{
|
||||
super.writeData((out) -> data.saveRender(level, this, out));
|
||||
super.writeData((out) -> renderSource.saveRender(level, this, out));
|
||||
this.doesFileExist = true;
|
||||
}
|
||||
catch (IOException e)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.seibel.lod.core.render;
|
||||
|
||||
import com.seibel.lod.core.datatype.render.ColumnRenderSource;
|
||||
import com.seibel.lod.core.level.IDhClientLevel;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.pos.DhSectionPos;
|
||||
import com.seibel.lod.core.datatype.render.IRenderSource;
|
||||
import com.seibel.lod.core.file.renderfile.ILodRenderSourceProvider;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -23,11 +23,11 @@ public class LodRenderSection
|
||||
// (Should always be 4 after tick() is done, or 0 only if this is an unloaded node)
|
||||
public byte childCount = 0;
|
||||
|
||||
private CompletableFuture<IRenderSource> loadFuture;
|
||||
private CompletableFuture<ColumnRenderSource> loadFuture;
|
||||
private boolean isRenderEnabled = false;
|
||||
|
||||
// TODO: Should I provide a way to change the render source?
|
||||
private IRenderSource renderSource;
|
||||
private ColumnRenderSource renderSource;
|
||||
private ILodRenderSourceProvider renderSourceProvider = null;
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ public class LodRenderSection
|
||||
|
||||
public boolean isOutdated() { return this.renderSource != null && !this.renderSource.isValid(); }
|
||||
|
||||
public IRenderSource getRenderSource() { return this.renderSource; }
|
||||
public ColumnRenderSource getRenderSource() { return this.renderSource; }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.core.render;
|
||||
|
||||
import com.seibel.lod.core.datatype.render.IRenderSource;
|
||||
import com.seibel.lod.core.datatype.render.ColumnRenderSource;
|
||||
import com.seibel.lod.core.enums.ELodDirection;
|
||||
import com.seibel.lod.core.pos.Pos2D;
|
||||
import com.seibel.lod.core.pos.DhSectionPos;
|
||||
@@ -265,7 +265,7 @@ public class RenderBufferHandler
|
||||
// (as this update() should be called from the same thread that calls update() on the quad tree)
|
||||
LodUtil.assertTrue(section != null);
|
||||
|
||||
IRenderSource currentRenderSource = section.getRenderSource();
|
||||
ColumnRenderSource currentRenderSource = section.getRenderSource();
|
||||
|
||||
// Update self's render buffer state
|
||||
if (!section.shouldRender())
|
||||
|
||||
Reference in New Issue
Block a user