mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Refactorings
This commit is contained in:
@@ -108,7 +108,7 @@ public class Spielemaschine extends Zeichenmaschine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw( Graphics2D pGraphics ) {
|
public void draw( Graphics2D graphics ) {
|
||||||
clear();
|
clear();
|
||||||
List<Drawable> it = List.copyOf(drawables);
|
List<Drawable> it = List.copyOf(drawables);
|
||||||
for( Drawable d: it ) {
|
for( Drawable d: it ) {
|
||||||
@@ -116,7 +116,7 @@ public class Spielemaschine extends Zeichenmaschine {
|
|||||||
d.draw(drawing);
|
d.draw(drawing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.draw(pGraphics);
|
super.draw(graphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
/**
|
/**
|
||||||
* Zustand der Zeichenmaschine insgesamt
|
* Zustand der Zeichenmaschine insgesamt
|
||||||
*/
|
*/
|
||||||
private Options.AppState state = Options.AppState.INITIALIZING;
|
private Options.AppState state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zustand des update/draw Threads
|
* Zustand des update/draw Threads
|
||||||
@@ -92,7 +92,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
/**
|
/**
|
||||||
* Ob der Zeichenthread noch laufen soll, oder beendet.
|
* Ob der Zeichenthread noch laufen soll, oder beendet.
|
||||||
*/
|
*/
|
||||||
private boolean running = false;
|
private boolean running;
|
||||||
|
|
||||||
private boolean terminateImediately = false;
|
private boolean terminateImediately = false;
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
* Ob die ZM bei nicht überschriebener update() Methode stoppen soll,
|
* Ob die ZM bei nicht überschriebener update() Methode stoppen soll,
|
||||||
* oder trotzdem weiterläuft.
|
* oder trotzdem weiterläuft.
|
||||||
*/
|
*/
|
||||||
private boolean run_once = true;
|
private final boolean run_once;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aktuelle Frames pro Sekunde der Zeichenmaschine.
|
* Aktuelle Frames pro Sekunde der Zeichenmaschine.
|
||||||
@@ -115,17 +115,17 @@ public class Zeichenmaschine extends Constants {
|
|||||||
/**
|
/**
|
||||||
* Hauptthread der Zeichenmaschine.
|
* Hauptthread der Zeichenmaschine.
|
||||||
*/
|
*/
|
||||||
private Thread mainThread;
|
private final Thread mainThread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue für geplante Aufgaben
|
* Queue für geplante Aufgaben
|
||||||
*/
|
*/
|
||||||
private DelayQueue<DelayedTask> taskQueue = new DelayQueue<>();
|
private final DelayQueue<DelayedTask> taskQueue = new DelayQueue<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue für abgefangene InputEvents
|
* Queue für abgefangene InputEvents
|
||||||
*/
|
*/
|
||||||
private BlockingQueue<InputEvent> eventQueue = new LinkedBlockingQueue<>();
|
private final BlockingQueue<InputEvent> eventQueue = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt an, ob nach Ende des Hauptthreads das Programm beendet werden soll,
|
* Gibt an, ob nach Ende des Hauptthreads das Programm beendet werden soll,
|
||||||
@@ -238,6 +238,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
* @param run_once {@code true} beendet die Zeichenmaschine nach einem
|
* @param run_once {@code true} beendet die Zeichenmaschine nach einem
|
||||||
* Aufruf von {@code draw()}.
|
* Aufruf von {@code draw()}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("static-access")
|
||||||
public Zeichenmaschine( int width, int height, String title, boolean run_once ) {
|
public Zeichenmaschine( int width, int height, String title, boolean run_once ) {
|
||||||
LOG.info("Starting " + APP_NAME + " " + APP_VERSION);
|
LOG.info("Starting " + APP_NAME + " " + APP_VERSION);
|
||||||
|
|
||||||
@@ -321,17 +322,15 @@ public class Zeichenmaschine extends Constants {
|
|||||||
*
|
*
|
||||||
* @param title
|
* @param title
|
||||||
*/
|
*/
|
||||||
private final Zeichenfenster createFrame( Zeichenleinwand c, String title ) {
|
private Zeichenfenster createFrame( Zeichenleinwand c, String title ) {
|
||||||
while( frame == null ) {
|
while( frame == null ) {
|
||||||
try {
|
try {
|
||||||
TaskRunner.invokeLater(new Runnable() {
|
TaskRunner.invokeLater(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Zeichenfenster.setLookAndFeel();
|
Zeichenfenster.setLookAndFeel();
|
||||||
frame = new Zeichenfenster(canvas, title);
|
frame = new Zeichenfenster(canvas, title);
|
||||||
}
|
|
||||||
}).get();
|
}).get();
|
||||||
} catch( InterruptedException e ) {
|
} catch( InterruptedException e ) {
|
||||||
|
// Keep waiting
|
||||||
} catch( ExecutionException e ) {
|
} catch( ExecutionException e ) {
|
||||||
LOG.error(e, "Error initializing application frame: %s", e.getMessage());
|
LOG.error(e, "Error initializing application frame: %s", e.getMessage());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -586,11 +585,11 @@ public class Zeichenmaschine extends Constants {
|
|||||||
* @see Zeichenleinwand#setSize(int, int)
|
* @see Zeichenleinwand#setSize(int, int)
|
||||||
*/
|
*/
|
||||||
public final void setSize( int width, int height ) {
|
public final void setSize( int width, int height ) {
|
||||||
frame.setSize(width, height);
|
frame.setCanvasSize(width, height);
|
||||||
|
|
||||||
java.awt.Rectangle canvasBounds = frame.getCanvasBounds();
|
java.awt.Rectangle canvasBounds = frame.getCanvasBounds();
|
||||||
canvasWidth = (int) canvasBounds.getWidth();
|
canvasWidth = canvasBounds.width;
|
||||||
canvasHeight = (int) canvasBounds.getHeight();
|
canvasHeight = canvasBounds.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1312,7 +1311,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
long overslept = 0L;
|
long overslept = 0L;
|
||||||
// Interne Zähler für tick und runtime
|
// Interne Zähler für tick und runtime
|
||||||
int _tick = 0;
|
int _tick = 0;
|
||||||
long _runtime = 0;
|
long _runtime;
|
||||||
// Öffentliche Zähler für Unterklassen
|
// Öffentliche Zähler für Unterklassen
|
||||||
tick = 0;
|
tick = 0;
|
||||||
runtime = 0;
|
runtime = 0;
|
||||||
@@ -1443,7 +1442,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove
|
// TODO: Remove
|
||||||
class DelayedTask implements Delayed {
|
static class DelayedTask implements Delayed {
|
||||||
|
|
||||||
long startTime; // in ms
|
long startTime; // in ms
|
||||||
|
|
||||||
@@ -1541,7 +1540,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
|
|
||||||
public UpdateThreadExecutor() {
|
public UpdateThreadExecutor() {
|
||||||
super(1, 1, 0L,
|
super(1, 1, 0L,
|
||||||
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(),
|
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),
|
||||||
new ThreadFactory() {
|
new ThreadFactory() {
|
||||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user