Arrange that random seeds are as harmonised as they can reasonably
[sgt/puzzles] / midend.c
index 8adc1c3..cde2729 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -132,6 +132,14 @@ static void midend_set_timer(midend_data *me)
        deactivate_timer(me->frontend);
 }
 
+void midend_force_redraw(midend_data *me)
+{
+    if (me->drawstate)
+        me->ourgame->free_drawstate(me->drawstate);
+    me->drawstate = me->ourgame->new_drawstate(me->states[0].state);
+    midend_redraw(me);
+}
+
 void midend_new_game(midend_data *me)
 {
     while (me->nstates > 0)
@@ -178,7 +186,8 @@ void midend_new_game(midend_data *me)
        me->aux_info = NULL;
 
         rs = random_init(me->seedstr, strlen(me->seedstr));
-        me->desc = me->ourgame->new_desc(me->curparams, rs, &me->aux_info);
+        me->desc = me->ourgame->new_desc(me->curparams, rs,
+                                        &me->aux_info, TRUE);
         random_free(rs);
     }
 
@@ -306,7 +315,7 @@ static int midend_really_process_key(midend_data *me, int x, int y, int button)
        if (!midend_undo(me))
             return 1;
     } else if (button == 'r' || button == 'R' ||
-               button == '\x12') {
+               button == '\x12' || button == '\x19') {
        midend_stop_anim(me);
        if (!midend_redo(me))
             return 1;
@@ -316,7 +325,7 @@ static int midend_really_process_key(midend_data *me, int x, int y, int button)
     } else {
         game_state *s =
             me->ourgame->make_move(me->states[me->statepos-1].state,
-                                   me->ui, x, y, button);
+                                   me->ui, me->drawstate, x, y, button);
 
         if (s == me->states[me->statepos-1].state) {
             /*
@@ -432,6 +441,14 @@ int midend_process_key(midend_data *me, int x, int y, int button)
      *    pressed, invent a button-up for the first one and then
      *    pass the button-down through as before.
      * 
+     * 2005-05-31: An addendum to the above. Some games might want
+     * a `priority order' among buttons, such that if one button is
+     * pressed while another is down then a fixed one of the
+     * buttons takes priority no matter what order they're pressed
+     * in. Mines, in particular, wants to treat a left+right click
+     * like a left click for the benefit of users of other
+     * implementations. So the last of the above points is modified
+     * in the presence of an (optional) button priority order.
      */
     if (IS_MOUSE_DRAG(button) || IS_MOUSE_RELEASE(button)) {
         if (me->pressed_mouse_button) {
@@ -445,6 +462,14 @@ int midend_process_key(midend_data *me, int x, int y, int button)
         } else
             return ret;                /* ignore it */
     } else if (IS_MOUSE_DOWN(button) && me->pressed_mouse_button) {
+       /*
+        * If the new button has lower priority than the old one,
+        * don't bother doing this.
+        */
+       if (me->ourgame->mouse_priorities &
+           BUTTON_BEATS(me->pressed_mouse_button, button))
+           return ret;                /* just ignore it */
+
         /*
          * Fabricate a button-up for the previously pressed button.
          */
@@ -521,7 +546,8 @@ float *midend_colours(midend_data *me, int *ncolours)
 
     if (me->nstates == 0) {
        game_aux_info *aux = NULL;
-        char *desc = me->ourgame->new_desc(me->params, me->random, &aux);
+        char *desc = me->ourgame->new_desc(me->params, me->random,
+                                          &aux, TRUE);
         state = me->ourgame->new_game(me, me->params, desc);
         sfree(desc);
        if (aux)