Auto code cleanup
This commit is contained in:
@@ -22,7 +22,7 @@ public final class KeyModifiers {
|
||||
MODIFIER_ALTGR, "ALTGR ");
|
||||
|
||||
public static String getModifierLabel(final int modifier) {
|
||||
final StringBuilder label = new StringBuilder(12);
|
||||
final var label = new StringBuilder(12);
|
||||
for (final Entry<Integer, String> entry : MODIFIER_LABELS.entrySet()) {
|
||||
if ((modifier & entry.getKey().intValue()) != 0) {
|
||||
label.append(entry.getValue());
|
||||
|
||||
@@ -84,10 +84,9 @@ public final class KeycodeRegistration {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof KeycodeRegistration)) {
|
||||
if (!(obj instanceof final KeycodeRegistration other)) {
|
||||
return false;
|
||||
}
|
||||
final KeycodeRegistration other = (KeycodeRegistration) obj;
|
||||
return this.code == other.code && Objects.equals(this.displayText, other.displayText) && Objects.equals(this.keyCodeDisplay, other.keyCodeDisplay) && this.modifier == other.modifier && Objects.equals(this.qualifier, other.qualifier);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class KeycodeRegistryImpl implements KeycodeRegistry {
|
||||
public void registerDefault(final KeycodeRegistration... keycodeRegistrations) {
|
||||
this.lazyLoadRegistry();
|
||||
|
||||
boolean added = false;
|
||||
var added = false;
|
||||
for (final KeycodeRegistration keycodeRegistration : keycodeRegistrations) {
|
||||
added |= this.registry.putIfAbsent(keycodeRegistration.getQualifier(), new KeycodeRegistration(keycodeRegistration)) == null;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class KeycodeRegistryImpl implements KeycodeRegistry {
|
||||
public boolean check(final String qualifier, final int code, final int modifiers) {
|
||||
this.lazyLoadRegistry();
|
||||
|
||||
final KeycodeRegistration reg = this.registry.get(qualifier);
|
||||
final var reg = this.registry.get(qualifier);
|
||||
if (reg == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -82,7 +82,6 @@ public class KeycodeRegistryImpl implements KeycodeRegistry {
|
||||
return reg.getCode() == code && reg.getModifier() == modifiers;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void lazyLoadRegistry() {
|
||||
if (this.registry == null) {
|
||||
synchronized (this) {
|
||||
|
||||
@@ -200,14 +200,14 @@ public class RendererData {
|
||||
}
|
||||
|
||||
public VideoOptions getVideoOptions() {
|
||||
return videoOptions;
|
||||
return this.videoOptions;
|
||||
}
|
||||
|
||||
public Consumer<Object> getEventConsumer() {
|
||||
return eventConsumer;
|
||||
return this.eventConsumer;
|
||||
}
|
||||
|
||||
public void setEventConsumer(Consumer<Object> eventConsumer) {
|
||||
public void setEventConsumer(final Consumer<Object> eventConsumer) {
|
||||
this.eventConsumer = eventConsumer;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import de.extio.game_engine.renderer.g2d.G2DRendererControl;
|
||||
|
||||
public class RendererFactory {
|
||||
|
||||
public static Renderer createG2DRenderer(final RenderingBoPool renderingBoPool, Consumer<Object> eventConsumer) {
|
||||
public static Renderer createG2DRenderer(final RenderingBoPool renderingBoPool, final Consumer<Object> eventConsumer) {
|
||||
final var rendererData = new RendererData();
|
||||
final var renderer = new G2DRenderer(rendererData);
|
||||
rendererData.setRendererControl(new G2DRendererControl(renderer, rendererData));
|
||||
|
||||
@@ -80,7 +80,7 @@ public class EnhancedWindow<T> extends Window {
|
||||
@Override
|
||||
public void updateArea() {
|
||||
if (this.areaFunction != null) {
|
||||
final Area2 area = this.areaFunction.apply(this.state);
|
||||
final var area = this.areaFunction.apply(this.state);
|
||||
this.setDimension(area.getDimension());
|
||||
// this.resizeCentered(area.getDimension());
|
||||
if (!this.persistentPosition) {
|
||||
@@ -117,7 +117,7 @@ public class EnhancedWindow<T> extends Window {
|
||||
// this.applyRelativeScreenPosition();
|
||||
// }
|
||||
/*else*/ if (this.areaFunction != null) {
|
||||
final Area2 area = this.areaFunction.apply(this.state);
|
||||
final var area = this.areaFunction.apply(this.state);
|
||||
this.setPosition(area.getPosition());
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,6 @@ public class EnhancedWindow<T> extends Window {
|
||||
|
||||
private void savePosition() {
|
||||
if (!this.persistentPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
// final CoordD2 existingPosition = (CoordD2) EngineFacade.instance().getPersistentClientState().state.get(this.getPersistentStateKeyName());
|
||||
|
||||
@@ -16,7 +16,6 @@ import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
import de.extio.game_engine.spatial2.model.Area2;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
|
||||
|
||||
/**
|
||||
* Helper for scrollbars.
|
||||
* I recommend to check for code examples to learn more about the usage of this helper and how to integrate in client modules.
|
||||
@@ -38,7 +37,7 @@ public class ScrollBar {
|
||||
}
|
||||
|
||||
public void onEvent(final UiControlEvent event, final Predicate<CoordI2> positionIntersectsPredicate) {
|
||||
final UiControlEvent uiControlEvent = (UiControlEvent) event;
|
||||
final var uiControlEvent = (UiControlEvent) event;
|
||||
|
||||
if (this.name.equals(uiControlEvent.getId())) {
|
||||
this.scrollPosition = 1.0D - ((Double) uiControlEvent.getPayload()).doubleValue();
|
||||
@@ -50,7 +49,7 @@ public class ScrollBar {
|
||||
this.lastNumElements > 0 &&
|
||||
positionIntersectsPredicate.test(absolutePos)) {
|
||||
|
||||
final double perElem = (button == 4 ? -1.0 : 1.0) / this.lastNumElements;
|
||||
final var perElem = (button == 4 ? -1.0 : 1.0) / this.lastNumElements;
|
||||
this.scrollPosition = Math.min(1.0, Math.max(0.0, this.scrollPosition + perElem));
|
||||
}
|
||||
}
|
||||
@@ -58,7 +57,7 @@ public class ScrollBar {
|
||||
public void render(final List<RenderingBo> renderingBo, final Area2 renderingArea, final int numElements, final RenderingBoPool renderingBoPool) {
|
||||
this.lastNumElements = numElements;
|
||||
|
||||
final RenderingBo bo = renderingBoPool.acquire(ControlRenderingBo.class)
|
||||
final var bo = renderingBoPool.acquire(ControlRenderingBo.class)
|
||||
.setId(this.name)
|
||||
.setType(SliderControl.class)
|
||||
.setCustomData(Boolean.FALSE)
|
||||
|
||||
@@ -14,10 +14,8 @@ import de.extio.game_engine.renderer.model.RenderingBo;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawWindowRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.SliderControl;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.WindowCloseButtonControl;
|
||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawWindowRenderingBo;
|
||||
import de.extio.game_engine.spatial2.WorldUtils2;
|
||||
import de.extio.game_engine.spatial2.model.Area2;
|
||||
import de.extio.game_engine.spatial2.model.CoordD2;
|
||||
@@ -168,15 +166,14 @@ public class Window implements HasPositionAndDimension2, AutoCloseable {
|
||||
return WorldUtils2.intersects(this.area.getPosition(), this.area.getDimension(), coord, ImmutableCoordI2.one());
|
||||
}
|
||||
|
||||
|
||||
public void render(final List<RenderingBo> renderingBo, final BiConsumer<List<RenderingBo>, RenderingBo> consumer) {
|
||||
final CoordI2 currentEffectiveViewportDimension = rendererControl.getEffectiveViewportDimension();
|
||||
final var currentEffectiveViewportDimension = this.rendererControl.getEffectiveViewportDimension();
|
||||
if (!currentEffectiveViewportDimension.equals(this.lastEffectiveViewportDimension)) {
|
||||
this.lastEffectiveViewportDimension = currentEffectiveViewportDimension;
|
||||
this.updateArea();
|
||||
}
|
||||
|
||||
RenderingBo bo = renderingBoPool.acquire(DrawWindowRenderingBo.class)
|
||||
var bo = this.renderingBoPool.acquire(DrawWindowRenderingBo.class)
|
||||
.setThickBorder(this.draggable)
|
||||
.withDimensionAbsolute(this.area.getDimension())
|
||||
.withPositionAbsoluteAnchorTopLeft(this.area.getPosition())
|
||||
@@ -187,7 +184,7 @@ public class Window implements HasPositionAndDimension2, AutoCloseable {
|
||||
consumer.accept(renderingBo, bo);
|
||||
|
||||
if (this.drawCloseButton) {
|
||||
bo = renderingBoPool.acquire(ControlRenderingBo.class)
|
||||
bo = this.renderingBoPool.acquire(ControlRenderingBo.class)
|
||||
.setType(WindowCloseButtonControl.class)
|
||||
.setId(this.name + "_Close")
|
||||
.setCustomData(this.draggable)
|
||||
@@ -215,8 +212,8 @@ public class Window implements HasPositionAndDimension2, AutoCloseable {
|
||||
}
|
||||
|
||||
protected void ensureBounds() {
|
||||
final CoordI2 effectiveDim = this.rendererControl.getEffectiveViewportDimension();
|
||||
boolean updated = false;
|
||||
final var effectiveDim = this.rendererControl.getEffectiveViewportDimension();
|
||||
var updated = false;
|
||||
|
||||
if (this.area.getPosition().getX() < 0) {
|
||||
this.area.getPosition().setX(0);
|
||||
@@ -249,13 +246,13 @@ public class Window implements HasPositionAndDimension2, AutoCloseable {
|
||||
}
|
||||
|
||||
protected void updateRelativeScreenPosition() {
|
||||
final CoordI2 currentEffectiveViewportDimension = this.rendererControl.getEffectiveViewportDimension();
|
||||
final var currentEffectiveViewportDimension = this.rendererControl.getEffectiveViewportDimension();
|
||||
this.relativeScreenPosition.setX((double) this.area.getPosition().getX() / (double) currentEffectiveViewportDimension.getX());
|
||||
this.relativeScreenPosition.setY((double) this.area.getPosition().getY() / (double) currentEffectiveViewportDimension.getY());
|
||||
}
|
||||
|
||||
protected void applyRelativeScreenPosition() {
|
||||
final CoordI2 currentEffectiveViewportDimension = this.rendererControl.getEffectiveViewportDimension();
|
||||
final var currentEffectiveViewportDimension = this.rendererControl.getEffectiveViewportDimension();
|
||||
this.area.getPosition().setX((int) (this.relativeScreenPosition.getX() * (double) currentEffectiveViewportDimension.getX()));
|
||||
this.area.getPosition().setY((int) (this.relativeScreenPosition.getY() * (double) currentEffectiveViewportDimension.getY()));
|
||||
this.ensureBounds();
|
||||
|
||||
@@ -2,14 +2,11 @@ package de.extio.game_engine.renderer.g2d;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Color;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.AWTEventListener;
|
||||
@@ -24,17 +21,13 @@ import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
|
||||
import de.extio.game_engine.keyboard.KeyModifiers;
|
||||
import de.extio.game_engine.renderer.RendererControl;
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
@@ -43,6 +36,8 @@ import de.extio.game_engine.renderer.model.event.KeyStrokeEvent;
|
||||
import de.extio.game_engine.renderer.model.event.MouseClickEvent;
|
||||
import de.extio.game_engine.renderer.model.event.MouseEnterEvent;
|
||||
import de.extio.game_engine.renderer.model.event.MouseMoveEvent;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class G2DMainFrame extends Frame {
|
||||
@@ -66,8 +61,8 @@ public class G2DMainFrame extends Frame {
|
||||
this.setLayout(null);
|
||||
this.setBackground(Color.BLACK);
|
||||
|
||||
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream("icon.png")) {
|
||||
final BufferedImage icon = ImageIO.read(in);
|
||||
try (var in = this.getClass().getClassLoader().getResourceAsStream("icon.png")) {
|
||||
final var icon = ImageIO.read(in);
|
||||
this.setIconImage(icon);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
@@ -190,7 +185,7 @@ public class G2DMainFrame extends Frame {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(final MouseEvent e) {
|
||||
final int button = this.getButton(e);
|
||||
final var button = this.getButton(e);
|
||||
|
||||
try {
|
||||
G2DMainFrame.this.rendererData.getEventConsumer().accept(new MouseMoveEvent(false, G2DMainFrame.getModifiers(e), ImmutableCoordI2.create(e.getX(), e.getY()), button));
|
||||
@@ -205,7 +200,7 @@ public class G2DMainFrame extends Frame {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(final MouseEvent e) {
|
||||
final int button = this.getButton(e);
|
||||
final var button = this.getButton(e);
|
||||
|
||||
try {
|
||||
G2DMainFrame.this.rendererData.getEventConsumer().accept(new MouseMoveEvent(true, G2DMainFrame.getModifiers(e), ImmutableCoordI2.create(e.getX(), e.getY()), button));
|
||||
@@ -219,7 +214,7 @@ public class G2DMainFrame extends Frame {
|
||||
}
|
||||
|
||||
private int getButton(final MouseEvent e) {
|
||||
int button = MouseEvent.NOBUTTON;
|
||||
var button = MouseEvent.NOBUTTON;
|
||||
if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0) {
|
||||
button = MouseEvent.BUTTON1;
|
||||
}
|
||||
@@ -250,23 +245,22 @@ public class G2DMainFrame extends Frame {
|
||||
|
||||
@Override
|
||||
public void eventDispatched(final AWTEvent event) {
|
||||
if (!(event instanceof KeyEvent)) {
|
||||
if (!(event instanceof final KeyEvent e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final KeyEvent e = (KeyEvent) event;
|
||||
if (e.getComponent() instanceof G2DControlHasExclusiveKeyEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getID() == KeyEvent.KEY_PRESSED) {
|
||||
LOGGER.trace("Press {} {} {}", e.getKeyCode(), KeyEvent.getKeyText(e.getKeyCode()), G2DMainFrame.getModifiers(e));
|
||||
final KeyStrokeEvent keyPressMessage = new KeyStrokeEvent(false, e.getKeyCode(), KeyEvent.getKeyText(e.getKeyCode()), G2DMainFrame.getModifiers(e));
|
||||
final var keyPressMessage = new KeyStrokeEvent(false, e.getKeyCode(), KeyEvent.getKeyText(e.getKeyCode()), G2DMainFrame.getModifiers(e));
|
||||
G2DMainFrame.this.rendererData.getEventConsumer().accept(keyPressMessage);
|
||||
}
|
||||
else if (event.getID() == KeyEvent.KEY_RELEASED) {
|
||||
LOGGER.trace("Release {} {} {}", e.getKeyCode(), KeyEvent.getKeyText(e.getKeyCode()), G2DMainFrame.getModifiers(e));
|
||||
final KeyStrokeEvent keyPressMessage = new KeyStrokeEvent(true, e.getKeyCode(), KeyEvent.getKeyText(e.getKeyCode()), G2DMainFrame.getModifiers(e));
|
||||
final var keyPressMessage = new KeyStrokeEvent(true, e.getKeyCode(), KeyEvent.getKeyText(e.getKeyCode()), G2DMainFrame.getModifiers(e));
|
||||
G2DMainFrame.this.rendererData.getEventConsumer().accept(keyPressMessage);
|
||||
}
|
||||
}
|
||||
@@ -327,7 +321,7 @@ public class G2DMainFrame extends Frame {
|
||||
}
|
||||
|
||||
private void registerFullScreenWindow(final int screenIdx, final Window window) {
|
||||
final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
final var env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice device;
|
||||
if (screenIdx > -1 && screenIdx < env.getScreenDevices().length) {
|
||||
device = env.getScreenDevices()[screenIdx];
|
||||
@@ -335,7 +329,7 @@ public class G2DMainFrame extends Frame {
|
||||
}
|
||||
else {
|
||||
device = env.getDefaultScreenDevice();
|
||||
for (int i = 0; i < env.getScreenDevices().length; i++) {
|
||||
for (var i = 0; i < env.getScreenDevices().length; i++) {
|
||||
if (device.getIDstring().equals(env.getScreenDevices()[i].getIDstring())) {
|
||||
this.rendererData.getVideoOptions().setFullScreenNumber(i);
|
||||
this.fullScreenIdxRegistered = window != null ? screenIdx : -1;
|
||||
@@ -345,8 +339,8 @@ public class G2DMainFrame extends Frame {
|
||||
}
|
||||
|
||||
if (window != null) {
|
||||
final int x = (int) device.getDefaultConfiguration().getBounds().getWidth();
|
||||
final int y = (int) device.getDefaultConfiguration().getBounds().getHeight();
|
||||
final var x = (int) device.getDefaultConfiguration().getBounds().getWidth();
|
||||
final var y = (int) device.getDefaultConfiguration().getBounds().getHeight();
|
||||
LOGGER.debug("Full screen size: {}x{}", x, y);
|
||||
window.setSize(x, y);
|
||||
}
|
||||
@@ -376,14 +370,14 @@ public class G2DMainFrame extends Frame {
|
||||
}
|
||||
|
||||
private void setupBorderlessWindow(final int screenIdx) {
|
||||
final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
final var env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice device;
|
||||
if (screenIdx > -1 && screenIdx < env.getScreenDevices().length) {
|
||||
device = env.getScreenDevices()[screenIdx];
|
||||
}
|
||||
else {
|
||||
device = env.getDefaultScreenDevice();
|
||||
for (int i = 0; i < env.getScreenDevices().length; i++) {
|
||||
for (var i = 0; i < env.getScreenDevices().length; i++) {
|
||||
if (device.getIDstring().equals(env.getScreenDevices()[i].getIDstring())) {
|
||||
this.rendererData.getVideoOptions().setFullScreenNumber(i);
|
||||
break;
|
||||
@@ -391,10 +385,10 @@ public class G2DMainFrame extends Frame {
|
||||
}
|
||||
}
|
||||
|
||||
final Point location = device.getDefaultConfiguration().getBounds().getLocation();
|
||||
final var location = device.getDefaultConfiguration().getBounds().getLocation();
|
||||
LOGGER.debug("Borderless screen location: {}", location);
|
||||
this.setLocation(location);
|
||||
final Rectangle bounds = device.getDefaultConfiguration().getBounds();
|
||||
final var bounds = device.getDefaultConfiguration().getBounds();
|
||||
LOGGER.debug("Borderless screen size: {}", bounds);
|
||||
this.setSize(bounds.width, bounds.height);
|
||||
|
||||
@@ -408,14 +402,14 @@ public class G2DMainFrame extends Frame {
|
||||
}
|
||||
|
||||
private void applyReferenceWindowGeometry() {
|
||||
final DisplayMode mode = this.getGraphicsConfiguration().getDevice().getDisplayMode();
|
||||
final var mode = this.getGraphicsConfiguration().getDevice().getDisplayMode();
|
||||
final CoordI2 size = ImmutableCoordI2.create(Math.min(mode.getWidth(), RendererControl.REFERENCE_RESOLUTION.getX()), Math.min(mode.getHeight(), RendererControl.REFERENCE_RESOLUTION.getY()));
|
||||
this.setLocation(mode.getWidth() / 2 - size.getX() / 2, mode.getHeight() / 2 - size.getY() / 2);
|
||||
this.setSize(size.getX(), size.getY());
|
||||
}
|
||||
|
||||
private static int getModifiers(final InputEvent event) {
|
||||
int result = 0;
|
||||
var result = 0;
|
||||
|
||||
if (event.isShiftDown()) {
|
||||
result |= KeyModifiers.MODIFIER_SHIFT;
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferStrategy;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -19,9 +18,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.extio.game_engine.renderer.Renderer;
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
import de.extio.game_engine.renderer.RenderingBoPoolImpl;
|
||||
import de.extio.game_engine.renderer.g2d.control.G2DDrawControl;
|
||||
import de.extio.game_engine.renderer.g2d.control.G2DDrawControlTooltip;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DAbstractRenderingBo;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawBackground;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawEffect;
|
||||
@@ -30,7 +28,11 @@ import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFpsHistory;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawImage;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawTest;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawWindow;
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
import de.extio.game_engine.renderer.g2d.control.G2DDrawControl;
|
||||
import de.extio.game_engine.renderer.g2d.control.G2DDrawControlTooltip;
|
||||
import de.extio.game_engine.renderer.model.RenderingBo;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawEffectRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawFontRenderingBo;
|
||||
@@ -38,10 +40,6 @@ import de.extio.game_engine.renderer.model.bo.DrawImageRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawTestRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawWindowRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.event.TakeScreenshotEvent;
|
||||
import de.extio.game_engine.renderer.model.RenderingBo;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
import de.extio.game_engine.util.RingBuffer;
|
||||
|
||||
public class G2DRenderer implements Renderer {
|
||||
@@ -126,7 +124,7 @@ public class G2DRenderer implements Renderer {
|
||||
return;
|
||||
}
|
||||
|
||||
final CoordI2 viewPortDimension = this.rendererData.getRendererControl().getAbsoluteViewportDimension();
|
||||
final var viewPortDimension = this.rendererData.getRendererControl().getAbsoluteViewportDimension();
|
||||
|
||||
if (viewPortDimension.getX() < 10 || viewPortDimension.getY() < 10) {
|
||||
// Some race condition happens rarely (mainly Windows 11) that window size is not initialized after entering full screen. Put a plaster on it...
|
||||
@@ -135,7 +133,7 @@ public class G2DRenderer implements Renderer {
|
||||
|
||||
BufferedImage screenshotImg = null;
|
||||
Graphics2D screenshotGraphics = null;
|
||||
final boolean takeScreenshot_ = this.takeScreenshot;
|
||||
final var takeScreenshot_ = this.takeScreenshot;
|
||||
if (takeScreenshot_) {
|
||||
this.takeScreenshot = false;
|
||||
screenshotImg = this.mainFrame.getGraphicsConfiguration().createCompatibleImage(viewPortDimension.getX(), viewPortDimension.getY());
|
||||
@@ -148,7 +146,7 @@ public class G2DRenderer implements Renderer {
|
||||
|
||||
Graphics2D screenGraphics = null;
|
||||
try {
|
||||
final BufferStrategy bufferStrategy = this.mainFrame.getBufferStrategy();
|
||||
final var bufferStrategy = this.mainFrame.getBufferStrategy();
|
||||
if (bufferStrategy == null) {
|
||||
LOGGER.warn("bufferStrategy == null");
|
||||
return;
|
||||
@@ -223,13 +221,13 @@ public class G2DRenderer implements Renderer {
|
||||
|
||||
// FPS
|
||||
|
||||
final StringBuilder sb = new StringBuilder(15);
|
||||
final var sb = new StringBuilder(15);
|
||||
sb.append(this.fps);
|
||||
sb.append("fps ");
|
||||
sb.append(this.frameDur);
|
||||
sb.append("ms");
|
||||
|
||||
final RenderingBo drawFont = this.rendererData.getRenderingBoPool().acquire(DrawFontRenderingBo.class)
|
||||
final var drawFont = this.rendererData.getRenderingBoPool().acquire(DrawFontRenderingBo.class)
|
||||
.setText(sb.toString())
|
||||
.setSize(14)
|
||||
.setColor(RgbaColor.WHITE)
|
||||
@@ -238,7 +236,7 @@ public class G2DRenderer implements Renderer {
|
||||
renderingBOs.add(drawFont);
|
||||
|
||||
this.fpsHistory.add(Integer.valueOf((int) this.frameDur));
|
||||
final RenderingBo drawFpsHistory = this.rendererData.getRenderingBoPool().acquire(G2DDrawFpsHistory.class)
|
||||
final var drawFpsHistory = this.rendererData.getRenderingBoPool().acquire(G2DDrawFpsHistory.class)
|
||||
.setHistory(this.fpsHistory)
|
||||
.setLayer(RenderingBoLayer.TOP)
|
||||
.withPositionAbsoluteAnchorTopRight(100, 50);
|
||||
@@ -246,7 +244,7 @@ public class G2DRenderer implements Renderer {
|
||||
}
|
||||
|
||||
private void frameCap() throws InterruptedException {
|
||||
final long fpsCurrentTime = System.currentTimeMillis();
|
||||
final var fpsCurrentTime = System.currentTimeMillis();
|
||||
if (fpsCurrentTime - this.fpsMeasurement >= 1000) {
|
||||
this.fpsMeasurement = fpsCurrentTime;
|
||||
this.fps = this.fpsCur;
|
||||
@@ -259,16 +257,16 @@ public class G2DRenderer implements Renderer {
|
||||
if (this.frameStart == 0) {
|
||||
this.frameStart = System.nanoTime();
|
||||
}
|
||||
final long target = this.frameStart + 1000000000L / this.rendererData.getRendererControl().getFrameRate();
|
||||
final var target = this.frameStart + 1000000000L / this.rendererData.getRendererControl().getFrameRate();
|
||||
this.frameDur = (System.nanoTime() - this.frameStart) / 1000000L;
|
||||
final long delta = target - System.nanoTime();
|
||||
final var delta = target - System.nanoTime();
|
||||
spinWait(delta);
|
||||
this.frameStart = System.nanoTime();
|
||||
}
|
||||
|
||||
private static void spinWait(final long nanoDuration) throws InterruptedException {
|
||||
final long end = System.nanoTime() + nanoDuration;
|
||||
long timeLeft = nanoDuration;
|
||||
final var end = System.nanoTime() + nanoDuration;
|
||||
var timeLeft = nanoDuration;
|
||||
do {
|
||||
if (timeLeft > SLEEP_PRECISION) {
|
||||
Thread.sleep(1);
|
||||
@@ -286,7 +284,7 @@ public class G2DRenderer implements Renderer {
|
||||
}
|
||||
|
||||
private void publishScreenshot(final BufferedImage screenshotImg, final Graphics2D screenshotGraphics) {
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
try (var baos = new ByteArrayOutputStream()) {
|
||||
ImageIO.write(screenshotImg, "png", baos);
|
||||
baos.flush();
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class G2DRendererControl implements RendererControl {
|
||||
}
|
||||
}
|
||||
|
||||
final G2DMainFrame mainFrame = new G2DMainFrame(this.rendererData);
|
||||
final var mainFrame = new G2DMainFrame(this.rendererData);
|
||||
if (this.rendererData.getVideoOptions().getVideoMode() == VideoOptionsVideoMode.FULLSCREEN) {
|
||||
mainFrame.fullscreen();
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class G2DRendererControl implements RendererControl {
|
||||
}
|
||||
|
||||
private void updateAbsoluteViewportPortDimension() {
|
||||
final CoordI2 absoluteDim = this.absoluteViewportDimension;
|
||||
final var absoluteDim = this.absoluteViewportDimension;
|
||||
if (absoluteDim == null || absoluteDim.getX() != this.renderer.getMainFrame().getWidth() || absoluteDim.getY() != this.renderer.getMainFrame().getHeight()) {
|
||||
this.absoluteViewportDimension = ImmutableCoordI2.create(this.renderer.getMainFrame().getWidth(), this.renderer.getMainFrame().getHeight());
|
||||
}
|
||||
@@ -204,13 +204,17 @@ public class G2DRendererControl implements RendererControl {
|
||||
|
||||
private void calculateViewportEffectiveDimension() {
|
||||
this.effectiveViewportDimension = ImmutableCoordI2.create((int) (this.absoluteViewportDimension.getX() / this.scaleFactor), (int) (this.absoluteViewportDimension.getY() / this.scaleFactor));
|
||||
if (LOGGER.isDebugEnabled()) LOGGER.debug("Viewport absolute dimension: {}", this.absoluteViewportDimension);
|
||||
if (LOGGER.isDebugEnabled()) LOGGER.debug("Viewport effective dimension: {}", this.effectiveViewportDimension);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Viewport absolute dimension: {}", this.absoluteViewportDimension);
|
||||
}
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Viewport effective dimension: {}", this.effectiveViewportDimension);
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateScaleFactor() {
|
||||
final double fLow = Math.min(this.absoluteViewportDimension.getX() / (double) REFERENCE_RESOLUTION.getX(), this.absoluteViewportDimension.getY() / (double) REFERENCE_RESOLUTION.getY());
|
||||
final double fHigh = Math.min(this.absoluteViewportDimension.getX() / (double) NO_SCALING_UPPER_LIMIT.getX(), this.absoluteViewportDimension.getY() / (double) NO_SCALING_UPPER_LIMIT.getY());
|
||||
final var fLow = Math.min(this.absoluteViewportDimension.getX() / (double) REFERENCE_RESOLUTION.getX(), this.absoluteViewportDimension.getY() / (double) REFERENCE_RESOLUTION.getY());
|
||||
final var fHigh = Math.min(this.absoluteViewportDimension.getX() / (double) NO_SCALING_UPPER_LIMIT.getX(), this.absoluteViewportDimension.getY() / (double) NO_SCALING_UPPER_LIMIT.getY());
|
||||
|
||||
double factor;
|
||||
if (this.isForceAutoScaling()) {
|
||||
@@ -229,7 +233,9 @@ public class G2DRendererControl implements RendererControl {
|
||||
}
|
||||
this.scaleFactor = Math.min(SCALE_FACTOR_MAX, Math.max(SCALE_FACTOR_MIN, factor));
|
||||
|
||||
if (LOGGER.isDebugEnabled()) LOGGER.debug("Viewport scale factor: {}", this.scaleFactor);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Viewport scale factor: {}", this.scaleFactor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,6 @@ package de.extio.game_engine.renderer.g2d.bo.rendering;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.io.FileInputStream;
|
||||
@@ -12,7 +11,6 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
@@ -60,7 +58,7 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
|
||||
|
||||
@Override
|
||||
public void render(final Graphics2D graphics, final double scaleFactor, final boolean force) {
|
||||
final CoordI2 windowDim = ((G2DRendererControl) this.rendererData.getRendererControl()).getAbsoluteViewportDimension();
|
||||
final var windowDim = ((G2DRendererControl) this.rendererData.getRendererControl()).getAbsoluteViewportDimension();
|
||||
|
||||
this.scroll(0, this.rendererData.getUiOptions().isBackgroundScrolling0(), this.rendererData.getUiOptions().isBackgroundScrollingReverse0(), windowDim);
|
||||
this.tileBackground(graphics, 0, this.rendererData.getUiOptions().getBackgroundResourceName0(),
|
||||
@@ -194,7 +192,7 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
|
||||
}
|
||||
G2DDrawBackground.BACKGROUND_IMAGE = null;
|
||||
|
||||
final GraphicsConfiguration gc = graphics.getDeviceConfiguration();
|
||||
final var gc = graphics.getDeviceConfiguration();
|
||||
G2DDrawBackground.BACKGROUND_IMAGE = gc.createCompatibleVolatileImage(G2DDrawBackground.BACKGROUND_BUFFEREDIMAGE.getWidth(), G2DDrawBackground.BACKGROUND_BUFFEREDIMAGE.getHeight());
|
||||
G2DDrawBackground.BACKGROUND_IMAGE.validate(gc);
|
||||
Graphics g = null;
|
||||
@@ -212,9 +210,9 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
|
||||
private void generateStars(final CoordI2 viewPort) {
|
||||
if (!viewPort.equals(this.starsViewport)) {
|
||||
this.starsViewport = viewPort.toImmutableCoordI2();
|
||||
final Random rand = ThreadLocalXorShift128Random.current();
|
||||
final var rand = ThreadLocalXorShift128Random.current();
|
||||
this.stars.clear();
|
||||
for (int i = 0; i < 350; i++) {
|
||||
for (var i = 0; i < 350; i++) {
|
||||
this.stars.add(new Star(
|
||||
ImmutableCoordI2.create(rand.nextInt(this.starsViewport.getX()), rand.nextInt(this.starsViewport.getY())),
|
||||
ImmutableCoordI2.create(rand.nextInt(3) + 2, rand.nextInt(3) + 2),
|
||||
|
||||
@@ -5,23 +5,16 @@ import java.awt.Frame;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.ComponentRenderingSupport;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawEffectRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.DrawEffectRenderingBoEffects;
|
||||
import de.extio.game_engine.renderer.model.RenderingBo;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawEffectRenderingBo;
|
||||
import de.extio.game_engine.spatial2.WorldUtils2;
|
||||
import de.extio.game_engine.spatial2.model.Area2;
|
||||
import de.extio.game_engine.spatial2.model.CoordD2;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
import de.extio.game_engine.spatial2.model.ImmutableCoordD2;
|
||||
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
|
||||
import de.extio.game_engine.spatial2.model.MutableCoordD2;
|
||||
import de.extio.game_engine.spatial2.model.MutableCoordI2;
|
||||
|
||||
public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectRenderingBo {
|
||||
@@ -46,8 +39,8 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
return;
|
||||
}
|
||||
|
||||
int x0 = (int) (this.x * scaleFactor);
|
||||
int y0 = (int) (this.y * scaleFactor);
|
||||
final var x0 = (int) (this.x * scaleFactor);
|
||||
final var y0 = (int) (this.y * scaleFactor);
|
||||
|
||||
List<CoordI2> coordinates = null;
|
||||
if (this.relativeCoordinates != null && !this.relativeCoordinates.isEmpty()) {
|
||||
@@ -62,10 +55,10 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
if (coordinates == null || coordinates.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
final int x1 = x0 + coordinates.get(0).getX();
|
||||
final int y1 = y0 + coordinates.get(0).getY();
|
||||
final var x1 = x0 + coordinates.get(0).getX();
|
||||
final var y1 = y0 + coordinates.get(0).getY();
|
||||
|
||||
final Area2 area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
|
||||
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
|
||||
if (this.cull(area)) {
|
||||
break;
|
||||
}
|
||||
@@ -81,10 +74,10 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
if (coordinates == null || coordinates.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
final int x1 = x0 + coordinates.get(0).getX();
|
||||
final int y1 = y0 + coordinates.get(0).getY();
|
||||
final var x1 = x0 + coordinates.get(0).getX();
|
||||
final var y1 = y0 + coordinates.get(0).getY();
|
||||
|
||||
final Area2 area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
|
||||
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
|
||||
if (this.cull(area)) {
|
||||
break;
|
||||
}
|
||||
@@ -102,9 +95,9 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
|
||||
case CIRCLE:
|
||||
case CIRCLE_FILLED: {
|
||||
final int diameter = Math.max(3, (int) Math.round(this.customInt0 * scaleFactor));
|
||||
final var diameter = Math.max(3, (int) Math.round(this.customInt0 * scaleFactor));
|
||||
|
||||
final Area2 area = new Area2(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(diameter, diameter));
|
||||
final var area = new Area2(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(diameter, diameter));
|
||||
if (this.cull(area)) {
|
||||
break;
|
||||
}
|
||||
@@ -122,9 +115,9 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
|
||||
case CIRCLE_CENTERED:
|
||||
case CIRCLE_CENTERED_FILLED: {
|
||||
final int radius = Math.max(3, (int) Math.round(this.customInt0 * scaleFactor));
|
||||
final var radius = Math.max(3, (int) Math.round(this.customInt0 * scaleFactor));
|
||||
|
||||
final Area2 area = new Area2(ImmutableCoordI2.create(x0, y0).substract(radius), ImmutableCoordI2.zero().add(radius * 2));
|
||||
final var area = new Area2(ImmutableCoordI2.create(x0, y0).substract(radius), ImmutableCoordI2.zero().add(radius * 2));
|
||||
if (this.cull(area)) {
|
||||
break;
|
||||
}
|
||||
@@ -144,21 +137,21 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
if (coordinates == null || coordinates.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
final int x1 = x0 + coordinates.get(0).getX();
|
||||
final int y1 = y0 + coordinates.get(0).getY();
|
||||
final var x1 = x0 + coordinates.get(0).getX();
|
||||
final var y1 = y0 + coordinates.get(0).getY();
|
||||
|
||||
final double width = Math.max(1, Math.max(Math.abs(x0 - x1), Math.abs(y0 - y1)) / 5);
|
||||
final double height = width;
|
||||
final int dx = x1 - x0;
|
||||
final int dy = y1 - y0;
|
||||
final double D = Math.max(1.0, Math.sqrt(Math.pow(dx, 2.0) + Math.pow(dy, 2.0)));
|
||||
double xm = D - width;
|
||||
double xn = xm;
|
||||
double ym = height;
|
||||
double yn = -height;
|
||||
final var height = width;
|
||||
final var dx = x1 - x0;
|
||||
final var dy = y1 - y0;
|
||||
final var D = Math.max(1.0, Math.sqrt(Math.pow(dx, 2.0) + Math.pow(dy, 2.0)));
|
||||
var xm = D - width;
|
||||
var xn = xm;
|
||||
var ym = height;
|
||||
var yn = -height;
|
||||
double x;
|
||||
final double sin = dy / D;
|
||||
final double cos = dx / D;
|
||||
final var sin = dy / D;
|
||||
final var cos = dx / D;
|
||||
|
||||
x = xm * cos - ym * sin + x0;
|
||||
ym = xm * sin + ym * cos + y0;
|
||||
@@ -168,7 +161,7 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
yn = xn * sin + yn * cos + y0;
|
||||
xn = x;
|
||||
|
||||
final Area2 area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1), ImmutableCoordI2.create((int) xm, (int) ym), ImmutableCoordI2.create((int) xn, (int) yn));
|
||||
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1), ImmutableCoordI2.create((int) xm, (int) ym), ImmutableCoordI2.create((int) xn, (int) yn));
|
||||
if (this.cull(area)) {
|
||||
break;
|
||||
}
|
||||
@@ -185,12 +178,12 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
if (coordinates == null || coordinates.size() < 2) {
|
||||
break;
|
||||
}
|
||||
final int x1 = x0 + coordinates.get(0).getX();
|
||||
final int y1 = y0 + coordinates.get(0).getY();
|
||||
final int x2 = x0 + coordinates.get(1).getX();
|
||||
final int y2 = y0 + coordinates.get(1).getY();
|
||||
final var x1 = x0 + coordinates.get(0).getX();
|
||||
final var y1 = y0 + coordinates.get(0).getY();
|
||||
final var x2 = x0 + coordinates.get(1).getX();
|
||||
final var y2 = y0 + coordinates.get(1).getY();
|
||||
|
||||
final Area2 area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1), ImmutableCoordI2.create(x2, y2));
|
||||
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1), ImmutableCoordI2.create(x2, y2));
|
||||
if (this.cull(area)) {
|
||||
break;
|
||||
}
|
||||
@@ -207,15 +200,15 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
||||
if (coordinates == null || coordinates.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
final int x1 = x0 + coordinates.get(0).getX();
|
||||
final int y1 = y0 + coordinates.get(0).getY();
|
||||
final var x1 = x0 + coordinates.get(0).getX();
|
||||
final var y1 = y0 + coordinates.get(0).getY();
|
||||
|
||||
final Area2 area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
|
||||
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
|
||||
if (this.cull(area)) {
|
||||
break;
|
||||
}
|
||||
|
||||
final int strength = this.customInt0 <= 0 ? 2 : this.customInt0;
|
||||
final var strength = this.customInt0 <= 0 ? 2 : this.customInt0;
|
||||
|
||||
if (this.effect == DrawEffectRenderingBoEffects.DECORATIVE_BORDER) {
|
||||
ComponentRenderingSupport.drawDecorativeBorder(graphics, area.getPosition().getX(), area.getPosition().getY(), area.getDimension().getX(), area.getDimension().getY(), strength, this.color == null ? Color.WHITE : this.color.toAwtColor());
|
||||
|
||||
@@ -4,15 +4,13 @@ import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import de.extio.game_engine.renderer.model.bo.DrawFontRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.DrawFontRenderingBoTextAlignment;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawFontRenderingBo;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
|
||||
import de.extio.game_engine.spatial2.model.MutableCoordI2;
|
||||
@@ -81,13 +79,13 @@ public class G2DDrawFont extends G2DAbstractRenderingBo implements DrawFontRende
|
||||
break;
|
||||
|
||||
case CENTER: {
|
||||
final CoordI2 textDim = G2DDrawFont.getTextDimensions(this.text, graphics, this.size, 1.0);
|
||||
final var textDim = G2DDrawFont.getTextDimensions(this.text, graphics, this.size, 1.0);
|
||||
renderText(graphics, textDim, scaleFactor, (this.width - textDim.getX()) / 2 + this.x, this.y, this.size, this.text);
|
||||
break;
|
||||
}
|
||||
|
||||
case RIGHT: {
|
||||
final CoordI2 textDim = G2DDrawFont.getTextDimensions(this.text, graphics, this.size, 1.0);
|
||||
final var textDim = G2DDrawFont.getTextDimensions(this.text, graphics, this.size, 1.0);
|
||||
renderText(graphics, textDim, scaleFactor, this.width - textDim.getX() + this.x, this.y, this.size, this.text);
|
||||
break;
|
||||
}
|
||||
@@ -106,8 +104,8 @@ public class G2DDrawFont extends G2DAbstractRenderingBo implements DrawFontRende
|
||||
}
|
||||
|
||||
public static Font getFont(final double scaleFactor, final int size_) {
|
||||
final int size = size_ == 0 ? FONT_SIZE_DEFAULT : size_;
|
||||
final float sizeScaled = Math.max(FONT_SIZE_MIN, (float) (size * scaleFactor));
|
||||
final var size = size_ == 0 ? FONT_SIZE_DEFAULT : size_;
|
||||
final var sizeScaled = Math.max(FONT_SIZE_MIN, (float) (size * scaleFactor));
|
||||
return baseFont.deriveFont(sizeScaled);
|
||||
}
|
||||
|
||||
@@ -120,9 +118,9 @@ public class G2DDrawFont extends G2DAbstractRenderingBo implements DrawFontRende
|
||||
return;
|
||||
}
|
||||
|
||||
final int size = size_ == 0 ? FONT_SIZE_DEFAULT : size_;
|
||||
final float sizeScaled = Math.max(FONT_SIZE_MIN, (float) (size * scaleFactor));
|
||||
final Font font = baseFont.deriveFont(sizeScaled);
|
||||
final var size = size_ == 0 ? FONT_SIZE_DEFAULT : size_;
|
||||
final var sizeScaled = Math.max(FONT_SIZE_MIN, (float) (size * scaleFactor));
|
||||
final var font = baseFont.deriveFont(sizeScaled);
|
||||
CoordI2 textDim;
|
||||
if (textDim_ == null) {
|
||||
textDim = getTextDimensions(text, graphics, size_, scaleFactor);
|
||||
@@ -139,11 +137,11 @@ public class G2DDrawFont extends G2DAbstractRenderingBo implements DrawFontRende
|
||||
return ImmutableCoordI2.one();
|
||||
}
|
||||
|
||||
final int size = size_ == 0 ? FONT_SIZE_DEFAULT : size_;
|
||||
final float sizeScaled = Math.max(FONT_SIZE_MIN, (float) (size * scaleFactor));
|
||||
final Font font = baseFont.deriveFont(sizeScaled);
|
||||
final GlyphVector gv = font.layoutGlyphVector(((Graphics2D) graphics).getFontRenderContext(), text.toCharArray(), 0, text.length(), Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
final Rectangle pixBounds = gv.getPixelBounds(((Graphics2D) graphics).getFontRenderContext(), 0, 0);
|
||||
final var size = size_ == 0 ? FONT_SIZE_DEFAULT : size_;
|
||||
final var sizeScaled = Math.max(FONT_SIZE_MIN, (float) (size * scaleFactor));
|
||||
final var font = baseFont.deriveFont(sizeScaled);
|
||||
final var gv = font.layoutGlyphVector(((Graphics2D) graphics).getFontRenderContext(), text.toCharArray(), 0, text.length(), Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
final var pixBounds = gv.getPixelBounds(((Graphics2D) graphics).getFontRenderContext(), 0, 0);
|
||||
return MutableCoordI2.create(pixBounds.x + pixBounds.width, pixBounds.height - (int) pixBounds.getMaxY());
|
||||
}
|
||||
|
||||
|
||||
@@ -33,14 +33,14 @@ public class G2DDrawFpsHistory extends G2DAbstractRenderingBo {
|
||||
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate());
|
||||
}
|
||||
|
||||
final int x = (int) (this.x * scaleFactor);
|
||||
final int y = (int) (this.y * scaleFactor);
|
||||
int i = 0;
|
||||
final var x = (int) (this.x * scaleFactor);
|
||||
final var y = (int) (this.y * scaleFactor);
|
||||
var i = 0;
|
||||
for (final Integer val : this.history) {
|
||||
if (val == null) {
|
||||
continue;
|
||||
}
|
||||
final int val_ = Math.max(1, Math.min((int) (100 * scaleFactor), (int) (val.intValue() * scaleFactor)));
|
||||
final var val_ = Math.max(1, Math.min((int) (100 * scaleFactor), (int) (val.intValue() * scaleFactor)));
|
||||
|
||||
if (val_ < this.thresholds[0]) {
|
||||
graphics.setColor(Color.DARK_GRAY);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package de.extio.game_engine.renderer.g2d.bo.rendering;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -9,15 +8,13 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawImageRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.RenderingBo;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawImageRenderingBo;
|
||||
|
||||
public class G2DDrawImage extends G2DAbstractRenderingBo implements DrawImageRenderingBo {
|
||||
|
||||
@@ -60,7 +57,7 @@ public class G2DDrawImage extends G2DAbstractRenderingBo implements DrawImageRen
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public void render(final Graphics2D graphics, final double scaleFactor, final boolean force) {
|
||||
CachedImage cachedImage = IMAGE_CACHE.get(this.resourceName);
|
||||
var cachedImage = IMAGE_CACHE.get(this.resourceName);
|
||||
if (cachedImage == null) {
|
||||
cachedImage = new CachedImage();
|
||||
cachedImage.setName(this.resourceName);
|
||||
@@ -90,9 +87,9 @@ public class G2DDrawImage extends G2DAbstractRenderingBo implements DrawImageRen
|
||||
}
|
||||
|
||||
if (this.transparency < 1.0f) {
|
||||
final Composite currentAlphaComposite = graphics.getComposite();
|
||||
final var currentAlphaComposite = graphics.getComposite();
|
||||
try {
|
||||
AlphaComposite ac = cachedImage.getAlphaComposite();
|
||||
var ac = cachedImage.getAlphaComposite();
|
||||
if (ac == null) {
|
||||
ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.transparency);
|
||||
cachedImage.setAlphaComposite(ac);
|
||||
@@ -124,9 +121,9 @@ public class G2DDrawImage extends G2DAbstractRenderingBo implements DrawImageRen
|
||||
}
|
||||
|
||||
public static void closeStatic() {
|
||||
final Iterator<CachedImage> it = IMAGE_CACHE.values().iterator();
|
||||
final var it = IMAGE_CACHE.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
final CachedImage cachedImage = it.next();
|
||||
final var cachedImage = it.next();
|
||||
if (!cachedImage.isUsed()) {
|
||||
LOGGER.debug("Removed image from cache: " + cachedImage.getName());
|
||||
|
||||
@@ -209,7 +206,7 @@ public class G2DDrawImage extends G2DAbstractRenderingBo implements DrawImageRen
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final var builder = new StringBuilder();
|
||||
builder.append("CachedImage [name=");
|
||||
builder.append(this.name);
|
||||
builder.append(", used=");
|
||||
|
||||
@@ -2,8 +2,8 @@ package de.extio.game_engine.renderer.g2d.bo.rendering;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import de.extio.game_engine.renderer.model.bo.DrawTestRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawTestRenderingBo;
|
||||
|
||||
public class G2DDrawTest extends G2DAbstractRenderingBo implements DrawTestRenderingBo {
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package de.extio.game_engine.renderer.g2d.bo.rendering;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.control.components.ComponentRenderingSupport;
|
||||
@@ -29,24 +28,24 @@ public class G2DDrawWindow extends G2DAbstractRenderingBo implements DrawWindowR
|
||||
|
||||
@Override
|
||||
public void render(final Graphics2D graphics, final double scaleFactor, final boolean force) {
|
||||
final int sx = (int) (this.x * scaleFactor);
|
||||
final int sy = (int) (this.y * scaleFactor);
|
||||
final int sw = (int) (this.width * scaleFactor);
|
||||
final int sh = (int) (this.height * scaleFactor);
|
||||
final int strength = Math.max(2, (int) (3 * scaleFactor));
|
||||
final var sx = (int) (this.x * scaleFactor);
|
||||
final var sy = (int) (this.y * scaleFactor);
|
||||
final var sw = (int) (this.width * scaleFactor);
|
||||
final var sh = (int) (this.height * scaleFactor);
|
||||
final var strength = Math.max(2, (int) (3 * scaleFactor));
|
||||
if (this.color == null) {
|
||||
this.color = COLOR_WINDOW;
|
||||
}
|
||||
|
||||
final Color cMain = this.color.toAwtColor();
|
||||
final RgbaColor rgbaDarker = new RgbaColor(cMain);
|
||||
final var cMain = this.color.toAwtColor();
|
||||
final var rgbaDarker = new RgbaColor(cMain);
|
||||
rgbaDarker.setR(rgbaDarker.getR() / 2);
|
||||
rgbaDarker.setG(rgbaDarker.getG() / 2);
|
||||
rgbaDarker.setB(rgbaDarker.getB() / 2);
|
||||
final Color cDarker = rgbaDarker.toAwtColor();
|
||||
final var cDarker = rgbaDarker.toAwtColor();
|
||||
|
||||
if (this.thickBorder) {
|
||||
final int borderStrength = strength * 2;
|
||||
final var borderStrength = strength * 2;
|
||||
graphics.setColor(cMain);
|
||||
graphics.fillRect(sx + strength * 2, sy + strength * 2, sw - strength * 4, borderStrength);
|
||||
graphics.setColor(cDarker);
|
||||
|
||||
@@ -2,19 +2,17 @@ package de.extio.game_engine.renderer.g2d.bo.rendering;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawWindowRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.ImmutableRgbaColor;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.DrawWindowRenderingBo;
|
||||
|
||||
public class G2DDrawWindow2 extends G2DAbstractRenderingBo implements DrawWindowRenderingBo {
|
||||
|
||||
@@ -51,10 +49,10 @@ public class G2DDrawWindow2 extends G2DAbstractRenderingBo implements DrawWindow
|
||||
LAST_SCALEFACTOR = scaleFactor;
|
||||
}
|
||||
|
||||
final Long key = Long.valueOf((long) this.width | ((long) this.height << 12) | ((this.thickBorder ? 1L : 0L) << 24) | ((long) this.awtColor.getRGB() << 32));
|
||||
G2DWindowCacheEntry entry = CACHE.get(key);
|
||||
final var key = Long.valueOf((long) this.width | ((long) this.height << 12) | ((this.thickBorder ? 1L : 0L) << 24) | ((long) this.awtColor.getRGB() << 32));
|
||||
var entry = CACHE.get(key);
|
||||
if (entry == null) {
|
||||
final BufferedImage img = ((G2DRenderer) this.rendererData.getRenderer()).getMainFrame().getGraphicsConfiguration().createCompatibleImage((int) (this.width * scaleFactor), (int) (this.height * scaleFactor), Transparency.TRANSLUCENT);
|
||||
final var img = ((G2DRenderer) this.rendererData.getRenderer()).getMainFrame().getGraphicsConfiguration().createCompatibleImage((int) (this.width * scaleFactor), (int) (this.height * scaleFactor), Transparency.TRANSLUCENT);
|
||||
this.paintWindow(img, scaleFactor);
|
||||
|
||||
entry = new G2DWindowCacheEntry();
|
||||
@@ -64,7 +62,7 @@ public class G2DDrawWindow2 extends G2DAbstractRenderingBo implements DrawWindow
|
||||
}
|
||||
entry.setUsed(true);
|
||||
|
||||
final Composite currentAlphaComposite = graphics.getComposite();
|
||||
final var currentAlphaComposite = graphics.getComposite();
|
||||
try {
|
||||
if (alphaComposite == null) {
|
||||
alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6F);
|
||||
@@ -87,9 +85,9 @@ public class G2DDrawWindow2 extends G2DAbstractRenderingBo implements DrawWindow
|
||||
}
|
||||
|
||||
public static void closeStatic() {
|
||||
final Iterator<G2DWindowCacheEntry> it = CACHE.values().iterator();
|
||||
final var it = CACHE.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
final G2DWindowCacheEntry entry = it.next();
|
||||
final var entry = it.next();
|
||||
if (!entry.isUsed()) {
|
||||
entry.close();
|
||||
it.remove();
|
||||
@@ -101,15 +99,15 @@ public class G2DDrawWindow2 extends G2DAbstractRenderingBo implements DrawWindow
|
||||
}
|
||||
|
||||
private void paintWindow(final BufferedImage img, final double scaleFactor) {
|
||||
final Graphics2D imgGraphics = img.createGraphics();
|
||||
final var imgGraphics = img.createGraphics();
|
||||
try {
|
||||
final int swidth = (int) (this.width * scaleFactor);
|
||||
final int sheight = (int) (this.height * scaleFactor);
|
||||
final float[] baseColor = new float[3];
|
||||
final var swidth = (int) (this.width * scaleFactor);
|
||||
final var sheight = (int) (this.height * scaleFactor);
|
||||
final var baseColor = new float[3];
|
||||
this.awtColor.getRGBColorComponents(baseColor);
|
||||
Color.RGBtoHSB((int) (baseColor[0] * 255), (int) (baseColor[1] * 255), (int) (baseColor[2] * 255), baseColor);
|
||||
|
||||
final int size = (int) (5 * scaleFactor);
|
||||
final var size = (int) (5 * scaleFactor);
|
||||
|
||||
imgGraphics.setColor(Color.BLACK);
|
||||
imgGraphics.fillRect(0, size, swidth, sheight - size * 3);
|
||||
@@ -131,7 +129,7 @@ public class G2DDrawWindow2 extends G2DAbstractRenderingBo implements DrawWindow
|
||||
imgGraphics.fillPolygon(new int[] { swidth, swidth - size * 2, swidth - size * 2, swidth - size }, new int[] { sheight - size * 2, sheight, sheight - size, sheight - size * 2 }, 4);
|
||||
|
||||
if (this.thickBorder) {
|
||||
for (int i = 0; i < size * 2; i++) {
|
||||
for (var i = 0; i < size * 2; i++) {
|
||||
imgGraphics.setColor(Color.getHSBColor(baseColor[0], baseColor[1], baseColor[2] * ((0.5F / (size * 2) * i) + 0.5F)));
|
||||
imgGraphics.drawLine(0, i, swidth, i);
|
||||
}
|
||||
|
||||
@@ -3,14 +3,13 @@ package de.extio.game_engine.renderer.g2d.control;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DAbstractRenderingBo;
|
||||
import de.extio.game_engine.renderer.g2d.control.impl.G2DBaseControlImpl;
|
||||
import de.extio.game_engine.renderer.g2d.control.impl.G2DButtonControlImpl;
|
||||
import de.extio.game_engine.renderer.g2d.control.impl.G2DLabelControlImpl;
|
||||
@@ -22,14 +21,10 @@ import de.extio.game_engine.renderer.g2d.control.impl.G2DTextfieldControlImpl2;
|
||||
import de.extio.game_engine.renderer.g2d.control.impl.G2DToggleButtonControlImpl;
|
||||
import de.extio.game_engine.renderer.g2d.control.impl.G2DTooltipControl;
|
||||
import de.extio.game_engine.renderer.g2d.control.impl.G2DWindowCloseButtonControlImpl;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DAbstractRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo;
|
||||
import de.extio.game_engine.renderer.model.DrawFontRenderingBoTextAlignment;
|
||||
import de.extio.game_engine.renderer.model.RenderingBo;
|
||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo;
|
||||
|
||||
public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRenderingBo {
|
||||
|
||||
@@ -146,7 +141,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
||||
|
||||
@Override
|
||||
public void render(final Graphics2D graphics, final double scaleFactor, final boolean force) {
|
||||
G2DBaseControlImpl control = (G2DBaseControlImpl) CACHED_CONTROLS.get(this.id);
|
||||
var control = (G2DBaseControlImpl) CACHED_CONTROLS.get(this.id);
|
||||
if (control == null) {
|
||||
if (this.clazz == ButtonControl.class) {
|
||||
control = new G2DButtonControlImpl();
|
||||
@@ -199,7 +194,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
||||
|
||||
CACHED_CONTROLS.put(this.id, control);
|
||||
if (this.controlGroup != null && !this.controlGroup.isEmpty()) {
|
||||
List<BaseControl> controls = CONTROL_GROUPS.get(this.controlGroup);
|
||||
var controls = CONTROL_GROUPS.get(this.controlGroup);
|
||||
if (controls == null) {
|
||||
controls = new ArrayList<>();
|
||||
CONTROL_GROUPS.put(this.controlGroup, controls);
|
||||
@@ -330,15 +325,15 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
||||
}
|
||||
|
||||
public static void closeStatic() {
|
||||
final Iterator<BaseControl> it = CACHED_CONTROLS.values().iterator();
|
||||
final var it = CACHED_CONTROLS.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
final BaseControl control = it.next();
|
||||
final var control = it.next();
|
||||
if (control.getInUse()) {
|
||||
control.setInUse(false);
|
||||
}
|
||||
else {
|
||||
if (control.getControlGroup() != null && !control.getControlGroup().isEmpty()) {
|
||||
final List<BaseControl> controls = CONTROL_GROUPS.get(control.getControlGroup());
|
||||
final var controls = CONTROL_GROUPS.get(control.getControlGroup());
|
||||
if (controls != null) {
|
||||
controls.remove(control);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
|
||||
public class G2DDrawControlTooltip extends G2DAbstractRenderingBo {
|
||||
|
||||
public static record TooltipRecord(CoordI2 position, String text) {}
|
||||
public static record TooltipRecord(CoordI2 position, String text) {
|
||||
}
|
||||
|
||||
public static TooltipRecord TOOLTIP = null;
|
||||
|
||||
@@ -27,7 +28,7 @@ public class G2DDrawControlTooltip extends G2DAbstractRenderingBo {
|
||||
return;
|
||||
}
|
||||
|
||||
final CoordI2 textDim = G2DDrawFont.getTextDimensions(TOOLTIP.text(), graphics, 14, scaleFactor);
|
||||
final var textDim = G2DDrawFont.getTextDimensions(TOOLTIP.text(), graphics, 14, scaleFactor);
|
||||
|
||||
graphics.setColor(BACKGROUND);
|
||||
graphics.fillRect(TOOLTIP.position().getX(), TOOLTIP.position().getY(), textDim.getX() + 20, textDim.getY() + 20);
|
||||
|
||||
@@ -5,7 +5,8 @@ import java.awt.Graphics2D;
|
||||
|
||||
public class ComponentRenderingSupport {
|
||||
|
||||
public final static record HSB(float h, float s, float b) {}
|
||||
public final static record HSB(float h, float s, float b) {
|
||||
}
|
||||
|
||||
public final static HSB HSB_COMPONENT_BORDER0 = new HSB(0.71f, 0.12f, 0.50f);
|
||||
|
||||
@@ -34,8 +35,8 @@ public class ComponentRenderingSupport {
|
||||
public final static Color COLOR_WINDOW_BGR = new Color(0, 0, 0, 180);
|
||||
|
||||
public static void drawDecorativeBorder(final Graphics2D g2d, final int x, final int y, final int w, final int h, final int strength, final Color color) {
|
||||
final int strength2 = strength * 2;
|
||||
final int strength4 = strength * 4;
|
||||
final var strength2 = strength * 2;
|
||||
final var strength4 = strength * 4;
|
||||
|
||||
g2d.setColor(color);
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class CustomButton extends CustomAbstractButton {
|
||||
@@ -17,12 +16,12 @@ public class CustomButton extends CustomAbstractButton {
|
||||
|
||||
@Override
|
||||
public void paint(final Graphics g) {
|
||||
final Graphics2D g2d = (Graphics2D) g;
|
||||
final var g2d = (Graphics2D) g;
|
||||
|
||||
float h, s, b;
|
||||
|
||||
final int borderStrength = (this.getWidth() < 48 || this.getHeight() < 48) ? 1 : 2;
|
||||
final int bgrStrength = (this.getWidth() < 48 || this.getHeight() < 48) ? 0 : 2;
|
||||
final var borderStrength = (this.getWidth() < 48 || this.getHeight() < 48) ? 1 : 2;
|
||||
final var bgrStrength = (this.getWidth() < 48 || this.getHeight() < 48) ? 0 : 2;
|
||||
|
||||
if (this.backgroundColor == null) {
|
||||
if ((this.state & STATE_TOGGLED) == 0) {
|
||||
@@ -43,7 +42,7 @@ public class CustomButton extends CustomAbstractButton {
|
||||
}
|
||||
}
|
||||
else {
|
||||
final float[] hsb = new float[3];
|
||||
final var hsb = new float[3];
|
||||
Color.RGBtoHSB(this.backgroundColor.getRed(), this.backgroundColor.getGreen(), this.backgroundColor.getBlue(), hsb);
|
||||
h = hsb[0];
|
||||
s = hsb[1];
|
||||
@@ -80,7 +79,7 @@ public class CustomButton extends CustomAbstractButton {
|
||||
else {
|
||||
g2d.setColor(Color.GRAY);
|
||||
}
|
||||
final CoordI2 textDim = G2DDrawFont.getTextDimensions(this.caption, g2d, this.fontSize, this.scaleFactor);
|
||||
final var textDim = G2DDrawFont.getTextDimensions(this.caption, g2d, this.fontSize, this.scaleFactor);
|
||||
G2DDrawFont.renderText(g2d,
|
||||
textDim,
|
||||
this.scaleFactor,
|
||||
@@ -90,7 +89,7 @@ public class CustomButton extends CustomAbstractButton {
|
||||
this.caption);
|
||||
}
|
||||
|
||||
Color color = (this.state & STATE_HOVERED) != 0 ? ComponentRenderingSupport.COLOR_COMPONENT_SELECTED_0 : ComponentRenderingSupport.COLOR_COMPONENT_BORDER0;
|
||||
var color = (this.state & STATE_HOVERED) != 0 ? ComponentRenderingSupport.COLOR_COMPONENT_SELECTED_0 : ComponentRenderingSupport.COLOR_COMPONENT_BORDER0;
|
||||
ComponentRenderingSupport.drawDecorativeBorder(g2d, 0, 0, this.getWidth() - 1, this.getHeight() - 1, borderStrength, color);
|
||||
color = this.isEnabled() ? (this.state & STATE_HOVERED) != 0 ? ComponentRenderingSupport.COLOR_COMPONENT_SELECTED_1 : ComponentRenderingSupport.COLOR_COMPONENT_BORDER1 : ComponentRenderingSupport.COLOR_COMPONENT_BORDER1_DIS;
|
||||
ComponentRenderingSupport.drawDecorativeBorder(g2d, borderStrength, borderStrength, this.getWidth() - 1 - 2 * borderStrength, this.getHeight() - 1 - 2 * borderStrength, borderStrength, color);
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.extio.game_engine.renderer.g2d.control.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.RepaintManager;
|
||||
@@ -50,7 +49,7 @@ public class CustomJTextField extends JTextField implements G2DControlHasExclusi
|
||||
|
||||
if (this.isFocusOwner()) {
|
||||
try {
|
||||
final Rectangle2D rect = this.getUI().modelToView2D(this, this.getCaret().getDot(), Bias.Forward);
|
||||
final var rect = this.getUI().modelToView2D(this, this.getCaret().getDot(), Bias.Forward);
|
||||
if (rect != null) {
|
||||
this.drawGraphics.setColor((System.currentTimeMillis() % 1000 < 500) ? CARET_COLOR : CARET_COLOR2);
|
||||
this.drawGraphics.fillRect((int) rect.getX(), (int) rect.getY(), Math.max(2, (int) rect.getWidth()), Math.max(6, (int) rect.getHeight()));
|
||||
|
||||
@@ -146,7 +146,7 @@ public class CustomLabel extends Component {
|
||||
|
||||
@Override
|
||||
public void paint(final Graphics g) {
|
||||
final Graphics2D g2d = (Graphics2D) g;
|
||||
final var g2d = (Graphics2D) g;
|
||||
|
||||
if (this.backgroundColor != null) {
|
||||
g2d.setColor(this.backgroundColor);
|
||||
@@ -160,7 +160,7 @@ public class CustomLabel extends Component {
|
||||
b = 0.80F;
|
||||
}
|
||||
else {
|
||||
final float[] hsb = Color.RGBtoHSB(this.foregroundColor.getRed(), this.foregroundColor.getGreen(), this.foregroundColor.getBlue(), null);
|
||||
final var hsb = Color.RGBtoHSB(this.foregroundColor.getRed(), this.foregroundColor.getGreen(), this.foregroundColor.getBlue(), null);
|
||||
h = hsb[0];
|
||||
s = hsb[1];
|
||||
b = hsb[2];
|
||||
@@ -183,8 +183,8 @@ public class CustomLabel extends Component {
|
||||
b = Math.max(0.0f, Math.min(1.0f, b));
|
||||
g2d.setColor(Color.getHSBColor(h, s, b));
|
||||
|
||||
final DrawFontRenderingBoTextAlignment alignment = this.textAlignment == null ? DrawFontRenderingBoTextAlignment.CENTER : this.textAlignment;
|
||||
final CoordI2 textDim = G2DDrawFont.getTextDimensions(this.caption, g2d, this.fontSize, this.scaleFactor);
|
||||
final var alignment = this.textAlignment == null ? DrawFontRenderingBoTextAlignment.CENTER : this.textAlignment;
|
||||
final var textDim = G2DDrawFont.getTextDimensions(this.caption, g2d, this.fontSize, this.scaleFactor);
|
||||
switch (alignment) {
|
||||
case LEFT: {
|
||||
G2DDrawFont.renderText(g2d,
|
||||
|
||||
@@ -143,7 +143,7 @@ public class CustomSlider extends Component {
|
||||
}
|
||||
|
||||
private void action(final MouseEvent e) {
|
||||
double value = CustomSlider.this.horizontal ? ((double) e.getX() / (double) CustomSlider.this.getWidth()) : (1.0 - ((double) e.getY() / (double) CustomSlider.this.getHeight()));
|
||||
var value = CustomSlider.this.horizontal ? ((double) e.getX() / (double) CustomSlider.this.getWidth()) : (1.0 - ((double) e.getY() / (double) CustomSlider.this.getHeight()));
|
||||
value = Math.min(1.0, Math.max(0.0, value));
|
||||
CustomSlider.this.setValue(value);
|
||||
synchronized (this) {
|
||||
@@ -168,7 +168,7 @@ public class CustomSlider extends Component {
|
||||
|
||||
@Override
|
||||
public void paint(final Graphics g) {
|
||||
final Graphics2D g2d = (Graphics2D) g;
|
||||
final var g2d = (Graphics2D) g;
|
||||
|
||||
float h, s, b;
|
||||
if (this.color == null) {
|
||||
@@ -177,7 +177,7 @@ public class CustomSlider extends Component {
|
||||
b = 0.80F;
|
||||
}
|
||||
else {
|
||||
final float[] hsb = Color.RGBtoHSB(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), null);
|
||||
final var hsb = Color.RGBtoHSB(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), null);
|
||||
h = hsb[0];
|
||||
s = hsb[1];
|
||||
b = hsb[2];
|
||||
@@ -196,9 +196,9 @@ public class CustomSlider extends Component {
|
||||
|
||||
// Small lines
|
||||
b -= 0.20F;
|
||||
final int length = this.horizontal ? this.getWidth() : this.getHeight();
|
||||
for (int i = 1; i < 10; i++) {
|
||||
final int pos = (int) ((double) length / 10.0 * i);
|
||||
final var length = this.horizontal ? this.getWidth() : this.getHeight();
|
||||
for (var i = 1; i < 10; i++) {
|
||||
final var pos = (int) ((double) length / 10.0 * i);
|
||||
if (this.horizontal) {
|
||||
this.drawLine(g2d, h, s, b, pos, this.getHeight() / 4, pos, this.getHeight() / 4 * 3, !this.horizontal);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class CustomSwitch extends CustomAbstractButton {
|
||||
@@ -19,10 +18,10 @@ public class CustomSwitch extends CustomAbstractButton {
|
||||
|
||||
@Override
|
||||
public void paint(final Graphics g) {
|
||||
final Graphics2D g2d = (Graphics2D) g;
|
||||
final var g2d = (Graphics2D) g;
|
||||
|
||||
final int dimY = this.getHeight() - 1;
|
||||
final int dimX = (int) (dimY * 1.5);
|
||||
final var dimY = this.getHeight() - 1;
|
||||
final var dimX = (int) (dimY * 1.5);
|
||||
|
||||
float h, s, b;
|
||||
if ((this.state & STATE_TOGGLED) == 0) {
|
||||
@@ -42,7 +41,7 @@ public class CustomSwitch extends CustomAbstractButton {
|
||||
b += 0.25F;
|
||||
}
|
||||
|
||||
final Color bodyColor = Color.getHSBColor(h, s, b);
|
||||
final var bodyColor = Color.getHSBColor(h, s, b);
|
||||
Color border0Color;
|
||||
Color border1Color;
|
||||
if (dimX < 45) {
|
||||
@@ -78,7 +77,7 @@ public class CustomSwitch extends CustomAbstractButton {
|
||||
else {
|
||||
g2d.setColor(Color.GRAY);
|
||||
}
|
||||
final CoordI2 textDim = G2DDrawFont.getTextDimensions(this.caption, g2d, this.fontSize, this.scaleFactor);
|
||||
final var textDim = G2DDrawFont.getTextDimensions(this.caption, g2d, this.fontSize, this.scaleFactor);
|
||||
G2DDrawFont.renderText(g2d,
|
||||
textDim,
|
||||
this.scaleFactor,
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.awt.event.ActionListener;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class CustomWindowCloseButton extends CustomAbstractButton {
|
||||
@@ -18,10 +17,10 @@ public class CustomWindowCloseButton extends CustomAbstractButton {
|
||||
|
||||
@Override
|
||||
public void paint(final Graphics g) {
|
||||
final Graphics2D g2d = (Graphics2D) g;
|
||||
final var g2d = (Graphics2D) g;
|
||||
|
||||
final boolean highlight = (this.state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
|
||||
final boolean pressed = (this.state & STATE_PRESSED) != 0;
|
||||
final var highlight = (this.state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
|
||||
final var pressed = (this.state & STATE_PRESSED) != 0;
|
||||
|
||||
Color color = null;
|
||||
if (pressed) {
|
||||
@@ -49,7 +48,7 @@ public class CustomWindowCloseButton extends CustomAbstractButton {
|
||||
else {
|
||||
g2d.setColor(Color.BLACK);
|
||||
}
|
||||
final CoordI2 textDim = G2DDrawFont.getTextDimensions("X", g2d, 16, this.scaleFactor);
|
||||
final var textDim = G2DDrawFont.getTextDimensions("X", g2d, 16, this.scaleFactor);
|
||||
G2DDrawFont.renderText(g2d, textDim, 1.0, ((this.getWidth() - textDim.getX()) / 2), ((this.getHeight() - textDim.getY()) / 2), (int) (16 * this.scaleFactor), "X");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package de.extio.game_engine.renderer.g2d.control.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.control.G2DDrawControl;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.SwitchControl;
|
||||
@@ -45,13 +43,12 @@ public abstract class G2DAbstractToggleButtonControlImpl extends G2DButtonContro
|
||||
}
|
||||
|
||||
private void manageCtrlGroupToggleState() {
|
||||
final List<BaseControl> controls = G2DDrawControl.CONTROL_GROUPS.get(this.controlGroup);
|
||||
final var controls = G2DDrawControl.CONTROL_GROUPS.get(this.controlGroup);
|
||||
if (controls != null && !controls.isEmpty()) {
|
||||
boolean controlInGroupToggled = false;
|
||||
var controlInGroupToggled = false;
|
||||
|
||||
for (final BaseControl control : controls) {
|
||||
if (control instanceof G2DToggleButtonControlImpl) {
|
||||
final G2DToggleButtonControlImpl tbControl = (G2DToggleButtonControlImpl) control;
|
||||
if (control instanceof final G2DToggleButtonControlImpl tbControl) {
|
||||
if (tbControl.control == this.control) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -8,15 +8,15 @@ import java.util.Objects;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderingHintFactory;
|
||||
import de.extio.game_engine.renderer.g2d.control.G2DDrawControlTooltip;
|
||||
import de.extio.game_engine.renderer.g2d.control.G2DDrawControlTooltip.TooltipRecord;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl;
|
||||
import de.extio.game_engine.spatial2.WorldUtils2;
|
||||
import de.extio.game_engine.spatial2.model.CoordI2;
|
||||
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl;
|
||||
|
||||
public abstract class G2DBaseControlImpl implements BaseControl {
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import java.util.Objects;
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomAbstractButton;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomButton;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.ButtonControl;
|
||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
|
||||
public class G2DButtonControlImpl extends G2DBaseControlImpl implements ButtonControl {
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ package de.extio.game_engine.renderer.g2d.control.impl;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomLabel;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.LabelControl;
|
||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
import de.extio.game_engine.renderer.model.DrawFontRenderingBoTextAlignment;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.LabelControl;
|
||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
|
||||
public class G2DLabelControlImpl extends G2DBaseControlImpl implements LabelControl {
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package de.extio.game_engine.renderer.g2d.control.impl;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.SetFocusControl;
|
||||
|
||||
@@ -35,8 +33,8 @@ public class G2DSetFocusControl extends G2DBaseControlImpl implements SetFocusCo
|
||||
return;
|
||||
}
|
||||
|
||||
final Component[] components = ((G2DRenderer) this.rendererData.getRenderer()).getMainFrame().getComponents();
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
final var components = ((G2DRenderer) this.rendererData.getRenderer()).getMainFrame().getComponents();
|
||||
for (var i = 0; i < components.length; i++) {
|
||||
if (this.focusId.equals(components[i].getName())) {
|
||||
components[i].requestFocus();
|
||||
break;
|
||||
|
||||
@@ -4,9 +4,9 @@ import java.util.function.Consumer;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomSlider;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.SliderControl;
|
||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
|
||||
public class G2DSliderControlImpl extends G2DBaseControlImpl implements SliderControl {
|
||||
|
||||
|
||||
@@ -15,15 +15,15 @@ import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.ComponentRenderingSupport;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomTable;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.TableControl;
|
||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
|
||||
|
||||
public class G2DTableControlImpl extends G2DBaseControlImpl implements TableControl {
|
||||
@@ -101,7 +101,6 @@ public class G2DTableControlImpl extends G2DBaseControlImpl implements TableCont
|
||||
this.scrollbar.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
protected void createControl() {
|
||||
this.control = new CustomTable();
|
||||
this.control.setName(this.id);
|
||||
@@ -110,8 +109,8 @@ public class G2DTableControlImpl extends G2DBaseControlImpl implements TableCont
|
||||
|
||||
@Override
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
final int row = G2DTableControlImpl.this.control.rowAtPoint(e.getPoint());
|
||||
final int col = G2DTableControlImpl.this.control.columnAtPoint(e.getPoint());
|
||||
final var row = G2DTableControlImpl.this.control.rowAtPoint(e.getPoint());
|
||||
final var col = G2DTableControlImpl.this.control.columnAtPoint(e.getPoint());
|
||||
if (row > -1 && col > -1) {
|
||||
if (G2DTableControlImpl.this.enabled) {
|
||||
G2DTableControlImpl.this.rendererData.getEventConsumer().accept(new UiControlEvent(G2DTableControlImpl.this.id, ImmutableCoordI2.create(row, col)));
|
||||
@@ -124,11 +123,11 @@ public class G2DTableControlImpl extends G2DBaseControlImpl implements TableCont
|
||||
@Override
|
||||
public void mouseWheelMoved(final MouseWheelEvent e) {
|
||||
if (e.getWheelRotation() == -1) {
|
||||
final int displayRows = G2DTableControlImpl.this.control.getHeight() / G2DTableControlImpl.this.control.getRowHeight();
|
||||
final var displayRows = G2DTableControlImpl.this.control.getHeight() / G2DTableControlImpl.this.control.getRowHeight();
|
||||
G2DTableControlImpl.this.scrollbar.setValue(Math.min(1.0, Math.max(0.0, G2DTableControlImpl.this.scrollbar.getValue() + ((double) displayRows / G2DTableControlImpl.this.rows / 2.0))));
|
||||
}
|
||||
else {
|
||||
final int displayRows = G2DTableControlImpl.this.control.getHeight() / G2DTableControlImpl.this.control.getRowHeight();
|
||||
final var displayRows = G2DTableControlImpl.this.control.getHeight() / G2DTableControlImpl.this.control.getRowHeight();
|
||||
G2DTableControlImpl.this.scrollbar.setValue(Math.min(1.0, Math.max(0.0, G2DTableControlImpl.this.scrollbar.getValue() - ((double) displayRows / G2DTableControlImpl.this.rows / 2.0))));
|
||||
}
|
||||
|
||||
@@ -142,7 +141,7 @@ public class G2DTableControlImpl extends G2DBaseControlImpl implements TableCont
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
|
||||
if (row == 0) {
|
||||
final Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
final var component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
component.setFont(component.getFont().deriveFont(Font.BOLD));
|
||||
return component;
|
||||
}
|
||||
@@ -175,17 +174,17 @@ public class G2DTableControlImpl extends G2DBaseControlImpl implements TableCont
|
||||
this.control.getDefaultModel().setRowCount(0);
|
||||
}
|
||||
else {
|
||||
final int actualColumns = this.data.size() / this.rows;
|
||||
final var actualColumns = this.data.size() / this.rows;
|
||||
this.control.getDefaultModel().setColumnCount(actualColumns);
|
||||
if (this.firstColDoubleSize) {
|
||||
for (int i = 0; i < actualColumns; i++) {
|
||||
for (var i = 0; i < actualColumns; i++) {
|
||||
this.control.getColumnModel().getColumn(i).setPreferredWidth(i == 0 ? 200 : 100);
|
||||
}
|
||||
}
|
||||
final int actualRows = (int) ((1.0 - this.scrollPositionPerc) * this.rows);
|
||||
final var actualRows = (int) ((1.0 - this.scrollPositionPerc) * this.rows);
|
||||
this.control.getDefaultModel().setRowCount(actualRows);
|
||||
final int offset = (this.rows - actualRows) * actualColumns;
|
||||
for (int i = 0; i < this.data.size() - offset; i++) {
|
||||
final var offset = (this.rows - actualRows) * actualColumns;
|
||||
for (var i = 0; i < this.data.size() - offset; i++) {
|
||||
this.control.getDefaultModel().setValueAt(this.data.get(i + offset), i / this.control.getDefaultModel().getColumnCount(), i % this.control.getDefaultModel().getColumnCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ import java.awt.TextField;
|
||||
import java.util.Objects;
|
||||
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.ComponentRenderingSupport;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomTextArea;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomTextField;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.TextfieldControl;
|
||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
|
||||
public class G2DTextfieldControlImpl extends G2DBaseControlImpl implements TextfieldControl {
|
||||
|
||||
@@ -74,7 +74,7 @@ public class G2DTextfieldControlImpl extends G2DBaseControlImpl implements Textf
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
final String curComponentText = this.textComponent.getText();
|
||||
final var curComponentText = this.textComponent.getText();
|
||||
if (!Objects.equals(this.lastText, curComponentText) && !((this.lastText == null || this.lastText.isEmpty()) && (curComponentText == null || curComponentText.isEmpty()))) {
|
||||
this.lastText = curComponentText;
|
||||
this.rendererData.getEventConsumer().accept(new UiControlEvent(this.id, this.lastText));
|
||||
@@ -126,7 +126,7 @@ public class G2DTextfieldControlImpl extends G2DBaseControlImpl implements Textf
|
||||
|
||||
try {
|
||||
if (this.caption != null && !this.textComponent.getText().equals(this.caption)) {
|
||||
final int pos = this.textComponent.getCaretPosition();
|
||||
final var pos = this.textComponent.getCaretPosition();
|
||||
this.safeInvoke(() -> this.textComponent.setText(this.caption));
|
||||
this.safeInvoke(() -> this.textComponent.setCaretPosition(pos));
|
||||
this.lastText = this.caption;
|
||||
@@ -139,7 +139,7 @@ public class G2DTextfieldControlImpl extends G2DBaseControlImpl implements Textf
|
||||
if (this.multiLine) {
|
||||
this.safeInvoke(() -> this.textComponent.setEditable(false));
|
||||
this.safeInvoke(() -> this.textComponent.setFocusable(false));
|
||||
final int scrollPos = (this.caption != null ? this.caption.lastIndexOf('\n') : -1) + 1;
|
||||
final var scrollPos = (this.caption != null ? this.caption.lastIndexOf('\n') : -1) + 1;
|
||||
this.safeInvoke(() -> this.textComponent.setCaretPosition(scrollPos));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ import java.awt.event.MouseWheelListener;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
import de.extio.game_engine.renderer.g2d.G2DRenderer;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.ComponentRenderingSupport;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomJTextArea;
|
||||
import de.extio.game_engine.renderer.g2d.control.components.CustomJTextField;
|
||||
import de.extio.game_engine.renderer.g2d.bo.rendering.G2DDrawFont;
|
||||
import de.extio.game_engine.renderer.RendererData;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl;
|
||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.TextfieldControl;
|
||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||
import de.extio.game_engine.renderer.model.RgbaColor;
|
||||
|
||||
public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements TextfieldControl {
|
||||
|
||||
@@ -109,7 +109,7 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(final MouseWheelEvent e) {
|
||||
final int displayRows = countMatches(G2DTextfieldControlImpl2.this.lastCaption, '\n');
|
||||
final var displayRows = G2DTextfieldControlImpl2.this.countMatches(G2DTextfieldControlImpl2.this.lastCaption, '\n');
|
||||
if (displayRows == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
final String curComponentText = this.textComponent.getText();
|
||||
final var curComponentText = this.textComponent.getText();
|
||||
if (!curComponentText.equals(this.lastText) && !(this.lastText == null || this.lastText.isEmpty() || curComponentText == null || curComponentText.isEmpty())) {
|
||||
this.lastText = curComponentText;
|
||||
this.rendererData.getEventConsumer().accept(new UiControlEvent(this.id, this.lastText));
|
||||
@@ -255,10 +255,10 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
|
||||
try {
|
||||
if (this.multiLine) {
|
||||
if (this.scrollPositionModified || this.caption != null) {
|
||||
final int displayRows = countMatches(this.lastCaption, '\n');
|
||||
final int skipRows = (int) ((double) this.scrollPositionPerc * (double) displayRows);
|
||||
int offset = 0;
|
||||
for (int i = 0; i < skipRows; i++) {
|
||||
final var displayRows = this.countMatches(this.lastCaption, '\n');
|
||||
final var skipRows = (int) ((double) this.scrollPositionPerc * (double) displayRows);
|
||||
var offset = 0;
|
||||
for (var i = 0; i < skipRows; i++) {
|
||||
offset = this.lastCaption.indexOf('\n', offset);
|
||||
if (offset == -1) {
|
||||
break;
|
||||
@@ -285,7 +285,7 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
|
||||
}
|
||||
else {
|
||||
if (this.caption != null && !this.textComponent.getText().equals(this.caption)) {
|
||||
final int pos = this.textComponent.getCaretPosition();
|
||||
final var pos = this.textComponent.getCaretPosition();
|
||||
this.safeInvoke(() -> this.textComponent.setText(this.caption));
|
||||
if (pos < this.textComponent.getText().length()) {
|
||||
this.safeInvoke(() -> this.textComponent.setCaretPosition(pos));
|
||||
@@ -310,8 +310,8 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
|
||||
if (str == null || str.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
var count = 0;
|
||||
for (var i = 0; i < str.length(); i++) {
|
||||
if (str.charAt(i) == ch) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -36,15 +36,15 @@ public class G2DWindowCloseButtonControlImpl extends G2DButtonControlImpl implem
|
||||
}
|
||||
else {
|
||||
this.translations++;
|
||||
final int x = this.x;
|
||||
final int y = this.y;
|
||||
final int w = this.width;
|
||||
final int h = this.height;
|
||||
final var x = this.x;
|
||||
final var y = this.y;
|
||||
final var w = this.width;
|
||||
final var h = this.height;
|
||||
try {
|
||||
final int sx = (int) this.x;
|
||||
final int sy = (int) this.y;
|
||||
final int sw = (int) this.width;
|
||||
final int strength = Math.max(2, (int) (3 * this.scaleFactor));
|
||||
final var sx = (int) this.x;
|
||||
final var sy = (int) this.y;
|
||||
final var sw = (int) this.width;
|
||||
final var strength = Math.max(2, (int) (3 * this.scaleFactor));
|
||||
|
||||
this.x = sx + sw - strength * 9;
|
||||
this.y = sy + strength * 2;
|
||||
|
||||
@@ -166,8 +166,8 @@ public class RgbaColor {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
final var prime = 31;
|
||||
var result = 1;
|
||||
result = prime * result + this.a;
|
||||
result = prime * result + this.b;
|
||||
result = prime * result + this.g;
|
||||
@@ -183,7 +183,7 @@ public class RgbaColor {
|
||||
if ((obj == null) || (this.getClass() != obj.getClass())) {
|
||||
return false;
|
||||
}
|
||||
final RgbaColor other = (RgbaColor) obj;
|
||||
final var other = (RgbaColor) obj;
|
||||
if (this.a != other.a) {
|
||||
return false;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ public class RgbaColor {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final var builder = new StringBuilder();
|
||||
builder.append("RgbaColor [r=");
|
||||
builder.append(this.r);
|
||||
builder.append(", g=");
|
||||
|
||||
@@ -190,10 +190,10 @@ public final class WorldUtils2 {
|
||||
public static RectI2 intersectRectangles(final RectI2 r0, final RectI2 r1) {
|
||||
final CoordI2 size0 = ImmutableCoordI2.create(r0.getC1().getX() - r0.getC0().getX(), r0.getC1().getY() - r0.getC0().getY());
|
||||
final CoordI2 size1 = ImmutableCoordI2.create(r1.getC1().getX() - r1.getC0().getX(), r1.getC1().getY() - r1.getC0().getY());
|
||||
final Rectangle rect0 = new Rectangle(r0.getC0().getX(), r0.getC0().getY(), size0.getX(), size0.getY());
|
||||
final Rectangle rect1 = new Rectangle(r1.getC0().getX(), r1.getC0().getY(), size1.getX(), size1.getY());
|
||||
final var rect0 = new Rectangle(r0.getC0().getX(), r0.getC0().getY(), size0.getX(), size0.getY());
|
||||
final var rect1 = new Rectangle(r1.getC0().getX(), r1.getC0().getY(), size1.getX(), size1.getY());
|
||||
|
||||
final Rectangle intersection = rect0.intersection(rect1);
|
||||
final var intersection = rect0.intersection(rect1);
|
||||
if (intersection.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -210,10 +210,10 @@ public final class WorldUtils2 {
|
||||
* @return The intersected area if r0 and r1 overlap, else null
|
||||
*/
|
||||
public static Area2 intersectAreas(final HasPositionAndDimension2 a0, final HasPositionAndDimension2 a1) {
|
||||
final Rectangle rect0 = new Rectangle(a0.getPosition().getX(), a0.getPosition().getY(), a0.getDimension().getX(), a0.getDimension().getY());
|
||||
final Rectangle rect1 = new Rectangle(a1.getPosition().getX(), a1.getPosition().getY(), a1.getDimension().getX(), a1.getDimension().getY());
|
||||
final var rect0 = new Rectangle(a0.getPosition().getX(), a0.getPosition().getY(), a0.getDimension().getX(), a0.getDimension().getY());
|
||||
final var rect1 = new Rectangle(a1.getPosition().getX(), a1.getPosition().getY(), a1.getDimension().getX(), a1.getDimension().getY());
|
||||
|
||||
final Rectangle intersection = rect0.intersection(rect1);
|
||||
final var intersection = rect0.intersection(rect1);
|
||||
if (intersection.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -242,10 +242,10 @@ public final class WorldUtils2 {
|
||||
* @return true / false whether obj0 intersects with obj1
|
||||
*/
|
||||
public static boolean intersects(final CoordI2 position0, final CoordI2 dimension0, final CoordI2 position1, final CoordI2 dimension1) {
|
||||
int d0x = dimension0.getX();
|
||||
int d0y = dimension0.getY();
|
||||
int d1x = dimension1.getX();
|
||||
int d1y = dimension1.getY();
|
||||
var d0x = dimension0.getX();
|
||||
var d0y = dimension0.getY();
|
||||
var d1x = dimension1.getX();
|
||||
var d1y = dimension1.getY();
|
||||
if (d0x <= 0 || d0y <= 0 || d1x <= 0 || d1y <= 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -261,7 +261,6 @@ public final class WorldUtils2 {
|
||||
(d1y < position1.getY() || d1y > position0.getY()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds an aligned Area2 from arbitrary points
|
||||
* @return
|
||||
@@ -273,7 +272,7 @@ public final class WorldUtils2 {
|
||||
|
||||
final CoordI2 corner0 = MutableCoordI2.create(points[0]);
|
||||
final CoordI2 corner1 = MutableCoordI2.create(points[0]).add(1, 1);
|
||||
for (int i = 1; i < points.length; i++) {
|
||||
for (var i = 1; i < points.length; i++) {
|
||||
corner0.setXY(Math.min(corner0.getX(), points[i].getX()), Math.min(corner0.getY(), points[i].getY()));
|
||||
corner1.setXY(Math.max(corner1.getX(), points[i].getX() + 1), Math.max(corner1.getY(), points[i].getY() + 1));
|
||||
}
|
||||
@@ -295,14 +294,14 @@ public final class WorldUtils2 {
|
||||
final CoordD2 pTarget = ImmutableCoordD2.create(pTarget_);
|
||||
final CoordD2 vTarget = ImmutableCoordD2.create(vTarget_);
|
||||
|
||||
final double a = (vTarget.getX() * vTarget.getX()) + (vTarget.getY() * vTarget.getY()) - (velOrigin * velOrigin);
|
||||
final double b = 2 * ((pTarget.getX() * vTarget.getX()) + (pTarget.getY() * vTarget.getY()) - (pOrigin.getX() * vTarget.getX()) - (pOrigin.getY() * vTarget.getY()));
|
||||
final double c = (pTarget.getX() * pTarget.getX()) + (pTarget.getY() * pTarget.getY()) + (pOrigin.getX() * pOrigin.getX()) + (pOrigin.getY() * pOrigin.getY()) - (2 * pOrigin.getX() * pTarget.getX()) - (2 * pOrigin.getY() * pTarget.getY());
|
||||
final double t0 = (-b + Math.sqrt((b * b) - (4.0 * a * c))) / (2.0 * a);
|
||||
final double t1 = (-b - Math.sqrt((b * b) - (4.0 * a * c))) / (2.0 * a);
|
||||
final var a = (vTarget.getX() * vTarget.getX()) + (vTarget.getY() * vTarget.getY()) - (velOrigin * velOrigin);
|
||||
final var b = 2 * ((pTarget.getX() * vTarget.getX()) + (pTarget.getY() * vTarget.getY()) - (pOrigin.getX() * vTarget.getX()) - (pOrigin.getY() * vTarget.getY()));
|
||||
final var c = (pTarget.getX() * pTarget.getX()) + (pTarget.getY() * pTarget.getY()) + (pOrigin.getX() * pOrigin.getX()) + (pOrigin.getY() * pOrigin.getY()) - (2 * pOrigin.getX() * pTarget.getX()) - (2 * pOrigin.getY() * pTarget.getY());
|
||||
final var t0 = (-b + Math.sqrt((b * b) - (4.0 * a * c))) / (2.0 * a);
|
||||
final var t1 = (-b - Math.sqrt((b * b) - (4.0 * a * c))) / (2.0 * a);
|
||||
|
||||
final boolean t0Pass = !Double.isNaN(t0) && t0 > 0.0;
|
||||
final boolean t1Pass = !Double.isNaN(t1) && t1 > 0.0;
|
||||
final var t0Pass = !Double.isNaN(t0) && t0 > 0.0;
|
||||
final var t1Pass = !Double.isNaN(t1) && t1 > 0.0;
|
||||
double t;
|
||||
if (t0Pass && t1Pass) {
|
||||
t = Math.min(t0, t1);
|
||||
@@ -341,7 +340,7 @@ public final class WorldUtils2 {
|
||||
|
||||
Arrays.sort(dists, (e0, e1) -> Double.compare(e0.dist, e1.dist));
|
||||
|
||||
final int sector = dists[0].sector | dists[1].sector;
|
||||
final var sector = dists[0].sector | dists[1].sector;
|
||||
|
||||
if (sector == 0b11) {
|
||||
return Edge2.TOP;
|
||||
@@ -366,22 +365,22 @@ public final class WorldUtils2 {
|
||||
* @return Pedal of altitude c
|
||||
*/
|
||||
public static CoordD2 getPedal(final CoordI2 a, final CoordI2 b, final CoordI2 c) {
|
||||
final double distA = getDistance(a, b);
|
||||
final var distA = getDistance(a, b);
|
||||
if (distA == 0.0) {
|
||||
return null;
|
||||
}
|
||||
final double distASquare = Math.pow(distA, 2.0);
|
||||
final double distB = getDistance(b, c);
|
||||
final double distBSquare = Math.pow(distB, 2.0);
|
||||
final double distC = getDistance(c, a);
|
||||
final double distCSquare = Math.pow(distC, 2.0);
|
||||
final var distASquare = Math.pow(distA, 2.0);
|
||||
final var distB = getDistance(b, c);
|
||||
final var distBSquare = Math.pow(distB, 2.0);
|
||||
final var distC = getDistance(c, a);
|
||||
final var distCSquare = Math.pow(distC, 2.0);
|
||||
|
||||
final double altA = Math.sqrt((2.0 * ((distASquare * distBSquare) + (distBSquare * distCSquare) + (distCSquare * distASquare))) - (Math.pow(distA, 4.0) + Math.pow(distB, 4.0) + Math.pow(distC, 4.0))) / (2.0 * distA);
|
||||
final var altA = Math.sqrt((2.0 * ((distASquare * distBSquare) + (distBSquare * distCSquare) + (distCSquare * distASquare))) - (Math.pow(distA, 4.0) + Math.pow(distB, 4.0) + Math.pow(distC, 4.0))) / (2.0 * distA);
|
||||
if (Double.isNaN(altA)) {
|
||||
return null;
|
||||
}
|
||||
final double alpha = getVectorAngle(b.substract(a), c.substract(a));
|
||||
final double scaleA = (Math.sqrt(distCSquare - Math.pow(altA, 2.0)) / distA) * copySign(Math.PI / 2.0 - Math.abs(alpha));
|
||||
final var alpha = getVectorAngle(b.substract(a), c.substract(a));
|
||||
final var scaleA = (Math.sqrt(distCSquare - Math.pow(altA, 2.0)) / distA) * copySign(Math.PI / 2.0 - Math.abs(alpha));
|
||||
if (Double.isNaN(scaleA)) {
|
||||
return null;
|
||||
}
|
||||
@@ -404,12 +403,12 @@ public final class WorldUtils2 {
|
||||
* Returns null if there is no pedal.
|
||||
*/
|
||||
public static CoordD2 getPedalOnLineSegmentAB(final CoordI2 a, final CoordI2 b, final CoordI2 c) {
|
||||
final CoordD2 pedal = getPedal(a, b, c);
|
||||
final var pedal = getPedal(a, b, c);
|
||||
if (pedal == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
double x = pedal.getX();
|
||||
var x = pedal.getX();
|
||||
final double minX = Math.min(a.getX(), b.getX());
|
||||
if (x < minX) {
|
||||
x = minX;
|
||||
@@ -419,7 +418,7 @@ public final class WorldUtils2 {
|
||||
x = maxX;
|
||||
}
|
||||
|
||||
double y = pedal.getY();
|
||||
var y = pedal.getY();
|
||||
final double minY = Math.min(a.getY(), b.getY());
|
||||
if (y < minY) {
|
||||
y = minY;
|
||||
@@ -446,15 +445,15 @@ public final class WorldUtils2 {
|
||||
* @return
|
||||
*/
|
||||
public static CoordI2 getClosestPoint(final CoordI2 origin, final HasPositionAndDimension2 target) {
|
||||
double minDistance = Double.MAX_VALUE;
|
||||
var minDistance = Double.MAX_VALUE;
|
||||
CoordI2 result = null;
|
||||
|
||||
final List<CoordI2> vertices = getVertices(target);
|
||||
for (int i = 1; i < 4; i++) {
|
||||
final CoordD2 pedal = getPedalOnLineSegmentAB(vertices.get(i - 1), vertices.get(i), origin);
|
||||
final var vertices = getVertices(target);
|
||||
for (var i = 1; i < 4; i++) {
|
||||
final var pedal = getPedalOnLineSegmentAB(vertices.get(i - 1), vertices.get(i), origin);
|
||||
if (pedal != null) {
|
||||
final CoordI2 pedalI = pedal.toImmutableCoordI2();
|
||||
final double distance = getDistance(origin, pedalI);
|
||||
final var pedalI = pedal.toImmutableCoordI2();
|
||||
final var distance = getDistance(origin, pedalI);
|
||||
if (distance < minDistance) {
|
||||
minDistance = distance;
|
||||
result = pedalI;
|
||||
@@ -477,17 +476,17 @@ public final class WorldUtils2 {
|
||||
* @return Waypoints for evasion or null if there is no collision
|
||||
*/
|
||||
public static List<CoordI2> evade(final HasPositionAndDimension2 origin, final double velOrigin, final CoordD2 vOrigin, final HasPositionAndDimension2 target, final CoordD2 vTarget, final CoordI2 oTarget, final CoordI2 pInterception_) {
|
||||
final double THRESHOLD_NOT_MOVING = 0.2;
|
||||
final var THRESHOLD_NOT_MOVING = 0.2;
|
||||
|
||||
final CoordI2 pOrigin = ImmutableCoordI2.create(origin.getPosition()).add(ImmutableCoordI2.create(origin.getDimension()).divide(2));
|
||||
final CoordI2 pTarget = ImmutableCoordI2.create(target.getPosition()).add(ImmutableCoordI2.create(target.getDimension()).divide(2));
|
||||
final double velTarget = getDistance(vTarget);
|
||||
final var velTarget = getDistance(vTarget);
|
||||
|
||||
if (velOrigin < THRESHOLD_NOT_MOVING) {
|
||||
// Corner case: Origin is not moving
|
||||
|
||||
final CoordD2 vOriginToTarget = ImmutableCoordD2.create(pTarget).substract(ImmutableCoordD2.create(pOrigin));
|
||||
CoordD2 vEvasion = MutableCoordD2
|
||||
var vEvasion = MutableCoordD2
|
||||
.create(-vOriginToTarget.getY(), vOriginToTarget.getX()) // Rotate by PI/2
|
||||
.toVNorm()
|
||||
.multiply(getDistance(origin.getDimension()) * 2.0);
|
||||
@@ -513,31 +512,31 @@ public final class WorldUtils2 {
|
||||
final CoordI2 boxDim = ImmutableCoordI2.create(
|
||||
Math.max(origin.getDimension().getX(), origin.getDimension().getY()) + 4,
|
||||
Math.max(origin.getDimension().getX(), origin.getDimension().getY()) + 4);
|
||||
final CoordI2 targetDimHalf = target.getDimension().divide(2);
|
||||
final Area2 box = new Area2(pInterception
|
||||
final var targetDimHalf = target.getDimension().divide(2);
|
||||
final var box = new Area2(pInterception
|
||||
.add(targetDimHalf.substract(oTarget))
|
||||
.substract(targetDimHalf)
|
||||
.substract(boxDim),
|
||||
targetDimHalf
|
||||
.add(boxDim)
|
||||
.multiply(2));
|
||||
final List<CoordI2> vertices = getVertices(box);
|
||||
final var vertices = getVertices(box);
|
||||
|
||||
// Rule out one or more vertices, because ...
|
||||
|
||||
if (velTarget >= THRESHOLD_NOT_MOVING && Math.abs(getVectorAngle(vOrigin, vTarget)) < Math.PI / 4.0) { // Velocity vectors are similar -> collision from behind
|
||||
// Remove both vertices in origin move direction
|
||||
|
||||
int removeVertexIdxLow = -1;
|
||||
int removeVertexIdxHigh = -1;
|
||||
var removeVertexIdxLow = -1;
|
||||
var removeVertexIdxHigh = -1;
|
||||
|
||||
double aLow = Math.PI;
|
||||
double aHigh = 0.0;
|
||||
for (int i = 0; i < vertices.size(); i++) {
|
||||
final CoordI2 curVertex = vertices.get(i);
|
||||
var aLow = Math.PI;
|
||||
var aHigh = 0.0;
|
||||
for (var i = 0; i < vertices.size(); i++) {
|
||||
final var curVertex = vertices.get(i);
|
||||
|
||||
final CoordD2 direction = pInterception.substract(curVertex).toImmutableCoordD2();
|
||||
final double a = Math.abs(getVectorAngle(vOrigin, direction));
|
||||
final var direction = pInterception.substract(curVertex).toImmutableCoordD2();
|
||||
final var a = Math.abs(getVectorAngle(vOrigin, direction));
|
||||
if (removeVertexIdxLow == -1 || a < aLow) {
|
||||
aLow = a;
|
||||
removeVertexIdxLow = i;
|
||||
@@ -554,26 +553,26 @@ public final class WorldUtils2 {
|
||||
else if (velTarget < velOrigin - 0.75) { // Origin speed is higher
|
||||
// Remove vertex farthest from origin move direction, but closest vertex will never be ruled out (-> primary)
|
||||
|
||||
int safeVertexIdx = 0;
|
||||
double vLen = -1.0;
|
||||
for (int i = 0; i < vertices.size(); i++) {
|
||||
final CoordI2 curVertex = vertices.get(i);
|
||||
final double curVLen = getDistance(pOrigin, curVertex);
|
||||
var safeVertexIdx = 0;
|
||||
var vLen = -1.0;
|
||||
for (var i = 0; i < vertices.size(); i++) {
|
||||
final var curVertex = vertices.get(i);
|
||||
final var curVLen = getDistance(pOrigin, curVertex);
|
||||
if (vLen < 0.0 || curVLen < vLen) {
|
||||
vLen = curVLen;
|
||||
safeVertexIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
int removeVertexIdx = 0;
|
||||
double aHigh = 0.0;
|
||||
for (int i = 0; i < vertices.size(); i++) {
|
||||
var removeVertexIdx = 0;
|
||||
var aHigh = 0.0;
|
||||
for (var i = 0; i < vertices.size(); i++) {
|
||||
if (i == safeVertexIdx) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final CoordI2 curVertex = vertices.get(i);
|
||||
final double a = Math.abs(getVectorAngle(curVertex.substract(pOrigin).toImmutableCoordD2(), vOrigin));
|
||||
final var curVertex = vertices.get(i);
|
||||
final var a = Math.abs(getVectorAngle(curVertex.substract(pOrigin).toImmutableCoordD2(), vOrigin));
|
||||
if (a > aHigh) {
|
||||
aHigh = a;
|
||||
removeVertexIdx = i;
|
||||
@@ -585,13 +584,13 @@ public final class WorldUtils2 {
|
||||
else {
|
||||
// Remove vertex closest to target move direction
|
||||
|
||||
int removeVertexIdx = -1;
|
||||
var removeVertexIdx = -1;
|
||||
|
||||
double vLen = -1.0;
|
||||
for (int i = 0; i < vertices.size(); i++) {
|
||||
final CoordI2 curVertex = vertices.get(i);
|
||||
var vLen = -1.0;
|
||||
for (var i = 0; i < vertices.size(); i++) {
|
||||
final var curVertex = vertices.get(i);
|
||||
final CoordD2 curV = ImmutableCoordD2.create(pInterception.substract(curVertex)).add(vTarget);
|
||||
final double curVLen = getDistance(curV);
|
||||
final var curVLen = getDistance(curV);
|
||||
if (vLen < 0.0 || curVLen < vLen) {
|
||||
vLen = curVLen;
|
||||
removeVertexIdx = i;
|
||||
@@ -603,11 +602,11 @@ public final class WorldUtils2 {
|
||||
|
||||
// Get closest vertex -> primary
|
||||
|
||||
int primaryVertexIdx = -1;
|
||||
double closestDist = -1.0;
|
||||
for (int i = 0; i < vertices.size(); i++) {
|
||||
var primaryVertexIdx = -1;
|
||||
var closestDist = -1.0;
|
||||
for (var i = 0; i < vertices.size(); i++) {
|
||||
if (vertices.get(i) != null) {
|
||||
final double curDist = getDistance(vertices.get(i), pOrigin);
|
||||
final var curDist = getDistance(vertices.get(i), pOrigin);
|
||||
if (closestDist < 0.0 || curDist < closestDist) {
|
||||
closestDist = curDist;
|
||||
primaryVertexIdx = i;
|
||||
@@ -617,13 +616,13 @@ public final class WorldUtils2 {
|
||||
|
||||
// Choose secondary vertex
|
||||
|
||||
final int candidate0 = (primaryVertexIdx + 1) % vertices.size();
|
||||
final int candidate1 = Math.floorMod(primaryVertexIdx - 1, vertices.size());
|
||||
final var candidate0 = (primaryVertexIdx + 1) % vertices.size();
|
||||
final var candidate1 = Math.floorMod(primaryVertexIdx - 1, vertices.size());
|
||||
int secondVertexIdx;
|
||||
if (vertices.get(candidate0) != null && vertices.get(candidate1) != null) {
|
||||
// Center vertex, choose secondary which is closer to origin velocity vector
|
||||
final double a0 = getVectorAngle(pInterception.substract(pOrigin), vertices.get(candidate0).substract(pOrigin));
|
||||
final double a1 = getVectorAngle(pInterception.substract(pOrigin), vertices.get(candidate1).substract(pOrigin));
|
||||
final var a0 = getVectorAngle(pInterception.substract(pOrigin), vertices.get(candidate0).substract(pOrigin));
|
||||
final var a1 = getVectorAngle(pInterception.substract(pOrigin), vertices.get(candidate1).substract(pOrigin));
|
||||
if (Math.abs(a0) < Math.abs(a1)) {
|
||||
secondVertexIdx = candidate0;
|
||||
}
|
||||
@@ -742,7 +741,7 @@ public final class WorldUtils2 {
|
||||
* @return random point in the circle
|
||||
*/
|
||||
public static CoordI2 getRandomPointOnCircle(final CoordI2 center, final int radius, final Random random) {
|
||||
final double angle = random.nextDouble() * Math.PI * 2.0 - Math.PI;
|
||||
final var angle = random.nextDouble() * Math.PI * 2.0 - Math.PI;
|
||||
return MutableCoordD2
|
||||
.create(Math.cos(angle), Math.sin(angle))
|
||||
.multiply(radius)
|
||||
@@ -758,7 +757,7 @@ public final class WorldUtils2 {
|
||||
* @return random point in the circle
|
||||
*/
|
||||
public static CoordI2 getReproduciblePointOnCircle(final CoordI2 center, final int radius, final AtomicInteger counter) {
|
||||
final double angle = counter.incrementAndGet() / 3.0 % Math.PI * 2.0 - Math.PI;
|
||||
final var angle = counter.incrementAndGet() / 3.0 % Math.PI * 2.0 - Math.PI;
|
||||
return MutableCoordD2
|
||||
.create(Math.cos(angle), Math.sin(angle))
|
||||
.multiply(radius)
|
||||
@@ -777,10 +776,10 @@ public final class WorldUtils2 {
|
||||
* @return Edges that are required as bit mask
|
||||
*/
|
||||
public static int calcEdgeRequirement(final CoordI2 c0, final CoordI2 c1) {
|
||||
final int dx = c0.getX() - c1.getX();
|
||||
final int dy = c0.getY() - c1.getY();
|
||||
final var dx = c0.getX() - c1.getX();
|
||||
final var dy = c0.getY() - c1.getY();
|
||||
|
||||
int edgeReq = 0;
|
||||
var edgeReq = 0;
|
||||
if (dx < 0 && dy < 0) {
|
||||
edgeReq = Edge2.LEFT.getBit() | Edge2.TOP.getBit();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class GridIndex2D<T extends HasPosition2> implements Iterable<T>, A
|
||||
}
|
||||
|
||||
public List<T> get(final HasPosition2 hasPosition2) {
|
||||
final CoordI2 coord = hasPosition2.getPosition();
|
||||
final var coord = hasPosition2.getPosition();
|
||||
if (!this.checkBounds(coord)) {
|
||||
return List.of();
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public final class GridIndex2D<T extends HasPosition2> implements Iterable<T>, A
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
final T result = GridIndex2D.this.index.get(this.x).get(this.y).get(this.i);
|
||||
final var result = GridIndex2D.this.index.get(this.x).get(this.y).get(this.i);
|
||||
this.forward();
|
||||
return result;
|
||||
}
|
||||
@@ -138,9 +138,9 @@ public final class GridIndex2D<T extends HasPosition2> implements Iterable<T>, A
|
||||
|
||||
@Override
|
||||
public void forEach(final Consumer<? super T> action) {
|
||||
for (int x = 0; x < this.index.size(); x++) {
|
||||
for (int y = 0; y < this.index.get(x).size(); y++) {
|
||||
for (int i = 0; i < this.index.get(x).get(y).size(); i++) {
|
||||
for (var x = 0; x < this.index.size(); x++) {
|
||||
for (var y = 0; y < this.index.get(x).size(); y++) {
|
||||
for (var i = 0; i < this.index.get(x).get(y).size(); i++) {
|
||||
action.accept(this.index.get(x).get(y).get(i));
|
||||
}
|
||||
}
|
||||
@@ -150,8 +150,8 @@ public final class GridIndex2D<T extends HasPosition2> implements Iterable<T>, A
|
||||
public void forEach(final BiConsumer<CoordI2, List<T>> action) {
|
||||
final CoordI2 coord = MutableCoordI2.create();
|
||||
|
||||
for (int x = 0; x < this.index.size(); x++) {
|
||||
for (int y = 0; y < this.index.get(x).size(); y++) {
|
||||
for (var x = 0; x < this.index.size(); x++) {
|
||||
for (var y = 0; y < this.index.get(x).size(); y++) {
|
||||
if (this.index.get(x).get(y).size() > 0) {
|
||||
coord.setXY(x, y);
|
||||
action.accept(coord, this.index.get(x).get(y));
|
||||
@@ -161,7 +161,7 @@ public final class GridIndex2D<T extends HasPosition2> implements Iterable<T>, A
|
||||
}
|
||||
|
||||
private void ensureBounds(final CoordI2 coord) {
|
||||
int delta = this.index.size() - coord.getX();
|
||||
var delta = this.index.size() - coord.getX();
|
||||
if (delta < 1) {
|
||||
for (delta = -delta; delta >= 0; delta--) {
|
||||
this.index.add(new ArrayList<>());
|
||||
|
||||
@@ -48,8 +48,8 @@ public final class LinearSearchIndex2D<T extends SpatialIndex2Capable> implement
|
||||
public List<T> find(final CoordI2 position, final CoordI2 dimension, final Predicate<T> filter) {
|
||||
List<T> result = null;
|
||||
|
||||
for (int i = 0; i < this.objects.size(); i++) {
|
||||
final T obj = this.objects.get(i);
|
||||
for (var i = 0; i < this.objects.size(); i++) {
|
||||
final var obj = this.objects.get(i);
|
||||
|
||||
if (WorldUtils2.intersects(position, dimension, obj.getPosition(), obj.getDimension())) {
|
||||
if (filter == null || filter.test(obj)) {
|
||||
@@ -73,8 +73,8 @@ public final class LinearSearchIndex2D<T extends SpatialIndex2Capable> implement
|
||||
|
||||
@Override
|
||||
public T findFirstAt(final CoordI2 position, final Predicate<T> filter) {
|
||||
for (int i = 0; i < this.objects.size(); i++) {
|
||||
final T obj = this.objects.get(i);
|
||||
for (var i = 0; i < this.objects.size(); i++) {
|
||||
final var obj = this.objects.get(i);
|
||||
|
||||
if (WorldUtils2.intersects(position, ImmutableCoordI2.one(), obj.getPosition(), obj.getDimension())) {
|
||||
if (filter == null || filter.test(obj)) {
|
||||
@@ -88,8 +88,8 @@ public final class LinearSearchIndex2D<T extends SpatialIndex2Capable> implement
|
||||
|
||||
@Override
|
||||
public void executeAt(final CoordI2 position, final Consumer<T> consumer, final Predicate<T> filter) {
|
||||
for (int i = 0; i < this.objects.size(); i++) {
|
||||
final T obj = this.objects.get(i);
|
||||
for (var i = 0; i < this.objects.size(); i++) {
|
||||
final var obj = this.objects.get(i);
|
||||
|
||||
if (WorldUtils2.intersects(position, ImmutableCoordI2.one(), obj.getPosition(), obj.getDimension())) {
|
||||
if (filter == null || filter.test(obj)) {
|
||||
|
||||
@@ -37,8 +37,8 @@ public final class Matrix2<T> implements Iterable<T> {
|
||||
this.dimension.setX(other.matrix.size());
|
||||
|
||||
this.matrix = new ArrayList<>(other.matrix);
|
||||
for (int x = 0; x < this.matrix.size(); x++) {
|
||||
final List<T> column = other.matrix.get(x);
|
||||
for (var x = 0; x < this.matrix.size(); x++) {
|
||||
final var column = other.matrix.get(x);
|
||||
this.matrix.set(x, new ArrayList<>(column));
|
||||
|
||||
if (column.size() > this.dimension.getY()) {
|
||||
@@ -93,8 +93,8 @@ public final class Matrix2<T> implements Iterable<T> {
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
for (int x = 0; x < this.matrix.size(); x++) {
|
||||
for (int y = 0; y < this.matrix.get(x).size(); y++) {
|
||||
for (var x = 0; x < this.matrix.size(); x++) {
|
||||
for (var y = 0; y < this.matrix.get(x).size(); y++) {
|
||||
this.matrix.get(x).set(y, null);
|
||||
}
|
||||
}
|
||||
@@ -127,11 +127,11 @@ public final class Matrix2<T> implements Iterable<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
int delta = this.matrix.size() - x;
|
||||
var delta = this.matrix.size() - x;
|
||||
if (delta < 1) {
|
||||
for (delta = -delta; delta >= 0; delta--) {
|
||||
final List<T> row = new ArrayList<>(y + 1);
|
||||
for (int i = 0; i <= y; i++) {
|
||||
for (var i = 0; i <= y; i++) {
|
||||
row.add(null);
|
||||
}
|
||||
this.matrix.add(row);
|
||||
@@ -165,8 +165,8 @@ public final class Matrix2<T> implements Iterable<T> {
|
||||
this.allocate(origDim.getY() - 1, origDim.getX() - 1);
|
||||
|
||||
final CoordI2 posSrc = MutableCoordI2.create();
|
||||
for (int x = 0; x < origDim.getY(); x++) {
|
||||
for (int y = 0; y < origDim.getX(); y++) {
|
||||
for (var x = 0; x < origDim.getY(); x++) {
|
||||
for (var y = 0; y < origDim.getX(); y++) {
|
||||
if (direction == Edge2.LEFT) {
|
||||
posSrc.setXY(origDim.getX() - y - 1, x);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ public final class Matrix2<T> implements Iterable<T> {
|
||||
posSrc.setXY(y, origDim.getY() - x - 1);
|
||||
}
|
||||
|
||||
final List<T> originalObjs = original.get(posSrc.getX());
|
||||
final var originalObjs = original.get(posSrc.getX());
|
||||
if (originalObjs.size() > posSrc.getY()) {
|
||||
this.matrix.get(x).set(y, originalObjs.get(posSrc.getY()));
|
||||
}
|
||||
@@ -222,8 +222,8 @@ public final class Matrix2<T> implements Iterable<T> {
|
||||
return this.obj;
|
||||
}
|
||||
|
||||
int x = this.x;
|
||||
int y = this.y;
|
||||
var x = this.x;
|
||||
var y = this.y;
|
||||
for (; x < Matrix2.this.matrix.size(); x++) {
|
||||
for (; y < Matrix2.this.matrix.get(x).size(); y++) {
|
||||
this.obj = Matrix2.this.matrix.get(x).get(y);
|
||||
@@ -251,9 +251,9 @@ public final class Matrix2<T> implements Iterable<T> {
|
||||
|
||||
@Override
|
||||
public void forEach(final Consumer<? super T> action) {
|
||||
for (int x = 0; x < this.matrix.size(); x++) {
|
||||
for (int y = 0; y < this.matrix.get(x).size(); y++) {
|
||||
final T obj = this.matrix.get(x).get(y);
|
||||
for (var x = 0; x < this.matrix.size(); x++) {
|
||||
for (var y = 0; y < this.matrix.get(x).size(); y++) {
|
||||
final var obj = this.matrix.get(x).get(y);
|
||||
if (obj != null) {
|
||||
action.accept(obj);
|
||||
}
|
||||
@@ -264,9 +264,9 @@ public final class Matrix2<T> implements Iterable<T> {
|
||||
public void forEach(final BiConsumer<CoordI2, T> consumer) {
|
||||
final CoordI2 coord = MutableCoordI2.create();
|
||||
|
||||
for (int x = 0; x < this.matrix.size(); x++) {
|
||||
for (int y = 0; y < this.matrix.get(x).size(); y++) {
|
||||
final T obj = this.matrix.get(x).get(y);
|
||||
for (var x = 0; x < this.matrix.size(); x++) {
|
||||
for (var y = 0; y < this.matrix.get(x).size(); y++) {
|
||||
final var obj = this.matrix.get(x).get(y);
|
||||
if (obj != null) {
|
||||
coord.setXY(x, y);
|
||||
consumer.accept(coord, obj);
|
||||
|
||||
@@ -51,10 +51,10 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void add(final T obj) {
|
||||
final RectI2 rect = this.toRectI2(obj.getPosition(), obj.getDimension());
|
||||
final var rect = this.toRectI2(obj.getPosition(), obj.getDimension());
|
||||
this.expandTree(rect);
|
||||
|
||||
Node<T> node = this.root;
|
||||
var node = this.root;
|
||||
traversal: while (true) {
|
||||
if (node.branches == null) {
|
||||
// Add leaf to fresh branch
|
||||
@@ -65,14 +65,14 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
|
||||
// Overflow -> Split if not already at lowest level
|
||||
if (node.createBranches()) {
|
||||
final List<T> toSplit = node.leaves;
|
||||
final var toSplit = node.leaves;
|
||||
if (toSplit != null) {
|
||||
node.leaves = null;
|
||||
|
||||
splitLeaves: for (int l = 0; l < toSplit.size(); l++) {
|
||||
final T leaf = toSplit.get(l);
|
||||
splitLeaves: for (var l = 0; l < toSplit.size(); l++) {
|
||||
final var leaf = toSplit.get(l);
|
||||
|
||||
for (int b = 0; b < ORDER; b++) {
|
||||
for (var b = 0; b < ORDER; b++) {
|
||||
if (this.contains(node.branches[b], leaf)) {
|
||||
this.addLeave(node.branches[b], leaf);
|
||||
continue splitLeaves;
|
||||
@@ -88,7 +88,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
else {
|
||||
// Traverse
|
||||
for (int i = 0; i < ORDER; i++) {
|
||||
for (var i = 0; i < ORDER; i++) {
|
||||
if (this.contains(node.branches[i], rect)) {
|
||||
node = node.branches[i];
|
||||
continue traversal;
|
||||
@@ -105,17 +105,17 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
@SuppressWarnings("unchecked")
|
||||
private void expandTree(final RectI2 rect) {
|
||||
if (this.root == null) {
|
||||
final int side = 1 << DEPTH_START;
|
||||
final var side = 1 << DEPTH_START;
|
||||
this.root = new Node<>(rect.getC0().getX() - side, rect.getC0().getY() - side, side << 1);
|
||||
this.root.createBranches();
|
||||
this.recalcDepth();
|
||||
}
|
||||
|
||||
for (int i = 0; !this.contains(this.root, rect); i++) {
|
||||
final RectI2 expansion = new RectI2(MutableCoordI2.create(), MutableCoordI2.create());
|
||||
final int[] branchesIntersect = new int[4];
|
||||
int intersects = 0;
|
||||
int containsBranch = -1;
|
||||
for (var i = 0; !this.contains(this.root, rect); i++) {
|
||||
final var expansion = new RectI2(MutableCoordI2.create(), MutableCoordI2.create());
|
||||
final var branchesIntersect = new int[4];
|
||||
var intersects = 0;
|
||||
var containsBranch = -1;
|
||||
|
||||
expansion.getC0().setXY(this.root.xMin, this.root.yMin);
|
||||
expansion.getC1().setXY(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
@@ -157,8 +157,8 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
|
||||
Node<T> rootNew = null;
|
||||
final int branch = containsBranch != -1 ? containsBranch : branchesIntersect[i % intersects];
|
||||
final int size = this.root.xMax - this.root.xMin + 1;
|
||||
final var branch = containsBranch != -1 ? containsBranch : branchesIntersect[i % intersects];
|
||||
final var size = this.root.xMax - this.root.xMin + 1;
|
||||
switch (branch) {
|
||||
case 0:
|
||||
rootNew = new Node<>(this.root.xMin, this.root.yMin, size << 1);
|
||||
@@ -221,7 +221,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
|
||||
@Override
|
||||
public void remove(final T obj) {
|
||||
final RectI2 rect = this.toRectI2Bounded(obj.getPosition(), obj.getDimension());
|
||||
final var rect = this.toRectI2Bounded(obj.getPosition(), obj.getDimension());
|
||||
if (rect == null) {
|
||||
return;
|
||||
}
|
||||
@@ -231,7 +231,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void remove(final T obj, final RectI2 rect) {
|
||||
Node<T> node = this.root;
|
||||
var node = this.root;
|
||||
traversal: while (true) {
|
||||
if (node.leaves != null) {
|
||||
node.leaves.remove(obj);
|
||||
@@ -243,7 +243,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
|
||||
if (node.branches != null) {
|
||||
for (int i = 0; i < ORDER; i++) {
|
||||
for (var i = 0; i < ORDER; i++) {
|
||||
if (this.contains(node.branches[i], rect)) {
|
||||
node = node.branches[i];
|
||||
continue traversal;
|
||||
@@ -256,9 +256,9 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
|
||||
private void shrink(final Node<T> node_) {
|
||||
Node<T> node = node_;
|
||||
var node = node_;
|
||||
while (node.parent != null) {
|
||||
for (int i = 0; i < ORDER; i++) {
|
||||
for (var i = 0; i < ORDER; i++) {
|
||||
if (node.parent.branches[i].leaves != null || node.parent.branches[i].branches != null) {
|
||||
return;
|
||||
}
|
||||
@@ -272,17 +272,17 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void move(final T obj, final CoordI2 oldPosition, final CoordI2 oldDimension) {
|
||||
final RectI2 rect = this.toRectI2Bounded(oldPosition, oldDimension);
|
||||
final var rect = this.toRectI2Bounded(oldPosition, oldDimension);
|
||||
if (rect != null) {
|
||||
int nodes = 0;
|
||||
Node<T> node = this.root;
|
||||
var nodes = 0;
|
||||
var node = this.root;
|
||||
traversal: while (true) {
|
||||
if (node.leaves != null) {
|
||||
this.nodesCache[nodes++] = node;
|
||||
}
|
||||
|
||||
if (node.branches != null) {
|
||||
for (int i = 0; i < ORDER; i++) {
|
||||
for (var i = 0; i < ORDER; i++) {
|
||||
if (this.contains(node.branches[i], rect)) {
|
||||
node = node.branches[i];
|
||||
continue traversal;
|
||||
@@ -292,7 +292,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
|
||||
if (!this.contains(node, obj)) {
|
||||
while (nodes-- > 0) {
|
||||
final Node<T> curNode = this.nodesCache[nodes];
|
||||
final var curNode = this.nodesCache[nodes];
|
||||
if (curNode.leaves != null) {
|
||||
curNode.leaves.remove(obj);
|
||||
if (curNode.leaves.isEmpty()) {
|
||||
@@ -319,7 +319,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
return this.findDim1(position, filter);
|
||||
}
|
||||
|
||||
final RectI2 rect = this.toRectI2Bounded(position, dimension);
|
||||
final var rect = this.toRectI2Bounded(position, dimension);
|
||||
if (rect == null) {
|
||||
return List.of();
|
||||
}
|
||||
@@ -337,7 +337,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
this.resultHolder.get().add(obj);
|
||||
}, filter);
|
||||
|
||||
final List<T> result = this.resultHolder.get();
|
||||
final var result = this.resultHolder.get();
|
||||
if (result == null) {
|
||||
return List.of();
|
||||
}
|
||||
@@ -349,13 +349,13 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
private List<T> findDimN(final RectI2 rect, final Predicate<T> filter) {
|
||||
List<T> result = null;
|
||||
|
||||
int level = 0;
|
||||
int branch = 0;
|
||||
Node<T> node = this.root;
|
||||
var level = 0;
|
||||
var branch = 0;
|
||||
var node = this.root;
|
||||
|
||||
traversal: while (true) {
|
||||
if (node.branches != null) {
|
||||
for (int b = branch; b < ORDER; b++) {
|
||||
for (var b = branch; b < ORDER; b++) {
|
||||
if (this.intersects(node.branches[b], rect)) {
|
||||
node = node.branches[b];
|
||||
this.traverseStack[level++] = b + 1;
|
||||
@@ -367,8 +367,8 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
|
||||
if (node.leaves != null) {
|
||||
for (int i = 0; i < node.leaves.size(); i++) {
|
||||
final T obj = node.leaves.get(i);
|
||||
for (var i = 0; i < node.leaves.size(); i++) {
|
||||
final var obj = node.leaves.get(i);
|
||||
if (this.intersects(obj, rect) && (filter == null || filter.test((T) obj))) {
|
||||
if (result == null) {
|
||||
result = new ArrayList<>(this.resultDim);
|
||||
@@ -397,16 +397,16 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T findFirstAt(final CoordI2 position, final Predicate<T> filter) {
|
||||
final RectI2 rect = this.toRectI2Bounded(position, ImmutableCoordI2.one());
|
||||
final var rect = this.toRectI2Bounded(position, ImmutableCoordI2.one());
|
||||
if (rect == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Node<T> node = this.root;
|
||||
var node = this.root;
|
||||
traversal: while (true) {
|
||||
if (node.leaves != null) {
|
||||
for (int i = 0; i < node.leaves.size(); i++) {
|
||||
final T obj = node.leaves.get(i);
|
||||
for (var i = 0; i < node.leaves.size(); i++) {
|
||||
final var obj = node.leaves.get(i);
|
||||
if (this.contains(obj, rect) && (filter == null || filter.test((T) obj))) {
|
||||
return obj;
|
||||
}
|
||||
@@ -414,7 +414,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
|
||||
if (node.branches != null) {
|
||||
for (int i = 0; i < ORDER; i++) {
|
||||
for (var i = 0; i < ORDER; i++) {
|
||||
if (this.contains(node.branches[i], rect)) {
|
||||
node = node.branches[i];
|
||||
continue traversal;
|
||||
@@ -431,16 +431,16 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void executeAt(final CoordI2 position, final Consumer<T> consumer, final Predicate<T> filter) {
|
||||
final RectI2 rect = this.toRectI2Bounded(position, ImmutableCoordI2.one());
|
||||
final var rect = this.toRectI2Bounded(position, ImmutableCoordI2.one());
|
||||
if (rect == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Node<T> node = this.root;
|
||||
var node = this.root;
|
||||
traversal: while (true) {
|
||||
if (node.leaves != null) {
|
||||
for (int i = 0; i < node.leaves.size(); i++) {
|
||||
final T obj = node.leaves.get(i);
|
||||
for (var i = 0; i < node.leaves.size(); i++) {
|
||||
final var obj = node.leaves.get(i);
|
||||
if (this.contains(obj, rect) && (filter == null || filter.test((T) obj))) {
|
||||
consumer.accept(obj);
|
||||
}
|
||||
@@ -448,7 +448,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
|
||||
if (node.branches != null) {
|
||||
for (int i = 0; i < ORDER; i++) {
|
||||
for (var i = 0; i < ORDER; i++) {
|
||||
if (this.contains(node.branches[i], rect)) {
|
||||
node = node.branches[i];
|
||||
continue traversal;
|
||||
@@ -493,7 +493,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
|
||||
if (this.node.leaves != null) {
|
||||
if (this.leaf < this.node.leaves.size()) {
|
||||
final T obj = this.node.leaves.get(this.leaf++);
|
||||
final var obj = this.node.leaves.get(this.leaf++);
|
||||
this.next = obj;
|
||||
break traversal;
|
||||
}
|
||||
@@ -533,8 +533,8 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
public void forEach(final Consumer<? super T> action) {
|
||||
this.traverseAll(node -> {
|
||||
if (node.leaves != null) {
|
||||
for (int i = 0; i < node.leaves.size(); i++) {
|
||||
final T obj = node.leaves.get(i);
|
||||
for (var i = 0; i < node.leaves.size(); i++) {
|
||||
final var obj = node.leaves.get(i);
|
||||
action.accept(obj);
|
||||
}
|
||||
}
|
||||
@@ -564,9 +564,9 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
return;
|
||||
}
|
||||
|
||||
int level = 0;
|
||||
int branch = 0;
|
||||
Node<T> node = this.root;
|
||||
var level = 0;
|
||||
var branch = 0;
|
||||
var node = this.root;
|
||||
|
||||
traversal: while (true) {
|
||||
if (node.branches != null && branch < ORDER) {
|
||||
@@ -644,8 +644,8 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
|
||||
public boolean intersects(final T obj, final RectI2 rect) {
|
||||
final int oUpperX = obj.getDimension().getX() + obj.getPosition().getX();
|
||||
final int oUpperY = obj.getDimension().getY() + obj.getPosition().getY();
|
||||
final var oUpperX = obj.getDimension().getX() + obj.getPosition().getX();
|
||||
final var oUpperY = obj.getDimension().getY() + obj.getPosition().getY();
|
||||
return ((oUpperX < obj.getPosition().getX() || oUpperX > rect.getC0().getX()) &&
|
||||
(oUpperY < obj.getPosition().getY() || oUpperY > rect.getC0().getY()) &&
|
||||
(rect.getC1().getX() + 1 < rect.getC0().getX() || rect.getC1().getX() >= obj.getPosition().getX()) &&
|
||||
@@ -692,7 +692,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
}
|
||||
|
||||
boolean createBranches() {
|
||||
final int partition = (this.xMax - this.xMin + 1) >> 1;
|
||||
final var partition = (this.xMax - this.xMin + 1) >> 1;
|
||||
if (partition == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -708,7 +708,7 @@ public final class QuadTree<T extends SpatialIndex2Capable> implements SpatialIn
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final var builder = new StringBuilder();
|
||||
builder.append("Node [xMin=");
|
||||
builder.append(this.xMin);
|
||||
builder.append(", xMax=");
|
||||
|
||||
@@ -44,8 +44,8 @@ public class Area2 extends Point2 implements HasPositionAndDimension2, SpatialIn
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
final var prime = 31;
|
||||
var result = super.hashCode();
|
||||
result = prime * result + ((this.dimension == null) ? 0 : this.dimension.hashCode());
|
||||
return result;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class Area2 extends Point2 implements HasPositionAndDimension2, SpatialIn
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
final Area2 other = (Area2) obj;
|
||||
final var other = (Area2) obj;
|
||||
if (this.dimension == null) {
|
||||
if (other.dimension != null) {
|
||||
return false;
|
||||
@@ -72,7 +72,7 @@ public class Area2 extends Point2 implements HasPositionAndDimension2, SpatialIn
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final var builder = new StringBuilder();
|
||||
builder.append("Area2 [getPosition()=");
|
||||
builder.append(this.getPosition());
|
||||
builder.append(", dimension=");
|
||||
|
||||
@@ -59,7 +59,7 @@ public interface Coord2Conversion {
|
||||
vNorm = (CoordD2) this;
|
||||
}
|
||||
|
||||
final double length = WorldUtils2.getDistance(vNorm);
|
||||
final var length = WorldUtils2.getDistance(vNorm);
|
||||
if (length > 0.0) {
|
||||
vNorm = vNorm.divide(length);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public enum Edge2 {
|
||||
LEFT(),
|
||||
TOP();
|
||||
|
||||
public final static Edge2[] VALUES_CACHED = new Edge2[] {
|
||||
public final static Edge2[] VALUES_CACHED = {
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
LEFT,
|
||||
@@ -121,7 +121,7 @@ public enum Edge2 {
|
||||
}
|
||||
|
||||
public static String toString(final int edges) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final var sb = new StringBuilder();
|
||||
sb.append("Edges [");
|
||||
|
||||
for (final Edge2 edge : Edge2.VALUES_CACHED) {
|
||||
@@ -135,7 +135,7 @@ public enum Edge2 {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private int bit;
|
||||
private final int bit;
|
||||
|
||||
Edge2() {
|
||||
this.bit = 1 << this.ordinal();
|
||||
|
||||
@@ -129,28 +129,28 @@ public final class ImmutableCoordD2 implements CoordD2 {
|
||||
|
||||
@Override
|
||||
public ImmutableCoordD2 divide(final CoordD2 delta) {
|
||||
final double dx = delta.getX() != 0.0 ? delta.getX() : 1.0;
|
||||
final double dy = delta.getY() != 0.0 ? delta.getY() : 1.0;
|
||||
final var dx = delta.getX() != 0.0 ? delta.getX() : 1.0;
|
||||
final var dy = delta.getY() != 0.0 ? delta.getY() : 1.0;
|
||||
return create(this.x / dx, this.y / dy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableCoordD2 divide(final double dx, final double dy) {
|
||||
final double dx_ = dx != 0.0 ? dx : 1.0;
|
||||
final double dy_ = dy != 0.0 ? dy : 1.0;
|
||||
final var dx_ = dx != 0.0 ? dx : 1.0;
|
||||
final var dy_ = dy != 0.0 ? dy : 1.0;
|
||||
return create(this.x / dx_, this.y / dy_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordD2 divide(final double n) {
|
||||
final double n_ = n != 0.0 ? n : 1.0;
|
||||
final var n_ = n != 0.0 ? n : 1.0;
|
||||
return create(this.x / n_, this.y / n_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
final var prime = 31;
|
||||
var result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(this.x);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
@@ -164,10 +164,9 @@ public final class ImmutableCoordD2 implements CoordD2 {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if ((obj == null) || !(obj instanceof CoordD2)) {
|
||||
if ((obj == null) || !(obj instanceof final CoordD2 other)) {
|
||||
return false;
|
||||
}
|
||||
final CoordD2 other = (CoordD2) obj;
|
||||
if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.getX())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ public final class ImmutableCoordI2 implements CoordI2 {
|
||||
private final static ImmutableCoordI2 COORD_ONE = new ImmutableCoordI2(1, 1);
|
||||
|
||||
static {
|
||||
int i = 0;
|
||||
for (int x = -COORD_CACHE_BOUND; x < COORD_CACHE_BOUND; x++) {
|
||||
for (int y = -COORD_CACHE_BOUND; y < COORD_CACHE_BOUND; y++) {
|
||||
var i = 0;
|
||||
for (var x = -COORD_CACHE_BOUND; x < COORD_CACHE_BOUND; x++) {
|
||||
for (var y = -COORD_CACHE_BOUND; y < COORD_CACHE_BOUND; y++) {
|
||||
COORD_CACHE[i++] = new ImmutableCoordI2(x, y);
|
||||
}
|
||||
}
|
||||
@@ -52,13 +52,13 @@ public final class ImmutableCoordI2 implements CoordI2 {
|
||||
|
||||
public static ImmutableCoordI2 create(final int x, final int y) {
|
||||
if (x >= -COORD_CACHE_BOUND && x < COORD_CACHE_BOUND && y >= -COORD_CACHE_BOUND && y < COORD_CACHE_BOUND) {
|
||||
final int idx = (x + COORD_CACHE_BOUND) * COORD_CACHE_DIM + (y + COORD_CACHE_BOUND);
|
||||
final var idx = (x + COORD_CACHE_BOUND) * COORD_CACHE_DIM + (y + COORD_CACHE_BOUND);
|
||||
if (idx >= 0 && idx < COORD_CACHE_SIZE) {
|
||||
return COORD_CACHE[idx];
|
||||
}
|
||||
}
|
||||
|
||||
ImmutableCoordI2 cached = LAST_CACHED;
|
||||
var cached = LAST_CACHED;
|
||||
if (cached.getX() != x || cached.getY() != y) {
|
||||
cached = new ImmutableCoordI2(x, y);
|
||||
LAST_CACHED = cached;
|
||||
@@ -160,28 +160,28 @@ public final class ImmutableCoordI2 implements CoordI2 {
|
||||
|
||||
@Override
|
||||
public ImmutableCoordI2 divide(final HasPosition2 delta) {
|
||||
final int dx = delta.getPosition().getX() != 0 ? delta.getPosition().getX() : 1;
|
||||
final int dy = delta.getPosition().getY() != 0 ? delta.getPosition().getY() : 1;
|
||||
final var dx = delta.getPosition().getX() != 0 ? delta.getPosition().getX() : 1;
|
||||
final var dy = delta.getPosition().getY() != 0 ? delta.getPosition().getY() : 1;
|
||||
return create(this.x / dx, this.y / dy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableCoordI2 divide(final int dx, final int dy) {
|
||||
final int dx_ = dx != 0 ? dx : 1;
|
||||
final int dy_ = dy != 0 ? dy : 1;
|
||||
final var dx_ = dx != 0 ? dx : 1;
|
||||
final var dy_ = dy != 0 ? dy : 1;
|
||||
return create(this.x / dx_, this.y / dy_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableCoordI2 divide(final int n) {
|
||||
final int n_ = n != 0 ? n : 1;
|
||||
final var n_ = n != 0 ? n : 1;
|
||||
return create(this.x / n_, this.y / n_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
final var prime = 31;
|
||||
var result = 1;
|
||||
result = prime * result + this.x;
|
||||
result = prime * result + this.y;
|
||||
return result;
|
||||
@@ -192,10 +192,9 @@ public final class ImmutableCoordI2 implements CoordI2 {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if ((obj == null) || !(obj instanceof CoordI2)) {
|
||||
if ((obj == null) || !(obj instanceof final CoordI2 other)) {
|
||||
return false;
|
||||
}
|
||||
final CoordI2 other = (CoordI2) obj;
|
||||
if (this.x != other.getX()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -178,8 +178,8 @@ public final class MutableCoordD2 implements CoordD2 {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
final var prime = 31;
|
||||
var result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(this.x);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
@@ -193,10 +193,9 @@ public final class MutableCoordD2 implements CoordD2 {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if ((obj == null) || !(obj instanceof CoordD2)) {
|
||||
if ((obj == null) || !(obj instanceof final CoordD2 other)) {
|
||||
return false;
|
||||
}
|
||||
final CoordD2 other = (CoordD2) obj;
|
||||
if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.getX())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -178,8 +178,8 @@ public final class MutableCoordI2 implements CoordI2 {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
final var prime = 31;
|
||||
var result = 1;
|
||||
result = prime * result + this.x;
|
||||
result = prime * result + this.y;
|
||||
return result;
|
||||
@@ -190,10 +190,9 @@ public final class MutableCoordI2 implements CoordI2 {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if ((obj == null) || !(obj instanceof CoordI2)) {
|
||||
if ((obj == null) || !(obj instanceof final CoordI2 other)) {
|
||||
return false;
|
||||
}
|
||||
final CoordI2 other = (CoordI2) obj;
|
||||
if (this.x != other.getX()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ public class Point2 implements HasPosition2 {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
final var prime = 31;
|
||||
var result = 1;
|
||||
result = prime * result + ((this.coord == null) ? 0 : this.coord.hashCode());
|
||||
return result;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class Point2 implements HasPosition2 {
|
||||
if ((obj == null) || (this.getClass() != obj.getClass())) {
|
||||
return false;
|
||||
}
|
||||
final Point2 other = (Point2) obj;
|
||||
final var other = (Point2) obj;
|
||||
if (this.coord == null) {
|
||||
if (other.coord != null) {
|
||||
return false;
|
||||
@@ -54,7 +54,7 @@ public class Point2 implements HasPosition2 {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final var builder = new StringBuilder();
|
||||
builder.append("Point2 [coord=");
|
||||
builder.append(this.coord);
|
||||
builder.append("]");
|
||||
|
||||
@@ -58,8 +58,8 @@ public class RectI2 {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
final var prime = 31;
|
||||
var result = 1;
|
||||
result = prime * result + ((this.c0 == null) ? 0 : this.c0.hashCode());
|
||||
result = prime * result + ((this.c1 == null) ? 0 : this.c1.hashCode());
|
||||
return result;
|
||||
@@ -73,7 +73,7 @@ public class RectI2 {
|
||||
if ((obj == null) || (this.getClass() != obj.getClass())) {
|
||||
return false;
|
||||
}
|
||||
final RectI2 other = (RectI2) obj;
|
||||
final var other = (RectI2) obj;
|
||||
if (this.c0 == null) {
|
||||
if (other.c0 != null) {
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package de.extio.game_engine.util;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import de.extio.game_engine.util.rng.ThreadLocalXorShift128Random;
|
||||
@@ -14,7 +13,7 @@ public final class FastRandomUUID {
|
||||
* Creates a random UUID that has been created fast without draining the operating system's pool of entropy but is not safe for security relevant use (but this is usually not our use case anyway)
|
||||
*/
|
||||
public static UUID create() {
|
||||
final Random cur = ThreadLocalXorShift128Random.current();
|
||||
final var cur = ThreadLocalXorShift128Random.current();
|
||||
return new UUID(cur.nextLong(), cur.nextLong());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,13 @@ import java.util.NoSuchElementException;
|
||||
public class RingBuffer<E> extends AbstractQueue<E> {
|
||||
|
||||
private final E[] buffer;
|
||||
|
||||
private int head;
|
||||
|
||||
private int tail;
|
||||
|
||||
private int size;
|
||||
|
||||
private final int capacity;
|
||||
|
||||
/**
|
||||
@@ -65,7 +69,7 @@ public class RingBuffer<E> extends AbstractQueue<E> {
|
||||
return null;
|
||||
}
|
||||
|
||||
final E element = this.buffer[this.head];
|
||||
final var element = this.buffer[this.head];
|
||||
this.buffer[this.head] = null; // Help GC
|
||||
this.head = (this.head + 1) % this.capacity;
|
||||
this.size--;
|
||||
@@ -93,7 +97,7 @@ public class RingBuffer<E> extends AbstractQueue<E> {
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (int i = 0; i < this.capacity; i++) {
|
||||
for (var i = 0; i < this.capacity; i++) {
|
||||
this.buffer[i] = null;
|
||||
}
|
||||
this.head = 0;
|
||||
@@ -131,12 +135,14 @@ public class RingBuffer<E> extends AbstractQueue<E> {
|
||||
if (index < 0 || index >= this.size) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size);
|
||||
}
|
||||
final int actualIndex = (this.head + index) % this.capacity;
|
||||
final var actualIndex = (this.head + index) % this.capacity;
|
||||
return this.buffer[actualIndex];
|
||||
}
|
||||
|
||||
private class RingBufferIterator implements Iterator<E> {
|
||||
|
||||
private int current = 0;
|
||||
|
||||
private final int expectedSize = RingBuffer.this.size;
|
||||
|
||||
@Override
|
||||
@@ -149,7 +155,7 @@ public class RingBuffer<E> extends AbstractQueue<E> {
|
||||
if (this.current >= this.expectedSize) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
final E element = RingBuffer.this.get(this.current);
|
||||
final var element = RingBuffer.this.get(this.current);
|
||||
this.current++;
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class XorShift128Random extends Random {
|
||||
}
|
||||
|
||||
public XorShift128Random(final String state) {
|
||||
final UUID uuid = UUID.fromString(state);
|
||||
final var uuid = UUID.fromString(state);
|
||||
this.state0 = uuid.getMostSignificantBits();
|
||||
this.state1 = uuid.getLeastSignificantBits();
|
||||
}
|
||||
@@ -41,8 +41,8 @@ public final class XorShift128Random extends Random {
|
||||
|
||||
@Override
|
||||
public long nextLong() {
|
||||
long s1 = this.state0;
|
||||
final long s0 = this.state1;
|
||||
var s1 = this.state0;
|
||||
final var s0 = this.state1;
|
||||
this.state0 = s0;
|
||||
s1 ^= s1 << 23;
|
||||
return (this.state1 = s1 ^ s0 ^ (s1 >>> 17) ^ (s0 >>> 26)) + s0;
|
||||
|
||||
@@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -15,6 +14,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class RingBufferTest {
|
||||
|
||||
private RingBuffer<String> buffer;
|
||||
|
||||
private static final int CAPACITY = 3;
|
||||
|
||||
@BeforeEach
|
||||
@@ -122,7 +122,7 @@ public class RingBufferTest {
|
||||
this.buffer.offer("C");
|
||||
this.buffer.offer("D"); // B, C, D
|
||||
|
||||
final Iterator<String> it = this.buffer.iterator();
|
||||
final var it = this.buffer.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals("B", it.next());
|
||||
assertTrue(it.hasNext());
|
||||
@@ -136,7 +136,7 @@ public class RingBufferTest {
|
||||
@Test
|
||||
void testIteratorRemoveUnsupported() {
|
||||
this.buffer.offer("A");
|
||||
final Iterator<String> it = this.buffer.iterator();
|
||||
final var it = this.buffer.iterator();
|
||||
assertThrows(UnsupportedOperationException.class, it::remove);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user