X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwengineo.c;h=936fcd86fd9b6f7ce8fafde90061558ad52946e2;hb=8c94141e6c30dc94777dee5824cfbf027a18f940;hp=d10f3d9ab0dd02c127d75e9bcea4c52f8232ad71;hpb=9ee62d95780e76fa6cfc8abc7986e9f3c28868fd;p=xboard.git diff --git a/winboard/wengineo.c b/winboard/wengineo.c index d10f3d9..936fcd8 100644 --- a/winboard/wengineo.c +++ b/winboard/wengineo.c @@ -3,6 +3,8 @@ * * Author: Alessandro Scotti (Dec 2005) * + * Copyright 2005 Alessandro Scotti + * * ------------------------------------------------------------------------ * * GNU XBoard is free software: you can redistribute it and/or modify @@ -32,9 +34,9 @@ #include #include "common.h" -#include "winboard.h" #include "frontend.h" #include "backend.h" +#include "winboard.h" #include "wsnap.h" @@ -59,27 +61,8 @@ HICON icons[8]; // [HGM] this front-end array translates back-end icon indicator HWND outputField[2][7]; // [HGM] front-end array to translate output field to window handle -void EngineOutputPopUp(); -void EngineOutputPopDown(); -int EngineOutputIsUp(); - #define SHOW_PONDERING -/* Imports from backend.c */ -char * SavePart(char *str); -extern int opponentKibitzes; - -/* Imports from winboard.c */ -extern HWND engineOutputDialog; -extern int engineOutputDialogUp; - -extern HINSTANCE hInst; -extern HWND hwndMain; - -extern WindowPlacement wpEngineOutput; - -extern BoardSize boardSize; - /* Module variables */ #define H_MARGIN 2 #define V_MARGIN 2 @@ -95,12 +78,11 @@ extern BoardSize boardSize; #define STATE_ANALYZING 3 static int windowMode = 1; - static int needInit = TRUE; - static int lastDepth[2] = { -1, -1 }; static int lastForwardMostMove[2] = { -1, -1 }; static int engineState[2] = { -1, -1 }; +static BOOLEAN engineOutputDialogUp = FALSE; typedef struct { // HWND hColorIcon; // [HGM] the output-control handles are no loger passed, @@ -304,9 +286,9 @@ static void ResizeWindowControls( HWND hDlg, int mode ) } // front end. Actual printing of PV lines into the output field -static void InsertIntoMemo( int which, char * text ) +static void InsertIntoMemo( int which, char * text, int where ) { - SendMessage( outputField[which][nMemo], EM_SETSEL, 0, 0 ); + SendMessage( outputField[which][nMemo], EM_SETSEL, where, where ); // [HGM] multivar: choose insertion point SendMessage( outputField[which][nMemo], EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text ); } @@ -452,6 +434,8 @@ void DoClearMemo(int which) //------------------------ pure back-end routines ------------------------------- +#define MAX_VAR 400 +static int scores[MAX_VAR], textEnd[MAX_VAR], curDepth[2], nrVariations[2]; // back end, due to front-end wrapper for SetWindowText, and new SetIcon arguments static void SetEngineState( int which, int state, char * state_data ) @@ -542,10 +526,10 @@ void EngineOutputUpdate( FrontEndProgramStats * stats ) clearMemo = TRUE; } - if( clearMemo ) DoClearMemo(which); + if( clearMemo ) { DoClearMemo(which); nrVariations[which] = 0; } /* Update */ - lastDepth[which] = depth; + lastDepth[which] = depth == 1 && ed.nodes == 0 ? 0 : depth; // [HGM] info-line kudge lastForwardMostMove[which] = forwardMostMove; if( ed.pv != 0 && ed.pv[0] == ' ' ) { @@ -689,6 +673,38 @@ static void SetEngineColorIcon( int which ) #define MAX_NAME_LENGTH 32 +// [HGM] multivar: sort Thinking Output within one depth on score + +static int InsertionPoint( int len, EngineOutputData * ed ) +{ + int i, offs = 0, newScore = ed->score, n = ed->which; + + if(ed->nodes == 0 && ed->score == 0 && ed->time == 0) + newScore = 1e6; // info lines inserted on top + if(ed->depth != curDepth[n]) { // depth has changed + curDepth[n] = ed->depth; + nrVariations[n] = 0; // throw away everything we had + } + // loop through all lines. Note even / odd used for different panes + for(i=nrVariations[n]-2; i>=0; i-=2) { + // put new item behind those we haven't looked at + offs = textEnd[i+n]; + textEnd[i+n+2] = offs + len; + scores[i+n+2] = newScore; + if(newScore < scores[i+n]) break; + // if it had higher score as previous, move previous in stead + scores[i+n+2] = scores[i+n]; + textEnd[i+n+2] = textEnd[i+n] + len; + } + if(i<0) { + offs = 0; + textEnd[n] = offs + len; + scores[n] = newScore; + } + nrVariations[n] += 2; + return offs; +} + // pure back end, now SetWindowText is called via wrapper DoSetWindowText static void UpdateControls( EngineOutputData * ed ) { @@ -805,7 +821,8 @@ static void UpdateControls( EngineOutputData * ed ) sprintf( s_time, "%d:%02d.%02d", time_secs / 60, time_secs % 60, time_cent ); /* Put all together... */ - sprintf( buf, "%3d\t%s\t%s\t%s\t", ed->depth, s_score, s_nodes, s_time ); + if(ed->nodes == 0 && ed->score == 0 && ed->time == 0) sprintf( buf, "%3d\t", ed->depth ); else + sprintf( buf, "%3d\t%s\t%s\t%s\t", ed->depth, s_score, s_nodes, s_time ); /* Add PV */ buflen = strlen(buf); @@ -817,7 +834,7 @@ static void UpdateControls( EngineOutputData * ed ) strcat( buf + buflen, "\r\n" ); /* Update memo */ - InsertIntoMemo( ed->which, buf ); + InsertIntoMemo( ed->which, buf, InsertionPoint(strlen(buf), ed) ); } /* Colors */ @@ -848,5 +865,5 @@ void OutputKibitz(int window, char *text) DoSetWindowText(1, nLabel, gameMode == IcsPlayingBlack ? gameInfo.white : gameInfo.black); // opponent name SetIcon( 1, nColorIcon, gameMode == IcsPlayingBlack ? nColorWhite : nColorBlack); SetIcon( 1, nStateIcon, nClear); - InsertIntoMemo(window-1, text); + InsertIntoMemo(window-1, text, 0); // [HGM] multivar: always at top }