NVoxelBuffer.java
package com.hypixel.hytale.builtin.hytalegenerator.newsystem.bufferbundle.buffers;
import com.hypixel.hytale.builtin.hytalegenerator.ArrayUtil;
import com.hypixel.hytale.builtin.hytalegenerator.bounds.Bounds3i;
import com.hypixel.hytale.builtin.hytalegenerator.newsystem.performanceinstruments.MemInstrument;
import com.hypixel.hytale.math.vector.Vector3i;
import java.util.Arrays;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class NVoxelBuffer<T> extends NBuffer {
public static final int BUFFER_SIZE_BITS = 3;
public static final Vector3i SIZE = new Vector3i(8, 8, 8);
private static final Bounds3i bounds;
@Nonnull
private final Class<T> voxelType;
@Nonnull
private State state;
@Nullable
ArrayContents<T> arrayContents;
T singleValue;
NVoxelBuffer<T> referenceBuffer;
{
.voxelType = voxelType;
.state = NVoxelBuffer.State.EMPTY;
.arrayContents = ;
.singleValue = ;
.referenceBuffer = ;
}
T {
bounds.contains(position);
Object var10000;
(.state.ordinal()) {
-> var10000 = .singleValue;
-> var10000 = .arrayContents.array[index(position)];
-> var10000 = .referenceBuffer.getVoxelContent(position);
-> var10000 = ;
}
(T)var10000;
}
Class<T> {
.voxelType;
}
{
bounds.contains(position);
(.state.ordinal()) {
:
(.singleValue == value) {
;
}
.switchFromSingleValueToArray();
.setVoxelContent(position, value);
;
:
.arrayContents.array[index(position)] = value;
;
:
.dereference();
.setVoxelContent(position, value);
;
:
.state = NVoxelBuffer.State.SINGLE_VALUE;
.singleValue = value;
}
}
{
.state = NVoxelBuffer.State.REFERENCE;
.referenceBuffer = .lastReference(sourceBuffer);
.singleValue = ;
.arrayContents = ;
}
NVoxelBuffer<T> {
(sourceBuffer.state == NVoxelBuffer.State.REFERENCE) {
sourceBuffer = sourceBuffer.referenceBuffer;
}
sourceBuffer;
}
MemInstrument.Report {
;
size_bytes += ;
(.state == NVoxelBuffer.State.ARRAY) {
size_bytes += .arrayContents.getMemoryUsage().size_bytes();
}
.Report(size_bytes);
}
{
.state == NVoxelBuffer.State.SINGLE_VALUE;
.state = NVoxelBuffer.State.ARRAY;
.arrayContents = <T>();
Arrays.fill(.arrayContents.array, .singleValue);
.singleValue = ;
}
{
.state == NVoxelBuffer.State.REFERENCE;
.state = .referenceBuffer.state;
(.state.ordinal()) {
:
.singleValue = .referenceBuffer.singleValue;
;
:
.arrayContents = <T>();
ArrayUtil.copy(.referenceBuffer.arrayContents.array, .arrayContents.array);
;
:
.referenceBuffer = .referenceBuffer.referenceBuffer;
;
:
;
}
}
{
position.y + position.x * SIZE.y + position.z * SIZE.y * SIZE.x;
}
{
bounds = (Vector3i.ZERO, SIZE);
}
<T> {
T[] array;
{
.array = (T[])( [NVoxelBuffer.SIZE.x * NVoxelBuffer.SIZE.y * NVoxelBuffer.SIZE.z]);
}
MemInstrument.Report {
+ * ().array.length;
.Report(size_bytes);
}
}
{
EMPTY,
SINGLE_VALUE,
ARRAY,
REFERENCE;
{
}
}
}