left a single stack of inputs in InputControl

invokeInNewThread will now reset input the method has planted
This commit is contained in:
Maxmtg
2013-03-22 17:52:05 +00:00
parent 55edddf27e
commit 37a0c9952d
3 changed files with 26 additions and 56 deletions

View File

@@ -14,6 +14,10 @@ import forge.control.input.InputLockUI;
*/ */
public class FThreads { public class FThreads {
static {
System.out.printf("(FThreads static ctor): Running on a machine with %d cpu core(s)%n", Runtime.getRuntime().availableProcessors() );
}
private final static ExecutorService threadPool = Executors.newCachedThreadPool(); private final static ExecutorService threadPool = Executors.newCachedThreadPool();
public static ExecutorService getCachedPool() { public static ExecutorService getCachedPool() {
return threadPool; return threadPool;
@@ -84,11 +88,22 @@ public class FThreads {
} }
private final static InputLockUI inpuptLock = new InputLockUI(); private final static InputLockUI inpuptLock = new InputLockUI();
public static void invokeInNewThread(Runnable proc, boolean lockUI) { public static void invokeInNewThread(final Runnable proc, boolean lockUI) {
getCachedPool().execute(proc); Runnable toRun = proc;
if( lockUI ) { if( lockUI ) {
// checkEDT("FThreads.invokeInNewthread", true)
Singletons.getModel().getMatch().getInput().setInput(inpuptLock); Singletons.getModel().getMatch().getInput().setInput(inpuptLock);
toRun = new Runnable() {
@Override
public void run() {
proc.run();
// may try special unlock method here
Singletons.getModel().getMatch().getInput().resetInput();
} }
};
}
getCachedPool().execute(toRun);
} }
} }

View File

@@ -84,10 +84,6 @@ public enum FControl {
private final SoundSystem soundSystem = new SoundSystem(); private final SoundSystem soundSystem = new SoundSystem();
static {
System.out.printf("(FControl static ctor): Running on a machine with %d cpu core(s)%n", Runtime.getRuntime().availableProcessors() );
}
/** /**
* <p> * <p>
* FControl. * FControl.

View File

@@ -40,10 +40,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
/** Constant <code>serialVersionUID=3955194449319994301L</code>. */ /** Constant <code>serialVersionUID=3955194449319994301L</code>. */
private static final long serialVersionUID = 3955194449319994301L; private static final long serialVersionUID = 3955194449319994301L;
private Input input;
private final Stack<Input> inputStack = new Stack<Input>(); private final Stack<Input> inputStack = new Stack<Input>();
private final Stack<Input> urgentInputStack = new Stack<Input>();
private final transient GameState game; private final transient GameState game;
/** /**
@@ -65,13 +62,9 @@ public class InputControl extends MyObservable implements java.io.Serializable {
* a {@link forge.control.input.Input} object. * a {@link forge.control.input.Input} object.
*/ */
public final void setInput(final Input in) { public final void setInput(final Input in) {
boolean isInputEmpty = this.input == null || this.input instanceof InputPassPriority;
//System.out.println(in.getClass().getName()); //System.out.println(in.getClass().getName());
if (!this.game.getStack().isResolving() && isInputEmpty) { this.inputStack.push(in);
this.input = in; // System.out.print("Current: " + input + "; Stack = " + inputStack);
} else {
this.inputStack.add(in);
}
this.updateObservers(); this.updateObservers();
} }
@@ -87,21 +80,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
*/ */
public final void setInputInterrupt(final Input in) { public final void setInputInterrupt(final Input in) {
// Make this // Make this
final Input old = this.input; this.inputStack.push(in);
this.urgentInputStack.add(old);
this.changeInput(in);
}
/**
* <p>
* changeInput.
* </p>
*
* @param in
* a {@link forge.control.input.Input} object.
*/
private void changeInput(final Input in) {
this.input = in;
this.updateObservers(); this.updateObservers();
} }
@@ -113,7 +92,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
* @return a {@link forge.control.input.Input} object. * @return a {@link forge.control.input.Input} object.
*/ */
public final Input getInput() { public final Input getInput() {
return this.input; return this.inputStack.peek();
} }
/** /**
@@ -122,7 +101,6 @@ public class InputControl extends MyObservable implements java.io.Serializable {
* </p> * </p>
*/ */
public final void clearInput() { public final void clearInput() {
this.input = null;
this.inputStack.clear(); this.inputStack.clear();
} }
@@ -136,7 +114,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
* a boolean. * a boolean.
*/ */
public final void resetInput() { public final void resetInput() {
this.input = null; this.inputStack.pop();
this.updateObservers(); this.updateObservers();
} }
@@ -157,30 +135,11 @@ public class InputControl extends MyObservable implements java.io.Serializable {
final Player priority = handler.getPriorityPlayer(); final Player priority = handler.getPriorityPlayer();
final MagicStack stack = game.getStack(); final MagicStack stack = game.getStack();
// TODO this resolving portion needs more work, but fixes Death Cloud // TODO this resolving portion needs more work, but fixes Death Cloud
// issues // issues
if (this.urgentInputStack.size() > 0) {
if (this.input != null) {
return this.input;
}
// if an SA is resolving, only change input for something that is
// part of the resolving SA
this.changeInput(this.urgentInputStack.pop());
return this.input;
}
if (stack.isResolving()) {
return null;
}
if (this.input != null) {
return this.input;
}
if (!this.inputStack.isEmpty()) { // incoming input to Control if (!this.inputStack.isEmpty()) { // incoming input to Control
this.changeInput(this.inputStack.pop()); return this.inputStack.peek();
return this.input;
} }
if (handler.hasPhaseEffects()) { if (handler.hasPhaseEffects()) {
@@ -249,8 +208,8 @@ public class InputControl extends MyObservable implements java.io.Serializable {
PhaseHandler ph = game.getPhaseHandler(); PhaseHandler ph = game.getPhaseHandler();
final Input tmp = getActualInput(); final Input tmp = getActualInput();
//String message = String.format("%s's %s, priority of %s [%sP] input is %s", ph.getPlayerTurn(), ph.getPhase(), ph.getPriorityPlayer(), ph.isPlayerPriorityAllowed() ? "+" : "-", tmp == null ? "null" : tmp.getClass().getSimpleName()); String message = String.format("%s's %s, priority of %s [%sP] input is %s", ph.getPlayerTurn(), ph.getPhase(), ph.getPriorityPlayer(), ph.isPlayerPriorityAllowed() ? "+" : "-", tmp == null ? "null" : tmp.getClass().getSimpleName());
//System.out.println(message); System.out.println(message);
if (tmp != null) { if (tmp != null) {
//System.out.println(ph.getPlayerTurn() + "'s " + ph.getPhase() + ", priority of " + ph.getPriorityPlayer() + " @ input is " + tmp.getClass().getName() ); //System.out.println(ph.getPlayerTurn() + "'s " + ph.getPhase() + ", priority of " + ph.getPriorityPlayer() + " @ input is " + tmp.getClass().getName() );
CMessage.SINGLETON_INSTANCE.getInputControl().setInput(tmp); CMessage.SINGLETON_INSTANCE.getInputControl().setInput(tmp);