diff --git a/src/main/java/kdotjpg/opensimplex2/areagen/OpenSimplex2S.java b/src/main/java/kdotjpg/opensimplex2/areagen/OpenSimplex2S.java index 3a17d8a..1f3c355 100644 --- a/src/main/java/kdotjpg/opensimplex2/areagen/OpenSimplex2S.java +++ b/src/main/java/kdotjpg/opensimplex2/areagen/OpenSimplex2S.java @@ -28,7 +28,7 @@ import java.util.Set; import java.util.HashSet; public class OpenSimplex2S { - + private static final int PSIZE = 2048; private static final int PMASK = 2047; @@ -40,12 +40,12 @@ public class OpenSimplex2S { perm = new short[PSIZE]; permGrad2 = new Grad2[PSIZE]; permGrad3 = new Grad3[PSIZE]; - short[] source = new short[PSIZE]; + short[] source = new short[PSIZE]; for (short i = 0; i < PSIZE; i++) source[i] = i; for (int i = PSIZE - 1; i >= 0; i--) { seed = seed * 6364136223846793005L + 1442695040888963407L; - int r = (int)((seed + 31) % (i + 1)); + int r = (int) ((seed + 31) % (i + 1)); if (r < 0) r += (i + 1); perm[i] = source[r]; @@ -54,55 +54,52 @@ public class OpenSimplex2S { source[r] = source[i]; } } - + /* * Traditional evaluators */ - + /** * 2D SuperSimplex noise, standard lattice orientation. */ public double noise2(double x, double y) { - + // Get points for A2* lattice double s = 0.366025403784439 * (x + y); double xs = x + s, ys = y + s; - + return noise2_Base(xs, ys); } - + /** - * 2D SuperSimplex noise, with Y pointing down the main diagonal. - * Might be better for a 2D sandbox style game, where Y is vertical. - * Probably slightly less optimal for heightmaps or continent maps. + * 2D SuperSimplex noise, with Y pointing down the main diagonal. Might be + * better for a 2D sandbox style game, where Y is vertical. Probably + * slightly less optimal for heightmaps or continent maps. */ public double noise2_XBeforeY(double x, double y) { - + // Skew transform and rotation baked into one. double xx = x * 0.7071067811865476; double yy = y * 1.224744871380249; - + return noise2_Base(yy + xx, yy - xx); } - + /** - * 2D SuperSimplex noise base. - * Lookup table implementation inspired by DigitalShadow. + * 2D SuperSimplex noise base. Lookup table implementation inspired by + * DigitalShadow. */ private double noise2_Base(double xs, double ys) { double value = 0; - + // Get base points and offsets int xsb = fastFloor(xs), ysb = fastFloor(ys); double xsi = xs - xsb, ysi = ys - ysb; - + // Index to point list - int a = (int)(xsi + ysi); - int index = - (a << 2) | - (int)(xsi - ysi / 2 + 1 - a / 2.0) << 3 | - (int)(ysi - xsi / 2 + 1 - a / 2.0) << 4; - + int a = (int) (xsi + ysi); + int index = (a << 2) | (int) (xsi - ysi / 2 + 1 - a / 2.0) << 3 | (int) (ysi - xsi / 2 + 1 - a / 2.0) << 4; + double ssi = (xsi + ysi) * -0.211324865405187; double xi = xsi + ssi, yi = ysi + ssi; @@ -112,98 +109,107 @@ public class OpenSimplex2S { double dx = xi + c.dx, dy = yi + c.dy; double attn = 2.0 / 3.0 - dx * dx - dy * dy; - if (attn <= 0) continue; + if (attn <= 0) + continue; int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK; Grad2 grad = permGrad2[perm[pxm] ^ pym]; double extrapolation = grad.dx * dx + grad.dy * dy; - + attn *= attn; value += attn * attn * extrapolation; } - + return value; } - + /** - * 3D Re-oriented 8-point BCC noise, classic orientation - * Proper substitute for what 3D SuperSimplex would be, - * in light of Forbidden Formulae. - * Use noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate. + * 3D Re-oriented 8-point BCC noise, classic orientation Proper substitute + * for what 3D SuperSimplex would be, in light of Forbidden Formulae. Use + * noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate. */ public double noise3_Classic(double x, double y, double z) { - - // Re-orient the cubic lattices via rotation, to produce the expected look on cardinal planar slices. - // If texturing objects that don't tend to have cardinal plane faces, you could even remove this. + + // Re-orient the cubic lattices via rotation, to produce the expected + // look on cardinal planar slices. + // If texturing objects that don't tend to have cardinal plane faces, + // you could even remove this. // Orthonormal rotation. Not a skew transform. double r = (2.0 / 3.0) * (x + y + z); double xr = r - x, yr = r - y, zr = r - z; - + // Evaluate both lattices to form a BCC lattice. return noise3_BCC(xr, yr, zr); } - + /** * 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, Y). - * Recommended for 3D terrain and time-varied animations. - * The Z coordinate should always be the "different" coordinate in your use case. - * If Y is vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use noise3_XZBeforeY. - * If Z is vertical in world coordinates, call noise3_XYBeforeZ(x, y, Z). - * For a time varied animation, call noise3_XYBeforeZ(x, y, T). + * Recommended for 3D terrain and time-varied animations. The Z coordinate + * should always be the "different" coordinate in your use case. If Y is + * vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use + * noise3_XZBeforeY. If Z is vertical in world coordinates, call + * noise3_XYBeforeZ(x, y, Z). For a time varied animation, call + * noise3_XYBeforeZ(x, y, T). */ public double noise3_XYBeforeZ(double x, double y, double z) { - - // Re-orient the cubic lattices without skewing, to make X and Y triangular like 2D. + + // Re-orient the cubic lattices without skewing, to make X and Y + // triangular like 2D. // Orthonormal rotation. Not a skew transform. double xy = x + y; double s2 = xy * -0.211324865405187; double zz = z * 0.577350269189626; double xr = x + s2 - zz, yr = y + s2 - zz; double zr = xy * 0.577350269189626 + zz; - + // Evaluate both lattices to form a BCC lattice. return noise3_BCC(xr, yr, zr); } - + /** * 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, Z). - * Recommended for 3D terrain and time-varied animations. - * The Y coordinate should always be the "different" coordinate in your use case. - * If Y is vertical in world coordinates, call noise3_XZBeforeY(x, Y, z). - * If Z is vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use noise3_XYBeforeZ. - * For a time varied animation, call noise3_XZBeforeY(x, T, y) or use noise3_XYBeforeZ. + * Recommended for 3D terrain and time-varied animations. The Y coordinate + * should always be the "different" coordinate in your use case. If Y is + * vertical in world coordinates, call noise3_XZBeforeY(x, Y, z). If Z is + * vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use + * noise3_XYBeforeZ. For a time varied animation, call noise3_XZBeforeY(x, + * T, y) or use noise3_XYBeforeZ. */ public double noise3_XZBeforeY(double x, double y, double z) { - - // Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D. + + // Re-orient the cubic lattices without skewing, to make X and Z + // triangular like 2D. // Orthonormal rotation. Not a skew transform. double xz = x + z; double s2 = xz * -0.211324865405187; double yy = y * 0.577350269189626; - double xr = x + s2 - yy; double zr = z + s2 - yy; + double xr = x + s2 - yy; + double zr = z + s2 - yy; double yr = xz * 0.577350269189626 + yy; - + // Evaluate both lattices to form a BCC lattice. return noise3_BCC(xr, yr, zr); } - + /** - * Generate overlapping cubic lattices for 3D Re-oriented BCC noise. - * Lookup table implementation inspired by DigitalShadow. - * It was actually faster to narrow down the points in the loop itself, - * than to build up the index with enough info to isolate 8 points. + * Generate overlapping cubic lattices for 3D Re-oriented BCC noise. Lookup + * table implementation inspired by DigitalShadow. It was actually faster to + * narrow down the points in the loop itself, than to build up the index + * with enough info to isolate 8 points. */ private double noise3_BCC(double xr, double yr, double zr) { - + // Get base and offsets inside cube of first lattice. int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr); double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb; - - // Identify which octant of the cube we're in. This determines which cell - // in the other cubic lattice we're in, and also narrows down one point on each. - int xht = (int)(xri + 0.5), yht = (int)(yri + 0.5), zht = (int)(zri + 0.5); + + // Identify which octant of the cube we're in. This determines which + // cell + // in the other cubic lattice we're in, and also narrows down one point + // on each. + int xht = (int) (xri + 0.5), yht = (int) (yri + 0.5), zht = (int) (zri + 0.5); int index = (xht << 0) | (yht << 1) | (zht << 2); - + // Point contributions double value = 0; LatticePoint3D c = LOOKUP_3D[index]; @@ -216,7 +222,7 @@ public class OpenSimplex2S { int pxm = (xrb + c.xrv) & PMASK, pym = (yrb + c.yrv) & PMASK, pzm = (zrb + c.zrv) & PMASK; Grad3 grad = permGrad3[perm[perm[pxm] ^ pym] ^ pzm]; double extrapolation = grad.dx * dxr + grad.dy * dyr + grad.dz * dzr; - + attn *= attn; value += attn * attn * extrapolation; c = c.nextOnSuccess; @@ -224,122 +230,138 @@ public class OpenSimplex2S { } return value; } - + /* * Area Generators */ - + /** - * Generate the 2D noise over a large area. - * Propagates by flood-fill instead of iterating over a range. - * Results may occasionally slightly exceed [-1, 1] due to the grid-snapped pre-generated kernel. + * Generate the 2D noise over a large area. Propagates by flood-fill instead + * of iterating over a range. Results may occasionally slightly exceed [-1, + * 1] due to the grid-snapped pre-generated kernel. */ public void generate2(GenerateContext2D context, double[][] buffer, int x0, int y0) { int height = buffer.length; int width = buffer[0].length; generate2(context, buffer, x0, y0, width, height, 0, 0); } - + /** - * Generate the 2D noise over a large area. - * Propagates by flood-fill instead of iterating over a range. - * Results may occasionally slightly exceed [-1, 1] due to the grid-snapped pre-generated kernel. + * Generate the 2D noise over a large area. Propagates by flood-fill instead + * of iterating over a range. Results may occasionally slightly exceed [-1, + * 1] due to the grid-snapped pre-generated kernel. */ - public void generate2(GenerateContext2D context, double[][] buffer, int x0, int y0, int width, int height, int skipX, int skipY) { + public void generate2(GenerateContext2D context, double[][] buffer, int x0, int y0, int width, int height, + int skipX, int skipY) { Queue queue = new LinkedList(); Set seen = new HashSet(); - + int scaledRadiusX = context.scaledRadiusX; int scaledRadiusY = context.scaledRadiusY; double[][] kernel = context.kernel; int x0Skipped = x0 + skipX, y0Skipped = y0 + skipY; - + // It seems that it's better for performance, to create a local copy. // - Slightly faster than generating the kernel here. // - Much faster than referencing it directly from the context object. // - Much faster than computing the kernel equation every time. // You can remove these lines if you find it's the opposite for you. // You'll have to double the bounds again in GenerateContext2D - kernel = new double[scaledRadiusY * 2][/*scaledRadiusX * 2*/]; + kernel = new double[scaledRadiusY * 2][/* scaledRadiusX * 2 */]; for (int yy = 0; yy < scaledRadiusY; yy++) { kernel[2 * scaledRadiusY - yy - 1] = kernel[yy] = (double[]) context.kernel[yy].clone(); } - + // Get started with one point/vertex. - // For some lattices, you might need to try a handful of points in the cell, - // or flip a couple of coordinates, to guarantee it or a neighbor contributes. + // For some lattices, you might need to try a handful of points in the + // cell, + // or flip a couple of coordinates, to guarantee it or a neighbor + // contributes. // For An* lattices, the base coordinate seems fine. - double x0f = x0Skipped * context.xFrequency; double y0f = y0Skipped * context.yFrequency; + double x0f = x0Skipped * context.xFrequency; + double y0f = y0Skipped * context.yFrequency; double x0s = context.orientation.s00 * x0f + context.orientation.s01 * y0f; double y0s = context.orientation.s10 * x0f + context.orientation.s11 * y0f; int x0sb = fastFloor(x0s), y0sb = fastFloor(y0s); AreaGenLatticePoint2D firstPoint = new AreaGenLatticePoint2D(context, x0sb, y0sb); queue.add(firstPoint); seen.add(firstPoint); - + while (!queue.isEmpty()) { AreaGenLatticePoint2D point = queue.remove(); int destPointX = point.destPointX; int destPointY = point.destPointY; - + // Prepare gradient vector int pxm = point.xsv & PMASK, pym = point.ysv & PMASK; Grad2 grad = context.orientation.gradients[perm[perm[pxm] ^ pym]]; double gx = grad.dx * context.xFrequency; double gy = grad.dy * context.yFrequency; - double gOff = 0.5 * (gx + gy); // to correct for (0.5, 0.5)-offset kernel - + double gOff = 0.5 * (gx + gy); // to correct for (0.5, 0.5)-offset + // kernel + // Contribution kernel bounds - int yy0 = destPointY - scaledRadiusY; if (yy0 < y0Skipped) yy0 = y0Skipped; - int yy1 = destPointY + scaledRadiusY; if (yy1 > y0 + height) yy1 = y0 + height; - + int yy0 = destPointY - scaledRadiusY; + if (yy0 < y0Skipped) + yy0 = y0Skipped; + int yy1 = destPointY + scaledRadiusY; + if (yy1 > y0 + height) + yy1 = y0 + height; + // For each row of the contribution circle, for (int yy = yy0; yy < yy1; yy++) { int dy = yy - destPointY; int ky = dy + scaledRadiusY; - + // Set up bounds so we only loop over what we need to int thisScaledRadiusX = context.kernelBounds[ky]; - int xx0 = destPointX - thisScaledRadiusX; if (xx0 < x0Skipped) xx0 = x0Skipped; - int xx1 = destPointX + thisScaledRadiusX; if (xx1 > x0 + width) xx1 = x0 + width; - + int xx0 = destPointX - thisScaledRadiusX; + if (xx0 < x0Skipped) + xx0 = x0Skipped; + int xx1 = destPointX + thisScaledRadiusX; + if (xx1 > x0 + width) + xx1 = x0 + width; + // For each point on that row for (int xx = xx0; xx < xx1; xx++) { int dx = xx - destPointX; int kx = dx + scaledRadiusX; - - // gOff accounts for our choice to offset the pre-generated kernel by (0.5, 0.5) to avoid the zero center. - // I found almost no difference in performance using gOff vs not (under 1ns diff per value on my system) + + // gOff accounts for our choice to offset the pre-generated + // kernel by (0.5, 0.5) to avoid the zero center. + // I found almost no difference in performance using gOff vs + // not (under 1ns diff per value on my system) double extrapolation = gx * dx + gy * dy + gOff; buffer[yy - y0][xx - x0] += kernel[ky][kx] * extrapolation; - + } } - + // For each neighbor of the point for (int i = 0; i < NEIGHBOR_MAP_2D.length; i++) { - AreaGenLatticePoint2D neighbor = new AreaGenLatticePoint2D(context, - point.xsv + NEIGHBOR_MAP_2D[i][0], point.ysv + NEIGHBOR_MAP_2D[i][1]); - + AreaGenLatticePoint2D neighbor = new AreaGenLatticePoint2D(context, point.xsv + NEIGHBOR_MAP_2D[i][0], + point.ysv + NEIGHBOR_MAP_2D[i][1]); + // If it's in range of the buffer region and not seen before - if (neighbor.destPointX + scaledRadiusX >= x0Skipped && neighbor.destPointX - scaledRadiusX <= x0 + width - 1 - && neighbor.destPointY + scaledRadiusY >= y0Skipped && neighbor.destPointY - scaledRadiusY <= y0 + height - 1 - && !seen.contains(neighbor)) { - + if (neighbor.destPointX + scaledRadiusX >= x0Skipped + && neighbor.destPointX - scaledRadiusX <= x0 + width - 1 + && neighbor.destPointY + scaledRadiusY >= y0Skipped + && neighbor.destPointY - scaledRadiusY <= y0 + height - 1 && !seen.contains(neighbor)) { + // Add it to the queue so we can process it at some point queue.add(neighbor); - + // Add it to the set so we don't add it to the queue again seen.add(neighbor); } } } } - + /** - * Generate the 3D noise over a large area/volume. - * Propagates by flood-fill instead of iterating over a range. - * Results may occasionally slightly exceed [-1, 1] due to the grid-snapped pre-generated kernel. + * Generate the 3D noise over a large area/volume. Propagates by flood-fill + * instead of iterating over a range. Results may occasionally slightly + * exceed [-1, 1] due to the grid-snapped pre-generated kernel. */ public void generate3(GenerateContext3D context, double[][][] buffer, int x0, int y0, int z0) { int depth = buffer.length; @@ -347,121 +369,142 @@ public class OpenSimplex2S { int width = buffer[0][0].length; generate3(context, buffer, x0, y0, z0, width, height, depth, 0, 0, 0); } - + /** - * Generate the 3D noise over a large area/volume. - * Propagates by flood-fill instead of iterating over a range. - * Results may occasionally slightly exceed [-1, 1] due to the grid-snapped pre-generated kernel. + * Generate the 3D noise over a large area/volume. Propagates by flood-fill + * instead of iterating over a range. Results may occasionally slightly + * exceed [-1, 1] due to the grid-snapped pre-generated kernel. */ - public void generate3(GenerateContext3D context, double[][][] buffer, int x0, int y0, int z0, int width, int height, int depth, int skipX, int skipY, int skipZ) { + public void generate3(GenerateContext3D context, double[][][] buffer, int x0, int y0, int z0, int width, int height, + int depth, int skipX, int skipY, int skipZ) { Queue queue = new LinkedList(); Set seen = new HashSet(); - + int scaledRadiusX = context.scaledRadiusX; int scaledRadiusY = context.scaledRadiusY; int scaledRadiusZ = context.scaledRadiusZ; double[][][] kernel = context.kernel; int x0Skipped = x0 + skipX, y0Skipped = y0 + skipY, z0Skipped = z0 + skipZ; - + // Quaternion multiplication for rotation. // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ - double qx = context.orientation.qx, qy = context.orientation.qy, qz = context.orientation.qz, qw = context.orientation.qw; - double x0f = x0Skipped * context.xFrequency, y0f = y0Skipped * context.yFrequency, z0f = z0Skipped * context.zFrequency; + double qx = context.orientation.qx, qy = context.orientation.qy, qz = context.orientation.qz, + qw = context.orientation.qw; + double x0f = x0Skipped * context.xFrequency, y0f = y0Skipped * context.yFrequency, + z0f = z0Skipped * context.zFrequency; double tx = 2 * (qy * z0f - qz * y0f); double ty = 2 * (qz * x0f - qx * z0f); double tz = 2 * (qx * y0f - qy * x0f); double x0r = x0f + qw * tx + (qy * tz - qz * ty); double y0r = y0f + qw * ty + (qz * tx - qx * tz); double z0r = z0f + qw * tz + (qx * ty - qy * tx); - + int x0rb = fastFloor(x0r), y0rb = fastFloor(y0r), z0rb = fastFloor(z0r); - + AreaGenLatticePoint3D firstPoint = new AreaGenLatticePoint3D(context, x0rb, y0rb, z0rb, 0); queue.add(firstPoint); seen.add(firstPoint); - + while (!queue.isEmpty()) { AreaGenLatticePoint3D point = queue.remove(); int destPointX = point.destPointX; int destPointY = point.destPointY; int destPointZ = point.destPointZ; - + // Prepare gradient vector int pxm = point.xsv & PMASK, pym = point.ysv & PMASK, pzm = point.zsv & PMASK; Grad3 grad = context.orientation.gradients[perm[perm[perm[pxm] ^ pym] ^ pzm]]; double gx = grad.dx * context.xFrequency; double gy = grad.dy * context.yFrequency; double gz = grad.dz * context.zFrequency; - double gOff = 0.5 * (gx + gy + gz); // to correct for (0.5, 0.5, 0.5)-offset kernel - + double gOff = 0.5 * (gx + gy + gz); // to correct for (0.5, 0.5, + // 0.5)-offset kernel + // Contribution kernel bounds. - int zz0 = destPointZ - scaledRadiusZ; if (zz0 < z0Skipped) zz0 = z0Skipped; - int zz1 = destPointZ + scaledRadiusZ; if (zz1 > z0 + depth) zz1 = z0 + depth; - + int zz0 = destPointZ - scaledRadiusZ; + if (zz0 < z0Skipped) + zz0 = z0Skipped; + int zz1 = destPointZ + scaledRadiusZ; + if (zz1 > z0 + depth) + zz1 = z0 + depth; + // For each x/y slice of the contribution sphere, for (int zz = zz0; zz < zz1; zz++) { int dz = zz - destPointZ; int kz = dz + scaledRadiusZ; - + // Set up bounds so we only loop over what we need to int thisScaledRadiusY = context.kernelBoundsY[kz]; - int yy0 = destPointY - thisScaledRadiusY; if (yy0 < y0Skipped) yy0 = y0Skipped; - int yy1 = destPointY + thisScaledRadiusY; if (yy1 > y0 + height) yy1 = y0 + height; - + int yy0 = destPointY - thisScaledRadiusY; + if (yy0 < y0Skipped) + yy0 = y0Skipped; + int yy1 = destPointY + thisScaledRadiusY; + if (yy1 > y0 + height) + yy1 = y0 + height; + // For each row of the contribution circle, for (int yy = yy0; yy < yy1; yy++) { int dy = yy - destPointY; int ky = dy + scaledRadiusY; - + // Set up bounds so we only loop over what we need to int thisScaledRadiusX = context.kernelBoundsX[kz][ky]; - int xx0 = destPointX - thisScaledRadiusX; if (xx0 < x0Skipped) xx0 = x0Skipped; - int xx1 = destPointX + thisScaledRadiusX; if (xx1 > x0 + width) xx1 = x0 + width; - + int xx0 = destPointX - thisScaledRadiusX; + if (xx0 < x0Skipped) + xx0 = x0Skipped; + int xx1 = destPointX + thisScaledRadiusX; + if (xx1 > x0 + width) + xx1 = x0 + width; + // For each point on that row for (int xx = xx0; xx < xx1; xx++) { int dx = xx - destPointX; int kx = dx + scaledRadiusX; - - // gOff accounts for our choice to offset the pre-generated kernel by (0.5, 0.5, 0.5) to avoid the zero center. + + // gOff accounts for our choice to offset the + // pre-generated kernel by (0.5, 0.5, 0.5) to avoid the + // zero center. double extrapolation = gx * dx + gy * dy + gz * dz + gOff; buffer[zz - z0][yy - y0][xx - x0] += kernel[kz][ky][kx] * extrapolation; - + } } } - + // For each neighbor of the point for (int i = 0; i < NEIGHBOR_MAP_3D[0].length; i++) { int l = point.lattice; AreaGenLatticePoint3D neighbor = new AreaGenLatticePoint3D(context, - point.xsv + NEIGHBOR_MAP_3D[l][i][0], point.ysv + NEIGHBOR_MAP_3D[l][i][1], point.zsv + NEIGHBOR_MAP_3D[l][i][2], 1 ^ l); - + point.xsv + NEIGHBOR_MAP_3D[l][i][0], point.ysv + NEIGHBOR_MAP_3D[l][i][1], + point.zsv + NEIGHBOR_MAP_3D[l][i][2], 1 ^ l); + // If it's in range of the buffer region and not seen before - if (neighbor.destPointX + scaledRadiusX >= x0Skipped && neighbor.destPointX - scaledRadiusX <= x0 + width - 1 - && neighbor.destPointY + scaledRadiusY >= y0Skipped && neighbor.destPointY - scaledRadiusY <= y0 + height - 1 - && neighbor.destPointZ + scaledRadiusZ >= z0Skipped && neighbor.destPointZ - scaledRadiusZ <= z0 + depth - 1 - && !seen.contains(neighbor)) { - + if (neighbor.destPointX + scaledRadiusX >= x0Skipped + && neighbor.destPointX - scaledRadiusX <= x0 + width - 1 + && neighbor.destPointY + scaledRadiusY >= y0Skipped + && neighbor.destPointY - scaledRadiusY <= y0 + height - 1 + && neighbor.destPointZ + scaledRadiusZ >= z0Skipped + && neighbor.destPointZ - scaledRadiusZ <= z0 + depth - 1 && !seen.contains(neighbor)) { + // Add it to the queue so we can process it at some point queue.add(neighbor); - + // Add it to the set so we don't add it to the queue again seen.add(neighbor); } } } } - + /* * Utility */ - + private static int fastFloor(double x) { - int xi = (int)x; + int xi = (int) x; return x < xi ? xi - 1 : xi; } - + /* * Definitions */ @@ -471,186 +514,242 @@ public class OpenSimplex2S { static { LOOKUP_2D = new LatticePoint2D[8 * 4]; LOOKUP_3D = new LatticePoint3D[8]; - + for (int i = 0; i < 8; i++) { int i1, j1, i2, j2; if ((i & 1) == 0) { - if ((i & 2) == 0) { i1 = -1; j1 = 0; } else { i1 = 1; j1 = 0; } - if ((i & 4) == 0) { i2 = 0; j2 = -1; } else { i2 = 0; j2 = 1; } + if ((i & 2) == 0) { + i1 = -1; + j1 = 0; + } else { + i1 = 1; + j1 = 0; + } + if ((i & 4) == 0) { + i2 = 0; + j2 = -1; + } else { + i2 = 0; + j2 = 1; + } } else { - if ((i & 2) != 0) { i1 = 2; j1 = 1; } else { i1 = 0; j1 = 1; } - if ((i & 4) != 0) { i2 = 1; j2 = 2; } else { i2 = 1; j2 = 0; } + if ((i & 2) != 0) { + i1 = 2; + j1 = 1; + } else { + i1 = 0; + j1 = 1; + } + if ((i & 4) != 0) { + i2 = 1; + j2 = 2; + } else { + i2 = 1; + j2 = 0; + } } LOOKUP_2D[i * 4 + 0] = new LatticePoint2D(0, 0); LOOKUP_2D[i * 4 + 1] = new LatticePoint2D(1, 1); LOOKUP_2D[i * 4 + 2] = new LatticePoint2D(i1, j1); LOOKUP_2D[i * 4 + 3] = new LatticePoint2D(i2, j2); } - + for (int i = 0; i < 8; i++) { int i1, j1, k1, i2, j2, k2; - i1 = (i >> 0) & 1; j1 = (i >> 1) & 1; k1 = (i >> 2) & 1; - i2 = i1 ^ 1; j2 = j1 ^ 1; k2 = k1 ^ 1; - - // The two points within this octant, one from each of the two cubic half-lattices. + i1 = (i >> 0) & 1; + j1 = (i >> 1) & 1; + k1 = (i >> 2) & 1; + i2 = i1 ^ 1; + j2 = j1 ^ 1; + k2 = k1 ^ 1; + + // The two points within this octant, one from each of the two cubic + // half-lattices. LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0); LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1); - + // (1, 0, 0) vs (0, 1, 1) away from octant. LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0); LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1 ^ 1, 0); - + // (1, 0, 0) vs (0, 1, 1) away from octant, on second half-lattice. LatticePoint3D c4 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1); LatticePoint3D c5 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + (k2 ^ 1), 1); - + // (0, 1, 0) vs (1, 0, 1) away from octant. LatticePoint3D c6 = new LatticePoint3D(i1, j1 ^ 1, k1, 0); LatticePoint3D c7 = new LatticePoint3D(i1 ^ 1, j1, k1 ^ 1, 0); - + // (0, 1, 0) vs (1, 0, 1) away from octant, on second half-lattice. LatticePoint3D c8 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1); LatticePoint3D c9 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + (k2 ^ 1), 1); - + // (0, 0, 1) vs (1, 1, 0) away from octant. LatticePoint3D cA = new LatticePoint3D(i1, j1, k1 ^ 1, 0); LatticePoint3D cB = new LatticePoint3D(i1 ^ 1, j1 ^ 1, k1, 0); - + // (0, 0, 1) vs (1, 1, 0) away from octant, on second half-lattice. LatticePoint3D cC = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1); LatticePoint3D cD = new LatticePoint3D(i1 + (i2 ^ 1), j1 + (j2 ^ 1), k1 + k2, 1); - + // First two points are guaranteed. c0.nextOnFailure = c0.nextOnSuccess = c1; c1.nextOnFailure = c1.nextOnSuccess = c2; - + // If c2 is in range, then we know c3 and c4 are not. - c2.nextOnFailure = c3; c2.nextOnSuccess = c5; - c3.nextOnFailure = c4; c3.nextOnSuccess = c4; - + c2.nextOnFailure = c3; + c2.nextOnSuccess = c5; + c3.nextOnFailure = c4; + c3.nextOnSuccess = c4; + // If c4 is in range, then we know c5 is not. - c4.nextOnFailure = c5; c4.nextOnSuccess = c6; + c4.nextOnFailure = c5; + c4.nextOnSuccess = c6; c5.nextOnFailure = c5.nextOnSuccess = c6; - + // If c6 is in range, then we know c7 and c8 are not. - c6.nextOnFailure = c7; c6.nextOnSuccess = c9; - c7.nextOnFailure = c8; c7.nextOnSuccess = c8; - + c6.nextOnFailure = c7; + c6.nextOnSuccess = c9; + c7.nextOnFailure = c8; + c7.nextOnSuccess = c8; + // If c8 is in range, then we know c9 is not. - c8.nextOnFailure = c9; c8.nextOnSuccess = cA; + c8.nextOnFailure = c9; + c8.nextOnSuccess = cA; c9.nextOnFailure = c9.nextOnSuccess = cA; - + // If cA is in range, then we know cB and cC are not. - cA.nextOnFailure = cB; cA.nextOnSuccess = cD; - cB.nextOnFailure = cC; cB.nextOnSuccess = cC; - + cA.nextOnFailure = cB; + cA.nextOnSuccess = cD; + cB.nextOnFailure = cC; + cB.nextOnSuccess = cC; + // If cC is in range, then we know cD is not. - cC.nextOnFailure = cD; cC.nextOnSuccess = null; + cC.nextOnFailure = cD; + cC.nextOnSuccess = null; cD.nextOnFailure = cD.nextOnSuccess = null; - + LOOKUP_3D[i] = c0; - + } } - + // Hexagon surrounding each vertex. - private static final int[][] NEIGHBOR_MAP_2D = { - { 1, 0 }, { 1, 1 }, { 0, 1 }, { 0, -1 }, { -1, -1 }, { -1, 0 } - }; - + private static final int[][] NEIGHBOR_MAP_2D = { { 1, 0 }, { 1, 1 }, { 0, 1 }, { 0, -1 }, { -1, -1 }, { -1, 0 } }; + // Cube surrounding each vertex. // Alternates between half-lattices. private static final int[][][] NEIGHBOR_MAP_3D = { - { - { 1024, 1024, 1024 }, { 1025, 1024, 1024 }, { 1024, 1025, 1024 }, { 1025, 1025, 1024 }, - { 1024, 1024, 1025 }, { 1025, 1024, 1025 }, { 1024, 1025, 1025 }, { 1025, 1025, 1025 } - }, - { - { -1024, -1024, -1024 }, { -1025, -1024, 1024 }, { -1024, -1025, -1024 }, { -1025, -1025, -1024 }, - { -1024, -1024, -1025 }, { -1025, -1024, -1025 }, { -1024, -1025, -1025 }, { -1025, -1025, 1025 } - }, - }; - + { { 1024, 1024, 1024 }, { 1025, 1024, 1024 }, { 1024, 1025, 1024 }, { 1025, 1025, 1024 }, + { 1024, 1024, 1025 }, { 1025, 1024, 1025 }, { 1024, 1025, 1025 }, { 1025, 1025, 1025 } }, + { { -1024, -1024, -1024 }, { -1025, -1024, 1024 }, { -1024, -1025, -1024 }, { -1025, -1025, -1024 }, + { -1024, -1024, -1025 }, { -1025, -1024, -1025 }, { -1024, -1025, -1025 }, + { -1025, -1025, 1025 } }, }; + private static class LatticePoint2D { int xsv, ysv; double dx, dy; + public LatticePoint2D(int xsv, int ysv) { - this.xsv = xsv; this.ysv = ysv; + this.xsv = xsv; + this.ysv = ysv; double ssv = (xsv + ysv) * -0.211324865405187; this.dx = -xsv - ssv; this.dy = -ysv - ssv; } } - + private static class LatticePoint3D { public double dxr, dyr, dzr; public int xrv, yrv, zrv; LatticePoint3D nextOnFailure, nextOnSuccess; + public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) { - this.dxr = -xrv + lattice * 0.5; this.dyr = -yrv + lattice * 0.5; this.dzr = -zrv + lattice * 0.5; - this.xrv = xrv + lattice * 1024; this.yrv = yrv + lattice * 1024; this.zrv = zrv + lattice * 1024; + this.dxr = -xrv + lattice * 0.5; + this.dyr = -yrv + lattice * 0.5; + this.dzr = -zrv + lattice * 0.5; + this.xrv = xrv + lattice * 1024; + this.yrv = yrv + lattice * 1024; + this.zrv = zrv + lattice * 1024; } } - + private static class AreaGenLatticePoint2D { int xsv, ysv; int destPointX, destPointY; + public AreaGenLatticePoint2D(GenerateContext2D context, int xsv, int ysv) { - this.xsv = xsv; this.ysv = ysv; - - //Matrix multiplication for inverse rotation. Simplex skew transforms have always been shorthand for matrices. - this.destPointX = (int)Math.ceil((context.orientation.t00 * xsv + context.orientation.t01 * ysv) * context.xFrequencyInverse); - this.destPointY = (int)Math.ceil((context.orientation.t10 * xsv + context.orientation.t11 * ysv) * context.yFrequencyInverse); + this.xsv = xsv; + this.ysv = ysv; + + // Matrix multiplication for inverse rotation. Simplex skew + // transforms have always been shorthand for matrices. + this.destPointX = (int) Math + .ceil((context.orientation.t00 * xsv + context.orientation.t01 * ysv) * context.xFrequencyInverse); + this.destPointY = (int) Math + .ceil((context.orientation.t10 * xsv + context.orientation.t11 * ysv) * context.yFrequencyInverse); } + @Override public int hashCode() { return xsv * 7841 + ysv; } + @Override public boolean equals(Object obj) { - if (!(obj instanceof AreaGenLatticePoint2D)) return false; + if (!(obj instanceof AreaGenLatticePoint2D)) + return false; AreaGenLatticePoint2D other = (AreaGenLatticePoint2D) obj; return (other.xsv == this.xsv && other.ysv == this.ysv); } } - + private static class AreaGenLatticePoint3D { int xsv, ysv, zsv, lattice; int destPointX, destPointY, destPointZ; + public AreaGenLatticePoint3D(GenerateContext3D context, int xsv, int ysv, int zsv, int lattice) { - this.xsv = xsv; this.ysv = ysv; this.zsv = zsv; this.lattice = lattice; + this.xsv = xsv; + this.ysv = ysv; + this.zsv = zsv; + this.lattice = lattice; double xr = (xsv - lattice * 1024.5); double yr = (ysv - lattice * 1024.5); double zr = (zsv - lattice * 1024.5); - + // Quaternion multiplication for inverse rotation. // https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/ - double qx = -context.orientation.qx, qy = -context.orientation.qy, qz = -context.orientation.qz, qw = context.orientation.qw; + double qx = -context.orientation.qx, qy = -context.orientation.qy, qz = -context.orientation.qz, + qw = context.orientation.qw; double tx = 2 * (qy * zr - qz * yr); double ty = 2 * (qz * xr - qx * zr); double tz = 2 * (qx * yr - qy * xr); double xrr = xr + qw * tx + (qy * tz - qz * ty); double yrr = yr + qw * ty + (qz * tx - qx * tz); double zrr = zr + qw * tz + (qx * ty - qy * tx); - - this.destPointX = (int)Math.ceil(xrr * context.xFrequencyInverse); - this.destPointY = (int)Math.ceil(yrr * context.yFrequencyInverse); - this.destPointZ = (int)Math.ceil(zrr * context.zFrequencyInverse); + + this.destPointX = (int) Math.ceil(xrr * context.xFrequencyInverse); + this.destPointY = (int) Math.ceil(yrr * context.yFrequencyInverse); + this.destPointZ = (int) Math.ceil(zrr * context.zFrequencyInverse); } + @Override public int hashCode() { return xsv * 2122193 + ysv * 2053 + zsv * 2 + lattice; } + @Override public boolean equals(Object obj) { - if (!(obj instanceof AreaGenLatticePoint3D)) return false; + if (!(obj instanceof AreaGenLatticePoint3D)) + return false; AreaGenLatticePoint3D other = (AreaGenLatticePoint3D) obj; - return (other.xsv == this.xsv && other.ysv == this.ysv && other.zsv == this.zsv && other.lattice == this.lattice); + return (other.xsv == this.xsv && other.ysv == this.ysv && other.zsv == this.zsv + && other.lattice == this.lattice); } } - + public static class GenerateContext2D { - + double xFrequency; double yFrequency; double xFrequencyInverse; @@ -660,37 +759,37 @@ public class OpenSimplex2S { double[][] kernel; int[] kernelBounds; LatticeOrientation2D orientation; - - public GenerateContext2D(LatticeOrientation2D orientation, double xFrequency, double yFrequency, double amplitude) { - + + public GenerateContext2D(LatticeOrientation2D orientation, double xFrequency, double yFrequency, + double amplitude) { + // These will be used by every call to generate this.orientation = orientation; this.xFrequency = xFrequency; this.yFrequency = yFrequency; this.xFrequencyInverse = 1.0 / xFrequency; this.yFrequencyInverse = 1.0 / yFrequency; - + double preciseScaledRadiusX = Math.sqrt(2.0 / 3.0) * xFrequencyInverse; double preciseScaledRadiusY = Math.sqrt(2.0 / 3.0) * yFrequencyInverse; - + // 0.25 because we offset center by 0.5 - this.scaledRadiusX = (int)Math.ceil(preciseScaledRadiusX + 0.25); - this.scaledRadiusY = (int)Math.ceil(preciseScaledRadiusY + 0.25); - + this.scaledRadiusX = (int) Math.ceil(preciseScaledRadiusX + 0.25); + this.scaledRadiusY = (int) Math.ceil(preciseScaledRadiusY + 0.25); + // So will these - kernel = new double[scaledRadiusY/* * 2*/][]; + kernel = new double[scaledRadiusY/* * 2 */][]; kernelBounds = new int[scaledRadiusY * 2]; for (int yy = 0; yy < scaledRadiusY * 2; yy++) { - + // Pre-generate boundary of circle - kernelBounds[yy] = (int)Math.ceil( - Math.sqrt(1.0 - - (yy + 0.5 - scaledRadiusY) * (yy + 0.5 - scaledRadiusY) / (scaledRadiusY * scaledRadiusY) - ) * scaledRadiusX); - + kernelBounds[yy] = (int) Math.ceil(Math.sqrt( + 1.0 - (yy + 0.5 - scaledRadiusY) * (yy + 0.5 - scaledRadiusY) / (scaledRadiusY * scaledRadiusY)) + * scaledRadiusX); + if (yy < scaledRadiusY) { kernel[yy] = new double[scaledRadiusX * 2]; - + // Pre-generate kernel for (int xx = 0; xx < scaledRadiusX * 2; xx++) { double dx = (xx + 0.5 - scaledRadiusX) * xFrequency; @@ -703,13 +802,13 @@ public class OpenSimplex2S { kernel[yy][xx] = 0.0; } } - } /* else kernel[yy] = kernel[2 * scaledRadiusY - yy - 1];*/ + } /* else kernel[yy] = kernel[2 * scaledRadiusY - yy - 1]; */ } } } - + public static class GenerateContext3D { - + double xFrequency; double yFrequency; double zFrequency; @@ -723,9 +822,10 @@ public class OpenSimplex2S { int[] kernelBoundsY; int[][] kernelBoundsX; LatticeOrientation3D orientation; - - public GenerateContext3D(LatticeOrientation3D orientation, double xFrequency, double yFrequency, double zFrequency, double amplitude) { - + + public GenerateContext3D(LatticeOrientation3D orientation, double xFrequency, double yFrequency, + double zFrequency, double amplitude) { + // These will be used by every call to generate this.orientation = orientation; this.xFrequency = xFrequency; @@ -734,27 +834,27 @@ public class OpenSimplex2S { this.xFrequencyInverse = 1.0 / xFrequency; this.yFrequencyInverse = 1.0 / yFrequency; this.zFrequencyInverse = 1.0 / zFrequency; - + double preciseScaledRadiusX = Math.sqrt(0.75) * xFrequencyInverse; double preciseScaledRadiusY = Math.sqrt(0.75) * yFrequencyInverse; double preciseScaledRadiusZ = Math.sqrt(0.75) * zFrequencyInverse; - + // 0.25 because we offset center by 0.5 - this.scaledRadiusX = (int)Math.ceil(preciseScaledRadiusX + 0.25); - this.scaledRadiusY = (int)Math.ceil(preciseScaledRadiusY + 0.25); - this.scaledRadiusZ = (int)Math.ceil(preciseScaledRadiusZ + 0.25); - + this.scaledRadiusX = (int) Math.ceil(preciseScaledRadiusX + 0.25); + this.scaledRadiusY = (int) Math.ceil(preciseScaledRadiusY + 0.25); + this.scaledRadiusZ = (int) Math.ceil(preciseScaledRadiusZ + 0.25); + // So will these kernel = new double[scaledRadiusZ * 2][][]; kernelBoundsY = new int[scaledRadiusZ * 2]; kernelBoundsX = new int[scaledRadiusZ * 2][]; for (int zz = 0; zz < scaledRadiusZ * 2; zz++) { - + // Pre-generate boundary of sphere - kernelBoundsY[zz] = (int)Math.ceil( - Math.sqrt(1.0 - (zz + 0.5 - scaledRadiusZ) * (zz + 0.5 - scaledRadiusZ) - / (scaledRadiusZ * scaledRadiusZ)) * scaledRadiusY); - + kernelBoundsY[zz] = (int) Math.ceil(Math.sqrt( + 1.0 - (zz + 0.5 - scaledRadiusZ) * (zz + 0.5 - scaledRadiusZ) / (scaledRadiusZ * scaledRadiusZ)) + * scaledRadiusY); + if (zz < scaledRadiusZ) { kernel[zz] = new double[scaledRadiusY * 2][]; kernelBoundsX[zz] = new int[scaledRadiusY * 2]; @@ -762,20 +862,21 @@ public class OpenSimplex2S { kernel[zz] = kernel[2 * scaledRadiusZ - zz - 1]; kernelBoundsX[zz] = kernelBoundsX[2 * scaledRadiusZ - zz - 1]; } - + if (zz < scaledRadiusZ) { for (int yy = 0; yy < scaledRadiusY * 2; yy++) { - + // Pre-generate boundary of sphere - kernelBoundsX[zz][yy] = (int)Math.ceil( - Math.sqrt(1.0 - - (yy + 0.5 - scaledRadiusY) * (yy + 0.5 - scaledRadiusY) / (scaledRadiusY * scaledRadiusY) - - (zz + 0.5 - scaledRadiusZ) * (zz + 0.5 - scaledRadiusZ) / (scaledRadiusZ * scaledRadiusZ) - ) * scaledRadiusX); - + kernelBoundsX[zz][yy] = (int) Math.ceil(Math.sqrt(1.0 + - (yy + 0.5 - scaledRadiusY) * (yy + 0.5 - scaledRadiusY) + / (scaledRadiusY * scaledRadiusY) + - (zz + 0.5 - scaledRadiusZ) * (zz + 0.5 - scaledRadiusZ) + / (scaledRadiusZ * scaledRadiusZ)) + * scaledRadiusX); + if (yy < scaledRadiusY) { kernel[zz][yy] = new double[scaledRadiusX * 2]; - + // Pre-generate kernel for (int xx = 0; xx < scaledRadiusX * 2; xx++) { double dx = (xx + 0.5 - scaledRadiusX) * xFrequency; @@ -789,108 +890,112 @@ public class OpenSimplex2S { kernel[zz][yy][xx] = 0.0; } } - - } else kernel[zz][yy] = kernel[zz][2 * scaledRadiusY - yy - 1]; + + } else + kernel[zz][yy] = kernel[zz][2 * scaledRadiusY - yy - 1]; } } } } } - + public enum LatticeOrientation2D { - // Simplex skew transforms have always been shorthand for the matrices they represent. - // But when we bake the rotation into the skew transform, we need to use the general form. - Standard(GRADIENTS_2D, - 1.366025403784439, 0.366025403784439, 0.366025403784439, 1.366025403784439, - 0.788675134594813, -0.211324865405187, -0.211324865405187, 0.788675134594813), - XBeforeY(GRADIENTS_2D_X_BEFORE_Y, - 0.7071067811865476, 1.224744871380249, -0.7071067811865476, 1.224744871380249, - 0.7071067811865476, -0.7071067811865476, 0.40824829046764305, 0.40824829046764305); - + // Simplex skew transforms have always been shorthand for the matrices + // they represent. + // But when we bake the rotation into the skew transform, we need to use + // the general form. + Standard(GRADIENTS_2D, 1.366025403784439, 0.366025403784439, 0.366025403784439, 1.366025403784439, + 0.788675134594813, -0.211324865405187, -0.211324865405187, + 0.788675134594813), XBeforeY(GRADIENTS_2D_X_BEFORE_Y, 0.7071067811865476, 1.224744871380249, + -0.7071067811865476, 1.224744871380249, 0.7071067811865476, -0.7071067811865476, + 0.40824829046764305, 0.40824829046764305); + Grad2[] gradients; double s00, s01, s10, s11; double t00, t01, t10, t11; - - private LatticeOrientation2D(Grad2[] gradients, - double s00, double s01, double s10, double s11, - double t00, double t01, double t10, double t11) { + + private LatticeOrientation2D(Grad2[] gradients, double s00, double s01, double s10, double s11, double t00, + double t01, double t10, double t11) { this.gradients = gradients; - this.s00 = s00; this.s01 = s01; this.s10 = s10; this.s11 = s11; - this.t00 = t00; this.t01 = t01; this.t10 = t10; this.t11 = t11; + this.s00 = s00; + this.s01 = s01; + this.s10 = s10; + this.s11 = s11; + this.t00 = t00; + this.t01 = t01; + this.t10 = t10; + this.t11 = t11; } } - + public enum LatticeOrientation3D { - // Quaternions for 3D. Could use matrices, but I already wrote this code before I moved them into here. - Classic(GRADIENTS_3D_CLASSIC, 0.577350269189626, 0.577350269189626, 0.577350269189626, 0), - XYBeforeZ(GRADIENTS_3D_XY_BEFORE_Z, 0.3250575836718682, -0.3250575836718682, 0, 0.8880738339771154), - XZBeforeY(GRADIENTS_3D_XZ_BEFORE_Y, -0.3250575836718682, 0, 0.3250575836718682, 0.8880738339771154); - + // Quaternions for 3D. Could use matrices, but I already wrote this code + // before I moved them into here. + Classic(GRADIENTS_3D_CLASSIC, 0.577350269189626, 0.577350269189626, 0.577350269189626, 0), XYBeforeZ( + GRADIENTS_3D_XY_BEFORE_Z, 0.3250575836718682, -0.3250575836718682, 0, 0.8880738339771154), XZBeforeY( + GRADIENTS_3D_XZ_BEFORE_Y, -0.3250575836718682, 0, 0.3250575836718682, 0.8880738339771154); + Grad3[] gradients; double qx, qy, qz, qw; - + private LatticeOrientation3D(Grad3[] gradients, double qx, double qy, double qz, double qw) { this.gradients = gradients; - this.qx = qx; this.qy = qy; this.qz = qz; this.qw = qw; + this.qx = qx; + this.qy = qy; + this.qz = qz; + this.qw = qw; } } - + /* * Gradients */ - + public static class Grad2 { double dx, dy; + public Grad2(double dx, double dy) { - this.dx = dx; this.dy = dy; + this.dx = dx; + this.dy = dy; } } - + public static class Grad3 { double dx, dy, dz; + public Grad3(double dx, double dy, double dz) { - this.dx = dx; this.dy = dy; this.dz = dz; + this.dx = dx; + this.dy = dy; + this.dz = dz; } } - + public static final double N2 = 0.05481866495625118; public static final double N3 = 0.2781926117527186; private static final Grad2[] GRADIENTS_2D, GRADIENTS_2D_X_BEFORE_Y; private static final Grad3[] GRADIENTS_3D, GRADIENTS_3D_CLASSIC, GRADIENTS_3D_XY_BEFORE_Z, GRADIENTS_3D_XZ_BEFORE_Y; static { - + GRADIENTS_2D = new Grad2[PSIZE]; GRADIENTS_2D_X_BEFORE_Y = new Grad2[PSIZE]; - Grad2[] grad2 = { - new Grad2( 0.130526192220052, 0.99144486137381), - new Grad2( 0.38268343236509, 0.923879532511287), - new Grad2( 0.608761429008721, 0.793353340291235), - new Grad2( 0.793353340291235, 0.608761429008721), - new Grad2( 0.923879532511287, 0.38268343236509), - new Grad2( 0.99144486137381, 0.130526192220051), - new Grad2( 0.99144486137381, -0.130526192220051), - new Grad2( 0.923879532511287, -0.38268343236509), - new Grad2( 0.793353340291235, -0.60876142900872), - new Grad2( 0.608761429008721, -0.793353340291235), - new Grad2( 0.38268343236509, -0.923879532511287), - new Grad2( 0.130526192220052, -0.99144486137381), - new Grad2(-0.130526192220052, -0.99144486137381), - new Grad2(-0.38268343236509, -0.923879532511287), - new Grad2(-0.608761429008721, -0.793353340291235), - new Grad2(-0.793353340291235, -0.608761429008721), - new Grad2(-0.923879532511287, -0.38268343236509), - new Grad2(-0.99144486137381, -0.130526192220052), - new Grad2(-0.99144486137381, 0.130526192220051), - new Grad2(-0.923879532511287, 0.38268343236509), - new Grad2(-0.793353340291235, 0.608761429008721), - new Grad2(-0.608761429008721, 0.793353340291235), - new Grad2(-0.38268343236509, 0.923879532511287), - new Grad2(-0.130526192220052, 0.99144486137381) - }; + Grad2[] grad2 = { new Grad2(0.130526192220052, 0.99144486137381), + new Grad2(0.38268343236509, 0.923879532511287), new Grad2(0.608761429008721, 0.793353340291235), + new Grad2(0.793353340291235, 0.608761429008721), new Grad2(0.923879532511287, 0.38268343236509), + new Grad2(0.99144486137381, 0.130526192220051), new Grad2(0.99144486137381, -0.130526192220051), + new Grad2(0.923879532511287, -0.38268343236509), new Grad2(0.793353340291235, -0.60876142900872), + new Grad2(0.608761429008721, -0.793353340291235), new Grad2(0.38268343236509, -0.923879532511287), + new Grad2(0.130526192220052, -0.99144486137381), new Grad2(-0.130526192220052, -0.99144486137381), + new Grad2(-0.38268343236509, -0.923879532511287), new Grad2(-0.608761429008721, -0.793353340291235), + new Grad2(-0.793353340291235, -0.608761429008721), new Grad2(-0.923879532511287, -0.38268343236509), + new Grad2(-0.99144486137381, -0.130526192220052), new Grad2(-0.99144486137381, 0.130526192220051), + new Grad2(-0.923879532511287, 0.38268343236509), new Grad2(-0.793353340291235, 0.608761429008721), + new Grad2(-0.608761429008721, 0.793353340291235), new Grad2(-0.38268343236509, 0.923879532511287), + new Grad2(-0.130526192220052, 0.99144486137381) }; Grad2[] grad2XBeforeY = new Grad2[grad2.length]; for (int i = 0; i < grad2.length; i++) { - grad2[i].dx /= N2; grad2[i].dy /= N2; - + grad2[i].dx /= N2; + grad2[i].dy /= N2; + // Unrotated gradients for XBeforeY 2D double xx = grad2[i].dx * 0.7071067811865476; double yy = grad2[i].dy * 0.7071067811865476; @@ -900,82 +1005,64 @@ public class OpenSimplex2S { GRADIENTS_2D[i] = grad2[i % grad2.length]; GRADIENTS_2D_X_BEFORE_Y[i] = grad2XBeforeY[i % grad2XBeforeY.length]; } - + GRADIENTS_3D = new Grad3[PSIZE]; GRADIENTS_3D_CLASSIC = new Grad3[PSIZE]; GRADIENTS_3D_XY_BEFORE_Z = new Grad3[PSIZE]; GRADIENTS_3D_XZ_BEFORE_Y = new Grad3[PSIZE]; - Grad3[] grad3 = { - new Grad3(-2.22474487139, -2.22474487139, -1.0), - new Grad3(-2.22474487139, -2.22474487139, 1.0), - new Grad3(-3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3(-1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3(-2.22474487139, -1.0, -2.22474487139), - new Grad3(-2.22474487139, 1.0, -2.22474487139), - new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3(-2.22474487139, -1.0, 2.22474487139), - new Grad3(-2.22474487139, 1.0, 2.22474487139), - new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3(-1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3(-2.22474487139, 2.22474487139, -1.0), - new Grad3(-2.22474487139, 2.22474487139, 1.0), - new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0), - new Grad3(-3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3(-1.0, -2.22474487139, -2.22474487139), - new Grad3( 1.0, -2.22474487139, -2.22474487139), - new Grad3( 0.0, -3.0862664687972017, -1.1721513422464978), - new Grad3( 0.0, -1.1721513422464978, -3.0862664687972017), - new Grad3(-1.0, -2.22474487139, 2.22474487139), - new Grad3( 1.0, -2.22474487139, 2.22474487139), - new Grad3( 0.0, -1.1721513422464978, 3.0862664687972017), - new Grad3( 0.0, -3.0862664687972017, 1.1721513422464978), - new Grad3(-1.0, 2.22474487139, -2.22474487139), - new Grad3( 1.0, 2.22474487139, -2.22474487139), - new Grad3( 0.0, 1.1721513422464978, -3.0862664687972017), - new Grad3( 0.0, 3.0862664687972017, -1.1721513422464978), - new Grad3(-1.0, 2.22474487139, 2.22474487139), - new Grad3( 1.0, 2.22474487139, 2.22474487139), - new Grad3( 0.0, 3.0862664687972017, 1.1721513422464978), - new Grad3( 0.0, 1.1721513422464978, 3.0862664687972017), - new Grad3( 2.22474487139, -2.22474487139, -1.0), - new Grad3( 2.22474487139, -2.22474487139, 1.0), - new Grad3( 1.1721513422464978, -3.0862664687972017, 0.0), - new Grad3( 3.0862664687972017, -1.1721513422464978, 0.0), - new Grad3( 2.22474487139, -1.0, -2.22474487139), - new Grad3( 2.22474487139, 1.0, -2.22474487139), - new Grad3( 3.0862664687972017, 0.0, -1.1721513422464978), - new Grad3( 1.1721513422464978, 0.0, -3.0862664687972017), - new Grad3( 2.22474487139, -1.0, 2.22474487139), - new Grad3( 2.22474487139, 1.0, 2.22474487139), - new Grad3( 1.1721513422464978, 0.0, 3.0862664687972017), - new Grad3( 3.0862664687972017, 0.0, 1.1721513422464978), - new Grad3( 2.22474487139, 2.22474487139, -1.0), - new Grad3( 2.22474487139, 2.22474487139, 1.0), - new Grad3( 3.0862664687972017, 1.1721513422464978, 0.0), - new Grad3( 1.1721513422464978, 3.0862664687972017, 0.0) - }; + Grad3[] grad3 = { new Grad3(-2.22474487139, -2.22474487139, -1.0), + new Grad3(-2.22474487139, -2.22474487139, 1.0), + new Grad3(-3.0862664687972017, -1.1721513422464978, 0.0), + new Grad3(-1.1721513422464978, -3.0862664687972017, 0.0), + new Grad3(-2.22474487139, -1.0, -2.22474487139), new Grad3(-2.22474487139, 1.0, -2.22474487139), + new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017), + new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978), + new Grad3(-2.22474487139, -1.0, 2.22474487139), new Grad3(-2.22474487139, 1.0, 2.22474487139), + new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978), + new Grad3(-1.1721513422464978, 0.0, 3.0862664687972017), new Grad3(-2.22474487139, 2.22474487139, -1.0), + new Grad3(-2.22474487139, 2.22474487139, 1.0), new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0), + new Grad3(-3.0862664687972017, 1.1721513422464978, 0.0), + new Grad3(-1.0, -2.22474487139, -2.22474487139), new Grad3(1.0, -2.22474487139, -2.22474487139), + new Grad3(0.0, -3.0862664687972017, -1.1721513422464978), + new Grad3(0.0, -1.1721513422464978, -3.0862664687972017), + new Grad3(-1.0, -2.22474487139, 2.22474487139), new Grad3(1.0, -2.22474487139, 2.22474487139), + new Grad3(0.0, -1.1721513422464978, 3.0862664687972017), + new Grad3(0.0, -3.0862664687972017, 1.1721513422464978), new Grad3(-1.0, 2.22474487139, -2.22474487139), + new Grad3(1.0, 2.22474487139, -2.22474487139), new Grad3(0.0, 1.1721513422464978, -3.0862664687972017), + new Grad3(0.0, 3.0862664687972017, -1.1721513422464978), new Grad3(-1.0, 2.22474487139, 2.22474487139), + new Grad3(1.0, 2.22474487139, 2.22474487139), new Grad3(0.0, 3.0862664687972017, 1.1721513422464978), + new Grad3(0.0, 1.1721513422464978, 3.0862664687972017), new Grad3(2.22474487139, -2.22474487139, -1.0), + new Grad3(2.22474487139, -2.22474487139, 1.0), new Grad3(1.1721513422464978, -3.0862664687972017, 0.0), + new Grad3(3.0862664687972017, -1.1721513422464978, 0.0), new Grad3(2.22474487139, -1.0, -2.22474487139), + new Grad3(2.22474487139, 1.0, -2.22474487139), new Grad3(3.0862664687972017, 0.0, -1.1721513422464978), + new Grad3(1.1721513422464978, 0.0, -3.0862664687972017), new Grad3(2.22474487139, -1.0, 2.22474487139), + new Grad3(2.22474487139, 1.0, 2.22474487139), new Grad3(1.1721513422464978, 0.0, 3.0862664687972017), + new Grad3(3.0862664687972017, 0.0, 1.1721513422464978), new Grad3(2.22474487139, 2.22474487139, -1.0), + new Grad3(2.22474487139, 2.22474487139, 1.0), new Grad3(3.0862664687972017, 1.1721513422464978, 0.0), + new Grad3(1.1721513422464978, 3.0862664687972017, 0.0) }; Grad3[] grad3Classic = new Grad3[grad3.length]; Grad3[] grad3XYBeforeZ = new Grad3[grad3.length]; Grad3[] grad3XZBeforeY = new Grad3[grad3.length]; for (int i = 0; i < grad3.length; i++) { - grad3[i].dx /= N3; grad3[i].dy /= N3; grad3[i].dz /= N3; - double gxr = grad3[i].dx, gyr = grad3[i].dy, gzr = grad3[i].dz; + grad3[i].dx /= N3; + grad3[i].dy /= N3; + grad3[i].dz /= N3; + double gxr = grad3[i].dx, gyr = grad3[i].dy, gzr = grad3[i].dz; // Unrotated gradients for classic 3D double grr = (2.0 / 3.0) * (gxr + gyr + gzr); -// double dx = grr - gxr, dy = grr - gyr, dz = grr - gzr; - grad3Classic[i] = new Grad3( grr - gxr, grr - gyr, grr - gzr ); - + // double dx = grr - gxr, dy = grr - gyr, dz = grr - gzr; + grad3Classic[i] = new Grad3(grr - gxr, grr - gyr, grr - gzr); + // Unrotated gradients for XYBeforeZ 3D double s2 = (gxr + gyr) * -0.211324865405187; double zz = gzr * 0.577350269189626; - grad3XYBeforeZ[i] = new Grad3( gxr + s2 + zz, gyr + s2 + zz, (gzr - gxr - gyr) * 0.577350269189626 ); - + grad3XYBeforeZ[i] = new Grad3(gxr + s2 + zz, gyr + s2 + zz, (gzr - gxr - gyr) * 0.577350269189626); + // Unrotated gradients for plane-first 3D s2 = (gxr + gzr) * -0.211324865405187; double yy = gyr * 0.577350269189626; - grad3XZBeforeY[i] = new Grad3( gxr + s2 + yy, (gyr - gxr - gzr) * 0.577350269189626, gzr + s2 + yy ); + grad3XZBeforeY[i] = new Grad3(gxr + s2 + yy, (gyr - gxr - gzr) * 0.577350269189626, gzr + s2 + yy); } for (int i = 0; i < PSIZE; i++) { GRADIENTS_3D[i] = grad3[i % grad3.length]; diff --git a/src/main/java/ru/windcorp/jputil/ArrayUtil.java b/src/main/java/ru/windcorp/jputil/ArrayUtil.java index 4c57314..7ae5dcc 100644 --- a/src/main/java/ru/windcorp/jputil/ArrayUtil.java +++ b/src/main/java/ru/windcorp/jputil/ArrayUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil; import java.lang.reflect.Array; @@ -611,8 +611,7 @@ public class ArrayUtil { int end = offset + length; if (end > arrayLength || offset < 0) throw new IllegalArgumentException( - "Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")" - ); + "Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")"); return length; } @@ -628,8 +627,7 @@ public class ArrayUtil { if (end > arrayLength || start < 0) throw new IllegalArgumentException( - "Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")" - ); + "Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")"); return end; } diff --git a/src/main/java/ru/windcorp/jputil/CSVWriter.java b/src/main/java/ru/windcorp/jputil/CSVWriter.java index 57ddec0..b74d88c 100644 --- a/src/main/java/ru/windcorp/jputil/CSVWriter.java +++ b/src/main/java/ru/windcorp/jputil/CSVWriter.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil; import java.io.OutputStream; diff --git a/src/main/java/ru/windcorp/jputil/PrimitiveUtil.java b/src/main/java/ru/windcorp/jputil/PrimitiveUtil.java index 7579413..28c6435 100644 --- a/src/main/java/ru/windcorp/jputil/PrimitiveUtil.java +++ b/src/main/java/ru/windcorp/jputil/PrimitiveUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil; import java.util.HashMap; @@ -30,18 +30,8 @@ public class PrimitiveUtil { private static final Map, Object> PRIMITIVE_TO_NULL = new HashMap<>(); static { - for ( - Class boxed : new Class[] { - Boolean.class, - Byte.class, - Short.class, - Character.class, - Integer.class, - Long.class, - Float.class, - Double.class - } - ) { + for (Class boxed : new Class[] { Boolean.class, Byte.class, Short.class, Character.class, Integer.class, + Long.class, Float.class, Double.class }) { try { PRIMITIVE_TO_BOXED.put((Class) boxed.getField("TYPE").get(null), boxed); } catch (Exception e) { diff --git a/src/main/java/ru/windcorp/jputil/SyncStreams.java b/src/main/java/ru/windcorp/jputil/SyncStreams.java index 9b2bc3a..80ed01b 100644 --- a/src/main/java/ru/windcorp/jputil/SyncStreams.java +++ b/src/main/java/ru/windcorp/jputil/SyncStreams.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil; import java.util.function.*; @@ -40,8 +40,7 @@ import java.util.stream.Stream; /** * Contains static methods to create {@link Stream Streams} that synchronize - * their - * * terminal operations on a given monitor. * @@ -50,7 +49,7 @@ import java.util.stream.Stream; */ // SonarLint: "Stream.peek" should be used with caution (java:S3864) -// We are implementing Stream, so peek() is required. +// We are implementing Stream, so peek() is required. @SuppressWarnings("squid:S3864") public class SyncStreams { @@ -1070,21 +1069,18 @@ public class SyncStreams { } /** - * Wraps the given {@link Stream} to make all - * * terminal operations acquire the provided monitor's lock before - * execution. Intermediate operations - * return streams that are also synchronized on the same object. The created - * stream will behave identically - * to the provided stream in all other aspects. Use this to synchronize - * access to stream's source. + * execution. Intermediate operations return streams that are also + * synchronized on the same object. The created stream will behave + * identically to the provided stream in all other aspects. Use this to + * synchronize access to stream's source. *

* The returned {@code Stream}'s {@link Stream#iterator() iterator()} and - * {@link Stream#spliterator() - * spliterator()} methods return regular non-synchronized iterators and - * spliterators respectively. It - * is the user's responsibility to avoid concurrency issues: + * {@link Stream#spliterator() spliterator()} methods return regular + * non-synchronized iterators and spliterators respectively. It is the + * user's responsibility to avoid concurrency issues: * *

 	 * synchronized (stream.getMonitor()) {
@@ -1103,14 +1099,17 @@ public class SyncStreams {
 	 * stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
 	 * 
* - * @param the class of objects in the Stream - * @param stream the stream to wrap. - * @param monitor the object that the stream will use for synchronization. - * When {@code null}, the stream - * will synchronize on itself. + * @param + * the class of objects in the Stream + * @param stream + * the stream to wrap. + * @param monitor + * the object that the stream will use for synchronization. When + * {@code null}, the stream will synchronize on itself. * @return a {@link SyncStream SyncStream<T>} synchronized on * {@code monitor} and backed by {@code stream}. - * @throws NullPointerException if {@code stream == null}. + * @throws NullPointerException + * if {@code stream == null}. */ public static SyncStream synchronizedStream(Stream stream, Object monitor) { Objects.requireNonNull(stream, "stream cannot be null"); @@ -1118,22 +1117,19 @@ public class SyncStreams { } /** - * Wraps the given {@link IntStream} to make all - * * terminal operations acquire the provided monitor's lock before - * execution. Intermediate operations - * return streams that are also synchronized on the same object. The created - * stream will behave identically - * to the provided stream in all other aspects. Use this to synchronize - * access to stream's source. + * execution. Intermediate operations return streams that are also + * synchronized on the same object. The created stream will behave + * identically to the provided stream in all other aspects. Use this to + * synchronize access to stream's source. *

* The returned {@code IntStream}'s {@link IntStream#iterator() - * iterator()} and - * {@link IntStream#spliterator() spliterator()} methods return regular - * non-synchronized iterators and - * spliterators respectively. It is the user's responsibility to avoid - * concurrency issues: + * iterator()} and {@link IntStream#spliterator() spliterator()} methods + * return regular non-synchronized iterators and spliterators + * respectively. It is the user's responsibility to avoid concurrency + * issues: * *

 	 * synchronized (stream.getMonitor()) {
@@ -1152,13 +1148,15 @@ public class SyncStreams {
 	 * stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
 	 * 
* - * @param stream the stream to wrap. - * @param monitor the object that the stream will use for synchronization. - * When {@code null}, the stream - * will synchronize on itself. + * @param stream + * the stream to wrap. + * @param monitor + * the object that the stream will use for synchronization. When + * {@code null}, the stream will synchronize on itself. * @return a {@link SyncIntStream} synchronized on {@code monitor} and * backed by {@code stream}. - * @throws NullPointerException if {@code stream == null}. + * @throws NullPointerException + * if {@code stream == null}. */ public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) { Objects.requireNonNull(stream, "stream cannot be null"); @@ -1166,22 +1164,19 @@ public class SyncStreams { } /** - * Wraps the given {@link LongStream} to make all - * * terminal operations acquire the provided monitor's lock before - * execution. Intermediate operations - * return streams that are also synchronized on the same object. The created - * stream will behave identically - * to the provided stream in all other aspects. Use this to synchronize - * access to stream's source. + * execution. Intermediate operations return streams that are also + * synchronized on the same object. The created stream will behave + * identically to the provided stream in all other aspects. Use this to + * synchronize access to stream's source. *

* The returned {@code LongStream}'s {@link LongStream#iterator() - * iterator()} and - * {@link LongStream#spliterator() spliterator()} methods return regular - * non-synchronized iterators and - * spliterators respectively. It is the user's responsibility to avoid - * concurrency issues: + * iterator()} and {@link LongStream#spliterator() spliterator()} methods + * return regular non-synchronized iterators and spliterators + * respectively. It is the user's responsibility to avoid concurrency + * issues: * *

 	 * synchronized (stream.getMonitor()) {
@@ -1200,13 +1195,15 @@ public class SyncStreams {
 	 * stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
 	 * 
* - * @param stream the stream to wrap. - * @param monitor the object that the stream will use for synchronization. - * When {@code null}, the stream - * will synchronize on itself. + * @param stream + * the stream to wrap. + * @param monitor + * the object that the stream will use for synchronization. When + * {@code null}, the stream will synchronize on itself. * @return a {@link SyncLongStream} synchronized on {@code monitor} and * backed by {@code stream}. - * @throws NullPointerException if {@code stream == null}. + * @throws NullPointerException + * if {@code stream == null}. */ public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) { Objects.requireNonNull(stream, "stream cannot be null"); @@ -1214,22 +1211,19 @@ public class SyncStreams { } /** - * Wraps the given {@link DoubleStream} to make all - * * terminal operations acquire the provided monitor's lock before - * execution. Intermediate operations - * return streams that are also synchronized on the same object. The created - * stream will behave identically - * to the provided stream in all other aspects. Use this to synchronize - * access to stream's source. + * execution. Intermediate operations return streams that are also + * synchronized on the same object. The created stream will behave + * identically to the provided stream in all other aspects. Use this to + * synchronize access to stream's source. *

* The returned {@code DoubleStream}'s {@link DoubleStream#iterator() - * iterator()} and - * {@link DoubleStream#spliterator() spliterator()} methods return regular - * non-synchronized iterators and - * spliterators respectively. It is the user's responsibility to avoid - * concurrency issues: + * iterator()} and {@link DoubleStream#spliterator() spliterator()} methods + * return regular non-synchronized iterators and spliterators + * respectively. It is the user's responsibility to avoid concurrency + * issues: * *

 	 * synchronized (stream.getMonitor()) {
@@ -1248,13 +1242,15 @@ public class SyncStreams {
 	 * stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
 	 * 
* - * @param stream the stream to wrap. - * @param monitor the object that the stream will use for synchronization. - * When {@code null}, the stream - * will synchronize on itself. + * @param stream + * the stream to wrap. + * @param monitor + * the object that the stream will use for synchronization. When + * {@code null}, the stream will synchronize on itself. * @return a {@link SyncDoubleStream} synchronized on {@code monitor} and * backed by {@code stream}. - * @throws NullPointerException if {@code stream == null}. + * @throws NullPointerException + * if {@code stream == null}. */ public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) { Objects.requireNonNull(stream, "stream cannot be null"); diff --git a/src/main/java/ru/windcorp/jputil/SyntaxException.java b/src/main/java/ru/windcorp/jputil/SyntaxException.java index 02cc3c4..8fdb710 100644 --- a/src/main/java/ru/windcorp/jputil/SyntaxException.java +++ b/src/main/java/ru/windcorp/jputil/SyntaxException.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil; public class SyntaxException extends Exception { diff --git a/src/main/java/ru/windcorp/jputil/chars/CharArrayIterator.java b/src/main/java/ru/windcorp/jputil/chars/CharArrayIterator.java index be0940d..659b567 100644 --- a/src/main/java/ru/windcorp/jputil/chars/CharArrayIterator.java +++ b/src/main/java/ru/windcorp/jputil/chars/CharArrayIterator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.text.CharacterIterator; @@ -108,7 +108,7 @@ public class CharArrayIterator implements CharacterIterator { return pos; } -// @SuppressWarnings("all") Just STFU, this _is_ terrific + // @SuppressWarnings("all") Just STFU, this _is_ terrific // SonarLint: "clone" should not be overridden (java:S2975) // And I wouldn't have done that if only CharacterIterator had not required diff --git a/src/main/java/ru/windcorp/jputil/chars/CharConsumer.java b/src/main/java/ru/windcorp/jputil/chars/CharConsumer.java index 7b68bb1..55448b0 100644 --- a/src/main/java/ru/windcorp/jputil/chars/CharConsumer.java +++ b/src/main/java/ru/windcorp/jputil/chars/CharConsumer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.util.function.IntConsumer; diff --git a/src/main/java/ru/windcorp/jputil/chars/CharConsumers.java b/src/main/java/ru/windcorp/jputil/chars/CharConsumers.java index 1ac7973..12a518d 100644 --- a/src/main/java/ru/windcorp/jputil/chars/CharConsumers.java +++ b/src/main/java/ru/windcorp/jputil/chars/CharConsumers.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.util.Objects; diff --git a/src/main/java/ru/windcorp/jputil/chars/CharPredicate.java b/src/main/java/ru/windcorp/jputil/chars/CharPredicate.java index 03ded02..c02beed 100644 --- a/src/main/java/ru/windcorp/jputil/chars/CharPredicate.java +++ b/src/main/java/ru/windcorp/jputil/chars/CharPredicate.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.util.Arrays; diff --git a/src/main/java/ru/windcorp/jputil/chars/CharSupplier.java b/src/main/java/ru/windcorp/jputil/chars/CharSupplier.java index 0743d79..2a9749b 100644 --- a/src/main/java/ru/windcorp/jputil/chars/CharSupplier.java +++ b/src/main/java/ru/windcorp/jputil/chars/CharSupplier.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.util.function.IntSupplier; diff --git a/src/main/java/ru/windcorp/jputil/chars/EscapeException.java b/src/main/java/ru/windcorp/jputil/chars/EscapeException.java index 935f72f..544c50f 100644 --- a/src/main/java/ru/windcorp/jputil/chars/EscapeException.java +++ b/src/main/java/ru/windcorp/jputil/chars/EscapeException.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; public class EscapeException extends Exception { diff --git a/src/main/java/ru/windcorp/jputil/chars/Escaper.java b/src/main/java/ru/windcorp/jputil/chars/Escaper.java index f19f6c7..a07dc08 100644 --- a/src/main/java/ru/windcorp/jputil/chars/Escaper.java +++ b/src/main/java/ru/windcorp/jputil/chars/Escaper.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.text.CharacterIterator; @@ -103,14 +103,8 @@ public class Escaper { } - public static final Escaper JAVA = new Escaper( - '\\', - 'u', - "tbnrf'\"".toCharArray(), - "\t\b\n\r\f\'\"".toCharArray(), - true, - true - ); + public static final Escaper JAVA = new Escaper('\\', 'u', "tbnrf'\"".toCharArray(), "\t\b\n\r\f\'\"".toCharArray(), + true, true); private final char escapeChar; private final char unicodeEscapeChar; @@ -120,14 +114,8 @@ public class Escaper { private final boolean preferUnicode; private final boolean strict; - protected Escaper( - char escapeChar, - char unicodeEscapeChar, - char[] safes, - char[] unsafes, - boolean preferUnicode, - boolean strict - ) { + protected Escaper(char escapeChar, char unicodeEscapeChar, char[] safes, char[] unsafes, boolean preferUnicode, + boolean strict) { this.escapeChar = escapeChar; this.unicodeEscapeChar = unicodeEscapeChar; this.safes = safes; @@ -152,8 +140,7 @@ public class Escaper { for (char c : unsafes) { if (c == escapeChar) throw new IllegalArgumentException( - "Unsafe characters contain escape chatacter (escape character is escaped automatically)" - ); + "Unsafe characters contain escape chatacter (escape character is escaped automatically)"); if (c == unicodeEscapeChar) throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter"); } @@ -173,11 +160,7 @@ public class Escaper { end = Integer.MAX_VALUE; else end = src.getPosition() + length; - while ( - src.has() && - src.getPosition() < end && - (until == null || !until.test(src.current())) - ) + while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) escape(src.consume(), output); } @@ -225,11 +208,7 @@ public class Escaper { int result = 0; - while ( - src.has() && - src.getPosition() < end && - (until == null || !until.test(src.current())) - ) { + while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) { result += getEscapedLength(src.consume()); } @@ -257,11 +236,7 @@ public class Escaper { end = Integer.MAX_VALUE; else end = src.getPosition() + length; - while ( - src.has() && - src.getPosition() < end && - (until == null || !until.test(src.current())) - ) { + while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) { output.accept(unescapeOneSequence(src)); } } @@ -282,10 +257,8 @@ public class Escaper { if (src.current() == unicodeEscapeChar) { src.next(); - return (char) (hexValue(src.consume()) << (4 * 3) | - hexValue(src.consume()) << (4 * 2) | - hexValue(src.consume()) << (4 * 1) | - hexValue(src.consume()) << (4 * 0)); + return (char) (hexValue(src.consume()) << (4 * 3) | hexValue(src.consume()) << (4 * 2) + | hexValue(src.consume()) << (4 * 1) | hexValue(src.consume()) << (4 * 0)); } int index = ArrayUtil.firstIndexOf(safes, src.current()); @@ -315,11 +288,7 @@ public class Escaper { int result = 0; - while ( - src.has() && - src.getPosition() < end && - (until == null || !until.test(src.current())) - ) { + while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) { skipOneSequence(src); result++; } @@ -328,11 +297,7 @@ public class Escaper { } public void skipOneSequence(CharReader src) { - if ( - src.current() == escapeChar - && - src.next() == unicodeEscapeChar - ) { + if (src.current() == escapeChar && src.next() == unicodeEscapeChar) { src.advance(4); } src.next(); diff --git a/src/main/java/ru/windcorp/jputil/chars/FancyCharacterIterator.java b/src/main/java/ru/windcorp/jputil/chars/FancyCharacterIterator.java index 183b672..da4e81e 100644 --- a/src/main/java/ru/windcorp/jputil/chars/FancyCharacterIterator.java +++ b/src/main/java/ru/windcorp/jputil/chars/FancyCharacterIterator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.text.CharacterIterator; @@ -86,7 +86,7 @@ public class FancyCharacterIterator implements CharacterIterator { return sb.toString(); } -// @SuppressWarnings("all") Just STFU, this _is_ terrific + // @SuppressWarnings("all") Just STFU, this _is_ terrific // SonarLint: "clone" should not be overridden (java:S2975) // And I wouldn't have done that if only CharacterIterator had not required diff --git a/src/main/java/ru/windcorp/jputil/chars/IndentedStringBuilder.java b/src/main/java/ru/windcorp/jputil/chars/IndentedStringBuilder.java index 92ba836..21afc6f 100644 --- a/src/main/java/ru/windcorp/jputil/chars/IndentedStringBuilder.java +++ b/src/main/java/ru/windcorp/jputil/chars/IndentedStringBuilder.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; public class IndentedStringBuilder { diff --git a/src/main/java/ru/windcorp/jputil/chars/StringUtil.java b/src/main/java/ru/windcorp/jputil/chars/StringUtil.java index f08018a..eb66975 100644 --- a/src/main/java/ru/windcorp/jputil/chars/StringUtil.java +++ b/src/main/java/ru/windcorp/jputil/chars/StringUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.io.IOException; @@ -41,13 +41,8 @@ public class StringUtil { private static final String EMPTY_PLACEHOLDER = "[empty]"; private static final String DEFAULT_SEPARATOR = "; "; - public static String arrayToString( - T[] array, - String separator, - String empty, - String nullPlaceholder, - String nullArray - ) { + public static String arrayToString(T[] array, String separator, String empty, String nullPlaceholder, + String nullArray) { if (separator == null) { throw new IllegalArgumentException(new NullPointerException()); @@ -79,13 +74,8 @@ public class StringUtil { return arrayToString(array, DEFAULT_SEPARATOR); } - public static String iteratorToString( - Iterator iterator, - String separator, - String empty, - String nullPlaceholder, - String nullIterator - ) { + public static String iteratorToString(Iterator iterator, String separator, String empty, String nullPlaceholder, + String nullIterator) { if (separator == null) { throw new IllegalArgumentException(new NullPointerException()); @@ -119,13 +109,8 @@ public class StringUtil { return iteratorToString(iterator, DEFAULT_SEPARATOR); } - public static String iterableToString( - Iterable iterable, - String separator, - String empty, - String nullPlaceholder, - String nullIterable - ) { + public static String iterableToString(Iterable iterable, String separator, String empty, String nullPlaceholder, + String nullIterable) { if (separator == null) { throw new IllegalArgumentException(new NullPointerException()); @@ -146,14 +131,8 @@ public class StringUtil { return iterableToString(iterable, DEFAULT_SEPARATOR); } - public static String supplierToString( - IntFunction supplier, - int length, - String separator, - String empty, - String nullPlaceholder, - String nullSupplier - ) { + public static String supplierToString(IntFunction supplier, int length, String separator, String empty, + String nullPlaceholder, String nullSupplier) { if (separator == null) throw new IllegalArgumentException(new NullPointerException()); @@ -163,28 +142,15 @@ public class StringUtil { return empty; if (length > 0) { - return supplierToStringExactly( - supplier, - length, - separator, - nullPlaceholder - ); + return supplierToStringExactly(supplier, length, separator, nullPlaceholder); } else { - return supplierToStringUntilNull( - supplier, - separator, - empty - ); + return supplierToStringUntilNull(supplier, separator, empty); } } - private static String supplierToStringExactly( - IntFunction supplier, - int length, - String separator, - String nullPlaceholder - ) { + private static String supplierToStringExactly(IntFunction supplier, int length, String separator, + String nullPlaceholder) { T element = supplier.apply(0); StringBuilder sb = new StringBuilder(element == null ? nullPlaceholder : element.toString()); @@ -198,11 +164,7 @@ public class StringUtil { return sb.toString(); } - private static String supplierToStringUntilNull( - IntFunction supplier, - String separator, - String empty - ) { + private static String supplierToStringUntilNull(IntFunction supplier, String separator, String empty) { T element = supplier.apply(0); if (element == null) { @@ -366,11 +328,7 @@ public class StringUtil { StringBuilder sb = new StringBuilder(); charLoop: for (char c : src.toCharArray()) { - if ( - (resultIndex + 1) < arrayLength - && - test.test(c) - ) { + if ((resultIndex + 1) < arrayLength && test.test(c)) { result[resultIndex] = resetStringBuilder(sb); ++resultIndex; continue charLoop; @@ -389,17 +347,17 @@ public class StringUtil { * index. *

* Indices {@code 0} and {@code src.length() - 1} produce {@code str} - * excluding - * the specified character and {@code ""}. + * excluding the specified character and {@code ""}. *

* - * @param src the String to split - * @param at index to split at - * @throws IllegalArgumentException if the index is out of bounds for - * {@code src} + * @param src + * the String to split + * @param at + * index to split at + * @throws IllegalArgumentException + * if the index is out of bounds for {@code src} * @return an array containing the substrings, in order of encounter in - * {@code src}. - * Its length is always 2. + * {@code src}. Its length is always 2. */ public static String[] splitAt(String src, int at) { Objects.requireNonNull(src, "src"); @@ -416,10 +374,7 @@ public class StringUtil { return new String[] { src.substring(0, src.length() - 1), "" }; } - return new String[] { - src.substring(0, at), - src.substring(at + 1) - }; + return new String[] { src.substring(0, at), src.substring(at + 1) }; } /** @@ -427,8 +382,7 @@ public class StringUtil { * indices. *

* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length - * outputs. - * Duplicate indices produce extra zero-length outputs. + * outputs. Duplicate indices produce extra zero-length outputs. *

* Examples: * @@ -439,13 +393,14 @@ public class StringUtil { * splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"} * * - * @param src the String to split - * @param at indices to split at, in any order - * @throws IllegalArgumentException if some index is out of bounds for - * {@code src} + * @param src + * the String to split + * @param at + * indices to split at, in any order + * @throws IllegalArgumentException + * if some index is out of bounds for {@code src} * @return an array containing the substrings, in order of encounter in - * {@code src}. - * Its length is always {@code at.length + 1}. + * {@code src}. Its length is always {@code at.length + 1}. */ public static String[] splitAt(String src, int... at) { Objects.requireNonNull(src, "src"); @@ -553,10 +508,8 @@ public class StringUtil { } if (endPos < beginPos) { - throw new IllegalArgumentException( - "endPos must be greater than or equal to beginPos (endPos=" - + endPos + ", beginPos=" + beginPos + ")" - ); + throw new IllegalArgumentException("endPos must be greater than or equal to beginPos (endPos=" + endPos + + ", beginPos=" + beginPos + ")"); } if (endPos >= Math.min(a.length, b.length)) { @@ -592,8 +545,7 @@ public class StringUtil { /** * Finds and returns the index of the specified appearance of the specified - * character - * in the given array. The search starts at index 0. + * character in the given array. The search starts at index 0. *

* Examples: *

@@ -630,10 +582,12 @@ public class StringUtil { * * * - * @param src - the array to search in. - * @param target - the character to search for. - * @param skip - the amount of target characters to be - * skipped. + * @param src + * - the array to search in. + * @param target + * - the character to search for. + * @param skip + * - the amount of target characters to be skipped. * @return The index of the skip+1th target * character or -1, if none found. * @see StringUtil#indexFromEnd(char[], char, int) @@ -653,8 +607,7 @@ public class StringUtil { /** * Finds and returns the index of the specified appearance of the specified - * character - * in the given array. The search starts at index + * character in the given array. The search starts at index * src.length - 1. *

* Examples: @@ -692,13 +645,15 @@ public class StringUtil { * * * - * @param src - the array to search in. - * @param target - the character to search for. - * @param skip - the amount of target characters to be - * skipped. + * @param src + * - the array to search in. + * @param target + * - the character to search for. + * @param skip + * - the amount of target characters to be skipped. * @return The index of the skip+1th - * targetcharacter - * from the end of the array or -1, if none found. + * targetcharacter from the end of the array or -1, if + * none found. * @see StringUtil#indexFromBeginning(char[], char, int) */ public static int indexFromEnd(char[] src, char target, int skip) { @@ -873,12 +828,8 @@ public class StringUtil { return result; } - private static void buildCombinations( - StringBuilder sb, - Collection result, - Iterable[] parts, - int index - ) { + private static void buildCombinations(StringBuilder sb, Collection result, Iterable[] parts, + int index) { if (index >= parts.length) { result.add(sb.toString()); } else { @@ -904,13 +855,8 @@ public class StringUtil { return result; } - private static void buildCombinations( - StringBuilder sb, - String[] result, - int[] resultIndex, - String[][] parts, - int index - ) { + private static void buildCombinations(StringBuilder sb, String[] result, int[] resultIndex, String[][] parts, + int index) { if (index >= parts.length) { result[resultIndex[0]++] = sb.toString(); } else { @@ -985,10 +931,7 @@ public class StringUtil { } private static char hexDigit(long value, int digit) { - return hexDigit( - (int) (value >>> (4 * digit)) - & 0xF - ); + return hexDigit((int) (value >>> (4 * digit)) & 0xF); } public static char hexDigit(int value) { diff --git a/src/main/java/ru/windcorp/jputil/chars/UncheckedEscapeException.java b/src/main/java/ru/windcorp/jputil/chars/UncheckedEscapeException.java index 33717ee..66b7002 100644 --- a/src/main/java/ru/windcorp/jputil/chars/UncheckedEscapeException.java +++ b/src/main/java/ru/windcorp/jputil/chars/UncheckedEscapeException.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; public class UncheckedEscapeException extends RuntimeException { diff --git a/src/main/java/ru/windcorp/jputil/chars/WordReader.java b/src/main/java/ru/windcorp/jputil/chars/WordReader.java index 22d6969..04dc5b6 100644 --- a/src/main/java/ru/windcorp/jputil/chars/WordReader.java +++ b/src/main/java/ru/windcorp/jputil/chars/WordReader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars; import java.io.IOException; diff --git a/src/main/java/ru/windcorp/jputil/chars/reader/AbstractCharReader.java b/src/main/java/ru/windcorp/jputil/chars/reader/AbstractCharReader.java index d31e092..aacf905 100644 --- a/src/main/java/ru/windcorp/jputil/chars/reader/AbstractCharReader.java +++ b/src/main/java/ru/windcorp/jputil/chars/reader/AbstractCharReader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars.reader; /** @@ -27,10 +27,9 @@ public abstract class AbstractCharReader implements CharReader { /** * Current position of this CharReader. The reader maps its input to - * positions starting from 0. - * Positions that are negative or lower than 0 are invalid. - * {@link #current()} - * will throw an exception if position is invalid. + * positions starting from 0. Positions that are negative or lower than 0 + * are invalid. {@link #current()} will throw an exception if position is + * invalid. */ protected int position = 0; diff --git a/src/main/java/ru/windcorp/jputil/chars/reader/ArrayCharReader.java b/src/main/java/ru/windcorp/jputil/chars/reader/ArrayCharReader.java index f12f590..09f5e6c 100644 --- a/src/main/java/ru/windcorp/jputil/chars/reader/ArrayCharReader.java +++ b/src/main/java/ru/windcorp/jputil/chars/reader/ArrayCharReader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars.reader; import java.util.Objects; diff --git a/src/main/java/ru/windcorp/jputil/chars/reader/BufferedCharReader.java b/src/main/java/ru/windcorp/jputil/chars/reader/BufferedCharReader.java index 83ae6b2..36e6eef 100644 --- a/src/main/java/ru/windcorp/jputil/chars/reader/BufferedCharReader.java +++ b/src/main/java/ru/windcorp/jputil/chars/reader/BufferedCharReader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars.reader; /** @@ -51,9 +51,12 @@ public abstract class BufferedCharReader extends AbstractCharReader { /** * Acquires next characters and stores them in the array. * - * @param buffer the output array - * @param offset index of the first character - * @param length maximum amount of characters to be pulled + * @param buffer + * the output array + * @param offset + * index of the first character + * @param length + * maximum amount of characters to be pulled * @return the amount of characters actually pulled */ protected int pullChars(char[] buffer, int offset, int length) { diff --git a/src/main/java/ru/windcorp/jputil/chars/reader/CharReader.java b/src/main/java/ru/windcorp/jputil/chars/reader/CharReader.java index 147daf3..01f21b9 100644 --- a/src/main/java/ru/windcorp/jputil/chars/reader/CharReader.java +++ b/src/main/java/ru/windcorp/jputil/chars/reader/CharReader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars.reader; import java.io.IOException; @@ -30,7 +30,7 @@ import ru.windcorp.jputil.chars.Escaper; */ // SonarLint: Constants should not be defined in interfaces (java:S1214) -// DONE is an essential part of the interface +// DONE is an essential part of the interface @SuppressWarnings("squid:S1214") public interface CharReader { @@ -179,8 +179,7 @@ public interface CharReader { /** * Skips to the end of the current line. Both "\n", - * "\r" - * and "\r\n" are considered line separators. + * "\r" and "\r\n" are considered line separators. * * @return the amount of characters in the skipped line */ diff --git a/src/main/java/ru/windcorp/jputil/chars/reader/CharReaders.java b/src/main/java/ru/windcorp/jputil/chars/reader/CharReaders.java index a181dbf..d6978a0 100644 --- a/src/main/java/ru/windcorp/jputil/chars/reader/CharReaders.java +++ b/src/main/java/ru/windcorp/jputil/chars/reader/CharReaders.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars.reader; import java.io.InputStream; diff --git a/src/main/java/ru/windcorp/jputil/chars/reader/ReaderCharReader.java b/src/main/java/ru/windcorp/jputil/chars/reader/ReaderCharReader.java index 51a88db..fec35b2 100644 --- a/src/main/java/ru/windcorp/jputil/chars/reader/ReaderCharReader.java +++ b/src/main/java/ru/windcorp/jputil/chars/reader/ReaderCharReader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars.reader; import java.io.IOException; diff --git a/src/main/java/ru/windcorp/jputil/chars/reader/StringCharReader.java b/src/main/java/ru/windcorp/jputil/chars/reader/StringCharReader.java index 5836d15..b8be2f8 100644 --- a/src/main/java/ru/windcorp/jputil/chars/reader/StringCharReader.java +++ b/src/main/java/ru/windcorp/jputil/chars/reader/StringCharReader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.chars.reader; import java.util.Objects; @@ -38,8 +38,7 @@ public class StringCharReader extends AbstractCharReader { int end = offset + length; if (end > str.length() || offset < 0) throw new IllegalArgumentException( - "String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")" - ); + "String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")"); this.offset = offset; this.length = length; diff --git a/src/main/java/ru/windcorp/jputil/functions/FloatSupplier.java b/src/main/java/ru/windcorp/jputil/functions/FloatSupplier.java index a157032..774e36b 100644 --- a/src/main/java/ru/windcorp/jputil/functions/FloatSupplier.java +++ b/src/main/java/ru/windcorp/jputil/functions/FloatSupplier.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.functions; @FunctionalInterface diff --git a/src/main/java/ru/windcorp/jputil/functions/ThrowingBiConsumer.java b/src/main/java/ru/windcorp/jputil/functions/ThrowingBiConsumer.java index be7cb8f..2ed41a3 100644 --- a/src/main/java/ru/windcorp/jputil/functions/ThrowingBiConsumer.java +++ b/src/main/java/ru/windcorp/jputil/functions/ThrowingBiConsumer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.functions; import java.util.function.BiConsumer; @@ -44,9 +44,16 @@ public interface ThrowingBiConsumer { } public static ThrowingBiConsumer concat( - ThrowingBiConsumer first, - ThrowingBiConsumer second - ) { + ThrowingBiConsumer first, + ThrowingBiConsumer second) { + return (t, u) -> { + first.accept(t, u); + second.accept(t, u); + }; + } + + public static ThrowingBiConsumer concat(BiConsumer first, + ThrowingBiConsumer second) { return (t, u) -> { first.accept(t, u); second.accept(t, u); @@ -54,19 +61,7 @@ public interface ThrowingBiConsumer { } public static ThrowingBiConsumer concat( - BiConsumer first, - ThrowingBiConsumer second - ) { - return (t, u) -> { - first.accept(t, u); - second.accept(t, u); - }; - } - - public static ThrowingBiConsumer concat( - ThrowingBiConsumer first, - BiConsumer second - ) { + ThrowingBiConsumer first, BiConsumer second) { return (t, u) -> { first.accept(t, u); second.accept(t, u); diff --git a/src/main/java/ru/windcorp/jputil/functions/ThrowingConsumer.java b/src/main/java/ru/windcorp/jputil/functions/ThrowingConsumer.java index 14449ca..e89bde5 100644 --- a/src/main/java/ru/windcorp/jputil/functions/ThrowingConsumer.java +++ b/src/main/java/ru/windcorp/jputil/functions/ThrowingConsumer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.functions; import java.util.function.BiConsumer; @@ -39,30 +39,24 @@ public interface ThrowingConsumer { }; } - public static ThrowingConsumer concat( - ThrowingConsumer first, - ThrowingConsumer second - ) { + public static ThrowingConsumer concat(ThrowingConsumer first, + ThrowingConsumer second) { return t -> { first.accept(t); second.accept(t); }; } - public static ThrowingConsumer concat( - Consumer first, - ThrowingConsumer second - ) { + public static ThrowingConsumer concat(Consumer first, + ThrowingConsumer second) { return t -> { first.accept(t); second.accept(t); }; } - public static ThrowingConsumer concat( - ThrowingConsumer first, - Consumer second - ) { + public static ThrowingConsumer concat(ThrowingConsumer first, + Consumer second) { return t -> { first.accept(t); second.accept(t); diff --git a/src/main/java/ru/windcorp/jputil/functions/ThrowingFunction.java b/src/main/java/ru/windcorp/jputil/functions/ThrowingFunction.java index afdd078..7c32b16 100644 --- a/src/main/java/ru/windcorp/jputil/functions/ThrowingFunction.java +++ b/src/main/java/ru/windcorp/jputil/functions/ThrowingFunction.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.functions; import java.util.function.BiConsumer; @@ -28,10 +28,8 @@ public interface ThrowingFunction { R apply(T t) throws E; @SuppressWarnings("unchecked") - default Function withHandler( - BiConsumer handler, - Function value - ) { + default Function withHandler(BiConsumer handler, + Function value) { return t -> { try { return apply(t); @@ -58,23 +56,18 @@ public interface ThrowingFunction { } public static ThrowingFunction compose( - ThrowingFunction first, - ThrowingFunction second - ) { + ThrowingFunction first, + ThrowingFunction second) { + return t -> second.apply(first.apply(t)); + } + + public static ThrowingFunction compose(Function first, + ThrowingFunction second) { return t -> second.apply(first.apply(t)); } public static ThrowingFunction compose( - Function first, - ThrowingFunction second - ) { - return t -> second.apply(first.apply(t)); - } - - public static ThrowingFunction compose( - ThrowingFunction first, - Function second - ) { + ThrowingFunction first, Function second) { return t -> second.apply(first.apply(t)); } diff --git a/src/main/java/ru/windcorp/jputil/functions/ThrowingRunnable.java b/src/main/java/ru/windcorp/jputil/functions/ThrowingRunnable.java index f27429b..f93ea61 100644 --- a/src/main/java/ru/windcorp/jputil/functions/ThrowingRunnable.java +++ b/src/main/java/ru/windcorp/jputil/functions/ThrowingRunnable.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.functions; import java.util.function.Consumer; @@ -38,10 +38,8 @@ public interface ThrowingRunnable { }; } - public static ThrowingRunnable concat( - ThrowingRunnable first, - ThrowingRunnable second - ) { + public static ThrowingRunnable concat(ThrowingRunnable first, + ThrowingRunnable second) { return () -> { first.run(); second.run(); diff --git a/src/main/java/ru/windcorp/jputil/functions/ThrowingSupplier.java b/src/main/java/ru/windcorp/jputil/functions/ThrowingSupplier.java index 84ad690..6583789 100644 --- a/src/main/java/ru/windcorp/jputil/functions/ThrowingSupplier.java +++ b/src/main/java/ru/windcorp/jputil/functions/ThrowingSupplier.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.functions; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/jputil/iterators/ArrayIterator.java b/src/main/java/ru/windcorp/jputil/iterators/ArrayIterator.java index 0b8fab2..aec4324 100644 --- a/src/main/java/ru/windcorp/jputil/iterators/ArrayIterator.java +++ b/src/main/java/ru/windcorp/jputil/iterators/ArrayIterator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.iterators; import java.util.Iterator; diff --git a/src/main/java/ru/windcorp/jputil/iterators/FunctionIterator.java b/src/main/java/ru/windcorp/jputil/iterators/FunctionIterator.java index abc5b44..e32d250 100644 --- a/src/main/java/ru/windcorp/jputil/iterators/FunctionIterator.java +++ b/src/main/java/ru/windcorp/jputil/iterators/FunctionIterator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.iterators; import java.util.Iterator; diff --git a/src/main/java/ru/windcorp/jputil/iterators/PeekingIterator.java b/src/main/java/ru/windcorp/jputil/iterators/PeekingIterator.java index 67f3da9..754e1ae 100644 --- a/src/main/java/ru/windcorp/jputil/iterators/PeekingIterator.java +++ b/src/main/java/ru/windcorp/jputil/iterators/PeekingIterator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.iterators; import java.util.Iterator; diff --git a/src/main/java/ru/windcorp/jputil/iterators/RangeIterator.java b/src/main/java/ru/windcorp/jputil/iterators/RangeIterator.java index 7da8ada..0047fa9 100644 --- a/src/main/java/ru/windcorp/jputil/iterators/RangeIterator.java +++ b/src/main/java/ru/windcorp/jputil/iterators/RangeIterator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.iterators; import java.util.Iterator; @@ -49,10 +49,8 @@ public class RangeIterator implements Iterator { public E next() { update(); if (nextIndex >= from + amount) { - throw new NoSuchElementException( - "RangeIterator about to retrieve element " + nextIndex - + " which exceeds upper boundary " + (from + amount) - ); + throw new NoSuchElementException("RangeIterator about to retrieve element " + nextIndex + + " which exceeds upper boundary " + (from + amount)); } E result = parent.next(); diff --git a/src/main/java/ru/windcorp/jputil/iterators/Reiterator.java b/src/main/java/ru/windcorp/jputil/iterators/Reiterator.java index 7969bc1..85d9122 100644 --- a/src/main/java/ru/windcorp/jputil/iterators/Reiterator.java +++ b/src/main/java/ru/windcorp/jputil/iterators/Reiterator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.iterators; import java.util.ArrayList; diff --git a/src/main/java/ru/windcorp/jputil/selectors/AbstractSelectorOperator.java b/src/main/java/ru/windcorp/jputil/selectors/AbstractSelectorOperator.java index 481e558..3448929 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/AbstractSelectorOperator.java +++ b/src/main/java/ru/windcorp/jputil/selectors/AbstractSelectorOperator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; public abstract class AbstractSelectorOperator implements SelectorOperator { diff --git a/src/main/java/ru/windcorp/jputil/selectors/NamedParameterizedSelector.java b/src/main/java/ru/windcorp/jputil/selectors/NamedParameterizedSelector.java index e0676fd..d0a7692 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/NamedParameterizedSelector.java +++ b/src/main/java/ru/windcorp/jputil/selectors/NamedParameterizedSelector.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import ru.windcorp.jputil.SyntaxException; diff --git a/src/main/java/ru/windcorp/jputil/selectors/NamedSelector.java b/src/main/java/ru/windcorp/jputil/selectors/NamedSelector.java index 196be14..7765505 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/NamedSelector.java +++ b/src/main/java/ru/windcorp/jputil/selectors/NamedSelector.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import ru.windcorp.jputil.SyntaxException; diff --git a/src/main/java/ru/windcorp/jputil/selectors/OperatorAnd.java b/src/main/java/ru/windcorp/jputil/selectors/OperatorAnd.java index 603c6d4..4b68bb6 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/OperatorAnd.java +++ b/src/main/java/ru/windcorp/jputil/selectors/OperatorAnd.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.Deque; diff --git a/src/main/java/ru/windcorp/jputil/selectors/OperatorExclude.java b/src/main/java/ru/windcorp/jputil/selectors/OperatorExclude.java index a805a2f..810f15f 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/OperatorExclude.java +++ b/src/main/java/ru/windcorp/jputil/selectors/OperatorExclude.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.Deque; diff --git a/src/main/java/ru/windcorp/jputil/selectors/OperatorNot.java b/src/main/java/ru/windcorp/jputil/selectors/OperatorNot.java index 2bf0300..b12f5dc 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/OperatorNot.java +++ b/src/main/java/ru/windcorp/jputil/selectors/OperatorNot.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.Deque; diff --git a/src/main/java/ru/windcorp/jputil/selectors/OperatorOr.java b/src/main/java/ru/windcorp/jputil/selectors/OperatorOr.java index 367e6c3..2388105 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/OperatorOr.java +++ b/src/main/java/ru/windcorp/jputil/selectors/OperatorOr.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.Deque; diff --git a/src/main/java/ru/windcorp/jputil/selectors/OperatorXor.java b/src/main/java/ru/windcorp/jputil/selectors/OperatorXor.java index 467e6a0..9b8a719 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/OperatorXor.java +++ b/src/main/java/ru/windcorp/jputil/selectors/OperatorXor.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.Deque; diff --git a/src/main/java/ru/windcorp/jputil/selectors/PredicateWrapper.java b/src/main/java/ru/windcorp/jputil/selectors/PredicateWrapper.java index 278df45..f43760a 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/PredicateWrapper.java +++ b/src/main/java/ru/windcorp/jputil/selectors/PredicateWrapper.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.function.Predicate; diff --git a/src/main/java/ru/windcorp/jputil/selectors/Selector.java b/src/main/java/ru/windcorp/jputil/selectors/Selector.java index eec8b06..450e717 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/Selector.java +++ b/src/main/java/ru/windcorp/jputil/selectors/Selector.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.function.Predicate; diff --git a/src/main/java/ru/windcorp/jputil/selectors/SelectorOperator.java b/src/main/java/ru/windcorp/jputil/selectors/SelectorOperator.java index 665d231..20b46b3 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/SelectorOperator.java +++ b/src/main/java/ru/windcorp/jputil/selectors/SelectorOperator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.Deque; diff --git a/src/main/java/ru/windcorp/jputil/selectors/SelectorSystem.java b/src/main/java/ru/windcorp/jputil/selectors/SelectorSystem.java index 0361795..a5543fe 100644 --- a/src/main/java/ru/windcorp/jputil/selectors/SelectorSystem.java +++ b/src/main/java/ru/windcorp/jputil/selectors/SelectorSystem.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.jputil.selectors; import java.util.ArrayList; @@ -37,7 +37,7 @@ public class SelectorSystem { private final Collection> selectors = Collections.synchronizedCollection(new ArrayList>()); private final Collection operators = Collections - .synchronizedCollection(new ArrayList()); + .synchronizedCollection(new ArrayList()); private String stackPrefix = null; diff --git a/src/main/java/ru/windcorp/progressia/Progressia.java b/src/main/java/ru/windcorp/progressia/Progressia.java index db899ea..fd3529f 100644 --- a/src/main/java/ru/windcorp/progressia/Progressia.java +++ b/src/main/java/ru/windcorp/progressia/Progressia.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia; public class Progressia { diff --git a/src/main/java/ru/windcorp/progressia/ProgressiaLauncher.java b/src/main/java/ru/windcorp/progressia/ProgressiaLauncher.java index c8935fc..08ce1e9 100644 --- a/src/main/java/ru/windcorp/progressia/ProgressiaLauncher.java +++ b/src/main/java/ru/windcorp/progressia/ProgressiaLauncher.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia; import ru.windcorp.progressia.common.util.crash.CrashReports; diff --git a/src/main/java/ru/windcorp/progressia/Proxy.java b/src/main/java/ru/windcorp/progressia/Proxy.java index a1af080..8b5542e 100644 --- a/src/main/java/ru/windcorp/progressia/Proxy.java +++ b/src/main/java/ru/windcorp/progressia/Proxy.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia; public interface Proxy { diff --git a/src/main/java/ru/windcorp/progressia/client/Client.java b/src/main/java/ru/windcorp/progressia/client/Client.java index d8800c7..5602048 100644 --- a/src/main/java/ru/windcorp/progressia/client/Client.java +++ b/src/main/java/ru/windcorp/progressia/client/Client.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client; import ru.windcorp.progressia.client.comms.DefaultClientCommsListener; @@ -69,11 +69,7 @@ public class Client { return; } - getCamera().setAnchor( - new EntityAnchor( - getWorld().getEntityRenderable(entity) - ) - ); + getCamera().setAnchor(new EntityAnchor(getWorld().getEntityRenderable(entity))); } } diff --git a/src/main/java/ru/windcorp/progressia/client/ClientProxy.java b/src/main/java/ru/windcorp/progressia/client/ClientProxy.java index 1d154e7..c7a221e 100644 --- a/src/main/java/ru/windcorp/progressia/client/ClientProxy.java +++ b/src/main/java/ru/windcorp/progressia/client/ClientProxy.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client; import ru.windcorp.progressia.Proxy; @@ -42,10 +42,8 @@ public class ClientProxy implements Proxy { try { RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init); RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init); - RenderTaskQueue.waitAndInvoke( - () -> Typefaces - .setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz"))) - ); + RenderTaskQueue.waitAndInvoke(() -> Typefaces + .setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz")))); } catch (InterruptedException e) { throw CrashReports.report(e, "ClientProxy failed"); } @@ -60,7 +58,7 @@ public class ClientProxy implements Proxy { ServerState.startServer(); ClientState.connectToLocalServer(); - + TestMusicPlayer.start(); } diff --git a/src/main/java/ru/windcorp/progressia/client/ClientState.java b/src/main/java/ru/windcorp/progressia/client/ClientState.java index 75f0f07..6060623 100644 --- a/src/main/java/ru/windcorp/progressia/client/ClientState.java +++ b/src/main/java/ru/windcorp/progressia/client/ClientState.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client; import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel; @@ -43,9 +43,7 @@ public class ClientState { WorldData world = new WorldData(); - LocalServerCommsChannel channel = new LocalServerCommsChannel( - ServerState.getInstance() - ); + LocalServerCommsChannel channel = new LocalServerCommsChannel(ServerState.getInstance()); Client client = new Client(world, channel); diff --git a/src/main/java/ru/windcorp/progressia/client/ProgressiaClientMain.java b/src/main/java/ru/windcorp/progressia/client/ProgressiaClientMain.java index bb0482d..d578c85 100644 --- a/src/main/java/ru/windcorp/progressia/client/ProgressiaClientMain.java +++ b/src/main/java/ru/windcorp/progressia/client/ProgressiaClientMain.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client; import ru.windcorp.progressia.ProgressiaLauncher; diff --git a/src/main/java/ru/windcorp/progressia/client/audio/AudioFormat.java b/src/main/java/ru/windcorp/progressia/client/audio/AudioFormat.java index 848e66c..cade47d 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/AudioFormat.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/AudioFormat.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio; public enum AudioFormat { diff --git a/src/main/java/ru/windcorp/progressia/client/audio/AudioManager.java b/src/main/java/ru/windcorp/progressia/client/audio/AudioManager.java index 49f2312..a7ddd32 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/AudioManager.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/AudioManager.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio; import org.lwjgl.openal.*; @@ -43,10 +43,7 @@ public class AudioManager { private static Speaker musicSpeaker; public static void initAL() { - String defaultDeviceName = alcGetString( - 0, - ALC_DEFAULT_DEVICE_SPECIFIER - ); + String defaultDeviceName = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER); device = alcOpenDevice(defaultDeviceName); @@ -75,10 +72,7 @@ public class AudioManager { lastSoundIndex = 0; } speaker = soundSpeakers.get(lastSoundIndex); - } while ( - speaker.getState() - .equals(Speaker.State.PLAYING_LOOP) - ); + } while (speaker.getState().equals(Speaker.State.PLAYING_LOOP)); return speaker; } diff --git a/src/main/java/ru/windcorp/progressia/client/audio/AudioRegistry.java b/src/main/java/ru/windcorp/progressia/client/audio/AudioRegistry.java index 3199622..2f1da30 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/AudioRegistry.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/AudioRegistry.java @@ -21,9 +21,9 @@ import ru.windcorp.progressia.client.audio.backend.SoundType; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; public class AudioRegistry extends NamespacedInstanceRegistry { - + private static final AudioRegistry INSTANCE = new AudioRegistry(); - + /** * @return the instance */ diff --git a/src/main/java/ru/windcorp/progressia/client/audio/AudioSystem.java b/src/main/java/ru/windcorp/progressia/client/audio/AudioSystem.java index 24cc2de..a4cab80 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/AudioSystem.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/AudioSystem.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio; import ru.windcorp.progressia.common.resource.ResourceManager; @@ -29,10 +29,7 @@ public class AudioSystem { } static void loadAudioData() { - AudioManager.loadSound( - ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"), - "Progressia:BlockDestroy", - AudioFormat.MONO - ); + AudioManager.loadSound(ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"), + "Progressia:BlockDestroy", AudioFormat.MONO); } } diff --git a/src/main/java/ru/windcorp/progressia/client/audio/Music.java b/src/main/java/ru/windcorp/progressia/client/audio/Music.java index 031b58e..d60860a 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/Music.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/Music.java @@ -15,18 +15,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio; import glm.vec._3.Vec3; import ru.windcorp.progressia.client.audio.backend.SoundType; import ru.windcorp.progressia.client.audio.backend.Speaker; -public class Music - extends Sound { - - - +public class Music extends Sound { + public Music(SoundType soundType, int timeLength, float pitch, float gain) { super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain); } @@ -47,7 +44,7 @@ public class Music protected Speaker initSpeaker() { return AudioManager.initMusicSpeaker(soundType); } - + @Override public void setPosition(Vec3 position) { throw new UnsupportedOperationException(); diff --git a/src/main/java/ru/windcorp/progressia/client/audio/Sound.java b/src/main/java/ru/windcorp/progressia/client/audio/Sound.java index 77f0c9e..a45b535 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/Sound.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/Sound.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio; import glm.vec._3.Vec3; @@ -29,9 +29,9 @@ public class Sound { protected float pitch = 1.0f; protected float gain = 1.0f; protected int timeLength = 0; - + protected SoundType soundType; - + public Sound(SoundType soundType) { this.soundType = soundType; } @@ -39,37 +39,23 @@ public class Sound { public Sound(String id) { this(AudioRegistry.getInstance().get(id)); } - - public Sound( - String id, - int timeLength, - Vec3 position, - Vec3 velocity, - float pitch, - float gain - ) { + + public Sound(String id, int timeLength, Vec3 position, Vec3 velocity, float pitch, float gain) { this(id); this.position = position; this.velocity = velocity; this.pitch = pitch; this.gain = gain; } - - public Sound( - SoundType soundType, - int timeLength, - Vec3 position, - Vec3 velocity, - float pitch, - float gain - ) { + + public Sound(SoundType soundType, int timeLength, Vec3 position, Vec3 velocity, float pitch, float gain) { this(soundType); this.position = position; this.velocity = velocity; this.pitch = pitch; this.gain = gain; } - + protected Speaker initSpeaker() { return AudioManager.initSpeaker(soundType); } @@ -119,7 +105,7 @@ public class Sound { public float getPitch() { return pitch; } - + public double getDuration() { return soundType.getDuration(); } diff --git a/src/main/java/ru/windcorp/progressia/client/audio/backend/AudioReader.java b/src/main/java/ru/windcorp/progressia/client/audio/backend/AudioReader.java index 9fa48e0..27e77b8 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/backend/AudioReader.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/backend/AudioReader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio.backend; import org.lwjgl.BufferUtils; @@ -39,12 +39,7 @@ public class AudioReader { ShortBuffer rawAudio = decodeVorbis(resource, channelBuffer, rateBuffer); - return new SoundType( - id, - rawAudio, - format, - rateBuffer.get(0) - ); + return new SoundType(id, rawAudio, format, rateBuffer.get(0)); } public static SoundType readAsMono(Resource resource, String id) { @@ -55,15 +50,7 @@ public class AudioReader { return readAsSpecified(resource, id, AL_FORMAT_STEREO16); } - private static ShortBuffer decodeVorbis( - Resource dataToDecode, - IntBuffer channelsBuffer, - IntBuffer rateBuffer - ) { - return stb_vorbis_decode_memory( - dataToDecode.readAsBytes(), - channelsBuffer, - rateBuffer - ); + private static ShortBuffer decodeVorbis(Resource dataToDecode, IntBuffer channelsBuffer, IntBuffer rateBuffer) { + return stb_vorbis_decode_memory(dataToDecode.readAsBytes(), channelsBuffer, rateBuffer); } } diff --git a/src/main/java/ru/windcorp/progressia/client/audio/backend/Listener.java b/src/main/java/ru/windcorp/progressia/client/audio/backend/Listener.java index 8f6fe35..78a9c9a 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/backend/Listener.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/backend/Listener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio.backend; import glm.vec._3.Vec3; @@ -55,9 +55,8 @@ public class Listener { if (isInWorld) { if (wasInWorld) { - velocity.set(camera.getLastAnchorPosition()).sub(position).div( - (float) GraphicsInterface.getFrameLength() - ); + velocity.set(camera.getLastAnchorPosition()).sub(position) + .div((float) GraphicsInterface.getFrameLength()); } else { // If !wasInWorld, previous position is nonsence. Assume 0. velocity.set(0); @@ -72,9 +71,9 @@ public class Listener { } /* - * Only apply if there is a chance that params changed. - * This can only happen if we are in world now (isInWorld) or we just - * left world (wasInWorld, then we need to reset). + * Only apply if there is a chance that params changed. This can only + * happen if we are in world now (isInWorld) or we just left world + * (wasInWorld, then we need to reset). */ if (isInWorld || wasInWorld) { applyParams(); @@ -91,17 +90,7 @@ public class Listener { private void applyParams() { alListener3f(AL_POSITION, position.x, position.y, position.z); alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z); - alListenerfv( - AL_ORIENTATION, - new float[] { - oriAt.x, - oriAt.y, - oriAt.z, - oriUp.x, - oriUp.y, - oriUp.z - } - ); + alListenerfv(AL_ORIENTATION, new float[] { oriAt.x, oriAt.y, oriAt.z, oriUp.x, oriUp.y, oriUp.z }); } } diff --git a/src/main/java/ru/windcorp/progressia/client/audio/backend/SoundType.java b/src/main/java/ru/windcorp/progressia/client/audio/backend/SoundType.java index cdb1954..fa7d5a0 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/backend/SoundType.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/backend/SoundType.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio.backend; import ru.windcorp.progressia.common.util.namespaces.Namespaced; @@ -34,12 +34,7 @@ public class SoundType extends Namespaced { private int audioBuffer; private double duration; - public SoundType( - String id, - ShortBuffer rawAudio, - int format, - int sampleRate - ) { + public SoundType(String id, ShortBuffer rawAudio, int format, int sampleRate) { super(id); this.rawAudio = rawAudio; this.sampleRate = sampleRate; @@ -56,7 +51,7 @@ public class SoundType extends Namespaced { public void initSpeaker(Speaker speaker) { speaker.setAudioData(audioBuffer); } - + public double getDuration() { return duration; } diff --git a/src/main/java/ru/windcorp/progressia/client/audio/backend/Speaker.java b/src/main/java/ru/windcorp/progressia/client/audio/backend/Speaker.java index c649a6a..6e7af4b 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/backend/Speaker.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/backend/Speaker.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.audio.backend; import glm.vec._3.Vec3; @@ -24,9 +24,7 @@ import static org.lwjgl.openal.AL11.*; public class Speaker { public enum State { - NOT_PLAYING, - PLAYING, - PLAYING_LOOP + NOT_PLAYING, PLAYING, PLAYING_LOOP } // Buffers @@ -49,13 +47,7 @@ public class Speaker { setAudioData(audioData); } - public Speaker( - int audioData, - Vec3 position, - Vec3 velocity, - float pitch, - float gain - ) { + public Speaker(int audioData, Vec3 position, Vec3 velocity, float pitch, float gain) { setAudioData(audioData); setPosition(position); setVelocity(velocity); @@ -63,12 +55,7 @@ public class Speaker { setGain(gain); } - public Speaker( - Vec3 position, - Vec3 velocity, - float pitch, - float gain - ) { + public Speaker(Vec3 position, Vec3 velocity, float pitch, float gain) { setPosition(position); setVelocity(velocity); setPitch(pitch); diff --git a/src/main/java/ru/windcorp/progressia/client/comms/DefaultClientCommsListener.java b/src/main/java/ru/windcorp/progressia/client/comms/DefaultClientCommsListener.java index dad05fd..e983e51 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/DefaultClientCommsListener.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/DefaultClientCommsListener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms; import java.io.IOException; @@ -39,9 +39,7 @@ public class DefaultClientCommsListener implements CommsListener { @Override public void onPacketReceived(Packet packet) { if (packet instanceof PacketAffectWorld) { - ((PacketAffectWorld) packet).apply( - getClient().getWorld().getData() - ); + ((PacketAffectWorld) packet).apply(getClient().getWorld().getData()); } else if (packet instanceof PacketSetLocalPlayer) { setLocalPlayer((PacketSetLocalPlayer) packet); } diff --git a/src/main/java/ru/windcorp/progressia/client/comms/ServerCommsChannel.java b/src/main/java/ru/windcorp/progressia/client/comms/ServerCommsChannel.java index 3a0a1b1..6bf9a8e 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/ServerCommsChannel.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/ServerCommsChannel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms; import ru.windcorp.progressia.common.comms.CommsChannel; diff --git a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTrigger.java b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTrigger.java index 88e9fa3..0f0e091 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTrigger.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTrigger.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.controls; import ru.windcorp.progressia.common.util.namespaces.Namespaced; diff --git a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerInputBased.java b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerInputBased.java index b2f8de4..f1985b3 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerInputBased.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerInputBased.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.controls; import ru.windcorp.progressia.client.graphics.input.InputEvent; diff --git a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerLambda.java b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerLambda.java index 22004b8..476c482 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerLambda.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerLambda.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.controls; import java.util.function.BiConsumer; @@ -33,17 +33,12 @@ public class ControlTriggerLambda extends ControlTriggerInputBased { private final Predicate predicate; private final BiConsumer dataWriter; - public ControlTriggerLambda( - String id, - Predicate predicate, - BiConsumer dataWriter - ) { + public ControlTriggerLambda(String id, Predicate predicate, + BiConsumer dataWriter) { super(id); - this.packetId = NamespacedUtil.getId( - NamespacedUtil.getNamespace(id), - "ControlKeyPress" + NamespacedUtil.getName(id) - ); + this.packetId = NamespacedUtil.getId(NamespacedUtil.getNamespace(id), + "ControlKeyPress" + NamespacedUtil.getName(id)); this.predicate = predicate; this.dataWriter = dataWriter; @@ -54,10 +49,7 @@ public class ControlTriggerLambda extends ControlTriggerInputBased { if (!predicate.test(event)) return null; - PacketControl packet = new PacketControl( - packetId, - ControlDataRegistry.getInstance().create(getId()) - ); + PacketControl packet = new PacketControl(packetId, ControlDataRegistry.getInstance().create(getId())); dataWriter.accept(event, packet.getControl()); diff --git a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerLocalLambda.java b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerLocalLambda.java index b2ae739..7708328 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerLocalLambda.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerLocalLambda.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.controls; import java.util.function.Consumer; @@ -29,11 +29,7 @@ public class ControlTriggerLocalLambda extends ControlTriggerInputBased { private final Predicate predicate; private final Consumer action; - public ControlTriggerLocalLambda( - String id, - Predicate predicate, - Consumer action - ) { + public ControlTriggerLocalLambda(String id, Predicate predicate, Consumer action) { super(id); this.predicate = predicate; diff --git a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerRegistry.java b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerRegistry.java index a2ec71e..5a3f4a9 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerRegistry.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggerRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.controls; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; diff --git a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggers.java b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggers.java index 2c0d61d..260e220 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggers.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/controls/ControlTriggers.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.controls; import java.util.function.BiConsumer; @@ -27,122 +27,59 @@ import ru.windcorp.progressia.common.comms.controls.ControlData; public class ControlTriggers { - public static ControlTriggerInputBased of( - String id, - BiConsumer dataWriter, - Predicate predicate - ) { + public static ControlTriggerInputBased of(String id, BiConsumer dataWriter, + Predicate predicate) { return new ControlTriggerLambda(id, predicate, dataWriter); } - public static ControlTriggerInputBased of( - String id, - Consumer dataWriter, - Predicate predicate - ) { - return of( - id, - (input, control) -> dataWriter.accept(control), - predicate - ); + public static ControlTriggerInputBased of(String id, Consumer dataWriter, + Predicate predicate) { + return of(id, (input, control) -> dataWriter.accept(control), predicate); } - public static ControlTriggerInputBased of( - String id, - Predicate predicate - ) { - return of( - id, - (input, control) -> { - }, - predicate - ); + public static ControlTriggerInputBased of(String id, Predicate predicate) { + return of(id, (input, control) -> { + }, predicate); } @SafeVarargs - public static ControlTriggerInputBased of( - String id, - Class inputType, - BiConsumer dataWriter, - Predicate... predicates - ) { - return of( - id, - createCheckedDataWriter(inputType, dataWriter), - createCheckedCompoundPredicate(inputType, predicates) - ); + public static ControlTriggerInputBased of(String id, Class inputType, + BiConsumer dataWriter, Predicate... predicates) { + return of(id, createCheckedDataWriter(inputType, dataWriter), + createCheckedCompoundPredicate(inputType, predicates)); } @SafeVarargs - public static ControlTriggerInputBased of( - String id, - Class inputType, - Consumer dataWriter, - Predicate... predicates - ) { - return of( - id, - inputType, - (input, control) -> dataWriter.accept(control), - predicates - ); + public static ControlTriggerInputBased of(String id, Class inputType, + Consumer dataWriter, Predicate... predicates) { + return of(id, inputType, (input, control) -> dataWriter.accept(control), predicates); } @SafeVarargs - public static ControlTriggerInputBased of( - String id, - Class inputType, - Predicate... predicates - ) { - return of( - id, - (input, control) -> { - }, - createCheckedCompoundPredicate(inputType, predicates) - ); + public static ControlTriggerInputBased of(String id, Class inputType, + Predicate... predicates) { + return of(id, (input, control) -> { + }, createCheckedCompoundPredicate(inputType, predicates)); } @SafeVarargs - public static ControlTriggerInputBased of( - String id, - BiConsumer dataWriter, - Predicate... predicates - ) { - return of( - id, - InputEvent.class, - dataWriter, - predicates - ); + public static ControlTriggerInputBased of(String id, BiConsumer dataWriter, + Predicate... predicates) { + return of(id, InputEvent.class, dataWriter, predicates); } @SafeVarargs - public static ControlTriggerInputBased of( - String id, - Consumer dataWriter, - Predicate... predicates - ) { - return of( - id, - (input, control) -> dataWriter.accept(control), - predicates - ); + public static ControlTriggerInputBased of(String id, Consumer dataWriter, + Predicate... predicates) { + return of(id, (input, control) -> dataWriter.accept(control), predicates); } @SafeVarargs - public static ControlTriggerInputBased of( - String id, - Predicate... predicates - ) { - return of( - id, - InputEvent.class, - (input, control) -> { - }, - predicates - ); + public static ControlTriggerInputBased of(String id, Predicate... predicates) { + return of(id, InputEvent.class, (input, control) -> { + }, predicates); } - + // // /// @@ -156,101 +93,53 @@ public class ControlTriggers { // // // - - public static ControlTriggerInputBased localOf( - String id, - Consumer action, - Predicate predicate - ) { + + public static ControlTriggerInputBased localOf(String id, Consumer action, + Predicate predicate) { return new ControlTriggerLocalLambda(id, predicate, action); } - public static ControlTriggerInputBased localOf( - String id, - Runnable action, - Predicate predicate - ) { - return localOf( - id, - input -> action.run(), - predicate - ); + public static ControlTriggerInputBased localOf(String id, Runnable action, Predicate predicate) { + return localOf(id, input -> action.run(), predicate); } @SafeVarargs - public static ControlTriggerInputBased localOf( - String id, - Class inputType, - Consumer action, - Predicate... predicates - ) { - return localOf( - id, - createCheckedAction(inputType, action), - createCheckedCompoundPredicate(inputType, predicates) - ); + public static ControlTriggerInputBased localOf(String id, Class inputType, + Consumer action, Predicate... predicates) { + return localOf(id, createCheckedAction(inputType, action), + createCheckedCompoundPredicate(inputType, predicates)); } @SafeVarargs - public static ControlTriggerInputBased localOf( - String id, - Class inputType, - Runnable action, - Predicate... predicates - ) { - return localOf( - id, - inputType, - input -> action.run(), - predicates - ); + public static ControlTriggerInputBased localOf(String id, Class inputType, + Runnable action, Predicate... predicates) { + return localOf(id, inputType, input -> action.run(), predicates); } @SafeVarargs - public static ControlTriggerInputBased localOf( - String id, - Consumer action, - Predicate... predicates - ) { - return localOf( - id, - InputEvent.class, - action, - predicates - ); + public static ControlTriggerInputBased localOf(String id, Consumer action, + Predicate... predicates) { + return localOf(id, InputEvent.class, action, predicates); } @SafeVarargs - public static ControlTriggerInputBased localOf( - String id, - Runnable action, - Predicate... predicates - ) { - return of( - id, - input -> action.run(), - predicates - ); + public static ControlTriggerInputBased localOf(String id, Runnable action, + Predicate... predicates) { + return of(id, input -> action.run(), predicates); } private static BiConsumer createCheckedDataWriter( - Class inputType, - BiConsumer dataWriter - ) { + Class inputType, BiConsumer dataWriter) { return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control); } - - private static Consumer createCheckedAction( - Class inputType, - Consumer action - ) { + + private static Consumer createCheckedAction(Class inputType, + Consumer action) { return inputEvent -> action.accept(inputType.cast(inputEvent)); } - private static Predicate createCheckedCompoundPredicate( - Class inputType, - Predicate[] predicates - ) { + private static Predicate createCheckedCompoundPredicate(Class inputType, + Predicate[] predicates) { return new CompoundCastPredicate<>(inputType, predicates); } diff --git a/src/main/java/ru/windcorp/progressia/client/comms/controls/InputBasedControls.java b/src/main/java/ru/windcorp/progressia/client/comms/controls/InputBasedControls.java index 28b9e1b..2fbd086 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/controls/InputBasedControls.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/controls/InputBasedControls.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.controls; import ru.windcorp.progressia.client.Client; @@ -32,8 +32,7 @@ public class InputBasedControls { this.client = client; this.controls = ControlTriggerRegistry.getInstance().values().stream() - .filter(ControlTriggerInputBased.class::isInstance) - .toArray(ControlTriggerInputBased[]::new); + .filter(ControlTriggerInputBased.class::isInstance).toArray(ControlTriggerInputBased[]::new); } public void handleInput(Input input) { diff --git a/src/main/java/ru/windcorp/progressia/client/comms/localhost/LocalClient.java b/src/main/java/ru/windcorp/progressia/client/comms/localhost/LocalClient.java index 816fba8..9fc0e47 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/localhost/LocalClient.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/localhost/LocalClient.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.localhost; import java.io.IOException; diff --git a/src/main/java/ru/windcorp/progressia/client/comms/localhost/LocalServerCommsChannel.java b/src/main/java/ru/windcorp/progressia/client/comms/localhost/LocalServerCommsChannel.java index 194a2a1..14ec90a 100644 --- a/src/main/java/ru/windcorp/progressia/client/comms/localhost/LocalServerCommsChannel.java +++ b/src/main/java/ru/windcorp/progressia/client/comms/localhost/LocalServerCommsChannel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.comms.localhost; import ru.windcorp.progressia.client.comms.ServerCommsChannel; @@ -34,11 +34,7 @@ public class LocalServerCommsChannel extends ServerCommsChannel { public void connect(String login) { setState(State.CONNECTED); - this.localClient = new LocalClient( - server.getClientManager().grabClientId(), - login, - this - ); + this.localClient = new LocalClient(server.getClientManager().grabClientId(), login, this); server.getClientManager().addClient(localClient); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/Colors.java b/src/main/java/ru/windcorp/progressia/client/graphics/Colors.java index 78aa79b..0aeee7d 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/Colors.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/Colors.java @@ -15,26 +15,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics; import glm.vec._4.Vec4; public class Colors { - public static final Vec4 WHITE = toVector(0xFFFFFFFF), - BLACK = toVector(0xFF000000), + public static final Vec4 WHITE = toVector(0xFFFFFFFF), BLACK = toVector(0xFF000000), - GRAY_4 = toVector(0xFF444444), - GRAY = toVector(0xFF888888), - GRAY_A = toVector(0xFFAAAAAA), + GRAY_4 = toVector(0xFF444444), GRAY = toVector(0xFF888888), GRAY_A = toVector(0xFFAAAAAA), - DEBUG_RED = toVector(0xFFFF0000), - DEBUG_GREEN = toVector(0xFF00FF00), - DEBUG_BLUE = toVector(0xFF0000FF), - DEBUG_CYAN = toVector(0xFF00FFFF), - DEBUG_MAGENTA = toVector(0xFFFF00FF), - DEBUG_YELLOW = toVector(0xFFFFFF00); + DEBUG_RED = toVector(0xFFFF0000), DEBUG_GREEN = toVector(0xFF00FF00), DEBUG_BLUE = toVector(0xFF0000FF), + DEBUG_CYAN = toVector(0xFF00FFFF), DEBUG_MAGENTA = toVector(0xFFFF00FF), + DEBUG_YELLOW = toVector(0xFFFFFF00); public static Vec4 toVector(int argb) { return toVector(argb, new Vec4()); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/GUI.java b/src/main/java/ru/windcorp/progressia/client/graphics/GUI.java index fc099d2..97e499c 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/GUI.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/GUI.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics; import java.util.ArrayList; @@ -42,7 +42,7 @@ public class GUI { } private static final List MODIFICATION_QUEUE = Collections - .synchronizedList(new ArrayList<>()); + .synchronizedList(new ArrayList<>()); private static class ModifiableInput extends Input { @Override diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/Layer.java b/src/main/java/ru/windcorp/progressia/client/graphics/Layer.java index 2dbef4a..ef6424c 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/Layer.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/Layer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/FaceCulling.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/FaceCulling.java index 61645f4..bdab268 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/FaceCulling.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/FaceCulling.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import java.util.ArrayDeque; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsBackend.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsBackend.java index 04c4a3d..233f3c9 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsBackend.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsBackend.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import glm.vec._2.i.Vec2i; @@ -61,7 +61,7 @@ public class GraphicsBackend { static void setOpenGLInitialized(boolean isOpenGLInitialized) { GraphicsBackend.isOpenGLInitialized = isOpenGLInitialized; } - + public static void initialize() { startRenderThread(); } @@ -159,27 +159,14 @@ public class GraphicsBackend { public static void setFullscreen() { GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); - glfwSetWindowMonitor( - getWindowHandle(), - glfwGetPrimaryMonitor(), - 0, - 0, - vidmode.width(), - vidmode.height(), - 0); + glfwSetWindowMonitor(getWindowHandle(), glfwGetPrimaryMonitor(), 0, 0, vidmode.width(), vidmode.height(), 0); isFullscreen = true; } public static void setWindowed() { GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); - glfwSetWindowMonitor( - getWindowHandle(), - 0, - (vidmode.width() - getFrameWidth()) / 2, - (vidmode.height() - getFrameHeight()) / 2, - getFrameWidth(), - getFrameHeight(), - 0); + glfwSetWindowMonitor(getWindowHandle(), 0, (vidmode.width() - getFrameWidth()) / 2, + (vidmode.height() - getFrameHeight()) / 2, getFrameWidth(), getFrameHeight(), 0); isFullscreen = false; } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsInterface.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsInterface.java index 799edfd..1fb18e3 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsInterface.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsInterface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import glm.vec._2.i.Vec2i; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/InputHandler.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/InputHandler.java index 34d936c..2dcbd44 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/InputHandler.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/InputHandler.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import org.lwjgl.glfw.GLFW; @@ -49,13 +49,7 @@ public class InputHandler { private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent(); - static void handleKeyInput( - long window, - int key, - int scancode, - int action, - int mods - ) { + static void handleKeyInput(long window, int key, int scancode, int action, int mods) { if (GraphicsBackend.getWindowHandle() != window) return; THE_KEY_EVENT.initialize(key, scancode, action, mods); @@ -71,12 +65,7 @@ public class InputHandler { } } - static void handleMouseButtonInput( - long window, - int key, - int action, - int mods - ) { + static void handleMouseButtonInput(long window, int key, int action, int mods) { handleKeyInput(window, key, Integer.MAX_VALUE - key, action, mods); } @@ -97,11 +86,7 @@ public class InputHandler { private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT = new ModifiableCursorMoveEvent(); - static void handleMouseMoveInput( - long window, - double x, - double y - ) { + static void handleMouseMoveInput(long window, double x, double y) { if (GraphicsBackend.getWindowHandle() != window) return; y = GraphicsInterface.getFrameHeight() - y; // Flip y axis @@ -131,11 +116,7 @@ public class InputHandler { private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT = new ModifiableWheelScrollEvent(); - static void handleWheelScroll( - long window, - double xoffset, - double yoffset - ) { + static void handleWheelScroll(long window, double xoffset, double yoffset) { if (GraphicsBackend.getWindowHandle() != window) return; THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset); @@ -162,10 +143,7 @@ public class InputHandler { /* * NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend */ - static void handleFrameResize( - int width, - int height - ) { + static void handleFrameResize(int width, int height) { THE_FRAME_RESIZE_EVENT.initialize(width, height); dispatch(THE_FRAME_RESIZE_EVENT); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/InputTracker.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/InputTracker.java index 29dec99..8e7e86c 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/InputTracker.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/InputTracker.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import glm.vec._2.d.Vec2d; @@ -24,10 +24,7 @@ import gnu.trove.set.hash.TIntHashSet; public class InputTracker { - private static final Vec2d CURSOR_POSITION = new Vec2d( - Double.NaN, - Double.NaN - ); + private static final Vec2d CURSOR_POSITION = new Vec2d(Double.NaN, Double.NaN); private static final TIntSet PRESSED_KEYS = new TIntHashSet(256); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java index 83c06c8..e311316 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import static org.lwjgl.opengl.GL11.*; @@ -68,7 +68,7 @@ class LWJGLInitializer { glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwMakeContextCurrent(handle); - glfwSwapInterval(0); // TODO: remove after config system is added + glfwSwapInterval(0); // TODO: remove after config system is added } private static void positionWindow() { @@ -94,16 +94,10 @@ class LWJGLInitializer { private static void setupWindowCallbacks() { long handle = GraphicsBackend.getWindowHandle(); - glfwSetFramebufferSizeCallback( - handle, - GraphicsBackend::onFrameResized - ); + glfwSetFramebufferSizeCallback(handle, GraphicsBackend::onFrameResized); glfwSetKeyCallback(handle, InputHandler::handleKeyInput); - glfwSetMouseButtonCallback( - handle, - InputHandler::handleMouseButtonInput - ); + glfwSetMouseButtonCallback(handle, InputHandler::handleMouseButtonInput); glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/OpenGLObjectTracker.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/OpenGLObjectTracker.java index c467d45..a62a32f 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/OpenGLObjectTracker.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/OpenGLObjectTracker.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import java.lang.ref.PhantomReference; @@ -34,19 +34,13 @@ public class OpenGLObjectTracker { private static final ReferenceQueue DELETE_QUEUE = new ReferenceQueue<>(); public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) { - GLPhantomReference glRef = new GLPhantomReference<>( - object, - DELETE_QUEUE, - object.getHandle(), - glDeleter - ); + GLPhantomReference glRef = new GLPhantomReference<>(object, DELETE_QUEUE, object.getHandle(), + glDeleter); TO_DELETE.add(glRef); } public static void deleteAllObjects() { - for ( - GLPhantomReference glRef : TO_DELETE - ) { + for (GLPhantomReference glRef : TO_DELETE) { glRef.clear(); } } @@ -75,20 +69,16 @@ public class OpenGLObjectTracker { * It is possible to create a phantom reference with a {@code null} * queue, but such a reference is completely useless: Its {@code get} * method will always return {@code null} and, since it does not have a - * queue, - * it will never be enqueued. + * queue, it will never be enqueued. * - * @param referent the object the new phantom reference will refer to - * @param q the queue with which the reference is to be - * registered, - * or {@code null} if registration is not required + * @param referent + * the object the new phantom reference will refer to + * @param q + * the queue with which the reference is to be registered, or + * {@code null} if registration is not required */ - public GLPhantomReference( - T referent, - ReferenceQueue q, - int referentGLhandle, - IntConsumer GLDeleter - ) { + public GLPhantomReference(T referent, ReferenceQueue q, int referentGLhandle, + IntConsumer GLDeleter) { super(referent, q); this.referentGLhandle = referentGLhandle; this.GLDeleter = GLDeleter; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderTaskQueue.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderTaskQueue.java index 0a1d722..5c8d260 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderTaskQueue.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderTaskQueue.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import ru.windcorp.jputil.functions.ThrowingRunnable; @@ -41,11 +41,7 @@ public class RenderTaskQueue { HANDLER.invokeNow(task); } - public static void waitAndInvoke( - ThrowingRunnable task - ) - throws InterruptedException, - E { + public static void waitAndInvoke(ThrowingRunnable task) throws InterruptedException, E { HANDLER.waitAndInvoke(task); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderThread.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderThread.java index 47d4306..d92385e 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderThread.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderThread.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import static org.lwjgl.glfw.GLFW.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/Usage.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/Usage.java index 8a526c1..dc3199d 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/Usage.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/Usage.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import static org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW; @@ -23,9 +23,7 @@ import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW; import static org.lwjgl.opengl.GL15.GL_STREAM_DRAW; public enum Usage { // TODO add _COPY and _READ, pref. as another enum - STATIC(GL_STATIC_DRAW), - DYNAMIC(GL_DYNAMIC_DRAW), - STREAM(GL_STREAM_DRAW); + STATIC(GL_STATIC_DRAW), DYNAMIC(GL_DYNAMIC_DRAW), STREAM(GL_STREAM_DRAW); private final int glCode; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/VertexBufferObject.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/VertexBufferObject.java index 7fe23f7..ad81138 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/VertexBufferObject.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/VertexBufferObject.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend; import static org.lwjgl.opengl.GL20.*; @@ -28,8 +28,7 @@ import ru.windcorp.progressia.client.graphics.backend.OpenGLObjectTracker.OpenGL public class VertexBufferObject implements OpenGLDeletable { public static enum BindTarget { - ARRAY(GL_ARRAY_BUFFER), - ELEMENT_ARRAY(GL_ELEMENT_ARRAY_BUFFER); + ARRAY(GL_ARRAY_BUFFER), ELEMENT_ARRAY(GL_ELEMENT_ARRAY_BUFFER); private final int glCode; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/CombinedShader.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/CombinedShader.java index 63fb4c9..754efba 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/CombinedShader.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/CombinedShader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders; import ru.windcorp.progressia.common.resource.Resource; @@ -32,12 +32,7 @@ public class CombinedShader extends Shader { for (int i = 1; i < resources.length; ++i) { if (ShaderType.guessByResourceName(resources[i]) != first) { throw new IllegalArgumentException( - "Deduced shader types of " - + resources[0] - + " and " - + resources[i] - + " differ" - ); + "Deduced shader types of " + resources[0] + " and " + resources[i] + " differ"); } } @@ -71,19 +66,8 @@ public class CombinedShader extends Shader { if (contents.codePointAt(versionIndex) == '#') { final String versionAnnotation = "#version "; - if ( - contents.regionMatches( - versionIndex, - versionAnnotation, - 0, - versionAnnotation.length() - ) - ) { - contents = contents.substring( - versionIndex - + versionAnnotation.length() - + "120".length() - ); + if (contents.regionMatches(versionIndex, versionAnnotation, 0, versionAnnotation.length())) { + contents = contents.substring(versionIndex + versionAnnotation.length() + "120".length()); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/Program.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/Program.java index 98d512e..b980c21 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/Program.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/Program.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders; import static org.lwjgl.opengl.GL11.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/Shader.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/Shader.java index 714fd1a..8851f66 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/Shader.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/Shader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders; import static org.lwjgl.opengl.GL11.*; @@ -57,10 +57,7 @@ public class Shader implements OpenGLDeletable { if (resource.contains("fsh")) return FRAGMENT; - throw new IllegalArgumentException( - "Cannot deduce shader type from resource name \"" + - resource + "\"" - ); + throw new IllegalArgumentException("Cannot deduce shader type from resource name \"" + resource + "\""); } } @@ -90,10 +87,7 @@ public class Shader implements OpenGLDeletable { } public Shader(String resource) { - this( - ShaderType.guessByResourceName(resource), - getShaderResource(resource).readAsString() - ); + this(ShaderType.guessByResourceName(resource), getShaderResource(resource).readAsString()); } @Override diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/attributes/Attribute.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/attributes/Attribute.java index d56210a..028a0b3 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/attributes/Attribute.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/attributes/Attribute.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.attributes; import ru.windcorp.progressia.client.graphics.backend.shaders.Program; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/attributes/AttributeVertexArray.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/attributes/AttributeVertexArray.java index 2ca192d..b380540 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/attributes/AttributeVertexArray.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/attributes/AttributeVertexArray.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.attributes; import static org.lwjgl.opengl.GL11.*; @@ -51,104 +51,29 @@ public class AttributeVertexArray extends Attribute { } } - public void set( - int size, - boolean normalized, - int stride, - ByteBuffer pointer - ) { - glVertexAttribPointer( - handle, - size, - GL_BYTE, - normalized, - stride, - pointer - ); + public void set(int size, boolean normalized, int stride, ByteBuffer pointer) { + glVertexAttribPointer(handle, size, GL_BYTE, normalized, stride, pointer); } - public void set( - int size, - boolean normalized, - int stride, - FloatBuffer pointer - ) { - glVertexAttribPointer( - handle, - size, - GL_FLOAT, - normalized, - stride, - pointer - ); + public void set(int size, boolean normalized, int stride, FloatBuffer pointer) { + glVertexAttribPointer(handle, size, GL_FLOAT, normalized, stride, pointer); } - public void set( - int size, - boolean normalized, - int stride, - IntBuffer pointer - ) { - glVertexAttribPointer( - handle, - size, - GL_INT, - normalized, - stride, - pointer - ); + public void set(int size, boolean normalized, int stride, IntBuffer pointer) { + glVertexAttribPointer(handle, size, GL_INT, normalized, stride, pointer); } - public void set( - int size, - boolean normalized, - int stride, - ShortBuffer pointer - ) { - glVertexAttribPointer( - handle, - size, - GL_SHORT, - normalized, - stride, - pointer - ); + public void set(int size, boolean normalized, int stride, ShortBuffer pointer) { + glVertexAttribPointer(handle, size, GL_SHORT, normalized, stride, pointer); } - public void set( - int size, - int type, - boolean normalized, - int stride, - long pointer - ) { - glVertexAttribPointer( - handle, - size, - type, - normalized, - stride, - pointer - ); + public void set(int size, int type, boolean normalized, int stride, long pointer) { + glVertexAttribPointer(handle, size, type, normalized, stride, pointer); } - public void set( - int size, - int type, - boolean normalized, - int stride, - VertexBufferObject vbo, - long offset - ) { + public void set(int size, int type, boolean normalized, int stride, VertexBufferObject vbo, long offset) { glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle()); - glVertexAttribPointer( - handle, - size, - type, - normalized, - stride, - offset - ); + glVertexAttribPointer(handle, size, type, normalized, stride, offset); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform.java index 8de5f1c..aa09d49 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import ru.windcorp.progressia.client.graphics.backend.shaders.Program; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform1Float.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform1Float.java index 6e2a62b..b41e313 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform1Float.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform1Float.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform1Int.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform1Int.java index 79d14a0..6389583 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform1Int.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform1Int.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Float.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Float.java index 166f47b..1c609c2 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Float.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Float.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Int.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Int.java index d8dde9b..679de9d 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Int.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Int.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Matrix.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Matrix.java index 6bbc3a9..b45c598 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Matrix.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform2Matrix.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Float.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Float.java index 21ea95b..d381a14 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Float.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Float.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Int.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Int.java index 1eb4690..283c459 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Int.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Int.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Matrix.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Matrix.java index 255fe2a..f2a0c12 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Matrix.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform3Matrix.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Float.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Float.java index daaab36..5aea97f 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Float.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Float.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Int.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Int.java index 6c2e760..31db411 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Int.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Int.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Matrix.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Matrix.java index e8281bd..e83cea5 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Matrix.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/shaders/uniforms/Uniform4Matrix.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; import static org.lwjgl.opengl.GL20.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/AssembledFlatLayer.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/AssembledFlatLayer.java index 83f9d6f..7bf8161 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/AssembledFlatLayer.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/AssembledFlatLayer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; import ru.windcorp.progressia.client.graphics.Layer; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/AssembledFlatRenderHelper.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/AssembledFlatRenderHelper.java index 5696ac2..789a378 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/AssembledFlatRenderHelper.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/AssembledFlatRenderHelper.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; import java.nio.FloatBuffer; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/DefaultFlatRenderHelper.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/DefaultFlatRenderHelper.java index 4ec676a..5550c24 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/DefaultFlatRenderHelper.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/DefaultFlatRenderHelper.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; import java.nio.FloatBuffer; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatGraphics.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatGraphics.java index 2b615ec..e7723e6 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatGraphics.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatGraphics.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; public class FlatGraphics { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatRenderHelper.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatRenderHelper.java index 704c579..1cdaf14 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatRenderHelper.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatRenderHelper.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; import java.nio.FloatBuffer; @@ -37,9 +37,8 @@ public abstract class FlatRenderHelper extends ShapeRenderHelper { float width = GraphicsInterface.getFrameWidth(); float height = GraphicsInterface.getFrameHeight(); - return finalTransform.identity().translate(-1, -1, 0) - .scale(2 / width, 2 / height, 1 / MAX_DEPTH) - .mul(getTransform()); + return finalTransform.identity().translate(-1, -1, 0).scale(2 / width, 2 / height, 1 / MAX_DEPTH) + .mul(getTransform()); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatRenderProgram.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatRenderProgram.java index 774e6f3..aecc404 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatRenderProgram.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/FlatRenderProgram.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; import java.nio.FloatBuffer; @@ -33,10 +33,8 @@ public class FlatRenderProgram extends ShapeRenderProgram { private static FlatRenderProgram def = null; public static void init() { - def = new FlatRenderProgram( - new String[] { "FlatDefault.vertex.glsl" }, - new String[] { "FlatDefault.fragment.glsl" } - ); + def = new FlatRenderProgram(new String[] { "FlatDefault.vertex.glsl" }, + new String[] { "FlatDefault.fragment.glsl" }); } public static FlatRenderProgram getDefault() { @@ -48,20 +46,13 @@ public class FlatRenderProgram extends ShapeRenderProgram { private static final String FLAT_VERTEX_SHADER_RESOURCE = "Flat.vertex.glsl"; private static final String FLAT_FRAGMENT_SHADER_RESOURCE = "Flat.fragment.glsl"; - private static final String MASK_COUNT_UNIFORM_NAME = "maskCount", - MASKS_UNIFORM_NAME = "masks"; + private static final String MASK_COUNT_UNIFORM_NAME = "maskCount", MASKS_UNIFORM_NAME = "masks"; private final Uniform1Int maskCountUniform; private final Uniform2Float masksUniform; - public FlatRenderProgram( - String[] vertexShaderResources, - String[] fragmentShaderResources - ) { - super( - attachVertexShader(vertexShaderResources), - attachFragmentShader(fragmentShaderResources) - ); + public FlatRenderProgram(String[] vertexShaderResources, String[] fragmentShaderResources) { + super(attachVertexShader(vertexShaderResources), attachFragmentShader(fragmentShaderResources)); this.maskCountUniform = getUniform(MASK_COUNT_UNIFORM_NAME).as1Int(); this.masksUniform = getUniform(MASKS_UNIFORM_NAME).as2Float(); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/Mask.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/Mask.java index e13400a..2114c24 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/Mask.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/Mask.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; public class Mask { @@ -88,8 +88,7 @@ public class Mask { @Override public String toString() { - return "(" + getStartX() + "; " + getStartY() + - ") -> (" + getEndX() + "; " + getEndY() + ")"; + return "(" + getStartX() + "; " + getStartY() + ") -> (" + getEndX() + "; " + getEndY() + ")"; } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/MaskStack.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/MaskStack.java index f114058..5f0e23c 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/MaskStack.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/MaskStack.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; import java.nio.FloatBuffer; @@ -24,9 +24,8 @@ import org.lwjgl.BufferUtils; public class MaskStack { - private final FloatBuffer buffer = BufferUtils.createFloatBuffer( - FlatRenderProgram.MASK_STACK_SIZE * TransformedMask.SIZE_IN_FLOATS - ); + private final FloatBuffer buffer = BufferUtils + .createFloatBuffer(FlatRenderProgram.MASK_STACK_SIZE * TransformedMask.SIZE_IN_FLOATS); public void pushMask(TransformedMask mask) { mask.writeToBuffer(buffer); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/RenderTarget.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/RenderTarget.java index 1fea54e..080b876 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/RenderTarget.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/RenderTarget.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; import java.util.ArrayList; @@ -45,11 +45,7 @@ public class RenderTarget { private final Mat4 transform; private final Renderable renderable; - public Clip( - Iterable masks, - Mat4 transform, - Renderable renderable - ) { + public Clip(Iterable masks, Mat4 transform, Renderable renderable) { for (TransformedMask mask : masks) { this.masks.pushMask(mask); } @@ -94,33 +90,19 @@ public class RenderTarget { protected void assembleCurrentClipFromFaces() { if (!currentClipFaces.isEmpty()) { - Face[] faces = currentClipFaces.toArray( - new Face[currentClipFaces.size()] - ); + Face[] faces = currentClipFaces.toArray(new Face[currentClipFaces.size()]); currentClipFaces.clear(); - Shape shape = new Shape( - Usage.STATIC, - FlatRenderProgram.getDefault(), - faces - ); + Shape shape = new Shape(Usage.STATIC, FlatRenderProgram.getDefault(), faces); - assembled.add( - new Clip( - maskStack, - getTransform(), - shape - ) - ); + assembled.add(new Clip(maskStack, getTransform(), shape)); } } public Clip[] assemble() { assembleCurrentClipFromFaces(); - Clip[] result = assembled.toArray( - new Clip[assembled.size()] - ); + Clip[] result = assembled.toArray(new Clip[assembled.size()]); reset(); @@ -142,21 +124,11 @@ public class RenderTarget { pushTransform(new Mat4().identity().translate(startX, startY, 0)); - maskStack.push( - new TransformedMask( - new Mask(startX, startY, endX, endY), - getTransform() - ) - ); + maskStack.push(new TransformedMask(new Mask(startX, startY, endX, endY), getTransform())); } public void pushMask(Mask mask) { - pushMaskStartEnd( - mask.getStartX(), - mask.getStartY(), - mask.getEndX(), - mask.getEndY() - ); + pushMaskStartEnd(mask.getStartX(), mask.getStartY(), mask.getEndX(), mask.getEndY()); } public void pushMaskStartSize(int x, int y, int width, int height) { @@ -189,142 +161,58 @@ public class RenderTarget { public void addCustomRenderer(Renderable renderable) { assembleCurrentClipFromFaces(); - assembled.add( - new Clip( - maskStack, - getTransform(), - renderable - ) - ); + assembled.add(new Clip(maskStack, getTransform(), renderable)); } protected void addFaceToCurrentClip(Face face) { currentClipFaces.add(face); } - public void drawTexture( - int x, - int y, - int width, - int height, - Vec4 color, - Texture texture - ) { - addFaceToCurrentClip( - createRectagleFace(x, y, width, height, color, texture) - ); + public void drawTexture(int x, int y, int width, int height, Vec4 color, Texture texture) { + addFaceToCurrentClip(createRectagleFace(x, y, width, height, color, texture)); } - public void drawTexture( - int x, - int y, - int width, - int height, - int color, - Texture texture - ) { + public void drawTexture(int x, int y, int width, int height, int color, Texture texture) { drawTexture(x, y, width, height, Colors.toVector(color), texture); } - public void drawTexture( - int x, - int y, - int width, - int height, - Texture texture - ) { + public void drawTexture(int x, int y, int width, int height, Texture texture) { drawTexture(x, y, width, height, Colors.WHITE, texture); } - public void fill( - int x, - int y, - int width, - int height, - Vec4 color - ) { + public void fill(int x, int y, int width, int height, Vec4 color) { drawTexture(x, y, width, height, color, null); } - public void fill( - int x, - int y, - int width, - int height, - int color - ) { + public void fill(int x, int y, int width, int height, int color) { fill(x, y, width, height, Colors.toVector(color)); } public void fill(Vec4 color) { - fill( - Integer.MIN_VALUE / 2, - Integer.MIN_VALUE / 2, - Integer.MAX_VALUE, - Integer.MAX_VALUE, - color - ); + fill(Integer.MIN_VALUE / 2, Integer.MIN_VALUE / 2, Integer.MAX_VALUE, Integer.MAX_VALUE, color); } public void fill(int color) { fill(Colors.toVector(color)); } - public Face createRectagleFace( - int x, - int y, - int width, - int height, - Vec4 color, - Texture texture - ) { + public Face createRectagleFace(int x, int y, int width, int height, Vec4 color, Texture texture) { float depth = this.depth--; - return Faces.createRectangle( - FlatRenderProgram.getDefault(), - texture, - color, - new Vec3(x, y, depth), - new Vec3(width, 0, 0), - new Vec3(0, height, 0), - false - ); + return Faces.createRectangle(FlatRenderProgram.getDefault(), texture, color, new Vec3(x, y, depth), + new Vec3(width, 0, 0), new Vec3(0, height, 0), false); } - public Face createRectagleFace( - int x, - int y, - int width, - int height, - int color, - Texture texture - ) { + public Face createRectagleFace(int x, int y, int width, int height, int color, Texture texture) { return createRectagleFace(x, y, width, height, Colors.toVector(color), texture); } - public Shape createRectagle( - int x, - int y, - int width, - int height, - Vec4 color, - Texture texture - ) { - return new Shape( - Usage.STATIC, - FlatRenderProgram.getDefault(), - createRectagleFace(x, y, width, height, color, texture) - ); + public Shape createRectagle(int x, int y, int width, int height, Vec4 color, Texture texture) { + return new Shape(Usage.STATIC, FlatRenderProgram.getDefault(), + createRectagleFace(x, y, width, height, color, texture)); } - public Shape createRectagle( - int x, - int y, - int width, - int height, - int color, - Texture texture - ) { + public Shape createRectagle(int x, int y, int width, int height, int color, Texture texture) { return createRectagle(x, y, width, height, Colors.toVector(color), texture); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/flat/TransformedMask.java b/src/main/java/ru/windcorp/progressia/client/graphics/flat/TransformedMask.java index 5328cc8..0f17a52 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/flat/TransformedMask.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/flat/TransformedMask.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.flat; import java.nio.FloatBuffer; @@ -42,14 +42,8 @@ public class TransformedMask { private Vec4 endXstartY = null; private Vec4 endXendY = null; - public TransformedMask( - Vec2 origin, - Vec2 width, - Vec2 height, - Vec2 counterOrigin, - Vec2 counterWidth, - Vec2 counterHeight - ) { + public TransformedMask(Vec2 origin, Vec2 width, Vec2 height, Vec2 counterOrigin, Vec2 counterWidth, + Vec2 counterHeight) { set(origin, width, height, counterOrigin, counterWidth, counterHeight); } @@ -61,14 +55,8 @@ public class TransformedMask { // Do nothing } - public TransformedMask set( - Vec2 origin, - Vec2 width, - Vec2 height, - Vec2 counterOrigin, - Vec2 counterWidth, - Vec2 counterHeight - ) { + public TransformedMask set(Vec2 origin, Vec2 width, Vec2 height, Vec2 counterOrigin, Vec2 counterWidth, + Vec2 counterHeight) { this.origin.set(origin.x, origin.y); this.width.set(width.x, width.y); this.height.set(height.x, height.y); @@ -112,35 +100,17 @@ public class TransformedMask { } private void setFields() { - origin.set( - startXstartY.x, - startXstartY.y - ); + origin.set(startXstartY.x, startXstartY.y); - width.set( - endXstartY.x - startXstartY.x, - endXstartY.y - startXstartY.y - ); + width.set(endXstartY.x - startXstartY.x, endXstartY.y - startXstartY.y); - height.set( - startXendY.x - startXstartY.x, - startXendY.y - startXstartY.y - ); + height.set(startXendY.x - startXstartY.x, startXendY.y - startXstartY.y); - counterOrigin.set( - endXendY.x, - endXendY.y - ); + counterOrigin.set(endXendY.x, endXendY.y); - counterWidth.set( - startXendY.x - endXendY.x, - startXendY.y - endXendY.y - ); + counterWidth.set(startXendY.x - endXendY.x, startXendY.y - endXendY.y); - counterHeight.set( - endXstartY.x - endXendY.x, - endXstartY.y - endXendY.y - ); + counterHeight.set(endXstartY.x - endXendY.x, endXstartY.y - endXendY.y); } public void writeToBuffer(FloatBuffer output) { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/font/Font.java b/src/main/java/ru/windcorp/progressia/client/graphics/font/Font.java index 591ff83..c7524a4 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/font/Font.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/font/Font.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.font; import java.util.function.Supplier; @@ -68,17 +68,11 @@ public class Font { return color; } - public Renderable assemble( - CharSequence chars, - float maxWidth - ) { + public Renderable assemble(CharSequence chars, float maxWidth) { return typeface.assembleStatic(chars, style, align, maxWidth, color); } - public Renderable assembleDynamic( - Supplier supplier, - float maxWidth - ) { + public Renderable assembleDynamic(Supplier supplier, float maxWidth) { return typeface.assembleDynamic(supplier, style, align, maxWidth, color); } @@ -102,7 +96,8 @@ public class Font { * Creates a new {@link Font} with the specified {@code style} exactly. This * object's style is ignored. * - * @param style the new style + * @param style + * the new style * @return the new font */ public Font withStyle(int style) { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifont.java b/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifont.java index f28975d..6b687b2 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifont.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifont.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.font; import gnu.trove.map.TCharObjectMap; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifontLoader.java b/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifontLoader.java index 9ead1db..3725b91 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifontLoader.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifontLoader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.font; import java.io.BufferedReader; @@ -73,7 +73,7 @@ public class GNUUnifontLoader { public static GNUUnifont load(Resource resource) { try (BufferedReader reader = createReader(resource)) { return createStream(reader).map(GNUUnifontLoader::parse).map(GNUUnifontLoader::addToAtlas) - .collect(Collectors.collectingAndThen(createMapper(), GNUUnifont::new)); + .collect(Collectors.collectingAndThen(createMapper(), GNUUnifont::new)); } catch (IOException | UncheckedIOException e) { throw CrashReports.report(e, "Could not load GNUUnifont"); } @@ -81,8 +81,7 @@ public class GNUUnifontLoader { private static BufferedReader createReader(Resource resource) throws IOException { return new BufferedReader( - new InputStreamReader(new GZIPInputStream(resource.getInputStream()), StandardCharsets.UTF_8) - ); + new InputStreamReader(new GZIPInputStream(resource.getInputStream()), StandardCharsets.UTF_8)); } private static Stream createStream(BufferedReader reader) { @@ -97,13 +96,8 @@ public class GNUUnifontLoader { char c = getChar(declar); - TextureDataEditor editor = new TextureDataEditor( - width, - GNUUnifont.HEIGHT, - width, - GNUUnifont.HEIGHT, - TEXTURE_SETTINGS - ); + TextureDataEditor editor = new TextureDataEditor(width, GNUUnifont.HEIGHT, width, GNUUnifont.HEIGHT, + TEXTURE_SETTINGS); for (int y = 0; y < GNUUnifont.HEIGHT; ++y) { for (int x = 0; x < width; ++x) { @@ -165,8 +159,7 @@ public class GNUUnifontLoader { if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'))) { throw new IOException( - "Illegal char in declar \"" + declar + "\" at index " + i + "; expected 0-9A-F" - ); + "Illegal char in declar \"" + declar + "\" at index " + i + "; expected 0-9A-F"); } } } @@ -190,18 +183,16 @@ public class GNUUnifontLoader { } private static Collector> createMapper() { - return Collector.of( - TCharObjectHashMap::new, + return Collector.of(TCharObjectHashMap::new, - (map, glyph) -> map.put(glyph.c, glyph.texture), + (map, glyph) -> map.put(glyph.c, glyph.texture), - (a, b) -> { - a.putAll(b); - return a; - }, + (a, b) -> { + a.putAll(b); + return a; + }, - Characteristics.UNORDERED - ); + Characteristics.UNORDERED); } private GNUUnifontLoader() { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/font/SpriteTypeface.java b/src/main/java/ru/windcorp/progressia/client/graphics/font/SpriteTypeface.java index 7920799..4b13a79 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/font/SpriteTypeface.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/font/SpriteTypeface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.font; import java.util.ArrayList; @@ -105,13 +105,7 @@ public abstract class SpriteTypeface extends Typeface { public abstract ShapeRenderProgram getProgram(); @Override - public Vec2i getSize( - CharSequence chars, - int style, - float align, - float maxWidth, - Vec2i output - ) { + public Vec2i getSize(CharSequence chars, int style, float align, float maxWidth, Vec2i output) { if (output == null) output = new Vec2i(); @@ -141,19 +135,8 @@ public abstract class SpriteTypeface extends Typeface { } private Shape createCharShape(char c) { - return new Shape( - Usage.STATIC, - getProgram(), - Faces.createRectangle( - getProgram(), - getTexture(c), - Colors.WHITE, - Vectors.ZERO_3, - new Vec3(getWidth(c), 0, 0), - new Vec3(0, getHeight(), 0), - false - ) - ); + return new Shape(Usage.STATIC, getProgram(), Faces.createRectangle(getProgram(), getTexture(c), Colors.WHITE, + Vectors.ZERO_3, new Vec3(getWidth(c), 0, 0), new Vec3(0, getHeight(), 0), false)); } private class DynamicText implements Renderable, Drawer { @@ -164,19 +147,8 @@ public abstract class SpriteTypeface extends Typeface { private final float maxWidth; private final Vec4 color; - private final Renderable unitLine = new Shape( - Usage.STATIC, - getProgram(), - Faces.createRectangle( - getProgram(), - null, - Vectors.UNIT_4, - Vectors.ZERO_3, - new Vec3(1, 0, 0), - new Vec3(0, 1, 0), - false - ) - ); + private final Renderable unitLine = new Shape(Usage.STATIC, getProgram(), Faces.createRectangle(getProgram(), + null, Vectors.UNIT_4, Vectors.ZERO_3, new Vec3(1, 0, 0), new Vec3(0, 1, 0), false)); private class DynamicWorkspace extends Workspace { private ShapeRenderHelper renderer; @@ -190,13 +162,7 @@ public abstract class SpriteTypeface extends Typeface { private final DynamicWorkspace workspace = new DynamicWorkspace(); - public DynamicText( - Supplier supplier, - int style, - float align, - float maxWidth, - Vec4 color - ) { + public DynamicText(Supplier supplier, int style, float align, float maxWidth, Vec4 color) { this.supplier = supplier; this.style = style; this.align = align; @@ -297,25 +263,12 @@ public abstract class SpriteTypeface extends Typeface { workspace.width.sub(workspace.origin); workspace.height.sub(workspace.origin); - workspace.faces.add( - Faces.createRectangle( - getProgram(), - texture, - color, - workspace.origin, - workspace.width, - workspace.height, - false - ) - ); + workspace.faces.add(Faces.createRectangle(getProgram(), texture, color, workspace.origin, workspace.width, + workspace.height, false)); } public Renderable assemble() { - return new Shape( - Usage.STATIC, - getProgram(), - workspace.faces.toArray(new Face[workspace.faces.size()]) - ); + return new Shape(Usage.STATIC, getProgram(), workspace.faces.toArray(new Face[workspace.faces.size()])); } } @@ -328,13 +281,8 @@ public abstract class SpriteTypeface extends Typeface { } @Override - public Renderable assembleDynamic( - Supplier supplier, - int style, - float align, - float maxWidth, - Vec4 color - ) { + public Renderable assembleDynamic(Supplier supplier, int style, float align, float maxWidth, + Vec4 color) { return new DynamicText(supplier, style, align, maxWidth, color); } @@ -424,15 +372,8 @@ public abstract class SpriteTypeface extends Typeface { void drawRectangle(Vec2 size, Vec4 color, Mat4 transform); } - protected void draw( - CharSequence text, - Drawer drawer, - Workspace workspace, - int style, - float align, - float maxWidth, - Vec4 color - ) { + protected void draw(CharSequence text, Drawer drawer, Workspace workspace, int style, float align, float maxWidth, + Vec4 color) { workspace.text = text; workspace.toIndex = text.length(); workspace.align = align; @@ -489,12 +430,7 @@ public abstract class SpriteTypeface extends Typeface { return w.align * (w.totalSize.x - w.currentWidth); } - private static final float[][] OUTLINE_DIRECTIONS = new float[][] { - { 0, 1 }, - { 1, 0 }, - { -1, 0 }, - { 0, -1 } - }; + private static final float[][] OUTLINE_DIRECTIONS = new float[][] { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } }; private void drawLine(Drawer drawer, Workspace workspace) { int style = workspace.styles.peek(); @@ -591,11 +527,8 @@ public abstract class SpriteTypeface extends Typeface { workspace.styles.pop(); } else { - throw new IllegalArgumentException( - "Style contains unknown flags " + Integer.toBinaryString( - (style & ~(Style.BOLD | Style.ITALIC | Style.SHADOW | Style.STRIKETHRU | Style.UNDERLINED)) - ) - ); + throw new IllegalArgumentException("Style contains unknown flags " + Integer.toBinaryString( + (style & ~(Style.BOLD | Style.ITALIC | Style.SHADOW | Style.STRIKETHRU | Style.UNDERLINED)))); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/font/Typeface.java b/src/main/java/ru/windcorp/progressia/client/graphics/font/Typeface.java index 3be5ebb..5cf83db 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/font/Typeface.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/font/Typeface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.font; import java.util.function.Supplier; @@ -29,12 +29,8 @@ import ru.windcorp.progressia.common.util.Vectors; public abstract class Typeface extends Named { public static class Style { - public static final int BOLD = 1 << 0, - ITALIC = 1 << 1, - UNDERLINED = 1 << 2, - STRIKETHRU = 1 << 3, - SHADOW = 1 << 4, - OUTLINED = 1 << 5; + public static final int BOLD = 1 << 0, ITALIC = 1 << 1, UNDERLINED = 1 << 2, STRIKETHRU = 1 << 3, + SHADOW = 1 << 4, OUTLINED = 1 << 5; public static final int PLAIN = 0; @@ -71,40 +67,19 @@ public abstract class Typeface extends Named { super(name); } - public abstract Renderable assembleStatic( - CharSequence chars, - int style, - float align, - float maxWidth, - Vec4 color - ); + public abstract Renderable assembleStatic(CharSequence chars, int style, float align, float maxWidth, Vec4 color); - public abstract Renderable assembleDynamic( - Supplier supplier, - int style, - float align, - float maxWidth, - Vec4 color - ); + public abstract Renderable assembleDynamic(Supplier supplier, int style, float align, float maxWidth, + Vec4 color); - public int getWidth( - CharSequence chars, - int style, - float align, - float maxWidth - ) { + public int getWidth(CharSequence chars, int style, float align, float maxWidth) { Vec2i v = Vectors.grab2i(); v = getSize(chars, style, align, maxWidth, v); Vectors.release(v); return v.x; } - public int getHeight( - CharSequence chars, - int style, - float align, - float maxWidth - ) { + public int getHeight(CharSequence chars, int style, float align, float maxWidth) { Vec2i v = Vectors.grab2i(); v = getSize(chars, style, align, maxWidth, v); Vectors.release(v); @@ -113,13 +88,7 @@ public abstract class Typeface extends Named { public abstract int getLineHeight(); - public abstract Vec2i getSize( - CharSequence chars, - int style, - float align, - float maxWidth, - Vec2i result - ); + public abstract Vec2i getSize(CharSequence chars, int style, float align, float maxWidth, Vec2i result); public abstract boolean supports(char c); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/font/Typefaces.java b/src/main/java/ru/windcorp/progressia/client/graphics/font/Typefaces.java index ed9c7c4..813087d 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/font/Typefaces.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/font/Typefaces.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.font; public class Typefaces { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Component.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Component.java index 4a131d8..05416e8 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Component.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Component.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui; import java.util.Collections; @@ -475,11 +475,8 @@ public class Component extends Named { eventBus.post(event); } - public void addListener( - Class type, - boolean handlesConsumed, - InputListener listener - ) { + public void addListener(Class type, boolean handlesConsumed, + InputListener listener) { if (inputBus == null) { inputBus = new InputBus(); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/DynamicLabel.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/DynamicLabel.java index bddad7b..ff62027 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/DynamicLabel.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/DynamicLabel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui; import glm.mat._4.Mat4; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/GUILayer.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/GUILayer.java index 2e0981c..9a4c648 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/GUILayer.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/GUILayer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui; import ru.windcorp.progressia.client.graphics.flat.AssembledFlatLayer; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Label.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Label.java index f7dbe33..cb074da 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Label.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Label.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui; import glm.mat._4.Mat4; @@ -95,13 +95,13 @@ public class Label extends Component { protected void assembleSelf(RenderTarget target) { float startX = getX() + font.getAlign() * (getWidth() - currentSize.x); - target.pushTransform( - new Mat4().identity().translate(startX, getY(), -1000) // TODO wtf - // is this - // magic - // <--- - .scale(2) - ); + target.pushTransform(new Mat4().identity().translate(startX, getY(), -1000) // TODO + // wtf + // is + // this + // magic + // <--- + .scale(2)); target.addCustomRenderer(font.assemble(currentText, maxWidth)); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Layout.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Layout.java index 8d5d84f..4d08ed4 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Layout.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Layout.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui; import glm.vec._2.i.Vec2i; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Panel.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Panel.java index 88e10f1..7f0cba9 100755 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Panel.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Panel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui; public class Panel extends Component { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildAddedEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildAddedEvent.java index f1611fe..9bbf93a 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildAddedEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildAddedEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.event; import ru.windcorp.progressia.client.graphics.gui.Component; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildEvent.java index a27cf79..0d63e38 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.event; import ru.windcorp.progressia.client.graphics.gui.Component; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildRemovedEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildRemovedEvent.java index 897d787..ec2e46c 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildRemovedEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ChildRemovedEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.event; import ru.windcorp.progressia.client.graphics.gui.Component; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ComponentEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ComponentEvent.java index b1d1175..dbf6e1c 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ComponentEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ComponentEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.event; import ru.windcorp.progressia.client.graphics.gui.Component; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/FocusEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/FocusEvent.java index ff859f3..fe476c2 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/FocusEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/FocusEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.event; import ru.windcorp.progressia.client.graphics.gui.Component; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/HierarchyEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/HierarchyEvent.java index d3a4984..5195c7e 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/HierarchyEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/HierarchyEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.event; import ru.windcorp.progressia.client.graphics.gui.Component; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/HoverEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/HoverEvent.java index b1d63ad..1e788f9 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/HoverEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/HoverEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.event; import ru.windcorp.progressia.client.graphics.gui.Component; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ParentChangedEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ParentChangedEvent.java index a7d9d40..ca5556a 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ParentChangedEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/event/ParentChangedEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.event; import ru.windcorp.progressia.client.graphics.gui.Component; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutAlign.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutAlign.java index d521914..422e108 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutAlign.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutAlign.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.layout; import static java.lang.Math.max; @@ -56,13 +56,8 @@ public class LayoutAlign implements Layout { size.x = min(size.x, cWidth); size.y = min(size.y, cHeight); - child.setBounds( - c.getX() + - (int) ((cWidth - size.x) * alignX) + margin, - c.getY() + - (int) ((cHeight - size.y) * alignY) + margin, - size - ); + child.setBounds(c.getX() + (int) ((cWidth - size.x) * alignX) + margin, + c.getY() + (int) ((cHeight - size.y) * alignY) + margin, size); }); } @@ -71,12 +66,10 @@ public class LayoutAlign implements Layout { public Vec2i calculatePreferredSize(Component c) { Vec2i result = new Vec2i(0, 0); - c.getChildren().stream() - .map(child -> child.getPreferredSize()) - .forEach(size -> { - result.x = max(size.x, result.x); - result.y = max(size.y, result.y); - }); + c.getChildren().stream().map(child -> child.getPreferredSize()).forEach(size -> { + result.x = max(size.x, result.x); + result.y = max(size.y, result.y); + }); result.x += 2 * margin; result.y += 2 * margin; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutBorderHorizontal.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutBorderHorizontal.java index 3e271de..05b9723 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutBorderHorizontal.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutBorderHorizontal.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.layout; import static java.lang.Math.max; @@ -26,9 +26,7 @@ import ru.windcorp.progressia.client.graphics.gui.Layout; public class LayoutBorderHorizontal implements Layout { - public static final String CENTER = "Center", - LEFT = "Left", - RIGHT = "Right"; + public static final String CENTER = "Center", LEFT = "Left", RIGHT = "Right"; private final int margin; @@ -51,32 +49,17 @@ public class LayoutBorderHorizontal implements Layout { if (child.getLayoutHint() == LEFT) { childSize = child.getPreferredSize(); left = childSize.x + margin; - child.setBounds( - c.getX(), - c.getY(), - childSize.x, - c.getHeight() - ); + child.setBounds(c.getX(), c.getY(), childSize.x, c.getHeight()); } else if (child.getLayoutHint() == RIGHT) { childSize = child.getPreferredSize(); right = childSize.x + margin; - child.setBounds( - c.getX() + c.getWidth() - childSize.x, - c.getY(), - childSize.x, - c.getHeight() - ); + child.setBounds(c.getX() + c.getWidth() - childSize.x, c.getY(), childSize.x, c.getHeight()); } } for (Component child : c.getChildren()) { if (child.getLayoutHint() == CENTER) { - child.setBounds( - c.getX() + left, - c.getY(), - c.getWidth() - left - right, - c.getHeight() - ); + child.setBounds(c.getX() + left, c.getY(), c.getWidth() - left - right, c.getHeight()); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutBorderVertical.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutBorderVertical.java index 0efcaa4..1d94db4 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutBorderVertical.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutBorderVertical.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.layout; import static java.lang.Math.max; @@ -26,9 +26,7 @@ import ru.windcorp.progressia.client.graphics.gui.Layout; public class LayoutBorderVertical implements Layout { - public static final String CENTER = "Center", - UP = "Up", - DOWN = "Down"; + public static final String CENTER = "Center", UP = "Up", DOWN = "Down"; private final int margin; @@ -51,32 +49,17 @@ public class LayoutBorderVertical implements Layout { if (child.getLayoutHint() == UP) { childSize = child.getPreferredSize(); top = childSize.y + margin; - child.setBounds( - c.getX(), - c.getY(), - c.getWidth(), - childSize.y - ); + child.setBounds(c.getX(), c.getY(), c.getWidth(), childSize.y); } else if (child.getLayoutHint() == DOWN) { childSize = child.getPreferredSize(); bottom = childSize.y + margin; - child.setBounds( - c.getX(), - c.getY() + c.getHeight() - childSize.y, - c.getWidth(), - childSize.y - ); + child.setBounds(c.getX(), c.getY() + c.getHeight() - childSize.y, c.getWidth(), childSize.y); } } for (Component child : c.getChildren()) { if (child.getLayoutHint() == CENTER) { - child.setBounds( - c.getX(), - c.getY() + top, - c.getWidth(), - c.getHeight() - top - bottom - ); + child.setBounds(c.getX(), c.getY() + top, c.getWidth(), c.getHeight() - top - bottom); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutGrid.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutGrid.java index fa2cdfe..20aebc1 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutGrid.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutGrid.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.layout; import java.util.Arrays; @@ -98,16 +98,13 @@ public class LayoutGrid implements Layout { if (!isSummed) throw new IllegalStateException("Not summed yet"); - child.setBounds( - parent.getX() + columns[column], - parent.getY() + rows[row], + child.setBounds(parent.getX() + columns[column], parent.getY() + rows[row], - (column != (columns.length - 1) ? (columns[column + 1] - columns[column] - gap) - : (parent.getWidth() - margin - columns[column])), + (column != (columns.length - 1) ? (columns[column + 1] - columns[column] - gap) + : (parent.getWidth() - margin - columns[column])), - (row != (rows.length - 1) ? (rows[row + 1] - rows[row] - gap) - : (parent.getHeight() - margin - rows[row])) - ); + (row != (rows.length - 1) ? (rows[row + 1] - rows[row] - gap) + : (parent.getHeight() - margin - rows[row]))); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutHorizontal.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutHorizontal.java index 85c37fa..5ce33b4 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutHorizontal.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutHorizontal.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.layout; import static java.lang.Math.max; @@ -43,8 +43,7 @@ public class LayoutHorizontal implements Layout { @Override public void layout(Component c) { - int x = c.getX() + margin, - y = c.getY() + margin; + int x = c.getX() + margin, y = c.getY() + margin; int width; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutVertical.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutVertical.java index 6e48d69..d03e124 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutVertical.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutVertical.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.gui.layout; import static java.lang.Math.max; @@ -43,8 +43,7 @@ public class LayoutVertical implements Layout { @Override public void layout(Component c) { - int x = c.getX() + margin, - y = c.getY() + c.getHeight(); + int x = c.getX() + margin, y = c.getY() + c.getHeight(); synchronized (c.getChildren()) { for (Component child : c.getChildren()) { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/CursorEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/CursorEvent.java index 43dd965..8bc480b 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/CursorEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/CursorEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; import glm.vec._2.d.Vec2d; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/CursorMoveEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/CursorMoveEvent.java index c87fc62..ccb107f 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/CursorMoveEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/CursorMoveEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; import glm.vec._2.Vec2; @@ -87,22 +87,14 @@ public class CursorMoveEvent extends CursorEvent { @Override public CursorMoveEvent snapshot() { - return new StaticMouseMoveEvent( - getPreviousPosition(), - getNewPosition(), - getTime() - ); + return new StaticMouseMoveEvent(getPreviousPosition(), getNewPosition(), getTime()); } private class StaticMouseMoveEvent extends CursorMoveEvent { private final Vec2d previousPosition = new Vec2d(); - public StaticMouseMoveEvent( - Vec2d previousPosition, - Vec2d newPosition, - double time - ) { + public StaticMouseMoveEvent(Vec2d previousPosition, Vec2d newPosition, double time) { super(newPosition, time); this.previousPosition.set(previousPosition.x, previousPosition.y); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/FrameResizeEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/FrameResizeEvent.java index 5589158..cf1a296 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/FrameResizeEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/FrameResizeEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; import glm.vec._2.i.Vec2i; @@ -67,11 +67,7 @@ public class FrameResizeEvent extends InputEvent { private final Vec2i previousSize; - public StaticFrameResizeEvent( - Vec2i newSize, - Vec2i previousSize, - double time - ) { + public StaticFrameResizeEvent(Vec2i newSize, Vec2i previousSize, double time) { super(newSize, time); this.previousSize = previousSize; } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/InputEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/InputEvent.java index b0c2483..dc8a187 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/InputEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/InputEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; public abstract class InputEvent { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/KeyEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/KeyEvent.java index 291b89e..c36e059 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/KeyEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/KeyEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; import org.lwjgl.glfw.GLFW; @@ -27,13 +27,7 @@ public class KeyEvent extends InputEvent { protected int action; protected int mods; - protected KeyEvent( - int key, - int scancode, - int action, - int mods, - double time - ) { + protected KeyEvent(int key, int scancode, int action, int mods, double time) { super(time); this.key = key; this.scancode = scancode; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/KeyMatcher.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/KeyMatcher.java index 6fedcd6..6073a7b 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/KeyMatcher.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/KeyMatcher.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; import java.util.function.Predicate; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/Keys.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/Keys.java index 3904f59..e0d6980 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/Keys.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/Keys.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; import java.lang.reflect.Field; @@ -46,17 +46,12 @@ public class Keys { private static final String MOUSE_BUTTON_PREFIX = "GLFW_MOUSE_BUTTON_"; private static final Set IGNORE_FIELDS = new HashSet<>( - Arrays.asList( - "GLFW_KEY_UNKNOWN", - "GLFW_KEY_LAST", - "GLFW_MOUSE_BUTTON_LAST", - "GLFW_MOUSE_BUTTON_1", // Alias - // for - // LEFT - "GLFW_MOUSE_BUTTON_2", // Alias for RIGHT - "GLFW_MOUSE_BUTTON_3" // Alias for MIDDLE - ) - ); + Arrays.asList("GLFW_KEY_UNKNOWN", "GLFW_KEY_LAST", "GLFW_MOUSE_BUTTON_LAST", "GLFW_MOUSE_BUTTON_1", // Alias + // for + // LEFT + "GLFW_MOUSE_BUTTON_2", // Alias for RIGHT + "GLFW_MOUSE_BUTTON_3" // Alias for MIDDLE + )); static { initializeDictionary(); @@ -100,14 +95,8 @@ public class Keys { } if (CODES_TO_NAMES.containsKey(value)) { - throw CrashReports.report( - null, - "Duplicate keys: %s and %s both map to %d(0x%s)", - CODES_TO_NAMES.get(value), - name, - value, - Integer.toHexString(value) - ); + throw CrashReports.report(null, "Duplicate keys: %s and %s both map to %d(0x%s)", CODES_TO_NAMES.get(value), + name, value, Integer.toHexString(value)); } CODES_TO_NAMES.put(value, name); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/WheelEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/WheelEvent.java index 24938c3..80c5282 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/WheelEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/WheelEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; public abstract class WheelEvent extends InputEvent { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/WheelScrollEvent.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/WheelScrollEvent.java index 968ff64..0ba2d2b 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/WheelScrollEvent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/WheelScrollEvent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input; import glm.vec._2.d.Vec2d; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/Input.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/Input.java index 1aad6bb..46da738 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/Input.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/Input.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input.bus; import ru.windcorp.progressia.client.graphics.input.InputEvent; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/InputBus.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/InputBus.java index a22a243..665831f 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/InputBus.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/InputBus.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input.bus; import java.util.ArrayList; @@ -31,28 +31,21 @@ public class InputBus { private final boolean handleConsumed; private final InputListener listener; - public WrappedListener( - Class type, - boolean handleConsumed, - InputListener listener - ) { + public WrappedListener(Class type, boolean handleConsumed, InputListener listener) { this.type = type; this.handleConsumed = handleConsumed; this.listener = listener; } private boolean handles(Input input) { - return (!input.isConsumed() || handleConsumed) && - type.isInstance(input.getEvent()); + return (!input.isConsumed() || handleConsumed) && type.isInstance(input.getEvent()); } @SuppressWarnings("unchecked") public void handle(Input input) { if (handles(input)) { boolean consumed = ((InputListener) listener) - .handle( - (InputEvent) type.cast(input.getEvent()) - ); + .handle((InputEvent) type.cast(input.getEvent())); input.setConsumed(consumed); } @@ -66,18 +59,12 @@ public class InputBus { listeners.forEach(l -> l.handle(input)); } - public void register( - Class type, - boolean handlesConsumed, - InputListener listener - ) { + public void register(Class type, boolean handlesConsumed, + InputListener listener) { listeners.add(new WrappedListener(type, handlesConsumed, listener)); } - public void register( - Class type, - InputListener listener - ) { + public void register(Class type, InputListener listener) { register(type, false, listener); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/InputListener.java b/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/InputListener.java index 0d68b5e..f6e3811 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/InputListener.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/input/bus/InputListener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.input.bus; import ru.windcorp.progressia.client.graphics.input.InputEvent; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/BlockFaceVectors.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/BlockFaceVectors.java index 3b929c0..e850d1a 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/BlockFaceVectors.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/BlockFaceVectors.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import static ru.windcorp.progressia.common.world.block.BlockFace.*; @@ -38,60 +38,40 @@ class BlockFaceVectors { Vec3 width = outer.getWidth(face); Vec3 height = outer.getHeight(face); - originBuilder.put( - face, - new Vec3(outer.getOrigin(face)) - ); + originBuilder.put(face, new Vec3(outer.getOrigin(face))); widthBuilder.put(face, new Vec3(width)); heightBuilder.put(face, new Vec3(height)); } - return new BlockFaceVectors( - originBuilder.build(), - widthBuilder.build(), - heightBuilder.build() - ); + return new BlockFaceVectors(originBuilder.build(), widthBuilder.build(), heightBuilder.build()); } private static final BlockFaceVectors OUTER; private static final BlockFaceVectors INNER; static { - OUTER = new BlockFaceVectors( - ImmutableMap.builder() + OUTER = new BlockFaceVectors(ImmutableMap.builder() - .put(TOP, new Vec3(-0.5f, +0.5f, +0.5f)) - .put(BOTTOM, new Vec3(-0.5f, -0.5f, -0.5f)) - .put(NORTH, new Vec3(+0.5f, -0.5f, -0.5f)) - .put(SOUTH, new Vec3(-0.5f, +0.5f, -0.5f)) - .put(WEST, new Vec3(+0.5f, +0.5f, -0.5f)) - .put(EAST, new Vec3(-0.5f, -0.5f, -0.5f)) + .put(TOP, new Vec3(-0.5f, +0.5f, +0.5f)).put(BOTTOM, new Vec3(-0.5f, -0.5f, -0.5f)) + .put(NORTH, new Vec3(+0.5f, -0.5f, -0.5f)).put(SOUTH, new Vec3(-0.5f, +0.5f, -0.5f)) + .put(WEST, new Vec3(+0.5f, +0.5f, -0.5f)).put(EAST, new Vec3(-0.5f, -0.5f, -0.5f)) .build(), - ImmutableMap.builder() + ImmutableMap.builder() - .put(TOP, new Vec3(0, -1, 0)) - .put(BOTTOM, new Vec3(0, +1, 0)) - .put(NORTH, new Vec3(0, +1, 0)) - .put(SOUTH, new Vec3(0, -1, 0)) - .put(WEST, new Vec3(-1, 0, 0)) - .put(EAST, new Vec3(+1, 0, 0)) + .put(TOP, new Vec3(0, -1, 0)).put(BOTTOM, new Vec3(0, +1, 0)).put(NORTH, new Vec3(0, +1, 0)) + .put(SOUTH, new Vec3(0, -1, 0)).put(WEST, new Vec3(-1, 0, 0)).put(EAST, new Vec3(+1, 0, 0)) - .build(), + .build(), - ImmutableMap.builder() + ImmutableMap.builder() - .put(TOP, new Vec3(+1, 0, 0)) - .put(BOTTOM, new Vec3(+1, 0, 0)) - .put(NORTH, new Vec3(0, 0, +1)) - .put(SOUTH, new Vec3(0, 0, +1)) - .put(WEST, new Vec3(0, 0, +1)) - .put(EAST, new Vec3(0, 0, +1)) + .put(TOP, new Vec3(+1, 0, 0)).put(BOTTOM, new Vec3(+1, 0, 0)).put(NORTH, new Vec3(0, 0, +1)) + .put(SOUTH, new Vec3(0, 0, +1)).put(WEST, new Vec3(0, 0, +1)).put(EAST, new Vec3(0, 0, +1)) - .build() - ); + .build()); INNER = createInner(OUTER); } @@ -104,11 +84,8 @@ class BlockFaceVectors { private final ImmutableMap widths; private final ImmutableMap heights; - public BlockFaceVectors( - ImmutableMap origins, - ImmutableMap widths, - ImmutableMap heights - ) { + public BlockFaceVectors(ImmutableMap origins, ImmutableMap widths, + ImmutableMap heights) { this.origins = origins; this.widths = widths; this.heights = heights; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/DynamicModel.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/DynamicModel.java index 9460bd7..80f880a 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/DynamicModel.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/DynamicModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import java.util.ArrayList; @@ -33,22 +33,14 @@ public abstract class DynamicModel extends Model { private final Mat4[] transforms; private final boolean[] dynamics; - public DynamicModel( - Renderable[] parts, - Mat4[] transforms, - boolean[] dynamic - ) { + public DynamicModel(Renderable[] parts, Mat4[] transforms, boolean[] dynamic) { super(parts); this.transforms = transforms; this.dynamics = dynamic; } public DynamicModel(Builder builder) { - this( - builder.getParts(), - builder.getTransforms(), - builder.getDynamics() - ); + this(builder.getParts(), builder.getTransforms(), builder.getDynamics()); } @Override @@ -78,11 +70,7 @@ public abstract class DynamicModel extends Model { protected Builder() { } - private Builder addPart( - Renderable part, - Mat4 transform, - boolean isDynamic - ) { + private Builder addPart(Renderable part, Mat4 transform, boolean isDynamic) { parts.add(Objects.requireNonNull(part, "part")); transforms.add(Objects.requireNonNull(transform, "transform")); dynamics.add(isDynamic); @@ -90,22 +78,15 @@ public abstract class DynamicModel extends Model { return this; } - public Builder addStaticPart( - Renderable part, - Mat4 transform - ) { + public Builder addStaticPart(Renderable part, Mat4 transform) { return addPart(part, new Mat4(transform), false); } - public Builder addDynamicPart( - Renderable part - ) { + public Builder addDynamicPart(Renderable part) { return addPart(part, new Mat4(), true); } - public Builder addStaticPart( - Renderable part - ) { + public Builder addStaticPart(Renderable part) { return addStaticPart(part, IDENTITY); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/EmptyModel.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/EmptyModel.java index f9cff67..f3e40a0 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/EmptyModel.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/EmptyModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import glm.mat._4.Mat4; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/Face.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/Face.java index 79da464..752c23a 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/Face.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/Face.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import java.nio.ByteBuffer; @@ -40,20 +40,13 @@ public class Face implements Comparable { private ShortBuffer userIndices; private boolean userIndicesUpdated = true; - public Face( - Texture texture, - ByteBuffer vertices, - ShortBuffer indices - ) { + public Face(Texture texture, ByteBuffer vertices, ShortBuffer indices) { setTexture(texture); setVertices(vertices); setIndices(indices); } - public Face( - Texture texture, - ByteBuffer vertices - ) { + public Face(Texture texture, ByteBuffer vertices) { this(texture, vertices, null); } @@ -66,22 +59,16 @@ public class Face implements Comparable { private void checkVertices() { if (vertices.remaining() % getBytesPerVertex() != 0) { - throw new IllegalArgumentException( - "Invalid vertex buffer: " + - (vertices.remaining() % getBytesPerVertex()) + - " extra bytes after last vertex" - ); + throw new IllegalArgumentException("Invalid vertex buffer: " + (vertices.remaining() % getBytesPerVertex()) + + " extra bytes after last vertex"); } } private void checkIndices() { if (userIndices != GENERATE_SUCCESSIVE_LATER) { if (userIndices.remaining() % 3 != 0) { - throw new IllegalArgumentException( - "Invalid vertex indices: " + - (userIndices.remaining() % 3) + - " extra indices after last triangle" - ); + throw new IllegalArgumentException("Invalid vertex indices: " + (userIndices.remaining() % 3) + + " extra indices after last triangle"); } userIndices.mark(); @@ -91,21 +78,15 @@ public class Face implements Comparable { short index = userIndices.get(); if (index < 0 || index >= vertexCount) { throw new IllegalArgumentException( - "Invalid vertex index " + index + - " (" + vertexCount + " vertices available)" - ); + "Invalid vertex index " + index + " (" + vertexCount + " vertices available)"); } } userIndices.reset(); } else { if (getVertexCount() % 3 != 0) { - throw new IllegalArgumentException( - "Invalid vertices: " + - (getVertexCount() % 3) + - " extra indices after last triangle " + - "(indices are automatic)" - ); + throw new IllegalArgumentException("Invalid vertices: " + (getVertexCount() % 3) + + " extra indices after last triangle " + "(indices are automatic)"); } } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/FaceGroup.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/FaceGroup.java index ee91544..7dc0356 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/FaceGroup.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/FaceGroup.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import ru.windcorp.progressia.client.graphics.texture.Texture; @@ -38,9 +38,8 @@ public class FaceGroup { for (int i = start; i < end; ++i) { Face face = faces[i]; - assert this.texture == null - ? (face.getTexture() == null) - : (face.getTexture().getSprite().getPrimitive() == this.texture); + assert this.texture == null ? (face.getTexture() == null) + : (face.getTexture().getSprite().getPrimitive() == this.texture); indexCount += face.getIndexCount(); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/Faces.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/Faces.java index d1e9c07..42eb2c0 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/Faces.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/Faces.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import java.nio.ShortBuffer; @@ -32,86 +32,30 @@ public class Faces { private Faces() { } - public static Face createRectangle( - ShapeRenderProgram program, - Texture texture, - Vec4 colorMultiplier, - Vec3 origin, - Vec3 width, - Vec3 height, - boolean flip - ) { + public static Face createRectangle(ShapeRenderProgram program, Texture texture, Vec4 colorMultiplier, Vec3 origin, + Vec3 width, Vec3 height, boolean flip) { VertexBuilder builder = program.getVertexBuilder(); - builder.addVertex( - origin, - colorMultiplier, - new Vec2(0, 0) - ).addVertex( - origin.add_(height), - colorMultiplier, - new Vec2(0, 1) - ).addVertex( - origin.add_(width), - colorMultiplier, - new Vec2(1, 0) - ).addVertex( - origin.add_(width).add(height), - colorMultiplier, - new Vec2(1, 1) - ); + builder.addVertex(origin, colorMultiplier, new Vec2(0, 0)) + .addVertex(origin.add_(height), colorMultiplier, new Vec2(0, 1)) + .addVertex(origin.add_(width), colorMultiplier, new Vec2(1, 0)) + .addVertex(origin.add_(width).add(height), colorMultiplier, new Vec2(1, 1)); - ShortBuffer buffer = flip ? ShortBuffer.wrap( - new short[] { - 0, - 1, - 3, - 0, - 3, - 2 - } - ) - : ShortBuffer.wrap( - new short[] { - 3, - 1, - 0, - 2, - 3, - 0 - } - ); + ShortBuffer buffer = flip ? ShortBuffer.wrap(new short[] { 0, 1, 3, 0, 3, 2 }) + : ShortBuffer.wrap(new short[] { 3, 1, 0, 2, 3, 0 }); - return new Face( - texture, - builder.assemble(), - buffer - ); + return new Face(texture, builder.assemble(), buffer); } - public static Face createBlockFace( - ShapeRenderProgram program, - Texture texture, - Vec4 colorMultiplier, - Vec3 blockCenter, - BlockFace face, - boolean inner - ) { + public static Face createBlockFace(ShapeRenderProgram program, Texture texture, Vec4 colorMultiplier, + Vec3 blockCenter, BlockFace face, boolean inner) { BlockFaceVectors vectors = BlockFaceVectors.get(inner); Vec3 origin = blockCenter.add_(vectors.getOrigin(face)); Vec3 width = vectors.getWidth(face); Vec3 height = vectors.getHeight(face); - return createRectangle( - program, - texture, - colorMultiplier, - origin, - width, - height, - inner - ); + return createRectangle(program, texture, colorMultiplier, origin, width, height, inner); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/LambdaModel.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/LambdaModel.java index 0ae31bf..b38df91 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/LambdaModel.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/LambdaModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import java.util.ArrayList; @@ -37,23 +37,13 @@ public class LambdaModel extends DynamicModel { private final TransformGetter[] getters; - public LambdaModel( - Renderable[] parts, - Mat4[] transforms, - boolean[] dynamic, - TransformGetter[] getters - ) { + public LambdaModel(Renderable[] parts, Mat4[] transforms, boolean[] dynamic, TransformGetter[] getters) { super(parts, transforms, dynamic); this.getters = getters; } public LambdaModel(Builder builder) { - this( - builder.getParts(), - builder.getTransforms(), - builder.getDynamics(), - builder.getGetters() - ); + this(builder.getParts(), builder.getTransforms(), builder.getDynamics(), builder.getGetters()); } @Override @@ -75,11 +65,7 @@ public class LambdaModel extends DynamicModel { protected Builder() { } - private Builder addPart( - Renderable part, - Mat4 transform, - TransformGetter getter - ) { + private Builder addPart(Renderable part, Mat4 transform, TransformGetter getter) { parts.add(Objects.requireNonNull(part, "part")); transforms.add(Objects.requireNonNull(transform, "transform")); dynamics.add(getter != null); @@ -88,23 +74,15 @@ public class LambdaModel extends DynamicModel { return this; } - public Builder addStaticPart( - Renderable part, - Mat4 transform - ) { + public Builder addStaticPart(Renderable part, Mat4 transform) { return addPart(part, new Mat4(transform), null); } - public Builder addDynamicPart( - Renderable part, - TransformGetter getter - ) { + public Builder addDynamicPart(Renderable part, TransformGetter getter) { return addPart(part, new Mat4(), getter); } - public Builder addStaticPart( - Renderable part - ) { + public Builder addStaticPart(Renderable part) { return addStaticPart(part, IDENTITY); } @@ -127,12 +105,8 @@ public class LambdaModel extends DynamicModel { } public static LambdaModel animate(Renderable model, TransformGetter transform) { - return new LambdaModel( - new Renderable[] { model }, - new Mat4[] { new Mat4() }, - new boolean[] { true }, - new TransformGetter[] { transform } - ); + return new LambdaModel(new Renderable[] { model }, new Mat4[] { new Mat4() }, new boolean[] { true }, + new TransformGetter[] { transform }); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/Model.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/Model.java index 47cd88b..5e59007 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/Model.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/Model.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import glm.mat._4.Mat4; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/Renderable.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/Renderable.java index 6063685..b379b75 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/Renderable.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/Renderable.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; public interface Renderable { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/Shape.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/Shape.java index 145b149..3a29c74 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/Shape.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/Shape.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import java.nio.ByteBuffer; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/ShapeRenderHelper.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/ShapeRenderHelper.java index 67578f6..517c711 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/ShapeRenderHelper.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/ShapeRenderHelper.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import glm.mat._4.Mat4; @@ -28,15 +28,10 @@ public class ShapeRenderHelper { protected static final int TRANSFORM_STACK_SIZE = 64; protected static final int COLOR_MULTIPLIER_STACK_SIZE = TRANSFORM_STACK_SIZE; - protected final StashingStack transformStack = new StashingStack<>( - TRANSFORM_STACK_SIZE, - Mat4::new - ); + protected final StashingStack transformStack = new StashingStack<>(TRANSFORM_STACK_SIZE, Mat4::new); - protected final StashingStack colorMultiplierStack = new StashingStack<>( - COLOR_MULTIPLIER_STACK_SIZE, - Vec4::new - ); + protected final StashingStack colorMultiplierStack = new StashingStack<>(COLOR_MULTIPLIER_STACK_SIZE, + Vec4::new); { transformStack.push().identity(); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/ShapeRenderProgram.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/ShapeRenderProgram.java index e27bc77..13a33e8 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/ShapeRenderProgram.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/ShapeRenderProgram.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import java.nio.ByteBuffer; @@ -43,19 +43,18 @@ import ru.windcorp.progressia.common.util.Vectors; public class ShapeRenderProgram extends Program { private static final int DEFAULT_BYTES_PER_VERTEX = 3 * Float.BYTES + // Position - 4 * Float.BYTES + // Color multiplier - 2 * Float.BYTES; // Texture coordinates + 4 * Float.BYTES + // Color multiplier + 2 * Float.BYTES; // Texture coordinates private static final String SHAPE_VERTEX_SHADER_RESOURCE = "Shape.vertex.glsl"; private static final String SHAPE_FRAGMENT_SHADER_RESOURCE = "Shape.fragment.glsl"; private static final String FINAL_TRANSFORM_UNIFORM_NAME = "finalTransform", - POSITIONS_ATTRIBUTE_NAME = "inputPositions", - UNIFORM_COLOR_MULTIPLER_ATTRIBUTE_NAME = "uniformColorMultiplier", - ATTRIBUTE_COLOR_MULTIPLER_ATTRIBUTE_NAME = "inputColorMultiplier", - TEXTURE_COORDS_ATTRIBUTE_NAME = "inputTextureCoords", - USE_TEXTURE_UNIFORM_NAME = "useTexture", - TEXTURE_SLOT_UNIFORM_NAME = "textureSlot"; + POSITIONS_ATTRIBUTE_NAME = "inputPositions", + UNIFORM_COLOR_MULTIPLER_ATTRIBUTE_NAME = "uniformColorMultiplier", + ATTRIBUTE_COLOR_MULTIPLER_ATTRIBUTE_NAME = "inputColorMultiplier", + TEXTURE_COORDS_ATTRIBUTE_NAME = "inputTextureCoords", USE_TEXTURE_UNIFORM_NAME = "useTexture", + TEXTURE_SLOT_UNIFORM_NAME = "textureSlot"; private final Uniform4Matrix finalTransformUniform; private final AttributeVertexArray positionsAttribute; @@ -65,21 +64,11 @@ public class ShapeRenderProgram extends Program { private final Uniform1Int useTextureUniform; private final Uniform1Int textureSlotUniform; - public ShapeRenderProgram( - String[] vertexShaderResources, - String[] fragmentShaderResources - ) { - super( - new CombinedShader( - attachVertexShader(vertexShaderResources) - ), - new CombinedShader( - attachFragmentShader(fragmentShaderResources) - ) - ); + public ShapeRenderProgram(String[] vertexShaderResources, String[] fragmentShaderResources) { + super(new CombinedShader(attachVertexShader(vertexShaderResources)), + new CombinedShader(attachFragmentShader(fragmentShaderResources))); - this.finalTransformUniform = getUniform(FINAL_TRANSFORM_UNIFORM_NAME) - .as4Matrix(); + this.finalTransformUniform = getUniform(FINAL_TRANSFORM_UNIFORM_NAME).as4Matrix(); this.positionsAttribute = getAttribute(POSITIONS_ATTRIBUTE_NAME).asVertexArray(); @@ -89,11 +78,9 @@ public class ShapeRenderProgram extends Program { this.textureCoordsAttribute = getAttribute(TEXTURE_COORDS_ATTRIBUTE_NAME).asVertexArray(); - this.useTextureUniform = getUniform(USE_TEXTURE_UNIFORM_NAME) - .as1Int(); + this.useTextureUniform = getUniform(USE_TEXTURE_UNIFORM_NAME).as1Int(); - this.textureSlotUniform = getUniform(TEXTURE_SLOT_UNIFORM_NAME) - .as1Int(); + this.textureSlotUniform = getUniform(TEXTURE_SLOT_UNIFORM_NAME).as1Int(); } private static String[] attachVertexShader(String[] others) { @@ -104,10 +91,7 @@ public class ShapeRenderProgram extends Program { return ObjectArrays.concat(SHAPE_FRAGMENT_SHADER_RESOURCE, others); } - public void render( - ShapeRenderHelper helper, - Shape shape - ) { + public void render(ShapeRenderHelper helper, Shape shape) { use(); configure(helper); @@ -145,34 +129,13 @@ public class ShapeRenderProgram extends Program { int vertexStride = getBytesPerVertex(); int offset = 0; - positionsAttribute.set( - 3, - GL11.GL_FLOAT, - false, - vertexStride, - vertices, - offset - ); + positionsAttribute.set(3, GL11.GL_FLOAT, false, vertexStride, vertices, offset); offset += 3 * Float.BYTES; - colorsAttribute.set( - 4, - GL11.GL_FLOAT, - false, - vertexStride, - vertices, - offset - ); + colorsAttribute.set(4, GL11.GL_FLOAT, false, vertexStride, vertices, offset); offset += 4 * Float.BYTES; - textureCoordsAttribute.set( - 2, - GL11.GL_FLOAT, - false, - vertexStride, - vertices, - offset - ); + textureCoordsAttribute.set(2, GL11.GL_FLOAT, false, vertexStride, vertices, offset); offset += 2 * Float.BYTES; return offset; @@ -193,12 +156,8 @@ public class ShapeRenderProgram extends Program { useTextureUniform.set(0); } - GL11.glDrawElements( - GL11.GL_TRIANGLES, - group.getIndexCount(), - GL11.GL_UNSIGNED_SHORT, - group.getByteOffsetOfIndices() - ); + GL11.glDrawElements(GL11.GL_TRIANGLES, group.getIndexCount(), GL11.GL_UNSIGNED_SHORT, + group.getByteOffsetOfIndices()); } public int getBytesPerVertex() { @@ -220,13 +179,9 @@ public class ShapeRenderProgram extends Program { Sprite sprite = face.getTexture().getSprite(); for (int i = 0; i < face.getVertexCount(); i++) { - int offset = vertices.position() + i * getBytesPerVertex() + (3 * Float.BYTES + - 4 * Float.BYTES); + int offset = vertices.position() + i * getBytesPerVertex() + (3 * Float.BYTES + 4 * Float.BYTES); - v.set( - vertices.getFloat(offset + 0 * Float.BYTES), - vertices.getFloat(offset + 1 * Float.BYTES) - ); + v.set(vertices.getFloat(offset + 0 * Float.BYTES), vertices.getFloat(offset + 1 * Float.BYTES)); v.mul(sprite.getSize()).add(sprite.getStart()); @@ -244,34 +199,11 @@ public class ShapeRenderProgram extends Program { } public static interface VertexBuilder { - VertexBuilder addVertex( - float x, - float y, - float z, - float r, - float g, - float b, - float tx, - float ty - ); + VertexBuilder addVertex(float x, float y, float z, float r, float g, float b, float tx, float ty); - VertexBuilder addVertex( - float x, - float y, - float z, - float r, - float g, - float b, - float a, - float tx, - float ty - ); + VertexBuilder addVertex(float x, float y, float z, float r, float g, float b, float a, float tx, float ty); - VertexBuilder addVertex( - Vec3 position, - Vec4 colorMultiplier, - Vec2 textureCoords - ); + VertexBuilder addVertex(Vec3 position, Vec4 colorMultiplier, Vec2 textureCoords); ByteBuffer assemble(); } @@ -293,84 +225,35 @@ public class ShapeRenderProgram extends Program { private final List vertices = new ArrayList<>(); @Override - public VertexBuilder addVertex( - float x, - float y, - float z, - float r, - float g, - float b, - float a, - float tx, - float ty - ) { - vertices.add( - new Vertex( - new Vec3(x, y, z), - new Vec4(r, g, b, a), - new Vec2(tx, ty) - ) - ); + public VertexBuilder addVertex(float x, float y, float z, float r, float g, float b, float a, float tx, + float ty) { + vertices.add(new Vertex(new Vec3(x, y, z), new Vec4(r, g, b, a), new Vec2(tx, ty))); return this; } @Override - public VertexBuilder addVertex( - float x, - float y, - float z, - float r, - float g, - float b, - float tx, - float ty - ) { - vertices.add( - new Vertex( - new Vec3(x, y, z), - new Vec4(r, g, b, 1f), - new Vec2(tx, ty) - ) - ); + public VertexBuilder addVertex(float x, float y, float z, float r, float g, float b, float tx, float ty) { + vertices.add(new Vertex(new Vec3(x, y, z), new Vec4(r, g, b, 1f), new Vec2(tx, ty))); return this; } @Override - public VertexBuilder addVertex( - Vec3 position, - Vec4 colorMultiplier, - Vec2 textureCoords - ) { - vertices.add( - new Vertex( - new Vec3(position), - new Vec4(colorMultiplier), - new Vec2(textureCoords) - ) - ); + public VertexBuilder addVertex(Vec3 position, Vec4 colorMultiplier, Vec2 textureCoords) { + vertices.add(new Vertex(new Vec3(position), new Vec4(colorMultiplier), new Vec2(textureCoords))); return this; } @Override public ByteBuffer assemble() { - ByteBuffer result = BufferUtils.createByteBuffer( - DEFAULT_BYTES_PER_VERTEX * vertices.size() - ); + ByteBuffer result = BufferUtils.createByteBuffer(DEFAULT_BYTES_PER_VERTEX * vertices.size()); for (Vertex v : vertices) { - result - .putFloat(v.position.x) - .putFloat(v.position.y) - .putFloat(v.position.z) - .putFloat(v.colorMultiplier.x) - .putFloat(v.colorMultiplier.y) - .putFloat(v.colorMultiplier.z) - .putFloat(v.colorMultiplier.w) - .putFloat(v.textureCoords.x) - .putFloat(v.textureCoords.y); + result.putFloat(v.position.x).putFloat(v.position.y).putFloat(v.position.z) + .putFloat(v.colorMultiplier.x).putFloat(v.colorMultiplier.y).putFloat(v.colorMultiplier.z) + .putFloat(v.colorMultiplier.w).putFloat(v.textureCoords.x).putFloat(v.textureCoords.y); } result.flip(); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/Shapes.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/Shapes.java index 7ddd5d6..e361392 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/Shapes.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/Shapes.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import java.util.Map; @@ -29,97 +29,37 @@ import ru.windcorp.progressia.common.world.block.BlockFace; public class Shapes { public static Shape createParallelepiped( - // Try saying that 10 times fast - ShapeRenderProgram program, + // Try saying that 10 times fast + ShapeRenderProgram program, - Vec3 origin, + Vec3 origin, - Vec3 width, - Vec3 height, - Vec3 depth, + Vec3 width, Vec3 height, Vec3 depth, - Vec4 colorMultiplier, + Vec4 colorMultiplier, - Texture topTexture, - Texture bottomTexture, - Texture northTexture, - Texture southTexture, - Texture eastTexture, - Texture westTexture, + Texture topTexture, Texture bottomTexture, Texture northTexture, Texture southTexture, Texture eastTexture, + Texture westTexture, - boolean flip - ) { + boolean flip) { - Face top = Faces.createRectangle( - program, - topTexture, - colorMultiplier, - origin.add_(height).add(width), - width.negate_(), - depth, - flip - ); + Face top = Faces.createRectangle(program, topTexture, colorMultiplier, origin.add_(height).add(width), + width.negate_(), depth, flip); - Face bottom = Faces.createRectangle( - program, - bottomTexture, - colorMultiplier, - origin, - width, - depth, - flip - ); + Face bottom = Faces.createRectangle(program, bottomTexture, colorMultiplier, origin, width, depth, flip); - Face north = Faces.createRectangle( - program, - northTexture, - colorMultiplier, - origin.add_(depth), - width, - height, - flip - ); + Face north = Faces.createRectangle(program, northTexture, colorMultiplier, origin.add_(depth), width, height, + flip); - Face south = Faces.createRectangle( - program, - southTexture, - colorMultiplier, - origin.add_(width), - width.negate_(), - height, - flip - ); + Face south = Faces.createRectangle(program, southTexture, colorMultiplier, origin.add_(width), width.negate_(), + height, flip); - Face east = Faces.createRectangle( - program, - eastTexture, - colorMultiplier, - origin, - depth, - height, - flip - ); + Face east = Faces.createRectangle(program, eastTexture, colorMultiplier, origin, depth, height, flip); - Face west = Faces.createRectangle( - program, - westTexture, - colorMultiplier, - origin.add_(width).add(depth), - depth.negate_(), - height, - flip - ); + Face west = Faces.createRectangle(program, westTexture, colorMultiplier, origin.add_(width).add(depth), + depth.negate_(), height, flip); - Shape result = new Shape( - Usage.STATIC, - program, - top, - bottom, - north, - south, - east, - west - ); + Shape result = new Shape(Usage.STATIC, program, top, bottom, north, south, east, west); return result; } @@ -145,15 +85,8 @@ public class Shapes { private boolean flip = false; - public PppBuilder( - ShapeRenderProgram program, - Texture top, - Texture bottom, - Texture north, - Texture south, - Texture east, - Texture west - ) { + public PppBuilder(ShapeRenderProgram program, Texture top, Texture bottom, Texture north, Texture south, + Texture east, Texture west) { this.program = program; this.topTexture = top; this.bottomTexture = bottom; @@ -163,19 +96,10 @@ public class Shapes { this.westTexture = west; } - public PppBuilder( - ShapeRenderProgram program, - Map textureMap - ) { - this( - program, - textureMap.get(BlockFace.TOP), - textureMap.get(BlockFace.BOTTOM), - textureMap.get(BlockFace.NORTH), - textureMap.get(BlockFace.SOUTH), - textureMap.get(BlockFace.EAST), - textureMap.get(BlockFace.WEST) - ); + public PppBuilder(ShapeRenderProgram program, Map textureMap) { + this(program, textureMap.get(BlockFace.TOP), textureMap.get(BlockFace.BOTTOM), + textureMap.get(BlockFace.NORTH), textureMap.get(BlockFace.SOUTH), textureMap.get(BlockFace.EAST), + textureMap.get(BlockFace.WEST)); } public PppBuilder(ShapeRenderProgram program, Texture texture) { @@ -266,21 +190,8 @@ public class Shapes { } public Shape create() { - return createParallelepiped( - program, - origin, - width, - height, - depth, - colorMultiplier, - topTexture, - bottomTexture, - northTexture, - southTexture, - eastTexture, - westTexture, - flip - ); + return createParallelepiped(program, origin, width, height, depth, colorMultiplier, topTexture, + bottomTexture, northTexture, southTexture, eastTexture, westTexture, flip); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/model/StaticModel.java b/src/main/java/ru/windcorp/progressia/client/graphics/model/StaticModel.java index 4c489d3..8c5ae87 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/model/StaticModel.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/model/StaticModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.model; import java.util.ArrayList; @@ -30,10 +30,7 @@ public class StaticModel extends Model { private final Mat4[] transforms; - public StaticModel( - Renderable[] parts, - Mat4[] transforms - ) { + public StaticModel(Renderable[] parts, Mat4[] transforms) { super(parts); this.transforms = transforms; } @@ -55,19 +52,14 @@ public class StaticModel extends Model { protected Builder() { } - public Builder addPart( - Renderable part, - Mat4 transform - ) { + public Builder addPart(Renderable part, Mat4 transform) { parts.add(Objects.requireNonNull(part, "part")); transforms.add(Objects.requireNonNull(transform, "transform")); return this; } - public Builder addPart( - Renderable part - ) { + public Builder addPart(Renderable part) { return addPart(part, IDENTITY); } @@ -78,7 +70,7 @@ public class StaticModel extends Model { private Mat4[] getTransforms() { return transforms.toArray(new Mat4[transforms.size()]); } - + public StaticModel build() { return new StaticModel(getParts(), getTransforms()); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/Atlases.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/Atlases.java index 94ed270..7ebe8fb 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/Atlases.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/Atlases.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import java.io.IOException; @@ -87,11 +87,8 @@ public class Atlases { editor.draw(data, nextX, nextY); - Sprite result = new Sprite( - getPrimitive(), - toPrimitiveCoords(nextX, nextY), - toPrimitiveCoords(width, height) - ); + Sprite result = new Sprite(getPrimitive(), toPrimitiveCoords(nextX, nextY), + toPrimitiveCoords(width, height)); nextX += width; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/ComplexTexture.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/ComplexTexture.java index a4f2881..31ecd52 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/ComplexTexture.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/ComplexTexture.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import java.util.Map; @@ -30,67 +30,27 @@ public class ComplexTexture { private final float assumedWidth; private final float assumedHeight; - public ComplexTexture( - TexturePrimitive primitive, - int abstractWidth, - int abstractHeight - ) { + public ComplexTexture(TexturePrimitive primitive, int abstractWidth, int abstractHeight) { this.primitive = primitive; - this.assumedWidth = abstractWidth - / (float) primitive.getWidth() * primitive.getBufferWidth(); + this.assumedWidth = abstractWidth / (float) primitive.getWidth() * primitive.getBufferWidth(); - this.assumedHeight = abstractHeight - / (float) primitive.getHeight() * primitive.getBufferHeight(); + this.assumedHeight = abstractHeight / (float) primitive.getHeight() * primitive.getBufferHeight(); } public Texture get(int x, int y, int width, int height) { - return new SimpleTexture( - new Sprite( - primitive, - new Vec2(x / assumedWidth, y / assumedHeight), - new Vec2(width / assumedWidth, height / assumedHeight) - ) - ); + return new SimpleTexture(new Sprite(primitive, new Vec2(x / assumedWidth, y / assumedHeight), + new Vec2(width / assumedWidth, height / assumedHeight))); } - public Map getCuboidTextures( - int x, - int y, - int width, - int height, - int depth - ) { - return BlockFace.mapToFaces( - get( - x + depth + width, - y + height + depth, - -width, - -depth - ), - get( - x + depth + width + width, - y + height + depth, - -width, - -depth - ), - get(x + depth, y, width, height), - get( - x + depth + width + depth, - y, - width, - height - ), - get(x, y, depth, height), - get(x + depth + width, y, depth, height) - ); + public Map getCuboidTextures(int x, int y, int width, int height, int depth) { + return BlockFace.mapToFaces(get(x + depth + width, y + height + depth, -width, -depth), + get(x + depth + width + width, y + height + depth, -width, -depth), get(x + depth, y, width, height), + get(x + depth + width + depth, y, width, height), get(x, y, depth, height), + get(x + depth + width, y, depth, height)); } - public Map getCuboidTextures( - int x, - int y, - int size - ) { + public Map getCuboidTextures(int x, int y, int size) { return getCuboidTextures(x, y, size, size, size); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTexture.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTexture.java index d772faa..f631f54 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTexture.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTexture.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; public class SimpleTexture extends Texture { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTextures.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTextures.java index 12db086..b547a8a 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTextures.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTextures.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import java.io.IOException; @@ -44,9 +44,7 @@ public class SimpleTextures { try { TextureDataEditor data = TextureLoader.loadPixels(resource, SETTINGS); - return new SimpleTexture( - new Sprite(new TexturePrimitive(data.getData())) - ); + return new SimpleTexture(new Sprite(new TexturePrimitive(data.getData()))); } catch (IOException e) { throw CrashReports.report(e, "Could not load texture %s", resource); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/Sprite.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/Sprite.java index fc13896..388c2dc 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/Sprite.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/Sprite.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import java.util.Objects; @@ -38,14 +38,8 @@ public class Sprite { } public Sprite(TexturePrimitive primitive) { - this( - primitive, - ORIGIN, - new Vec2( - primitive.getWidth() / (float) primitive.getBufferWidth(), - primitive.getHeight() / (float) primitive.getBufferHeight() - ) - ); + this(primitive, ORIGIN, new Vec2(primitive.getWidth() / (float) primitive.getBufferWidth(), + primitive.getHeight() / (float) primitive.getBufferHeight())); } public TexturePrimitive getPrimitive() { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/Texture.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/Texture.java index a4d89bf..3041679 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/Texture.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/Texture.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; public abstract class Texture { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureData.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureData.java index 0453984..891111b 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureData.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import static org.lwjgl.opengl.GL11.*; @@ -35,14 +35,8 @@ class TextureData { private final int width; private final int height; - public TextureData( - ByteBuffer data, - int bufferWidth, - int bufferHeight, - int width, - int height, - TextureSettings settings - ) { + public TextureData(ByteBuffer data, int bufferWidth, int bufferHeight, int width, int height, + TextureSettings settings) { this.data = data; this.width = width; this.height = height; @@ -66,16 +60,15 @@ class TextureData { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D( - GL_TEXTURE_2D, // Load 2D image - 0, // Not mipmapped - GL_RGBA, // Use RGBA - bufferWidth, // Width - bufferHeight, // Height - 0, // No border - GL_RGBA, // Use RGBA (required) - GL_UNSIGNED_BYTE, // Use unsigned bytes - data // Data buffer + glTexImage2D(GL_TEXTURE_2D, // Load 2D image + 0, // Not mipmapped + GL_RGBA, // Use RGBA + bufferWidth, // Width + bufferHeight, // Height + 0, // No border + GL_RGBA, // Use RGBA (required) + GL_UNSIGNED_BYTE, // Use unsigned bytes + data // Data buffer ); return handle; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureDataEditor.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureDataEditor.java index 7079f59..e52365c 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureDataEditor.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureDataEditor.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import static ru.windcorp.progressia.client.graphics.texture.TextureUtil.BYTES_PER_PIXEL; @@ -28,21 +28,10 @@ public class TextureDataEditor { protected final TextureData data; - public TextureDataEditor( - int bufferWidth, - int bufferHeight, - int contentWidth, - int contentHeight, - TextureSettings settings - ) { - this.data = new TextureData( - BufferUtils.createByteBuffer(bufferWidth * bufferHeight * 4), - bufferWidth, - bufferHeight, - contentWidth, - contentHeight, - settings - ); + public TextureDataEditor(int bufferWidth, int bufferHeight, int contentWidth, int contentHeight, + TextureSettings settings) { + this.data = new TextureData(BufferUtils.createByteBuffer(bufferWidth * bufferHeight * 4), bufferWidth, + bufferHeight, contentWidth, contentHeight, settings); } public TextureDataEditor(TextureData data) { @@ -61,21 +50,13 @@ public class TextureDataEditor { TextureData t = getData(); ByteBuffer fromBuffer = getBuffer(); - ByteBuffer toBuffer = BufferUtils.createByteBuffer( - fromBuffer.capacity() - ); + ByteBuffer toBuffer = BufferUtils.createByteBuffer(fromBuffer.capacity()); copy(fromBuffer, 0, fromBuffer.capacity(), toBuffer); toBuffer.clear(); - return new TextureData( - toBuffer, - t.getBufferWidth(), - t.getBufferHeight(), - t.getContentWidth(), - t.getContentHeight(), - t.getSettings() - ); + return new TextureData(toBuffer, t.getBufferWidth(), t.getBufferHeight(), t.getContentWidth(), + t.getContentHeight(), t.getSettings()); } public TextureData createSnapshot(TextureData output) { @@ -114,16 +95,7 @@ public class TextureDataEditor { return getData().getSettings(); } - public void draw( - ByteBuffer src, - int srcWidth, - int srcX, - int srcY, - int dstX, - int dstY, - int width, - int height - ) { + public void draw(ByteBuffer src, int srcWidth, int srcX, int srcY, int dstX, int dstY, int width, int height) { ByteBuffer dst = getBuffer(); int position = src.position(); @@ -148,77 +120,20 @@ public class TextureDataEditor { } } - public void draw( - TextureData source, - int srcX, - int srcY, - int dstX, - int dstY, - int width, - int height - ) { - draw( - source.getData(), - source.getBufferWidth(), - srcX, - srcY, - dstX, - dstY, - width, - height - ); + public void draw(TextureData source, int srcX, int srcY, int dstX, int dstY, int width, int height) { + draw(source.getData(), source.getBufferWidth(), srcX, srcY, dstX, dstY, width, height); } - public void draw( - TextureData source, - int dstX, - int dstY - ) { - draw( - source, - 0, - 0, - dstX, - dstY, - source.getContentWidth(), - source.getContentHeight() - ); + public void draw(TextureData source, int dstX, int dstY) { + draw(source, 0, 0, dstX, dstY, source.getContentWidth(), source.getContentHeight()); } - public void draw( - TextureDataEditor source, - int srcX, - int srcY, - int dstX, - int dstY, - int width, - int height - ) { - draw( - source.getData(), - srcX, - srcY, - dstX, - dstY, - width, - height - ); + public void draw(TextureDataEditor source, int srcX, int srcY, int dstX, int dstY, int width, int height) { + draw(source.getData(), srcX, srcY, dstX, dstY, width, height); } - public void draw( - TextureDataEditor source, - int dstX, - int dstY - ) { - draw( - source, - 0, - 0, - dstX, - dstY, - source.getContentWidth(), - source.getContentHeight() - ); + public void draw(TextureDataEditor source, int dstX, int dstY) { + draw(source, 0, 0, dstX, dstY, source.getContentWidth(), source.getContentHeight()); } public void setPixel(int x, int y, int color) { @@ -237,12 +152,7 @@ public class TextureDataEditor { buffer.limit(buffer.position() + length * BYTES_PER_PIXEL); } - private static void copy( - ByteBuffer src, - int srcStart, - int srcEnd, - ByteBuffer dst - ) { + private static void copy(ByteBuffer src, int srcStart, int srcEnd, ByteBuffer dst) { int position = src.position(); int limit = src.limit(); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureLoader.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureLoader.java index 18f2326..d406c65 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureLoader.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureLoader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import java.awt.Graphics2D; @@ -31,11 +31,7 @@ import ru.windcorp.progressia.common.util.BinUtil; public class TextureLoader { - public static TextureDataEditor loadPixels( - InputStream compressed, - TextureSettings settings - ) - throws IOException { + public static TextureDataEditor loadPixels(InputStream compressed, TextureSettings settings) throws IOException { BufferedImage readResult = ImageIO.read(compressed); int width = readResult.getWidth(); @@ -44,10 +40,7 @@ public class TextureLoader { int bufferWidth = BinUtil.roundToGreaterPowerOf2(width); int bufferHeight = BinUtil.roundToGreaterPowerOf2(height); - WritableRaster raster = TextureUtil.createRaster( - bufferWidth, - bufferHeight - ); + WritableRaster raster = TextureUtil.createRaster(bufferWidth, bufferHeight); BufferedImage canvas = TextureUtil.createCanvas(raster); @@ -56,49 +49,22 @@ public class TextureLoader { try { g.setColor(TextureUtil.CANVAS_BACKGROUND); g.fillRect(0, 0, bufferWidth, bufferHeight); - g.drawImage( - readResult, - 0, - 0, - width, - height, - 0, - height, - width, - 0, // Flip the image - null - ); + g.drawImage(readResult, 0, 0, width, height, 0, height, width, 0, // Flip + // the + // image + null); } finally { g.dispose(); } - TextureDataEditor result = new TextureDataEditor( - bufferWidth, - bufferHeight, - width, - height, - settings - ); + TextureDataEditor result = new TextureDataEditor(bufferWidth, bufferHeight, width, height, settings); - result.draw( - TextureUtil.extractBytes(raster), - bufferWidth, - 0, - 0, - 0, - 0, - width, - height - ); + result.draw(TextureUtil.extractBytes(raster), bufferWidth, 0, 0, 0, 0, width, height); return result; } - public static TextureDataEditor loadPixels( - Resource resource, - TextureSettings settings - ) - throws IOException { + public static TextureDataEditor loadPixels(Resource resource, TextureSettings settings) throws IOException { return loadPixels(resource.getInputStream(), settings); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TexturePrimitive.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TexturePrimitive.java index a1895bb..62c981b 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TexturePrimitive.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TexturePrimitive.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import static org.lwjgl.opengl.GL11.*; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureSettings.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureSettings.java index 3dd43a4..0b75742 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureSettings.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureSettings.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; public class TextureSettings { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureUtil.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureUtil.java index ea0fdee..72eab34 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureUtil.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.texture; import java.awt.Color; @@ -39,35 +39,28 @@ public class TextureUtil { public static final Color CANVAS_BACKGROUND = new Color(0, true); - public static final ColorModel COLOR_MODEL = new ComponentColorModel( - ColorSpace.getInstance(ColorSpace.CS_sRGB), // Use RGB - null, // Use every bit - true, // Has alpha - false, // Not premultiplied - Transparency.TRANSLUCENT, // Can have any alpha - DataBuffer.TYPE_BYTE // Store bytewise + public static final ColorModel COLOR_MODEL = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), // Use + // RGB + null, // Use every bit + true, // Has alpha + false, // Not premultiplied + Transparency.TRANSLUCENT, // Can have any alpha + DataBuffer.TYPE_BYTE // Store bytewise ); private static final Hashtable BUFFERED_IMAGE_PROPERTIES = new Hashtable<>(); - public static WritableRaster createRaster( - int bufferWidth, - int bufferHeight - ) { - return Raster.createInterleavedRaster( - DataBuffer.TYPE_BYTE, // Storage model - bufferWidth, // Buffer width - bufferHeight, // Buffer height - BYTES_PER_PIXEL, // ARGB - null // Location (here (0; 0)) + public static WritableRaster createRaster(int bufferWidth, int bufferHeight) { + return Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, // Storage + // model + bufferWidth, // Buffer width + bufferHeight, // Buffer height + BYTES_PER_PIXEL, // ARGB + null // Location (here (0; 0)) ); } - public static WritableRaster createRaster( - ByteBuffer buffer, - int bufferWidth, - int bufferHeight - ) { + public static WritableRaster createRaster(ByteBuffer buffer, int bufferWidth, int bufferHeight) { final int bands = BYTES_PER_PIXEL; byte[] bytes = new byte[bufferWidth * bufferHeight * bands]; @@ -77,23 +70,21 @@ public class TextureUtil { DataBufferByte dataBuffer = new DataBufferByte(bytes, bytes.length); - return Raster.createInterleavedRaster( - dataBuffer, // The buffer - bufferWidth, // Buffer width - bufferHeight, // Buffer height - bands * bufferWidth, // Scanline stride - bands, // Pixel stride - new int[] { 0, 1, 2, 3 }, // Band offsets - null // Location (here (0; 0)) + return Raster.createInterleavedRaster(dataBuffer, // The buffer + bufferWidth, // Buffer width + bufferHeight, // Buffer height + bands * bufferWidth, // Scanline stride + bands, // Pixel stride + new int[] { 0, 1, 2, 3 }, // Band offsets + null // Location (here (0; 0)) ); } public static BufferedImage createCanvas(WritableRaster raster) { - return new BufferedImage( - COLOR_MODEL, // Color model - raster, // Backing raster - false, // Raster is not premultipied - BUFFERED_IMAGE_PROPERTIES // Properties + return new BufferedImage(COLOR_MODEL, // Color model + raster, // Backing raster + false, // Raster is not premultipied + BUFFERED_IMAGE_PROPERTIES // Properties ); } @@ -107,10 +98,7 @@ public class TextureUtil { return buffer; } - public static ByteBuffer extractBytes( - WritableRaster raster, - ByteBuffer output - ) { + public static ByteBuffer extractBytes(WritableRaster raster, ByteBuffer output) { byte[] data = ((DataBufferByte) raster.getDataBuffer()).getData(); output.put(data); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/Camera.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/Camera.java index 46b551c..c8faf61 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/Camera.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/Camera.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.world; import static java.lang.Math.*; @@ -42,10 +42,7 @@ public class Camera { void applyCameraRotation(Mat4 output); - public static Mode of( - Consumer offsetGetter, - Consumer rotator - ) { + public static Mode of(Consumer offsetGetter, Consumer rotator) { return new Mode() { @Override public void getCameraOffset(Vec3 output) { @@ -121,13 +118,8 @@ public class Camera { private void applyPerspective(WorldRenderHelper helper) { Mat4 previous = helper.getViewTransform(); - Glm.perspective( - computeFovY(), - GraphicsInterface.getAspectRatio(), - 0.01f, - 150.0f, - helper.pushViewTransform() - ).mul(previous); + Glm.perspective(computeFovY(), GraphicsInterface.getAspectRatio(), 0.01f, 150.0f, helper.pushViewTransform()) + .mul(previous); } private void rotateCoordinateSystem(WorldRenderHelper helper) { @@ -152,23 +144,14 @@ public class Camera { float pitch = anchor.getCameraPitch(); float yaw = anchor.getCameraYaw(); - helper.pushViewTransform() - .rotateY(-pitch) - .rotateZ(-yaw); + helper.pushViewTransform().rotateY(-pitch).rotateZ(-yaw); this.lastAnchorYaw = yaw; this.lastAnchorPitch = pitch; - this.lastAnchorLookingAt.set( - cos(pitch) * cos(yaw), - cos(pitch) * sin(yaw), - sin(pitch) - ); - this.lastAnchorUp.set( - cos(pitch + PI_F / 2) * cos(yaw), - cos(pitch + PI_F / 2) * sin(yaw), - sin(pitch + PI_F / 2) - ); + this.lastAnchorLookingAt.set(cos(pitch) * cos(yaw), cos(pitch) * sin(yaw), sin(pitch)); + this.lastAnchorUp.set(cos(pitch + PI_F / 2) * cos(yaw), cos(pitch + PI_F / 2) * sin(yaw), + sin(pitch + PI_F / 2)); } private void applyPosition(WorldRenderHelper helper) { @@ -194,11 +177,7 @@ public class Camera { if (widthOverHeight >= 1) { return fieldOfView; } else { - return (float) (2 * atan( - 1 / widthOverHeight - * - tan(fieldOfView / 2) - )); + return (float) (2 * atan(1 / widthOverHeight * tan(fieldOfView / 2))); } } @@ -234,9 +213,7 @@ public class Camera { if (modesCollection.isEmpty()) { throw new IllegalArgumentException( - "Anchor " + anchor + " returned no camera modes," - + " at least one required" - ); + "Anchor " + anchor + " returned no camera modes," + " at least one required"); } this.anchor = anchor; @@ -250,24 +227,8 @@ public class Camera { this.lastAnchorYaw = Float.NaN; this.lastAnchorPitch = Float.NaN; - this.lastCameraMatrix.set( - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN, - Float.NaN - ); + this.lastCameraMatrix.set(Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, + Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN); this.lastAnchorLookingAt.set(Float.NaN); this.lastAnchorUp.set(Float.NaN); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/EntityAnchor.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/EntityAnchor.java index d11ea92..6b34029 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/EntityAnchor.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/EntityAnchor.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.world; import java.util.Collection; @@ -39,23 +39,16 @@ public class EntityAnchor implements Anchor { this.model = model; this.modes = ImmutableList.of( - // From viewpoint / first person - Mode.of(v -> v.set(0), m -> { - }), + // From viewpoint / first person + Mode.of(v -> v.set(0), m -> { + }), - // Third person, looking forward - Mode.of( - v -> v.set(-3.5f, +0.5f, 0), - m -> { - } - ), + // Third person, looking forward + Mode.of(v -> v.set(-3.5f, +0.5f, 0), m -> { + }), - // Third person, looking back - Mode.of( - v -> v.set(-3.5f, 0, 0), - m -> m.rotateZ((float) Math.PI) - ) - ); + // Third person, looking back + Mode.of(v -> v.set(-3.5f, 0, 0), m -> m.rotateZ((float) Math.PI))); } @Override diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/LayerWorld.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/LayerWorld.java index 317dfa2..ccc052a 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/LayerWorld.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/LayerWorld.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.world; import java.util.ArrayList; @@ -132,12 +132,8 @@ public class LayerWorld extends Layer { tmp_collideableList.clear(); tmp_collideableList.addAll(this.client.getWorld().getData().getEntities()); - Collider.performCollisions( - tmp_collideableList, - this.client.getWorld().getData(), - tickLength, - tmp_colliderWorkspace - ); + Collider.performCollisions(tmp_collideableList, this.client.getWorld().getData(), tickLength, + tmp_colliderWorkspace); } private static final Renderable SELECTION_BOX = tmp_createSelectionBox(); @@ -166,26 +162,14 @@ public class LayerWorld extends Layer { for (float phi = 0; phi < 2 * FloatMathUtil.PI_F; phi += FloatMathUtil.PI_F / 2) { Mat4 rot = new Mat4().identity().rotateZ(phi).scale(scale); - b.addPart( - new PppBuilder(p, (Texture) null).setOrigin( - new Vec3(-f - 0.5f, -f - 0.5f, -f - 0.5f) - ).setSize(f, f, 2 * f + 1).setColorMultiplier(color).create(), - rot - ); + b.addPart(new PppBuilder(p, (Texture) null).setOrigin(new Vec3(-f - 0.5f, -f - 0.5f, -f - 0.5f)) + .setSize(f, f, 2 * f + 1).setColorMultiplier(color).create(), rot); - b.addPart( - new PppBuilder(p, (Texture) null).setOrigin( - new Vec3(-f - 0.5f, -0.5f, -f - 0.5f) - ).setSize(f, 1, f).setColorMultiplier(color).create(), - rot - ); + b.addPart(new PppBuilder(p, (Texture) null).setOrigin(new Vec3(-f - 0.5f, -0.5f, -f - 0.5f)) + .setSize(f, 1, f).setColorMultiplier(color).create(), rot); - b.addPart( - new PppBuilder(p, (Texture) null).setOrigin( - new Vec3(-f - 0.5f, -0.5f, +0.5f) - ).setSize(f, 1, f).setColorMultiplier(color).create(), - rot - ); + b.addPart(new PppBuilder(p, (Texture) null).setOrigin(new Vec3(-f - 0.5f, -0.5f, +0.5f)).setSize(f, 1, f) + .setColorMultiplier(color).create(), rot); } return b.build(); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/LocalPlayer.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/LocalPlayer.java index 620185b..7a4443a 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/LocalPlayer.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/LocalPlayer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.world; import ru.windcorp.progressia.client.Client; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/Selection.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/Selection.java index cd4ba29..3d997ee 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/Selection.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/Selection.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.world; import glm.vec._2.Vec2; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/WorldRenderHelper.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/WorldRenderHelper.java index de17238..e677eaf 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/WorldRenderHelper.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/WorldRenderHelper.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.world; import glm.mat._4.Mat4; @@ -24,10 +24,7 @@ import ru.windcorp.progressia.common.util.StashingStack; public class WorldRenderHelper extends ShapeRenderHelper { - private final StashingStack viewTransformStack = new StashingStack<>( - TRANSFORM_STACK_SIZE, - Mat4::new - ); + private final StashingStack viewTransformStack = new StashingStack<>(TRANSFORM_STACK_SIZE, Mat4::new); { viewTransformStack.push().identity(); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/WorldRenderProgram.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/WorldRenderProgram.java index 5e55297..3e7223c 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/WorldRenderProgram.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/WorldRenderProgram.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.graphics.world; import java.nio.ByteBuffer; @@ -44,10 +44,8 @@ public class WorldRenderProgram extends ShapeRenderProgram { private static WorldRenderProgram def = null; public static void init() { - def = new WorldRenderProgram( - new String[] { "WorldDefault.vertex.glsl" }, - new String[] { "WorldDefault.fragment.glsl" } - ); + def = new WorldRenderProgram(new String[] { "WorldDefault.vertex.glsl" }, + new String[] { "WorldDefault.fragment.glsl" }); } public static WorldRenderProgram getDefault() { @@ -55,33 +53,25 @@ public class WorldRenderProgram extends ShapeRenderProgram { } private static final int DEFAULT_BYTES_PER_VERTEX = 3 * Float.BYTES + // Position - 4 * Float.BYTES + // Color multiplier - 2 * Float.BYTES + // Texture coordinates - 3 * Float.BYTES; // Normals + 4 * Float.BYTES + // Color multiplier + 2 * Float.BYTES + // Texture coordinates + 3 * Float.BYTES; // Normals private static final String WORLD_VERTEX_SHADER_RESOURCE = "World.vertex.glsl"; private static final String WORLD_FRAGMENT_SHADER_RESOURCE = "World.fragment.glsl"; private static final String WORLD_TRANSFORM_UNIFORM_NAME = "worldTransform", - NORMALS_ATTRIBUTE_NAME = "inputNormals"; + NORMALS_ATTRIBUTE_NAME = "inputNormals"; private final Uniform4Matrix worldTransformUniform; private final AttributeVertexArray normalsAttribute; - public WorldRenderProgram( - String[] vertexShaderResources, - String[] fragmentShaderResources - ) { - super( - attachVertexShader(vertexShaderResources), - attachFragmentShader(fragmentShaderResources) - ); + public WorldRenderProgram(String[] vertexShaderResources, String[] fragmentShaderResources) { + super(attachVertexShader(vertexShaderResources), attachFragmentShader(fragmentShaderResources)); - this.worldTransformUniform = getUniform(WORLD_TRANSFORM_UNIFORM_NAME) - .as4Matrix(); + this.worldTransformUniform = getUniform(WORLD_TRANSFORM_UNIFORM_NAME).as4Matrix(); - this.normalsAttribute = getAttribute(NORMALS_ATTRIBUTE_NAME) - .asVertexArray(); + this.normalsAttribute = getAttribute(NORMALS_ATTRIBUTE_NAME).asVertexArray(); } private static String[] attachVertexShader(String[] others) { @@ -103,14 +93,7 @@ public class WorldRenderProgram extends ShapeRenderProgram { int vertexStride = getBytesPerVertex(); int offset = super.bindVertices(vertices); - normalsAttribute.set( - 3, - GL11.GL_FLOAT, - false, - vertexStride, - vertices, - offset - ); + normalsAttribute.set(3, GL11.GL_FLOAT, false, vertexStride, vertices, offset); offset += 3 * Float.BYTES; return offset; @@ -130,8 +113,7 @@ public class WorldRenderProgram extends ShapeRenderProgram { @Override public int getBytesPerVertex() { - return super.getBytesPerVertex() + - 3 * Float.BYTES; // Normals + return super.getBytesPerVertex() + 3 * Float.BYTES; // Normals } @Override @@ -171,12 +153,7 @@ public class WorldRenderProgram extends ShapeRenderProgram { Vectors.release(normal); } - private void computeOneNormal( - Vec3 a, - Vec3 b, - Vec3 c, - Vec3 normal - ) { + private void computeOneNormal(Vec3 a, Vec3 b, Vec3 c, Vec3 normal) { b.sub(a); c.sub(a); b.cross(c, normal); @@ -187,18 +164,14 @@ public class WorldRenderProgram extends ShapeRenderProgram { ByteBuffer vertices = face.getVertices(); int offset = vertices.position() + index * getBytesPerVertex(); - result.set( - vertices.getFloat(offset + 0 * Float.BYTES), - vertices.getFloat(offset + 1 * Float.BYTES), - vertices.getFloat(offset + 2 * Float.BYTES) - ); + result.set(vertices.getFloat(offset + 0 * Float.BYTES), vertices.getFloat(offset + 1 * Float.BYTES), + vertices.getFloat(offset + 2 * Float.BYTES)); } private void saveVertexNormal(Face face, int index, Vec3 normal) { ByteBuffer vertices = face.getVertices(); - int offset = vertices.position() + index * getBytesPerVertex() + (3 * Float.BYTES + - 4 * Float.BYTES + - 2 * Float.BYTES); + int offset = vertices.position() + index * getBytesPerVertex() + + (3 * Float.BYTES + 4 * Float.BYTES + 2 * Float.BYTES); vertices.putFloat(offset + 0 * Float.BYTES, normal.x); vertices.putFloat(offset + 1 * Float.BYTES, normal.y); @@ -231,87 +204,36 @@ public class WorldRenderProgram extends ShapeRenderProgram { private final List vertices = new ArrayList<>(); @Override - public VertexBuilder addVertex( - float x, - float y, - float z, - float r, - float g, - float b, - float tx, - float ty - ) { - vertices.add( - new Vertex( - new Vec3(x, y, z), - new Vec4(r, g, b, 1), - new Vec2(tx, ty) - ) - ); + public VertexBuilder addVertex(float x, float y, float z, float r, float g, float b, float tx, float ty) { + vertices.add(new Vertex(new Vec3(x, y, z), new Vec4(r, g, b, 1), new Vec2(tx, ty))); return this; } @Override - public VertexBuilder addVertex( - float x, - float y, - float z, - float r, - float g, - float b, - float a, - float tx, - float ty - ) { - vertices.add( - new Vertex( - new Vec3(x, y, z), - new Vec4(r, g, b, a), - new Vec2(tx, ty) - ) - ); + public VertexBuilder addVertex(float x, float y, float z, float r, float g, float b, float a, float tx, + float ty) { + vertices.add(new Vertex(new Vec3(x, y, z), new Vec4(r, g, b, a), new Vec2(tx, ty))); return this; } @Override - public VertexBuilder addVertex( - Vec3 position, - Vec4 colorMultiplier, - Vec2 textureCoords - ) { - vertices.add( - new Vertex( - new Vec3(position), - new Vec4(colorMultiplier), - new Vec2(textureCoords) - ) - ); + public VertexBuilder addVertex(Vec3 position, Vec4 colorMultiplier, Vec2 textureCoords) { + vertices.add(new Vertex(new Vec3(position), new Vec4(colorMultiplier), new Vec2(textureCoords))); return this; } @Override public ByteBuffer assemble() { - ByteBuffer result = BufferUtils.createByteBuffer( - DEFAULT_BYTES_PER_VERTEX * vertices.size() - ); + ByteBuffer result = BufferUtils.createByteBuffer(DEFAULT_BYTES_PER_VERTEX * vertices.size()); for (Vertex v : vertices) { - result - .putFloat(v.position.x) - .putFloat(v.position.y) - .putFloat(v.position.z) - .putFloat(v.colorMultiplier.x) - .putFloat(v.colorMultiplier.y) - .putFloat(v.colorMultiplier.z) - .putFloat(v.colorMultiplier.w) - .putFloat(v.textureCoords.x) - .putFloat(v.textureCoords.y) - .putFloat(Float.NaN) - .putFloat(Float.NaN) - .putFloat(Float.NaN); + result.putFloat(v.position.x).putFloat(v.position.y).putFloat(v.position.z) + .putFloat(v.colorMultiplier.x).putFloat(v.colorMultiplier.y).putFloat(v.colorMultiplier.z) + .putFloat(v.colorMultiplier.w).putFloat(v.textureCoords.x).putFloat(v.textureCoords.y) + .putFloat(Float.NaN).putFloat(Float.NaN).putFloat(Float.NaN); } result.flip(); diff --git a/src/main/java/ru/windcorp/progressia/client/localization/LocaleListener.java b/src/main/java/ru/windcorp/progressia/client/localization/LocaleListener.java index b7c1f54..8e06d9f 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/LocaleListener.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/LocaleListener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; @FunctionalInterface diff --git a/src/main/java/ru/windcorp/progressia/client/localization/Localizer.java b/src/main/java/ru/windcorp/progressia/client/localization/Localizer.java index b61d000..e90ecd8 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/Localizer.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/Localizer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; import java.lang.ref.WeakReference; @@ -35,7 +35,7 @@ public class Localizer { private final Map langList; private final Collection> listeners = Collections - .synchronizedCollection(new LinkedList<>()); + .synchronizedCollection(new LinkedList<>()); // lang list must be in the same folder as .lang files public Localizer(String langFolder) { diff --git a/src/main/java/ru/windcorp/progressia/client/localization/MutableString.java b/src/main/java/ru/windcorp/progressia/client/localization/MutableString.java index a96d804..a1dfc92 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/MutableString.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/MutableString.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; import java.lang.ref.WeakReference; @@ -34,7 +34,7 @@ public abstract class MutableString { protected String data; protected final Collection> listeners = Collections - .synchronizedCollection(new LinkedList<>()); + .synchronizedCollection(new LinkedList<>()); private Collection myListeners = null; diff --git a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringConcat.java b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringConcat.java index f31fbca..e16533e 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringConcat.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringConcat.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; public class MutableStringConcat extends MutableString { diff --git a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringFormatter.java b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringFormatter.java index fddba06..07fad9d 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringFormatter.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringFormatter.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; import java.util.IllegalFormatException; diff --git a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringFunc.java b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringFunc.java index d945618..82ae330 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringFunc.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringFunc.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; import java.util.function.Function; diff --git a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringLocalized.java b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringLocalized.java index 583d9e5..32a6d68 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringLocalized.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringLocalized.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; public class MutableStringLocalized extends MutableString { diff --git a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringParented.java b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringParented.java index d7b0fae..fd6c8fd 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/MutableStringParented.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/MutableStringParented.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; public abstract class MutableStringParented extends MutableString { diff --git a/src/main/java/ru/windcorp/progressia/client/localization/Parser.java b/src/main/java/ru/windcorp/progressia/client/localization/Parser.java index 7d587dc..cdb220a 100644 --- a/src/main/java/ru/windcorp/progressia/client/localization/Parser.java +++ b/src/main/java/ru/windcorp/progressia/client/localization/Parser.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.localization; import ru.windcorp.jputil.chars.EscapeException; @@ -30,8 +30,7 @@ import java.util.Map; public class Parser { private String filePath; - static private final Escaper ESCAPER = new Escaper.EscaperBuilder() - .withChars("n", "\n").build(); + static private final Escaper ESCAPER = new Escaper.EscaperBuilder().withChars("n", "\n").build(); public Parser(String filePath) { this.filePath = filePath; @@ -43,11 +42,7 @@ public class Parser { public Map parse() { Map parsedData = new HashMap<>(); - try ( - Reader rawData = ResourceManager - .getResource(filePath) - .getReader() - ) { + try (Reader rawData = ResourceManager.getResource(filePath).getReader()) { int code; char c; StringBuilder stringBuilder = new StringBuilder(); @@ -88,10 +83,7 @@ public class Parser { stringBuilder.append(c); } } - parsedData.put( - ESCAPER.unescape(key), - ESCAPER.unescape(stringBuilder.toString()) - ); + parsedData.put(ESCAPER.unescape(key), ESCAPER.unescape(stringBuilder.toString())); stringBuilder.setLength(0); } } else if (c == '\n') { diff --git a/src/main/java/ru/windcorp/progressia/client/world/ChunkRender.java b/src/main/java/ru/windcorp/progressia/client/world/ChunkRender.java index 21f6098..43f883c 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/ChunkRender.java +++ b/src/main/java/ru/windcorp/progressia/client/world/ChunkRender.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world; import java.util.Collections; @@ -34,8 +34,7 @@ import ru.windcorp.progressia.common.world.block.BlockFace; import ru.windcorp.progressia.common.world.generic.GenericChunk; import ru.windcorp.progressia.common.world.tile.TileDataStack; -public class ChunkRender - implements GenericChunk { +public class ChunkRender implements GenericChunk { private final WorldRender world; private final ChunkData data; @@ -43,7 +42,7 @@ public class ChunkRender private final ChunkRenderModel model; private final Map tileRenderLists = Collections - .synchronizedMap(new WeakHashMap<>()); + .synchronizedMap(new WeakHashMap<>()); public ChunkRender(WorldRender world, ChunkData data) { this.world = world; @@ -58,9 +57,7 @@ public class ChunkRender @Override public BlockRender getBlock(Vec3i posInChunk) { - return BlockRenderRegistry.getInstance().get( - getData().getBlock(posInChunk).getId() - ); + return BlockRenderRegistry.getInstance().get(getData().getBlock(posInChunk).getId()); } @Override @@ -74,10 +71,7 @@ public class ChunkRender } private TileRenderStack getTileStackWrapper(TileDataStack tileDataList) { - return tileRenderLists.computeIfAbsent( - tileDataList, - TileRenderStackImpl::new - ); + return tileRenderLists.computeIfAbsent(tileDataList, TileRenderStackImpl::new); } public WorldRender getWorld() { diff --git a/src/main/java/ru/windcorp/progressia/client/world/ChunkRenderModel.java b/src/main/java/ru/windcorp/progressia/client/world/ChunkRenderModel.java index 9653abe..d15ba68 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/ChunkRenderModel.java +++ b/src/main/java/ru/windcorp/progressia/client/world/ChunkRenderModel.java @@ -39,9 +39,9 @@ import ru.windcorp.progressia.common.world.ChunkData; import ru.windcorp.progressia.common.world.block.BlockFace; public class ChunkRenderModel implements Renderable { - + private final ChunkRender chunk; - + private final Collection optimizers = new ArrayList<>(); private Model model = null; @@ -51,44 +51,42 @@ public class ChunkRenderModel implements Renderable { @Override public void render(ShapeRenderHelper renderer) { - if (model == null) return; - - renderer.pushTransform().translate( - chunk.getX() * ChunkData.BLOCKS_PER_CHUNK, - chunk.getY() * ChunkData.BLOCKS_PER_CHUNK, - chunk.getZ() * ChunkData.BLOCKS_PER_CHUNK - ); + if (model == null) + return; + + renderer.pushTransform().translate(chunk.getX() * ChunkData.BLOCKS_PER_CHUNK, + chunk.getY() * ChunkData.BLOCKS_PER_CHUNK, chunk.getZ() * ChunkData.BLOCKS_PER_CHUNK); model.render(renderer); renderer.popTransform(); } - + public void update() { setupCROs(); - + StaticModel.Builder sink = StaticModel.builder(); - + optimizers.forEach(ChunkRenderOptimizer::startRender); - + chunk.forEachBiC(blockInChunk -> { processBlockAndTiles(blockInChunk, sink); }); - + for (ChunkRenderOptimizer optimizer : optimizers) { Renderable renderable = optimizer.endRender(); if (renderable != null) { sink.addPart(renderable); } } - + this.model = sink.build(); this.optimizers.clear(); } private void setupCROs() { Set ids = ChunkRenderOptimizerRegistry.getInstance().keySet(); - + for (String id : ids) { ChunkRenderOptimizer optimizer = ChunkRenderOptimizerRegistry.getInstance().create(id); optimizer.setup(chunk); @@ -98,7 +96,7 @@ public class ChunkRenderModel implements Renderable { private void processBlockAndTiles(Vec3i blockInChunk, Builder sink) { processBlock(blockInChunk, sink); - + for (BlockFace face : BlockFace.getFaces()) { processTileStack(blockInChunk, face, sink); } @@ -106,18 +104,16 @@ public class ChunkRenderModel implements Renderable { private void processBlock(Vec3i blockInChunk, Builder sink) { BlockRender block = chunk.getBlock(blockInChunk); - + if (block instanceof BlockRenderNone) { return; } - + if (block.needsOwnRenderable()) { - sink.addPart( - block.createRenderable(chunk.getData(), blockInChunk), - new Mat4().identity().translate(blockInChunk.x, blockInChunk.y, blockInChunk.z) - ); + sink.addPart(block.createRenderable(chunk.getData(), blockInChunk), + new Mat4().identity().translate(blockInChunk.x, blockInChunk.y, blockInChunk.z)); } - + processBlockWithCROs(block, blockInChunk); } @@ -129,26 +125,24 @@ public class ChunkRenderModel implements Renderable { private void processTileStack(Vec3i blockInChunk, BlockFace face, Builder sink) { TileRenderStack trs = chunk.getTilesOrNull(blockInChunk, face); - + if (trs == null || trs.isEmpty()) { return; } - + trs.forEach(tile -> processTile(tile, blockInChunk, face, sink)); } - private void processTile(TileRender tile, Vec3i blockInChunk, BlockFace face, Builder sink) { + private void processTile(TileRender tile, Vec3i blockInChunk, BlockFace face, Builder sink) { if (tile instanceof TileRenderNone) { return; } - + if (tile.needsOwnRenderable()) { - sink.addPart( - tile.createRenderable(chunk.getData(), blockInChunk, face), - new Mat4().identity().translate(blockInChunk.x, blockInChunk.y, blockInChunk.z) - ); + sink.addPart(tile.createRenderable(chunk.getData(), blockInChunk, face), + new Mat4().identity().translate(blockInChunk.x, blockInChunk.y, blockInChunk.z)); } - + processTileWithCROs(tile, blockInChunk, face); } diff --git a/src/main/java/ru/windcorp/progressia/client/world/ChunkUpdateListener.java b/src/main/java/ru/windcorp/progressia/client/world/ChunkUpdateListener.java index c348498..8e0eb1d 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/ChunkUpdateListener.java +++ b/src/main/java/ru/windcorp/progressia/client/world/ChunkUpdateListener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world; import glm.vec._3.i.Vec3i; @@ -39,7 +39,7 @@ class ChunkUpdateListener implements ChunkDataListener { public void onChunkChanged(ChunkData chunk) { world.getChunk(chunk).markForUpdate(); } - + @Override public void onChunkLoaded(ChunkData chunk) { Vec3i cursor = new Vec3i(); @@ -49,37 +49,32 @@ class ChunkUpdateListener implements ChunkDataListener { world.markChunkForUpdate(cursor); } } - + @Override public void onChunkBlockChanged(ChunkData chunk, Vec3i blockInChunk, BlockData previous, BlockData current) { onLocationChanged(chunk, blockInChunk); } - + @Override - public void onChunkTilesChanged( - ChunkData chunk, - Vec3i blockInChunk, - BlockFace face, - TileData tile, - boolean wasAdded - ) { + public void onChunkTilesChanged(ChunkData chunk, Vec3i blockInChunk, BlockFace face, TileData tile, + boolean wasAdded) { onLocationChanged(chunk, blockInChunk); } private void onLocationChanged(ChunkData chunk, Vec3i blockInChunk) { Vec3i chunkPos = Vectors.grab3i().set(chunk.getX(), chunk.getY(), chunk.getZ()); - + checkCoordinate(blockInChunk, chunkPos, VectorUtil.Axis.X); checkCoordinate(blockInChunk, chunkPos, VectorUtil.Axis.Y); checkCoordinate(blockInChunk, chunkPos, VectorUtil.Axis.Z); - + Vectors.release(chunkPos); } private void checkCoordinate(Vec3i blockInChunk, Vec3i chunkPos, VectorUtil.Axis axis) { int block = VectorUtil.get(blockInChunk, axis); int diff = 0; - + if (block == 0) { diff = -1; } else if (block == ChunkData.BLOCKS_PER_CHUNK - 1) { @@ -87,12 +82,12 @@ class ChunkUpdateListener implements ChunkDataListener { } else { return; } - + int previousChunkPos = VectorUtil.get(chunkPos, axis); VectorUtil.set(chunkPos, axis, previousChunkPos + diff); world.markChunkForUpdate(chunkPos); - + VectorUtil.set(chunkPos, axis, previousChunkPos); } diff --git a/src/main/java/ru/windcorp/progressia/client/world/WorldRender.java b/src/main/java/ru/windcorp/progressia/client/world/WorldRender.java index 8be08c2..c8e63a9 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/WorldRender.java +++ b/src/main/java/ru/windcorp/progressia/client/world/WorldRender.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world; import java.util.Collection; @@ -47,7 +47,7 @@ import ru.windcorp.progressia.common.world.generic.ChunkSets; import ru.windcorp.progressia.common.world.generic.GenericWorld; public class WorldRender - implements GenericWorld { + implements GenericWorld { private final WorldData data; private final Client client; @@ -207,15 +207,11 @@ public class WorldRender } public EntityRenderable getEntityRenderable(EntityData entity) { - return entityModels.computeIfAbsent( - entity, - WorldRender::createEntityRenderable - ); + return entityModels.computeIfAbsent(entity, WorldRender::createEntityRenderable); } private static EntityRenderable createEntityRenderable(EntityData entity) { - return EntityRenderRegistry.getInstance().get(entity.getId()) - .createRenderable(entity); + return EntityRenderRegistry.getInstance().get(entity.getId()).createRenderable(entity); } public void markChunkForUpdate(Vec3i chunkPos) { diff --git a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRender.java b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRender.java index d350fa8..9b6c7ca 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRender.java +++ b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRender.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.block; import ru.windcorp.progressia.client.graphics.model.ShapeRenderHelper; @@ -32,9 +32,7 @@ public abstract class BlockRender extends Namespaced implements GenericBlock { } public void render(ShapeRenderHelper renderer) { - throw new UnsupportedOperationException( - "BlockRender.render() not implemented in " + this - ); + throw new UnsupportedOperationException("BlockRender.render() not implemented in " + this); } public Renderable createRenderable(ChunkData chunk, Vec3i blockInChunk) { diff --git a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderNone.java b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderNone.java index 84a2c4b..3f422f2 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderNone.java +++ b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderNone.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.block; import glm.vec._3.i.Vec3i; diff --git a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderOpaqueCube.java b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderOpaqueCube.java index e4d8723..5b2dc27 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderOpaqueCube.java +++ b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderOpaqueCube.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.block; import ru.windcorp.progressia.client.graphics.texture.Texture; @@ -23,36 +23,13 @@ import ru.windcorp.progressia.common.world.block.BlockFace; public class BlockRenderOpaqueCube extends BlockRenderTexturedCube { - public BlockRenderOpaqueCube( - String id, - Texture topTexture, - Texture bottomTexture, - Texture northTexture, - Texture southTexture, - Texture eastTexture, - Texture westTexture - ) { - super( - id, - topTexture, - bottomTexture, - northTexture, - southTexture, - eastTexture, - westTexture - ); + public BlockRenderOpaqueCube(String id, Texture topTexture, Texture bottomTexture, Texture northTexture, + Texture southTexture, Texture eastTexture, Texture westTexture) { + super(id, topTexture, bottomTexture, northTexture, southTexture, eastTexture, westTexture); } public BlockRenderOpaqueCube(String id, Texture texture) { - this( - id, - texture, - texture, - texture, - texture, - texture, - texture - ); + this(id, texture, texture, texture, texture, texture, texture); } @Override diff --git a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderRegistry.java b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderRegistry.java index 29bac40..2caacba 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderRegistry.java +++ b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.block; import ru.windcorp.progressia.client.graphics.texture.Atlases; @@ -37,11 +37,7 @@ public class BlockRenderRegistry extends NamespacedInstanceRegistry public static Texture getBlockTexture(String name) { return new SimpleTexture( - Atlases.getSprite( - ResourceManager.getTextureResource("blocks/" + name), - BLOCKS_ATLAS_GROUP - ) - ); + Atlases.getSprite(ResourceManager.getTextureResource("blocks/" + name), BLOCKS_ATLAS_GROUP)); } public static AtlasGroup getBlocksAtlasGroup() { diff --git a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderTexturedCube.java b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderTexturedCube.java index 1042a46..d254798 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderTexturedCube.java +++ b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderTexturedCube.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.block; import static ru.windcorp.progressia.common.world.block.BlockFace.*; @@ -40,21 +40,12 @@ import ru.windcorp.progressia.common.util.Vectors; import ru.windcorp.progressia.common.world.ChunkData; import ru.windcorp.progressia.common.world.block.BlockFace; -public abstract class BlockRenderTexturedCube - extends BlockRender - implements BlockOptimizedSurface { +public abstract class BlockRenderTexturedCube extends BlockRender implements BlockOptimizedSurface { private final Map textures = new HashMap<>(); - public BlockRenderTexturedCube( - String id, - Texture topTexture, - Texture bottomTexture, - Texture northTexture, - Texture southTexture, - Texture eastTexture, - Texture westTexture - ) { + public BlockRenderTexturedCube(String id, Texture topTexture, Texture bottomTexture, Texture northTexture, + Texture southTexture, Texture eastTexture, Texture westTexture) { super(id); textures.put(TOP, topTexture); @@ -68,52 +59,39 @@ public abstract class BlockRenderTexturedCube public Texture getTexture(BlockFace blockFace) { return textures.get(blockFace); } - + public Vec4 getColorMultiplier(BlockFace blockFace) { return Colors.WHITE; } @Override - public final void getFaces( - ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, - boolean inner, - Consumer output, - Vec3 offset - ) { + public final void getFaces(ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, boolean inner, + Consumer output, Vec3 offset) { output.accept(createFace(chunk, blockInChunk, blockFace, inner, offset)); } - - private Face createFace( - ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, - boolean inner, - Vec3 offset - ) { - return Faces.createBlockFace( - WorldRenderProgram.getDefault(), - getTexture(blockFace), - getColorMultiplier(blockFace), - offset, - blockFace, - inner - ); + + private Face createFace(ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, boolean inner, Vec3 offset) { + return Faces.createBlockFace(WorldRenderProgram.getDefault(), getTexture(blockFace), + getColorMultiplier(blockFace), offset, blockFace, inner); } @Override public Renderable createRenderable(ChunkData chunk, Vec3i blockInChunk) { boolean opaque = isBlockOpaque(); - + Face[] faces = new Face[BLOCK_FACE_COUNT + (opaque ? BLOCK_FACE_COUNT : 0)]; - + for (int i = 0; i < BLOCK_FACE_COUNT; ++i) { faces[i] = createFace(chunk, blockInChunk, BlockFace.getFaces().get(i), false, Vectors.ZERO_3); } - + if (!opaque) { for (int i = 0; i < BLOCK_FACE_COUNT; ++i) { - faces[i + BLOCK_FACE_COUNT] = createFace(chunk, blockInChunk, BlockFace.getFaces().get(i), true, Vectors.ZERO_3); + faces[i + BLOCK_FACE_COUNT] = createFace(chunk, blockInChunk, BlockFace.getFaces().get(i), true, + Vectors.ZERO_3); } } - + return new Shape(Usage.STATIC, WorldRenderProgram.getDefault(), faces); } diff --git a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderTransparentCube.java b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderTransparentCube.java index 7f3df03..944d451 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderTransparentCube.java +++ b/src/main/java/ru/windcorp/progressia/client/world/block/BlockRenderTransparentCube.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.block; import ru.windcorp.progressia.client.graphics.texture.Texture; @@ -23,36 +23,13 @@ import ru.windcorp.progressia.common.world.block.BlockFace; public class BlockRenderTransparentCube extends BlockRenderTexturedCube { - public BlockRenderTransparentCube( - String id, - Texture topTexture, - Texture bottomTexture, - Texture northTexture, - Texture southTexture, - Texture eastTexture, - Texture westTexture - ) { - super( - id, - topTexture, - bottomTexture, - northTexture, - southTexture, - eastTexture, - westTexture - ); + public BlockRenderTransparentCube(String id, Texture topTexture, Texture bottomTexture, Texture northTexture, + Texture southTexture, Texture eastTexture, Texture westTexture) { + super(id, topTexture, bottomTexture, northTexture, southTexture, eastTexture, westTexture); } public BlockRenderTransparentCube(String id, Texture texture) { - this( - id, - texture, - texture, - texture, - texture, - texture, - texture - ); + this(id, texture, texture, texture, texture, texture, texture); } @Override diff --git a/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizer.java b/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizer.java index b684c6a..ddf923a 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizer.java +++ b/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizer.java @@ -35,10 +35,9 @@ import ru.windcorp.progressia.common.world.block.BlockFace; * tiles. An example of a CRO is {@link ChunkRenderOptimizerSurface}: it removes * block surfaces and tiles that it knows cannot be seen, thus significantly * reducing total polygon count. - *

CRO lifecycle

- * A CRO instance is created by {@link ChunkRenderOptimizerRegistry}. It may - * then be used to work on multiple chunks sequentially. Each chunk is processed - * in the following way: + *

CRO lifecycle

A CRO instance is created by + * {@link ChunkRenderOptimizerRegistry}. It may then be used to work on multiple + * chunks sequentially. Each chunk is processed in the following way: *
    *
  1. {@link #setup(ChunkRender)} is invoked to provide the {@link ChunkRender} * instance.
  2. @@ -63,7 +62,8 @@ public abstract class ChunkRenderOptimizer extends Namespaced { /** * Creates a new CRO instance with the specified ID. * - * @param id the ID of this CRO + * @param id + * the ID of this CRO */ public ChunkRenderOptimizer(String id) { super(id); @@ -74,7 +74,8 @@ public abstract class ChunkRenderOptimizer extends Namespaced { * specify the chunk. When overriding, {@code super.setup(chunk)} must be * invoked. * - * @param chunk the chunk that will be processed next + * @param chunk + * the chunk that will be processed next */ public void setup(ChunkRender chunk) { this.chunk = chunk; @@ -98,10 +99,11 @@ public abstract class ChunkRenderOptimizer extends Namespaced { * method is only invoked once per block. This method is not necessarily * invoked for each block. * - * @param block a {@link BlockRender} instance describing the block. - * It corresponds to - * {@code getChunk().getBlock(blockInChunk)}. - * @param blockInChunk the position of the block + * @param block + * a {@link BlockRender} instance describing the block. It + * corresponds to {@code getChunk().getBlock(blockInChunk)}. + * @param blockInChunk + * the position of the block */ public abstract void addBlock(BlockRender block, Vec3i blockInChunk); @@ -112,9 +114,12 @@ public abstract class ChunkRenderOptimizer extends Namespaced { * invoked for each tile. When multiple tiles in a tile stack are requested, * this method is invoked for lower tiles first. * - * @param tile a {@link BlockRender} instance describing the tile - * @param blockInChunk the position of the block that the tile belongs to - * @param blockFace the face that the tile belongs to + * @param tile + * a {@link BlockRender} instance describing the tile + * @param blockInChunk + * the position of the block that the tile belongs to + * @param blockFace + * the face that the tile belongs to */ public abstract void addTile(TileRender tile, Vec3i blockInChunk, BlockFace blockFace); diff --git a/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizerRegistry.java b/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizerRegistry.java index 7e4dc87..7676b4f 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizerRegistry.java +++ b/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizerRegistry.java @@ -15,15 +15,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.cro; import ru.windcorp.progressia.common.util.namespaces.NamespacedFactoryRegistry; public class ChunkRenderOptimizerRegistry extends NamespacedFactoryRegistry { - + private static final ChunkRenderOptimizerRegistry INSTANCE = new ChunkRenderOptimizerRegistry(); - + /** * @return the instance */ diff --git a/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizerSurface.java b/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizerSurface.java index 488938e..12b4275 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizerSurface.java +++ b/src/main/java/ru/windcorp/progressia/client/world/cro/ChunkRenderOptimizerSurface.java @@ -56,32 +56,31 @@ public class ChunkRenderOptimizerSurface extends ChunkRenderOptimizer { * The coordinates of the face vertices must be in chunk coordinate * system. * - * @param chunk the chunk that contains the requested face - * @param blockInChunk the block in chunk - * @param blockFace the requested face - * @param inner whether this face should be visible from inside - * ({@code true}) or outside ({@code false}) - * @param output a consumer that the created faces must be given - * to - * @param offset an additional offset that must be applied to all - * vertices + * @param chunk + * the chunk that contains the requested face + * @param blockInChunk + * the block in chunk + * @param blockFace + * the requested face + * @param inner + * whether this face should be visible from inside + * ({@code true}) or outside ({@code false}) + * @param output + * a consumer that the created faces must be given to + * @param offset + * an additional offset that must be applied to all vertices */ - void getFaces( - ChunkData chunk, - Vec3i blockInChunk, - BlockFace blockFace, - boolean inner, - Consumer output, - Vec3 offset /* kostyl 156% */ + void getFaces(ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, boolean inner, Consumer output, + Vec3 offset /* kostyl 156% */ ); /** * Returns the opacity of the surface identified by the provided - * {@link BlockFace}. - * Opaque surfaces prevent surfaces behind them from being included in - * chunk models. + * {@link BlockFace}. Opaque surfaces prevent surfaces behind them from + * being included in chunk models. * - * @param blockFace the face to query + * @param blockFace + * the face to query * @return {@code true} iff the surface is opaque. */ boolean isOpaque(BlockFace blockFace); @@ -95,8 +94,7 @@ public class ChunkRenderOptimizerSurface extends ChunkRenderOptimizer { /** * Returns the opacity of the block. Opaque blocks do not expect that * the camera can be inside them. Opaque blocks prevent surfaces that - * face them - * from being included in chunk models. + * face them from being included in chunk models. * * @return {@code true} iff the block is opaque. */ @@ -207,9 +205,7 @@ public class ChunkRenderOptimizerSurface extends ChunkRenderOptimizer { @Override public Renderable endRender() { - Collection shapeFaces = new ArrayList<>( - BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK * 3 - ); + Collection shapeFaces = new ArrayList<>(BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK * 3); Vec3i cursor = new Vec3i(); Consumer consumer = shapeFaces::add; @@ -227,17 +223,11 @@ public class ChunkRenderOptimizerSurface extends ChunkRenderOptimizer { return null; } - return new Shape( - Usage.STATIC, - WorldRenderProgram.getDefault(), - shapeFaces.toArray(new Face[shapeFaces.size()]) - ); + return new Shape(Usage.STATIC, WorldRenderProgram.getDefault(), + shapeFaces.toArray(new Face[shapeFaces.size()])); } - private void processOuterFaces( - Vec3i blockInChunk, - Consumer output - ) { + private void processOuterFaces(Vec3i blockInChunk, Consumer output) { for (BlockFace blockFace : BlockFace.getFaces()) { processOuterFace(blockInChunk, blockFace, output); } @@ -255,11 +245,7 @@ public class ChunkRenderOptimizerSurface extends ChunkRenderOptimizer { Vec3 faceOrigin = new Vec3(blockInChunk.x, blockInChunk.y, blockInChunk.z); Vec3 offset = new Vec3(blockFace.getFloatVector()).mul(OVERLAY_OFFSET); - for ( - int layer = info.topOpaqueSurface; - layer < info.tileCount; - ++layer - ) { + for (int layer = info.topOpaqueSurface; layer < info.tileCount; ++layer) { OptimizedSurface surface = info.getSurface(layer); if (surface == null) continue; // layer may be BLOCK_LAYER, then block may be null @@ -270,10 +256,7 @@ public class ChunkRenderOptimizerSurface extends ChunkRenderOptimizer { } } - private void processInnerFaces( - Vec3i blockInChunk, - Consumer output - ) { + private void processInnerFaces(Vec3i blockInChunk, Consumer output) { for (BlockFace blockFace : BlockFace.getFaces()) { processInnerFace(blockInChunk, blockFace, output); } @@ -291,11 +274,7 @@ public class ChunkRenderOptimizerSurface extends ChunkRenderOptimizer { Vec3 faceOrigin = new Vec3(blockInChunk.x, blockInChunk.y, blockInChunk.z); Vec3 offset = new Vec3(blockFace.getFloatVector()).mul(OVERLAY_OFFSET); - for ( - int layer = FaceInfo.BLOCK_LAYER; - layer <= info.bottomOpaqueSurface && layer < info.tileCount; - ++layer - ) { + for (int layer = FaceInfo.BLOCK_LAYER; layer <= info.bottomOpaqueSurface && layer < info.tileCount; ++layer) { OptimizedSurface surface = info.getSurface(layer); if (surface == null) continue; // layer may be BLOCK_LAYER, then block may be null @@ -365,12 +344,8 @@ public class ChunkRenderOptimizerSurface extends ChunkRenderOptimizer { blockInChunk.z = 0; chunkPos.z += 1; } else { - throw new AssertionError( - "Requested incorrent neighbor (" - + blockInLocalChunk.x + "; " - + blockInLocalChunk.y + "; " - + blockInLocalChunk.z + ")" - ); + throw new AssertionError("Requested incorrent neighbor (" + blockInLocalChunk.x + "; " + + blockInLocalChunk.y + "; " + blockInLocalChunk.z + ")"); } ChunkRender chunk = this.chunk.getWorld().getChunk(chunkPos); diff --git a/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRender.java b/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRender.java index 13a2b24..8243c9d 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRender.java +++ b/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRender.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.entity; import ru.windcorp.progressia.common.util.namespaces.Namespaced; diff --git a/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRenderRegistry.java b/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRenderRegistry.java index 60b7bf6..e6ff550 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRenderRegistry.java +++ b/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRenderRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.entity; import java.io.IOException; @@ -37,14 +37,9 @@ public class EntityRenderRegistry extends NamespacedInstanceRegistry. */ - + package ru.windcorp.progressia.client.world.entity; import glm.vec._3.Vec3; diff --git a/src/main/java/ru/windcorp/progressia/client/world/entity/HumanoidModel.java b/src/main/java/ru/windcorp/progressia/client/world/entity/HumanoidModel.java index 1609bfc..2f13407 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/entity/HumanoidModel.java +++ b/src/main/java/ru/windcorp/progressia/client/world/entity/HumanoidModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.entity; import static java.lang.Math.*; @@ -32,11 +32,7 @@ public class HumanoidModel extends NPedModel { protected static abstract class Limb extends BodyPart { private final float animationOffset; - public Limb( - Renderable renderable, - Vec3 joint, - float animationOffset - ) { + public Limb(Renderable renderable, Vec3 joint, float animationOffset) { super(renderable, joint); this.animationOffset = animationOffset; } @@ -54,11 +50,7 @@ public class HumanoidModel extends NPedModel { } public static class Leg extends Limb { - public Leg( - Renderable renderable, - Vec3 joint, - float animationOffset - ) { + public Leg(Renderable renderable, Vec3 joint, float animationOffset) { super(renderable, joint, animationOffset); } @@ -69,11 +61,7 @@ public class HumanoidModel extends NPedModel { } public static class Arm extends Limb { - public Arm( - Renderable renderable, - Vec3 joint, - float animationOffset - ) { + public Arm(Renderable renderable, Vec3 joint, float animationOffset) { super(renderable, joint, animationOffset); } @@ -91,18 +79,11 @@ public class HumanoidModel extends NPedModel { private float walkingLegSwing; private float walkingArmSwing; - public HumanoidModel( - EntityData entity, + public HumanoidModel(EntityData entity, - Body body, - Head head, - Arm leftArm, - Arm rightArm, - Leg leftLeg, - Leg rightLeg, + Body body, Head head, Arm leftArm, Arm rightArm, Leg leftLeg, Leg rightLeg, - float scale - ) { + float scale) { super(entity, body, head, scale); this.leftArm = leftArm; this.rightArm = rightArm; diff --git a/src/main/java/ru/windcorp/progressia/client/world/entity/NPedModel.java b/src/main/java/ru/windcorp/progressia/client/world/entity/NPedModel.java index ead6565..33bef76 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/entity/NPedModel.java +++ b/src/main/java/ru/windcorp/progressia/client/world/entity/NPedModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.entity; import static java.lang.Math.atan2; @@ -47,10 +47,7 @@ public abstract class NPedModel extends EntityRenderable { } } - protected void render( - ShapeRenderHelper renderer, - NPedModel model - ) { + protected void render(ShapeRenderHelper renderer, NPedModel model) { renderer.pushTransform().translate(translation); applyTransform(renderer.pushTransform(), model); renderable.render(renderer); @@ -82,13 +79,7 @@ public abstract class NPedModel extends EntityRenderable { private final Vec3 viewPoint; - public Head( - Renderable renderable, - Vec3 joint, - double maxYawDegrees, - double maxPitchDegrees, - Vec3 viewPoint - ) { + public Head(Renderable renderable, Vec3 joint, double maxYawDegrees, double maxPitchDegrees, Vec3 viewPoint) { super(renderable, joint); this.maxYaw = (float) toRadians(maxYawDegrees); this.maxPitch = (float) toRadians(maxPitchDegrees); @@ -176,11 +167,7 @@ public abstract class NPedModel extends EntityRenderable { bodyYaw = normalizeAngle(bodyYaw); - headPitch = Glm.clamp( - getData().getPitch(), - -head.maxPitch, - head.maxPitch - ); + headPitch = Glm.clamp(getData().getPitch(), -head.maxPitch, head.maxPitch); } private void accountForVelocity() { @@ -194,9 +181,8 @@ public abstract class NPedModel extends EntityRenderable { // TODO switch to world time walkingParameter += velocity * GraphicsInterface.getFrameLength() * 1000; - bodyYaw += velocityParameter * normalizeAngle( - (float) (atan2(horizontal.y, horizontal.x) - bodyYaw) - ) * min(1, GraphicsInterface.getFrameLength() * 10); + bodyYaw += velocityParameter * normalizeAngle((float) (atan2(horizontal.y, horizontal.x) - bodyYaw)) + * min(1, GraphicsInterface.getFrameLength() * 10); } private void evaluateVelocityCoeff() { @@ -212,12 +198,7 @@ public abstract class NPedModel extends EntityRenderable { Mat4 m = new Mat4(); Vec4 v = new Vec4(); - m.identity() - .scale(scale) - .rotateZ(bodyYaw) - .translate(head.getTranslation()) - .rotateZ(headYaw) - .rotateY(headPitch); + m.identity().scale(scale).rotateZ(bodyYaw).translate(head.getTranslation()).rotateZ(headYaw).rotateY(headPitch); v.set(head.getViewPoint(), 1); m.mul(v); @@ -247,9 +228,8 @@ public abstract class NPedModel extends EntityRenderable { /** * Returns a number in the range [0; 1] that can be used to scale animation - * effects that depend on speed. - * This parameter is 0 when the entity is not moving and 1 when it's moving - * "fast". + * effects that depend on speed. This parameter is 0 when the entity is not + * moving and 1 when it's moving "fast". * * @return velocity parameter */ @@ -259,9 +239,8 @@ public abstract class NPedModel extends EntityRenderable { /** * Returns a number that can be used to parameterize animation effects that - * depend on walking. - * This parameter increases when the entity moves (e.g. this can be total - * traveled distance). + * depend on walking. This parameter increases when the entity moves (e.g. + * this can be total traveled distance). * * @return walking parameter */ diff --git a/src/main/java/ru/windcorp/progressia/client/world/entity/QuadripedModel.java b/src/main/java/ru/windcorp/progressia/client/world/entity/QuadripedModel.java index 8755b08..d31579f 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/entity/QuadripedModel.java +++ b/src/main/java/ru/windcorp/progressia/client/world/entity/QuadripedModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.entity; import static java.lang.Math.*; @@ -33,11 +33,7 @@ public class QuadripedModel extends NPedModel { public static class Leg extends BodyPart { private final float animationOffset; - public Leg( - Renderable renderable, - Vec3 joint, - float animationOffset - ) { + public Leg(Renderable renderable, Vec3 joint, float animationOffset) { super(renderable, joint); this.animationOffset = animationOffset; } @@ -57,18 +53,11 @@ public class QuadripedModel extends NPedModel { private float walkingSwing = (float) toRadians(30); - public QuadripedModel( - EntityData entity, + public QuadripedModel(EntityData entity, - Body body, - Head head, - Leg leftForeLeg, - Leg rightForeLeg, - Leg leftHindLeg, - Leg rightHindLeg, + Body body, Head head, Leg leftForeLeg, Leg rightForeLeg, Leg leftHindLeg, Leg rightHindLeg, - float scale - ) { + float scale) { super(entity, body, head, scale); this.leftForeLeg = leftForeLeg; diff --git a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRender.java b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRender.java index 4f82d86..7cc3615 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRender.java +++ b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRender.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.tile; import ru.windcorp.progressia.client.graphics.model.ShapeRenderHelper; @@ -34,9 +34,7 @@ public class TileRender extends Namespaced implements GenericTile { } public void render(ShapeRenderHelper renderer, BlockFace face) { - throw new UnsupportedOperationException( - "TileRender.render() not implemented in " + this - ); + throw new UnsupportedOperationException("TileRender.render() not implemented in " + this); } public Renderable createRenderable(ChunkData chunk, Vec3i blockInChunk, BlockFace face) { diff --git a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderGrass.java b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderGrass.java index c73647b..e50d8d4 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderGrass.java +++ b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderGrass.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.tile; import ru.windcorp.progressia.client.graphics.texture.Texture; @@ -26,11 +26,7 @@ public class TileRenderGrass extends TileRenderSurface { private final Texture topTexture; private final Texture sideTexture; - public TileRenderGrass( - String id, - Texture top, - Texture side - ) { + public TileRenderGrass(String id, Texture top, Texture side) { super(id); this.topTexture = top; this.sideTexture = side; diff --git a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderNone.java b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderNone.java index 8e2a6e4..56ea3cb 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderNone.java +++ b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderNone.java @@ -28,12 +28,12 @@ public class TileRenderNone extends TileRender { public TileRenderNone(String id) { super(id); } - + @Override public Renderable createRenderable(ChunkData chunk, Vec3i blockInChunk, BlockFace face) { return EmptyModel.getInstance(); } - + @Override public boolean needsOwnRenderable() { return false; diff --git a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderOpaqueSurface.java b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderOpaqueSurface.java index e4990e8..bcc9df5 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderOpaqueSurface.java +++ b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderOpaqueSurface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.tile; import ru.windcorp.progressia.client.graphics.texture.Texture; diff --git a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderRegistry.java b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderRegistry.java index b240933..7b9d5ec 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderRegistry.java +++ b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.tile; import ru.windcorp.progressia.client.graphics.texture.Atlases; @@ -41,11 +41,7 @@ public class TileRenderRegistry extends NamespacedInstanceRegistry { public static Texture getTileTexture(String name) { return new SimpleTexture( - Atlases.getSprite( - ResourceManager.getTextureResource("tiles/" + name), - TILES_ATLAS_GROUP - ) - ); + Atlases.getSprite(ResourceManager.getTextureResource("tiles/" + name), TILES_ATLAS_GROUP)); } } diff --git a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderStack.java b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderStack.java index 6bb8fb0..8c3d00b 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderStack.java +++ b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderStack.java @@ -15,15 +15,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.tile; import ru.windcorp.progressia.client.world.ChunkRender; import ru.windcorp.progressia.common.world.generic.GenericTileStack; import ru.windcorp.progressia.common.world.tile.TileDataStack; -public abstract class TileRenderStack - extends GenericTileStack { +public abstract class TileRenderStack extends GenericTileStack { public abstract TileDataStack getData(); diff --git a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderSurface.java b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderSurface.java index eebcb07..c41d811 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderSurface.java +++ b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderSurface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.tile; import java.util.function.Consumer; @@ -44,7 +44,7 @@ public abstract class TileRenderSurface extends TileRender implements TileOptimi super(id); this.texture = texture; } - + public TileRenderSurface(String id) { this(id, null); } @@ -52,45 +52,28 @@ public abstract class TileRenderSurface extends TileRender implements TileOptimi public Texture getTexture(BlockFace blockFace) { return texture; } - + public Vec4 getColorMultiplier(BlockFace blockFace) { return Colors.WHITE; } - + @Override - public final void getFaces( - ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, - boolean inner, - Consumer output, - Vec3 offset - ) { + public final void getFaces(ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, boolean inner, + Consumer output, Vec3 offset) { output.accept(createFace(chunk, blockInChunk, blockFace, inner, offset)); } - - private Face createFace( - ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, - boolean inner, - Vec3 offset - ) { - return Faces.createBlockFace( - WorldRenderProgram.getDefault(), - getTexture(blockFace), - getColorMultiplier(blockFace), - offset, - blockFace, - inner - ); + + private Face createFace(ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, boolean inner, Vec3 offset) { + return Faces.createBlockFace(WorldRenderProgram.getDefault(), getTexture(blockFace), + getColorMultiplier(blockFace), offset, blockFace, inner); } @Override public Renderable createRenderable(ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace) { - return new Shape( - Usage.STATIC, - WorldRenderProgram.getDefault(), - - createFace(chunk, blockInChunk, blockFace, false, Vectors.ZERO_3), - createFace(chunk, blockInChunk, blockFace, true, Vectors.ZERO_3) - ); + return new Shape(Usage.STATIC, WorldRenderProgram.getDefault(), + + createFace(chunk, blockInChunk, blockFace, false, Vectors.ZERO_3), + createFace(chunk, blockInChunk, blockFace, true, Vectors.ZERO_3)); } @Override diff --git a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderTransparentSurface.java b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderTransparentSurface.java index b35986e..af512a9 100644 --- a/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderTransparentSurface.java +++ b/src/main/java/ru/windcorp/progressia/client/world/tile/TileRenderTransparentSurface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.client.world.tile; import ru.windcorp.progressia.client.graphics.texture.Texture; diff --git a/src/main/java/ru/windcorp/progressia/common/Units.java b/src/main/java/ru/windcorp/progressia/common/Units.java index 842e378..0f868aa 100644 --- a/src/main/java/ru/windcorp/progressia/common/Units.java +++ b/src/main/java/ru/windcorp/progressia/common/Units.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common; import java.lang.annotation.ElementType; @@ -112,12 +112,9 @@ public class Units { private static final TCharFloatMap PREFIXES_BY_CHAR; static { - TCharFloatMap prefixes = new TCharFloatHashMap( - gnu.trove.impl.Constants.DEFAULT_CAPACITY, - gnu.trove.impl.Constants.DEFAULT_LOAD_FACTOR, - gnu.trove.impl.Constants.DEFAULT_CHAR_NO_ENTRY_VALUE, - Float.NaN - ); + TCharFloatMap prefixes = new TCharFloatHashMap(gnu.trove.impl.Constants.DEFAULT_CAPACITY, + gnu.trove.impl.Constants.DEFAULT_LOAD_FACTOR, gnu.trove.impl.Constants.DEFAULT_CHAR_NO_ENTRY_VALUE, + Float.NaN); prefixes.put('G', 1e+9f); prefixes.put('M', 1e+6f); @@ -133,13 +130,8 @@ public class Units { private static final TObjectFloatMap KNOWN_UNITS = createMap(); private static TObjectFloatMap createMap() { - return TCollections.synchronizedMap( - new TObjectFloatHashMap<>( - gnu.trove.impl.Constants.DEFAULT_CAPACITY, - gnu.trove.impl.Constants.DEFAULT_LOAD_FACTOR, - Float.NaN - ) - ); + return TCollections.synchronizedMap(new TObjectFloatHashMap<>(gnu.trove.impl.Constants.DEFAULT_CAPACITY, + gnu.trove.impl.Constants.DEFAULT_LOAD_FACTOR, Float.NaN)); } public static void registerUnits(Class source) throws IllegalAccessException { @@ -210,9 +202,9 @@ public class Units { * parenthesis are allowed at all. As such, *
      *
    • Multiple units under the division bar should be located after the - * single {@code '/'} and separated by {@code '*'}: - * gas constant ought - * to have {@code "J/K*mol"} units.
    • + * single {@code '/'} and separated by {@code '*'}: gas constant ought to + * have {@code "J/K*mol"} units. *
    • Exponentiation of parenthesis should be expanded: (m/s)² = * {@code "m^2/s^2"}.
    • *
    • Exponents should also be used for expressing roots: √s = @@ -221,8 +213,10 @@ public class Units { * discouraged.
    • *
    * - * @param unit unit declaration - * @throws IllegalArgumentException if the declaration is invalid + * @param unit + * unit declaration + * @throws IllegalArgumentException + * if the declaration is invalid * @return the value of the unit * @see #get(String) get(String) * @see #registerUnit(float, String...) diff --git a/src/main/java/ru/windcorp/progressia/common/collision/AABB.java b/src/main/java/ru/windcorp/progressia/common/collision/AABB.java index fd8ffe9..ce27f68 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/AABB.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/AABB.java @@ -15,14 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import glm.vec._3.Vec3; /** - * An implementation of an - * Axis-Aligned * Bounding Box. * @@ -36,17 +35,7 @@ public class AABB implements AABBoid { private final Vec3 widthSelector = new Vec3(); private final Vec3 heightSelector = new Vec3(); - public AABBWallImpl( - float ox, - float oy, - float oz, - float wx, - float wy, - float wz, - float hx, - float hy, - float hz - ) { + public AABBWallImpl(float ox, float oy, float oz, float wx, float wy, float wz, float hx, float hy, float hz) { this.originOffset.set(ox, oy, oz); this.widthSelector.set(wx, wy, wz); this.heightSelector.set(hx, hy, hz); @@ -71,13 +60,12 @@ public class AABB implements AABBoid { public static final AABB UNIT_CUBE = new AABB(0, 0, 0, 1, 1, 1); - private final Wall[] walls = new Wall[] { - new AABBWallImpl(-0.5f, -0.5f, +0.5f, +1, 0, 0, 0, +1, 0), // Top - new AABBWallImpl(-0.5f, -0.5f, -0.5f, 0, +1, 0, +1, 0, 0), // Bottom - new AABBWallImpl(+0.5f, -0.5f, -0.5f, 0, +1, 0, 0, 0, +1), // North - new AABBWallImpl(-0.5f, +0.5f, -0.5f, 0, -1, 0, 0, 0, +1), // South - new AABBWallImpl(+0.5f, +0.5f, -0.5f, -1, 0, 0, 0, 0, +1), // West - new AABBWallImpl(-0.5f, -0.5f, -0.5f, +1, 0, 0, 0, 0, +1) // East + private final Wall[] walls = new Wall[] { new AABBWallImpl(-0.5f, -0.5f, +0.5f, +1, 0, 0, 0, +1, 0), // Top + new AABBWallImpl(-0.5f, -0.5f, -0.5f, 0, +1, 0, +1, 0, 0), // Bottom + new AABBWallImpl(+0.5f, -0.5f, -0.5f, 0, +1, 0, 0, 0, +1), // North + new AABBWallImpl(-0.5f, +0.5f, -0.5f, 0, -1, 0, 0, 0, +1), // South + new AABBWallImpl(+0.5f, +0.5f, -0.5f, -1, 0, 0, 0, 0, +1), // West + new AABBWallImpl(-0.5f, -0.5f, -0.5f, +1, 0, 0, 0, 0, +1) // East }; private final Vec3 origin = new Vec3(); @@ -87,14 +75,7 @@ public class AABB implements AABBoid { this(origin.x, origin.y, origin.z, size.x, size.y, size.z); } - public AABB( - float ox, - float oy, - float oz, - float xSize, - float ySize, - float zSize - ) { + public AABB(float ox, float oy, float oz, float xSize, float ySize, float zSize) { this.origin.set(ox, oy, oz); this.size.set(xSize, ySize, zSize); } diff --git a/src/main/java/ru/windcorp/progressia/common/collision/AABBoid.java b/src/main/java/ru/windcorp/progressia/common/collision/AABBoid.java index ab2cd80..04312f1 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/AABBoid.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/AABBoid.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import glm.vec._3.Vec3; diff --git a/src/main/java/ru/windcorp/progressia/common/collision/Collideable.java b/src/main/java/ru/windcorp/progressia/common/collision/Collideable.java index 8db7805..14ca2c3 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/Collideable.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/Collideable.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import glm.vec._3.Vec3; @@ -26,10 +26,11 @@ public interface Collideable { CollisionModel getCollisionModel(); /** - * Invoked by {@link Collider} when two entities are about to collide. - * The world is at the moment of collision. + * Invoked by {@link Collider} when two entities are about to collide. The + * world is at the moment of collision. * - * @param other the colliding object + * @param other + * the colliding object * @return {@code true} iff the collision should not be handled normally * (e.g. this object has disappeared) */ @@ -37,8 +38,8 @@ public interface Collideable { /** * Returns the mass of this {@link Collideable} that should be used to - * calculate collisions. - * Collision mass must be a positive number. Positive infinity is allowed. + * calculate collisions. Collision mass must be a positive number. Positive + * infinity is allowed. * * @return this object's collision mass */ diff --git a/src/main/java/ru/windcorp/progressia/common/collision/CollisionModel.java b/src/main/java/ru/windcorp/progressia/common/collision/CollisionModel.java index 9ade6af..209063a 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/CollisionModel.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/CollisionModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import glm.vec._3.Vec3; diff --git a/src/main/java/ru/windcorp/progressia/common/collision/CollisionPathComputer.java b/src/main/java/ru/windcorp/progressia/common/collision/CollisionPathComputer.java index 4826bce..88a57e1 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/CollisionPathComputer.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/CollisionPathComputer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import java.util.function.Consumer; @@ -30,11 +30,7 @@ public class CollisionPathComputer { private static final float PADDING = 0.5f; - public static void forEveryBlockInCollisionPath( - Collideable coll, - float maxTime, - Consumer action - ) { + public static void forEveryBlockInCollisionPath(Collideable coll, float maxTime, Consumer action) { Vec3 displacement = Vectors.grab3(); coll.getCollideableVelocity(displacement); displacement.mul(maxTime); @@ -44,11 +40,7 @@ public class CollisionPathComputer { Vectors.release(displacement); } - private static void handleModel( - CollisionModel model, - Vec3 displacement, - Consumer action - ) { + private static void handleModel(CollisionModel model, Vec3 displacement, Consumer action) { if (model instanceof CompoundCollisionModel) { for (CollisionModel subModel : ((CompoundCollisionModel) model).getModels()) { handleModel(subModel, displacement, action); @@ -71,21 +63,13 @@ public class CollisionPathComputer { Vec3i pos = Vectors.grab3i(); - for ( - pos.x = (int) floor(origin.x + min(0, size.x) + min(0, displacement.x) - PADDING); - pos.x <= (int) ceil(origin.x + max(0, size.x) + max(0, displacement.x) + PADDING); - pos.x += 1 - ) { - for ( - pos.y = (int) floor(origin.y + min(0, size.y) + min(0, displacement.y) - PADDING); - pos.y <= (int) ceil(origin.y + max(0, size.y) + max(0, displacement.y) + PADDING); - pos.y += 1 - ) { - for ( - pos.z = (int) floor(origin.z + min(0, size.z) + min(0, displacement.z) - PADDING); - pos.z <= (int) ceil(origin.z + max(0, size.z) + max(0, displacement.z) + PADDING); - pos.z += 1 - ) { + for (pos.x = (int) floor(origin.x + min(0, size.x) + min(0, displacement.x) - PADDING); pos.x <= (int) ceil( + origin.x + max(0, size.x) + max(0, displacement.x) + PADDING); pos.x += 1) { + for (pos.y = (int) floor(origin.y + min(0, size.y) + min(0, displacement.y) - PADDING); pos.y <= (int) ceil( + origin.y + max(0, size.y) + max(0, displacement.y) + PADDING); pos.y += 1) { + for (pos.z = (int) floor( + origin.z + min(0, size.z) + min(0, displacement.z) - PADDING); pos.z <= (int) ceil( + origin.z + max(0, size.z) + max(0, displacement.z) + PADDING); pos.z += 1) { action.accept(pos); } } diff --git a/src/main/java/ru/windcorp/progressia/common/collision/CompoundCollisionModel.java b/src/main/java/ru/windcorp/progressia/common/collision/CompoundCollisionModel.java index 6f5ec24..a91dfdf 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/CompoundCollisionModel.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/CompoundCollisionModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import java.util.Collection; diff --git a/src/main/java/ru/windcorp/progressia/common/collision/TransformedCollisionModel.java b/src/main/java/ru/windcorp/progressia/common/collision/TransformedCollisionModel.java index 96bfbee..9622423 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/TransformedCollisionModel.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/TransformedCollisionModel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/common/collision/TranslatedAABB.java b/src/main/java/ru/windcorp/progressia/common/collision/TranslatedAABB.java index 4c33ad2..fd94cfc 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/TranslatedAABB.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/TranslatedAABB.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import glm.vec._3.Vec3; diff --git a/src/main/java/ru/windcorp/progressia/common/collision/Wall.java b/src/main/java/ru/windcorp/progressia/common/collision/Wall.java index 91ca006..91e9f72 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/Wall.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/Wall.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import glm.vec._3.Vec3; diff --git a/src/main/java/ru/windcorp/progressia/common/collision/WorldCollisionHelper.java b/src/main/java/ru/windcorp/progressia/common/collision/WorldCollisionHelper.java index 69d2d4a..c843edc 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/WorldCollisionHelper.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/WorldCollisionHelper.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision; import java.util.ArrayList; @@ -68,25 +68,22 @@ public class WorldCollisionHelper { /** * Changes the state of this helper's {@link #getCollideable()} so it is - * ready to adequately handle - * collisions with the {@code collideable} that might happen in the next - * {@code maxTime} seconds. - * This helper is only valid for checking collisions with the given - * Collideable and only within + * ready to adequately handle collisions with the {@code collideable} that + * might happen in the next {@code maxTime} seconds. This helper is only + * valid for checking collisions with the given Collideable and only within * the given time limit. * - * @param collideable the {@link Collideable} that collisions will be - * checked against - * @param maxTime maximum collision time + * @param collideable + * the {@link Collideable} that collisions will be checked + * against + * @param maxTime + * maximum collision time */ public void tuneToCollideable(WorldData world, Collideable collideable, float maxTime) { activeBlockModels.forEach(blockModelCache::release); activeBlockModels.clear(); - CollisionPathComputer.forEveryBlockInCollisionPath( - collideable, - maxTime, - v -> addModel(world.getCollisionModelOfBlock(v), v) - ); + CollisionPathComputer.forEveryBlockInCollisionPath(collideable, maxTime, + v -> addModel(world.getCollisionModelOfBlock(v), v)); } private void addModel(CollisionModel model, Vec3i pos) { diff --git a/src/main/java/ru/windcorp/progressia/common/collision/colliders/AABBoidCollider.java b/src/main/java/ru/windcorp/progressia/common/collision/colliders/AABBoidCollider.java index 5fab3d8..7ff3ca1 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/colliders/AABBoidCollider.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/colliders/AABBoidCollider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision.colliders; import glm.mat._3.Mat3; @@ -29,14 +29,8 @@ import ru.windcorp.progressia.common.world.block.BlockFace; class AABBoidCollider { - static Collider.Collision computeModelCollision( - Collideable aBody, - Collideable bBody, - AABBoid aModel, - AABBoid bModel, - float tickLength, - ColliderWorkspace workspace - ) { + static Collider.Collision computeModelCollision(Collideable aBody, Collideable bBody, AABBoid aModel, + AABBoid bModel, float tickLength, ColliderWorkspace workspace) { Collideable obstacleBody = bBody; Collideable colliderBody = aBody; AABBoid obstacleModel = bModel; @@ -53,15 +47,8 @@ class AABBoidCollider { for (int i = 0; i < BlockFace.BLOCK_FACE_COUNT; ++i) { Wall wall = originCollisionSpace.getWall(i); - Collision collision = computeWallCollision( - wall, - colliderModel, - collisionVelocity, - tickLength, - workspace, - aBody, - bBody - ); + Collision collision = computeWallCollision(wall, colliderModel, collisionVelocity, tickLength, workspace, + aBody, bBody); // Update result if (collision != null) { @@ -86,11 +73,7 @@ class AABBoidCollider { return result; } - private static void computeCollisionVelocity( - Vec3 output, - Collideable obstacleBody, - Collideable colliderBody - ) { + private static void computeCollisionVelocity(Vec3 output, Collideable obstacleBody, Collideable colliderBody) { Vec3 obstacleVelocity = Vectors.grab3(); Vec3 colliderVelocity = Vectors.grab3(); @@ -124,53 +107,29 @@ class AABBoidCollider { /* * Here we determine whether a collision has actually happened, and if it - * did, at what moment. - * The basic idea is to compute the moment of collision and impact - * coordinates in wall coordinate space. - * Then, we can check impact coordinates to determine if we actually hit the - * wall or flew by and then - * check time to make sure the collision is not too far in the future and - * not in the past. - * DETAILED EXPLANATION: - * Consider a surface defined by an origin r_wall and two noncollinear - * nonzero vectors w and h. - * Consider a line defined by an origin r_line and a nonzero vector v. - * Then, a collision occurs if there exist x, y and t such that - * ______ _ - * r_line + v * t - * and - * ______ _ _ - * r_wall + w * x + h * y - * describe the same location (indeed, this corresponds to a collision at - * moment t0 + t - * with a point on the wall with coordinates (x; y) in (w; h) coordinate - * system). - * Therefore, - * ______ _ ______ _ _ - * r_line + v*t = r_wall + w*x + h*y; - * _ ⎡w_x h_x -v_x⎤ ⎡x⎤ _ ______ ______ - * r = ⎢w_y h_y -v_y⎥ * ⎢y⎥, where r = r_line - r_wall; - * ⎣w_z h_z -v_z⎦ ⎣t⎦ - * ⎡x⎤ ⎡w_x h_x -v_x⎤ -1 _ - * ⎢y⎥ = ⎢w_y h_y -v_y⎥ * r, if the matrix is invertible. - * ⎣t⎦ ⎣w_z h_z -v_z⎦ - * Then, one only needs to ensure that: - * 0 < x < 1, - * 0 < y < 1, and - * 0 < t < T, where T is remaining tick time. - * If the matrix is not invertible or any of the conditions are not met, no - * collision happened. - * If all conditions are satisfied, then the moment of impact is t0 + t. + * did, at what moment. The basic idea is to compute the moment of collision + * and impact coordinates in wall coordinate space. Then, we can check + * impact coordinates to determine if we actually hit the wall or flew by + * and then check time to make sure the collision is not too far in the + * future and not in the past. DETAILED EXPLANATION: Consider a surface + * defined by an origin r_wall and two noncollinear nonzero vectors w and h. + * Consider a line defined by an origin r_line and a nonzero vector v. Then, + * a collision occurs if there exist x, y and t such that ______ _ r_line + + * v * t and ______ _ _ r_wall + w * x + h * y describe the same location + * (indeed, this corresponds to a collision at moment t0 + t with a point on + * the wall with coordinates (x; y) in (w; h) coordinate system). Therefore, + * ______ _ ______ _ _ r_line + v*t = r_wall + w*x + h*y; _ ⎡w_x h_x + * -v_x⎤ ⎡x⎤ _ ______ ______ r = ⎢w_y h_y -v_y⎥ * ⎢y⎥, where r + * = r_line - r_wall; ⎣w_z h_z -v_z⎦ ⎣t⎦ ⎡x⎤ ⎡w_x h_x -v_x⎤ + * -1 _ ⎢y⎥ = ⎢w_y h_y -v_y⎥ * r, if the matrix is invertible. + * ⎣t⎦ ⎣w_z h_z -v_z⎦ Then, one only needs to ensure that: 0 < x < + * 1, 0 < y < 1, and 0 < t < T, where T is remaining tick time. If the + * matrix is not invertible or any of the conditions are not met, no + * collision happened. If all conditions are satisfied, then the moment of + * impact is t0 + t. */ - private static Collision computeWallCollision( - Wall obstacleWall, - AABBoid colliderModel, - Vec3 collisionVelocity, - float tickLength, - ColliderWorkspace workspace, - Collideable aBody, - Collideable bBody - ) { + private static Collision computeWallCollision(Wall obstacleWall, AABBoid colliderModel, Vec3 collisionVelocity, + float tickLength, ColliderWorkspace workspace, Collideable aBody, Collideable bBody) { Vec3 w = Vectors.grab3(); Vec3 h = Vectors.grab3(); Vec3 v = Vectors.grab3(); diff --git a/src/main/java/ru/windcorp/progressia/common/collision/colliders/AnythingWithCompoundCollider.java b/src/main/java/ru/windcorp/progressia/common/collision/colliders/AnythingWithCompoundCollider.java index 559de13..a1f3383 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/colliders/AnythingWithCompoundCollider.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/colliders/AnythingWithCompoundCollider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision.colliders; import ru.windcorp.progressia.common.collision.Collideable; @@ -26,26 +26,13 @@ import ru.windcorp.progressia.common.collision.colliders.Collider.Collision; class AnythingWithCompoundCollider { - static Collider.Collision computeModelCollision( - Collideable aBody, - Collideable bBody, - CompoundCollisionModel aModel, - CollisionModel bModel, - float tickLength, - ColliderWorkspace workspace - ) { + static Collider.Collision computeModelCollision(Collideable aBody, Collideable bBody, CompoundCollisionModel aModel, + CollisionModel bModel, float tickLength, ColliderWorkspace workspace) { Collision result = null; for (CollisionModel aModelPart : aModel.getModels()) { - Collision collision = Collider.getCollision( - aBody, - bBody, - aModelPart, - bModel, - tickLength, - workspace - ); + Collision collision = Collider.getCollision(aBody, bBody, aModelPart, bModel, tickLength, workspace); // Update result if (collision != null) { diff --git a/src/main/java/ru/windcorp/progressia/common/collision/colliders/Collider.java b/src/main/java/ru/windcorp/progressia/common/collision/colliders/Collider.java index 56bc8ad..48e1640 100644 --- a/src/main/java/ru/windcorp/progressia/common/collision/colliders/Collider.java +++ b/src/main/java/ru/windcorp/progressia/common/collision/colliders/Collider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.collision.colliders; import java.util.Collection; @@ -37,18 +37,14 @@ public class Collider { * Dear Princess Celestia, *

    * When {@linkplain #advanceTime(Collection, Collision, WorldData, float) - * advancing time}, - * time step for all entities except currently colliding bodies is - * the current - * collisions's timestamp relative to now. However, currently colliding - * bodies - * (Collision.a and Collision.b) have a smaller time step. This is done to - * make sure - * they don't intersect due to rounding errors. + * advancing time}, time step for all entities except currently + * colliding bodies is the current collisions's timestamp relative to now. + * However, currently colliding bodies (Collision.a and Collision.b) have a + * smaller time step. This is done to make sure they don't intersect due to + * rounding errors. *

    * Today I learned that bad code has nothing to do with friendship, although - * lemme tell ya: - * it's got some dank magic. + * lemme tell ya: it's got some dank magic. *

    * Your faithful student,
    * Kostyl. @@ -59,21 +55,14 @@ public class Collider { * 1f */; - public static void performCollisions( - List colls, - WorldData world, - float tickLength, - ColliderWorkspace workspace - ) { + public static void performCollisions(List colls, WorldData world, float tickLength, + ColliderWorkspace workspace) { int collisionCount = 0; int maxCollisions = colls.size() * MAX_COLLISIONS_PER_ENTITY; while (true) { if (collisionCount > maxCollisions) { - LogManager.getLogger().warn( - "Attempted to handle more than {} collisions", - maxCollisions - ); + LogManager.getLogger().warn("Attempted to handle more than {} collisions", maxCollisions); return; } @@ -93,12 +82,8 @@ public class Collider { advanceTime(colls, null, world, tickLength); } - private static Collision getFirstCollision( - List colls, - float tickLength, - WorldData world, - ColliderWorkspace workspace - ) { + private static Collision getFirstCollision(List colls, float tickLength, WorldData world, + ColliderWorkspace workspace) { Collision result = null; Collideable worldColl = workspace.worldCollisionHelper.getCollideable(); @@ -108,10 +93,7 @@ public class Collider { tuneWorldCollisionHelper(a, tickLength, world, workspace); - result = workspace.updateLatestCollision( - result, - getCollision(a, worldColl, tickLength, workspace) - ); + result = workspace.updateLatestCollision(result, getCollision(a, worldColl, tickLength, workspace)); for (int j = i + 1; j < colls.size(); ++j) { Collideable b = colls.get(j); @@ -123,81 +105,42 @@ public class Collider { return result; } - private static void tuneWorldCollisionHelper( - Collideable coll, - float tickLength, - WorldData world, - ColliderWorkspace workspace - ) { + private static void tuneWorldCollisionHelper(Collideable coll, float tickLength, WorldData world, + ColliderWorkspace workspace) { WorldCollisionHelper wch = workspace.worldCollisionHelper; wch.tuneToCollideable(world, coll, tickLength); } - static Collision getCollision( - Collideable a, - Collideable b, - float tickLength, - ColliderWorkspace workspace - ) { + static Collision getCollision(Collideable a, Collideable b, float tickLength, ColliderWorkspace workspace) { CollisionModel aModel = a.getCollisionModel(); CollisionModel bModel = b.getCollisionModel(); return getCollision(a, b, aModel, bModel, tickLength, workspace); } - static Collision getCollision( - Collideable aBody, - Collideable bBody, - CollisionModel aModel, - CollisionModel bModel, - float tickLength, - ColliderWorkspace workspace - ) { + static Collision getCollision(Collideable aBody, Collideable bBody, CollisionModel aModel, CollisionModel bModel, + float tickLength, ColliderWorkspace workspace) { if (aModel instanceof AABBoid && bModel instanceof AABBoid) { - return AABBoidCollider.computeModelCollision( - aBody, - bBody, - (AABBoid) aModel, - (AABBoid) bModel, - tickLength, - workspace - ); + return AABBoidCollider.computeModelCollision(aBody, bBody, (AABBoid) aModel, (AABBoid) bModel, tickLength, + workspace); } if (aModel instanceof CompoundCollisionModel) { - return AnythingWithCompoundCollider.computeModelCollision( - aBody, - bBody, - (CompoundCollisionModel) aModel, - bModel, - tickLength, - workspace - ); + return AnythingWithCompoundCollider.computeModelCollision(aBody, bBody, (CompoundCollisionModel) aModel, + bModel, tickLength, workspace); } if (bModel instanceof CompoundCollisionModel) { - return AnythingWithCompoundCollider.computeModelCollision( - bBody, - aBody, - (CompoundCollisionModel) bModel, - aModel, - tickLength, - workspace - ); + return AnythingWithCompoundCollider.computeModelCollision(bBody, aBody, (CompoundCollisionModel) bModel, + aModel, tickLength, workspace); } throw new UnsupportedOperationException( - "Collisions between " + aModel + " and " + bModel + " are not yet implemented" - ); + "Collisions between " + aModel + " and " + bModel + " are not yet implemented"); } - private static void collide( - Collision collision, + private static void collide(Collision collision, - Collection colls, - WorldData world, - float tickLength, - ColliderWorkspace workspace - ) { + Collection colls, WorldData world, float tickLength, ColliderWorkspace workspace) { advanceTime(colls, collision, world, collision.time); boolean doNotHandle = false; @@ -213,64 +156,38 @@ public class Collider { } /* - * Here we compute the change in body velocities due to a collision. - * We make the following simplifications: - * 1) The bodies are perfectly rigid; - * 2) The collision is perfectly inelastic - * (no bouncing); - * 3) The bodies are spherical; - * 4) No tangential friction exists - * (bodies do not experience friction when sliding against each other); - * 5) Velocities are not relativistic. - * Angular momentum is ignored per 3) and 4), - * e.g. when something pushes an end of a long stick, the stick does not - * rotate. - * DETAILED EXPLANATION: - * Two spherical (sic) bodies, a and b, experience a perfectly inelastic - * collision - * along a unit vector - * _ _ _ _ _ - * n = (w ⨯ h) / (|w ⨯ h|), - * _ _ - * where w and h are two noncollinear nonzero vectors on the dividing plane. - * ___ ___ - * Body masses and velocities are M_a, M_b and v_a, v_b, respectively. - * ___ ___ - * After the collision desired velocities are u_a and u_b, respectively. - * _ - * (Notation convention: suffix 'n' denotes a vector projection onto vector - * n, - * and suffix 't' denotes a vector projection onto the dividing plane.) - * Consider the law of conservation of momentum for axis n and the dividing - * plane: - * ____________ ____________ ________________ - * n: ⎧ p_a_before_n + p_b_before_n = p_common_after_n; - * ⎨ ___________ ____________ - * t: ⎩ p_i_after_t = p_i_before_t for any i in {a, b}. - * Expressing all p_* in given terms: - * ___ _ ___ _ ___ ___ ____ ____ - * n: ⎧ M_a * (v_a ⋅ n) + M_b * (v_b ⋅ n) = (M_a + M_b) * u_n, where u_n ≡ - * u_an = u_bn; - * ⎨ ____ ___ _ ___ _ - * t: ⎩ u_it = v_i - n * (v_i ⋅ n) for any i in {a, b}. - * Therefore: - * ___ _ ___ _ ___ _ - * u_n = n * ( M_a/(M_a + M_b) * v_a ⋅ n + M_b/(M_a + M_b) * v_b ⋅ n ); - * or, equivalently, - * ___ _ ___ _ ___ _ - * u_n = n * ( m_a * v_a ⋅ n + m_b * v_b ⋅ n ), - * where m_a and m_b are relative masses (see below). - * Finally, - * ___ ____ ___ - * u_i = u_it + u_n for any i in {a, b}. - * The usage of relative masses m_i permits a convenient generalization of - * the algorithm - * for infinite masses, signifying masses "significantly greater" than - * finite masses: - * 1) If both M_a and M_b are finite, let m_i = M_i / (M_a + M_b) for any i + * Here we compute the change in body velocities due to a collision. We make + * the following simplifications: 1) The bodies are perfectly rigid; 2) The + * collision is perfectly inelastic (no bouncing); 3) The bodies are + * spherical; 4) No tangential friction exists (bodies do not experience + * friction when sliding against each other); 5) Velocities are not + * relativistic. Angular momentum is ignored per 3) and 4), e.g. when + * something pushes an end of a long stick, the stick does not rotate. + * DETAILED EXPLANATION: Two spherical (sic) bodies, a and b, experience a + * perfectly inelastic collision along a unit vector _ _ _ _ _ n = (w ⨯ h) + * / (|w ⨯ h|), _ _ where w and h are two noncollinear nonzero vectors on + * the dividing plane. ___ ___ Body masses and velocities are M_a, M_b and + * v_a, v_b, respectively. ___ ___ After the collision desired velocities + * are u_a and u_b, respectively. _ (Notation convention: suffix 'n' denotes + * a vector projection onto vector n, and suffix 't' denotes a vector + * projection onto the dividing plane.) Consider the law of conservation of + * momentum for axis n and the dividing plane: ____________ ____________ + * ________________ n: ⎧ p_a_before_n + p_b_before_n = p_common_after_n; + * ⎨ ___________ ____________ t: ⎩ p_i_after_t = p_i_before_t for any i + * in {a, b}. Expressing all p_* in given terms: ___ _ ___ _ ___ ___ ____ + * ____ n: ⎧ M_a * (v_a ⋅ n) + M_b * (v_b ⋅ n) = (M_a + M_b) * u_n, + * where u_n ≡ u_an = u_bn; ⎨ ____ ___ _ ___ _ t: ⎩ u_it = v_i - n * + * (v_i ⋅ n) for any i in {a, b}. Therefore: ___ _ ___ _ ___ _ u_n = n * ( + * M_a/(M_a + M_b) * v_a ⋅ n + M_b/(M_a + M_b) * v_b ⋅ n ); or, + * equivalently, ___ _ ___ _ ___ _ u_n = n * ( m_a * v_a ⋅ n + m_b * v_b + * ⋅ n ), where m_a and m_b are relative masses (see below). Finally, ___ + * ____ ___ u_i = u_it + u_n for any i in {a, b}. The usage of relative + * masses m_i permits a convenient generalization of the algorithm for + * infinite masses, signifying masses "significantly greater" than finite + * masses: 1) If both M_a and M_b are finite, let m_i = M_i / (M_a + M_b) + * for any i in {a, b}. 2) If M_i is finite but M_j is infinite, let m_i = 0 + * and m_j = 1. 3) If both M_a and M_b are infinite, let m_i = 1/2 for any i * in {a, b}. - * 2) If M_i is finite but M_j is infinite, let m_i = 0 and m_j = 1. - * 3) If both M_a and M_b are infinite, let m_i = 1/2 for any i in {a, b}. */ private static void handlePhysics(Collision collision) { // Fuck JGLM @@ -333,12 +250,7 @@ public class Collider { Vectors.release(du_b); } - private static void separate( - Collision collision, - Vec3 normal, - float aRelativeMass, - float bRelativeMass - ) { + private static void separate(Collision collision, Vec3 normal, float aRelativeMass, float bRelativeMass) { final float margin = 1e-4f; Vec3 displacement = Vectors.grab3(); @@ -352,12 +264,8 @@ public class Collider { Vectors.release(displacement); } - private static void advanceTime( - Collection colls, - Collision exceptions, - WorldData world, - float step - ) { + private static void advanceTime(Collection colls, Collision exceptions, WorldData world, + float step) { world.advanceTime(step); Vec3 tmp = Vectors.grab3(); @@ -425,17 +333,12 @@ public class Collider { public final Vec3 wallHeight = new Vec3(); /** - * Time offset from the start of the tick. - * 0 means right now, tickLength means at the end of the tick. + * Time offset from the start of the tick. 0 means right now, tickLength + * means at the end of the tick. */ public float time; - public Collision set( - Collideable a, - Collideable b, - Wall wall, - float time - ) { + public Collision set(Collideable a, Collideable b, Wall wall, float time) { this.a = a; this.b = b; wall.getWidth(wallWidth); diff --git a/src/main/java/ru/windcorp/progressia/common/comms/CommsChannel.java b/src/main/java/ru/windcorp/progressia/common/comms/CommsChannel.java index 288b5dd..32e8829 100644 --- a/src/main/java/ru/windcorp/progressia/common/comms/CommsChannel.java +++ b/src/main/java/ru/windcorp/progressia/common/comms/CommsChannel.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.comms; import java.io.IOException; @@ -56,15 +56,9 @@ public abstract class CommsChannel { protected abstract void doSendPacket(Packet packet) throws IOException; - private synchronized void sendPacket( - Packet packet, - State expectedState, - String errorMessage - ) { + private synchronized void sendPacket(Packet packet, State expectedState, String errorMessage) { if (getState() != expectedState) { - throw new IllegalStateException( - String.format(errorMessage, this, getState()) - ); + throw new IllegalStateException(String.format(errorMessage, this, getState())); } try { @@ -75,27 +69,15 @@ public abstract class CommsChannel { } public synchronized void sendPacket(Packet packet) { - sendPacket( - packet, - State.CONNECTED, - "Client %s is in state %s and cannot receive packets normally" - ); + sendPacket(packet, State.CONNECTED, "Client %s is in state %s and cannot receive packets normally"); } public synchronized void sendConnectingPacket(Packet packet) { - sendPacket( - packet, - State.CONNECTING, - "Client %s is in state %s and is no longer connecting" - ); + sendPacket(packet, State.CONNECTING, "Client %s is in state %s and is no longer connecting"); } public synchronized void sendDisconnectingPacket(Packet packet) { - sendPacket( - packet, - State.CONNECTING, - "Client %s is in state %s and is no longer disconnecting" - ); + sendPacket(packet, State.CONNECTING, "Client %s is in state %s and is no longer disconnecting"); } public abstract void disconnect(); diff --git a/src/main/java/ru/windcorp/progressia/common/comms/CommsListener.java b/src/main/java/ru/windcorp/progressia/common/comms/CommsListener.java index 7445e93..e133cf8 100644 --- a/src/main/java/ru/windcorp/progressia/common/comms/CommsListener.java +++ b/src/main/java/ru/windcorp/progressia/common/comms/CommsListener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.comms; import java.io.IOException; diff --git a/src/main/java/ru/windcorp/progressia/common/comms/controls/ControlData.java b/src/main/java/ru/windcorp/progressia/common/comms/controls/ControlData.java index 46e4e94..d90505b 100644 --- a/src/main/java/ru/windcorp/progressia/common/comms/controls/ControlData.java +++ b/src/main/java/ru/windcorp/progressia/common/comms/controls/ControlData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.comms.controls; import ru.windcorp.progressia.common.util.namespaces.Namespaced; diff --git a/src/main/java/ru/windcorp/progressia/common/comms/controls/ControlDataRegistry.java b/src/main/java/ru/windcorp/progressia/common/comms/controls/ControlDataRegistry.java index cd884e8..59a8529 100644 --- a/src/main/java/ru/windcorp/progressia/common/comms/controls/ControlDataRegistry.java +++ b/src/main/java/ru/windcorp/progressia/common/comms/controls/ControlDataRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.comms.controls; import ru.windcorp.progressia.common.util.namespaces.NamespacedFactoryRegistry; diff --git a/src/main/java/ru/windcorp/progressia/common/comms/controls/PacketControl.java b/src/main/java/ru/windcorp/progressia/common/comms/controls/PacketControl.java index d5abd39..2d352bb 100644 --- a/src/main/java/ru/windcorp/progressia/common/comms/controls/PacketControl.java +++ b/src/main/java/ru/windcorp/progressia/common/comms/controls/PacketControl.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.comms.controls; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/comms/packets/Packet.java b/src/main/java/ru/windcorp/progressia/common/comms/packets/Packet.java index 5421028..8669eb3 100644 --- a/src/main/java/ru/windcorp/progressia/common/comms/packets/Packet.java +++ b/src/main/java/ru/windcorp/progressia/common/comms/packets/Packet.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.comms.packets; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/hacks/GuavaEventBusHijacker.java b/src/main/java/ru/windcorp/progressia/common/hacks/GuavaEventBusHijacker.java index 6bc7901..dada94e 100644 --- a/src/main/java/ru/windcorp/progressia/common/hacks/GuavaEventBusHijacker.java +++ b/src/main/java/ru/windcorp/progressia/common/hacks/GuavaEventBusHijacker.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.hacks; import java.lang.reflect.Constructor; @@ -30,14 +30,10 @@ import ru.windcorp.progressia.common.util.crash.CrashReports; /** * This class had to be written because there is not legal way to instantiate a - * non-async - * {@link EventBus} with both a custom identifier and a custom exception - * handler. Which - * is a shame. Guava maintainers know about the issue but have rejected - * solutions multiple - * times without a clearly stated reason; looks like some dirty - * reflection will - * have to do. + * non-async {@link EventBus} with both a custom identifier and a custom + * exception handler. Which is a shame. Guava maintainers know about the issue + * but have rejected solutions multiple times without a clearly stated + * reason; looks like some dirty reflection will have to do. * * @author javapony */ @@ -50,30 +46,22 @@ public class GuavaEventBusHijacker { try { Class dispatcherClass = Class.forName("com.google.common.eventbus.Dispatcher"); - THE_CONSTRUCTOR = EventBus.class.getDeclaredConstructor( - String.class, - Executor.class, - dispatcherClass, - SubscriberExceptionHandler.class - ); + THE_CONSTRUCTOR = EventBus.class.getDeclaredConstructor(String.class, Executor.class, dispatcherClass, + SubscriberExceptionHandler.class); THE_CONSTRUCTOR.setAccessible(true); DISPATCHER__PER_THREAD_DISPATCH_QUEUE = dispatcherClass.getDeclaredMethod("perThreadDispatchQueue"); DISPATCHER__PER_THREAD_DISPATCH_QUEUE.setAccessible(true); } catch (Exception e) { - throw CrashReports - .report(e, "Something went horribly wrong when setting up EventBus hijacking. Has Guava updated?"); + throw CrashReports.report(e, + "Something went horribly wrong when setting up EventBus hijacking. Has Guava updated?"); } } public static EventBus newEventBus(String identifier, SubscriberExceptionHandler exceptionHandler) { try { - return THE_CONSTRUCTOR.newInstance( - identifier, - MoreExecutors.directExecutor(), - DISPATCHER__PER_THREAD_DISPATCH_QUEUE.invoke(null), - exceptionHandler - ); + return THE_CONSTRUCTOR.newInstance(identifier, MoreExecutors.directExecutor(), + DISPATCHER__PER_THREAD_DISPATCH_QUEUE.invoke(null), exceptionHandler); } catch (Exception e) { throw CrashReports.report(e, "Something went horribly wrong when hijacking EventBus. Has Guava updated?"); } diff --git a/src/main/java/ru/windcorp/progressia/common/resource/Resource.java b/src/main/java/ru/windcorp/progressia/common/resource/Resource.java index 6cd4d32..41cf621 100644 --- a/src/main/java/ru/windcorp/progressia/common/resource/Resource.java +++ b/src/main/java/ru/windcorp/progressia/common/resource/Resource.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.resource; import java.io.IOException; @@ -34,7 +34,7 @@ import ru.windcorp.progressia.common.util.Named; import ru.windcorp.progressia.common.util.crash.CrashReports; public class Resource extends Named { - + private final ResourceReader resourceReader; public Resource(String name, ResourceReader resourceReader) { @@ -45,7 +45,7 @@ public class Resource extends Named { public InputStream getInputStream() { return getResourceReader().read(getName()); } - + public ResourceReader getResourceReader() { return resourceReader; } diff --git a/src/main/java/ru/windcorp/progressia/common/resource/ResourceManager.java b/src/main/java/ru/windcorp/progressia/common/resource/ResourceManager.java index 33db64d..fcfc43f 100644 --- a/src/main/java/ru/windcorp/progressia/common/resource/ResourceManager.java +++ b/src/main/java/ru/windcorp/progressia/common/resource/ResourceManager.java @@ -15,18 +15,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.resource; public class ResourceManager { - + private static final ResourceReader CLASSPATH_READER = new ClasspathResourceReader(); private static final ResourceReader FILESYSTEM_READER = new FilesystemResourceReader(); public static Resource getResource(String name) { return new Resource(name, CLASSPATH_READER); } - + public static Resource getFileResource(String name) { return new Resource(name, FILESYSTEM_READER); } diff --git a/src/main/java/ru/windcorp/progressia/common/resource/ResourceReader.java b/src/main/java/ru/windcorp/progressia/common/resource/ResourceReader.java index 1f95f2c..49c221c 100644 --- a/src/main/java/ru/windcorp/progressia/common/resource/ResourceReader.java +++ b/src/main/java/ru/windcorp/progressia/common/resource/ResourceReader.java @@ -20,7 +20,7 @@ package ru.windcorp.progressia.common.resource; import java.io.InputStream; public interface ResourceReader { - + InputStream read(String name); } diff --git a/src/main/java/ru/windcorp/progressia/common/state/AbstractStatefulObjectLayout.java b/src/main/java/ru/windcorp/progressia/common/state/AbstractStatefulObjectLayout.java index b2feb80..6752fd7 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/AbstractStatefulObjectLayout.java +++ b/src/main/java/ru/windcorp/progressia/common/state/AbstractStatefulObjectLayout.java @@ -15,15 +15,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -public abstract class AbstractStatefulObjectLayout - extends StatefulObjectLayout { +public abstract class AbstractStatefulObjectLayout extends StatefulObjectLayout { public AbstractStatefulObjectLayout(String objectId) { super(objectId); @@ -34,12 +33,7 @@ public abstract class AbstractStatefulObjectLayout protected abstract StateField getField(int fieldIndex); @Override - public void read( - StatefulObject object, - DataInput input, - IOContext context - ) - throws IOException { + public void read(StatefulObject object, DataInput input, IOContext context) throws IOException { int fieldCount = getFieldCount(); for (int i = 0; i < fieldCount; ++i) { @@ -53,12 +47,7 @@ public abstract class AbstractStatefulObjectLayout } @Override - public void write( - StatefulObject object, - DataOutput output, - IOContext context - ) - throws IOException { + public void write(StatefulObject object, DataOutput output, IOContext context) throws IOException { int fieldCount = getFieldCount(); for (int i = 0; i < fieldCount; ++i) { diff --git a/src/main/java/ru/windcorp/progressia/common/state/HashMapStateStorage.java b/src/main/java/ru/windcorp/progressia/common/state/HashMapStateStorage.java index 52d446f..56ee25d 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/HashMapStateStorage.java +++ b/src/main/java/ru/windcorp/progressia/common/state/HashMapStateStorage.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import gnu.trove.map.TIntIntMap; diff --git a/src/main/java/ru/windcorp/progressia/common/state/IOContext.java b/src/main/java/ru/windcorp/progressia/common/state/IOContext.java index b18f875..c309596 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/IOContext.java +++ b/src/main/java/ru/windcorp/progressia/common/state/IOContext.java @@ -15,13 +15,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; public enum IOContext { - COMMS, - SAVE, - INTERNAL; + COMMS, SAVE, INTERNAL; } diff --git a/src/main/java/ru/windcorp/progressia/common/state/InspectingStatefulObjectLayout.java b/src/main/java/ru/windcorp/progressia/common/state/InspectingStatefulObjectLayout.java index 8b0a9fe..d32af14 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/InspectingStatefulObjectLayout.java +++ b/src/main/java/ru/windcorp/progressia/common/state/InspectingStatefulObjectLayout.java @@ -15,14 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import java.util.ArrayList; import java.util.List; -public class InspectingStatefulObjectLayout - extends AbstractStatefulObjectLayout { +public class InspectingStatefulObjectLayout extends AbstractStatefulObjectLayout { private final List fields = new ArrayList<>(); @@ -48,11 +47,7 @@ public class InspectingStatefulObjectLayout } public StatefulObjectLayout compile() { - return new OptimizedStatefulObjectLayout( - getObjectId(), - fields, - fieldIndexCounters - ); + return new OptimizedStatefulObjectLayout(getObjectId(), fields, fieldIndexCounters); } private T registerField(T field) { @@ -71,13 +66,7 @@ public class InspectingStatefulObjectLayout @Override public IntStateField build() { - return registerField( - new IntStateField( - id, - isLocal, - fieldIndexCounters.getIntsThenIncrement() - ) - ); + return registerField(new IntStateField(id, isLocal, fieldIndexCounters.getIntsThenIncrement())); } } @@ -105,10 +94,7 @@ public class InspectingStatefulObjectLayout public void setOrdinal(int ordinal) { if (ordinal != fields.size()) { throw new IllegalStateException( - "This field is going to receive ordinal " - + fields.size() + ", requested ordinal " - + ordinal - ); + "This field is going to receive ordinal " + fields.size() + ", requested ordinal " + ordinal); } } diff --git a/src/main/java/ru/windcorp/progressia/common/state/IntStateField.java b/src/main/java/ru/windcorp/progressia/common/state/IntStateField.java index abf8573..7390187 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/IntStateField.java +++ b/src/main/java/ru/windcorp/progressia/common/state/IntStateField.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import java.io.DataInput; @@ -24,11 +24,7 @@ import java.io.IOException; public class IntStateField extends StateField { - public IntStateField( - String id, - boolean isLocal, - int index - ) { + public IntStateField(String id, boolean isLocal, int index) { super(id, isLocal, index); } @@ -45,22 +41,12 @@ public class IntStateField extends StateField { } @Override - public void read( - StatefulObject object, - DataInput input, - IOContext context - ) - throws IOException { + public void read(StatefulObject object, DataInput input, IOContext context) throws IOException { object.getStorage().setInt(getIndex(), input.readInt()); } @Override - public void write( - StatefulObject object, - DataOutput output, - IOContext context - ) - throws IOException { + public void write(StatefulObject object, DataOutput output, IOContext context) throws IOException { output.writeInt(object.getStorage().getInt(getIndex())); } diff --git a/src/main/java/ru/windcorp/progressia/common/state/OptimizedStateStorage.java b/src/main/java/ru/windcorp/progressia/common/state/OptimizedStateStorage.java index 478fbac..fbedec7 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/OptimizedStateStorage.java +++ b/src/main/java/ru/windcorp/progressia/common/state/OptimizedStateStorage.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; public class OptimizedStateStorage extends StateStorage { diff --git a/src/main/java/ru/windcorp/progressia/common/state/OptimizedStatefulObjectLayout.java b/src/main/java/ru/windcorp/progressia/common/state/OptimizedStatefulObjectLayout.java index 1158ab0..c9269c2 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/OptimizedStatefulObjectLayout.java +++ b/src/main/java/ru/windcorp/progressia/common/state/OptimizedStatefulObjectLayout.java @@ -15,24 +15,19 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import java.util.List; import com.google.common.collect.ImmutableList; -public class OptimizedStatefulObjectLayout - extends AbstractStatefulObjectLayout { +public class OptimizedStatefulObjectLayout extends AbstractStatefulObjectLayout { private final List fields; private final PrimitiveCounters sizes; - public OptimizedStatefulObjectLayout( - String objectId, - List fields, - PrimitiveCounters counters - ) { + public OptimizedStatefulObjectLayout(String objectId, List fields, PrimitiveCounters counters) { super(objectId); this.fields = ImmutableList.copyOf(fields); this.sizes = new PrimitiveCounters(counters); diff --git a/src/main/java/ru/windcorp/progressia/common/state/PrimitiveCounters.java b/src/main/java/ru/windcorp/progressia/common/state/PrimitiveCounters.java index d3e2dbb..243d62a 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/PrimitiveCounters.java +++ b/src/main/java/ru/windcorp/progressia/common/state/PrimitiveCounters.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; class PrimitiveCounters { diff --git a/src/main/java/ru/windcorp/progressia/common/state/StateChanger.java b/src/main/java/ru/windcorp/progressia/common/state/StateChanger.java index cc8cd5a..a93e64e 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/StateChanger.java +++ b/src/main/java/ru/windcorp/progressia/common/state/StateChanger.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; public interface StateChanger { diff --git a/src/main/java/ru/windcorp/progressia/common/state/StateField.java b/src/main/java/ru/windcorp/progressia/common/state/StateField.java index ca88c4f..1e512ef 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/StateField.java +++ b/src/main/java/ru/windcorp/progressia/common/state/StateField.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import java.io.DataInput; @@ -29,11 +29,7 @@ public abstract class StateField extends Namespaced { private final boolean isLocal; private final int index; - public StateField( - String id, - boolean isLocal, - int index - ) { + public StateField(String id, boolean isLocal, int index) { super(id); this.isLocal = isLocal; this.index = index; @@ -47,19 +43,9 @@ public abstract class StateField extends Namespaced { return index; } - public abstract void read( - StatefulObject object, - DataInput input, - IOContext context - ) - throws IOException; + public abstract void read(StatefulObject object, DataInput input, IOContext context) throws IOException; - public abstract void write( - StatefulObject object, - DataOutput output, - IOContext context - ) - throws IOException; + public abstract void write(StatefulObject object, DataOutput output, IOContext context) throws IOException; public abstract void copy(StatefulObject from, StatefulObject to); diff --git a/src/main/java/ru/windcorp/progressia/common/state/StateFieldBuilder.java b/src/main/java/ru/windcorp/progressia/common/state/StateFieldBuilder.java index 97c7176..935129a 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/StateFieldBuilder.java +++ b/src/main/java/ru/windcorp/progressia/common/state/StateFieldBuilder.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; public interface StateFieldBuilder { diff --git a/src/main/java/ru/windcorp/progressia/common/state/StateStorage.java b/src/main/java/ru/windcorp/progressia/common/state/StateStorage.java index 2f999f0..647ae00 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/StateStorage.java +++ b/src/main/java/ru/windcorp/progressia/common/state/StateStorage.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; public abstract class StateStorage { diff --git a/src/main/java/ru/windcorp/progressia/common/state/StatefulObject.java b/src/main/java/ru/windcorp/progressia/common/state/StatefulObject.java index 39f5b58..39714b6 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/StatefulObject.java +++ b/src/main/java/ru/windcorp/progressia/common/state/StatefulObject.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import java.io.DataInput; @@ -26,24 +26,22 @@ import java.util.Objects; import ru.windcorp.progressia.common.util.namespaces.Namespaced; /** - * An abstract class describing objects that have trackable state, - * such as blocks, tiles or entities. This class contains the declaration of - * the state mechanics - * (implementation of which is mostly delegated to + * An abstract class describing objects that have trackable state, such as + * blocks, tiles or entities. This class contains the declaration of the state + * mechanics (implementation of which is mostly delegated to * {@link StatefulObjectLayout}). - *

    Structure

    - * Stateful objects are characterized by their likeness and state. + *

    Structure

    Stateful objects are characterized by their + * likeness and state. *

    * An object's likeness is the combination of the object's runtime class (as in * {@link #getClass()}) and its ID. Objects that are "alike" share the same - * internal structure, represented by a common - * {@linkplain StatefulObjectLayout layout}. Likeness can be tested with - * {@link #isLike(Object)}. + * internal structure, represented by a common {@linkplain StatefulObjectLayout + * layout}. Likeness can be tested with {@link #isLike(Object)}. *

    * An object's state is the combination of the values of an object's * {@linkplain StateField state fields}. State fields are different from object - * fields as described by the Java language: not every object field is a part - * of its state, although state fields are usually implemented as object fields. + * fields as described by the Java language: not every object field is a part of + * its state, although state fields are usually implemented as object fields. * Each state field is, in its turn, has the following characteristics: *

      *
    • ID, distinct from the ID of the stateful object to which it belongs. @@ -58,10 +56,7 @@ public abstract class StatefulObject extends Namespaced { private final StateStorage storage; - public StatefulObject( - StatefulObjectRegistry type, - String id - ) { + public StatefulObject(StatefulObjectRegistry type, String id) { super(id); this.layout = type.getLayout(getId()); this.storage = getLayout().createStorage(); @@ -69,8 +64,8 @@ public abstract class StatefulObject extends Namespaced { /** * Returns the {@link StatefulObjectLayout} describing objects that are - * {@linkplain #isLike(Object) "like"} this object. - * You probably don't need this. + * {@linkplain #isLike(Object) "like"} this object. You probably don't need + * this. * * @return this object's field layout */ @@ -106,8 +101,10 @@ public abstract class StatefulObject extends Namespaced { * sequence of invocations must occur during construction of each object * with the same ID. * - * @param namespace the namespace of the new field - * @param name the name of the new field + * @param namespace + * the namespace of the new field + * @param name + * the name of the new field * @return a configured builder */ protected StateFieldBuilder field(String id) { @@ -128,10 +125,13 @@ public abstract class StatefulObject extends Namespaced { * from {@code input}. If {@code context == COMMS}, the state of local * fields is unspecified after this operation. * - * @param input a {@link DataInput} that a state can be read from - * @param context the context - * @throws IOException if the state is encoded poorly or an error occurs - * in {@code input} + * @param input + * a {@link DataInput} that a state can be read from + * @param context + * the context + * @throws IOException + * if the state is encoded poorly or an error occurs in + * {@code input} */ public void read(DataInput input, IOContext context) throws IOException { getLayout().read(this, input, context); @@ -141,9 +141,12 @@ public abstract class StatefulObject extends Namespaced { * Writes the binary representation of the state of this object to the * {@code output}. * - * @param output a {@link DataOutput} that a state can be written to - * @param context the context - * @throws IOException if an error occurs in {@code output} + * @param output + * a {@link DataOutput} that a state can be written to + * @param context + * the context + * @throws IOException + * if an error occurs in {@code output} */ public void write(DataOutput output, IOContext context) throws IOException { getLayout().write(this, output, context); @@ -164,22 +167,19 @@ public abstract class StatefulObject extends Namespaced { * to {@code destination} can affect this object.
    • *
    * - * @param destination the object to copy this object into. + * @param destination + * the object to copy this object into. */ public StatefulObject copy(StatefulObject destination) { Objects.requireNonNull(destination, "destination"); if (destination == this) { - throw new IllegalArgumentException( - "Cannot copy an object into itself" - ); + throw new IllegalArgumentException("Cannot copy an object into itself"); } if (destination.getClass() != this.getClass()) { throw new IllegalArgumentException( - "Cannot copy from " + getClass() - + " (ID " + getId() + ") to " + destination.getClass() - ); + "Cannot copy from " + getClass() + " (ID " + getId() + ") to " + destination.getClass()); } getLayout().copy(this, destination); @@ -200,7 +200,8 @@ public abstract class StatefulObject extends Namespaced { * {@linkplain #isLike(Object) "like"} and their binary representations * match exactly. * - * @param obj the object to examine + * @param obj + * the object to examine * @return {@code true} if {@code obj != null} and this object is equal to * {@code obj} */ @@ -220,7 +221,8 @@ public abstract class StatefulObject extends Namespaced { * Returns {@code true} iff this object and {@code obj} have the same ID and * are instances of the same class. * - * @param obj the object to examine + * @param obj + * the object to examine * @return {@code true} if {@code obj} is "like" this object */ public boolean isLike(Object obj) { diff --git a/src/main/java/ru/windcorp/progressia/common/state/StatefulObjectLayout.java b/src/main/java/ru/windcorp/progressia/common/state/StatefulObjectLayout.java index 4490cdf..b841848 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/StatefulObjectLayout.java +++ b/src/main/java/ru/windcorp/progressia/common/state/StatefulObjectLayout.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import java.io.DataInput; @@ -38,25 +38,13 @@ public abstract class StatefulObjectLayout { protected void checkObject(StatefulObject object) { if (!object.getId().equals(getObjectId())) { - throw new IllegalArgumentException( - object.getId() + " is not " + getObjectId() - ); + throw new IllegalArgumentException(object.getId() + " is not " + getObjectId()); } } - public abstract void read( - StatefulObject object, - DataInput input, - IOContext context - ) - throws IOException; + public abstract void read(StatefulObject object, DataInput input, IOContext context) throws IOException; - public abstract void write( - StatefulObject object, - DataOutput output, - IOContext context - ) - throws IOException; + public abstract void write(StatefulObject object, DataOutput output, IOContext context) throws IOException; public abstract void copy(StatefulObject from, StatefulObject to); diff --git a/src/main/java/ru/windcorp/progressia/common/state/StatefulObjectRegistry.java b/src/main/java/ru/windcorp/progressia/common/state/StatefulObjectRegistry.java index aa082a6..8f01ac8 100644 --- a/src/main/java/ru/windcorp/progressia/common/state/StatefulObjectRegistry.java +++ b/src/main/java/ru/windcorp/progressia/common/state/StatefulObjectRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.state; import java.util.Collections; @@ -78,9 +78,7 @@ public class StatefulObjectRegistry { StatefulObjectLayout layout = layouts.get(id); if (layout == null) { - throw new IllegalArgumentException( - "ID " + id + " has not been registered" - ); + throw new IllegalArgumentException("ID " + id + " has not been registered"); } return layout; @@ -88,9 +86,7 @@ public class StatefulObjectRegistry { protected void register(Type type) { if (!type.getRegistrationFlag().compareAndSet(false, true)) { - throw new IllegalStateException( - "ID " + type.getId() + " is already registered" - ); + throw new IllegalStateException("ID " + type.getId() + " is already registered"); } InspectingStatefulObjectLayout inspector = new InspectingStatefulObjectLayout(type.getId()); diff --git a/src/main/java/ru/windcorp/progressia/common/util/BinUtil.java b/src/main/java/ru/windcorp/progressia/common/util/BinUtil.java index ffc8a43..042d2a1 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/BinUtil.java +++ b/src/main/java/ru/windcorp/progressia/common/util/BinUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; public class BinUtil { diff --git a/src/main/java/ru/windcorp/progressia/common/util/ByteBufferInputStream.java b/src/main/java/ru/windcorp/progressia/common/util/ByteBufferInputStream.java index 6b317a7..f3380a9 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/ByteBufferInputStream.java +++ b/src/main/java/ru/windcorp/progressia/common/util/ByteBufferInputStream.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.io.InputStream; diff --git a/src/main/java/ru/windcorp/progressia/common/util/ByteBufferOutputStream.java b/src/main/java/ru/windcorp/progressia/common/util/ByteBufferOutputStream.java index 8931c75..152a17f 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/ByteBufferOutputStream.java +++ b/src/main/java/ru/windcorp/progressia/common/util/ByteBufferOutputStream.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.io.IOException; diff --git a/src/main/java/ru/windcorp/progressia/common/util/CoordinatePacker.java b/src/main/java/ru/windcorp/progressia/common/util/CoordinatePacker.java index 0ef2413..f909b8a 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/CoordinatePacker.java +++ b/src/main/java/ru/windcorp/progressia/common/util/CoordinatePacker.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import glm.vec._2.i.Vec2i; @@ -33,13 +33,10 @@ public class CoordinatePacker { BITS_3_INTS_INTO_LONG = 64 / 3; /* - * What happens below: - * 1. 1 << BITS_3_INTS_INTO_LONG: - * 0000 ... 00100 ... 0000 - * \_________/ - BITS_3_INTS_INTO_LONG zeros - * 2. (1 << BITS_3_INTS_INTO_LONG) - 1: - * 0000 ... 00011 ... 1111 - * \_________/ - BITS_3_INTS_INTO_LONG ones - WIN + * What happens below: 1. 1 << BITS_3_INTS_INTO_LONG: 0000 ... 00100 ... + * 0000 \_________/ - BITS_3_INTS_INTO_LONG zeros 2. (1 << + * BITS_3_INTS_INTO_LONG) - 1: 0000 ... 00011 ... 1111 \_________/ - + * BITS_3_INTS_INTO_LONG ones - WIN */ MASK_3_INTS_INTO_LONG = (1l << BITS_3_INTS_INTO_LONG) - 1; @@ -49,9 +46,9 @@ public class CoordinatePacker { } public static long pack3IntsIntoLong(int a, int b, int c) { - return ((a & MASK_3_INTS_INTO_LONG) << (2 * BITS_3_INTS_INTO_LONG)) | - ((b & MASK_3_INTS_INTO_LONG) << (1 * BITS_3_INTS_INTO_LONG)) | - ((c & MASK_3_INTS_INTO_LONG) << (0 * BITS_3_INTS_INTO_LONG)); + return ((a & MASK_3_INTS_INTO_LONG) << (2 * BITS_3_INTS_INTO_LONG)) + | ((b & MASK_3_INTS_INTO_LONG) << (1 * BITS_3_INTS_INTO_LONG)) + | ((c & MASK_3_INTS_INTO_LONG) << (0 * BITS_3_INTS_INTO_LONG)); } public static long pack3IntsIntoLong(Vec3i v) { @@ -63,8 +60,7 @@ public class CoordinatePacker { throw new IllegalArgumentException("Invalid index " + index); } - int result = (int) ((packed >>> ((2 - index) * BITS_3_INTS_INTO_LONG)) - & MASK_3_INTS_INTO_LONG); + int result = (int) ((packed >>> ((2 - index) * BITS_3_INTS_INTO_LONG)) & MASK_3_INTS_INTO_LONG); final long signMask = ((MASK_3_INTS_INTO_LONG + 1) >> 1); @@ -79,18 +75,14 @@ public class CoordinatePacker { if (output == null) output = new Vec3i(); - output.set( - unpack3IntsFromLong(packed, 0), - unpack3IntsFromLong(packed, 1), - unpack3IntsFromLong(packed, 2) - ); + output.set(unpack3IntsFromLong(packed, 0), unpack3IntsFromLong(packed, 1), unpack3IntsFromLong(packed, 2)); return output; } public static long pack2IntsIntoLong(int a, int b) { - return ((a & MASK_2_INTS_INTO_LONG) << (1 * BITS_2_INTS_INTO_LONG)) | - ((b & MASK_2_INTS_INTO_LONG) << (0 * BITS_2_INTS_INTO_LONG)); + return ((a & MASK_2_INTS_INTO_LONG) << (1 * BITS_2_INTS_INTO_LONG)) + | ((b & MASK_2_INTS_INTO_LONG) << (0 * BITS_2_INTS_INTO_LONG)); } public static long pack2IntsIntoLong(Vec2i v) { @@ -102,8 +94,7 @@ public class CoordinatePacker { throw new IllegalArgumentException("Invalid index " + index); } - int result = (int) ((packed >>> ((1 - index) * BITS_2_INTS_INTO_LONG)) - & MASK_2_INTS_INTO_LONG); + int result = (int) ((packed >>> ((1 - index) * BITS_2_INTS_INTO_LONG)) & MASK_2_INTS_INTO_LONG); return result; } @@ -112,10 +103,7 @@ public class CoordinatePacker { if (output == null) output = new Vec2i(); - output.set( - unpack2IntsFromLong(packed, 0), - unpack2IntsFromLong(packed, 1) - ); + output.set(unpack2IntsFromLong(packed, 0), unpack2IntsFromLong(packed, 1)); return output; } diff --git a/src/main/java/ru/windcorp/progressia/common/util/DataBuffer.java b/src/main/java/ru/windcorp/progressia/common/util/DataBuffer.java index 23522c1..b500ace 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/DataBuffer.java +++ b/src/main/java/ru/windcorp/progressia/common/util/DataBuffer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.io.DataInput; @@ -113,10 +113,7 @@ public class DataBuffer { int length = buffer.size(); while (position < length) { - int currentLength = Math.min( - transferBuffer.length, - length - position - ); + int currentLength = Math.min(transferBuffer.length, length - position); buffer.toArray(transferBuffer, position, 0, currentLength); sink.write(transferBuffer, 0, currentLength); diff --git a/src/main/java/ru/windcorp/progressia/common/util/FloatMathUtil.java b/src/main/java/ru/windcorp/progressia/common/util/FloatMathUtil.java index 43487c0..a1008de 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/FloatMathUtil.java +++ b/src/main/java/ru/windcorp/progressia/common/util/FloatMathUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; public class FloatMathUtil { diff --git a/src/main/java/ru/windcorp/progressia/common/util/LowOverheadCache.java b/src/main/java/ru/windcorp/progressia/common/util/LowOverheadCache.java index c5b2952..9d668e9 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/LowOverheadCache.java +++ b/src/main/java/ru/windcorp/progressia/common/util/LowOverheadCache.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.util.ArrayList; diff --git a/src/main/java/ru/windcorp/progressia/common/util/Matrices.java b/src/main/java/ru/windcorp/progressia/common/util/Matrices.java index 8804272..b36669b 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/Matrices.java +++ b/src/main/java/ru/windcorp/progressia/common/util/Matrices.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import glm.mat._3.Mat3; @@ -37,8 +37,8 @@ import glm.mat._4.d.Mat4d; * } * * - * Provided objects may be reused after {@code release} has been invoked; - * do not store them. + * Provided objects may be reused after {@code release} has been invoked; do not + * store them. *

    * This class is thread- and recursion-safe. * diff --git a/src/main/java/ru/windcorp/progressia/common/util/MultiLOC.java b/src/main/java/ru/windcorp/progressia/common/util/MultiLOC.java index 295244d..3d417ac 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/MultiLOC.java +++ b/src/main/java/ru/windcorp/progressia/common/util/MultiLOC.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.util.HashMap; diff --git a/src/main/java/ru/windcorp/progressia/common/util/Named.java b/src/main/java/ru/windcorp/progressia/common/util/Named.java index d9fc97a..8722ad4 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/Named.java +++ b/src/main/java/ru/windcorp/progressia/common/util/Named.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.util.Objects; diff --git a/src/main/java/ru/windcorp/progressia/common/util/SizeLimitedList.java b/src/main/java/ru/windcorp/progressia/common/util/SizeLimitedList.java index 2010ccb..9e86954 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/SizeLimitedList.java +++ b/src/main/java/ru/windcorp/progressia/common/util/SizeLimitedList.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.util.Collection; @@ -27,9 +27,7 @@ import com.google.common.collect.ForwardingList; public class SizeLimitedList extends ForwardingList { - private static final class RandomAccessSizeLimitedList - extends SizeLimitedList - implements RandomAccess { + private static final class RandomAccessSizeLimitedList extends SizeLimitedList implements RandomAccess { protected RandomAccessSizeLimitedList(List parent, int maxSize) { super(parent, maxSize); } @@ -76,9 +74,7 @@ public class SizeLimitedList extends ForwardingList { private void checkMaxSize() { if (size() >= maxSize) { - throw new UnsupportedOperationException( - "Maximum size " + maxSize + " reached" - ); + throw new UnsupportedOperationException("Maximum size " + maxSize + " reached"); } } diff --git a/src/main/java/ru/windcorp/progressia/common/util/StashingStack.java b/src/main/java/ru/windcorp/progressia/common/util/StashingStack.java index 394c79d..fcd4059 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/StashingStack.java +++ b/src/main/java/ru/windcorp/progressia/common/util/StashingStack.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.util.Arrays; @@ -45,9 +45,8 @@ public class StashingStack implements Iterable { /** * Stores all elements. Elements with indices - * [0; {@link #head}] - * are present in the stack, elements with indices - * ({@link #head}; contents.length] are stashed. + * [0; {@link #head}] are present in the stack, elements with + * indices ({@link #head}; contents.length] are stashed. */ private final Object[] contents; @@ -66,7 +65,8 @@ public class StashingStack implements Iterable { /** * Creates a new stack. Its stash is filled with {@code null}s. * - * @param capacity stack's capacity + * @param capacity + * stack's capacity */ public StashingStack(int capacity) { this((T[]) new Object[capacity], 0); @@ -75,7 +75,8 @@ public class StashingStack implements Iterable { /** * Creates a new stack with the supplied stash. * - * @param contents elements that are put in the stash initially. + * @param contents + * elements that are put in the stash initially. */ public StashingStack(T[] contents) { this(contents.clone(), 0); @@ -84,7 +85,8 @@ public class StashingStack implements Iterable { /** * Creates a new stack with the supplied stash. * - * @param contents elements that are put in the stash initially. + * @param contents + * elements that are put in the stash initially. */ public StashingStack(Iterable contents) { this(Iterables.toArray(contents, Object.class), 0); @@ -95,8 +97,10 @@ public class StashingStack implements Iterable { * {@code generator}. The generator's {@link Supplier#get() get()} method * will only be invoked {@code capacity} times from within this constructor. * - * @param capacity stack's capacity - * @param generator a supplier of objects for the stash + * @param capacity + * stack's capacity + * @param generator + * a supplier of objects for the stash */ public StashingStack(int capacity, Supplier generator) { this(capacity); @@ -160,7 +164,8 @@ public class StashingStack implements Iterable { * empty throws a {@link NoSuchElementException}. * * @return head of this stack - * @throws NoSuchElementException is the stack is empty + * @throws NoSuchElementException + * is the stack is empty * @see #peek() */ public T getHead() { @@ -170,8 +175,8 @@ public class StashingStack implements Iterable { } /** - * Returns and removes the head of this stack. If the stack is - * empty returns {@code null}. + * Returns and removes the head of this stack. If the stack is empty returns + * {@code null}. * * @return head of this stack or {@code null} * @see #removeHead() @@ -183,11 +188,12 @@ public class StashingStack implements Iterable { } /** - * Returns and removes the head of this stack. If the stack is - * empty throws a {@link NoSuchElementException}. + * Returns and removes the head of this stack. If the stack is empty throws + * a {@link NoSuchElementException}. * * @return head of this stack - * @throws NoSuchElementException is the stack is empty + * @throws NoSuchElementException + * is the stack is empty * @see #pop() */ public T removeHead() { @@ -216,7 +222,8 @@ public class StashingStack implements Iterable { * removed. If the stack is already full throws an * {@link IllegalStateException}. * - * @param newElement the element to push + * @param newElement + * the element to push * @return the new head */ public T push(T newElement) { @@ -233,17 +240,16 @@ public class StashingStack implements Iterable { * bottom of the stack. If the index is out of bounds, an * {@link IndexOutOfBoundsException} is thrown. * - * @param index index of the element to retrieve, - * [0; {@link #getSize()}) + * @param index + * index of the element to retrieve, + * [0; {@link #getSize()}) * @return the requested element - * @throws IndexOutOfBoundsException if the index is negative or greater - * than head + * @throws IndexOutOfBoundsException + * if the index is negative or greater than head */ public T get(int index) { if (index > head) { - throw new IndexOutOfBoundsException( - "Requested index " + index + " > head " + head - ); + throw new IndexOutOfBoundsException("Requested index " + index + " > head " + head); } return (T) contents[index]; diff --git a/src/main/java/ru/windcorp/progressia/common/util/TaskQueue.java b/src/main/java/ru/windcorp/progressia/common/util/TaskQueue.java index a081356..7010896 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/TaskQueue.java +++ b/src/main/java/ru/windcorp/progressia/common/util/TaskQueue.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.util.Collection; @@ -62,11 +62,7 @@ public class TaskQueue { private final Object waitAndInvokeMonitor = new Object(); @SuppressWarnings("unchecked") - public void waitAndInvoke( - ThrowingRunnable task - ) - throws InterruptedException, - E { + public void waitAndInvoke(ThrowingRunnable task) throws InterruptedException, E { if (runNow.getAsBoolean()) { task.run(); diff --git a/src/main/java/ru/windcorp/progressia/common/util/VectorUtil.java b/src/main/java/ru/windcorp/progressia/common/util/VectorUtil.java index 00ede3e..18cc6be 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/VectorUtil.java +++ b/src/main/java/ru/windcorp/progressia/common/util/VectorUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import java.util.function.Consumer; @@ -37,15 +37,7 @@ public class VectorUtil { X, Y, Z, W; } - public static void iterateCuboid( - int x0, - int y0, - int z0, - int x1, - int y1, - int z1, - Consumer action - ) { + public static void iterateCuboid(int x0, int y0, int z0, int x1, int y1, int z1, Consumer action) { Vec3i cursor = Vectors.grab3i(); for (int x = x0; x < x1; ++x) { @@ -60,23 +52,12 @@ public class VectorUtil { Vectors.release(cursor); } - public static void iterateCuboid( - Vec3i vMin, - Vec3i vMax, - Consumer action - ) { + public static void iterateCuboid(Vec3i vMin, Vec3i vMax, Consumer action) { iterateCuboid(vMin.x, vMin.y, vMin.z, vMax.x, vMax.y, vMax.z, action); } - public static void iterateCuboidAround( - int cx, - int cy, - int cz, - int dx, - int dy, - int dz, - Consumer action - ) { + public static void iterateCuboidAround(int cx, int cy, int cz, int dx, int dy, int dz, + Consumer action) { if (dx < 0) throw new IllegalArgumentException("dx " + dx + " is negative"); if (dy < 0) @@ -98,29 +79,15 @@ public class VectorUtil { iterateCuboid(cx - dx, cy - dy, cz - dz, cx + dx + 1, cy + dy + 1, cz + dz + 1, action); } - public static void iterateCuboidAround( - Vec3i center, - Vec3i diameters, - Consumer action - ) { + public static void iterateCuboidAround(Vec3i center, Vec3i diameters, Consumer action) { iterateCuboidAround(center.x, center.y, center.z, diameters.x, diameters.y, diameters.z, action); } - public static void iterateCuboidAround( - int cx, - int cy, - int cz, - int diameter, - Consumer action - ) { + public static void iterateCuboidAround(int cx, int cy, int cz, int diameter, Consumer action) { iterateCuboidAround(cx, cy, cz, diameter, diameter, diameter, action); } - public static void iterateCuboidAround( - Vec3i center, - int diameter, - Consumer action - ) { + public static void iterateCuboidAround(Vec3i center, int diameter, Consumer action) { iterateCuboidAround(center.x, center.y, center.z, diameter, action); } @@ -143,35 +110,14 @@ public class VectorUtil { inOut.set(vec4.x, vec4.y, vec4.z); } - public static Vec3 linearCombination( - Vec3 va, - float ka, - Vec3 vb, - float kb, - Vec3 output - ) { - output.set( - va.x * ka + vb.x * kb, - va.y * ka + vb.y * kb, - va.z * ka + vb.z * kb - ); + public static Vec3 linearCombination(Vec3 va, float ka, Vec3 vb, float kb, Vec3 output) { + output.set(va.x * ka + vb.x * kb, va.y * ka + vb.y * kb, va.z * ka + vb.z * kb); return output; } - public static Vec3 linearCombination( - Vec3 va, - float ka, - Vec3 vb, - float kb, - Vec3 vc, - float kc, - Vec3 output - ) { - output.set( - va.x * ka + vb.x * kb + vc.x * kc, - va.y * ka + vb.y * kb + vc.y * kc, - va.z * ka + vb.z * kb + vc.z * kc - ); + public static Vec3 linearCombination(Vec3 va, float ka, Vec3 vb, float kb, Vec3 vc, float kc, Vec3 output) { + output.set(va.x * ka + vb.x * kb + vc.x * kc, va.y * ka + vb.y * kb + vc.y * kc, + va.z * ka + vb.z * kb + vc.z * kc); return output; } diff --git a/src/main/java/ru/windcorp/progressia/common/util/Vectors.java b/src/main/java/ru/windcorp/progressia/common/util/Vectors.java index 7d99ea5..2cb4336 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/Vectors.java +++ b/src/main/java/ru/windcorp/progressia/common/util/Vectors.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util; import glm.vec._2.Vec2; @@ -40,8 +40,8 @@ import glm.vec._4.i.Vec4i; * } * * - * Provided objects may be reused after {@code release} has been invoked; - * do not store them. + * Provided objects may be reused after {@code release} has been invoked; do not + * store them. *

    * This class is thread- and recursion-safe. * diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/Analyzer.java b/src/main/java/ru/windcorp/progressia/common/util/crash/Analyzer.java index 3289c3d..e17f964 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/Analyzer.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/Analyzer.java @@ -15,16 +15,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash; /** * A crash report utility that performs analysis of a problem during crash * report generation and presents its conclusion to the user via the crash - * report. - * Unlike {@link ContextProvider}s, Analyzers are provided with the reported - * problem - * details. + * report. Unlike {@link ContextProvider}s, Analyzers are provided with the + * reported problem details. * * @see ContextProvider * @author serega404 @@ -32,22 +30,24 @@ package ru.windcorp.progressia.common.util.crash; public interface Analyzer { /** - * Provides a human-readable string describing this analyzer's conclusion - * on the presented problem, or returns {@code null} if no conclusion - * could be made. + * Provides a human-readable string describing this analyzer's conclusion on + * the presented problem, or returns {@code null} if no conclusion could be + * made. * - * @param throwable The reported throwable (may be {@code null}) - * @param messageFormat A {@linkplain java.util.Formatter#syntax format - * string} of a - * human-readable description of the problem - * @param args The arguments for the format string + * @param throwable + * The reported throwable (may be {@code null}) + * @param messageFormat + * A {@linkplain java.util.Formatter#syntax format string} of a + * human-readable description of the problem + * @param args + * The arguments for the format string * @return a conclusion or {@code null} */ String analyze(Throwable throwable, String messageFormat, Object... args); /** - * Returns this analyzer's human-readable name. - * It should be A String In Title Case With Spaces. + * Returns this analyzer's human-readable name. It should be A String In + * Title Case With Spaces. * * @return this analyzer's name */ diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/ContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/ContextProvider.java index 5b62663..8180e4a 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/ContextProvider.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/ContextProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash; import java.util.Map; @@ -33,23 +33,20 @@ public interface ContextProvider { /** * Provides human-readable description of the state of the game and the - * system. - * This information is {@link Map#put(Object, Object) put} into the provided - * map - * as key-value pairs. Keys are the characteristic being described, such as - * "OS Name", - * and should be Strings In Title Case With Spaces. - * If this provider cannot provide any information at this moment, the map - * is not - * modified. + * system. This information is {@link Map#put(Object, Object) put} into the + * provided map as key-value pairs. Keys are the characteristic being + * described, such as "OS Name", and should be Strings In Title Case With + * Spaces. If this provider cannot provide any information at this moment, + * the map is not modified. * - * @param output the map to append output to + * @param output + * the map to append output to */ void provideContext(Map output); /** - * Returns this provider's human-readable name. - * It should be A String In Title Case With Spaces. + * Returns this provider's human-readable name. It should be A String In + * Title Case With Spaces. * * @return this provider's name */ diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/CrashReports.java b/src/main/java/ru/windcorp/progressia/common/util/crash/CrashReports.java index ab0ec3e..3b634cf 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/CrashReports.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/CrashReports.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash; import org.apache.logging.log4j.LogManager; @@ -38,9 +38,8 @@ import java.util.*; /** * A utility for reporting critical problems, gathering system context and - * terminating the application consequently (crashing). - * Do not hesitate to use {@link #report(Throwable, String, Object...)} at every - * other line. + * terminating the application consequently (crashing). Do not hesitate to use + * {@link #report(Throwable, String, Object...)} at every other line. * * @author serega404 */ @@ -56,8 +55,8 @@ public class CrashReports { /** * Creates a {@link ReportedException} that describes the provided problem - * so the program can crash later. - * This method is intended to be used like so: + * so the program can crash later. This method is intended to be used like + * so: * *

     	 * try {
    @@ -68,26 +67,24 @@ public class CrashReports {
     	 * 
    *

    * Such usage ensures that the report will be dealt with at the top of the - * call stack - * (at least in methods that have a properly set up + * call stack (at least in methods that have a properly set up * {@linkplain #crash(Throwable, String, Object...) crash handler}). Not - * throwing the returned - * exception is pointless; using this in a thread without a crash handler - * will not produce a crash. + * throwing the returned exception is pointless; using this in a thread + * without a crash handler will not produce a crash. *

    * Avoid inserting variable information into {@code messageFormat} directly; - * use - * {@linkplain Formatter#summary format string} syntax and {@code args}. - * Different Strings - * in {@code messageFormat} may be interpreted as unrelated problems by - * {@linkplain Analyzer crash analyzers}. + * use {@linkplain Formatter#summary format string} syntax and {@code args}. + * Different Strings in {@code messageFormat} may be interpreted as + * unrelated problems by {@linkplain Analyzer crash analyzers}. * - * @param throwable a {@link Throwable} that caused the problem, if any; - * {@code null} otherwise - * @param messageFormat a human-readable description of the problem - * displayed in the crash report - * @param args an array of arguments for formatting - * {@code messageFormat} + * @param throwable + * a {@link Throwable} that caused the problem, if any; + * {@code null} otherwise + * @param messageFormat + * a human-readable description of the problem displayed in the + * crash report + * @param args + * an array of arguments for formatting {@code messageFormat} * @return an exception containing the provided information that must be * thrown */ @@ -102,32 +99,28 @@ public class CrashReports { * Crashes the program due to the supplied problem. *

    * Use {@link #report(Throwable, String, Object...)} unless you are - * creating a catch-all handler for a - * thread. + * creating a catch-all handler for a thread. *

    * This method recovers information about the problem by casting - * {@code throwable} to {@link ReportedException}, - * or, failing that, uses the provided arguments as the information instead. - * It then constructs a full crash - * report, exports it and terminates the program by invoking + * {@code throwable} to {@link ReportedException}, or, failing that, uses + * the provided arguments as the information instead. It then constructs a + * full crash report, exports it and terminates the program by invoking * {@link System#exit(int)}. *

    * Such behavior can be dangerous or lead to unwanted consequences in the - * middle of the call stack, so it is - * necessary to invoke this method as high on the call stack as possible, - * usually in a {@code catch} clause - * of a {@code try} statement enveloping the thread's main method(s). + * middle of the call stack, so it is necessary to invoke this method as + * high on the call stack as possible, usually in a {@code catch} clause of + * a {@code try} statement enveloping the thread's main method(s). * - * @param throwable a {@link ReportedException} or another - * {@link Throwable} that caused the problem, if any; - * {@code null} otherwise - * @param messageFormat a human-readable description of the problem used - * when {@code throwable} is not a - * {@link ReportedException}. See - * {@link #report(Throwable, String, Object...)} for - * details. - * @param args an array of arguments for formatting - * {@code messageFormat} + * @param throwable + * a {@link ReportedException} or another {@link Throwable} that + * caused the problem, if any; {@code null} otherwise + * @param messageFormat + * a human-readable description of the problem used when + * {@code throwable} is not a {@link ReportedException}. See + * {@link #report(Throwable, String, Object...)} for details. + * @param args + * an array of arguments for formatting {@code messageFormat} * @return {@code null}, although this method never returns normally. * Provided for convenience. */ @@ -229,12 +222,8 @@ public class CrashReports { } } - private static boolean appendAnalyzers( - StringBuilder output, - Throwable throwable, - String messageFormat, - Object[] args - ) { + private static boolean appendAnalyzers(StringBuilder output, Throwable throwable, String messageFormat, + Object[] args) { boolean analyzerResponsesExist = false; // Do a local copy to avoid deadlocks -OLEGSHA @@ -334,10 +323,8 @@ public class CrashReports { Files.createDirectory(CRASH_REPORTS_PATH); createFileForCrashReport(output, CRASH_REPORTS_PATH.toString() + "/latest.log"); - createFileForCrashReport( - output, - CRASH_REPORTS_PATH.toString() + "/crash-" + dateFormat.format(date) + ".log" - ); + createFileForCrashReport(output, + CRASH_REPORTS_PATH.toString() + "/crash-" + dateFormat.format(date) + ".log"); } catch (Throwable t) { // Crash Report not created } @@ -359,7 +346,8 @@ public class CrashReports { * Registers the provided {@link ContextProvider} so it is consulted in the * case of a crash. * - * @param provider the provider to register + * @param provider + * the provider to register */ public static void registerProvider(ContextProvider provider) { PROVIDERS.add(provider); @@ -369,7 +357,8 @@ public class CrashReports { * Registers the provided {@link Analyzer} so it is consulted in the case of * a crash. * - * @param analyzer the analyzer to register + * @param analyzer + * the analyzer to register */ public static void registerAnalyzer(Analyzer analyzer) { ANALYZERS.add(analyzer); @@ -377,11 +366,10 @@ public class CrashReports { /** * A wrapper used by {@link CrashReports} to transfer problem details from - * the place of - * occurrence to the handler at the top of the stack. Rethrow if caught - * (unless using {@link CrashReports#report(Throwable, String, Object...)}, - * which does - * so automatically). + * the place of occurrence to the handler at the top of the stack. Rethrow + * if caught (unless using + * {@link CrashReports#report(Throwable, String, Object...)}, which does so + * automatically). * * @author serega404 */ @@ -395,11 +383,13 @@ public class CrashReports { /** * Constructs a {@link ReportedException}. * - * @param throwable the reported {@link Throwable} or {@code null} - * @param messageFormat the reported message format. - * This is not the message of the constructed - * Exception. - * @param args the reported message format arguments + * @param throwable + * the reported {@link Throwable} or {@code null} + * @param messageFormat + * the reported message format. This is not the message + * of the constructed Exception. + * @param args + * the reported message format arguments */ public ReportedException(Throwable throwable, String messageFormat, Object... args) { super(throwable); diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/ReportingEventBus.java b/src/main/java/ru/windcorp/progressia/common/util/crash/ReportingEventBus.java index 141efa9..87bb0f1 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/ReportingEventBus.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/ReportingEventBus.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash; import com.google.common.eventbus.EventBus; @@ -28,14 +28,11 @@ public class ReportingEventBus { } public static EventBus create(String identifier) { - return GuavaEventBusHijacker.newEventBus( - identifier, - (throwable, context) -> { - // Makes sense to append identifier to messageFormat because - // different EventBuses are completely unrelated - throw CrashReports.crash(throwable, "Unexpected exception in EventBus " + identifier); - } - ); + return GuavaEventBusHijacker.newEventBus(identifier, (throwable, context) -> { + // Makes sense to append identifier to messageFormat because + // different EventBuses are completely unrelated + throw CrashReports.crash(throwable, "Unexpected exception in EventBus " + identifier); + }); } } diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/analyzers/OutOfMemoryAnalyzer.java b/src/main/java/ru/windcorp/progressia/common/util/crash/analyzers/OutOfMemoryAnalyzer.java index c07152f..647e9b3 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/analyzers/OutOfMemoryAnalyzer.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/analyzers/OutOfMemoryAnalyzer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash.analyzers; import ru.windcorp.progressia.common.util.crash.Analyzer; diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/ArgsContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/ArgsContextProvider.java index 6c16902..55786c5 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/ArgsContextProvider.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/ArgsContextProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash.providers; import ru.windcorp.progressia.ProgressiaLauncher; diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/JavaVersionContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/JavaVersionContextProvider.java index b8f4358..184a916 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/JavaVersionContextProvider.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/JavaVersionContextProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash.providers; import ru.windcorp.progressia.common.util.crash.ContextProvider; diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/LanguageContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/LanguageContextProvider.java index ca9d387..8de2668 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/LanguageContextProvider.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/LanguageContextProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash.providers; import ru.windcorp.progressia.client.localization.Localizer; diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/OSContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/OSContextProvider.java index 7fd4610..56752fd 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/OSContextProvider.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/OSContextProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash.providers; import ru.windcorp.progressia.common.util.crash.ContextProvider; diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/OpenALContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/OpenALContextProvider.java index ad31bba..77626b3 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/OpenALContextProvider.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/OpenALContextProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash.providers; import ru.windcorp.progressia.client.audio.AudioManager; diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/RAMContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/RAMContextProvider.java index 9c60921..47e9dd5 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/RAMContextProvider.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/RAMContextProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.crash.providers; import ru.windcorp.progressia.common.util.crash.ContextProvider; @@ -29,11 +29,8 @@ public class RAMContextProvider implements ContextProvider { output.put("Max Memory", Runtime.getRuntime().maxMemory() / 1024 / 1024 + " MB"); output.put("Total Memory", Runtime.getRuntime().totalMemory() / 1024 / 1024 + " MB"); output.put("Free Memory", Runtime.getRuntime().freeMemory() / 1024 / 1024 + " MB"); - output.put( - "Used Memory", - (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 - + " MB" - ); + output.put("Used Memory", + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + " MB"); } @Override diff --git a/src/main/java/ru/windcorp/progressia/common/util/dynstr/DoubleFlusher.java b/src/main/java/ru/windcorp/progressia/common/util/dynstr/DoubleFlusher.java index 6068669..ab21b4b 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/dynstr/DoubleFlusher.java +++ b/src/main/java/ru/windcorp/progressia/common/util/dynstr/DoubleFlusher.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.dynstr; import gnu.trove.list.TCharList; diff --git a/src/main/java/ru/windcorp/progressia/common/util/dynstr/DynamicString.java b/src/main/java/ru/windcorp/progressia/common/util/dynstr/DynamicString.java index 8376a3d..89892c1 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/dynstr/DynamicString.java +++ b/src/main/java/ru/windcorp/progressia/common/util/dynstr/DynamicString.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.dynstr; import java.util.function.Supplier; @@ -45,8 +45,8 @@ public final class DynamicString implements CharSequence { } /** - * Causes the contents of this string to be reevaluated. - * This is not currently thread-safe, take caution. + * Causes the contents of this string to be reevaluated. This is not + * currently thread-safe, take caution. */ public void update() { chars.clear(); diff --git a/src/main/java/ru/windcorp/progressia/common/util/dynstr/DynamicStrings.java b/src/main/java/ru/windcorp/progressia/common/util/dynstr/DynamicStrings.java index 030cd9d..0b5745e 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/dynstr/DynamicStrings.java +++ b/src/main/java/ru/windcorp/progressia/common/util/dynstr/DynamicStrings.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.dynstr; import java.util.ArrayList; diff --git a/src/main/java/ru/windcorp/progressia/common/util/dynstr/FloatFlusher.java b/src/main/java/ru/windcorp/progressia/common/util/dynstr/FloatFlusher.java index 0b245ee..26a727e 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/dynstr/FloatFlusher.java +++ b/src/main/java/ru/windcorp/progressia/common/util/dynstr/FloatFlusher.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.dynstr; import gnu.trove.list.TCharList; diff --git a/src/main/java/ru/windcorp/progressia/common/util/dynstr/IntFlusher.java b/src/main/java/ru/windcorp/progressia/common/util/dynstr/IntFlusher.java index 9924f81..937c9fa 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/dynstr/IntFlusher.java +++ b/src/main/java/ru/windcorp/progressia/common/util/dynstr/IntFlusher.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.dynstr; import gnu.trove.list.TCharList; @@ -61,211 +61,19 @@ class IntFlusher { /* * Copied from OpenJDK's Integer.DigitTens and Integer.DigitOnes */ - private static final char[] DIGIT_TENS = { - '0', - '0', - '0', - '0', - '0', - '0', - '0', - '0', - '0', - '0', - '1', - '1', - '1', - '1', - '1', - '1', - '1', - '1', - '1', - '1', - '2', - '2', - '2', - '2', - '2', - '2', - '2', - '2', - '2', - '2', - '3', - '3', - '3', - '3', - '3', - '3', - '3', - '3', - '3', - '3', - '4', - '4', - '4', - '4', - '4', - '4', - '4', - '4', - '4', - '4', - '5', - '5', - '5', - '5', - '5', - '5', - '5', - '5', - '5', - '5', - '6', - '6', - '6', - '6', - '6', - '6', - '6', - '6', - '6', - '6', - '7', - '7', - '7', - '7', - '7', - '7', - '7', - '7', - '7', - '7', - '8', - '8', - '8', - '8', - '8', - '8', - '8', - '8', - '8', - '8', - '9', - '9', - '9', - '9', - '9', - '9', - '9', - '9', - '9', - '9', - }; + private static final char[] DIGIT_TENS = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', + '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', + '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', + '5', '5', '5', '5', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '7', '7', + '7', '7', '7', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9', '9', + '9', '9', }; - private static final char[] DIGIT_ONES = { - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - }; + private static final char[] DIGIT_ONES = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', + '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', + '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', }; /* * Adapted from OpenJDK's Integer.getChars(int, int, byte[]) diff --git a/src/main/java/ru/windcorp/progressia/common/util/namespaces/IllegalIdException.java b/src/main/java/ru/windcorp/progressia/common/util/namespaces/IllegalIdException.java index d896bac..ba27e4a 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/namespaces/IllegalIdException.java +++ b/src/main/java/ru/windcorp/progressia/common/util/namespaces/IllegalIdException.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.namespaces; public class IllegalIdException extends RuntimeException { @@ -26,12 +26,8 @@ public class IllegalIdException extends RuntimeException { super(); } - protected IllegalIdException( - String message, - Throwable cause, - boolean enableSuppression, - boolean writableStackTrace - ) { + protected IllegalIdException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/src/main/java/ru/windcorp/progressia/common/util/namespaces/Namespaced.java b/src/main/java/ru/windcorp/progressia/common/util/namespaces/Namespaced.java index 2d87007..557804b 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/namespaces/Namespaced.java +++ b/src/main/java/ru/windcorp/progressia/common/util/namespaces/Namespaced.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.namespaces; public abstract class Namespaced { diff --git a/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedFactoryRegistry.java b/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedFactoryRegistry.java index 2a94593..9f419fd 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedFactoryRegistry.java +++ b/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedFactoryRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.namespaces; import java.util.Collection; @@ -28,7 +28,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class NamespacedFactoryRegistry - implements Map> { + implements Map> { @FunctionalInterface public static interface Factory { @@ -86,8 +86,7 @@ public class NamespacedFactoryRegistry E result = factory.build(id); if (!result.getId().equals(id)) { throw new IllegalStateException( - "Requested ID " + id + " but factory " + factory + " returned an object with ID " + result.getId() - ); + "Requested ID " + id + " but factory " + factory + " returned an object with ID " + result.getId()); } return result; } diff --git a/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedInstanceRegistry.java b/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedInstanceRegistry.java index ce1f3cf..e748fe7 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedInstanceRegistry.java +++ b/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedInstanceRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.namespaces; import java.util.Collection; @@ -29,8 +29,7 @@ import org.apache.logging.log4j.Logger; import com.google.errorprone.annotations.DoNotCall; -public class NamespacedInstanceRegistry - implements Map { +public class NamespacedInstanceRegistry implements Map { private final Map backingMap = Collections.synchronizedMap(new HashMap<>()); @@ -87,9 +86,7 @@ public class NamespacedInstanceRegistry @DoNotCall @Deprecated public E put(String key, E value) { - throw new UnsupportedOperationException( - "Use NamespacedInstanceRegistry.register(E)" - ); + throw new UnsupportedOperationException("Use NamespacedInstanceRegistry.register(E)"); } @Override @@ -104,9 +101,7 @@ public class NamespacedInstanceRegistry @DoNotCall @Deprecated public void putAll(Map m) { - throw new UnsupportedOperationException( - "Use NamespacedInstanceRegistry.registerAll(Collection)" - ); + throw new UnsupportedOperationException("Use NamespacedInstanceRegistry.registerAll(Collection)"); } @Override diff --git a/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedUtil.java b/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedUtil.java index b969b8e..0796c50 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedUtil.java +++ b/src/main/java/ru/windcorp/progressia/common/util/namespaces/NamespacedUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.util.namespaces; import java.util.Objects; @@ -38,8 +38,8 @@ public class NamespacedUtil { public static final int MIN_NAME_LENGTH = MIN_PART_LENGTH; /* - * This is the definition of the accepted pattern, but the value of - * these constants is not actually consulted in the check* methods. + * This is the definition of the accepted pattern, but the value of these + * constants is not actually consulted in the check* methods. */ private static final String PART_CORE_REGEX = "[A-Z][a-zA-Z0-9]{2," + (MAX_PART_LENGTH - 1) + "}"; private static final String PART_REGEX = "^" + PART_CORE_REGEX + "$"; @@ -75,10 +75,8 @@ public class NamespacedUtil { if (areSeparatorsInvalid) { int separators = StringUtil.count(id, SEPARATOR); throw new IllegalIdException( - "ID \"" + id + "\" is invalid. " - + (separators == 0 ? "No " : "Too many (" + separators + ") ") - + "separators '" + SEPARATOR + "' found, exactly one required" - ); + "ID \"" + id + "\" is invalid. " + (separators == 0 ? "No " : "Too many (" + separators + ") ") + + "separators '" + SEPARATOR + "' found, exactly one required"); } checkPart(id, 0, firstSeparator, "namespace"); @@ -89,32 +87,20 @@ public class NamespacedUtil { Objects.requireNonNull(data, nameForErrors); if (length > MAX_PART_LENGTH) { - throw new IllegalIdException( - nameForErrors + " \"" + data.substring(offset, offset + length) + "\" is too long. " - + "Expected at most " + MAX_PART_LENGTH - + " characters" - ); + throw new IllegalIdException(nameForErrors + " \"" + data.substring(offset, offset + length) + + "\" is too long. " + "Expected at most " + MAX_PART_LENGTH + " characters"); } else if (length < MIN_PART_LENGTH) { - throw new IllegalIdException( - nameForErrors + " \"" + data.substring(offset, offset + length) + "\" is too short. " - + "Expected at lest " + MIN_PART_LENGTH - + " characters" - ); + throw new IllegalIdException(nameForErrors + " \"" + data.substring(offset, offset + length) + + "\" is too short. " + "Expected at lest " + MIN_PART_LENGTH + " characters"); } // Don't actually use *_REGEX for speed for (int i = 0; i < length; ++i) { char c = data.charAt(i + offset); - if ( - !((c >= 'A' && c <= 'Z') || - (i != 0 && c >= 'a' && c <= 'z') || - (i != 0 && c >= '0' && c <= '9')) - ) { - throw new IllegalIdException( - nameForErrors + " \"" + data.substring(offset, offset + length) + "\" is invalid. " - + "Allowed is: " + PART_REGEX - ); + if (!((c >= 'A' && c <= 'Z') || (i != 0 && c >= 'a' && c <= 'z') || (i != 0 && c >= '0' && c <= '9'))) { + throw new IllegalIdException(nameForErrors + " \"" + data.substring(offset, offset + length) + + "\" is invalid. " + "Allowed is: " + PART_REGEX); } } } diff --git a/src/main/java/ru/windcorp/progressia/common/world/BlockRay.java b/src/main/java/ru/windcorp/progressia/common/world/BlockRay.java index 4d5f1f9..e94ec08 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/BlockRay.java +++ b/src/main/java/ru/windcorp/progressia/common/world/BlockRay.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import glm.vec._3.Vec3; @@ -159,7 +159,8 @@ public class BlockRay { /** * Returns a smallest integer a such that a > c. * - * @param c the number to compute strict ceiling of + * @param c + * the number to compute strict ceiling of * @return the strict ceiling of c */ private static float strictCeil(float c) { @@ -169,7 +170,8 @@ public class BlockRay { /** * Returns a largest integer a such that a < c. * - * @param c the number to compute strict ceiling of + * @param c + * the number to compute strict ceiling of * @return the strict ceiling of c */ private static float strictFloor(float c) { diff --git a/src/main/java/ru/windcorp/progressia/common/world/ChunkData.java b/src/main/java/ru/windcorp/progressia/common/world/ChunkData.java index 252429c..9a49545 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/ChunkData.java +++ b/src/main/java/ru/windcorp/progressia/common/world/ChunkData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import static ru.windcorp.progressia.common.world.block.BlockFace.*; @@ -38,8 +38,7 @@ import ru.windcorp.progressia.common.world.tile.TileDataStack; import ru.windcorp.progressia.common.world.tile.TileReference; import ru.windcorp.progressia.common.world.tile.TileStackIsFullException; -public class ChunkData - implements GenericChunk { +public class ChunkData implements GenericChunk { public static final int BLOCKS_PER_CHUNK = Coordinates.CHUNK_SIZE; @@ -48,8 +47,8 @@ public class ChunkData private final BlockData[] blocks = new BlockData[BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK]; - private final TileDataStack[] tiles = new TileDataStack[BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK * - BLOCK_FACE_COUNT]; + private final TileDataStack[] tiles = new TileDataStack[BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK + * BLOCK_FACE_COUNT]; private Object generationHint = null; @@ -90,14 +89,9 @@ public class ChunkData /** * Internal use only. Modify a list returned by * {@link #getTiles(Vec3i, BlockFace)} or - * {@link #getTilesOrNull(Vec3i, BlockFace)} - * to change tiles. + * {@link #getTilesOrNull(Vec3i, BlockFace)} to change tiles. */ - protected void setTiles( - Vec3i blockInChunk, - BlockFace face, - TileDataStack tiles - ) { + protected void setTiles(Vec3i blockInChunk, BlockFace face, TileDataStack tiles) { this.tiles[getTileIndex(blockInChunk, face)] = tiles; } @@ -137,51 +131,34 @@ public class ChunkData private static int getBlockIndex(Vec3i posInChunk) { checkLocalCoordinates(posInChunk); - return posInChunk.z * BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK + - posInChunk.y * BLOCKS_PER_CHUNK + - posInChunk.x; + return posInChunk.z * BLOCKS_PER_CHUNK * BLOCKS_PER_CHUNK + posInChunk.y * BLOCKS_PER_CHUNK + posInChunk.x; } private static int getTileIndex(Vec3i posInChunk, BlockFace face) { - return getBlockIndex(posInChunk) * BLOCK_FACE_COUNT + - face.getId(); + return getBlockIndex(posInChunk) * BLOCK_FACE_COUNT + face.getId(); } private static void checkLocalCoordinates(Vec3i posInChunk) { if (!isInBounds(posInChunk)) { throw new IllegalCoordinatesException( - "Coordinates " + str(posInChunk) + " " - + "are not legal chunk coordinates" - ); + "Coordinates " + str(posInChunk) + " " + "are not legal chunk coordinates"); } } public static boolean isInBounds(Vec3i posInChunk) { - return posInChunk.x >= 0 && posInChunk.x < BLOCKS_PER_CHUNK && - posInChunk.y >= 0 && posInChunk.y < BLOCKS_PER_CHUNK && - posInChunk.z >= 0 && posInChunk.z < BLOCKS_PER_CHUNK; + return posInChunk.x >= 0 && posInChunk.x < BLOCKS_PER_CHUNK && posInChunk.y >= 0 + && posInChunk.y < BLOCKS_PER_CHUNK && posInChunk.z >= 0 && posInChunk.z < BLOCKS_PER_CHUNK; } public boolean isBorder(Vec3i blockInChunk, BlockFace face) { final int min = 0, max = BLOCKS_PER_CHUNK - 1; - return (blockInChunk.x == min && face == SOUTH) || - (blockInChunk.x == max && face == NORTH) || - (blockInChunk.y == min && face == EAST) || - (blockInChunk.y == max && face == WEST) || - (blockInChunk.z == min && face == BOTTOM) || - (blockInChunk.z == max && face == TOP); + return (blockInChunk.x == min && face == SOUTH) || (blockInChunk.x == max && face == NORTH) + || (blockInChunk.y == min && face == EAST) || (blockInChunk.y == max && face == WEST) + || (blockInChunk.z == min && face == BOTTOM) || (blockInChunk.z == max && face == TOP); } public void forEachBlock(Consumer action) { - VectorUtil.iterateCuboid( - 0, - 0, - 0, - BLOCKS_PER_CHUNK, - BLOCKS_PER_CHUNK, - BLOCKS_PER_CHUNK, - action - ); + VectorUtil.iterateCuboid(0, 0, 0, BLOCKS_PER_CHUNK, BLOCKS_PER_CHUNK, BLOCKS_PER_CHUNK, action); } public void forEachTileStack(Consumer action) { @@ -198,8 +175,9 @@ public class ChunkData /** * Iterates over all tiles in this chunk. * - * @param action the action to perform. {@code TileLocation} refers to each - * tile using its primary block + * @param action + * the action to perform. {@code TileLocation} refers to each + * tile using its primary block */ public void forEachTile(BiConsumer action) { forEachTileStack(stack -> stack.forEach(tileData -> action.accept(stack, tileData))); @@ -243,10 +221,8 @@ public class ChunkData /** * Implementation of {@link TileDataStack} used internally by - * {@link ChunkData} to - * actually store the tiles. This is basically an array wrapper with - * reporting - * capabilities. + * {@link ChunkData} to actually store the tiles. This is basically an array + * wrapper with reporting capabilities. * * @author javapony */ @@ -412,8 +388,7 @@ public class ChunkData return; if (assignedTag == -1) { throw new IllegalArgumentException( - "Tag " + tag + " already used by tile at index " + getIndexByTag(tag) - ); + "Tag " + tag + " already used by tile at index " + getIndexByTag(tag)); } indicesByTag[tagsByIndex[size() - 1]] = -1; @@ -498,8 +473,7 @@ public class ChunkData if (index >= TILES_PER_FACE) throw new TileStackIsFullException( - "Index " + index + " is out of bounds: maximum tile stack size is " + TILES_PER_FACE - ); + "Index " + index + " is out of bounds: maximum tile stack size is " + TILES_PER_FACE); } private void report(TileData previous, TileData current) { diff --git a/src/main/java/ru/windcorp/progressia/common/world/ChunkDataListener.java b/src/main/java/ru/windcorp/progressia/common/world/ChunkDataListener.java index 72008c4..f9a7fb2 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/ChunkDataListener.java +++ b/src/main/java/ru/windcorp/progressia/common/world/ChunkDataListener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import glm.vec._3.i.Vec3i; @@ -26,49 +26,50 @@ import ru.windcorp.progressia.common.world.tile.TileData; public interface ChunkDataListener { /** - * Invoked after a block has changed in a chunk. - * This is not triggered when a change is caused by chunk loading or - * unloading. + * Invoked after a block has changed in a chunk. This is not triggered when + * a change is caused by chunk loading or unloading. * - * @param chunk the chunk that has changed - * @param blockInChunk the {@linkplain Coordinates#blockInChunk chunk - * coordinates} of the change - * @param previous the previous occupant of {@code blockInChunk} - * @param current the current (new) occupant of {@code blockInChunk} + * @param chunk + * the chunk that has changed + * @param blockInChunk + * the {@linkplain Coordinates#blockInChunk chunk coordinates} of + * the change + * @param previous + * the previous occupant of {@code blockInChunk} + * @param current + * the current (new) occupant of {@code blockInChunk} */ default void onChunkBlockChanged(ChunkData chunk, Vec3i blockInChunk, BlockData previous, BlockData current) { } /** - * Invoked after a tile has been added or removed from a chunk. - * This is not triggered when a change is caused by chunk loading or - * unloading. + * Invoked after a tile has been added or removed from a chunk. This is not + * triggered when a change is caused by chunk loading or unloading. * - * @param chunk the chunk that has changed - * @param blockInChunk the {@linkplain Coordinates#blockInChunk chunk - * coordinates} of the change - * @param face the face that the changed tile belongs or belonged to - * @param tile the tile that has been added or removed - * @param wasAdded {@code true} iff the tile has been added, - * {@code false} iff the tile has been removed + * @param chunk + * the chunk that has changed + * @param blockInChunk + * the {@linkplain Coordinates#blockInChunk chunk coordinates} of + * the change + * @param face + * the face that the changed tile belongs or belonged to + * @param tile + * the tile that has been added or removed + * @param wasAdded + * {@code true} iff the tile has been added, {@code false} iff + * the tile has been removed */ - default void onChunkTilesChanged( - ChunkData chunk, - Vec3i blockInChunk, - BlockFace face, - TileData tile, - boolean wasAdded - ) { + default void onChunkTilesChanged(ChunkData chunk, Vec3i blockInChunk, BlockFace face, TileData tile, + boolean wasAdded) { } /** * Invoked whenever a chunk changes, loads or unloads. If some other method - * in this - * {@code ChunkDataListener} are to be invoked, e.g. is the change was - * caused by a - * block being removed, this method is called last. + * in this {@code ChunkDataListener} are to be invoked, e.g. is the change + * was caused by a block being removed, this method is called last. * - * @param chunk the chunk that has changed + * @param chunk + * the chunk that has changed */ default void onChunkChanged(ChunkData chunk) { } @@ -76,7 +77,8 @@ public interface ChunkDataListener { /** * Invoked whenever a chunk has been loaded. * - * @param chunk the chunk that has loaded + * @param chunk + * the chunk that has loaded */ default void onChunkLoaded(ChunkData chunk) { } @@ -84,7 +86,8 @@ public interface ChunkDataListener { /** * Invoked whenever a chunk is about to be unloaded. * - * @param chunk the chunk that is going to be loaded + * @param chunk + * the chunk that is going to be loaded */ default void beforeChunkUnloaded(ChunkData chunk) { } diff --git a/src/main/java/ru/windcorp/progressia/common/world/ChunkDataListeners.java b/src/main/java/ru/windcorp/progressia/common/world/ChunkDataListeners.java index b39437c..fdae0ab 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/ChunkDataListeners.java +++ b/src/main/java/ru/windcorp/progressia/common/world/ChunkDataListeners.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/common/world/Coordinates.java b/src/main/java/ru/windcorp/progressia/common/world/Coordinates.java index 55f2076..bc26afe 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/Coordinates.java +++ b/src/main/java/ru/windcorp/progressia/common/world/Coordinates.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import static ru.windcorp.progressia.common.world.ChunkData.BLOCKS_PER_CHUNK; @@ -29,20 +29,17 @@ import glm.vec._3.i.Vec3i; * Three types of coordinates are used in Progressia: *

      *
    • World coordinates, in code referred to as - * {@code blockInWorld} - - * coordinates relative to world origin. Every block in the world has unique - * world coordinates.
    • + * {@code blockInWorld} - coordinates relative to world origin. Every block in + * the world has unique world coordinates. *
    • Chunk coordinates, in code referred to as - * {@code blockInChunk} - - * coordinates relative some chunk's origin. Every block in the chunk has unique - * chunk coordinates, but blocks in different chunks may have identical chunk - * coordinates. These coordinates are only useful in combination with a chunk - * reference. Chunk coordinates are always + * {@code blockInChunk} - coordinates relative some chunk's origin. Every block + * in the chunk has unique chunk coordinates, but blocks in different chunks may + * have identical chunk coordinates. These coordinates are only useful in + * combination with a chunk reference. Chunk coordinates are always * [0; {@link #BLOCKS_PER_CHUNK}).
    • *
    • Coordinates of chunk, in code referred to as - * {@code chunk} - - * chunk coordinates relative to world origin. Every chunk in the world has - * unique coordinates of chunk.
    • + * {@code chunk} - chunk coordinates relative to world origin. Every chunk in + * the world has unique coordinates of chunk. *
    */ public class Coordinates { @@ -55,7 +52,8 @@ public class Coordinates { * Computes the coordinate of the chunk that the block specified by the * provided world coordinate belongs to. * - * @param blockInWorld world coordinate of the block + * @param blockInWorld + * world coordinate of the block * @return the corresponding coordinate of the chunk containing the block * @see #convertInWorldToChunk(Vec3i, Vec3i) */ @@ -67,15 +65,14 @@ public class Coordinates { * Computes the coordinates of the chunk that the block specified by the * provided world coordinates belongs to. * - * @param blockInWorld world coordinates of the block - * @param output a {@link Vec3i} to store the result in + * @param blockInWorld + * world coordinates of the block + * @param output + * a {@link Vec3i} to store the result in * @return {@code output} * @see #convertInWorldToChunk(int) */ - public static Vec3i convertInWorldToChunk( - Vec3i blockInWorld, - Vec3i output - ) { + public static Vec3i convertInWorldToChunk(Vec3i blockInWorld, Vec3i output) { if (output == null) output = new Vec3i(); @@ -87,10 +84,11 @@ public class Coordinates { } /** - * Computes the chunk coordinate that the block specified by the - * provided world coordinate has in its chunk. + * Computes the chunk coordinate that the block specified by the provided + * world coordinate has in its chunk. * - * @param blockInWorld world coordinate of the block + * @param blockInWorld + * world coordinate of the block * @return the corresponding chunk coordinate of the block * @see #convertInWorldToInChunk(Vec3i, Vec3i) */ @@ -99,18 +97,17 @@ public class Coordinates { } /** - * Computes the chunk coordinates that the block specified by the - * provided world coordinates has in its chunk. + * Computes the chunk coordinates that the block specified by the provided + * world coordinates has in its chunk. * - * @param blockInWorld world coordinates of the block - * @param output a {@link Vec3i} to store the result in + * @param blockInWorld + * world coordinates of the block + * @param output + * a {@link Vec3i} to store the result in * @return {@code output} * @see #convertInWorldToInChunk(int) */ - public static Vec3i convertInWorldToInChunk( - Vec3i blockInWorld, - Vec3i output - ) { + public static Vec3i convertInWorldToInChunk(Vec3i blockInWorld, Vec3i output) { if (output == null) output = new Vec3i(); @@ -125,8 +122,10 @@ public class Coordinates { * Computes the world coordinate of the block specified by its chunk * coordinate and the coordinate of its chunk. * - * @param chunk coordinate of chunk - * @param blockInChunk chunk coordinate of block + * @param chunk + * coordinate of chunk + * @param blockInChunk + * chunk coordinate of block * @return corresponding world coordinate * @see #getInWorld(int, int) */ @@ -138,17 +137,16 @@ public class Coordinates { * Computes the world coordinates of the block specified by its chunk * coordinates and the coordinates of its chunk. * - * @param chunk coordinate of chunk - * @param blockInChunk chunk coordinate of block - * @param output a {@link Vec3i} to store the result in + * @param chunk + * coordinate of chunk + * @param blockInChunk + * chunk coordinate of block + * @param output + * a {@link Vec3i} to store the result in * @return {@code output} * @see #getInWorld(int) */ - public static Vec3i getInWorld( - Vec3i chunk, - Vec3i blockInChunk, - Vec3i output - ) { + public static Vec3i getInWorld(Vec3i chunk, Vec3i blockInChunk, Vec3i output) { if (output == null) output = new Vec3i(); @@ -158,7 +156,7 @@ public class Coordinates { return output; } - + public static boolean isOnChunkBorder(int blockInChunk) { return blockInChunk == 0 || blockInChunk == BLOCKS_PER_CHUNK - 1; } diff --git a/src/main/java/ru/windcorp/progressia/common/world/DecodingException.java b/src/main/java/ru/windcorp/progressia/common/world/DecodingException.java index 532d22f..410bfad 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/DecodingException.java +++ b/src/main/java/ru/windcorp/progressia/common/world/DecodingException.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; /** diff --git a/src/main/java/ru/windcorp/progressia/common/world/IllegalCoordinatesException.java b/src/main/java/ru/windcorp/progressia/common/world/IllegalCoordinatesException.java index 69240cf..1c3a3d3 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/IllegalCoordinatesException.java +++ b/src/main/java/ru/windcorp/progressia/common/world/IllegalCoordinatesException.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; public class IllegalCoordinatesException extends RuntimeException { @@ -38,12 +38,8 @@ public class IllegalCoordinatesException extends RuntimeException { super(message, cause); } - public IllegalCoordinatesException( - String message, - Throwable cause, - boolean enableSuppression, - boolean writableStackTrace - ) { + public IllegalCoordinatesException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/src/main/java/ru/windcorp/progressia/common/world/PacketAffectChunk.java b/src/main/java/ru/windcorp/progressia/common/world/PacketAffectChunk.java index 95e6eab..fdd4ce3 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/PacketAffectChunk.java +++ b/src/main/java/ru/windcorp/progressia/common/world/PacketAffectChunk.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import glm.vec._3.i.Vec3i; diff --git a/src/main/java/ru/windcorp/progressia/common/world/PacketAffectWorld.java b/src/main/java/ru/windcorp/progressia/common/world/PacketAffectWorld.java index 8433b9b..1432f1c 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/PacketAffectWorld.java +++ b/src/main/java/ru/windcorp/progressia/common/world/PacketAffectWorld.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import ru.windcorp.progressia.common.comms.packets.Packet; diff --git a/src/main/java/ru/windcorp/progressia/common/world/PacketRevokeChunk.java b/src/main/java/ru/windcorp/progressia/common/world/PacketRevokeChunk.java index c65b045..c1ab7e3 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/PacketRevokeChunk.java +++ b/src/main/java/ru/windcorp/progressia/common/world/PacketRevokeChunk.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/PacketSendChunk.java b/src/main/java/ru/windcorp/progressia/common/world/PacketSendChunk.java index ca079ff..12a78c8 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/PacketSendChunk.java +++ b/src/main/java/ru/windcorp/progressia/common/world/PacketSendChunk.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/PacketSetLocalPlayer.java b/src/main/java/ru/windcorp/progressia/common/world/PacketSetLocalPlayer.java index f835614..625a4c5 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/PacketSetLocalPlayer.java +++ b/src/main/java/ru/windcorp/progressia/common/world/PacketSetLocalPlayer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/PlayerData.java b/src/main/java/ru/windcorp/progressia/common/world/PlayerData.java index 2123e3f..ecd512b 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/PlayerData.java +++ b/src/main/java/ru/windcorp/progressia/common/world/PlayerData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import ru.windcorp.progressia.common.world.entity.EntityData; diff --git a/src/main/java/ru/windcorp/progressia/common/world/WorldData.java b/src/main/java/ru/windcorp/progressia/common/world/WorldData.java index 85c6188..8b8db6b 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/WorldData.java +++ b/src/main/java/ru/windcorp/progressia/common/world/WorldData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import java.util.ArrayList; @@ -39,12 +39,10 @@ import ru.windcorp.progressia.common.world.generic.LongBasedChunkMap; import ru.windcorp.progressia.common.world.tile.TileData; import ru.windcorp.progressia.common.world.tile.TileDataStack; -public class WorldData - implements GenericWorld { +public class WorldData implements GenericWorld { private final ChunkMap chunksByPos = new LongBasedChunkMap<>( - TCollections.synchronizedMap(new TLongObjectHashMap<>()) - ); + TCollections.synchronizedMap(new TLongObjectHashMap<>())); private final Collection chunks = Collections.unmodifiableCollection(chunksByPos.values()); @@ -102,14 +100,8 @@ public class WorldData ChunkData previous = chunksByPos.get(chunk); if (previous != null) { - throw new IllegalArgumentException( - String.format( - "Chunk at (%d; %d; %d) already exists", - chunk.getPosition().x, - chunk.getPosition().y, - chunk.getPosition().z - ) - ); + throw new IllegalArgumentException(String.format("Chunk at (%d; %d; %d) already exists", + chunk.getPosition().x, chunk.getPosition().y, chunk.getPosition().z)); } chunksByPos.put(chunk, chunk); @@ -128,11 +120,8 @@ public class WorldData public void setBlock(Vec3i blockInWorld, BlockData block, boolean notify) { ChunkData chunk = getChunkByBlock(blockInWorld); if (chunk == null) - throw new IllegalCoordinatesException( - "Coordinates " - + "(" + blockInWorld.x + "; " + blockInWorld.y + "; " + blockInWorld.z + ") " - + "do not belong to a loaded chunk" - ); + throw new IllegalCoordinatesException("Coordinates " + "(" + blockInWorld.x + "; " + blockInWorld.y + "; " + + blockInWorld.z + ") " + "do not belong to a loaded chunk"); chunk.setBlock(Coordinates.convertInWorldToInChunk(blockInWorld, null), block, notify); } @@ -167,8 +156,7 @@ public class WorldData if (entity == null) { throw new IllegalArgumentException( - "Entity with EntityID " + EntityData.formatEntityId(entityId) + " not present" - ); + "Entity with EntityID " + EntityData.formatEntityId(entityId) + " not present"); } else { removeEntity(entity); } diff --git a/src/main/java/ru/windcorp/progressia/common/world/WorldDataListener.java b/src/main/java/ru/windcorp/progressia/common/world/WorldDataListener.java index 9211efd..875bb93 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/WorldDataListener.java +++ b/src/main/java/ru/windcorp/progressia/common/world/WorldDataListener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world; import java.util.function.Consumer; @@ -27,19 +27,20 @@ public interface WorldDataListener { /** * Invoked when a new {@link ChunkData} instance is created. This method - * should be used to add - * {@link ChunkDataListener}s to a new chunk. When listeners are added with - * this method, - * their {@link ChunkDataListener#onChunkLoaded(ChunkData) onChunkLoaded} - * methods will be invoked. + * should be used to add {@link ChunkDataListener}s to a new chunk. When + * listeners are added with this method, their + * {@link ChunkDataListener#onChunkLoaded(ChunkData) onChunkLoaded} methods + * will be invoked. * - * @param world the world instance - * @param chunk the {@linkplain Coordinates#chunk coordinates of - * chunk} of the chunk about to load - * @param chunkListenerSink a sink for listeners. All listeners passed to - * its - * {@link Consumer#accept(Object) accept} method - * will be added to the chunk. + * @param world + * the world instance + * @param chunk + * the {@linkplain Coordinates#chunk coordinates of chunk} of the + * chunk about to load + * @param chunkListenerSink + * a sink for listeners. All listeners passed to its + * {@link Consumer#accept(Object) accept} method will be added to + * the chunk. */ default void getChunkListeners(WorldData world, Vec3i chunk, Consumer chunkListenerSink) { } @@ -47,8 +48,10 @@ public interface WorldDataListener { /** * Invoked whenever a {@link Chunk} has been loaded. * - * @param world the world instance - * @param chunk the chunk that has loaded + * @param world + * the world instance + * @param chunk + * the chunk that has loaded */ default void onChunkLoaded(WorldData world, ChunkData chunk) { } @@ -56,8 +59,10 @@ public interface WorldDataListener { /** * Invoked whenever a {@link Chunk} is about to be unloaded. * - * @param world the world instance - * @param chunk the chunk that is going to be unloaded + * @param world + * the world instance + * @param chunk + * the chunk that is going to be unloaded */ default void beforeChunkUnloaded(WorldData world, ChunkData chunk) { } @@ -65,8 +70,10 @@ public interface WorldDataListener { /** * Invoked whenever an {@link EntityData} has been added. * - * @param world the world instance - * @param entity the entity that has been added + * @param world + * the world instance + * @param entity + * the entity that has been added */ default void onEntityAdded(WorldData world, EntityData entity) { } @@ -74,8 +81,10 @@ public interface WorldDataListener { /** * Invoked whenever an {@link EntityData} is about to be removed. * - * @param world the world instance - * @param entity the entity that is going to be removed + * @param world + * the world instance + * @param entity + * the entity that is going to be removed */ default void beforeEntityRemoved(WorldData world, EntityData entity) { } diff --git a/src/main/java/ru/windcorp/progressia/common/world/block/BlockData.java b/src/main/java/ru/windcorp/progressia/common/world/block/BlockData.java index e94f838..2c9d352 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/block/BlockData.java +++ b/src/main/java/ru/windcorp/progressia/common/world/block/BlockData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.block; import ru.windcorp.progressia.common.collision.AABB; diff --git a/src/main/java/ru/windcorp/progressia/common/world/block/BlockDataRegistry.java b/src/main/java/ru/windcorp/progressia/common/world/block/BlockDataRegistry.java index ac1934c..68b7412 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/block/BlockDataRegistry.java +++ b/src/main/java/ru/windcorp/progressia/common/world/block/BlockDataRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.block; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; diff --git a/src/main/java/ru/windcorp/progressia/common/world/block/BlockFace.java b/src/main/java/ru/windcorp/progressia/common/world/block/BlockFace.java index 9023500..741a4d8 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/block/BlockFace.java +++ b/src/main/java/ru/windcorp/progressia/common/world/block/BlockFace.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.block; import com.google.common.collect.ImmutableList; @@ -26,11 +26,9 @@ import glm.vec._3.i.Vec3i; public final class BlockFace extends BlockRelation { public static final BlockFace TOP = new BlockFace(0, 0, +1, true, "TOP"), - BOTTOM = new BlockFace(0, 0, -1, false, "BOTTOM"), - NORTH = new BlockFace(+1, 0, 0, true, "NORTH"), - SOUTH = new BlockFace(-1, 0, 0, false, "SOUTH"), - WEST = new BlockFace(0, +1, 0, false, "WEST"), - EAST = new BlockFace(0, -1, 0, true, "EAST"); + BOTTOM = new BlockFace(0, 0, -1, false, "BOTTOM"), NORTH = new BlockFace(+1, 0, 0, true, "NORTH"), + SOUTH = new BlockFace(-1, 0, 0, false, "SOUTH"), WEST = new BlockFace(0, +1, 0, false, "WEST"), + EAST = new BlockFace(0, -1, 0, true, "EAST"); private static final ImmutableList ALL_FACES = ImmutableList.of(TOP, BOTTOM, NORTH, SOUTH, WEST, EAST); @@ -41,10 +39,10 @@ public final class BlockFace extends BlockRelation { } private static final ImmutableList PRIMARY_FACES = ALL_FACES.stream().filter(BlockFace::isPrimary) - .collect(ImmutableList.toImmutableList()); + .collect(ImmutableList.toImmutableList()); private static final ImmutableList SECONDARY_FACES = ALL_FACES.stream().filter(BlockFace::isSecondary) - .collect(ImmutableList.toImmutableList()); + .collect(ImmutableList.toImmutableList()); public static final int BLOCK_FACE_COUNT = ALL_FACES.size(); public static final int PRIMARY_BLOCK_FACE_COUNT = PRIMARY_FACES.size(); @@ -67,22 +65,9 @@ public final class BlockFace extends BlockRelation { b.counterFace = a; } - public static ImmutableMap mapToFaces( - E top, - E bottom, - E north, - E south, - E east, - E west - ) { - return ImmutableMap.builderWithExpectedSize(6) - .put(TOP, top) - .put(BOTTOM, bottom) - .put(NORTH, north) - .put(SOUTH, south) - .put(EAST, east) - .put(WEST, west) - .build(); + public static ImmutableMap mapToFaces(E top, E bottom, E north, E south, E east, E west) { + return ImmutableMap.builderWithExpectedSize(6).put(TOP, top).put(BOTTOM, bottom).put(NORTH, north) + .put(SOUTH, south).put(EAST, east).put(WEST, west).build(); } private static int nextId = 0; diff --git a/src/main/java/ru/windcorp/progressia/common/world/block/BlockRelation.java b/src/main/java/ru/windcorp/progressia/common/world/block/BlockRelation.java index 659a5fa..ce6997e 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/block/BlockRelation.java +++ b/src/main/java/ru/windcorp/progressia/common/world/block/BlockRelation.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.block; import static java.lang.Math.abs; @@ -43,7 +43,7 @@ public class BlockRelation { public Vec3i getVector() { return vector; } - + public Vec3 getFloatVector() { return floatVector; } @@ -65,9 +65,9 @@ public class BlockRelation { /** * Returns the Manhattan distance, also known as the taxicab distance, * between the source and the destination blocks. Manhattan distance is - * defined as the sum of the absolute values of the coordinates, - * which is also the minimum amount of block faces that need to be crossed - * to move from source to destination. + * defined as the sum of the absolute values of the coordinates, which is + * also the minimum amount of block faces that need to be crossed to move + * from source to destination. * * @return the sum of the absolute values of the coordinates */ diff --git a/src/main/java/ru/windcorp/progressia/common/world/block/PacketAffectBlock.java b/src/main/java/ru/windcorp/progressia/common/world/block/PacketAffectBlock.java index 2c1c8a2..5a4a3ac 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/block/PacketAffectBlock.java +++ b/src/main/java/ru/windcorp/progressia/common/world/block/PacketAffectBlock.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.block; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/block/PacketSetBlock.java b/src/main/java/ru/windcorp/progressia/common/world/block/PacketSetBlock.java index 55d0eb2..a29fa2e 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/block/PacketSetBlock.java +++ b/src/main/java/ru/windcorp/progressia/common/world/block/PacketSetBlock.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.block; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/entity/EntityData.java b/src/main/java/ru/windcorp/progressia/common/world/entity/EntityData.java index 7b3325c..3201972 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/entity/EntityData.java +++ b/src/main/java/ru/windcorp/progressia/common/world/entity/EntityData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.entity; import java.io.DataInput; @@ -40,8 +40,8 @@ public class EntityData extends StatefulObject implements Collideable, GenericEn /** * The unique {@code long} value guaranteed to never be assigned to an - * entity as its entity ID. - * This can safely be used as a placeholder or a sentinel value. + * entity as its entity ID. This can safely be used as a placeholder or a + * sentinel value. */ public static final long NULL_ENTITY_ID = 0x0000_0000_0000_0000; @@ -153,22 +153,16 @@ public class EntityData extends StatefulObject implements Collideable, GenericEn } public Vec3 getLookingAtVector(Vec3 output) { - output.set( - Math.cos(getPitch()) * Math.cos(getYaw()), - Math.cos(getPitch()) * Math.sin(getYaw()), - -Math.sin(getPitch()) - ); + output.set(Math.cos(getPitch()) * Math.cos(getYaw()), Math.cos(getPitch()) * Math.sin(getYaw()), + -Math.sin(getPitch())); return output; } @Override public String toString() { - return new StringBuilder(super.toString()) - .append(" (EntityID ") - .append(StringUtil.toFullHex(getEntityId())) - .append(")") - .toString(); + return new StringBuilder(super.toString()).append(" (EntityID ").append(StringUtil.toFullHex(getEntityId())) + .append(")").toString(); } public static String formatEntityId(long entityId) { @@ -197,22 +191,11 @@ public class EntityData extends StatefulObject implements Collideable, GenericEn @Override public void read(DataInput input, IOContext context) throws IOException { - Vec3 position = new Vec3( - input.readFloat(), - input.readFloat(), - input.readFloat() - ); + Vec3 position = new Vec3(input.readFloat(), input.readFloat(), input.readFloat()); - Vec3 velocity = new Vec3( - input.readFloat(), - input.readFloat(), - input.readFloat() - ); + Vec3 velocity = new Vec3(input.readFloat(), input.readFloat(), input.readFloat()); - Vec2 direction = new Vec2( - input.readFloat(), - input.readFloat() - ); + Vec2 direction = new Vec2(input.readFloat(), input.readFloat()); setPosition(position); setVelocity(velocity); diff --git a/src/main/java/ru/windcorp/progressia/common/world/entity/EntityDataRegistry.java b/src/main/java/ru/windcorp/progressia/common/world/entity/EntityDataRegistry.java index 26f219d..34271ae 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/entity/EntityDataRegistry.java +++ b/src/main/java/ru/windcorp/progressia/common/world/entity/EntityDataRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.entity; import ru.windcorp.progressia.common.state.StatefulObjectRegistry; diff --git a/src/main/java/ru/windcorp/progressia/common/world/entity/PacketAffectEntity.java b/src/main/java/ru/windcorp/progressia/common/world/entity/PacketAffectEntity.java index f3bf792..aefd64e 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/entity/PacketAffectEntity.java +++ b/src/main/java/ru/windcorp/progressia/common/world/entity/PacketAffectEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.entity; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/entity/PacketChangeEntity.java b/src/main/java/ru/windcorp/progressia/common/world/entity/PacketChangeEntity.java index d09b0f3..515f1f0 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/entity/PacketChangeEntity.java +++ b/src/main/java/ru/windcorp/progressia/common/world/entity/PacketChangeEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.entity; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/entity/PacketRevokeEntity.java b/src/main/java/ru/windcorp/progressia/common/world/entity/PacketRevokeEntity.java index 06dfc12..98b1d88 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/entity/PacketRevokeEntity.java +++ b/src/main/java/ru/windcorp/progressia/common/world/entity/PacketRevokeEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.entity; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/entity/PacketSendEntity.java b/src/main/java/ru/windcorp/progressia/common/world/entity/PacketSendEntity.java index 6604d4a..93d724c 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/entity/PacketSendEntity.java +++ b/src/main/java/ru/windcorp/progressia/common/world/entity/PacketSendEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.entity; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkMap.java b/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkMap.java index 6c35781..d298d69 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkMap.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkMap.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import java.util.Collection; @@ -97,10 +97,8 @@ public interface ChunkMap { return containsChunk(chunk) ? def : get(chunk); } - default > V compute( - C chunk, - BiFunction remappingFunction - ) { + default > V compute(C chunk, + BiFunction remappingFunction) { V newValue = remappingFunction.apply(chunk, get(chunk)); if (newValue == null) { @@ -128,10 +126,8 @@ public interface ChunkMap { void forEach(BiConsumer action); - default > void forEachIn( - GenericWorld world, - BiConsumer action - ) { + default > void forEachIn(GenericWorld world, + BiConsumer action) { forEach((pos, value) -> { C chunk = world.getChunk(pos); if (chunk == null) diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkSet.java b/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkSet.java index 73c2267..9ee94af 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkSet.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkSet.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import java.util.Collection; @@ -87,10 +87,8 @@ public interface ChunkSet extends Iterable { return remove(chunk.getPosition()); } - default > void forEachIn( - GenericWorld world, - Consumer action - ) { + default > void forEachIn(GenericWorld world, + Consumer action) { forEach(position -> { C chunk = world.getChunk(position); if (chunk == null) diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkSets.java b/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkSets.java index 93413e4..ac79696 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkSets.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/ChunkSets.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import java.util.Iterator; @@ -219,10 +219,8 @@ public class ChunkSets { } @Override - public > void forEachIn( - GenericWorld world, - Consumer action - ) { + public > void forEachIn(GenericWorld world, + Consumer action) { synchronized (mutex) { parent.forEachIn(world, action); } diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericBlock.java b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericBlock.java index d669b07..1d2c252 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericBlock.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericBlock.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; public interface GenericBlock { diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericChunk.java b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericChunk.java index 656304f..cd93df6 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericChunk.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericChunk.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import java.util.function.Consumer; @@ -75,9 +75,8 @@ public interface GenericChunk, B exten } default boolean containsBiC(Vec3i blockInChunk) { - return blockInChunk.x >= 0 && blockInChunk.x < BLOCKS_PER_CHUNK && - blockInChunk.y >= 0 && blockInChunk.y < BLOCKS_PER_CHUNK && - blockInChunk.z >= 0 && blockInChunk.z < BLOCKS_PER_CHUNK; + return blockInChunk.x >= 0 && blockInChunk.x < BLOCKS_PER_CHUNK && blockInChunk.y >= 0 + && blockInChunk.y < BLOCKS_PER_CHUNK && blockInChunk.z >= 0 && blockInChunk.z < BLOCKS_PER_CHUNK; } default boolean containsBiW(Vec3i blockInWorld) { @@ -91,17 +90,20 @@ public interface GenericChunk, B exten Vectors.release(v); return result; } - + default boolean isSurfaceBiC(Vec3i blockInChunk) { int hits = 0; - - if (Coordinates.isOnChunkBorder(blockInChunk.x)) hits++; - if (Coordinates.isOnChunkBorder(blockInChunk.y)) hits++; - if (Coordinates.isOnChunkBorder(blockInChunk.z)) hits++; - + + if (Coordinates.isOnChunkBorder(blockInChunk.x)) + hits++; + if (Coordinates.isOnChunkBorder(blockInChunk.y)) + hits++; + if (Coordinates.isOnChunkBorder(blockInChunk.z)) + hits++; + return hits >= 1; } - + default boolean isSurfaceBiW(Vec3i blockInWorld) { Vec3i v = Vectors.grab3i(); @@ -113,17 +115,20 @@ public interface GenericChunk, B exten Vectors.release(v); return result; } - + default boolean isEdgeBiC(Vec3i blockInChunk) { int hits = 0; - - if (Coordinates.isOnChunkBorder(blockInChunk.x)) hits++; - if (Coordinates.isOnChunkBorder(blockInChunk.y)) hits++; - if (Coordinates.isOnChunkBorder(blockInChunk.z)) hits++; - + + if (Coordinates.isOnChunkBorder(blockInChunk.x)) + hits++; + if (Coordinates.isOnChunkBorder(blockInChunk.y)) + hits++; + if (Coordinates.isOnChunkBorder(blockInChunk.z)) + hits++; + return hits >= 2; } - + default boolean isEdgeBiW(Vec3i blockInWorld) { Vec3i v = Vectors.grab3i(); @@ -135,17 +140,20 @@ public interface GenericChunk, B exten Vectors.release(v); return result; } - + default boolean isVertexBiC(Vec3i blockInChunk) { int hits = 0; - - if (Coordinates.isOnChunkBorder(blockInChunk.x)) hits++; - if (Coordinates.isOnChunkBorder(blockInChunk.y)) hits++; - if (Coordinates.isOnChunkBorder(blockInChunk.z)) hits++; - + + if (Coordinates.isOnChunkBorder(blockInChunk.x)) + hits++; + if (Coordinates.isOnChunkBorder(blockInChunk.y)) + hits++; + if (Coordinates.isOnChunkBorder(blockInChunk.z)) + hits++; + return hits == 3; } - + default boolean isVertexBiW(Vec3i blockInWorld) { Vec3i v = Vectors.grab3i(); @@ -159,27 +167,12 @@ public interface GenericChunk, B exten } default void forEachBiC(Consumer action) { - VectorUtil.iterateCuboid( - 0, - 0, - 0, - BLOCKS_PER_CHUNK, - BLOCKS_PER_CHUNK, - BLOCKS_PER_CHUNK, - action - ); + VectorUtil.iterateCuboid(0, 0, 0, BLOCKS_PER_CHUNK, BLOCKS_PER_CHUNK, BLOCKS_PER_CHUNK, action); } default void forEachBiW(Consumer action) { - VectorUtil.iterateCuboid( - Coordinates.getInWorld(getX(), 0), - Coordinates.getInWorld(getY(), 0), - Coordinates.getInWorld(getZ(), 0), - BLOCKS_PER_CHUNK, - BLOCKS_PER_CHUNK, - BLOCKS_PER_CHUNK, - action - ); + VectorUtil.iterateCuboid(Coordinates.getInWorld(getX(), 0), Coordinates.getInWorld(getY(), 0), + Coordinates.getInWorld(getZ(), 0), BLOCKS_PER_CHUNK, BLOCKS_PER_CHUNK, BLOCKS_PER_CHUNK, action); } default TS getTilesOrNull(Vec3i blockInChunk, BlockFace face) { diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericEntity.java b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericEntity.java index c15bd39..ee802b9 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericEntity.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import glm.vec._3.Vec3; diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericTile.java b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericTile.java index e35aec2..73bf63b 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericTile.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; public interface GenericTile { diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericTileStack.java b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericTileStack.java index 31a5158..32a3786 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericTileStack.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericTileStack.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import java.util.AbstractList; @@ -28,8 +28,7 @@ import ru.windcorp.progressia.common.world.Coordinates; import ru.windcorp.progressia.common.world.block.BlockFace; public abstract class GenericTileStack, T extends GenericTile, C extends GenericChunk> - extends AbstractList - implements RandomAccess { + extends AbstractList implements RandomAccess { public static interface TSConsumer { void accept(int layer, T tile); diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericWorld.java b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericWorld.java index 943067e..e1b71fa 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/GenericWorld.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/GenericWorld.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import java.util.Collection; diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/LongBasedChunkMap.java b/src/main/java/ru/windcorp/progressia/common/world/generic/LongBasedChunkMap.java index 2fbc912..855f0d7 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/LongBasedChunkMap.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/LongBasedChunkMap.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import java.util.Collection; diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/LongBasedChunkSet.java b/src/main/java/ru/windcorp/progressia/common/world/generic/LongBasedChunkSet.java index cd5a755..f5112c8 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/LongBasedChunkSet.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/LongBasedChunkSet.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.generic; import java.util.Iterator; diff --git a/src/main/java/ru/windcorp/progressia/common/world/io/ChunkCodec.java b/src/main/java/ru/windcorp/progressia/common/world/io/ChunkCodec.java index 7c2a35c..46207bb 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/io/ChunkCodec.java +++ b/src/main/java/ru/windcorp/progressia/common/world/io/ChunkCodec.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.io; import java.io.DataInputStream; @@ -47,8 +47,7 @@ public abstract class ChunkCodec extends Namespaced { } public abstract ChunkData decode(WorldData world, Vec3i position, DataInputStream input, IOContext context) - throws DecodingException, - IOException; + throws DecodingException, IOException; public abstract boolean shouldEncode(ChunkData chunk, IOContext context); diff --git a/src/main/java/ru/windcorp/progressia/common/world/io/ChunkIO.java b/src/main/java/ru/windcorp/progressia/common/world/io/ChunkIO.java index 025738f..b02104d 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/io/ChunkIO.java +++ b/src/main/java/ru/windcorp/progressia/common/world/io/ChunkIO.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.io; import java.io.DataInputStream; @@ -41,8 +41,7 @@ public class ChunkIO { private static final List CODECS_BY_PRIORITY = new ArrayList<>(); public static ChunkData load(WorldData world, Vec3i position, DataInputStream data, IOContext context) - throws DecodingException, - IOException { + throws DecodingException, IOException { if (CODECS_BY_ID.isEmpty()) throw new IllegalStateException("No codecs registered"); @@ -53,8 +52,7 @@ public class ChunkIO { ChunkCodec codec = getCodec((byte) signature); if (codec == null) { throw new DecodingException( - "Unknown codec signature " + Integer.toHexString(signature) + "; is it from the future?" - ); + "Unknown codec signature " + Integer.toHexString(signature) + "; is it from the future?"); } try { @@ -62,19 +60,12 @@ public class ChunkIO { } catch (IOException | DecodingException e) { throw e; } catch (Throwable t) { - throw CrashReports.report( - t, - "Codec %s has failed to decode chunk (%d; %d; %d)", - codec.getId(), - position.x, - position.y, - position.z - ); + throw CrashReports.report(t, "Codec %s has failed to decode chunk (%d; %d; %d)", codec.getId(), position.x, + position.y, position.z); } } - public static void save(ChunkData chunk, DataOutputStream output, IOContext context) - throws IOException { + public static void save(ChunkData chunk, DataOutputStream output, IOContext context) throws IOException { ChunkCodec codec = getCodec(chunk, context); try { @@ -83,14 +74,8 @@ public class ChunkIO { } catch (IOException e) { throw e; } catch (Throwable t) { - throw CrashReports.report( - t, - "Codec %s has failed to encode chunk (%d; %d; %d)", - codec.getId(), - chunk.getPosition().x, - chunk.getPosition().y, - chunk.getPosition().z - ); + throw CrashReports.report(t, "Codec %s has failed to encode chunk (%d; %d; %d)", codec.getId(), + chunk.getPosition().x, chunk.getPosition().y, chunk.getPosition().z); } } diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAddTile.java b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAddTile.java index 650b4a7..bfc47c2 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAddTile.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAddTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAffectTile.java b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAffectTile.java index b12012c..07d9105 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAffectTile.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAffectTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; import java.io.DataInput; diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketRemoveTile.java b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketRemoveTile.java index 9a8ef6c..7e9fb47 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketRemoveTile.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketRemoveTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; import java.io.DataInput; @@ -60,15 +60,8 @@ public class PacketRemoveTile extends PacketAffectTile { int index = stack.getIndexByTag(getTag()); if (index < 0) { - throw CrashReports.report( - null, - "Could not find tile with tag %d at (%d; %d; %d; %s)", - getTag(), - getBlockInWorld().x, - getBlockInWorld().y, - getBlockInWorld().z, - getFace() - ); + throw CrashReports.report(null, "Could not find tile with tag %d at (%d; %d; %d; %s)", getTag(), + getBlockInWorld().x, getBlockInWorld().y, getBlockInWorld().z, getFace()); } stack.remove(index); diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/TileData.java b/src/main/java/ru/windcorp/progressia/common/world/tile/TileData.java index d314445..b8f42aa 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/TileData.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/TileData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; import ru.windcorp.progressia.common.util.namespaces.Namespaced; diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/TileDataRegistry.java b/src/main/java/ru/windcorp/progressia/common/world/tile/TileDataRegistry.java index 110baea..5508ded 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/TileDataRegistry.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/TileDataRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/TileDataStack.java b/src/main/java/ru/windcorp/progressia/common/world/tile/TileDataStack.java index 80f0ba4..d9a60b5 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/TileDataStack.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/TileDataStack.java @@ -15,26 +15,26 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; import ru.windcorp.progressia.common.world.ChunkData; import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.generic.GenericTileStack; -public abstract class TileDataStack - extends GenericTileStack { +public abstract class TileDataStack extends GenericTileStack { /** * Inserts the specified tile at the specified position in this stack. * Shifts the tile currently at that position (if any) and any tiles above - * to - * the top (adds one to their indices). + * to the top (adds one to their indices). * - * @param index index at which the specified tile is to be inserted - * @param tile tile to be inserted - * @throws TileStackIsFullException if this stack is {@linkplain #isFull() - * full} + * @param index + * index at which the specified tile is to be inserted + * @param tile + * tile to be inserted + * @throws TileStackIsFullException + * if this stack is {@linkplain #isFull() full} */ /* * Impl note: AbstractList provides a useless implementation of this method, @@ -45,15 +45,15 @@ public abstract class TileDataStack /** * Adds the specified tile at the end of this stack assigning it the - * provided tag. - * This method is useful for copying stacks when preserving tags is - * necessary. + * provided tag. This method is useful for copying stacks when preserving + * tags is necessary. * - * @param tile the tile to add - * @param tag the tag to assign the new tile - * @throws IllegalArgumentException if this stack already contains a tile - * with the - * provided tag + * @param tile + * the tile to add + * @param tag + * the tag to assign the new tile + * @throws IllegalArgumentException + * if this stack already contains a tile with the provided tag */ public abstract void load(TileData tile, int tag); @@ -61,8 +61,10 @@ public abstract class TileDataStack * Replaces the tile at the specified position in this stack with the * specified tile. * - * @param index index of the tile to replace - * @param tile tile to be stored at the specified position + * @param index + * index of the tile to replace + * @param tile + * tile to be stored at the specified position * @return the tile previously at the specified position */ /* @@ -74,12 +76,11 @@ public abstract class TileDataStack /** * Removes the tile at the specified position in this list. Shifts any - * subsequent tiles - * to the left (subtracts one from their indices). Returns the tile that was - * removed - * from the list. + * subsequent tiles to the left (subtracts one from their indices). Returns + * the tile that was removed from the list. * - * @param index the index of the tile to be removed + * @param index + * the index of the tile to be removed * @return the tile previously at the specified position */ /* @@ -108,12 +109,13 @@ public abstract class TileDataStack } /** - * Attempts to {@link #add(int, TileData) add} the provided {@code tile} - * at {@code index}. If the stack is {@linkplain #isFull() full}, does - * nothing. + * Attempts to {@link #add(int, TileData) add} the provided {@code tile} at + * {@code index}. If the stack is {@linkplain #isFull() full}, does nothing. * - * @param index the index to insert the tile at - * @param tile the tile to try to add + * @param index + * the index to insert the tile at + * @param tile + * the tile to try to add * @return {@code true} iff this stack has changed */ public boolean offer(int index, TileData tile) { diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/TileReference.java b/src/main/java/ru/windcorp/progressia/common/world/tile/TileReference.java index 75fde58..b8d593f 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/TileReference.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/TileReference.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; public interface TileReference { diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/TileStackIsFullException.java b/src/main/java/ru/windcorp/progressia/common/world/tile/TileStackIsFullException.java index c9f6240..8db0b55 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/TileStackIsFullException.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/TileStackIsFullException.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; public class TileStackIsFullException extends RuntimeException { @@ -26,12 +26,8 @@ public class TileStackIsFullException extends RuntimeException { } - public TileStackIsFullException( - String message, - Throwable cause, - boolean enableSuppression, - boolean writableStackTrace - ) { + public TileStackIsFullException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/src/main/java/ru/windcorp/progressia/server/ChunkLoader.java b/src/main/java/ru/windcorp/progressia/server/ChunkLoader.java index d708fe2..f2391a2 100644 --- a/src/main/java/ru/windcorp/progressia/server/ChunkLoader.java +++ b/src/main/java/ru/windcorp/progressia/server/ChunkLoader.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/ChunkManager.java b/src/main/java/ru/windcorp/progressia/server/ChunkManager.java index b0b0777..685fe51 100644 --- a/src/main/java/ru/windcorp/progressia/server/ChunkManager.java +++ b/src/main/java/ru/windcorp/progressia/server/ChunkManager.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server; import java.util.Collections; @@ -160,13 +160,7 @@ public class ChunkManager { ChunkData chunk = world.getChunk(chunkPos); if (chunk == null) { throw new IllegalStateException( - String.format( - "Chunk (%d; %d; %d) not loaded, cannot unload", - chunkPos.x, - chunkPos.y, - chunkPos.z - ) - ); + String.format("Chunk (%d; %d; %d) not loaded, cannot unload", chunkPos.x, chunkPos.y, chunkPos.z)); } world.removeChunk(chunk); @@ -180,13 +174,7 @@ public class ChunkManager { if (chunk == null) { throw new IllegalStateException( - String.format( - "Chunk (%d; %d; %d) is not loaded, cannot send", - chunkPos.x, - chunkPos.y, - chunkPos.z - ) - ); + String.format("Chunk (%d; %d; %d) is not loaded, cannot send", chunkPos.x, chunkPos.y, chunkPos.z)); } PacketSendChunk packet = new PacketSendChunk(); diff --git a/src/main/java/ru/windcorp/progressia/server/EntityManager.java b/src/main/java/ru/windcorp/progressia/server/EntityManager.java index d904c83..0e2a211 100644 --- a/src/main/java/ru/windcorp/progressia/server/EntityManager.java +++ b/src/main/java/ru/windcorp/progressia/server/EntityManager.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server; import java.util.Collections; @@ -145,9 +145,8 @@ public class EntityManager { EntityData entity = server.getWorld().getData().getEntity(entityId); if (entity == null) { - throw new IllegalStateException( - "Entity with entity ID " + new String(StringUtil.toFullHex(entityId)) + " is not loaded, cannot send" - ); + throw new IllegalStateException("Entity with entity ID " + new String(StringUtil.toFullHex(entityId)) + + " is not loaded, cannot send"); } PacketSendEntity packet = new PacketSendEntity(); diff --git a/src/main/java/ru/windcorp/progressia/server/Player.java b/src/main/java/ru/windcorp/progressia/server/Player.java index ea373a8..9b29918 100644 --- a/src/main/java/ru/windcorp/progressia/server/Player.java +++ b/src/main/java/ru/windcorp/progressia/server/Player.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/PlayerManager.java b/src/main/java/ru/windcorp/progressia/server/PlayerManager.java index 38d0f32..3e7bd40 100644 --- a/src/main/java/ru/windcorp/progressia/server/PlayerManager.java +++ b/src/main/java/ru/windcorp/progressia/server/PlayerManager.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server; import java.util.ArrayList; @@ -61,12 +61,7 @@ public class PlayerManager { player.setEntityId(TestContent.PLAYER_ENTITY_ID); player.setPosition(TestContent.SPAWN); - player.setDirection( - new Vec2( - Math.toRadians(40), - Math.toRadians(10) - ) - ); + player.setDirection(new Vec2(Math.toRadians(40), Math.toRadians(10))); getServer().getWorld().getData().addEntity(player); diff --git a/src/main/java/ru/windcorp/progressia/server/Server.java b/src/main/java/ru/windcorp/progressia/server/Server.java index 487616d..fba1857 100644 --- a/src/main/java/ru/windcorp/progressia/server/Server.java +++ b/src/main/java/ru/windcorp/progressia/server/Server.java @@ -83,8 +83,8 @@ public class Server { } /** - * Returns this server's {@link ClientManager}. - * Use this to deal with communications, e.g. send packets. + * Returns this server's {@link ClientManager}. Use this to deal with + * communications, e.g. send packets. * * @return the {@link ClientManager} that handles this server */ @@ -110,15 +110,16 @@ public class Server { } /** - * Requests that the provided task is executed once on next server tick. - * The task will be run in the main server thread. The task object is - * discarded after execution. + * Requests that the provided task is executed once on next server tick. The + * task will be run in the main server thread. The task object is discarded + * after execution. *

    * Use this method to request a one-time (rare) action that must necessarily * happen in the main server thread, such as initialization tasks or * reconfiguration. * - * @param task the task to run + * @param task + * the task to run * @see #invokeNow(Runnable) * @see #schedule(Consumer) */ @@ -129,15 +130,15 @@ public class Server { /** * Executes the tasks in the server main thread as soon as possible. *

    - * If this method is invoked in the server main thread, then the task is - * run immediately (the method blocks until the task finishes). Otherwise - * this method behaves exactly like {@link #invokeLater(Runnable)}. + * If this method is invoked in the server main thread, then the task is run + * immediately (the method blocks until the task finishes). Otherwise this + * method behaves exactly like {@link #invokeLater(Runnable)}. *

    * Use this method to make sure that a piece of code is run in the main - * server - * thread. + * server thread. * - * @param task the task to run + * @param task + * the task to run * @see #invokeLater(Runnable) * @see #schedule(Consumer) */ @@ -145,11 +146,7 @@ public class Server { taskQueue.invokeNow(task); } - public void waitAndInvoke( - ThrowingRunnable task - ) - throws InterruptedException, - E { + public void waitAndInvoke(ThrowingRunnable task) throws InterruptedException, E { taskQueue.waitAndInvoke(task); } @@ -197,8 +194,8 @@ public class Server { /** * Returns the {@link WorldAccessor} object for this server. Use the - * provided accessor to - * request common {@link Evaluation}s and {@link Change}s. + * provided accessor to request common {@link Evaluation}s and + * {@link Change}s. * * @return a {@link WorldAccessor} * @see #requestChange(Change) @@ -238,11 +235,10 @@ public class Server { /** * Shuts the server down, disconnecting the clients with the provided - * message. - * This method blocks until the shutdown is complete. + * message. This method blocks until the shutdown is complete. * - * @param message the message to send to the clients as the disconnect - * reason + * @param message + * the message to send to the clients as the disconnect reason */ public void shutdown(String message) { LogManager.getLogger().warn("Server.shutdown() is not yet implemented"); @@ -256,10 +252,9 @@ public class Server { /** * Returns an instance of {@link java.util.Random Random} that can be used - * as a source of indeterministic - * randomness. World generation and other algorithms that must have random - * but reproducible results should - * not use this. + * as a source of indeterministic randomness. World generation and other + * algorithms that must have random but reproducible results should not use + * this. * * @return a thread-safe indeterministic instance of * {@link java.util.Random}. diff --git a/src/main/java/ru/windcorp/progressia/server/ServerState.java b/src/main/java/ru/windcorp/progressia/server/ServerState.java index 774f17d..d252e0c 100644 --- a/src/main/java/ru/windcorp/progressia/server/ServerState.java +++ b/src/main/java/ru/windcorp/progressia/server/ServerState.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server; import ru.windcorp.progressia.common.world.WorldData; diff --git a/src/main/java/ru/windcorp/progressia/server/ServerThread.java b/src/main/java/ru/windcorp/progressia/server/ServerThread.java index 90f3ce9..2cf3296 100644 --- a/src/main/java/ru/windcorp/progressia/server/ServerThread.java +++ b/src/main/java/ru/windcorp/progressia/server/ServerThread.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server; import java.util.concurrent.Executors; @@ -51,9 +51,8 @@ public class ServerThread implements Runnable { } private final Server server; - private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor( - r -> new Thread(new ServerThreadTracker(r), "Server thread") - ); + private final ScheduledExecutorService executor = Executors + .newSingleThreadScheduledExecutor(r -> new Thread(new ServerThreadTracker(r), "Server thread")); private final TickerCoordinator ticker; diff --git a/src/main/java/ru/windcorp/progressia/server/TickingSettings.java b/src/main/java/ru/windcorp/progressia/server/TickingSettings.java index 743da10..8cb77d6 100644 --- a/src/main/java/ru/windcorp/progressia/server/TickingSettings.java +++ b/src/main/java/ru/windcorp/progressia/server/TickingSettings.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server; import ru.windcorp.progressia.common.Units; diff --git a/src/main/java/ru/windcorp/progressia/server/comms/Client.java b/src/main/java/ru/windcorp/progressia/server/comms/Client.java index f439e27..fdc1e98 100644 --- a/src/main/java/ru/windcorp/progressia/server/comms/Client.java +++ b/src/main/java/ru/windcorp/progressia/server/comms/Client.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.comms; import ru.windcorp.progressia.common.comms.CommsChannel; diff --git a/src/main/java/ru/windcorp/progressia/server/comms/ClientChat.java b/src/main/java/ru/windcorp/progressia/server/comms/ClientChat.java index 35b9ca2..3d46634 100644 --- a/src/main/java/ru/windcorp/progressia/server/comms/ClientChat.java +++ b/src/main/java/ru/windcorp/progressia/server/comms/ClientChat.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.comms; public abstract class ClientChat extends Client { diff --git a/src/main/java/ru/windcorp/progressia/server/comms/ClientManager.java b/src/main/java/ru/windcorp/progressia/server/comms/ClientManager.java index cb4b80b..56bdab3 100644 --- a/src/main/java/ru/windcorp/progressia/server/comms/ClientManager.java +++ b/src/main/java/ru/windcorp/progressia/server/comms/ClientManager.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.comms; import java.util.Collection; @@ -91,7 +91,8 @@ public class ClientManager { /** * Sends the provided packet to all connected player clients. * - * @param packet the packet to broadcast + * @param packet + * the packet to broadcast */ public void broadcastToAllPlayers(Packet packet) { getClients().forEach(c -> { @@ -107,8 +108,10 @@ public class ClientManager { * Sends the provided packet to all connected player clients that can see * the chunk identified by {@code chunkPos}. * - * @param packet the packet to broadcast - * @param chunkPos the chunk coordinates of the chunk that must be visible + * @param packet + * the packet to broadcast + * @param chunkPos + * the chunk coordinates of the chunk that must be visible */ public void broadcastLocal(Packet packet, Vec3i chunkPos) { getClients().forEach(c -> { @@ -126,8 +129,10 @@ public class ClientManager { * Sends the provided packet to all connected player clients that can see * the entity identified by {@code entityId}. * - * @param packet the packet to broadcast - * @param entityId the ID of the entity that must be visible + * @param packet + * the packet to broadcast + * @param entityId + * the ID of the entity that must be visible */ public void broadcastLocal(Packet packet, long entityId) { getClients().forEach(c -> { diff --git a/src/main/java/ru/windcorp/progressia/server/comms/ClientPlayer.java b/src/main/java/ru/windcorp/progressia/server/comms/ClientPlayer.java index c455b8e..d414524 100644 --- a/src/main/java/ru/windcorp/progressia/server/comms/ClientPlayer.java +++ b/src/main/java/ru/windcorp/progressia/server/comms/ClientPlayer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.comms; import glm.vec._3.i.Vec3i; diff --git a/src/main/java/ru/windcorp/progressia/server/comms/DefaultServerCommsListener.java b/src/main/java/ru/windcorp/progressia/server/comms/DefaultServerCommsListener.java index d570e01..bcc51ac 100644 --- a/src/main/java/ru/windcorp/progressia/server/comms/DefaultServerCommsListener.java +++ b/src/main/java/ru/windcorp/progressia/server/comms/DefaultServerCommsListener.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.comms; import java.io.IOException; @@ -41,9 +41,8 @@ public class DefaultServerCommsListener implements CommsListener { if (packet instanceof PacketControl) { PacketControl packetControl = (PacketControl) packet; - ControlLogicRegistry.getInstance().get( - packetControl.getControl().getId() - ).apply(manager.getServer(), packetControl, client); + ControlLogicRegistry.getInstance().get(packetControl.getControl().getId()).apply(manager.getServer(), + packetControl, client); } } } diff --git a/src/main/java/ru/windcorp/progressia/server/comms/controls/ControlLogic.java b/src/main/java/ru/windcorp/progressia/server/comms/controls/ControlLogic.java index 31e97a2..713ada7 100644 --- a/src/main/java/ru/windcorp/progressia/server/comms/controls/ControlLogic.java +++ b/src/main/java/ru/windcorp/progressia/server/comms/controls/ControlLogic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.comms.controls; import ru.windcorp.progressia.common.comms.controls.PacketControl; @@ -27,22 +27,14 @@ public abstract class ControlLogic extends Namespaced { @FunctionalInterface public static interface Lambda { - void apply( - Server server, - PacketControl packet, - Client client - ); + void apply(Server server, PacketControl packet, Client client); } public ControlLogic(String id) { super(id); } - public abstract void apply( - Server server, - PacketControl packet, - Client client - ); + public abstract void apply(Server server, PacketControl packet, Client client); public static ControlLogic of(String id, Lambda logic) { return new ControlLogic(id) { diff --git a/src/main/java/ru/windcorp/progressia/server/comms/controls/ControlLogicRegistry.java b/src/main/java/ru/windcorp/progressia/server/comms/controls/ControlLogicRegistry.java index 18ece0a..92112e3 100644 --- a/src/main/java/ru/windcorp/progressia/server/comms/controls/ControlLogicRegistry.java +++ b/src/main/java/ru/windcorp/progressia/server/comms/controls/ControlLogicRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.comms.controls; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; diff --git a/src/main/java/ru/windcorp/progressia/server/world/ChunkLogic.java b/src/main/java/ru/windcorp/progressia/server/world/ChunkLogic.java index 37685d2..e9b1257 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ChunkLogic.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ChunkLogic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world; import java.util.ArrayList; @@ -53,7 +53,7 @@ public class ChunkLogic implements GenericChunk tileLogicLists = Collections - .synchronizedMap(new WeakHashMap<>()); + .synchronizedMap(new WeakHashMap<>()); public ChunkLogic(WorldLogic world, ChunkData data) { this.world = world; @@ -69,9 +69,7 @@ public class ChunkLogic implements GenericChunk action) { tickingTiles.forEach(ref -> { - action.accept( - ref, - TileLogicRegistry.getInstance().get(ref.get().getId()) - ); + action.accept(ref, TileLogicRegistry.getInstance().get(ref.get().getId())); }); } diff --git a/src/main/java/ru/windcorp/progressia/server/world/ChunkTickContext.java b/src/main/java/ru/windcorp/progressia/server/world/ChunkTickContext.java index 5eed263..c197706 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ChunkTickContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ChunkTickContext.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/TickAndUpdateUtil.java b/src/main/java/ru/windcorp/progressia/server/world/TickAndUpdateUtil.java index 22d106e..bb7fb2e 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/TickAndUpdateUtil.java +++ b/src/main/java/ru/windcorp/progressia/server/world/TickAndUpdateUtil.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world; import glm.vec._3.i.Vec3i; @@ -67,18 +67,18 @@ public class TickAndUpdateUtil { return; TileTickContext tickContext = TickContextMutable.start().withWorld(world).withBlock(blockInWorld).withFace(face) - .withLayer(layer); + .withLayer(layer); tickTile((TickableTile) tile, tickContext); } public static void tickTiles(WorldLogic world, Vec3i blockInWorld, BlockFace face) { TickContextMutable.start().withWorld(world).withBlock(blockInWorld).withFace(face).build() - .forEachTile(context -> { - TileLogic tile = context.getTile(); - if (tile instanceof TickableTile) { - tickTile((TickableTile) tile, context); - } - }); + .forEachTile(context -> { + TileLogic tile = context.getTile(); + if (tile instanceof TickableTile) { + tickTile((TickableTile) tile, context); + } + }); } public static void updateBlock(UpdateableBlock block, BlockTickContext context) { @@ -112,18 +112,18 @@ public class TickAndUpdateUtil { return; TileTickContext tickContext = TickContextMutable.start().withWorld(world).withBlock(blockInWorld).withFace(face) - .withLayer(layer); + .withLayer(layer); updateTile((UpdateableTile) tile, tickContext); } public static void updateTiles(WorldLogic world, Vec3i blockInWorld, BlockFace face) { TickContextMutable.start().withWorld(world).withBlock(blockInWorld).withFace(face).build() - .forEachTile(context -> { - TileLogic tile = context.getTile(); - if (tile instanceof UpdateableTile) { - updateTile((UpdateableTile) tile, context); - } - }); + .forEachTile(context -> { + TileLogic tile = context.getTile(); + if (tile instanceof UpdateableTile) { + updateTile((UpdateableTile) tile, context); + } + }); } public static void tickEntity(EntityLogic logic, EntityData data, TickContext context) { @@ -135,11 +135,8 @@ public class TickAndUpdateUtil { } public static void tickEntity(EntityData data, Server server) { - tickEntity( - EntityLogicRegistry.getInstance().get(data.getId()), - data, - TickContextMutable.start().withServer(server).build() - ); + tickEntity(EntityLogicRegistry.getInstance().get(data.getId()), data, + TickContextMutable.start().withServer(server).build()); } private TickAndUpdateUtil() { diff --git a/src/main/java/ru/windcorp/progressia/server/world/TickContext.java b/src/main/java/ru/windcorp/progressia/server/world/TickContext.java index 50dda55..0997c65 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/TickContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/TickContext.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world; import java.util.Random; diff --git a/src/main/java/ru/windcorp/progressia/server/world/TickContextMutable.java b/src/main/java/ru/windcorp/progressia/server/world/TickContextMutable.java index 68185d9..2c92857 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/TickContextMutable.java +++ b/src/main/java/ru/windcorp/progressia/server/world/TickContextMutable.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world; import java.util.Objects; @@ -138,9 +138,8 @@ public abstract class TickContextMutable implements BlockTickContext, TSTickCont * Impl */ - public static class Impl - extends TickContextMutable - implements Builder.Empty, Builder.World, Builder.Chunk, Builder.Block, Builder.TileStack { + public static class Impl extends TickContextMutable + implements Builder.Empty, Builder.World, Builder.Chunk, Builder.Block, Builder.TileStack { protected Impl() { } @@ -214,8 +213,7 @@ public abstract class TickContextMutable implements BlockTickContext, TSTickCont } /* - * Builder - * memo: do NOT use Context getters, they throw ISEs + * Builder memo: do NOT use Context getters, they throw ISEs */ @Override @@ -425,8 +423,7 @@ public abstract class TickContextMutable implements BlockTickContext, TSTickCont if ((role == null) || (requiredRole.compareTo(role) > 0)) { throw new IllegalStateException( - "This context is currently initialized as " + role + "; requested " + requiredRole - ); + "This context is currently initialized as " + role + "; requested " + requiredRole); } } @@ -442,8 +439,7 @@ public abstract class TickContextMutable implements BlockTickContext, TSTickCont } else { if (role != requiredRole) { throw new IllegalStateException( - "This context is currently initialized as " + role + "; requested " + requiredRole - ); + "This context is currently initialized as " + role + "; requested " + requiredRole); } } } @@ -474,17 +470,8 @@ public abstract class TickContextMutable implements BlockTickContext, TSTickCont break; } - return String.format( - format, - this.chunk.x, - this.chunk.y, - this.chunk.z, - this.blockInWorld.x, - this.blockInWorld.y, - this.blockInWorld.z, - this.face, - this.layer - ); + return String.format(format, this.chunk.x, this.chunk.y, this.chunk.z, this.blockInWorld.x, + this.blockInWorld.y, this.blockInWorld.z, this.face, this.layer); } } diff --git a/src/main/java/ru/windcorp/progressia/server/world/UpdateTriggerer.java b/src/main/java/ru/windcorp/progressia/server/world/UpdateTriggerer.java index 511170e..a7c122a 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/UpdateTriggerer.java +++ b/src/main/java/ru/windcorp/progressia/server/world/UpdateTriggerer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world; import glm.vec._3.i.Vec3i; @@ -36,23 +36,13 @@ public class UpdateTriggerer implements ChunkDataListener { } @Override - public void onChunkBlockChanged( - ChunkData chunk, - Vec3i blockInChunk, - BlockData previous, - BlockData current - ) { + public void onChunkBlockChanged(ChunkData chunk, Vec3i blockInChunk, BlockData previous, BlockData current) { server.getWorldAccessor().triggerUpdates(Coordinates.getInWorld(chunk.getPosition(), blockInChunk, null)); } @Override - public void onChunkTilesChanged( - ChunkData chunk, - Vec3i blockInChunk, - BlockFace face, - TileData tile, - boolean wasAdded - ) { + public void onChunkTilesChanged(ChunkData chunk, Vec3i blockInChunk, BlockFace face, TileData tile, + boolean wasAdded) { server.getWorldAccessor().triggerUpdates(Coordinates.getInWorld(chunk.getPosition(), blockInChunk, null), face); } diff --git a/src/main/java/ru/windcorp/progressia/server/world/WorldLogic.java b/src/main/java/ru/windcorp/progressia/server/world/WorldLogic.java index 93a1028..2f3a32b 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/WorldLogic.java +++ b/src/main/java/ru/windcorp/progressia/server/world/WorldLogic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world; import java.util.Collection; @@ -38,14 +38,13 @@ import ru.windcorp.progressia.server.world.ticking.Evaluation; import ru.windcorp.progressia.server.world.tile.TileLogic; import ru.windcorp.progressia.server.world.tile.TileLogicStack; -public class WorldLogic - implements GenericWorld { private final WorldData data; diff --git a/src/main/java/ru/windcorp/progressia/server/world/block/BlockLogic.java b/src/main/java/ru/windcorp/progressia/server/world/block/BlockLogic.java index 794259f..fcf141d 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/block/BlockLogic.java +++ b/src/main/java/ru/windcorp/progressia/server/world/block/BlockLogic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.block; import ru.windcorp.progressia.common.util.namespaces.Namespaced; diff --git a/src/main/java/ru/windcorp/progressia/server/world/block/BlockLogicRegistry.java b/src/main/java/ru/windcorp/progressia/server/world/block/BlockLogicRegistry.java index df18ff7..b50b02f 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/block/BlockLogicRegistry.java +++ b/src/main/java/ru/windcorp/progressia/server/world/block/BlockLogicRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.block; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; diff --git a/src/main/java/ru/windcorp/progressia/server/world/block/BlockTickContext.java b/src/main/java/ru/windcorp/progressia/server/world/block/BlockTickContext.java index a305b9a..d10f10c 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/block/BlockTickContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/block/BlockTickContext.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.block; import java.util.Objects; diff --git a/src/main/java/ru/windcorp/progressia/server/world/block/TickableBlock.java b/src/main/java/ru/windcorp/progressia/server/world/block/TickableBlock.java index 56ba938..62b830f 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/block/TickableBlock.java +++ b/src/main/java/ru/windcorp/progressia/server/world/block/TickableBlock.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.block; import ru.windcorp.progressia.server.world.ticking.TickingPolicy; diff --git a/src/main/java/ru/windcorp/progressia/server/world/block/UpdateableBlock.java b/src/main/java/ru/windcorp/progressia/server/world/block/UpdateableBlock.java index 1497c92..12ae51c 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/block/UpdateableBlock.java +++ b/src/main/java/ru/windcorp/progressia/server/world/block/UpdateableBlock.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.block; import org.apache.logging.log4j.LogManager; @@ -23,13 +23,8 @@ import org.apache.logging.log4j.LogManager; public interface UpdateableBlock { default void update(BlockTickContext context) { - LogManager.getLogger().info( - "Updating block {} @ ({}; {}; {})", - context.getBlock(), - context.getBlockInWorld().x, - context.getBlockInWorld().y, - context.getBlockInWorld().z - ); + LogManager.getLogger().info("Updating block {} @ ({}; {}; {})", context.getBlock(), context.getBlockInWorld().x, + context.getBlockInWorld().y, context.getBlockInWorld().z); } } diff --git a/src/main/java/ru/windcorp/progressia/server/world/entity/EntityLogic.java b/src/main/java/ru/windcorp/progressia/server/world/entity/EntityLogic.java index 7725612..0f33517 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/entity/EntityLogic.java +++ b/src/main/java/ru/windcorp/progressia/server/world/entity/EntityLogic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.entity; import ru.windcorp.progressia.common.util.namespaces.Namespaced; diff --git a/src/main/java/ru/windcorp/progressia/server/world/entity/EntityLogicRegistry.java b/src/main/java/ru/windcorp/progressia/server/world/entity/EntityLogicRegistry.java index d8b05d4..a3ecd20 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/entity/EntityLogicRegistry.java +++ b/src/main/java/ru/windcorp/progressia/server/world/entity/EntityLogicRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.entity; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; diff --git a/src/main/java/ru/windcorp/progressia/server/world/generation/AbstractWorldGenerator.java b/src/main/java/ru/windcorp/progressia/server/world/generation/AbstractWorldGenerator.java index ffb5c06..2753a8f 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/generation/AbstractWorldGenerator.java +++ b/src/main/java/ru/windcorp/progressia/server/world/generation/AbstractWorldGenerator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.generation; import java.io.DataInputStream; diff --git a/src/main/java/ru/windcorp/progressia/server/world/generation/WorldGenerator.java b/src/main/java/ru/windcorp/progressia/server/world/generation/WorldGenerator.java index afed281..41a7885 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/generation/WorldGenerator.java +++ b/src/main/java/ru/windcorp/progressia/server/world/generation/WorldGenerator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.generation; import java.io.DataInputStream; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/AddTile.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/AddTile.java index 6e9ea47..238a42f 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/AddTile.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/AddTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/BlockTriggeredUpdate.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/BlockTriggeredUpdate.java index 331a5c4..6d8d408 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/BlockTriggeredUpdate.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/BlockTriggeredUpdate.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedBlockChange.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedBlockChange.java index b005285..62cedac 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedBlockChange.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedBlockChange.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedChange.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedChange.java index e1eb5ca..d5db70a 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedChange.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedChange.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedChunkChange.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedChunkChange.java index d98c001..ef4a8cf 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedChunkChange.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedChunkChange.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedEvaluation.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedEvaluation.java index da865b4..5fe1320 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedEvaluation.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedEvaluation.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedTileChange.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedTileChange.java index 1b6cde2..7d27be0 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedTileChange.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedTileChange.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.Objects; @@ -58,9 +58,8 @@ public class CachedTileChange

    extends CachedChunkCha if (my.getTag() == -1 || other.getTag() == -1) return false; - return Glm.equals(my.getBlockInWorld(), other.getBlockInWorld()) - && (my.getFace() == other.getFace()) - && (my.getTag() == other.getTag()); + return Glm.equals(my.getBlockInWorld(), other.getBlockInWorld()) && (my.getFace() == other.getFace()) + && (my.getTag() == other.getTag()); } @Override @@ -69,7 +68,7 @@ public class CachedTileChange

    extends CachedChunkCha Vec3i biw = packet.getBlockInWorld(); return getClass().getSimpleName() + " (" + biw.x + "; " + biw.y + "; " + biw.z + "; " + packet.getFace() - + "; tag: " + packet.getTag() + ")"; + + "; tag: " + packet.getTag() + ")"; } } diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedWorldChange.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedWorldChange.java index 711bd5d..c01e83a 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedWorldChange.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/CachedWorldChange.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/ChangeEntity.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/ChangeEntity.java index 08f1212..a7a7072 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/ChangeEntity.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/ChangeEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/RemoveTile.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/RemoveTile.java index 42dea30..0f811b1 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/RemoveTile.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/RemoveTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/SetBlock.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/SetBlock.java index 330333b..e4cc4fb 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/SetBlock.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/SetBlock.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/StateChange.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/StateChange.java index 93d5f08..4aa8c7c 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/StateChange.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/StateChange.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; @FunctionalInterface diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/TickChunk.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/TickChunk.java index c0895e1..b9dd457 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/TickChunk.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/TickChunk.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.ArrayList; @@ -44,9 +44,8 @@ import static ru.windcorp.progressia.common.world.ChunkData.BLOCKS_PER_CHUNK; public class TickChunk extends Evaluation { - private static final int CHUNK_VOLUME = ChunkData.BLOCKS_PER_CHUNK * - ChunkData.BLOCKS_PER_CHUNK * - ChunkData.BLOCKS_PER_CHUNK; + private static final int CHUNK_VOLUME = ChunkData.BLOCKS_PER_CHUNK * ChunkData.BLOCKS_PER_CHUNK + * ChunkData.BLOCKS_PER_CHUNK; private final List> randomTickMethods; @@ -106,9 +105,9 @@ public class TickChunk extends Evaluation { float ticks = computeRandomTicks(server); /* - * If we are expected to run 3.25 random ticks per tick - * on average, then run 3 random ticks unconditionally - * and run one extra random tick with 0.25 chance + * If we are expected to run 3.25 random ticks per tick on average, then + * run 3 random ticks unconditionally and run one extra random tick with + * 0.25 chance */ float unconditionalTicks = FloatMathUtil.floor(ticks); float extraTickChance = ticks - unconditionalTicks; @@ -124,19 +123,14 @@ public class TickChunk extends Evaluation { private void tickRandomOnce(Server server) { // Pick a target at random: a block or one of 3 primary block faces - randomTickMethods.get( - server.getAdHocRandom().nextInt(randomTickMethods.size()) - ).accept(server); + randomTickMethods.get(server.getAdHocRandom().nextInt(randomTickMethods.size())).accept(server); } private void tickRandomBlock(Server server) { Random random = server.getAdHocRandom(); - Vec3i blockInChunk = new Vec3i( - random.nextInt(BLOCKS_PER_CHUNK), - random.nextInt(BLOCKS_PER_CHUNK), - random.nextInt(BLOCKS_PER_CHUNK) - ); + Vec3i blockInChunk = new Vec3i(random.nextInt(BLOCKS_PER_CHUNK), random.nextInt(BLOCKS_PER_CHUNK), + random.nextInt(BLOCKS_PER_CHUNK)); BlockLogic block = this.chunk.getBlock(blockInChunk); @@ -154,11 +148,8 @@ public class TickChunk extends Evaluation { private void tickRandomTile(Server server, BlockFace face) { Random random = server.getAdHocRandom(); - Vec3i blockInChunk = new Vec3i( - random.nextInt(BLOCKS_PER_CHUNK), - random.nextInt(BLOCKS_PER_CHUNK), - random.nextInt(BLOCKS_PER_CHUNK) - ); + Vec3i blockInChunk = new Vec3i(random.nextInt(BLOCKS_PER_CHUNK), random.nextInt(BLOCKS_PER_CHUNK), + random.nextInt(BLOCKS_PER_CHUNK)); TileDataStack tiles = this.chunk.getData().getTilesOrNull(blockInChunk, face); if (tiles == null || tiles.isEmpty()) @@ -179,9 +170,8 @@ public class TickChunk extends Evaluation { } private float computeRandomTicks(Server server) { - return (float) (server.getTickingSettings().getRandomTickFrequency() * - CHUNK_VOLUME * randomTickMethods.size() * - server.getTickLength()); + return (float) (server.getTickingSettings().getRandomTickFrequency() * CHUNK_VOLUME * randomTickMethods.size() + * server.getTickLength()); } @Override diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/TickEntitiesTask.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/TickEntitiesTask.java index 1e76b23..8376c8d 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/TickEntitiesTask.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/TickEntitiesTask.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import glm.vec._3.i.Vec3i; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/TileTriggeredUpdate.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/TileTriggeredUpdate.java index 76fc414..80b91bd 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/TileTriggeredUpdate.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/TileTriggeredUpdate.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tasks/WorldAccessor.java b/src/main/java/ru/windcorp/progressia/server/world/tasks/WorldAccessor.java index 2c83ccd..28d91a4 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tasks/WorldAccessor.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tasks/WorldAccessor.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tasks; import java.util.function.Consumer; @@ -38,14 +38,13 @@ public class WorldAccessor { MultiLOC mloc = new MultiLOC(); Consumer disposer = mloc::release; - cache = mloc - .addClass(SetBlock.class, () -> new SetBlock(disposer)) - .addClass(AddTile.class, () -> new AddTile(disposer)) - .addClass(RemoveTile.class, () -> new RemoveTile(disposer)) - .addClass(ChangeEntity.class, () -> new ChangeEntity(disposer)) + cache = mloc.addClass(SetBlock.class, () -> new SetBlock(disposer)) + .addClass(AddTile.class, () -> new AddTile(disposer)) + .addClass(RemoveTile.class, () -> new RemoveTile(disposer)) + .addClass(ChangeEntity.class, () -> new ChangeEntity(disposer)) - .addClass(BlockTriggeredUpdate.class, () -> new BlockTriggeredUpdate(disposer)) - .addClass(TileTriggeredUpdate.class, () -> new TileTriggeredUpdate(disposer)); + .addClass(BlockTriggeredUpdate.class, () -> new BlockTriggeredUpdate(disposer)) + .addClass(TileTriggeredUpdate.class, () -> new TileTriggeredUpdate(disposer)); } private final Server server; @@ -80,10 +79,7 @@ public class WorldAccessor { server.requestChange(change); } - public void changeEntity( - T entity, - StateChange stateChange - ) { + public void changeEntity(T entity, StateChange stateChange) { ChangeEntity change = cache.grab(ChangeEntity.class); change.set(entity, stateChange); server.requestChange(change); diff --git a/src/main/java/ru/windcorp/progressia/server/world/ticking/Change.java b/src/main/java/ru/windcorp/progressia/server/world/ticking/Change.java index b0fc7f2..c0cf115 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ticking/Change.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ticking/Change.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.ticking; import ru.windcorp.progressia.server.Server; @@ -32,14 +32,13 @@ public abstract class Change extends TickerTask { * Performs the changes on the provided server instance. *

    * This method will be executed when the world is in an inconsistent state - * and may not be queried, - * only changed. Therefore, all necessary inspection must be performed - * before this method is invoked, - * typically by an {@link Evaluation}. Failure to abide by this contract may - * lead to race conditions - * and/or devil invasions. + * and may not be queried, only changed. Therefore, all necessary inspection + * must be performed before this method is invoked, typically by an + * {@link Evaluation}. Failure to abide by this contract may lead to race + * conditions and/or devil invasions. * - * @param server the {@link Server} instance to affect + * @param server + * the {@link Server} instance to affect */ public abstract void affect(Server server); diff --git a/src/main/java/ru/windcorp/progressia/server/world/ticking/DevilInvasionException.java b/src/main/java/ru/windcorp/progressia/server/world/ticking/DevilInvasionException.java index 50ff69c..fd146bc 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ticking/DevilInvasionException.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ticking/DevilInvasionException.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.ticking; public class DevilInvasionException extends RuntimeException { diff --git a/src/main/java/ru/windcorp/progressia/server/world/ticking/Evaluation.java b/src/main/java/ru/windcorp/progressia/server/world/ticking/Evaluation.java index f4f3922..b541871 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ticking/Evaluation.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ticking/Evaluation.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.ticking; import ru.windcorp.progressia.server.Server; @@ -30,14 +30,15 @@ public abstract class Evaluation extends TickerTask { /** * Performs the analysis of the provided server instance. *

    - * This method will be executed when the world is in an consistent state - * and may be queried for meaningful information. However, other - * evaluations may be happening concurrently, so any world modification - * is prohibited. Evaluations are expected to request {@link Change}s - * to interact with the world. Failure to abide by this contract may - * lead to race conditions and/or devil invasions. + * This method will be executed when the world is in an consistent state and + * may be queried for meaningful information. However, other evaluations may + * be happening concurrently, so any world modification is prohibited. + * Evaluations are expected to request {@link Change}s to interact with the + * world. Failure to abide by this contract may lead to race conditions + * and/or devil invasions. * - * @param server the server instance to inspect + * @param server + * the server instance to inspect */ public abstract void evaluate(Server server); diff --git a/src/main/java/ru/windcorp/progressia/server/world/ticking/Ticker.java b/src/main/java/ru/windcorp/progressia/server/world/ticking/Ticker.java index 5c4b83e..4d0a22a 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ticking/Ticker.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ticking/Ticker.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.ticking; import java.util.ArrayList; diff --git a/src/main/java/ru/windcorp/progressia/server/world/ticking/TickerCoordinator.java b/src/main/java/ru/windcorp/progressia/server/world/ticking/TickerCoordinator.java index 7d58d6d..d4a9bba 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ticking/TickerCoordinator.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ticking/TickerCoordinator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.ticking; import java.util.ArrayList; @@ -41,8 +41,7 @@ import ru.windcorp.progressia.server.Server; /** * Central control point for serverside ticking. This class provides an - * interface to - * interact with Tickers. + * interface to interact with Tickers. * * @author javapony */ @@ -66,8 +65,7 @@ public class TickerCoordinator { /** * All tasks that must be {@linkplain TickerTask#dispose() disposed of} at - * the end of the current - * tick. This list must be empty when not in + * the end of the current tick. This list must be empty when not in * {@link #runPassStage(Collection, String)}. */ private final Collection toDispose = new ArrayList<>(INITIAL_QUEUE_SIZE); @@ -152,7 +150,7 @@ public class TickerCoordinator { public double getTPS() { return 1 / tickLength; } - + public long getUptimeTicks() { return ticks; } @@ -168,7 +166,7 @@ public class TickerCoordinator { tickStart = System.currentTimeMillis(); } - + private void onTickEnd() { ticks++; } @@ -191,7 +189,7 @@ public class TickerCoordinator { logger.debug("Pass complete"); passes++; } - + onTickEnd(); logger.debug("Tick complete; run {} passes", passes); @@ -218,11 +216,8 @@ public class TickerCoordinator { runPassStage(pendingChanges, "CHANGE"); } - private synchronized void runPassStage( - Collection tasks, - String stageName - ) - throws InterruptedException { + private synchronized void runPassStage(Collection tasks, String stageName) + throws InterruptedException { if (!toDispose.isEmpty()) throw new IllegalStateException("toDispose is not empty: " + toDispose); @@ -238,11 +233,8 @@ public class TickerCoordinator { toDispose.clear(); } - private synchronized void startPassStage( - Collection tasks, - Collection toDispose, - String stageName - ) { + private synchronized void startPassStage(Collection tasks, Collection toDispose, + String stageName) { if (tasks.isEmpty()) { logger.debug("Skipping stage {}: tasks is empty", stageName); return; @@ -269,11 +261,8 @@ public class TickerCoordinator { logger.debug("Stage started"); } - private Collection selectTasks( - Ticker ticker, - Collection tasks, - Collection output - ) { + private Collection selectTasks(Ticker ticker, Collection tasks, + Collection output) { // TODO implement properly for (TickerTask task : tasks) { @@ -319,12 +308,8 @@ public class TickerCoordinator { logger.debug("javahorse kill urself"); } - throw CrashReports.crash( - t, - "Something has gone horribly wrong in server ticker code " - + "(thread %s) and it is (probably) not related to mods or devils.", - thread - ); + throw CrashReports.crash(t, "Something has gone horribly wrong in server ticker code " + + "(thread %s) and it is (probably) not related to mods or devils.", thread); } } diff --git a/src/main/java/ru/windcorp/progressia/server/world/ticking/TickerTask.java b/src/main/java/ru/windcorp/progressia/server/world/ticking/TickerTask.java index 4a075c0..a5f9738 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ticking/TickerTask.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ticking/TickerTask.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.ticking; import glm.vec._3.i.Vec3i; @@ -23,11 +23,10 @@ import ru.windcorp.progressia.common.world.Coordinates; import ru.windcorp.progressia.server.Server; /** - * A task that can be executed by a Ticker. - * This is a superinterface for {@link Change} and {@link Evaluation} and is not - * meant to be extended further. - * This interface is used to determine the Ticker that is suitable for the - * execution of this task. + * A task that can be executed by a Ticker. This is a superinterface for + * {@link Change} and {@link Evaluation} and is not meant to be extended + * further. This interface is used to determine the Ticker that is suitable for + * the execution of this task. * * @author javapony */ @@ -35,8 +34,8 @@ public abstract class TickerTask { /** * Returns {@code false} iff this task is thread-safe and may be executed by - * any Ticker. If and only if a task returns {@code true} in this method - * is its {@link #getRelevantChunk(Vec3i)} method invoked. + * any Ticker. If and only if a task returns {@code true} in this method is + * its {@link #getRelevantChunk(Vec3i)} method invoked. * * @implNote Default implementation returns {@code true}, making this task * thread-sensitive @@ -49,18 +48,18 @@ public abstract class TickerTask { /** * Sets {@code output} to be equal to the {@linkplain Coordinates#chunk - * coordinates of chunk} - * of the chunk that must be owned by the Ticker will execute this task. - * This method - * is not invoked iff {@link #isThreadSensitive()} returned {@code false}. + * coordinates of chunk} of the chunk that must be owned by the Ticker will + * execute this task. This method is not invoked iff + * {@link #isThreadSensitive()} returned {@code false}. * - * @param output a {@link Vec3i} to set to the requested value + * @param output + * a {@link Vec3i} to set to the requested value */ public abstract void getRelevantChunk(Vec3i output); /** - * Invoked when this task has completed and will no longer be used. - * This method is guaranteed to be invoked in the main server thread. + * Invoked when this task has completed and will no longer be used. This + * method is guaranteed to be invoked in the main server thread. * * @implNote Default implementation does nothing */ @@ -72,7 +71,8 @@ public abstract class TickerTask { * Executes this task. This method is provided for the convenience of * Tickers. * - * @param server the server to run on + * @param server + * the server to run on */ abstract void run(Server server); diff --git a/src/main/java/ru/windcorp/progressia/server/world/ticking/TickingPolicy.java b/src/main/java/ru/windcorp/progressia/server/world/ticking/TickingPolicy.java index a5836fe..87a6fc9 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/ticking/TickingPolicy.java +++ b/src/main/java/ru/windcorp/progressia/server/world/ticking/TickingPolicy.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.ticking; import ru.windcorp.progressia.server.world.block.TickableBlock; @@ -23,27 +23,24 @@ import ru.windcorp.progressia.server.world.tile.TickableTile; /** * Various ticking policies that {@link TickableBlock} or {@link TickableTile} - * can have. - * Ticking policy determines when, and if, the block or tile is ticked. + * can have. Ticking policy determines when, and if, the block or tile is + * ticked. * * @author javapony */ public enum TickingPolicy { /** - * The ticking policy that requests that no ticks happen. - * This is typically used for blocks or tiles that only tick under certain - * conditions, - * which are not meant at the moment. + * The ticking policy that requests that no ticks happen. This is typically + * used for blocks or tiles that only tick under certain conditions, which + * are not meant at the moment. */ NONE, /** * The ticking policy that requests that the object is ticked every server - * tick exactly once. - * This should not be used for objects that only change rarely; consider - * using {@link RANDOM} - * instead. + * tick exactly once. This should not be used for objects that only change + * rarely; consider using {@link RANDOM} instead. */ REGULAR, diff --git a/src/main/java/ru/windcorp/progressia/server/world/tile/HangingTileLogic.java b/src/main/java/ru/windcorp/progressia/server/world/tile/HangingTileLogic.java index 745f289..fdd3a53 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tile/HangingTileLogic.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tile/HangingTileLogic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tile; import ru.windcorp.progressia.server.world.block.BlockLogic; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tile/TSTickContext.java b/src/main/java/ru/windcorp/progressia/server/world/tile/TSTickContext.java index 399f7b8..0e746ca 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tile/TSTickContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tile/TSTickContext.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tile; import java.util.Objects; @@ -71,7 +71,7 @@ public interface TSTickContext extends BlockTickContext { default TileTickContext forLayer(int layer) { return TickContextMutable.start().withServer(getServer()).withBlock(getBlockInWorld()).withFace(getFace()) - .withLayer(layer); + .withLayer(layer); } default boolean forEachTile(Consumer action) { @@ -90,10 +90,8 @@ public interface TSTickContext extends BlockTickContext { } default TSTickContext getComplementary() { - return TickContextMutable.copyWorld(this) - .withBlock(getBlockInWorld().add_(getFace().getVector())) - .withFace(getFace().getCounter()) - .build(); + return TickContextMutable.copyWorld(this).withBlock(getBlockInWorld().add_(getFace().getVector())) + .withFace(getFace().getCounter()).build(); } default R evalComplementary(Function action) { diff --git a/src/main/java/ru/windcorp/progressia/server/world/tile/TickableTile.java b/src/main/java/ru/windcorp/progressia/server/world/tile/TickableTile.java index 4def3b0..50a4b15 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tile/TickableTile.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tile/TickableTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tile; import ru.windcorp.progressia.server.world.ticking.TickingPolicy; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogic.java b/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogic.java index 4a97ead..c623999 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogic.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tile; import ru.windcorp.progressia.common.util.namespaces.Namespaced; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogicRegistry.java b/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogicRegistry.java index d8bceaf..cc0fca6 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogicRegistry.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogicRegistry.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tile; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogicStack.java b/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogicStack.java index 5e91963..ce94cfc 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogicStack.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tile/TileLogicStack.java @@ -15,15 +15,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tile; import ru.windcorp.progressia.common.world.generic.GenericTileStack; import ru.windcorp.progressia.common.world.tile.TileDataStack; import ru.windcorp.progressia.server.world.ChunkLogic; -public abstract class TileLogicStack - extends GenericTileStack { +public abstract class TileLogicStack extends GenericTileStack { public abstract TileDataStack getData(); diff --git a/src/main/java/ru/windcorp/progressia/server/world/tile/TileTickContext.java b/src/main/java/ru/windcorp/progressia/server/world/tile/TileTickContext.java index 45f41ec..69dc77d 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tile/TileTickContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tile/TileTickContext.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tile; import ru.windcorp.progressia.common.world.tile.TileData; diff --git a/src/main/java/ru/windcorp/progressia/server/world/tile/UpdateableTile.java b/src/main/java/ru/windcorp/progressia/server/world/tile/UpdateableTile.java index bf114fa..0a5aca5 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/tile/UpdateableTile.java +++ b/src/main/java/ru/windcorp/progressia/server/world/tile/UpdateableTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.server.world.tile; public interface UpdateableTile { diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java index 3cc0e9c..729d857 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java @@ -53,8 +53,9 @@ public class TestEntityLogicFallingBlock extends EntityLogic { return; } - //LogManager.getLogger().info("NotNull "+entity.toString()+" "+String.valueOf(entity!=null) + " " + - //context.toString()); + // LogManager.getLogger().info("NotNull "+entity.toString()+" + // "+String.valueOf(entity!=null) + " " + + // context.toString()); super.tick(entity, context); // friction @@ -66,13 +67,13 @@ public class TestEntityLogicFallingBlock extends EntityLogic { TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld() .getData().getEntity(entity.getEntityId()); // ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); // fallBlock = (TestEntityDataFallingBlock) entity; - - //LogManager.getLogger().info("NotNull FB "+String.valueOf(fallBlock!=null)); - if (fallBlock==null) - { + + // LogManager.getLogger().info("NotNull FB + // "+String.valueOf(fallBlock!=null)); + if (fallBlock == null) { return; } - + if (fallBlock.isDone() || !context.getWorld().isBlockLoaded(fallBlock.getBlockInWorld(null))) { return; } @@ -101,14 +102,15 @@ public class TestEntityLogicFallingBlock extends EntityLogic { // "+String.valueOf(occupiedBlock.z)); // LogManager.getLogger().info("Block is of type " + // context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); - - if (context.getWorldData().isBlockLoaded(occupiedBlock) && context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId() != "Test:Air") { + + if (context.getWorldData().isBlockLoaded(occupiedBlock) + && context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId() != "Test:Air") { LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x)); // ClientState.getInstance().getWorld().getData().setBlock(occupiedBlock, // fallBlock.getBlock(),true); context.getAccessor().setBlock(occupiedBlock, fallBlock.getBlock()); fallBlock.setInvisible(); // Until I know how to properly delete it. - ClientState.getInstance().getWorld().getData().removeEntity(entity.getEntityId());//context.getWorldData().removeEntity(entity.getEntityId()); + ClientState.getInstance().getWorld().getData().removeEntity(entity.getEntityId());// context.getWorldData().removeEntity(entity.getEntityId()); } } } diff --git a/src/main/java/ru/windcorp/progressia/test/gen/TestTerrainGenerator.java b/src/main/java/ru/windcorp/progressia/test/gen/TestTerrainGenerator.java index c4f5ec7..851845a 100644 --- a/src/main/java/ru/windcorp/progressia/test/gen/TestTerrainGenerator.java +++ b/src/main/java/ru/windcorp/progressia/test/gen/TestTerrainGenerator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test.gen; import kdotjpg.opensimplex2.areagen.OpenSimplex2S; @@ -34,45 +34,13 @@ class TestTerrainGenerator { public TestTerrainGenerator(TestWorldGenerator testWorldGenerator, WorldLogic world) { this.noise = new OpenSimplex2S("We're getting somewhere".hashCode()); - Func2D plainsHeight = tweak( - octaves( - tweak(primitive(), 0.01, 0.5), - 2, - 3 - ), - 1, - 0.2, - 0.2 - ); + Func2D plainsHeight = tweak(octaves(tweak(primitive(), 0.01, 0.5), 2, 3), 1, 0.2, 0.2); - Func2D mountainsHeight = tweak( - octaves( - ridge(tweak(primitive(), 0.01, 1)), - 2, - 1.5, - 12 - ), - 1, - 3 - ); + Func2D mountainsHeight = tweak(octaves(ridge(tweak(primitive(), 0.01, 1)), 2, 1.5, 12), 1, 3); - Func2D mountainousity = tweak( - octaves( - tweak(primitive(), 0.007, 1), - 2, - 3 - ), - 1, - 1, - -0.25 - ); + Func2D mountainousity = tweak(octaves(tweak(primitive(), 0.007, 1), 2, 3), 1, 1, -0.25); - shape = tweak( - add(multiply(squash(mountainousity, 10), mountainsHeight), plainsHeight), - 0.001, - 1000, - 0 - ); + shape = tweak(add(multiply(squash(mountainousity, 10), mountainsHeight), plainsHeight), 0.001, 1000, 0); } public void compute(int startX, int startY, double[][] heightMap, double[][] slopeMap) { diff --git a/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java b/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java index 8ce6e45..96213fe 100644 --- a/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java +++ b/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java @@ -63,16 +63,16 @@ public class TestWorldGenerator extends AbstractWorldGenerator { public void onChunkBlockChanged(ChunkData chunk, Vec3i blockInChunk, BlockData previous, BlockData current) { Vec3i chunkWorldPos = chunk.getPosition().mul_(16).add_(blockInChunk); - - if (TestEntityLogicFallingBlock.FallingBlocks.contains(chunk.getWorld() - .getBlock(chunkWorldPos.add_(0, 0, 1)).getId())) { - chunk.getWorld().setBlock(chunkWorldPos.add_(0, 0, 1), BlockDataRegistry.getInstance().get(chunk.getWorld().getBlock(chunkWorldPos.add_(0,0,1)).getId()), true); + + if (TestEntityLogicFallingBlock.FallingBlocks + .contains(chunk.getWorld().getBlock(chunkWorldPos.add_(0, 0, 1)).getId())) { + chunk.getWorld().setBlock(chunkWorldPos.add_(0, 0, 1), BlockDataRegistry.getInstance() + .get(chunk.getWorld().getBlock(chunkWorldPos.add_(0, 0, 1)).getId()), true); } if (!TestEntityLogicFallingBlock.FallingBlocks.contains(current.getId())) { return; } - if (chunk.getWorld().getBlock(chunkWorldPos.add_(0, 0, -1)) - .getId() == "Test:Air") { + if (chunk.getWorld().getBlock(chunkWorldPos.add_(0, 0, -1)).getId() == "Test:Air") { LogManager.getLogger().info("Inserting FallingBlock"); TestEntityDataFallingBlock fallingBlock = new TestEntityDataFallingBlock(); @@ -87,7 +87,7 @@ public class TestWorldGenerator extends AbstractWorldGenerator { chunk.getWorld().addEntity(fallingBlock); chunk.setBlock(blockInChunk, previous, false); - + LogManager.getLogger().info(String.valueOf(chunkWorldPos.x) + " " + String.valueOf(chunkWorldPos.y) + " " + String.valueOf(chunkWorldPos.z)); }