refactor(renderer): introduce skipDisplayFrame logic in RendererData and update G2DRenderer rendering cycle
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package de.extio.game_engine.renderer;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -31,6 +32,8 @@ public class RendererData {
|
||||
|
||||
private final AtomicLong frame = new AtomicLong();
|
||||
|
||||
private final AtomicBoolean skipDisplayFrame = new AtomicBoolean(false);
|
||||
|
||||
private final KeycodeRegistry keycodeRegistry;
|
||||
|
||||
private final EventService eventService;
|
||||
@@ -88,6 +91,14 @@ public class RendererData {
|
||||
return this.frame.incrementAndGet();
|
||||
}
|
||||
|
||||
public boolean isSkipDisplayFrame() {
|
||||
return this.skipDisplayFrame.get();
|
||||
}
|
||||
|
||||
public boolean setSkipDisplayFrame(final boolean skipDisplayFrame) {
|
||||
return this.skipDisplayFrame.getAndSet(skipDisplayFrame);
|
||||
}
|
||||
|
||||
public Renderer getRenderer() {
|
||||
return this.renderer;
|
||||
}
|
||||
|
||||
@@ -225,7 +225,10 @@ public class G2DRenderer implements Renderer {
|
||||
// Rendering cycle START
|
||||
//
|
||||
|
||||
bufferStrategy.show();
|
||||
final var skipDisplay = this.rendererData.setSkipDisplayFrame(false);
|
||||
if (! skipDisplay) {
|
||||
bufferStrategy.show();
|
||||
}
|
||||
Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
finally {
|
||||
|
||||
Reference in New Issue
Block a user