This commit is contained in:
ngb
2022-06-13 21:23:25 +02:00
parent ab53d0401a
commit 85990023b8

View File

@@ -134,7 +134,7 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
* @param title Der Titel, der oben im Fenster steht. * @param title Der Titel, der oben im Fenster steht.
*/ */
public Zeichenmaschine( String title ) { public Zeichenmaschine( String title ) {
this(STD_WIDTH, STD_HEIGHT, title); this(STD_WIDTH, STD_HEIGHT, title, true);
} }
/** /**
@@ -203,6 +203,7 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
// FPS setzen // FPS setzen
framesPerSecond = STD_FPS; framesPerSecond = STD_FPS;
this.run_once = run_once;
// Settings der Unterklasse aufrufen, falls das Fenster vor dem Öffnen // Settings der Unterklasse aufrufen, falls das Fenster vor dem Öffnen
// verändert werden soll. // verändert werden soll.
@@ -216,12 +217,7 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing( WindowEvent e ) { public void windowClosing( WindowEvent e ) {
if( running ) { exit();
running = false;
quitAfterTeardown = true;
} else {
quit();
}
} }
}); });
@@ -391,7 +387,19 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
/** /**
* Beendet das Programm. * Beendet das Programm.
*/ */
public void quit() { public final void exit() {
if( running ) {
running = false;
this.quitAfterTeardown = true;
} else {
quit(true);
}
}
/**
* Beendet das Programm vollständig.
*/
public final void quit() {
//quit(!IN_BLUEJ); //quit(!IN_BLUEJ);
quit(true); quit(true);
} }
@@ -403,7 +411,7 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
* @param exit Ob die VM beendet werden soll. * @param exit Ob die VM beendet werden soll.
* @see System#exit(int) * @see System#exit(int)
*/ */
public void quit( boolean exit ) { public final void quit( boolean exit ) {
frame.setVisible(false); frame.setVisible(false);
canvas.dispose(); canvas.dispose();
frame.dispose(); frame.dispose();
@@ -830,12 +838,13 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
* @param delta * @param delta
*/ */
public void update( double delta ) { public void update( double delta ) {
running = false; //running = !run_once;
stop_after_update = run_once;
} }
/** /**
* {@code draw()} wird einmal pro Frame aufgerufen. Bei einer * {@code draw()} wird einmal pro Frame aufgerufen. Bei einer
* {@link #getFramesPerSecond() Framerate} von {@code 60} also in etwa 60-Mal * {@link #getFramesPerSecond() Framerate} von 60 also in etwa 60-Mal
* pro Sekunde. In der {@code draw}-Methode wird der Inhalt der Ebenen * pro Sekunde. In der {@code draw}-Methode wird der Inhalt der Ebenen
* manipuliert und deren Inhalte gezeichnet. Am Ende des Frames werden alle * manipuliert und deren Inhalte gezeichnet. Am Ende des Frames werden alle
* Ebenen auf die {@link Zeichenleinwand} übertragen. * Ebenen auf die {@link Zeichenleinwand} übertragen.
@@ -844,7 +853,7 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
* da hier die Zeichnung des Programms erstellt wird. * da hier die Zeichnung des Programms erstellt wird.
*/ */
public void draw() { public void draw() {
// Intentionally left blank running = !stop_after_update;
} }
/** /**
@@ -1012,7 +1021,7 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
tick = 0; tick = 0;
runtime = 0; runtime = 0;
// call setup of subclass // call setup of subclass and wait
setup(); setup();
state = Options.AppState.RUNNING; state = Options.AppState.RUNNING;
@@ -1023,13 +1032,15 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
saveMousePosition(mouseEvent); saveMousePosition(mouseEvent);
handleUpdate(delta); if( state != Options.AppState.PAUSED ) {
handleDraw(); handleUpdate(delta);
handleDraw();
if( canvas != null ) { if( canvas != null ) {
canvas.render(); canvas.render();
//canvas.invalidate(); // canvas.invalidate();
//frame.repaint(); // frame.repaint();
}
} }
// delta time in ns // delta time in ns
@@ -1055,6 +1066,11 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
_runtime = System.currentTimeMillis() - start; _runtime = System.currentTimeMillis() - start;
tick = _tick; tick = _tick;
runtime = _runtime; runtime = _runtime;
if( pause_pending ) {
state = Options.AppState.PAUSED;
pause_pending = false;
}
} }
state = Options.AppState.STOPPED; state = Options.AppState.STOPPED;