mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
making isGameOver synchronized,
isValid in InputProxy.java is also synchronized instead of being volatile
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14145,6 +14145,7 @@ src/main/java/forge/game/GameActionPlay.java -text
|
|||||||
src/main/java/forge/game/GameActionUtil.java svneol=native#text/plain
|
src/main/java/forge/game/GameActionUtil.java svneol=native#text/plain
|
||||||
src/main/java/forge/game/GameEndReason.java -text
|
src/main/java/forge/game/GameEndReason.java -text
|
||||||
src/main/java/forge/game/GameFormat.java -text
|
src/main/java/forge/game/GameFormat.java -text
|
||||||
|
src/main/java/forge/game/GameInputUpdatesThread.java -text
|
||||||
src/main/java/forge/game/GameLossReason.java -text
|
src/main/java/forge/game/GameLossReason.java -text
|
||||||
src/main/java/forge/game/GameNew.java -text
|
src/main/java/forge/game/GameNew.java -text
|
||||||
src/main/java/forge/game/GameOutcome.java -text
|
src/main/java/forge/game/GameOutcome.java -text
|
||||||
|
|||||||
41
src/main/java/forge/game/GameInputUpdatesThread.java
Normal file
41
src/main/java/forge/game/GameInputUpdatesThread.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package forge.game;
|
||||||
|
|
||||||
|
import forge.error.BugReporter;
|
||||||
|
import forge.gui.match.controllers.CMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public final class GameInputUpdatesThread extends Thread {
|
||||||
|
private final MatchController match;
|
||||||
|
private final GameState game;
|
||||||
|
private boolean wasChangedRecently;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for Constructor.
|
||||||
|
* @param match
|
||||||
|
* @param game
|
||||||
|
*/
|
||||||
|
public GameInputUpdatesThread(MatchController match, GameState game) {
|
||||||
|
this.match = match;
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(){
|
||||||
|
while(!game.isGameOver()) {
|
||||||
|
boolean needsNewInput = CMessage.SINGLETON_INSTANCE.getInputControl().isValid() == false;
|
||||||
|
if ( needsNewInput ) {
|
||||||
|
match.getInput().setNewInput(game);
|
||||||
|
wasChangedRecently = true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(wasChangedRecently ? 2 : 40);
|
||||||
|
wasChangedRecently = false;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
BugReporter.reportException(e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,6 @@ import forge.card.trigger.TriggerType;
|
|||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.CardPool;
|
import forge.deck.CardPool;
|
||||||
import forge.deck.DeckSection;
|
import forge.deck.DeckSection;
|
||||||
import forge.error.BugReporter;
|
|
||||||
import forge.game.event.FlipCoinEvent;
|
import forge.game.event.FlipCoinEvent;
|
||||||
import forge.game.phase.PhaseHandler;
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.player.AIPlayer;
|
import forge.game.player.AIPlayer;
|
||||||
@@ -34,7 +33,6 @@ import forge.game.player.LobbyPlayer;
|
|||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.zone.PlayerZone;
|
import forge.game.zone.PlayerZone;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.match.controllers.CMessage;
|
|
||||||
import forge.gui.match.views.VAntes;
|
import forge.gui.match.views.VAntes;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
@@ -49,43 +47,6 @@ import forge.util.MyRandom;
|
|||||||
*/
|
*/
|
||||||
public class GameNew {
|
public class GameNew {
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: Write javadoc for this type.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static final class GameInputUpdatesThread extends Thread {
|
|
||||||
private final MatchController match;
|
|
||||||
private final GameState game;
|
|
||||||
private boolean wasChangedRecently;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: Write javadoc for Constructor.
|
|
||||||
* @param match
|
|
||||||
* @param game
|
|
||||||
*/
|
|
||||||
public GameInputUpdatesThread(MatchController match, GameState game) {
|
|
||||||
this.match = match;
|
|
||||||
this.game = game;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
while(!game.isGameOver()) {
|
|
||||||
boolean needsNewInput = CMessage.SINGLETON_INSTANCE.getInputControl().isValid() == false;
|
|
||||||
if ( needsNewInput ) {
|
|
||||||
match.getInput().setNewInput(game);
|
|
||||||
wasChangedRecently = true;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Thread.sleep(wasChangedRecently ? 2 : 40);
|
|
||||||
wasChangedRecently = false;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
BugReporter.reportException(e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final ForgePreferences preferences = Singletons.getModel().getPreferences();
|
public static final ForgePreferences preferences = Singletons.getModel().getPreferences();
|
||||||
|
|
||||||
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool secion, boolean canRandomFoil, Random generator) {
|
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool secion, boolean canRandomFoil, Random generator) {
|
||||||
@@ -235,10 +196,6 @@ public class GameNew {
|
|||||||
for (final Player p1 : game.getPlayers()) {
|
for (final Player p1 : game.getPlayers()) {
|
||||||
p1.drawCards(p1.getMaxHandSize());
|
p1.drawCards(p1.getMaxHandSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread thGame = new GameInputUpdatesThread(match, game);
|
|
||||||
thGame.setName("Game input updater");
|
|
||||||
thGame.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ultimate of Karn the Liberated
|
// ultimate of Karn the Liberated
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ public class GameState {
|
|||||||
/**
|
/**
|
||||||
* @return the gameOver
|
* @return the gameOver
|
||||||
*/
|
*/
|
||||||
public boolean isGameOver() {
|
public synchronized boolean isGameOver() {
|
||||||
return gameOver;
|
return gameOver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +295,7 @@ public class GameState {
|
|||||||
* @param reason
|
* @param reason
|
||||||
* @param go the gameOver to set
|
* @param go the gameOver to set
|
||||||
*/
|
*/
|
||||||
public void setGameOver(GameEndReason reason) {
|
public synchronized void setGameOver(GameEndReason reason) {
|
||||||
this.gameOver = true;
|
this.gameOver = true;
|
||||||
for (Player p : roIngamePlayers) {
|
for (Player p : roIngamePlayers) {
|
||||||
p.onGameOver();
|
p.onGameOver();
|
||||||
|
|||||||
@@ -160,6 +160,10 @@ public class MatchController {
|
|||||||
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
|
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
|
||||||
GameNew.newGame(this, startConditions, currentGame, canRandomFoil);
|
GameNew.newGame(this, startConditions, currentGame, canRandomFoil);
|
||||||
|
|
||||||
|
Thread thGame = new GameInputUpdatesThread(this, currentGame);
|
||||||
|
thGame.setName("Game input updater");
|
||||||
|
thGame.start();
|
||||||
|
|
||||||
// TODO restore this functionality!!!
|
// TODO restore this functionality!!!
|
||||||
//VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(Preferences.DEV_MODE);
|
//VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(Preferences.DEV_MODE);
|
||||||
for (final VField field : VMatchUI.SINGLETON_INSTANCE.getFieldViews()) {
|
for (final VField field : VMatchUI.SINGLETON_INSTANCE.getFieldViews()) {
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ public class InputProxy extends MyObservable implements Observer {
|
|||||||
|
|
||||||
/** The input. */
|
/** The input. */
|
||||||
private Input input;
|
private Input input;
|
||||||
private volatile boolean valid = false;
|
private boolean valid = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void update(final Observable observable, final Object obj) {
|
public final synchronized void update(final Observable observable, final Object obj) {
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +52,7 @@ public class InputProxy extends MyObservable implements Observer {
|
|||||||
* @param in
|
* @param in
|
||||||
* a {@link forge.control.input.Input} object.
|
* a {@link forge.control.input.Input} object.
|
||||||
*/
|
*/
|
||||||
public final void setInput(final Input in) {
|
public final synchronized void setInput(final Input in) {
|
||||||
valid = true;
|
valid = true;
|
||||||
this.input = in;
|
this.input = in;
|
||||||
this.input.showMessage(); // this call may invalidate the input by the time it returns
|
this.input.showMessage(); // this call may invalidate the input by the time it returns
|
||||||
@@ -114,7 +114,7 @@ public class InputProxy extends MyObservable implements Observer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isValid() {
|
public synchronized boolean isValid() {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user