rename dataFile -> fullDataFile

This commit is contained in:
James Seibel
2023-02-13 20:24:31 -06:00
parent 228ba2b2e2
commit 6ff1d92ce1
22 changed files with 113 additions and 110 deletions
@@ -2,7 +2,7 @@ package com.seibel.lod.core.datatype;
import com.google.common.collect.HashMultimap;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.file.datafile.DataMetaFile;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
import java.io.IOException;
import java.io.InputStream;
@@ -62,7 +62,7 @@ public abstract class AbstractDataSourceLoader
}
/** Can return null as meaning the requirement is not met */
public abstract ILodDataSource loadData(DataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException;
public abstract ILodDataSource loadData(FullDataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException;
}
@@ -3,9 +3,9 @@ package com.seibel.lod.core.datatype;
import com.seibel.lod.core.datatype.full.ChunkSizedData;
import com.seibel.lod.core.datatype.full.FullDataPointIdMap;
import com.seibel.lod.core.datatype.full.accessor.SingleFullArrayView;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.pos.DhSectionPos;
import com.seibel.lod.core.file.datafile.DataMetaFile;
import java.io.IOException;
import java.io.OutputStream;
@@ -22,7 +22,7 @@ public interface ILodDataSource
boolean isEmpty();
void saveData(IDhLevel level, DataMetaFile file, OutputStream dataStream) throws IOException;
void saveData(IDhLevel level, FullDataMetaFile file, OutputStream dataStream) throws IOException;
/**
* Attempts to get the data column for the given relative x and z position.
@@ -2,9 +2,9 @@ package com.seibel.lod.core.datatype.full;
import com.seibel.lod.core.datatype.ILodDataSource;
import com.seibel.lod.core.datatype.full.accessor.SingleFullArrayView;
import com.seibel.lod.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.lod.core.pos.DhLodPos;
import com.seibel.lod.core.pos.DhSectionPos;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.util.LodUtil;
import org.apache.logging.log4j.Logger;
@@ -14,12 +14,12 @@ import java.util.concurrent.CompletableFuture;
public class FullDataDownSampler {
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
public static CompletableFuture<ILodDataSource> createDownSamplingFuture(DhSectionPos newTarget, IDataSourceProvider provider) {
public static CompletableFuture<ILodDataSource> createDownSamplingFuture(DhSectionPos newTarget, IFullDataSourceProvider provider) {
// TODO: Make this future somehow run with lowest priority (to ensure ram usage stays low)
return createDownSamplingFuture(FullDataSource.createEmpty(newTarget), provider);
}
public static CompletableFuture<ILodDataSource> createDownSamplingFuture(FullDataSource target, IDataSourceProvider provider) {
public static CompletableFuture<ILodDataSource> createDownSamplingFuture(FullDataSource target, IFullDataSourceProvider provider) {
int sectionSizeNeeded = 1 << target.getDataDetail();
ArrayList<CompletableFuture<ILodDataSource>> futures;
@@ -2,8 +2,8 @@ package com.seibel.lod.core.datatype.full;
import com.seibel.lod.core.datatype.AbstractDataSourceLoader;
import com.seibel.lod.core.datatype.ILodDataSource;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.file.datafile.DataMetaFile;
import java.io.IOException;
import java.io.InputStream;
@@ -16,7 +16,7 @@ public class FullDataLoader extends AbstractDataSourceLoader
}
@Override
public ILodDataSource loadData(DataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException
public ILodDataSource loadData(FullDataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException
{
//TODO: Add decompressor here
return FullDataSource.loadData(dataFile, data, level);
@@ -5,7 +5,7 @@ import com.seibel.lod.core.datatype.full.accessor.SingleFullArrayView;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.pos.DhBlockPos2D;
import com.seibel.lod.core.pos.DhLodPos;
import com.seibel.lod.core.file.datafile.DataMetaFile;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.lod.core.datatype.ILodDataSource;
import com.seibel.lod.core.pos.DhSectionPos;
import com.seibel.lod.core.util.BitShiftUtil;
@@ -127,7 +127,7 @@ public class FullDataSource extends FullArrayView implements ILodDataSource
public void markNotEmpty() { this.isEmpty = false; }
@Override
public void saveData(IDhLevel level, DataMetaFile file, OutputStream dataStream) throws IOException
public void saveData(IDhLevel level, FullDataMetaFile file, OutputStream dataStream) throws IOException
{
DataOutputStream dos = new DataOutputStream(dataStream); // DO NOT CLOSE
{
@@ -172,7 +172,7 @@ public class FullDataSource extends FullArrayView implements ILodDataSource
}
public static FullDataSource loadData(DataMetaFile dataFile, InputStream dataStream, IDhLevel level) throws IOException
public static FullDataSource loadData(FullDataMetaFile dataFile, InputStream dataStream, IDhLevel level) throws IOException
{
DataInputStream dos = new DataInputStream(dataStream); // DO NOT CLOSE
{
@@ -2,8 +2,8 @@ package com.seibel.lod.core.datatype.full;
import com.seibel.lod.core.datatype.AbstractDataSourceLoader;
import com.seibel.lod.core.datatype.ILodDataSource;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.file.datafile.DataMetaFile;
import java.io.IOException;
import java.io.InputStream;
@@ -16,7 +16,7 @@ public class SparseDataLoader extends AbstractDataSourceLoader
}
@Override
public ILodDataSource loadData(DataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException
public ILodDataSource loadData(FullDataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException
{
return SparseDataSource.loadData(dataFile, data, level);
}
@@ -4,10 +4,10 @@ import com.seibel.lod.core.datatype.IIncompleteDataSource;
import com.seibel.lod.core.datatype.ILodDataSource;
import com.seibel.lod.core.datatype.full.accessor.FullArrayView;
import com.seibel.lod.core.datatype.full.accessor.SingleFullArrayView;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.pos.DhLodPos;
import com.seibel.lod.core.pos.DhSectionPos;
import com.seibel.lod.core.file.datafile.DataMetaFile;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.util.BitShiftUtil;
import com.seibel.lod.core.util.LodUtil;
@@ -210,7 +210,7 @@ public class SparseDataSource implements IIncompleteDataSource
}
@Override
public void saveData(IDhLevel level, DataMetaFile file, OutputStream dataStream) throws IOException
public void saveData(IDhLevel level, FullDataMetaFile file, OutputStream dataStream) throws IOException
{
try (DataOutputStream dos = new DataOutputStream(dataStream))
{
@@ -279,7 +279,7 @@ public class SparseDataSource implements IIncompleteDataSource
}
}
public static SparseDataSource loadData(DataMetaFile dataFile, InputStream dataStream, IDhLevel level) throws IOException
public static SparseDataSource loadData(FullDataMetaFile dataFile, InputStream dataStream, IDhLevel level) throws IOException
{
LodUtil.assertTrue(dataFile.pos.sectionDetailLevel > SPARSE_UNIT_DETAIL);
LodUtil.assertTrue(dataFile.pos.sectionDetailLevel <= MAX_SECTION_DETAIL);
@@ -2,7 +2,7 @@ package com.seibel.lod.core.datatype.full;
import com.seibel.lod.core.datatype.AbstractDataSourceLoader;
import com.seibel.lod.core.datatype.ILodDataSource;
import com.seibel.lod.core.file.datafile.DataMetaFile;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.lod.core.level.IDhLevel;
import java.io.IOException;
@@ -15,7 +15,7 @@ public class SpottyDataLoader extends AbstractDataSourceLoader
}
@Override
public ILodDataSource loadData(DataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException {
public ILodDataSource loadData(FullDataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException {
return SpottyDataSource.loadData(dataFile, data, level);
}
}
@@ -4,7 +4,7 @@ import com.seibel.lod.core.datatype.IIncompleteDataSource;
import com.seibel.lod.core.datatype.ILodDataSource;
import com.seibel.lod.core.datatype.full.accessor.FullArrayView;
import com.seibel.lod.core.datatype.full.accessor.SingleFullArrayView;
import com.seibel.lod.core.file.datafile.DataMetaFile;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.pos.DhLodPos;
@@ -79,7 +79,7 @@ public class SpottyDataSource extends FullArrayView implements IIncompleteDataSo
public void markNotEmpty() { this.isEmpty = false; }
@Override
public void saveData(IDhLevel level, DataMetaFile file, OutputStream dataStream) throws IOException
public void saveData(IDhLevel level, FullDataMetaFile file, OutputStream dataStream) throws IOException
{
DataOutputStream dos = new DataOutputStream(dataStream); // DO NOT CLOSE
{
@@ -118,7 +118,7 @@ public class SpottyDataSource extends FullArrayView implements IIncompleteDataSo
}
public static SpottyDataSource loadData(DataMetaFile dataFile, InputStream dataStream, IDhLevel level) throws IOException
public static SpottyDataSource loadData(FullDataMetaFile dataFile, InputStream dataStream, IDhLevel level) throws IOException
{
DataInputStream dos = new DataInputStream(dataStream); // DO NOT CLOSE
{
@@ -1,11 +0,0 @@
package com.seibel.lod.core.file.datafile;
import com.seibel.lod.core.level.IDhLevel;
import java.io.File;
public class RemoteDataFileHandler extends DataFileHandler {
public RemoteDataFileHandler(IDhLevel level, File saveRootDir) {
super(level, saveRootDir);
}
}
@@ -1,4 +1,4 @@
package com.seibel.lod.core.file.datafile;
package com.seibel.lod.core.file.fullDatafile;
import com.google.common.collect.HashMultimap;
import com.seibel.lod.core.datatype.IIncompleteDataSource;
@@ -18,7 +18,6 @@ import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -28,18 +27,18 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
public class DataFileHandler implements IDataSourceProvider
public class FullDataFileHandler implements IFullDataSourceProvider
{
// Note: Single main thread only for now. May make it multi-thread later, depending on the usage.
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
final ExecutorService fileReaderThread = LodUtil.makeThreadPool(4, "FileReaderThread");
final ConcurrentHashMap<DhSectionPos, DataMetaFile> files = new ConcurrentHashMap<>();
final ConcurrentHashMap<DhSectionPos, FullDataMetaFile> files = new ConcurrentHashMap<>();
final IDhLevel level;
final File saveDir;
AtomicInteger topDetailLevel = new AtomicInteger(-1);
final int minDetailLevel = FullDataSource.SECTION_SIZE_OFFSET;
public DataFileHandler(IDhLevel level, File saveRootDir)
public FullDataFileHandler(IDhLevel level, File saveRootDir)
{
this.saveDir = saveRootDir;
this.level = level;
@@ -52,7 +51,7 @@ public class DataFileHandler implements IDataSourceProvider
@Override
public void addScannedFile(Collection<File> detectedFiles)
{
HashMultimap<DhSectionPos, DataMetaFile> filesByPos = HashMultimap.create();
HashMultimap<DhSectionPos, FullDataMetaFile> filesByPos = HashMultimap.create();
LOGGER.info("Detected {} valid files in {}", detectedFiles.size(), this.saveDir);
{ // Sort files by pos.
@@ -60,7 +59,7 @@ public class DataFileHandler implements IDataSourceProvider
{
try
{
DataMetaFile metaFile = new DataMetaFile(this, this.level, file);
FullDataMetaFile metaFile = new FullDataMetaFile(this, this.level, file);
filesByPos.put(metaFile.pos, metaFile);
}
catch (IOException e)
@@ -95,8 +94,8 @@ public class DataFileHandler implements IDataSourceProvider
// Warn for multiple files with the same pos, and then select the one with the latest timestamp.
for (DhSectionPos pos : filesByPos.keySet())
{
Collection<DataMetaFile> metaFiles = filesByPos.get(pos);
DataMetaFile fileToUse;
Collection<FullDataMetaFile> metaFiles = filesByPos.get(pos);
FullDataMetaFile fileToUse;
if (metaFiles.size() > 1)
{
fileToUse = Collections.max(metaFiles, Comparator.comparingLong(a -> a.metaData.dataVersion.get()));
@@ -105,7 +104,7 @@ public class DataFileHandler implements IDataSourceProvider
sb.append("Multiple files with the same pos: ");
sb.append(pos);
sb.append("\n");
for (DataMetaFile metaFile : metaFiles)
for (FullDataMetaFile metaFile : metaFiles)
{
sb.append("\t");
sb.append(metaFile.path);
@@ -118,7 +117,7 @@ public class DataFileHandler implements IDataSourceProvider
LOGGER.warn(sb.toString());
// Rename all other files with the same pos to .old
for (DataMetaFile metaFile : metaFiles)
for (FullDataMetaFile metaFile : metaFiles)
{
if (metaFile == fileToUse)
{
@@ -149,15 +148,15 @@ public class DataFileHandler implements IDataSourceProvider
}
}
protected DataMetaFile getOrMakeFile(DhSectionPos pos)
protected FullDataMetaFile getOrMakeFile(DhSectionPos pos)
{
DataMetaFile metaFile = this.files.get(pos);
FullDataMetaFile metaFile = this.files.get(pos);
if (metaFile == null)
{
DataMetaFile newMetaFile;
FullDataMetaFile newMetaFile;
try
{
newMetaFile = new DataMetaFile(this, this.level, pos);
newMetaFile = new FullDataMetaFile(this, this.level, pos);
}
catch (IOException e)
{
@@ -176,11 +175,11 @@ public class DataFileHandler implements IDataSourceProvider
/**
* Populates the preexistingFiles and missingFilePositions ArrayLists.
*
* @param preexistingFiles the list of {@link DataMetaFile}'s that have been created for the given position.
* @param missingFilePositions the list of {@link DhSectionPos}'s that don't have {@link DataMetaFile} created for them yet.
* @param preexistingFiles the list of {@link FullDataMetaFile}'s that have been created for the given position.
* @param missingFilePositions the list of {@link DhSectionPos}'s that don't have {@link FullDataMetaFile} created for them yet.
*/
protected void getDataFilesForPosition(DhSectionPos basePos, DhSectionPos pos,
ArrayList<DataMetaFile> preexistingFiles, ArrayList<DhSectionPos> missingFilePositions)
ArrayList<FullDataMetaFile> preexistingFiles, ArrayList<DhSectionPos> missingFilePositions)
{
byte sectionDetail = pos.sectionDetailLevel;
boolean allEmpty = true;
@@ -229,12 +228,12 @@ public class DataFileHandler implements IDataSourceProvider
this.recursiveGetDataFilesForPosition(3, basePos, pos, preexistingFiles, missingFilePositions);
}
}
private void recursiveGetDataFilesForPosition(int childIndex, DhSectionPos basePos, DhSectionPos pos, ArrayList<DataMetaFile> preexistingFiles, ArrayList<DhSectionPos> missingFilePositions)
private void recursiveGetDataFilesForPosition(int childIndex, DhSectionPos basePos, DhSectionPos pos, ArrayList<FullDataMetaFile> preexistingFiles, ArrayList<DhSectionPos> missingFilePositions)
{
DhSectionPos childPos = pos.getChildByIndex(childIndex);
if (FullDataSource.firstDataPosCanAffectSecond(basePos, childPos))
{
DataMetaFile metaFile = this.files.get(childPos);
FullDataMetaFile metaFile = this.files.get(childPos);
if (metaFile != null)
{
// we have reached a populated leaf node in the quad tree
@@ -265,7 +264,7 @@ public class DataFileHandler implements IDataSourceProvider
public CompletableFuture<ILodDataSource> read(DhSectionPos pos)
{
this.topDetailLevel.updateAndGet(intVal -> Math.max(intVal, pos.sectionDetailLevel));
DataMetaFile metaFile = this.getOrMakeFile(pos);
FullDataMetaFile metaFile = this.getOrMakeFile(pos);
if (metaFile == null)
{
return CompletableFuture.completedFuture(null);
@@ -276,7 +275,7 @@ public class DataFileHandler implements IDataSourceProvider
CompletableFuture<ILodDataSource> futureWrapper = new CompletableFuture<>();
metaFile.loadOrGetCachedAsync().exceptionally((e) ->
{
DataMetaFile newMetaFile = this.removeCorruptedFile(pos, metaFile, e);
FullDataMetaFile newMetaFile = this.removeCorruptedFile(pos, metaFile, e);
futureWrapper.completeExceptionally(e);
return null; // return value doesn't matter
@@ -300,7 +299,7 @@ public class DataFileHandler implements IDataSourceProvider
}
private void recursiveWrite(DhSectionPos sectionPos, ChunkSizedData chunkData)
{
DataMetaFile metaFile = this.files.get(sectionPos);
FullDataMetaFile metaFile = this.files.get(sectionPos);
if (metaFile != null)
{
// Fast path: if there is a file for this section, just write to it.
@@ -318,7 +317,7 @@ public class DataFileHandler implements IDataSourceProvider
public CompletableFuture<Void> flushAndSave()
{
ArrayList<CompletableFuture<Void>> futures = new ArrayList<>();
for (DataMetaFile metaFile : this.files.values())
for (FullDataMetaFile metaFile : this.files.values())
{
futures.add(metaFile.flushAndSave());
}
@@ -328,7 +327,7 @@ public class DataFileHandler implements IDataSourceProvider
@Override
public long getCacheVersion(DhSectionPos sectionPos)
{
DataMetaFile file = this.files.get(sectionPos);
FullDataMetaFile file = this.files.get(sectionPos);
if (file == null)
{
return 0;
@@ -339,7 +338,7 @@ public class DataFileHandler implements IDataSourceProvider
@Override
public boolean isCacheVersionValid(DhSectionPos sectionPos, long cacheVersion)
{
DataMetaFile file = this.files.get(sectionPos);
FullDataMetaFile file = this.files.get(sectionPos);
if (file == null)
{
return cacheVersion >= 0;
@@ -348,10 +347,10 @@ public class DataFileHandler implements IDataSourceProvider
}
@Override
public CompletableFuture<ILodDataSource> onCreateDataFile(DataMetaFile file)
public CompletableFuture<ILodDataSource> onCreateDataFile(FullDataMetaFile file)
{
DhSectionPos pos = file.pos;
ArrayList<DataMetaFile> existFiles = new ArrayList<>();
ArrayList<FullDataMetaFile> existFiles = new ArrayList<>();
ArrayList<DhSectionPos> missing = new ArrayList<>();
this.getDataFilesForPosition(pos, pos, existFiles, missing);
LodUtil.assertTrue(!missing.isEmpty() || !existFiles.isEmpty());
@@ -366,7 +365,7 @@ public class DataFileHandler implements IDataSourceProvider
{
for (DhSectionPos missingPos : missing)
{
DataMetaFile newFile = this.getOrMakeFile(missingPos);
FullDataMetaFile newFile = this.getOrMakeFile(missingPos);
if (newFile != null)
{
existFiles.add(newFile);
@@ -377,7 +376,7 @@ public class DataFileHandler implements IDataSourceProvider
SparseDataSource.createEmpty(pos) :
SpottyDataSource.createEmpty(pos);
for (DataMetaFile metaFile : existFiles)
for (FullDataMetaFile metaFile : existFiles)
{
futures.add(metaFile.loadOrGetCachedAsync()
.thenAccept((data) ->
@@ -390,7 +389,7 @@ public class DataFileHandler implements IDataSourceProvider
})
.exceptionally((e) ->
{
DataMetaFile newMetaFile = this.removeCorruptedFile(pos, metaFile, e);
FullDataMetaFile newMetaFile = this.removeCorruptedFile(pos, metaFile, e);
return null;
})
);
@@ -400,14 +399,14 @@ public class DataFileHandler implements IDataSourceProvider
}
}
private DataMetaFile removeCorruptedFile(DhSectionPos pos, DataMetaFile metaFile, Throwable exception)
private FullDataMetaFile removeCorruptedFile(DhSectionPos pos, FullDataMetaFile metaFile, Throwable exception)
{
LOGGER.error("Error reading Data file ["+pos+"]", exception);
FileUtil.renameCorruptedFile(metaFile.path);
// remove the DataMetaFile since the old one was corrupted
// remove the FullDataMetaFile since the old one was corrupted
this.files.remove(pos);
// create a new DataMetaFile to write new data to
// create a new FullDataMetaFile to write new data to
return this.getOrMakeFile(pos);
}
@@ -465,7 +464,7 @@ public class DataFileHandler implements IDataSourceProvider
@Override
public void close()
{
DataMetaFile.debugCheck();
FullDataMetaFile.debugCheck();
//TODO
}
@@ -1,4 +1,4 @@
package com.seibel.lod.core.file.datafile;
package com.seibel.lod.core.file.fullDatafile;
import java.io.*;
import java.lang.ref.*;
@@ -21,12 +21,15 @@ import com.seibel.lod.core.util.AtomicsUtil;
import com.seibel.lod.core.util.LodUtil;
import org.apache.logging.log4j.Logger;
public class DataMetaFile extends AbstractMetaDataFile
/**
* Related to the stored Blockstate/Biome ID data.
*/
public class FullDataMetaFile extends AbstractMetaDataFile
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger(DataMetaFile.class.getSimpleName());
private static final Logger LOGGER = DhLoggerBuilder.getLogger(FullDataMetaFile.class.getSimpleName());
private final IDhLevel level;
private final IDataSourceProvider handler;
private final IFullDataSourceProvider handler;
private boolean doesFileExist;
public AbstractDataSourceLoader loader;
@@ -75,7 +78,7 @@ public class DataMetaFile extends AbstractMetaDataFile
// Create a new metaFile
public DataMetaFile(IDataSourceProvider handler, IDhLevel level, DhSectionPos pos) throws IOException {
public FullDataMetaFile(IFullDataSourceProvider handler, IDhLevel level, DhSectionPos pos) throws IOException {
super(handler.computeDataFilePath(pos), pos);
debugCheck();
this.handler = handler;
@@ -84,7 +87,7 @@ public class DataMetaFile extends AbstractMetaDataFile
doesFileExist = false;
}
public DataMetaFile(IDataSourceProvider handler, IDhLevel level, File path) throws IOException {
public FullDataMetaFile(IFullDataSourceProvider handler, IDhLevel level, File path) throws IOException {
super(path);
debugCheck();
this.handler = handler;
@@ -1,4 +1,4 @@
package com.seibel.lod.core.file.datafile;
package com.seibel.lod.core.file.fullDatafile;
import com.seibel.lod.core.datatype.IIncompleteDataSource;
import com.seibel.lod.core.datatype.ILodDataSource;
@@ -20,7 +20,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
public class GeneratedDataFileHandler extends DataFileHandler
public class GeneratedFullDataFileHandler extends FullDataFileHandler
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
@@ -28,7 +28,7 @@ public class GeneratedDataFileHandler extends DataFileHandler
public GeneratedDataFileHandler(IDhServerLevel level, File saveRootDir) { super(level, saveRootDir); }
public GeneratedFullDataFileHandler(IDhServerLevel level, File saveRootDir) { super(level, saveRootDir); }
@@ -44,11 +44,11 @@ public class GeneratedDataFileHandler extends DataFileHandler
@Override
public CompletableFuture<ILodDataSource> onCreateDataFile(DataMetaFile file)
public CompletableFuture<ILodDataSource> onCreateDataFile(FullDataMetaFile file)
{
DhSectionPos pos = file.pos;
ArrayList<DataMetaFile> existingFiles = new ArrayList<>();
ArrayList<FullDataMetaFile> existingFiles = new ArrayList<>();
ArrayList<DhSectionPos> missingPositions = new ArrayList<>();
this.getDataFilesForPosition(pos, pos, existingFiles, missingPositions);
@@ -85,7 +85,7 @@ public class GeneratedDataFileHandler extends DataFileHandler
// create the missing metaData files
for (DhSectionPos missingPos : missingPositions)
{
DataMetaFile newFile = this.getOrMakeFile(missingPos);
FullDataMetaFile newFile = this.getOrMakeFile(missingPos);
if (newFile != null)
{
existingFiles.add(newFile);
@@ -96,7 +96,7 @@ public class GeneratedDataFileHandler extends DataFileHandler
// read in the existing data
final ArrayList<CompletableFuture<Void>> futures = new ArrayList<>(existingFiles.size());
for (DataMetaFile existingFile : existingFiles)
for (FullDataMetaFile existingFile : existingFiles)
{
futures.add(existingFile.loadOrGetCachedAsync()
.exceptionally((ex) -> /*Ignore file read errors*/null)
@@ -173,7 +173,7 @@ public class GeneratedDataFileHandler extends DataFileHandler
{
if (chunk.getBBoxLodPos().overlaps(this.loadedTargetData.getSectionPos().getSectionBBoxPos()))
{
GeneratedDataFileHandler.this.write(this.loadedTargetData.getSectionPos(), chunk);
GeneratedFullDataFileHandler.this.write(this.loadedTargetData.getSectionPos(), chunk);
}
};
}
@@ -1,4 +1,4 @@
package com.seibel.lod.core.file.datafile;
package com.seibel.lod.core.file.fullDatafile;
import com.seibel.lod.core.datatype.ILodDataSource;
import com.seibel.lod.core.datatype.full.ChunkSizedData;
@@ -12,7 +12,7 @@ import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Function;
public interface IDataSourceProvider extends AutoCloseable {
public interface IFullDataSourceProvider extends AutoCloseable {
void addScannedFile(Collection<File> detectedFiles);
CompletableFuture<ILodDataSource> read(DhSectionPos pos);
@@ -22,7 +22,7 @@ public interface IDataSourceProvider extends AutoCloseable {
long getCacheVersion(DhSectionPos sectionPos);
boolean isCacheVersionValid(DhSectionPos sectionPos, long cacheVersion);
CompletableFuture<ILodDataSource> onCreateDataFile(DataMetaFile file);
CompletableFuture<ILodDataSource> onCreateDataFile(FullDataMetaFile file);
ILodDataSource onDataFileLoaded(ILodDataSource source, MetaData metaData, Consumer<ILodDataSource> onUpdated, Function<ILodDataSource, Boolean> updater);
CompletableFuture<ILodDataSource> onDataFileRefresh(ILodDataSource source, MetaData metaData, Function<ILodDataSource, Boolean> updater, Consumer<ILodDataSource> onUpdated);
File computeDataFilePath(DhSectionPos pos);
@@ -0,0 +1,12 @@
package com.seibel.lod.core.file.fullDatafile;
import com.seibel.lod.core.level.IDhLevel;
import java.io.File;
public class RemoteFullDataFileHandler extends FullDataFileHandler
{
public RemoteFullDataFileHandler(IDhLevel level, File saveRootDir) {
super(level, saveRootDir);
}
}
@@ -8,7 +8,7 @@ import com.seibel.lod.core.datatype.AbstractRenderSourceLoader;
import com.seibel.lod.core.datatype.column.ColumnRenderSource;
import com.seibel.lod.core.datatype.full.ChunkSizedData;
import com.seibel.lod.core.datatype.transform.DataRenderTransformer;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.lod.core.level.IDhClientLevel;
import com.seibel.lod.core.pos.DhLodPos;
import com.seibel.lod.core.pos.DhSectionPos;
@@ -35,14 +35,14 @@ public class RenderFileHandler implements ILodRenderSourceProvider
private final IDhClientLevel level;
private final File saveDir;
private final IDataSourceProvider dataSourceProvider;
private final IFullDataSourceProvider dataSourceProvider;
private final ConcurrentHashMap<DhSectionPos, Object> cacheUpdateLockBySectionPos = new ConcurrentHashMap<>();
public RenderFileHandler(IDataSourceProvider sourceProvider, IDhClientLevel level, File saveRootDir)
public RenderFileHandler(IFullDataSourceProvider sourceProvider, IDhClientLevel level, File saveRootDir)
{
this.dataSourceProvider = sourceProvider;
this.level = level;
@@ -7,8 +7,8 @@ import com.seibel.lod.core.datatype.full.FullDataPoint;
import com.seibel.lod.core.datatype.full.accessor.SingleFullArrayView;
import com.seibel.lod.core.datatype.transform.LodDataBuilder;
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
import com.seibel.lod.core.file.datafile.DataFileHandler;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.file.fullDatafile.FullDataFileHandler;
import com.seibel.lod.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.lod.core.file.structure.ClientOnlySaveStructure;
import com.seibel.lod.core.level.DhClientLevel;
import com.seibel.lod.core.level.IDhLevel;
@@ -220,7 +220,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
break;
}
IDhLevel tempLevel = new DhClientLevel(new ClientOnlySaveStructure(), clientLevelWrapper);
IDataSourceProvider fileHandler = new DataFileHandler(tempLevel, testLevelFolder);
IFullDataSourceProvider fileHandler = new FullDataFileHandler(tempLevel, testLevelFolder);
CompletableFuture<ILodDataSource> testDataSource = fileHandler.read(new DhSectionPos(playerChunkPos));
ILodDataSource lodDataSource = testDataSource.get();
@@ -1,9 +1,9 @@
package com.seibel.lod.core.level;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.lod.core.render.LodQuadTree;
import com.seibel.lod.core.util.FileScanUtil;
import com.seibel.lod.core.file.datafile.RemoteDataFileHandler;
import com.seibel.lod.core.file.fullDatafile.RemoteFullDataFileHandler;
import com.seibel.lod.core.file.renderfile.RenderFileHandler;
import com.seibel.lod.core.pos.DhBlockPos2D;
import com.seibel.lod.core.render.RenderBufferHandler;
@@ -30,7 +30,7 @@ public class DhClientLevel implements IDhClientLevel
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
public final ClientOnlySaveStructure save;
public final RemoteDataFileHandler dataFileHandler;
public final RemoteFullDataFileHandler dataFileHandler;
public final RenderFileHandler renderFileHandler;
public final RenderBufferHandler renderBufferHandler; //TODO: Should this be owned by renderer?
public final IClientLevelWrapper level;
@@ -44,7 +44,7 @@ public class DhClientLevel implements IDhClientLevel
this.save = save;
save.getDataFolder(level).mkdirs();
save.getRenderCacheFolder(level).mkdirs();
this.dataFileHandler = new RemoteDataFileHandler(this, save.getDataFolder(level));
this.dataFileHandler = new RemoteFullDataFileHandler(this, save.getDataFolder(level));
this.renderFileHandler = new RenderFileHandler(this.dataFileHandler, this, save.getRenderCacheFolder(level));
this.tree = new LodQuadTree(this, Config.Client.Graphics.Quality.lodChunkRenderDistance.get() * 16,
MC_CLIENT.getPlayerBlockPos().x, MC_CLIENT.getPlayerBlockPos().z, this.renderFileHandler);
@@ -89,7 +89,7 @@ public class DhClientLevel implements IDhClientLevel
public ILevelWrapper getLevelWrapper() { return this.level; }
@Override
public IDataSourceProvider getFileHandler() { return this.dataFileHandler; }
public IFullDataSourceProvider getFileHandler() { return this.dataFileHandler; }
@Override
public void clearRenderDataCache()
@@ -6,13 +6,13 @@ import com.seibel.lod.core.config.AppliedConfigState;
import com.seibel.lod.core.datatype.full.ChunkSizedData;
import com.seibel.lod.core.datatype.full.FullDataSource;
import com.seibel.lod.core.datatype.transform.ChunkToLodBuilder;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.lod.core.generation.BatchGenerator;
import com.seibel.lod.core.generation.WorldGenerationQueue;
import com.seibel.lod.core.pos.DhLodPos;
import com.seibel.lod.core.pos.DhSectionPos;
import com.seibel.lod.core.render.LodQuadTree;
import com.seibel.lod.core.file.datafile.GeneratedDataFileHandler;
import com.seibel.lod.core.file.fullDatafile.GeneratedFullDataFileHandler;
import com.seibel.lod.core.util.FileScanUtil;
import com.seibel.lod.core.file.renderfile.RenderFileHandler;
import com.seibel.lod.core.pos.DhBlockPos2D;
@@ -46,7 +46,7 @@ public class DhClientServerLevel implements IDhClientLevel, IDhServerLevel
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
public final LocalSaveStructure save;
public final GeneratedDataFileHandler dataFileHandler;
public final GeneratedFullDataFileHandler dataFileHandler;
public final ChunkToLodBuilder chunkToLodBuilder;
public final IServerLevelWrapper serverLevel;
private final AppliedConfigState<Boolean> generatorEnabled;
@@ -63,7 +63,7 @@ public class DhClientServerLevel implements IDhClientLevel, IDhServerLevel
this.save = save;
save.getDataFolder(level).mkdirs();
save.getRenderCacheFolder(level).mkdirs();
this.dataFileHandler = new GeneratedDataFileHandler(this, save.getDataFolder(level));
this.dataFileHandler = new GeneratedFullDataFileHandler(this, save.getDataFolder(level));
FileScanUtil.scanFile(save, this.serverLevel, this.dataFileHandler, null);
LOGGER.info("Started DHLevel for {} with saves at {}", level, save);
this.f3Msg = new F3Screen.NestedMessage(this::f3Log);
@@ -337,7 +337,7 @@ public class DhClientServerLevel implements IDhClientLevel, IDhServerLevel
public IServerLevelWrapper getServerLevelWrapper() { return this.serverLevel; }
@Override
public IDataSourceProvider getFileHandler() { return this.dataFileHandler; }
public IFullDataSourceProvider getFileHandler() { return this.dataFileHandler; }
@Override
public void clearRenderDataCache()
@@ -1,8 +1,8 @@
package com.seibel.lod.core.level;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.lod.core.util.FileScanUtil;
import com.seibel.lod.core.file.datafile.DataFileHandler;
import com.seibel.lod.core.file.fullDatafile.FullDataFileHandler;
import com.seibel.lod.core.file.structure.LocalSaveStructure;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
@@ -17,7 +17,7 @@ public class DhServerLevel implements IDhServerLevel
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
public final LocalSaveStructure save;
public final DataFileHandler dataFileHandler;
public final FullDataFileHandler dataFileHandler;
public final IServerLevelWrapper level;
public DhServerLevel(LocalSaveStructure save, IServerLevelWrapper level)
@@ -25,7 +25,7 @@ public class DhServerLevel implements IDhServerLevel
this.save = save;
this.level = level;
save.getDataFolder(level).mkdirs();
this.dataFileHandler = new DataFileHandler(this, save.getDataFolder(level)); //FIXME: GenerationQueue
this.dataFileHandler = new FullDataFileHandler(this, save.getDataFolder(level)); //FIXME: GenerationQueue
FileScanUtil.scanFile(save, level, this.dataFileHandler, null);
LOGGER.info("Started DHLevel for {} with saves at {}", level, save);
}
@@ -67,7 +67,7 @@ public class DhServerLevel implements IDhServerLevel
public ILevelWrapper getLevelWrapper() { return this.level; }
@Override
public IDataSourceProvider getFileHandler() { return this.dataFileHandler; }
public IFullDataSourceProvider getFileHandler() { return this.dataFileHandler; }
@Override
public void clearRenderDataCache()
@@ -1,6 +1,6 @@
package com.seibel.lod.core.level;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
@@ -18,7 +18,7 @@ public interface IDhLevel extends AutoCloseable
void updateChunk(IChunkWrapper chunk);
IDataSourceProvider getFileHandler();
IFullDataSourceProvider getFileHandler();
/**
* Re-creates the color, render data.
@@ -1,6 +1,6 @@
package com.seibel.lod.core.util;
import com.seibel.lod.core.file.datafile.IDataSourceProvider;
import com.seibel.lod.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.lod.core.file.renderfile.ILodRenderSourceProvider;
import com.seibel.lod.core.file.structure.AbstractSaveStructure;
import com.seibel.lod.core.logging.DhLoggerBuilder;
@@ -19,7 +19,7 @@ public class FileScanUtil {
public static final int MAX_SCAN_DEPTH = 5;
public static final String LOD_FILE_POSTFIX = ".lod";
public static void scanFile(AbstractSaveStructure save, ILevelWrapper level,
@Nullable IDataSourceProvider dataSource,
@Nullable IFullDataSourceProvider dataSource,
@Nullable ILodRenderSourceProvider renderSource) {
if (dataSource != null) {
try (Stream<Path> pathStream = Files.walk(save.getDataFolder(level).toPath(), MAX_SCAN_DEPTH)) {