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;
@Override
public void setThinkingInfo(String pvStr, String statStr, String bookInfo,
ArrayList<ArrayList<Move>> pvMoves, ArrayList<Move> bookMoves) {
thinkingStr1 = pvStr;
thinkingStr2 = statStr;
bookInfoStr = bookInfo;
this.pvMoves = pvMoves;
this.bookMoves = bookMoves;
public void setThinkingInfo(ThinkingInfo ti) {
thinkingStr1 = ti.pvStr;
thinkingStr2 = ti.statStr;
bookInfoStr = ti.bookInfo;
this.pvMoves = ti.pvMoves;
this.bookMoves = ti.bookMoves;
updateThinkingInfo();
if (ctrl.computerBusy()) {

View File

@ -52,9 +52,17 @@ public interface GUIInterface {
/** Update the list of moves. */
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. */
public void setThinkingInfo(String pvStr, String statStr, String bookInfo,
ArrayList<ArrayList<Move>> pvMoves, ArrayList<Move> bookMoves);
public void setThinkingInfo(ThinkingInfo ti);
/** Ask what to promote a pawn to. Should call reportPromotePiece() when done. */
public void requestPromotePiece();

View File

@ -30,6 +30,7 @@ import java.util.Map;
import org.petero.droidfish.EngineOptions;
import org.petero.droidfish.GUIInterface;
import org.petero.droidfish.GUIInterface.ThinkingInfo;
import org.petero.droidfish.GameMode;
import org.petero.droidfish.PGNOptions;
import org.petero.droidfish.Util;
@ -67,6 +68,7 @@ public class DroidChessController {
private Move promoteMove;
private int searchId;
private volatile ThinkingInfo latestThinkingInfo = null;
/** Constructor. */
public DroidChessController(GUIInterface gui, PgnToken.PgnTokenReceiver gameTextListener, PGNOptions options) {
@ -769,9 +771,17 @@ public class DroidChessController {
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() {
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()));
}
private final synchronized void setThinkingInfo(int id, ArrayList<ArrayList<Move>> pvMoves, String pvStr,
String statStr, String bookInfo, ArrayList<Move> bookMoves) {
if (id == searchId)
gui.setThinkingInfo(pvStr, statStr, bookInfo, pvMoves, bookMoves);
private final synchronized void setThinkingInfo(ThinkingInfo ti) {
if ((ti.id == searchId) && (ti == latestThinkingInfo))
gui.setThinkingInfo(ti);
}
private final void updateMoveList() {