diff --git a/.gitignore b/.gitignore index e7a4f0a3..01cfea5a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ /libs/javafxdependencies/target/ /libs/goapcom/target/ /libs/observer/target/ -/libs/rendertools/target/ +/libs/commons/target/ /libs/maze/target/ /libs/tacviewfx/target/ /libs/dynamicproperties/target/ diff --git a/TODO.md b/TODO.md index 774284ab..426d8bc6 100644 --- a/TODO.md +++ b/TODO.md @@ -1,11 +1,11 @@ # TODO LIST # 1 -* new InputComponent interacting with MapComponent - * (map) zooming (<<<<<<<--------------------------------) -* add sortable physics modifier components * NULLImplementations -> Optionals ... * +* only render visible part of screen! special renderer for screen. (<-) +* add sortable physics modifier components +* * dynamic changeable render properties! * optimize Layers so that they must not be reinstantiated every time on update. Reuse layers and remove/extend entities on update * @@ -17,7 +17,6 @@ * add menu - # 1.1 * load entity to environment * load new environment diff --git a/libs/rendertools/pom.xml b/libs/commons/pom.xml similarity index 93% rename from libs/rendertools/pom.xml rename to libs/commons/pom.xml index ec8488d4..27e8910e 100644 --- a/libs/rendertools/pom.xml +++ b/libs/commons/pom.xml @@ -9,10 +9,10 @@ 4.0.0 - recom-rendertools + recom-commons 1.0.0-SNAPSHOT - RECOM Render Tools - RECOM Render Tools + RECOM Commons + RECOM Commons diff --git a/libs/rendertools/src/main/java/com/recom/rendertools/calculator/ARGBCalculator.java b/libs/commons/src/main/java/com/recom/commons/calculator/ARGBCalculator.java similarity index 68% rename from libs/rendertools/src/main/java/com/recom/rendertools/calculator/ARGBCalculator.java rename to libs/commons/src/main/java/com/recom/commons/calculator/ARGBCalculator.java index 5398d829..bbb9b7f6 100644 --- a/libs/rendertools/src/main/java/com/recom/rendertools/calculator/ARGBCalculator.java +++ b/libs/commons/src/main/java/com/recom/commons/calculator/ARGBCalculator.java @@ -1,13 +1,11 @@ -package com.recom.rendertools.calculator; +package com.recom.commons.calculator; import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; -import lombok.experimental.UtilityClass; @NoArgsConstructor public class ARGBCalculator { - public int blend(final int foregroundColor, final int backgroundColour) { + public static int blend(final int foregroundColor, final int backgroundColour) { final double alpha = getAlphaComponent(foregroundColor) / 255.0; final double oneMinusAlpha = 1 - alpha; @@ -19,23 +17,23 @@ public int blend(final int foregroundColor, final int backgroundColour) { return compose(newAlpha, (int) newRed, (int) newGreen, (int) newBlue); } - public int getAlphaComponent(final int color) { + public static int getAlphaComponent(final int color) { return (color >> 24) & 0xff; } - public int getRedComponent(final int color) { + public static int getRedComponent(final int color) { return (color >> 16) & 0xff; } - public int getGreenComponent(final int color) { + public static int getGreenComponent(final int color) { return (color >> 8) & 0xff; } - public int getBlueComponent(final int color) { + public static int getBlueComponent(final int color) { return color & 0xff; } - public int compose(final int alpha, final int red, final int green, final int blue) { + public static int compose(final int alpha, final int red, final int green, final int blue) { return ((alpha & 0xFF) << 24) | ((red & 0xFF) << 16) | ((green & 0xFF) << 8) | diff --git a/libs/rendertools/src/main/java/com/recom/rendertools/calculator/ARGBColor.java b/libs/commons/src/main/java/com/recom/commons/calculator/ARGBColor.java similarity index 94% rename from libs/rendertools/src/main/java/com/recom/rendertools/calculator/ARGBColor.java rename to libs/commons/src/main/java/com/recom/commons/calculator/ARGBColor.java index b2e141ea..e0a62c05 100644 --- a/libs/rendertools/src/main/java/com/recom/rendertools/calculator/ARGBColor.java +++ b/libs/commons/src/main/java/com/recom/commons/calculator/ARGBColor.java @@ -1,4 +1,4 @@ -package com.recom.rendertools.calculator; +package com.recom.commons.calculator; import lombok.NoArgsConstructor; import lombok.NonNull; diff --git a/libs/commons/src/main/java/com/recom/commons/calculator/TrigonometricCalculator.java b/libs/commons/src/main/java/com/recom/commons/calculator/TrigonometricCalculator.java new file mode 100644 index 00000000..8acfd28d --- /dev/null +++ b/libs/commons/src/main/java/com/recom/commons/calculator/TrigonometricCalculator.java @@ -0,0 +1,29 @@ +package com.recom.commons.calculator; + +public class TrigonometricCalculator { + + public static double calculateRadiantBetweenPoints( + final double x1, + final double y1, + final double x2, + final double y2 + ) { + final double deltaX = x2 - x1; + final double deltaY = y2 - y1; + + return Math.atan2(deltaY, deltaX); + } + + public static double calculateDistanceBetweenPoints( + final double x1, + final double y1, + final double x2, + final double y2 + ) { + final double deltaX = x2 - x1; + final double deltaY = y2 - y1; + + return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); + } + +} diff --git a/libs/commons/src/main/java/com/recom/commons/math/Round.java b/libs/commons/src/main/java/com/recom/commons/math/Round.java new file mode 100644 index 00000000..1528ba1a --- /dev/null +++ b/libs/commons/src/main/java/com/recom/commons/math/Round.java @@ -0,0 +1,16 @@ +package com.recom.commons.math; + +public class Round { + + public static int halfUp(final double number) { + final int integerComponent = (int) Math.floor(number); + final double decimalComponent = number - integerComponent; + + if (decimalComponent >= 0.5) { + return integerComponent + 1; + } else { + return integerComponent; + } + } + +} diff --git a/libs/commons/src/main/java/com/recom/commons/math/Sign.java b/libs/commons/src/main/java/com/recom/commons/math/Sign.java new file mode 100644 index 00000000..94a4c0a5 --- /dev/null +++ b/libs/commons/src/main/java/com/recom/commons/math/Sign.java @@ -0,0 +1,25 @@ +package com.recom.commons.math; + +public class Sign { + + public static int of(final int number) { + if (number > 0) { + return 1; + } else if (number < 0) { + return -1; + } else { + return 0; + } + } + + public static int of(final double number) { + if (number > 0) { + return 1; + } else if (number < 0) { + return -1; + } else { + return 0; + } + } + +} diff --git a/libs/rendertools/src/main/java/com/recom/rendertools/rasterizer/HeightMapDescriptor.java b/libs/commons/src/main/java/com/recom/commons/rasterizer/HeightMapDescriptor.java similarity index 91% rename from libs/rendertools/src/main/java/com/recom/rendertools/rasterizer/HeightMapDescriptor.java rename to libs/commons/src/main/java/com/recom/commons/rasterizer/HeightMapDescriptor.java index 3be507c0..70eaaeba 100644 --- a/libs/rendertools/src/main/java/com/recom/rendertools/rasterizer/HeightMapDescriptor.java +++ b/libs/commons/src/main/java/com/recom/commons/rasterizer/HeightMapDescriptor.java @@ -1,4 +1,4 @@ -package com.recom.rendertools.rasterizer; +package com.recom.commons.rasterizer; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/libs/rendertools/src/main/java/com/recom/rendertools/rasterizer/HeightmapRasterizer.java b/libs/commons/src/main/java/com/recom/commons/rasterizer/HeightmapRasterizer.java similarity index 74% rename from libs/rendertools/src/main/java/com/recom/rendertools/rasterizer/HeightmapRasterizer.java rename to libs/commons/src/main/java/com/recom/commons/rasterizer/HeightmapRasterizer.java index f163f59f..5de4d87e 100644 --- a/libs/rendertools/src/main/java/com/recom/rendertools/rasterizer/HeightmapRasterizer.java +++ b/libs/commons/src/main/java/com/recom/commons/rasterizer/HeightmapRasterizer.java @@ -1,4 +1,4 @@ -package com.recom.rendertools.rasterizer; +package com.recom.commons.rasterizer; import lombok.NonNull; @@ -9,23 +9,24 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; + public class HeightmapRasterizer { + @NonNull + private final HeightmapScaler heightmapScaler; + + public HeightmapRasterizer() { + heightmapScaler = new HeightmapScaler(); + } + @NonNull public ByteArrayOutputStream rasterizeHeightMapPNG(@NonNull final HeightMapDescriptor command) throws IOException { - @NonNull int[] pixelBuffer = rasterizeHeightMapRGB(command); + final int[] pixelBuffer = rasterizeHeightMapRGB(command); final int width = command.getHeightMap().length; final int height = command.getHeightMap()[0].length; final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); -// for (int x = 0; x < width; x++) { -// for (int z = 0; z < height; z++) { -// final int rgb = pixelBuffer[x + z * width]; // get the color from the int buffer array -// image.setRGB(x, z, rgb); -// } -// } - final int[] imagePixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); System.arraycopy(pixelBuffer, 0, imagePixels, 0, pixelBuffer.length); @@ -69,15 +70,25 @@ public int[] rasterizeHeightMapRGB(@NonNull final HeightMapDescriptor command) { return imageBuffer; } - public int[] rasterizeHeightMapARGB(@NonNull final HeightMapDescriptor command) { - final int[] rgbPixels = rasterizeHeightMapRGB(command); - - // add solid alpha channel xff000000 value to each pixel - for (int i = 0; i < rgbPixels.length; i++) { - rgbPixels[i] = 0xff000000 | rgbPixels[i]; - } + public int[] rasterizeHeightMapRGB( + @NonNull final HeightMapDescriptor heightMapDescriptor, + final int scale + ) { + final int[] originalHeightMap = rasterizeHeightMapRGB(heightMapDescriptor); - return rgbPixels; + return heightmapScaler.scaleMap(heightMapDescriptor, scale, originalHeightMap); } + +// public int[] rasterizeHeightMapARGB(@NonNull final HeightMapDescriptor command) { +// final int[] rgbPixels = rasterizeHeightMapRGB(command); +// +// // add solid alpha channel xff000000 value to each pixel +// for (int i = 0; i < rgbPixels.length; i++) { +// rgbPixels[i] = 0xff000000 | rgbPixels[i]; +// } +// +// return rgbPixels; +// } + } \ No newline at end of file diff --git a/libs/commons/src/main/java/com/recom/commons/rasterizer/HeightmapScaler.java b/libs/commons/src/main/java/com/recom/commons/rasterizer/HeightmapScaler.java new file mode 100644 index 00000000..ce3296d3 --- /dev/null +++ b/libs/commons/src/main/java/com/recom/commons/rasterizer/HeightmapScaler.java @@ -0,0 +1,71 @@ +package com.recom.commons.rasterizer; + +import com.recom.commons.calculator.ARGBCalculator; +import lombok.NonNull; + +public class HeightmapScaler { + + + public int[] scaleMap( + @NonNull final HeightMapDescriptor heightMapDescriptor, + final int scale, + final int[] originalHeightMap + ) { + final int originalHeight = heightMapDescriptor.getHeightMap().length; + final int originalWidth = heightMapDescriptor.getHeightMap()[0].length; + + if (Math.abs(scale) == 1 || scale == 0) { + return originalHeightMap; + } else if (scale > 1) { + final int scaledHeight = heightMapDescriptor.getHeightMap().length * scale; + final int scaledWidth = heightMapDescriptor.getHeightMap()[0].length * scale; + + final int[] scaledMap = new int[scaledHeight * scaledWidth]; + for (int x = 0; x < originalHeight; x++) { + for (int z = 0; z < originalWidth; z++) { + final int color = originalHeightMap[x + z * originalWidth]; + for (int scaledPixelX = 0; scaledPixelX < scale; scaledPixelX++) { + for (int scaledPixelZ = 0; scaledPixelZ < scale; scaledPixelZ++) { + scaledMap[(x * scale + scaledPixelX) + (z * scale + scaledPixelZ) * scaledWidth] = color; + } + } + } + } + + return scaledMap; + } else { + // Nearest Neighbour Downsampling: https://en.wikipedia.org/wiki/Image_scaling + final int absScale = Math.abs(scale); + final int scaledHeight = heightMapDescriptor.getHeightMap().length / absScale; + final int scaledWidth = heightMapDescriptor.getHeightMap()[0].length / absScale; + + final int[] scaledMap = new int[scaledHeight * scaledWidth]; + for (int x = 0; x < scaledHeight; x++) { + for (int z = 0; z < scaledWidth; z++) { + int alphaComponentSum = 0; + int redComponentSum = 0; + int greenComponentSum = 0; + int blueComponentSum = 0; + for (int scaledPixelX = 0; scaledPixelX < absScale; scaledPixelX++) { + for (int scaledPixelZ = 0; scaledPixelZ < absScale; scaledPixelZ++) { + alphaComponentSum += ARGBCalculator.getAlphaComponent(originalHeightMap[(x * absScale + scaledPixelX) + (z * absScale + scaledPixelZ) * originalWidth]); + redComponentSum += ARGBCalculator.getRedComponent(originalHeightMap[(x * absScale + scaledPixelX) + (z * absScale + scaledPixelZ) * originalWidth]); + greenComponentSum += ARGBCalculator.getGreenComponent(originalHeightMap[(x * absScale + scaledPixelX) + (z * absScale + scaledPixelZ) * originalWidth]); + blueComponentSum += ARGBCalculator.getBlueComponent(originalHeightMap[(x * absScale + scaledPixelX) + (z * absScale + scaledPixelZ) * originalWidth]); + } + } + final int scalePow = (int) Math.pow(absScale, 2); + alphaComponentSum /= scalePow; + redComponentSum /= scalePow; + greenComponentSum /= scalePow; + blueComponentSum /= scalePow; + + scaledMap[x + z * scaledWidth] = ARGBCalculator.compose(alphaComponentSum, redComponentSum, greenComponentSum, blueComponentSum); + } + } + + return scaledMap; + } + } + +} \ No newline at end of file diff --git a/libs/commons/src/main/java/com/recom/commons/units/PixelCoordinate.java b/libs/commons/src/main/java/com/recom/commons/units/PixelCoordinate.java new file mode 100644 index 00000000..df4e105f --- /dev/null +++ b/libs/commons/src/main/java/com/recom/commons/units/PixelCoordinate.java @@ -0,0 +1,33 @@ +package com.recom.commons.units; + +import com.recom.commons.units.calc.ScalingTool; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; + +@Data +@Builder +public class PixelCoordinate { + + private int x; + private int y; + + public static PixelCoordinate of( + final int x, + final int y + ) { + return new PixelCoordinate(x, y); + } + + public static PixelCoordinate of( + final double x, + final double y + ) { + return new PixelCoordinate((int) x, (int) y); + } + + @NonNull + public PixelCoordinate scaled(final int scaleFactor) { + return PixelCoordinate.of(ScalingTool.scaleDimension(getX(), scaleFactor), ScalingTool.scaleDimension(getY(), scaleFactor)); + } +} diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/PixelDimension.java b/libs/commons/src/main/java/com/recom/commons/units/PixelDimension.java similarity index 94% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/PixelDimension.java rename to libs/commons/src/main/java/com/recom/commons/units/PixelDimension.java index 43345b96..048b6bef 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/PixelDimension.java +++ b/libs/commons/src/main/java/com/recom/commons/units/PixelDimension.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.units; +package com.recom.commons.units; import lombok.Getter; import lombok.NonNull; @@ -12,10 +12,10 @@ public class PixelDimension { @NonNull private static final HashMap INSTANCE_LIST = new HashMap<>(); - private final int widthX; private final int heightY; + @NonNull public static PixelDimension of( final int widthX, diff --git a/libs/commons/src/main/java/com/recom/commons/units/ScaleFactor.java b/libs/commons/src/main/java/com/recom/commons/units/ScaleFactor.java new file mode 100644 index 00000000..1d599e8c --- /dev/null +++ b/libs/commons/src/main/java/com/recom/commons/units/ScaleFactor.java @@ -0,0 +1,61 @@ +package com.recom.commons.units; + +import lombok.Getter; + +/** + * The scale factor is NEVER 0 + * ... -3 -2 1 2 3 ... + */ +@Getter +public class ScaleFactor implements Cloneable { + + private int scaleFactor = 1; + + + public void zoomIn() { + switch (scaleFactor) { + case -2: + scaleFactor = 1; + break; + case -1, 1: + scaleFactor = 2; + break; + default: + scaleFactor++; + break; + } + } + + public void zoomOut() { + switch (scaleFactor) { + case 2: + scaleFactor = 1; + break; + case 1, -1: + scaleFactor = -2; + break; + default: + scaleFactor--; + break; + } + } + + public int getSign() { + if (scaleFactor > 0) { + return 1; + } else if (scaleFactor < 0) { + return -1; + } else { + return 0; + } + } + + @Override + public ScaleFactor clone() { + final ScaleFactor scaleFactorClone = new ScaleFactor(); + scaleFactorClone.scaleFactor = this.scaleFactor; + + return scaleFactorClone; + } + +} diff --git a/libs/commons/src/main/java/com/recom/commons/units/TimeUnits.java b/libs/commons/src/main/java/com/recom/commons/units/TimeUnits.java new file mode 100644 index 00000000..729a193f --- /dev/null +++ b/libs/commons/src/main/java/com/recom/commons/units/TimeUnits.java @@ -0,0 +1,14 @@ +package com.recom.commons.units; + +public class TimeUnits { + + public static final double ONE_MILLI_IN_NANOS_D = 1_000_000; + public static final long ONE_MILLI_IN_NANOS_L = 1_000_000; + + public static final long SECOND_IN_NANOS_L = 1_000_000_000; + public static final double SECOND_IN_NANOS_D = 1_000_000_000.0; + + public static final long SECOND_IN_MILLIS_L = 1000; + public static final double SECOND_IN_MILLIS_D = 1000.0; + +} diff --git a/libs/commons/src/main/java/com/recom/commons/units/calc/ScalingTool.java b/libs/commons/src/main/java/com/recom/commons/units/calc/ScalingTool.java new file mode 100644 index 00000000..8497ad5c --- /dev/null +++ b/libs/commons/src/main/java/com/recom/commons/units/calc/ScalingTool.java @@ -0,0 +1,49 @@ +package com.recom.commons.units.calc; + +public class ScalingTool { + + public static double scaleDimension( + final int originalDimension, + final int scaleFactor + ) { + if (scaleFactor > 0) { + return originalDimension * scaleFactor; + } else { + return originalDimension / (double) Math.abs(scaleFactor); + } + } + + public static double scaleDimension( + final double originalDimension, + final int scaleFactor + ) { + if (scaleFactor > 0) { + return originalDimension * scaleFactor; + } else { + return originalDimension / (double) Math.abs(scaleFactor); + } + } + + public static double normalizeDimension( + final int scaledDimension, + final int scaleFactor + ) { + if (scaleFactor > 0) { + return scaledDimension / (double) scaleFactor; + } else { + return scaledDimension * Math.abs(scaleFactor); + } + } + + public static double normalizeDimension( + final double scaledDimension, + final int scaleFactor + ) { + if (scaleFactor > 0) { + return scaledDimension / (double) scaleFactor; + } else { + return scaledDimension * Math.abs(scaleFactor); + } + } + +} \ No newline at end of file diff --git a/libs/rendertools/src/test/java/com/recom/rendertools/calculator/ARGBCalculaltorTest.java b/libs/commons/src/test/java/com/recom/commons/calculator/ARGBCalculatorTest.java similarity index 65% rename from libs/rendertools/src/test/java/com/recom/rendertools/calculator/ARGBCalculaltorTest.java rename to libs/commons/src/test/java/com/recom/commons/calculator/ARGBCalculatorTest.java index ef18f312..c2efd3fb 100644 --- a/libs/rendertools/src/test/java/com/recom/rendertools/calculator/ARGBCalculaltorTest.java +++ b/libs/commons/src/test/java/com/recom/commons/calculator/ARGBCalculatorTest.java @@ -1,27 +1,18 @@ -package com.recom.rendertools.calculator; +package com.recom.commons.calculator; -import com.recom.rendertools.calculator.ARGBCalculator; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -class ARGBCalculaltorTest { +class ARGBCalculatorTest { - // private ARGBCalculatorProvider provider; - private ARGBCalculator calculatorToTest; - - @BeforeEach - public void beforeEach() { - calculatorToTest = new ARGBCalculator(); - } @Test void getAlpha() { // PREPARE int argb = 0xffaaaaaa; // EXECUTE - int alphaComponent = calculatorToTest.getAlphaComponent(argb); + int alphaComponent = ARGBCalculator.getAlphaComponent(argb); // ASSERT assertEquals(0xff, alphaComponent); } @@ -31,7 +22,7 @@ void getAlpha1() { // PREPARE int argb = 0x00aaaaaa; // EXECUTE - int alphaComponent = calculatorToTest.getAlphaComponent(argb); + int alphaComponent = ARGBCalculator.getAlphaComponent(argb); // ASSERT assertEquals(0x00, alphaComponent); } @@ -41,7 +32,7 @@ void getAlpha2() { // PREPARE int argb = 0x99aaaaaa; // EXECUTE - int alphaComponent = calculatorToTest.getAlphaComponent(argb); + int alphaComponent = ARGBCalculator.getAlphaComponent(argb); // ASSERT assertEquals(0x99, alphaComponent); } @@ -51,7 +42,7 @@ void getRed() { // PREPARE int argb = 0xffaa9999; // EXECUTE - int alphaComponent = calculatorToTest.getRedComponent(argb); + int alphaComponent = ARGBCalculator.getRedComponent(argb); // ASSERT assertEquals(0xaa, alphaComponent); } @@ -61,7 +52,7 @@ void getRed1() { // PREPARE int argb = 0x00ffaaaa; // EXECUTE - int alphaComponent = calculatorToTest.getRedComponent(argb); + int alphaComponent = ARGBCalculator.getRedComponent(argb); // ASSERT assertEquals(0xff, alphaComponent); } @@ -71,7 +62,7 @@ void getGreen() { // PREPARE int argb = 0xff99aa99; // EXECUTE - int alphaComponent = calculatorToTest.getGreenComponent(argb); + int alphaComponent = ARGBCalculator.getGreenComponent(argb); // ASSERT assertEquals(0xaa, alphaComponent); } @@ -81,7 +72,7 @@ void getGreen1() { // PREPARE int argb = 0x00aaffaa; // EXECUTE - int alphaComponent = calculatorToTest.getGreenComponent(argb); + int alphaComponent = ARGBCalculator.getGreenComponent(argb); // ASSERT assertEquals(0xff, alphaComponent); } @@ -91,7 +82,7 @@ void getBlue() { // PREPARE int argb = 0xff9999aa; // EXECUTE - int alphaComponent = calculatorToTest.getBlueComponent(argb); + int alphaComponent = ARGBCalculator.getBlueComponent(argb); // ASSERT assertEquals(0xaa, alphaComponent); } @@ -101,7 +92,7 @@ void getBlue1() { // PREPARE int argb = 0x00aaaaff; // EXECUTE - int alphaComponent = calculatorToTest.getBlueComponent(argb); + int alphaComponent = ARGBCalculator.getBlueComponent(argb); // ASSERT assertEquals(0xff, alphaComponent); } @@ -112,7 +103,7 @@ void blendWhiteWithRed() { int solidWhite = 0xffffffff; int solidRed = 0xffff0000; // EXECUTE - int mixedColor1 = calculatorToTest.blend(solidWhite, solidRed); + int mixedColor1 = ARGBCalculator.blend(solidWhite, solidRed); // ASSERT assertEquals(0xffffffff, mixedColor1); } @@ -123,7 +114,7 @@ void blendSolids_WhiteWithBlack() { int solidWhiteForeground = 0xffffffff; int solidBlackBackground = 0xff000000; // EXECUTE - int mixedColor = calculatorToTest.blend(solidWhiteForeground, solidBlackBackground); + int mixedColor = ARGBCalculator.blend(solidWhiteForeground, solidBlackBackground); // ASSERT assertEquals(solidWhiteForeground, mixedColor); } @@ -134,7 +125,7 @@ void blendSolidWhiteWithAlphaRed() { int solidWhiteBackground = 0xffFFFFFF; int alphaRedForeground = 0x7dFF0000; // EXECUTE - int mixedColor1 = calculatorToTest.blend(alphaRedForeground, solidWhiteBackground); + int mixedColor1 = ARGBCalculator.blend(alphaRedForeground, solidWhiteBackground); // ASSERT assertEquals(0xffFF8282, mixedColor1); } diff --git a/libs/pom.xml b/libs/pom.xml index 55005395..ea09e52c 100644 --- a/libs/pom.xml +++ b/libs/pom.xml @@ -14,14 +14,14 @@ pom - sharedmodels + commons + dynamicproperties goapcom - observer - rendertools + javafxdependencies maze + observer + sharedmodels tacviewfx - javafxdependencies - dynamicproperties diff --git a/libs/tacviewfx/pom.xml b/libs/tacviewfx/pom.xml index a2da929d..c082b3be 100644 --- a/libs/tacviewfx/pom.xml +++ b/libs/tacviewfx/pom.xml @@ -24,7 +24,7 @@ com.recom - recom-rendertools + recom-commons 1.0.0-SNAPSHOT compile diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/TrigonometricCalculator.java b/libs/tacviewfx/src/main/java/com/recom/tacview/TrigonometricCalculator.java deleted file mode 100644 index b08aea3b..00000000 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/TrigonometricCalculator.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.recom.tacview; - -import javafx.scene.input.MouseEvent; -import lombok.NonNull; - -public class TrigonometricCalculator { - - public static double calculateRadiantBetweenMouseEvents( - @NonNull final MouseEvent dragSource, - @NonNull final MouseEvent event - ) { - return calculateRadiantBetweenPoints( - dragSource.getX(), - dragSource.getY(), - event.getX(), - event.getY() - ); - } - - public static double calculateRadiantBetweenPoints( - final double x, - final double y, - final double x1, - final double y1 - ) { - final double deltaX = x1 - x; - final double deltaY = y1 - y; - - return Math.atan2(deltaY, deltaX); - } - - public static double calculateDistanceBetweenMouseEvents( - @NonNull final MouseEvent dragSource, - @NonNull final MouseEvent event - ) { - return calculateDistanceBetweenPoints( - dragSource.getX(), - dragSource.getY(), - event.getX(), - event.getY() - ); - } - - public static double calculateDistanceBetweenPoints( - final double x1, - final double y1, - final double x2, - final double y2 - ) { - final double deltaX = x2 - x1; - final double deltaY = y2 - y1; - - return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); - } - -} diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/configuration/DefaultEngineModuleConfiguration.java b/libs/tacviewfx/src/main/java/com/recom/tacview/configuration/DefaultEngineModuleConfiguration.java index 4089f3ae..a68cd43c 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/configuration/DefaultEngineModuleConfiguration.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/configuration/DefaultEngineModuleConfiguration.java @@ -1,6 +1,6 @@ package com.recom.tacview.configuration; -import com.recom.tacview.engine.entitycomponentsystem.environment.Environment; +import com.recom.tacview.engine.ecs.environment.Environment; import com.recom.tacview.engine.module.DefaultEngineModule; import com.recom.tacview.engine.module.EngineModule; import com.recom.tacview.service.RandomProvider; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/configuration/DefaultEnvironmentConfiguration.java b/libs/tacviewfx/src/main/java/com/recom/tacview/configuration/DefaultEnvironmentConfiguration.java index a1d04231..7164d79e 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/configuration/DefaultEnvironmentConfiguration.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/configuration/DefaultEnvironmentConfiguration.java @@ -1,6 +1,6 @@ package com.recom.tacview.configuration; -import com.recom.tacview.engine.entitycomponentsystem.environment.Environment; +import com.recom.tacview.engine.ecs.environment.Environment; import com.recom.tacview.engine.module.DefaultEnvironment; import com.recom.tacview.engine.renderer.RenderProvider; import com.recom.tacview.property.RendererProperties; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/SwappableCanvasBuffer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/SwappableCanvasBuffer.java index d25e6c60..d4b74d3d 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/SwappableCanvasBuffer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/SwappableCanvasBuffer.java @@ -17,13 +17,10 @@ public class SwappableCanvasBuffer { private final Canvas canvas; @NonNull private final ScreenComposer screenComposer; - - private IntBuffer intBuffer = null; private PixelFormat pixelFormat = null; private PixelBuffer imagePixelBuffer = null; private WritableImage img = null; - public int currentShownBackBufferIndex = -1; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/TacViewer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/TacViewer.java index e6ce210c..b176eb28 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/TacViewer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/TacViewer.java @@ -7,6 +7,7 @@ import com.recom.tacview.engine.input.mapper.mousebutton.JavaFxMouseButtonCommandMapper; import com.recom.tacview.engine.input.mapper.scroll.JavaFxMouseScrollCommandMapper; import com.recom.tacview.engine.module.EngineModule; +import com.recom.commons.units.TimeUnits; import com.recom.tacview.property.RendererProperties; import com.recom.tacview.property.TickProperties; import com.recom.tacview.service.profiler.ProfilerProvider; @@ -17,9 +18,9 @@ import lombok.NonNull; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import org.springframework.lang.Nullable; import java.time.Duration; +import java.util.Optional; @Slf4j public class TacViewer extends Canvas { @@ -39,19 +40,16 @@ public class TacViewer extends Canvas { @NonNull private final InputManager inputManager; @NonNull - private final AnimationTimer animationTimerLoop; - @NonNull private final Thread.UncaughtExceptionHandler globalExceptionHandler; - - @NonNull private final SwappableCanvasBuffer canvasBuffer; @NonNull - private Thread engineLoopRunnerThread; - + private final AnimationTimer animationTimerLoop; + @NonNull + private final Thread engineLoopThread; @Setter - @Nullable - private ProfileFPSStrategy profileFPSStrategy; + @NonNull + private Optional maybeProfileFPSStrategy; public TacViewer( @@ -78,6 +76,7 @@ public TacViewer( this.profiler.startProfiling(); this.animationTimerLoop = provideAnimationTimer(); + this.engineLoopThread = provideEngineLoopThread(); this.setFocusTraversable(true); this.requestFocus(); @@ -99,8 +98,10 @@ public void handle(final long now) { }; } - private void runEngineLoop() { - engineLoopRunnerThread = new Thread(() -> { + + @NonNull + private Thread provideEngineLoopThread() { + final Thread thread = new Thread(() -> { Thread.currentThread().setUncaughtExceptionHandler(globalExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(globalExceptionHandler); @@ -109,21 +110,20 @@ private void runEngineLoop() { profiler.getLoopCounter().countLoop(); } }); + thread.setDaemon(false); - engineLoopRunnerThread.setDaemon(false); - engineLoopRunnerThread.start(); + return thread; } - public synchronized void start() { engineModule.run(); animationTimerLoop.start(); - runEngineLoop(); + engineLoopThread.start(); } public synchronized void stop() { animationTimerLoop.stop(); - engineLoopRunnerThread.interrupt(); + engineLoopThread.interrupt(); try { Thread.sleep(Duration.ofMillis(10)); } catch (final InterruptedException e) { @@ -135,7 +135,7 @@ private void engineLoop( @NonNull final TickProperties tickProperties, @NonNull final RendererProperties rendererProperties ) { - // HANDLE TIME + // HANDLE TIME CALCULATIONS final long currentNanoTimeOnLoopStart = System.nanoTime(); final long elapsedEngineNanoTime = (currentNanoTimeOnLoopStart - profiler.previousTickNanoTime); final long deltaTickNanoTime = currentNanoTimeOnLoopStart - profiler.previousTickNanoTime; @@ -163,17 +163,16 @@ private void engineLoop( } // HANDLE PROFILING - if (profileFPSStrategy != null && profiler.getLoopCounter().isOneSecondPassed()) { - profileFPSStrategy.execute(profiler.writeProfile()); + if (maybeProfileFPSStrategy.isPresent() && profiler.getLoopCounter().isOneSecondPassed()) { + maybeProfileFPSStrategy.get().execute(profiler.writeProfile()); } - - // sleep until next loop - final long loopDuration = System.nanoTime() - currentNanoTimeOnLoopStart; - final long nanosToSleep = targetNanosOfLoops - loopDuration; - if (nanosToSleep >= nanosToSleep/10) { + // SLEEP UNTIL NEXT LOOP + final long loopNanosUntilHere = System.nanoTime() - currentNanoTimeOnLoopStart; + final long nanosToSleep = targetNanosOfLoops - loopNanosUntilHere; + if (nanosToSleep >= 0) { try { - Thread.sleep(nanosToSleep / 1_000_000, (int) (nanosToSleep % 1_000_000)); + Thread.sleep(nanosToSleep / TimeUnits.ONE_MILLI_IN_NANOS_L, (int) (nanosToSleep % TimeUnits.ONE_MILLI_IN_NANOS_L)); } catch (final InterruptedException e) { log.warn("Interrupted engineLoop while sleeping"); } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/TacViewerProfiler.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/TacViewerProfiler.java index 0dcb7c7f..ad1a2907 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/TacViewerProfiler.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/TacViewerProfiler.java @@ -12,13 +12,10 @@ public class TacViewerProfiler { @NonNull private final LoopCounter loopCounter; - @NonNull private final FPSCounter fpsCounter; - @NonNull private final TPSCounter tpsCounter; - public long previousTickNanoTime = 0; public long previousFrameNanoTime = 0; public long inputHandlingNanoTime = 0; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/ChildPropagateableSoilableState.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/ChildPropagateableSoilableState.java similarity index 63% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/ChildPropagateableSoilableState.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/ChildPropagateableSoilableState.java index e058fe72..b6634e8c 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/ChildPropagateableSoilableState.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/ChildPropagateableSoilableState.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem; +package com.recom.tacview.engine.ecs; public interface ChildPropagateableSoilableState { diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/ParentPropagateableSoilableState.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/ParentPropagateableSoilableState.java similarity index 63% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/ParentPropagateableSoilableState.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/ParentPropagateableSoilableState.java index e3499413..c6207fe4 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/ParentPropagateableSoilableState.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/ParentPropagateableSoilableState.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem; +package com.recom.tacview.engine.ecs; public interface ParentPropagateableSoilableState { diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/BelongsToEntity.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/BelongsToEntity.java similarity index 61% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/BelongsToEntity.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/BelongsToEntity.java index 722c392a..2c82fa25 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/BelongsToEntity.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/BelongsToEntity.java @@ -1,6 +1,6 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; -import com.recom.tacview.engine.entitycomponentsystem.entity.IsEntity; +import com.recom.tacview.engine.ecs.entity.IsEntity; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/BelongsToMergeableComponentLayer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/BelongsToMergeableComponentLayer.java similarity index 84% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/BelongsToMergeableComponentLayer.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/BelongsToMergeableComponentLayer.java index a893dcd3..d5a9ddc8 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/BelongsToMergeableComponentLayer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/BelongsToMergeableComponentLayer.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; import com.recom.tacview.engine.renderables.mergeable.IsMergeableComponentLayer; import org.springframework.lang.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/ComponentTemplate.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/ComponentTemplate.java similarity index 79% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/ComponentTemplate.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/ComponentTemplate.java index 7487bd21..4ce908ec 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/ComponentTemplate.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/ComponentTemplate.java @@ -1,7 +1,7 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; -import com.recom.tacview.engine.entitycomponentsystem.entity.NullEntity; -import com.recom.tacview.engine.entitycomponentsystem.entity.IsEntity; +import com.recom.tacview.engine.ecs.entity.NullEntity; +import com.recom.tacview.engine.ecs.entity.IsEntity; import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -14,7 +14,6 @@ public abstract class ComponentTemplate implements IsComponent { @Setter @NonNull private IsEntity entity = NullEntity.INSTANCE; - @NonNull private final ComponentType componentType; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/ComponentType.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/ComponentType.java similarity index 71% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/ComponentType.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/ComponentType.java index dcf251b9..a8a1f804 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/ComponentType.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/ComponentType.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -6,7 +6,7 @@ @RequiredArgsConstructor public enum ComponentType { - InputComponent(0, com.recom.tacview.engine.entitycomponentsystem.component.InputComponent.class), + InputComponent(0, com.recom.tacview.engine.ecs.component.InputComponent.class), PhysicsCoreComponent(10000, PhysicCoreComponent.class), PhysicsComponent(20000, PhysicComponent.class), RenderableComponent(30000, RenderableComponent.class); diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/HandlesInputCommand.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/HandlesInputCommand.java similarity index 74% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/HandlesInputCommand.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/HandlesInputCommand.java index 3277ff7b..020681cc 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/HandlesInputCommand.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/HandlesInputCommand.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; import com.recom.tacview.engine.input.command.IsCommand; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/HasComponentType.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/HasComponentType.java similarity index 63% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/HasComponentType.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/HasComponentType.java index ffa1b6c9..0d2660af 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/HasComponentType.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/HasComponentType.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/InputComponent.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/InputComponent.java similarity index 84% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/InputComponent.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/InputComponent.java index 6ea26f90..a8baf209 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/InputComponent.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/InputComponent.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; import com.recom.tacview.engine.input.command.IsCommand; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/IsComponent.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/IsComponent.java similarity index 82% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/IsComponent.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/IsComponent.java index e57711bc..302c63ce 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/IsComponent.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/IsComponent.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; import com.recom.tacview.engine.IsUpdatable; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicComponent.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/PhysicComponent.java similarity index 93% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicComponent.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/PhysicComponent.java index 720354f5..14f59a14 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicComponent.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/PhysicComponent.java @@ -1,4 +1,6 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; + +import com.recom.commons.units.TimeUnits; public class PhysicComponent extends ComponentTemplate { @@ -32,7 +34,7 @@ public void update(final long elapsedNanoTime) { } private double elapsedSeconds(final long elapsedNanoTime) { - return elapsedNanoTime / 1_000_000_000.0; + return elapsedNanoTime / TimeUnits.SECOND_IN_NANOS_D; } private double applyRestoringForce( diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicCoreComponent.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/PhysicCoreComponent.java similarity index 91% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicCoreComponent.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/PhysicCoreComponent.java index 5c75a85b..a0b4ac74 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicCoreComponent.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/PhysicCoreComponent.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; import lombok.Getter; import lombok.Setter; @@ -8,15 +8,10 @@ public class PhysicCoreComponent extends ComponentTemplate { private double positionX = 0.0; - private double positionY = 0.0; - private double velocityXComponent = 0.0; - private double velocityYComponent = 0.0; - private double dragInNewton = 1.0; - private double frictionForce = 0; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/RenderableComponent.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/RenderableComponent.java similarity index 84% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/RenderableComponent.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/RenderableComponent.java index d4a690cb..ecf1d77a 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/RenderableComponent.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/component/RenderableComponent.java @@ -1,13 +1,13 @@ -package com.recom.tacview.engine.entitycomponentsystem.component; +package com.recom.tacview.engine.ecs.component; -import com.recom.tacview.engine.entitycomponentsystem.ChildPropagateableSoilableState; -import com.recom.tacview.engine.entitycomponentsystem.ParentPropagateableSoilableState; +import com.recom.tacview.engine.ecs.ChildPropagateableSoilableState; +import com.recom.tacview.engine.ecs.ParentPropagateableSoilableState; import com.recom.tacview.engine.graphics.buffer.NullPixelBuffer; import com.recom.tacview.engine.graphics.buffer.PixelBuffer; import com.recom.tacview.engine.renderables.HasPixelBuffer; import com.recom.tacview.engine.renderables.mergeable.IsMergeableComponentLayer; import com.recom.tacview.engine.renderables.mergeable.NullMergeableComponentLayer; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -17,7 +17,6 @@ public abstract class RenderableComponent extends ComponentTemplate implements HasPixelBuffer, BelongsToMergeableComponentLayer, ParentPropagateableSoilableState, ChildPropagateableSoilableState { private int zIndex = 0; - @NonNull protected PixelBuffer pixelBuffer; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/BelongsToEnvironment.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/BelongsToEnvironment.java similarity index 58% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/BelongsToEnvironment.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/BelongsToEnvironment.java index 375855fd..e7ddabed 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/BelongsToEnvironment.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/BelongsToEnvironment.java @@ -1,6 +1,6 @@ -package com.recom.tacview.engine.entitycomponentsystem.entity; +package com.recom.tacview.engine.ecs.entity; -import com.recom.tacview.engine.entitycomponentsystem.environment.IsEnvironment; +import com.recom.tacview.engine.ecs.environment.IsEnvironment; import org.springframework.lang.NonNull; public interface BelongsToEnvironment { diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/Entity.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/Entity.java similarity index 90% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/Entity.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/Entity.java index ad092314..3cc144cc 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/Entity.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/Entity.java @@ -1,9 +1,9 @@ -package com.recom.tacview.engine.entitycomponentsystem.entity; +package com.recom.tacview.engine.ecs.entity; import com.recom.tacview.engine.IsUpdatable; -import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType; -import com.recom.tacview.engine.entitycomponentsystem.component.IsComponent; -import com.recom.tacview.engine.entitycomponentsystem.environment.IsEnvironment; +import com.recom.tacview.engine.ecs.component.ComponentType; +import com.recom.tacview.engine.ecs.component.IsComponent; +import com.recom.tacview.engine.ecs.environment.IsEnvironment; import com.recom.tacview.engine.module.NullEnvironment; import lombok.Getter; import lombok.NonNull; @@ -16,12 +16,10 @@ public class Entity implements IsEntity { @NonNull private final List components = new ArrayList<>(); - @Getter @Setter @NonNull private IsEnvironment environment = NullEnvironment.INSTANCE; - @NonNull private Map, List> componentMap = new HashMap<>(); diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/HasComponents.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/HasComponents.java new file mode 100644 index 00000000..c7aef439 --- /dev/null +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/HasComponents.java @@ -0,0 +1,13 @@ +package com.recom.tacview.engine.ecs.entity; + +import com.recom.tacview.engine.ecs.component.IsComponent; +import lombok.NonNull; + +import java.util.List; + +public interface HasComponents { + + @NonNull + List getComponents(); + +} diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/HasLocatableComponents.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/HasLocatableComponents.java similarity index 73% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/HasLocatableComponents.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/HasLocatableComponents.java index c560c572..38d254cf 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/HasLocatableComponents.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/HasLocatableComponents.java @@ -1,7 +1,7 @@ -package com.recom.tacview.engine.entitycomponentsystem.entity; +package com.recom.tacview.engine.ecs.entity; -import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType; -import com.recom.tacview.engine.entitycomponentsystem.component.IsComponent; +import com.recom.tacview.engine.ecs.component.ComponentType; +import com.recom.tacview.engine.ecs.component.IsComponent; import lombok.NonNull; import java.util.List; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/IsEntity.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/IsEntity.java similarity index 69% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/IsEntity.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/IsEntity.java index 1082a06a..9092827f 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/IsEntity.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/IsEntity.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.entity; +package com.recom.tacview.engine.ecs.entity; import com.recom.tacview.engine.IsUpdatable; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/NullEntity.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/NullEntity.java similarity index 85% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/NullEntity.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/NullEntity.java index a1deb5ae..ec720f1f 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/NullEntity.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/entity/NullEntity.java @@ -1,7 +1,7 @@ -package com.recom.tacview.engine.entitycomponentsystem.entity; +package com.recom.tacview.engine.ecs.entity; -import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType; -import com.recom.tacview.engine.entitycomponentsystem.component.IsComponent; +import com.recom.tacview.engine.ecs.component.ComponentType; +import com.recom.tacview.engine.ecs.component.IsComponent; import lombok.NonNull; import java.util.Collections; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/Environment.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/Environment.java similarity index 91% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/Environment.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/Environment.java index 9ec0baac..075d73a2 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/Environment.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/Environment.java @@ -1,7 +1,7 @@ -package com.recom.tacview.engine.entitycomponentsystem.environment; +package com.recom.tacview.engine.ecs.environment; -import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType; -import com.recom.tacview.engine.entitycomponentsystem.entity.Entity; +import com.recom.tacview.engine.ecs.component.ComponentType; +import com.recom.tacview.engine.ecs.entity.Entity; import com.recom.tacview.engine.graphics.renderpipeline.IsRenderPipeline; import com.recom.tacview.engine.graphics.renderpipeline.RenderPipeline; import com.recom.tacview.engine.renderer.RenderProvider; @@ -30,8 +30,6 @@ public abstract class Environment implements IsEnvironment { @Getter @NonNull private final IsRenderPipeline renderPipeline = new RenderPipeline(this); - - @NonNull private final List entities = new ArrayList<>(); diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/HasEntities.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/HasEntities.java new file mode 100644 index 00000000..f3c0169a --- /dev/null +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/HasEntities.java @@ -0,0 +1,13 @@ +package com.recom.tacview.engine.ecs.environment; + +import com.recom.tacview.engine.ecs.entity.Entity; +import lombok.NonNull; + +import java.util.List; + +public interface HasEntities { + + @NonNull + List getEntities(); + +} diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/HasManagableEntities.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/HasManagableEntities.java similarity index 64% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/HasManagableEntities.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/HasManagableEntities.java index f9e6c13c..d7852895 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/HasManagableEntities.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/HasManagableEntities.java @@ -1,6 +1,6 @@ -package com.recom.tacview.engine.entitycomponentsystem.environment; +package com.recom.tacview.engine.ecs.environment; -import com.recom.tacview.engine.entitycomponentsystem.entity.Entity; +import com.recom.tacview.engine.ecs.entity.Entity; import lombok.NonNull; import java.util.List; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/IsEnvironment.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/IsEnvironment.java similarity index 90% rename from libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/IsEnvironment.java rename to libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/IsEnvironment.java index 15d04eb5..6a33769c 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/IsEnvironment.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/ecs/environment/IsEnvironment.java @@ -1,4 +1,4 @@ -package com.recom.tacview.engine.entitycomponentsystem.environment; +package com.recom.tacview.engine.ecs.environment; import com.recom.tacview.engine.IsUpdatable; import com.recom.tacview.engine.graphics.renderpipeline.IsRenderPipeline; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/HasComponents.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/HasComponents.java deleted file mode 100644 index fd51cfb4..00000000 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/entity/HasComponents.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.recom.tacview.engine.entitycomponentsystem.entity; - -import com.recom.tacview.engine.entitycomponentsystem.component.IsComponent; -import lombok.NonNull; - -import java.util.List; - -public interface HasComponents { - - @NonNull List getComponents(); - -} diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/HasEntities.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/HasEntities.java deleted file mode 100644 index 3d8a6f37..00000000 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/environment/HasEntities.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.recom.tacview.engine.entitycomponentsystem.environment; - -import com.recom.tacview.engine.entitycomponentsystem.entity.Entity; -import lombok.NonNull; - -import java.util.List; - -public interface HasEntities { - - @NonNull List getEntities(); - -} diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsBufferable.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsBufferable.java index 0d2554a9..cfeb99e6 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsBufferable.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsBufferable.java @@ -1,10 +1,12 @@ package com.recom.tacview.engine.graphics; import com.recom.tacview.engine.renderables.IsSoilable; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; +import lombok.NonNull; public interface IsBufferable extends IsScanable, IsSoilable { + @NonNull PixelDimension getDimension(); void bufferPixelAt( diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsComposable.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsComposable.java index 70a61df3..33c4605c 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsComposable.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsComposable.java @@ -1,6 +1,6 @@ package com.recom.tacview.engine.graphics; -import com.recom.tacview.engine.entitycomponentsystem.environment.Environment; +import com.recom.tacview.engine.ecs.environment.Environment; import com.recom.tacview.engine.renderables.HasPixelBuffer; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsScanable.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsScanable.java index e66a1684..ff715844 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsScanable.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/IsScanable.java @@ -1,10 +1,12 @@ package com.recom.tacview.engine.graphics; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; +import lombok.NonNull; public interface IsScanable { + @NonNull PixelDimension getDimension(); int scanPixelAt( diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/ScreenComposer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/ScreenComposer.java index 1eeb49d1..369b81dd 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/ScreenComposer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/ScreenComposer.java @@ -1,6 +1,6 @@ package com.recom.tacview.engine.graphics; -import com.recom.tacview.engine.entitycomponentsystem.environment.Environment; +import com.recom.tacview.engine.ecs.environment.Environment; import com.recom.tacview.engine.graphics.buffer.PixelBuffer; import com.recom.tacview.engine.graphics.buffer.PixelRingBuffer; import com.recom.tacview.engine.graphics.renderpipeline.IsRenderPipeline; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/NullPixelBuffer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/NullPixelBuffer.java index 99a74528..ea36e7e1 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/NullPixelBuffer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/NullPixelBuffer.java @@ -1,9 +1,11 @@ package com.recom.tacview.engine.graphics.buffer; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; +import lombok.NonNull; public class NullPixelBuffer extends PixelBuffer { + @NonNull public static PixelBuffer INSTANCE = new NullPixelBuffer(); private NullPixelBuffer() { diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/PixelBuffer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/PixelBuffer.java index 31c7291a..8f66930f 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/PixelBuffer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/PixelBuffer.java @@ -1,7 +1,7 @@ package com.recom.tacview.engine.graphics.buffer; import com.recom.tacview.engine.graphics.IsBufferable; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -12,13 +12,12 @@ public class PixelBuffer implements IsBufferable { @Getter protected PixelDimension dimension; - @Getter @Setter private boolean dirty = false; - protected int[] pixelBuffer; + public PixelBuffer(@NonNull final PixelDimension dimension) { this.dimension = dimension; pixelBuffer = new int[dimension.getWidthX() * dimension.getHeightY()]; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/PixelRingBuffer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/PixelRingBuffer.java index c6cbf7a0..b6968672 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/PixelRingBuffer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/buffer/PixelRingBuffer.java @@ -1,7 +1,7 @@ package com.recom.tacview.engine.graphics.buffer; import com.recom.tacview.engine.renderables.HasPixelBuffer; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import lombok.Getter; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/IsRenderPipeline.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/IsRenderPipeline.java index f827d431..25fd6a24 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/IsRenderPipeline.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/IsRenderPipeline.java @@ -1,7 +1,7 @@ package com.recom.tacview.engine.graphics.renderpipeline; -import com.recom.tacview.engine.entitycomponentsystem.ChildPropagateableSoilableState; -import com.recom.tacview.engine.entitycomponentsystem.ParentPropagateableSoilableState; +import com.recom.tacview.engine.ecs.ChildPropagateableSoilableState; +import com.recom.tacview.engine.ecs.ParentPropagateableSoilableState; import com.recom.tacview.engine.renderables.mergeable.MergeableComponentLayer; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/NullRenderPipeline.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/NullRenderPipeline.java index 235799ea..7fb5354f 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/NullRenderPipeline.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/NullRenderPipeline.java @@ -1,6 +1,6 @@ package com.recom.tacview.engine.graphics.renderpipeline; -import com.recom.tacview.engine.entitycomponentsystem.component.RenderableComponent; +import com.recom.tacview.engine.ecs.component.RenderableComponent; import com.recom.tacview.engine.renderables.mergeable.MergeableComponentLayer; import lombok.Getter; import lombok.NonNull; @@ -13,8 +13,10 @@ public class NullRenderPipeline implements IsRenderPipeline { + @NonNull public static final NullRenderPipeline INSTANCE = new NullRenderPipeline(); + private NullRenderPipeline() { } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/RenderPipeline.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/RenderPipeline.java index 01a8230b..926348c6 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/RenderPipeline.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/renderpipeline/RenderPipeline.java @@ -1,8 +1,8 @@ package com.recom.tacview.engine.graphics.renderpipeline; -import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType; -import com.recom.tacview.engine.entitycomponentsystem.component.RenderableComponent; -import com.recom.tacview.engine.entitycomponentsystem.environment.IsEnvironment; +import com.recom.tacview.engine.ecs.component.ComponentType; +import com.recom.tacview.engine.ecs.component.RenderableComponent; +import com.recom.tacview.engine.ecs.environment.IsEnvironment; import com.recom.tacview.engine.renderables.mergeable.MergeableComponentLayer; import lombok.Getter; import lombok.NonNull; @@ -20,14 +20,11 @@ public class RenderPipeline implements IsRenderPipeline { @NonNull private final IsEnvironment environment; - @NonNull - final Map> renderableComponentList = new HashMap<>(); - + private final Map> renderableComponentList = new HashMap<>(); @Getter @NonNull private final List layers = new ArrayList<>(); - @Getter @Setter private boolean dirty = true; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/scanable/ScanableNoise.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/scanable/ScanableNoise.java index 96e22b23..27fd8f8e 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/scanable/ScanableNoise.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/graphics/scanable/ScanableNoise.java @@ -1,7 +1,7 @@ package com.recom.tacview.engine.graphics.scanable; import com.recom.tacview.engine.graphics.IsScanable; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import com.recom.tacview.service.RandomProvider; import lombok.Getter; import lombok.NonNull; @@ -16,6 +16,7 @@ public class ScanableNoise implements IsScanable { @NonNull private final PixelDimension dimension; + @Override public int scanPixelAt( final int x, diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/InputManager.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/InputManager.java index d3f5ffa9..53ac8c54 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/InputManager.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/InputManager.java @@ -23,10 +23,8 @@ public class InputManager { private final BlockingQueue> inputEventQueue = new LinkedBlockingQueue<>(); @NonNull final LinkedList> drainedInputEventQueue = new LinkedList<>(); - @NonNull private final LinkedList> registeredCommandsMappers = new LinkedList<>(); - @NonNull private final LinkedList> createdInputCommands = new LinkedList<>(); diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/command/mousebutton/MouseButtonCommand.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/command/mousebutton/MouseButtonCommand.java index 81cd3704..4fec5faa 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/command/mousebutton/MouseButtonCommand.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/command/mousebutton/MouseButtonCommand.java @@ -10,7 +10,6 @@ public class MouseButtonCommand implements IsMouseCommand { private final long timeBetweenDragStartAndDragStop; private final boolean probableDraggingIntention; - @NonNull private final NanoTimedEvent nanoTimedEvent; private final boolean doubleClick; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/command/mousebutton/MouseDragCommand.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/command/mousebutton/MouseDragCommand.java index 06529aeb..99993596 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/command/mousebutton/MouseDragCommand.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/command/mousebutton/MouseDragCommand.java @@ -1,6 +1,6 @@ package com.recom.tacview.engine.input.command.mousebutton; -import com.recom.tacview.TrigonometricCalculator; +import com.recom.tacview.util.MouseCalculator; import com.recom.tacview.engine.input.NanoTimedEvent; import javafx.scene.input.MouseEvent; import lombok.Getter; @@ -96,7 +96,7 @@ public boolean isInOriginPosition() { } public double getDistance() { - return TrigonometricCalculator.calculateDistanceBetweenMouseEvents(sourceNanoTimedEvent.getEvent(), nanoTimedEvent.getEvent()); + return MouseCalculator.calculateDistanceBetweenMouseEvents(sourceNanoTimedEvent.getEvent(), nanoTimedEvent.getEvent()); } public double getDistanceX() { @@ -108,7 +108,7 @@ public double getDistanceY() { } public double getRadiant() { - return TrigonometricCalculator.calculateRadiantBetweenMouseEvents(sourceNanoTimedEvent.getEvent(), nanoTimedEvent.getEvent()); + return MouseCalculator.calculateRadiantBetweenMouseEvents(sourceNanoTimedEvent.getEvent(), nanoTimedEvent.getEvent()); } } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/keyboard/KeyboardCommandGenerator.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/keyboard/KeyboardCommandGenerator.java index 1646cc52..ca17c2cd 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/keyboard/KeyboardCommandGenerator.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/keyboard/KeyboardCommandGenerator.java @@ -21,13 +21,12 @@ public class KeyboardCommandGenerator { @NonNull private final HashMap> pressedKeyEventsBuffer = new HashMap<>(); - @NonNull private final LinkedList bufferedCommands = new LinkedList<>(); - @NonNull private final HashSet ignoredKeyCodes = new HashSet<>(); + public KeyboardCommandGenerator() { ignoredKeyCodes.add(KeyCode.WINDOWS); } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/fsm/MouseButtonEventFSM1.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/fsm/MouseButtonEventFSM1.java index 14cafb1a..49b61b76 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/fsm/MouseButtonEventFSM1.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/fsm/MouseButtonEventFSM1.java @@ -17,21 +17,14 @@ @Slf4j public class MouseButtonEventFSM1 implements IsMouseButtonEventFSM { - @NonNull private final long doubleClickThresholdNanos; - - @NonNull private final long dragThresholdNanos; - @NonNull private final MouseButton responsibleForMouseButton; - @NonNull private FSMStates1 currentMachineState = FSMStates1.NEW; - @NonNull private final MouseEventBuffer mouseEventBuffer = new MouseEventBuffer(); - @NonNull private final LinkedList> bufferedCommands = new LinkedList<>(); diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/fsm/MouseButtonEventFSM2.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/fsm/MouseButtonEventFSM2.java index d61ab331..69a6ac5a 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/fsm/MouseButtonEventFSM2.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/fsm/MouseButtonEventFSM2.java @@ -17,9 +17,7 @@ @Slf4j public class MouseButtonEventFSM2 implements IsMouseButtonEventFSM { - @NonNull private final long doubleClickThresholdNanos; - @NonNull private final long dragToClickThresholdNanos; @NonNull private final MouseButton responsibleForMouseButton; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/scroll/JavaFxMouseScrollCommandMapper.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/scroll/JavaFxMouseScrollCommandMapper.java index 0f276844..55d4e596 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/scroll/JavaFxMouseScrollCommandMapper.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/scroll/JavaFxMouseScrollCommandMapper.java @@ -18,7 +18,6 @@ public class JavaFxMouseScrollCommandMapper implements IsInputCommandMapper> unprocessedScrollEvents = new LinkedBlockingQueue<>(); - @NonNull private final LinkedList mappedCommands = new LinkedList<>(); diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/DefaultEngineModule.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/DefaultEngineModule.java index d9d09970..06edd46e 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/DefaultEngineModule.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/DefaultEngineModule.java @@ -1,11 +1,11 @@ package com.recom.tacview.engine.module; -import com.recom.tacview.engine.entitycomponentsystem.component.RenderableComponent; -import com.recom.tacview.engine.entitycomponentsystem.entity.Entity; -import com.recom.tacview.engine.entitycomponentsystem.environment.Environment; +import com.recom.tacview.engine.ecs.component.RenderableComponent; +import com.recom.tacview.engine.ecs.entity.Entity; +import com.recom.tacview.engine.ecs.environment.Environment; import com.recom.tacview.engine.renderables.mergeable.ScanableNoiseMergeable; import com.recom.tacview.engine.renderer.RenderProvider; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import com.recom.tacview.service.RandomProvider; import lombok.NonNull; import lombok.RequiredArgsConstructor; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/DefaultEnvironment.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/DefaultEnvironment.java index c2564cdb..eb22f5ed 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/DefaultEnvironment.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/DefaultEnvironment.java @@ -1,6 +1,6 @@ package com.recom.tacview.engine.module; -import com.recom.tacview.engine.entitycomponentsystem.environment.Environment; +import com.recom.tacview.engine.ecs.environment.Environment; import com.recom.tacview.engine.renderer.RenderProvider; import com.recom.tacview.property.RendererProperties; import com.recom.tacview.service.RendererExecutorProvider; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/EngineModule.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/EngineModule.java index 582d2681..3b32fa61 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/EngineModule.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/EngineModule.java @@ -1,9 +1,9 @@ package com.recom.tacview.engine.module; import com.recom.tacview.engine.IsUpdatable; -import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType; -import com.recom.tacview.engine.entitycomponentsystem.component.InputComponent; -import com.recom.tacview.engine.entitycomponentsystem.environment.Environment; +import com.recom.tacview.engine.ecs.component.ComponentType; +import com.recom.tacview.engine.ecs.component.InputComponent; +import com.recom.tacview.engine.ecs.environment.Environment; import com.recom.tacview.engine.input.command.IsCommand; import lombok.Getter; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/NullEnvironment.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/NullEnvironment.java index 06e7fd52..039ceb6a 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/NullEnvironment.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/module/NullEnvironment.java @@ -1,7 +1,7 @@ package com.recom.tacview.engine.module; -import com.recom.tacview.engine.entitycomponentsystem.entity.Entity; -import com.recom.tacview.engine.entitycomponentsystem.environment.IsEnvironment; +import com.recom.tacview.engine.ecs.entity.Entity; +import com.recom.tacview.engine.ecs.environment.IsEnvironment; import com.recom.tacview.engine.graphics.renderpipeline.IsRenderPipeline; import com.recom.tacview.engine.graphics.renderpipeline.NullRenderPipeline; import com.recom.tacview.engine.renderer.RenderProvider; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/IsPositionable.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/IsPositionable.java index e0d9ead9..25625aba 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/IsPositionable.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/IsPositionable.java @@ -1,9 +1,11 @@ package com.recom.tacview.engine.renderables; -import com.recom.tacview.engine.units.PixelCoordinate; +import com.recom.commons.units.PixelCoordinate; +import lombok.NonNull; public interface IsPositionable { + @NonNull PixelCoordinate getPosition(); } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/BufferedMergeableTemplate.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/BufferedMergeableTemplate.java index 52f7bead..b4e7f8ad 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/BufferedMergeableTemplate.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/BufferedMergeableTemplate.java @@ -5,7 +5,7 @@ import com.recom.tacview.engine.renderables.HasPixelBuffer; import com.recom.tacview.engine.renderables.IsMergeable; import com.recom.tacview.engine.renderer.RenderProvider; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import lombok.Getter; import lombok.NonNull; @@ -15,10 +15,10 @@ public abstract class BufferedMergeableTemplate implements IsMergeable, HasPixel @Getter @NonNull private final PixelBuffer pixelBuffer; - @NonNull private final RenderProvider renderProvider; + public BufferedMergeableTemplate( @NonNull final PixelDimension dimension, @NonNull final RenderProvider renderProvider diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/IsMergeableComponentLayer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/IsMergeableComponentLayer.java index ab566fbc..ed8bb070 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/IsMergeableComponentLayer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/IsMergeableComponentLayer.java @@ -1,7 +1,7 @@ package com.recom.tacview.engine.renderables.mergeable; -import com.recom.tacview.engine.entitycomponentsystem.ChildPropagateableSoilableState; -import com.recom.tacview.engine.entitycomponentsystem.ParentPropagateableSoilableState; +import com.recom.tacview.engine.ecs.ChildPropagateableSoilableState; +import com.recom.tacview.engine.ecs.ParentPropagateableSoilableState; import com.recom.tacview.engine.renderables.HasPixelBuffer; import com.recom.tacview.engine.renderables.IsMergeable; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/MergeableComponentLayer.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/MergeableComponentLayer.java index cf41a972..df991397 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/MergeableComponentLayer.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/MergeableComponentLayer.java @@ -1,9 +1,9 @@ package com.recom.tacview.engine.renderables.mergeable; -import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType; -import com.recom.tacview.engine.entitycomponentsystem.component.PhysicCoreComponent; -import com.recom.tacview.engine.entitycomponentsystem.component.RenderableComponent; -import com.recom.tacview.engine.entitycomponentsystem.environment.IsEnvironment; +import com.recom.tacview.engine.ecs.component.ComponentType; +import com.recom.tacview.engine.ecs.component.PhysicCoreComponent; +import com.recom.tacview.engine.ecs.component.RenderableComponent; +import com.recom.tacview.engine.ecs.environment.IsEnvironment; import lombok.Getter; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/ScanableMergeableTemplate.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/ScanableMergeableTemplate.java index ec6a36be..a783ca7e 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/ScanableMergeableTemplate.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/ScanableMergeableTemplate.java @@ -2,7 +2,7 @@ import com.recom.tacview.engine.graphics.IsScanable; import com.recom.tacview.engine.renderables.IsMergeable; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/ScanableNoiseMergeable.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/ScanableNoiseMergeable.java index 9694a620..68402490 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/ScanableNoiseMergeable.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/ScanableNoiseMergeable.java @@ -4,7 +4,7 @@ import com.recom.tacview.engine.graphics.buffer.PixelBuffer; import com.recom.tacview.engine.graphics.scanable.ScanableNoise; import com.recom.tacview.engine.renderer.RenderProvider; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import com.recom.tacview.service.RandomProvider; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/SolidColorMergeable.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/SolidColorMergeable.java index 9fb1adea..052eede5 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/SolidColorMergeable.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/mergeable/SolidColorMergeable.java @@ -1,6 +1,5 @@ package com.recom.tacview.engine.renderables.mergeable; -import com.recom.tacview.engine.renderables.mergeable.BufferedMergeableTemplate; import com.recom.tacview.engine.renderer.RenderProvider; import com.recom.tacview.property.RendererProperties; import lombok.NonNull; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/sprite/Sprite.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/sprite/Sprite.java index 4f7b5b7d..3f7cbc0a 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/sprite/Sprite.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/sprite/Sprite.java @@ -2,7 +2,7 @@ import com.recom.tacview.engine.renderables.HasPixelBuffer; import com.recom.tacview.engine.graphics.buffer.PixelBuffer; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import lombok.Getter; import lombok.NonNull; @@ -12,6 +12,7 @@ public class Sprite implements HasPixelBuffer { @NonNull private final PixelBuffer pixelBuffer; + public Sprite(@NonNull final PixelDimension dimension) { pixelBuffer = new PixelBuffer(dimension); } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/sprite/SpriteAtlas.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/sprite/SpriteAtlas.java index 30bca1f1..dab19e5c 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/sprite/SpriteAtlas.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/sprite/SpriteAtlas.java @@ -2,7 +2,7 @@ import com.recom.tacview.engine.graphics.buffer.PixelBuffer; import com.recom.tacview.engine.renderables.HasPixelBuffer; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import lombok.Getter; import lombok.NonNull; @@ -16,6 +16,7 @@ public class SpriteAtlas implements HasPixelBuffer { @NonNull private final PixelBuffer pixelBuffer; + public SpriteAtlas(@NonNull final String path) throws IOException { final BufferedImage image = ImageIO.read(SpriteAtlas.class.getResource(path)); final PixelDimension dimension = PixelDimension.of(image.getWidth(), image.getHeight()); diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/tile/IsTile.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/tile/IsTile.java index ecd7acaf..dc839aac 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/tile/IsTile.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderables/tile/IsTile.java @@ -4,7 +4,7 @@ import com.recom.tacview.engine.renderables.HasPixelBuffer; import com.recom.tacview.engine.renderables.IsPositionable; import com.recom.tacview.engine.renderables.sprite.Sprite; -import com.recom.tacview.engine.units.PixelCoordinate; +import com.recom.commons.units.PixelCoordinate; import lombok.NonNull; public interface IsTile extends HasPixelBuffer, IsPositionable { diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderer/RenderProvider.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderer/RenderProvider.java index e6853f36..e4c6b647 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderer/RenderProvider.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderer/RenderProvider.java @@ -22,6 +22,7 @@ public final class RenderProvider { @Nullable private IsRenderable instance; + public IsRenderable provide() { if (instance == null) { if (rendererProperties.isParallelizedRendering()) { diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderer/RendererTemplate.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderer/RendererTemplate.java index eaf8c4bb..28e575f6 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderer/RendererTemplate.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/renderer/RendererTemplate.java @@ -15,6 +15,7 @@ abstract class RendererTemplate implements IsRenderable { @NonNull protected final ARGBCalculatorProvider argbCalculatorProvider; + public RendererTemplate(@NonNull final ARGBCalculatorProvider argbCalculatorProvider) { this.argbCalculatorProvider = argbCalculatorProvider; } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/PixelCoordinate.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/PixelCoordinate.java deleted file mode 100644 index 757c01b9..00000000 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/PixelCoordinate.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.recom.tacview.engine.units; - -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class PixelCoordinate { - - private int withX; - private int heightY; - -} diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/TimeUnits.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/TimeUnits.java deleted file mode 100644 index 6e71bfe4..00000000 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/units/TimeUnits.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.recom.tacview.engine.units; - -public class TimeUnits { - - public static double SECOND_IN_NANOS = 1000000000.0; - public static double SECOND_IN_MILLIS = 1000.0; - -} diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/property/RendererProperties.java b/libs/tacviewfx/src/main/java/com/recom/tacview/property/RendererProperties.java index f01b0934..2905496b 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/property/RendererProperties.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/property/RendererProperties.java @@ -1,6 +1,6 @@ package com.recom.tacview.property; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import lombok.*; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/property/TickProperties.java b/libs/tacviewfx/src/main/java/com/recom/tacview/property/TickProperties.java index 9940e9a6..a2819e14 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/property/TickProperties.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/property/TickProperties.java @@ -16,7 +16,6 @@ public class TickProperties { private int targetTps; - private long tickThresholdNanoTime = 0; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/service/RandomProvider.java b/libs/tacviewfx/src/main/java/com/recom/tacview/service/RandomProvider.java index e5e9a277..1b02d237 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/service/RandomProvider.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/service/RandomProvider.java @@ -14,6 +14,7 @@ public final class RandomProvider { private int poolSize = 10; private int currentInstance = 0; + @PostConstruct public void postConstruct() { instancePool = new Random[poolSize]; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/service/argb/ARGBCalculatorProvider.java b/libs/tacviewfx/src/main/java/com/recom/tacview/service/argb/ARGBCalculatorProvider.java index adee1b7e..56c0c2bd 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/service/argb/ARGBCalculatorProvider.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/service/argb/ARGBCalculatorProvider.java @@ -1,6 +1,6 @@ package com.recom.tacview.service.argb; -import com.recom.rendertools.calculator.ARGBCalculator; +import com.recom.commons.calculator.ARGBCalculator; import org.springframework.lang.Nullable; import org.springframework.stereotype.Service; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/service/profiler/LoopCounter.java b/libs/tacviewfx/src/main/java/com/recom/tacview/service/profiler/LoopCounter.java index e40aa1a2..b437aee5 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/service/profiler/LoopCounter.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/service/profiler/LoopCounter.java @@ -1,7 +1,7 @@ package com.recom.tacview.service.profiler; -import com.recom.tacview.engine.units.TimeUnits; +import com.recom.commons.units.TimeUnits; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -22,7 +22,7 @@ public void countLoop() { public boolean isOneSecondPassed() { final long now = System.currentTimeMillis(); - final boolean isOneSecondPassed = now - lastProfileIterationInMillis > TimeUnits.SECOND_IN_MILLIS; + final boolean isOneSecondPassed = now - lastProfileIterationInMillis > TimeUnits.SECOND_IN_MILLIS_D; if (isOneSecondPassed) { lastProfileIterationInMillis = now; } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/service/profiler/Profiler.java b/libs/tacviewfx/src/main/java/com/recom/tacview/service/profiler/Profiler.java index 0d2772de..7936c441 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/service/profiler/Profiler.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/service/profiler/Profiler.java @@ -10,7 +10,6 @@ public class Profiler { @NonNull private final String profilerName; private long nanoTimeStart; - @Getter private long profiledNanos = 0; diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/strategy/ProfileFPSStrategy.java b/libs/tacviewfx/src/main/java/com/recom/tacview/strategy/ProfileFPSStrategy.java index 93fa0073..10ff4f6b 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/strategy/ProfileFPSStrategy.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/strategy/ProfileFPSStrategy.java @@ -11,6 +11,7 @@ public class ProfileFPSStrategy { @NonNull private final IsFPSProfilable runnable; + public void execute(@NonNull final String profiled) { runnable.setFPS(profiled); } diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/util/MouseCalculator.java b/libs/tacviewfx/src/main/java/com/recom/tacview/util/MouseCalculator.java new file mode 100644 index 00000000..6371ed61 --- /dev/null +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/util/MouseCalculator.java @@ -0,0 +1,34 @@ +package com.recom.tacview.util; + +import javafx.scene.input.MouseEvent; +import lombok.NonNull; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class MouseCalculator { + + public static double calculateRadiantBetweenMouseEvents( + @NonNull final MouseEvent dragSource, + @NonNull final MouseEvent event + ) { + return com.recom.commons.calculator.TrigonometricCalculator.calculateRadiantBetweenPoints( + dragSource.getX(), + dragSource.getY(), + event.getX(), + event.getY() + ); + } + + public static double calculateDistanceBetweenMouseEvents( + @NonNull final MouseEvent dragSource, + @NonNull final MouseEvent event + ) { + return com.recom.commons.calculator.TrigonometricCalculator.calculateDistanceBetweenPoints( + dragSource.getX(), + dragSource.getY(), + event.getX(), + event.getY() + ); + } + +} diff --git a/libs/tacviewfx/src/test/java/com/recom/tacview/engine/graphics/buffer/PixelBufferTest.java b/libs/tacviewfx/src/test/java/com/recom/tacview/engine/graphics/buffer/PixelBufferTest.java index 8c938fe4..bb821ab0 100644 --- a/libs/tacviewfx/src/test/java/com/recom/tacview/engine/graphics/buffer/PixelBufferTest.java +++ b/libs/tacviewfx/src/test/java/com/recom/tacview/engine/graphics/buffer/PixelBufferTest.java @@ -1,6 +1,6 @@ package com.recom.tacview.engine.graphics.buffer; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/MultithreadedSoftwareRenderer2Test.java b/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/MultithreadedSoftwareRenderer2Test.java index d4862d31..f05a0b8f 100644 --- a/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/MultithreadedSoftwareRenderer2Test.java +++ b/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/MultithreadedSoftwareRenderer2Test.java @@ -3,7 +3,7 @@ import com.recom.tacview.engine.graphics.IsScanable; import com.recom.tacview.engine.graphics.buffer.PixelBuffer; import com.recom.tacview.engine.renderables.sprite.SpriteAtlas; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import com.recom.tacview.property.RendererProperties; import com.recom.tacview.service.RendererExecutorProvider; import com.recom.tacview.service.argb.ARGBCalculatorProvider; diff --git a/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/MultithreadedSoftwareRendererTest.java b/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/MultithreadedSoftwareRendererTest.java index ab3bdfb0..ec343dc5 100644 --- a/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/MultithreadedSoftwareRendererTest.java +++ b/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/MultithreadedSoftwareRendererTest.java @@ -3,7 +3,7 @@ import com.recom.tacview.engine.graphics.IsScanable; import com.recom.tacview.engine.graphics.buffer.PixelBuffer; import com.recom.tacview.engine.renderables.sprite.SpriteAtlas; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import com.recom.tacview.property.RendererProperties; import com.recom.tacview.service.RendererExecutorProvider; import com.recom.tacview.service.argb.ARGBCalculatorProvider; diff --git a/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/SoftwareRendererTest.java b/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/SoftwareRendererTest.java index 29316a52..023279fd 100644 --- a/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/SoftwareRendererTest.java +++ b/libs/tacviewfx/src/test/java/com/recom/tacview/engine/renderer/SoftwareRendererTest.java @@ -3,7 +3,7 @@ import com.recom.tacview.engine.graphics.IsScanable; import com.recom.tacview.engine.graphics.buffer.PixelBuffer; import com.recom.tacview.engine.renderables.sprite.SpriteAtlas; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.commons.units.PixelDimension; import com.recom.tacview.service.argb.ARGBCalculatorProvider; import lombok.NonNull; import lombok.RequiredArgsConstructor; diff --git a/services/recom-backend/pom.xml b/services/recom-backend/pom.xml index f4a1b7c8..7079b0d4 100644 --- a/services/recom-backend/pom.xml +++ b/services/recom-backend/pom.xml @@ -44,7 +44,7 @@ com.recom - recom-rendertools + recom-commons 1.0.0-SNAPSHOT compile diff --git a/services/recom-backend/src/main/java/com/recom/api/map/MapTopographyController.java b/services/recom-backend/src/main/java/com/recom/api/map/MapTopographyController.java index dc2aa1bd..4d05ab35 100644 --- a/services/recom-backend/src/main/java/com/recom/api/map/MapTopographyController.java +++ b/services/recom-backend/src/main/java/com/recom/api/map/MapTopographyController.java @@ -6,7 +6,7 @@ import com.recom.entity.map.GameMap; import com.recom.exception.HttpNotFoundException; import com.recom.mapper.HeightMapDescriptorMapper; -import com.recom.rendertools.rasterizer.HeightMapDescriptor; +import com.recom.commons.rasterizer.HeightMapDescriptor; import com.recom.security.account.RECOMAccount; import com.recom.security.account.RECOMAuthorities; import com.recom.service.AssertionService; diff --git a/services/recom-backend/src/main/java/com/recom/configuration/ColorCalculatorConfiguration.java b/services/recom-backend/src/main/java/com/recom/configuration/ColorCalculatorConfiguration.java index 531582e1..38aff3e3 100644 --- a/services/recom-backend/src/main/java/com/recom/configuration/ColorCalculatorConfiguration.java +++ b/services/recom-backend/src/main/java/com/recom/configuration/ColorCalculatorConfiguration.java @@ -1,6 +1,6 @@ package com.recom.configuration; -import com.recom.rendertools.calculator.ARGBCalculator; +import com.recom.commons.calculator.ARGBCalculator; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/services/recom-backend/src/main/java/com/recom/configuration/HeightmapRasterizerConfiguration.java b/services/recom-backend/src/main/java/com/recom/configuration/HeightmapRasterizerConfiguration.java index d7f0efce..4be696f7 100644 --- a/services/recom-backend/src/main/java/com/recom/configuration/HeightmapRasterizerConfiguration.java +++ b/services/recom-backend/src/main/java/com/recom/configuration/HeightmapRasterizerConfiguration.java @@ -1,6 +1,6 @@ package com.recom.configuration; -import com.recom.rendertools.rasterizer.HeightmapRasterizer; +import com.recom.commons.rasterizer.HeightmapRasterizer; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/services/recom-backend/src/main/java/com/recom/mapper/HeightMapDescriptorMapper.java b/services/recom-backend/src/main/java/com/recom/mapper/HeightMapDescriptorMapper.java index 6cb4d516..ba355ca9 100644 --- a/services/recom-backend/src/main/java/com/recom/mapper/HeightMapDescriptorMapper.java +++ b/services/recom-backend/src/main/java/com/recom/mapper/HeightMapDescriptorMapper.java @@ -1,7 +1,7 @@ package com.recom.mapper; import com.recom.dto.map.topography.HeightMapDescriptorDto; -import com.recom.rendertools.rasterizer.HeightMapDescriptor; +import com.recom.commons.rasterizer.HeightMapDescriptor; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/services/recom-backend/src/main/java/com/recom/service/map/MapRendererService.java b/services/recom-backend/src/main/java/com/recom/service/map/MapRendererService.java index 7a9aebc0..03de7b1e 100644 --- a/services/recom-backend/src/main/java/com/recom/service/map/MapRendererService.java +++ b/services/recom-backend/src/main/java/com/recom/service/map/MapRendererService.java @@ -5,7 +5,7 @@ import com.recom.dto.map.renderer.MapRenderResponseDto; import com.recom.entity.map.GameMap; import com.recom.service.map.cluster.ClusteringService; -import com.recom.rendertools.calculator.ARGBColor; +import com.recom.commons.calculator.ARGBColor; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/services/recom-backend/src/main/java/com/recom/service/map/topography/HeightmapGeneratorService.java b/services/recom-backend/src/main/java/com/recom/service/map/topography/HeightmapGeneratorService.java index fb838631..6a50436b 100644 --- a/services/recom-backend/src/main/java/com/recom/service/map/topography/HeightmapGeneratorService.java +++ b/services/recom-backend/src/main/java/com/recom/service/map/topography/HeightmapGeneratorService.java @@ -2,8 +2,8 @@ import com.recom.entity.map.MapTopography; import com.recom.model.map.TopographyData; -import com.recom.rendertools.rasterizer.HeightMapDescriptor; -import com.recom.rendertools.rasterizer.HeightmapRasterizer; +import com.recom.commons.rasterizer.HeightMapDescriptor; +import com.recom.commons.rasterizer.HeightmapRasterizer; import com.recom.service.SerializationService; import lombok.NonNull; import lombok.RequiredArgsConstructor; diff --git a/services/recom-backend/src/main/java/com/recom/service/map/topography/TopographyMapDataService.java b/services/recom-backend/src/main/java/com/recom/service/map/topography/TopographyMapDataService.java index ea808d9a..582287c4 100644 --- a/services/recom-backend/src/main/java/com/recom/service/map/topography/TopographyMapDataService.java +++ b/services/recom-backend/src/main/java/com/recom/service/map/topography/TopographyMapDataService.java @@ -4,7 +4,7 @@ import com.recom.entity.map.MapTopography; import com.recom.exception.HttpNotFoundException; import com.recom.exception.HttpUnprocessableEntityException; -import com.recom.rendertools.rasterizer.HeightMapDescriptor; +import com.recom.commons.rasterizer.HeightMapDescriptor; import com.recom.persistence.map.topography.MapLocatedTopographyPersistenceLayer; import com.recom.service.SerializationService; import lombok.NonNull; diff --git a/services/recom-backend/src/test/java/com/recom/service/map/topography/HeightmapGeneratorServiceTest.java b/services/recom-backend/src/test/java/com/recom/service/map/topography/HeightmapGeneratorServiceTest.java index d10426ff..c5c9b734 100644 --- a/services/recom-backend/src/test/java/com/recom/service/map/topography/HeightmapGeneratorServiceTest.java +++ b/services/recom-backend/src/test/java/com/recom/service/map/topography/HeightmapGeneratorServiceTest.java @@ -3,7 +3,7 @@ import com.recom.entity.map.GameMap; import com.recom.entity.map.MapTopography; import com.recom.model.map.TopographyData; -import com.recom.rendertools.rasterizer.HeightmapRasterizer; +import com.recom.commons.rasterizer.HeightmapRasterizer; import com.recom.service.SerializationService; import com.recom.testhelper.SerializeObjectHelper; import org.junit.jupiter.api.Test; diff --git a/services/recom-commander/pom.xml b/services/recom-commander/pom.xml index 62cf4aa2..452d3693 100644 --- a/services/recom-commander/pom.xml +++ b/services/recom-commander/pom.xml @@ -30,7 +30,7 @@ com.recom - recom-rendertools + recom-commons 1.0.0-SNAPSHOT compile diff --git a/services/recom-commander/src/main/java/com/recom/commander/JavaFxApplication.java b/services/recom-commander/src/main/java/com/recom/commander/JavaFxApplication.java index c510697e..8c7b5e37 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/JavaFxApplication.java +++ b/services/recom-commander/src/main/java/com/recom/commander/JavaFxApplication.java @@ -5,6 +5,7 @@ import com.recom.commander.event.ShutdownEvent; import com.recom.commander.event.StageReadyEvent; import com.recom.commander.exception.GlobalExceptionHandler; +import com.recom.commander.util.LoggerUtil; import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; @@ -54,6 +55,7 @@ private void setGlobalExceptionHandler() { @Override public void stop() { + System.out.println("\n\n" + LoggerUtil.generateCenteredString("STOP")); log.warn("Closing application context ..."); applicationContext.publishEvent(new ShutdownEvent(this)); applicationContext.close(); diff --git a/services/recom-commander/src/main/java/com/recom/commander/configuration/ColorCalculatorConfiguration.java b/services/recom-commander/src/main/java/com/recom/commander/configuration/ColorCalculatorConfiguration.java index 27e8a1a9..1f8faf6e 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/configuration/ColorCalculatorConfiguration.java +++ b/services/recom-commander/src/main/java/com/recom/commander/configuration/ColorCalculatorConfiguration.java @@ -1,6 +1,6 @@ package com.recom.commander.configuration; -import com.recom.rendertools.calculator.ARGBCalculator; +import com.recom.commons.calculator.ARGBCalculator; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/services/recom-commander/src/main/java/com/recom/commander/configuration/HeightmapRasterizerConfiguration.java b/services/recom-commander/src/main/java/com/recom/commander/configuration/HeightmapRasterizerConfiguration.java index 1c2ba118..70d75561 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/configuration/HeightmapRasterizerConfiguration.java +++ b/services/recom-commander/src/main/java/com/recom/commander/configuration/HeightmapRasterizerConfiguration.java @@ -1,6 +1,6 @@ package com.recom.commander.configuration; -import com.recom.rendertools.rasterizer.HeightmapRasterizer; +import com.recom.commons.rasterizer.HeightmapRasterizer; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/services/recom-commander/src/main/java/com/recom/commander/configuration/RECOMMapEntityConfiguration.java b/services/recom-commander/src/main/java/com/recom/commander/configuration/RECOMMapEntityConfiguration.java index 0f1f1eac..965c28a2 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/configuration/RECOMMapEntityConfiguration.java +++ b/services/recom-commander/src/main/java/com/recom/commander/configuration/RECOMMapEntityConfiguration.java @@ -3,8 +3,8 @@ import com.recom.commander.enginemodule.entity.recommapentity.RECOMMapEntity; import com.recom.commander.enginemodule.entity.recommapentity.component.RECOMMapComponent; import com.recom.commander.enginemodule.entity.recommapentity.component.RECOMMapInputComponent; -import com.recom.tacview.engine.entitycomponentsystem.component.PhysicComponent; -import com.recom.tacview.engine.entitycomponentsystem.component.PhysicCoreComponent; +import com.recom.tacview.engine.ecs.component.PhysicComponent; +import com.recom.tacview.engine.ecs.component.PhysicCoreComponent; import lombok.NonNull; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/TacViewerEngineModule.java b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/TacViewerEngineModule.java index cd4b4056..f8cb440a 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/TacViewerEngineModule.java +++ b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/TacViewerEngineModule.java @@ -1,7 +1,7 @@ package com.recom.commander.enginemodule; import com.recom.commander.enginemodule.entity.recommapentity.RECOMMapEntity; -import com.recom.tacview.engine.entitycomponentsystem.environment.Environment; +import com.recom.tacview.engine.ecs.environment.Environment; import com.recom.tacview.engine.module.EngineModule; import lombok.NonNull; import org.springframework.stereotype.Component; diff --git a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/RECOMMapEntity.java b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/RECOMMapEntity.java index bb0ed730..4e6ba2b0 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/RECOMMapEntity.java +++ b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/RECOMMapEntity.java @@ -1,6 +1,6 @@ package com.recom.commander.enginemodule.entity.recommapentity; -import com.recom.tacview.engine.entitycomponentsystem.entity.Entity; +import com.recom.tacview.engine.ecs.entity.Entity; public class RECOMMapEntity extends Entity { diff --git a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapComponent.java b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapComponent.java index 5a35dbc2..f81b90de 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapComponent.java +++ b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapComponent.java @@ -4,6 +4,13 @@ import com.recom.commander.mapper.HeightMapDescriptorMapper; import com.recom.commander.service.map.overview.data.MapsOverviewService; import com.recom.commander.service.map.topography.data.MapTopographyDataService; +import com.recom.commander.util.MapCalculator; +import com.recom.commons.rasterizer.HeightMapDescriptor; +import com.recom.commons.rasterizer.HeightmapRasterizer; +import com.recom.commons.units.PixelCoordinate; +import com.recom.commons.units.PixelDimension; +import com.recom.commons.units.ScaleFactor; +import com.recom.commons.units.calc.ScalingTool; import com.recom.dto.map.MapOverviewDto; import com.recom.dto.map.topography.HeightMapDescriptorDto; import com.recom.dto.map.topography.MapTopographyRequestDto; @@ -11,19 +18,19 @@ import com.recom.observer.ReactiveObserver; import com.recom.observer.Subjective; import com.recom.observer.TakeNoticeRunnable; -import com.recom.rendertools.rasterizer.HeightMapDescriptor; -import com.recom.rendertools.rasterizer.HeightmapRasterizer; -import com.recom.tacview.engine.entitycomponentsystem.component.RenderableComponent; +import com.recom.tacview.engine.ecs.component.PhysicCoreComponent; +import com.recom.tacview.engine.ecs.component.RenderableComponent; import com.recom.tacview.engine.graphics.buffer.PixelBuffer; -import com.recom.tacview.engine.units.PixelDimension; +import com.recom.tacview.engine.input.NanoTimedEvent; +import com.recom.tacview.property.RendererProperties; import jakarta.annotation.Nullable; -import jakarta.annotation.PostConstruct; +import javafx.scene.input.ScrollEvent; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; -import java.util.LinkedList; +import java.util.Optional; @Slf4j @Component @@ -35,32 +42,31 @@ public class RECOMMapComponent extends RenderableComponent implements AutoClosea private final MapTopographyDataService mapTopographyDataService; @NonNull private final HeightmapRasterizer heightmapRasterizer; - + @NonNull + private final RendererProperties rendererProperties; + @NonNull + private Optional maybeHeightMapDescriptor = Optional.empty(); @Nullable - private ReactiveObserver mapOverviewReactiveObserver; + private final ReactiveObserver mapOverviewReactiveObserver; @Nullable - private ReactiveObserver mapTopographyDataReactiveObserver; - - private int pixelFactor = 1; - + private final ReactiveObserver mapTopographyDataReactiveObserver; @NonNull - private final LinkedList scaledMapPixelBufferList = new LinkedList<>(); + private final ScaleFactor mapScale = new ScaleFactor(); public RECOMMapComponent( @NonNull final MapsOverviewService mapsOverviewService, @NonNull final MapTopographyDataService mapTopographyDataService, - @NonNull final HeightmapRasterizer heightmapRasterizer + @NonNull final HeightmapRasterizer heightmapRasterizer, + @NonNull final RendererProperties rendererProperties ) { super(); this.mapsOverviewService = mapsOverviewService; this.mapTopographyDataService = mapTopographyDataService; this.heightmapRasterizer = heightmapRasterizer; + this.rendererProperties = rendererProperties; this.setZIndex(0); - } - @PostConstruct - public void init() { mapOverviewReactiveObserver = ReactiveObserver.reactWith(onReloadMapOverviewReaction()); mapOverviewReactiveObserver.observe(mapsOverviewService.getBufferedSubject()); @@ -77,12 +83,9 @@ private TakeNoticeRunnable onReloadMapTopographyDataReac log.debug("Received map topography data"); final HeightMapDescriptorDto heightMapDescriptorDto = notification.getPayload(); final HeightMapDescriptor heightMapDescriptor = HeightMapDescriptorMapper.INSTANCE.toModel(heightMapDescriptorDto); + maybeHeightMapDescriptor = Optional.of(heightMapDescriptor); - final int[] pixelBufferArray = heightmapRasterizer.rasterizeHeightMapRGB(heightMapDescriptor); - final PixelDimension dimension = PixelDimension.of(heightMapDescriptor.getHeightMap().length, heightMapDescriptor.getHeightMap()[0].length); - - this.pixelBuffer = new PixelBuffer(dimension, pixelBufferArray); - propagateDirtyStateToParent(); + setMap(heightMapDescriptor); }; } @@ -120,25 +123,83 @@ public void close() { } } - public void zoomIn() { - if (pixelFactor == 1) { - return; - } else { - pixelFactor--; - swapBuffer(); + public void zoomIn( + @NonNull final NanoTimedEvent nanoTimedEvent, + @NonNull final PhysicCoreComponent physicsCoreComponent + ) { + if (maybeHeightMapDescriptor.isPresent()) { + final PixelCoordinate mouseCoordinateOnCanvas = PixelCoordinate.of( + MapCalculator.applyRenderScale(nanoTimedEvent.getEvent().getSceneX(), rendererProperties), + MapCalculator.applyRenderScale(nanoTimedEvent.getEvent().getSceneY(), rendererProperties) + ); + final PixelCoordinate normalizedCoordinateOnMap = MapCalculator.getCoordinateOfMouseOnMap(nanoTimedEvent, physicsCoreComponent, mapScale, rendererProperties); + + mapScale.zoomIn(); + if (mapScale.getScaleFactor() == 1) { + setMap(maybeHeightMapDescriptor.get()); + } else { + setScaledMap(maybeHeightMapDescriptor.get(), mapScale.getScaleFactor()); + } + + final PixelCoordinate scaledMapCoordinate = normalizedCoordinateOnMap.scaled(mapScale.getScaleFactor()); + physicsCoreComponent.setPositionX(-scaledMapCoordinate.getX() + mouseCoordinateOnCanvas.getX()); + physicsCoreComponent.setPositionY(-scaledMapCoordinate.getY() + mouseCoordinateOnCanvas.getY()); } } - public void zoomOut() { - pixelFactor++; - swapBuffer(); + public void zoomOut( + @NonNull final NanoTimedEvent nanoTimedEvent, + @NonNull final PhysicCoreComponent physicsCoreComponent + ) { + if (maybeHeightMapDescriptor.isPresent()) { + final PixelCoordinate mouseCoordinateOnCanvas = PixelCoordinate.of( + MapCalculator.applyRenderScale(nanoTimedEvent.getEvent().getSceneX(), rendererProperties), + MapCalculator.applyRenderScale(nanoTimedEvent.getEvent().getSceneY(), rendererProperties) + ); + final PixelCoordinate normalizedCoordinateOnMap = MapCalculator.getCoordinateOfMouseOnMap(nanoTimedEvent, physicsCoreComponent, mapScale, rendererProperties); + + mapScale.zoomOut(); + + if (mapScale.getScaleFactor() == 1) { + setMap(maybeHeightMapDescriptor.get()); + } else { + setScaledMap(maybeHeightMapDescriptor.get(), mapScale.getScaleFactor()); + } + + final PixelCoordinate scaledMapCoordinate = normalizedCoordinateOnMap.scaled(mapScale.getScaleFactor()); + physicsCoreComponent.setPositionX(-scaledMapCoordinate.getX() + mouseCoordinateOnCanvas.getX()); + physicsCoreComponent.setPositionY(-scaledMapCoordinate.getY() + mouseCoordinateOnCanvas.getY()); + } } - private void swapBuffer() { - // @TODO <<<<-------------------------------------------------------------------------------------------------- + private void setMap(@NonNull final HeightMapDescriptor heightMapDescriptor) { + final int mapWidth = heightMapDescriptor.getHeightMap().length; + final int mapHeight = heightMapDescriptor.getHeightMap()[0].length; + + final int[] pixelBufferArray = heightmapRasterizer.rasterizeHeightMapRGB(heightMapDescriptor); + + final PixelBuffer newPixelBuffer = new PixelBuffer(PixelDimension.of(mapWidth, mapHeight), pixelBufferArray); + this.setPixelBuffer(newPixelBuffer); + + propagateDirtyStateToParent(); + } + + private void setScaledMap( + @NonNull HeightMapDescriptor heightMapDescriptor, + final int scaleFactor + ) { + final int originalMapHeight = heightMapDescriptor.getHeightMap().length; + final int originalMapWidth = heightMapDescriptor.getHeightMap()[0].length; + + final int scaledMapWidth = (int) ScalingTool.scaleDimension(originalMapWidth, scaleFactor); + final int scaledMapHeight = (int) ScalingTool.scaleDimension(originalMapHeight, scaleFactor); + + final int[] newScaledPixelArray = heightmapRasterizer.rasterizeHeightMapRGB(heightMapDescriptor, scaleFactor); + + final PixelBuffer newScaledPixelBuffer = new PixelBuffer(PixelDimension.of(scaledMapWidth, scaledMapHeight), newScaledPixelArray); + this.setPixelBuffer(newScaledPixelBuffer); - // init first element with actual buffer! - scaledMapPixelBufferList.add(this.pixelBuffer); + propagateDirtyStateToParent(); } } diff --git a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapInputComponent.java b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapInputComponent.java index 003bcf97..1036412e 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapInputComponent.java +++ b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapInputComponent.java @@ -1,8 +1,8 @@ package com.recom.commander.enginemodule.entity.recommapentity.component; -import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType; -import com.recom.tacview.engine.entitycomponentsystem.component.InputComponent; -import com.recom.tacview.engine.entitycomponentsystem.component.PhysicCoreComponent; +import com.recom.tacview.engine.ecs.component.ComponentType; +import com.recom.tacview.engine.ecs.component.InputComponent; +import com.recom.tacview.engine.ecs.component.PhysicCoreComponent; import com.recom.tacview.engine.input.command.IsCommand; import com.recom.tacview.engine.input.command.keyboard.KeyboardCommand; import com.recom.tacview.engine.input.command.mousebutton.MouseButton; @@ -55,10 +55,10 @@ private void handleKeyboardCommand(@NonNull final KeyboardCommand keyboardComman private void handleScrollCommand(@NonNull final ScrollCommand scrollCommand) { this.getEntity().locateComponent(ComponentType.PhysicsCoreComponent).ifPresent(physicsCoreComponent -> { if (scrollCommand.getNanoTimedEvent().getEvent().getDeltaY() > 0) { - locateRecomMapComponent().ifPresent(RECOMMapComponent::zoomIn); + locateRecomMapComponent().ifPresent((mapComponent) -> mapComponent.zoomIn(scrollCommand.getNanoTimedEvent(), physicsCoreComponent)); // TODO: Re-Reouting Events to entity -> ReDispatch; locate consumer(s), cache and call them with event } else if (scrollCommand.getNanoTimedEvent().getEvent().getDeltaY() < 0) { - locateRecomMapComponent().ifPresent(RECOMMapComponent::zoomOut); + locateRecomMapComponent().ifPresent((mapComponent) -> mapComponent.zoomOut(scrollCommand.getNanoTimedEvent(), physicsCoreComponent)); // TODO: Re-Reouting Events to entity -> ReDispatch; locate consumer(s), cache and call them with event } }); diff --git a/services/recom-commander/src/main/java/com/recom/commander/initializr/TacViewStageInitializer.java b/services/recom-commander/src/main/java/com/recom/commander/initializr/TacViewStageInitializer.java index c3f814d9..3f58b33e 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/initializr/TacViewStageInitializer.java +++ b/services/recom-commander/src/main/java/com/recom/commander/initializr/TacViewStageInitializer.java @@ -4,6 +4,7 @@ import com.recom.commander.event.ShutdownEvent; import com.recom.commander.exception.GlobalExceptionHandler; import com.recom.commander.property.SpringApplicationProperties; +import com.recom.commander.util.LoggerUtil; import com.recom.tacview.engine.TacViewer; import com.recom.tacview.engine.graphics.ScreenComposer; import com.recom.tacview.engine.input.GenericFXInputEventListener; @@ -24,11 +25,11 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.SpringApplication; import org.springframework.context.event.EventListener; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; +import java.util.Optional; + @Slf4j @Component @@ -53,9 +54,8 @@ public class TacViewStageInitializer { private final GenericFXInputEventListener genericFXInputEventListener; @NonNull private final InputManager inputManager; - - @Nullable - private TacViewer tacViewer = null; + @NonNull + private Optional maybeTacViewer = Optional.empty(); @EventListener(classes = InitializeStageEvent.class) @@ -66,9 +66,8 @@ public void onApplicationEvent(@NonNull final InitializeStageEvent event) { populateTacViewStage(tacViewStage); tacViewStage.show(); tacViewStage.setOnCloseRequest(onCloseEvent -> { - tacViewer.stop(); + System.out.println("\n\n" + LoggerUtil.generateCenteredString("CLOSED")); Platform.exit(); - Platform.runLater(Platform::exit); }); } catch (final Throwable t) { globalExceptionHandler.uncaughtException(Thread.currentThread(), t); @@ -79,7 +78,7 @@ private void populateTacViewStage(@NonNull final Stage stage) { final BorderPane root = new BorderPane(); root.setBackground(new Background(new BackgroundFill(Color.BLACK, null, null))); - tacViewer = new TacViewer( + final TacViewer tacViewer = new TacViewer( rendererProperties, tickProperties, profilerProvider, @@ -90,7 +89,8 @@ private void populateTacViewStage(@NonNull final Stage stage) { globalExceptionHandler ); - root.setCenter(tacViewer); + maybeTacViewer = Optional.of(tacViewer); + root.setCenter(maybeTacViewer.get()); final Scene scene = new Scene(root, rendererProperties.getScaledWindowWidth(), rendererProperties.getScaledWindowHeight()); stage.setTitle(springApplicationProperties.getName()); @@ -103,7 +103,7 @@ private void populateTacViewStage(@NonNull final Stage stage) { final ProfileFPSStrategy profileFPSStrategy = new ProfileFPSStrategy((@NonNull final String profiled) -> { Platform.runLater(() -> titleProperty.setValue(profiled)); }); - tacViewer.setProfileFPSStrategy(profileFPSStrategy); + tacViewer.setMaybeProfileFPSStrategy(Optional.of(profileFPSStrategy)); tacViewer.start(); stage.setResizable(false); @@ -113,9 +113,7 @@ private void populateTacViewStage(@NonNull final Stage stage) { @EventListener(classes = ShutdownEvent.class) public void shutdown() { log.warn("Shutdown TacViewer ..."); - if (tacViewer != null) { - tacViewer.stop(); - } + maybeTacViewer.ifPresent(TacViewer::stop); } } \ No newline at end of file diff --git a/services/recom-commander/src/main/java/com/recom/commander/mapper/HeightMapDescriptorMapper.java b/services/recom-commander/src/main/java/com/recom/commander/mapper/HeightMapDescriptorMapper.java index 67486012..a65b2b96 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/mapper/HeightMapDescriptorMapper.java +++ b/services/recom-commander/src/main/java/com/recom/commander/mapper/HeightMapDescriptorMapper.java @@ -1,7 +1,7 @@ package com.recom.commander.mapper; import com.recom.dto.map.topography.HeightMapDescriptorDto; -import com.recom.rendertools.rasterizer.HeightMapDescriptor; +import com.recom.commons.rasterizer.HeightMapDescriptor; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/services/recom-commander/src/main/java/com/recom/commander/util/LoggerUtil.java b/services/recom-commander/src/main/java/com/recom/commander/util/LoggerUtil.java new file mode 100644 index 00000000..ded60ea8 --- /dev/null +++ b/services/recom-commander/src/main/java/com/recom/commander/util/LoggerUtil.java @@ -0,0 +1,27 @@ +package com.recom.commander.util; + +import lombok.NonNull; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class LoggerUtil { + + public String generateCenteredString(@NonNull final String text) { + final int totalWidth = 80; + final int textWidth = text.length(); + + if (textWidth >= totalWidth) { + return text; + } + + final int padding = (totalWidth - textWidth) / 2; + final StringBuilder stringBuilder = new StringBuilder(); + + stringBuilder.append("-".repeat(padding)); + stringBuilder.append(' ').append(text).append(' '); + stringBuilder.append("-".repeat(Math.max(0, totalWidth - stringBuilder.length()))); + + return stringBuilder.toString(); + } + +} diff --git a/services/recom-commander/src/main/java/com/recom/commander/util/MapCalculator.java b/services/recom-commander/src/main/java/com/recom/commander/util/MapCalculator.java new file mode 100644 index 00000000..0542b124 --- /dev/null +++ b/services/recom-commander/src/main/java/com/recom/commander/util/MapCalculator.java @@ -0,0 +1,54 @@ +package com.recom.commander.util; + +import com.recom.commons.math.Round; +import com.recom.commons.units.PixelCoordinate; +import com.recom.commons.units.ScaleFactor; +import com.recom.commons.units.calc.ScalingTool; +import com.recom.tacview.engine.ecs.component.PhysicCoreComponent; +import com.recom.tacview.engine.input.NanoTimedEvent; +import com.recom.tacview.property.RendererProperties; +import javafx.scene.input.ScrollEvent; +import lombok.NonNull; +import lombok.experimental.UtilityClass; + + +@UtilityClass +public class MapCalculator { + + @NonNull + public PixelCoordinate getCoordinateOfMouseOnMap( + @NonNull final NanoTimedEvent nanoTimedEvent, + @NonNull final PhysicCoreComponent physicsCoreComponent, + @NonNull final ScaleFactor scaleFactor, + @NonNull final RendererProperties rendererProperties + ) { + final double originX = physicsCoreComponent.getPositionX(); + final double originY = physicsCoreComponent.getPositionY(); + + final double mouseOnCanvasX = applyRenderScale(nanoTimedEvent.getEvent().getSceneX(), rendererProperties); + final double mouseOnCanvasY = applyRenderScale(nanoTimedEvent.getEvent().getSceneY(), rendererProperties); + + final int scaledMousePositionOnScaledMapX = (int) (-1 * originX + mouseOnCanvasX); + final int scaledMousePositionOnScaledMapY = (int) (-1 * originY + mouseOnCanvasY); + + final int normalizedMousePositionOnNormalizedMapX = Round.halfUp(ScalingTool.normalizeDimension(scaledMousePositionOnScaledMapX, scaleFactor.getScaleFactor())); + final int normalizedMousePositionOnNormalizedMapY = Round.halfUp(ScalingTool.normalizeDimension(scaledMousePositionOnScaledMapY, scaleFactor.getScaleFactor())); + + return PixelCoordinate.of(normalizedMousePositionOnNormalizedMapX, normalizedMousePositionOnNormalizedMapY); + } + + public double applyRenderScale( + @NonNull final int dimension, + @NonNull final RendererProperties rendererProperties + ) { + return dimension / (double) rendererProperties.getScale(); + } + + public double applyRenderScale( + @NonNull final double dimension, + @NonNull final RendererProperties rendererProperties + ) { + return dimension / (double) rendererProperties.getScale(); + } + +} diff --git a/services/recom-commander/src/main/resources/application.properties b/services/recom-commander/src/main/resources/application.properties index 8c6fead7..7558df45 100644 --- a/services/recom-commander/src/main/resources/application.properties +++ b/services/recom-commander/src/main/resources/application.properties @@ -5,15 +5,15 @@ spring.threads.virtual.enabled=true # ENGINE -engine.renderer.width=2000 -engine.renderer.height=1300 -engine.renderer.scale=1 +engine.renderer.width=960 +engine.renderer.height=540 +engine.renderer.scale=2 engine.renderer.parallelizedRendering=true engine.renderer.renderFragments=8 engine.renderer.threadPoolSize=-1 engine.renderer.composer.backBufferSize=10 -engine.renderer.targetFps=70 -engine.tick.targetTps=70 +engine.renderer.targetFps=63 +engine.tick.targetTps=63 #BASIC REST CLIENT CONFIGURATION