refactor(renderer): Rename closeStatic method to staticCleanupAfterFrame for clarity
This commit is contained in:
@@ -202,7 +202,7 @@ public class G2DRenderer implements Renderer {
|
||||
}
|
||||
|
||||
for (final RenderingBo bo : usedRenderingBoTypes.values()) {
|
||||
bo.closeStatic();
|
||||
bo.staticCleanupAfterFrame();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -18,7 +18,7 @@ public abstract class G2DAbstractRenderingBo extends AbstractRenderingBo {
|
||||
public abstract void render(Graphics2D graphics, double scaleFactor, boolean force);
|
||||
|
||||
@Override
|
||||
public void closeStatic() {
|
||||
public void staticCleanupAfterFrame() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
|
||||
|
||||
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 sourceOffset = MutableCoordI2.create();
|
||||
@@ -51,10 +55,6 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
|
||||
|
||||
private final CoordI2 overflow = MutableCoordI2.create();
|
||||
|
||||
private List<Star> stars;
|
||||
|
||||
private CoordI2 starsViewport = ImmutableCoordI2.create();
|
||||
|
||||
public G2DDrawBackground() {
|
||||
super(RenderingBoLayer.BACKGROUND0);
|
||||
}
|
||||
@@ -69,8 +69,6 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
|
||||
this.destPosition.setXY(o.destPosition);
|
||||
this.destPosition2.setXY(o.destPosition2);
|
||||
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.destPosition2.setXY(0, 0);
|
||||
this.overflow.setXY(0, 0);
|
||||
this.starsViewport = ImmutableCoordI2.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,7 +149,7 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
|
||||
private void drawStars(final Graphics2D graphics, final CoordI2 offset, final CoordI2 viewPort) {
|
||||
this.generateStars(viewPort);
|
||||
|
||||
for (final Star element : this.stars) {
|
||||
for (final Star element : STARS) {
|
||||
graphics.setColor(element.color.toAwtColor());
|
||||
graphics.fillOval(
|
||||
Math.floorMod(element.position.getX() - offset.getX(), viewPort.getX()),
|
||||
@@ -235,20 +232,15 @@ public class G2DDrawBackground extends G2DAbstractRenderingBo {
|
||||
}
|
||||
|
||||
private void generateStars(final CoordI2 viewPort) {
|
||||
if (this.stars == null || !viewPort.equals(this.starsViewport)) {
|
||||
if (this.stars == null) {
|
||||
this.stars = new ArrayList<>();
|
||||
}
|
||||
else {
|
||||
this.stars.clear();
|
||||
}
|
||||
if (STARS.isEmpty() || !viewPort.equals(STARS_LAST_VIEWPORT)) {
|
||||
STARS.clear();
|
||||
|
||||
this.starsViewport = viewPort.toImmutableCoordI2();
|
||||
STARS_LAST_VIEWPORT = viewPort.toImmutableCoordI2();
|
||||
final var rand = ThreadLocalXorShift128Random.current();
|
||||
|
||||
for (var i = 0; i < 350; i++) {
|
||||
this.stars.add(new Star(
|
||||
ImmutableCoordI2.create(rand.nextInt(this.starsViewport.getX()), rand.nextInt(this.starsViewport.getY())),
|
||||
STARS.add(new Star(
|
||||
ImmutableCoordI2.create(rand.nextInt(STARS_LAST_VIEWPORT.getX()), rand.nextInt(STARS_LAST_VIEWPORT.getY())),
|
||||
ImmutableCoordI2.create(rand.nextInt(3) + 2, rand.nextInt(3) + 2),
|
||||
new ImmutableRgbaColor(rand.nextInt(30) + 100, rand.nextInt(30) + 100, rand.nextInt(30) + 130)));
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ public class G2DDrawFpsHistory extends G2DAbstractRenderingBo {
|
||||
|
||||
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() {
|
||||
super(RenderingBoLayer.TOP);
|
||||
@@ -32,12 +32,12 @@ public class G2DDrawFpsHistory extends G2DAbstractRenderingBo {
|
||||
|
||||
@Override
|
||||
public void render(final Graphics2D graphics, final double scaleFactor, final boolean force) {
|
||||
if (this.thresholdsFrameRate != this.rendererData.getRendererControl().getFrameRate()) {
|
||||
this.thresholdsFrameRate = this.rendererData.getRendererControl().getFrameRate();
|
||||
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.2);
|
||||
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.75);
|
||||
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.9);
|
||||
this.thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate());
|
||||
if (thresholdsFrameRate != this.rendererData.getRendererControl().getFrameRate()) {
|
||||
thresholdsFrameRate = this.rendererData.getRendererControl().getFrameRate();
|
||||
thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.2);
|
||||
thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.75);
|
||||
thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate() * 0.9);
|
||||
thresholds[0] = (int) (1000.0 / this.rendererData.getRendererControl().getFrameRate());
|
||||
}
|
||||
|
||||
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)));
|
||||
|
||||
if (val_ < this.thresholds[0]) {
|
||||
if (val_ < thresholds[0]) {
|
||||
graphics.setColor(Color.DARK_GRAY);
|
||||
}
|
||||
else if (val_ < this.thresholds[1]) {
|
||||
else if (val_ < thresholds[1]) {
|
||||
graphics.setColor(Color.GRAY);
|
||||
}
|
||||
else if (val_ < this.thresholds[2]) {
|
||||
else if (val_ < thresholds[2]) {
|
||||
graphics.setColor(Color.YELLOW);
|
||||
}
|
||||
else if (val_ < this.thresholds[3]) {
|
||||
else if (val_ < thresholds[3]) {
|
||||
graphics.setColor(Color.ORANGE);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -142,7 +142,7 @@ public class G2DDrawImage extends G2DAbstractRenderingBo implements DrawImageRen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeStatic() {
|
||||
public void staticCleanupAfterFrame() {
|
||||
final var it = IMAGE_CACHE.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
final var cachedImage = it.next();
|
||||
|
||||
@@ -103,7 +103,7 @@ public class G2DDrawWindow2 extends G2DAbstractRenderingBo implements DrawWindow
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeStatic() {
|
||||
public void staticCleanupAfterFrame() {
|
||||
final var it = CACHE.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
final var entry = it.next();
|
||||
|
||||
@@ -351,7 +351,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeStatic() {
|
||||
public void staticCleanupAfterFrame() {
|
||||
final var it = CACHED_CONTROLS.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
final var control = it.next();
|
||||
|
||||
@@ -44,7 +44,7 @@ public class G2DDrawControlTooltip extends G2DAbstractRenderingBo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeStatic() {
|
||||
public void staticCleanupAfterFrame() {
|
||||
TOOLTIP = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public abstract class AbstractRenderingBo implements RenderingBo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeStatic() {
|
||||
public void staticCleanupAfterFrame() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ public interface RenderingBo extends AutoCloseable {
|
||||
|
||||
void apply(RenderingBo other);
|
||||
|
||||
void closeStatic();
|
||||
void staticCleanupAfterFrame();
|
||||
|
||||
void setRendererData(RendererData RendererData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user