[gnome-nibbles/arnaudb/use-uint8: 7/15] Remove a FIXME.



commit 915ef3e5609f56b873cae8e86447f20d60419b8c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jul 2 02:12:36 2020 +0200

    Remove a FIXME.

 src/nibbles-game.vala   | 14 ++++++++++----
 src/nibbles-test.vala   | 42 ++++++++++++++++++++----------------------
 src/nibbles-view.vala   | 32 +++++++++++++-------------------
 src/nibbles-window.vala |  1 +
 src/worm.vala           |  7 ++++++-
 5 files changed, 50 insertions(+), 46 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index fedb955..fcc4af4 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -28,7 +28,6 @@ private enum GameStatus
 
 private class NibblesGame : Object
 {
-    internal const int GAMEDELAY = 35;
 
     internal const int MAX_WORMS = 6;
 
@@ -43,6 +42,7 @@ private class NibblesGame : Object
     public bool skip_score      { internal get; protected construct set; }
     public int current_level    { internal get; protected construct set; }
     public int speed            { internal get; internal construct set; }
+    public int gamedelay        { internal get; protected construct; }
 
     /* Board data */
     internal int[,] board;
@@ -84,9 +84,9 @@ private class NibblesGame : Object
         boni.bonus_removed.connect ((bonus) => bonus_removed (bonus));
     }
 
-    internal NibblesGame (int start_level, int speed, bool fakes, int width, int height, bool no_random = 
false)
+    internal NibblesGame (int start_level, int speed, int gamedelay, bool fakes, int width, int height, bool 
no_random = false)
     {
-        Object (skip_score: (start_level != 1), current_level: start_level, speed: speed, fakes: fakes, 
width: width, height: height);
+        Object (skip_score: (start_level != 1), current_level: start_level, speed: speed, gamedelay: 
gamedelay, fakes: fakes, width: width, height: height);
 
         Random.set_seed (no_random ? 42 : (uint32) time_t ());
     }
@@ -262,7 +262,7 @@ private class NibblesGame : Object
 
         is_running = true;
 
-        main_id = Timeout.add (GAMEDELAY * speed, () => {
+        main_id = Timeout.add (gamedelay * speed, () => {
                 bonus_cycle = (bonus_cycle + 1) % 3;
                 if (bonus_cycle == 0)
                     add_bonus (false);
@@ -362,6 +362,7 @@ private class NibblesGame : Object
         {
             var worm = new Worm (i, width, height);
             worm.bonus_found.connect (bonus_found_cb);
+            worm.finish_added.connect (worm_dematerialization_request);
             worm.is_human = (i < numhumans);
             worms.add (worm);
         }
@@ -486,6 +487,11 @@ private class NibblesGame : Object
                 other_worm.reverse (board);
     }
 
+    private void worm_dematerialization_request (Worm worm)
+    {
+        worm.dematerialize (board, /* number of rounds */ 3, gamedelay);
+    }
+
     /*\
     * * Handling bonuses
     \*/
diff --git a/src/nibbles-test.vala b/src/nibbles-test.vala
index d1ba881..e159be9 100644
--- a/src/nibbles-test.vala
+++ b/src/nibbles-test.vala
@@ -56,7 +56,12 @@ namespace NibblesTest
                                     uint8 final_bonuses,
                                     WormTest [] worms)
     {
-        NibblesGame game = new NibblesGame (/* start level */ 1, /* speed */ 0, /* fakes */ false, board 
[0].char_count (), board.length, /* no random */ true);
+        NibblesGame game = new NibblesGame (/* start level  */ 1,   // used as score multiplier
+                                            /* speed        */ 0,
+                                            /* delay        */ 0,
+                                            /* fakes        */ false,
+                                            /* size x and y */ board [0].char_count (), board.length,
+                                            /* no random    */ true);
 
         game.numhumans = 0;
         game.numai = worms.length;
@@ -64,11 +69,6 @@ namespace NibblesTest
 
         game.load_board (board, regular_bonuses);
 
-        ulong [] worms_handlers = new ulong [game.worms.size];
-        foreach (Worm worm in game.worms)
-            // FIXME we should not have to connect to anything                  // TODO what’s this 3 in 
dematerialize?
-            worms_handlers [worm.id] = worm.finish_added.connect (() => { worm.dematerialize (game.board, 
3); worm.is_stopped = false; });
-
         assert_true (game.numworms   == worms.length);
         assert_true (game.worms.size == worms.length);
 
@@ -109,8 +109,6 @@ namespace NibblesTest
 //        Test.message (@"applied bonus: $applied_bonus");
         assert_true (applied_bonus == final_bonuses);
 
-        foreach (Worm worm in game.worms)
-            worm.disconnect (worms_handlers [worm.id]);
         game.disconnect (game_handler_1);
         game.disconnect (game_handler_2);
 
@@ -124,23 +122,23 @@ namespace NibblesTest
     private static void test_games ()
     {
         Test.message ("test board 008");
-        test_board (level_008, /* regular bonus = 8 + numworms */ 12, /* final bonuses */ 15,
-                    { WormTest () { start_x =  4, start_y = 14, final_lives = 6, final_score =  11 },
-                      WormTest () { start_x = 18, start_y = 31, final_lives = 5, final_score =  14 },
-                      WormTest () { start_x =  9, start_y = 39, final_lives = 6, final_score = 119 },
-                      WormTest () { start_x = 51, start_y = 45, final_lives = 6, final_score =  19 }});
+        test_board (level_008, /* regular bonus = 8 + numworms */ 12, /* final bonuses */ 14,
+                    { WormTest () { start_x =  4, start_y = 14, final_lives = 6, final_score =  20 },
+                      WormTest () { start_x = 18, start_y = 31, final_lives = 5, final_score =  15 },
+                      WormTest () { start_x =  9, start_y = 39, final_lives = 5, final_score =  33 },
+                      WormTest () { start_x = 51, start_y = 45, final_lives = 6, final_score =   8 }});
 
         Test.message ("test board 011");
-        test_board (level_011, /* regular bonus = 8 + numworms */ 12, /* final bonuses */ 18,
-                    { WormTest () { start_x = 15, start_y =  9, final_lives = 5, final_score =  12 },
-                      WormTest () { start_x = 44, start_y =  9, final_lives = 6, final_score =   0 },
-                      WormTest () { start_x = 76, start_y =  9, final_lives = 6, final_score =   0 },
-                      WormTest () { start_x = 15, start_y = 56, final_lives = 6, final_score = 115 }});
+        test_board (level_011, /* regular bonus = 8 + numworms */ 12, /* final bonuses */ 17,
+                    { WormTest () { start_x = 15, start_y =  9, final_lives = 5, final_score =  76 },
+                      WormTest () { start_x = 44, start_y =  9, final_lives = 6, final_score =   5 },
+                      WormTest () { start_x = 76, start_y =  9, final_lives = 6, final_score =  18 },
+                      WormTest () { start_x = 15, start_y = 56, final_lives = 6, final_score = 100 }});
 
         Test.message ("test board 025");
         test_board (level_025, /* regular bonus = 8 + numworms */ 12, /* final bonuses */ 14,
-                    { WormTest () { start_x = 11, start_y =  6, final_lives = 5, final_score =   5 },
-                      WormTest () { start_x = 80, start_y =  6, final_lives = 6, final_score =  26 },
+                    { WormTest () { start_x = 11, start_y =  6, final_lives = 5, final_score =  17 },
+                      WormTest () { start_x = 80, start_y =  6, final_lives = 6, final_score =  14 },
                       WormTest () { start_x = 14, start_y = 37, final_lives = 6, final_score =  22 },
                       WormTest () { start_x = 79, start_y = 27, final_lives = 6, final_score =  22 }});
     }
@@ -416,7 +414,7 @@ namespace NibblesTest
             "┣━━━━━━━.━━━━━━━━┫",
             "┃▶..............◀┃",
             "┗━━━━━━━━━━━━━━━━┛"
-        };  /* expected: 6, 5 */
+        };  /* expected: 6, 4 */
     private const string [] test_heads_3 = {
             "┏━━━━━━━━━━━━━━━━┓",
             "┃................┃",
@@ -456,7 +454,7 @@ namespace NibblesTest
             "┏━━━━━┛.┃........┃",
             "┃▶......┃........┃",
             "┗━━━━━━━┻━━━━━━━━┛"
-        };  /* expected: 6, 5 */
+        };  /* expected: 6, 4 */
     private const string [] test_heads_7 = {
             "........┏━━━━━━━━┓",
             "┏━━━━━━━┛........┃",
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 2518639..6dc61d8 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -27,7 +27,7 @@ private class WormActor : Clutter.Actor
 
         save_easing_state ();
         set_easing_mode (Clutter.AnimationMode.EASE_OUT_CIRC);
-        set_easing_duration (NibblesGame.GAMEDELAY * 26);
+        set_easing_duration (NibblesView.GAMEDELAY * 26);
         set_scale (1.0, 1.0);
         set_pivot_point (0.5f, 0.5f);
         set_opacity (0xff);
@@ -38,7 +38,7 @@ private class WormActor : Clutter.Actor
     {
         save_easing_state ();
         set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
-        set_easing_duration (NibblesGame.GAMEDELAY * 15);
+        set_easing_duration (NibblesView.GAMEDELAY * 15);
         set_scale (0.4f, 0.4f);
         set_opacity (0);
         restore_easing_state ();
@@ -58,7 +58,7 @@ private class BonusTexture : GtkClutter.Texture
 
         save_easing_state ();
         set_easing_mode (Clutter.AnimationMode.EASE_OUT_BOUNCE);
-        set_easing_duration (NibblesGame.GAMEDELAY * 20);
+        set_easing_duration (NibblesView.GAMEDELAY * 20);
         set_scale (1.0, 1.0);
         set_pivot_point (0.5f, 0.5f);
         set_opacity (0xff);
@@ -84,7 +84,7 @@ private class WarpTexture: GtkClutter.Texture
 
         save_easing_state ();
         set_easing_mode (Clutter.AnimationMode.EASE_OUT_CIRC);
-        set_easing_duration (NibblesGame.GAMEDELAY * 15);
+        set_easing_duration (NibblesView.GAMEDELAY * 15);
         set_scale (1.0, 1.0);
         set_pivot_point (0.5f, 0.5f);
         set_opacity (0xff);
@@ -95,7 +95,7 @@ private class WarpTexture: GtkClutter.Texture
     {
         save_easing_state ();
         set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
-        set_easing_duration (NibblesGame.GAMEDELAY * 15);
+        set_easing_duration (NibblesView.GAMEDELAY * 15);
         set_scale (0.4f, 0.4f);
         set_pivot_point (0.5f, 0.5f);
         set_opacity (0);
@@ -112,6 +112,7 @@ private class NibblesView : GtkClutter.Embed
 {
     internal const int WIDTH = 92;
     internal const int HEIGHT = 66;
+    internal const int GAMEDELAY = 35;
 
     private const int MINIMUM_TILE_SIZE = 7;
     public int tile_size { internal get; protected construct set; }
@@ -354,7 +355,7 @@ private class NibblesView : GtkClutter.Embed
 
         level.save_easing_state ();
         level.set_easing_mode (Clutter.AnimationMode.EASE_OUT_BOUNCE);
-        level.set_easing_duration (NibblesGame.GAMEDELAY * NibblesGame.GAMEDELAY);
+        level.set_easing_duration (GAMEDELAY * GAMEDELAY);
         level.set_scale (1.0, 1.0);
         level.set_pivot_point (0.5f, 0.5f);
         level.set_opacity (0xff);
@@ -458,7 +459,7 @@ private class NibblesView : GtkClutter.Embed
                 var actors = worm_actors.@get (worm);
 
                 actors.save_easing_state ();
-                actors.set_easing_duration (NibblesGame.GAMEDELAY * 10);
+                actors.set_easing_duration (GAMEDELAY * 10);
                 actors.set_opacity (opacity);
                 actors.restore_easing_state ();
             });
@@ -515,7 +516,7 @@ private class NibblesView : GtkClutter.Embed
 
         level.save_easing_state ();
         level.set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
-        level.set_easing_duration (NibblesGame.GAMEDELAY * 20);
+        level.set_easing_duration (GAMEDELAY * 20);
         level.set_scale (0.4f, 0.4f);
         level.set_pivot_point (0.5f, 0.5f);
         level.set_opacity (0);
@@ -587,18 +588,11 @@ private class NibblesView : GtkClutter.Embed
 
         actors.save_easing_state ();
         actors.set_easing_mode (Clutter.AnimationMode.EASE_OUT);
-        actors.set_easing_duration (NibblesGame.GAMEDELAY * 20);
+        actors.set_easing_duration (GAMEDELAY * 20);
         actors.set_scale (1.0, 1.0);
         actors.set_pivot_point (0.5f, 0.5f);
         actors.set_opacity (0xff);
         actors.restore_easing_state ();
-
-        worm.dematerialize (game.board, 3);
-
-        Timeout.add (NibblesGame.GAMEDELAY * 27, () => {
-            worm.is_stopped = false;
-            return Source.REMOVE;
-        });
     }
 
     private void worm_moved_cb (Worm worm)
@@ -661,7 +655,7 @@ private class NibblesView : GtkClutter.Embed
 
         group.save_easing_state ();
         group.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
-        group.set_easing_duration (NibblesGame.GAMEDELAY * 9);
+        group.set_easing_duration (GAMEDELAY * 9);
         group.set_scale (2.0f, 2.0f);
         group.set_pivot_point (0.5f, 0.5f);
         group.set_opacity (0);
@@ -703,7 +697,7 @@ private class NibblesView : GtkClutter.Embed
 
         group.save_easing_state ();
         group.set_easing_mode (Clutter.AnimationMode.EASE_OUT_EXPO);
-        group.set_easing_duration (NibblesGame.GAMEDELAY * 25);
+        group.set_easing_duration (GAMEDELAY * 25);
         group.set_opacity (0);
         group.restore_easing_state ();
     }
@@ -765,7 +759,7 @@ private class NibblesView : GtkClutter.Embed
 
         actor.save_easing_state ();
         actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUINT);
-        actor.set_easing_duration (NibblesGame.GAMEDELAY * 15);
+        actor.set_easing_duration (GAMEDELAY * 15);
         actor.set_scale (1.45f, 1.45f);
         actor.set_pivot_point (0.5f, 0.5f);
         actor.restore_easing_state ();
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 24188a8..19d9d3e 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -137,6 +137,7 @@ private class NibblesWindow : ApplicationWindow
         /* Create game */
         game = new NibblesGame (start_level,
                                 settings.get_int ("speed"),
+                                NibblesView.GAMEDELAY,
                                 settings.get_boolean ("fakes"),
                                 NibblesView.WIDTH,
                                 NibblesView.HEIGHT);
diff --git a/src/worm.vala b/src/worm.vala
index b8d2ebc..bd20af0 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -313,7 +313,7 @@ private class Worm : Object
         rounds_dematerialized = 0;
     }
 
-    internal void dematerialize (int [,] board, int rounds)
+    internal void dematerialize (int [,] board, int rounds, int gamedelay)
     {
         rounds_dematerialized = rounds;
         is_materialized = false;
@@ -322,6 +322,11 @@ private class Worm : Object
             if (board[pos.x, pos.y] == NibblesGame.WORMCHAR + id)
                 board[pos.x, pos.y] = NibblesGame.EMPTYCHAR;
         }
+
+        Timeout.add (gamedelay * 27, () => {
+                is_stopped = false;
+                return Source.REMOVE;
+            });
     }
 
     internal void add_life ()


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