mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 14:43:33 +02:00
Bug: Spielemaschine blockt nicht mehr nebenläufige Threads
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package schule.ngb.zm;
|
package schule.ngb.zm;
|
||||||
|
|
||||||
|
import schule.ngb.zm.layers.DrawableLayer;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -13,7 +15,7 @@ public class Spielemaschine extends Zeichenmaschine {
|
|||||||
|
|
||||||
private LinkedList<Updatable> updatables;
|
private LinkedList<Updatable> updatables;
|
||||||
|
|
||||||
private GraphicsLayer mainLayer;
|
private GameLayer mainLayer;
|
||||||
|
|
||||||
public Spielemaschine( String title ) {
|
public Spielemaschine( String title ) {
|
||||||
this(DEFAULT_WIDTH, DEFAULT_HEIGHT, title);
|
this(DEFAULT_WIDTH, DEFAULT_HEIGHT, title);
|
||||||
@@ -26,7 +28,7 @@ public class Spielemaschine extends Zeichenmaschine {
|
|||||||
drawables = new LinkedList<>();
|
drawables = new LinkedList<>();
|
||||||
updatables = new LinkedList<>();
|
updatables = new LinkedList<>();
|
||||||
|
|
||||||
mainLayer = new GraphicsLayer();
|
mainLayer = new GameLayer();
|
||||||
canvas.addLayer(mainLayer);
|
canvas.addLayer(mainLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +85,7 @@ public class Spielemaschine extends Zeichenmaschine {
|
|||||||
@Override
|
@Override
|
||||||
public final void update( double delta ) {
|
public final void update( double delta ) {
|
||||||
synchronized( updatables ) {
|
synchronized( updatables ) {
|
||||||
List<Updatable> it = Collections.unmodifiableList(updatables);
|
List<Updatable> it = List.copyOf(updatables);
|
||||||
for( Updatable u: it ) {
|
for( Updatable u: it ) {
|
||||||
if( u.isActive() ) {
|
if( u.isActive() ) {
|
||||||
u.update(delta);
|
u.update(delta);
|
||||||
@@ -96,23 +98,27 @@ public class Spielemaschine extends Zeichenmaschine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void draw() {
|
public final void draw() {
|
||||||
mainLayer.clear();
|
|
||||||
synchronized( drawables ) {
|
|
||||||
List<Drawable> it = Collections.unmodifiableList(drawables);
|
|
||||||
for( Drawable d: it ) {
|
|
||||||
if( d.isVisible() ) {
|
|
||||||
d.draw(mainLayer.getGraphics());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class GraphicsLayer extends Layer {
|
private class GameLayer extends Layer {
|
||||||
|
|
||||||
public Graphics2D getGraphics() {
|
public Graphics2D getGraphics() {
|
||||||
return drawing;
|
return drawing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw( Graphics2D pGraphics ) {
|
||||||
|
clear();
|
||||||
|
List<Drawable> it = List.copyOf(drawables);
|
||||||
|
for( Drawable d: it ) {
|
||||||
|
if( d.isVisible() ) {
|
||||||
|
d.draw(drawing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.draw(pGraphics);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user