mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 06:33:34 +02:00
Setter für FPS verhindert das setzen auf weniger als 0 frames
This commit is contained in:
@@ -247,6 +247,11 @@ public class Constants {
|
|||||||
* Zeichenmaschine selbst vorgenommen werden.
|
* Zeichenmaschine selbst vorgenommen werden.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktuell dargestellte Bilder pro Sekunde.
|
||||||
|
*/
|
||||||
|
public static int framesPerSecond = STD_FPS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anzahl der Ticks (Frames), die das Programm bisher läuft.
|
* Anzahl der Ticks (Frames), die das Programm bisher läuft.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
private boolean stop_after_update = false, run_once = true;
|
private boolean stop_after_update = false, run_once = true;
|
||||||
|
|
||||||
// Aktuelle Frames pro Sekunde der Zeichenmaschine.
|
// Aktuelle Frames pro Sekunde der Zeichenmaschine.
|
||||||
private int framesPerSecond;
|
private int framesPerSecondInternal;
|
||||||
|
|
||||||
// Hauptthread der Zeichenmaschine.
|
// Hauptthread der Zeichenmaschine.
|
||||||
private Thread mainThread;
|
private Thread mainThread;
|
||||||
@@ -312,7 +312,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
shapes = getShapesLayer();
|
shapes = getShapesLayer();
|
||||||
|
|
||||||
// FPS setzen
|
// FPS setzen
|
||||||
framesPerSecond = STD_FPS;
|
framesPerSecondInternal = STD_FPS;
|
||||||
this.run_once = run_once;
|
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
|
||||||
@@ -799,7 +799,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
* @return Angepeilte Frames pro Sekunde
|
* @return Angepeilte Frames pro Sekunde
|
||||||
*/
|
*/
|
||||||
public final int getFramesPerSecond() {
|
public final int getFramesPerSecond() {
|
||||||
return framesPerSecond;
|
return framesPerSecondInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -808,7 +808,13 @@ public class Zeichenmaschine extends Constants {
|
|||||||
* @param pFramesPerSecond Neue FPS.
|
* @param pFramesPerSecond Neue FPS.
|
||||||
*/
|
*/
|
||||||
public final void setFramesPerSecond( int pFramesPerSecond ) {
|
public final void setFramesPerSecond( int pFramesPerSecond ) {
|
||||||
framesPerSecond = pFramesPerSecond;
|
if( pFramesPerSecond > 0 ) {
|
||||||
|
framesPerSecondInternal = pFramesPerSecond;
|
||||||
|
} else {
|
||||||
|
framesPerSecondInternal = 1;
|
||||||
|
// Logger ...
|
||||||
|
}
|
||||||
|
framesPerSecond = framesPerSecondInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1363,7 +1369,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
// delta time in ns
|
// delta time in ns
|
||||||
long afterTime = System.nanoTime();
|
long afterTime = System.nanoTime();
|
||||||
long dt = afterTime - beforeTime;
|
long dt = afterTime - beforeTime;
|
||||||
long sleep = ((1000000000L / framesPerSecond) - dt) - overslept;
|
long sleep = ((1000000000L / framesPerSecondInternal) - dt) - overslept;
|
||||||
|
|
||||||
|
|
||||||
if( sleep > 0 ) {
|
if( sleep > 0 ) {
|
||||||
@@ -1382,6 +1388,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
_runtime = System.currentTimeMillis() - start;
|
_runtime = System.currentTimeMillis() - start;
|
||||||
tick = _tick;
|
tick = _tick;
|
||||||
runtime = _runtime;
|
runtime = _runtime;
|
||||||
|
framesPerSecond = framesPerSecondInternal;
|
||||||
|
|
||||||
if( pause_pending ) {
|
if( pause_pending ) {
|
||||||
state = Options.AppState.PAUSED;
|
state = Options.AppState.PAUSED;
|
||||||
@@ -1391,6 +1398,7 @@ public class Zeichenmaschine extends Constants {
|
|||||||
state = Options.AppState.STOPPED;
|
state = Options.AppState.STOPPED;
|
||||||
|
|
||||||
teardown();
|
teardown();
|
||||||
|
cleanup();
|
||||||
state = Options.AppState.TERMINATED;
|
state = Options.AppState.TERMINATED;
|
||||||
|
|
||||||
if( quitAfterTeardown ) {
|
if( quitAfterTeardown ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user