X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=mainloop.c;fp=mainloop.c;h=d41e713a386e231ae13e79becc7fd922e06f1c4f;hb=e15efca6667b2673b4c1a5879a6917eab6800e58;hp=0000000000000000000000000000000000000000;hpb=0d182b4efac85dce968068bfe4509e52e9a30051;p=polyglot.git diff --git a/mainloop.c b/mainloop.c new file mode 100644 index 0000000..d41e713 --- /dev/null +++ b/mainloop.c @@ -0,0 +1,103 @@ +// mainloop.c + +// constants + +static const int StringSize = 4096; + +// includes + +#include +#include +#include +#include + +#include "main.h" +#include "engine.h" +#include "gui.h" +#include "option.h" +#include "xboard2uci.h" +#include "uci2uci.h" + +// prototypes + +static void mainloop_init (); +static void mainloop_wait_for_event (); +static void mainloop_engine_step(char * string); +static void mainloop_gui_step(char * string); + +// functions + +// mainloop_init() + +static void mainloop_init(){ + if(!option_get_bool("UCI")){ + xboard2uci_init(); // the default + } +} + +// mainloop_engine_step() + +static void mainloop_engine_step(char * string){ + if(option_get_bool("UCI")){ + uci2uci_engine_step(string); + }else{ + xboard2uci_engine_step(string); + } +} + +// mainloop_gui_step() + +static void mainloop_gui_step(char * string){ + if(option_get_bool("UCI")){ + uci2uci_gui_step(string); + }else if(my_string_equal(string,"uci")){ // mode auto detection + my_log("POLYGLOT *** Switching to UCI mode ***\n"); + option_set("UCI","TRUE"); + uci2uci_gui_step(string); + }else{ + xboard2uci_gui_step(string); + } +} + +// mainloop() + +void mainloop() { + char string[StringSize]; + mainloop_init(); + while (!engine_eof(Engine)) { + // process buffered lines + while(TRUE){ + if(gui_get_non_blocking(GUI,string)){ + mainloop_gui_step(string); + }else if(!engine_eof(Engine) && + engine_get_non_blocking(Engine,string) ){ + mainloop_engine_step(string); + }else{ + break; + } + } + mainloop_wait_for_event(); + } + my_log("POLYGLOT *** Mainloop has ended ***\n"); + // This should be handled better. + engine_close(Engine); + my_log("POLYGLOT Calling exit\n"); + exit(EXIT_SUCCESS); + +} + + + + +// mainloop_wait_for_event() + +static void mainloop_wait_for_event(){ + pipex_t *pipex[3]; + pipex[0]=GUI->pipex; + pipex[1]=Engine->pipex; + pipex[2]=NULL; + pipex_wait_event(pipex); +} + + +