mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Code cleanup
This commit is contained in:
@@ -22,16 +22,16 @@ import forge.gui.match.CMatchUI;
|
|||||||
|
|
||||||
public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
||||||
private final FControl fc;
|
private final FControl fc;
|
||||||
|
|
||||||
private final InputPlaybackControl inputPlayback = new InputPlaybackControl(this);
|
private final InputPlaybackControl inputPlayback = new InputPlaybackControl(this);
|
||||||
private final AtomicBoolean paused = new AtomicBoolean(false);
|
private final AtomicBoolean paused = new AtomicBoolean(false);
|
||||||
|
|
||||||
private final CyclicBarrier gameThreadPauser = new CyclicBarrier(2);
|
private final CyclicBarrier gameThreadPauser = new CyclicBarrier(2);
|
||||||
|
|
||||||
public FControlGamePlayback(FControl fc ) {
|
public FControlGamePlayback(FControl fc) {
|
||||||
this.fc = fc;
|
this.fc = fc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void receiveGameEvent(final GameEvent ev) { ev.visit(this); }
|
public void receiveGameEvent(final GameEvent ev) { ev.visit(this); }
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
|||||||
private int resolveDelay = 400;
|
private int resolveDelay = 400;
|
||||||
|
|
||||||
private boolean fasterPlayback = false;
|
private boolean fasterPlayback = false;
|
||||||
|
|
||||||
private void pauseForEvent(int delay) {
|
private void pauseForEvent(int delay) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(fasterPlayback ? delay / 10 : delay);
|
Thread.sleep(fasterPlayback ? delay / 10 : delay);
|
||||||
@@ -51,38 +51,37 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(GameEventBlockersDeclared event) {
|
public Void visit(GameEventBlockersDeclared event) {
|
||||||
pauseForEvent(combatDelay);
|
pauseForEvent(combatDelay);
|
||||||
return super.visit(event);
|
return super.visit(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.game.event.IGameEventVisitor.Base#visit(forge.game.event.GameEventTurnPhase)
|
* @see forge.game.event.IGameEventVisitor.Base#visit(forge.game.event.GameEventTurnPhase)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Void visit(GameEventTurnPhase ev) {
|
public Void visit(GameEventTurnPhase ev) {
|
||||||
boolean isUiToStop = CMatchUI.SINGLETON_INSTANCE.stopAtPhase(ev.playerTurn, ev.phase);
|
boolean isUiToStop = CMatchUI.SINGLETON_INSTANCE.stopAtPhase(ev.playerTurn, ev.phase);
|
||||||
|
|
||||||
switch(ev.phase) {
|
switch(ev.phase) {
|
||||||
case COMBAT_END:
|
case COMBAT_END:
|
||||||
case COMBAT_DECLARE_ATTACKERS:
|
case COMBAT_DECLARE_ATTACKERS:
|
||||||
case COMBAT_DECLARE_BLOCKERS:
|
case COMBAT_DECLARE_BLOCKERS:
|
||||||
if( fc.getObservedGame().getPhaseHandler().inCombat() )
|
if (fc.getObservedGame().getPhaseHandler().inCombat()) {
|
||||||
pauseForEvent(combatDelay);
|
pauseForEvent(combatDelay);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if( isUiToStop )
|
if (isUiToStop) {
|
||||||
pauseForEvent(phasesDelay);
|
pauseForEvent(phasesDelay);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.game.event.IGameEventVisitor.Base#visit(forge.game.event.GameEventDuelFinished)
|
* @see forge.game.event.IGameEventVisitor.Base#visit(forge.game.event.GameEventDuelFinished)
|
||||||
*/
|
*/
|
||||||
@@ -91,7 +90,6 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
|||||||
fc.getInputQueue().removeInput(inputPlayback);
|
fc.getInputQueue().removeInput(inputPlayback);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(GameEventGameStarted event) {
|
public Void visit(GameEventGameStarted event) {
|
||||||
@@ -104,14 +102,14 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
|||||||
pauseForEvent(resolveDelay);
|
pauseForEvent(resolveDelay);
|
||||||
return super.visit(event);
|
return super.visit(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(final GameEventSpellResolved event) {
|
public Void visit(final GameEventSpellResolved event) {
|
||||||
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() { CMatchUI.SINGLETON_INSTANCE.setCard(event.spell.getSourceCard()); } });
|
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() { CMatchUI.SINGLETON_INSTANCE.setCard(event.spell.getSourceCard()); } });
|
||||||
pauseForEvent(resolveDelay);
|
pauseForEvent(resolveDelay);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.game.event.IGameEventVisitor.Base#visit(forge.game.event.GameEventSpellAbilityCast)
|
* @see forge.game.event.IGameEventVisitor.Base#visit(forge.game.event.GameEventSpellAbilityCast)
|
||||||
*/
|
*/
|
||||||
@@ -121,13 +119,13 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
|||||||
pauseForEvent(castDelay);
|
pauseForEvent(castDelay);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.game.event.IGameEventVisitor.Base#visit(forge.game.event.GameEventPlayerPriority)
|
* @see forge.game.event.IGameEventVisitor.Base#visit(forge.game.event.GameEventPlayerPriority)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Void visit(GameEventPlayerPriority event) {
|
public Void visit(GameEventPlayerPriority event) {
|
||||||
if ( paused.get() ) {
|
if (paused.get()) {
|
||||||
try {
|
try {
|
||||||
inputPlayback.onGamePaused();
|
inputPlayback.onGamePaused();
|
||||||
gameThreadPauser.await();
|
gameThreadPauser.await();
|
||||||
@@ -141,17 +139,17 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onGameStopRequested() {
|
public void onGameStopRequested() {
|
||||||
paused.set(false);
|
paused.set(false);
|
||||||
if ( gameThreadPauser.getNumberWaiting() != 0)
|
if (gameThreadPauser.getNumberWaiting() != 0) {
|
||||||
releaseGameThread();
|
releaseGameThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void releaseGameThread() {
|
private void releaseGameThread() {
|
||||||
// just need to run another thread through the barrier... not edt preferrably :)
|
// just need to run another thread through the barrier... not edt preferrably :)
|
||||||
|
|
||||||
fc.getObservedGame().getAction().invoke( new Runnable() {
|
fc.getObservedGame().getAction().invoke(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -170,7 +168,6 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
|||||||
public void resume() {
|
public void resume() {
|
||||||
paused.set(false);
|
paused.set(false);
|
||||||
releaseGameThread();
|
releaseGameThread();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
|
|||||||
Reference in New Issue
Block a user