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:
Maxmtg
2013-04-19 06:41:27 +00:00
parent ff5c92cf20
commit 010a3ae727
4 changed files with 14 additions and 10 deletions

View File

@@ -136,6 +136,15 @@ public class FThreads {
getScheduledPool().schedule(inputUpdater, milliseconds, TimeUnit.MILLISECONDS); 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() { public static String debugGetCurrThreadId() {
return isEDT() ? "EDT" : Long.toString(Thread.currentThread().getId()); return isEDT() ? "EDT" : Long.toString(Thread.currentThread().getId());
} }

View File

@@ -788,7 +788,7 @@ public class CardFactoryUtil {
*/ */
public static List<Card> getActivateablesFromZone(final PlayerZone zone, final Player activator) { 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 // Only check the top card of the library
if (zone.is(ZoneType.Library)) { if (zone.is(ZoneType.Library)) {

View File

@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.concurrent.CopyOnWriteArrayList;
import forge.Card; import forge.Card;
import forge.Singletons; import forge.Singletons;
@@ -42,7 +43,7 @@ public class Zone extends MyObservable implements IZone, Observer, java.io.Seria
private static final long serialVersionUID = -5687652485777639176L; private static final long serialVersionUID = -5687652485777639176L;
/** The cards. */ /** 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 transient List<Card> roCardList;
protected final ZoneType zoneName; protected final ZoneType zoneName;
protected boolean update = true; protected boolean update = true;

View File

@@ -503,17 +503,11 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
public void setupPlayZone() { public void setupPlayZone() {
boolean wasSet = wantRedraw.getAndSet(true); boolean wasSet = wantRedraw.getAndSet(true);
if(wasSet) return; if(wasSet) return;
FThreads.invokeInEdtLater(new Runnable() { FThreads.delayInEDT(50, new Runnable() { // postpone play area update per 50ms
@Override @Override
public void run() { 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); wantRedraw.set(false);
final List<Card> modelshot = new ArrayList<Card>(model); // I am afraid of ConcurrentModificationExceptions setupPlayZone(model);
setupPlayZone(modelshot);
} }
}); });
} }