From ca3a88fcfe0d10b8d841251166afbf5cc1a02886 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sun, 7 Nov 2010 21:33:19 +0100 Subject: [PATCH] Let Engine #2 Settings start second engine If the second engine is not yet running, it would be impossible to use the settings dialog for it, as the features have not been received and the dialog will be empty. So the user could not adjust the engine parameters before starting a match. Using this menu now automatically starts the engine, and delays the appearence of the popup untill the features are received, using a similar mechanism as in TwoMachinesEventIfReady(). --- backend.c | 45 +++++++++++++++++++++++++++++++++------------ backend.h | 3 +++ winboard/winboard.c | 9 +++++++++ xoptions.c | 1 + 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/backend.c b/backend.c index 01d447e..1de9cb7 100644 --- a/backend.c +++ b/backend.c @@ -11853,6 +11853,37 @@ DisplayTwoMachinesTitle() } void +SettingsMenuIfReady() +{ + if (second.lastPing != second.lastPong) { + DisplayMessage("", _("Waiting for second chess program")); + ScheduleDelayedEvent(SettingsMenuIfReady, 10); // [HGM] fast: lowered from 1000 + return; + } + ThawUI(); + DisplayMessage("", ""); + SettingsPopUp(&second); +} + +int +WaitForSecond(DelayedEventCallback retry) +{ + if (second.pr == NULL) { + StartChessProgram(&second); + if (second.protocolVersion == 1) { + retry(); + } else { + /* kludge: allow timeout for initial "feature" command */ + FreezeUI(); + DisplayMessage("", _("Starting second chess program")); + ScheduleDelayedEvent(retry, FEATURE_TIMEOUT); + } + return 1; + } + return 0; +} + +void TwoMachinesEvent P((void)) { int i; @@ -11894,18 +11925,7 @@ TwoMachinesEvent P((void)) TruncateGame(); // [HGM] vari: MachineWhite and MachineBlack do this... ResurrectChessProgram(); /* in case first program isn't running */ - if (second.pr == NULL) { - StartChessProgram(&second); - if (second.protocolVersion == 1) { - TwoMachinesEventIfReady(); - } else { - /* kludge: allow timeout for initial "feature" command */ - FreezeUI(); - DisplayMessage("", _("Starting second chess program")); - ScheduleDelayedEvent(TwoMachinesEventIfReady, FEATURE_TIMEOUT); - } - return; - } + if(WaitForSecond(TwoMachinesEventIfReady)) return; DisplayMessage("", ""); InitChessProgram(&second, FALSE); SendToProgram("force\n", &second); @@ -13844,6 +13864,7 @@ FeatureDone(cps, val) { DelayedEventCallback cb = GetDelayedEvent(); if ((cb == InitBackEnd3 && cps == &first) || + (cb == SettingsMenuIfReady && cps == &second) || (cb == TwoMachinesEventIfReady && cps == &second)) { CancelDelayedEvent(); ScheduleDelayedEvent(cb, val ? 1 : 3600000); diff --git a/backend.h b/backend.h index 0b901c1..6da6323 100644 --- a/backend.h +++ b/backend.h @@ -206,6 +206,8 @@ void AnalyzeModeEvent P((void)); void AnalyzeFileEvent P((void)); void InitPosition P((int redraw)); void NewSettingEvent P((int option, int *feature, char *command, int value)); +int WaitForSecond P((DelayedEventCallback x)); +void SettingsMenuIfReady P((void)); void DoEcho P((void)); void DontEcho P((void)); void TidyProgramName P((char *prog, char *host, char *buf)); @@ -396,5 +398,6 @@ extern int shuffleOpenings; extern ChessProgramStats programStats; extern int opponentKibitzes; // used by wengineo.c extern int errorExitStatus; +void SettingsPopUp P((ChessProgramState *cps)); // [HGM] really in front-end, but CPS not known in frontend.h #endif /* _BACKEND */ diff --git a/winboard/winboard.c b/winboard/winboard.c index e7916ca..76c36e8 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -186,6 +186,7 @@ COLORREF lightSquareColor, darkSquareColor, whitePieceColor, HPALETTE hPal; ColorClass currentColorClass; +static HWND savedHwnd; HWND hCommPort = NULL; /* currently open comm port */ static HWND hwndPause; /* pause button */ static HBITMAP pieceBitmap[3][(int) BlackPawn]; /* [HGM] nr of bitmaps referred to bP in stead of wK */ @@ -5052,6 +5053,8 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_Engine2Options: + savedHwnd = hwnd; + if(WaitForSecond(SettingsMenuIfReady)) break; EngineOptionsPopup(hwnd, &second); break; @@ -9763,3 +9766,9 @@ HistorySet( char movelist[][2*MOVE_LEN], int first, int last, int current ) EvalGraphSet( first, last, current, pvInfoList ); } + +void +SettingsPopUp(ChessProgramState *cps) +{ // [HGM] wrapper needed because handles must not be passed through back-end + EngineOptionsPopup(savedHwnd, cps); +} diff --git a/xoptions.c b/xoptions.c index 2f58c7b..b30719d 100644 --- a/xoptions.c +++ b/xoptions.c @@ -1745,6 +1745,7 @@ void SecondSettingsProc(w, event, prms, nprms) String *prms; Cardinal *nprms; { + if(WaitForSecond(SettingsMenuIfReady)) return; SettingsPopUp(&second); } -- 1.7.0.4