From: H.G. Muller Date: Sun, 14 Oct 2012 08:47:21 +0000 (+0200) Subject: Move ICS-engine analyze and AnalyzeGame code to shared back-end X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=e52795a90f3a8136332ed86ff17920e6e75e5f3f Move ICS-engine analyze and AnalyzeGame code to shared back-end This code was still duplicated between WB and XB in the front-ends. Because of its incorporation in AnalyzeModeEvent the 'middle-end' function AnalyzeModeProc could be eliminated. AnalyzeModeEvent was made to return an int to flag its success, and keep the JAWS code based on it out of XBoard. The AnalyzeGame code is now incorporated in AnalyzeFileEvent(). --- diff --git a/backend.c b/backend.c index b7dad06..9f90dad 100644 --- a/backend.c +++ b/backend.c @@ -13445,18 +13445,59 @@ ToggleSecond () } } +/* Toggle ShowThinking */ void +ToggleShowThinking() +{ + appData.showThinking = !appData.showThinking; + ShowThinkingEvent(); +} + +int AnalyzeModeEvent () { - if (gameMode == AnalyzeMode) { ToggleSecond(); return; } + char buf[MSG_SIZ]; + + if (!first.analysisSupport) { + snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); + DisplayError(buf, 0); + return 0; + } + /* [DM] icsEngineAnalyze [HGM] This is horrible code; reverse the gameMode and isEngineAnalyze tests! */ + if (appData.icsActive) { + if (gameMode != IcsObserving) { + snprintf(buf, MSG_SIZ, _("You are not observing a game")); + DisplayError(buf, 0); + /* secure check */ + if (appData.icsEngineAnalyze) { + if (appData.debugMode) + fprintf(debugFP, _("Found unexpected active ICS engine analyze \n")); + ExitAnalyzeMode(); + ModeHighlight(); + } + return 0; + } + /* if enable, user wants to disable icsEngineAnalyze */ + if (appData.icsEngineAnalyze) { + ExitAnalyzeMode(); + ModeHighlight(); + return 0; + } + appData.icsEngineAnalyze = TRUE; + if (appData.debugMode) + fprintf(debugFP, _("ICS engine analyze starting... \n")); + } + + if (gameMode == AnalyzeMode) { ToggleSecond(); return 0; } if (appData.noChessProgram || gameMode == AnalyzeMode) - return; + return 0; if (gameMode != AnalyzeFile) { if (!appData.icsEngineAnalyze) { EditGameEvent(); - if (gameMode != EditGame) return; + if (gameMode != EditGame) return 0; } + if (!appData.showThinking) ToggleShowThinking(); ResurrectChessProgram(); SendToProgram("analyze\n", &first); first.analyzing = TRUE; @@ -13472,6 +13513,7 @@ AnalyzeModeEvent () StartAnalysisClock(); GetTimeMark(&lastNodeCountTime); lastNodeCount = 0; + return 1; } void @@ -13480,9 +13522,17 @@ AnalyzeFileEvent () if (appData.noChessProgram || gameMode == AnalyzeFile) return; + if (!first.analysisSupport) { + char buf[MSG_SIZ]; + snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); + DisplayError(buf, 0); + return; + } + if (gameMode != AnalyzeMode) { EditGameEvent(); if (gameMode != EditGame) return; + if (!appData.showThinking) ToggleShowThinking(); ResurrectChessProgram(); SendToProgram("analyze\n", &first); first.analyzing = TRUE; @@ -13499,6 +13549,7 @@ AnalyzeFileEvent () GetTimeMark(&lastNodeCountTime); lastNodeCount = 0; if(appData.timeDelay > 0) StartLoadGameTimer((long)(1000.0f * appData.timeDelay)); + AnalysisPeriodicEvent(1); } void diff --git a/backend.h b/backend.h index 6ca8d52..40c4d08 100644 --- a/backend.h +++ b/backend.h @@ -207,7 +207,7 @@ void MailMoveEvent P((void)); void EditTagsEvent P((void)); void GetMoveListEvent P((void)); void ExitAnalyzeMode P((void)); -void AnalyzeModeEvent P((void)); +int AnalyzeModeEvent P((void)); void AnalyzeFileEvent P((void)); void MatchEvent P((int mode)); void RecentEngineEvent P((int nr)); diff --git a/menus.c b/menus.c index 1af89f3..ed2d95b 100644 --- a/menus.c +++ b/menus.c @@ -256,67 +256,6 @@ QuitProc () } void -AnalyzeModeProc () -{ - char buf[MSG_SIZ]; - - if (!first.analysisSupport) { - snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); - DisplayError(buf, 0); - return; - } - /* [DM] icsEngineAnalyze [HGM] This is horrible code; reverse the gameMode and isEngineAnalyze tests! */ - if (appData.icsActive) { - if (gameMode != IcsObserving) { - snprintf(buf, MSG_SIZ, _("You are not observing a game")); - DisplayError(buf, 0); - /* secure check */ - if (appData.icsEngineAnalyze) { - if (appData.debugMode) - fprintf(debugFP, _("Found unexpected active ICS engine analyze \n")); - ExitAnalyzeMode(); - ModeHighlight(); - } - return; - } - /* if enable, use want disable icsEngineAnalyze */ - if (appData.icsEngineAnalyze) { - ExitAnalyzeMode(); - ModeHighlight(); - return; - } - appData.icsEngineAnalyze = TRUE; - if (appData.debugMode) - fprintf(debugFP, _("ICS engine analyze starting... \n")); - } -#ifndef OPTIONSDIALOG - if (!appData.showThinking) - ShowThinkingProc(); -#endif - - AnalyzeModeEvent(); -} - -void -AnalyzeFileProc () -{ - if (!first.analysisSupport) { - char buf[MSG_SIZ]; - snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); - DisplayError(buf, 0); - return; - } -// Reset(FALSE, TRUE); -#ifndef OPTIONSDIALOG - if (!appData.showThinking) - ShowThinkingProc(); -#endif - AnalyzeFileEvent(); -// FileNamePopUp(_("File to analyze"), "", ".pgn .game", LoadGamePopUp, "rb"); - AnalysisPeriodicEvent(1); -} - -void MatchProc () { MatchEvent(2); @@ -708,8 +647,8 @@ MenuItem modeMenu[] = { {N_("Machine White Ctrl+W"), "MachineWhite", MachineWhiteEvent}, {N_("Machine Black Ctrl+B"), "MachineBlack", MachineBlackEvent}, {N_("Two Machines Ctrl+T"), "TwoMachines", TwoMachinesEvent}, - {N_("Analysis Mode Ctrl+A"), "AnalysisMode", AnalyzeModeProc}, - {N_("Analyze Game Ctrl+G"), "AnalyzeFile", AnalyzeFileProc }, + {N_("Analysis Mode Ctrl+A"), "AnalysisMode", (MenuProc*) AnalyzeModeEvent}, + {N_("Analyze Game Ctrl+G"), "AnalyzeFile", AnalyzeFileEvent }, {N_("Edit Game Ctrl+E"), "EditGame", EditGameEvent}, {N_("Edit Position Ctrl+Shift+E"), "EditPosition", EditPositionEvent}, {N_("Training"), "Training", TrainingEvent}, diff --git a/winboard/winboard.c b/winboard/winboard.c index f133d33..cc4b5a9 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -4468,14 +4468,6 @@ PromotionPopUp() PromotionPopup(hwndMain); } -/* Toggle ShowThinking */ -VOID -ToggleShowThinking() -{ - appData.showThinking = !appData.showThinking; - ShowThinkingEvent(); -} - VOID LoadGameDialog(HWND hwnd, char* title) { @@ -4947,52 +4939,13 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_AnalysisMode: - if (!first.analysisSupport) { - snprintf(buf, MSG_SIZ, _("%s does not support analysis"), first.tidy); - DisplayError(buf, 0); - } else { + if(AnalyzeModeEvent()) { SAY("analyzing current position"); - /* [DM] icsEngineAnlyze [HGM] Why is this front-end??? */ - if (appData.icsActive) { - if (gameMode != IcsObserving) { - snprintf(buf, MSG_SIZ, "You are not observing a game"); - DisplayError(buf, 0); - /* secure check */ - if (appData.icsEngineAnalyze) { - if (appData.debugMode) - fprintf(debugFP, "Found unexpected active ICS engine analyze \n"); - ExitAnalyzeMode(); - ModeHighlight(); - break; - } - break; - } else { - /* if enable, user want disable icsEngineAnalyze */ - if (appData.icsEngineAnalyze) { - ExitAnalyzeMode(); - ModeHighlight(); - break; - } - appData.icsEngineAnalyze = TRUE; - if (appData.debugMode) fprintf(debugFP, "ICS engine analyze starting...\n"); - } - } - if (!appData.showThinking) ToggleShowThinking(); - AnalyzeModeEvent(); } break; case IDM_AnalyzeFile: - if (!first.analysisSupport) { - char buf[MSG_SIZ]; - snprintf(buf, MSG_SIZ, _("%s does not support analysis"), first.tidy); - DisplayError(buf, 0); - } else { - if (!appData.showThinking) ToggleShowThinking(); - AnalyzeFileEvent(); -// LoadGameDialog(hwnd, _("Analyze Game from File")); - AnalysisPeriodicEvent(1); - } + AnalyzeFileEvent(); break; case IDM_IcsClient: