[iagno/gnome-3-10] Add cancel_pending_computer_moves utility methods



commit 8ede8bf784ef27e43fb0b122c0181130336e7c44
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sat Sep 28 19:11:28 2013 -0500

    Add cancel_pending_computer_moves utility methods
    
    Also, properly use it at the start of computer_move_cb
    
    This should avoid the situation where computer_move_cb gets called
    multiple times in succession.

 src/iagno.vala |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)
---
diff --git a/src/iagno.vala b/src/iagno.vala
index ba9b059..e0616bd 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -210,12 +210,7 @@ public class Iagno : Gtk.Application
 
     private void start_game ()
     {
-        /* Cancel any pending computer moves */
-        if (computer_timer != 0)
-        {
-            Source.remove (computer_timer);
-            computer_timer = 0;
-        }
+        cancel_pending_computer_moves ();
 
         if (game != null)
             SignalHandler.disconnect_by_func (game, null, this);
@@ -280,12 +275,7 @@ public class Iagno : Gtk.Application
 
     private void undo_move_cb ()
     {
-        /* Cancel any pending computer moves */
-        if (computer_timer != 0)
-        {
-            Source.remove (computer_timer);
-            computer_timer = 0;
-        }
+        cancel_pending_computer_moves ();
 
         /* Undo once if the human player just moved, otherwise undo both moves */
         if ((game.current_color == Player.DARK && dark_computer != null) ||
@@ -367,10 +357,7 @@ public class Iagno : Gtk.Application
 
     private bool computer_move_cb ()
     {
-        /* set computer_timer to 0 *before* calling move() since that will
-         * call game_move_cb and possibly create a new timer.
-         */
-        computer_timer = 0;
+        cancel_pending_computer_moves ();
         if (game.current_color == Player.LIGHT)
             light_computer.move ();
         else
@@ -378,6 +365,15 @@ public class Iagno : Gtk.Application
         return false;
     }
 
+    private void cancel_pending_computer_moves ()
+    {
+        if (computer_timer != 0)
+        {
+            Source.remove (computer_timer);
+            computer_timer = 0;
+        }
+    }
+
     private void game_complete_cb ()
     {
         update_ui ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]