refactor(renderer): Rename closeStatic method to staticCleanupAfterFrame for clarity

This commit is contained in:
extio-de
2025-12-25 16:40:02 +01:00
parent 53efaa0455
commit 4efbe3e8e3
10 changed files with 30 additions and 38 deletions

View File

@@ -202,7 +202,7 @@ public class G2DRenderer implements Renderer {
} }
for (final RenderingBo bo : usedRenderingBoTypes.values()) { for (final RenderingBo bo : usedRenderingBoTypes.values()) {
bo.closeStatic(); bo.staticCleanupAfterFrame();
} }
// //

View File

@@ -18,7 +18,7 @@ public abstract class G2DAbstractRenderingBo extends AbstractRenderingBo {
public abstract void render(Graphics2D graphics, double scaleFactor, boolean force); public abstract void render(Graphics2D graphics, double scaleFactor, boolean force);
@Override @Override
public void closeStatic() { public void staticCleanupAfterFrame() {
} }
} }

View File

@@ -41,6 +41,10 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
private final static int[] BUILTIN_SCROLL_OFFSET_X = new int[2]; private final static int[] BUILTIN_SCROLL_OFFSET_X = new int[2];
private final static List<Star> STARS = new ArrayList<>();
private static CoordI2 STARS_LAST_VIEWPORT = ImmutableCoordI2.create();
private final CoordI2 bgrOffset = MutableCoordI2.create(); private final CoordI2 bgrOffset = MutableCoordI2.create();
private final CoordI2 sourceOffset = MutableCoordI2.create(); private final CoordI2 sourceOffset = MutableCoordI2.create();
@@ -51,10 +55,6 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
private final CoordI2 overflow = MutableCoordI2.create(); private final CoordI2 overflow = MutableCoordI2.create();
private List<Star> stars;
private CoordI2 starsViewport = ImmutableCoordI2.create();
public G2DDrawBackground() { public G2DDrawBackground() {
super(RenderingBoLayer.BACKGROUND0); super(RenderingBoLayer.BACKGROUND0);
} }
@@ -69,8 +69,6 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
this.destPosition.setXY(o.destPosition); this.destPosition.setXY(o.destPosition);
this.destPosition2.setXY(o.destPosition2); this.destPosition2.setXY(o.destPosition2);
this.overflow.setXY(o.overflow); this.overflow.setXY(o.overflow);
this.starsViewport = o.starsViewport;
this.stars = o.stars; // shallow copy for performance
} }
} }
@@ -83,7 +81,6 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
this.destPosition.setXY(0, 0); this.destPosition.setXY(0, 0);
this.destPosition2.setXY(0, 0); this.destPosition2.setXY(0, 0);
this.overflow.setXY(0, 0); this.overflow.setXY(0, 0);
this.starsViewport = ImmutableCoordI2.create();
} }
@Override @Override
@@ -152,7 +149,7 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
private void drawStars(final Graphics2D graphics, final CoordI2 offset, final CoordI2 viewPort) { private void drawStars(final Graphics2D graphics, final CoordI2 offset, final CoordI2 viewPort) {
this.generateStars(viewPort); this.generateStars(viewPort);
for (final Star element : this.stars) { for (final Star element : STARS) {
graphics.setColor(element.color.toAwtColor()); graphics.setColor(element.color.toAwtColor());
graphics.fillOval( graphics.fillOval(
Math.floorMod(element.position.getX() - offset.getX(), viewPort.getX()), Math.floorMod(element.position.getX() - offset.getX(), viewPort.getX()),
@@ -235,20 +232,15 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
} }
private void generateStars(final CoordI2 viewPort) { private void generateStars(final CoordI2 viewPort) {
if (this.stars == null || !viewPort.equals(this.starsViewport)) { if (STARS.isEmpty() || !viewPort.equals(STARS_LAST_VIEWPORT)) {
if (this.stars == null) { STARS.clear();
this.stars = new ArrayList<>();
}
else {
this.stars.clear();
}
this.starsViewport = viewPort.toImmutableCoordI2(); STARS_LAST_VIEWPORT = viewPort.toImmutableCoordI2();
final var rand = ThreadLocalXorShift128Random.current(); final var rand = ThreadLocalXorShift128Random.current();
for (var i = 0; i < 350; i++) { for (var i = 0; i < 350; i++) {
this.stars.add(new Star( STARS.add(new Star(
ImmutableCoordI2.create(rand.nextInt(this.starsViewport.getX()), rand.nextInt(this.starsViewport.getY())), ImmutableCoordI2.create(rand.nextInt(STARS_LAST_VIEWPORT.getX()), rand.nextInt(STARS_LAST_VIEWPORT.getY())),
ImmutableCoordI2.create(rand.nextInt(3) + 2, rand.nextInt(3) + 2), ImmutableCoordI2.create(rand.nextInt(3) + 2, rand.nextInt(3) + 2),
new ImmutableRgbaColor(rand.nextInt(30) + 100, rand.nextInt(30) + 100, rand.nextInt(30) + 130))); new ImmutableRgbaColor(rand.nextInt(30) + 100, rand.nextInt(30) + 100, rand.nextInt(30) + 130)));
} }

View File

@@ -17,9 +17,9 @@ public class G2DDrawFpsHistory extends G2DAbstractRenderingBo {
private Collection<Integer> history; private Collection<Integer> history;
private final int[] thresholds = new int[4]; private final static int[] thresholds = new int[4];
private int thresholdsFrameRate; private static int thresholdsFrameRate;
public G2DDrawFpsHistory() { public G2DDrawFpsHistory() {
super(RenderingBoLayer.TOP); super(RenderingBoLayer.TOP);
@@ -32,12 +32,12 @@ public class G2DDrawFpsHistory extends G2DAbstractRenderingBo {
@Override @Override
public void render(final Graphics2D graphics, final double scaleFactor, final boolean force) { public void render(final Graphics2D graphics, final double scaleFactor, final boolean force) {
if (this.thresholdsFrameRate != this.rendererData.getRendererControl().getFrameRate()) { if (thresholdsFrameRate != this.rendererData.getRendererControl().getFrameRate()) {
this.thresholdsFrameRate = this.rendererData.getRendererControl().getFrameRate(); thresholdsFrameRate = this.rendererData.getRendererControl().getFrameRate();
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.2); thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.2);
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.75); thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.75);
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.9); thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.9);
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate()); thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate());
} }
final var x = (int) (this.x * scaleFactor); final var x = (int) (this.x * scaleFactor);
@@ -49,16 +49,16 @@ public class G2DDrawFpsHistory extends G2DAbstractRenderingBo {
} }
final var 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]) { if (val_ < thresholds[0]) {
graphics.setColor(Color.DARK_GRAY); graphics.setColor(Color.DARK_GRAY);
} }
else if (val_ < this.thresholds[1]) { else if (val_ < thresholds[1]) {
graphics.setColor(Color.GRAY); graphics.setColor(Color.GRAY);
} }
else if (val_ < this.thresholds[2]) { else if (val_ < thresholds[2]) {
graphics.setColor(Color.YELLOW); graphics.setColor(Color.YELLOW);
} }
else if (val_ < this.thresholds[3]) { else if (val_ < thresholds[3]) {
graphics.setColor(Color.ORANGE); graphics.setColor(Color.ORANGE);
} }
else { else {

View File

@@ -142,7 +142,7 @@ public class G2DDrawImage extends G2DAbstractRenderingBo implements DrawImageRen
} }
@Override @Override
public void closeStatic() { public void staticCleanupAfterFrame() {
final var it = IMAGE_CACHE.values().iterator(); final var it = IMAGE_CACHE.values().iterator();
while (it.hasNext()) { while (it.hasNext()) {
final var cachedImage = it.next(); final var cachedImage = it.next();

View File

@@ -103,7 +103,7 @@ public class G2DDrawWindow2 extends G2DAbstractRenderingBo implements DrawWindow
} }
@Override @Override
public void closeStatic() { public void staticCleanupAfterFrame() {
final var it = CACHE.values().iterator(); final var it = CACHE.values().iterator();
while (it.hasNext()) { while (it.hasNext()) {
final var entry = it.next(); final var entry = it.next();

View File

@@ -351,7 +351,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
} }
@Override @Override
public void closeStatic() { public void staticCleanupAfterFrame() {
final var it = CACHED_CONTROLS.values().iterator(); final var it = CACHED_CONTROLS.values().iterator();
while (it.hasNext()) { while (it.hasNext()) {
final var control = it.next(); final var control = it.next();

View File

@@ -44,7 +44,7 @@ public class G2DDrawControlTooltip extends G2DAbstractRenderingBo {
} }
@Override @Override
public void closeStatic() { public void staticCleanupAfterFrame() {
TOOLTIP = null; TOOLTIP = null;
} }
} }

View File

@@ -242,7 +242,7 @@ public abstract class AbstractRenderingBo implements RenderingBo {
} }
@Override @Override
public void closeStatic() { public void staticCleanupAfterFrame() {
} }

View File

@@ -109,7 +109,7 @@ public interface RenderingBo extends AutoCloseable {
void apply(RenderingBo other); void apply(RenderingBo other);
void closeStatic(); void staticCleanupAfterFrame();
void setRendererData(RendererData RendererData); void setRendererData(RendererData RendererData);