mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-19 20:22:18 +01:00
DroidFish: Avoid unnecessary GUI updates.
This commit is contained in:
@@ -196,8 +196,10 @@ public class DroidChessController {
|
|||||||
if (computerPlayer != null) {
|
if (computerPlayer != null) {
|
||||||
computerPlayer.setBookOptions(bookOptions);
|
computerPlayer.setBookOptions(bookOptions);
|
||||||
if (analysisThread != null) {
|
if (analysisThread != null) {
|
||||||
stopAnalysis();
|
boolean updateGui = stopAnalysis();
|
||||||
startAnalysis();
|
updateGui |= startAnalysis();
|
||||||
|
if (updateGui)
|
||||||
|
updateGUI();
|
||||||
}
|
}
|
||||||
updateBookHints();
|
updateBookHints();
|
||||||
}
|
}
|
||||||
@@ -222,8 +224,10 @@ public class DroidChessController {
|
|||||||
|
|
||||||
public final void newGame(GameMode gameMode) {
|
public final void newGame(GameMode gameMode) {
|
||||||
ss.searchResultWanted = false;
|
ss.searchResultWanted = false;
|
||||||
stopComputerThinking();
|
boolean updateGui = stopComputerThinking();
|
||||||
stopAnalysis();
|
updateGui |= stopAnalysis();
|
||||||
|
if (updateGui)
|
||||||
|
updateGUI();
|
||||||
this.gameMode = gameMode;
|
this.gameMode = gameMode;
|
||||||
ponderMove = null;
|
ponderMove = null;
|
||||||
if (computerPlayer == null) {
|
if (computerPlayer == null) {
|
||||||
@@ -775,11 +779,10 @@ public class DroidChessController {
|
|||||||
listener.clearSearchInfo();
|
listener.clearSearchInfo();
|
||||||
computerPlayer.shouldStop = false;
|
computerPlayer.shouldStop = false;
|
||||||
computerThread.start();
|
computerThread.start();
|
||||||
updateGUI();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final synchronized void stopComputerThinking() {
|
private final synchronized boolean stopComputerThinking() {
|
||||||
if (computerThread != null) {
|
if (computerThread != null) {
|
||||||
computerPlayer.stopSearch();
|
computerPlayer.stopSearch();
|
||||||
try {
|
try {
|
||||||
@@ -788,13 +791,14 @@ public class DroidChessController {
|
|||||||
System.out.printf("Could not stop computer thread%n");
|
System.out.printf("Could not stop computer thread%n");
|
||||||
}
|
}
|
||||||
computerThread = null;
|
computerThread = null;
|
||||||
updateGUI();
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final synchronized void startAnalysis() {
|
private final synchronized boolean startAnalysis() {
|
||||||
if (gameMode.analysisMode()) {
|
if (gameMode.analysisMode()) {
|
||||||
if (computerThread != null) return;
|
if (computerThread != null) return false;
|
||||||
if (analysisThread == null) {
|
if (analysisThread == null) {
|
||||||
ss = new SearchStatus();
|
ss = new SearchStatus();
|
||||||
final Pair<Position, ArrayList<Move>> ph = game.getUCIHistory();
|
final Pair<Position, ArrayList<Move>> ph = game.getUCIHistory();
|
||||||
@@ -814,12 +818,13 @@ public class DroidChessController {
|
|||||||
listener.clearSearchInfo();
|
listener.clearSearchInfo();
|
||||||
computerPlayer.shouldStop = false;
|
computerPlayer.shouldStop = false;
|
||||||
analysisThread.start();
|
analysisThread.start();
|
||||||
updateGUI();
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final synchronized void stopAnalysis() {
|
private final synchronized boolean stopAnalysis() {
|
||||||
if (analysisThread != null) {
|
if (analysisThread != null) {
|
||||||
computerPlayer.stopSearch();
|
computerPlayer.stopSearch();
|
||||||
try {
|
try {
|
||||||
@@ -829,8 +834,9 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
analysisThread = null;
|
analysisThread = null;
|
||||||
listener.clearSearchInfo();
|
listener.clearSearchInfo();
|
||||||
updateGUI();
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final synchronized void setEngineStrength(String engine, int strength) {
|
public final synchronized void setEngineStrength(String engine, int strength) {
|
||||||
@@ -887,8 +893,11 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final synchronized void stopPonder() {
|
public final synchronized void stopPonder() {
|
||||||
if ((computerThread != null) && humansTurn())
|
if ((computerThread != null) && humansTurn()) {
|
||||||
stopComputerThinking();
|
boolean updateGui = stopComputerThinking();
|
||||||
|
if (updateGui)
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object shutdownEngineLock = new Object();
|
private Object shutdownEngineLock = new Object();
|
||||||
@@ -896,8 +905,10 @@ public class DroidChessController {
|
|||||||
synchronized (shutdownEngineLock) {
|
synchronized (shutdownEngineLock) {
|
||||||
gameMode = new GameMode(GameMode.TWO_PLAYERS);
|
gameMode = new GameMode(GameMode.TWO_PLAYERS);
|
||||||
ss.searchResultWanted = false;
|
ss.searchResultWanted = false;
|
||||||
stopComputerThinking();
|
boolean updateGui = stopComputerThinking();
|
||||||
stopAnalysis();
|
updateGui |= stopAnalysis();
|
||||||
|
if (updateGui)
|
||||||
|
updateGUI();
|
||||||
ponderMove = null;
|
ponderMove = null;
|
||||||
computerPlayer.shutdownEngine();
|
computerPlayer.shutdownEngine();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user