only perform card definition loading from initialize, UI calls waitForAllCards to block until card definitions are loaded
parent
dd4c720a77
commit
123ebeaf13
|
@ -209,7 +209,13 @@ public class CardDefinitions {
|
|||
}
|
||||
reporter.setMessage("Loading cards...100%");
|
||||
printStatistics();
|
||||
updateNewCardsLog(loadCardsSnapshotFile());
|
||||
|
||||
/*
|
||||
updateNewCardsLog calls getPlayableNonTokenCardNames which causes a deadlock,
|
||||
commenting it out for now
|
||||
|
||||
updateNewCardsLog(CardDefinitions.loadCardsSnapshotFile());
|
||||
*/
|
||||
}
|
||||
|
||||
private static boolean isZero(double value, double delta){
|
||||
|
@ -271,7 +277,7 @@ public class CardDefinitions {
|
|||
* Returns a list of all playable MagicCardDefinitions EXCEPT those classed as hidden.
|
||||
*/
|
||||
public static List<MagicCardDefinition> getDefaultPlayableCardDefs() {
|
||||
MagicSystem.initializeEngine();
|
||||
MagicSystem.waitForAllCards();
|
||||
return defaultPlayableCardDefs;
|
||||
}
|
||||
|
||||
|
@ -279,7 +285,7 @@ public class CardDefinitions {
|
|||
* Returns a list all playable MagicCardDefinitions INCLUDING those classed as hidden.
|
||||
*/
|
||||
public static Collection<MagicCardDefinition> getAllPlayableCardDefs() {
|
||||
MagicSystem.initializeEngine();
|
||||
MagicSystem.waitForAllCards();
|
||||
return allPlayableCardDefs.values();
|
||||
}
|
||||
|
||||
|
@ -291,12 +297,12 @@ public class CardDefinitions {
|
|||
}
|
||||
|
||||
public static List<MagicCardDefinition> getLandCards() {
|
||||
MagicSystem.initializeEngine();
|
||||
MagicSystem.waitForAllCards();
|
||||
return landCards;
|
||||
}
|
||||
|
||||
public static List<MagicCardDefinition> getSpellCards() {
|
||||
MagicSystem.initializeEngine();
|
||||
MagicSystem.waitForAllCards();
|
||||
return spellCards;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public class DeckEditorPanel extends JPanel {
|
|||
|
||||
public DeckEditorPanel(final MagicDeck deck) {
|
||||
|
||||
MagicSystem.initializeEngine();
|
||||
MagicSystem.waitForAllCards();
|
||||
|
||||
// lhs
|
||||
sideBarPanel = new DeckEditorSideBarPanel();
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ExplorerPanel extends ExplorerDeckEditorPanel implements ICardSelec
|
|||
|
||||
private void setupExplorerPanel(final MagicDeck deck0) {
|
||||
|
||||
MagicSystem.initializeEngine();
|
||||
MagicSystem.waitForAllCards();
|
||||
|
||||
this.deck = new MagicDeck();
|
||||
this.originalDeck = deck0;
|
||||
|
|
|
@ -10,6 +10,9 @@ import magic.data.GeneralConfig;
|
|||
import magic.model.MagicGameLog;
|
||||
import magic.utility.MagicFileSystem.DataPath;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.List;
|
||||
|
@ -19,7 +22,12 @@ final public class MagicSystem {
|
|||
private MagicSystem() {}
|
||||
|
||||
public static final boolean IS_WINDOWS_OS = System.getProperty("os.name").toLowerCase().startsWith("windows");
|
||||
private static boolean cardsLoaded = false;
|
||||
private static final ProgressReporter reporter = new ProgressReporter();
|
||||
private static final FutureTask<Void> loadCards = new FutureTask<>(new Runnable() {
|
||||
public void run() {
|
||||
initializeEngine(reporter);
|
||||
}
|
||||
}, null);
|
||||
|
||||
public static boolean isTestGame() {
|
||||
return (System.getProperty("testGame") != null);
|
||||
|
@ -75,21 +83,29 @@ final public class MagicSystem {
|
|||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public static synchronized void initializeEngine() {
|
||||
if (cardsLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
cardsLoaded = true;
|
||||
initializeEngine(new ProgressReporter());
|
||||
public static String getLoadingProgress() {
|
||||
return reporter.getMessage();
|
||||
}
|
||||
|
||||
public static void waitForAllCards() {
|
||||
if (loadCards.isDone()) {
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
loadCards.get();
|
||||
} catch (final InterruptedException|ExecutionException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializeEngine(final ProgressReporter reporter) {
|
||||
if (isParseMissing()) {
|
||||
UnimplementedParser.parseScriptsMissing(reporter);
|
||||
reporter.setMessage("Parsing card abilities...");
|
||||
UnimplementedParser.parseCardAbilities();
|
||||
|
||||
}
|
||||
CardDefinitions.loadCardDefinitions(reporter);
|
||||
if (isDebugMode()) {
|
||||
|
@ -120,10 +136,13 @@ final public class MagicSystem {
|
|||
// setup the game log
|
||||
reporter.setMessage("Initializing log...");
|
||||
MagicGameLog.initialize();
|
||||
|
||||
// if parse scripts missing or pre-load abilities then load everything.
|
||||
|
||||
// start a separate thread to load cards
|
||||
Executors.newSingleThreadExecutor().execute(loadCards);
|
||||
|
||||
// if parse scripts missing or pre-load abilities then load cards synchronously
|
||||
if (isParseMissing() || isDebugMode()) {
|
||||
initializeEngine(reporter);
|
||||
waitForAllCards();
|
||||
}
|
||||
|
||||
reporter.setMessage("Loading cube definitions...");
|
||||
|
|
|
@ -2,9 +2,15 @@ package magic.utility;
|
|||
|
||||
public class ProgressReporter {
|
||||
|
||||
private String msg;
|
||||
|
||||
public void setMessage(final String message) {
|
||||
// suppress progress messages by default.
|
||||
// Extend class to create implementation specific reporting.
|
||||
msg = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue