mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-11 02:06:21 +00:00
Mantle & Debugging
This commit is contained in:
@@ -61,6 +61,14 @@ public interface Hunk<T> {
|
||||
return new HunkView<T>(src);
|
||||
}
|
||||
|
||||
default boolean isMapped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default int getEntryCount() {
|
||||
return getWidth() * getHeight() * getDepth();
|
||||
}
|
||||
|
||||
static <A, B> Hunk<B> convertedReadView(Hunk<A> src, Function<A, B> reader) {
|
||||
return new FunctionalHunkView<A, B>(src, reader, null);
|
||||
}
|
||||
@@ -1059,6 +1067,45 @@ public interface Hunk<T> {
|
||||
setRaw(x, y, z, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a hunk that is optimized for specific uses
|
||||
* @param w width
|
||||
* @param h height
|
||||
* @param d depth
|
||||
* @param type the class type
|
||||
* @param packed if the hunk is generally more than 50% full (non-null nodes)
|
||||
* @param concurrent if this hunk must be thread safe
|
||||
* @param <T> the type
|
||||
* @return the hunk
|
||||
*/
|
||||
static <T> Hunk<T> newHunk(int w, int h, int d, Class<T> type, boolean packed, boolean concurrent)
|
||||
{
|
||||
if(type.equals(Double.class))
|
||||
{
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicDoubleHunk(w,h,d) : newMappedHunk(w,h,d)
|
||||
: packed ? newArrayHunk(w,h,d) : newMappedHunkSynced(w,h,d);
|
||||
}
|
||||
|
||||
if(type.equals(Integer.class))
|
||||
{
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicIntegerHunk(w,h,d) : newMappedHunk(w,h,d)
|
||||
: packed ? newArrayHunk(w,h,d) : newMappedHunkSynced(w,h,d);
|
||||
}
|
||||
|
||||
if(type.equals(Long.class))
|
||||
{
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicLongHunk(w,h,d) : newMappedHunk(w,h,d)
|
||||
: packed ? newArrayHunk(w,h,d) : newMappedHunkSynced(w,h,d);
|
||||
}
|
||||
|
||||
return concurrent ?
|
||||
packed ? newAtomicHunk(w,h,d) : newMappedHunk(w,h,d)
|
||||
: packed ? newArrayHunk(w,h,d) : newMappedHunkSynced(w,h,d);
|
||||
}
|
||||
|
||||
default void setIfExists(int x, int y, int z, T t) {
|
||||
if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight() || z < 0 || z >= getDepth()) {
|
||||
return;
|
||||
|
||||
24
src/main/java/com/volmit/iris/util/hunk/HunkFactory.java
Normal file
24
src/main/java/com/volmit/iris/util/hunk/HunkFactory.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.hunk;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface HunkFactory {
|
||||
<T> Hunk<T> create(int w, int h, int d);
|
||||
}
|
||||
@@ -20,6 +20,7 @@ package com.volmit.iris.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.hunk.HunkFactory;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ public class MappedHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
public boolean isMapped() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return data.isEmpty();
|
||||
|
||||
Reference in New Issue
Block a user