From: Yann Dirson Date: Wed, 23 Oct 2013 21:27:46 +0000 (+0200) Subject: Make UpdateClocks and input-polling dspwrappers-based too. X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=d23b84fee73518dfb6b281d1eaedbe4fc4aa34b2;p=gnushogi.git Make UpdateClocks and input-polling dspwrappers-based too. Those things are the only thing called from ElapsedTime() to be different between Curses and Raw/X, and were not abstracted yet. The poll-based polling code was not called from within ElapsedTime(), which made it less frequently called, but that did not seem to be a problem. And it was redundant in Curses mode with the FIONREAD call. --- diff --git a/gnushogi/cursesdsp.c b/gnushogi/cursesdsp.c index fb4437d..5540ede 100644 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@ -716,8 +716,8 @@ Curses_OutputMove(void) } -static void -UpdateClocks(void) +void +Curses_UpdateClocks(void) { short m, s; long dt; @@ -1196,25 +1196,12 @@ Curses_DoTable(short table[NO_SQUARES]) } -/* - * Determine the time that has passed since the search was started. If the - * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout - * to true which will terminate the search. - * iop = COMPUTE_MODE calculate et, bump ETnodes - * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded, - * set reference time - */ void -Curses_ElapsedTime(ElapsedTime_mode iop) +Curses_PollForInput(void) { - long current_time; int i; int nchar; -#ifdef HAVE_GETTIMEOFDAY - struct timeval tv; -#endif - if ((i = ioctl((int) 0, FIONREAD, &nchar))) { perror("FIONREAD"); @@ -1232,6 +1219,25 @@ Curses_ElapsedTime(ElapsedTime_mode iop) flag.bothsides = false; } +} + +/* + * Determine the time that has passed since the search was started. If the + * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout + * to true which will terminate the search. + * iop = COMPUTE_MODE calculate et, bump ETnodes + * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded, + * set reference time + */ +void +Curses_ElapsedTime(ElapsedTime_mode iop) +{ + long current_time; +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; +#endif + + PollForInput(); #ifdef HAVE_GETTIMEOFDAY gettimeofday(&tv, NULL); diff --git a/gnushogi/cursesdsp.h b/gnushogi/cursesdsp.h index 421c134..0c0ade1 100644 --- a/gnushogi/cursesdsp.h +++ b/gnushogi/cursesdsp.h @@ -54,6 +54,7 @@ void Curses_GiveHint(void); void Curses_Initialize(void); void Curses_ShowNodeCnt(long NodeCnt); void Curses_OutputMove(void); +void Curses_PollForInput(void); void Curses_SearchStartStuff(short side); void Curses_SelectLevel(char *sx); void Curses_SetContempt(void); @@ -76,6 +77,7 @@ void Curses_ShowResults(short score, unsigned short *bstline, char ch); void Curses_ShowSidetoMove(void); void Curses_ShowStage(void); void Curses_TerminateSearch(int sig); +void Curses_UpdateClocks(void); void Curses_UpdateDisplay(short f, short t, short redraw, short isspec); void Curses_help(void); diff --git a/gnushogi/dspwrappers.c b/gnushogi/dspwrappers.c index b29afbe..59d55ee 100644 --- a/gnushogi/dspwrappers.c +++ b/gnushogi/dspwrappers.c @@ -92,6 +92,7 @@ DISPLAY_VOIDFUNC(GiveHint) DISPLAY_VOIDFUNC(Initialize) DISPLAY_FUNC(ShowNodeCnt, (long NodeCnt), (NodeCnt)) DISPLAY_VOIDFUNC(OutputMove) +DISPLAY_VOIDFUNC(PollForInput) DISPLAY_VOIDFUNC(SetContempt) DISPLAY_FUNC(SearchStartStuff, (short side), (side)) DISPLAY_FUNC(SelectLevel, (char *sx), (sx)) @@ -112,6 +113,7 @@ DISPLAY_FUNC(ShowResults, (short score, unsigned short *bstline, char ch), (scor DISPLAY_VOIDFUNC(ShowSidetoMove) DISPLAY_VOIDFUNC(ShowStage) DISPLAY_FUNC(TerminateSearch, (int sig), (sig)) +DISPLAY_VOIDFUNC(UpdateClocks) DISPLAY_FUNC(UpdateDisplay, (short f, short t, short redraw, short isspec), (f, t, redraw, isspec)) DISPLAY_VOIDFUNC(help) diff --git a/gnushogi/dspwrappers.h b/gnushogi/dspwrappers.h index 9c5e3fe..97de97d 100644 --- a/gnushogi/dspwrappers.h +++ b/gnushogi/dspwrappers.h @@ -52,6 +52,7 @@ extern void GiveHint(void); extern void Initialize(void); extern void ShowNodeCnt(long NodeCnt); extern void OutputMove(void); +extern void PollForInput(void); extern void SetContempt(void); extern void SearchStartStuff(short side); extern void SelectLevel(char *sx); @@ -74,6 +75,7 @@ extern void ShowResults(short score, unsigned short *bstline, char ch); extern void ShowSidetoMove(void); extern void ShowStage(void); extern void TerminateSearch(int sig); +extern void UpdateClocks(void); extern void UpdateDisplay(short f, short t, short redraw, short isspec); extern void help(void); diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index 0edfafd..e71877d 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include "gnushogi.h" #include "rawdsp.h" @@ -627,6 +629,12 @@ Raw_OutputMove(void) void +Raw_UpdateClocks(void) +{ +} + + +void Raw_UpdateDisplay(short f, short t, short redraw, short isspec) { @@ -983,6 +991,24 @@ Raw_ShowPostnValues(void) } +void +Raw_PollForInput(void) +{ + static struct pollfd pollfds[1] = { /* [0] = */ { /* .fd = */ STDIN_FILENO, + /* .events = */ POLLIN } }; + int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0); + if (cnt < 0) { + perror("polling standard input"); + ExitShogi(); + } + if (cnt) { /* if anything to read, or error occured */ + if (!flag.timeout) + flag.back = true; /* previous: flag.timeout = true; */ + flag.bothsides = false; + } +} + + /* * Determine the time that has passed since the search was started. If the * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout @@ -997,6 +1023,11 @@ Raw_ElapsedTime(ElapsedTime_mode iop) long current_time; #ifdef HAVE_GETTIMEOFDAY struct timeval tv; +#endif + + PollForInput(); + +#ifdef HAVE_GETTIMEOFDAY gettimeofday(&tv, NULL); current_time = tv.tv_sec*100 + (tv.tv_usec/10000); #else @@ -1035,5 +1066,10 @@ Raw_ElapsedTime(ElapsedTime_mode iop) time0 = current_time; } + +#ifdef QUIETBACKGROUND + if (!background) +#endif + UpdateClocks(); } } diff --git a/gnushogi/rawdsp.h b/gnushogi/rawdsp.h index 7c01fd8..6162d24 100644 --- a/gnushogi/rawdsp.h +++ b/gnushogi/rawdsp.h @@ -54,6 +54,7 @@ void Raw_GiveHint(void); void Raw_Initialize(void); void Raw_ShowNodeCnt(long NodeCnt); void Raw_OutputMove(void); +void Raw_PollForInput(void); void Raw_SearchStartStuff(short side); void Raw_SelectLevel(char *sx); void Raw_SetContempt(void); @@ -76,6 +77,7 @@ void Raw_ShowResults(short score, unsigned short *bstline, char ch); void Raw_ShowSidetoMove(void); void Raw_ShowStage(void); void Raw_TerminateSearch(int sig); +void Raw_UpdateClocks(void); void Raw_UpdateDisplay(short f, short t, short redraw, short isspec); void Raw_help(void); diff --git a/gnushogi/search.c b/gnushogi/search.c index c1d8fd9..35c968a 100644 --- a/gnushogi/search.c +++ b/gnushogi/search.c @@ -30,8 +30,6 @@ */ #include "gnushogi.h" -#include -#include short background = 0; static short DepthBeyond; @@ -528,8 +526,6 @@ search(short side, short best = -(SCORE_LIMIT + 3000); short bestwidth = 0; short mustcut; - static struct pollfd pollfds[1] = { /* [0] = */ { /* .fd = */ STDIN_FILENO, - /* .events = */ POLLIN } }; #ifdef NULLMOVE short PVsave; @@ -547,19 +543,6 @@ search(short side, { ElapsedTime(COMPUTE_MODE); - if(background) { - int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0); - if (cnt < 0) { - perror("polling standard input"); - ExitShogi(); - } - if (cnt) { /* if anything to read, or error occured */ - if (!flag.timeout) - flag.back = true; /* previous: flag.timeout = true; */ - flag.bothsides = false; - } - } - if (flag.back) { flag.back = false;