From 3bf0d18e88844a622d60c0e13c595884b14e960d Mon Sep 17 00:00:00 2001 From: Tefek <493msi@gmail.com> Date: Sun, 18 Oct 2020 00:57:08 +0200 Subject: [PATCH] [PlutoLib] Code cleanup --- .../cz/tefek/pluto/engine/input/InputBus.java | 11 ++++++----- .../tefek/pluto/io/logger/OutputSplitStream.java | 7 ++++--- .../java/cz/tefek/pluto/math/CubicBezier.java | 15 +++++++-------- .../java/cz/tefek/pluto/math/CubicBezierLT.java | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/plutocore/src/main/java/cz/tefek/pluto/engine/input/InputBus.java b/plutocore/src/main/java/cz/tefek/pluto/engine/input/InputBus.java index 3b4da24..b466315 100644 --- a/plutocore/src/main/java/cz/tefek/pluto/engine/input/InputBus.java +++ b/plutocore/src/main/java/cz/tefek/pluto/engine/input/InputBus.java @@ -23,12 +23,13 @@ public class InputBus public static void init(Display display) { var instance = new InputBus(); + var windowPointer = display.getWindowPointer(); - GLFW.glfwSetKeyCallback(display.getWindowPointer(), instance.keyboard); - GLFW.glfwSetMouseButtonCallback(display.getWindowPointer(), instance.mouseButton); - GLFW.glfwSetCursorPosCallback(display.getWindowPointer(), instance.cursorPosition); - GLFW.glfwSetScrollCallback(display.getWindowPointer(), instance.scroll); - GLFW.glfwSetCharCallback(display.getWindowPointer(), instance.charInput); + GLFW.glfwSetKeyCallback(windowPointer, instance.keyboard); + GLFW.glfwSetMouseButtonCallback(windowPointer, instance.mouseButton); + GLFW.glfwSetCursorPosCallback(windowPointer, instance.cursorPosition); + GLFW.glfwSetScrollCallback(windowPointer, instance.scroll); + GLFW.glfwSetCharCallback(windowPointer, instance.charInput); INSTANCE.set(instance); } diff --git a/plutolib/src/main/java/cz/tefek/pluto/io/logger/OutputSplitStream.java b/plutolib/src/main/java/cz/tefek/pluto/io/logger/OutputSplitStream.java index 4738f29..cfaebe3 100644 --- a/plutolib/src/main/java/cz/tefek/pluto/io/logger/OutputSplitStream.java +++ b/plutolib/src/main/java/cz/tefek/pluto/io/logger/OutputSplitStream.java @@ -1,5 +1,6 @@ package cz.tefek.pluto.io.logger; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.OutputStream; @@ -10,7 +11,7 @@ import java.io.OutputStream; * @author 493msi * */ -class OutputSplitStream extends OutputStream +public class OutputSplitStream extends OutputStream { private final OutputStream outputStreamA; private final boolean shouldAClose; @@ -36,14 +37,14 @@ class OutputSplitStream extends OutputStream } @Override - public void write(byte[] b) throws IOException + public void write(@Nonnull byte[] b) throws IOException { this.outputStreamA.write(b); this.outputStreamB.write(b); } @Override - public void write(byte[] b, int off, int len) throws IOException + public void write(@Nonnull byte[] b, int off, int len) throws IOException { this.outputStreamA.write(b, off, len); this.outputStreamB.write(b, off, len); diff --git a/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezier.java b/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezier.java index b4f4379..fe0215a 100644 --- a/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezier.java +++ b/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezier.java @@ -10,7 +10,7 @@ package cz.tefek.pluto.math; public class CubicBezier { private static final int iterations = 16; - private double a, b, c, d; + private final double a, b, c, d; /** * Creates a new {@code CubicBezier} from the given parameters. @@ -62,23 +62,22 @@ public class CubicBezier double t = 0.5; double x; - double y = 3 * (1 - t) * (1 - t) * t * this.b + 3 * (1 - t) * t * t * this.d + t * t * t; + + // Resulting Y value + double result = 3 * (1 - t) * (1 - t) * t * this.b + 3 * (1 - t) * t * t * this.d + t * t * t; double delta = 0.25; - boolean uh; for (int i = 0; i < iterations; i++) { x = 3 * (1 - t) * (1 - t) * t * this.a + 3 * (1 - t) * t * t * this.c + t * t * t; - y = 3 * (1 - t) * (1 - t) * t * this.b + 3 * (1 - t) * t * t * this.d + t * t * t; + result = 3 * (1 - t) * (1 - t) * t * this.b + 3 * (1 - t) * t * t * this.d + t * t * t; - uh = x > xIn; - - t += uh ? -delta : delta; + t += x > xIn ? -delta : delta; delta /= 2; } - return y; + return result; } } diff --git a/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezierLT.java b/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezierLT.java index a7b44e2..ab8f7aa 100644 --- a/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezierLT.java +++ b/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezierLT.java @@ -42,7 +42,7 @@ public class CubicBezierLT } /** - * Retrives the approximate value for the given x and the supplied + * Retrieves the approximate value for the given x and the supplied * parameters in the constructor. * * @param xIn the input X position