Compare commits
15 Commits
falling-sa
...
newtps
Author | SHA1 | Date | |
---|---|---|---|
a984333c3a | |||
4a1f1b7545 | |||
af7b39d8e9 | |||
a0acd16008 | |||
330ed1ab9b | |||
7e852ff05f | |||
6e1b0e3f69 | |||
411780b120 | |||
5359b93738 | |||
f9aae94bbc | |||
5c57a57e9a | |||
468b6dc327 | |||
69942ad17b | |||
3c74a808f3 | |||
8327fcfd19 |
@ -1,69 +0,0 @@
|
|||||||
# Contributing Guidelines
|
|
||||||
|
|
||||||
This document lists conventions adopted by Progressia developers.
|
|
||||||
|
|
||||||
## git
|
|
||||||
|
|
||||||
### Branches
|
|
||||||
Progressia repository contains a `master` branch and several "feature" branches.
|
|
||||||
|
|
||||||
`master` is expected to contain a version of the game suitable for demonstration and forking/branching. Do not commit directly to `master` without OLEGSHA's approval.
|
|
||||||
- `master` must always correctly build without compiler warnings (see below).
|
|
||||||
- `master` must always pass all unit tests.
|
|
||||||
- `master` must always be able to launch successfully.
|
|
||||||
- `master` must always only contain working features.
|
|
||||||
- `master` should not contain excessive debug code.
|
|
||||||
- `master` must always have its code and filenames formatted (see below).
|
|
||||||
|
|
||||||
"Feature" branches are branches dedicated to the development of a single feature. When the feature reaches completion the branch is merged into `master` and removed. Intermediate merges into `master` may occur when some fitting milestone is reached. Intermediate merges from `master` may be done as necessary. Merges between "feature" branches should generally be avoided.
|
|
||||||
|
|
||||||
When beginning work on a new feature, create a new branch based on `master` (or on another "feature" branch if absolutely necessary). Use `all-small-with-dashes` to name the branch: `add-trees` or `rebalance-plastics` are good names. Do not fix unrelated bugs or work on unrelated features in a "feature" branch - create a new one, switch to an existing one or commit directly to `master` if the changes are small enough.
|
|
||||||
|
|
||||||
"Feature" branches may not be formatted properly. Formatting is required before merging into `master` or other branches.
|
|
||||||
|
|
||||||
### Commits
|
|
||||||
- Commits must leave the branch in a state that builds without compiler warnings (see below).
|
|
||||||
- Changes should be grouped in commits semantically. Avoid committing many small related changes in sequence; if necessary, wait and accumulate them. Avoid committing unrelated changes together; if necessary, split staged changes into several commits. This should normally result in about 1-2 commits for a day's work.
|
|
||||||
- Commit bulk changes (renaming, formatting, ...) separately. Don't ever commit whitespace changes outside formatting commits.
|
|
||||||
- Message format:
|
|
||||||
|
|
||||||
```
|
|
||||||
Short description of changes
|
|
||||||
<empty line>
|
|
||||||
- Enumeration of changes
|
|
||||||
- Nest when appropriate
|
|
||||||
- Use dashes only
|
|
||||||
- List not needed for small commits
|
|
||||||
```
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```
|
|
||||||
Changed packages for relations, renamed Face to ShapePart
|
|
||||||
|
|
||||||
- Added BlockRelation as an abstract superclass to existing relations
|
|
||||||
- Must be given an absolute "up" direction before use
|
|
||||||
- Moved AbsFace, AbsRelation and BlockRelation to .world.rels
|
|
||||||
- Renamed Face to ShapePart to reduce confusion with AbsFace
|
|
||||||
```
|
|
||||||
|
|
||||||
- Only commit changes described in the commit message. Please double-check staged files before committing.
|
|
||||||
- Avoid merge conflicts. Pull before committing.
|
|
||||||
- Better sign commits than not. See: [git](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work), [GitHub](https://docs.github.com/en/github/authenticating-to-github/managing-commit-signature-verification).
|
|
||||||
|
|
||||||
## Code
|
|
||||||
|
|
||||||
### Warnings
|
|
||||||
Make sure that all committed code contains no compiler warnings. This specifically includes unused imports, unused private members, missing `@Override`s and warnings related to generics.
|
|
||||||
|
|
||||||
Warnings about unknown tokens in `@SuppressWarnings` are temporarily ignored. Please disable them in your IDE.
|
|
||||||
|
|
||||||
### Code Style
|
|
||||||
Formatting code is important.
|
|
||||||
|
|
||||||
- The format is specified within the files inside `/templates_and_presets/eclipse_ide`. Import the specifications into Eclipse or IntelliJ IDEA and use the IDEs' format feature. Alternatively format the code manually in accordance with existing files.
|
|
||||||
- Only use tabs for indentation. Never indent with spaces even when wrapping lines. This is to ensure that indentation does not break when tab width is different.
|
|
||||||
- Don't use `I` prefix for interfaces (not `IDoable` but `Doable`).
|
|
||||||
- Prioritize readability over compactness. Do not hesitate to use (very) long identifiers if they aid comprehension.
|
|
||||||
- Document all mathematics unless it is trivial, especially when using math notation for variable names.
|
|
||||||
- Use proper English when writing comments. Avoid boxes in comments. Use `//` for single-line comments.
|
|
@ -45,7 +45,7 @@ public class OpenSimplex2S {
|
|||||||
source[i] = i;
|
source[i] = i;
|
||||||
for (int i = PSIZE - 1; i >= 0; i--) {
|
for (int i = PSIZE - 1; i >= 0; i--) {
|
||||||
seed = seed * 6364136223846793005L + 1442695040888963407L;
|
seed = seed * 6364136223846793005L + 1442695040888963407L;
|
||||||
int r = (int) ((seed + 31) % (i + 1));
|
int r = (int)((seed + 31) % (i + 1));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
r += (i + 1);
|
r += (i + 1);
|
||||||
perm[i] = source[r];
|
perm[i] = source[r];
|
||||||
@ -72,9 +72,9 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2D SuperSimplex noise, with Y pointing down the main diagonal. Might be
|
* 2D SuperSimplex noise, with Y pointing down the main diagonal.
|
||||||
* better for a 2D sandbox style game, where Y is vertical. Probably
|
* Might be better for a 2D sandbox style game, where Y is vertical.
|
||||||
* slightly less optimal for heightmaps or continent maps.
|
* Probably slightly less optimal for heightmaps or continent maps.
|
||||||
*/
|
*/
|
||||||
public double noise2_XBeforeY(double x, double y) {
|
public double noise2_XBeforeY(double x, double y) {
|
||||||
|
|
||||||
@ -86,8 +86,8 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2D SuperSimplex noise base. Lookup table implementation inspired by
|
* 2D SuperSimplex noise base.
|
||||||
* DigitalShadow.
|
* Lookup table implementation inspired by DigitalShadow.
|
||||||
*/
|
*/
|
||||||
private double noise2_Base(double xs, double ys) {
|
private double noise2_Base(double xs, double ys) {
|
||||||
double value = 0;
|
double value = 0;
|
||||||
@ -97,8 +97,11 @@ public class OpenSimplex2S {
|
|||||||
double xsi = xs - xsb, ysi = ys - ysb;
|
double xsi = xs - xsb, ysi = ys - ysb;
|
||||||
|
|
||||||
// Index to point list
|
// Index to point list
|
||||||
int a = (int) (xsi + ysi);
|
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 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 ssi = (xsi + ysi) * -0.211324865405187;
|
||||||
double xi = xsi + ssi, yi = ysi + ssi;
|
double xi = xsi + ssi, yi = ysi + ssi;
|
||||||
@ -109,8 +112,7 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
double dx = xi + c.dx, dy = yi + c.dy;
|
double dx = xi + c.dx, dy = yi + c.dy;
|
||||||
double attn = 2.0 / 3.0 - dx * dx - dy * dy;
|
double attn = 2.0 / 3.0 - dx * dx - dy * dy;
|
||||||
if (attn <= 0)
|
if (attn <= 0) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK;
|
int pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK;
|
||||||
Grad2 grad = permGrad2[perm[pxm] ^ pym];
|
Grad2 grad = permGrad2[perm[pxm] ^ pym];
|
||||||
@ -124,16 +126,15 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 3D Re-oriented 8-point BCC noise, classic orientation Proper substitute
|
* 3D Re-oriented 8-point BCC noise, classic orientation
|
||||||
* for what 3D SuperSimplex would be, in light of Forbidden Formulae. Use
|
* Proper substitute for what 3D SuperSimplex would be,
|
||||||
* noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate.
|
* in light of Forbidden Formulae.
|
||||||
|
* Use noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate.
|
||||||
*/
|
*/
|
||||||
public double noise3_Classic(double x, double y, double z) {
|
public double noise3_Classic(double x, double y, double z) {
|
||||||
|
|
||||||
// Re-orient the cubic lattices via rotation, to produce the expected
|
// Re-orient the cubic lattices via rotation, to produce the expected look on cardinal planar slices.
|
||||||
// look on cardinal planar slices.
|
// If texturing objects that don't tend to have cardinal plane faces, you could even remove this.
|
||||||
// If texturing objects that don't tend to have cardinal plane faces,
|
|
||||||
// you could even remove this.
|
|
||||||
// Orthonormal rotation. Not a skew transform.
|
// Orthonormal rotation. Not a skew transform.
|
||||||
double r = (2.0 / 3.0) * (x + y + z);
|
double r = (2.0 / 3.0) * (x + y + z);
|
||||||
double xr = r - x, yr = r - y, zr = r - z;
|
double xr = r - x, yr = r - y, zr = r - z;
|
||||||
@ -144,17 +145,15 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, Y).
|
* 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
|
* Recommended for 3D terrain and time-varied animations.
|
||||||
* should always be the "different" coordinate in your use case. If Y is
|
* The Z coordinate should always be the "different" coordinate in your use case.
|
||||||
* vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use
|
* If Y is vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use noise3_XZBeforeY.
|
||||||
* noise3_XZBeforeY. If Z is vertical in world coordinates, call
|
* If Z is vertical in world coordinates, call noise3_XYBeforeZ(x, y, Z).
|
||||||
* noise3_XYBeforeZ(x, y, Z). For a time varied animation, call
|
* For a time varied animation, call noise3_XYBeforeZ(x, y, T).
|
||||||
* noise3_XYBeforeZ(x, y, T).
|
|
||||||
*/
|
*/
|
||||||
public double noise3_XYBeforeZ(double x, double y, double z) {
|
public double noise3_XYBeforeZ(double x, double y, double z) {
|
||||||
|
|
||||||
// Re-orient the cubic lattices without skewing, to make X and Y
|
// Re-orient the cubic lattices without skewing, to make X and Y triangular like 2D.
|
||||||
// triangular like 2D.
|
|
||||||
// Orthonormal rotation. Not a skew transform.
|
// Orthonormal rotation. Not a skew transform.
|
||||||
double xy = x + y;
|
double xy = x + y;
|
||||||
double s2 = xy * -0.211324865405187;
|
double s2 = xy * -0.211324865405187;
|
||||||
@ -168,23 +167,20 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, Z).
|
* 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
|
* Recommended for 3D terrain and time-varied animations.
|
||||||
* should always be the "different" coordinate in your use case. If Y is
|
* The Y coordinate should always be the "different" coordinate in your use case.
|
||||||
* vertical in world coordinates, call noise3_XZBeforeY(x, Y, z). If Z is
|
* If Y is vertical in world coordinates, call noise3_XZBeforeY(x, Y, z).
|
||||||
* vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use
|
* If Z is vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use noise3_XYBeforeZ.
|
||||||
* noise3_XYBeforeZ. For a time varied animation, call noise3_XZBeforeY(x,
|
* For a time varied animation, call noise3_XZBeforeY(x, T, y) or use noise3_XYBeforeZ.
|
||||||
* T, y) or use noise3_XYBeforeZ.
|
|
||||||
*/
|
*/
|
||||||
public double noise3_XZBeforeY(double x, double y, double z) {
|
public double noise3_XZBeforeY(double x, double y, double z) {
|
||||||
|
|
||||||
// Re-orient the cubic lattices without skewing, to make X and Z
|
// Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D.
|
||||||
// triangular like 2D.
|
|
||||||
// Orthonormal rotation. Not a skew transform.
|
// Orthonormal rotation. Not a skew transform.
|
||||||
double xz = x + z;
|
double xz = x + z;
|
||||||
double s2 = xz * -0.211324865405187;
|
double s2 = xz * -0.211324865405187;
|
||||||
double yy = y * 0.577350269189626;
|
double yy = y * 0.577350269189626;
|
||||||
double xr = x + s2 - yy;
|
double xr = x + s2 - yy; double zr = z + s2 - yy;
|
||||||
double zr = z + s2 - yy;
|
|
||||||
double yr = xz * 0.577350269189626 + yy;
|
double yr = xz * 0.577350269189626 + yy;
|
||||||
|
|
||||||
// Evaluate both lattices to form a BCC lattice.
|
// Evaluate both lattices to form a BCC lattice.
|
||||||
@ -192,10 +188,10 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate overlapping cubic lattices for 3D Re-oriented BCC noise. Lookup
|
* Generate overlapping cubic lattices for 3D Re-oriented BCC noise.
|
||||||
* table implementation inspired by DigitalShadow. It was actually faster to
|
* Lookup table implementation inspired by DigitalShadow.
|
||||||
* narrow down the points in the loop itself, than to build up the index
|
* It was actually faster to narrow down the points in the loop itself,
|
||||||
* with enough info to isolate 8 points.
|
* than to build up the index with enough info to isolate 8 points.
|
||||||
*/
|
*/
|
||||||
private double noise3_BCC(double xr, double yr, double zr) {
|
private double noise3_BCC(double xr, double yr, double zr) {
|
||||||
|
|
||||||
@ -203,11 +199,9 @@ public class OpenSimplex2S {
|
|||||||
int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr);
|
int xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr);
|
||||||
double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb;
|
double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb;
|
||||||
|
|
||||||
// Identify which octant of the cube we're in. This determines which
|
// Identify which octant of the cube we're in. This determines which cell
|
||||||
// cell
|
// in the other cubic lattice we're in, and also narrows down one point on each.
|
||||||
// in the other cubic lattice we're in, and also narrows down one point
|
int xht = (int)(xri + 0.5), yht = (int)(yri + 0.5), zht = (int)(zri + 0.5);
|
||||||
// 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);
|
int index = (xht << 0) | (yht << 1) | (zht << 2);
|
||||||
|
|
||||||
// Point contributions
|
// Point contributions
|
||||||
@ -236,9 +230,9 @@ public class OpenSimplex2S {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the 2D noise over a large area. Propagates by flood-fill instead
|
* Generate the 2D noise over a large area.
|
||||||
* of iterating over a range. Results may occasionally slightly exceed [-1,
|
* Propagates by flood-fill instead of iterating over a range.
|
||||||
* 1] due to the grid-snapped pre-generated kernel.
|
* 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) {
|
public void generate2(GenerateContext2D context, double[][] buffer, int x0, int y0) {
|
||||||
int height = buffer.length;
|
int height = buffer.length;
|
||||||
@ -247,12 +241,11 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the 2D noise over a large area. Propagates by flood-fill instead
|
* Generate the 2D noise over a large area.
|
||||||
* of iterating over a range. Results may occasionally slightly exceed [-1,
|
* Propagates by flood-fill instead of iterating over a range.
|
||||||
* 1] due to the grid-snapped pre-generated kernel.
|
* 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,
|
public void generate2(GenerateContext2D context, double[][] buffer, int x0, int y0, int width, int height, int skipX, int skipY) {
|
||||||
int skipX, int skipY) {
|
|
||||||
Queue<AreaGenLatticePoint2D> queue = new LinkedList<AreaGenLatticePoint2D>();
|
Queue<AreaGenLatticePoint2D> queue = new LinkedList<AreaGenLatticePoint2D>();
|
||||||
Set<AreaGenLatticePoint2D> seen = new HashSet<AreaGenLatticePoint2D>();
|
Set<AreaGenLatticePoint2D> seen = new HashSet<AreaGenLatticePoint2D>();
|
||||||
|
|
||||||
@ -267,19 +260,16 @@ public class OpenSimplex2S {
|
|||||||
// - Much faster than computing the kernel equation every time.
|
// - Much faster than computing the kernel equation every time.
|
||||||
// You can remove these lines if you find it's the opposite for you.
|
// You can remove these lines if you find it's the opposite for you.
|
||||||
// You'll have to double the bounds again in GenerateContext2D
|
// 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++) {
|
for (int yy = 0; yy < scaledRadiusY; yy++) {
|
||||||
kernel[2 * scaledRadiusY - yy - 1] = kernel[yy] = (double[]) context.kernel[yy].clone();
|
kernel[2 * scaledRadiusY - yy - 1] = kernel[yy] = (double[]) context.kernel[yy].clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get started with one point/vertex.
|
// Get started with one point/vertex.
|
||||||
// For some lattices, you might need to try a handful of points in the
|
// For some lattices, you might need to try a handful of points in the cell,
|
||||||
// cell,
|
// or flip a couple of coordinates, to guarantee it or a neighbor contributes.
|
||||||
// or flip a couple of coordinates, to guarantee it or a neighbor
|
|
||||||
// contributes.
|
|
||||||
// For An* lattices, the base coordinate seems fine.
|
// For An* lattices, the base coordinate seems fine.
|
||||||
double x0f = x0Skipped * context.xFrequency;
|
double x0f = x0Skipped * context.xFrequency; double y0f = y0Skipped * context.yFrequency;
|
||||||
double y0f = y0Skipped * context.yFrequency;
|
|
||||||
double x0s = context.orientation.s00 * x0f + context.orientation.s01 * y0f;
|
double x0s = context.orientation.s00 * x0f + context.orientation.s01 * y0f;
|
||||||
double y0s = context.orientation.s10 * x0f + context.orientation.s11 * y0f;
|
double y0s = context.orientation.s10 * x0f + context.orientation.s11 * y0f;
|
||||||
int x0sb = fastFloor(x0s), y0sb = fastFloor(y0s);
|
int x0sb = fastFloor(x0s), y0sb = fastFloor(y0s);
|
||||||
@ -297,16 +287,11 @@ public class OpenSimplex2S {
|
|||||||
Grad2 grad = context.orientation.gradients[perm[perm[pxm] ^ pym]];
|
Grad2 grad = context.orientation.gradients[perm[perm[pxm] ^ pym]];
|
||||||
double gx = grad.dx * context.xFrequency;
|
double gx = grad.dx * context.xFrequency;
|
||||||
double gy = grad.dy * context.yFrequency;
|
double gy = grad.dy * context.yFrequency;
|
||||||
double gOff = 0.5 * (gx + gy); // to correct for (0.5, 0.5)-offset
|
double gOff = 0.5 * (gx + gy); // to correct for (0.5, 0.5)-offset kernel
|
||||||
// kernel
|
|
||||||
|
|
||||||
// Contribution kernel bounds
|
// Contribution kernel bounds
|
||||||
int yy0 = destPointY - scaledRadiusY;
|
int yy0 = destPointY - scaledRadiusY; if (yy0 < y0Skipped) yy0 = y0Skipped;
|
||||||
if (yy0 < y0Skipped)
|
int yy1 = destPointY + scaledRadiusY; if (yy1 > y0 + height) yy1 = y0 + height;
|
||||||
yy0 = y0Skipped;
|
|
||||||
int yy1 = destPointY + scaledRadiusY;
|
|
||||||
if (yy1 > y0 + height)
|
|
||||||
yy1 = y0 + height;
|
|
||||||
|
|
||||||
// For each row of the contribution circle,
|
// For each row of the contribution circle,
|
||||||
for (int yy = yy0; yy < yy1; yy++) {
|
for (int yy = yy0; yy < yy1; yy++) {
|
||||||
@ -315,22 +300,16 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
// Set up bounds so we only loop over what we need to
|
// Set up bounds so we only loop over what we need to
|
||||||
int thisScaledRadiusX = context.kernelBounds[ky];
|
int thisScaledRadiusX = context.kernelBounds[ky];
|
||||||
int xx0 = destPointX - thisScaledRadiusX;
|
int xx0 = destPointX - thisScaledRadiusX; if (xx0 < x0Skipped) xx0 = x0Skipped;
|
||||||
if (xx0 < x0Skipped)
|
int xx1 = destPointX + thisScaledRadiusX; if (xx1 > x0 + width) xx1 = x0 + width;
|
||||||
xx0 = x0Skipped;
|
|
||||||
int xx1 = destPointX + thisScaledRadiusX;
|
|
||||||
if (xx1 > x0 + width)
|
|
||||||
xx1 = x0 + width;
|
|
||||||
|
|
||||||
// For each point on that row
|
// For each point on that row
|
||||||
for (int xx = xx0; xx < xx1; xx++) {
|
for (int xx = xx0; xx < xx1; xx++) {
|
||||||
int dx = xx - destPointX;
|
int dx = xx - destPointX;
|
||||||
int kx = dx + scaledRadiusX;
|
int kx = dx + scaledRadiusX;
|
||||||
|
|
||||||
// gOff accounts for our choice to offset the pre-generated
|
// gOff accounts for our choice to offset the pre-generated kernel by (0.5, 0.5) to avoid the zero center.
|
||||||
// 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)
|
||||||
// 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;
|
double extrapolation = gx * dx + gy * dy + gOff;
|
||||||
buffer[yy - y0][xx - x0] += kernel[ky][kx] * extrapolation;
|
buffer[yy - y0][xx - x0] += kernel[ky][kx] * extrapolation;
|
||||||
|
|
||||||
@ -339,14 +318,13 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
// For each neighbor of the point
|
// For each neighbor of the point
|
||||||
for (int i = 0; i < NEIGHBOR_MAP_2D.length; i++) {
|
for (int i = 0; i < NEIGHBOR_MAP_2D.length; i++) {
|
||||||
AreaGenLatticePoint2D neighbor = new AreaGenLatticePoint2D(context, point.xsv + NEIGHBOR_MAP_2D[i][0],
|
AreaGenLatticePoint2D neighbor = new AreaGenLatticePoint2D(context,
|
||||||
point.ysv + NEIGHBOR_MAP_2D[i][1]);
|
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 it's in range of the buffer region and not seen before
|
||||||
if (neighbor.destPointX + scaledRadiusX >= x0Skipped
|
if (neighbor.destPointX + scaledRadiusX >= x0Skipped && neighbor.destPointX - scaledRadiusX <= x0 + width - 1
|
||||||
&& neighbor.destPointX - scaledRadiusX <= x0 + width - 1
|
&& neighbor.destPointY + scaledRadiusY >= y0Skipped && neighbor.destPointY - scaledRadiusY <= y0 + height - 1
|
||||||
&& neighbor.destPointY + scaledRadiusY >= y0Skipped
|
&& !seen.contains(neighbor)) {
|
||||||
&& neighbor.destPointY - scaledRadiusY <= y0 + height - 1 && !seen.contains(neighbor)) {
|
|
||||||
|
|
||||||
// Add it to the queue so we can process it at some point
|
// Add it to the queue so we can process it at some point
|
||||||
queue.add(neighbor);
|
queue.add(neighbor);
|
||||||
@ -359,9 +337,9 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the 3D noise over a large area/volume. Propagates by flood-fill
|
* Generate the 3D noise over a large area/volume.
|
||||||
* instead of iterating over a range. Results may occasionally slightly
|
* Propagates by flood-fill instead of iterating over a range.
|
||||||
* exceed [-1, 1] due to the grid-snapped pre-generated kernel.
|
* 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) {
|
public void generate3(GenerateContext3D context, double[][][] buffer, int x0, int y0, int z0) {
|
||||||
int depth = buffer.length;
|
int depth = buffer.length;
|
||||||
@ -371,12 +349,11 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the 3D noise over a large area/volume. Propagates by flood-fill
|
* Generate the 3D noise over a large area/volume.
|
||||||
* instead of iterating over a range. Results may occasionally slightly
|
* Propagates by flood-fill instead of iterating over a range.
|
||||||
* exceed [-1, 1] due to the grid-snapped pre-generated kernel.
|
* 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,
|
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) {
|
||||||
int depth, int skipX, int skipY, int skipZ) {
|
|
||||||
Queue<AreaGenLatticePoint3D> queue = new LinkedList<AreaGenLatticePoint3D>();
|
Queue<AreaGenLatticePoint3D> queue = new LinkedList<AreaGenLatticePoint3D>();
|
||||||
Set<AreaGenLatticePoint3D> seen = new HashSet<AreaGenLatticePoint3D>();
|
Set<AreaGenLatticePoint3D> seen = new HashSet<AreaGenLatticePoint3D>();
|
||||||
|
|
||||||
@ -388,10 +365,8 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
// Quaternion multiplication for rotation.
|
// Quaternion multiplication for rotation.
|
||||||
// https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/
|
// 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,
|
double qx = context.orientation.qx, qy = context.orientation.qy, qz = context.orientation.qz, qw = context.orientation.qw;
|
||||||
qw = context.orientation.qw;
|
double x0f = x0Skipped * context.xFrequency, y0f = y0Skipped * context.yFrequency, z0f = z0Skipped * context.zFrequency;
|
||||||
double x0f = x0Skipped * context.xFrequency, y0f = y0Skipped * context.yFrequency,
|
|
||||||
z0f = z0Skipped * context.zFrequency;
|
|
||||||
double tx = 2 * (qy * z0f - qz * y0f);
|
double tx = 2 * (qy * z0f - qz * y0f);
|
||||||
double ty = 2 * (qz * x0f - qx * z0f);
|
double ty = 2 * (qz * x0f - qx * z0f);
|
||||||
double tz = 2 * (qx * y0f - qy * x0f);
|
double tz = 2 * (qx * y0f - qy * x0f);
|
||||||
@ -417,16 +392,11 @@ public class OpenSimplex2S {
|
|||||||
double gx = grad.dx * context.xFrequency;
|
double gx = grad.dx * context.xFrequency;
|
||||||
double gy = grad.dy * context.yFrequency;
|
double gy = grad.dy * context.yFrequency;
|
||||||
double gz = grad.dz * context.zFrequency;
|
double gz = grad.dz * context.zFrequency;
|
||||||
double gOff = 0.5 * (gx + gy + gz); // to correct for (0.5, 0.5,
|
double gOff = 0.5 * (gx + gy + gz); // to correct for (0.5, 0.5, 0.5)-offset kernel
|
||||||
// 0.5)-offset kernel
|
|
||||||
|
|
||||||
// Contribution kernel bounds.
|
// Contribution kernel bounds.
|
||||||
int zz0 = destPointZ - scaledRadiusZ;
|
int zz0 = destPointZ - scaledRadiusZ; if (zz0 < z0Skipped) zz0 = z0Skipped;
|
||||||
if (zz0 < z0Skipped)
|
int zz1 = destPointZ + scaledRadiusZ; if (zz1 > z0 + depth) zz1 = z0 + depth;
|
||||||
zz0 = z0Skipped;
|
|
||||||
int zz1 = destPointZ + scaledRadiusZ;
|
|
||||||
if (zz1 > z0 + depth)
|
|
||||||
zz1 = z0 + depth;
|
|
||||||
|
|
||||||
// For each x/y slice of the contribution sphere,
|
// For each x/y slice of the contribution sphere,
|
||||||
for (int zz = zz0; zz < zz1; zz++) {
|
for (int zz = zz0; zz < zz1; zz++) {
|
||||||
@ -435,12 +405,8 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
// Set up bounds so we only loop over what we need to
|
// Set up bounds so we only loop over what we need to
|
||||||
int thisScaledRadiusY = context.kernelBoundsY[kz];
|
int thisScaledRadiusY = context.kernelBoundsY[kz];
|
||||||
int yy0 = destPointY - thisScaledRadiusY;
|
int yy0 = destPointY - thisScaledRadiusY; if (yy0 < y0Skipped) yy0 = y0Skipped;
|
||||||
if (yy0 < y0Skipped)
|
int yy1 = destPointY + thisScaledRadiusY; if (yy1 > y0 + height) yy1 = y0 + height;
|
||||||
yy0 = y0Skipped;
|
|
||||||
int yy1 = destPointY + thisScaledRadiusY;
|
|
||||||
if (yy1 > y0 + height)
|
|
||||||
yy1 = y0 + height;
|
|
||||||
|
|
||||||
// For each row of the contribution circle,
|
// For each row of the contribution circle,
|
||||||
for (int yy = yy0; yy < yy1; yy++) {
|
for (int yy = yy0; yy < yy1; yy++) {
|
||||||
@ -449,21 +415,15 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
// Set up bounds so we only loop over what we need to
|
// Set up bounds so we only loop over what we need to
|
||||||
int thisScaledRadiusX = context.kernelBoundsX[kz][ky];
|
int thisScaledRadiusX = context.kernelBoundsX[kz][ky];
|
||||||
int xx0 = destPointX - thisScaledRadiusX;
|
int xx0 = destPointX - thisScaledRadiusX; if (xx0 < x0Skipped) xx0 = x0Skipped;
|
||||||
if (xx0 < x0Skipped)
|
int xx1 = destPointX + thisScaledRadiusX; if (xx1 > x0 + width) xx1 = x0 + width;
|
||||||
xx0 = x0Skipped;
|
|
||||||
int xx1 = destPointX + thisScaledRadiusX;
|
|
||||||
if (xx1 > x0 + width)
|
|
||||||
xx1 = x0 + width;
|
|
||||||
|
|
||||||
// For each point on that row
|
// For each point on that row
|
||||||
for (int xx = xx0; xx < xx1; xx++) {
|
for (int xx = xx0; xx < xx1; xx++) {
|
||||||
int dx = xx - destPointX;
|
int dx = xx - destPointX;
|
||||||
int kx = dx + scaledRadiusX;
|
int kx = dx + scaledRadiusX;
|
||||||
|
|
||||||
// gOff accounts for our choice to offset the
|
// gOff accounts for our choice to offset the pre-generated kernel by (0.5, 0.5, 0.5) to avoid the zero center.
|
||||||
// pre-generated kernel by (0.5, 0.5, 0.5) to avoid the
|
|
||||||
// zero center.
|
|
||||||
double extrapolation = gx * dx + gy * dy + gz * dz + gOff;
|
double extrapolation = gx * dx + gy * dy + gz * dz + gOff;
|
||||||
buffer[zz - z0][yy - y0][xx - x0] += kernel[kz][ky][kx] * extrapolation;
|
buffer[zz - z0][yy - y0][xx - x0] += kernel[kz][ky][kx] * extrapolation;
|
||||||
|
|
||||||
@ -475,16 +435,13 @@ public class OpenSimplex2S {
|
|||||||
for (int i = 0; i < NEIGHBOR_MAP_3D[0].length; i++) {
|
for (int i = 0; i < NEIGHBOR_MAP_3D[0].length; i++) {
|
||||||
int l = point.lattice;
|
int l = point.lattice;
|
||||||
AreaGenLatticePoint3D neighbor = new AreaGenLatticePoint3D(context,
|
AreaGenLatticePoint3D neighbor = new AreaGenLatticePoint3D(context,
|
||||||
point.xsv + NEIGHBOR_MAP_3D[l][i][0], point.ysv + NEIGHBOR_MAP_3D[l][i][1],
|
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.zsv + NEIGHBOR_MAP_3D[l][i][2], 1 ^ l);
|
|
||||||
|
|
||||||
// If it's in range of the buffer region and not seen before
|
// If it's in range of the buffer region and not seen before
|
||||||
if (neighbor.destPointX + scaledRadiusX >= x0Skipped
|
if (neighbor.destPointX + scaledRadiusX >= x0Skipped && neighbor.destPointX - scaledRadiusX <= x0 + width - 1
|
||||||
&& neighbor.destPointX - scaledRadiusX <= x0 + width - 1
|
&& neighbor.destPointY + scaledRadiusY >= y0Skipped && neighbor.destPointY - scaledRadiusY <= y0 + height - 1
|
||||||
&& neighbor.destPointY + scaledRadiusY >= y0Skipped
|
&& neighbor.destPointZ + scaledRadiusZ >= z0Skipped && neighbor.destPointZ - scaledRadiusZ <= z0 + depth - 1
|
||||||
&& neighbor.destPointY - scaledRadiusY <= y0 + height - 1
|
&& !seen.contains(neighbor)) {
|
||||||
&& 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
|
// Add it to the queue so we can process it at some point
|
||||||
queue.add(neighbor);
|
queue.add(neighbor);
|
||||||
@ -501,7 +458,7 @@ public class OpenSimplex2S {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
private static int fastFloor(double x) {
|
private static int fastFloor(double x) {
|
||||||
int xi = (int) x;
|
int xi = (int)x;
|
||||||
return x < xi ? xi - 1 : xi;
|
return x < xi ? xi - 1 : xi;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,35 +475,11 @@ public class OpenSimplex2S {
|
|||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
int i1, j1, i2, j2;
|
int i1, j1, i2, j2;
|
||||||
if ((i & 1) == 0) {
|
if ((i & 1) == 0) {
|
||||||
if ((i & 2) == 0) {
|
if ((i & 2) == 0) { i1 = -1; j1 = 0; } else { i1 = 1; j1 = 0; }
|
||||||
i1 = -1;
|
if ((i & 4) == 0) { i2 = 0; j2 = -1; } else { i2 = 0; j2 = 1; }
|
||||||
j1 = 0;
|
|
||||||
} else {
|
} else {
|
||||||
i1 = 1;
|
if ((i & 2) != 0) { i1 = 2; j1 = 1; } else { i1 = 0; j1 = 1; }
|
||||||
j1 = 0;
|
if ((i & 4) != 0) { i2 = 1; j2 = 2; } else { i2 = 1; j2 = 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
LOOKUP_2D[i * 4 + 0] = new LatticePoint2D(0, 0);
|
LOOKUP_2D[i * 4 + 0] = new LatticePoint2D(0, 0);
|
||||||
LOOKUP_2D[i * 4 + 1] = new LatticePoint2D(1, 1);
|
LOOKUP_2D[i * 4 + 1] = new LatticePoint2D(1, 1);
|
||||||
@ -556,15 +489,10 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
int i1, j1, k1, i2, j2, k2;
|
int i1, j1, k1, i2, j2, k2;
|
||||||
i1 = (i >> 0) & 1;
|
i1 = (i >> 0) & 1; j1 = (i >> 1) & 1; k1 = (i >> 2) & 1;
|
||||||
j1 = (i >> 1) & 1;
|
i2 = i1 ^ 1; j2 = j1 ^ 1; k2 = k1 ^ 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
|
// The two points within this octant, one from each of the two cubic half-lattices.
|
||||||
// half-lattices.
|
|
||||||
LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0);
|
LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0);
|
||||||
LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1);
|
LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1);
|
||||||
|
|
||||||
@ -597,36 +525,27 @@ public class OpenSimplex2S {
|
|||||||
c1.nextOnFailure = c1.nextOnSuccess = c2;
|
c1.nextOnFailure = c1.nextOnSuccess = c2;
|
||||||
|
|
||||||
// If c2 is in range, then we know c3 and c4 are not.
|
// If c2 is in range, then we know c3 and c4 are not.
|
||||||
c2.nextOnFailure = c3;
|
c2.nextOnFailure = c3; c2.nextOnSuccess = c5;
|
||||||
c2.nextOnSuccess = c5;
|
c3.nextOnFailure = c4; c3.nextOnSuccess = c4;
|
||||||
c3.nextOnFailure = c4;
|
|
||||||
c3.nextOnSuccess = c4;
|
|
||||||
|
|
||||||
// If c4 is in range, then we know c5 is not.
|
// If c4 is in range, then we know c5 is not.
|
||||||
c4.nextOnFailure = c5;
|
c4.nextOnFailure = c5; c4.nextOnSuccess = c6;
|
||||||
c4.nextOnSuccess = c6;
|
|
||||||
c5.nextOnFailure = c5.nextOnSuccess = c6;
|
c5.nextOnFailure = c5.nextOnSuccess = c6;
|
||||||
|
|
||||||
// If c6 is in range, then we know c7 and c8 are not.
|
// If c6 is in range, then we know c7 and c8 are not.
|
||||||
c6.nextOnFailure = c7;
|
c6.nextOnFailure = c7; c6.nextOnSuccess = c9;
|
||||||
c6.nextOnSuccess = c9;
|
c7.nextOnFailure = c8; c7.nextOnSuccess = c8;
|
||||||
c7.nextOnFailure = c8;
|
|
||||||
c7.nextOnSuccess = c8;
|
|
||||||
|
|
||||||
// If c8 is in range, then we know c9 is not.
|
// If c8 is in range, then we know c9 is not.
|
||||||
c8.nextOnFailure = c9;
|
c8.nextOnFailure = c9; c8.nextOnSuccess = cA;
|
||||||
c8.nextOnSuccess = cA;
|
|
||||||
c9.nextOnFailure = c9.nextOnSuccess = cA;
|
c9.nextOnFailure = c9.nextOnSuccess = cA;
|
||||||
|
|
||||||
// If cA is in range, then we know cB and cC are not.
|
// If cA is in range, then we know cB and cC are not.
|
||||||
cA.nextOnFailure = cB;
|
cA.nextOnFailure = cB; cA.nextOnSuccess = cD;
|
||||||
cA.nextOnSuccess = cD;
|
cB.nextOnFailure = cC; cB.nextOnSuccess = cC;
|
||||||
cB.nextOnFailure = cC;
|
|
||||||
cB.nextOnSuccess = cC;
|
|
||||||
|
|
||||||
// If cC is in range, then we know cD is not.
|
// If cC is in range, then we know cD is not.
|
||||||
cC.nextOnFailure = cD;
|
cC.nextOnFailure = cD; cC.nextOnSuccess = null;
|
||||||
cC.nextOnSuccess = null;
|
|
||||||
cD.nextOnFailure = cD.nextOnSuccess = null;
|
cD.nextOnFailure = cD.nextOnSuccess = null;
|
||||||
|
|
||||||
LOOKUP_3D[i] = c0;
|
LOOKUP_3D[i] = c0;
|
||||||
@ -635,24 +554,28 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hexagon surrounding each vertex.
|
// 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.
|
// Cube surrounding each vertex.
|
||||||
// Alternates between half-lattices.
|
// Alternates between half-lattices.
|
||||||
private static final int[][][] NEIGHBOR_MAP_3D = {
|
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, -1024 }, { -1025, -1024, 1024 }, { -1024, -1025, -1024 }, { -1025, -1025, -1024 },
|
{ 1024, 1024, 1025 }, { 1025, 1024, 1025 }, { 1024, 1025, 1025 }, { 1025, 1025, 1025 }
|
||||||
{ -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 {
|
private static class LatticePoint2D {
|
||||||
int xsv, ysv;
|
int xsv, ysv;
|
||||||
double dx, dy;
|
double dx, dy;
|
||||||
|
|
||||||
public LatticePoint2D(int xsv, int ysv) {
|
public LatticePoint2D(int xsv, int ysv) {
|
||||||
this.xsv = xsv;
|
this.xsv = xsv; this.ysv = ysv;
|
||||||
this.ysv = ysv;
|
|
||||||
double ssv = (xsv + ysv) * -0.211324865405187;
|
double ssv = (xsv + ysv) * -0.211324865405187;
|
||||||
this.dx = -xsv - ssv;
|
this.dx = -xsv - ssv;
|
||||||
this.dy = -ysv - ssv;
|
this.dy = -ysv - ssv;
|
||||||
@ -663,42 +586,29 @@ public class OpenSimplex2S {
|
|||||||
public double dxr, dyr, dzr;
|
public double dxr, dyr, dzr;
|
||||||
public int xrv, yrv, zrv;
|
public int xrv, yrv, zrv;
|
||||||
LatticePoint3D nextOnFailure, nextOnSuccess;
|
LatticePoint3D nextOnFailure, nextOnSuccess;
|
||||||
|
|
||||||
public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) {
|
public LatticePoint3D(int xrv, int yrv, int zrv, int lattice) {
|
||||||
this.dxr = -xrv + lattice * 0.5;
|
this.dxr = -xrv + lattice * 0.5; this.dyr = -yrv + lattice * 0.5; this.dzr = -zrv + lattice * 0.5;
|
||||||
this.dyr = -yrv + lattice * 0.5;
|
this.xrv = xrv + lattice * 1024; this.yrv = yrv + lattice * 1024; this.zrv = zrv + lattice * 1024;
|
||||||
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 {
|
private static class AreaGenLatticePoint2D {
|
||||||
int xsv, ysv;
|
int xsv, ysv;
|
||||||
int destPointX, destPointY;
|
int destPointX, destPointY;
|
||||||
|
|
||||||
public AreaGenLatticePoint2D(GenerateContext2D context, int xsv, int ysv) {
|
public AreaGenLatticePoint2D(GenerateContext2D context, int xsv, int ysv) {
|
||||||
this.xsv = xsv;
|
this.xsv = xsv; this.ysv = ysv;
|
||||||
this.ysv = ysv;
|
|
||||||
|
|
||||||
// Matrix multiplication for inverse rotation. Simplex skew
|
//Matrix multiplication for inverse rotation. Simplex skew transforms have always been shorthand for matrices.
|
||||||
// transforms have always been shorthand for matrices.
|
this.destPointX = (int)Math.ceil((context.orientation.t00 * xsv + context.orientation.t01 * ysv) * context.xFrequencyInverse);
|
||||||
this.destPointX = (int) Math
|
this.destPointY = (int)Math.ceil((context.orientation.t10 * xsv + context.orientation.t11 * ysv) * context.yFrequencyInverse);
|
||||||
.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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return xsv * 7841 + ysv;
|
return xsv * 7841 + ysv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof AreaGenLatticePoint2D))
|
if (!(obj instanceof AreaGenLatticePoint2D)) return false;
|
||||||
return false;
|
|
||||||
AreaGenLatticePoint2D other = (AreaGenLatticePoint2D) obj;
|
AreaGenLatticePoint2D other = (AreaGenLatticePoint2D) obj;
|
||||||
return (other.xsv == this.xsv && other.ysv == this.ysv);
|
return (other.xsv == this.xsv && other.ysv == this.ysv);
|
||||||
}
|
}
|
||||||
@ -707,20 +617,15 @@ public class OpenSimplex2S {
|
|||||||
private static class AreaGenLatticePoint3D {
|
private static class AreaGenLatticePoint3D {
|
||||||
int xsv, ysv, zsv, lattice;
|
int xsv, ysv, zsv, lattice;
|
||||||
int destPointX, destPointY, destPointZ;
|
int destPointX, destPointY, destPointZ;
|
||||||
|
|
||||||
public AreaGenLatticePoint3D(GenerateContext3D context, int xsv, int ysv, int zsv, int lattice) {
|
public AreaGenLatticePoint3D(GenerateContext3D context, int xsv, int ysv, int zsv, int lattice) {
|
||||||
this.xsv = xsv;
|
this.xsv = xsv; this.ysv = ysv; this.zsv = zsv; this.lattice = lattice;
|
||||||
this.ysv = ysv;
|
|
||||||
this.zsv = zsv;
|
|
||||||
this.lattice = lattice;
|
|
||||||
double xr = (xsv - lattice * 1024.5);
|
double xr = (xsv - lattice * 1024.5);
|
||||||
double yr = (ysv - lattice * 1024.5);
|
double yr = (ysv - lattice * 1024.5);
|
||||||
double zr = (zsv - lattice * 1024.5);
|
double zr = (zsv - lattice * 1024.5);
|
||||||
|
|
||||||
// Quaternion multiplication for inverse rotation.
|
// Quaternion multiplication for inverse rotation.
|
||||||
// https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/
|
// 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,
|
double qx = -context.orientation.qx, qy = -context.orientation.qy, qz = -context.orientation.qz, qw = context.orientation.qw;
|
||||||
qw = context.orientation.qw;
|
|
||||||
double tx = 2 * (qy * zr - qz * yr);
|
double tx = 2 * (qy * zr - qz * yr);
|
||||||
double ty = 2 * (qz * xr - qx * zr);
|
double ty = 2 * (qz * xr - qx * zr);
|
||||||
double tz = 2 * (qx * yr - qy * xr);
|
double tz = 2 * (qx * yr - qy * xr);
|
||||||
@ -728,23 +633,19 @@ public class OpenSimplex2S {
|
|||||||
double yrr = yr + qw * ty + (qz * tx - qx * tz);
|
double yrr = yr + qw * ty + (qz * tx - qx * tz);
|
||||||
double zrr = zr + qw * tz + (qx * ty - qy * tx);
|
double zrr = zr + qw * tz + (qx * ty - qy * tx);
|
||||||
|
|
||||||
this.destPointX = (int) Math.ceil(xrr * context.xFrequencyInverse);
|
this.destPointX = (int)Math.ceil(xrr * context.xFrequencyInverse);
|
||||||
this.destPointY = (int) Math.ceil(yrr * context.yFrequencyInverse);
|
this.destPointY = (int)Math.ceil(yrr * context.yFrequencyInverse);
|
||||||
this.destPointZ = (int) Math.ceil(zrr * context.zFrequencyInverse);
|
this.destPointZ = (int)Math.ceil(zrr * context.zFrequencyInverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return xsv * 2122193 + ysv * 2053 + zsv * 2 + lattice;
|
return xsv * 2122193 + ysv * 2053 + zsv * 2 + lattice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof AreaGenLatticePoint3D))
|
if (!(obj instanceof AreaGenLatticePoint3D)) return false;
|
||||||
return false;
|
|
||||||
AreaGenLatticePoint3D other = (AreaGenLatticePoint3D) obj;
|
AreaGenLatticePoint3D other = (AreaGenLatticePoint3D) obj;
|
||||||
return (other.xsv == this.xsv && other.ysv == this.ysv && other.zsv == this.zsv
|
return (other.xsv == this.xsv && other.ysv == this.ysv && other.zsv == this.zsv && other.lattice == this.lattice);
|
||||||
&& other.lattice == this.lattice);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,8 +661,7 @@ public class OpenSimplex2S {
|
|||||||
int[] kernelBounds;
|
int[] kernelBounds;
|
||||||
LatticeOrientation2D orientation;
|
LatticeOrientation2D orientation;
|
||||||
|
|
||||||
public GenerateContext2D(LatticeOrientation2D orientation, double xFrequency, double yFrequency,
|
public GenerateContext2D(LatticeOrientation2D orientation, double xFrequency, double yFrequency, double amplitude) {
|
||||||
double amplitude) {
|
|
||||||
|
|
||||||
// These will be used by every call to generate
|
// These will be used by every call to generate
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
@ -774,18 +674,19 @@ public class OpenSimplex2S {
|
|||||||
double preciseScaledRadiusY = Math.sqrt(2.0 / 3.0) * yFrequencyInverse;
|
double preciseScaledRadiusY = Math.sqrt(2.0 / 3.0) * yFrequencyInverse;
|
||||||
|
|
||||||
// 0.25 because we offset center by 0.5
|
// 0.25 because we offset center by 0.5
|
||||||
this.scaledRadiusX = (int) Math.ceil(preciseScaledRadiusX + 0.25);
|
this.scaledRadiusX = (int)Math.ceil(preciseScaledRadiusX + 0.25);
|
||||||
this.scaledRadiusY = (int) Math.ceil(preciseScaledRadiusY + 0.25);
|
this.scaledRadiusY = (int)Math.ceil(preciseScaledRadiusY + 0.25);
|
||||||
|
|
||||||
// So will these
|
// So will these
|
||||||
kernel = new double[scaledRadiusY/* * 2 */][];
|
kernel = new double[scaledRadiusY/* * 2*/][];
|
||||||
kernelBounds = new int[scaledRadiusY * 2];
|
kernelBounds = new int[scaledRadiusY * 2];
|
||||||
for (int yy = 0; yy < scaledRadiusY * 2; yy++) {
|
for (int yy = 0; yy < scaledRadiusY * 2; yy++) {
|
||||||
|
|
||||||
// Pre-generate boundary of circle
|
// Pre-generate boundary of circle
|
||||||
kernelBounds[yy] = (int) Math.ceil(Math.sqrt(
|
kernelBounds[yy] = (int)Math.ceil(
|
||||||
1.0 - (yy + 0.5 - scaledRadiusY) * (yy + 0.5 - scaledRadiusY) / (scaledRadiusY * scaledRadiusY))
|
Math.sqrt(1.0
|
||||||
* scaledRadiusX);
|
- (yy + 0.5 - scaledRadiusY) * (yy + 0.5 - scaledRadiusY) / (scaledRadiusY * scaledRadiusY)
|
||||||
|
) * scaledRadiusX);
|
||||||
|
|
||||||
if (yy < scaledRadiusY) {
|
if (yy < scaledRadiusY) {
|
||||||
kernel[yy] = new double[scaledRadiusX * 2];
|
kernel[yy] = new double[scaledRadiusX * 2];
|
||||||
@ -802,7 +703,7 @@ public class OpenSimplex2S {
|
|||||||
kernel[yy][xx] = 0.0;
|
kernel[yy][xx] = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* else kernel[yy] = kernel[2 * scaledRadiusY - yy - 1]; */
|
} /* else kernel[yy] = kernel[2 * scaledRadiusY - yy - 1];*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -823,8 +724,7 @@ public class OpenSimplex2S {
|
|||||||
int[][] kernelBoundsX;
|
int[][] kernelBoundsX;
|
||||||
LatticeOrientation3D orientation;
|
LatticeOrientation3D orientation;
|
||||||
|
|
||||||
public GenerateContext3D(LatticeOrientation3D orientation, double xFrequency, double yFrequency,
|
public GenerateContext3D(LatticeOrientation3D orientation, double xFrequency, double yFrequency, double zFrequency, double amplitude) {
|
||||||
double zFrequency, double amplitude) {
|
|
||||||
|
|
||||||
// These will be used by every call to generate
|
// These will be used by every call to generate
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
@ -840,9 +740,9 @@ public class OpenSimplex2S {
|
|||||||
double preciseScaledRadiusZ = Math.sqrt(0.75) * zFrequencyInverse;
|
double preciseScaledRadiusZ = Math.sqrt(0.75) * zFrequencyInverse;
|
||||||
|
|
||||||
// 0.25 because we offset center by 0.5
|
// 0.25 because we offset center by 0.5
|
||||||
this.scaledRadiusX = (int) Math.ceil(preciseScaledRadiusX + 0.25);
|
this.scaledRadiusX = (int)Math.ceil(preciseScaledRadiusX + 0.25);
|
||||||
this.scaledRadiusY = (int) Math.ceil(preciseScaledRadiusY + 0.25);
|
this.scaledRadiusY = (int)Math.ceil(preciseScaledRadiusY + 0.25);
|
||||||
this.scaledRadiusZ = (int) Math.ceil(preciseScaledRadiusZ + 0.25);
|
this.scaledRadiusZ = (int)Math.ceil(preciseScaledRadiusZ + 0.25);
|
||||||
|
|
||||||
// So will these
|
// So will these
|
||||||
kernel = new double[scaledRadiusZ * 2][][];
|
kernel = new double[scaledRadiusZ * 2][][];
|
||||||
@ -851,9 +751,9 @@ public class OpenSimplex2S {
|
|||||||
for (int zz = 0; zz < scaledRadiusZ * 2; zz++) {
|
for (int zz = 0; zz < scaledRadiusZ * 2; zz++) {
|
||||||
|
|
||||||
// Pre-generate boundary of sphere
|
// Pre-generate boundary of sphere
|
||||||
kernelBoundsY[zz] = (int) Math.ceil(Math.sqrt(
|
kernelBoundsY[zz] = (int)Math.ceil(
|
||||||
1.0 - (zz + 0.5 - scaledRadiusZ) * (zz + 0.5 - scaledRadiusZ) / (scaledRadiusZ * scaledRadiusZ))
|
Math.sqrt(1.0 - (zz + 0.5 - scaledRadiusZ) * (zz + 0.5 - scaledRadiusZ)
|
||||||
* scaledRadiusY);
|
/ (scaledRadiusZ * scaledRadiusZ)) * scaledRadiusY);
|
||||||
|
|
||||||
if (zz < scaledRadiusZ) {
|
if (zz < scaledRadiusZ) {
|
||||||
kernel[zz] = new double[scaledRadiusY * 2][];
|
kernel[zz] = new double[scaledRadiusY * 2][];
|
||||||
@ -867,12 +767,11 @@ public class OpenSimplex2S {
|
|||||||
for (int yy = 0; yy < scaledRadiusY * 2; yy++) {
|
for (int yy = 0; yy < scaledRadiusY * 2; yy++) {
|
||||||
|
|
||||||
// Pre-generate boundary of sphere
|
// Pre-generate boundary of sphere
|
||||||
kernelBoundsX[zz][yy] = (int) Math.ceil(Math.sqrt(1.0
|
kernelBoundsX[zz][yy] = (int)Math.ceil(
|
||||||
- (yy + 0.5 - scaledRadiusY) * (yy + 0.5 - scaledRadiusY)
|
Math.sqrt(1.0
|
||||||
/ (scaledRadiusY * scaledRadiusY)
|
- (yy + 0.5 - scaledRadiusY) * (yy + 0.5 - scaledRadiusY) / (scaledRadiusY * scaledRadiusY)
|
||||||
- (zz + 0.5 - scaledRadiusZ) * (zz + 0.5 - scaledRadiusZ)
|
- (zz + 0.5 - scaledRadiusZ) * (zz + 0.5 - scaledRadiusZ) / (scaledRadiusZ * scaledRadiusZ)
|
||||||
/ (scaledRadiusZ * scaledRadiusZ))
|
) * scaledRadiusX);
|
||||||
* scaledRadiusX);
|
|
||||||
|
|
||||||
if (yy < scaledRadiusY) {
|
if (yy < scaledRadiusY) {
|
||||||
kernel[zz][yy] = new double[scaledRadiusX * 2];
|
kernel[zz][yy] = new double[scaledRadiusX * 2];
|
||||||
@ -891,8 +790,7 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else kernel[zz][yy] = kernel[zz][2 * scaledRadiusY - yy - 1];
|
||||||
kernel[zz][yy] = kernel[zz][2 * scaledRadiusY - yy - 1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -900,50 +798,40 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum LatticeOrientation2D {
|
public enum LatticeOrientation2D {
|
||||||
// Simplex skew transforms have always been shorthand for the matrices
|
// Simplex skew transforms have always been shorthand for the matrices they represent.
|
||||||
// they represent.
|
// But when we bake the rotation into the skew transform, we need to use the general form.
|
||||||
// But when we bake the rotation into the skew transform, we need to use
|
Standard(GRADIENTS_2D,
|
||||||
// the general form.
|
1.366025403784439, 0.366025403784439, 0.366025403784439, 1.366025403784439,
|
||||||
Standard(GRADIENTS_2D, 1.366025403784439, 0.366025403784439, 0.366025403784439, 1.366025403784439,
|
0.788675134594813, -0.211324865405187, -0.211324865405187, 0.788675134594813),
|
||||||
0.788675134594813, -0.211324865405187, -0.211324865405187,
|
XBeforeY(GRADIENTS_2D_X_BEFORE_Y,
|
||||||
0.788675134594813), XBeforeY(GRADIENTS_2D_X_BEFORE_Y, 0.7071067811865476, 1.224744871380249,
|
0.7071067811865476, 1.224744871380249, -0.7071067811865476, 1.224744871380249,
|
||||||
-0.7071067811865476, 1.224744871380249, 0.7071067811865476, -0.7071067811865476,
|
0.7071067811865476, -0.7071067811865476, 0.40824829046764305, 0.40824829046764305);
|
||||||
0.40824829046764305, 0.40824829046764305);
|
|
||||||
|
|
||||||
Grad2[] gradients;
|
Grad2[] gradients;
|
||||||
double s00, s01, s10, s11;
|
double s00, s01, s10, s11;
|
||||||
double t00, t01, t10, t11;
|
double t00, t01, t10, t11;
|
||||||
|
|
||||||
private LatticeOrientation2D(Grad2[] gradients, double s00, double s01, double s10, double s11, double t00,
|
private LatticeOrientation2D(Grad2[] gradients,
|
||||||
double t01, double t10, double t11) {
|
double s00, double s01, double s10, double s11,
|
||||||
|
double t00, double t01, double t10, double t11) {
|
||||||
this.gradients = gradients;
|
this.gradients = gradients;
|
||||||
this.s00 = s00;
|
this.s00 = s00; this.s01 = s01; this.s10 = s10; this.s11 = s11;
|
||||||
this.s01 = s01;
|
this.t00 = t00; this.t01 = t01; this.t10 = t10; this.t11 = t11;
|
||||||
this.s10 = s10;
|
|
||||||
this.s11 = s11;
|
|
||||||
this.t00 = t00;
|
|
||||||
this.t01 = t01;
|
|
||||||
this.t10 = t10;
|
|
||||||
this.t11 = t11;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LatticeOrientation3D {
|
public enum LatticeOrientation3D {
|
||||||
// Quaternions for 3D. Could use matrices, but I already wrote this code
|
// Quaternions for 3D. Could use matrices, but I already wrote this code before I moved them into here.
|
||||||
// before I moved them into here.
|
Classic(GRADIENTS_3D_CLASSIC, 0.577350269189626, 0.577350269189626, 0.577350269189626, 0),
|
||||||
Classic(GRADIENTS_3D_CLASSIC, 0.577350269189626, 0.577350269189626, 0.577350269189626, 0), XYBeforeZ(
|
XYBeforeZ(GRADIENTS_3D_XY_BEFORE_Z, 0.3250575836718682, -0.3250575836718682, 0, 0.8880738339771154),
|
||||||
GRADIENTS_3D_XY_BEFORE_Z, 0.3250575836718682, -0.3250575836718682, 0, 0.8880738339771154), XZBeforeY(
|
XZBeforeY(GRADIENTS_3D_XZ_BEFORE_Y, -0.3250575836718682, 0, 0.3250575836718682, 0.8880738339771154);
|
||||||
GRADIENTS_3D_XZ_BEFORE_Y, -0.3250575836718682, 0, 0.3250575836718682, 0.8880738339771154);
|
|
||||||
|
|
||||||
Grad3[] gradients;
|
Grad3[] gradients;
|
||||||
double qx, qy, qz, qw;
|
double qx, qy, qz, qw;
|
||||||
|
|
||||||
private LatticeOrientation3D(Grad3[] gradients, double qx, double qy, double qz, double qw) {
|
private LatticeOrientation3D(Grad3[] gradients, double qx, double qy, double qz, double qw) {
|
||||||
this.gradients = gradients;
|
this.gradients = gradients;
|
||||||
this.qx = qx;
|
this.qx = qx; this.qy = qy; this.qz = qz; this.qw = qw;
|
||||||
this.qy = qy;
|
|
||||||
this.qz = qz;
|
|
||||||
this.qw = qw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -953,20 +841,15 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
public static class Grad2 {
|
public static class Grad2 {
|
||||||
double dx, dy;
|
double dx, dy;
|
||||||
|
|
||||||
public Grad2(double dx, double dy) {
|
public Grad2(double dx, double dy) {
|
||||||
this.dx = dx;
|
this.dx = dx; this.dy = dy;
|
||||||
this.dy = dy;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Grad3 {
|
public static class Grad3 {
|
||||||
double dx, dy, dz;
|
double dx, dy, dz;
|
||||||
|
|
||||||
public Grad3(double dx, double dy, double dz) {
|
public Grad3(double dx, double dy, double dz) {
|
||||||
this.dx = dx;
|
this.dx = dx; this.dy = dy; this.dz = dz;
|
||||||
this.dy = dy;
|
|
||||||
this.dz = dz;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,23 +861,35 @@ public class OpenSimplex2S {
|
|||||||
|
|
||||||
GRADIENTS_2D = new Grad2[PSIZE];
|
GRADIENTS_2D = new Grad2[PSIZE];
|
||||||
GRADIENTS_2D_X_BEFORE_Y = new Grad2[PSIZE];
|
GRADIENTS_2D_X_BEFORE_Y = new Grad2[PSIZE];
|
||||||
Grad2[] grad2 = { new Grad2(0.130526192220052, 0.99144486137381),
|
Grad2[] grad2 = {
|
||||||
new Grad2(0.38268343236509, 0.923879532511287), new Grad2(0.608761429008721, 0.793353340291235),
|
new Grad2( 0.130526192220052, 0.99144486137381),
|
||||||
new Grad2(0.793353340291235, 0.608761429008721), new Grad2(0.923879532511287, 0.38268343236509),
|
new Grad2( 0.38268343236509, 0.923879532511287),
|
||||||
new Grad2(0.99144486137381, 0.130526192220051), new Grad2(0.99144486137381, -0.130526192220051),
|
new Grad2( 0.608761429008721, 0.793353340291235),
|
||||||
new Grad2(0.923879532511287, -0.38268343236509), new Grad2(0.793353340291235, -0.60876142900872),
|
new Grad2( 0.793353340291235, 0.608761429008721),
|
||||||
new Grad2(0.608761429008721, -0.793353340291235), new Grad2(0.38268343236509, -0.923879532511287),
|
new Grad2( 0.923879532511287, 0.38268343236509),
|
||||||
new Grad2(0.130526192220052, -0.99144486137381), new Grad2(-0.130526192220052, -0.99144486137381),
|
new Grad2( 0.99144486137381, 0.130526192220051),
|
||||||
new Grad2(-0.38268343236509, -0.923879532511287), new Grad2(-0.608761429008721, -0.793353340291235),
|
new Grad2( 0.99144486137381, -0.130526192220051),
|
||||||
new Grad2(-0.793353340291235, -0.608761429008721), new Grad2(-0.923879532511287, -0.38268343236509),
|
new Grad2( 0.923879532511287, -0.38268343236509),
|
||||||
new Grad2(-0.99144486137381, -0.130526192220052), new Grad2(-0.99144486137381, 0.130526192220051),
|
new Grad2( 0.793353340291235, -0.60876142900872),
|
||||||
new Grad2(-0.923879532511287, 0.38268343236509), new Grad2(-0.793353340291235, 0.608761429008721),
|
new Grad2( 0.608761429008721, -0.793353340291235),
|
||||||
new Grad2(-0.608761429008721, 0.793353340291235), new Grad2(-0.38268343236509, 0.923879532511287),
|
new Grad2( 0.38268343236509, -0.923879532511287),
|
||||||
new Grad2(-0.130526192220052, 0.99144486137381) };
|
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];
|
Grad2[] grad2XBeforeY = new Grad2[grad2.length];
|
||||||
for (int i = 0; i < grad2.length; i++) {
|
for (int i = 0; i < grad2.length; i++) {
|
||||||
grad2[i].dx /= N2;
|
grad2[i].dx /= N2; grad2[i].dy /= N2;
|
||||||
grad2[i].dy /= N2;
|
|
||||||
|
|
||||||
// Unrotated gradients for XBeforeY 2D
|
// Unrotated gradients for XBeforeY 2D
|
||||||
double xx = grad2[i].dx * 0.7071067811865476;
|
double xx = grad2[i].dx * 0.7071067811865476;
|
||||||
@ -1010,59 +905,77 @@ public class OpenSimplex2S {
|
|||||||
GRADIENTS_3D_CLASSIC = new Grad3[PSIZE];
|
GRADIENTS_3D_CLASSIC = new Grad3[PSIZE];
|
||||||
GRADIENTS_3D_XY_BEFORE_Z = new Grad3[PSIZE];
|
GRADIENTS_3D_XY_BEFORE_Z = new Grad3[PSIZE];
|
||||||
GRADIENTS_3D_XZ_BEFORE_Y = new Grad3[PSIZE];
|
GRADIENTS_3D_XZ_BEFORE_Y = new Grad3[PSIZE];
|
||||||
Grad3[] grad3 = { new Grad3(-2.22474487139, -2.22474487139, -1.0),
|
Grad3[] grad3 = {
|
||||||
|
new Grad3(-2.22474487139, -2.22474487139, -1.0),
|
||||||
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(-3.0862664687972017, -1.1721513422464978, 0.0),
|
||||||
new Grad3(-1.1721513422464978, -3.0862664687972017, 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(-2.22474487139, -1.0, -2.22474487139),
|
||||||
|
new Grad3(-2.22474487139, 1.0, -2.22474487139),
|
||||||
new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017),
|
new Grad3(-1.1721513422464978, 0.0, -3.0862664687972017),
|
||||||
new Grad3(-3.0862664687972017, 0.0, -1.1721513422464978),
|
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(-2.22474487139, -1.0, 2.22474487139),
|
||||||
|
new Grad3(-2.22474487139, 1.0, 2.22474487139),
|
||||||
new Grad3(-3.0862664687972017, 0.0, 1.1721513422464978),
|
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(-1.1721513422464978, 0.0, 3.0862664687972017),
|
||||||
new Grad3(-2.22474487139, 2.22474487139, 1.0), new Grad3(-1.1721513422464978, 3.0862664687972017, 0.0),
|
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(-3.0862664687972017, 1.1721513422464978, 0.0),
|
||||||
new Grad3(-1.0, -2.22474487139, -2.22474487139), 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( 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, -1.1721513422464978, 3.0862664687972017),
|
new Grad3(-1.0, -2.22474487139, 2.22474487139),
|
||||||
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(1.0, 2.22474487139, -2.22474487139), new Grad3(0.0, 1.1721513422464978, -3.0862664687972017),
|
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( 0.0, -3.0862664687972017, 1.1721513422464978),
|
||||||
new Grad3(1.0, 2.22474487139, 2.22474487139), new Grad3(0.0, 3.0862664687972017, 1.1721513422464978),
|
new Grad3(-1.0, 2.22474487139, -2.22474487139),
|
||||||
new Grad3(0.0, 1.1721513422464978, 3.0862664687972017), new Grad3(2.22474487139, -2.22474487139, -1.0),
|
new Grad3( 1.0, 2.22474487139, -2.22474487139),
|
||||||
new Grad3(2.22474487139, -2.22474487139, 1.0), new Grad3(1.1721513422464978, -3.0862664687972017, 0.0),
|
new Grad3( 0.0, 1.1721513422464978, -3.0862664687972017),
|
||||||
new Grad3(3.0862664687972017, -1.1721513422464978, 0.0), new Grad3(2.22474487139, -1.0, -2.22474487139),
|
new Grad3( 0.0, 3.0862664687972017, -1.1721513422464978),
|
||||||
new Grad3(2.22474487139, 1.0, -2.22474487139), new Grad3(3.0862664687972017, 0.0, -1.1721513422464978),
|
new Grad3(-1.0, 2.22474487139, 2.22474487139),
|
||||||
new Grad3(1.1721513422464978, 0.0, -3.0862664687972017), new Grad3(2.22474487139, -1.0, 2.22474487139),
|
new Grad3( 1.0, 2.22474487139, 2.22474487139),
|
||||||
new Grad3(2.22474487139, 1.0, 2.22474487139), new Grad3(1.1721513422464978, 0.0, 3.0862664687972017),
|
new Grad3( 0.0, 3.0862664687972017, 1.1721513422464978),
|
||||||
new Grad3(3.0862664687972017, 0.0, 1.1721513422464978), new Grad3(2.22474487139, 2.22474487139, -1.0),
|
new Grad3( 0.0, 1.1721513422464978, 3.0862664687972017),
|
||||||
new Grad3(2.22474487139, 2.22474487139, 1.0), new Grad3(3.0862664687972017, 1.1721513422464978, 0.0),
|
new Grad3( 2.22474487139, -2.22474487139, -1.0),
|
||||||
new Grad3(1.1721513422464978, 3.0862664687972017, 0.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[] grad3Classic = new Grad3[grad3.length];
|
||||||
Grad3[] grad3XYBeforeZ = new Grad3[grad3.length];
|
Grad3[] grad3XYBeforeZ = new Grad3[grad3.length];
|
||||||
Grad3[] grad3XZBeforeY = new Grad3[grad3.length];
|
Grad3[] grad3XZBeforeY = new Grad3[grad3.length];
|
||||||
for (int i = 0; i < grad3.length; i++) {
|
for (int i = 0; i < grad3.length; i++) {
|
||||||
grad3[i].dx /= N3;
|
grad3[i].dx /= N3; grad3[i].dy /= N3; grad3[i].dz /= N3;
|
||||||
grad3[i].dy /= N3;
|
|
||||||
grad3[i].dz /= N3;
|
|
||||||
double gxr = grad3[i].dx, gyr = grad3[i].dy, gzr = grad3[i].dz;
|
double gxr = grad3[i].dx, gyr = grad3[i].dy, gzr = grad3[i].dz;
|
||||||
|
|
||||||
// Unrotated gradients for classic 3D
|
// Unrotated gradients for classic 3D
|
||||||
double grr = (2.0 / 3.0) * (gxr + gyr + gzr);
|
double grr = (2.0 / 3.0) * (gxr + gyr + gzr);
|
||||||
// double dx = grr - gxr, dy = grr - gyr, dz = grr - gzr;
|
// double dx = grr - gxr, dy = grr - gyr, dz = grr - gzr;
|
||||||
grad3Classic[i] = new Grad3(grr - gxr, grr - gyr, grr - gzr);
|
grad3Classic[i] = new Grad3( grr - gxr, grr - gyr, grr - gzr );
|
||||||
|
|
||||||
// Unrotated gradients for XYBeforeZ 3D
|
// Unrotated gradients for XYBeforeZ 3D
|
||||||
double s2 = (gxr + gyr) * -0.211324865405187;
|
double s2 = (gxr + gyr) * -0.211324865405187;
|
||||||
double zz = gzr * 0.577350269189626;
|
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
|
// Unrotated gradients for plane-first 3D
|
||||||
s2 = (gxr + gzr) * -0.211324865405187;
|
s2 = (gxr + gzr) * -0.211324865405187;
|
||||||
double yy = gyr * 0.577350269189626;
|
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++) {
|
for (int i = 0; i < PSIZE; i++) {
|
||||||
GRADIENTS_3D[i] = grad3[i % grad3.length];
|
GRADIENTS_3D[i] = grad3[i % grad3.length];
|
||||||
|
@ -611,7 +611,8 @@ public class ArrayUtil {
|
|||||||
int end = offset + length;
|
int end = offset + length;
|
||||||
if (end > arrayLength || offset < 0)
|
if (end > arrayLength || offset < 0)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")");
|
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
@ -627,7 +628,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
if (end > arrayLength || start < 0)
|
if (end > arrayLength || start < 0)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")");
|
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,18 @@ public class PrimitiveUtil {
|
|||||||
private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>();
|
private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (Class<?> boxed : new Class<?>[] { Boolean.class, Byte.class, Short.class, Character.class, Integer.class,
|
for (
|
||||||
Long.class, Float.class, Double.class }) {
|
Class<?> boxed : new Class<?>[] {
|
||||||
|
Boolean.class,
|
||||||
|
Byte.class,
|
||||||
|
Short.class,
|
||||||
|
Character.class,
|
||||||
|
Integer.class,
|
||||||
|
Long.class,
|
||||||
|
Float.class,
|
||||||
|
Double.class
|
||||||
|
}
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed);
|
PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -40,7 +40,8 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains static methods to create {@link Stream Streams} that synchronize
|
* Contains static methods to create {@link Stream Streams} that synchronize
|
||||||
* their <a href=
|
* their
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> on a given monitor.
|
* terminal operations</a> on a given monitor.
|
||||||
*
|
*
|
||||||
@ -1069,18 +1070,21 @@ public class SyncStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link Stream} to make all <a href=
|
* Wraps the given {@link Stream} to make all
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> acquire the provided monitor's lock before
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* execution. Intermediate operations return streams that are also
|
* execution. Intermediate operations
|
||||||
* synchronized on the same object. The created stream will behave
|
* return streams that are also synchronized on the same object. The created
|
||||||
* identically to the provided stream in all other aspects. Use this to
|
* stream will behave identically
|
||||||
* synchronize access to stream's source.
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
* <p>
|
* <p>
|
||||||
* <i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and
|
* <i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and
|
||||||
* {@link Stream#spliterator() spliterator()} methods return regular
|
* {@link Stream#spliterator()
|
||||||
* non-synchronized iterators and spliterators respectively</i>. It is the
|
* spliterator()} methods return regular non-synchronized iterators and
|
||||||
* user's responsibility to avoid concurrency issues:
|
* spliterators respectively</i>. It
|
||||||
|
* is the user's responsibility to avoid concurrency issues:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
@ -1099,17 +1103,14 @@ public class SyncStreams {
|
|||||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T> the class of objects in the Stream
|
||||||
* the class of objects in the Stream
|
* @param stream the stream to wrap.
|
||||||
* @param stream
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
* the stream to wrap.
|
* When {@code null}, the stream
|
||||||
* @param monitor
|
* will synchronize on itself.
|
||||||
* 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
|
* @return a {@link SyncStream SyncStream<T>} synchronized on
|
||||||
* {@code monitor} and backed by {@code stream}.
|
* {@code monitor} and backed by {@code stream}.
|
||||||
* @throws NullPointerException
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
* if {@code stream == null}.
|
|
||||||
*/
|
*/
|
||||||
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
|
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
|
||||||
Objects.requireNonNull(stream, "stream cannot be null");
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
@ -1117,19 +1118,22 @@ public class SyncStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link IntStream} to make all <a href=
|
* Wraps the given {@link IntStream} to make all
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> acquire the provided monitor's lock before
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* execution. Intermediate operations return streams that are also
|
* execution. Intermediate operations
|
||||||
* synchronized on the same object. The created stream will behave
|
* return streams that are also synchronized on the same object. The created
|
||||||
* identically to the provided stream in all other aspects. Use this to
|
* stream will behave identically
|
||||||
* synchronize access to stream's source.
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
* <p>
|
* <p>
|
||||||
* <i>The returned {@code IntStream}'s {@link IntStream#iterator()
|
* <i>The returned {@code IntStream}'s {@link IntStream#iterator()
|
||||||
* iterator()} and {@link IntStream#spliterator() spliterator()} methods
|
* iterator()} and
|
||||||
* return regular non-synchronized iterators and spliterators
|
* {@link IntStream#spliterator() spliterator()} methods return regular
|
||||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
* non-synchronized iterators and
|
||||||
* issues:
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
@ -1148,15 +1152,13 @@ public class SyncStreams {
|
|||||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream
|
* @param stream the stream to wrap.
|
||||||
* the stream to wrap.
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
* @param monitor
|
* When {@code null}, the stream
|
||||||
* the object that the stream will use for synchronization. When
|
* will synchronize on itself.
|
||||||
* {@code null}, the stream will synchronize on itself.
|
|
||||||
* @return a {@link SyncIntStream} synchronized on {@code monitor} and
|
* @return a {@link SyncIntStream} synchronized on {@code monitor} and
|
||||||
* backed by {@code stream}.
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
* if {@code stream == null}.
|
|
||||||
*/
|
*/
|
||||||
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
|
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
|
||||||
Objects.requireNonNull(stream, "stream cannot be null");
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
@ -1164,19 +1166,22 @@ public class SyncStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link LongStream} to make all <a href=
|
* Wraps the given {@link LongStream} to make all
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> acquire the provided monitor's lock before
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* execution. Intermediate operations return streams that are also
|
* execution. Intermediate operations
|
||||||
* synchronized on the same object. The created stream will behave
|
* return streams that are also synchronized on the same object. The created
|
||||||
* identically to the provided stream in all other aspects. Use this to
|
* stream will behave identically
|
||||||
* synchronize access to stream's source.
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
* <p>
|
* <p>
|
||||||
* <i>The returned {@code LongStream}'s {@link LongStream#iterator()
|
* <i>The returned {@code LongStream}'s {@link LongStream#iterator()
|
||||||
* iterator()} and {@link LongStream#spliterator() spliterator()} methods
|
* iterator()} and
|
||||||
* return regular non-synchronized iterators and spliterators
|
* {@link LongStream#spliterator() spliterator()} methods return regular
|
||||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
* non-synchronized iterators and
|
||||||
* issues:
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
@ -1195,15 +1200,13 @@ public class SyncStreams {
|
|||||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream
|
* @param stream the stream to wrap.
|
||||||
* the stream to wrap.
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
* @param monitor
|
* When {@code null}, the stream
|
||||||
* the object that the stream will use for synchronization. When
|
* will synchronize on itself.
|
||||||
* {@code null}, the stream will synchronize on itself.
|
|
||||||
* @return a {@link SyncLongStream} synchronized on {@code monitor} and
|
* @return a {@link SyncLongStream} synchronized on {@code monitor} and
|
||||||
* backed by {@code stream}.
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
* if {@code stream == null}.
|
|
||||||
*/
|
*/
|
||||||
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
|
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
|
||||||
Objects.requireNonNull(stream, "stream cannot be null");
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
@ -1211,19 +1214,22 @@ public class SyncStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link DoubleStream} to make all <a href=
|
* Wraps the given {@link DoubleStream} to make all
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> acquire the provided monitor's lock before
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* execution. Intermediate operations return streams that are also
|
* execution. Intermediate operations
|
||||||
* synchronized on the same object. The created stream will behave
|
* return streams that are also synchronized on the same object. The created
|
||||||
* identically to the provided stream in all other aspects. Use this to
|
* stream will behave identically
|
||||||
* synchronize access to stream's source.
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
* <p>
|
* <p>
|
||||||
* <i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator()
|
* <i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator()
|
||||||
* iterator()} and {@link DoubleStream#spliterator() spliterator()} methods
|
* iterator()} and
|
||||||
* return regular non-synchronized iterators and spliterators
|
* {@link DoubleStream#spliterator() spliterator()} methods return regular
|
||||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
* non-synchronized iterators and
|
||||||
* issues:
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
@ -1242,15 +1248,13 @@ public class SyncStreams {
|
|||||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream
|
* @param stream the stream to wrap.
|
||||||
* the stream to wrap.
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
* @param monitor
|
* When {@code null}, the stream
|
||||||
* the object that the stream will use for synchronization. When
|
* will synchronize on itself.
|
||||||
* {@code null}, the stream will synchronize on itself.
|
|
||||||
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and
|
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and
|
||||||
* backed by {@code stream}.
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
* if {@code stream == null}.
|
|
||||||
*/
|
*/
|
||||||
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
|
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
|
||||||
Objects.requireNonNull(stream, "stream cannot be null");
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
|
@ -108,7 +108,7 @@ public class CharArrayIterator implements CharacterIterator {
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
||||||
|
|
||||||
// SonarLint: "clone" should not be overridden (java:S2975)
|
// SonarLint: "clone" should not be overridden (java:S2975)
|
||||||
// And I wouldn't have done that if only CharacterIterator had not required
|
// And I wouldn't have done that if only CharacterIterator had not required
|
||||||
|
@ -103,8 +103,14 @@ public class Escaper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Escaper JAVA = new Escaper('\\', 'u', "tbnrf'\"".toCharArray(), "\t\b\n\r\f\'\"".toCharArray(),
|
public static final Escaper JAVA = new Escaper(
|
||||||
true, true);
|
'\\',
|
||||||
|
'u',
|
||||||
|
"tbnrf'\"".toCharArray(),
|
||||||
|
"\t\b\n\r\f\'\"".toCharArray(),
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
private final char escapeChar;
|
private final char escapeChar;
|
||||||
private final char unicodeEscapeChar;
|
private final char unicodeEscapeChar;
|
||||||
@ -114,8 +120,14 @@ public class Escaper {
|
|||||||
private final boolean preferUnicode;
|
private final boolean preferUnicode;
|
||||||
private final boolean strict;
|
private final boolean strict;
|
||||||
|
|
||||||
protected Escaper(char escapeChar, char unicodeEscapeChar, char[] safes, char[] unsafes, boolean preferUnicode,
|
protected Escaper(
|
||||||
boolean strict) {
|
char escapeChar,
|
||||||
|
char unicodeEscapeChar,
|
||||||
|
char[] safes,
|
||||||
|
char[] unsafes,
|
||||||
|
boolean preferUnicode,
|
||||||
|
boolean strict
|
||||||
|
) {
|
||||||
this.escapeChar = escapeChar;
|
this.escapeChar = escapeChar;
|
||||||
this.unicodeEscapeChar = unicodeEscapeChar;
|
this.unicodeEscapeChar = unicodeEscapeChar;
|
||||||
this.safes = safes;
|
this.safes = safes;
|
||||||
@ -140,7 +152,8 @@ public class Escaper {
|
|||||||
for (char c : unsafes) {
|
for (char c : unsafes) {
|
||||||
if (c == escapeChar)
|
if (c == escapeChar)
|
||||||
throw new IllegalArgumentException(
|
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)
|
if (c == unicodeEscapeChar)
|
||||||
throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
||||||
}
|
}
|
||||||
@ -160,7 +173,11 @@ public class Escaper {
|
|||||||
end = Integer.MAX_VALUE;
|
end = Integer.MAX_VALUE;
|
||||||
else
|
else
|
||||||
end = src.getPosition() + length;
|
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);
|
escape(src.consume(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +225,11 @@ public class Escaper {
|
|||||||
|
|
||||||
int result = 0;
|
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());
|
result += getEscapedLength(src.consume());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +257,11 @@ public class Escaper {
|
|||||||
end = Integer.MAX_VALUE;
|
end = Integer.MAX_VALUE;
|
||||||
else
|
else
|
||||||
end = src.getPosition() + length;
|
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));
|
output.accept(unescapeOneSequence(src));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,8 +282,10 @@ public class Escaper {
|
|||||||
|
|
||||||
if (src.current() == unicodeEscapeChar) {
|
if (src.current() == unicodeEscapeChar) {
|
||||||
src.next();
|
src.next();
|
||||||
return (char) (hexValue(src.consume()) << (4 * 3) | hexValue(src.consume()) << (4 * 2)
|
return (char) (hexValue(src.consume()) << (4 * 3) |
|
||||||
| hexValue(src.consume()) << (4 * 1) | hexValue(src.consume()) << (4 * 0));
|
hexValue(src.consume()) << (4 * 2) |
|
||||||
|
hexValue(src.consume()) << (4 * 1) |
|
||||||
|
hexValue(src.consume()) << (4 * 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = ArrayUtil.firstIndexOf(safes, src.current());
|
int index = ArrayUtil.firstIndexOf(safes, src.current());
|
||||||
@ -288,7 +315,11 @@ public class Escaper {
|
|||||||
|
|
||||||
int result = 0;
|
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);
|
skipOneSequence(src);
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
@ -297,7 +328,11 @@ public class Escaper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void skipOneSequence(CharReader src) {
|
public void skipOneSequence(CharReader src) {
|
||||||
if (src.current() == escapeChar && src.next() == unicodeEscapeChar) {
|
if (
|
||||||
|
src.current() == escapeChar
|
||||||
|
&&
|
||||||
|
src.next() == unicodeEscapeChar
|
||||||
|
) {
|
||||||
src.advance(4);
|
src.advance(4);
|
||||||
}
|
}
|
||||||
src.next();
|
src.next();
|
||||||
|
@ -86,7 +86,7 @@ public class FancyCharacterIterator implements CharacterIterator {
|
|||||||
return sb.toString();
|
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)
|
// SonarLint: "clone" should not be overridden (java:S2975)
|
||||||
// And I wouldn't have done that if only CharacterIterator had not required
|
// And I wouldn't have done that if only CharacterIterator had not required
|
||||||
|
@ -41,8 +41,13 @@ public class StringUtil {
|
|||||||
private static final String EMPTY_PLACEHOLDER = "[empty]";
|
private static final String EMPTY_PLACEHOLDER = "[empty]";
|
||||||
private static final String DEFAULT_SEPARATOR = "; ";
|
private static final String DEFAULT_SEPARATOR = "; ";
|
||||||
|
|
||||||
public static <T> String arrayToString(T[] array, String separator, String empty, String nullPlaceholder,
|
public static <T> String arrayToString(
|
||||||
String nullArray) {
|
T[] array,
|
||||||
|
String separator,
|
||||||
|
String empty,
|
||||||
|
String nullPlaceholder,
|
||||||
|
String nullArray
|
||||||
|
) {
|
||||||
|
|
||||||
if (separator == null) {
|
if (separator == null) {
|
||||||
throw new IllegalArgumentException(new NullPointerException());
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
@ -74,8 +79,13 @@ public class StringUtil {
|
|||||||
return arrayToString(array, DEFAULT_SEPARATOR);
|
return arrayToString(array, DEFAULT_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String iteratorToString(Iterator<?> iterator, String separator, String empty, String nullPlaceholder,
|
public static String iteratorToString(
|
||||||
String nullIterator) {
|
Iterator<?> iterator,
|
||||||
|
String separator,
|
||||||
|
String empty,
|
||||||
|
String nullPlaceholder,
|
||||||
|
String nullIterator
|
||||||
|
) {
|
||||||
|
|
||||||
if (separator == null) {
|
if (separator == null) {
|
||||||
throw new IllegalArgumentException(new NullPointerException());
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
@ -109,8 +119,13 @@ public class StringUtil {
|
|||||||
return iteratorToString(iterator, DEFAULT_SEPARATOR);
|
return iteratorToString(iterator, DEFAULT_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String iterableToString(Iterable<?> iterable, String separator, String empty, String nullPlaceholder,
|
public static String iterableToString(
|
||||||
String nullIterable) {
|
Iterable<?> iterable,
|
||||||
|
String separator,
|
||||||
|
String empty,
|
||||||
|
String nullPlaceholder,
|
||||||
|
String nullIterable
|
||||||
|
) {
|
||||||
|
|
||||||
if (separator == null) {
|
if (separator == null) {
|
||||||
throw new IllegalArgumentException(new NullPointerException());
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
@ -131,8 +146,14 @@ public class StringUtil {
|
|||||||
return iterableToString(iterable, DEFAULT_SEPARATOR);
|
return iterableToString(iterable, DEFAULT_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> String supplierToString(IntFunction<T> supplier, int length, String separator, String empty,
|
public static <T> String supplierToString(
|
||||||
String nullPlaceholder, String nullSupplier) {
|
IntFunction<T> supplier,
|
||||||
|
int length,
|
||||||
|
String separator,
|
||||||
|
String empty,
|
||||||
|
String nullPlaceholder,
|
||||||
|
String nullSupplier
|
||||||
|
) {
|
||||||
|
|
||||||
if (separator == null)
|
if (separator == null)
|
||||||
throw new IllegalArgumentException(new NullPointerException());
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
@ -142,15 +163,28 @@ public class StringUtil {
|
|||||||
return empty;
|
return empty;
|
||||||
|
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
return supplierToStringExactly(supplier, length, separator, nullPlaceholder);
|
return supplierToStringExactly(
|
||||||
|
supplier,
|
||||||
|
length,
|
||||||
|
separator,
|
||||||
|
nullPlaceholder
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return supplierToStringUntilNull(supplier, separator, empty);
|
return supplierToStringUntilNull(
|
||||||
|
supplier,
|
||||||
|
separator,
|
||||||
|
empty
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> String supplierToStringExactly(IntFunction<T> supplier, int length, String separator,
|
private static <T> String supplierToStringExactly(
|
||||||
String nullPlaceholder) {
|
IntFunction<T> supplier,
|
||||||
|
int length,
|
||||||
|
String separator,
|
||||||
|
String nullPlaceholder
|
||||||
|
) {
|
||||||
T element = supplier.apply(0);
|
T element = supplier.apply(0);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(element == null ? nullPlaceholder : element.toString());
|
StringBuilder sb = new StringBuilder(element == null ? nullPlaceholder : element.toString());
|
||||||
@ -164,7 +198,11 @@ public class StringUtil {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> String supplierToStringUntilNull(IntFunction<T> supplier, String separator, String empty) {
|
private static <T> String supplierToStringUntilNull(
|
||||||
|
IntFunction<T> supplier,
|
||||||
|
String separator,
|
||||||
|
String empty
|
||||||
|
) {
|
||||||
T element = supplier.apply(0);
|
T element = supplier.apply(0);
|
||||||
|
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
@ -328,7 +366,11 @@ public class StringUtil {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
charLoop: for (char c : src.toCharArray()) {
|
charLoop: for (char c : src.toCharArray()) {
|
||||||
if ((resultIndex + 1) < arrayLength && test.test(c)) {
|
if (
|
||||||
|
(resultIndex + 1) < arrayLength
|
||||||
|
&&
|
||||||
|
test.test(c)
|
||||||
|
) {
|
||||||
result[resultIndex] = resetStringBuilder(sb);
|
result[resultIndex] = resetStringBuilder(sb);
|
||||||
++resultIndex;
|
++resultIndex;
|
||||||
continue charLoop;
|
continue charLoop;
|
||||||
@ -347,17 +389,17 @@ public class StringUtil {
|
|||||||
* index.
|
* index.
|
||||||
* <p>
|
* <p>
|
||||||
* Indices {@code 0} and {@code src.length() - 1} produce {@code str}
|
* Indices {@code 0} and {@code src.length() - 1} produce {@code str}
|
||||||
* excluding the specified character and {@code ""}.
|
* excluding
|
||||||
|
* the specified character and {@code ""}.
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src the String to split
|
||||||
* the String to split
|
* @param at index to split at
|
||||||
* @param at
|
* @throws IllegalArgumentException if the index is out of bounds for
|
||||||
* index to split at
|
* {@code src}
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the index is out of bounds for {@code src}
|
|
||||||
* @return an array containing the substrings, in order of encounter in
|
* @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) {
|
public static String[] splitAt(String src, int at) {
|
||||||
Objects.requireNonNull(src, "src");
|
Objects.requireNonNull(src, "src");
|
||||||
@ -374,7 +416,10 @@ public class StringUtil {
|
|||||||
return new String[] { src.substring(0, src.length() - 1), "" };
|
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)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -382,7 +427,8 @@ public class StringUtil {
|
|||||||
* indices.
|
* indices.
|
||||||
* <p>
|
* <p>
|
||||||
* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length
|
* 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.
|
||||||
* <p>
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
@ -393,14 +439,13 @@ public class StringUtil {
|
|||||||
* splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"}
|
* splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"}
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src the String to split
|
||||||
* the String to split
|
* @param at indices to split at, in any order
|
||||||
* @param at
|
* @throws IllegalArgumentException if some index is out of bounds for
|
||||||
* indices to split at, in any order
|
* {@code src}
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if some index is out of bounds for {@code src}
|
|
||||||
* @return an array containing the substrings, in order of encounter in
|
* @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) {
|
public static String[] splitAt(String src, int... at) {
|
||||||
Objects.requireNonNull(src, "src");
|
Objects.requireNonNull(src, "src");
|
||||||
@ -508,8 +553,10 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (endPos < beginPos) {
|
if (endPos < beginPos) {
|
||||||
throw new IllegalArgumentException("endPos must be greater than or equal to beginPos (endPos=" + endPos
|
throw new IllegalArgumentException(
|
||||||
+ ", beginPos=" + beginPos + ")");
|
"endPos must be greater than or equal to beginPos (endPos="
|
||||||
|
+ endPos + ", beginPos=" + beginPos + ")"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endPos >= Math.min(a.length, b.length)) {
|
if (endPos >= Math.min(a.length, b.length)) {
|
||||||
@ -545,7 +592,8 @@ public class StringUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and returns the index of the specified appearance of the specified
|
* 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.
|
||||||
* <p>
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
* <p>
|
* <p>
|
||||||
@ -582,12 +630,10 @@ public class StringUtil {
|
|||||||
* </tr>
|
* </tr>
|
||||||
* </table>
|
* </table>
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src - the array to search in.
|
||||||
* - the array to search in.
|
* @param target - the character to search for.
|
||||||
* @param target
|
* @param skip - the amount of <code>target</code> characters to be
|
||||||
* - the character to search for.
|
* skipped.
|
||||||
* @param skip
|
|
||||||
* - the amount of <code>target</code> characters to be skipped.
|
|
||||||
* @return The index of the <code>skip+1</code>th <code>target</code>
|
* @return The index of the <code>skip+1</code>th <code>target</code>
|
||||||
* character or -1, if none found.
|
* character or -1, if none found.
|
||||||
* @see StringUtil#indexFromEnd(char[], char, int)
|
* @see StringUtil#indexFromEnd(char[], char, int)
|
||||||
@ -607,7 +653,8 @@ public class StringUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and returns the index of the specified appearance of the specified
|
* 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
|
||||||
* <code>src.length - 1</code>.
|
* <code>src.length - 1</code>.
|
||||||
* <p>
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
@ -645,15 +692,13 @@ public class StringUtil {
|
|||||||
* </tr>
|
* </tr>
|
||||||
* </table>
|
* </table>
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src - the array to search in.
|
||||||
* - the array to search in.
|
* @param target - the character to search for.
|
||||||
* @param target
|
* @param skip - the amount of <code>target</code> characters to be
|
||||||
* - the character to search for.
|
* skipped.
|
||||||
* @param skip
|
|
||||||
* - the amount of <code>target</code> characters to be skipped.
|
|
||||||
* @return The index of the <code>skip+1</code>th
|
* @return The index of the <code>skip+1</code>th
|
||||||
* <code>target</code>character from the end of the array or -1, if
|
* <code>target</code>character
|
||||||
* none found.
|
* from the end of the array or -1, if none found.
|
||||||
* @see StringUtil#indexFromBeginning(char[], char, int)
|
* @see StringUtil#indexFromBeginning(char[], char, int)
|
||||||
*/
|
*/
|
||||||
public static int indexFromEnd(char[] src, char target, int skip) {
|
public static int indexFromEnd(char[] src, char target, int skip) {
|
||||||
@ -828,8 +873,12 @@ public class StringUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void buildCombinations(StringBuilder sb, Collection<String> result, Iterable<String>[] parts,
|
private static void buildCombinations(
|
||||||
int index) {
|
StringBuilder sb,
|
||||||
|
Collection<String> result,
|
||||||
|
Iterable<String>[] parts,
|
||||||
|
int index
|
||||||
|
) {
|
||||||
if (index >= parts.length) {
|
if (index >= parts.length) {
|
||||||
result.add(sb.toString());
|
result.add(sb.toString());
|
||||||
} else {
|
} else {
|
||||||
@ -855,8 +904,13 @@ public class StringUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void buildCombinations(StringBuilder sb, String[] result, int[] resultIndex, String[][] parts,
|
private static void buildCombinations(
|
||||||
int index) {
|
StringBuilder sb,
|
||||||
|
String[] result,
|
||||||
|
int[] resultIndex,
|
||||||
|
String[][] parts,
|
||||||
|
int index
|
||||||
|
) {
|
||||||
if (index >= parts.length) {
|
if (index >= parts.length) {
|
||||||
result[resultIndex[0]++] = sb.toString();
|
result[resultIndex[0]++] = sb.toString();
|
||||||
} else {
|
} else {
|
||||||
@ -931,7 +985,10 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static char hexDigit(long value, int digit) {
|
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) {
|
public static char hexDigit(int value) {
|
||||||
|
@ -27,9 +27,10 @@ public abstract class AbstractCharReader implements CharReader {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Current position of this CharReader. The reader maps its input to
|
* Current position of this CharReader. The reader maps its input to
|
||||||
* positions starting from 0. Positions that are negative or lower than 0
|
* positions starting from 0.
|
||||||
* are invalid. {@link #current()} will throw an exception if position is
|
* Positions that are negative or lower than 0 are invalid.
|
||||||
* invalid.
|
* {@link #current()}
|
||||||
|
* will throw an exception if position is invalid.
|
||||||
*/
|
*/
|
||||||
protected int position = 0;
|
protected int position = 0;
|
||||||
|
|
||||||
|
@ -51,12 +51,9 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
|||||||
/**
|
/**
|
||||||
* Acquires next characters and stores them in the array.
|
* Acquires next characters and stores them in the array.
|
||||||
*
|
*
|
||||||
* @param buffer
|
* @param buffer the output array
|
||||||
* the output array
|
* @param offset index of the first character
|
||||||
* @param offset
|
* @param length maximum amount of characters to be pulled
|
||||||
* index of the first character
|
|
||||||
* @param length
|
|
||||||
* maximum amount of characters to be pulled
|
|
||||||
* @return the amount of characters actually pulled
|
* @return the amount of characters actually pulled
|
||||||
*/
|
*/
|
||||||
protected int pullChars(char[] buffer, int offset, int length) {
|
protected int pullChars(char[] buffer, int offset, int length) {
|
||||||
|
@ -179,7 +179,8 @@ public interface CharReader {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips to the end of the current line. Both <code>"\n"</code>,
|
* Skips to the end of the current line. Both <code>"\n"</code>,
|
||||||
* <code>"\r"</code> and <code>"\r\n"</code> are considered line separators.
|
* <code>"\r"</code>
|
||||||
|
* and <code>"\r\n"</code> are considered line separators.
|
||||||
*
|
*
|
||||||
* @return the amount of characters in the skipped line
|
* @return the amount of characters in the skipped line
|
||||||
*/
|
*/
|
||||||
|
@ -38,7 +38,8 @@ public class StringCharReader extends AbstractCharReader {
|
|||||||
int end = offset + length;
|
int end = offset + length;
|
||||||
if (end > str.length() || offset < 0)
|
if (end > str.length() || offset < 0)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")");
|
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
|
@ -45,15 +45,8 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
|||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
ThrowingBiConsumer<? super T, ? super U, ? extends E> first,
|
ThrowingBiConsumer<? super T, ? super U, ? extends E> first,
|
||||||
ThrowingBiConsumer<? super T, ? super U, ? extends E> second) {
|
ThrowingBiConsumer<? super T, ? super U, ? extends E> second
|
||||||
return (t, u) -> {
|
) {
|
||||||
first.accept(t, u);
|
|
||||||
second.accept(t, u);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(BiConsumer<? super T, ? super U> first,
|
|
||||||
ThrowingBiConsumer<? super T, ? super U, E> second) {
|
|
||||||
return (t, u) -> {
|
return (t, u) -> {
|
||||||
first.accept(t, u);
|
first.accept(t, u);
|
||||||
second.accept(t, u);
|
second.accept(t, u);
|
||||||
@ -61,7 +54,19 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
ThrowingBiConsumer<? super T, ? super U, E> first, BiConsumer<? super T, ? super U> second) {
|
BiConsumer<? super T, ? super U> first,
|
||||||
|
ThrowingBiConsumer<? super T, ? super U, E> second
|
||||||
|
) {
|
||||||
|
return (t, u) -> {
|
||||||
|
first.accept(t, u);
|
||||||
|
second.accept(t, u);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
|
ThrowingBiConsumer<? super T, ? super U, E> first,
|
||||||
|
BiConsumer<? super T, ? super U> second
|
||||||
|
) {
|
||||||
return (t, u) -> {
|
return (t, u) -> {
|
||||||
first.accept(t, u);
|
first.accept(t, u);
|
||||||
second.accept(t, u);
|
second.accept(t, u);
|
||||||
|
@ -39,24 +39,30 @@ public interface ThrowingConsumer<T, E extends Exception> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first,
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
ThrowingConsumer<? super T, ? extends E> second) {
|
ThrowingConsumer<? super T, ? extends E> first,
|
||||||
|
ThrowingConsumer<? super T, ? extends E> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(Consumer<? super T> first,
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
ThrowingConsumer<? super T, ? extends E> second) {
|
Consumer<? super T> first,
|
||||||
|
ThrowingConsumer<? super T, ? extends E> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first,
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
Consumer<? super T> second) {
|
ThrowingConsumer<? super T, ? extends E> first,
|
||||||
|
Consumer<? super T> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
|
@ -28,8 +28,10 @@ public interface ThrowingFunction<T, R, E extends Exception> {
|
|||||||
R apply(T t) throws E;
|
R apply(T t) throws E;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default Function<T, R> withHandler(BiConsumer<? super T, ? super E> handler,
|
default Function<T, R> withHandler(
|
||||||
Function<? super T, ? extends R> value) {
|
BiConsumer<? super T, ? super E> handler,
|
||||||
|
Function<? super T, ? extends R> value
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
try {
|
try {
|
||||||
return apply(t);
|
return apply(t);
|
||||||
@ -57,17 +59,22 @@ public interface ThrowingFunction<T, R, E extends Exception> {
|
|||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
ThrowingFunction<? super T, I, ? extends E> first,
|
ThrowingFunction<? super T, I, ? extends E> first,
|
||||||
ThrowingFunction<? super I, ? extends R, ? extends E> second) {
|
ThrowingFunction<? super I, ? extends R, ? extends E> second
|
||||||
return t -> second.apply(first.apply(t));
|
) {
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(Function<? super T, I> first,
|
|
||||||
ThrowingFunction<? super I, ? extends R, E> second) {
|
|
||||||
return t -> second.apply(first.apply(t));
|
return t -> second.apply(first.apply(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
ThrowingFunction<? super T, I, E> first, Function<? super I, ? extends R> second) {
|
Function<? super T, I> first,
|
||||||
|
ThrowingFunction<? super I, ? extends R, E> second
|
||||||
|
) {
|
||||||
|
return t -> second.apply(first.apply(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
|
ThrowingFunction<? super T, I, E> first,
|
||||||
|
Function<? super I, ? extends R> second
|
||||||
|
) {
|
||||||
return t -> second.apply(first.apply(t));
|
return t -> second.apply(first.apply(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,10 @@ public interface ThrowingRunnable<E extends Exception> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E extends Exception> ThrowingRunnable<E> concat(ThrowingRunnable<? extends E> first,
|
public static <E extends Exception> ThrowingRunnable<E> concat(
|
||||||
ThrowingRunnable<? extends E> second) {
|
ThrowingRunnable<? extends E> first,
|
||||||
|
ThrowingRunnable<? extends E> second
|
||||||
|
) {
|
||||||
return () -> {
|
return () -> {
|
||||||
first.run();
|
first.run();
|
||||||
second.run();
|
second.run();
|
||||||
|
@ -49,8 +49,10 @@ public class RangeIterator<E> implements Iterator<E> {
|
|||||||
public E next() {
|
public E next() {
|
||||||
update();
|
update();
|
||||||
if (nextIndex >= from + amount) {
|
if (nextIndex >= from + amount) {
|
||||||
throw new NoSuchElementException("RangeIterator about to retrieve element " + nextIndex
|
throw new NoSuchElementException(
|
||||||
+ " which exceeds upper boundary " + (from + amount));
|
"RangeIterator about to retrieve element " + nextIndex
|
||||||
|
+ " which exceeds upper boundary " + (from + amount)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
E result = parent.next();
|
E result = parent.next();
|
||||||
|
@ -24,7 +24,7 @@ import ru.windcorp.progressia.client.graphics.world.Camera;
|
|||||||
import ru.windcorp.progressia.client.graphics.world.EntityAnchor;
|
import ru.windcorp.progressia.client.graphics.world.EntityAnchor;
|
||||||
import ru.windcorp.progressia.client.graphics.world.LocalPlayer;
|
import ru.windcorp.progressia.client.graphics.world.LocalPlayer;
|
||||||
import ru.windcorp.progressia.client.world.WorldRender;
|
import ru.windcorp.progressia.client.world.WorldRender;
|
||||||
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
@ -36,7 +36,7 @@ public class Client {
|
|||||||
|
|
||||||
private final ServerCommsChannel comms;
|
private final ServerCommsChannel comms;
|
||||||
|
|
||||||
public Client(DefaultWorldData world, ServerCommsChannel comms) {
|
public Client(WorldData world, ServerCommsChannel comms) {
|
||||||
this.world = new WorldRender(world, this);
|
this.world = new WorldRender(world, this);
|
||||||
this.comms = comms;
|
this.comms = comms;
|
||||||
|
|
||||||
@ -69,7 +69,11 @@ public class Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCamera().setAnchor(new EntityAnchor(getWorld().getEntityRenderable(entity)));
|
getCamera().setAnchor(
|
||||||
|
new EntityAnchor(
|
||||||
|
getWorld().getEntityRenderable(entity)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,10 @@ public class ClientProxy implements Proxy {
|
|||||||
try {
|
try {
|
||||||
RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init);
|
RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init);
|
||||||
RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init);
|
RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init);
|
||||||
RenderTaskQueue.waitAndInvoke(() -> Typefaces
|
RenderTaskQueue.waitAndInvoke(
|
||||||
.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz"))));
|
() -> Typefaces
|
||||||
|
.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz")))
|
||||||
|
);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw CrashReports.report(e, "ClientProxy failed");
|
throw CrashReports.report(e, "ClientProxy failed");
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ package ru.windcorp.progressia.client;
|
|||||||
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
||||||
import ru.windcorp.progressia.client.graphics.GUI;
|
import ru.windcorp.progressia.client.graphics.GUI;
|
||||||
import ru.windcorp.progressia.client.graphics.world.LayerWorld;
|
import ru.windcorp.progressia.client.graphics.world.LayerWorld;
|
||||||
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
import ru.windcorp.progressia.server.ServerState;
|
import ru.windcorp.progressia.server.ServerState;
|
||||||
import ru.windcorp.progressia.test.LayerAbout;
|
import ru.windcorp.progressia.test.LayerAbout;
|
||||||
import ru.windcorp.progressia.test.LayerTestUI;
|
import ru.windcorp.progressia.test.LayerTestUI;
|
||||||
@ -41,9 +41,11 @@ public class ClientState {
|
|||||||
|
|
||||||
public static void connectToLocalServer() {
|
public static void connectToLocalServer() {
|
||||||
|
|
||||||
DefaultWorldData world = new DefaultWorldData();
|
WorldData world = new WorldData();
|
||||||
|
|
||||||
LocalServerCommsChannel channel = new LocalServerCommsChannel(ServerState.getInstance());
|
LocalServerCommsChannel channel = new LocalServerCommsChannel(
|
||||||
|
ServerState.getInstance()
|
||||||
|
);
|
||||||
|
|
||||||
Client client = new Client(world, channel);
|
Client client = new Client(world, channel);
|
||||||
|
|
||||||
|
@ -43,7 +43,10 @@ public class AudioManager {
|
|||||||
private static Speaker musicSpeaker;
|
private static Speaker musicSpeaker;
|
||||||
|
|
||||||
public static void initAL() {
|
public static void initAL() {
|
||||||
String defaultDeviceName = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER);
|
String defaultDeviceName = alcGetString(
|
||||||
|
0,
|
||||||
|
ALC_DEFAULT_DEVICE_SPECIFIER
|
||||||
|
);
|
||||||
|
|
||||||
device = alcOpenDevice(defaultDeviceName);
|
device = alcOpenDevice(defaultDeviceName);
|
||||||
|
|
||||||
@ -72,7 +75,10 @@ public class AudioManager {
|
|||||||
lastSoundIndex = 0;
|
lastSoundIndex = 0;
|
||||||
}
|
}
|
||||||
speaker = soundSpeakers.get(lastSoundIndex);
|
speaker = soundSpeakers.get(lastSoundIndex);
|
||||||
} while (speaker.getState().equals(Speaker.State.PLAYING_LOOP));
|
} while (
|
||||||
|
speaker.getState()
|
||||||
|
.equals(Speaker.State.PLAYING_LOOP)
|
||||||
|
);
|
||||||
return speaker;
|
return speaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,10 @@ public class AudioSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void loadAudioData() {
|
static void loadAudioData() {
|
||||||
AudioManager.loadSound(ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"),
|
AudioManager.loadSound(
|
||||||
"Progressia:BlockDestroy", AudioFormat.MONO);
|
ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"),
|
||||||
|
"Progressia:BlockDestroy",
|
||||||
|
AudioFormat.MONO
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,10 @@ import glm.vec._3.Vec3;
|
|||||||
import ru.windcorp.progressia.client.audio.backend.SoundType;
|
import ru.windcorp.progressia.client.audio.backend.SoundType;
|
||||||
import ru.windcorp.progressia.client.audio.backend.Speaker;
|
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) {
|
public Music(SoundType soundType, int timeLength, float pitch, float gain) {
|
||||||
super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain);
|
super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain);
|
||||||
|
@ -40,7 +40,14 @@ public class Sound {
|
|||||||
this(AudioRegistry.getInstance().get(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(id);
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
@ -48,7 +55,14 @@ public class Sound {
|
|||||||
this.gain = gain;
|
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(soundType);
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
|
@ -39,7 +39,12 @@ public class AudioReader {
|
|||||||
|
|
||||||
ShortBuffer rawAudio = decodeVorbis(resource, channelBuffer, rateBuffer);
|
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) {
|
public static SoundType readAsMono(Resource resource, String id) {
|
||||||
@ -50,7 +55,15 @@ public class AudioReader {
|
|||||||
return readAsSpecified(resource, id, AL_FORMAT_STEREO16);
|
return readAsSpecified(resource, id, AL_FORMAT_STEREO16);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ShortBuffer decodeVorbis(Resource dataToDecode, IntBuffer channelsBuffer, IntBuffer rateBuffer) {
|
private static ShortBuffer decodeVorbis(
|
||||||
return stb_vorbis_decode_memory(dataToDecode.readAsBytes(), channelsBuffer, rateBuffer);
|
Resource dataToDecode,
|
||||||
|
IntBuffer channelsBuffer,
|
||||||
|
IntBuffer rateBuffer
|
||||||
|
) {
|
||||||
|
return stb_vorbis_decode_memory(
|
||||||
|
dataToDecode.readAsBytes(),
|
||||||
|
channelsBuffer,
|
||||||
|
rateBuffer
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,9 @@ public class Listener {
|
|||||||
if (isInWorld) {
|
if (isInWorld) {
|
||||||
|
|
||||||
if (wasInWorld) {
|
if (wasInWorld) {
|
||||||
velocity.set(camera.getLastAnchorPosition()).sub(position)
|
velocity.set(camera.getLastAnchorPosition()).sub(position).div(
|
||||||
.div((float) GraphicsInterface.getFrameLength());
|
(float) GraphicsInterface.getFrameLength()
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// If !wasInWorld, previous position is nonsence. Assume 0.
|
// If !wasInWorld, previous position is nonsence. Assume 0.
|
||||||
velocity.set(0);
|
velocity.set(0);
|
||||||
@ -71,9 +72,9 @@ public class Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only apply if there is a chance that params changed. This can only
|
* Only apply if there is a chance that params changed.
|
||||||
* happen if we are in world now (isInWorld) or we just left world
|
* This can only happen if we are in world now (isInWorld) or we just
|
||||||
* (wasInWorld, then we need to reset).
|
* left world (wasInWorld, then we need to reset).
|
||||||
*/
|
*/
|
||||||
if (isInWorld || wasInWorld) {
|
if (isInWorld || wasInWorld) {
|
||||||
applyParams();
|
applyParams();
|
||||||
@ -90,7 +91,17 @@ public class Listener {
|
|||||||
private void applyParams() {
|
private void applyParams() {
|
||||||
alListener3f(AL_POSITION, position.x, position.y, position.z);
|
alListener3f(AL_POSITION, position.x, position.y, position.z);
|
||||||
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.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
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,12 @@ public class SoundType extends Namespaced {
|
|||||||
private int audioBuffer;
|
private int audioBuffer;
|
||||||
private double duration;
|
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);
|
super(id);
|
||||||
this.rawAudio = rawAudio;
|
this.rawAudio = rawAudio;
|
||||||
this.sampleRate = sampleRate;
|
this.sampleRate = sampleRate;
|
||||||
|
@ -24,7 +24,9 @@ import static org.lwjgl.openal.AL11.*;
|
|||||||
public class Speaker {
|
public class Speaker {
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
NOT_PLAYING, PLAYING, PLAYING_LOOP
|
NOT_PLAYING,
|
||||||
|
PLAYING,
|
||||||
|
PLAYING_LOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffers
|
// Buffers
|
||||||
@ -47,7 +49,13 @@ public class Speaker {
|
|||||||
setAudioData(audioData);
|
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);
|
setAudioData(audioData);
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
setVelocity(velocity);
|
setVelocity(velocity);
|
||||||
@ -55,7 +63,12 @@ public class Speaker {
|
|||||||
setGain(gain);
|
setGain(gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Speaker(Vec3 position, Vec3 velocity, float pitch, float gain) {
|
public Speaker(
|
||||||
|
Vec3 position,
|
||||||
|
Vec3 velocity,
|
||||||
|
float pitch,
|
||||||
|
float gain
|
||||||
|
) {
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
setVelocity(velocity);
|
setVelocity(velocity);
|
||||||
setPitch(pitch);
|
setPitch(pitch);
|
||||||
|
@ -39,7 +39,9 @@ public class DefaultClientCommsListener implements CommsListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPacketReceived(Packet packet) {
|
public void onPacketReceived(Packet packet) {
|
||||||
if (packet instanceof PacketAffectWorld) {
|
if (packet instanceof PacketAffectWorld) {
|
||||||
((PacketAffectWorld) packet).apply(getClient().getWorld().getData());
|
((PacketAffectWorld) packet).apply(
|
||||||
|
getClient().getWorld().getData()
|
||||||
|
);
|
||||||
} else if (packet instanceof PacketSetLocalPlayer) {
|
} else if (packet instanceof PacketSetLocalPlayer) {
|
||||||
setLocalPlayer((PacketSetLocalPlayer) packet);
|
setLocalPlayer((PacketSetLocalPlayer) packet);
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,17 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
|||||||
private final Predicate<InputEvent> predicate;
|
private final Predicate<InputEvent> predicate;
|
||||||
private final BiConsumer<InputEvent, ControlData> dataWriter;
|
private final BiConsumer<InputEvent, ControlData> dataWriter;
|
||||||
|
|
||||||
public ControlTriggerLambda(String id, Predicate<InputEvent> predicate,
|
public ControlTriggerLambda(
|
||||||
BiConsumer<InputEvent, ControlData> dataWriter) {
|
String id,
|
||||||
|
Predicate<InputEvent> predicate,
|
||||||
|
BiConsumer<InputEvent, ControlData> dataWriter
|
||||||
|
) {
|
||||||
super(id);
|
super(id);
|
||||||
|
|
||||||
this.packetId = NamespacedUtil.getId(NamespacedUtil.getNamespace(id),
|
this.packetId = NamespacedUtil.getId(
|
||||||
"ControlKeyPress" + NamespacedUtil.getName(id));
|
NamespacedUtil.getNamespace(id),
|
||||||
|
"ControlKeyPress" + NamespacedUtil.getName(id)
|
||||||
|
);
|
||||||
|
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
this.dataWriter = dataWriter;
|
this.dataWriter = dataWriter;
|
||||||
@ -49,7 +54,10 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
|||||||
if (!predicate.test(event))
|
if (!predicate.test(event))
|
||||||
return null;
|
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());
|
dataWriter.accept(event, packet.getControl());
|
||||||
|
|
||||||
|
@ -29,7 +29,11 @@ public class ControlTriggerLocalLambda extends ControlTriggerInputBased {
|
|||||||
private final Predicate<InputEvent> predicate;
|
private final Predicate<InputEvent> predicate;
|
||||||
private final Consumer<InputEvent> action;
|
private final Consumer<InputEvent> action;
|
||||||
|
|
||||||
public ControlTriggerLocalLambda(String id, Predicate<InputEvent> predicate, Consumer<InputEvent> action) {
|
public ControlTriggerLocalLambda(
|
||||||
|
String id,
|
||||||
|
Predicate<InputEvent> predicate,
|
||||||
|
Consumer<InputEvent> action
|
||||||
|
) {
|
||||||
super(id);
|
super(id);
|
||||||
|
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
|
@ -27,57 +27,120 @@ import ru.windcorp.progressia.common.comms.controls.ControlData;
|
|||||||
|
|
||||||
public class ControlTriggers {
|
public class ControlTriggers {
|
||||||
|
|
||||||
public static ControlTriggerInputBased of(String id, BiConsumer<InputEvent, ControlData> dataWriter,
|
public static ControlTriggerInputBased of(
|
||||||
Predicate<InputEvent> predicate) {
|
String id,
|
||||||
|
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||||
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
return new ControlTriggerLambda(id, predicate, dataWriter);
|
return new ControlTriggerLambda(id, predicate, dataWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlTriggerInputBased of(String id, Consumer<ControlData> dataWriter,
|
public static ControlTriggerInputBased of(
|
||||||
Predicate<InputEvent> predicate) {
|
String id,
|
||||||
return of(id, (input, control) -> dataWriter.accept(control), predicate);
|
Consumer<ControlData> dataWriter,
|
||||||
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
(input, control) -> dataWriter.accept(control),
|
||||||
|
predicate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlTriggerInputBased of(String id, Predicate<InputEvent> predicate) {
|
public static ControlTriggerInputBased of(
|
||||||
return of(id, (input, control) -> {
|
String id,
|
||||||
}, predicate);
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
(input, control) -> {
|
||||||
|
},
|
||||||
|
predicate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||||
BiConsumer<I, ControlData> dataWriter, Predicate<I>... predicates) {
|
String id,
|
||||||
return of(id, createCheckedDataWriter(inputType, dataWriter),
|
Class<I> inputType,
|
||||||
createCheckedCompoundPredicate(inputType, predicates));
|
BiConsumer<I, ControlData> dataWriter,
|
||||||
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
createCheckedDataWriter(inputType, dataWriter),
|
||||||
|
createCheckedCompoundPredicate(inputType, predicates)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||||
Consumer<ControlData> dataWriter, Predicate<I>... predicates) {
|
String id,
|
||||||
return of(id, inputType, (input, control) -> dataWriter.accept(control), predicates);
|
Class<I> inputType,
|
||||||
|
Consumer<ControlData> dataWriter,
|
||||||
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
inputType,
|
||||||
|
(input, control) -> dataWriter.accept(control),
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||||
Predicate<I>... predicates) {
|
String id,
|
||||||
return of(id, (input, control) -> {
|
Class<I> inputType,
|
||||||
}, createCheckedCompoundPredicate(inputType, predicates));
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
(input, control) -> {
|
||||||
|
},
|
||||||
|
createCheckedCompoundPredicate(inputType, predicates)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static ControlTriggerInputBased of(String id, BiConsumer<InputEvent, ControlData> dataWriter,
|
public static ControlTriggerInputBased of(
|
||||||
Predicate<InputEvent>... predicates) {
|
String id,
|
||||||
return of(id, InputEvent.class, dataWriter, predicates);
|
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||||
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
InputEvent.class,
|
||||||
|
dataWriter,
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Consumer<ControlData> dataWriter,
|
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||||
Predicate<InputEvent>... predicates) {
|
String id,
|
||||||
return of(id, (input, control) -> dataWriter.accept(control), predicates);
|
Consumer<ControlData> dataWriter,
|
||||||
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
(input, control) -> dataWriter.accept(control),
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static ControlTriggerInputBased of(String id, Predicate<InputEvent>... predicates) {
|
public static ControlTriggerInputBased of(
|
||||||
return of(id, InputEvent.class, (input, control) -> {
|
String id,
|
||||||
}, predicates);
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
InputEvent.class,
|
||||||
|
(input, control) -> {
|
||||||
|
},
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -94,52 +157,100 @@ public class ControlTriggers {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
public static ControlTriggerInputBased localOf(String id, Consumer<InputEvent> action,
|
public static ControlTriggerInputBased localOf(
|
||||||
Predicate<InputEvent> predicate) {
|
String id,
|
||||||
|
Consumer<InputEvent> action,
|
||||||
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
return new ControlTriggerLocalLambda(id, predicate, action);
|
return new ControlTriggerLocalLambda(id, predicate, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlTriggerInputBased localOf(String id, Runnable action, Predicate<InputEvent> predicate) {
|
public static ControlTriggerInputBased localOf(
|
||||||
return localOf(id, input -> action.run(), predicate);
|
String id,
|
||||||
|
Runnable action,
|
||||||
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
|
return localOf(
|
||||||
|
id,
|
||||||
|
input -> action.run(),
|
||||||
|
predicate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased localOf(
|
||||||
Consumer<I> action, Predicate<I>... predicates) {
|
String id,
|
||||||
return localOf(id, createCheckedAction(inputType, action),
|
Class<I> inputType,
|
||||||
createCheckedCompoundPredicate(inputType, predicates));
|
Consumer<I> action,
|
||||||
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return localOf(
|
||||||
|
id,
|
||||||
|
createCheckedAction(inputType, action),
|
||||||
|
createCheckedCompoundPredicate(inputType, predicates)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased localOf(
|
||||||
Runnable action, Predicate<I>... predicates) {
|
String id,
|
||||||
return localOf(id, inputType, input -> action.run(), predicates);
|
Class<I> inputType,
|
||||||
|
Runnable action,
|
||||||
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return localOf(
|
||||||
|
id,
|
||||||
|
inputType,
|
||||||
|
input -> action.run(),
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static ControlTriggerInputBased localOf(String id, Consumer<InputEvent> action,
|
public static ControlTriggerInputBased localOf(
|
||||||
Predicate<InputEvent>... predicates) {
|
String id,
|
||||||
return localOf(id, InputEvent.class, action, predicates);
|
Consumer<InputEvent> action,
|
||||||
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return localOf(
|
||||||
|
id,
|
||||||
|
InputEvent.class,
|
||||||
|
action,
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Runnable action,
|
public static <I extends InputEvent> ControlTriggerInputBased localOf(
|
||||||
Predicate<InputEvent>... predicates) {
|
String id,
|
||||||
return of(id, input -> action.run(), predicates);
|
Runnable action,
|
||||||
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
input -> action.run(),
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <I extends InputEvent> BiConsumer<InputEvent, ControlData> createCheckedDataWriter(
|
private static <I extends InputEvent> BiConsumer<InputEvent, ControlData> createCheckedDataWriter(
|
||||||
Class<I> inputType, BiConsumer<I, ControlData> dataWriter) {
|
Class<I> inputType,
|
||||||
|
BiConsumer<I, ControlData> dataWriter
|
||||||
|
) {
|
||||||
return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control);
|
return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <I extends InputEvent> Consumer<InputEvent> createCheckedAction(Class<I> inputType,
|
private static <I extends InputEvent> Consumer<InputEvent> createCheckedAction(
|
||||||
Consumer<I> action) {
|
Class<I> inputType,
|
||||||
|
Consumer<I> action
|
||||||
|
) {
|
||||||
return inputEvent -> action.accept(inputType.cast(inputEvent));
|
return inputEvent -> action.accept(inputType.cast(inputEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate(Class<I> inputType,
|
private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate(
|
||||||
Predicate<I>[] predicates) {
|
Class<I> inputType,
|
||||||
|
Predicate<I>[] predicates
|
||||||
|
) {
|
||||||
return new CompoundCastPredicate<>(inputType, predicates);
|
return new CompoundCastPredicate<>(inputType, predicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ public class InputBasedControls {
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
this.controls = ControlTriggerRegistry.getInstance().values().stream()
|
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) {
|
public void handleInput(Input input) {
|
||||||
|
@ -34,7 +34,11 @@ public class LocalServerCommsChannel extends ServerCommsChannel {
|
|||||||
public void connect(String login) {
|
public void connect(String login) {
|
||||||
setState(State.CONNECTED);
|
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);
|
server.getClientManager().addClient(localClient);
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,7 @@ public class Colors {
|
|||||||
DEBUG_BLUE = toVector(0xFF0000FF),
|
DEBUG_BLUE = toVector(0xFF0000FF),
|
||||||
DEBUG_CYAN = toVector(0xFF00FFFF),
|
DEBUG_CYAN = toVector(0xFF00FFFF),
|
||||||
DEBUG_MAGENTA = toVector(0xFFFF00FF),
|
DEBUG_MAGENTA = toVector(0xFFFF00FF),
|
||||||
DEBUG_YELLOW = toVector(0xFFFFFF00),
|
DEBUG_YELLOW = toVector(0xFFFFFF00);
|
||||||
|
|
||||||
LIGHT_GRAY = toVector(0xFFCBCBD0),
|
|
||||||
BLUE = toVector(0xFF37A2E6),
|
|
||||||
HOVER_BLUE = toVector(0xFFC3E4F7),
|
|
||||||
DISABLED_GRAY = toVector(0xFFE5E5E5),
|
|
||||||
DISABLED_BLUE = toVector(0xFFB2D8ED);
|
|
||||||
|
|
||||||
public static Vec4 toVector(int argb) {
|
public static Vec4 toVector(int argb) {
|
||||||
return toVector(argb, new Vec4());
|
return toVector(argb, new Vec4());
|
||||||
|
@ -24,7 +24,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.CursorEvent;
|
import ru.windcorp.progressia.client.graphics.input.CursorEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.input.FrameResizeEvent;
|
import ru.windcorp.progressia.client.graphics.input.FrameResizeEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
@ -58,24 +57,15 @@ public class GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void addBottomLayer(Layer layer) {
|
public static void addBottomLayer(Layer layer) {
|
||||||
modify(layers -> {
|
modify(layers -> layers.add(layer));
|
||||||
layers.add(layer);
|
|
||||||
layer.onAdded();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addTopLayer(Layer layer) {
|
public static void addTopLayer(Layer layer) {
|
||||||
modify(layers -> {
|
modify(layers -> layers.add(0, layer));
|
||||||
layers.add(0, layer);
|
|
||||||
layer.onAdded();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeLayer(Layer layer) {
|
public static void removeLayer(Layer layer) {
|
||||||
modify(layers -> {
|
modify(layers -> layers.remove(layer));
|
||||||
layers.remove(layer);
|
|
||||||
layer.onRemoved();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void modify(LayerStackModification mod) {
|
private static void modify(LayerStackModification mod) {
|
||||||
@ -88,33 +78,12 @@ public class GUI {
|
|||||||
|
|
||||||
public static void render() {
|
public static void render() {
|
||||||
synchronized (LAYERS) {
|
synchronized (LAYERS) {
|
||||||
|
|
||||||
if (!MODIFICATION_QUEUE.isEmpty()) {
|
|
||||||
MODIFICATION_QUEUE.forEach(action -> action.affect(LAYERS));
|
MODIFICATION_QUEUE.forEach(action -> action.affect(LAYERS));
|
||||||
MODIFICATION_QUEUE.clear();
|
MODIFICATION_QUEUE.clear();
|
||||||
|
|
||||||
boolean isMouseCurrentlyCaptured = GraphicsInterface.isMouseCaptured();
|
|
||||||
Layer.CursorPolicy policy = Layer.CursorPolicy.REQUIRE;
|
|
||||||
|
|
||||||
for (Layer layer : LAYERS) {
|
|
||||||
Layer.CursorPolicy currentPolicy = layer.getCursorPolicy();
|
|
||||||
|
|
||||||
if (currentPolicy != Layer.CursorPolicy.INDIFFERENT) {
|
|
||||||
policy = currentPolicy;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shouldCaptureMouse = (policy == Layer.CursorPolicy.FORBID);
|
|
||||||
if (shouldCaptureMouse != isMouseCurrentlyCaptured) {
|
|
||||||
GraphicsInterface.setMouseCaptured(shouldCaptureMouse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = LAYERS.size() - 1; i >= 0; --i) {
|
for (int i = LAYERS.size() - 1; i >= 0; --i) {
|
||||||
LAYERS.get(i).render();
|
LAYERS.get(i).render();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,52 +31,15 @@ public abstract class Layer {
|
|||||||
|
|
||||||
private final AtomicBoolean isValid = new AtomicBoolean(false);
|
private final AtomicBoolean isValid = new AtomicBoolean(false);
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents various requests that a {@link Layer} can make regarding the
|
|
||||||
* presence of a visible cursor. The value of the highest layer that is not
|
|
||||||
* {@link #INDIFFERENT} is used.
|
|
||||||
*/
|
|
||||||
public static enum CursorPolicy {
|
|
||||||
/**
|
|
||||||
* Require that a cursor is visible.
|
|
||||||
*/
|
|
||||||
REQUIRE,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link Layer} should not affect the presence or absence of a
|
|
||||||
* visible cursor; lower layers should be consulted.
|
|
||||||
*/
|
|
||||||
INDIFFERENT,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Forbid a visible cursor.
|
|
||||||
*/
|
|
||||||
FORBID
|
|
||||||
}
|
|
||||||
|
|
||||||
private CursorPolicy cursorPolicy = CursorPolicy.INDIFFERENT;
|
|
||||||
|
|
||||||
public Layer(String name) {
|
public Layer(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Layer " + name;
|
return "Layer " + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CursorPolicy getCursorPolicy() {
|
|
||||||
return cursorPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCursorPolicy(CursorPolicy cursorPolicy) {
|
|
||||||
this.cursorPolicy = cursorPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
void render() {
|
void render() {
|
||||||
GraphicsInterface.startNextLayer();
|
GraphicsInterface.startNextLayer();
|
||||||
|
|
||||||
@ -116,12 +79,4 @@ public abstract class Layer {
|
|||||||
return GraphicsInterface.getFrameHeight();
|
return GraphicsInterface.getFrameHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onAdded() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onRemoved() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -159,14 +159,27 @@ public class GraphicsBackend {
|
|||||||
|
|
||||||
public static void setFullscreen() {
|
public static void setFullscreen() {
|
||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
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;
|
isFullscreen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setWindowed() {
|
public static void setWindowed() {
|
||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
glfwSetWindowMonitor(getWindowHandle(), 0, (vidmode.width() - getFrameWidth()) / 2,
|
glfwSetWindowMonitor(
|
||||||
(vidmode.height() - getFrameHeight()) / 2, getFrameWidth(), getFrameHeight(), 0);
|
getWindowHandle(),
|
||||||
|
0,
|
||||||
|
(vidmode.width() - getFrameWidth()) / 2,
|
||||||
|
(vidmode.height() - getFrameHeight()) / 2,
|
||||||
|
getFrameWidth(),
|
||||||
|
getFrameHeight(),
|
||||||
|
0);
|
||||||
isFullscreen = false;
|
isFullscreen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,18 +192,4 @@ public class GraphicsBackend {
|
|||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
return vidmode.refreshRate();
|
return vidmode.refreshRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMouseCaptured() {
|
|
||||||
return glfwGetInputMode(windowHandle, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setMouseCaptured(boolean capture) {
|
|
||||||
int mode = capture ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL;
|
|
||||||
glfwSetInputMode(windowHandle, GLFW_CURSOR, mode);
|
|
||||||
|
|
||||||
if (!capture) {
|
|
||||||
glfwSetCursorPos(windowHandle, FRAME_SIZE.x / 2.0, FRAME_SIZE.y / 2.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -82,12 +82,4 @@ public class GraphicsInterface {
|
|||||||
GraphicsBackend.setVSyncEnabled(GraphicsBackend.isVSyncEnabled());
|
GraphicsBackend.setVSyncEnabled(GraphicsBackend.isVSyncEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMouseCaptured() {
|
|
||||||
return GraphicsBackend.isMouseCaptured();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setMouseCaptured(boolean capture) {
|
|
||||||
GraphicsBackend.setMouseCaptured(capture);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,13 @@ public class InputHandler {
|
|||||||
|
|
||||||
private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent();
|
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)
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
return;
|
return;
|
||||||
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
||||||
@ -65,7 +71,12 @@ 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);
|
handleKeyInput(window, key, Integer.MAX_VALUE - key, action, mods);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +97,11 @@ public class InputHandler {
|
|||||||
|
|
||||||
private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT = new ModifiableCursorMoveEvent();
|
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)
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
return;
|
return;
|
||||||
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
|
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
|
||||||
@ -116,7 +131,11 @@ public class InputHandler {
|
|||||||
|
|
||||||
private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT = new ModifiableWheelScrollEvent();
|
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)
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
return;
|
return;
|
||||||
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
|
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
|
||||||
@ -143,7 +162,10 @@ public class InputHandler {
|
|||||||
/*
|
/*
|
||||||
* NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend
|
* 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);
|
THE_FRAME_RESIZE_EVENT.initialize(width, height);
|
||||||
dispatch(THE_FRAME_RESIZE_EVENT);
|
dispatch(THE_FRAME_RESIZE_EVENT);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,10 @@ import gnu.trove.set.hash.TIntHashSet;
|
|||||||
|
|
||||||
public class InputTracker {
|
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);
|
private static final TIntSet PRESSED_KEYS = new TIntHashSet(256);
|
||||||
|
|
||||||
|
@ -65,6 +65,8 @@ class LWJGLInitializer {
|
|||||||
|
|
||||||
GraphicsBackend.setWindowHandle(handle);
|
GraphicsBackend.setWindowHandle(handle);
|
||||||
|
|
||||||
|
glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
|
||||||
glfwMakeContextCurrent(handle);
|
glfwMakeContextCurrent(handle);
|
||||||
glfwSwapInterval(0); // TODO: remove after config system is added
|
glfwSwapInterval(0); // TODO: remove after config system is added
|
||||||
}
|
}
|
||||||
@ -92,10 +94,16 @@ class LWJGLInitializer {
|
|||||||
private static void setupWindowCallbacks() {
|
private static void setupWindowCallbacks() {
|
||||||
long handle = GraphicsBackend.getWindowHandle();
|
long handle = GraphicsBackend.getWindowHandle();
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(handle, GraphicsBackend::onFrameResized);
|
glfwSetFramebufferSizeCallback(
|
||||||
|
handle,
|
||||||
|
GraphicsBackend::onFrameResized
|
||||||
|
);
|
||||||
|
|
||||||
glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
|
glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
|
||||||
glfwSetMouseButtonCallback(handle, InputHandler::handleMouseButtonInput);
|
glfwSetMouseButtonCallback(
|
||||||
|
handle,
|
||||||
|
InputHandler::handleMouseButtonInput
|
||||||
|
);
|
||||||
|
|
||||||
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);
|
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);
|
||||||
|
|
||||||
|
@ -34,13 +34,19 @@ public class OpenGLObjectTracker {
|
|||||||
private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>();
|
private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>();
|
||||||
|
|
||||||
public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) {
|
public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) {
|
||||||
GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>(object, DELETE_QUEUE, object.getHandle(),
|
GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>(
|
||||||
glDeleter);
|
object,
|
||||||
|
DELETE_QUEUE,
|
||||||
|
object.getHandle(),
|
||||||
|
glDeleter
|
||||||
|
);
|
||||||
TO_DELETE.add(glRef);
|
TO_DELETE.add(glRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteAllObjects() {
|
public static void deleteAllObjects() {
|
||||||
for (GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE) {
|
for (
|
||||||
|
GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE
|
||||||
|
) {
|
||||||
glRef.clear();
|
glRef.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,16 +75,20 @@ public class OpenGLObjectTracker {
|
|||||||
* It is possible to create a phantom reference with a {@code null}
|
* It is possible to create a phantom reference with a {@code null}
|
||||||
* queue, but such a reference is completely useless: Its {@code get}
|
* queue, but such a reference is completely useless: Its {@code get}
|
||||||
* method will always return {@code null} and, since it does not have a
|
* 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
|
* @param referent the object the new phantom reference will refer to
|
||||||
* the object the new phantom reference will refer to
|
* @param q the queue with which the reference is to be
|
||||||
* @param q
|
* registered,
|
||||||
* the queue with which the reference is to be registered, or
|
* or {@code null} if registration is not required
|
||||||
* {@code null} if registration is not required
|
|
||||||
*/
|
*/
|
||||||
public GLPhantomReference(T referent, ReferenceQueue<? super T> q, int referentGLhandle,
|
public GLPhantomReference(
|
||||||
IntConsumer GLDeleter) {
|
T referent,
|
||||||
|
ReferenceQueue<? super T> q,
|
||||||
|
int referentGLhandle,
|
||||||
|
IntConsumer GLDeleter
|
||||||
|
) {
|
||||||
super(referent, q);
|
super(referent, q);
|
||||||
this.referentGLhandle = referentGLhandle;
|
this.referentGLhandle = referentGLhandle;
|
||||||
this.GLDeleter = GLDeleter;
|
this.GLDeleter = GLDeleter;
|
||||||
|
@ -41,7 +41,11 @@ public class RenderTaskQueue {
|
|||||||
HANDLER.invokeNow(task);
|
HANDLER.invokeNow(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E extends Exception> void waitAndInvoke(ThrowingRunnable<E> task) throws InterruptedException, E {
|
public static <E extends Exception> void waitAndInvoke(
|
||||||
|
ThrowingRunnable<E> task
|
||||||
|
)
|
||||||
|
throws InterruptedException,
|
||||||
|
E {
|
||||||
HANDLER.waitAndInvoke(task);
|
HANDLER.waitAndInvoke(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,9 @@ import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;
|
|||||||
import static org.lwjgl.opengl.GL15.GL_STREAM_DRAW;
|
import static org.lwjgl.opengl.GL15.GL_STREAM_DRAW;
|
||||||
|
|
||||||
public enum Usage { // TODO add _COPY and _READ, pref. as another enum
|
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;
|
private final int glCode;
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ import ru.windcorp.progressia.client.graphics.backend.OpenGLObjectTracker.OpenGL
|
|||||||
public class VertexBufferObject implements OpenGLDeletable {
|
public class VertexBufferObject implements OpenGLDeletable {
|
||||||
|
|
||||||
public static enum BindTarget {
|
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;
|
private final int glCode;
|
||||||
|
|
||||||
|
@ -32,7 +32,12 @@ public class CombinedShader extends Shader {
|
|||||||
for (int i = 1; i < resources.length; ++i) {
|
for (int i = 1; i < resources.length; ++i) {
|
||||||
if (ShaderType.guessByResourceName(resources[i]) != first) {
|
if (ShaderType.guessByResourceName(resources[i]) != first) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Deduced shader types of " + resources[0] + " and " + resources[i] + " differ");
|
"Deduced shader types of "
|
||||||
|
+ resources[0]
|
||||||
|
+ " and "
|
||||||
|
+ resources[i]
|
||||||
|
+ " differ"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +71,19 @@ public class CombinedShader extends Shader {
|
|||||||
if (contents.codePointAt(versionIndex) == '#') {
|
if (contents.codePointAt(versionIndex) == '#') {
|
||||||
final String versionAnnotation = "#version ";
|
final String versionAnnotation = "#version ";
|
||||||
|
|
||||||
if (contents.regionMatches(versionIndex, versionAnnotation, 0, versionAnnotation.length())) {
|
if (
|
||||||
contents = contents.substring(versionIndex + versionAnnotation.length() + "120".length());
|
contents.regionMatches(
|
||||||
|
versionIndex,
|
||||||
|
versionAnnotation,
|
||||||
|
0,
|
||||||
|
versionAnnotation.length()
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
contents = contents.substring(
|
||||||
|
versionIndex
|
||||||
|
+ versionAnnotation.length()
|
||||||
|
+ "120".length()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,10 @@ public class Shader implements OpenGLDeletable {
|
|||||||
if (resource.contains("fsh"))
|
if (resource.contains("fsh"))
|
||||||
return FRAGMENT;
|
return FRAGMENT;
|
||||||
|
|
||||||
throw new IllegalArgumentException("Cannot deduce shader type from resource name \"" + resource + "\"");
|
throw new IllegalArgumentException(
|
||||||
|
"Cannot deduce shader type from resource name \"" +
|
||||||
|
resource + "\""
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +90,10 @@ public class Shader implements OpenGLDeletable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Shader(String resource) {
|
public Shader(String resource) {
|
||||||
this(ShaderType.guessByResourceName(resource), getShaderResource(resource).readAsString());
|
this(
|
||||||
|
ShaderType.guessByResourceName(resource),
|
||||||
|
getShaderResource(resource).readAsString()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,29 +51,104 @@ public class AttributeVertexArray extends Attribute {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(int size, boolean normalized, int stride, ByteBuffer pointer) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, GL_BYTE, normalized, stride, pointer);
|
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) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, GL_FLOAT, normalized, stride, pointer);
|
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) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, GL_INT, normalized, stride, pointer);
|
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) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, GL_SHORT, normalized, stride, pointer);
|
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) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, type, normalized, stride, pointer);
|
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());
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle());
|
||||||
glVertexAttribPointer(handle, size, type, normalized, stride, offset);
|
glVertexAttribPointer(
|
||||||
|
handle,
|
||||||
|
size,
|
||||||
|
type,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
offset
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ public abstract class FlatRenderHelper extends ShapeRenderHelper {
|
|||||||
float width = GraphicsInterface.getFrameWidth();
|
float width = GraphicsInterface.getFrameWidth();
|
||||||
float height = GraphicsInterface.getFrameHeight();
|
float height = GraphicsInterface.getFrameHeight();
|
||||||
|
|
||||||
return finalTransform.identity().translate(-1, -1, 0).scale(2 / width, 2 / height, 1 / MAX_DEPTH)
|
return finalTransform.identity().translate(-1, -1, 0)
|
||||||
|
.scale(2 / width, 2 / height, 1 / MAX_DEPTH)
|
||||||
.mul(getTransform());
|
.mul(getTransform());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,10 @@ public class FlatRenderProgram extends ShapeRenderProgram {
|
|||||||
private static FlatRenderProgram def = null;
|
private static FlatRenderProgram def = null;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
def = new FlatRenderProgram(new String[] { "FlatDefault.vertex.glsl" },
|
def = new FlatRenderProgram(
|
||||||
new String[] { "FlatDefault.fragment.glsl" });
|
new String[] { "FlatDefault.vertex.glsl" },
|
||||||
|
new String[] { "FlatDefault.fragment.glsl" }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FlatRenderProgram getDefault() {
|
public static FlatRenderProgram getDefault() {
|
||||||
@ -46,13 +48,20 @@ public class FlatRenderProgram extends ShapeRenderProgram {
|
|||||||
private static final String FLAT_VERTEX_SHADER_RESOURCE = "Flat.vertex.glsl";
|
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 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 Uniform1Int maskCountUniform;
|
||||||
private final Uniform2Float masksUniform;
|
private final Uniform2Float masksUniform;
|
||||||
|
|
||||||
public FlatRenderProgram(String[] vertexShaderResources, String[] fragmentShaderResources) {
|
public FlatRenderProgram(
|
||||||
super(attachVertexShader(vertexShaderResources), attachFragmentShader(fragmentShaderResources));
|
String[] vertexShaderResources,
|
||||||
|
String[] fragmentShaderResources
|
||||||
|
) {
|
||||||
|
super(
|
||||||
|
attachVertexShader(vertexShaderResources),
|
||||||
|
attachFragmentShader(fragmentShaderResources)
|
||||||
|
);
|
||||||
|
|
||||||
this.maskCountUniform = getUniform(MASK_COUNT_UNIFORM_NAME).as1Int();
|
this.maskCountUniform = getUniform(MASK_COUNT_UNIFORM_NAME).as1Int();
|
||||||
this.masksUniform = getUniform(MASKS_UNIFORM_NAME).as2Float();
|
this.masksUniform = getUniform(MASKS_UNIFORM_NAME).as2Float();
|
||||||
|
@ -88,7 +88,8 @@ public class Mask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "(" + getStartX() + "; " + getStartY() + ") -> (" + getEndX() + "; " + getEndY() + ")";
|
return "(" + getStartX() + "; " + getStartY() +
|
||||||
|
") -> (" + getEndX() + "; " + getEndY() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,9 @@ import org.lwjgl.BufferUtils;
|
|||||||
|
|
||||||
public class MaskStack {
|
public class MaskStack {
|
||||||
|
|
||||||
private final FloatBuffer buffer = BufferUtils
|
private final FloatBuffer buffer = BufferUtils.createFloatBuffer(
|
||||||
.createFloatBuffer(FlatRenderProgram.MASK_STACK_SIZE * TransformedMask.SIZE_IN_FLOATS);
|
FlatRenderProgram.MASK_STACK_SIZE * TransformedMask.SIZE_IN_FLOATS
|
||||||
|
);
|
||||||
|
|
||||||
public void pushMask(TransformedMask mask) {
|
public void pushMask(TransformedMask mask) {
|
||||||
mask.writeToBuffer(buffer);
|
mask.writeToBuffer(buffer);
|
||||||
|
@ -29,8 +29,8 @@ import glm.vec._3.Vec3;
|
|||||||
import glm.vec._4.Vec4;
|
import glm.vec._4.Vec4;
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
import ru.windcorp.progressia.client.graphics.backend.Usage;
|
import ru.windcorp.progressia.client.graphics.backend.Usage;
|
||||||
import ru.windcorp.progressia.client.graphics.model.ShapePart;
|
import ru.windcorp.progressia.client.graphics.model.Face;
|
||||||
import ru.windcorp.progressia.client.graphics.model.ShapeParts;
|
import ru.windcorp.progressia.client.graphics.model.Faces;
|
||||||
import ru.windcorp.progressia.client.graphics.model.Shape;
|
import ru.windcorp.progressia.client.graphics.model.Shape;
|
||||||
import ru.windcorp.progressia.client.graphics.model.Renderable;
|
import ru.windcorp.progressia.client.graphics.model.Renderable;
|
||||||
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
||||||
@ -84,7 +84,7 @@ public class RenderTarget {
|
|||||||
|
|
||||||
private final Deque<TransformedMask> maskStack = new LinkedList<>();
|
private final Deque<TransformedMask> maskStack = new LinkedList<>();
|
||||||
private final Deque<Mat4> transformStack = new LinkedList<>();
|
private final Deque<Mat4> transformStack = new LinkedList<>();
|
||||||
private final List<ShapePart> currentClipFaces = new ArrayList<>();
|
private final List<Face> currentClipFaces = new ArrayList<>();
|
||||||
|
|
||||||
private int depth = 0;
|
private int depth = 0;
|
||||||
|
|
||||||
@ -94,8 +94,8 @@ public class RenderTarget {
|
|||||||
|
|
||||||
protected void assembleCurrentClipFromFaces() {
|
protected void assembleCurrentClipFromFaces() {
|
||||||
if (!currentClipFaces.isEmpty()) {
|
if (!currentClipFaces.isEmpty()) {
|
||||||
ShapePart[] faces = currentClipFaces.toArray(
|
Face[] faces = currentClipFaces.toArray(
|
||||||
new ShapePart[currentClipFaces.size()]
|
new Face[currentClipFaces.size()]
|
||||||
);
|
);
|
||||||
currentClipFaces.clear();
|
currentClipFaces.clear();
|
||||||
|
|
||||||
@ -189,13 +189,16 @@ public class RenderTarget {
|
|||||||
|
|
||||||
public void addCustomRenderer(Renderable renderable) {
|
public void addCustomRenderer(Renderable renderable) {
|
||||||
assembleCurrentClipFromFaces();
|
assembleCurrentClipFromFaces();
|
||||||
|
assembled.add(
|
||||||
float depth = this.depth--;
|
new Clip(
|
||||||
Mat4 transform = new Mat4().translate(0, 0, depth).mul(getTransform());
|
maskStack,
|
||||||
assembled.add(new Clip(maskStack, transform, renderable));
|
getTransform(),
|
||||||
|
renderable
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addFaceToCurrentClip(ShapePart face) {
|
protected void addFaceToCurrentClip(Face face) {
|
||||||
currentClipFaces.add(face);
|
currentClipFaces.add(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +270,7 @@ public class RenderTarget {
|
|||||||
fill(Colors.toVector(color));
|
fill(Colors.toVector(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapePart createRectagleFace(
|
public Face createRectagleFace(
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
int width,
|
int width,
|
||||||
@ -277,7 +280,7 @@ public class RenderTarget {
|
|||||||
) {
|
) {
|
||||||
float depth = this.depth--;
|
float depth = this.depth--;
|
||||||
|
|
||||||
return ShapeParts.createRectangle(
|
return Faces.createRectangle(
|
||||||
FlatRenderProgram.getDefault(),
|
FlatRenderProgram.getDefault(),
|
||||||
texture,
|
texture,
|
||||||
color,
|
color,
|
||||||
@ -288,7 +291,7 @@ public class RenderTarget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapePart createRectagleFace(
|
public Face createRectagleFace(
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
int width,
|
int width,
|
||||||
|
@ -42,8 +42,14 @@ public class TransformedMask {
|
|||||||
private Vec4 endXstartY = null;
|
private Vec4 endXstartY = null;
|
||||||
private Vec4 endXendY = null;
|
private Vec4 endXendY = null;
|
||||||
|
|
||||||
public TransformedMask(Vec2 origin, Vec2 width, Vec2 height, Vec2 counterOrigin, Vec2 counterWidth,
|
public TransformedMask(
|
||||||
Vec2 counterHeight) {
|
Vec2 origin,
|
||||||
|
Vec2 width,
|
||||||
|
Vec2 height,
|
||||||
|
Vec2 counterOrigin,
|
||||||
|
Vec2 counterWidth,
|
||||||
|
Vec2 counterHeight
|
||||||
|
) {
|
||||||
set(origin, width, height, counterOrigin, counterWidth, counterHeight);
|
set(origin, width, height, counterOrigin, counterWidth, counterHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +61,14 @@ public class TransformedMask {
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransformedMask set(Vec2 origin, Vec2 width, Vec2 height, Vec2 counterOrigin, Vec2 counterWidth,
|
public TransformedMask set(
|
||||||
Vec2 counterHeight) {
|
Vec2 origin,
|
||||||
|
Vec2 width,
|
||||||
|
Vec2 height,
|
||||||
|
Vec2 counterOrigin,
|
||||||
|
Vec2 counterWidth,
|
||||||
|
Vec2 counterHeight
|
||||||
|
) {
|
||||||
this.origin.set(origin.x, origin.y);
|
this.origin.set(origin.x, origin.y);
|
||||||
this.width.set(width.x, width.y);
|
this.width.set(width.x, width.y);
|
||||||
this.height.set(height.x, height.y);
|
this.height.set(height.x, height.y);
|
||||||
@ -100,17 +112,35 @@ public class TransformedMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setFields() {
|
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) {
|
public void writeToBuffer(FloatBuffer output) {
|
||||||
|
@ -68,11 +68,17 @@ public class Font {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Renderable assemble(CharSequence chars, float maxWidth) {
|
public Renderable assemble(
|
||||||
|
CharSequence chars,
|
||||||
|
float maxWidth
|
||||||
|
) {
|
||||||
return typeface.assembleStatic(chars, style, align, maxWidth, color);
|
return typeface.assembleStatic(chars, style, align, maxWidth, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Renderable assembleDynamic(Supplier<CharSequence> supplier, float maxWidth) {
|
public Renderable assembleDynamic(
|
||||||
|
Supplier<CharSequence> supplier,
|
||||||
|
float maxWidth
|
||||||
|
) {
|
||||||
return typeface.assembleDynamic(supplier, style, align, maxWidth, color);
|
return typeface.assembleDynamic(supplier, style, align, maxWidth, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,8 +102,7 @@ public class Font {
|
|||||||
* Creates a new {@link Font} with the specified {@code style} exactly. This
|
* Creates a new {@link Font} with the specified {@code style} exactly. This
|
||||||
* object's style is ignored.
|
* object's style is ignored.
|
||||||
*
|
*
|
||||||
* @param style
|
* @param style the new style
|
||||||
* the new style
|
|
||||||
* @return the new font
|
* @return the new font
|
||||||
*/
|
*/
|
||||||
public Font withStyle(int style) {
|
public Font withStyle(int style) {
|
||||||
|
@ -81,7 +81,8 @@ public class GNUUnifontLoader {
|
|||||||
|
|
||||||
private static BufferedReader createReader(Resource resource) throws IOException {
|
private static BufferedReader createReader(Resource resource) throws IOException {
|
||||||
return new BufferedReader(
|
return new BufferedReader(
|
||||||
new InputStreamReader(new GZIPInputStream(resource.getInputStream()), StandardCharsets.UTF_8));
|
new InputStreamReader(new GZIPInputStream(resource.getInputStream()), StandardCharsets.UTF_8)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<String> createStream(BufferedReader reader) {
|
private static Stream<String> createStream(BufferedReader reader) {
|
||||||
@ -96,8 +97,13 @@ public class GNUUnifontLoader {
|
|||||||
|
|
||||||
char c = getChar(declar);
|
char c = getChar(declar);
|
||||||
|
|
||||||
TextureDataEditor editor = new TextureDataEditor(width, GNUUnifont.HEIGHT, width, GNUUnifont.HEIGHT,
|
TextureDataEditor editor = new TextureDataEditor(
|
||||||
TEXTURE_SETTINGS);
|
width,
|
||||||
|
GNUUnifont.HEIGHT,
|
||||||
|
width,
|
||||||
|
GNUUnifont.HEIGHT,
|
||||||
|
TEXTURE_SETTINGS
|
||||||
|
);
|
||||||
|
|
||||||
for (int y = 0; y < GNUUnifont.HEIGHT; ++y) {
|
for (int y = 0; y < GNUUnifont.HEIGHT; ++y) {
|
||||||
for (int x = 0; x < width; ++x) {
|
for (int x = 0; x < width; ++x) {
|
||||||
@ -159,7 +165,8 @@ public class GNUUnifontLoader {
|
|||||||
|
|
||||||
if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'))) {
|
if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'))) {
|
||||||
throw new IOException(
|
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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,7 +190,8 @@ public class GNUUnifontLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Collector<AtlasGlyph, ?, TCharObjectMap<Texture>> createMapper() {
|
private static Collector<AtlasGlyph, ?, TCharObjectMap<Texture>> createMapper() {
|
||||||
return Collector.of(TCharObjectHashMap<Texture>::new,
|
return Collector.of(
|
||||||
|
TCharObjectHashMap<Texture>::new,
|
||||||
|
|
||||||
(map, glyph) -> map.put(glyph.c, glyph.texture),
|
(map, glyph) -> map.put(glyph.c, glyph.texture),
|
||||||
|
|
||||||
@ -192,7 +200,8 @@ public class GNUUnifontLoader {
|
|||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
|
|
||||||
Characteristics.UNORDERED);
|
Characteristics.UNORDERED
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GNUUnifontLoader() {
|
private GNUUnifontLoader() {
|
||||||
|
@ -33,8 +33,8 @@ import gnu.trove.stack.TIntStack;
|
|||||||
import gnu.trove.stack.array.TIntArrayStack;
|
import gnu.trove.stack.array.TIntArrayStack;
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
import ru.windcorp.progressia.client.graphics.backend.Usage;
|
import ru.windcorp.progressia.client.graphics.backend.Usage;
|
||||||
import ru.windcorp.progressia.client.graphics.model.ShapePart;
|
import ru.windcorp.progressia.client.graphics.model.Face;
|
||||||
import ru.windcorp.progressia.client.graphics.model.ShapeParts;
|
import ru.windcorp.progressia.client.graphics.model.Faces;
|
||||||
import ru.windcorp.progressia.client.graphics.model.Shape;
|
import ru.windcorp.progressia.client.graphics.model.Shape;
|
||||||
import ru.windcorp.progressia.client.graphics.model.ShapeRenderHelper;
|
import ru.windcorp.progressia.client.graphics.model.ShapeRenderHelper;
|
||||||
import ru.windcorp.progressia.client.graphics.model.ShapeRenderProgram;
|
import ru.windcorp.progressia.client.graphics.model.ShapeRenderProgram;
|
||||||
@ -144,7 +144,7 @@ public abstract class SpriteTypeface extends Typeface {
|
|||||||
return new Shape(
|
return new Shape(
|
||||||
Usage.STATIC,
|
Usage.STATIC,
|
||||||
getProgram(),
|
getProgram(),
|
||||||
ShapeParts.createRectangle(
|
Faces.createRectangle(
|
||||||
getProgram(),
|
getProgram(),
|
||||||
getTexture(c),
|
getTexture(c),
|
||||||
Colors.WHITE,
|
Colors.WHITE,
|
||||||
@ -167,7 +167,7 @@ public abstract class SpriteTypeface extends Typeface {
|
|||||||
private final Renderable unitLine = new Shape(
|
private final Renderable unitLine = new Shape(
|
||||||
Usage.STATIC,
|
Usage.STATIC,
|
||||||
getProgram(),
|
getProgram(),
|
||||||
ShapeParts.createRectangle(
|
Faces.createRectangle(
|
||||||
getProgram(),
|
getProgram(),
|
||||||
null,
|
null,
|
||||||
Vectors.UNIT_4,
|
Vectors.UNIT_4,
|
||||||
@ -257,7 +257,7 @@ public abstract class SpriteTypeface extends Typeface {
|
|||||||
|
|
||||||
private class SDWorkspace extends SpriteTypeface.Workspace {
|
private class SDWorkspace extends SpriteTypeface.Workspace {
|
||||||
|
|
||||||
private final Collection<ShapePart> faces = new ArrayList<>();
|
private final Collection<Face> faces = new ArrayList<>();
|
||||||
|
|
||||||
private final Vec3 origin = new Vec3();
|
private final Vec3 origin = new Vec3();
|
||||||
private final Vec3 width = new Vec3();
|
private final Vec3 width = new Vec3();
|
||||||
@ -298,7 +298,7 @@ public abstract class SpriteTypeface extends Typeface {
|
|||||||
workspace.height.sub(workspace.origin);
|
workspace.height.sub(workspace.origin);
|
||||||
|
|
||||||
workspace.faces.add(
|
workspace.faces.add(
|
||||||
ShapeParts.createRectangle(
|
Faces.createRectangle(
|
||||||
getProgram(),
|
getProgram(),
|
||||||
texture,
|
texture,
|
||||||
color,
|
color,
|
||||||
@ -314,7 +314,7 @@ public abstract class SpriteTypeface extends Typeface {
|
|||||||
return new Shape(
|
return new Shape(
|
||||||
Usage.STATIC,
|
Usage.STATIC,
|
||||||
getProgram(),
|
getProgram(),
|
||||||
workspace.faces.toArray(new ShapePart[workspace.faces.size()])
|
workspace.faces.toArray(new Face[workspace.faces.size()])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,12 @@ import ru.windcorp.progressia.common.util.Vectors;
|
|||||||
public abstract class Typeface extends Named {
|
public abstract class Typeface extends Named {
|
||||||
|
|
||||||
public static class Style {
|
public static class Style {
|
||||||
public static final int BOLD = 1 << 0, ITALIC = 1 << 1, UNDERLINED = 1 << 2, STRIKETHRU = 1 << 3,
|
public static final int BOLD = 1 << 0,
|
||||||
SHADOW = 1 << 4, OUTLINED = 1 << 5;
|
ITALIC = 1 << 1,
|
||||||
|
UNDERLINED = 1 << 2,
|
||||||
|
STRIKETHRU = 1 << 3,
|
||||||
|
SHADOW = 1 << 4,
|
||||||
|
OUTLINED = 1 << 5;
|
||||||
|
|
||||||
public static final int PLAIN = 0;
|
public static final int PLAIN = 0;
|
||||||
|
|
||||||
@ -67,19 +71,40 @@ public abstract class Typeface extends Named {
|
|||||||
super(name);
|
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<CharSequence> supplier, int style, float align, float maxWidth,
|
public abstract Renderable assembleDynamic(
|
||||||
Vec4 color);
|
Supplier<CharSequence> 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();
|
Vec2i v = Vectors.grab2i();
|
||||||
v = getSize(chars, style, align, maxWidth, v);
|
v = getSize(chars, style, align, maxWidth, v);
|
||||||
Vectors.release(v);
|
Vectors.release(v);
|
||||||
return v.x;
|
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();
|
Vec2i v = Vectors.grab2i();
|
||||||
v = getSize(chars, style, align, maxWidth, v);
|
v = getSize(chars, style, align, maxWidth, v);
|
||||||
Vectors.release(v);
|
Vectors.release(v);
|
||||||
@ -88,7 +113,13 @@ public abstract class Typeface extends Named {
|
|||||||
|
|
||||||
public abstract int getLineHeight();
|
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);
|
public abstract boolean supports(char c);
|
||||||
|
|
||||||
|
@ -1,151 +0,0 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
|
||||||
import com.google.common.eventbus.Subscribe;
|
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.ButtonEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.EnableEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
|
||||||
|
|
||||||
public abstract class BasicButton extends Component {
|
|
||||||
|
|
||||||
private final Label label;
|
|
||||||
|
|
||||||
private boolean isPressed = false;
|
|
||||||
private final Collection<Consumer<BasicButton>> actions = Collections.synchronizedCollection(new ArrayList<>());
|
|
||||||
|
|
||||||
public BasicButton(String name, String label, Font labelFont) {
|
|
||||||
super(name);
|
|
||||||
this.label = new Label(name + ".Label", labelFont, label);
|
|
||||||
|
|
||||||
setLayout(new LayoutAlign(10));
|
|
||||||
addChild(this.label);
|
|
||||||
|
|
||||||
setFocusable(true);
|
|
||||||
reassembleAt(ARTrigger.HOVER, ARTrigger.FOCUS, ARTrigger.ENABLE);
|
|
||||||
|
|
||||||
// Click triggers
|
|
||||||
addListener(KeyEvent.class, e -> {
|
|
||||||
if (e.isRepeat()) {
|
|
||||||
return false;
|
|
||||||
} else if (
|
|
||||||
e.isLeftMouseButton() ||
|
|
||||||
e.getKey() == GLFW.GLFW_KEY_SPACE ||
|
|
||||||
e.getKey() == GLFW.GLFW_KEY_ENTER
|
|
||||||
) {
|
|
||||||
setPressed(e.isPress());
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addListener(new Object() {
|
|
||||||
|
|
||||||
// Release when losing focus
|
|
||||||
@Subscribe
|
|
||||||
public void onFocusChange(FocusEvent e) {
|
|
||||||
if (!e.getNewState()) {
|
|
||||||
setPressed(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Release when hover ends
|
|
||||||
@Subscribe
|
|
||||||
public void onHoverEnded(HoverEvent e) {
|
|
||||||
if (!e.isNowHovered()) {
|
|
||||||
setPressed(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Release when disabled
|
|
||||||
@Subscribe
|
|
||||||
public void onDisabled(EnableEvent e) {
|
|
||||||
if (!e.getComponent().isEnabled()) {
|
|
||||||
setPressed(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger virtualClick when button is released
|
|
||||||
@Subscribe
|
|
||||||
public void onRelease(ButtonEvent.Release e) {
|
|
||||||
virtualClick();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicButton(String name, String label) {
|
|
||||||
this(name, label, new Font());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPressed() {
|
|
||||||
return isPressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void click() {
|
|
||||||
setPressed(true);
|
|
||||||
setPressed(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPressed(boolean isPressed) {
|
|
||||||
if (this.isPressed != isPressed) {
|
|
||||||
this.isPressed = isPressed;
|
|
||||||
|
|
||||||
if (isPressed) {
|
|
||||||
takeFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatchEvent(ButtonEvent.create(this, this.isPressed));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicButton addAction(Consumer<BasicButton> action) {
|
|
||||||
this.actions.add(Objects.requireNonNull(action, "action"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeAction(Consumer<BasicButton> action) {
|
|
||||||
return this.actions.remove(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void virtualClick() {
|
|
||||||
this.actions.forEach(action -> {
|
|
||||||
action.accept(this);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Label getLabel() {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,79 +1,83 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui;
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
import glm.vec._4.Vec4;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import glm.mat._4.Mat4;
|
||||||
|
import glm.vec._2.i.Vec2i;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||||
|
|
||||||
public class Button extends BasicButton {
|
public class Button extends Interactable {
|
||||||
|
|
||||||
public Button(String name, String label, Font labelFont) {
|
public <T extends InputEvent> Button(String name, Label textLabel, Consumer<Button> onClick) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
|
||||||
super(name, label, labelFont);
|
super(name, textLabel);
|
||||||
|
setPreferredSize(107,34);
|
||||||
|
//Button inButton = (Button) setFocusable(true);
|
||||||
|
|
||||||
|
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if ((e.isLeftMouseButton() && containsCursor()) || (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()) )
|
||||||
|
{
|
||||||
|
isClicked = e.isPress();
|
||||||
|
if (!isDisabled())
|
||||||
|
{
|
||||||
|
onClick.accept(this);
|
||||||
|
takeFocus();
|
||||||
}
|
}
|
||||||
|
requestReassembly();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;});
|
||||||
|
|
||||||
public Button(String name, String label) {
|
|
||||||
this(name, label, new Font());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void assembleSelf(RenderTarget target) {
|
protected void assembleSelf(RenderTarget target) {
|
||||||
// Border
|
//Border
|
||||||
|
if (isDisabled())
|
||||||
Vec4 borderColor;
|
{
|
||||||
if (isPressed() || isHovered() || isFocused()) {
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFE5E5E5);
|
||||||
borderColor = Colors.BLUE;
|
|
||||||
} else {
|
|
||||||
borderColor = Colors.LIGHT_GRAY;
|
|
||||||
}
|
}
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), borderColor);
|
else if (isClicked() || isHovered() || isFocused())
|
||||||
|
{
|
||||||
// Inside area
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFF37A2E6);
|
||||||
|
|
||||||
if (isPressed()) {
|
|
||||||
// Do nothing
|
|
||||||
} else {
|
|
||||||
Vec4 backgroundColor;
|
|
||||||
if (isHovered() && isEnabled()) {
|
|
||||||
backgroundColor = Colors.HOVER_BLUE;
|
|
||||||
} else {
|
|
||||||
backgroundColor = Colors.WHITE;
|
|
||||||
}
|
}
|
||||||
target.fill(getX() + 2, getY() + 2, getWidth() - 4, getHeight() - 4, backgroundColor);
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFCBCBD0);
|
||||||
|
}
|
||||||
|
//Inside area
|
||||||
|
if (!isClicked() && isHovered() && !isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, 0xFFC3E4F7);
|
||||||
|
}
|
||||||
|
else if (!isClicked() || isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, Colors.WHITE);
|
||||||
|
}
|
||||||
|
Font tempFont = new Font().withColor(Colors.BLACK);
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
tempFont = tempFont.withColor(Colors.GRAY_A);
|
||||||
|
}
|
||||||
|
else if (isClicked())
|
||||||
|
{
|
||||||
|
tempFont = tempFont.withColor(Colors.WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change label font color
|
target.pushTransform(new Mat4().identity().translate( getX()+.5f*getWidth()-.5f*label.getPreferredSize().x, getY(), 0));
|
||||||
|
label = new Label(label.getName(), tempFont, label.getContentSupplier());
|
||||||
if (isPressed()) {
|
label.assembleSelf(target);
|
||||||
getLabel().setFont(getLabel().getFont().withColor(Colors.WHITE));
|
target.popTransform();
|
||||||
} else {
|
|
||||||
getLabel().setFont(getLabel().getFont().withColor(Colors.BLACK));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void postAssembleSelf(RenderTarget target) {
|
|
||||||
// Apply disable tint
|
|
||||||
|
|
||||||
if (!isEnabled()) {
|
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), Colors.toVector(0x88FFFFFF));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,149 +1,117 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui;
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import glm.mat._4.Mat4;
|
||||||
import glm.vec._2.i.Vec2i;
|
import glm.vec._2.i.Vec2i;
|
||||||
import glm.vec._4.Vec4;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||||
import ru.windcorp.progressia.client.graphics.font.Typefaces;
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutHorizontal;
|
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||||
|
|
||||||
public class Checkbox extends BasicButton {
|
public class Checkbox extends Interactable {
|
||||||
|
|
||||||
private class Tick extends Component {
|
private boolean isActive;
|
||||||
|
|
||||||
public Tick() {
|
public <T extends InputEvent> Checkbox(String name, Label textLabel, Consumer<Checkbox> onSet, Consumer<Checkbox> onReset) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
|
||||||
super(Checkbox.this.getName() + ".Tick");
|
super(name, textLabel);
|
||||||
|
setPreferredSize(44 + textLabel.getPreferredSize().x,textLabel.getPreferredSize().y);
|
||||||
|
//Checkbox inCheck = (Checkbox) setFocusable(true);
|
||||||
|
|
||||||
setPreferredSize(new Vec2i(Typefaces.getDefault().getLineHeight() * 3 / 2));
|
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if (e.isLeftMouseButton() && containsCursor()|| (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()))
|
||||||
|
{
|
||||||
|
isClicked = e.isPress();
|
||||||
|
if (!isDisabled())
|
||||||
|
{
|
||||||
|
if (!isClicked && !isActive)
|
||||||
|
{
|
||||||
|
onSet.accept(this);
|
||||||
|
isActive = !isActive;
|
||||||
|
}
|
||||||
|
else if (!isClicked && isActive)
|
||||||
|
{
|
||||||
|
onReset.accept(this);
|
||||||
|
isActive = !isActive;
|
||||||
|
}
|
||||||
|
else if (isClicked)
|
||||||
|
{
|
||||||
|
takeFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requestReassembly();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive()
|
||||||
|
{
|
||||||
|
return isActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void assembleSelf(RenderTarget target) {
|
protected void assembleSelf(RenderTarget target) {
|
||||||
|
//Border
|
||||||
int size = getPreferredSize().x;
|
if (isDisabled())
|
||||||
int x = getX();
|
{
|
||||||
int y = getY() + (getHeight() - size) / 2;
|
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFFE5E5E5);
|
||||||
|
|
||||||
// Border
|
|
||||||
|
|
||||||
Vec4 borderColor;
|
|
||||||
if (Checkbox.this.isPressed() || Checkbox.this.isHovered() || Checkbox.this.isFocused()) {
|
|
||||||
borderColor = Colors.BLUE;
|
|
||||||
} else {
|
|
||||||
borderColor = Colors.LIGHT_GRAY;
|
|
||||||
}
|
}
|
||||||
target.fill(x, y, size, size, borderColor);
|
else if (isClicked() || isHovered() || isFocused())
|
||||||
|
{
|
||||||
// Inside area
|
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFF37A2E6); // blue
|
||||||
|
|
||||||
if (Checkbox.this.isPressed()) {
|
|
||||||
// Do nothing
|
|
||||||
} else {
|
|
||||||
Vec4 backgroundColor;
|
|
||||||
if (Checkbox.this.isHovered() && Checkbox.this.isEnabled()) {
|
|
||||||
backgroundColor = Colors.HOVER_BLUE;
|
|
||||||
} else {
|
|
||||||
backgroundColor = Colors.WHITE;
|
|
||||||
}
|
}
|
||||||
target.fill(x + 2, y + 2, size - 4, size - 4, backgroundColor);
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFFCBCBD0);
|
||||||
}
|
}
|
||||||
|
//Inside area
|
||||||
// "Tick"
|
if (!isClicked() && isHovered() && !isDisabled())
|
||||||
|
{
|
||||||
if (Checkbox.this.isChecked()) {
|
target.fill(getX()+2+label.getPreferredSize().x, getY()+2, getWidth()-label.getPreferredSize().x-4, getHeight()-4, 0xFFC3E4F7); // light blue
|
||||||
target.fill(x + 4, y + 4, size - 8, size - 8, Colors.BLUE);
|
}
|
||||||
|
else if (!isClicked() || isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+2+label.getPreferredSize().x, getY()+2, getWidth()-label.getPreferredSize().x-4, getHeight()-4, Colors.WHITE);
|
||||||
|
}
|
||||||
|
if (isActive() && !isClicked())
|
||||||
|
{
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFB3D7EF);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6); // blue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!isClicked())
|
||||||
|
{
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFE5E5E5);
|
||||||
}
|
}
|
||||||
|
else if (isFocused() || isHovered())
|
||||||
private boolean checked;
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6); // blue
|
||||||
public Checkbox(String name, String label, Font labelFont, boolean check) {
|
|
||||||
super(name, label, labelFont);
|
|
||||||
this.checked = check;
|
|
||||||
|
|
||||||
assert getChildren().size() == 1 : "Checkbox expects that BasicButton contains exactly one child";
|
|
||||||
Component basicChild = getChild(0);
|
|
||||||
|
|
||||||
Group group = new Group(getName() + ".LabelAndTick", new LayoutHorizontal(0, 10));
|
|
||||||
removeChild(basicChild);
|
|
||||||
setLayout(new LayoutAlign(0, 0.5f, 10));
|
|
||||||
group.setLayoutHint(basicChild.getLayoutHint());
|
|
||||||
group.addChild(new Tick());
|
|
||||||
group.addChild(basicChild);
|
|
||||||
addChild(group);
|
|
||||||
|
|
||||||
addAction(b -> switchState());
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
public Checkbox(String name, String label, Font labelFont) {
|
{
|
||||||
this(name, label, labelFont, false);
|
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFCBCBD0);
|
||||||
}
|
}
|
||||||
|
target.fill(getX()+label.getPreferredSize().x+6, getY()+6, getHeight()-12, getHeight()-12, Colors.WHITE);
|
||||||
public Checkbox(String name, String label, boolean check) {
|
|
||||||
this(name, label, new Font(), check);
|
|
||||||
}
|
}
|
||||||
|
target.pushTransform(new Mat4().identity().translate( getX(), getY(), 0));
|
||||||
public Checkbox(String name, String label) {
|
label.assembleSelf(target);
|
||||||
this(name, label, false);
|
target.popTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchState() {
|
|
||||||
setChecked(!isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the checked
|
|
||||||
*/
|
|
||||||
public boolean isChecked() {
|
|
||||||
return checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param checked the checked to set
|
|
||||||
*/
|
|
||||||
public void setChecked(boolean checked) {
|
|
||||||
this.checked = checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assembleSelf(RenderTarget target) {
|
|
||||||
// Change label font color
|
|
||||||
|
|
||||||
if (isPressed()) {
|
|
||||||
getLabel().setFont(getLabel().getFont().withColor(Colors.BLUE));
|
|
||||||
} else {
|
|
||||||
getLabel().setFont(getLabel().getFont().withColor(Colors.BLACK));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void postAssembleSelf(RenderTarget target) {
|
|
||||||
// Apply disable tint
|
|
||||||
|
|
||||||
if (!isEnabled()) {
|
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), Colors.toVector(0x88FFFFFF));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,23 +19,18 @@
|
|||||||
package ru.windcorp.progressia.client.graphics.gui;
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
|
||||||
|
|
||||||
import glm.vec._2.i.Vec2i;
|
import glm.vec._2.i.Vec2i;
|
||||||
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.ChildAddedEvent;
|
import ru.windcorp.progressia.client.graphics.gui.event.ChildAddedEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.ChildRemovedEvent;
|
import ru.windcorp.progressia.client.graphics.gui.event.ChildRemovedEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.EnableEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.ParentChangedEvent;
|
import ru.windcorp.progressia.client.graphics.gui.event.ParentChangedEvent;
|
||||||
@ -67,8 +62,6 @@ public class Component extends Named {
|
|||||||
private Object layoutHint = null;
|
private Object layoutHint = null;
|
||||||
private Layout layout = null;
|
private Layout layout = null;
|
||||||
|
|
||||||
private boolean isEnabled = true;
|
|
||||||
|
|
||||||
private boolean isFocusable = false;
|
private boolean isFocusable = false;
|
||||||
private boolean isFocused = false;
|
private boolean isFocused = false;
|
||||||
|
|
||||||
@ -292,31 +285,10 @@ public class Component extends Named {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether this component is focusable. A component needs to be
|
|
||||||
* focusable to become focused. A component that is focusable may not
|
|
||||||
* necessarily be ready to gain focus (see {@link #canGainFocusNow()}).
|
|
||||||
*
|
|
||||||
* @return {@code true} iff the component is focusable
|
|
||||||
* @see #canGainFocusNow()
|
|
||||||
*/
|
|
||||||
public boolean isFocusable() {
|
public boolean isFocusable() {
|
||||||
return isFocusable;
|
return isFocusable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether this component can become focused at this moment.
|
|
||||||
* <p>
|
|
||||||
* The implementation of this method in {@link Component} considers the
|
|
||||||
* component a focus candidate if it is both focusable and enabled.
|
|
||||||
*
|
|
||||||
* @return {@code true} iff the component can receive focus
|
|
||||||
* @see #isFocusable()
|
|
||||||
*/
|
|
||||||
public boolean canGainFocusNow() {
|
|
||||||
return isFocusable() && isEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component setFocusable(boolean focusable) {
|
public Component setFocusable(boolean focusable) {
|
||||||
this.isFocusable = focusable;
|
this.isFocusable = focusable;
|
||||||
return this;
|
return this;
|
||||||
@ -365,7 +337,7 @@ public class Component extends Named {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.canGainFocusNow()) {
|
if (component.isFocusable()) {
|
||||||
setFocused(false);
|
setFocused(false);
|
||||||
component.setFocused(true);
|
component.setFocused(true);
|
||||||
return;
|
return;
|
||||||
@ -407,7 +379,7 @@ public class Component extends Named {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.canGainFocusNow()) {
|
if (component.isFocusable()) {
|
||||||
setFocused(false);
|
setFocused(false);
|
||||||
component.setFocused(true);
|
component.setFocused(true);
|
||||||
return;
|
return;
|
||||||
@ -461,51 +433,12 @@ public class Component extends Named {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return isEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables or disables this component. An {@link EnableEvent} is dispatched
|
|
||||||
* if the state changes.
|
|
||||||
*
|
|
||||||
* @param enabled {@code true} to enable the component, {@code false} to
|
|
||||||
* disable the component
|
|
||||||
* @see #setEnabledRecursively(boolean)
|
|
||||||
*/
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
if (this.isEnabled != enabled) {
|
|
||||||
if (isFocused() && isEnabled()) {
|
|
||||||
focusNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEnabled()) {
|
|
||||||
setHovered(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isEnabled = enabled;
|
|
||||||
dispatchEvent(new EnableEvent(this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables or disables this component and all of its children recursively.
|
|
||||||
*
|
|
||||||
* @param enabled {@code true} to enable the components, {@code false} to
|
|
||||||
* disable the components
|
|
||||||
* @see #setEnabled(boolean)
|
|
||||||
*/
|
|
||||||
public void setEnabledRecursively(boolean enabled) {
|
|
||||||
setEnabled(enabled);
|
|
||||||
getChildren().forEach(c -> c.setEnabledRecursively(enabled));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHovered() {
|
public boolean isHovered() {
|
||||||
return isHovered;
|
return isHovered;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setHovered(boolean isHovered) {
|
protected void setHovered(boolean isHovered) {
|
||||||
if (this.isHovered != isHovered && isEnabled()) {
|
if (this.isHovered != isHovered) {
|
||||||
this.isHovered = isHovered;
|
this.isHovered = isHovered;
|
||||||
|
|
||||||
if (!isHovered && !getChildren().isEmpty()) {
|
if (!isHovered && !getChildren().isEmpty()) {
|
||||||
@ -542,8 +475,11 @@ public class Component extends Named {
|
|||||||
eventBus.post(event);
|
eventBus.post(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends InputEvent> void addListener(Class<? extends T> type, boolean handlesConsumed,
|
public <T extends InputEvent> void addListener(
|
||||||
InputListener<T> listener) {
|
Class<? extends T> type,
|
||||||
|
boolean handlesConsumed,
|
||||||
|
InputListener<T> listener
|
||||||
|
) {
|
||||||
if (inputBus == null) {
|
if (inputBus == null) {
|
||||||
inputBus = new InputBus();
|
inputBus = new InputBus();
|
||||||
}
|
}
|
||||||
@ -566,7 +502,7 @@ public class Component extends Named {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void handleInput(Input input) {
|
protected void handleInput(Input input) {
|
||||||
if (inputBus != null && isEnabled()) {
|
if (inputBus != null) {
|
||||||
inputBus.dispatch(input);
|
inputBus.dispatch(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -662,17 +598,6 @@ public class Component extends Named {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Schedules the reassembly to occur.
|
|
||||||
* <p>
|
|
||||||
* This method is invoked in root components whenever a
|
|
||||||
* {@linkplain #requestReassembly() reassembly request} is made by one of
|
|
||||||
* its children. When creating the dedicated root component, override this
|
|
||||||
* method to perform any implementation-specific actions that will cause a
|
|
||||||
* reassembly as soon as possible.
|
|
||||||
* <p>
|
|
||||||
* The default implementation of this method does nothing.
|
|
||||||
*/
|
|
||||||
protected void handleReassemblyRequest() {
|
protected void handleReassemblyRequest() {
|
||||||
// To be overridden
|
// To be overridden
|
||||||
}
|
}
|
||||||
@ -713,135 +638,6 @@ public class Component extends Named {
|
|||||||
getChildren().forEach(child -> child.assemble(target));
|
getChildren().forEach(child -> child.assemble(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Automatic Reassembly
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The various kinds of changes that may be used with
|
|
||||||
* {@link Component#reassembleAt(ARTrigger...)}.
|
|
||||||
*/
|
|
||||||
protected static enum ARTrigger {
|
|
||||||
/**
|
|
||||||
* Reassemble the component whenever its hover status changes, e.g.
|
|
||||||
* whenever the pointer enters or leaves its bounds.
|
|
||||||
*/
|
|
||||||
HOVER,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reassemble the component whenever it gains or loses focus.
|
|
||||||
* <p>
|
|
||||||
* <em>Component must be focusable to be able to gain focus.</em> The
|
|
||||||
* component will not be reassembled unless
|
|
||||||
* {@link Component#setFocusable(boolean) setFocusable(true)} has been
|
|
||||||
* invoked.
|
|
||||||
*/
|
|
||||||
FOCUS,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reassemble the component whenever it is enabled or disabled.
|
|
||||||
*/
|
|
||||||
ENABLE
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All trigger objects (event listeners) that are currently registered with
|
|
||||||
* {@link #eventBus}. The field is {@code null} until the first trigger is
|
|
||||||
* installed.
|
|
||||||
*/
|
|
||||||
private Map<ARTrigger, Object> autoReassemblyTriggerObjects = null;
|
|
||||||
|
|
||||||
private Object createTriggerObject(ARTrigger type) {
|
|
||||||
switch (type) {
|
|
||||||
case HOVER:
|
|
||||||
return new Object() {
|
|
||||||
@Subscribe
|
|
||||||
public void onHoverChanged(HoverEvent e) {
|
|
||||||
requestReassembly();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
case FOCUS:
|
|
||||||
return new Object() {
|
|
||||||
@Subscribe
|
|
||||||
public void onFocusChanged(FocusEvent e) {
|
|
||||||
requestReassembly();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
case ENABLE:
|
|
||||||
return new Object() {
|
|
||||||
@Subscribe
|
|
||||||
public void onEnabled(EnableEvent e) {
|
|
||||||
requestReassembly();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
default:
|
|
||||||
throw new NullPointerException("type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requests that {@link #requestReassembly()} is invoked on this component
|
|
||||||
* whenever any of the specified changes occur. Duplicate attempts to
|
|
||||||
* register the same trigger are silently ignored.
|
|
||||||
* <p>
|
|
||||||
* {@code triggers} may be empty, which results in a no-op. It must not be
|
|
||||||
* {@code null}.
|
|
||||||
*
|
|
||||||
* @param triggers the {@linkplain ARTrigger triggers} to
|
|
||||||
* request reassembly with.
|
|
||||||
* @see #disableAutoReassemblyAt(ARTrigger...)
|
|
||||||
*/
|
|
||||||
protected synchronized void reassembleAt(ARTrigger... triggers) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(triggers, "triggers");
|
|
||||||
if (triggers.length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (autoReassemblyTriggerObjects == null) {
|
|
||||||
autoReassemblyTriggerObjects = new EnumMap<>(ARTrigger.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ARTrigger trigger : triggers) {
|
|
||||||
if (!autoReassemblyTriggerObjects.containsKey(trigger)) {
|
|
||||||
Object triggerObject = createTriggerObject(trigger);
|
|
||||||
addListener(trigger);
|
|
||||||
autoReassemblyTriggerObjects.put(trigger, triggerObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requests that {@link #requestReassembly()} is no longer invoked on this
|
|
||||||
* component whenever any of the specified changes occur. After a trigger is
|
|
||||||
* removed, it may be reinstalled with
|
|
||||||
* {@link #reassembleAt(ARTrigger...)}. Attempts to remove a
|
|
||||||
* nonexistant trigger are silently ignored.
|
|
||||||
* <p>
|
|
||||||
* {@code triggers} may be empty, which results in a no-op. It must not be
|
|
||||||
* {@code null}.
|
|
||||||
*
|
|
||||||
* @param triggers the {@linkplain ARTrigger triggers} to remove
|
|
||||||
* @see #reassemblyAt(ARTrigger...)
|
|
||||||
*/
|
|
||||||
protected synchronized void disableAutoReassemblyAt(ARTrigger... triggers) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(triggers, "triggers");
|
|
||||||
if (triggers.length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (autoReassemblyTriggerObjects == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (ARTrigger trigger : triggers) {
|
|
||||||
Object triggerObject = autoReassemblyTriggerObjects.remove(trigger);
|
|
||||||
if (triggerObject != null) {
|
|
||||||
removeListener(trigger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Returns a component that displays this component in its center.
|
// * Returns a component that displays this component in its center.
|
||||||
// * @return a {@link Aligner} initialized to center this component
|
// * @return a {@link Aligner} initialized to center this component
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
|
import glm.vec._2.i.Vec2i;
|
||||||
|
|
||||||
|
public class Interactable extends Component {
|
||||||
|
|
||||||
|
private Vec2i currentSize;
|
||||||
|
protected boolean isDisabled;
|
||||||
|
protected boolean isClicked;
|
||||||
|
protected Label label;
|
||||||
|
|
||||||
|
public Interactable(String name, Label textLabel)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
label = textLabel;
|
||||||
|
addChild(textLabel);
|
||||||
|
|
||||||
|
addListener(new Object() {
|
||||||
|
@Subscribe
|
||||||
|
public void onHoverChanged(HoverEvent e) {
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addListener(new Object() {
|
||||||
|
@Subscribe
|
||||||
|
public void onFocusChanged(FocusEvent e) {
|
||||||
|
//inButton.setText(new Label("dummy",new Font().withColor(Colors.BLACK),e.getNewState() ? "Is Focused" : "Isn't focused"));
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClicked()
|
||||||
|
{
|
||||||
|
return isClicked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisable(boolean isDisabled)
|
||||||
|
{
|
||||||
|
this.isDisabled = isDisabled;
|
||||||
|
setFocusable(isDisabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisabled()
|
||||||
|
{
|
||||||
|
return isDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(Label newText)
|
||||||
|
{
|
||||||
|
removeChild(label);
|
||||||
|
label = newText;
|
||||||
|
addChild(label);
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
}
|
@ -83,11 +83,6 @@ public class Label extends Component {
|
|||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFont(Font font) {
|
|
||||||
this.font = font;
|
|
||||||
requestReassembly();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCurrentText() {
|
public String getCurrentText() {
|
||||||
return currentText;
|
return currentText;
|
||||||
}
|
}
|
||||||
@ -101,7 +96,11 @@ public class Label extends Component {
|
|||||||
float startX = getX() + font.getAlign() * (getWidth() - currentSize.x);
|
float startX = getX() + font.getAlign() * (getWidth() - currentSize.x);
|
||||||
|
|
||||||
target.pushTransform(
|
target.pushTransform(
|
||||||
new Mat4().identity().translate(startX, getY(), 0).scale(2)
|
new Mat4().identity().translate(startX, getY(), -1000) // TODO wtf
|
||||||
|
// is this
|
||||||
|
// magic
|
||||||
|
// <---
|
||||||
|
.scale(2)
|
||||||
);
|
);
|
||||||
|
|
||||||
target.addCustomRenderer(font.assemble(currentText, maxWidth));
|
target.addCustomRenderer(font.assemble(currentText, maxWidth));
|
||||||
|
@ -15,66 +15,14 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui;
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
import java.util.Objects;
|
public class Panel extends Component {
|
||||||
|
|
||||||
import glm.vec._4.Vec4;
|
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
|
||||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
|
||||||
|
|
||||||
public class Panel extends Group {
|
|
||||||
|
|
||||||
private Vec4 fill;
|
|
||||||
private Vec4 border;
|
|
||||||
|
|
||||||
public Panel(String name, Layout layout, Vec4 fill, Vec4 border) {
|
|
||||||
super(name, layout);
|
|
||||||
|
|
||||||
this.fill = Objects.requireNonNull(fill, "fill");
|
|
||||||
this.border = border;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Panel(String name, Layout layout) {
|
public Panel(String name, Layout layout) {
|
||||||
this(name, layout, Colors.WHITE, Colors.LIGHT_GRAY);
|
super(name);
|
||||||
}
|
setLayout(layout);
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the fill
|
|
||||||
*/
|
|
||||||
public Vec4 getFill() {
|
|
||||||
return fill;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param fill the fill to set
|
|
||||||
*/
|
|
||||||
public void setFill(Vec4 fill) {
|
|
||||||
this.fill = Objects.requireNonNull(fill, "fill");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the border
|
|
||||||
*/
|
|
||||||
public Vec4 getBorder() {
|
|
||||||
return border;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param border the border to set
|
|
||||||
*/
|
|
||||||
public void setBorder(Vec4 border) {
|
|
||||||
this.border = border;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assembleSelf(RenderTarget target) {
|
|
||||||
if (border == null) {
|
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), fill);
|
|
||||||
} else {
|
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), border);
|
|
||||||
target.fill(getX() + 2, getY() + 2, getWidth() - 4, getHeight() - 4, fill);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,205 +1,87 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui;
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
import glm.mat._4.Mat4;
|
||||||
import glm.vec._2.i.Vec2i;
|
import glm.vec._2.i.Vec2i;
|
||||||
import glm.vec._4.Vec4;
|
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
|
||||||
import ru.windcorp.progressia.client.graphics.font.Typefaces;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutHorizontal;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||||
|
|
||||||
public class RadioButton extends BasicButton {
|
public class RadioButton extends Interactable {
|
||||||
|
private RadioManager manager;
|
||||||
|
private boolean isSelected;
|
||||||
|
|
||||||
private class Tick extends Component {
|
public RadioButton(String name, Label textLabel, Consumer<RadioButton> onSelect, RadioManager myManager)
|
||||||
|
{
|
||||||
|
super(name, textLabel);
|
||||||
|
setPreferredSize(textLabel.getPreferredSize().x+23,textLabel.getPreferredSize().y);
|
||||||
|
manager = myManager;
|
||||||
|
manager.addOption(this);
|
||||||
|
|
||||||
public Tick() {
|
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if ((e.isLeftMouseButton() && containsCursor()) || (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()) )
|
||||||
super(RadioButton.this.getName() + ".Tick");
|
{
|
||||||
|
isClicked = e.isPress();
|
||||||
setPreferredSize(new Vec2i(Typefaces.getDefault().getLineHeight() * 3 / 2));
|
if (!isDisabled() && !isClicked)
|
||||||
}
|
{
|
||||||
|
onSelect.accept(this);
|
||||||
private void cross(RenderTarget target, int x, int y, int size, Vec4 color) {
|
manager.selectSelf(this);
|
||||||
target.fill(x + 4, y, size - 8, size, color);
|
|
||||||
target.fill(x + 2, y + 2, size - 4, size - 4, color);
|
|
||||||
target.fill(x, y + 4, size, size - 8, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assembleSelf(RenderTarget target) {
|
|
||||||
|
|
||||||
int size = getPreferredSize().x;
|
|
||||||
int x = getX();
|
|
||||||
int y = getY() + (getHeight() - size) / 2;
|
|
||||||
|
|
||||||
// Border
|
|
||||||
|
|
||||||
Vec4 borderColor;
|
|
||||||
if (RadioButton.this.isPressed() || RadioButton.this.isHovered() || RadioButton.this.isFocused()) {
|
|
||||||
borderColor = Colors.BLUE;
|
|
||||||
} else {
|
|
||||||
borderColor = Colors.LIGHT_GRAY;
|
|
||||||
}
|
|
||||||
cross(target, x, y, size, borderColor);
|
|
||||||
|
|
||||||
// Inside area
|
|
||||||
|
|
||||||
if (RadioButton.this.isPressed()) {
|
|
||||||
// Do nothing
|
|
||||||
} else {
|
|
||||||
Vec4 backgroundColor;
|
|
||||||
if (RadioButton.this.isHovered() && RadioButton.this.isEnabled()) {
|
|
||||||
backgroundColor = Colors.HOVER_BLUE;
|
|
||||||
} else {
|
|
||||||
backgroundColor = Colors.WHITE;
|
|
||||||
}
|
|
||||||
cross(target, x + 2, y + 2, size - 4, backgroundColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Tick"
|
|
||||||
|
|
||||||
if (RadioButton.this.isChecked()) {
|
|
||||||
cross(target, x + 4, y + 4, size - 8, Colors.BLUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checked;
|
|
||||||
|
|
||||||
private RadioButtonGroup group = null;
|
|
||||||
|
|
||||||
public RadioButton(String name, String label, Font labelFont, boolean check) {
|
|
||||||
super(name, label, labelFont);
|
|
||||||
this.checked = check;
|
|
||||||
|
|
||||||
assert getChildren().size() == 1 : "RadioButton expects that BasicButton contains exactly one child";
|
|
||||||
Component basicChild = getChild(0);
|
|
||||||
|
|
||||||
Group group = new Group(getName() + ".LabelAndTick", new LayoutHorizontal(0, 10));
|
|
||||||
removeChild(basicChild);
|
|
||||||
setLayout(new LayoutAlign(0, 0.5f, 10));
|
|
||||||
group.setLayoutHint(basicChild.getLayoutHint());
|
|
||||||
group.addChild(new Tick());
|
|
||||||
group.addChild(basicChild);
|
|
||||||
addChild(group);
|
|
||||||
|
|
||||||
addListener(KeyEvent.class, e -> {
|
|
||||||
if (e.isRelease()) return false;
|
|
||||||
|
|
||||||
if (e.getKey() == GLFW.GLFW_KEY_LEFT || e.getKey() == GLFW.GLFW_KEY_UP) {
|
|
||||||
if (this.group != null) {
|
|
||||||
this.group.selectPrevious();
|
|
||||||
this.group.getSelected().takeFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else if (e.getKey() == GLFW.GLFW_KEY_RIGHT || e.getKey() == GLFW.GLFW_KEY_DOWN) {
|
|
||||||
if (this.group != null) {
|
|
||||||
this.group.selectNext();
|
|
||||||
this.group.getSelected().takeFocus();
|
|
||||||
}
|
}
|
||||||
|
requestReassembly();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;});
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
addAction(b -> setChecked(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RadioButton(String name, String label, Font labelFont) {
|
public boolean isSelected()
|
||||||
this(name, label, labelFont, false);
|
{
|
||||||
|
return isSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RadioButton(String name, String label, boolean check) {
|
public void setSelected(boolean selected)
|
||||||
this(name, label, new Font(), check);
|
{
|
||||||
|
isSelected = selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RadioButton(String name, String label) {
|
|
||||||
this(name, label, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param group the group to set
|
|
||||||
*/
|
|
||||||
public RadioButton setGroup(RadioButtonGroup group) {
|
|
||||||
|
|
||||||
if (this.group != null) {
|
|
||||||
group.selectNext();
|
|
||||||
removeAction(group.listener);
|
|
||||||
group.buttons.remove(this);
|
|
||||||
group.getSelected(); // Clear reference if this was the only button in the group
|
|
||||||
}
|
|
||||||
|
|
||||||
this.group = group;
|
|
||||||
|
|
||||||
if (this.group != null) {
|
|
||||||
group.buttons.add(this);
|
|
||||||
addAction(group.listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
setChecked(false);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the checked
|
|
||||||
*/
|
|
||||||
public boolean isChecked() {
|
|
||||||
return checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param checked the checked to set
|
|
||||||
*/
|
|
||||||
public void setChecked(boolean checked) {
|
|
||||||
this.checked = checked;
|
|
||||||
|
|
||||||
if (group != null) {
|
|
||||||
group.listener.accept(this); // Failsafe for manual invocations of setChecked()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assembleSelf(RenderTarget target) {
|
protected void assembleSelf(RenderTarget target) {
|
||||||
// Change label font color
|
if (isDisabled())
|
||||||
|
{
|
||||||
if (isPressed()) {
|
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFFE5E5E5);
|
||||||
getLabel().setFont(getLabel().getFont().withColor(Colors.BLUE));
|
}
|
||||||
} else {
|
else if (isClicked() || isHovered() || isFocused())
|
||||||
getLabel().setFont(getLabel().getFont().withColor(Colors.BLACK));
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFF37A2E6);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFFCBCBD0);
|
||||||
|
}
|
||||||
|
//Inside area
|
||||||
|
if (!isClicked() && isHovered() && !isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+2, getY()+2, getHeight()-4, getHeight()-4, 0xFFC3E4F7);
|
||||||
|
}
|
||||||
|
else if (!isClicked() || isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+2, getY()+2, getHeight()-4, getHeight()-4, Colors.WHITE);
|
||||||
|
}
|
||||||
|
if (isSelected())
|
||||||
|
{
|
||||||
|
if (!isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFC3E4F7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
target.pushTransform(new Mat4().identity().translate( getX(), getY(), 0));
|
||||||
protected void postAssembleSelf(RenderTarget target) {
|
label.assembleSelf(target);
|
||||||
// Apply disable tint
|
target.popTransform();
|
||||||
|
|
||||||
if (!isEnabled()) {
|
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), Colors.toVector(0x88FFFFFF));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,119 +0,0 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class RadioButtonGroup {
|
|
||||||
|
|
||||||
private final Collection<Consumer<RadioButtonGroup>> actions = Collections.synchronizedCollection(new ArrayList<>());
|
|
||||||
final List<RadioButton> buttons = Collections.synchronizedList(new ArrayList<>());
|
|
||||||
|
|
||||||
private RadioButton selected = null;
|
|
||||||
|
|
||||||
Consumer<BasicButton> listener = b -> {
|
|
||||||
if (b instanceof RadioButton && ((RadioButton) b).isChecked() && buttons.contains(b)) {
|
|
||||||
select((RadioButton) b);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public RadioButtonGroup addAction(Consumer<RadioButtonGroup> action) {
|
|
||||||
this.actions.add(Objects.requireNonNull(action, "action"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeAction(Consumer<BasicButton> action) {
|
|
||||||
return this.actions.remove(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RadioButton> getButtons() {
|
|
||||||
return Collections.unmodifiableList(buttons);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized RadioButton getSelected() {
|
|
||||||
if (!buttons.contains(selected)) {
|
|
||||||
selected = null;
|
|
||||||
}
|
|
||||||
return selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void select(RadioButton button) {
|
|
||||||
if (button != null && !buttons.contains(button)) {
|
|
||||||
throw new IllegalArgumentException("Button " + button + " is not in the group");
|
|
||||||
}
|
|
||||||
|
|
||||||
getSelected(); // Clear if invalid
|
|
||||||
|
|
||||||
if (selected == button) {
|
|
||||||
return; // Terminate listener-setter recursion
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected != null) {
|
|
||||||
selected.setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
selected = button;
|
|
||||||
|
|
||||||
if (selected != null) {
|
|
||||||
selected.setChecked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
actions.forEach(action -> action.accept(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void selectNext() {
|
|
||||||
selectNeighbour(+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void selectPrevious() {
|
|
||||||
selectNeighbour(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void selectNeighbour(int direction) {
|
|
||||||
if (getSelected() == null) {
|
|
||||||
if (buttons.isEmpty()) {
|
|
||||||
throw new IllegalStateException("Cannot select neighbour button: group empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
select(buttons.get(0));
|
|
||||||
} else {
|
|
||||||
RadioButton button;
|
|
||||||
int index = buttons.indexOf(selected);
|
|
||||||
|
|
||||||
do {
|
|
||||||
index += direction;
|
|
||||||
|
|
||||||
if (index >= buttons.size()) {
|
|
||||||
index = 0;
|
|
||||||
} else if (index < 0) {
|
|
||||||
index = buttons.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
button = buttons.get(index);
|
|
||||||
} while (button != getSelected() && !button.isEnabled());
|
|
||||||
|
|
||||||
select(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,37 @@
|
|||||||
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class RadioManager {
|
||||||
|
private List<RadioButton> options;
|
||||||
|
private int selectedOption;
|
||||||
|
|
||||||
|
public RadioManager()
|
||||||
|
{
|
||||||
|
options = Collections.synchronizedList(new CopyOnWriteArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOption(RadioButton option)
|
||||||
|
{
|
||||||
|
options.add(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelected()
|
||||||
|
{
|
||||||
|
return selectedOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectSelf(RadioButton option)
|
||||||
|
{
|
||||||
|
if (!options.contains(option))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
options.get(selectedOption).setSelected(false);
|
||||||
|
selectedOption = options.indexOf(option);
|
||||||
|
option.takeFocus();
|
||||||
|
option.setSelected(true);
|
||||||
|
}
|
||||||
|
}
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui.event;
|
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.BasicButton;
|
|
||||||
|
|
||||||
public class ButtonEvent extends ComponentEvent {
|
|
||||||
|
|
||||||
public static class Press extends ButtonEvent {
|
|
||||||
public Press(BasicButton button) {
|
|
||||||
super(button, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Release extends ButtonEvent {
|
|
||||||
public Release(BasicButton button) {
|
|
||||||
super(button, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final boolean isPress;
|
|
||||||
|
|
||||||
protected ButtonEvent(BasicButton button, boolean isPress) {
|
|
||||||
super(button);
|
|
||||||
this.isPress = isPress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ButtonEvent create(BasicButton button, boolean isPress) {
|
|
||||||
if (isPress) {
|
|
||||||
return new Press(button);
|
|
||||||
} else {
|
|
||||||
return new Release(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPress() {
|
|
||||||
return isPress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRelease() {
|
|
||||||
return !isPress;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package ru.windcorp.progressia.client.graphics.gui.event;
|
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Component;
|
|
||||||
|
|
||||||
public class EnableEvent extends ComponentEvent {
|
|
||||||
|
|
||||||
public EnableEvent(Component component) {
|
|
||||||
super(component);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -56,8 +56,13 @@ public class LayoutAlign implements Layout {
|
|||||||
size.x = min(size.x, cWidth);
|
size.x = min(size.x, cWidth);
|
||||||
size.y = min(size.y, cHeight);
|
size.y = min(size.y, cHeight);
|
||||||
|
|
||||||
child.setBounds(c.getX() + (int) ((cWidth - size.x) * alignX) + margin,
|
child.setBounds(
|
||||||
c.getY() + (int) ((cHeight - size.y) * alignY) + margin, size);
|
c.getX() +
|
||||||
|
(int) ((cWidth - size.x) * alignX) + margin,
|
||||||
|
c.getY() +
|
||||||
|
(int) ((cHeight - size.y) * alignY) + margin,
|
||||||
|
size
|
||||||
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -66,7 +71,9 @@ public class LayoutAlign implements Layout {
|
|||||||
public Vec2i calculatePreferredSize(Component c) {
|
public Vec2i calculatePreferredSize(Component c) {
|
||||||
Vec2i result = new Vec2i(0, 0);
|
Vec2i result = new Vec2i(0, 0);
|
||||||
|
|
||||||
c.getChildren().stream().map(child -> child.getPreferredSize()).forEach(size -> {
|
c.getChildren().stream()
|
||||||
|
.map(child -> child.getPreferredSize())
|
||||||
|
.forEach(size -> {
|
||||||
result.x = max(size.x, result.x);
|
result.x = max(size.x, result.x);
|
||||||
result.y = max(size.y, result.y);
|
result.y = max(size.y, result.y);
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,9 @@ import ru.windcorp.progressia.client.graphics.gui.Layout;
|
|||||||
|
|
||||||
public class LayoutBorderHorizontal implements 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;
|
private final int margin;
|
||||||
|
|
||||||
@ -49,17 +51,32 @@ public class LayoutBorderHorizontal implements Layout {
|
|||||||
if (child.getLayoutHint() == LEFT) {
|
if (child.getLayoutHint() == LEFT) {
|
||||||
childSize = child.getPreferredSize();
|
childSize = child.getPreferredSize();
|
||||||
left = childSize.x + margin;
|
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) {
|
} else if (child.getLayoutHint() == RIGHT) {
|
||||||
childSize = child.getPreferredSize();
|
childSize = child.getPreferredSize();
|
||||||
right = childSize.x + margin;
|
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()) {
|
for (Component child : c.getChildren()) {
|
||||||
if (child.getLayoutHint() == CENTER) {
|
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()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,9 @@ import ru.windcorp.progressia.client.graphics.gui.Layout;
|
|||||||
|
|
||||||
public class LayoutBorderVertical implements 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;
|
private final int margin;
|
||||||
|
|
||||||
@ -49,17 +51,32 @@ public class LayoutBorderVertical implements Layout {
|
|||||||
if (child.getLayoutHint() == UP) {
|
if (child.getLayoutHint() == UP) {
|
||||||
childSize = child.getPreferredSize();
|
childSize = child.getPreferredSize();
|
||||||
top = childSize.y + margin;
|
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) {
|
} else if (child.getLayoutHint() == DOWN) {
|
||||||
childSize = child.getPreferredSize();
|
childSize = child.getPreferredSize();
|
||||||
bottom = childSize.y + margin;
|
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()) {
|
for (Component child : c.getChildren()) {
|
||||||
if (child.getLayoutHint() == CENTER) {
|
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
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui.layout;
|
|
||||||
|
|
||||||
import static java.lang.Math.max;
|
|
||||||
|
|
||||||
import glm.vec._2.i.Vec2i;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Component;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Layout;
|
|
||||||
|
|
||||||
public class LayoutFill implements Layout {
|
|
||||||
|
|
||||||
private final int margin;
|
|
||||||
|
|
||||||
public LayoutFill(int margin) {
|
|
||||||
this.margin = margin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LayoutFill() {
|
|
||||||
this(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void layout(Component c) {
|
|
||||||
c.getChildren().forEach(child -> {
|
|
||||||
|
|
||||||
int cWidth = c.getWidth() - 2 * margin;
|
|
||||||
int cHeight = c.getHeight() - 2 * margin;
|
|
||||||
|
|
||||||
child.setBounds(
|
|
||||||
c.getX() + margin,
|
|
||||||
c.getY() + margin,
|
|
||||||
cWidth,
|
|
||||||
cHeight
|
|
||||||
);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
result.x += 2 * margin;
|
|
||||||
result.y += 2 * margin;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getClass().getSimpleName() + "(" + margin + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -98,26 +98,15 @@ public class LayoutGrid implements Layout {
|
|||||||
if (!isSummed)
|
if (!isSummed)
|
||||||
throw new IllegalStateException("Not summed yet");
|
throw new IllegalStateException("Not summed yet");
|
||||||
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
if (column == columns.length - 1) {
|
|
||||||
width = parent.getWidth() - margin - columns[column];
|
|
||||||
} else {
|
|
||||||
width = columns[column + 1] - columns[column] - gap;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (row == rows.length - 1) {
|
|
||||||
height = parent.getHeight() - margin - rows[row];
|
|
||||||
} else {
|
|
||||||
height = rows[row + 1] - rows[row] - gap;
|
|
||||||
}
|
|
||||||
|
|
||||||
child.setBounds(
|
child.setBounds(
|
||||||
parent.getX() + columns[column],
|
parent.getX() + columns[column],
|
||||||
parent.getY() + parent.getHeight() - (rows[row] + height),
|
parent.getY() + rows[row],
|
||||||
|
|
||||||
width,
|
(column != (columns.length - 1) ? (columns[column + 1] - columns[column] - gap)
|
||||||
height
|
: (parent.getWidth() - margin - columns[column])),
|
||||||
|
|
||||||
|
(row != (rows.length - 1) ? (rows[row + 1] - rows[row] - gap)
|
||||||
|
: (parent.getHeight() - margin - rows[row]))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,9 +132,10 @@ public class LayoutGrid implements Layout {
|
|||||||
GridDimensions grid = calculateGrid(c);
|
GridDimensions grid = calculateGrid(c);
|
||||||
grid.sum();
|
grid.sum();
|
||||||
|
|
||||||
|
int[] coords;
|
||||||
for (Component child : c.getChildren()) {
|
for (Component child : c.getChildren()) {
|
||||||
Vec2i coords = (Vec2i) child.getLayoutHint();
|
coords = (int[]) child.getLayoutHint();
|
||||||
grid.setBounds(coords.x, coords.y, child, c);
|
grid.setBounds(coords[0], coords[1], child, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,10 +149,11 @@ public class LayoutGrid implements Layout {
|
|||||||
|
|
||||||
private GridDimensions calculateGrid(Component parent) {
|
private GridDimensions calculateGrid(Component parent) {
|
||||||
GridDimensions result = new GridDimensions();
|
GridDimensions result = new GridDimensions();
|
||||||
|
int[] coords;
|
||||||
|
|
||||||
for (Component child : parent.getChildren()) {
|
for (Component child : parent.getChildren()) {
|
||||||
Vec2i coords = (Vec2i) child.getLayoutHint();
|
coords = (int[]) child.getLayoutHint();
|
||||||
result.add(coords.x, coords.y, child.getPreferredSize());
|
result.add(coords[0], coords[1], child.getPreferredSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -43,7 +43,8 @@ public class LayoutHorizontal implements Layout {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void layout(Component c) {
|
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;
|
int width;
|
||||||
|
|
||||||
|
@ -43,7 +43,8 @@ public class LayoutVertical implements Layout {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void layout(Component c) {
|
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()) {
|
synchronized (c.getChildren()) {
|
||||||
for (Component child : c.getChildren()) {
|
for (Component child : c.getChildren()) {
|
||||||
|
@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui.menu;
|
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
|
||||||
import glm.vec._2.i.Vec2i;
|
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
|
||||||
import ru.windcorp.progressia.client.graphics.GUI;
|
|
||||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Component;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Layout;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.bus.Input;
|
|
||||||
import ru.windcorp.progressia.client.localization.MutableString;
|
|
||||||
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
|
||||||
|
|
||||||
public class MenuLayer extends GUILayer {
|
|
||||||
|
|
||||||
private final Component content;
|
|
||||||
private final Component background;
|
|
||||||
|
|
||||||
private final Runnable closeAction = () -> {
|
|
||||||
GUI.removeLayer(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
public MenuLayer(String name, Component content) {
|
|
||||||
super(name, new LayoutFill(0));
|
|
||||||
|
|
||||||
setCursorPolicy(CursorPolicy.REQUIRE);
|
|
||||||
|
|
||||||
this.background = new Panel(name + ".Background", new LayoutAlign(10), Colors.toVector(0x66000000), null);
|
|
||||||
this.content = content;
|
|
||||||
|
|
||||||
background.addChild(content);
|
|
||||||
getRoot().addChild(background);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MenuLayer(String name, Layout contentLayout) {
|
|
||||||
this(name, new Panel(name + ".Content", contentLayout));
|
|
||||||
}
|
|
||||||
|
|
||||||
public MenuLayer(String name) {
|
|
||||||
this(name, new LayoutVertical(20, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getBackground() {
|
|
||||||
return background;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addTitle() {
|
|
||||||
String translationKey = "Layer" + getName() + ".Title";
|
|
||||||
MutableString titleText = new MutableStringLocalized(translationKey);
|
|
||||||
Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(0.5f);
|
|
||||||
|
|
||||||
Label label = new Label(getName() + ".Title", titleFont, titleText);
|
|
||||||
getContent().addChild(label);
|
|
||||||
|
|
||||||
Panel panel = new Panel(getName() + ".Title.Underscore", null, Colors.BLUE, null);
|
|
||||||
panel.setLayout(new LayoutFill() {
|
|
||||||
@Override
|
|
||||||
public Vec2i calculatePreferredSize(Component c) {
|
|
||||||
return new Vec2i(label.getPreferredSize().x + 40, 4);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
getContent().addChild(panel);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Runnable getCloseAction() {
|
|
||||||
return closeAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void handleInput(Input input) {
|
|
||||||
|
|
||||||
if (!input.isConsumed()) {
|
|
||||||
InputEvent event = input.getEvent();
|
|
||||||
|
|
||||||
if (event instanceof KeyEvent) {
|
|
||||||
KeyEvent keyEvent = (KeyEvent) event;
|
|
||||||
if (keyEvent.isPress() && keyEvent.getKey() == GLFW.GLFW_KEY_ESCAPE) {
|
|
||||||
getCloseAction().run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
super.handleInput(input);
|
|
||||||
input.consume();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -87,14 +87,22 @@ public class CursorMoveEvent extends CursorEvent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CursorMoveEvent snapshot() {
|
public CursorMoveEvent snapshot() {
|
||||||
return new StaticMouseMoveEvent(getPreviousPosition(), getNewPosition(), getTime());
|
return new StaticMouseMoveEvent(
|
||||||
|
getPreviousPosition(),
|
||||||
|
getNewPosition(),
|
||||||
|
getTime()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class StaticMouseMoveEvent extends CursorMoveEvent {
|
private class StaticMouseMoveEvent extends CursorMoveEvent {
|
||||||
|
|
||||||
private final Vec2d previousPosition = new Vec2d();
|
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);
|
super(newPosition, time);
|
||||||
this.previousPosition.set(previousPosition.x, previousPosition.y);
|
this.previousPosition.set(previousPosition.x, previousPosition.y);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,11 @@ public class FrameResizeEvent extends InputEvent {
|
|||||||
|
|
||||||
private final Vec2i previousSize;
|
private final Vec2i previousSize;
|
||||||
|
|
||||||
public StaticFrameResizeEvent(Vec2i newSize, Vec2i previousSize, double time) {
|
public StaticFrameResizeEvent(
|
||||||
|
Vec2i newSize,
|
||||||
|
Vec2i previousSize,
|
||||||
|
double time
|
||||||
|
) {
|
||||||
super(newSize, time);
|
super(newSize, time);
|
||||||
this.previousSize = previousSize;
|
this.previousSize = previousSize;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,13 @@ public class KeyEvent extends InputEvent {
|
|||||||
protected int action;
|
protected int action;
|
||||||
protected int mods;
|
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);
|
super(time);
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.scancode = scancode;
|
this.scancode = scancode;
|
||||||
|
@ -46,12 +46,17 @@ public class Keys {
|
|||||||
private static final String MOUSE_BUTTON_PREFIX = "GLFW_MOUSE_BUTTON_";
|
private static final String MOUSE_BUTTON_PREFIX = "GLFW_MOUSE_BUTTON_";
|
||||||
|
|
||||||
private static final Set<String> IGNORE_FIELDS = new HashSet<>(
|
private static final Set<String> IGNORE_FIELDS = new HashSet<>(
|
||||||
Arrays.asList("GLFW_KEY_UNKNOWN", "GLFW_KEY_LAST", "GLFW_MOUSE_BUTTON_LAST", "GLFW_MOUSE_BUTTON_1", // Alias
|
Arrays.asList(
|
||||||
|
"GLFW_KEY_UNKNOWN",
|
||||||
|
"GLFW_KEY_LAST",
|
||||||
|
"GLFW_MOUSE_BUTTON_LAST",
|
||||||
|
"GLFW_MOUSE_BUTTON_1", // Alias
|
||||||
// for
|
// for
|
||||||
// LEFT
|
// LEFT
|
||||||
"GLFW_MOUSE_BUTTON_2", // Alias for RIGHT
|
"GLFW_MOUSE_BUTTON_2", // Alias for RIGHT
|
||||||
"GLFW_MOUSE_BUTTON_3" // Alias for MIDDLE
|
"GLFW_MOUSE_BUTTON_3" // Alias for MIDDLE
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
initializeDictionary();
|
initializeDictionary();
|
||||||
@ -95,8 +100,14 @@ public class Keys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CODES_TO_NAMES.containsKey(value)) {
|
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),
|
throw CrashReports.report(
|
||||||
name, value, Integer.toHexString(value));
|
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);
|
CODES_TO_NAMES.put(value, name);
|
||||||
|
@ -31,21 +31,28 @@ public class InputBus {
|
|||||||
private final boolean handleConsumed;
|
private final boolean handleConsumed;
|
||||||
private final InputListener<?> listener;
|
private final InputListener<?> listener;
|
||||||
|
|
||||||
public WrappedListener(Class<?> type, boolean handleConsumed, InputListener<?> listener) {
|
public WrappedListener(
|
||||||
|
Class<?> type,
|
||||||
|
boolean handleConsumed,
|
||||||
|
InputListener<?> listener
|
||||||
|
) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.handleConsumed = handleConsumed;
|
this.handleConsumed = handleConsumed;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handles(Input input) {
|
private boolean handles(Input input) {
|
||||||
return (!input.isConsumed() || handleConsumed) && type.isInstance(input.getEvent());
|
return (!input.isConsumed() || handleConsumed) &&
|
||||||
|
type.isInstance(input.getEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void handle(Input input) {
|
public void handle(Input input) {
|
||||||
if (handles(input)) {
|
if (handles(input)) {
|
||||||
boolean consumed = ((InputListener<InputEvent>) listener)
|
boolean consumed = ((InputListener<InputEvent>) listener)
|
||||||
.handle((InputEvent) type.cast(input.getEvent()));
|
.handle(
|
||||||
|
(InputEvent) type.cast(input.getEvent())
|
||||||
|
);
|
||||||
|
|
||||||
input.setConsumed(consumed);
|
input.setConsumed(consumed);
|
||||||
}
|
}
|
||||||
@ -59,12 +66,18 @@ public class InputBus {
|
|||||||
listeners.forEach(l -> l.handle(input));
|
listeners.forEach(l -> l.handle(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends InputEvent> void register(Class<? extends T> type, boolean handlesConsumed,
|
public <T extends InputEvent> void register(
|
||||||
InputListener<T> listener) {
|
Class<? extends T> type,
|
||||||
|
boolean handlesConsumed,
|
||||||
|
InputListener<T> listener
|
||||||
|
) {
|
||||||
listeners.add(new WrappedListener(type, handlesConsumed, listener));
|
listeners.add(new WrappedListener(type, handlesConsumed, listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends InputEvent> void register(Class<? extends T> type, InputListener<T> listener) {
|
public <T extends InputEvent> void register(
|
||||||
|
Class<? extends T> type,
|
||||||
|
InputListener<T> listener
|
||||||
|
) {
|
||||||
register(type, false, listener);
|
register(type, false, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,23 +18,23 @@
|
|||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.model;
|
package ru.windcorp.progressia.client.graphics.model;
|
||||||
|
|
||||||
import static ru.windcorp.progressia.common.world.rels.AbsFace.*;
|
import static ru.windcorp.progressia.common.world.block.BlockFace.*;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
import ru.windcorp.progressia.common.world.rels.AbsFace;
|
import ru.windcorp.progressia.common.world.block.BlockFace;
|
||||||
|
|
||||||
class BlockFaceVectors {
|
class BlockFaceVectors {
|
||||||
|
|
||||||
private static BlockFaceVectors createInner(BlockFaceVectors outer) {
|
private static BlockFaceVectors createInner(BlockFaceVectors outer) {
|
||||||
ImmutableMap.Builder<AbsFace, Vec3> originBuilder = ImmutableMap.builder();
|
ImmutableMap.Builder<BlockFace, Vec3> originBuilder = ImmutableMap.builder();
|
||||||
|
|
||||||
ImmutableMap.Builder<AbsFace, Vec3> widthBuilder = ImmutableMap.builder();
|
ImmutableMap.Builder<BlockFace, Vec3> widthBuilder = ImmutableMap.builder();
|
||||||
|
|
||||||
ImmutableMap.Builder<AbsFace, Vec3> heightBuilder = ImmutableMap.builder();
|
ImmutableMap.Builder<BlockFace, Vec3> heightBuilder = ImmutableMap.builder();
|
||||||
|
|
||||||
for (AbsFace face : getFaces()) {
|
for (BlockFace face : getFaces()) {
|
||||||
Vec3 width = outer.getWidth(face);
|
Vec3 width = outer.getWidth(face);
|
||||||
Vec3 height = outer.getHeight(face);
|
Vec3 height = outer.getHeight(face);
|
||||||
|
|
||||||
@ -59,36 +59,36 @@ class BlockFaceVectors {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
OUTER = new BlockFaceVectors(
|
OUTER = new BlockFaceVectors(
|
||||||
ImmutableMap.<AbsFace, Vec3>builder()
|
ImmutableMap.<BlockFace, Vec3>builder()
|
||||||
|
|
||||||
.put(POS_Z, new Vec3(-0.5f, +0.5f, +0.5f))
|
.put(TOP, new Vec3(-0.5f, +0.5f, +0.5f))
|
||||||
.put(NEG_Z, new Vec3(-0.5f, -0.5f, -0.5f))
|
.put(BOTTOM, new Vec3(-0.5f, -0.5f, -0.5f))
|
||||||
.put(POS_X, new Vec3(+0.5f, -0.5f, -0.5f))
|
.put(NORTH, new Vec3(+0.5f, -0.5f, -0.5f))
|
||||||
.put(NEG_X, new Vec3(-0.5f, +0.5f, -0.5f))
|
.put(SOUTH, new Vec3(-0.5f, +0.5f, -0.5f))
|
||||||
.put(POS_Y, new Vec3(+0.5f, +0.5f, -0.5f))
|
.put(WEST, new Vec3(+0.5f, +0.5f, -0.5f))
|
||||||
.put(NEG_Y, new Vec3(-0.5f, -0.5f, -0.5f))
|
.put(EAST, new Vec3(-0.5f, -0.5f, -0.5f))
|
||||||
|
|
||||||
.build(),
|
.build(),
|
||||||
|
|
||||||
ImmutableMap.<AbsFace, Vec3>builder()
|
ImmutableMap.<BlockFace, Vec3>builder()
|
||||||
|
|
||||||
.put(POS_Z, new Vec3(0, -1, 0))
|
.put(TOP, new Vec3(0, -1, 0))
|
||||||
.put(NEG_Z, new Vec3(0, +1, 0))
|
.put(BOTTOM, new Vec3(0, +1, 0))
|
||||||
.put(POS_X, new Vec3(0, +1, 0))
|
.put(NORTH, new Vec3(0, +1, 0))
|
||||||
.put(NEG_X, new Vec3(0, -1, 0))
|
.put(SOUTH, new Vec3(0, -1, 0))
|
||||||
.put(POS_Y, new Vec3(-1, 0, 0))
|
.put(WEST, new Vec3(-1, 0, 0))
|
||||||
.put(NEG_Y, new Vec3(+1, 0, 0))
|
.put(EAST, new Vec3(+1, 0, 0))
|
||||||
|
|
||||||
.build(),
|
.build(),
|
||||||
|
|
||||||
ImmutableMap.<AbsFace, Vec3>builder()
|
ImmutableMap.<BlockFace, Vec3>builder()
|
||||||
|
|
||||||
.put(POS_Z, new Vec3(+1, 0, 0))
|
.put(TOP, new Vec3(+1, 0, 0))
|
||||||
.put(NEG_Z, new Vec3(+1, 0, 0))
|
.put(BOTTOM, new Vec3(+1, 0, 0))
|
||||||
.put(POS_X, new Vec3(0, 0, +1))
|
.put(NORTH, new Vec3(0, 0, +1))
|
||||||
.put(NEG_X, new Vec3(0, 0, +1))
|
.put(SOUTH, new Vec3(0, 0, +1))
|
||||||
.put(POS_Y, new Vec3(0, 0, +1))
|
.put(WEST, new Vec3(0, 0, +1))
|
||||||
.put(NEG_Y, new Vec3(0, 0, +1))
|
.put(EAST, new Vec3(0, 0, +1))
|
||||||
|
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
@ -100,29 +100,29 @@ class BlockFaceVectors {
|
|||||||
return inner ? INNER : OUTER;
|
return inner ? INNER : OUTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ImmutableMap<AbsFace, Vec3> origins;
|
private final ImmutableMap<BlockFace, Vec3> origins;
|
||||||
private final ImmutableMap<AbsFace, Vec3> widths;
|
private final ImmutableMap<BlockFace, Vec3> widths;
|
||||||
private final ImmutableMap<AbsFace, Vec3> heights;
|
private final ImmutableMap<BlockFace, Vec3> heights;
|
||||||
|
|
||||||
public BlockFaceVectors(
|
public BlockFaceVectors(
|
||||||
ImmutableMap<AbsFace, Vec3> origins,
|
ImmutableMap<BlockFace, Vec3> origins,
|
||||||
ImmutableMap<AbsFace, Vec3> widths,
|
ImmutableMap<BlockFace, Vec3> widths,
|
||||||
ImmutableMap<AbsFace, Vec3> heights
|
ImmutableMap<BlockFace, Vec3> heights
|
||||||
) {
|
) {
|
||||||
this.origins = origins;
|
this.origins = origins;
|
||||||
this.widths = widths;
|
this.widths = widths;
|
||||||
this.heights = heights;
|
this.heights = heights;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 getOrigin(AbsFace face) {
|
public Vec3 getOrigin(BlockFace face) {
|
||||||
return origins.get(face);
|
return origins.get(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 getWidth(AbsFace face) {
|
public Vec3 getWidth(BlockFace face) {
|
||||||
return widths.get(face);
|
return widths.get(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 getHeight(AbsFace face) {
|
public Vec3 getHeight(BlockFace face) {
|
||||||
return heights.get(face);
|
return heights.get(face);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,22 @@ public abstract class DynamicModel extends Model {
|
|||||||
private final Mat4[] transforms;
|
private final Mat4[] transforms;
|
||||||
private final boolean[] dynamics;
|
private final boolean[] dynamics;
|
||||||
|
|
||||||
public DynamicModel(Renderable[] parts, Mat4[] transforms, boolean[] dynamic) {
|
public DynamicModel(
|
||||||
|
Renderable[] parts,
|
||||||
|
Mat4[] transforms,
|
||||||
|
boolean[] dynamic
|
||||||
|
) {
|
||||||
super(parts);
|
super(parts);
|
||||||
this.transforms = transforms;
|
this.transforms = transforms;
|
||||||
this.dynamics = dynamic;
|
this.dynamics = dynamic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicModel(Builder builder) {
|
public DynamicModel(Builder builder) {
|
||||||
this(builder.getParts(), builder.getTransforms(), builder.getDynamics());
|
this(
|
||||||
|
builder.getParts(),
|
||||||
|
builder.getTransforms(),
|
||||||
|
builder.getDynamics()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,7 +78,11 @@ public abstract class DynamicModel extends Model {
|
|||||||
protected Builder() {
|
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"));
|
parts.add(Objects.requireNonNull(part, "part"));
|
||||||
transforms.add(Objects.requireNonNull(transform, "transform"));
|
transforms.add(Objects.requireNonNull(transform, "transform"));
|
||||||
dynamics.add(isDynamic);
|
dynamics.add(isDynamic);
|
||||||
@ -78,15 +90,22 @@ public abstract class DynamicModel extends Model {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addStaticPart(Renderable part, Mat4 transform) {
|
public Builder addStaticPart(
|
||||||
|
Renderable part,
|
||||||
|
Mat4 transform
|
||||||
|
) {
|
||||||
return addPart(part, new Mat4(transform), false);
|
return addPart(part, new Mat4(transform), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addDynamicPart(Renderable part) {
|
public Builder addDynamicPart(
|
||||||
|
Renderable part
|
||||||
|
) {
|
||||||
return addPart(part, new Mat4(), true);
|
return addPart(part, new Mat4(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addStaticPart(Renderable part) {
|
public Builder addStaticPart(
|
||||||
|
Renderable part
|
||||||
|
) {
|
||||||
return addStaticPart(part, IDENTITY);
|
return addStaticPart(part, IDENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
||||||
|
|
||||||
public class ShapePart implements Comparable<ShapePart> {
|
public class Face implements Comparable<Face> {
|
||||||
|
|
||||||
private static final ShortBuffer GENERATE_SUCCESSIVE_LATER = null;
|
private static final ShortBuffer GENERATE_SUCCESSIVE_LATER = null;
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public class ShapePart implements Comparable<ShapePart> {
|
|||||||
private ShortBuffer userIndices;
|
private ShortBuffer userIndices;
|
||||||
private boolean userIndicesUpdated = true;
|
private boolean userIndicesUpdated = true;
|
||||||
|
|
||||||
public ShapePart(
|
public Face(
|
||||||
Texture texture,
|
Texture texture,
|
||||||
ByteBuffer vertices,
|
ByteBuffer vertices,
|
||||||
ShortBuffer indices
|
ShortBuffer indices
|
||||||
@ -50,7 +50,7 @@ public class ShapePart implements Comparable<ShapePart> {
|
|||||||
setIndices(indices);
|
setIndices(indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapePart(
|
public Face(
|
||||||
Texture texture,
|
Texture texture,
|
||||||
ByteBuffer vertices
|
ByteBuffer vertices
|
||||||
) {
|
) {
|
||||||
@ -155,7 +155,7 @@ public class ShapePart implements Comparable<ShapePart> {
|
|||||||
return vertices;
|
return vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapePart setVertices(ByteBuffer vertices) {
|
public Face setVertices(ByteBuffer vertices) {
|
||||||
this.vertices = Objects.requireNonNull(vertices, "vertices");
|
this.vertices = Objects.requireNonNull(vertices, "vertices");
|
||||||
markForVertexUpdate();
|
markForVertexUpdate();
|
||||||
return this;
|
return this;
|
||||||
@ -202,7 +202,7 @@ public class ShapePart implements Comparable<ShapePart> {
|
|||||||
return userIndices.remaining();
|
return userIndices.remaining();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapePart setIndices(ShortBuffer indices) {
|
public Face setIndices(ShortBuffer indices) {
|
||||||
if (indices == null) {
|
if (indices == null) {
|
||||||
indices = GENERATE_SUCCESSIVE_LATER;
|
indices = GENERATE_SUCCESSIVE_LATER;
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ public class ShapePart implements Comparable<ShapePart> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(ShapePart o) {
|
public int compareTo(Face o) {
|
||||||
return Integer.compare(getSortingIndex(), o.getSortingIndex());
|
return Integer.compare(getSortingIndex(), o.getSortingIndex());
|
||||||
}
|
}
|
||||||
|
|
@ -21,13 +21,13 @@ package ru.windcorp.progressia.client.graphics.model;
|
|||||||
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
||||||
import ru.windcorp.progressia.client.graphics.texture.TexturePrimitive;
|
import ru.windcorp.progressia.client.graphics.texture.TexturePrimitive;
|
||||||
|
|
||||||
public class ShapePartGroup {
|
public class FaceGroup {
|
||||||
|
|
||||||
private final TexturePrimitive texture;
|
private final TexturePrimitive texture;
|
||||||
private final int indexCount;
|
private final int indexCount;
|
||||||
private final int byteOffsetOfIndices;
|
private final int byteOffsetOfIndices;
|
||||||
|
|
||||||
ShapePartGroup(ShapePart[] faces, int start, int end) {
|
FaceGroup(Face[] faces, int start, int end) {
|
||||||
|
|
||||||
Texture t = faces[start].getTexture();
|
Texture t = faces[start].getTexture();
|
||||||
this.texture = t == null ? null : t.getSprite().getPrimitive();
|
this.texture = t == null ? null : t.getSprite().getPrimitive();
|
||||||
@ -36,9 +36,10 @@ public class ShapePartGroup {
|
|||||||
int indexCount = 0;
|
int indexCount = 0;
|
||||||
|
|
||||||
for (int i = start; i < end; ++i) {
|
for (int i = start; i < end; ++i) {
|
||||||
ShapePart face = faces[i];
|
Face face = faces[i];
|
||||||
|
|
||||||
assert this.texture == null ? (face.getTexture() == null)
|
assert this.texture == null
|
||||||
|
? (face.getTexture() == null)
|
||||||
: (face.getTexture().getSprite().getPrimitive() == this.texture);
|
: (face.getTexture().getSprite().getPrimitive() == this.texture);
|
||||||
|
|
||||||
indexCount += face.getIndexCount();
|
indexCount += face.getIndexCount();
|
@ -25,14 +25,14 @@ import glm.vec._3.Vec3;
|
|||||||
import glm.vec._4.Vec4;
|
import glm.vec._4.Vec4;
|
||||||
import ru.windcorp.progressia.client.graphics.model.ShapeRenderProgram.VertexBuilder;
|
import ru.windcorp.progressia.client.graphics.model.ShapeRenderProgram.VertexBuilder;
|
||||||
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
||||||
import ru.windcorp.progressia.common.world.rels.AbsFace;
|
import ru.windcorp.progressia.common.world.block.BlockFace;
|
||||||
|
|
||||||
public class ShapeParts {
|
public class Faces {
|
||||||
|
|
||||||
private ShapeParts() {
|
private Faces() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ShapePart createRectangle(
|
public static Face createRectangle(
|
||||||
ShapeRenderProgram program,
|
ShapeRenderProgram program,
|
||||||
Texture texture,
|
Texture texture,
|
||||||
Vec4 colorMultiplier,
|
Vec4 colorMultiplier,
|
||||||
@ -82,19 +82,19 @@ public class ShapeParts {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return new ShapePart(
|
return new Face(
|
||||||
texture,
|
texture,
|
||||||
builder.assemble(),
|
builder.assemble(),
|
||||||
buffer
|
buffer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ShapePart createBlockFace(
|
public static Face createBlockFace(
|
||||||
ShapeRenderProgram program,
|
ShapeRenderProgram program,
|
||||||
Texture texture,
|
Texture texture,
|
||||||
Vec4 colorMultiplier,
|
Vec4 colorMultiplier,
|
||||||
Vec3 blockCenter,
|
Vec3 blockCenter,
|
||||||
AbsFace face,
|
BlockFace face,
|
||||||
boolean inner
|
boolean inner
|
||||||
) {
|
) {
|
||||||
BlockFaceVectors vectors = BlockFaceVectors.get(inner);
|
BlockFaceVectors vectors = BlockFaceVectors.get(inner);
|
@ -37,13 +37,23 @@ public class LambdaModel extends DynamicModel {
|
|||||||
|
|
||||||
private final TransformGetter[] getters;
|
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);
|
super(parts, transforms, dynamic);
|
||||||
this.getters = getters;
|
this.getters = getters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LambdaModel(Builder builder) {
|
public LambdaModel(Builder builder) {
|
||||||
this(builder.getParts(), builder.getTransforms(), builder.getDynamics(), builder.getGetters());
|
this(
|
||||||
|
builder.getParts(),
|
||||||
|
builder.getTransforms(),
|
||||||
|
builder.getDynamics(),
|
||||||
|
builder.getGetters()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -65,7 +75,11 @@ public class LambdaModel extends DynamicModel {
|
|||||||
protected Builder() {
|
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"));
|
parts.add(Objects.requireNonNull(part, "part"));
|
||||||
transforms.add(Objects.requireNonNull(transform, "transform"));
|
transforms.add(Objects.requireNonNull(transform, "transform"));
|
||||||
dynamics.add(getter != null);
|
dynamics.add(getter != null);
|
||||||
@ -74,15 +88,23 @@ public class LambdaModel extends DynamicModel {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addStaticPart(Renderable part, Mat4 transform) {
|
public Builder addStaticPart(
|
||||||
|
Renderable part,
|
||||||
|
Mat4 transform
|
||||||
|
) {
|
||||||
return addPart(part, new Mat4(transform), null);
|
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);
|
return addPart(part, new Mat4(), getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addStaticPart(Renderable part) {
|
public Builder addStaticPart(
|
||||||
|
Renderable part
|
||||||
|
) {
|
||||||
return addStaticPart(part, IDENTITY);
|
return addStaticPart(part, IDENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +127,12 @@ public class LambdaModel extends DynamicModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static LambdaModel animate(Renderable model, TransformGetter transform) {
|
public static LambdaModel animate(Renderable model, TransformGetter transform) {
|
||||||
return new LambdaModel(new Renderable[] { model }, new Mat4[] { new Mat4() }, new boolean[] { true },
|
return new LambdaModel(
|
||||||
new TransformGetter[] { transform });
|
new Renderable[] { model },
|
||||||
|
new Mat4[] { new Mat4() },
|
||||||
|
new boolean[] { true },
|
||||||
|
new TransformGetter[] { transform }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,10 @@ import ru.windcorp.progressia.client.graphics.backend.VertexBufferObject;
|
|||||||
public class Shape implements Renderable {
|
public class Shape implements Renderable {
|
||||||
|
|
||||||
private final ShapeRenderProgram program;
|
private final ShapeRenderProgram program;
|
||||||
private final ShapePart[] parts;
|
private final Face[] faces;
|
||||||
private final Usage usage;
|
private final Usage usage;
|
||||||
|
|
||||||
private ShapePartGroup[] groups;
|
private FaceGroup[] groups;
|
||||||
|
|
||||||
private ByteBuffer vertices;
|
private ByteBuffer vertices;
|
||||||
private ShortBuffer indices;
|
private ShortBuffer indices;
|
||||||
@ -45,33 +45,33 @@ public class Shape implements Renderable {
|
|||||||
private VertexBufferObject verticesVbo;
|
private VertexBufferObject verticesVbo;
|
||||||
private VertexBufferObject indicesVbo;
|
private VertexBufferObject indicesVbo;
|
||||||
|
|
||||||
public Shape(Usage usage, ShapeRenderProgram program, ShapePart... parts) {
|
public Shape(Usage usage, ShapeRenderProgram program, Face... faces) {
|
||||||
this.program = program;
|
this.program = program;
|
||||||
this.parts = parts;
|
this.faces = faces;
|
||||||
this.usage = usage;
|
this.usage = usage;
|
||||||
|
|
||||||
configureParts();
|
configureFaces();
|
||||||
program.preprocess(this);
|
program.preprocess(this);
|
||||||
|
|
||||||
assembleBuffers();
|
assembleBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureParts() {
|
private void configureFaces() {
|
||||||
for (ShapePart part : parts) {
|
for (Face face : faces) {
|
||||||
part.setShape(this);
|
face.setShape(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assembleBuffers() {
|
private void assembleBuffers() {
|
||||||
// TODO optimize: only update faces that requested it
|
// TODO optimize: only update faces that requested it
|
||||||
|
|
||||||
sortParts();
|
sortFaces();
|
||||||
resizeBuffers();
|
resizeBuffers();
|
||||||
|
|
||||||
for (ShapePart part : parts) {
|
for (Face face : faces) {
|
||||||
assembleVertices(part);
|
assembleVertices(face);
|
||||||
assembleIndices(part);
|
assembleIndices(face);
|
||||||
part.resetUpdateFlags();
|
face.resetUpdateFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.vertices.flip();
|
this.vertices.flip();
|
||||||
@ -85,110 +85,110 @@ public class Shape implements Renderable {
|
|||||||
|
|
||||||
private void resizeBuffers() {
|
private void resizeBuffers() {
|
||||||
int verticesRequired = 0, indicesRequired = 0;
|
int verticesRequired = 0, indicesRequired = 0;
|
||||||
for (ShapePart part : parts) {
|
for (Face face : faces) {
|
||||||
verticesRequired += part.getVertices().remaining();
|
verticesRequired += face.getVertices().remaining();
|
||||||
indicesRequired += part.getIndices().remaining();
|
indicesRequired += face.getIndices().remaining();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vertices == null || vertices.capacity() < verticesRequired) {
|
if (this.vertices == null || vertices.capacity() < verticesRequired) {
|
||||||
this.vertices = BufferUtils.createByteBuffer(verticesRequired);
|
this.vertices = BufferUtils.createByteBuffer(verticesRequired);
|
||||||
} else {
|
} else {
|
||||||
vertices.position(0).limit(verticesRequired);
|
this.vertices.position(0).limit(verticesRequired);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indices == null || indices.capacity() < indicesRequired) {
|
if (this.indices == null || this.indices.capacity() < indicesRequired) {
|
||||||
this.indices = BufferUtils.createShortBuffer(indicesRequired);
|
this.indices = BufferUtils.createShortBuffer(indicesRequired);
|
||||||
} else {
|
} else {
|
||||||
indices.position(0).limit(indicesRequired);
|
this.indices.position(0).limit(indicesRequired);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assembleVertices(ShapePart part) {
|
private void assembleVertices(Face face) {
|
||||||
part.locationOfVertices = this.vertices.position();
|
face.locationOfVertices = this.vertices.position();
|
||||||
|
|
||||||
insertVertices(part);
|
insertVertices(face);
|
||||||
linkVerticesWith(part);
|
linkVerticesWith(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertVertices(ShapePart part) {
|
private void insertVertices(Face face) {
|
||||||
ByteBuffer partVertices = part.getVertices();
|
ByteBuffer faceVertices = face.getVertices();
|
||||||
|
|
||||||
partVertices.mark();
|
faceVertices.mark();
|
||||||
this.vertices.put(partVertices);
|
this.vertices.put(faceVertices);
|
||||||
partVertices.reset();
|
faceVertices.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void linkVerticesWith(ShapePart part) {
|
private void linkVerticesWith(Face face) {
|
||||||
int limit = vertices.limit();
|
int limit = vertices.limit();
|
||||||
int position = vertices.position();
|
int position = vertices.position();
|
||||||
|
|
||||||
vertices.limit(position).position(part.getLocationOfVertices());
|
vertices.limit(position).position(face.getLocationOfVertices());
|
||||||
part.vertices = vertices.slice();
|
face.vertices = vertices.slice();
|
||||||
|
|
||||||
vertices.position(position).limit(limit);
|
vertices.position(position).limit(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assembleIndices(ShapePart part) {
|
private void assembleIndices(Face face) {
|
||||||
short vertexOffset = (short) (part.getLocationOfVertices() / program.getBytesPerVertex());
|
short vertexOffset = (short) (face.getLocationOfVertices() / program.getBytesPerVertex());
|
||||||
|
|
||||||
part.locationOfIndices = indices.position();
|
face.locationOfIndices = indices.position();
|
||||||
|
|
||||||
ShortBuffer partIndices = part.getIndices();
|
ShortBuffer faceIndices = face.getIndices();
|
||||||
|
|
||||||
if (partIndices == null) {
|
if (faceIndices == null) {
|
||||||
for (int i = 0; i < part.getVertexCount(); ++i) {
|
for (int i = 0; i < face.getVertexCount(); ++i) {
|
||||||
this.indices.put((short) (vertexOffset + i));
|
this.indices.put((short) (vertexOffset + i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = partIndices.position(); i < partIndices.limit(); ++i) {
|
for (int i = faceIndices.position(); i < faceIndices.limit(); ++i) {
|
||||||
short partIndex = partIndices.get(i);
|
short faceIndex = faceIndices.get(i);
|
||||||
partIndex += vertexOffset;
|
faceIndex += vertexOffset;
|
||||||
this.indices.put(partIndex);
|
this.indices.put(faceIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortParts() {
|
private void sortFaces() {
|
||||||
Arrays.sort(parts);
|
Arrays.sort(faces);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assembleGroups() {
|
private void assembleGroups() {
|
||||||
int unique = countUniqueParts();
|
int unique = countUniqueFaces();
|
||||||
this.groups = new ShapePartGroup[unique];
|
this.groups = new FaceGroup[unique];
|
||||||
|
|
||||||
if (parts.length == 0)
|
if (faces.length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int previousHandle = parts[0].getSortingIndex();
|
int previousHandle = faces[0].getSortingIndex();
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int groupIndex = 0;
|
int groupIndex = 0;
|
||||||
|
|
||||||
for (int i = 1; i < parts.length; ++i) {
|
for (int i = 1; i < faces.length; ++i) {
|
||||||
if (previousHandle != parts[i].getSortingIndex()) {
|
if (previousHandle != faces[i].getSortingIndex()) {
|
||||||
|
|
||||||
groups[groupIndex] = new ShapePartGroup(parts, start, i);
|
groups[groupIndex] = new FaceGroup(faces, start, i);
|
||||||
start = i;
|
start = i;
|
||||||
groupIndex++;
|
groupIndex++;
|
||||||
|
|
||||||
previousHandle = parts[i].getSortingIndex();
|
previousHandle = faces[i].getSortingIndex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert groupIndex == groups.length - 1;
|
assert groupIndex == groups.length - 1;
|
||||||
groups[groupIndex] = new ShapePartGroup(parts, start, parts.length);
|
groups[groupIndex] = new FaceGroup(faces, start, faces.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countUniqueParts() {
|
private int countUniqueFaces() {
|
||||||
if (parts.length == 0)
|
if (faces.length == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int result = 1;
|
int result = 1;
|
||||||
int previousHandle = parts[0].getSortingIndex();
|
int previousHandle = faces[0].getSortingIndex();
|
||||||
|
|
||||||
for (int i = 1; i < parts.length; ++i) {
|
for (int i = 1; i < faces.length; ++i) {
|
||||||
if (previousHandle != parts[i].getSortingIndex()) {
|
if (previousHandle != faces[i].getSortingIndex()) {
|
||||||
result++;
|
result++;
|
||||||
previousHandle = parts[i].getSortingIndex();
|
previousHandle = faces[i].getSortingIndex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,11 +238,11 @@ public class Shape implements Renderable {
|
|||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapePart[] getParts() {
|
public Face[] getFaces() {
|
||||||
return parts;
|
return faces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapePartGroup[] getGroups() {
|
public FaceGroup[] getGroups() {
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,10 +28,15 @@ public class ShapeRenderHelper {
|
|||||||
protected static final int TRANSFORM_STACK_SIZE = 64;
|
protected static final int TRANSFORM_STACK_SIZE = 64;
|
||||||
protected static final int COLOR_MULTIPLIER_STACK_SIZE = TRANSFORM_STACK_SIZE;
|
protected static final int COLOR_MULTIPLIER_STACK_SIZE = TRANSFORM_STACK_SIZE;
|
||||||
|
|
||||||
protected final StashingStack<Mat4> transformStack = new StashingStack<>(TRANSFORM_STACK_SIZE, Mat4::new);
|
protected final StashingStack<Mat4> transformStack = new StashingStack<>(
|
||||||
|
TRANSFORM_STACK_SIZE,
|
||||||
|
Mat4::new
|
||||||
|
);
|
||||||
|
|
||||||
protected final StashingStack<Vec4> colorMultiplierStack = new StashingStack<>(COLOR_MULTIPLIER_STACK_SIZE,
|
protected final StashingStack<Vec4> colorMultiplierStack = new StashingStack<>(
|
||||||
Vec4::new);
|
COLOR_MULTIPLIER_STACK_SIZE,
|
||||||
|
Vec4::new
|
||||||
|
);
|
||||||
|
|
||||||
{
|
{
|
||||||
transformStack.push().identity();
|
transformStack.push().identity();
|
||||||
|
@ -53,7 +53,8 @@ public class ShapeRenderProgram extends Program {
|
|||||||
POSITIONS_ATTRIBUTE_NAME = "inputPositions",
|
POSITIONS_ATTRIBUTE_NAME = "inputPositions",
|
||||||
UNIFORM_COLOR_MULTIPLER_ATTRIBUTE_NAME = "uniformColorMultiplier",
|
UNIFORM_COLOR_MULTIPLER_ATTRIBUTE_NAME = "uniformColorMultiplier",
|
||||||
ATTRIBUTE_COLOR_MULTIPLER_ATTRIBUTE_NAME = "inputColorMultiplier",
|
ATTRIBUTE_COLOR_MULTIPLER_ATTRIBUTE_NAME = "inputColorMultiplier",
|
||||||
TEXTURE_COORDS_ATTRIBUTE_NAME = "inputTextureCoords", USE_TEXTURE_UNIFORM_NAME = "useTexture",
|
TEXTURE_COORDS_ATTRIBUTE_NAME = "inputTextureCoords",
|
||||||
|
USE_TEXTURE_UNIFORM_NAME = "useTexture",
|
||||||
TEXTURE_SLOT_UNIFORM_NAME = "textureSlot";
|
TEXTURE_SLOT_UNIFORM_NAME = "textureSlot";
|
||||||
|
|
||||||
private final Uniform4Matrix finalTransformUniform;
|
private final Uniform4Matrix finalTransformUniform;
|
||||||
@ -64,11 +65,21 @@ public class ShapeRenderProgram extends Program {
|
|||||||
private final Uniform1Int useTextureUniform;
|
private final Uniform1Int useTextureUniform;
|
||||||
private final Uniform1Int textureSlotUniform;
|
private final Uniform1Int textureSlotUniform;
|
||||||
|
|
||||||
public ShapeRenderProgram(String[] vertexShaderResources, String[] fragmentShaderResources) {
|
public ShapeRenderProgram(
|
||||||
super(new CombinedShader(attachVertexShader(vertexShaderResources)),
|
String[] vertexShaderResources,
|
||||||
new CombinedShader(attachFragmentShader(fragmentShaderResources)));
|
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();
|
this.positionsAttribute = getAttribute(POSITIONS_ATTRIBUTE_NAME).asVertexArray();
|
||||||
|
|
||||||
@ -78,9 +89,11 @@ public class ShapeRenderProgram extends Program {
|
|||||||
|
|
||||||
this.textureCoordsAttribute = getAttribute(TEXTURE_COORDS_ATTRIBUTE_NAME).asVertexArray();
|
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) {
|
private static String[] attachVertexShader(String[] others) {
|
||||||
@ -91,7 +104,10 @@ public class ShapeRenderProgram extends Program {
|
|||||||
return ObjectArrays.concat(SHAPE_FRAGMENT_SHADER_RESOURCE, others);
|
return ObjectArrays.concat(SHAPE_FRAGMENT_SHADER_RESOURCE, others);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(ShapeRenderHelper helper, Shape shape) {
|
public void render(
|
||||||
|
ShapeRenderHelper helper,
|
||||||
|
Shape shape
|
||||||
|
) {
|
||||||
use();
|
use();
|
||||||
configure(helper);
|
configure(helper);
|
||||||
|
|
||||||
@ -100,7 +116,7 @@ public class ShapeRenderProgram extends Program {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
enableAttributes();
|
enableAttributes();
|
||||||
for (ShapePartGroup group : shape.getGroups()) {
|
for (FaceGroup group : shape.getGroups()) {
|
||||||
renderFaceGroup(group);
|
renderFaceGroup(group);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -129,13 +145,34 @@ public class ShapeRenderProgram extends Program {
|
|||||||
int vertexStride = getBytesPerVertex();
|
int vertexStride = getBytesPerVertex();
|
||||||
int offset = 0;
|
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;
|
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;
|
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;
|
offset += 2 * Float.BYTES;
|
||||||
|
|
||||||
return offset;
|
return offset;
|
||||||
@ -145,7 +182,7 @@ public class ShapeRenderProgram extends Program {
|
|||||||
indices.bind(BindTarget.ELEMENT_ARRAY);
|
indices.bind(BindTarget.ELEMENT_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void renderFaceGroup(ShapePartGroup group) {
|
protected void renderFaceGroup(FaceGroup group) {
|
||||||
TexturePrimitive texture = group.getTexture();
|
TexturePrimitive texture = group.getTexture();
|
||||||
|
|
||||||
if (texture != null) {
|
if (texture != null) {
|
||||||
@ -156,8 +193,12 @@ public class ShapeRenderProgram extends Program {
|
|||||||
useTextureUniform.set(0);
|
useTextureUniform.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GL11.glDrawElements(GL11.GL_TRIANGLES, group.getIndexCount(), GL11.GL_UNSIGNED_SHORT,
|
GL11.glDrawElements(
|
||||||
group.getByteOffsetOfIndices());
|
GL11.GL_TRIANGLES,
|
||||||
|
group.getIndexCount(),
|
||||||
|
GL11.GL_UNSIGNED_SHORT,
|
||||||
|
group.getByteOffsetOfIndices()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBytesPerVertex() {
|
public int getBytesPerVertex() {
|
||||||
@ -165,12 +206,12 @@ public class ShapeRenderProgram extends Program {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void preprocess(Shape shape) {
|
public void preprocess(Shape shape) {
|
||||||
for (ShapePart face : shape.getParts()) {
|
for (Face face : shape.getFaces()) {
|
||||||
applySprites(face);
|
applySprites(face);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applySprites(ShapePart face) {
|
private void applySprites(Face face) {
|
||||||
if (face.getTexture() == null)
|
if (face.getTexture() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -179,9 +220,13 @@ public class ShapeRenderProgram extends Program {
|
|||||||
Sprite sprite = face.getTexture().getSprite();
|
Sprite sprite = face.getTexture().getSprite();
|
||||||
|
|
||||||
for (int i = 0; i < face.getVertexCount(); i++) {
|
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());
|
v.mul(sprite.getSize()).add(sprite.getStart());
|
||||||
|
|
||||||
@ -199,11 +244,34 @@ public class ShapeRenderProgram extends Program {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static interface VertexBuilder {
|
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();
|
ByteBuffer assemble();
|
||||||
}
|
}
|
||||||
@ -225,35 +293,84 @@ public class ShapeRenderProgram extends Program {
|
|||||||
private final List<Vertex> vertices = new ArrayList<>();
|
private final List<Vertex> vertices = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VertexBuilder addVertex(float x, float y, float z, float r, float g, float b, float a, float tx,
|
public VertexBuilder addVertex(
|
||||||
float ty) {
|
float x,
|
||||||
vertices.add(new Vertex(new Vec3(x, y, z), new Vec4(r, g, b, a), new Vec2(tx, ty)));
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VertexBuilder addVertex(float x, float y, float z, float r, float g, float b, float tx, float ty) {
|
public VertexBuilder addVertex(
|
||||||
vertices.add(new Vertex(new Vec3(x, y, z), new Vec4(r, g, b, 1f), new Vec2(tx, ty)));
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VertexBuilder addVertex(Vec3 position, Vec4 colorMultiplier, Vec2 textureCoords) {
|
public VertexBuilder addVertex(
|
||||||
vertices.add(new Vertex(new Vec3(position), new Vec4(colorMultiplier), new Vec2(textureCoords)));
|
Vec3 position,
|
||||||
|
Vec4 colorMultiplier,
|
||||||
|
Vec2 textureCoords
|
||||||
|
) {
|
||||||
|
vertices.add(
|
||||||
|
new Vertex(
|
||||||
|
new Vec3(position),
|
||||||
|
new Vec4(colorMultiplier),
|
||||||
|
new Vec2(textureCoords)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer assemble() {
|
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) {
|
for (Vertex v : vertices) {
|
||||||
result.putFloat(v.position.x).putFloat(v.position.y).putFloat(v.position.z)
|
result
|
||||||
.putFloat(v.colorMultiplier.x).putFloat(v.colorMultiplier.y).putFloat(v.colorMultiplier.z)
|
.putFloat(v.position.x)
|
||||||
.putFloat(v.colorMultiplier.w).putFloat(v.textureCoords.x).putFloat(v.textureCoords.y);
|
.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();
|
result.flip();
|
||||||
|
@ -24,7 +24,7 @@ import glm.vec._3.Vec3;
|
|||||||
import glm.vec._4.Vec4;
|
import glm.vec._4.Vec4;
|
||||||
import ru.windcorp.progressia.client.graphics.backend.Usage;
|
import ru.windcorp.progressia.client.graphics.backend.Usage;
|
||||||
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
||||||
import ru.windcorp.progressia.common.world.rels.AbsFace;
|
import ru.windcorp.progressia.common.world.block.BlockFace;
|
||||||
|
|
||||||
public class Shapes {
|
public class Shapes {
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ public class Shapes {
|
|||||||
boolean flip
|
boolean flip
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ShapePart top = ShapeParts.createRectangle(
|
Face top = Faces.createRectangle(
|
||||||
program,
|
program,
|
||||||
topTexture,
|
topTexture,
|
||||||
colorMultiplier,
|
colorMultiplier,
|
||||||
@ -60,7 +60,7 @@ public class Shapes {
|
|||||||
flip
|
flip
|
||||||
);
|
);
|
||||||
|
|
||||||
ShapePart bottom = ShapeParts.createRectangle(
|
Face bottom = Faces.createRectangle(
|
||||||
program,
|
program,
|
||||||
bottomTexture,
|
bottomTexture,
|
||||||
colorMultiplier,
|
colorMultiplier,
|
||||||
@ -70,7 +70,7 @@ public class Shapes {
|
|||||||
flip
|
flip
|
||||||
);
|
);
|
||||||
|
|
||||||
ShapePart north = ShapeParts.createRectangle(
|
Face north = Faces.createRectangle(
|
||||||
program,
|
program,
|
||||||
northTexture,
|
northTexture,
|
||||||
colorMultiplier,
|
colorMultiplier,
|
||||||
@ -80,7 +80,7 @@ public class Shapes {
|
|||||||
flip
|
flip
|
||||||
);
|
);
|
||||||
|
|
||||||
ShapePart south = ShapeParts.createRectangle(
|
Face south = Faces.createRectangle(
|
||||||
program,
|
program,
|
||||||
southTexture,
|
southTexture,
|
||||||
colorMultiplier,
|
colorMultiplier,
|
||||||
@ -90,7 +90,7 @@ public class Shapes {
|
|||||||
flip
|
flip
|
||||||
);
|
);
|
||||||
|
|
||||||
ShapePart east = ShapeParts.createRectangle(
|
Face east = Faces.createRectangle(
|
||||||
program,
|
program,
|
||||||
eastTexture,
|
eastTexture,
|
||||||
colorMultiplier,
|
colorMultiplier,
|
||||||
@ -100,7 +100,7 @@ public class Shapes {
|
|||||||
flip
|
flip
|
||||||
);
|
);
|
||||||
|
|
||||||
ShapePart west = ShapeParts.createRectangle(
|
Face west = Faces.createRectangle(
|
||||||
program,
|
program,
|
||||||
westTexture,
|
westTexture,
|
||||||
colorMultiplier,
|
colorMultiplier,
|
||||||
@ -165,16 +165,16 @@ public class Shapes {
|
|||||||
|
|
||||||
public PppBuilder(
|
public PppBuilder(
|
||||||
ShapeRenderProgram program,
|
ShapeRenderProgram program,
|
||||||
Map<AbsFace, Texture> textureMap
|
Map<BlockFace, Texture> textureMap
|
||||||
) {
|
) {
|
||||||
this(
|
this(
|
||||||
program,
|
program,
|
||||||
textureMap.get(AbsFace.POS_Z),
|
textureMap.get(BlockFace.TOP),
|
||||||
textureMap.get(AbsFace.NEG_Z),
|
textureMap.get(BlockFace.BOTTOM),
|
||||||
textureMap.get(AbsFace.POS_X),
|
textureMap.get(BlockFace.NORTH),
|
||||||
textureMap.get(AbsFace.NEG_X),
|
textureMap.get(BlockFace.SOUTH),
|
||||||
textureMap.get(AbsFace.NEG_Y),
|
textureMap.get(BlockFace.EAST),
|
||||||
textureMap.get(AbsFace.POS_Y)
|
textureMap.get(BlockFace.WEST)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,10 @@ public class StaticModel extends Model {
|
|||||||
|
|
||||||
private final Mat4[] transforms;
|
private final Mat4[] transforms;
|
||||||
|
|
||||||
public StaticModel(Renderable[] parts, Mat4[] transforms) {
|
public StaticModel(
|
||||||
|
Renderable[] parts,
|
||||||
|
Mat4[] transforms
|
||||||
|
) {
|
||||||
super(parts);
|
super(parts);
|
||||||
this.transforms = transforms;
|
this.transforms = transforms;
|
||||||
}
|
}
|
||||||
@ -52,14 +55,19 @@ public class StaticModel extends Model {
|
|||||||
protected Builder() {
|
protected Builder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addPart(Renderable part, Mat4 transform) {
|
public Builder addPart(
|
||||||
|
Renderable part,
|
||||||
|
Mat4 transform
|
||||||
|
) {
|
||||||
parts.add(Objects.requireNonNull(part, "part"));
|
parts.add(Objects.requireNonNull(part, "part"));
|
||||||
transforms.add(Objects.requireNonNull(transform, "transform"));
|
transforms.add(Objects.requireNonNull(transform, "transform"));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addPart(Renderable part) {
|
public Builder addPart(
|
||||||
|
Renderable part
|
||||||
|
) {
|
||||||
return addPart(part, IDENTITY);
|
return addPart(part, IDENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,8 +87,11 @@ public class Atlases {
|
|||||||
|
|
||||||
editor.draw(data, nextX, nextY);
|
editor.draw(data, nextX, nextY);
|
||||||
|
|
||||||
Sprite result = new Sprite(getPrimitive(), toPrimitiveCoords(nextX, nextY),
|
Sprite result = new Sprite(
|
||||||
toPrimitiveCoords(width, height));
|
getPrimitive(),
|
||||||
|
toPrimitiveCoords(nextX, nextY),
|
||||||
|
toPrimitiveCoords(width, height)
|
||||||
|
);
|
||||||
|
|
||||||
nextX += width;
|
nextX += width;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ package ru.windcorp.progressia.client.graphics.texture;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import glm.vec._2.Vec2;
|
import glm.vec._2.Vec2;
|
||||||
import ru.windcorp.progressia.common.world.rels.AbsFace;
|
import ru.windcorp.progressia.common.world.block.BlockFace;
|
||||||
|
|
||||||
public class ComplexTexture {
|
public class ComplexTexture {
|
||||||
|
|
||||||
@ -54,14 +54,14 @@ public class ComplexTexture {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<AbsFace, Texture> getCuboidTextures(
|
public Map<BlockFace, Texture> getCuboidTextures(
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int depth
|
int depth
|
||||||
) {
|
) {
|
||||||
return AbsFace.mapToFaces(
|
return BlockFace.mapToFaces(
|
||||||
get(
|
get(
|
||||||
x + depth + width,
|
x + depth + width,
|
||||||
y + height + depth,
|
y + height + depth,
|
||||||
@ -86,7 +86,7 @@ public class ComplexTexture {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<AbsFace, Texture> getCuboidTextures(
|
public Map<BlockFace, Texture> getCuboidTextures(
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
int size
|
int size
|
||||||
|
@ -44,7 +44,9 @@ public class SimpleTextures {
|
|||||||
try {
|
try {
|
||||||
TextureDataEditor data = TextureLoader.loadPixels(resource, SETTINGS);
|
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) {
|
} catch (IOException e) {
|
||||||
throw CrashReports.report(e, "Could not load texture %s", resource);
|
throw CrashReports.report(e, "Could not load texture %s", resource);
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,14 @@ public class Sprite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Sprite(TexturePrimitive primitive) {
|
public Sprite(TexturePrimitive primitive) {
|
||||||
this(primitive, ORIGIN, new Vec2(primitive.getWidth() / (float) primitive.getBufferWidth(),
|
this(
|
||||||
primitive.getHeight() / (float) primitive.getBufferHeight()));
|
primitive,
|
||||||
|
ORIGIN,
|
||||||
|
new Vec2(
|
||||||
|
primitive.getWidth() / (float) primitive.getBufferWidth(),
|
||||||
|
primitive.getHeight() / (float) primitive.getBufferHeight()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TexturePrimitive getPrimitive() {
|
public TexturePrimitive getPrimitive() {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user