mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-06 07:46:08 +00:00
Cleanup
This commit is contained in:
@@ -78,8 +78,10 @@ public interface Hunk<T> {
|
||||
* Create a hunk view from a source hunk. This view reads and writes through to
|
||||
* the source hunk. Its is not a copy.
|
||||
*
|
||||
* @param <T> the type
|
||||
* @param src the source hunk
|
||||
* @param <T>
|
||||
* the type
|
||||
* @param src
|
||||
* the source hunk
|
||||
* @return the hunk view
|
||||
*/
|
||||
static <T> Hunk<T> view(Hunk<T> src) {
|
||||
@@ -197,9 +199,12 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Creates a new bounding hunk from the given hunks
|
||||
*
|
||||
* @param <T> the type
|
||||
* @param factory the factory that creates a hunk
|
||||
* @param hunks the hunks
|
||||
* @param <T>
|
||||
* the type
|
||||
* @param factory
|
||||
* the factory that creates a hunk
|
||||
* @param hunks
|
||||
* the hunks
|
||||
* @return the new bounding hunk
|
||||
*/
|
||||
@SafeVarargs
|
||||
@@ -208,7 +213,7 @@ public interface Hunk<T> {
|
||||
int h = 0;
|
||||
int d = 0;
|
||||
|
||||
for (Hunk<T> i : hunks) {
|
||||
for(Hunk<T> i : hunks) {
|
||||
w = Math.max(w, i.getWidth());
|
||||
h = Math.max(h, i.getHeight());
|
||||
d = Math.max(d, i.getDepth());
|
||||
@@ -216,7 +221,7 @@ public interface Hunk<T> {
|
||||
|
||||
Hunk<T> b = factory.apply(w, h, d);
|
||||
|
||||
for (Hunk<T> i : hunks) {
|
||||
for(Hunk<T> i : hunks) {
|
||||
b.insert(i);
|
||||
}
|
||||
|
||||
@@ -224,11 +229,11 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
static <A, B> void computeDual2D(int parallelism, Hunk<A> a, Hunk<B> b, Consumer5<Integer, Integer, Integer, Hunk<A>, Hunk<B>> v) {
|
||||
if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) {
|
||||
if(a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) {
|
||||
throw new RuntimeException("Hunk sizes must match!");
|
||||
}
|
||||
|
||||
if (a.get2DDimension(parallelism) == 1) {
|
||||
if(a.get2DDimension(parallelism) == 1) {
|
||||
v.accept(0, 0, 0, a, b);
|
||||
return;
|
||||
}
|
||||
@@ -239,7 +244,7 @@ public interface Hunk<T> {
|
||||
{
|
||||
v.accept(xx, yy, zz, ha, hr);
|
||||
|
||||
synchronized (rq) {
|
||||
synchronized(rq) {
|
||||
rq.add(r);
|
||||
}
|
||||
}), (x, y, z, hax, hbx) ->
|
||||
@@ -253,13 +258,13 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
static <A, B> void getDualSections2D(int sections, Hunk<A> a, Hunk<B> b, Consumer6<Integer, Integer, Integer, Hunk<A>, Hunk<B>, Runnable> v, Consumer5<Integer, Integer, Integer, Hunk<A>, Hunk<B>> inserterAB) {
|
||||
if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) {
|
||||
if(a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) {
|
||||
throw new RuntimeException("Hunk sizes must match!");
|
||||
}
|
||||
|
||||
int dim = a.get2DDimension(sections);
|
||||
|
||||
if (sections <= 1) {
|
||||
if(sections <= 1) {
|
||||
getDualSection(0, 0, 0, a.getWidth(), a.getHeight(), a.getDepth(), a, b, (ha, hr, r) -> v.accept(0, 0, 0, ha, hr, r), inserterAB);
|
||||
return;
|
||||
}
|
||||
@@ -270,10 +275,10 @@ public interface Hunk<T> {
|
||||
int dr = a.getDepth() - (d * dim);
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < a.getWidth(); i += w) {
|
||||
for(i = 0; i < a.getWidth(); i += w) {
|
||||
int ii = i;
|
||||
|
||||
for (j = 0; j < a.getDepth(); j += d) {
|
||||
for(j = 0; j < a.getDepth(); j += d) {
|
||||
int jj = j;
|
||||
getDualSection(i, 0, j, i + w + (i == 0 ? wr : 0), a.getHeight(), j + d + (j == 0 ? dr : 0), a, b, (ha, hr, r) -> v.accept(ii, 0, jj, ha, hr, r), inserterAB);
|
||||
i = i == 0 ? i + wr : i;
|
||||
@@ -291,37 +296,44 @@ public interface Hunk<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
|
||||
* @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)) {
|
||||
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);
|
||||
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)) {
|
||||
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);
|
||||
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)) {
|
||||
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);
|
||||
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);
|
||||
packed ? newAtomicHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z) {
|
||||
@@ -359,15 +371,15 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
static void rotate(double x, double y, double z, int[] c) {
|
||||
if (x % 360 != 0) {
|
||||
if(x % 360 != 0) {
|
||||
rotateAroundX(Math.toRadians(x), c);
|
||||
}
|
||||
|
||||
if (y % 360 != 0) {
|
||||
if(y % 360 != 0) {
|
||||
rotateAroundY(Math.toRadians(y), c);
|
||||
}
|
||||
|
||||
if (z % 360 != 0) {
|
||||
if(z % 360 != 0) {
|
||||
rotateAroundZ(Math.toRadians(z), c);
|
||||
}
|
||||
}
|
||||
@@ -469,14 +481,14 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default int filterDimension(int dim) {
|
||||
if (dim <= 1) {
|
||||
if(dim <= 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
dim = dim % 2 != 0 ? dim + 1 : dim;
|
||||
|
||||
if (dim > getMinimumDimension() / 2) {
|
||||
if (dim <= 2) {
|
||||
if(dim > getMinimumDimension() / 2) {
|
||||
if(dim <= 2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -487,7 +499,7 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default int get2DDimension(int sections) {
|
||||
if (sections <= 1) {
|
||||
if(sections <= 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -495,7 +507,7 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default int get3DDimension(int sections) {
|
||||
if (sections <= 1) {
|
||||
if(sections <= 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -556,8 +568,10 @@ public interface Hunk<T> {
|
||||
* hunk.set(hunkX, ?, hunkZ, noise(actualBlockX, ?, actualBlockZ));<br>
|
||||
* }<br>
|
||||
*
|
||||
* @param p the predicate
|
||||
* @param c the consumer
|
||||
* @param p
|
||||
* the predicate
|
||||
* @param c
|
||||
* the consumer
|
||||
* @return this
|
||||
*/
|
||||
default Hunk<T> iterateSurfaces2D(Predicate<T> p, Consumer8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Hunk<T>> c) {
|
||||
@@ -618,9 +632,12 @@ public interface Hunk<T> {
|
||||
* hunk.set(hunkX, ?, hunkZ, noise(actualBlockX, ?, actualBlockZ));<br>
|
||||
* }<br>
|
||||
*
|
||||
* @param parallelism the ideal threads to use on this
|
||||
* @param p the predicate
|
||||
* @param c the consumer
|
||||
* @param parallelism
|
||||
* the ideal threads to use on this
|
||||
* @param p
|
||||
* the predicate
|
||||
* @param c
|
||||
* the consumer
|
||||
* @return this
|
||||
*/
|
||||
default Hunk<T> iterateSurfaces2D(int parallelism, Predicate<T> p, Consumer8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Hunk<T>> c) {
|
||||
@@ -629,20 +646,20 @@ public interface Hunk<T> {
|
||||
int last = -1;
|
||||
int in = getHeight() - 1;
|
||||
boolean hitting = false;
|
||||
for (int i = getHeight() - 1; i >= 0; i--) {
|
||||
for(int i = getHeight() - 1; i >= 0; i--) {
|
||||
boolean solid = p.test(h.get(ax, i, az));
|
||||
|
||||
if (!hitting && solid) {
|
||||
if(!hitting && solid) {
|
||||
in = i;
|
||||
hitting = true;
|
||||
} else if (hitting && !solid) {
|
||||
} else if(hitting && !solid) {
|
||||
hitting = false;
|
||||
c.accept(ax, az, hox, hoz, in, i - 1, last, h);
|
||||
last = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (hitting) {
|
||||
if(hitting) {
|
||||
c.accept(ax, az, hox, hoz, in, 0, last, h);
|
||||
}
|
||||
});
|
||||
@@ -657,7 +674,8 @@ public interface Hunk<T> {
|
||||
* <p>
|
||||
* hunk.set(ax, ?, az, NOISE.get(ax+hx, az+hz));
|
||||
*
|
||||
* @param c the consumer hunkX, hunkZ, hunkOffsetX, hunkOffsetZ.
|
||||
* @param c
|
||||
* the consumer hunkX, hunkZ, hunkOffsetX, hunkOffsetZ.
|
||||
* @return this
|
||||
*/
|
||||
default Hunk<T> iterate2DTop(Consumer5<Integer, Integer, Integer, Integer, Hunk<T>> c) {
|
||||
@@ -675,15 +693,17 @@ public interface Hunk<T> {
|
||||
* <p>
|
||||
* hunk.set(ax, ?, az, NOISE.get(ax+hx, az+hz));
|
||||
*
|
||||
* @param parallelism the target parallelism value or 0 to disable
|
||||
* @param c the consumer hunkX, hunkZ, hunkOffsetX, hunkOffsetZ.
|
||||
* @param parallelism
|
||||
* the target parallelism value or 0 to disable
|
||||
* @param c
|
||||
* the consumer hunkX, hunkZ, hunkOffsetX, hunkOffsetZ.
|
||||
* @return this
|
||||
*/
|
||||
default Hunk<T> iterate2DTop(int parallelism, Consumer5<Integer, Integer, Integer, Integer, Hunk<T>> c) {
|
||||
compute2D(parallelism, (x, y, z, h) ->
|
||||
{
|
||||
for (int i = 0; i < h.getWidth(); i++) {
|
||||
for (int k = 0; k < h.getDepth(); k++) {
|
||||
for(int i = 0; i < h.getWidth(); i++) {
|
||||
for(int k = 0; k < h.getDepth(); k++) {
|
||||
c.accept(i, k, x, z, h);
|
||||
}
|
||||
}
|
||||
@@ -699,7 +719,7 @@ public interface Hunk<T> {
|
||||
default Hunk<T> iterate(int parallelism, Predicate<T> p, Consumer3<Integer, Integer, Integer> c) {
|
||||
iterate(parallelism, (x, y, z, t) ->
|
||||
{
|
||||
if (p.test(t)) {
|
||||
if(p.test(t)) {
|
||||
c.accept(x, y, z);
|
||||
}
|
||||
});
|
||||
@@ -714,7 +734,7 @@ public interface Hunk<T> {
|
||||
default Hunk<T> iterate(int parallelism, Predicate<T> p, Consumer4<Integer, Integer, Integer, T> c) {
|
||||
iterate(parallelism, (x, y, z, t) ->
|
||||
{
|
||||
if (p.test(t)) {
|
||||
if(p.test(t)) {
|
||||
c.accept(x, y, z, t);
|
||||
}
|
||||
});
|
||||
@@ -727,9 +747,9 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default Hunk<T> iterateSync(Consumer3<Integer, Integer, Integer> c) {
|
||||
for (int i = 0; i < getWidth(); i++) {
|
||||
for (int j = 0; j < getHeight(); j++) {
|
||||
for (int k = 0; k < getDepth(); k++) {
|
||||
for(int i = 0; i < getWidth(); i++) {
|
||||
for(int j = 0; j < getHeight(); j++) {
|
||||
for(int k = 0; k < getDepth(); k++) {
|
||||
c.accept(i, j, k);
|
||||
}
|
||||
}
|
||||
@@ -739,9 +759,9 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
|
||||
for (int i = 0; i < getWidth(); i++) {
|
||||
for (int j = 0; j < getHeight(); j++) {
|
||||
for (int k = 0; k < getDepth(); k++) {
|
||||
for(int i = 0; i < getWidth(); i++) {
|
||||
for(int j = 0; j < getHeight(); j++) {
|
||||
for(int k = 0; k < getDepth(); k++) {
|
||||
c.accept(i, j, k, get(i, j, k));
|
||||
}
|
||||
}
|
||||
@@ -751,9 +771,9 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default Hunk<T> updateSync(Function4<Integer, Integer, Integer, T, T> c) {
|
||||
for (int i = 0; i < getWidth(); i++) {
|
||||
for (int j = 0; j < getHeight(); j++) {
|
||||
for (int k = 0; k < getDepth(); k++) {
|
||||
for(int i = 0; i < getWidth(); i++) {
|
||||
for(int j = 0; j < getHeight(); j++) {
|
||||
for(int k = 0; k < getDepth(); k++) {
|
||||
set(i, j, k, c.apply(i, j, k, get(i, j, k)));
|
||||
}
|
||||
}
|
||||
@@ -763,9 +783,9 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default Hunk<T> iterateSyncIO(Consumer4IO<Integer, Integer, Integer, T> c) throws IOException {
|
||||
for (int i = 0; i < getWidth(); i++) {
|
||||
for (int j = 0; j < getHeight(); j++) {
|
||||
for (int k = 0; k < getDepth(); k++) {
|
||||
for(int i = 0; i < getWidth(); i++) {
|
||||
for(int j = 0; j < getHeight(); j++) {
|
||||
for(int k = 0; k < getDepth(); k++) {
|
||||
c.accept(i, j, k, get(i, j, k));
|
||||
}
|
||||
}
|
||||
@@ -777,9 +797,9 @@ public interface Hunk<T> {
|
||||
default Hunk<T> iterate(int parallelism, Consumer3<Integer, Integer, Integer> c) {
|
||||
compute3D(parallelism, (x, y, z, h) ->
|
||||
{
|
||||
for (int i = 0; i < h.getWidth(); i++) {
|
||||
for (int j = 0; j < h.getHeight(); j++) {
|
||||
for (int k = 0; k < h.getDepth(); k++) {
|
||||
for(int i = 0; i < h.getWidth(); i++) {
|
||||
for(int j = 0; j < h.getHeight(); j++) {
|
||||
for(int k = 0; k < h.getDepth(); k++) {
|
||||
c.accept(i + x, j + y, k + z);
|
||||
}
|
||||
}
|
||||
@@ -796,9 +816,9 @@ public interface Hunk<T> {
|
||||
default Hunk<T> iterate(int parallelism, Consumer4<Integer, Integer, Integer, T> c) {
|
||||
compute3D(parallelism, (x, y, z, h) ->
|
||||
{
|
||||
for (int i = 0; i < h.getWidth(); i++) {
|
||||
for (int j = 0; j < h.getHeight(); j++) {
|
||||
for (int k = 0; k < h.getDepth(); k++) {
|
||||
for(int i = 0; i < h.getWidth(); i++) {
|
||||
for(int j = 0; j < h.getHeight(); j++) {
|
||||
for(int k = 0; k < h.getDepth(); k++) {
|
||||
c.accept(i + x, j + y, k + z, h.get(i, j, k));
|
||||
}
|
||||
}
|
||||
@@ -813,14 +833,14 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default Hunk<T> compute2D(int parallelism, Consumer4<Integer, Integer, Integer, Hunk<T>> v) {
|
||||
if (get2DDimension(parallelism) == 1) {
|
||||
if(get2DDimension(parallelism) == 1) {
|
||||
v.accept(0, 0, 0, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
BurstExecutor e = MultiBurst.burst.burst(parallelism);
|
||||
|
||||
if (isAtomic()) {
|
||||
if(isAtomic()) {
|
||||
getSectionsAtomic2D(parallelism, (xx, yy, zz, h) -> e.queue(() ->
|
||||
{
|
||||
v.accept(xx, yy, zz, h);
|
||||
@@ -834,7 +854,7 @@ public interface Hunk<T> {
|
||||
{
|
||||
v.accept(xx, yy, zz, h);
|
||||
|
||||
synchronized (rq) {
|
||||
synchronized(rq) {
|
||||
rq.add(r);
|
||||
}
|
||||
}), this::insert);
|
||||
@@ -847,7 +867,7 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default Hunk<T> compute2DYRange(int parallelism, int ymin, int ymax, Consumer4<Integer, Integer, Integer, Hunk<T>> v) {
|
||||
if (get2DDimension(parallelism) == 1) {
|
||||
if(get2DDimension(parallelism) == 1) {
|
||||
v.accept(0, 0, 0, this);
|
||||
return this;
|
||||
}
|
||||
@@ -858,7 +878,7 @@ public interface Hunk<T> {
|
||||
{
|
||||
v.accept(xx, yy, zz, h);
|
||||
|
||||
synchronized (rq) {
|
||||
synchronized(rq) {
|
||||
rq.add(r);
|
||||
}
|
||||
}), this::insert);
|
||||
@@ -872,7 +892,7 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default Hunk<T> compute3D(int parallelism, Consumer4<Integer, Integer, Integer, Hunk<T>> v) {
|
||||
if (get3DDimension(parallelism) == 1) {
|
||||
if(get3DDimension(parallelism) == 1) {
|
||||
v.accept(0, 0, 0, this);
|
||||
return this;
|
||||
}
|
||||
@@ -882,7 +902,7 @@ public interface Hunk<T> {
|
||||
getSections3D(parallelism, (xx, yy, zz, h, r) -> e.queue(() ->
|
||||
{
|
||||
v.accept(xx, yy, zz, h);
|
||||
synchronized (rq) {
|
||||
synchronized(rq) {
|
||||
rq.add(r);
|
||||
}
|
||||
}), this::insert);
|
||||
@@ -898,7 +918,7 @@ public interface Hunk<T> {
|
||||
default Hunk<T> getSectionsAtomic2D(int sections, Consumer4<Integer, Integer, Integer, Hunk<T>> v) {
|
||||
int dim = get2DDimension(sections);
|
||||
|
||||
if (sections <= 1) {
|
||||
if(sections <= 1) {
|
||||
getAtomicSection(0, 0, 0, getWidth(), getHeight(), getDepth(), (hh) -> v.accept(0, 0, 0, hh));
|
||||
return this;
|
||||
}
|
||||
@@ -909,10 +929,10 @@ public interface Hunk<T> {
|
||||
int dr = getDepth() - (d * dim);
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < getWidth(); i += w) {
|
||||
for(i = 0; i < getWidth(); i += w) {
|
||||
int ii = i;
|
||||
|
||||
for (j = 0; j < getDepth(); j += d) {
|
||||
for(j = 0; j < getDepth(); j += d) {
|
||||
int jj = j;
|
||||
getAtomicSection(i, 0, j, i + w + (i == 0 ? wr : 0), getHeight(), j + d + (j == 0 ? dr : 0), (h) -> v.accept(ii, 0, jj, h));
|
||||
i = i == 0 ? i + wr : i;
|
||||
@@ -926,7 +946,7 @@ public interface Hunk<T> {
|
||||
default Hunk<T> getSections2D(int sections, Consumer5<Integer, Integer, Integer, Hunk<T>, Runnable> v, Consumer4<Integer, Integer, Integer, Hunk<T>> inserter) {
|
||||
int dim = get2DDimension(sections);
|
||||
|
||||
if (sections <= 1) {
|
||||
if(sections <= 1) {
|
||||
getSection(0, 0, 0, getWidth(), getHeight(), getDepth(), (hh, r) -> v.accept(0, 0, 0, hh, r), inserter);
|
||||
return this;
|
||||
}
|
||||
@@ -937,10 +957,10 @@ public interface Hunk<T> {
|
||||
int dr = getDepth() - (d * dim);
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < getWidth(); i += w) {
|
||||
for(i = 0; i < getWidth(); i += w) {
|
||||
int ii = i;
|
||||
|
||||
for (j = 0; j < getDepth(); j += d) {
|
||||
for(j = 0; j < getDepth(); j += d) {
|
||||
int jj = j;
|
||||
getSection(i, 0, j, i + w + (i == 0 ? wr : 0), getHeight(), j + d + (j == 0 ? dr : 0), (h, r) -> v.accept(ii, 0, jj, h, r), inserter);
|
||||
i = i == 0 ? i + wr : i;
|
||||
@@ -954,7 +974,7 @@ public interface Hunk<T> {
|
||||
default Hunk<T> getSections2DYLimit(int sections, int ymin, int ymax, Consumer5<Integer, Integer, Integer, Hunk<T>, Runnable> v, Consumer4<Integer, Integer, Integer, Hunk<T>> inserter) {
|
||||
int dim = get2DDimension(sections);
|
||||
|
||||
if (sections <= 1) {
|
||||
if(sections <= 1) {
|
||||
getSection(0, 0, 0, getWidth(), getHeight(), getDepth(), (hh, r) -> v.accept(0, 0, 0, hh, r), inserter);
|
||||
return this;
|
||||
}
|
||||
@@ -965,10 +985,10 @@ public interface Hunk<T> {
|
||||
int dr = getDepth() - (d * dim);
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < getWidth(); i += w) {
|
||||
for(i = 0; i < getWidth(); i += w) {
|
||||
int ii = i;
|
||||
|
||||
for (j = 0; j < getDepth(); j += d) {
|
||||
for(j = 0; j < getDepth(); j += d) {
|
||||
int jj = j;
|
||||
getSection(i, ymin, j, i + w + (i == 0 ? wr : 0), ymax, j + d + (j == 0 ? dr : 0), (h, r) -> v.accept(ii, ymin, jj, h, r), inserter);
|
||||
i = i == 0 ? i + wr : i;
|
||||
@@ -986,7 +1006,7 @@ public interface Hunk<T> {
|
||||
default Hunk<T> getSections3D(int sections, Consumer5<Integer, Integer, Integer, Hunk<T>, Runnable> v, Consumer4<Integer, Integer, Integer, Hunk<T>> inserter) {
|
||||
int dim = get3DDimension(sections);
|
||||
|
||||
if (sections <= 1) {
|
||||
if(sections <= 1) {
|
||||
getSection(0, 0, 0, getWidth(), getHeight(), getDepth(), (hh, r) -> v.accept(0, 0, 0, hh, r), inserter);
|
||||
return this;
|
||||
}
|
||||
@@ -999,13 +1019,13 @@ public interface Hunk<T> {
|
||||
int dr = getDepth() - (d * dim);
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < getWidth(); i += w) {
|
||||
for(i = 0; i < getWidth(); i += w) {
|
||||
int ii = i;
|
||||
|
||||
for (j = 0; j < getHeight(); j += d) {
|
||||
for(j = 0; j < getHeight(); j += d) {
|
||||
int jj = j;
|
||||
|
||||
for (k = 0; k < getDepth(); k += d) {
|
||||
for(k = 0; k < getDepth(); k += d) {
|
||||
int kk = k;
|
||||
getSection(ii, jj, kk, i + w + (i == 0 ? wr : 0), j + h + (j == 0 ? hr : 0), k + d + (k == 0 ? dr : 0), (hh, r) -> v.accept(ii, jj, kk, hh, r), inserter);
|
||||
i = i == 0 ? i + wr : i;
|
||||
@@ -1037,20 +1057,26 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Create a new hunk from a section of this hunk.
|
||||
*
|
||||
* @param x1 The min x (inclusive)
|
||||
* @param y1 The min y (inclusive)
|
||||
* @param z1 The min z (inclusive)
|
||||
* @param x2 The max x (exclusive)
|
||||
* @param y2 The max y (exclusive)
|
||||
* @param z2 The max z (exclusive)
|
||||
* @param x1
|
||||
* The min x (inclusive)
|
||||
* @param y1
|
||||
* The min y (inclusive)
|
||||
* @param z1
|
||||
* The min z (inclusive)
|
||||
* @param x2
|
||||
* The max x (exclusive)
|
||||
* @param y2
|
||||
* The max y (exclusive)
|
||||
* @param z2
|
||||
* The max z (exclusive)
|
||||
* @return the new hunk (x2-x1, y2-y1, z2-z1)
|
||||
*/
|
||||
default ArrayHunk<T> crop(int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
ArrayHunk<T> h = new ArrayHunk<T>(x2 - x1, y2 - y1, z2 - z1);
|
||||
|
||||
for (int i = x1; i < x2; i++) {
|
||||
for (int j = y1; j < y2; j++) {
|
||||
for (int k = z1; k < z2; k++) {
|
||||
for(int i = x1; i < x2; i++) {
|
||||
for(int j = y1; j < y2; j++) {
|
||||
for(int k = z1; k < z2; k++) {
|
||||
h.setRaw(i - x1, j - y1, k - z1, getRaw(i, j, k));
|
||||
}
|
||||
}
|
||||
@@ -1063,12 +1089,18 @@ public interface Hunk<T> {
|
||||
* Create a new view of this same hunk from a section of this hunk.
|
||||
* Modifications are routed to this hunk!
|
||||
*
|
||||
* @param x1 The min x (inclusive)
|
||||
* @param y1 The min y (inclusive)
|
||||
* @param z1 The min z (inclusive)
|
||||
* @param x2 The max x (exclusive)
|
||||
* @param y2 The max y (exclusive)
|
||||
* @param z2 The max z (exclusive)
|
||||
* @param x1
|
||||
* The min x (inclusive)
|
||||
* @param y1
|
||||
* The min y (inclusive)
|
||||
* @param z1
|
||||
* The min z (inclusive)
|
||||
* @param x2
|
||||
* The max x (exclusive)
|
||||
* @param y2
|
||||
* The max y (exclusive)
|
||||
* @param z2
|
||||
* The max z (exclusive)
|
||||
* @return the cropped view of this hunk (x2-x1, y2-y1, z2-z1)
|
||||
*/
|
||||
default Hunk<T> croppedView(int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
@@ -1093,18 +1125,25 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Set a region
|
||||
*
|
||||
* @param x1 inclusive 1st x
|
||||
* @param y1 inclusive 1st y
|
||||
* @param z1 inclusive 1st z
|
||||
* @param x2 inclusive 2nd x
|
||||
* @param y2 inclusive 2nd y
|
||||
* @param z2 inclusive 2nd z
|
||||
* @param t the value to set
|
||||
* @param x1
|
||||
* inclusive 1st x
|
||||
* @param y1
|
||||
* inclusive 1st y
|
||||
* @param z1
|
||||
* inclusive 1st z
|
||||
* @param x2
|
||||
* inclusive 2nd x
|
||||
* @param y2
|
||||
* inclusive 2nd y
|
||||
* @param z2
|
||||
* inclusive 2nd z
|
||||
* @param t
|
||||
* the value to set
|
||||
*/
|
||||
default void set(int x1, int y1, int z1, int x2, int y2, int z2, T t) {
|
||||
for (int i = x1; i <= x2; i++) {
|
||||
for (int j = y1; j <= y2; j++) {
|
||||
for (int k = z1; k <= z2; k++) {
|
||||
for(int i = x1; i <= x2; i++) {
|
||||
for(int j = y1; j <= y2; j++) {
|
||||
for(int k = z1; k <= z2; k++) {
|
||||
setRaw(i, j, k, t);
|
||||
}
|
||||
}
|
||||
@@ -1114,9 +1153,12 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Get the value to the closest valid position
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @return the value closest to the border of the hunk
|
||||
*/
|
||||
default T getClosest(int x, int y, int z) {
|
||||
@@ -1146,11 +1188,12 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Get a 1 node thick hunk representing the face of this hunk
|
||||
*
|
||||
* @param f the face
|
||||
* @param f
|
||||
* the face
|
||||
* @return the hunk view of this hunk
|
||||
*/
|
||||
default Hunk<T> viewFace(HunkFace f) {
|
||||
switch (f) {
|
||||
switch(f) {
|
||||
case BOTTOM:
|
||||
return croppedView(0, 0, 0, getWidth() - 1, 0, getDepth() - 1);
|
||||
case EAST:
|
||||
@@ -1173,11 +1216,12 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Crop (copy) a 1 node thick hunk representing the face of this hunk
|
||||
*
|
||||
* @param f the face
|
||||
* @param f
|
||||
* the face
|
||||
* @return the hunk copy (face) of this hunk
|
||||
*/
|
||||
default Hunk<T> cropFace(HunkFace f) {
|
||||
switch (f) {
|
||||
switch(f) {
|
||||
case BOTTOM:
|
||||
return crop(0, 0, 0, getWidth() - 1, 0, getDepth() - 1);
|
||||
case EAST:
|
||||
@@ -1200,17 +1244,21 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Set a value at the given position
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @param t the value
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @param t
|
||||
* the value
|
||||
*/
|
||||
default void set(int x, int y, int z, T t) {
|
||||
setRaw(x, y, z, t);
|
||||
}
|
||||
|
||||
default void setIfExists(int x, int y, int z, T t) {
|
||||
if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight() || z < 0 || z >= getDepth()) {
|
||||
if(x < 0 || x >= getWidth() || y < 0 || y >= getHeight() || z < 0 || z >= getDepth()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1218,7 +1266,7 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
default T getIfExists(int x, int y, int z, T t) {
|
||||
if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight() || z < 0 || z >= getDepth()) {
|
||||
if(x < 0 || x >= getWidth() || y < 0 || y >= getHeight() || z < 0 || z >= getDepth()) {
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -1232,19 +1280,26 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Set a value at the given position without checking coordinate bounds
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @param t the value
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @param t
|
||||
* the value
|
||||
*/
|
||||
void setRaw(int x, int y, int z, T t);
|
||||
|
||||
/**
|
||||
* Get a value at the given position without checking coordinate bounds
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @return the value or null
|
||||
*/
|
||||
T getRaw(int x, int y, int z);
|
||||
@@ -1252,9 +1307,12 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Get a value at the given position
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param z the z
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @return the value or null
|
||||
*/
|
||||
default T get(int x, int y, int z) {
|
||||
@@ -1264,7 +1322,7 @@ public interface Hunk<T> {
|
||||
default T getOr(int x, int y, int z, T t) {
|
||||
T v = getRaw(x, y, z);
|
||||
|
||||
if (v == null) {
|
||||
if(v == null) {
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -1274,10 +1332,14 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Insert a hunk into this one with an offset the inserted hunk
|
||||
*
|
||||
* @param offX the offset from zero for x
|
||||
* @param offY the offset from zero for y
|
||||
* @param offZ the offset from zero for z
|
||||
* @param hunk the hunk to insert
|
||||
* @param offX
|
||||
* the offset from zero for x
|
||||
* @param offY
|
||||
* the offset from zero for y
|
||||
* @param offZ
|
||||
* the offset from zero for z
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
*/
|
||||
default void insert(int offX, int offY, int offZ, Hunk<T> hunk) {
|
||||
insert(offX, offY, offZ, hunk, false);
|
||||
@@ -1290,7 +1352,8 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Insert a hunk into this one
|
||||
*
|
||||
* @param hunk the hunk to insert
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
*/
|
||||
default void insert(Hunk<T> hunk) {
|
||||
insert(0, 0, 0, hunk, false);
|
||||
@@ -1310,8 +1373,10 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Insert a hunk into this one
|
||||
*
|
||||
* @param hunk the hunk to insert
|
||||
* @param inverted invert the inserted hunk or not
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
* @param inverted
|
||||
* invert the inserted hunk or not
|
||||
*/
|
||||
default void insert(Hunk<T> hunk, boolean inverted) {
|
||||
insert(0, 0, 0, hunk, inverted);
|
||||
@@ -1321,16 +1386,21 @@ public interface Hunk<T> {
|
||||
* Insert a hunk into this one with an offset and possibly inverting the y of
|
||||
* the inserted hunk
|
||||
*
|
||||
* @param offX the offset from zero for x
|
||||
* @param offY the offset from zero for y
|
||||
* @param offZ the offset from zero for z
|
||||
* @param hunk the hunk to insert
|
||||
* @param invertY should the inserted hunk be inverted
|
||||
* @param offX
|
||||
* the offset from zero for x
|
||||
* @param offY
|
||||
* the offset from zero for y
|
||||
* @param offZ
|
||||
* the offset from zero for z
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
* @param invertY
|
||||
* should the inserted hunk be inverted
|
||||
*/
|
||||
default void insert(int offX, int offY, int offZ, Hunk<T> hunk, boolean invertY) {
|
||||
for (int i = offX; i < offX + hunk.getWidth(); i++) {
|
||||
for (int j = offY; j < offY + hunk.getHeight(); j++) {
|
||||
for (int k = offZ; k < offZ + hunk.getDepth(); k++) {
|
||||
for(int i = offX; i < offX + hunk.getWidth(); i++) {
|
||||
for(int j = offY; j < offY + hunk.getHeight(); j++) {
|
||||
for(int k = offZ; k < offZ + hunk.getDepth(); k++) {
|
||||
setRaw(i, j, k, hunk.getRaw(i - offX, j - offY, k - offZ));
|
||||
}
|
||||
}
|
||||
@@ -1338,20 +1408,26 @@ public interface Hunk<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a hunk into this one with an offset and possibly inverting the y of. Will never insert a node if its already used
|
||||
* Insert a hunk into this one with an offset and possibly inverting the y of. Will never insert a node if its
|
||||
* already used
|
||||
* the inserted hunk
|
||||
*
|
||||
* @param offX the offset from zero for x
|
||||
* @param offY the offset from zero for y
|
||||
* @param offZ the offset from zero for z
|
||||
* @param hunk the hunk to insert
|
||||
* @param invertY should the inserted hunk be inverted
|
||||
* @param offX
|
||||
* the offset from zero for x
|
||||
* @param offY
|
||||
* the offset from zero for y
|
||||
* @param offZ
|
||||
* the offset from zero for z
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
* @param invertY
|
||||
* should the inserted hunk be inverted
|
||||
*/
|
||||
default void insertSoftly(int offX, int offY, int offZ, Hunk<T> hunk, boolean invertY, Predicate<T> shouldOverwrite) {
|
||||
for (int i = offX; i < offX + hunk.getWidth(); i++) {
|
||||
for (int j = offY; j < offY + hunk.getHeight(); j++) {
|
||||
for (int k = offZ; k < offZ + hunk.getDepth(); k++) {
|
||||
if (shouldOverwrite.test(getRaw(i, j, k))) {
|
||||
for(int i = offX; i < offX + hunk.getWidth(); i++) {
|
||||
for(int j = offY; j < offY + hunk.getHeight(); j++) {
|
||||
for(int k = offZ; k < offZ + hunk.getDepth(); k++) {
|
||||
if(shouldOverwrite.test(getRaw(i, j, k))) {
|
||||
setRaw(i, j, k, hunk.getRaw(i - offX, j - offY, k - offZ));
|
||||
}
|
||||
}
|
||||
@@ -1362,7 +1438,8 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Acts like fill, however if used by a mapped hunk, will simply clear it
|
||||
*
|
||||
* @param b the data to use for fill
|
||||
* @param b
|
||||
* the data to use for fill
|
||||
*/
|
||||
default void empty(T b) {
|
||||
fill(b);
|
||||
@@ -1371,21 +1448,24 @@ public interface Hunk<T> {
|
||||
/**
|
||||
* Take a hunk and scale it up using interpolation
|
||||
*
|
||||
* @param scale the scale
|
||||
* @param d the interpolation method
|
||||
* @param interpolated the interpolated value converter
|
||||
* @param scale
|
||||
* the scale
|
||||
* @param d
|
||||
* the interpolation method
|
||||
* @param interpolated
|
||||
* the interpolated value converter
|
||||
* @return the new hunk
|
||||
*/
|
||||
default Hunk<T> interpolate3D(double scale, InterpolationMethod3D d, Interpolated<T> interpolated) {
|
||||
Hunk<T> t = Hunk.newArrayHunk((int) (getWidth() * scale), (int) (getHeight() * scale), (int) (getDepth() * scale));
|
||||
NoiseProvider3 n3 = (x, y, z) -> interpolated.toDouble(
|
||||
t.get((int) (x / scale),
|
||||
(int) (y / scale),
|
||||
(int) (z / scale)));
|
||||
t.get((int) (x / scale),
|
||||
(int) (y / scale),
|
||||
(int) (z / scale)));
|
||||
|
||||
for (int i = 0; i < t.getWidth(); i++) {
|
||||
for (int j = 0; j < t.getHeight(); j++) {
|
||||
for (int k = 0; k < t.getDepth(); k++) {
|
||||
for(int i = 0; i < t.getWidth(); i++) {
|
||||
for(int j = 0; j < t.getHeight(); j++) {
|
||||
for(int k = 0; k < t.getDepth(); k++) {
|
||||
t.set(i, j, k, interpolated.fromDouble(IrisInterpolation.getNoise3D(d, i, j, k, scale, n3)));
|
||||
}
|
||||
}
|
||||
@@ -1398,20 +1478,23 @@ public interface Hunk<T> {
|
||||
* Take a hunk and scale it up using interpolation
|
||||
* 2D, (using only x and z) assumes the height is 1
|
||||
*
|
||||
* @param scale the scale
|
||||
* @param d the interpolation method
|
||||
* @param interpolated the interpolated value converter
|
||||
* @param scale
|
||||
* the scale
|
||||
* @param d
|
||||
* the interpolation method
|
||||
* @param interpolated
|
||||
* the interpolated value converter
|
||||
* @return the new hunk
|
||||
*/
|
||||
default Hunk<T> interpolate2D(double scale, InterpolationMethod d, Interpolated<T> interpolated) {
|
||||
Hunk<T> t = Hunk.newArrayHunk((int) (getWidth() * scale), 1, (int) (getDepth() * scale));
|
||||
NoiseProvider n2 = (x, z) -> interpolated.toDouble(
|
||||
t.get((int) (x / scale),
|
||||
0,
|
||||
(int) (z / scale)));
|
||||
t.get((int) (x / scale),
|
||||
0,
|
||||
(int) (z / scale)));
|
||||
|
||||
for (int i = 0; i < t.getWidth(); i++) {
|
||||
for (int j = 0; j < t.getDepth(); j++) {
|
||||
for(int i = 0; i < t.getWidth(); i++) {
|
||||
for(int j = 0; j < t.getDepth(); j++) {
|
||||
t.set(i, 0, j, interpolated.fromDouble(IrisInterpolation.getNoise(d, i, j, scale, n2)));
|
||||
}
|
||||
}
|
||||
@@ -1451,9 +1534,9 @@ public interface Hunk<T> {
|
||||
Hunk<T> r = builder.get(maxX - minX, maxY - minY, maxZ - minZ);
|
||||
int[] cr = {(maxX - minX) / 2, (maxY - minY) / 2, (maxZ - minZ) / 2};
|
||||
|
||||
for (i = 0; i < w; i++) {
|
||||
for (j = 0; j < h; j++) {
|
||||
for (k = 0; k < d; k++) {
|
||||
for(i = 0; i < w; i++) {
|
||||
for(j = 0; j < h; j++) {
|
||||
for(k = 0; k < d; k++) {
|
||||
b[0] = i - c[0];
|
||||
b[1] = j - c[1];
|
||||
b[2] = k - c[2];
|
||||
@@ -1461,7 +1544,7 @@ public interface Hunk<T> {
|
||||
|
||||
try {
|
||||
r.set(b[0] + cr[0], b[1] + cr[1], b[2] + cr[2], get(i, j, k));
|
||||
} catch (Throwable e) {
|
||||
} catch(Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.util.hunk.bits;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
@@ -30,27 +29,27 @@ import java.util.concurrent.atomic.AtomicLongArray;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public class DataBits {
|
||||
private static final int[] MAGIC = new int[]{
|
||||
-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE,
|
||||
0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756,
|
||||
0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0,
|
||||
390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378,
|
||||
306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 0, 3, 252645135, 252645135,
|
||||
0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0,
|
||||
204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970,
|
||||
178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862,
|
||||
0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0,
|
||||
138547332, 138547332, 0, Integer.MIN_VALUE, 0, 4, 130150524, 130150524, 0, 126322567,
|
||||
126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197,
|
||||
0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0,
|
||||
104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893,
|
||||
97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282,
|
||||
0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0,
|
||||
84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431,
|
||||
79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303,
|
||||
0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0,
|
||||
70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, Integer.MIN_VALUE,
|
||||
0, 5};
|
||||
private static final int[] MAGIC = new int[] {
|
||||
-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE,
|
||||
0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756,
|
||||
0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0,
|
||||
390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378,
|
||||
306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 0, 3, 252645135, 252645135,
|
||||
0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0,
|
||||
204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970,
|
||||
178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862,
|
||||
0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0,
|
||||
138547332, 138547332, 0, Integer.MIN_VALUE, 0, 4, 130150524, 130150524, 0, 126322567,
|
||||
126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197,
|
||||
0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0,
|
||||
104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893,
|
||||
97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282,
|
||||
0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0,
|
||||
84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431,
|
||||
79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303,
|
||||
0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0,
|
||||
70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, Integer.MIN_VALUE,
|
||||
0, 5};
|
||||
|
||||
private final AtomicLongArray data;
|
||||
private final int bits;
|
||||
@@ -81,8 +80,8 @@ public class DataBits {
|
||||
this.divideShift = MAGIC[var3 + 2];
|
||||
int var4 = (length + valuesPerLong - 1) / valuesPerLong;
|
||||
|
||||
if (data != null) {
|
||||
if (data.length() != var4) {
|
||||
if(data != null) {
|
||||
if(data.length() != var4) {
|
||||
throw new RuntimeException("NO! Trying to load " + data.length() + " into actual size of " + var4 + " because length: " + length + " (bits: " + bits + ")");
|
||||
}
|
||||
this.data = data;
|
||||
@@ -102,7 +101,7 @@ public class DataBits {
|
||||
private static AtomicLongArray longs(DataInputStream din, int longSize) throws IOException {
|
||||
AtomicLongArray a = new AtomicLongArray(longSize);
|
||||
|
||||
for (int i = 0; i < a.length(); i++) {
|
||||
for(int i = 0; i < a.length(); i++) {
|
||||
a.set(i, Varint.readUnsignedVarLong(din));
|
||||
}
|
||||
|
||||
@@ -110,11 +109,11 @@ public class DataBits {
|
||||
}
|
||||
|
||||
public DataBits setBits(int newBits) {
|
||||
if (bits != newBits) {
|
||||
if(bits != newBits) {
|
||||
DataBits newData = new DataBits(newBits, size);
|
||||
AtomicInteger c = new AtomicInteger(0);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
for(int i = 0; i < size; i++) {
|
||||
newData.set(i, get(i));
|
||||
}
|
||||
|
||||
@@ -175,12 +174,12 @@ public class DataBits {
|
||||
|
||||
public void getAll(IntConsumer var0) {
|
||||
int var1 = 0;
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
for(int i = 0; i < data.length(); i++) {
|
||||
long var5 = data.get(i);
|
||||
for (int var7 = 0; var7 < valuesPerLong; var7++) {
|
||||
for(int var7 = 0; var7 < valuesPerLong; var7++) {
|
||||
var0.accept((int) (var5 & mask));
|
||||
var5 >>= bits;
|
||||
if (++var1 >= size) {
|
||||
if(++var1 >= size) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +187,7 @@ public class DataBits {
|
||||
}
|
||||
|
||||
public void write(DataOutputStream dos) throws IOException {
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
for(int i = 0; i < data.length(); i++) {
|
||||
Varint.writeUnsignedVarLong(data.get(i), dos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.util.hunk.bits;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -56,8 +55,7 @@ public class DataContainer<T> {
|
||||
this.bits = new AtomicInteger(palette.get().bits());
|
||||
}
|
||||
|
||||
public static String readBitString(DataInputStream din) throws IOException
|
||||
{
|
||||
public static String readBitString(DataInputStream din) throws IOException {
|
||||
DataContainer<Character> c = new DataContainer<>(din, new Writable<Character>() {
|
||||
@Override
|
||||
public Character readNodeData(DataInputStream din) throws IOException {
|
||||
@@ -72,8 +70,7 @@ public class DataContainer<T> {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(int i = c.size()-1; i >= 0; i--)
|
||||
{
|
||||
for(int i = c.size() - 1; i >= 0; i--) {
|
||||
sb.setCharAt(i, c.get(i));
|
||||
}
|
||||
|
||||
@@ -93,27 +90,24 @@ public class DataContainer<T> {
|
||||
}
|
||||
}, s.length());
|
||||
|
||||
for(int i = 0; i < s.length(); i++)
|
||||
{
|
||||
for(int i = 0; i < s.length(); i++) {
|
||||
c.set(i, s.charAt(i));
|
||||
}
|
||||
|
||||
c.writeDos(dos);
|
||||
}
|
||||
|
||||
public DataBits getData()
|
||||
{
|
||||
public DataBits getData() {
|
||||
return data.get();
|
||||
}
|
||||
|
||||
public Palette<T> getPalette()
|
||||
{
|
||||
public Palette<T> getPalette() {
|
||||
return palette.get();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "DataContainer <" + length + " x " + bits + " bits> -> Palette<" + palette.get().getClass().getSimpleName().replaceAll("\\QPalette\\E", "") + ">: " + palette.get().size() +
|
||||
" " + data.get().toString() + " PalBit: " + palette.get().bits();
|
||||
" " + data.get().toString() + " PalBit: " + palette.get().bits();
|
||||
}
|
||||
|
||||
public byte[] write() throws IOException {
|
||||
@@ -136,13 +130,13 @@ public class DataContainer<T> {
|
||||
|
||||
private Palette<T> newPalette(DataInputStream din) throws IOException {
|
||||
int paletteSize = Varint.readUnsignedVarInt(din);
|
||||
Palette<T> d = newPalette(bits(paletteSize+1));
|
||||
Palette<T> d = newPalette(bits(paletteSize + 1));
|
||||
d.from(paletteSize, writer, din);
|
||||
return d;
|
||||
}
|
||||
|
||||
private Palette<T> newPalette(int bits) {
|
||||
if (bits <= LINEAR_BITS_LIMIT) {
|
||||
if(bits <= LINEAR_BITS_LIMIT) {
|
||||
return new LinearPalette<>(LINEAR_INITIAL_LENGTH);
|
||||
}
|
||||
|
||||
@@ -150,17 +144,16 @@ public class DataContainer<T> {
|
||||
}
|
||||
|
||||
public void ensurePaletted(T t) {
|
||||
if (palette.get().id(t) == -1) {
|
||||
if(palette.get().id(t) == -1) {
|
||||
expandOne();
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int position, T t) {
|
||||
synchronized (this)
|
||||
{
|
||||
synchronized(this) {
|
||||
int id = palette.get().id(t);
|
||||
|
||||
if (id == -1) {
|
||||
if(id == -1) {
|
||||
expandOne();
|
||||
id = palette.get().add(t);
|
||||
}
|
||||
@@ -170,17 +163,16 @@ public class DataContainer<T> {
|
||||
}
|
||||
|
||||
private void expandOne() {
|
||||
if (palette.get().size() + 1 >= BIT[bits.get()]) {
|
||||
if(palette.get().size() + 1 >= BIT[bits.get()]) {
|
||||
setBits(bits.get() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public T get(int position) {
|
||||
synchronized (this)
|
||||
{
|
||||
synchronized(this) {
|
||||
int id = data.get().get(position) + 1;
|
||||
|
||||
if (id <= 0) {
|
||||
if(id <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -189,8 +181,8 @@ public class DataContainer<T> {
|
||||
}
|
||||
|
||||
public void setBits(int bits) {
|
||||
if (this.bits.get() != bits) {
|
||||
if (this.bits.get() <= LINEAR_BITS_LIMIT != bits <= LINEAR_BITS_LIMIT) {
|
||||
if(this.bits.get() != bits) {
|
||||
if(this.bits.get() <= LINEAR_BITS_LIMIT != bits <= LINEAR_BITS_LIMIT) {
|
||||
palette.set(newPalette(bits).from(palette.get()));
|
||||
}
|
||||
|
||||
@@ -202,7 +194,7 @@ public class DataContainer<T> {
|
||||
private static int[] computeBitLimits() {
|
||||
int[] m = new int[16];
|
||||
|
||||
for (int i = 0; i < m.length; i++) {
|
||||
for(int i = 0; i < m.length; i++) {
|
||||
m[i] = (int) Math.pow(2, i);
|
||||
}
|
||||
|
||||
@@ -210,12 +202,12 @@ public class DataContainer<T> {
|
||||
}
|
||||
|
||||
protected static int bits(int size) {
|
||||
if (DataContainer.BIT[INITIAL_BITS] >= size) {
|
||||
if(DataContainer.BIT[INITIAL_BITS] >= size) {
|
||||
return INITIAL_BITS;
|
||||
}
|
||||
|
||||
for (int i = 0; i < DataContainer.BIT.length; i++) {
|
||||
if (DataContainer.BIT[i] >= size) {
|
||||
for(int i = 0; i < DataContainer.BIT.length; i++) {
|
||||
if(DataContainer.BIT[i] >= size) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class HashPalette<T> implements Palette<T> {
|
||||
|
||||
@Override
|
||||
public T get(int id) {
|
||||
if (id < 0 || id >= size.get()) {
|
||||
if(id < 0 || id >= size.get()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class HashPalette<T> implements Palette<T> {
|
||||
int index = size.getAndIncrement();
|
||||
palette.put(t, index);
|
||||
|
||||
if (t != null) {
|
||||
if(t != null) {
|
||||
lookup.put(index, t);
|
||||
}
|
||||
|
||||
@@ -59,8 +59,7 @@ public class HashPalette<T> implements Palette<T> {
|
||||
|
||||
@Override
|
||||
public int id(T t) {
|
||||
if(t == null)
|
||||
{
|
||||
if(t == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -75,9 +74,8 @@ public class HashPalette<T> implements Palette<T> {
|
||||
|
||||
@Override
|
||||
public void iterate(Consumer2<T, Integer> c) {
|
||||
for (T i : palette.keySet()) {
|
||||
if(i == null)
|
||||
{
|
||||
for(T i : palette.keySet()) {
|
||||
if(i == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.hunk.bits;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.function.Consumer2;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -38,7 +36,7 @@ public class LinearPalette<T> implements Palette<T> {
|
||||
|
||||
@Override
|
||||
public T get(int id) {
|
||||
if (id < 0 || id >= size.get()) {
|
||||
if(id < 0 || id >= size.get()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -54,10 +52,10 @@ public class LinearPalette<T> implements Palette<T> {
|
||||
}
|
||||
|
||||
private void grow(int newLength) {
|
||||
if (newLength > palette.get().length()) {
|
||||
if(newLength > palette.get().length()) {
|
||||
AtomicReferenceArray<T> a = new AtomicReferenceArray<>(newLength + size.get());
|
||||
|
||||
for (int i = 0; i < palette.get().length(); i++) {
|
||||
for(int i = 0; i < palette.get().length(); i++) {
|
||||
a.set(i, palette.get().get(i));
|
||||
}
|
||||
|
||||
@@ -67,13 +65,12 @@ public class LinearPalette<T> implements Palette<T> {
|
||||
|
||||
@Override
|
||||
public int id(T t) {
|
||||
if(t == null)
|
||||
{
|
||||
if(t == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 1; i < size() + 1; i++) {
|
||||
if (t.equals(palette.get().get(i))) {
|
||||
for(int i = 1; i < size() + 1; i++) {
|
||||
if(t.equals(palette.get().get(i))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -83,12 +80,12 @@ public class LinearPalette<T> implements Palette<T> {
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size.get()-1;
|
||||
return size.get() - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iterate(Consumer2<T, Integer> c) {
|
||||
for (int i = 1; i < size()+1; i++) {
|
||||
for(int i = 1; i < size() + 1; i++) {
|
||||
c.accept(palette.get().get(i), i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface Palette<T> {
|
||||
int size();
|
||||
|
||||
default int bits() {
|
||||
return DataContainer.bits(size()+1);
|
||||
return DataContainer.bits(size() + 1);
|
||||
}
|
||||
|
||||
void iterate(Consumer2<T, Integer> c);
|
||||
@@ -44,14 +44,14 @@ public interface Palette<T> {
|
||||
iterate((a, b) -> {
|
||||
try {
|
||||
c.accept(a, b);
|
||||
} catch (IOException e) {
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
default Palette<T> from(int size, Writable<T> writable, DataInputStream in) throws IOException {
|
||||
for (int i = 0; i < size; i++) {
|
||||
for(int i = 0; i < size; i++) {
|
||||
add(writable.readNodeData(in));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,31 +22,23 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.slices.BlockMatter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
public class TecTest {
|
||||
public static Set<BlockData> randomBlocks(int max)
|
||||
{
|
||||
public static Set<BlockData> randomBlocks(int max) {
|
||||
KSet<BlockData> d = new KSet<>();
|
||||
|
||||
while(d.size() < max)
|
||||
{
|
||||
while(d.size() < max) {
|
||||
Material m = Material.values()[RNG.r.i(Material.values().length - 1)];
|
||||
if(m.isBlock())
|
||||
{
|
||||
if(m.isBlock()) {
|
||||
d.add(m.createBlockData());
|
||||
}
|
||||
}
|
||||
@@ -54,23 +46,19 @@ public class TecTest {
|
||||
return d;
|
||||
}
|
||||
|
||||
public static void go()
|
||||
{
|
||||
public static void go() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean test(int size, int pal)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static boolean test(int size, int pal) {
|
||||
try {
|
||||
Iris.info("Test? " + size + " " + pal);
|
||||
KList<BlockData> blocks = new KList<>(randomBlocks(pal));
|
||||
Iris.info("Fill " + pal + " -> " + size + " Entries");
|
||||
Writable<BlockData> writer = new BlockMatter();
|
||||
DataContainer<BlockData> dc = new DataContainer<>(writer, size);
|
||||
|
||||
for(int i = 0; i < dc.size(); i++)
|
||||
{
|
||||
for(int i = 0; i < dc.size(); i++) {
|
||||
dc.set(i, blocks.getRandom());
|
||||
}
|
||||
|
||||
@@ -84,13 +72,9 @@ public class TecTest {
|
||||
if(Arrays.equals(dat, dat2)) {
|
||||
Iris.info("MATCH");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < dc.size(); i++)
|
||||
{
|
||||
if(!dx.get(i).equals(dc.get(i)))
|
||||
{
|
||||
} else {
|
||||
for(int i = 0; i < dc.size(); i++) {
|
||||
if(!dx.get(i).equals(dc.get(i))) {
|
||||
Iris.info("FAIL Expected " + dc.get(i).getAsString(true) + " but got " + dx.get(i).getAsString(true));
|
||||
return false;
|
||||
}
|
||||
@@ -99,10 +83,7 @@ public class TecTest {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MappedHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
if (t == null) {
|
||||
if(t == null) {
|
||||
data.remove(index(x, y, z));
|
||||
return;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class MappedHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
public synchronized Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
|
||||
int idx, z;
|
||||
|
||||
for (Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
for(Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
idx = g.getKey();
|
||||
z = idx / (getWidth() * getHeight());
|
||||
idx -= (z * getWidth() * getHeight());
|
||||
@@ -83,7 +83,7 @@ public class MappedHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
public synchronized Hunk<T> iterateSyncIO(Consumer4IO<Integer, Integer, Integer, T> c) throws IOException {
|
||||
int idx, z;
|
||||
|
||||
for (Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
for(Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
idx = g.getKey();
|
||||
z = idx / (getWidth() * getHeight());
|
||||
idx -= (z * getWidth() * getHeight());
|
||||
|
||||
@@ -48,15 +48,15 @@ public class MappedSyncHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
synchronized (data) {
|
||||
synchronized(data) {
|
||||
return data.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
synchronized (data) {
|
||||
if (t == null) {
|
||||
synchronized(data) {
|
||||
if(t == null) {
|
||||
data.remove(index(x, y, z));
|
||||
return;
|
||||
}
|
||||
@@ -71,10 +71,10 @@ public class MappedSyncHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
|
||||
synchronized (data) {
|
||||
synchronized(data) {
|
||||
int idx, z;
|
||||
|
||||
for (Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
for(Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
idx = g.getKey();
|
||||
z = idx / (getWidth() * getHeight());
|
||||
idx -= (z * getWidth() * getHeight());
|
||||
@@ -87,10 +87,10 @@ public class MappedSyncHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSyncIO(Consumer4IO<Integer, Integer, Integer, T> c) throws IOException {
|
||||
synchronized (data) {
|
||||
synchronized(data) {
|
||||
int idx, z;
|
||||
|
||||
for (Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
for(Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
idx = g.getKey();
|
||||
z = idx / (getWidth() * getHeight());
|
||||
idx -= (z * getWidth() * getHeight());
|
||||
@@ -103,14 +103,14 @@ public class MappedSyncHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public void empty(T b) {
|
||||
synchronized (data) {
|
||||
synchronized(data) {
|
||||
data.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
synchronized (data) {
|
||||
synchronized(data) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
|
||||
@Data
|
||||
@@ -54,11 +53,11 @@ public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
|
||||
for (int i = 0; i < getWidth(); i++) {
|
||||
for (int j = 0; j < getHeight(); j++) {
|
||||
for (int k = 0; k < getDepth(); k++) {
|
||||
for(int i = 0; i < getWidth(); i++) {
|
||||
for(int j = 0; j < getHeight(); j++) {
|
||||
for(int k = 0; k < getDepth(); k++) {
|
||||
T t = getRaw(i, j, k);
|
||||
if (t != null) {
|
||||
if(t != null) {
|
||||
c.accept(i, j, k, t);
|
||||
}
|
||||
}
|
||||
@@ -69,11 +68,11 @@ public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSyncIO(Consumer4IO<Integer, Integer, Integer, T> c) throws IOException {
|
||||
for (int i = 0; i < getWidth(); i++) {
|
||||
for (int j = 0; j < getHeight(); j++) {
|
||||
for (int k = 0; k < getDepth(); k++) {
|
||||
for(int i = 0; i < getWidth(); i++) {
|
||||
for(int j = 0; j < getHeight(); j++) {
|
||||
for(int k = 0; k < getDepth(); k++) {
|
||||
T t = getRaw(i, j, k);
|
||||
if (t != null) {
|
||||
if(t != null) {
|
||||
c.accept(i, j, k, t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class PaletteOrHunk<T> extends StorageHunk<T> implements Hunk<T>
|
||||
}
|
||||
|
||||
public void setPalette(DataContainer<T> c) {
|
||||
if (isPalette()) {
|
||||
if(isPalette()) {
|
||||
((PaletteHunk<T>) hunk).setPalette(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class StorageHunk<T> implements Hunk<T> {
|
||||
private final int depth;
|
||||
|
||||
public StorageHunk(int width, int height, int depth) {
|
||||
if (width <= 0 || height <= 0 || depth <= 0) {
|
||||
if(width <= 0 || height <= 0 || depth <= 0) {
|
||||
throw new RuntimeException("Unsupported size " + width + " " + height + " " + depth);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,14 +38,14 @@ public class SynchronizedArrayHunk<T> extends StorageHunk<T> implements Hunk<T>
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
synchronized (data) {
|
||||
synchronized(data) {
|
||||
data[index(x, y, z)] = t;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
synchronized (data) {
|
||||
synchronized(data) {
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class SynchronizedArrayHunk<T> extends StorageHunk<T> implements Hunk<T>
|
||||
|
||||
@Override
|
||||
public void fill(T t) {
|
||||
synchronized (data) {
|
||||
synchronized(data) {
|
||||
Arrays.fill(data, t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ public class BiomeGridHunkView implements Hunk<Biome> {
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Biome t) {
|
||||
chunk.setBiome(x, y+minHeight, z, t);
|
||||
chunk.setBiome(x, y + minHeight, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getRaw(int x, int y, int z) {
|
||||
return chunk.getBiome(x, y+minHeight, z);
|
||||
return chunk.getBiome(x, y + minHeight, z);
|
||||
}
|
||||
|
||||
public void forceBiomeBaseInto(int x, int y, int z, Object somethingVeryDirty) {
|
||||
if (chunk instanceof LinkedTerrainChunk) {
|
||||
INMS.get().forceBiomeInto(x, y+minHeight, z, somethingVeryDirty, ((LinkedTerrainChunk) chunk).getRawBiome());
|
||||
if(chunk instanceof LinkedTerrainChunk) {
|
||||
INMS.get().forceBiomeInto(x, y + minHeight, z, somethingVeryDirty, ((LinkedTerrainChunk) chunk).getRawBiome());
|
||||
return;
|
||||
}
|
||||
INMS.get().forceBiomeInto(x, y+minHeight, z, somethingVeryDirty, chunk);
|
||||
INMS.get().forceBiomeInto(x, y + minHeight, z, somethingVeryDirty, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ChunkBiomeHunkView implements Hunk<Biome> {
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Biome t) {
|
||||
if (t == null) {
|
||||
if(t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,6 @@ public class ChunkBiomeHunkView implements Hunk<Biome> {
|
||||
@Override
|
||||
public Biome getRaw(int x, int y, int z) {
|
||||
return Iris.service(EditSVC.class)
|
||||
.getBiome(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16));
|
||||
.getBiome(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,24 +47,24 @@ public class ChunkDataHunkView implements Hunk<BlockData> {
|
||||
|
||||
@Override
|
||||
public void set(int x1, int y1, int z1, int x2, int y2, int z2, BlockData t) {
|
||||
if (t == null) {
|
||||
if(t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
chunk.setRegion(x1, y1+chunk.getMinHeight(), z1, x2, y2+chunk.getMinHeight(), z2, t);
|
||||
chunk.setRegion(x1, y1 + chunk.getMinHeight(), z1, x2, y2 + chunk.getMinHeight(), z2, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, BlockData t) {
|
||||
if (t == null) {
|
||||
if(t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
chunk.setBlock(x, y+chunk.getMinHeight(), z, t);
|
||||
chunk.setBlock(x, y + chunk.getMinHeight(), z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getRaw(int x, int y, int z) {
|
||||
return chunk.getBlockData(x, y+chunk.getMinHeight(), z);
|
||||
return chunk.getBlockData(x, y + chunk.getMinHeight(), z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ChunkHunkView implements Hunk<BlockData> {
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, BlockData t) {
|
||||
if (t == null) {
|
||||
if(t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class FunctionalHunkView<R, T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
if (backConverter == null) {
|
||||
if(backConverter == null) {
|
||||
throw new UnsupportedOperationException("You cannot writeNodeData to this hunk (Read Only)");
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class FunctionalHunkView<R, T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
if (converter == null) {
|
||||
if(converter == null) {
|
||||
throw new UnsupportedOperationException("You cannot read this hunk (Write Only)");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ public class RotatedXHunkView<T> implements Hunk<T> {
|
||||
int yc = (int) Math.round(cos * (getHeight() / 2f) - sin * (getDepth() / 2f));
|
||||
int zc = (int) Math.round(sin * (getHeight() / 2f) + cos * (getDepth() / 2f));
|
||||
src.setIfExists(x,
|
||||
(int) Math.round(cos * (y - yc) - sin * (z - zc)) - yc,
|
||||
(int) Math.round(sin * y - yc + cos * (z - zc)) - zc,
|
||||
t);
|
||||
(int) Math.round(cos * (y - yc) - sin * (z - zc)) - yc,
|
||||
(int) Math.round(sin * y - yc + cos * (z - zc)) - zc,
|
||||
t);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,8 +46,8 @@ public class RotatedXHunkView<T> implements Hunk<T> {
|
||||
int yc = (int) Math.round(cos * (getHeight() / 2f) - sin * (getDepth() / 2f));
|
||||
int zc = (int) Math.round(sin * (getHeight() / 2f) + cos * (getDepth() / 2f));
|
||||
return src.getIfExists(x,
|
||||
(int) Math.round(cos * (y - yc) - sin * (z - zc)) - yc,
|
||||
(int) Math.round(sin * y - yc + cos * (z - zc)) - zc
|
||||
(int) Math.round(cos * (y - yc) - sin * (z - zc)) - yc,
|
||||
(int) Math.round(sin * y - yc + cos * (z - zc)) - zc
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ public class RotatedYHunkView<T> implements Hunk<T> {
|
||||
int xc = (int) Math.round(cos * (getWidth() / 2f) + sin * (getDepth() / 2f));
|
||||
int zc = (int) Math.round(-sin * (getWidth() / 2f) + cos * (getDepth() / 2f));
|
||||
src.setIfExists((int)
|
||||
Math.round(cos * (x - xc) + sin * (z - zc)) - xc,
|
||||
y,
|
||||
(int) Math.round(-sin * (x - xc) + cos * (z - zc)) - zc, t);
|
||||
Math.round(cos * (x - xc) + sin * (z - zc)) - xc,
|
||||
y,
|
||||
(int) Math.round(-sin * (x - xc) + cos * (z - zc)) - zc, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,9 +46,9 @@ public class RotatedYHunkView<T> implements Hunk<T> {
|
||||
int xc = (int) Math.round(cos * (getWidth() / 2f) + sin * (getDepth() / 2f));
|
||||
int zc = (int) Math.round(-sin * (getWidth() / 2f) + cos * (getDepth() / 2f));
|
||||
return src.getIfExists(
|
||||
(int) Math.round(cos * (x - xc) + sin * (z - zc)) - xc,
|
||||
y,
|
||||
(int) Math.round(-sin * (x - xc) + cos * (z - zc)) - zc
|
||||
(int) Math.round(cos * (x - xc) + sin * (z - zc)) - xc,
|
||||
y,
|
||||
(int) Math.round(-sin * (x - xc) + cos * (z - zc)) - zc
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ public class RotatedZHunkView<T> implements Hunk<T> {
|
||||
int xc = (int) Math.round(cos * (getWidth() / 2f) - sin * (getHeight() / 2f));
|
||||
int yc = (int) Math.round(sin * (getWidth() / 2f) + cos * (getHeight() / 2f));
|
||||
return src.getIfExists((int) Math.round(cos * (x - xc) - sin * (y - yc)) - xc,
|
||||
(int) Math.round(sin * (x - xc) + cos * (y - yc)) - yc
|
||||
, z);
|
||||
(int) Math.round(sin * (x - xc) + cos * (y - yc)) - yc
|
||||
, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SynchronizedHunkView<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
synchronized (src) {
|
||||
synchronized(src) {
|
||||
src.setRaw(x, y, z, t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class WriteTrackHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
if (!b.get()) {
|
||||
if(!b.get()) {
|
||||
b.set(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user