Auto format and move around a few comments

This commit is contained in:
James Seibel
2022-09-29 22:15:15 -05:00
parent 956f13c674
commit 58be4da5ca
5 changed files with 213 additions and 198 deletions
@@ -8,51 +8,61 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public abstract class DataSourceLoader {
public static final HashMultimap<Class<? extends LodDataSource>, DataSourceLoader> loaderRegistry = HashMultimap.create();
public final Class<? extends LodDataSource> clazz;
public static final HashMap<Long, Class<? extends LodDataSource>> datatypeIdRegistry = new HashMap<>();
public static DataSourceLoader getLoader(long dataTypeId, byte dataVersion) {
return loaderRegistry.get(datatypeIdRegistry.get(dataTypeId)).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, dataVersion) >= 0)
.findFirst().orElse(null);
}
public static DataSourceLoader getLoader(Class<? extends LodDataSource> clazz, byte dataVersion) {
return loaderRegistry.get(clazz).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, dataVersion) >= 0)
.findFirst().orElse(null);
}
public final long datatypeId;
public final byte[] loaderSupportedVersions;
public DataSourceLoader(Class<? extends LodDataSource> clazz, long datatypeId, byte[] loaderSupportedVersions) {
this.datatypeId = datatypeId;
this.loaderSupportedVersions = loaderSupportedVersions;
Arrays.sort(loaderSupportedVersions); // sort to allow fast access
this.clazz = clazz;
if (datatypeIdRegistry.containsKey(datatypeId) && datatypeIdRegistry.get(datatypeId) != clazz) {
throw new IllegalArgumentException("Loader for datatypeId " + datatypeId + " already registered with different class: "
+ datatypeIdRegistry.get(datatypeId) + " != " + clazz);
}
Set<DataSourceLoader> loaders = loaderRegistry.get(clazz);
if (loaders.stream().anyMatch(other -> {
// see if any loaderSupportsVersion conflicts with this one
for (byte otherVer : other.loaderSupportedVersions) {
if (Arrays.binarySearch(loaderSupportedVersions, otherVer) >= 0) return true;
}
return false;
})) {
throw new IllegalArgumentException("Loader for class " + clazz + " that supports one of the version in "
+ Arrays.toString(loaderSupportedVersions) + " already registered!");
}
datatypeIdRegistry.put(datatypeId, clazz);
loaderRegistry.put(clazz, this);
}
// Can return null as meaning the requirement is not met
public abstract LodDataSource loadData(DataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException;
public abstract class DataSourceLoader
{
public static final HashMultimap<Class<? extends LodDataSource>, DataSourceLoader> loaderRegistry = HashMultimap.create();
public final Class<? extends LodDataSource> clazz;
public static final HashMap<Long, Class<? extends LodDataSource>> datatypeIdRegistry = new HashMap<>();
public static DataSourceLoader getLoader(long dataTypeId, byte dataVersion)
{
return loaderRegistry.get(datatypeIdRegistry.get(dataTypeId)).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, dataVersion) >= 0)
.findFirst().orElse(null);
}
public static DataSourceLoader getLoader(Class<? extends LodDataSource> clazz, byte dataVersion)
{
return loaderRegistry.get(clazz).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, dataVersion) >= 0)
.findFirst().orElse(null);
}
public final long datatypeId;
public final byte[] loaderSupportedVersions;
public DataSourceLoader(Class<? extends LodDataSource> clazz, long datatypeId, byte[] loaderSupportedVersions)
{
this.datatypeId = datatypeId;
this.loaderSupportedVersions = loaderSupportedVersions;
Arrays.sort(loaderSupportedVersions); // sort to allow fast access
this.clazz = clazz;
if (datatypeIdRegistry.containsKey(datatypeId) && datatypeIdRegistry.get(datatypeId) != clazz)
{
throw new IllegalArgumentException("Loader for datatypeId " + datatypeId + " already registered with different class: "
+ datatypeIdRegistry.get(datatypeId) + " != " + clazz);
}
Set<DataSourceLoader> loaders = loaderRegistry.get(clazz);
if (loaders.stream().anyMatch(other -> {
// see if any loaderSupportsVersion conflicts with this one
for (byte otherVer : other.loaderSupportedVersions)
{
if (Arrays.binarySearch(loaderSupportedVersions, otherVer) >= 0)
return true;
}
return false;
}))
{
throw new IllegalArgumentException("Loader for class " + clazz + " that supports one of the version in "
+ Arrays.toString(loaderSupportedVersions) + " already registered!");
}
datatypeIdRegistry.put(datatypeId, clazz);
loaderRegistry.put(clazz, this);
}
// Can return null as meaning the requirement is not met
public abstract LodDataSource loadData(DataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException;
}
@@ -8,15 +8,18 @@ import com.seibel.lod.core.file.datafile.DataMetaFile;
import java.io.IOException;
import java.io.OutputStream;
public interface LodDataSource {
DhSectionPos getSectionPos();
byte getDataDetail();
byte getDataVersion();
void update(ChunkSizedData data);
boolean isEmpty();
// Saving related
void saveData(IDhLevel level, DataMetaFile file, OutputStream dataStream) throws IOException;
public interface LodDataSource
{
DhSectionPos getSectionPos();
byte getDataDetail();
byte getDataVersion();
void update(ChunkSizedData data);
boolean isEmpty();
// Saving related
void saveData(IDhLevel level, DataMetaFile file, OutputStream dataStream) throws IOException;
}
@@ -11,35 +11,38 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicReference;
public interface LodRenderSource {
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 trySwapRenderBuffer(LodQuadTree quadTree, AtomicReference<RenderBuffer> referenceSlot);
void saveRender(IDhClientLevel level, RenderMetaFile 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(ChunkSizedData chunkData, IDhClientLevel level);
// Only override the data that has not been written directly using write(), and skip those that are empty
void weakWrite(LodRenderSource source);
public interface LodRenderSource
{
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 trySwapRenderBuffer(LodQuadTree quadTree, AtomicReference<RenderBuffer> referenceSlot);
void saveRender(IDhClientLevel level, RenderMetaFile 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(ChunkSizedData chunkData, IDhClientLevel level);
/** Only override the data that has not been written directly using write(), and skip those that are empty */
void weakWrite(LodRenderSource source);
}
@@ -11,64 +11,53 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicReference;
public class PlaceHolderRenderSource implements LodRenderSource {
final DhSectionPos pos;
boolean isValid = true;
public PlaceHolderRenderSource(DhSectionPos pos) {
this.pos = pos;
}
@Override
public DhSectionPos getSectionPos() {
return pos;
}
@Override
public byte getDataDetail() {
return 0;
}
@Override
public void enableRender(IDhClientLevel level, LodQuadTree quadTree) {
}
@Override
public void disableRender() {}
@Override
public void dispose() {}
@Override
public boolean trySwapRenderBuffer(LodQuadTree quadTree, AtomicReference<RenderBuffer> referenceSlots) {
return false;
}
@Override
public void saveRender(IDhClientLevel level, RenderMetaFile file, OutputStream dataStream) throws IOException {
throw new UnsupportedOperationException("EmptyRenderSource should NEVER be saved!");
}
@Override
public byte getRenderVersion() {
return 0;
}
public void markInvalid() {
isValid = false;
}
@Override
public boolean isValid() {
return isValid;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public void fastWrite(ChunkSizedData chunkData, IDhClientLevel level) {}
@Override
public void weakWrite(LodRenderSource source) {}
public class PlaceHolderRenderSource implements LodRenderSource
{
final DhSectionPos pos;
boolean isValid = true;
public PlaceHolderRenderSource(DhSectionPos pos) { this.pos = pos; }
@Override
public DhSectionPos getSectionPos() { return pos; }
@Override
public byte getDataDetail() { return 0; }
@Override
public void enableRender(IDhClientLevel level, LodQuadTree quadTree){ /* TODO */ }
@Override
public void disableRender(){ /* TODO */ }
@Override
public void dispose(){ /* TODO */ }
@Override
public boolean trySwapRenderBuffer(LodQuadTree quadTree, AtomicReference<RenderBuffer> referenceSlots) { return false; }
@Override
public void saveRender(IDhClientLevel level, RenderMetaFile file, OutputStream dataStream) throws IOException
{
throw new UnsupportedOperationException("EmptyRenderSource should NEVER be saved!");
}
@Override
public byte getRenderVersion() { return 0; }
public void markInvalid() { isValid = false; }
@Override
public boolean isValid() { return isValid; }
@Override
public boolean isEmpty() { return true; }
@Override
public void fastWrite(ChunkSizedData chunkData, IDhClientLevel level) { /* TODO */ }
@Override
public void weakWrite(LodRenderSource source) { /* TODO */ }
}
@@ -9,53 +9,63 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public abstract class RenderSourceLoader {
public static final HashMultimap<Class<? extends LodRenderSource>, RenderSourceLoader> loaderRegistry = HashMultimap.create();
public static final HashMap<Long, Class<? extends LodRenderSource>> renderTypeIdRegistry = new HashMap<>();
public static RenderSourceLoader getLoader(long renderTypeId, byte loaderVersion) {
return loaderRegistry.get(renderTypeIdRegistry.get(renderTypeId)).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, loaderVersion) >= 0)
.findFirst().orElse(null);
}
public static RenderSourceLoader getLoader(Class<? extends LodRenderSource> clazz, byte loaderVersion) {
return loaderRegistry.get(clazz).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, loaderVersion) >= 0)
.findFirst().orElse(null);
}
public final Class<? extends LodRenderSource> clazz;
public final long renderTypeId;
public final byte[] loaderSupportedVersions;
public final byte detailOffset;
public RenderSourceLoader(Class<? extends LodRenderSource> clazz, long renderTypeId, byte[] loaderSupportedVersions, byte detailOffset) {
this.renderTypeId = renderTypeId;
this.loaderSupportedVersions = loaderSupportedVersions;
Arrays.sort(loaderSupportedVersions); // sort to allow fast access
this.clazz = clazz;
if (renderTypeIdRegistry.containsKey(renderTypeId) && renderTypeIdRegistry.get(renderTypeId) != clazz) {
throw new IllegalArgumentException("Loader for renderTypeId " + renderTypeId + " already registered with different class: "
+ renderTypeIdRegistry.get(renderTypeId) + " != " + clazz);
}
Set<RenderSourceLoader> loaders = loaderRegistry.get(clazz);
if (loaders.stream().anyMatch(other -> {
// see if any loaderSupportsVersion conflicts with this one
for (byte otherVer : other.loaderSupportedVersions) {
if (Arrays.binarySearch(loaderSupportedVersions, otherVer) >= 0) return true;
}
return false;
})) {
throw new IllegalArgumentException("Loader for class " + clazz + " that supports one of the version in "
+ Arrays.toString(loaderSupportedVersions) + " already registered!");
}
renderTypeIdRegistry.put(renderTypeId, clazz);
loaderRegistry.put(clazz, this);
this.detailOffset = detailOffset;
}
// Can return null as meaning the file is out of date or something
public abstract LodRenderSource loadRender(RenderMetaFile renderFile, InputStream data, IDhLevel level) throws IOException;
public abstract LodRenderSource createRender(LodDataSource dataSource, IDhClientLevel level);
public abstract class RenderSourceLoader
{
public static final HashMultimap<Class<? extends LodRenderSource>, RenderSourceLoader> loaderRegistry = HashMultimap.create();
public static final HashMap<Long, Class<? extends LodRenderSource>> renderTypeIdRegistry = new HashMap<>();
public static RenderSourceLoader getLoader(long renderTypeId, byte loaderVersion)
{
return loaderRegistry.get(renderTypeIdRegistry.get(renderTypeId)).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, loaderVersion) >= 0)
.findFirst().orElse(null);
}
public static RenderSourceLoader getLoader(Class<? extends LodRenderSource> clazz, byte loaderVersion)
{
return loaderRegistry.get(clazz).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, loaderVersion) >= 0)
.findFirst().orElse(null);
}
public final Class<? extends LodRenderSource> clazz;
public final long renderTypeId;
public final byte[] loaderSupportedVersions;
public final byte detailOffset;
public RenderSourceLoader(Class<? extends LodRenderSource> clazz, long renderTypeId, byte[] loaderSupportedVersions, byte detailOffset)
{
this.renderTypeId = renderTypeId;
this.loaderSupportedVersions = loaderSupportedVersions;
Arrays.sort(loaderSupportedVersions); // sort to allow fast access
this.clazz = clazz;
if (renderTypeIdRegistry.containsKey(renderTypeId) && renderTypeIdRegistry.get(renderTypeId) != clazz)
{
throw new IllegalArgumentException("Loader for renderTypeId " + renderTypeId + " already registered with different class: "
+ renderTypeIdRegistry.get(renderTypeId) + " != " + clazz);
}
Set<RenderSourceLoader> loaders = loaderRegistry.get(clazz);
if (loaders.stream().anyMatch(other -> {
// see if any loaderSupportsVersion conflicts with this one
for (byte otherVer : other.loaderSupportedVersions)
{
if (Arrays.binarySearch(loaderSupportedVersions, otherVer) >= 0)
return true;
}
return false;
}))
{
throw new IllegalArgumentException("Loader for class " + clazz + " that supports one of the version in "
+ Arrays.toString(loaderSupportedVersions) + " already registered!");
}
renderTypeIdRegistry.put(renderTypeId, clazz);
loaderRegistry.put(clazz, this);
this.detailOffset = detailOffset;
}
// Can return null as meaning the file is out of date or something
public abstract LodRenderSource loadRender(RenderMetaFile renderFile, InputStream data, IDhLevel level) throws IOException;
public abstract LodRenderSource createRender(LodDataSource dataSource, IDhClientLevel level);
}