v0.6.1b: fixed rare concurrent modification of actor sets

This commit is contained in:
Evan Debenham 2017-08-23 03:56:42 -04:00
parent 70cce2c8b3
commit 25c0449bb0

View File

@ -100,13 +100,12 @@ public abstract class Actor implements Bundlable {
private static HashSet<Actor> all = new HashSet<>(); private static HashSet<Actor> all = new HashSet<>();
private static HashSet<Char> chars = new HashSet<>(); private static HashSet<Char> chars = new HashSet<>();
private static volatile Actor current; private static volatile Actor current;
private static volatile boolean processing;
private static SparseArray<Actor> ids = new SparseArray<>(); private static SparseArray<Actor> ids = new SparseArray<>();
private static float now = 0; private static float now = 0;
public static void clear() { public static synchronized void clear() {
now = 0; now = 0;
@ -116,7 +115,7 @@ public abstract class Actor implements Bundlable {
ids.clear(); ids.clear();
} }
public static void fixTime() { public static synchronized void fixTime() {
if (Dungeon.hero != null && all.contains( Dungeon.hero )) { if (Dungeon.hero != null && all.contains( Dungeon.hero )) {
Statistics.duration += now; Statistics.duration += now;
@ -264,7 +263,7 @@ public abstract class Actor implements Bundlable {
add( actor, now + delay ); add( actor, now + delay );
} }
private static void add( Actor actor, float time ) { private static synchronized void add( Actor actor, float time ) {
if (all.contains( actor )) { if (all.contains( actor )) {
return; return;
@ -286,7 +285,7 @@ public abstract class Actor implements Bundlable {
} }
} }
public static void remove( Actor actor ) { public static synchronized void remove( Actor actor ) {
if (actor != null) { if (actor != null) {
all.remove( actor ); all.remove( actor );
@ -299,7 +298,7 @@ public abstract class Actor implements Bundlable {
} }
} }
public static Char findChar( int pos ) { public static synchronized Char findChar( int pos ) {
for (Char ch : chars){ for (Char ch : chars){
if (ch.pos == pos) if (ch.pos == pos)
return ch; return ch;
@ -307,13 +306,13 @@ public abstract class Actor implements Bundlable {
return null; return null;
} }
public static Actor findById( int id ) { public static synchronized Actor findById( int id ) {
return ids.get( id ); return ids.get( id );
} }
public static HashSet<Actor> all() { public static synchronized HashSet<Actor> all() {
return all; return new HashSet<Actor>(all);
} }
public static HashSet<Char> chars() { return chars; } public static synchronized HashSet<Char> chars() { return new HashSet<Char>(chars); }
} }