v0.4.2: fixed some concurrency issues
This commit is contained in:
parent
d2bfb43965
commit
293925b27e
|
@ -41,7 +41,7 @@ public class Group extends Gizmo {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public synchronized void destroy() {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
for (int i=0; i < length; i++) {
|
for (int i=0; i < length; i++) {
|
||||||
Gizmo g = members.get( i );
|
Gizmo g = members.get( i );
|
||||||
|
@ -56,7 +56,7 @@ public class Group extends Gizmo {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public synchronized void update() {
|
||||||
for (int i=0; i < length; i++) {
|
for (int i=0; i < length; i++) {
|
||||||
Gizmo g = members.get( i );
|
Gizmo g = members.get( i );
|
||||||
if (g != null && g.exists && g.active
|
if (g != null && g.exists && g.active
|
||||||
|
@ -69,7 +69,7 @@ public class Group extends Gizmo {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public synchronized void draw() {
|
||||||
for (int i=0; i < length; i++) {
|
for (int i=0; i < length; i++) {
|
||||||
Gizmo g = members.get( i );
|
Gizmo g = members.get( i );
|
||||||
if (g != null && g.exists && g.isVisible()) {
|
if (g != null && g.exists && g.isVisible()) {
|
||||||
|
@ -79,7 +79,7 @@ public class Group extends Gizmo {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kill() {
|
public synchronized void kill() {
|
||||||
// A killed group keeps all its members,
|
// A killed group keeps all its members,
|
||||||
// but they get killed too
|
// but they get killed too
|
||||||
for (int i=0; i < length; i++) {
|
for (int i=0; i < length; i++) {
|
||||||
|
@ -92,11 +92,11 @@ public class Group extends Gizmo {
|
||||||
super.kill();
|
super.kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int indexOf( Gizmo g ) {
|
public synchronized int indexOf( Gizmo g ) {
|
||||||
return members.indexOf( g );
|
return members.indexOf( g );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gizmo add( Gizmo g ) {
|
public synchronized Gizmo add( Gizmo g ) {
|
||||||
|
|
||||||
if (g.parent == this) {
|
if (g.parent == this) {
|
||||||
return g;
|
return g;
|
||||||
|
@ -121,7 +121,7 @@ public class Group extends Gizmo {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gizmo addToFront( Gizmo g){
|
public synchronized Gizmo addToFront( Gizmo g){
|
||||||
|
|
||||||
if (g.parent == this) {
|
if (g.parent == this) {
|
||||||
return g;
|
return g;
|
||||||
|
@ -151,7 +151,7 @@ public class Group extends Gizmo {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gizmo addToBack( Gizmo g ) {
|
public synchronized Gizmo addToBack( Gizmo g ) {
|
||||||
|
|
||||||
if (g.parent == this) {
|
if (g.parent == this) {
|
||||||
sendToBack( g );
|
sendToBack( g );
|
||||||
|
@ -174,7 +174,7 @@ public class Group extends Gizmo {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gizmo recycle( Class<? extends Gizmo> c ) {
|
public synchronized Gizmo recycle( Class<? extends Gizmo> c ) {
|
||||||
|
|
||||||
Gizmo g = getFirstAvailable( c );
|
Gizmo g = getFirstAvailable( c );
|
||||||
if (g != null) {
|
if (g != null) {
|
||||||
|
@ -198,7 +198,7 @@ public class Group extends Gizmo {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fast removal - replacing with null
|
// Fast removal - replacing with null
|
||||||
public Gizmo erase( Gizmo g ) {
|
public synchronized Gizmo erase( Gizmo g ) {
|
||||||
int index = members.indexOf( g );
|
int index = members.indexOf( g );
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
|
@ -211,7 +211,7 @@ public class Group extends Gizmo {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Real removal
|
// Real removal
|
||||||
public Gizmo remove( Gizmo g ) {
|
public synchronized Gizmo remove( Gizmo g ) {
|
||||||
if (members.remove( g )) {
|
if (members.remove( g )) {
|
||||||
length--;
|
length--;
|
||||||
g.parent = null;
|
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 );
|
int index = members.indexOf( oldOne );
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
members.set( index, newOne );
|
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++) {
|
for (int i=0; i < length; i++) {
|
||||||
Gizmo g = members.get( i );
|
Gizmo g = members.get( i );
|
||||||
|
@ -245,7 +245,7 @@ public class Group extends Gizmo {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int countLiving() {
|
public synchronized int countLiving() {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ public class Group extends Gizmo {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int countDead() {
|
public synchronized int countDead() {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ public class Group extends Gizmo {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gizmo random() {
|
public synchronized Gizmo random() {
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
return members.get( (int)(Math.random() * length) );
|
return members.get( (int)(Math.random() * length) );
|
||||||
} else {
|
} else {
|
||||||
|
@ -281,7 +281,7 @@ public class Group extends Gizmo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public synchronized void clear() {
|
||||||
for (int i=0; i < length; i++) {
|
for (int i=0; i < length; i++) {
|
||||||
Gizmo g = members.get( i );
|
Gizmo g = members.get( i );
|
||||||
if (g != null) {
|
if (g != null) {
|
||||||
|
@ -292,7 +292,7 @@ public class Group extends Gizmo {
|
||||||
length = 0;
|
length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gizmo bringToFront( Gizmo g ) {
|
public synchronized Gizmo bringToFront( Gizmo g ) {
|
||||||
if (members.contains( g )) {
|
if (members.contains( g )) {
|
||||||
members.remove( g );
|
members.remove( g );
|
||||||
members.add( 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 )) {
|
if (members.contains( g )) {
|
||||||
members.remove( g );
|
members.remove( g );
|
||||||
members.add( 0, g );
|
members.add( 0, g );
|
||||||
|
|
|
@ -148,6 +148,9 @@ public class Image extends Visual {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public void draw() {
|
||||||
|
|
||||||
|
if (texture == null)
|
||||||
|
return;
|
||||||
|
|
||||||
super.draw();
|
super.draw();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user