mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
fix for concurrent modification problems http://www.slightlymagic.net/forum/viewtopic.php?p=115820#p115820
note: copy to new arraylist does not help against comodification problem. The only known to me solution is use classes from java.util.concurrent Playarea redraw timeout increased to 50ms
This commit is contained in:
@@ -136,6 +136,15 @@ public class FThreads {
|
||||
getScheduledPool().schedule(inputUpdater, milliseconds, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public static void delayInEDT(int milliseconds, final Runnable inputUpdater) {
|
||||
Runnable runInEdt = new Runnable() {
|
||||
@Override public void run() {
|
||||
FThreads.invokeInEdtNowOrLater(inputUpdater);
|
||||
}
|
||||
};
|
||||
delay(milliseconds, runInEdt);
|
||||
}
|
||||
|
||||
public static String debugGetCurrThreadId() {
|
||||
return isEDT() ? "EDT" : Long.toString(Thread.currentThread().getId());
|
||||
}
|
||||
|
||||
@@ -788,7 +788,7 @@ public class CardFactoryUtil {
|
||||
*/
|
||||
public static List<Card> getActivateablesFromZone(final PlayerZone zone, final Player activator) {
|
||||
|
||||
Iterable<Card> cl = Lists.newArrayList(zone.getCards());
|
||||
Iterable<Card> cl = zone.getCards(); // copy to new AL won't help here
|
||||
|
||||
// Only check the top card of the library
|
||||
if (zone.is(ZoneType.Library)) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
@@ -42,7 +43,7 @@ public class Zone extends MyObservable implements IZone, Observer, java.io.Seria
|
||||
private static final long serialVersionUID = -5687652485777639176L;
|
||||
|
||||
/** The cards. */
|
||||
protected final transient List<Card> cardList = new ArrayList<Card>();
|
||||
protected final transient List<Card> cardList = new CopyOnWriteArrayList<Card>();
|
||||
protected final transient List<Card> roCardList;
|
||||
protected final ZoneType zoneName;
|
||||
protected boolean update = true;
|
||||
|
||||
@@ -503,17 +503,11 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
public void setupPlayZone() {
|
||||
boolean wasSet = wantRedraw.getAndSet(true);
|
||||
if(wasSet) return;
|
||||
FThreads.invokeInEdtLater(new Runnable() {
|
||||
FThreads.delayInEDT(50, new Runnable() { // postpone play area update per 50ms
|
||||
@Override
|
||||
public void run() {
|
||||
try { // user won't notice, but the requests coming in that interval won't trigger re-draw
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
wantRedraw.set(false);
|
||||
final List<Card> modelshot = new ArrayList<Card>(model); // I am afraid of ConcurrentModificationExceptions
|
||||
setupPlayZone(modelshot);
|
||||
setupPlayZone(model);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user