mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 06:33:34 +02:00
ShapesLayer now handles Updatables separately
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package schule.ngb.zm.layers;
|
package schule.ngb.zm.layers;
|
||||||
|
|
||||||
import schule.ngb.zm.Layer;
|
import schule.ngb.zm.Layer;
|
||||||
|
import schule.ngb.zm.Updatable;
|
||||||
import schule.ngb.zm.anim.Animation;
|
import schule.ngb.zm.anim.Animation;
|
||||||
import schule.ngb.zm.anim.AnimationFacade;
|
import schule.ngb.zm.anim.AnimationFacade;
|
||||||
import schule.ngb.zm.anim.Easing;
|
import schule.ngb.zm.anim.Easing;
|
||||||
@@ -24,20 +25,26 @@ public class ShapesLayer extends Layer {
|
|||||||
*/
|
*/
|
||||||
protected boolean clearBeforeDraw = true;
|
protected boolean clearBeforeDraw = true;
|
||||||
|
|
||||||
private final List<Shape> shapes;
|
protected boolean updateShapes = true;
|
||||||
|
|
||||||
|
protected final List<Shape> shapes;
|
||||||
|
|
||||||
private final List<Animation<? extends Shape>> animations;
|
private final List<Animation<? extends Shape>> animations;
|
||||||
|
|
||||||
|
private final List<Updatable> updatables;
|
||||||
|
|
||||||
public ShapesLayer() {
|
public ShapesLayer() {
|
||||||
super();
|
super();
|
||||||
shapes = new LinkedList<>();
|
shapes = new LinkedList<>();
|
||||||
animations = new LinkedList<>();
|
animations = new LinkedList<>();
|
||||||
|
updatables = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapesLayer( int width, int height ) {
|
public ShapesLayer( int width, int height ) {
|
||||||
super(width, height);
|
super(width, height);
|
||||||
shapes = new LinkedList<>();
|
shapes = new LinkedList<>();
|
||||||
animations = new LinkedList<>();
|
animations = new LinkedList<>();
|
||||||
|
updatables = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shape getShape( int index ) {
|
public Shape getShape( int index ) {
|
||||||
@@ -70,12 +77,24 @@ public class ShapesLayer extends Layer {
|
|||||||
public void add( Shape... shapes ) {
|
public void add( Shape... shapes ) {
|
||||||
synchronized( this.shapes ) {
|
synchronized( this.shapes ) {
|
||||||
Collections.addAll(this.shapes, shapes);
|
Collections.addAll(this.shapes, shapes);
|
||||||
|
|
||||||
|
for( Shape s : shapes ) {
|
||||||
|
if( Updatable.class.isInstance(s) ) {
|
||||||
|
updatables.add((Updatable) s);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add( Collection<Shape> shapes ) {
|
public void add( Collection<Shape> shapes ) {
|
||||||
synchronized( this.shapes ) {
|
synchronized( this.shapes ) {
|
||||||
this.shapes.addAll(shapes);
|
this.shapes.addAll(shapes);
|
||||||
|
|
||||||
|
for( Shape s : shapes ) {
|
||||||
|
if( Updatable.class.isInstance(s) ) {
|
||||||
|
updatables.add((Updatable) s);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +158,16 @@ public class ShapesLayer extends Layer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( double delta ) {
|
public void update( double delta ) {
|
||||||
|
if( updateShapes ) {
|
||||||
|
Iterator<Updatable> uit = updatables.iterator();
|
||||||
|
while( uit.hasNext() ) {
|
||||||
|
Updatable u = uit.next();
|
||||||
|
if( u.isActive() ) {
|
||||||
|
u.update(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Iterator<Animation<? extends Shape>> it = animations.iterator();
|
Iterator<Animation<? extends Shape>> it = animations.iterator();
|
||||||
while( it.hasNext() ) {
|
while( it.hasNext() ) {
|
||||||
Animation<? extends Shape> anim = it.next();
|
Animation<? extends Shape> anim = it.next();
|
||||||
|
|||||||
Reference in New Issue
Block a user