WorldMap now successfully IONIZABLE!

This commit is contained in:
Ondřej Hruška
2014-04-19 03:43:18 +02:00
parent b70279acd5
commit db3da1554d
32 changed files with 413 additions and 225 deletions
@@ -60,7 +60,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
this(value);
setEasing(easing);
}
/**
* Create animator with easing
@@ -74,6 +74,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
setEasing(easingIn, easingOut);
}
/**
* Create as copy of another
*
@@ -1,32 +1,38 @@
package mightypork.util.control.timing;
import mightypork.util.constraints.num.mutable.NumAnimated;
public abstract class TimedTask implements Runnable, Updateable {
private NumAnimated timer = new NumAnimated(0);
private final NumAnimated timer = new NumAnimated(0);
private boolean running = false;
@Override
public void update(double delta)
{
if(running) {
if (running) {
timer.update(delta);
if(timer.isFinished()) {
if (timer.isFinished()) {
running = false;
run();
}
}
}
public void start(double seconds) {
public void start(double seconds)
{
timer.reset();
timer.animate(1, seconds);
running = true;
}
public void stop() {
public void stop()
{
running = false;
timer.reset();
}
+39 -45
View File
@@ -70,16 +70,10 @@ public class Ion {
*/
public static final short ENTRY = 60;
/**
* Start mark - general purpose, marks start of a sequence of stored
* objects.
*/
public static final short START = 61;
/**
* End mark - general purpose, marks end of sequence of stored objects.
*/
public static final short END = 62;
public static final short END = 61;
// built in 80..99
/** Map mark (built-in data structure) */
@@ -135,7 +129,7 @@ public class Ion {
if (mark > Short.MAX_VALUE) throw new IllegalArgumentException("Mark too high (max " + Short.MAX_VALUE + ").");
if (mark < Short.MIN_VALUE) throw new IllegalArgumentException("Mark too low (min " + Short.MIN_VALUE + ").");
short m = (short) mark;
final short m = (short) mark;
if (markRangeChecking && m >= 0 && m < 100) {
throw new IllegalArgumentException("Marks 0..99 are reserved.");
@@ -304,7 +298,7 @@ public class Ion {
case BOOLEAN_ARRAY:
length = readInt(in);
boolean[] bools = new boolean[length];
final boolean[] bools = new boolean[length];
for (int i = 0; i < length; i++) {
bools[i] = readBoolean(in);
}
@@ -312,7 +306,7 @@ public class Ion {
case BYTE_ARRAY:
length = readInt(in);
byte[] bytes = new byte[length];
final byte[] bytes = new byte[length];
for (int i = 0; i < length; i++) {
bytes[i] = readByte(in);
}
@@ -320,7 +314,7 @@ public class Ion {
case CHAR_ARRAY:
length = readInt(in);
char[] chars = new char[length];
final char[] chars = new char[length];
for (int i = 0; i < length; i++) {
chars[i] = readChar(in);
}
@@ -328,7 +322,7 @@ public class Ion {
case SHORT_ARRAY:
length = readInt(in);
short[] shorts = new short[length];
final short[] shorts = new short[length];
for (int i = 0; i < length; i++) {
shorts[i] = readShort(in);
}
@@ -336,7 +330,7 @@ public class Ion {
case INT_ARRAY:
length = readInt(in);
int[] ints = new int[length];
final int[] ints = new int[length];
for (int i = 0; i < length; i++) {
ints[i] = readInt(in);
}
@@ -344,7 +338,7 @@ public class Ion {
case LONG_ARRAY:
length = readInt(in);
long[] longs = new long[length];
final long[] longs = new long[length];
for (int i = 0; i < length; i++) {
longs[i] = readLong(in);
}
@@ -352,7 +346,7 @@ public class Ion {
case FLOAT_ARRAY:
length = readInt(in);
float[] floats = new float[length];
final float[] floats = new float[length];
for (int i = 0; i < length; i++) {
floats[i] = readFloat(in);
}
@@ -360,7 +354,7 @@ public class Ion {
case DOUBLE_ARRAY:
length = readInt(in);
double[] doubles = new double[length];
final double[] doubles = new double[length];
for (int i = 0; i < length; i++) {
doubles[i] = readDouble(in);
}
@@ -368,7 +362,7 @@ public class Ion {
case STRING_ARRAY:
length = readInt(in);
String[] Strings = new String[length];
final String[] Strings = new String[length];
for (int i = 0; i < length; i++) {
Strings[i] = readString(in);
}
@@ -732,7 +726,7 @@ public class Ion {
public static void writeBooleanArray(OutputStream out, boolean[] arr) throws IOException
{
writeInt(out, arr.length);
for (boolean a : arr) {
for (final boolean a : arr) {
writeBoolean(out, a);
}
}
@@ -748,7 +742,7 @@ public class Ion {
public static void writeByteArray(OutputStream out, byte[] arr) throws IOException
{
writeInt(out, arr.length);
for (byte a : arr) {
for (final byte a : arr) {
writeByte(out, a);
}
}
@@ -764,7 +758,7 @@ public class Ion {
public static void writeCharArray(OutputStream out, char[] arr) throws IOException
{
writeInt(out, arr.length);
for (char a : arr) {
for (final char a : arr) {
writeChar(out, a);
}
}
@@ -780,7 +774,7 @@ public class Ion {
public static void writeShortArray(OutputStream out, short[] arr) throws IOException
{
writeInt(out, arr.length);
for (short a : arr) {
for (final short a : arr) {
writeShort(out, a);
}
}
@@ -796,7 +790,7 @@ public class Ion {
public static void writeIntArray(OutputStream out, int[] arr) throws IOException
{
writeInt(out, arr.length);
for (int a : arr) {
for (final int a : arr) {
writeInt(out, a);
}
}
@@ -812,7 +806,7 @@ public class Ion {
public static void writeLongArray(OutputStream out, long[] arr) throws IOException
{
writeInt(out, arr.length);
for (long a : arr) {
for (final long a : arr) {
writeLong(out, a);
}
}
@@ -828,7 +822,7 @@ public class Ion {
public static void writeFloatArray(OutputStream out, float[] arr) throws IOException
{
writeInt(out, arr.length);
for (float a : arr) {
for (final float a : arr) {
writeFloat(out, a);
}
}
@@ -844,7 +838,7 @@ public class Ion {
public static void writeDoubleArray(OutputStream out, double[] arr) throws IOException
{
writeInt(out, arr.length);
for (double a : arr) {
for (final double a : arr) {
writeDouble(out, a);
}
}
@@ -860,7 +854,7 @@ public class Ion {
public static void writeStringArray(OutputStream out, String[] arr) throws IOException
{
writeInt(out, arr.length);
for (String a : arr) {
for (final String a : arr) {
writeString(out, a);
}
}
@@ -888,7 +882,7 @@ public class Ion {
*/
public static byte readByte(InputStream in) throws IOException
{
int b = in.read();
final int b = in.read();
if (-1 == b) throw new IOException("End of stream.");
return (byte) b;
}
@@ -1018,8 +1012,8 @@ public class Ion {
*/
public static boolean[] readBooleanArray(InputStream in) throws IOException
{
int length = readInt(in);
boolean[] booleans = new boolean[length];
final int length = readInt(in);
final boolean[] booleans = new boolean[length];
for (int i = 0; i < length; i++) {
booleans[i] = readBoolean(in);
}
@@ -1036,8 +1030,8 @@ public class Ion {
*/
public static byte[] readByteArray(InputStream in) throws IOException
{
int length = readInt(in);
byte[] bytes = new byte[length];
final int length = readInt(in);
final byte[] bytes = new byte[length];
for (int i = 0; i < length; i++) {
bytes[i] = readByte(in);
}
@@ -1054,8 +1048,8 @@ public class Ion {
*/
public static char[] readCharArray(InputStream in) throws IOException
{
int length = readInt(in);
char[] chars = new char[length];
final int length = readInt(in);
final char[] chars = new char[length];
for (int i = 0; i < length; i++) {
chars[i] = readChar(in);
}
@@ -1072,8 +1066,8 @@ public class Ion {
*/
public static short[] readShortArray(InputStream in) throws IOException
{
int length = readInt(in);
short[] shorts = new short[length];
final int length = readInt(in);
final short[] shorts = new short[length];
for (int i = 0; i < length; i++) {
shorts[i] = readShort(in);
}
@@ -1090,8 +1084,8 @@ public class Ion {
*/
public static int[] readIntArray(InputStream in) throws IOException
{
int length = readInt(in);
int[] ints = new int[length];
final int length = readInt(in);
final int[] ints = new int[length];
for (int i = 0; i < length; i++) {
ints[i] = readInt(in);
}
@@ -1108,8 +1102,8 @@ public class Ion {
*/
public static long[] readLongArray(InputStream in) throws IOException
{
int length = readInt(in);
long[] longs = new long[length];
final int length = readInt(in);
final long[] longs = new long[length];
for (int i = 0; i < length; i++) {
longs[i] = readLong(in);
}
@@ -1126,8 +1120,8 @@ public class Ion {
*/
public static float[] readFloatArray(InputStream in) throws IOException
{
int length = readInt(in);
float[] floats = new float[length];
final int length = readInt(in);
final float[] floats = new float[length];
for (int i = 0; i < length; i++) {
floats[i] = readFloat(in);
}
@@ -1144,8 +1138,8 @@ public class Ion {
*/
public static double[] readDoubleArray(InputStream in) throws IOException
{
int length = readInt(in);
double[] doubles = new double[length];
final int length = readInt(in);
final double[] doubles = new double[length];
for (int i = 0; i < length; i++) {
doubles[i] = readDouble(in);
}
@@ -1162,8 +1156,8 @@ public class Ion {
*/
public static String[] readStringArray(InputStream in) throws IOException
{
int length = readInt(in);
String[] Strings = new String[length];
final int length = readInt(in);
final String[] Strings = new String[length];
for (int i = 0; i < length; i++) {
Strings[i] = readString(in);
}
@@ -1,7 +1,6 @@
package mightypork.util.files.ion;
/**
* Ionizable HashMap<String, Object> with getters and setters for individual
* supported types.
@@ -116,7 +115,6 @@ public class IonDataBundle extends IonMap<String, Object> {
{
super.put(key, num);
}
public Object getOfType(String key, Class<?> type)
+1 -1
View File
@@ -81,7 +81,7 @@ public class NoiseGen {
*/
public double[][] buildMap(int width, int height)
{
double[][] map = new double[height][width];
final double[][] map = new double[height][width];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
@@ -48,7 +48,7 @@ public class PerlinNoiseGenerator {
private final Random rand = new Random(DEFAULT_SEED);
/** Permutation array for the improved noise function */
private int[] p_imp;
private final int[] p_imp;
/** P array for perline 1 noise */
private int[] p;
@@ -103,39 +103,39 @@ public class PerlinNoiseGenerator {
public double improvedNoise(double x, double y, double z)
{
// Constraint the point to a unit cube
int uc_x = (int) Math.floor(x) & 255;
int uc_y = (int) Math.floor(y) & 255;
int uc_z = (int) Math.floor(z) & 255;
final int uc_x = (int) Math.floor(x) & 255;
final int uc_y = (int) Math.floor(y) & 255;
final int uc_z = (int) Math.floor(z) & 255;
// Relative location of the point in the unit cube
double xo = x - Math.floor(x);
double yo = y - Math.floor(y);
double zo = z - Math.floor(z);
final double xo = x - Math.floor(x);
final double yo = y - Math.floor(y);
final double zo = z - Math.floor(z);
// Fade curves for x, y and z
double u = fade(xo);
double v = fade(yo);
double w = fade(zo);
final double u = fade(xo);
final double v = fade(yo);
final double w = fade(zo);
// Generate a hash for each coordinate to find out where in the cube
// it lies.
int a = p_imp[uc_x] + uc_y;
int aa = p_imp[a] + uc_z;
int ab = p_imp[a + 1] + uc_z;
final int a = p_imp[uc_x] + uc_y;
final int aa = p_imp[a] + uc_z;
final int ab = p_imp[a + 1] + uc_z;
int b = p_imp[uc_x + 1] + uc_y;
int ba = p_imp[b] + uc_z;
int bb = p_imp[b + 1] + uc_z;
final int b = p_imp[uc_x + 1] + uc_y;
final int ba = p_imp[b] + uc_z;
final int bb = p_imp[b + 1] + uc_z;
// blend results from the 8 corners based on the noise function
double c1 = grad(p_imp[aa], xo, yo, zo);
double c2 = grad(p_imp[ba], xo - 1, yo, zo);
double c3 = grad(p_imp[ab], xo, yo - 1, zo);
double c4 = grad(p_imp[bb], xo - 1, yo - 1, zo);
double c5 = grad(p_imp[aa + 1], xo, yo, zo - 1);
double c6 = grad(p_imp[ba + 1], xo - 1, yo, zo - 1);
double c7 = grad(p_imp[ab + 1], xo, yo - 1, zo - 1);
double c8 = grad(p_imp[bb + 1], xo - 1, yo - 1, zo - 1);
final double c1 = grad(p_imp[aa], xo, yo, zo);
final double c2 = grad(p_imp[ba], xo - 1, yo, zo);
final double c3 = grad(p_imp[ab], xo, yo - 1, zo);
final double c4 = grad(p_imp[bb], xo - 1, yo - 1, zo);
final double c5 = grad(p_imp[aa + 1], xo, yo, zo - 1);
final double c6 = grad(p_imp[ba + 1], xo - 1, yo, zo - 1);
final double c7 = grad(p_imp[ab + 1], xo, yo - 1, zo - 1);
final double c8 = grad(p_imp[bb + 1], xo - 1, yo - 1, zo - 1);
return lerp(w, lerp(v, lerp(u, c1, c2), lerp(u, c3, c4)), lerp(v, lerp(u, c5, c6), lerp(u, c7, c8)));
}
@@ -149,16 +149,16 @@ public class PerlinNoiseGenerator {
*/
public double noise1(double x)
{
double t = x + N;
int bx0 = ((int) t) & BM;
int bx1 = (bx0 + 1) & BM;
double rx0 = t - (int) t;
double rx1 = rx0 - 1;
final double t = x + N;
final int bx0 = ((int) t) & BM;
final int bx1 = (bx0 + 1) & BM;
final double rx0 = t - (int) t;
final double rx1 = rx0 - 1;
double sx = sCurve(rx0);
final double sx = sCurve(rx0);
double u = rx0 * g1[p[bx0]];
double v = rx1 * g1[p[bx1]];
final double u = rx0 * g1[p[bx0]];
final double v = rx1 * g1[p[bx1]];
return lerp(sx, u, v);
}
@@ -174,39 +174,39 @@ public class PerlinNoiseGenerator {
public double noise2(double x, double y)
{
double t = x + N;
int bx0 = ((int) t) & BM;
int bx1 = (bx0 + 1) & BM;
double rx0 = t - (int) t;
double rx1 = rx0 - 1;
final int bx0 = ((int) t) & BM;
final int bx1 = (bx0 + 1) & BM;
final double rx0 = t - (int) t;
final double rx1 = rx0 - 1;
t = y + N;
int by0 = ((int) t) & BM;
int by1 = (by0 + 1) & BM;
double ry0 = t - (int) t;
double ry1 = ry0 - 1;
final int by0 = ((int) t) & BM;
final int by1 = (by0 + 1) & BM;
final double ry0 = t - (int) t;
final double ry1 = ry0 - 1;
int i = p[bx0];
int j = p[bx1];
final int i = p[bx0];
final int j = p[bx1];
int b00 = p[i + by0];
int b10 = p[j + by0];
int b01 = p[i + by1];
int b11 = p[j + by1];
final int b00 = p[i + by0];
final int b10 = p[j + by0];
final int b01 = p[i + by1];
final int b11 = p[j + by1];
double sx = sCurve(rx0);
double sy = sCurve(ry0);
final double sx = sCurve(rx0);
final double sy = sCurve(ry0);
double[] q = g2[b00];
double u = rx0 * q[0] + ry0 * q[1];
q = g2[b10];
double v = rx1 * q[0] + ry0 * q[1];
double a = lerp(sx, u, v);
final double a = lerp(sx, u, v);
q = g2[b01];
u = rx0 * q[0] + ry1 * q[1];
q = g2[b11];
v = rx1 * q[0] + ry1 * q[1];
double b = lerp(sx, u, v);
final double b = lerp(sx, u, v);
return lerp(sy, a, b);
}
@@ -223,34 +223,34 @@ public class PerlinNoiseGenerator {
public double noise3(double x, double y, double z)
{
double t = x + N;
int bx0 = ((int) t) & BM;
int bx1 = (bx0 + 1) & BM;
double rx0 = t - (int) t;
double rx1 = rx0 - 1;
final int bx0 = ((int) t) & BM;
final int bx1 = (bx0 + 1) & BM;
final double rx0 = t - (int) t;
final double rx1 = rx0 - 1;
t = y + N;
int by0 = ((int) t) & BM;
int by1 = (by0 + 1) & BM;
double ry0 = t - (int) t;
double ry1 = ry0 - 1;
final int by0 = ((int) t) & BM;
final int by1 = (by0 + 1) & BM;
final double ry0 = t - (int) t;
final double ry1 = ry0 - 1;
t = z + N;
int bz0 = ((int) t) & BM;
int bz1 = (bz0 + 1) & BM;
double rz0 = t - (int) t;
double rz1 = rz0 - 1;
final int bz0 = ((int) t) & BM;
final int bz1 = (bz0 + 1) & BM;
final double rz0 = t - (int) t;
final double rz1 = rz0 - 1;
int i = p[bx0];
int j = p[bx1];
final int i = p[bx0];
final int j = p[bx1];
int b00 = p[i + by0];
int b10 = p[j + by0];
int b01 = p[i + by1];
int b11 = p[j + by1];
final int b00 = p[i + by0];
final int b10 = p[j + by0];
final int b01 = p[i + by1];
final int b11 = p[j + by1];
t = sCurve(rx0);
double sy = sCurve(ry0);
double sz = sCurve(rz0);
final double sy = sCurve(ry0);
final double sz = sCurve(rz0);
double[] q = g3[b00 + bz0];
double u = (rx0 * q[0] + ry0 * q[1] + rz0 * q[2]);
@@ -264,7 +264,7 @@ public class PerlinNoiseGenerator {
v = (rx1 * q[0] + ry1 * q[1] + rz0 * q[2]);
double b = lerp(t, u, v);
double c = lerp(sy, a, b);
final double c = lerp(sy, a, b);
q = g3[b00 + bz1];
u = (rx0 * q[0] + ry0 * q[1] + rz1 * q[2]);
@@ -278,7 +278,7 @@ public class PerlinNoiseGenerator {
v = (rx1 * q[0] + ry1 * q[1] + rz1 * q[2]);
b = lerp(t, u, v);
double d = lerp(sy, a, b);
final double d = lerp(sy, a, b);
return lerp(sz, c, d);
}
@@ -491,9 +491,9 @@ public class PerlinNoiseGenerator {
private double grad(int hash, double x, double y, double z)
{
// Convert low 4 bits of hash code into 12 gradient directions.
int h = hash & 15;
double u = (h < 8 || h == 12 || h == 13) ? x : y;
double v = (h < 4 || h == 12 || h == 13) ? y : z;
final int h = hash & 15;
final double u = (h < 8 || h == 12 || h == 13) ? x : y;
final double v = (h < 4 || h == 12 || h == 13) ? y : z;
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
}
@@ -513,7 +513,7 @@ public class PerlinNoiseGenerator {
*/
private void normalize2(double[] v)
{
double s = 1 / Math.sqrt(v[0] * v[0] + v[1] * v[1]);
final double s = 1 / Math.sqrt(v[0] * v[0] + v[1] * v[1]);
v[0] *= s;
v[1] *= s;
}
@@ -524,7 +524,7 @@ public class PerlinNoiseGenerator {
*/
private void normalize3(double[] v)
{
double s = 1 / Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
final double s = 1 / Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
v[0] *= s;
v[1] *= s;
v[2] *= s;