mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
LockAndInvokeGameAction moved from static method to instanced.
This commit is contained in:
@@ -9,7 +9,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import forge.control.input.InputQueue;
|
||||
import forge.control.input.InputSynchronized;
|
||||
|
||||
/**
|
||||
@@ -115,32 +114,6 @@ public class FThreads {
|
||||
}
|
||||
}
|
||||
|
||||
public static void invokeInNewThread(final Runnable proc, boolean lockUI) {
|
||||
Runnable toRun = proc;
|
||||
final InputQueue iq = Singletons.getControl().getMatch().getInput();
|
||||
//final GameState game = Singletons.getControl().getMatch().getCurrentGame();
|
||||
//final InputQueue iq = game.getMatch().getInput();
|
||||
if( lockUI ) {
|
||||
|
||||
// StackTraceElement[] trace = Thread.currentThread().getStackTrace();
|
||||
// System.out.printf("%s > Invoke in new thread during %s called from %s%n", FThreads.isEDT() ? "EDT" : "TRD", game.getPhaseHandler().getPhase(), trace[2].toString());
|
||||
// if( trace[2].toString().contains("InputBase.stop"))
|
||||
// for(StackTraceElement se : trace) {
|
||||
// System.out.println(se.toString());
|
||||
// }
|
||||
|
||||
iq.lock();
|
||||
toRun = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
proc.run();
|
||||
iq.unlock();
|
||||
}
|
||||
};
|
||||
}
|
||||
invokeInNewThread(toRun);
|
||||
}
|
||||
|
||||
public static void setInputAndWait(InputSynchronized input) {
|
||||
Singletons.getControl().getMatch().getInput().setInput(input);
|
||||
input.awaitLatchRelease();
|
||||
|
||||
@@ -66,8 +66,6 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
|
||||
protected void afterStop() { }
|
||||
|
||||
|
||||
|
||||
protected void passPriority() {
|
||||
final Runnable pass = new Runnable() {
|
||||
@Override public void run() {
|
||||
@@ -75,7 +73,7 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
}
|
||||
};
|
||||
if( FThreads.isEDT() )
|
||||
FThreads.invokeInNewThread(pass, true);
|
||||
player.getGame().getMatch().getInput().LockAndInvokeGameAction(pass);
|
||||
else
|
||||
pass.run();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package forge.control.input;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.game.GameState;
|
||||
import forge.game.player.Player;
|
||||
@@ -78,11 +77,11 @@ public class InputCleanup extends InputBase {
|
||||
if (!zone.is(ZoneType.Hand, Singletons.getControl().getPlayer()))
|
||||
return;
|
||||
|
||||
FThreads.invokeInNewThread(new Runnable() {
|
||||
game.getMatch().getInput().LockAndInvokeGameAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
card.getController().discard(card, null);
|
||||
}
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package forge.control.input;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.player.HumanPlay;
|
||||
@@ -90,7 +89,7 @@ public class InputPassPriority extends InputBase {
|
||||
}
|
||||
};
|
||||
|
||||
FThreads.invokeInNewThread(execAbility, true);
|
||||
player.getGame().getMatch().getInput().LockAndInvokeGameAction(execAbility);
|
||||
}
|
||||
else {
|
||||
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardUtil;
|
||||
import forge.FThreads;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
import forge.card.ability.ApiType;
|
||||
@@ -198,7 +197,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
onManaAbilityPlayed(chosen);
|
||||
}
|
||||
};
|
||||
FThreads.invokeInNewThread(proc, true);
|
||||
game.getMatch().getInput().LockAndInvokeGameAction(proc);
|
||||
// EDT that removes lockUI from input stack will call our showMessage() method
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package forge.control.input;
|
||||
import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.game.GameAge;
|
||||
import forge.game.GameState;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
@@ -202,4 +203,28 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
|
||||
return inputStack.toString();
|
||||
}
|
||||
|
||||
public void LockAndInvokeGameAction(final Runnable proc) {
|
||||
|
||||
//final GameState game = Singletons.getControl().getMatch().getCurrentGame();
|
||||
//final InputQueue iq = game.getMatch().getInput();
|
||||
|
||||
|
||||
// StackTraceElement[] trace = Thread.currentThread().getStackTrace();
|
||||
// System.out.printf("%s > Invoke in new thread during %s called from %s%n", FThreads.isEDT() ? "EDT" : "TRD", game.getPhaseHandler().getPhase(), trace[2].toString());
|
||||
// if( trace[2].toString().contains("InputBase.stop"))
|
||||
// for(StackTraceElement se : trace) {
|
||||
// System.out.println(se.toString());
|
||||
// }
|
||||
|
||||
this.lock();
|
||||
Runnable toRun = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
proc.run();
|
||||
InputQueue.this.unlock();
|
||||
}
|
||||
};
|
||||
FThreads.invokeInNewThread(toRun);
|
||||
}
|
||||
|
||||
} // InputControl
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
package forge.game.ai;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.control.input.InputBase;
|
||||
|
||||
/**
|
||||
@@ -63,7 +62,7 @@ public class AiInputCommon extends InputBase implements AiInput {
|
||||
* \"Detailed Error Trace\" to the Forge forum.");
|
||||
*/
|
||||
|
||||
FThreads.invokeInNewThread(aiActions, true);
|
||||
computer.getGame().getMatch().getInput().LockAndInvokeGameAction(aiActions);
|
||||
|
||||
} // getMessage();
|
||||
|
||||
|
||||
@@ -751,7 +751,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
};
|
||||
|
||||
if ( FThreads.isEDT() )
|
||||
FThreads.invokeInNewThread(proc, true);
|
||||
game.getMatch().getInput().LockAndInvokeGameAction(proc);
|
||||
else
|
||||
proc.run();
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class QuestEventChallenge extends QuestEvent {
|
||||
private boolean repeatable = false;
|
||||
|
||||
private boolean useBazaar = true;
|
||||
private Boolean forceAnte = false;
|
||||
private Boolean forceAnte = null;
|
||||
|
||||
/** The wins reqd. */
|
||||
private int winsReqd = 20;
|
||||
|
||||
Reference in New Issue
Block a user