DroidFish: More efficient update of "thinking info" when the engine

provides data faster than the GUI can handle.
This commit is contained in:
Peter Osterlund
2015-10-10 17:43:16 +02:00
parent 9d5fad30a4
commit e768c9408a
3 changed files with 30 additions and 14 deletions

View File

@@ -1709,13 +1709,12 @@ public class DroidFish extends Activity implements GUIInterface {
private ArrayList<Move> variantMoves = null; private ArrayList<Move> variantMoves = null;
@Override @Override
public void setThinkingInfo(String pvStr, String statStr, String bookInfo, public void setThinkingInfo(ThinkingInfo ti) {
ArrayList<ArrayList<Move>> pvMoves, ArrayList<Move> bookMoves) { thinkingStr1 = ti.pvStr;
thinkingStr1 = pvStr; thinkingStr2 = ti.statStr;
thinkingStr2 = statStr; bookInfoStr = ti.bookInfo;
bookInfoStr = bookInfo; this.pvMoves = ti.pvMoves;
this.pvMoves = pvMoves; this.bookMoves = ti.bookMoves;
this.bookMoves = bookMoves;
updateThinkingInfo(); updateThinkingInfo();
if (ctrl.computerBusy()) { if (ctrl.computerBusy()) {

View File

@@ -52,9 +52,17 @@ public interface GUIInterface {
/** Update the list of moves. */ /** Update the list of moves. */
public void moveListUpdated(); public void moveListUpdated();
final public static class ThinkingInfo {
public int id;
public String pvStr;
public String statStr;
public String bookInfo;
public ArrayList<ArrayList<Move>> pvMoves;
public ArrayList<Move> bookMoves;
}
/** Update the computer thinking information. */ /** Update the computer thinking information. */
public void setThinkingInfo(String pvStr, String statStr, String bookInfo, public void setThinkingInfo(ThinkingInfo ti);
ArrayList<ArrayList<Move>> pvMoves, ArrayList<Move> bookMoves);
/** Ask what to promote a pawn to. Should call reportPromotePiece() when done. */ /** Ask what to promote a pawn to. Should call reportPromotePiece() when done. */
public void requestPromotePiece(); public void requestPromotePiece();

View File

@@ -30,6 +30,7 @@ import java.util.Map;
import org.petero.droidfish.EngineOptions; import org.petero.droidfish.EngineOptions;
import org.petero.droidfish.GUIInterface; import org.petero.droidfish.GUIInterface;
import org.petero.droidfish.GUIInterface.ThinkingInfo;
import org.petero.droidfish.GameMode; import org.petero.droidfish.GameMode;
import org.petero.droidfish.PGNOptions; import org.petero.droidfish.PGNOptions;
import org.petero.droidfish.Util; import org.petero.droidfish.Util;
@@ -67,6 +68,7 @@ public class DroidChessController {
private Move promoteMove; private Move promoteMove;
private int searchId; private int searchId;
private volatile ThinkingInfo latestThinkingInfo = null;
/** Constructor. */ /** Constructor. */
public DroidChessController(GUIInterface gui, PgnToken.PgnTokenReceiver gameTextListener, PGNOptions options) { public DroidChessController(GUIInterface gui, PgnToken.PgnTokenReceiver gameTextListener, PGNOptions options) {
@@ -769,9 +771,17 @@ public class DroidChessController {
pvMoves.add(pvInfoV.get(i).pv); pvMoves.add(pvInfoV.get(i).pv);
} }
} }
final ThinkingInfo ti = new ThinkingInfo();
ti.id = id;
ti.pvStr = newPV;
ti.statStr = statStr;
ti.bookInfo = newBookInfo;
ti.pvMoves = pvMoves;
ti.bookMoves = bookMoves;
latestThinkingInfo = ti;
gui.runOnUIThread(new Runnable() { gui.runOnUIThread(new Runnable() {
public void run() { public void run() {
setThinkingInfo(id, pvMoves, newPV, statStr, newBookInfo, bookMoves); setThinkingInfo(ti);
} }
}); });
} }
@@ -1122,10 +1132,9 @@ public class DroidChessController {
gui.updateMaterialDifferenceTitle(Util.getMaterialDiff(game.currPos())); gui.updateMaterialDifferenceTitle(Util.getMaterialDiff(game.currPos()));
} }
private final synchronized void setThinkingInfo(int id, ArrayList<ArrayList<Move>> pvMoves, String pvStr, private final synchronized void setThinkingInfo(ThinkingInfo ti) {
String statStr, String bookInfo, ArrayList<Move> bookMoves) { if ((ti.id == searchId) && (ti == latestThinkingInfo))
if (id == searchId) gui.setThinkingInfo(ti);
gui.setThinkingInfo(pvStr, statStr, bookInfo, pvMoves, bookMoves);
} }
private final void updateMoveList() { private final void updateMoveList() {