Only resend changed options on xreuse restart
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sat, 26 Nov 2016 12:56:16 +0000 (13:56 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 13 Jan 2017 15:39:23 +0000 (16:39 +0100)
For engines that specify reuse=1, a new engine process is started for
every game. This new process is made aware of the option settings as
they were specified by the user during the live of its predecessors.
Now this resending is limited to the options that have different value
from their original default. To achieve that, the default values are
now remembered (in the last 104 bytes of the Option.name buffer, which
was allocated way too large): 4 bytes for integet value, 99 char text.

backend.c

index c18fa3e..2f3db5e 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -10935,23 +10935,27 @@ ResendOptions (ChessProgramState *cps)
   char buf[MSG_SIZ];
   Option *opt = cps->option;
   for(i=0; i<cps->nrOptions; i++, opt++) {
+      *buf = NULLCHAR;
       switch(opt->type) {
         case Spin:
         case Slider:
         case CheckBox:
+           if(opt->value != *(int*) (opt->name + MSG_SIZ - 104))
            snprintf(buf, MSG_SIZ, "option %s=%d\n", opt->name, opt->value);
           break;
         case ComboBox:
-          snprintf(buf, MSG_SIZ, "option %s=%s\n", opt->name, opt->choice[opt->value]);
+           if(opt->value != *(int*) (opt->name + MSG_SIZ - 104))
+            snprintf(buf, MSG_SIZ, "option %s=%s\n", opt->name, opt->choice[opt->value]);
           break;
         default:
+           if(strcmp(opt->textValue, opt->name + MSG_SIZ - 100))
            snprintf(buf, MSG_SIZ, "option %s=%s\n", opt->name, opt->textValue);
           break;
         case Button:
         case SaveButton:
           continue;
       }
-      SendToProgram(buf, cps);
+      if(*buf) SendToProgram(buf, cps);
   }
 }
 
@@ -17281,6 +17285,8 @@ ParseOption (Option *opt, ChessProgramState *cps)
                strcat(buf, "\n");
                SendToProgram(buf, cps);
        }
+       *(int*) (opt->name + MSG_SIZ - 104) = opt->value; // hide default values somewhere
+       if(opt->target == &opt->textValue) strncpy(opt->name + MSG_SIZ - 100, opt->textValue, 99);
        return TRUE;
 }