From fc3039b4848e35114a3cdf3fe0e7bdcd4bdfeace Mon Sep 17 00:00:00 2001 From: "J. Neugebauer" Date: Mon, 19 Jun 2023 10:26:36 +0200 Subject: [PATCH] ShapesLayer now handles Updatables separately --- .../schule/ngb/zm/layers/ShapesLayer.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/schule/ngb/zm/layers/ShapesLayer.java b/src/main/java/schule/ngb/zm/layers/ShapesLayer.java index 5791edc..30426d2 100644 --- a/src/main/java/schule/ngb/zm/layers/ShapesLayer.java +++ b/src/main/java/schule/ngb/zm/layers/ShapesLayer.java @@ -1,6 +1,7 @@ package schule.ngb.zm.layers; import schule.ngb.zm.Layer; +import schule.ngb.zm.Updatable; import schule.ngb.zm.anim.Animation; import schule.ngb.zm.anim.AnimationFacade; import schule.ngb.zm.anim.Easing; @@ -24,20 +25,26 @@ public class ShapesLayer extends Layer { */ protected boolean clearBeforeDraw = true; - private final List shapes; + protected boolean updateShapes = true; + + protected final List shapes; private final List> animations; + private final List updatables; + public ShapesLayer() { super(); shapes = new LinkedList<>(); animations = new LinkedList<>(); + updatables = new LinkedList<>(); } public ShapesLayer( int width, int height ) { super(width, height); shapes = new LinkedList<>(); animations = new LinkedList<>(); + updatables = new LinkedList<>(); } public Shape getShape( int index ) { @@ -70,12 +77,24 @@ public class ShapesLayer extends Layer { public void add( Shape... shapes ) { synchronized( this.shapes ) { Collections.addAll(this.shapes, shapes); + + for( Shape s : shapes ) { + if( Updatable.class.isInstance(s) ) { + updatables.add((Updatable) s); + } + } } } public void add( Collection shapes ) { synchronized( this.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 public void update( double delta ) { + if( updateShapes ) { + Iterator uit = updatables.iterator(); + while( uit.hasNext() ) { + Updatable u = uit.next(); + if( u.isActive() ) { + u.update(delta); + } + } + } + Iterator> it = animations.iterator(); while( it.hasNext() ) { Animation anim = it.next();