v0.4.2: fixed some concurrency issues

This commit is contained in:
Evan Debenham 2016-09-02 22:11:57 -04:00
parent d2bfb43965
commit 293925b27e
2 changed files with 22 additions and 19 deletions

View File

@ -41,7 +41,7 @@ public class Group extends Gizmo {
}
@Override
public void destroy() {
public synchronized void destroy() {
super.destroy();
for (int i=0; i < length; i++) {
Gizmo g = members.get( i );
@ -56,7 +56,7 @@ public class Group extends Gizmo {
}
@Override
public void update() {
public synchronized void update() {
for (int i=0; i < length; i++) {
Gizmo g = members.get( i );
if (g != null && g.exists && g.active
@ -69,7 +69,7 @@ public class Group extends Gizmo {
}
@Override
public void draw() {
public synchronized void draw() {
for (int i=0; i < length; i++) {
Gizmo g = members.get( i );
if (g != null && g.exists && g.isVisible()) {
@ -79,7 +79,7 @@ public class Group extends Gizmo {
}
@Override
public void kill() {
public synchronized void kill() {
// A killed group keeps all its members,
// but they get killed too
for (int i=0; i < length; i++) {
@ -92,11 +92,11 @@ public class Group extends Gizmo {
super.kill();
}
public int indexOf( Gizmo g ) {
public synchronized int indexOf( Gizmo g ) {
return members.indexOf( g );
}
public Gizmo add( Gizmo g ) {
public synchronized Gizmo add( Gizmo g ) {
if (g.parent == this) {
return g;
@ -121,7 +121,7 @@ public class Group extends Gizmo {
return g;
}
public Gizmo addToFront( Gizmo g){
public synchronized Gizmo addToFront( Gizmo g){
if (g.parent == this) {
return g;
@ -151,7 +151,7 @@ public class Group extends Gizmo {
return g;
}
public Gizmo addToBack( Gizmo g ) {
public synchronized Gizmo addToBack( Gizmo g ) {
if (g.parent == this) {
sendToBack( g );
@ -174,7 +174,7 @@ public class Group extends Gizmo {
return g;
}
public Gizmo recycle( Class<? extends Gizmo> c ) {
public synchronized Gizmo recycle( Class<? extends Gizmo> c ) {
Gizmo g = getFirstAvailable( c );
if (g != null) {
@ -198,7 +198,7 @@ public class Group extends Gizmo {
}
// Fast removal - replacing with null
public Gizmo erase( Gizmo g ) {
public synchronized Gizmo erase( Gizmo g ) {
int index = members.indexOf( g );
if (index != -1) {
@ -211,7 +211,7 @@ public class Group extends Gizmo {
}
// Real removal
public Gizmo remove( Gizmo g ) {
public synchronized Gizmo remove( Gizmo g ) {
if (members.remove( g )) {
length--;
g.parent = null;
@ -221,7 +221,7 @@ public class Group extends Gizmo {
}
}
public Gizmo replace( Gizmo oldOne, Gizmo newOne ) {
public synchronized Gizmo replace( Gizmo oldOne, Gizmo newOne ) {
int index = members.indexOf( oldOne );
if (index != -1) {
members.set( index, newOne );
@ -233,7 +233,7 @@ public class Group extends Gizmo {
}
}
public Gizmo getFirstAvailable( Class<? extends Gizmo> c ) {
public synchronized Gizmo getFirstAvailable( Class<? extends Gizmo> c ) {
for (int i=0; i < length; i++) {
Gizmo g = members.get( i );
@ -245,7 +245,7 @@ public class Group extends Gizmo {
return null;
}
public int countLiving() {
public synchronized int countLiving() {
int count = 0;
@ -259,7 +259,7 @@ public class Group extends Gizmo {
return count;
}
public int countDead() {
public synchronized int countDead() {
int count = 0;
@ -273,7 +273,7 @@ public class Group extends Gizmo {
return count;
}
public Gizmo random() {
public synchronized Gizmo random() {
if (length > 0) {
return members.get( (int)(Math.random() * length) );
} else {
@ -281,7 +281,7 @@ public class Group extends Gizmo {
}
}
public void clear() {
public synchronized void clear() {
for (int i=0; i < length; i++) {
Gizmo g = members.get( i );
if (g != null) {
@ -292,7 +292,7 @@ public class Group extends Gizmo {
length = 0;
}
public Gizmo bringToFront( Gizmo g ) {
public synchronized Gizmo bringToFront( Gizmo g ) {
if (members.contains( g )) {
members.remove( g );
members.add( g );
@ -302,7 +302,7 @@ public class Group extends Gizmo {
}
}
public Gizmo sendToBack( Gizmo g ) {
public synchronized Gizmo sendToBack( Gizmo g ) {
if (members.contains( g )) {
members.remove( g );
members.add( 0, g );

View File

@ -148,6 +148,9 @@ public class Image extends Visual {
@Override
public void draw() {
if (texture == null)
return;
super.draw();