[AUTO] Cleanup code

This commit is contained in:
dfsek 2020-11-23 23:02:36 -07:00
parent 65c2ad6b7a
commit f309bd8809
6 changed files with 85 additions and 83 deletions

View File

@ -12,8 +12,8 @@ import java.util.Map;
public class BiomeSnowConfig extends TerraConfigSection { public class BiomeSnowConfig extends TerraConfigSection {
private final int[] snowHeights; private final int[] snowHeights;
private boolean doSnow = false;
private final boolean physics; private final boolean physics;
private boolean doSnow = false;
public BiomeSnowConfig(TerraConfig parent) throws InvalidConfigurationException { public BiomeSnowConfig(TerraConfig parent) throws InvalidConfigurationException {
super(parent); super(parent);

View File

@ -50,7 +50,9 @@ public class NoiseFunction2 implements NoiseFunction {
double zz = z >= 0 ? z * 2 : z * -2 - 1; double zz = z >= 0 ? z * 2 : z * -2 - 1;
double key = (xx >= zz) ? (xx * xx + xx + zz) : (zz * zz + xx); double key = (xx >= zz) ? (xx * xx + xx + zz) : (zz * zz + xx);
double value = this.get(key); double value = this.get(key);
if (this.size() > cacheSize) { this.clear(); } if(this.size() > cacheSize) {
this.clear();
}
return (value == 4.9E-324D ? addAndReturn(noise.getNoise(x, z), key) : value); return (value == 4.9E-324D ? addAndReturn(noise.getNoise(x, z), key) : value);
} }

View File

@ -36,24 +36,24 @@ package com.dfsek.terra.util.hash;
import java.io.Serializable; import java.io.Serializable;
public abstract class HashIntrinsic implements Serializable { public abstract class HashIntrinsic implements Serializable {
private static final long serialVersionUID = 8058099372006904458L;
protected static final int DEFAULT_INITIAL_CAPACITY = 16;
protected static final int MAXIMUM_CAPACITY = 1073741824;
protected static final float DEFAULT_LOAD_FACTOR = 0.75F;
protected int size;
protected int threshold;
protected float loadFactor;
protected int capMinus1;
public static final int FLOAT_EXP_BIT_MASK = 2139095040; public static final int FLOAT_EXP_BIT_MASK = 2139095040;
public static final int FLOAT_SIGNIF_BIT_MASK = 8388607; public static final int FLOAT_SIGNIF_BIT_MASK = 8388607;
public static final long DOUBLE_EXP_BIT_MASK = 9218868437227405312L; public static final long DOUBLE_EXP_BIT_MASK = 9218868437227405312L;
public static final long DOUBLE_SIGNIF_BIT_MASK = 4503599627370495L; public static final long DOUBLE_SIGNIF_BIT_MASK = 4503599627370495L;
protected static final int DEFAULT_INITIAL_CAPACITY = 16;
protected static final int MAXIMUM_CAPACITY = 1073741824;
protected static final float DEFAULT_LOAD_FACTOR = 0.75F;
private static final long serialVersionUID = 8058099372006904458L;
protected int size;
protected int threshold;
protected float loadFactor;
protected int capMinus1;
protected HashIntrinsic(int initialCapacity, float loadFactor) { protected HashIntrinsic(int initialCapacity, float loadFactor) {
if (initialCapacity <= 0) { if(initialCapacity <= 0) {
throw new IllegalArgumentException("Illegal initial capacity: " + initialCapacity); throw new IllegalArgumentException("Illegal initial capacity: " + initialCapacity);
} else if (!(loadFactor <= 0.0F) && !Float.isNaN(loadFactor)) { } else if(!(loadFactor <= 0.0F) && !Float.isNaN(loadFactor)) {
if (initialCapacity > 1073741824) { if(initialCapacity > 1073741824) {
initialCapacity = 1073741824; initialCapacity = 1073741824;
} }
@ -63,14 +63,14 @@ public abstract class HashIntrinsic implements Serializable {
this.capMinus1 = capacity - 1; this.capMinus1 = capacity - 1;
this.loadFactor = loadFactor; this.loadFactor = loadFactor;
this.threshold = (int)((float)capacity * loadFactor); this.threshold = (int) ((float) capacity * loadFactor);
} else { } else {
throw new IllegalArgumentException("Illegal load factor: " + loadFactor); throw new IllegalArgumentException("Illegal load factor: " + loadFactor);
} }
} }
protected static int hashCodeLong(long value) { protected static int hashCodeLong(long value) {
return (int)(value ^ value >>> 32); return (int) (value ^ value >>> 32);
} }
protected static int hashCodeFloat(float value) { protected static int hashCodeFloat(float value) {
@ -79,12 +79,12 @@ public abstract class HashIntrinsic implements Serializable {
protected static int hashCodeDouble(double value) { protected static int hashCodeDouble(double value) {
long bits = doubleToLongBits(value); long bits = doubleToLongBits(value);
return (int)(bits ^ bits >>> 32); return (int) (bits ^ bits >>> 32);
} }
public static int floatToIntBits(float value) { public static int floatToIntBits(float value) {
int result = Float.floatToRawIntBits(value); int result = Float.floatToRawIntBits(value);
if ((result & 2139095040) == 2139095040 && (result & 8388607) != 0) { if((result & 2139095040) == 2139095040 && (result & 8388607) != 0) {
result = 2143289344; result = 2143289344;
} }
@ -93,7 +93,7 @@ public abstract class HashIntrinsic implements Serializable {
public static long doubleToLongBits(double value) { public static long doubleToLongBits(double value) {
long result = Double.doubleToRawLongBits(value); long result = Double.doubleToRawLongBits(value);
if ((result & 9218868437227405312L) == 9218868437227405312L && (result & 4503599627370495L) != 0L) { if((result & 9218868437227405312L) == 9218868437227405312L && (result & 4503599627370495L) != 0L) {
result = 9221120237041090560L; result = 9221120237041090560L;
} }

View File

@ -57,7 +57,7 @@ public class HashMapDoubleDouble extends HashIntrinsic {
int i = tableIndex(hashCodeDouble(key), this.capMinus1); int i = tableIndex(hashCodeDouble(key), this.capMinus1);
for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) { for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) {
if (e.key == key) { if(e.key == key) {
return true; return true;
} }
} }
@ -68,7 +68,7 @@ public class HashMapDoubleDouble extends HashIntrinsic {
public boolean containsValue(double value) { public boolean containsValue(double value) {
for(int i = 0; i < this.table.length; ++i) { for(int i = 0; i < this.table.length; ++i) {
for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) { for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) {
if (value == e.value) { if(value == e.value) {
return true; return true;
} }
} }
@ -81,7 +81,7 @@ public class HashMapDoubleDouble extends HashIntrinsic {
int i = tableIndex(hashCodeDouble(key), this.capMinus1); int i = tableIndex(hashCodeDouble(key), this.capMinus1);
for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) { for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) {
if (key == e.key) { if(key == e.key) {
return e.value; return e.value;
} }
} }
@ -93,7 +93,7 @@ public class HashMapDoubleDouble extends HashIntrinsic {
int i = tableIndex(hashCodeDouble(key), this.capMinus1); int i = tableIndex(hashCodeDouble(key), this.capMinus1);
for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) { for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) {
if (key == e.key) { if(key == e.key) {
return e; return e;
} }
} }
@ -105,7 +105,7 @@ public class HashMapDoubleDouble extends HashIntrinsic {
int i = tableIndex(hashCodeDouble(key), this.capMinus1); int i = tableIndex(hashCodeDouble(key), this.capMinus1);
for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) { for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) {
if (key == e.key) { if(key == e.key) {
double oldValue = e.value; double oldValue = e.value;
e.value = value; e.value = value;
return oldValue; return oldValue;
@ -119,7 +119,7 @@ public class HashMapDoubleDouble extends HashIntrinsic {
private void addEntry(double key, double value, int index) { private void addEntry(double key, double value, int index) {
HashMapDoubleDouble.Entry e = this.table[index]; HashMapDoubleDouble.Entry e = this.table[index];
this.table[index] = new HashMapDoubleDouble.Entry(key, value, e); this.table[index] = new HashMapDoubleDouble.Entry(key, value, e);
if (this.size++ >= this.threshold) { if(this.size++ >= this.threshold) {
this.resize(2 * this.table.length); this.resize(2 * this.table.length);
} }
@ -127,21 +127,21 @@ public class HashMapDoubleDouble extends HashIntrinsic {
public void resize(int newCapacity) { public void resize(int newCapacity) {
int oldCapacity = this.table.length; int oldCapacity = this.table.length;
if (oldCapacity == 1073741824) { if(oldCapacity == 1073741824) {
this.threshold = 2147483647; this.threshold = 2147483647;
} else { } else {
HashMapDoubleDouble.Entry[] newTable = this.createTable(newCapacity); HashMapDoubleDouble.Entry[] newTable = this.createTable(newCapacity);
this.capMinus1 = newCapacity - 1; this.capMinus1 = newCapacity - 1;
this.transfer(newTable); this.transfer(newTable);
this.table = newTable; this.table = newTable;
this.threshold = (int)((float)newCapacity * this.loadFactor); this.threshold = (int) ((float) newCapacity * this.loadFactor);
} }
} }
private void transfer(HashMapDoubleDouble.Entry[] newTable) { private void transfer(HashMapDoubleDouble.Entry[] newTable) {
for(int j = 0; j < this.table.length; ++j) { for(int j = 0; j < this.table.length; ++j) {
HashMapDoubleDouble.Entry e = this.table[j]; HashMapDoubleDouble.Entry e = this.table[j];
if (e != null) { if(e != null) {
this.table[j] = null; this.table[j] = null;
HashMapDoubleDouble.Entry next; HashMapDoubleDouble.Entry next;
@ -165,9 +165,9 @@ public class HashMapDoubleDouble extends HashIntrinsic {
HashMapDoubleDouble.Entry next; HashMapDoubleDouble.Entry next;
for(e = prev; e != null; e = next) { for(e = prev; e != null; e = next) {
next = e.next; next = e.next;
if (key == e.key) { if(key == e.key) {
--this.size; --this.size;
if (prev == e) { if(prev == e) {
this.table[i] = next; this.table[i] = next;
} else { } else {
prev.next = next; prev.next = next;
@ -195,65 +195,18 @@ public class HashMapDoubleDouble extends HashIntrinsic {
} }
public long memoryEstimate(int ptrsize) { public long memoryEstimate(int ptrsize) {
return (long)ptrsize * (long)(this.capMinus1 + this.size + 1) + (long)(this.size * 64 / 4); return (long) ptrsize * (long) (this.capMinus1 + this.size + 1) + (long) (this.size * 64 / 4);
} }
public HashMapDoubleDouble.Iterator iterator() { public HashMapDoubleDouble.Iterator iterator() {
return new HashMapDoubleDouble.Iterator(); return new HashMapDoubleDouble.Iterator();
} }
public class Iterator {
HashMapDoubleDouble.Entry next;
int index;
HashMapDoubleDouble.Entry current;
Iterator() {
if (HashMapDoubleDouble.this.size > 0) {
while(this.index < HashMapDoubleDouble.this.table.length && (this.next = HashMapDoubleDouble.this.table[this.index++]) == null) {
}
}
}
public final boolean hasNext() {
return this.next != null;
}
public HashMapDoubleDouble.Entry nextEntry() {
HashMapDoubleDouble.Entry e = this.next;
if (e == null) {
throw new NoSuchElementException();
} else {
if ((this.next = e.next) == null) {
while(this.index < HashMapDoubleDouble.this.table.length && (this.next = HashMapDoubleDouble.this.table[this.index++]) == null) {
}
}
this.current = e;
return e;
}
}
public double next() {
return this.nextEntry().value;
}
public void remove() {
if (this.current == null) {
throw new IllegalStateException();
} else {
double k = this.current.key;
this.current = null;
HashMapDoubleDouble.this.remove(k);
}
}
}
public static class Entry implements Serializable { public static class Entry implements Serializable {
private static final long serialVersionUID = 7972173983741231238L;
private final double key; private final double key;
private double value; private double value;
private HashMapDoubleDouble.Entry next; private HashMapDoubleDouble.Entry next;
private static final long serialVersionUID = 7972173983741231238L;
public Entry(double key, double val, HashMapDoubleDouble.Entry n) { public Entry(double key, double val, HashMapDoubleDouble.Entry n) {
this.key = key; this.key = key;
@ -276,8 +229,8 @@ public class HashMapDoubleDouble extends HashIntrinsic {
} }
public final boolean equals(Object o) { public final boolean equals(Object o) {
HashMapDoubleDouble.Entry e = (HashMapDoubleDouble.Entry)o; HashMapDoubleDouble.Entry e = (HashMapDoubleDouble.Entry) o;
return this.key == e.key && this.value == e.value; return this.key == e.key && this.value == e.value;
} }
public final String toString() { public final String toString() {
@ -288,4 +241,51 @@ public class HashMapDoubleDouble extends HashIntrinsic {
return hashCodeDouble(key) + hashCodeDouble(value); return hashCodeDouble(key) + hashCodeDouble(value);
} }
} }
public class Iterator {
HashMapDoubleDouble.Entry next;
int index;
HashMapDoubleDouble.Entry current;
Iterator() {
if(HashMapDoubleDouble.this.size > 0) {
while(this.index < HashMapDoubleDouble.this.table.length && (this.next = HashMapDoubleDouble.this.table[this.index++]) == null) {
}
}
}
public final boolean hasNext() {
return this.next != null;
}
public HashMapDoubleDouble.Entry nextEntry() {
HashMapDoubleDouble.Entry e = this.next;
if(e == null) {
throw new NoSuchElementException();
} else {
if((this.next = e.next) == null) {
while(this.index < HashMapDoubleDouble.this.table.length && (this.next = HashMapDoubleDouble.this.table[this.index++]) == null) {
}
}
this.current = e;
return e;
}
}
public double next() {
return this.nextEntry().value;
}
public void remove() {
if(this.current == null) {
throw new IllegalStateException();
} else {
double k = this.current.key;
this.current = null;
HashMapDoubleDouble.this.remove(k);
}
}
}
} }

View File

@ -62,7 +62,7 @@ class DistributionTest {
int end = normalMap.length - 1; int end = normalMap.length - 1;
while(start + 1 < end) { while(start + 1 < end) {
int mid = start + (end - start) / 2; int mid = start + (end - start) / 2;
if (normalMap[mid] <= d) { if(normalMap[mid] <= d) {
start = mid; start = mid;
} else { } else {
end = mid; end = mid;
@ -70,7 +70,7 @@ class DistributionTest {
} }
double left = FastMath.abs(normalMap[start] - d); double left = FastMath.abs(normalMap[start] - d);
double right = FastMath.abs(normalMap[end] - d); double right = FastMath.abs(normalMap[end] - d);
if (left <= right) { if(left <= right) {
return start * (num) / (normalMap.length); return start * (num) / (normalMap.length);
} }
return end * (num) / (normalMap.length); return end * (num) / (normalMap.length);

View File

@ -95,7 +95,7 @@ class LookupGenerator {
public static int normalizeNew(double d) { public static int normalizeNew(double d) {
for(int i = 0; i < lookup.length; i++) { for(int i = 0; i < lookup.length; i++) {
if (d < lookup[i]) return i; if(d < lookup[i]) return i;
} }
return lookup.length - 1; return lookup.length - 1;
} }